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 https://opensource.org/licenses/CDDL-1.0. 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 // Deprecated. Use P2ALIGN_TYPED instead. 142 // #define P2ALIGN(x, align) ((x) & -(align)) 143 #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1) 144 #define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1) 145 #define P2PHASE(x, align) ((x) & ((align) - 1)) 146 #define P2NPHASE(x, align) (-(x) & ((align) - 1)) 147 #define ISP2(x) (((x) & ((x) - 1)) == 0) 148 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0) 149 #define P2BOUNDARY(off, len, align) \ 150 (((off) ^ ((off) + (len) - 1)) > (align) - 1) 151 152 /* 153 * Typed version of the P2* macros. These macros should be used to ensure 154 * that the result is correctly calculated based on the data type of (x), 155 * which is passed in as the last argument, regardless of the data 156 * type of the alignment. For example, if (x) is of type uint64_t, 157 * and we want to round it up to a page boundary using "PAGESIZE" as 158 * the alignment, we can do either 159 * 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) - 1) | ((type)(align) - 1)) + 1) 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 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) 182 #define RLIM64_INFINITY RLIM_INFINITY 183 #ifndef HAVE_ERESTART 184 #define ERESTART EAGAIN 185 #endif 186 #define ABS(a) ((a) < 0 ? -(a) : (a)) 187 188 #endif 189 #ifdef __cplusplus 190 } 191 #endif 192 193 #endif /* _SYS_CCOMPILE_H */ 194