FreeBSD Bugzilla – Attachment 228141 Details for
Bug 258544
[exp-run] add endian.h
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Version 2 of endian patches
endian-exprun-v2.diff (text/plain), 6.75 KB, created by
Warner Losh
on 2021-09-23 22:23:14 UTC
(
hide
)
Description:
Version 2 of endian patches
Filename:
MIME Type:
Creator:
Warner Losh
Created:
2021-09-23 22:23:14 UTC
Size:
6.75 KB
patch
obsolete
>diff --git a/include/Makefile b/include/Makefile >index f5c0fc598b0c..678d539f266a 100644 >--- a/include/Makefile >+++ b/include/Makefile >@@ -9,10 +9,11 @@ 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 err.h fmtmsg.h fnmatch.h fstab.h \ >- fts.h ftw.h getopt.h glob.h grp.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 \ > ieeefp.h ifaddrs.h \ > inttypes.h iso646.h kenv.h langinfo.h libgen.h limits.h link.h \ > locale.h malloc.h malloc_np.h memory.h monetary.h mpool.h mqueue.h \ >diff --git a/include/byteswap.h b/include/byteswap.h >new file mode 100644 >index 000000000000..0cacfe716ccc >--- /dev/null >+++ b/include/byteswap.h >@@ -0,0 +1,31 @@ >+/*- >+ * Copyright (c) 2021 M. Warner Losh <imp@FreeBSD.org> >+ * >+ * SPDX-License-Identifier: BSD-2-Clause >+ */ >+ >+/* >+ * A mostly Linux/glibc-compatible byteswap.h >+ */ >+ >+#ifndef _BYTESWAP_H_ >+#define _BYTESWAP_H_ >+ >+#include <sys/_endian.h> >+ >+/* >+ * byteswap.h defines the macros below. Much software are uses either >+ * sys/endian.h or endian.h and byteswap.h. One can't define bswap16 etc in >+ * endian.h because some software defines them only when they detect endian.h is >+ * used (but not when sys/endian.h is used). So for endian.h to work properly, >+ * we have to pair it with this file, with these defines. >+ */ >+#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/include/endian.h b/include/endian.h >new file mode 100644 >index 000000000000..c7b78217cedd >--- /dev/null >+++ b/include/endian.h >@@ -0,0 +1,43 @@ >+/*- >+ * Copyright (c) 2021 M. Warner Losh <imp@FreeBSD.org> >+ * >+ * SPDX-License-Identifier: BSD-2-Clause >+ */ >+ >+/* >+ * A mostly Linux/glibc-compatible endian.h >+ */ >+ >+#ifndef _ENDIAN_H_ >+#define _ENDIAN_H_ >+ >+/* >+ * FreeBSD's sys/_endian.h is very close to the interface provided on Linux by >+ * glibc's endian.h. >+ */ >+#include <sys/_endian.h> >+ >+/* >+ * glibc uses double underscore for these symbols. Define these unconditionally. >+ * The compiler defines __BYTE_ORDER__ these days, so we don't do anything >+ * with that since sys/endian.h defines _BYTE_ORDER based on it. >+ */ >+#define __BIG_ENDIAN _BIG_ENDIAN >+#define __BYTE_ORDER _BYTE_ORDER >+#define __LITTLE_ENDIAN _LITTLE_ENDIAN >+#define __PDP_ENDIAN _PDP_ENDIAN >+ >+/* >+ * FreeBSD's sys/endian.h and machine/endian.h doesn't define a separate >+ * byte order for floats. Use the host non-float byte order. >+ */ >+#define __FLOAT_WORD_ORDER _BYTE_ORDER >+ >+/* >+ * We don't define BIG_ENDI, LITTLE_ENDI, HIGH_HALF and LOW_HALF macros that >+ * glibc's endian.h defines since those appear to be internal to internal to >+ * glibc. We also don't try to emulate the various helper macros that glibc >+ * uses to limit namespace visibility. >+ */ >+ >+#endif /* _ENDIAN_H_ */ >diff --git a/sys/sys/_endian.h b/sys/sys/_endian.h >index 936962cc729f..ff909f532663 100644 >--- a/sys/sys/_endian.h >+++ b/sys/sys/_endian.h >@@ -32,7 +32,7 @@ > #ifndef _SYS__ENDIAN_H_ > #define _SYS__ENDIAN_H_ > >-#ifndef _MACHINE_ENDIAN_H_ >+#if !defined(_MACHINE_ENDIAN_H_) && !defined(_BYTESWAP_H_) && !defined(_ENDIAN_H_) > #error "sys/_endian.h should not be included directly" > #endif > >@@ -89,4 +89,38 @@ > #define __ntohs(x) ((__uint16_t)(x)) > #endif > >+/* >+ * Host to big endian, host to little endian, big endian to host, and little >+ * endian to host byte order functions as detailed in byteorder(9). >+ */ >+#if _BYTE_ORDER == _LITTLE_ENDIAN >+#define htobe16(x) __bswap16((x)) >+#define htobe32(x) __bswap32((x)) >+#define htobe64(x) __bswap64((x)) >+#define htole16(x) ((uint16_t)(x)) >+#define htole32(x) ((uint32_t)(x)) >+#define htole64(x) ((uint64_t)(x)) >+ >+#define be16toh(x) __bswap16((x)) >+#define be32toh(x) __bswap32((x)) >+#define be64toh(x) __bswap64((x)) >+#define le16toh(x) ((uint16_t)(x)) >+#define le32toh(x) ((uint32_t)(x)) >+#define le64toh(x) ((uint64_t)(x)) >+#else /* _BYTE_ORDER != _LITTLE_ENDIAN */ >+#define htobe16(x) ((uint16_t)(x)) >+#define htobe32(x) ((uint32_t)(x)) >+#define htobe64(x) ((uint64_t)(x)) >+#define htole16(x) __bswap16((x)) >+#define htole32(x) __bswap32((x)) >+#define htole64(x) __bswap64((x)) >+ >+#define be16toh(x) ((uint16_t)(x)) >+#define be32toh(x) ((uint32_t)(x)) >+#define be64toh(x) ((uint64_t)(x)) >+#define le16toh(x) __bswap16((x)) >+#define le32toh(x) __bswap32((x)) >+#define le64toh(x) __bswap64((x)) >+#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */ >+ > #endif /* _SYS__ENDIAN_H_ */ >diff --git a/sys/sys/endian.h b/sys/sys/endian.h >index faac0458ae2c..d91c442e9238 100644 >--- a/sys/sys/endian.h >+++ b/sys/sys/endian.h >@@ -55,6 +55,12 @@ typedef __uint64_t uint64_t; > #define _UINT64_T_DECLARED > #endif > >+/* >+ * Note: While tempting to try to avoid namespace pollution from this file, >+ * several software packages assume these marcos are defined, even when it >+ * defines _POSIX_C_SOURCE to request an unpolluted namespace. >+ */ >+ > /* > * General byte order swapping functions. > */ >@@ -62,42 +68,7 @@ typedef __uint64_t uint64_t; > #define bswap32(x) __bswap32(x) > #define bswap64(x) __bswap64(x) > >-/* >- * Host to big endian, host to little endian, big endian to host, and little >- * endian to host byte order functions as detailed in byteorder(9). >- */ >-#if _BYTE_ORDER == _LITTLE_ENDIAN >-#define htobe16(x) __bswap16((x)) >-#define htobe32(x) __bswap32((x)) >-#define htobe64(x) __bswap64((x)) >-#define htole16(x) ((uint16_t)(x)) >-#define htole32(x) ((uint32_t)(x)) >-#define htole64(x) ((uint64_t)(x)) >- >-#define be16toh(x) __bswap16((x)) >-#define be32toh(x) __bswap32((x)) >-#define be64toh(x) __bswap64((x)) >-#define le16toh(x) ((uint16_t)(x)) >-#define le32toh(x) ((uint32_t)(x)) >-#define le64toh(x) ((uint64_t)(x)) >-#else /* _BYTE_ORDER != _LITTLE_ENDIAN */ >-#define htobe16(x) ((uint16_t)(x)) >-#define htobe32(x) ((uint32_t)(x)) >-#define htobe64(x) ((uint64_t)(x)) >-#define htole16(x) __bswap16((x)) >-#define htole32(x) __bswap32((x)) >-#define htole64(x) __bswap64((x)) >- >-#define be16toh(x) ((uint16_t)(x)) >-#define be32toh(x) ((uint32_t)(x)) >-#define be64toh(x) ((uint64_t)(x)) >-#define le16toh(x) __bswap16((x)) >-#define le32toh(x) __bswap32((x)) >-#define le64toh(x) __bswap64((x)) >-#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */ >- > /* Alignment-agnostic encode/decode bytestream to/from little/big endian. */ >- > static __inline uint16_t > be16dec(const void *pp) > { >@@ -203,5 +174,4 @@ le64enc(void *pp, uint64_t u) > le32enc(p, (uint32_t)(u & 0xffffffffU)); > le32enc(p + 4, (uint32_t)(u >> 32)); > } >- > #endif /* _SYS_ENDIAN_H_ */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 258544
:
227946
| 228141