From nobody Fri Jan 20 23:49:56 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NzGSh31yxz2swV3; Fri, 20 Jan 2023 23:49:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NzGSh2DcGz3tjv; Fri, 20 Jan 2023 23:49:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674258596; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6sKFanVV68JxMpeS8vy+yX1MJ4pGL6qZ8BavUFD4iqE=; b=SaTwnBWXf31Mys4RHvquwW5YFN4BgrI8zHY+68wb3iUCKsjuUuryVaSkVzNu+/EnsgYHdm U1FyYxfxSkc78hMfGM1Gpie+FJN4aKidW62+Uaf4N8v1MBkK0ShrQwHXiPCt4xqq6QCceK T4GFWMDgn/cPG0b9JC2X4L7N9ACHAXLJp8GLQgE4M4WlOgxlV6yXBxe7TJWAhQWYYFl1oD bKpZC7P06Vtk+Bvz1LysYYueJVxqwiIVUUai0PCRjeGce1AOxDRAhtq2zgWAjFCNYptP7k j9FfZrpdwJf6PywXzvH0snJpLpJk0Y/77/IVKOxuD2QmgLMyF5c6r+YMFGxmvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674258596; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6sKFanVV68JxMpeS8vy+yX1MJ4pGL6qZ8BavUFD4iqE=; b=hPk0ZGpEAc2TwzkS15ODus66cjv5kHugbQGk8M3i7X43BeViPjo2k9f65XKCONJZvUCd/R p829Z1qqANllpRf0khNwSCePpi8fR7THahseYhhW30jJ4F5hfybMIk0oLa9XundMq2TPE5 c0lErTJfpzTdWESzuSIipchlQg8vV94t5ewNpFQs0xMAQbB7uV6xirKQT3vunPS/bYt7C3 1JZNrX9DBiD0vYC8KocmaL+mNdhnL8W9tJk/mna68l925fttPoY9NeJhID6sRRrWOcf1w0 GYij7C1MDL/BhXBDEdEMW1BegIZezIVTWVw46i3kvQRlmBSQIPp6vVfei4mdtQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674258596; a=rsa-sha256; cv=none; b=gpUxZAk6DqbXbJQRsK6F+HELCyoBa3h2wHPWvKnErntDCXvF3tylTbgf9gZO3a5V0aLfXM WrzWSaZ+BUED8OFlNNYkPY/yCFviMgH0XFphRYRAj+X2KkWGYSl6aWgHWMRL8Ud1/9ovhX OkJDRbAoOhiR97WPGkKQHupsiccQBYtHMXWa64Zx85pz/xKplgcV26wLmRSWM0mX1xcLHa VoSislYx9n5MwWd4Xm4Yyzkzwhol6FDV49cjQFzclb7lwRNQLmyz9H8GhoYHXaUijlEyZ7 OHqWrSD1lCLawBMCUyKLkCjyRM+e61TblZMI7QaSdsuOviZ2F90CKje2OEGVqg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NzGSh1L74zplP; Fri, 20 Jan 2023 23:49:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30KNnucu088206; Fri, 20 Jan 2023 23:49:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30KNnunt088205; Fri, 20 Jan 2023 23:49:56 GMT (envelope-from git) Date: Fri, 20 Jan 2023 23:49:56 GMT Message-Id: <202301202349.30KNnunt088205@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 1761b09bf42d - main - byteswap.h: Add a glibc/linux compatible byteswap.h List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1761b09bf42d2842e82c1ac614c23d31c4d4c0dc Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=1761b09bf42d2842e82c1ac614c23d31c4d4c0dc commit 1761b09bf42d2842e82c1ac614c23d31c4d4c0dc Author: Warner Losh AuthorDate: 2023-01-20 23:33:37 +0000 Commit: Warner Losh CommitDate: 2023-01-20 23:37:39 +0000 byteswap.h: Add a glibc/linux compatible byteswap.h For endian.h to work instead of sys/endian.h, some software needs byteswap.h available. It must define {__,}byteswap_{16,32,64}. Included sys/_endian.h to get an appropriate __byteswap16, etc and defines the new macros in terms of them. Enhance _endian.h to allow it to be included from here too. Sponsored by: Netflix Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D32051 --- include/Makefile | 3 ++- include/byteswap.h | 41 +++++++++++++++++++++++++++++++++++++++++ sys/sys/_endian.h | 2 +- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/include/Makefile b/include/Makefile index aa4c115a3931..24124a1f366b 100644 --- a/include/Makefile +++ b/include/Makefile @@ -12,7 +12,8 @@ SUBDIR= arpa protocols rpcsvc rpc xlocale SUBDIR+= i386 .endif SUBDIR_PARALLEL= -INCS= a.out.h ar.h assert.h bitstring.h complex.h cpio.h _ctype.h ctype.h \ +INCS= a.out.h ar.h assert.h bitstring.h byteswap.h \ + complex.h cpio.h _ctype.h ctype.h \ db.h \ dirent.h dlfcn.h elf.h elf-hints.h endian.h err.h fmtmsg.h fnmatch.h \ fstab.h fts.h ftw.h getopt.h glob.h grp.h \ diff --git a/include/byteswap.h b/include/byteswap.h new file mode 100644 index 000000000000..a7b816ee82b0 --- /dev/null +++ b/include/byteswap.h @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2021 M. Warner Losh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +/* + * A mostly Linux/glibc-compatible byteswap.h + */ + +#ifndef _BYTESWAP_H_ +#define _BYTESWAP_H_ + +/* + * sys/_endian.h brings in the shared interfaces between BSD's sys/endian.h, and + * glibc's endian.h. However, we need to include it here to get the + * __bswap{16,32,64} definitions that we use. sys/_endian.h has been consturcted to + * be compatible with including , or both in either order, + * as well as providing the BSD the bulk of sys/endian.h functionality. + */ +#include + +/* + * glibc's defines the bswap_* and __bswap_* macros below. Most + * software uses either just , or both and + * . However, one can't define bswap16, etc in because + * several software packages will define them only when they detect + * is included (but not when sys/endian.h is included). Defining bswap16, etc + * here causes compilation errors for those packages. and + * need to be paired together, with the below defines here, for + * the highest level of glibc compatibility. + */ +#define __bswap_16(x) __bswap16(x) +#define __bswap_32(x) __bswap32(x) +#define __bswap_64(x) __bswap64(x) + +#define bswap_16(x) __bswap16(x) +#define bswap_32(x) __bswap32(x) +#define bswap_64(x) __bswap64(x) + +#endif /* _BYTESWAP_H_ */ diff --git a/sys/sys/_endian.h b/sys/sys/_endian.h index 72e1a40a8deb..ff909f532663 100644 --- a/sys/sys/_endian.h +++ b/sys/sys/_endian.h @@ -32,7 +32,7 @@ #ifndef _SYS__ENDIAN_H_ #define _SYS__ENDIAN_H_ -#if !defined(_MACHINE_ENDIAN_H_) && !defined(_ENDIAN_H_) +#if !defined(_MACHINE_ENDIAN_H_) && !defined(_BYTESWAP_H_) && !defined(_ENDIAN_H_) #error "sys/_endian.h should not be included directly" #endif