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