]> git.proxmox.com Git - mirror_zfs.git/blob - include/sys/sysmacros.h
Add some crude debugging support. It leaves alot to be
[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 #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, FMT, CAST) do { \
80 const TYPE __left = (TYPE)(LEFT); \
81 const TYPE __right = (TYPE)(RIGHT); \
82 if (!(__left OP __right)) { \
83 printk("spl: Error VERIFY3(" FMT " " #OP " " FMT ")\n", \
84 CAST __left, CAST __right); \
85 BUG(); \
86 } \
87 } while (0)
88
89 #define VERIFY3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t, "%ld", (long))
90 #define VERIFY3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t, "%lu", (unsigned long))
91 #define VERIFY3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t, "%p", (void *))
92
93 #define ASSERT3S(x, y, z) VERIFY3S(x, y, z)
94 #define ASSERT3U(x, y, z) VERIFY3U(x, y, z)
95 #define ASSERT3P(x, y, z) VERIFY3P(x, y, z)
96
97 /* Dtrace probes do not exist in the linux kernel */
98
99 #ifdef DTRACE_PROBE1
100 #undef DTRACE_PROBE1
101 #endif /* DTRACE_PROBE1 */
102 #define DTRACE_PROBE1(a, b, c) ((void)0)
103
104 #ifdef DTRACE_PROBE2
105 #undef DTRACE_PROBE2
106 #endif /* DTRACE_PROBE2 */
107 #define DTRACE_PROBE2(a, b, c, d, e) ((void)0)
108
109 #ifdef DTRACE_PROBE3
110 #undef DTRACE_PROBE3
111 #endif /* DTRACE_PROBE3 */
112 #define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0)
113
114 #ifdef DTRACE_PROBE4
115 #undef DTRACE_PROBE4
116 #endif /* DTRACE_PROBE4 */
117 #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0)
118
119 /* Missing globals */
120 extern int p0;
121 extern char hw_serial[11];
122
123 /* Missing misc functions */
124 extern int highbit(unsigned long i);
125 extern int ddi_strtoul(const char *hw_serial, char **nptr,
126 int base, unsigned long *result);
127
128 #define makedevice(maj,min) makedev(maj,min)
129
130 /* common macros */
131 #ifndef MIN
132 #define MIN(a, b) ((a) < (b) ? (a) : (b))
133 #endif
134 #ifndef MAX
135 #define MAX(a, b) ((a) < (b) ? (b) : (a))
136 #endif
137 #ifndef ABS
138 #define ABS(a) ((a) < 0 ? -(a) : (a))
139 #endif
140
141 /*
142 * Compatibility macros/typedefs needed for Solaris -> Linux port
143 */
144 #define P2ALIGN(x, align) ((x) & -(align))
145 #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
146 #define P2ROUNDUP(x, align) (-(-(x) & -(align)))
147 #define P2ROUNDUP_TYPED(x, align, type) \
148 (-(-(type)(x) & -(type)(align)))
149 #define P2PHASE(x, align) ((x) & ((align) - 1))
150 #define P2NPHASE(x, align) (-(x) & ((align) - 1))
151 #define P2NPHASE_TYPED(x, align, type) \
152 (-(type)(x) & ((type)(align) - 1))
153 #define ISP2(x) (((x) & ((x) - 1)) == 0)
154 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
155
156 /*
157 * Typed version of the P2* macros. These macros should be used to ensure
158 * that the result is correctly calculated based on the data type of (x),
159 * which is passed in as the last argument, regardless of the data
160 * type of the alignment. For example, if (x) is of type uint64_t,
161 * and we want to round it up to a page boundary using "PAGESIZE" as
162 * the alignment, we can do either
163 * P2ROUNDUP(x, (uint64_t)PAGESIZE)
164 * or
165 * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
166 */
167 #define P2ALIGN_TYPED(x, align, type) \
168 ((type)(x) & -(type)(align))
169 #define P2PHASE_TYPED(x, align, type) \
170 ((type)(x) & ((type)(align) - 1))
171 #define P2NPHASE_TYPED(x, align, type) \
172 (-(type)(x) & ((type)(align) - 1))
173 #define P2ROUNDUP_TYPED(x, align, type) \
174 (-(-(type)(x) & -(type)(align)))
175 #define P2END_TYPED(x, align, type) \
176 (-(~(type)(x) & -(type)(align)))
177 #define P2PHASEUP_TYPED(x, align, phase, type) \
178 ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
179 #define P2CROSS_TYPED(x, y, align, type) \
180 (((type)(x) ^ (type)(y)) > (type)(align) - 1)
181 #define P2SAMEHIGHBIT_TYPED(x, y, type) \
182 (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
183
184 #if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof)
185
186 /* avoid any possibility of clashing with <stddef.h> version */
187
188 #define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
189 #endif
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195 #endif /* _SPL_SYSMACROS_H */