]>
Commit | Line | Data |
---|---|---|
14c5326c | 1 | #ifndef _SPL_SYSMACROS_H |
2 | #define _SPL_SYSMACROS_H | |
3 | ||
4 | #ifdef __cplusplus | |
5 | extern "C" { | |
6 | #endif | |
7 | ||
8 | #include <linux/module.h> | |
05ae387b | 9 | #include <sys/varargs.h> |
14c5326c | 10 | |
11 | #ifndef _KERNEL | |
12 | #define _KERNEL __KERNEL__ | |
13 | #endif | |
14 | ||
15 | /* Missing defines. | |
16 | */ | |
ed61a7d0 | 17 | #define FALSE 0 |
18 | #define TRUE 1 | |
b0dd3380 | 19 | |
14c5326c | 20 | #define INT32_MAX INT_MAX |
3b3ba48f | 21 | #define INT32_MIN INT_MIN |
22 | #define UINT32_MAX UINT_MAX | |
23 | #define UINT32_MIN UINT_MIN | |
24 | #define INT64_MAX LLONG_MAX | |
25 | #define INT64_MIN LLONG_MIN | |
26 | #define UINT64_MAX ULLONG_MAX | |
27 | #define UINT64_MIN ULLONG_MIN | |
28 | ||
14c5326c | 29 | #define NBBY 8 |
30 | #define ENOTSUP ENOTSUPP | |
b0dd3380 | 31 | |
05ae387b | 32 | #define MAXMSGLEN 256 |
14c5326c | 33 | #define MAXNAMELEN 256 |
34 | #define MAXPATHLEN PATH_MAX | |
b0dd3380 | 35 | #define MAXOFFSET_T 0x7fffffffffffffffl |
36 | ||
37 | #define MAXBSIZE 8192 | |
38 | #define DEV_BSIZE 512 | |
39 | #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ | |
40 | ||
14c5326c | 41 | #define max_ncpus 64 |
12472b24 | 42 | #define CPU_SEQID smp_processor_id() /* I think... */ |
b0dd3380 | 43 | #define _NOTE(x) |
14c5326c | 44 | |
45 | /* 0..MAX_PRIO-1: Process priority | |
46 | * 0..MAX_RT_PRIO-1: RT priority tasks | |
47 | * MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks | |
48 | * | |
49 | * Treat shim tasks as SCHED_NORMAL tasks | |
50 | */ | |
51 | #define minclsyspri (MAX_RT_PRIO) | |
52 | #define maxclsyspri (MAX_PRIO-1) | |
53 | ||
54 | #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20) | |
55 | #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20) | |
56 | ||
57 | #define kred NULL | |
58 | ||
59 | #define FREAD 1 | |
60 | #define FWRITE 2 | |
61 | #define FCREAT O_CREAT | |
62 | #define FTRUNC O_TRUNC | |
63 | #define FOFFMAX O_LARGEFILE | |
64 | #define FSYNC O_SYNC | |
65 | #define FDSYNC O_DSYNC | |
66 | #define FRSYNC O_RSYNC | |
67 | #define FEXCL O_EXCL | |
68 | ||
69 | #define FNODSYNC 0x10000 /* fsync pseudo flag */ | |
70 | #define FNOFOLLOW 0x20000 /* don't follow symlinks */ | |
71 | ||
72 | /* Missing macros | |
73 | */ | |
74 | #define PAGESIZE PAGE_SIZE | |
75 | ||
76 | /* from Solaris sys/byteorder.h */ | |
77 | #define BSWAP_8(x) ((x) & 0xff) | |
78 | #define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8)) | |
79 | #define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16)) | |
80 | #define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32)) | |
81 | ||
82 | /* Map some simple functions. | |
83 | */ | |
84 | #define bzero(ptr,size) memset(ptr,0,size) | |
85 | #define bcopy(src,dest,size) memcpy(dest,src,size) | |
b0dd3380 | 86 | #define bcmp(src,dest,size) memcmp((src), (dest), (size_t)(size)) |
14c5326c | 87 | #define ASSERT(x) BUG_ON(!(x)) |
77b1fe8f | 88 | #define VERIFY(x) ASSERT(x) |
a713518f | 89 | |
90 | #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \ | |
91 | const TYPE __left = (TYPE)(LEFT); \ | |
92 | const TYPE __right = (TYPE)(RIGHT); \ | |
93 | if (!(__left OP __right)) \ | |
94 | BUG(); \ | |
95 | } while (0) | |
96 | ||
97 | #define VERIFY3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t) | |
98 | #define VERIFY3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t) | |
99 | #define VERIFY3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t) | |
100 | ||
101 | #define ASSERT3S(x, y, z) VERIFY3S(x, y, z) | |
102 | #define ASSERT3U(x, y, z) VERIFY3U(x, y, z) | |
103 | #define ASSERT3P(x, y, z) VERIFY3P(x, y, z) | |
104 | ||
105 | /* Dtrace probes do not exist in the linux kernel */ | |
106 | ||
107 | #ifdef DTRACE_PROBE1 | |
108 | #undef DTRACE_PROBE1 | |
109 | #endif /* DTRACE_PROBE1 */ | |
3b3ba48f | 110 | #define DTRACE_PROBE1(a, b, c) ((void)0) |
a713518f | 111 | |
112 | #ifdef DTRACE_PROBE2 | |
113 | #undef DTRACE_PROBE2 | |
114 | #endif /* DTRACE_PROBE2 */ | |
3b3ba48f | 115 | #define DTRACE_PROBE2(a, b, c, d, e) ((void)0) |
a713518f | 116 | |
117 | #ifdef DTRACE_PROBE3 | |
118 | #undef DTRACE_PROBE3 | |
119 | #endif /* DTRACE_PROBE3 */ | |
3b3ba48f | 120 | #define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0) |
a713518f | 121 | |
122 | #ifdef DTRACE_PROBE4 | |
123 | #undef DTRACE_PROBE4 | |
124 | #endif /* DTRACE_PROBE4 */ | |
3b3ba48f | 125 | #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0) |
14c5326c | 126 | |
77b1fe8f | 127 | /* Missing globals */ |
14c5326c | 128 | extern int p0; |
129 | ||
77b1fe8f | 130 | /* Missing misc functions */ |
131 | extern int highbit(unsigned long i); | |
132 | ||
14c5326c | 133 | #define makedevice(maj,min) makedev(maj,min) |
3b3ba48f | 134 | #define zone_dataset_visible(x, y) (1) |
135 | #define INGLOBALZONE(z) (1) | |
0b3cf046 | 136 | #define utsname system_utsname |
14c5326c | 137 | |
138 | /* XXX - Borrowed from zfs project libsolcompat/include/sys/sysmacros.h */ | |
139 | /* common macros */ | |
140 | #ifndef MIN | |
141 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
142 | #endif | |
143 | #ifndef MAX | |
144 | #define MAX(a, b) ((a) < (b) ? (b) : (a)) | |
145 | #endif | |
146 | #ifndef ABS | |
147 | #define ABS(a) ((a) < 0 ? -(a) : (a)) | |
148 | #endif | |
149 | ||
150 | /* | |
151 | * Compatibility macros/typedefs needed for Solaris -> Linux port | |
152 | */ | |
153 | #define P2ALIGN(x, align) ((x) & -(align)) | |
154 | #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1) | |
155 | #define P2ROUNDUP(x, align) (-(-(x) & -(align))) | |
156 | #define P2ROUNDUP_TYPED(x, align, type) \ | |
157 | (-(-(type)(x) & -(type)(align))) | |
158 | #define P2PHASE(x, align) ((x) & ((align) - 1)) | |
159 | #define P2NPHASE(x, align) (-(x) & ((align) - 1)) | |
160 | #define P2NPHASE_TYPED(x, align, type) \ | |
161 | (-(type)(x) & ((type)(align) - 1)) | |
162 | #define ISP2(x) (((x) & ((x) - 1)) == 0) | |
163 | #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0) | |
164 | ||
165 | /* | |
166 | * Typed version of the P2* macros. These macros should be used to ensure | |
167 | * that the result is correctly calculated based on the data type of (x), | |
168 | * which is passed in as the last argument, regardless of the data | |
169 | * type of the alignment. For example, if (x) is of type uint64_t, | |
170 | * and we want to round it up to a page boundary using "PAGESIZE" as | |
171 | * the alignment, we can do either | |
172 | * P2ROUNDUP(x, (uint64_t)PAGESIZE) | |
173 | * or | |
174 | * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t) | |
175 | */ | |
176 | #define P2ALIGN_TYPED(x, align, type) \ | |
177 | ((type)(x) & -(type)(align)) | |
178 | #define P2PHASE_TYPED(x, align, type) \ | |
179 | ((type)(x) & ((type)(align) - 1)) | |
180 | #define P2NPHASE_TYPED(x, align, type) \ | |
181 | (-(type)(x) & ((type)(align) - 1)) | |
182 | #define P2ROUNDUP_TYPED(x, align, type) \ | |
183 | (-(-(type)(x) & -(type)(align))) | |
184 | #define P2END_TYPED(x, align, type) \ | |
185 | (-(~(type)(x) & -(type)(align))) | |
186 | #define P2PHASEUP_TYPED(x, align, phase, type) \ | |
187 | ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align))) | |
188 | #define P2CROSS_TYPED(x, y, align, type) \ | |
189 | (((type)(x) ^ (type)(y)) > (type)(align) - 1) | |
190 | #define P2SAMEHIGHBIT_TYPED(x, y, type) \ | |
191 | (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y))) | |
192 | ||
193 | #if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof) | |
194 | ||
195 | /* avoid any possibility of clashing with <stddef.h> version */ | |
196 | ||
197 | #define offsetof(s, m) ((size_t)(&(((s *)0)->m))) | |
198 | #endif | |
199 | ||
200 | #ifdef __cplusplus | |
201 | } | |
202 | #endif | |
203 | ||
204 | #endif /* _SPL_SYSMACROS_H */ |