2 * Keep all the ugly #ifdef for system stuff here
12 #if defined(__BEOS__) || \
13 defined(__NetBSD__) || \
14 defined(__FreeBSD__) || \
17 # include <inttypes.h>
18 #elif defined(__linux__) || defined(__WIN32__) || defined(__MINGW32__)
28 #if !defined(__WIN32__) && !defined(__MINGW32__)
29 # include <sys/mman.h>
32 /* Not all systems (like Windows) has this define, and yes
33 * we do replace/emulate mmap() on those systems ...
36 # define MAP_FAILED ((void *)-1)
40 #ifndef O_BINARY /* should be define'd on __WIN32__ */
46 # include <byteswap.h>
47 #elif defined(__MACH__) || defined(__FreeBSD__)
48 # include <machine/endian.h>
49 typedef unsigned long ulong;
53 typedef uint16_t __u16;
54 typedef uint32_t __u32;
55 typedef unsigned int uint;
58 ((((x) & 0xff00) >> 8) | \
59 (((x) & 0x00ff) << 8))
61 ((((x) & 0xff000000) >> 24) | \
62 (((x) & 0x00ff0000) >> 8) | \
63 (((x) & 0x0000ff00) << 8) | \
64 (((x) & 0x000000ff) << 24))
65 #define _uswap_64(x, sfx) \
66 ((((x) & 0xff00000000000000##sfx) >> 56) | \
67 (((x) & 0x00ff000000000000##sfx) >> 40) | \
68 (((x) & 0x0000ff0000000000##sfx) >> 24) | \
69 (((x) & 0x000000ff00000000##sfx) >> 8) | \
70 (((x) & 0x00000000ff000000##sfx) << 8) | \
71 (((x) & 0x0000000000ff0000##sfx) << 24) | \
72 (((x) & 0x000000000000ff00##sfx) << 40) | \
73 (((x) & 0x00000000000000ff##sfx) << 56))
75 # define uswap_64(x) _uswap_64(x, ull)
77 # define uswap_64(x) _uswap_64(x, )
80 #if __BYTE_ORDER == __LITTLE_ENDIAN
81 # define cpu_to_le16(x) (x)
82 # define cpu_to_le32(x) (x)
83 # define cpu_to_le64(x) (x)
84 # define le16_to_cpu(x) (x)
85 # define le32_to_cpu(x) (x)
86 # define le64_to_cpu(x) (x)
87 # define cpu_to_be16(x) uswap_16(x)
88 # define cpu_to_be32(x) uswap_32(x)
89 # define cpu_to_be64(x) uswap_64(x)
90 # define be16_to_cpu(x) uswap_16(x)
91 # define be32_to_cpu(x) uswap_32(x)
92 # define be64_to_cpu(x) uswap_64(x)
94 # define cpu_to_le16(x) uswap_16(x)
95 # define cpu_to_le32(x) uswap_32(x)
96 # define cpu_to_le64(x) uswap_64(x)
97 # define le16_to_cpu(x) uswap_16(x)
98 # define le32_to_cpu(x) uswap_32(x)
99 # define le64_to_cpu(x) uswap_64(x)
100 # define cpu_to_be16(x) (x)
101 # define cpu_to_be32(x) (x)
102 # define cpu_to_be64(x) (x)
103 # define be16_to_cpu(x) (x)
104 # define be32_to_cpu(x) (x)
105 # define be64_to_cpu(x) (x)
108 #else /* !USE_HOSTCC */
110 #include <linux/string.h>
111 #include <linux/types.h>
112 #include <asm/byteorder.h>
114 #if __SIZEOF_LONG__ == 8
115 # define __WORDSIZE 64
116 #elif __SIZEOF_LONG__ == 4
117 # define __WORDSIZE 32
120 * Assume 32-bit for now - only newer toolchains support this feature and
121 * this is only required for sandbox support at present.
123 #define __WORDSIZE 32
126 /* Types for `void *' pointers. */
128 typedef unsigned long int uintptr_t;
129 #elif __WORDSIZE == 32
130 typedef unsigned int uintptr_t;
132 #error "__WORDSIZE has unexpected value"
137 /* compiler options */
138 #define uninitialized_var(x) x = x
140 #define likely(x) __builtin_expect(!!(x), 1)
141 #define unlikely(x) __builtin_expect(!!(x), 0)