diff options
Diffstat (limited to 'usr/src')
28 files changed, 1506 insertions, 3 deletions
diff --git a/usr/src/head/Makefile b/usr/src/head/Makefile index 7b83f1ee75..030a9d51f8 100644 --- a/usr/src/head/Makefile +++ b/usr/src/head/Makefile @@ -66,6 +66,7 @@ HDRS= $($(MACH)_HDRS) $(ATTRDB_HDRS) \ dlfcn.h \ door.h \ elf.h \ + endian.h \ err.h \ errno.h \ euc.h \ diff --git a/usr/src/head/endian.h b/usr/src/head/endian.h new file mode 100644 index 0000000000..a5117bbacd --- /dev/null +++ b/usr/src/head/endian.h @@ -0,0 +1,70 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2016 Joyent, Inc. + */ + +#ifndef _ENDIAN_H +#define _ENDIAN_H + +/* + * Endian conversion routines, see endian(3C) + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <sys/isa_defs.h> +#include <inttypes.h> + +#define LITTLE_ENDIAN 1234 +#define BIG_ENDIAN 4321 +#define PDP_ENDIAN 3412 + +#ifdef _LITTLE_ENDIAN +#define BYTE_ORDER LITTLE_ENDIAN +#elif _BIG_ENDIAN +#define BYTE_ORDER BIG_ENDIAN +#else +#error "Unknown byte order" +#endif /* _LITTLE_ENDIAN */ + +extern uint16_t htobe16(uint16_t); +extern uint32_t htobe32(uint32_t); +extern uint64_t htobe64(uint64_t); + +extern uint16_t htole16(uint16_t); +extern uint32_t htole32(uint32_t); +extern uint64_t htole64(uint64_t); + +/* Supply both the old and new BSD names */ +extern uint16_t betoh16(uint16_t); +extern uint16_t letoh16(uint16_t); +extern uint16_t be16toh(uint16_t); +extern uint16_t le16toh(uint16_t); + +extern uint32_t betoh32(uint32_t); +extern uint32_t letoh32(uint32_t); +extern uint32_t be32toh(uint32_t); +extern uint32_t le32toh(uint32_t); + +extern uint64_t betoh64(uint64_t); +extern uint64_t letoh64(uint64_t); +extern uint64_t be64toh(uint64_t); +extern uint64_t le64toh(uint64_t); + +#ifdef __cplusplus +} +#endif + +#endif /* _ENDIAN_H */ diff --git a/usr/src/lib/libc/amd64/Makefile b/usr/src/lib/libc/amd64/Makefile index 0a55bf964f..4580972482 100644 --- a/usr/src/lib/libc/amd64/Makefile +++ b/usr/src/lib/libc/amd64/Makefile @@ -115,6 +115,7 @@ GENOBJS= \ byteorder.o \ cuexit.o \ ecvt.o \ + endian.o \ errlst.o \ amd64_data.o \ ldivide.o \ diff --git a/usr/src/lib/libc/amd64/gen/byteorder.s b/usr/src/lib/libc/amd64/gen/byteorder.s index 5a192f0a68..12ea90f649 100644 --- a/usr/src/lib/libc/amd64/gen/byteorder.s +++ b/usr/src/lib/libc/amd64/gen/byteorder.s @@ -21,6 +21,7 @@ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright (c) 2015, Joyent, Inc. */ .file "byteorder.s" @@ -90,3 +91,89 @@ shrl $16, %eax /* moves high 16-bit to low 16-bit */ ret /* return (%eax) */ SET_SIZE(ntohs) + +/* + * uint16_t htobe16(uint16_t in); + * uint32_t htobe32(uint32_t in); + * uint64_t htobe64(uint64_t in); + * + * Byte swap 16, 32, and 64 bits respectively. + * eg. htons(), htonl(), and htonll(). + */ + ENTRY(htobe16) + movl %edi, %eax /* %eax = hs */ + bswap %eax /* reverses the byte order of %eax */ + shrl $16, %eax /* moves high 16-bit to low 16-bit */ + ret /* return (%eax) */ + SET_SIZE(htobe16) + + ENTRY(htobe32) + movl %edi, %eax /* %eax = hl */ + bswap %eax /* reverses the byte order of %eax */ + ret /* return (%eax) */ + SET_SIZE(htobe32) + + ENTRY(htobe64) + movq %rdi, %rax /* %rax = hll */ + bswapq %rax /* reverses the byte order of %rax */ + ret /* return (%rax) */ + SET_SIZE(htobe64) + + +/* + * uint16_t betoh16(uint16_t in) + * uint16_t be16toh(uint16_t in) + * + * Convert in to little endian, eg. ntohs() + */ + ENTRY(betoh16) + movl %edi, %eax /* %eax = hs */ + bswap %eax /* reverses the byte order of %eax */ + shrl $16, %eax /* moves high 16-bit to low 16-bit */ + ret /* return (%eax) */ + SET_SIZE(betoh16) + + ENTRY(be16toh) + movl %edi, %eax /* %eax = hs */ + bswap %eax /* reverses the byte order of %eax */ + shrl $16, %eax /* moves high 16-bit to low 16-bit */ + ret /* return (%eax) */ + SET_SIZE(be16toh) + + +/* + * uint32_t betoh32(uint32_t in) + * uint32_t be32toh(uint32_t in) + * + * Convert in to little endian, eg. ntohl() + */ + ENTRY(betoh32) + movl %edi, %eax /* %eax = hl */ + bswap %eax /* reverses the byte order of %eax */ + ret /* return (%eax) */ + SET_SIZE(betoh32) + + ENTRY(be32toh) + movl %edi, %eax /* %eax = hl */ + bswap %eax /* reverses the byte order of %eax */ + ret /* return (%eax) */ + SET_SIZE(be32toh) + + +/* + * uint64_t betoh64(uint64_t in) + * uint64_t be64toh(uint64_t in) + * + * Convert in to little endian, eg. ntohll() + */ + ENTRY(betoh64) + movq %rdi, %rax /* %rax = hll */ + bswapq %rax /* reverses the byte order of %rax */ + ret /* return (%rax) */ + SET_SIZE(betoh64) + + ENTRY(be64toh) + movq %rdi, %rax /* %rax = hll */ + bswapq %rax /* reverses the byte order of %rax */ + ret /* return (%rax) */ + SET_SIZE(be64toh) diff --git a/usr/src/lib/libc/amd64/gen/endian.c b/usr/src/lib/libc/amd64/gen/endian.c new file mode 100644 index 0000000000..b04a2d0b5b --- /dev/null +++ b/usr/src/lib/libc/amd64/gen/endian.c @@ -0,0 +1,74 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2015, Joyent, Inc. + */ + +/* + * General, no-op functions for endian(3C). The rest are in byteorder.s. + */ + +#include <endian.h> + +uint16_t +htole16(uint16_t in) +{ + return (in); +} + +uint32_t +htole32(uint32_t in) +{ + return (in); +} + +uint64_t +htole64(uint64_t in) +{ + return (in); +} + +uint16_t +letoh16(uint16_t in) +{ + return (in); +} + +uint16_t +le16toh(uint16_t in) +{ + return (in); +} + +uint32_t +letoh32(uint32_t in) +{ + return (in); +} + +uint32_t +le32toh(uint32_t in) +{ + return (in); +} + +uint64_t +letoh64(uint64_t in) +{ + return (in); +} + +uint64_t +le64toh(uint64_t in) +{ + return (in); +} diff --git a/usr/src/lib/libc/i386/Makefile.com b/usr/src/lib/libc/i386/Makefile.com index 21adf0d5a1..c73b03879f 100644 --- a/usr/src/lib/libc/i386/Makefile.com +++ b/usr/src/lib/libc/i386/Makefile.com @@ -122,6 +122,7 @@ GENOBJS= \ byteorder64.o \ cuexit.o \ ecvt.o \ + endian.o \ errlst.o \ i386_data.o \ ladd.o \ diff --git a/usr/src/lib/libc/i386/gen/byteorder.s b/usr/src/lib/libc/i386/gen/byteorder.s index 9689b2b6bf..2b1204d1ba 100644 --- a/usr/src/lib/libc/i386/gen/byteorder.s +++ b/usr/src/lib/libc/i386/gen/byteorder.s @@ -21,6 +21,7 @@ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright (c) 2015, Joyent, Inc. */ .file "byteorder.s" @@ -32,7 +33,9 @@ * As such, they could be implemented as a single routine, using * multiple ALTENTRY/SET_SIZE definitions. We don't do this so * that they will have unique addresses, allowing DTrace and - * other debuggers to tell them apart. + * other debuggers to tell them apart. With the endian + * functions we do the same, even though it's similarly + * repetitive. */ / unsigned long htonl( hl ) @@ -70,3 +73,61 @@ shrl $16, %eax / moves high 16-bit to low 16-bit ret / return (%eax) SET_SIZE(ntohs) + +/ uint16_t htobe16(uint16_t in) +/ +/ Convert in to big endian, eg. htons() +/ + ENTRY(htobe16) + movl 4(%esp), %eax / %eax = hs + bswap %eax / reverses the byte order of %eax + shrl $16, %eax / moves high 16-bit to low 16-bit + ret / return (%eax) + SET_SIZE(htobe16) + +/ uint32_t htobe32(uint32_t in) +/ +/ Convert in to big endian, eg. htonl() +/ + ENTRY(htobe32) + movl 4(%esp), %eax / %eax = hl + bswap %eax / reverses the byte order of %eax + ret / return (%eax) + SET_SIZE(htobe32) + +/ uint16_t betoh16(uint16_t in) +/ uint16_t be16toh(uint16_t in) +/ +/ Convert in to little endian, eg. ntohs() +/ + ENTRY(betoh16) + movl 4(%esp), %eax / %eax = hs + bswap %eax / reverses the byte order of %eax + shrl $16, %eax / moves high 16-bit to low 16-bit + ret / return (%eax) + SET_SIZE(betoh16) + + ENTRY(be16toh) + movl 4(%esp), %eax / %eax = hs + bswap %eax / reverses the byte order of %eax + shrl $16, %eax / moves high 16-bit to low 16-bit + ret / return (%eax) + SET_SIZE(be16toh) + + +/ uint32_t be32toh(uint32_t in) +/ uint32_t betoh32(uint32_t in) +/ +/ Convert in to little endian, eg. ntohl() +/ + ENTRY(be32toh) + movl 4(%esp), %eax / %eax = hl + bswap %eax / reverses the byte order of %eax + ret / return (%eax) + SET_SIZE(be32toh) + + ENTRY(betoh32) + movl 4(%esp), %eax / %eax = hl + bswap %eax / reverses the byte order of %eax + ret / return (%eax) + SET_SIZE(betoh32) diff --git a/usr/src/lib/libc/i386/gen/byteorder64.c b/usr/src/lib/libc/i386/gen/byteorder64.c index 3806a62f34..00c37d2a1b 100644 --- a/usr/src/lib/libc/i386/gen/byteorder64.c +++ b/usr/src/lib/libc/i386/gen/byteorder64.c @@ -22,6 +22,7 @@ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright (c) 2015, Joyent, Inc. */ #include <sys/isa_defs.h> @@ -47,4 +48,40 @@ ntohll(uint64_t in) return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32); } +uint64_t +htobe64(uint64_t in) +{ + return (htonl(in >> 32) | ((uint64_t)htonl(in) << 32)); +} + +uint64_t +htole64(uint64_t in) +{ + return (in); +} + +uint64_t +betoh64(uint64_t in) +{ + return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32); +} + +uint64_t +letoh64(uint64_t in) +{ + return (in); +} + +uint64_t +be64toh(uint64_t in) +{ + return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32); +} + +uint64_t +le64toh(uint64_t in) +{ + return (in); +} + #endif /* (_BIG_ENDIAN) || _LP64) && !__lint */ diff --git a/usr/src/lib/libc/i386/gen/endian.c b/usr/src/lib/libc/i386/gen/endian.c new file mode 100644 index 0000000000..580c965406 --- /dev/null +++ b/usr/src/lib/libc/i386/gen/endian.c @@ -0,0 +1,57 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2015, Joyent, Inc. + */ + +#include <sys/isa_defs.h> +#include <endian.h> + +/* + * General endian(3C) functions that are basically no-ops. + */ + +uint16_t +letoh16(uint16_t in) +{ + return (in); +} + +uint16_t +le16toh(uint16_t in) +{ + return (in); +} + +uint32_t +letoh32(uint32_t in) +{ + return (in); +} + +uint32_t +le32toh(uint32_t in) +{ + return (in); +} + +uint16_t +htole16(uint16_t in) +{ + return (in); +} + +uint32_t +htole32(uint32_t in) +{ + return (in); +} diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers index 78e2707b49..afb07a4bb9 100644 --- a/usr/src/lib/libc/port/mapfile-vers +++ b/usr/src/lib/libc/port/mapfile-vers @@ -93,6 +93,28 @@ $if _x86 && _ELF64 $add amd64 $endif +SYMBOL_VERSION ILLUMOS_0.22 { # endian(3C) + protected: + htobe16; + htobe32; + htobe64; + htole16; + htole32; + htole64; + betoh16; + letoh16; + be16toh; + le16toh; + betoh32; + letoh32; + be32toh; + le32toh; + betoh64; + letoh64; + be64toh; + le64toh; +} ILLUMOS_0.21; + SYMBOL_VERSION ILLUMOS_0.21 { protected: pthread_attr_get_np; diff --git a/usr/src/lib/libc/sparc/Makefile.com b/usr/src/lib/libc/sparc/Makefile.com index 5302bb8ebd..062949b3f9 100644 --- a/usr/src/lib/libc/sparc/Makefile.com +++ b/usr/src/lib/libc/sparc/Makefile.com @@ -147,6 +147,7 @@ GENOBJS= \ byteorder.o \ cuexit.o \ ecvt.o \ + endian.o \ errlst.o \ getctxt.o \ ladd.o \ @@ -1189,6 +1190,7 @@ SRCS= \ $(LIBCBASE)/gen/_xregs_clrptr.c \ $(LIBCBASE)/gen/byteorder.c \ $(LIBCBASE)/gen/ecvt.c \ + $(LIBCBASE)/gen/endian.c \ $(LIBCBASE)/gen/getctxt.c \ $(LIBCBASE)/gen/lmul.c \ $(LIBCBASE)/gen/makectxt.c \ diff --git a/usr/src/lib/libc/sparc/gen/endian.c b/usr/src/lib/libc/sparc/gen/endian.c new file mode 100644 index 0000000000..b19974b86a --- /dev/null +++ b/usr/src/lib/libc/sparc/gen/endian.c @@ -0,0 +1,158 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2015, Joyent, Inc. + */ + +/* + * endian(3C) routines + */ + +uint16_t +htole16(uint16_t in) +{ + return (((in & 0xff) << 8) | ((in & 0xff00) >> 8)); +} + +uint32_t +htole32(uint32_t in) +{ + return (((in & 0xffUL) << 24) | + (in & 0xff00UL) << 8 | + (in & 0xff0000UL) >> 8 | + ((in & 0xff000000UL) >> 24)); +} + +uint64_t +htole64(uint64_t in) +{ + return (((in & 0xffULL) << 56) | + ((in & 0xff00ULL) << 40) | + ((in & 0xff0000ULL) << 24) | + ((in & 0xff000000ULL) << 8) | + ((in & 0xff00000000ULL) >> 8) | + ((in & 0xff0000000000ULL) >> 24) | + ((in & 0xff000000000000ULL) >> 40) | + ((in & 0xff00000000000000ULL) >> 56)); +} + +uint16_t +letoh16(uint16_t in) +{ + return (((in & 0xff) << 8) | ((in & 0xff00) >> 8)); +} + +uint16_t +le16toh(uint16_t in) +{ + return (((in & 0xff) << 8) | ((in & 0xff00) >> 8)); +} + +uint32_t +letoh32(uint32_t in) +{ + return (((in & 0xffUL) << 24) | + (in & 0xff00UL) << 8 | + (in & 0xff0000UL) >> 8 | + ((in & 0xff000000UL) >> 24)); +} + +uint32_t +le32toh(uint32_t in) +{ + return (((in & 0xffUL) << 24) | + (in & 0xff00UL) << 8 | + (in & 0xff0000UL) >> 8 | + ((in & 0xff000000UL) >> 24)); +} + +uint64_t +letoh64(uint64_t in) +{ + return (((in & 0xffULL) << 56) | + ((in & 0xff00ULL) << 40) | + ((in & 0xff0000ULL) << 24) | + ((in & 0xff000000ULL) << 8) | + ((in & 0xff00000000ULL) >> 8) | + ((in & 0xff0000000000ULL) >> 24) | + ((in & 0xff000000000000ULL) >> 40) | + ((in & 0xff00000000000000ULL) >> 56)); +} + +uint64_t +le64toh(uint64_t in) +{ + return (((in & 0xffULL) << 56) | + ((in & 0xff00ULL) << 40) | + ((in & 0xff0000ULL) << 24) | + ((in & 0xff000000ULL) << 8) | + ((in & 0xff00000000ULL) >> 8) | + ((in & 0xff0000000000ULL) >> 24) | + ((in & 0xff000000000000ULL) >> 40) | + ((in & 0xff00000000000000ULL) >> 56)); +} + +/* Anything to or from big-endian is a no-op */ + +uint16_t +htobe16(uint16_t in) +{ + return (in); +} + +uint32_t +htobe32(uint32_t in) +{ + return (in); +} + +uint64_t +htobe64(uint64_t in) +{ + return (in); +} + +uint16_t +betoh16(uint16_t in) +{ + return (in); +} + +uint16_t +be16toh(uint16_t in) +{ + return (in); +} + +uint32_t +betoh32(uint32_t in) +{ + return (in); +} + +uint32_t +be32toh(uint32_t in) +{ + return (in); +} + +uint64_t +betoh64(uint64_t in) +{ + return (in); +} + +uint64_t +be64toh(uint64_t in) +{ + return (in); +} diff --git a/usr/src/lib/libc/sparcv9/Makefile.com b/usr/src/lib/libc/sparcv9/Makefile.com index d323044aff..596d349dfb 100644 --- a/usr/src/lib/libc/sparcv9/Makefile.com +++ b/usr/src/lib/libc/sparcv9/Makefile.com @@ -147,6 +147,7 @@ GENOBJS= \ byteorder.o \ cuexit.o \ ecvt.o \ + endian.o \ getctxt.o \ lock.o \ makectxt.o \ @@ -1118,6 +1119,7 @@ SRCS= \ $(LIBCBASE)/crt/_ftou.c \ $(LIBCBASE)/gen/_xregs_clrptr.c \ $(LIBCBASE)/gen/byteorder.c \ + $(LIBCBASE)/gen/endian.c \ $(LIBCBASE)/gen/ecvt.c \ $(LIBCBASE)/gen/getctxt.c \ $(LIBCBASE)/gen/makectxt.c \ diff --git a/usr/src/lib/libc/sparcv9/gen/endian.c b/usr/src/lib/libc/sparcv9/gen/endian.c new file mode 100644 index 0000000000..b19974b86a --- /dev/null +++ b/usr/src/lib/libc/sparcv9/gen/endian.c @@ -0,0 +1,158 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2015, Joyent, Inc. + */ + +/* + * endian(3C) routines + */ + +uint16_t +htole16(uint16_t in) +{ + return (((in & 0xff) << 8) | ((in & 0xff00) >> 8)); +} + +uint32_t +htole32(uint32_t in) +{ + return (((in & 0xffUL) << 24) | + (in & 0xff00UL) << 8 | + (in & 0xff0000UL) >> 8 | + ((in & 0xff000000UL) >> 24)); +} + +uint64_t +htole64(uint64_t in) +{ + return (((in & 0xffULL) << 56) | + ((in & 0xff00ULL) << 40) | + ((in & 0xff0000ULL) << 24) | + ((in & 0xff000000ULL) << 8) | + ((in & 0xff00000000ULL) >> 8) | + ((in & 0xff0000000000ULL) >> 24) | + ((in & 0xff000000000000ULL) >> 40) | + ((in & 0xff00000000000000ULL) >> 56)); +} + +uint16_t +letoh16(uint16_t in) +{ + return (((in & 0xff) << 8) | ((in & 0xff00) >> 8)); +} + +uint16_t +le16toh(uint16_t in) +{ + return (((in & 0xff) << 8) | ((in & 0xff00) >> 8)); +} + +uint32_t +letoh32(uint32_t in) +{ + return (((in & 0xffUL) << 24) | + (in & 0xff00UL) << 8 | + (in & 0xff0000UL) >> 8 | + ((in & 0xff000000UL) >> 24)); +} + +uint32_t +le32toh(uint32_t in) +{ + return (((in & 0xffUL) << 24) | + (in & 0xff00UL) << 8 | + (in & 0xff0000UL) >> 8 | + ((in & 0xff000000UL) >> 24)); +} + +uint64_t +letoh64(uint64_t in) +{ + return (((in & 0xffULL) << 56) | + ((in & 0xff00ULL) << 40) | + ((in & 0xff0000ULL) << 24) | + ((in & 0xff000000ULL) << 8) | + ((in & 0xff00000000ULL) >> 8) | + ((in & 0xff0000000000ULL) >> 24) | + ((in & 0xff000000000000ULL) >> 40) | + ((in & 0xff00000000000000ULL) >> 56)); +} + +uint64_t +le64toh(uint64_t in) +{ + return (((in & 0xffULL) << 56) | + ((in & 0xff00ULL) << 40) | + ((in & 0xff0000ULL) << 24) | + ((in & 0xff000000ULL) << 8) | + ((in & 0xff00000000ULL) >> 8) | + ((in & 0xff0000000000ULL) >> 24) | + ((in & 0xff000000000000ULL) >> 40) | + ((in & 0xff00000000000000ULL) >> 56)); +} + +/* Anything to or from big-endian is a no-op */ + +uint16_t +htobe16(uint16_t in) +{ + return (in); +} + +uint32_t +htobe32(uint32_t in) +{ + return (in); +} + +uint64_t +htobe64(uint64_t in) +{ + return (in); +} + +uint16_t +betoh16(uint16_t in) +{ + return (in); +} + +uint16_t +be16toh(uint16_t in) +{ + return (in); +} + +uint32_t +betoh32(uint32_t in) +{ + return (in); +} + +uint32_t +be32toh(uint32_t in) +{ + return (in); +} + +uint64_t +betoh64(uint64_t in) +{ + return (in); +} + +uint64_t +be64toh(uint64_t in) +{ + return (in); +} diff --git a/usr/src/man/man3c/Makefile b/usr/src/man/man3c/Makefile index eebbda3288..61591de7e7 100644 --- a/usr/src/man/man3c/Makefile +++ b/usr/src/man/man3c/Makefile @@ -113,6 +113,7 @@ MANFILES= __fbufsize.3c \ enable_extended_FILE_stdio.3c \ encrypt.3c \ end.3c \ + endian.3c \ epoll_create.3c \ epoll_ctl.3c \ epoll_wait.3c \ @@ -698,6 +699,12 @@ MANLINKS= FD_CLR.3c \ backtrace_symbols_fd.3c \ bcmp.3c \ bcopy.3c \ + be16toh.3c \ + be32toh.3c \ + be64toh.3c \ + betoh16.3c \ + betoh32.3c \ + betoh64.3c \ bind_textdomain_codeset.3c \ bindtextdomain.3c \ btowc_l.3c \ @@ -861,6 +868,12 @@ MANLINKS= FD_CLR.3c \ hasmntopt.3c \ hcreate.3c \ hdestroy.3c \ + htobe16.3c \ + htobe32.3c \ + htobe64.3c \ + htole16.3c \ + htole32.3c \ + htole64.3c \ initstate.3c \ innetgr.3c \ isalnum.3c \ @@ -934,6 +947,12 @@ MANLINKS= FD_CLR.3c \ labs.3c \ lcong48.3c \ ldiv.3c \ + le16toh.3c \ + le32toh.3c \ + le64toh.3c \ + letoh16.3c \ + letoh32.3c \ + letoh64.3c \ lfind.3c \ llabs.3c \ lldiv.3c \ @@ -1635,6 +1654,25 @@ _etext.3c := LINKSRC = end.3c edata.3c := LINKSRC = end.3c etext.3c := LINKSRC = end.3c +be16toh.3c := LINKSRC = endian.3c +be32toh.3c := LINKSRC = endian.3c +be64toh.3c := LINKSRC = endian.3c +betoh16.3c := LINKSRC = endian.3c +betoh32.3c := LINKSRC = endian.3c +betoh64.3c := LINKSRC = endian.3c +htobe16.3c := LINKSRC = endian.3c +htobe32.3c := LINKSRC = endian.3c +htobe64.3c := LINKSRC = endian.3c +htole16.3c := LINKSRC = endian.3c +htole32.3c := LINKSRC = endian.3c +htole64.3c := LINKSRC = endian.3c +le16toh.3c := LINKSRC = endian.3c +le32toh.3c := LINKSRC = endian.3c +le64toh.3c := LINKSRC = endian.3c +letoh16.3c := LINKSRC = endian.3c +letoh32.3c := LINKSRC = endian.3c +letoh64.3c := LINKSRC = endian.3c + epoll_create1.3c := LINKSRC = epoll_create.3c epoll_pwait.3c := LINKSRC = epoll_wait.3c diff --git a/usr/src/man/man3c/endian.3c b/usr/src/man/man3c/endian.3c new file mode 100644 index 0000000000..5161af8fbd --- /dev/null +++ b/usr/src/man/man3c/endian.3c @@ -0,0 +1,191 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd January 30, 2016 +.Dt ENDIAN 3C +.Os +.Sh NAME +.Nm endian , +.Nm be16toh , +.Nm be32toh , +.Nm be64toh , +.Nm betoh16 , +.Nm betoh32 , +.Nm betoh64 , +.Nm htobe16 , +.Nm htobe32 , +.Nm htobe64 , +.Nm htole16 , +.Nm htole32 , +.Nm htole64 , +.Nm le16toh , +.Nm le32toh , +.Nm le64toh , +.Nm letoh16 , +.Nm letoh32 , +.Nm letoh64 +.Nd convert between big and little endian byte order +.Sh SYNOPSIS +.In endian.h +.Ft uint16_t +.Fo be16toh +.Fa "uint16_t be16" +.Fc +.Ft uint32_t +.Fo be32toh +.Fa "uint32_t be32" +.Fc +.Ft uint64_t +.Fo betoh64 +.Fa "uint64_t be64" +.Fc +.Ft uint16_t +.Fo betoh16 +.Fa "uint16_t be16" +.Fc +.Ft uint32_t +.Fo betoh32 +.Fa "uint32_t be32" +.Fc +.Ft uint64_t +.Fo be64toh +.Fa "uint64_t be64" +.Fc +.Ft uint16_t +.Fo htobe16 +.Fa "uint16_t host16" +.Fc +.Ft uint32_t +.Fo htobe32 +.Fa "uint32_t host32" +.Fc +.Ft uint64_t +.Fo htobe64 +.Fa "uint64_t host64" +.Fc +.Ft uint16_t +.Fo htole16 +.Fa "uint16_t host16" +.Fc +.Ft uint32_t +.Fo htole32 +.Fa "uint32_t host32" +.Fc +.Ft uint64_t +.Fo htole64 +.Fa "uint64_t host64" +.Fc +.Ft uint16_t +.Fo le16toh +.Fa "uint16_t le16" +.Fc +.Ft uint32_t +.Fo le32toh +.Fa "uint32_t le32" +.Fc +.Ft uint64_t +.Fo le64toh +.Fa "uint64_t le64" +.Fc +.Ft uint16_t +.Fo letoh16 +.Fa "uint16_t le16" +.Fc +.Ft uint32_t +.Fo letoh32 +.Fa "uint32_t le32" +.Fc +.Ft uint64_t +.Fo letoh64 +.Fa "uint64_t le64" +.Fc +.Sh DESCRIPTION +The +.Nm +family of functions convert 16, 32, and 64-bit values between the host's +native byte order and big- or little-endian. All of the functions in +this family simply return their input when the host's native byte order +is the same as the desired order. For more information on +endianness, see +.Xr byteorder 5 . +.Pp +The +.Fn betoh16 , +.Fn betoh32 , +and +.Fn betoh64 +functions take a 16-bit, 32-bit, or 64-bit value and convert it from +big-endian to the host's native endianness, swapping bytes as required. +.Pp +The +.Fn letoh16 , +.Fn letoh32 , +and +.Fn letoh64 +functions take a 16-bit, 32-bit, or 64-bit value and convert it from +little-endian to the host's native endianness, swapping bytes as +required. +.Pp +The +.Fn htobe16 , +.Fn htobe32 , +and +.Fn htobe64 +functions take a 16-bit, 32-bit, or 64-bit value and convert it from +the host's native endianness to big-endian, swapping bytes as required. +.Pp +The +.Fn htole16 , +.Fn htole32 , +and +.Fn htole64 +functions take a 16-bit, 32-bit, or 64-bit value and convert it from +the host's native endianness to little-endian, swapping bytes as +required. +.Pp +The functions +.Fn be16toh , +.Fn be32toh , +.Fn be64toh , +.Fn le16toh , +.Fn le32toh , +and +.Fn le64toh , +are the same as +.Fn betoh16 , +.Fn betoh32 , +.Fn betoh64 , +.Fn letoh16 , +.Fn letoh32 , +and +.Fn letoh64 +respectively. Historically, different platforms have diverged on the +naming of these functions. To better support extant software, both are +provided. +.Pp +While these functions are common across multiple platforms, they have +not been standardized. Portable applications should instead use the +functions defined in +.Xr byteorder 3C . +.Sh RETURN VALUES +The functions always succeed and return a value that has been properly +converted. +.Sh INTERFACE STABILITY +.Sy Committed +.Sh MT-LEVEL +.Sy MT-Safe +.Sh SEE ALSO +.Xr byteorder 3C , +.Xr endian.h 3HEAD , +.Xr attributes 5 , +.Xr byteorder 5 diff --git a/usr/src/man/man3head/Makefile b/usr/src/man/man3head/Makefile index e53332b152..0e1c2efb17 100644 --- a/usr/src/man/man3head/Makefile +++ b/usr/src/man/man3head/Makefile @@ -27,6 +27,7 @@ MANFILES= acct.h.3head \ complex.h.3head \ cpio.h.3head \ dirent.h.3head \ + endian.h.3head \ errno.h.3head \ fcntl.h.3head \ fenv.h.3head \ diff --git a/usr/src/man/man3head/endian.h.3head b/usr/src/man/man3head/endian.h.3head new file mode 100644 index 0000000000..0fe5931751 --- /dev/null +++ b/usr/src/man/man3head/endian.h.3head @@ -0,0 +1,88 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd January 30, 2016 +.Dt ENDIAN.H 3HEAD +.Os +.Sh NAME +.Nm endian.h +.Nd definitions for endian routines +.Sh SYNOPSIS +.In endian.h +.Sh DESCRIPTION +The +.In endian.h +header defines functions and macros focused on converting data between +the host machines native byte order and big or little-endian values. +While the manual page details the macros defined by +.In endian.h , +the functions are documented separately in +.Xr endian 3C. +More information on endianness and a general background on the topic can +be found in +.Xr byteorder 5 . +.Pp +The +.In endian.h +header defines the following macros: +.Bl -tag -width Ds +.It Sy LITTLE_ENDIAN +A constant used to indicate a little-endian integer. It is always +defined, regardless of the actual endianess of the underlying platform. +This macro should be used to compare against the +.Sy BYTE_ORDER +macro. +.It Sy BIG_ENDIAN +A constant used to indicate a big-endian integer. It is always defined, +regardless of the actual endianess of the underlying platform. This +macro should be used to compare against the +.Sy BYTE_ORDER +macro. +.It Sy PDP_ENDIAN +A constant used to indicate the endianness used for four byte values on +the PDP-11. It is always defined, regardless of the actual endianess of +the underlying platform. This macro should be used to compare against +the +.Sy BYTE_ORDER +macro. +.It Sy BYTE_ORDER +The value of the +.Sy BYTE_ORDER +macro will be one of +.Sy LITTLE_ENDIAN +or +.Sy BIG_ENDIAN . +At this time, no supported architectures use the byte order indicated by +the +.Sy PDP_ENDIAN +macro. +.Pp +To determine the byte order of a system, one may compare the +.Sy BYTE_ORDER +to one of the aforementioned macros. +.El +.Pp +In addition to the routines provided by this header, standardized +functions may be found in +.Xr byteorder 3C . +The header +.Xr types.h 3HEAD +also defines additional pre-processor symbols to determine the current +endianness of the system. +.Sh INTERFACE STABILITY +.Sy Committed +.Sh SEE ALSO +.Xr endian 3C , +.Xr types.h 3HEAD , +.Xr attributes 5 , +.Xr byteorder 5 diff --git a/usr/src/man/man3socket/byteorder.3socket b/usr/src/man/man3socket/byteorder.3socket index bb5e22fc46..1d08cd8204 100644 --- a/usr/src/man/man3socket/byteorder.3socket +++ b/usr/src/man/man3socket/byteorder.3socket @@ -4,7 +4,7 @@ .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH BYTEORDER 3SOCKET "Nov 23, 2015" +.TH BYTEORDER 3SOCKET "Mar 10, 2016" .SH NAME byteorder, htonl, htonll, htons, ntohl, ntohll, ntohs \- convert values between host and network byte order @@ -74,4 +74,4 @@ MT-Level Safe .SH SEE ALSO .LP \fBgethostbyname\fR(3NSL), \fBgetservbyname\fR(3SOCKET), \fBinet.h\fR(3HEAD), -\fBattributes\fR(5) +\fBattributes\fR(5), \fBbyteorder\fR(5) diff --git a/usr/src/man/man5/Makefile b/usr/src/man/man5/Makefile index c30af8e1d1..71ed86715f 100644 --- a/usr/src/man/man5/Makefile +++ b/usr/src/man/man5/Makefile @@ -30,6 +30,7 @@ MANFILES= Intro.5 \ audit_remote.5 \ audit_syslog.5 \ brands.5 \ + byteorder.5 \ cancellation.5 \ charmap.5 \ condition.5 \ @@ -154,6 +155,7 @@ MANLINKS= ANSI.5 \ architecture.5 \ availability.5 \ compile.5 \ + endian.5 \ intro.5 \ pthreads.5 \ stability.5 \ @@ -170,6 +172,8 @@ availability.5 := LINKSRC = attributes.5 stability.5 := LINKSRC = attributes.5 standard.5 := LINKSRC = attributes.5 +endian.5 := LINKSRC = byteorder.5 + RBAC.5 := LINKSRC = rbac.5 advance.5 := LINKSRC = regexp.5 diff --git a/usr/src/man/man5/byteorder.5 b/usr/src/man/man5/byteorder.5 new file mode 100644 index 0000000000..4172008e97 --- /dev/null +++ b/usr/src/man/man5/byteorder.5 @@ -0,0 +1,264 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2016 Joyent, Inc. +.\" +.Dd January 31, 2016 +.Dt BYTEORDER 5 +.Os +.Sh NAME +.Nm byteorder , +.Nm endian +.Nd byte order and endianness +.Sh DESCRIPTION +Integer values which occupy more than 1 byte in memory can be laid out +in different ways on different platforms. In particular, there is a +major split between those which place the least significant byte of an +integer at the lowest address, and those which place the most +significant byte there instead. As this difference relates to which +end of the integer is found in memory first, the term +.Em endian +is used to refer to a particular byte order. +.Pp +A platform is referred to as using a +.Em big-endian +byte order when it places the most significant byte at the lowest +address, and +.Em little-endian +when it places the least significant byte first. Some platforms may also +switch between big- and little-endian mode and run code compiled for +either. +.Pp +Historically, there have also been some systems that utilized +.Em middle-endian +byte orders for integers larger than 2 bytes. Such orderings are not in +common use today. +.Pp +Endianness is also of particular importance when dealing with values +that are being read into memory from an external source. For example, +network protocols such as IP conventionally define the fields in a +packet as being always stored in big-endian byte order. This means that +a little-endian machine will have to perform transformations on these +fields in order to process them. +.Ss Examples +To illustrate endianness in memory, let us consider the decimal integer +2864434397. This number fits in 32 bits of storage (4 bytes). +.Pp +On a big-endian system, this integer would be written into memory as +the bytes 0xAA, 0xBB, 0xCC, 0xDD, in order from lowest memory address to +highest. +.Pp +On a little-endian system, it would be written instead as the bytes +0xDD, 0xCC, 0xBB, 0xAA, in that order. +.Pp +If both the big- and little-endian systems were asked to store this +integer at address 0x100, we would see the following in each of their +memory: +.Bd -literal + + Big-Endian + + ++------++------++------++------++ + || 0xAA || 0xBB || 0xCC || 0xDD || + ++------++------++------++------++ + ^^ ^^ ^^ ^^ + 0x100 0x101 0x102 0x103 + vv vv vv vv + ++------++------++------++------++ + || 0xDD || 0xCC || 0xBB || 0xAA || + ++------++------++------++------++ + + Little-Endian +.Ed +.Pp +It is particularly important to note that even though the byte order is +different between these two machines, the bit ordering within each byte, +by convention, is still the same. +.Pp +For example, take the decimal integer 4660, which occupies in 16 bits (2 +bytes). +.Pp +On a big-endian system, this would be written into memory as 0x12, then +0x34. +.Pp +On a little-endian system, it would be written as 0x34, then 0x12. Note +that this is not at all the same as seeing 0x43 then 0x21 in memory -- +only the bytes are re-ordered, not any bits (or nybbles) within them. +.Pp +As before, storing this at address 0x100: +.Bd -literal + Big-Endian + + ++------++------++ + || 0x12 || 0x34 || + ++------++------++ + ^^ ^^ + 0x100 0x101 + vv vv + ++------++------++ + || 0x34 || 0x12 || + ++------++------++ + + Little-Endian +.Ed +.Pp +This example shows how an eight byte number, 0xBADCAFEDEADBEEF is stored +in both big and little-endian: +.Bd -literal + Big-Endian + + +------+------+------+------+------+------+------+------+ + | 0xBA | 0xDC | 0xAF | 0xFE | 0xDE | 0xAD | 0xBE | 0xEF | + +------+------+------+------+------+------+------+------+ + ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ + 0x100 0x101 0x102 0x103 0x104 0x105 0x106 0x107 + vv vv vv vv vv vv vv vv + +------+------+------+------+------+------+------+------+ + | 0xEF | 0xBE | 0xAD | 0xDE | 0xFE | 0xAF | 0xDC | 0xBA | + +------+------+------+------+------+------+------+------+ + + Little-Endian + +.Ed +.Pp +The treatment of different endian values would not be complete without +discussing +.Em PDP-endian , +which is also known as +.Em middle-endian . +While the PDP-11 was a 16-bit little-endian system, it laid out 32-bit +values in a different way from current little-endian systems. First, it +would divide a 32-bit number into two 16-bit numbers. Each 16-bit number +would be stored in little-endian; however, the two 16-bit words would be +stored with the larger 16-bit word appearing first in memory, followed +by the latter. +.Pp +The following image illustrates PDP-endian and compares it against +little-endian values. Here, we'll start with the value 0xAABBCCDD and +show how the four bytes for it will be laid out, starting at 0x100. +.Bd -literal + PDP-Endian + + ++------++------++------++------++ + || 0xBB || 0xAA || 0xDD || 0xCC || + ++------++------++------++------++ + ^^ ^^ ^^ ^^ + 0x100 0x101 0x102 0x103 + vv vv vv vv + ++------++------++------++------++ + || 0xDD || 0xCC || 0xBB || 0xAA || + ++------++------++------++------++ + + Little-Endian + +.Ed +.Ss Network Byte Order +The term 'network byte order' refers to big-endian ordering, and +originates from the IEEE. Early disagreements over which byte ordering +to use for network traffic prompted RFC1700 to define that all +IETF-specified network protocols use big-endian ordering unless noted +explicitly otherwise. The Internet protocol family (IP, and thus TCP and +UDP etc) particularly adhere to this convention. +.Ss Determining the System's Byte Order +The operating system supports both big-endian and little-endian CPUs. To +make it easier for programs to determine the endianness of the +platform they are being compiled for, functions and macro constants are +provided in the system header files. +.Pp +The endianness of the system can be obtained by including the header +.In sys/types.h +and using the pre-processor macros +.Sy _LITTLE_ENDIAN +and +.Sy _BIG_ENDIAN . +See +.Xr types.h 3HEAD +for more information. +.Pp +Additionally, the header +.In endian.h +defines an alternative means for determining the endianness of the +current system. See +.Xr endian.h 3HEAD +for more information. +.Pp +illumos runs on both big- and little-endian systems. When writing +software for which the endianness is important, one must always check +the byte order and convert it appropriately. +.Ss Converting Between Byte Orders +The system provides two different sets of functions to convert values +between big-endian and little-endian. They are defined in +.Xr byteorder 3C +and +.Xr endian 3C . +.Pp +The +.Xr byteorder 3SOCKET +family of functions convert data between the host's native byte order +and big- or little-endian. +The functions operate on either 16-bit, 32-bit, or 64-bit values. +Functions that convert from network byte order to the host's byte order +start with the string +.Sy ntoh , +while functions which convert from the host's byte order to network byte +order, begin with +.Sy hton . +For example, to convert a 32-bit value, a long, from network byte order +to the host's, one would use the function +.Xr ntohl 3SOCKET . +.Pp +These functions have been standardized by POSIX. However, the 64-bit variants, +.Xr ntohll 3SOCKET +and +.Xr htonll 3SOCKET +are not standardized and may not be found on other systems. For more +information on these functions, see +.Xr byteorder 3SOCKET . +.Pp +The second family of functions, +.Xr endian 3C , +provide a means to convert between the host's byte order +and big-endian and little-endian specifically. While these functions are +similar to those in +.Xr byteorder 3C , +they more explicitly cover different data conversions. Like them, these +functions operate on either 16-bit, 32-bit, or 64-bit values. When +converting from big-endian, to the host's endianness, the functions +begin with +.Sy betoh . +If instead, one is converting data from the host's native endianness to +another, then it starts with +.Sy htobe . +When working with little-endian data, the prefixes +.Sy letoh +and +.Sy htole +convert little-endian data to the host's endianness and from the host's +to little-endian respectively. +.Pp +These functions +are not standardized and the header they appear in varies between the +BSDs and GNU/Linux. Applications that wish to be portable, should +instead use the +.Xr byteorder 3C +functions. +.Pp +All of these functions in both families simply return their input when +the host's native byte order is the same as the desired order. For +example, when calling +.Xr htonl 3SOCKET +on a big-endian system the original data is returned with no conversion +or modification. +.Sh SEE ALSO +.Xr endian 3C , +.Xr endian.h 3HEAD , +.Xr inet 3HEAD , +.Xr byteorder 3SOCKET diff --git a/usr/src/pkg/manifests/system-header.mf b/usr/src/pkg/manifests/system-header.mf index 787395c361..d14c524fc7 100644 --- a/usr/src/pkg/manifests/system-header.mf +++ b/usr/src/pkg/manifests/system-header.mf @@ -363,6 +363,7 @@ file path=usr/include/dirent.h file path=usr/include/dlfcn.h file path=usr/include/door.h file path=usr/include/elf.h +file path=usr/include/endian.h file path=usr/include/err.h file path=usr/include/errno.h file path=usr/include/eti.h @@ -1867,6 +1868,7 @@ file path=usr/share/man/man3head/assert.h.3head file path=usr/share/man/man3head/complex.h.3head file path=usr/share/man/man3head/cpio.h.3head file path=usr/share/man/man3head/dirent.h.3head +file path=usr/share/man/man3head/endian.h.3head file path=usr/share/man/man3head/errno.h.3head file path=usr/share/man/man3head/fcntl.h.3head file path=usr/share/man/man3head/fenv.h.3head diff --git a/usr/src/pkg/manifests/system-library.man3c.inc b/usr/src/pkg/manifests/system-library.man3c.inc index f0a33077b4..91c54dd6ea 100644 --- a/usr/src/pkg/manifests/system-library.man3c.inc +++ b/usr/src/pkg/manifests/system-library.man3c.inc @@ -108,6 +108,7 @@ file path=usr/share/man/man3c/ecvt.3c file path=usr/share/man/man3c/enable_extended_FILE_stdio.3c file path=usr/share/man/man3c/encrypt.3c file path=usr/share/man/man3c/end.3c +file path=usr/share/man/man3c/endian.3c file path=usr/share/man/man3c/epoll_create.3c file path=usr/share/man/man3c/epoll_ctl.3c file path=usr/share/man/man3c/epoll_wait.3c @@ -692,6 +693,12 @@ link path=usr/share/man/man3c/backtrace_symbols.3c target=walkcontext.3c link path=usr/share/man/man3c/backtrace_symbols_fd.3c target=walkcontext.3c link path=usr/share/man/man3c/bcmp.3c target=bstring.3c link path=usr/share/man/man3c/bcopy.3c target=bstring.3c +link path=usr/share/man/man3c/be16toh.3c target=endian.3c +link path=usr/share/man/man3c/be32toh.3c target=endian.3c +link path=usr/share/man/man3c/be64toh.3c target=endian.3c +link path=usr/share/man/man3c/betoh16.3c target=endian.3c +link path=usr/share/man/man3c/betoh32.3c target=endian.3c +link path=usr/share/man/man3c/betoh64.3c target=endian.3c link path=usr/share/man/man3c/bind_textdomain_codeset.3c target=gettext.3c link path=usr/share/man/man3c/bindtextdomain.3c target=gettext.3c link path=usr/share/man/man3c/btowc_l.3c target=btowc.3c @@ -861,6 +868,12 @@ link path=usr/share/man/man3c/gsignal.3c target=ssignal.3c link path=usr/share/man/man3c/hasmntopt.3c target=getmntent.3c link path=usr/share/man/man3c/hcreate.3c target=hsearch.3c link path=usr/share/man/man3c/hdestroy.3c target=hsearch.3c +link path=usr/share/man/man3c/htobe16.3c target=endian.3c +link path=usr/share/man/man3c/htobe32.3c target=endian.3c +link path=usr/share/man/man3c/htobe64.3c target=endian.3c +link path=usr/share/man/man3c/htole16.3c target=endian.3c +link path=usr/share/man/man3c/htole32.3c target=endian.3c +link path=usr/share/man/man3c/htole64.3c target=endian.3c link path=usr/share/man/man3c/initstate.3c target=random.3c link path=usr/share/man/man3c/innetgr.3c target=getnetgrent.3c link path=usr/share/man/man3c/isalnum.3c target=ctype.3c @@ -934,6 +947,12 @@ link path=usr/share/man/man3c/l64a.3c target=a64l.3c link path=usr/share/man/man3c/labs.3c target=abs.3c link path=usr/share/man/man3c/lcong48.3c target=drand48.3c link path=usr/share/man/man3c/ldiv.3c target=div.3c +link path=usr/share/man/man3c/le16toh.3c target=endian.3c +link path=usr/share/man/man3c/le32toh.3c target=endian.3c +link path=usr/share/man/man3c/le64toh.3c target=endian.3c +link path=usr/share/man/man3c/letoh16.3c target=endian.3c +link path=usr/share/man/man3c/letoh32.3c target=endian.3c +link path=usr/share/man/man3c/letoh64.3c target=endian.3c link path=usr/share/man/man3c/lfind.3c target=lsearch.3c link path=usr/share/man/man3c/llabs.3c target=abs.3c link path=usr/share/man/man3c/lldiv.3c target=div.3c diff --git a/usr/src/pkg/manifests/system-library.man5.inc b/usr/src/pkg/manifests/system-library.man5.inc index 63d883e984..b2167fc879 100644 --- a/usr/src/pkg/manifests/system-library.man5.inc +++ b/usr/src/pkg/manifests/system-library.man5.inc @@ -17,6 +17,7 @@ file path=usr/share/man/man5/audit_binfile.5 file path=usr/share/man/man5/audit_remote.5 file path=usr/share/man/man5/audit_syslog.5 +file path=usr/share/man/man5/byteorder.5 file path=usr/share/man/man5/cancellation.5 file path=usr/share/man/man5/charmap.5 file path=usr/share/man/man5/condition.5 @@ -65,5 +66,6 @@ file path=usr/share/man/man5/timerfd.5 file path=usr/share/man/man5/threads.5 link path=usr/share/man/man5/advance.5 target=regexp.5 link path=usr/share/man/man5/compile.5 target=regexp.5 +link path=usr/share/man/man5/endian.5 target=byteorder.5 link path=usr/share/man/man5/pthreads.5 target=threads.5 link path=usr/share/man/man5/step.5 target=regexp.5 diff --git a/usr/src/pkg/manifests/system-test-libctest.mf b/usr/src/pkg/manifests/system-test-libctest.mf index 66ea7c17db..6fb203a3ab 100644 --- a/usr/src/pkg/manifests/system-test-libctest.mf +++ b/usr/src/pkg/manifests/system-test-libctest.mf @@ -79,6 +79,8 @@ file path=opt/libc-tests/tests/c11_tss.64 mode=0555 file path=opt/libc-tests/tests/call_once.32 mode=0555 file path=opt/libc-tests/tests/call_once.64 mode=0555 file path=opt/libc-tests/tests/catopen mode=0555 +file path=opt/libc-tests/tests/endian.32 mode=0555 +file path=opt/libc-tests/tests/endian.64 mode=0555 file path=opt/libc-tests/tests/fpround_test mode=0555 file path=opt/libc-tests/tests/fpround_test.$(ARCH) mode=0555 file path=opt/libc-tests/tests/fpround_test.$(ARCH64) mode=0555 diff --git a/usr/src/test/libc-tests/runfiles/default.run b/usr/src/test/libc-tests/runfiles/default.run index 44e6c1e3dc..6cc36ee305 100644 --- a/usr/src/test/libc-tests/runfiles/default.run +++ b/usr/src/test/libc-tests/runfiles/default.run @@ -60,6 +60,8 @@ outputdir = /var/tmp/test_results [/opt/libc-tests/tests/call_once.32] [/opt/libc-tests/tests/call_once.64] [/opt/libc-tests/tests/catopen] +[/opt/libc-tests/tests/endian.32] +[/opt/libc-tests/tests/endian.64] [/opt/libc-tests/tests/quick_exit] [/opt/libc-tests/tests/priv_gettext] [/opt/libc-tests/tests/strerror] diff --git a/usr/src/test/libc-tests/tests/Makefile b/usr/src/test/libc-tests/tests/Makefile index 72634efd10..4f237e9136 100644 --- a/usr/src/test/libc-tests/tests/Makefile +++ b/usr/src/test/libc-tests/tests/Makefile @@ -33,6 +33,7 @@ PROGS = \ c11_threads \ c11_tss \ call_once \ + endian \ quick_exit_order \ quick_exit_status \ timespec_get diff --git a/usr/src/test/libc-tests/tests/endian.c b/usr/src/test/libc-tests/tests/endian.c new file mode 100644 index 0000000000..1165ad773d --- /dev/null +++ b/usr/src/test/libc-tests/tests/endian.c @@ -0,0 +1,158 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2016 Joyent, Inc. + */ + +/* + * Test endian(3C). + */ + +#include <sys/types.h> +#include <endian.h> +#include <sys/debug.h> + +#ifndef BIG_ENDIAN +#error "Missing BIG_ENDIAN definition" +#endif + +#ifndef LITTLE_ENDIAN +#error "Missing LITTLE_ENDIAN definition" +#endif + +static void +endian_fromhost(void) +{ + uint16_t val16 = 0x1122; + uint32_t val32 = 0x11223344; + uint64_t val64 = 0x1122334455667788ULL; + uint16_t ebe16, ele16, test16; + uint32_t ebe32, ele32, test32; + uint64_t ebe64, ele64, test64; + +#ifdef _LITTLE_ENDIAN + ebe16 = 0x2211; + ebe32 = 0x44332211UL; + ebe64 = 0x8877665544332211ULL; + ele16 = 0x1122; + ele32 = 0x11223344UL; + ele64 = 0x1122334455667788ULL; +#elif _BIG_ENDIAN + ele16 = 0x2211; + ele32 = 0x44332211UL; + ele64 = 0x8877665544332211ULL; + ebe16 = 0x1122; + ebe32 = 0x11223344UL; + ebe64 = 0x1122334455667788ULL; +#else +#error "Unknown byte order" +#endif /* _LITTLE_ENDIAN */ + + test16 = htobe16(val16); + VERIFY3U(test16, ==, ebe16); + test32 = htobe32(val32); + VERIFY3U(test32, ==, ebe32); + test64 = htobe64(val64); + VERIFY3U(test64, ==, ebe64); + + test16 = htole16(val16); + VERIFY3U(test16, ==, ele16); + test32 = htole32(val32); + VERIFY3U(test32, ==, ele32); + test64 = htole64(val64); + VERIFY3U(test64, ==, ele64); +} + +static void +endian_frombig(void) +{ + uint16_t val16 = 0x1122; + uint32_t val32 = 0x11223344; + uint64_t val64 = 0x1122334455667788ULL; + uint16_t e16, test16; + uint32_t e32, test32; + uint64_t e64, test64; + +#ifdef _LITTLE_ENDIAN + e16 = 0x2211; + e32 = 0x44332211UL; + e64 = 0x8877665544332211ULL; +#elif _BIG_ENDIAN + e16 = 0x1122; + e32 = 0x11223344UL; + e64 = 0x1122334455667788ULL; +#else +#error "Unknown byte order" +#endif /* _LITTLE_ENDIAN */ + + test16 = be16toh(val16); + VERIFY3U(test16, ==, e16); + test16 = betoh16(val16); + VERIFY3U(test16, ==, e16); + + test32 = be32toh(val32); + VERIFY3U(test32, ==, e32); + test32 = betoh32(val32); + VERIFY3U(test32, ==, e32); + + test64 = be64toh(val64); + VERIFY3U(test64, ==, e64); + test64 = betoh64(val64); + VERIFY3U(test64, ==, e64); +} + +static void +endian_fromlittle(void) +{ + uint16_t val16 = 0x1122; + uint32_t val32 = 0x11223344; + uint64_t val64 = 0x1122334455667788ULL; + uint16_t e16, test16; + uint32_t e32, test32; + uint64_t e64, test64; + +#ifdef _LITTLE_ENDIAN + e16 = 0x1122; + e32 = 0x11223344UL; + e64 = 0x1122334455667788ULL; +#elif _BIG_ENDIAN + e16 = 0x2211; + e32 = 0x44332211UL; + e64 = 0x8877665544332211ULL; +#else +#error "Unknown byte order" +#endif /* _LITTLE_ENDIAN */ + + test16 = le16toh(val16); + VERIFY3U(test16, ==, e16); + test16 = letoh16(val16); + VERIFY3U(test16, ==, e16); + + test32 = le32toh(val32); + VERIFY3U(test32, ==, e32); + test32 = letoh32(val32); + VERIFY3U(test32, ==, e32); + + test64 = le64toh(val64); + VERIFY3U(test64, ==, e64); + test64 = letoh64(val64); + VERIFY3U(test64, ==, e64); +} + +int +main(void) +{ + endian_fromhost(); + endian_frombig(); + endian_fromlittle(); + return (0); +} |