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