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
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.
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]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _SYS_CCOMPILE_H
28 #define _SYS_CCOMPILE_H
31 * This file contains definitions designed to enable different compilers
32 * to be used harmoniously on Solaris systems.
40 * Allow for version tests for compiler bugs and features.
43 #define __GNUC_VERSION \
44 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
46 #define __GNUC_VERSION 0
49 #if defined(__ATTRIBUTE_IMPLEMENTED) || defined(__GNUC__)
53 * analogous to lint's PRINTFLIKEn
55 #define __sun_attr___PRINTFLIKE__(__n) \
56 __attribute__((__format__(printf, __n, (__n)+1)))
57 #define __sun_attr___VPRINTFLIKE__(__n) \
58 __attribute__((__format__(printf, __n, 0)))
60 #define __sun_attr___KPRINTFLIKE__ __sun_attr___PRINTFLIKE__
61 #define __sun_attr___KVPRINTFLIKE__ __sun_attr___VPRINTFLIKE__
64 * Currently the openzfs codebase has a lot of formatting errors
65 * which are not picked up in the linux build because they're not
66 * doing formatting checks. LLVM's kprintf implementation doesn't
67 * actually do format checks!
69 * For FreeBSD these break under gcc! LLVM shim'ed cmn_err as a
70 * format attribute but also didn't check anything. If one
71 * replaces it with the above, all of the format issues
72 * in the codebase show up.
74 * Once those format string issues are addressed, the above
75 * should be flipped on once again.
77 #define __sun_attr___PRINTFLIKE__(__n)
78 #define __sun_attr___VPRINTFLIKE__(__n)
79 #define __sun_attr___KPRINTFLIKE__(__n)
80 #define __sun_attr___KVPRINTFLIKE__(__n)
85 * This one's pretty obvious -- the function never returns
87 #define __sun_attr___noreturn__ __attribute__((__noreturn__))
90 * This is an appropriate label for functions that do not
91 * modify their arguments, e.g. strlen()
93 #define __sun_attr___pure__ __attribute__((__pure__))
96 * This is a stronger form of __pure__. Can be used for functions
97 * that do not modify their arguments and don't depend on global
100 #define __sun_attr___const__ __attribute__((__const__))
103 * structure packing like #pragma pack(1)
105 #define __sun_attr___packed__ __attribute__((__packed__))
107 #define ___sun_attr_inner(__a) __sun_attr_##__a
108 #define __sun_attr__(__a) ___sun_attr_inner __a
110 #else /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */
112 #define __sun_attr__(__a)
114 #endif /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */
117 * Shorthand versions for readability
120 #define __PRINTFLIKE(__n) __sun_attr__((__PRINTFLIKE__(__n)))
121 #define __VPRINTFLIKE(__n) __sun_attr__((__VPRINTFLIKE__(__n)))
122 #define __KPRINTFLIKE(__n) __sun_attr__((__KPRINTFLIKE__(__n)))
123 #define __KVPRINTFLIKE(__n) __sun_attr__((__KVPRINTFLIKE__(__n)))
124 #if defined(_KERNEL) || defined(_STANDALONE)
125 #define __NORETURN __sun_attr__((__noreturn__))
126 #endif /* _KERNEL || _STANDALONE */
127 #define __CONST __sun_attr__((__const__))
128 #define __PURE __sun_attr__((__pure__))
130 #if defined(INVARIANTS) && !defined(ZFS_DEBUG)
135 #define EXPORT_SYMBOL(x)
136 #define MODULE_AUTHOR(s)
137 #define MODULE_DESCRIPTION(s)
138 #define MODULE_LICENSE(s)
139 #define module_param(a, b, c)
140 #define module_param_call(a, b, c, d, e)
141 #define module_param_named(a, b, c, d)
142 #define MODULE_PARM_DESC(a, b)
147 #if !defined(ZFS_DEBUG) && !defined(NDEBUG)
152 #define EINTEGRITY 97 /* EINTEGRITY is new in 13 */
156 * These are bespoke errnos used in ZFS. We map them to their closest FreeBSD
157 * equivalents. This gives us more useful error messages from strerror(3).
159 #define ECKSUM EINTEGRITY
160 #define EFRAGS ENOSPC
162 /* Similar for ENOACTIVE */
163 #define ENOTACTIVE ECANCELED
165 #define EREMOTEIO EREMOTE
167 #define ETIME ETIMEDOUT
169 #define O_LARGEFILE 0
174 #ifndef HAVE_RPC_TYPES
185 #if defined(_KERNEL) || defined(_STANDALONE)
186 #define param_set_charp(a, b) (0)
187 #define ATTR_UID AT_UID
188 #define ATTR_GID AT_GID
189 #define ATTR_MODE AT_MODE
190 #define ATTR_XVATTR AT_XVATTR
191 #define ATTR_CTIME AT_CTIME
192 #define ATTR_MTIME AT_MTIME
193 #define ATTR_ATIME AT_ATIME
194 #if defined(_STANDALONE)
195 #define vmem_free kmem_free
196 #define vmem_zalloc kmem_zalloc
197 #define vmem_alloc kmem_zalloc
199 #define vmem_free zfs_kmem_free
200 #define vmem_zalloc(size, flags) zfs_kmem_alloc(size, flags | M_ZERO)
201 #define vmem_alloc zfs_kmem_alloc
203 #define MUTEX_NOLOCKDEP 0
204 #define RW_NOLOCKDEP 0
210 * XXX We really need to consolidate on standard
211 * error codes in the common code
213 #define ENOSTR ENOTCONN
214 #define ENODATA EINVAL
217 #define __BSD_VISIBLE 1
219 #define __POSIX_VISIBLE 201808
220 #define __XSI_VISIBLE 1000
222 #define ARRAY_SIZE(a) (sizeof (a) / sizeof (a[0]))
224 /* Note: this file can be used on linux/macOS when bootstrapping tools. */
225 #if defined(__FreeBSD__)
227 #define pwrite64 pwrite
228 #define ftruncate64 ftruncate
229 #define lseek64 lseek
230 #define pread64 pread
232 #define lstat64 lstat
233 #define statfs64 statfs
234 #define readdir64 readdir
235 #define dirent64 dirent
237 #define P2ALIGN(x, align) ((x) & -(align))
238 #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
239 #define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1)
240 #define P2PHASE(x, align) ((x) & ((align) - 1))
241 #define P2NPHASE(x, align) (-(x) & ((align) - 1))
242 #define ISP2(x) (((x) & ((x) - 1)) == 0)
243 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
244 #define P2BOUNDARY(off, len, align) \
245 (((off) ^ ((off) + (len) - 1)) > (align) - 1)
248 * Typed version of the P2* macros. These macros should be used to ensure
249 * that the result is correctly calculated based on the data type of (x),
250 * which is passed in as the last argument, regardless of the data
251 * type of the alignment. For example, if (x) is of type uint64_t,
252 * and we want to round it up to a page boundary using "PAGESIZE" as
253 * the alignment, we can do either
255 * P2ROUNDUP(x, (uint64_t)PAGESIZE)
257 * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
259 #define P2ALIGN_TYPED(x, align, type) \
260 ((type)(x) & -(type)(align))
261 #define P2PHASE_TYPED(x, align, type) \
262 ((type)(x) & ((type)(align) - 1))
263 #define P2NPHASE_TYPED(x, align, type) \
264 (-(type)(x) & ((type)(align) - 1))
265 #define P2ROUNDUP_TYPED(x, align, type) \
266 ((((type)(x) - 1) | ((type)(align) - 1)) + 1)
267 #define P2END_TYPED(x, align, type) \
268 (-(~(type)(x) & -(type)(align)))
269 #define P2PHASEUP_TYPED(x, align, phase, type) \
270 ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
271 #define P2CROSS_TYPED(x, y, align, type) \
272 (((type)(x) ^ (type)(y)) > (type)(align) - 1)
273 #define P2SAMEHIGHBIT_TYPED(x, y, type) \
274 (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
276 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
277 #define RLIM64_INFINITY RLIM_INFINITY
278 #ifndef HAVE_ERESTART
279 #define ERESTART EAGAIN
281 #define ABS(a) ((a) < 0 ? -(a) : (a))
288 #endif /* _SYS_CCOMPILE_H */