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