From nobody Tue Jan 24 23:28:26 2023 X-Original-To: dev-commits-src-branches@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 4P1jp30mVHz30yy7; Tue, 24 Jan 2023 23:28:27 +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 4P1jp274fwz3j9H; Tue, 24 Jan 2023 23:28:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674602907; 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=aDYvHx21SS9P/aXDObRGNv6ujxYYZl7JnPQU3+7XmQI=; b=wIvZzNdh7C6aMuUwNrQjppa0bLeb9Fl4DuHffizibaiHT1UfO5qJ2gC44RsStNbFJxjPYU qvi76daZKVJ1hb1jLMaPBHnzuVRjOxP5EQJPO1N/moz2DBOJXWB6GePKLIA5goY8RW6KTl SIOU+jPB4YyT7SXOw1sorVxJ19XZmDAO2O86g7x6CLZXrjlE1Z7aXkIapOVW7fKPkvv1oC bCmL4U8wkz4TokkK34FGh8HaoVD/+kt7lqB5vL8uMnEB7TgyQs9d7F/8rgHNSekvTSQQD1 41yJWNUcnwn9QbAuYdyXf1aueoHbyAYlA0/tyXxio8C0wKeEg/kU9FYK7a/0rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674602907; 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=aDYvHx21SS9P/aXDObRGNv6ujxYYZl7JnPQU3+7XmQI=; b=PM9QRvkyMCxDB4u0evYuVmQs5SwJamRNy4YQLI8qaIV0S/JgxEPSKVAoo41kvSXD+bbVzv FzTR5mleoWAU2covfbzYyhCwK1VfdN3ASsRqCM/gyXk27ExVxZidWrFE/N4C5lnG2ibPxA 463rpwbHf5NIKPnxbxc7Fy+8KrZp0Z5QCZVqK07/dzt9B0+5O5/QaPwxtmJ5aLxwdhkA2h VIq2C3rls1p0EsNMBBNG/ti89IBCHIL9UtWnMW2+eOplv9Fw5cP6pvLCSSo0ikK8VmeqFu SO7vX7aV3TS801Tst3vB+BLVkltHqE4tnTYtpbzTx+xmWJ94qCgRGUP7Q2a95A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674602907; a=rsa-sha256; cv=none; b=EP5B1o0KIoyUZxBMUxJV9EFPyQ2g6IIIvp87r0CZG4uT2LTlLryb6asK/SjfIicLS28l7V 7GD4J5qa9fcfInlhvu5MYQ5Jp7tF9l71hc2Onbpw6LfGrgRkhtANPOdRmXdBYf80ZQSJfb tEuGY6fbU7f9xgkCSU7ZcokbUMZbXQMiCX7ayN5cZSQJQf5AKA0JQgUk0akCHUrNO2aghG YJUoip0ZEtPUT6MaELrFn4j+LTm/h/jr9mPldpu/fF+tgOY6lTqvO/+eBemFDZgQW7Ofcd j8ZCAul7L/5tja3jtpfJxjSm2dILhcnSNqe0V15VXdCAOS+Q5pOqB/uOXE1kUQ== 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 4P1jp264wqzSDw; Tue, 24 Jan 2023 23:28:26 +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 30ONSQ22092259; Tue, 24 Jan 2023 23:28:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30ONSQhR092257; Tue, 24 Jan 2023 23:28:26 GMT (envelope-from git) Date: Tue, 24 Jan 2023 23:28:26 GMT Message-Id: <202301242328.30ONSQhR092257@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 1dd126163b94 - stable/13 - byteswap.h: Add a glibc/linux compatible byteswap.h List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 1dd126163b9448c2dcfe27978fee50649548437c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=1dd126163b9448c2dcfe27978fee50649548437c commit 1dd126163b9448c2dcfe27978fee50649548437c Author: Warner Losh AuthorDate: 2023-01-20 23:33:37 +0000 Commit: Warner Losh CommitDate: 2023-01-24 23:26:28 +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 (cherry picked from commit 1761b09bf42d2842e82c1ac614c23d31c4d4c0dc) --- 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 b7aa723a562f..490b430d94c6 100644 --- a/include/Makefile +++ b/include/Makefile @@ -9,7 +9,8 @@ PACKAGE=runtime CLEANFILES= osreldate.h version SUBDIR= arpa protocols rpcsvc rpc xlocale 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