Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix zfs internal endian checks with _ZFS #10621

Merged
merged 1 commit into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config/Rules.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ if BUILD_FREEBSD
AM_CFLAGS += -fPIC -Werror -Wno-unknown-pragmas -Wno-enum-conversion
AM_CFLAGS += -include $(top_srcdir)/include/os/freebsd/spl/sys/ccompile.h
AM_CFLAGS += -I/usr/include -I/usr/local/include
AM_CFLAGS += -D_MACHINE_ENDIAN_H_
endif

AM_CPPFLAGS = -D_GNU_SOURCE
Expand Down
1 change: 0 additions & 1 deletion include/os/freebsd/spl/sys/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ KERNEL_H = \
dirent.h \
disp.h \
dkio.h \
endian.h \
extdirent.h \
file.h \
freebsd_rwlock.h \
Expand Down
4 changes: 2 additions & 2 deletions include/os/freebsd/spl/sys/byteorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
/*
* Macros to convert from a specific byte order to/from native byte order
*/
#if BYTE_ORDER == BIG_ENDIAN
#if BYTE_ORDER == _BIG_ENDIAN
#define BE_8(x) BMASK_8(x)
#define BE_16(x) BMASK_16(x)
#define BE_32(x) BMASK_32(x)
Expand All @@ -80,7 +80,7 @@
#define BE_64(x) BSWAP_64(x)
#endif

#if BYTE_ORDER == BIG_ENDIAN
#if BYTE_ORDER == _BIG_ENDIAN
#define htonll(x) BMASK_64(x)
#define ntohll(x) BMASK_64(x)
#else
Expand Down
42 changes: 0 additions & 42 deletions include/os/freebsd/spl/sys/endian.h

This file was deleted.

9 changes: 9 additions & 0 deletions include/os/freebsd/spl/sys/isa_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#ifndef _SYS_ISA_DEFS_H
#define _SYS_ISA_DEFS_H
#include <sys/endian.h>

/*
* This header file serves to group a set of well known defines and to
Expand Down Expand Up @@ -696,6 +697,14 @@ extern "C" {
#error "Both _ILP32 and _LP64 are defined"
#endif

#if BYTE_ORDER == _BIG_ENDIAN
#define _ZFS_BIG_ENDIAN
#elif BYTE_ORDER == _LITTLE_ENDIAN
#define _ZFS_LITTLE_ENDIAN
#else
#error "unknown byte order"
#endif

#ifdef __cplusplus
}
#endif
Expand Down
11 changes: 10 additions & 1 deletion include/os/linux/spl/sys/byteorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
#define _SPL_BYTEORDER_H

#include <asm/byteorder.h>

#if defined(__BIG_ENDIAN) && !defined(_ZFS_BIG_ENDIAN)
#define _ZFS_BIG_ENDIAN
#endif

#if defined(__LITTLE_ENDIAN) && !defined(_ZFS_LITTLE_ENDIAN)
#define _ZFS_LITTLE_ENDIAN
#endif

#include <sys/isa_defs.h>

#define BSWAP_8(x) ((x) & 0xff)
Expand All @@ -49,7 +58,7 @@
#define BE_IN32(xa) \
(((uint32_t)BE_IN16(xa) << 16) | BE_IN16((uint8_t *)(xa)+2))

#ifdef _BIG_ENDIAN
#ifdef _ZFS_BIG_ENDIAN
static __inline__ uint64_t
htonll(uint64_t n)
{
Expand Down
30 changes: 11 additions & 19 deletions include/os/linux/spl/sys/isa_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@
#endif

#if defined(__ARMEL__) || defined(__AARCH64EL__)
#define _LITTLE_ENDIAN
#define _ZFS_LITTLE_ENDIAN
#else
#define _BIG_ENDIAN
#define _ZFS_BIG_ENDIAN
#endif

/*
Expand Down Expand Up @@ -149,7 +149,7 @@
#endif
#endif

#define _BIG_ENDIAN
#define _ZFS_BIG_ENDIAN
#define _SUNOS_VTOC_16
#define _ALIGNMENT_REQUIRED 1

Expand All @@ -165,7 +165,7 @@
#endif
#endif

#define _BIG_ENDIAN
#define _ZFS_BIG_ENDIAN

/*
* Illumos doesn't define _ALIGNMENT_REQUIRED for s390, so default to 1
Expand All @@ -177,9 +177,9 @@
#elif defined(__mips__)

#if defined(__MIPSEB__)
#define _BIG_ENDIAN
#define _ZFS_BIG_ENDIAN
#elif defined(__MIPSEL__)
#define _LITTLE_ENDIAN
#define _ZFS_LITTLE_ENDIAN
#else
#error MIPS no endian specified
#endif
Expand Down Expand Up @@ -211,7 +211,7 @@
#define __rv64g__
#endif

#define _LITTLE_ENDIAN
#define _ZFS_LITTLE_ENDIAN

#define _SUNOS_VTOC_16

Expand Down Expand Up @@ -243,20 +243,12 @@
#define HAVE_EFFICIENT_UNALIGNED_ACCESS
#endif

#if defined(__LITTLE_ENDIAN) && !defined(_LITTLE_ENDIAN)
#define _LITTLE_ENDIAN __LITTLE_ENDIAN
#if defined(_ZFS_LITTLE_ENDIAN) && defined(_ZFS_BIG_ENDIAN)
#error "Both _ZFS_LITTLE_ENDIAN and _ZFS_BIG_ENDIAN are defined"
#endif

#if defined(__BIG_ENDIAN) && !defined(_BIG_ENDIAN)
#define _BIG_ENDIAN __BIG_ENDIAN
#endif

#if defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
#error "Both _LITTLE_ENDIAN and _BIG_ENDIAN are defined"
#endif

#if !defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
#error "Neither _LITTLE_ENDIAN or _BIG_ENDIAN are defined"
#if !defined(_ZFS_LITTLE_ENDIAN) && !defined(_ZFS_BIG_ENDIAN)
#error "Neither _ZFS_LITTLE_ENDIAN or _ZFS_BIG_ENDIAN are defined"
#endif

#endif /* _SPL_ISA_DEFS_H */
2 changes: 1 addition & 1 deletion include/sys/spa.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ _NOTE(CONSTCOND) } while (0)
ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0); \
}

#ifdef _BIG_ENDIAN
#ifdef _ZFS_BIG_ENDIAN
#define ZFS_HOST_BYTEORDER (0ULL)
#else
#define ZFS_HOST_BYTEORDER (1ULL)
Expand Down
127 changes: 4 additions & 123 deletions lib/libspl/include/os/freebsd/sys/byteorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,91 +40,8 @@
#ifndef _SYS_BYTEORDER_H
#define _SYS_BYTEORDER_H

/*
* XXX FIXME
* on FreeBSD _BIG_ENDIAN is defined on all architectures so we have
* to exclude _MACHINE_ENDIAN_H_ and define the bulk of it here
*/

#include <sys/cdefs.h>
#include <sys/_types.h>

/*
* Define the order of 32-bit words in 64-bit words.
*/
#define _QUAD_HIGHWORD 1
#define _QUAD_LOWWORD 0

/*
* Definitions for byte order, according to byte significance from low
* address to high.
*/
#undef _LITTLE_ENDIAN
/* LSB first: i386, vax */
#define _LITTLE_ENDIAN 1234
/* LSB first in word, MSW first in long */
#define _PDP_ENDIAN 3412

#define _BYTE_ORDER _LITTLE_ENDIAN

/*
* Deprecated variants that don't have enough underscores to be useful in more
* strict namespaces.
*/
#if __BSD_VISIBLE
#define LITTLE_ENDIAN _LITTLE_ENDIAN
#define PDP_ENDIAN _PDP_ENDIAN
#define BYTE_ORDER _BYTE_ORDER
#endif

#define __bswap16_gen(x) (__uint16_t)((x) << 8 | (x) >> 8)
#define __bswap32_gen(x) \
(((__uint32_t)__bswap16((x) & 0xffff) << 16) | __bswap16((x) >> 16))
#define __bswap64_gen(x) \
(((__uint64_t)__bswap32((x) & 0xffffffff) << 32) | __bswap32((x) >> 32))

#ifdef __GNUCLIKE_BUILTIN_CONSTANT_P
#define __bswap16(x) \
((__uint16_t)(__builtin_constant_p(x) ? \
__bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
#define __bswap32(x) \
(__builtin_constant_p(x) ? \
__bswap32_gen((__uint32_t)(x)) : __bswap32_var(x))
#define __bswap64(x) \
(__builtin_constant_p(x) ? \
__bswap64_gen((__uint64_t)(x)) : __bswap64_var(x))
#else
/* XXX these are broken for use in static initializers. */
#define __bswap16(x) __bswap16_var(x)
#define __bswap32(x) __bswap32_var(x)
#define __bswap64(x) __bswap64_var(x)
#endif

/* These are defined as functions to avoid multiple evaluation of x. */

static __inline __uint16_t
__bswap16_var(__uint16_t _x)
{

return (__bswap16_gen(_x));
}

static __inline __uint32_t
__bswap32_var(__uint32_t _x)
{

#ifdef __GNUCLIKE_ASM
__asm("bswap %0" : "+r" (_x));
return (_x);
#else
return (__bswap32_gen(_x));
#endif
}
#define __htonl(x) __bswap32(x)
#define __htons(x) __bswap16(x)
#define __ntohl(x) __bswap32(x)
#define __ntohs(x) __bswap16(x)

#include <sys/endian.h>
#include <netinet/in.h>
#include <sys/isa_defs.h>
#include <sys/int_types.h>

Expand All @@ -140,42 +57,6 @@ extern "C" {
/*
* macros for conversion between host and (internet) network byte order
*/

#if defined(_BIG_ENDIAN) && !defined(ntohl) && !defined(__lint)
/* big-endian */
#if defined(_BIG_ENDIAN) && (defined(__amd64__) || defined(__amd64))
#error "incompatible ENDIAN / ARCH combination"
#endif
#define ntohl(x) (x)
#define ntohs(x) (x)
#define htonl(x) (x)
#define htons(x) (x)

#elif !defined(ntohl) /* little-endian */

#ifndef _IN_PORT_T
#define _IN_PORT_T
typedef uint16_t in_port_t;
#endif

#ifndef _IN_ADDR_T
#define _IN_ADDR_T
typedef uint32_t in_addr_t;
#endif

#if !defined(_XPG4_2) || defined(__EXTENSIONS__) || defined(_XPG5)
extern uint32_t htonl(uint32_t);
extern uint16_t htons(uint16_t);
extern uint32_t ntohl(uint32_t);
extern uint16_t ntohs(uint16_t);
#else
extern in_addr_t htonl(in_addr_t);
extern in_port_t htons(in_port_t);
extern in_addr_t ntohl(in_addr_t);
extern in_port_t ntohs(in_port_t);
#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) || defined(_XPG5) */
#endif

#if !defined(_XPG4_2) || defined(__EXTENSIONS__)

/*
Expand All @@ -194,7 +75,7 @@ extern in_port_t ntohs(in_port_t);
/*
* Macros to convert from a specific byte order to/from native byte order
*/
#ifdef _BIG_ENDIAN
#ifdef _ZFS_BIG_ENDIAN
#define BE_8(x) BMASK_8(x)
#define BE_16(x) BMASK_16(x)
#define BE_32(x) BMASK_32(x)
Expand All @@ -214,7 +95,7 @@ extern in_port_t ntohs(in_port_t);
#define BE_64(x) BSWAP_64(x)
#endif

#ifdef _BIG_ENDIAN
#ifdef _ZFS_BIG_ENDIAN
static __inline__ uint64_t
htonll(uint64_t n)
{
Expand Down
4 changes: 0 additions & 4 deletions lib/libspl/include/os/freebsd/sys/zfs_context_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
#ifndef ZFS_CONTEXT_OS_H_
#define ZFS_CONTEXT_OS_H_

#if BYTE_ORDER != BIG_ENDIAN
#undef _BIG_ENDIAN
#endif

#define ZFS_EXPORTS_PATH "/etc/zfs/exports"

#endif
Loading