]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/os/freebsd/spl/sys/ccompile.h
Update OpenZFS to 2.0.0-rc3-gbd565f
[FreeBSD/FreeBSD.git] / include / os / freebsd / spl / sys / ccompile.h
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26
27 #ifndef _SYS_CCOMPILE_H
28 #define _SYS_CCOMPILE_H
29
30 /*
31  * This file contains definitions designed to enable different compilers
32  * to be used harmoniously on Solaris systems.
33  */
34
35 #ifdef  __cplusplus
36 extern "C" {
37 #endif
38
39 /*
40  * Allow for version tests for compiler bugs and features.
41  */
42 #if defined(__GNUC__)
43 #define __GNUC_VERSION  \
44         (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
45 #else
46 #define __GNUC_VERSION  0
47 #endif
48
49 #if defined(__ATTRIBUTE_IMPLEMENTED) || defined(__GNUC__)
50
51 /*
52  * analogous to lint's PRINTFLIKEn
53  */
54 #define __sun_attr___PRINTFLIKE__(__n)  \
55                 __attribute__((__format__(printf, __n, (__n)+1)))
56 #define __sun_attr___VPRINTFLIKE__(__n) \
57                 __attribute__((__format__(printf, __n, 0)))
58
59 /*
60  * Handle the kernel printf routines that can take '%b' too
61  */
62 #if __GNUC_VERSION < 30402
63 /*
64  * XX64 at least this doesn't work correctly yet with 3.4.1 anyway!
65  */
66 #define __sun_attr___KPRINTFLIKE__      __sun_attr___PRINTFLIKE__
67 #define __sun_attr___KVPRINTFLIKE__     __sun_attr___VPRINTFLIKE__
68 #else
69 #define __sun_attr___KPRINTFLIKE__(__n) \
70                 __attribute__((__format__(cmn_err, __n, (__n)+1)))
71 #define __sun_attr___KVPRINTFLIKE__(__n) \
72                 __attribute__((__format__(cmn_err, __n, 0)))
73 #endif
74
75 /*
76  * This one's pretty obvious -- the function never returns
77  */
78 #define __sun_attr___noreturn__ __attribute__((__noreturn__))
79
80
81 /*
82  * This is an appropriate label for functions that do not
83  * modify their arguments, e.g. strlen()
84  */
85 #define __sun_attr___pure__     __attribute__((__pure__))
86
87 /*
88  * This is a stronger form of __pure__. Can be used for functions
89  * that do not modify their arguments and don't depend on global
90  * memory.
91  */
92 #define __sun_attr___const__    __attribute__((__const__))
93
94 /*
95  * structure packing like #pragma pack(1)
96  */
97 #define __sun_attr___packed__   __attribute__((__packed__))
98
99 #define ___sun_attr_inner(__a)  __sun_attr_##__a
100 #define __sun_attr__(__a)       ___sun_attr_inner __a
101
102 #else   /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */
103
104 #define __sun_attr__(__a)
105
106 #endif  /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */
107
108 /*
109  * Shorthand versions for readability
110  */
111
112 #define __PRINTFLIKE(__n)       __sun_attr__((__PRINTFLIKE__(__n)))
113 #define __VPRINTFLIKE(__n)      __sun_attr__((__VPRINTFLIKE__(__n)))
114 #define __KPRINTFLIKE(__n)      __sun_attr__((__KPRINTFLIKE__(__n)))
115 #define __KVPRINTFLIKE(__n)     __sun_attr__((__KVPRINTFLIKE__(__n)))
116 #if     defined(_KERNEL) || defined(_STANDALONE)
117 #define __NORETURN              __sun_attr__((__noreturn__))
118 #endif /* _KERNEL || _STANDALONE */
119 #define __CONST                 __sun_attr__((__const__))
120 #define __PURE                  __sun_attr__((__pure__))
121
122 #if defined(INVARIANTS) && !defined(ZFS_DEBUG)
123 #define ZFS_DEBUG
124 #undef  NDEBUG
125 #endif
126
127 #define EXPORT_SYMBOL(x)
128 #define MODULE_AUTHOR(s)
129 #define MODULE_DESCRIPTION(s)
130 #define MODULE_LICENSE(s)
131 #define module_param(a, b, c)
132 #define module_param_call(a, b, c, d, e)
133 #define module_param_named(a, b, c, d)
134 #define MODULE_PARM_DESC(a, b)
135 #define asm __asm
136 #ifdef ZFS_DEBUG
137 #undef NDEBUG
138 #endif
139 #if !defined(ZFS_DEBUG) && !defined(NDEBUG)
140 #define NDEBUG
141 #endif
142
143 #ifndef EINTEGRITY
144 #define EINTEGRITY 97 /* EINTEGRITY is new in 13 */
145 #endif
146
147 /*
148  * These are bespoke errnos used in ZFS. We map them to their closest FreeBSD
149  * equivalents. This gives us more useful error messages from strerror(3).
150  */
151 #define ECKSUM  EINTEGRITY
152 #define EFRAGS  ENOSPC
153
154 /* Similar for ENOACTIVE */
155 #define ENOTACTIVE      ECANCELED
156
157 #define EREMOTEIO EREMOTE
158 #define ECHRNG ENXIO
159 #define ETIME ETIMEDOUT
160
161 #define O_LARGEFILE 0
162 #define O_RSYNC 0
163 #define O_DSYNC 0
164
165 #ifndef LOCORE
166 #ifndef HAVE_RPC_TYPES
167 typedef int bool_t;
168 typedef int enum_t;
169 #endif
170 #endif
171
172 #ifndef __cplusplus
173 #define __init
174 #define __exit
175 #endif
176
177 #if defined(_KERNEL) || defined(_STANDALONE)
178 #define param_set_charp(a, b) (0)
179 #define ATTR_UID AT_UID
180 #define ATTR_GID AT_GID
181 #define ATTR_MODE AT_MODE
182 #define ATTR_XVATTR     AT_XVATTR
183 #define ATTR_CTIME      AT_CTIME
184 #define ATTR_MTIME      AT_MTIME
185 #define ATTR_ATIME      AT_ATIME
186 #if defined(_STANDALONE)
187 #define vmem_free kmem_free
188 #define vmem_zalloc kmem_zalloc
189 #define vmem_alloc kmem_zalloc
190 #else
191 #define vmem_free zfs_kmem_free
192 #define vmem_zalloc(size, flags) zfs_kmem_alloc(size, flags | M_ZERO)
193 #define vmem_alloc zfs_kmem_alloc
194 #endif
195 #define MUTEX_NOLOCKDEP 0
196 #define RW_NOLOCKDEP 0
197
198 #else
199 #define FALSE 0
200 #define TRUE 1
201         /*
202          * XXX We really need to consolidate on standard
203          * error codes in the common code
204          */
205 #define ENOSTR ENOTCONN
206 #define ENODATA EINVAL
207
208
209 #define __BSD_VISIBLE 1
210 #ifndef IN_BASE
211 #define __POSIX_VISIBLE 201808
212 #define __XSI_VISIBLE 1000
213 #endif
214 #define ARRAY_SIZE(a) (sizeof (a) / sizeof (a[0]))
215 #define mmap64 mmap
216 /* Note: this file can be used on linux/macOS when bootstrapping tools. */
217 #if defined(__FreeBSD__)
218 #define open64 open
219 #define pwrite64 pwrite
220 #define ftruncate64 ftruncate
221 #define lseek64 lseek
222 #define pread64 pread
223 #define stat64 stat
224 #define lstat64 lstat
225 #define statfs64 statfs
226 #define readdir64 readdir
227 #define dirent64 dirent
228 #endif
229 #define P2ALIGN(x, align)               ((x) & -(align))
230 #define P2CROSS(x, y, align)    (((x) ^ (y)) > (align) - 1)
231 #define P2ROUNDUP(x, align)             ((((x) - 1) | ((align) - 1)) + 1)
232 #define P2PHASE(x, align)               ((x) & ((align) - 1))
233 #define P2NPHASE(x, align)              (-(x) & ((align) - 1))
234 #define ISP2(x)                 (((x) & ((x) - 1)) == 0)
235 #define IS_P2ALIGNED(v, a)      ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
236 #define P2BOUNDARY(off, len, align) \
237         (((off) ^ ((off) + (len) - 1)) > (align) - 1)
238
239 /*
240  * Typed version of the P2* macros.  These macros should be used to ensure
241  * that the result is correctly calculated based on the data type of (x),
242  * which is passed in as the last argument, regardless of the data
243  * type of the alignment.  For example, if (x) is of type uint64_t,
244  * and we want to round it up to a page boundary using "PAGESIZE" as
245  * the alignment, we can do either
246  *
247  * P2ROUNDUP(x, (uint64_t)PAGESIZE)
248  * or
249  * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
250  */
251 #define P2ALIGN_TYPED(x, align, type)   \
252         ((type)(x) & -(type)(align))
253 #define P2PHASE_TYPED(x, align, type)   \
254         ((type)(x) & ((type)(align) - 1))
255 #define P2NPHASE_TYPED(x, align, type)  \
256         (-(type)(x) & ((type)(align) - 1))
257 #define P2ROUNDUP_TYPED(x, align, type) \
258         ((((type)(x) - 1) | ((type)(align) - 1)) + 1)
259 #define P2END_TYPED(x, align, type)     \
260         (-(~(type)(x) & -(type)(align)))
261 #define P2PHASEUP_TYPED(x, align, phase, type)  \
262         ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
263 #define P2CROSS_TYPED(x, y, align, type)        \
264         (((type)(x) ^ (type)(y)) > (type)(align) - 1)
265 #define P2SAMEHIGHBIT_TYPED(x, y, type) \
266         (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
267
268 #define DIV_ROUND_UP(n, d)      (((n) + (d) - 1) / (d))
269 #define RLIM64_INFINITY RLIM_INFINITY
270 #ifndef HAVE_ERESTART
271 #define ERESTART EAGAIN
272 #endif
273 #define ABS(a)  ((a) < 0 ? -(a) : (a))
274
275 #endif
276 #ifdef  __cplusplus
277 }
278 #endif
279
280 #endif  /* _SYS_CCOMPILE_H */