]> git.proxmox.com Git - mirror_spl-debian.git/blob - include/sys/sysmacros.h
Minimal signal handling interface.
[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 #include <sys/varargs.h>
10 #include <sys/zone.h>
11 #include <sys/signal.h>
12
13 #ifndef _KERNEL
14 #define _KERNEL __KERNEL__
15 #endif
16
17 /* Missing defines.
18 */
19 #define FALSE 0
20 #define TRUE 1
21
22 #define INT32_MAX INT_MAX
23 #define INT32_MIN INT_MIN
24 #define UINT32_MAX UINT_MAX
25 #define UINT32_MIN UINT_MIN
26 #define INT64_MAX LLONG_MAX
27 #define INT64_MIN LLONG_MIN
28 #define UINT64_MAX ULLONG_MAX
29 #define UINT64_MIN ULLONG_MIN
30
31 #define NBBY 8
32 #define ENOTSUP ENOTSUPP
33
34 #define MAXMSGLEN 256
35 #define MAXNAMELEN 256
36 #define MAXPATHLEN PATH_MAX
37 #define MAXOFFSET_T 0x7fffffffffffffffl
38
39 #define MAXBSIZE 8192
40 #define DEV_BSIZE 512
41 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
42
43 #define max_ncpus 64
44 #define CPU_SEQID smp_processor_id() /* I think... */
45 #define _NOTE(x)
46
47 #define RLIM64_INFINITY RLIM_INFINITY
48
49 /* 0..MAX_PRIO-1: Process priority
50 * 0..MAX_RT_PRIO-1: RT priority tasks
51 * MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks
52 *
53 * Treat shim tasks as SCHED_NORMAL tasks
54 */
55 #define minclsyspri (MAX_RT_PRIO)
56 #define maxclsyspri (MAX_PRIO-1)
57
58 #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
59 #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
60
61 /* Missing macros
62 */
63 #define PAGESIZE PAGE_SIZE
64
65 /* from Solaris sys/byteorder.h */
66 #define BSWAP_8(x) ((x) & 0xff)
67 #define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8))
68 #define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16))
69 #define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32))
70
71 /* Map some simple functions.
72 */
73 #define bzero(ptr,size) memset(ptr,0,size)
74 #define bcopy(src,dest,size) memcpy(dest,src,size)
75 #define bcmp(src,dest,size) memcmp((src), (dest), (size_t)(size))
76 #define ASSERT(x) BUG_ON(!(x))
77 #define VERIFY(x) ASSERT(x)
78
79 #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
80 const TYPE __left = (TYPE)(LEFT); \
81 const TYPE __right = (TYPE)(RIGHT); \
82 if (!(__left OP __right)) \
83 BUG(); \
84 } while (0)
85
86 #define VERIFY3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t)
87 #define VERIFY3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t)
88 #define VERIFY3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t)
89
90 #define ASSERT3S(x, y, z) VERIFY3S(x, y, z)
91 #define ASSERT3U(x, y, z) VERIFY3U(x, y, z)
92 #define ASSERT3P(x, y, z) VERIFY3P(x, y, z)
93
94 /* Dtrace probes do not exist in the linux kernel */
95
96 #ifdef DTRACE_PROBE1
97 #undef DTRACE_PROBE1
98 #endif /* DTRACE_PROBE1 */
99 #define DTRACE_PROBE1(a, b, c) ((void)0)
100
101 #ifdef DTRACE_PROBE2
102 #undef DTRACE_PROBE2
103 #endif /* DTRACE_PROBE2 */
104 #define DTRACE_PROBE2(a, b, c, d, e) ((void)0)
105
106 #ifdef DTRACE_PROBE3
107 #undef DTRACE_PROBE3
108 #endif /* DTRACE_PROBE3 */
109 #define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0)
110
111 #ifdef DTRACE_PROBE4
112 #undef DTRACE_PROBE4
113 #endif /* DTRACE_PROBE4 */
114 #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0)
115
116 /* Missing globals */
117 extern int p0;
118 extern char hw_serial[11];
119
120 /* Missing misc functions */
121 extern int highbit(unsigned long i);
122 extern int ddi_strtoul(const char *hw_serial, char **nptr,
123 int base, unsigned long *result);
124
125 #define makedevice(maj,min) makedev(maj,min)
126
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 */