]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/include/os/freebsd/spl/sys/ccompile.h
zfs: merge openzfs/zfs@deb121309
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / 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 #if defined(INVARIANTS) && !defined(ZFS_DEBUG)
40 #define ZFS_DEBUG
41 #undef  NDEBUG
42 #endif
43
44 #define EXPORT_SYMBOL(x)
45 #define module_param(a, b, c)
46 #define module_param_call(a, b, c, d, e)
47 #define module_param_named(a, b, c, d)
48 #define MODULE_PARM_DESC(a, b)
49 #define asm __asm
50 #ifdef ZFS_DEBUG
51 #undef NDEBUG
52 #endif
53 #if !defined(ZFS_DEBUG) && !defined(NDEBUG)
54 #define NDEBUG
55 #endif
56
57 #ifndef EINTEGRITY
58 #define EINTEGRITY 97 /* EINTEGRITY is new in 13 */
59 #endif
60
61 /*
62  * These are bespoke errnos used in ZFS. We map them to their closest FreeBSD
63  * equivalents. This gives us more useful error messages from strerror(3).
64  */
65 #define ECKSUM  EINTEGRITY
66 #define EFRAGS  ENOSPC
67
68 /* Similar for ENOACTIVE */
69 #define ENOTACTIVE      ECANCELED
70
71 #define EREMOTEIO EREMOTE
72 #define ECHRNG ENXIO
73 #define ETIME ETIMEDOUT
74
75 #ifndef LOCORE
76 #ifndef HAVE_RPC_TYPES
77 #ifndef _KERNEL
78 typedef int bool_t;
79 typedef int enum_t;
80 #endif
81 #endif
82 #endif
83
84 #ifndef __cplusplus
85 #define __init
86 #define __exit
87 #endif
88
89 #if defined(_KERNEL) || defined(_STANDALONE)
90 #define param_set_charp(a, b) (0)
91 #define ATTR_UID AT_UID
92 #define ATTR_GID AT_GID
93 #define ATTR_MODE AT_MODE
94 #define ATTR_XVATTR     AT_XVATTR
95 #define ATTR_CTIME      AT_CTIME
96 #define ATTR_MTIME      AT_MTIME
97 #define ATTR_ATIME      AT_ATIME
98 #if defined(_STANDALONE)
99 #define vmem_free kmem_free
100 #define vmem_zalloc kmem_zalloc
101 #define vmem_alloc kmem_zalloc
102 #else
103 #define vmem_free zfs_kmem_free
104 #define vmem_zalloc(size, flags) zfs_kmem_alloc(size, flags | M_ZERO)
105 #define vmem_alloc zfs_kmem_alloc
106 #endif
107 #define MUTEX_NOLOCKDEP 0
108 #define RW_NOLOCKDEP 0
109
110 #else
111 #define FALSE 0
112 #define TRUE 1
113         /*
114          * XXX We really need to consolidate on standard
115          * error codes in the common code
116          */
117 #define ENOSTR ENOTCONN
118 #define ENODATA EINVAL
119
120
121 #define __BSD_VISIBLE 1
122 #ifndef IN_BASE
123 #define __POSIX_VISIBLE 201808
124 #define __XSI_VISIBLE 1000
125 #endif
126 #define ARRAY_SIZE(a) (sizeof (a) / sizeof (a[0]))
127 #define mmap64 mmap
128 /* Note: this file can be used on linux/macOS when bootstrapping tools. */
129 #if defined(__FreeBSD__)
130 #define open64 open
131 #define pwrite64 pwrite
132 #define ftruncate64 ftruncate
133 #define lseek64 lseek
134 #define pread64 pread
135 #define stat64 stat
136 #define lstat64 lstat
137 #define statfs64 statfs
138 #define readdir64 readdir
139 #define dirent64 dirent
140 #endif
141 #define P2ALIGN(x, align)               ((x) & -(align))
142 #define P2CROSS(x, y, align)    (((x) ^ (y)) > (align) - 1)
143 #define P2ROUNDUP(x, align)             ((((x) - 1) | ((align) - 1)) + 1)
144 #define P2PHASE(x, align)               ((x) & ((align) - 1))
145 #define P2NPHASE(x, align)              (-(x) & ((align) - 1))
146 #define ISP2(x)                 (((x) & ((x) - 1)) == 0)
147 #define IS_P2ALIGNED(v, a)      ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
148 #define P2BOUNDARY(off, len, align) \
149         (((off) ^ ((off) + (len) - 1)) > (align) - 1)
150
151 /*
152  * Typed version of the P2* macros.  These macros should be used to ensure
153  * that the result is correctly calculated based on the data type of (x),
154  * which is passed in as the last argument, regardless of the data
155  * type of the alignment.  For example, if (x) is of type uint64_t,
156  * and we want to round it up to a page boundary using "PAGESIZE" as
157  * the alignment, we can do either
158  *
159  * P2ROUNDUP(x, (uint64_t)PAGESIZE)
160  * or
161  * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
162  */
163 #define P2ALIGN_TYPED(x, align, type)   \
164         ((type)(x) & -(type)(align))
165 #define P2PHASE_TYPED(x, align, type)   \
166         ((type)(x) & ((type)(align) - 1))
167 #define P2NPHASE_TYPED(x, align, type)  \
168         (-(type)(x) & ((type)(align) - 1))
169 #define P2ROUNDUP_TYPED(x, align, type) \
170         ((((type)(x) - 1) | ((type)(align) - 1)) + 1)
171 #define P2END_TYPED(x, align, type)     \
172         (-(~(type)(x) & -(type)(align)))
173 #define P2PHASEUP_TYPED(x, align, phase, type)  \
174         ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
175 #define P2CROSS_TYPED(x, y, align, type)        \
176         (((type)(x) ^ (type)(y)) > (type)(align) - 1)
177 #define P2SAMEHIGHBIT_TYPED(x, y, type) \
178         (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
179
180 #define DIV_ROUND_UP(n, d)      (((n) + (d) - 1) / (d))
181 #define RLIM64_INFINITY RLIM_INFINITY
182 #ifndef HAVE_ERESTART
183 #define ERESTART EAGAIN
184 #endif
185 #define ABS(a)  ((a) < 0 ? -(a) : (a))
186
187 #endif
188 #ifdef  __cplusplus
189 }
190 #endif
191
192 #endif  /* _SYS_CCOMPILE_H */