1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * CDDL HEADER START 4 * 5 * The contents of this file are subject to the terms of the 6 * Common Development and Distribution License, Version 1.0 only 7 * (the "License"). You may not use this file except in compliance 8 * with the License. 9 * 10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11 * or https://opensource.org/licenses/CDDL-1.0. 12 * See the License for the specific language governing permissions 13 * and limitations under the License. 14 * 15 * When distributing Covered Code, include this CDDL HEADER in each 16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17 * If applicable, add the following below this CDDL HEADER, with the 18 * fields enclosed by brackets "[]" replaced with your own identifying 19 * information: Portions Copyright [yyyy] [name of copyright owner] 20 * 21 * CDDL HEADER END 22 */ 23 /* 24 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. 26 */ 27 28 #ifndef _SYS_CCOMPILE_H 29 #define _SYS_CCOMPILE_H 30 31 /* 32 * This file contains definitions designed to enable different compilers 33 * to be used harmoniously on Solaris systems. 34 */ 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #if defined(INVARIANTS) && !defined(ZFS_DEBUG) 41 #define ZFS_DEBUG 42 #undef NDEBUG 43 #endif 44 45 #define EXPORT_SYMBOL(x) 46 #define module_param(a, b, c) 47 #define module_param_call(a, b, c, d, e) 48 #define module_param_named(a, b, c, d) 49 #define MODULE_PARM_DESC(a, b) 50 #define asm __asm 51 #ifdef ZFS_DEBUG 52 #undef NDEBUG 53 #endif 54 #if !defined(ZFS_DEBUG) && !defined(NDEBUG) 55 #define NDEBUG 56 #endif 57 58 #ifndef EINTEGRITY 59 #define EINTEGRITY 97 /* EINTEGRITY is new in 13 */ 60 #endif 61 62 /* 63 * These are bespoke errnos used in ZFS. We map them to their closest FreeBSD 64 * equivalents. This gives us more useful error messages from strerror(3). 65 */ 66 #define ECKSUM EINTEGRITY 67 #define EFRAGS ENOSPC 68 69 /* Similar for ENOACTIVE */ 70 #define ENOTACTIVE ECANCELED 71 72 #define EREMOTEIO EREMOTE 73 #define ECHRNG ENXIO 74 #define ETIME ETIMEDOUT 75 76 #ifndef LOCORE 77 #ifndef HAVE_RPC_TYPES 78 #ifndef _KERNEL 79 typedef int bool_t; 80 typedef int enum_t; 81 #endif 82 #endif 83 #endif 84 85 #ifndef __cplusplus 86 #define __init 87 #define __exit 88 #endif 89 90 #if defined(_KERNEL) || defined(_STANDALONE) 91 #define param_set_charp(a, b) (0) 92 #define ATTR_UID AT_UID 93 #define ATTR_GID AT_GID 94 #define ATTR_MODE AT_MODE 95 #define ATTR_XVATTR AT_XVATTR 96 #define ATTR_CTIME AT_CTIME 97 #define ATTR_MTIME AT_MTIME 98 #define ATTR_ATIME AT_ATIME 99 #if defined(_STANDALONE) 100 #define vmem_free kmem_free 101 #define vmem_zalloc kmem_zalloc 102 #define vmem_alloc kmem_zalloc 103 #else 104 #define vmem_free zfs_kmem_free 105 #define vmem_zalloc(size, flags) zfs_kmem_alloc(size, flags | M_ZERO) 106 #define vmem_alloc zfs_kmem_alloc 107 #endif 108 #define MUTEX_NOLOCKDEP 0 109 #define RW_NOLOCKDEP 0 110 111 #else 112 #define FALSE 0 113 #define TRUE 1 114 /* 115 * XXX We really need to consolidate on standard 116 * error codes in the common code 117 */ 118 #define ENOSTR ENOTCONN 119 #define ENODATA EINVAL 120 121 122 #define __BSD_VISIBLE 1 123 #ifndef IN_BASE 124 #define __POSIX_VISIBLE 201808 125 #define __XSI_VISIBLE 1000 126 #endif 127 #define ARRAY_SIZE(a) (sizeof (a) / sizeof (a[0])) 128 #define mmap64 mmap 129 /* Note: this file can be used on linux/macOS when bootstrapping tools. */ 130 #if defined(__FreeBSD__) 131 #define open64 open 132 #define pwrite64 pwrite 133 #define ftruncate64 ftruncate 134 #define lseek64 lseek 135 #define pread64 pread 136 #define stat64 stat 137 #define lstat64 lstat 138 #define statfs64 statfs 139 #define readdir64 readdir 140 #define dirent64 dirent 141 #endif 142 // Deprecated. Use P2ALIGN_TYPED instead. 143 // #define P2ALIGN(x, align) ((x) & -(align)) 144 #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1) 145 #define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1) 146 #define P2PHASE(x, align) ((x) & ((align) - 1)) 147 #define P2NPHASE(x, align) (-(x) & ((align) - 1)) 148 #define ISP2(x) (((x) & ((x) - 1)) == 0) 149 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0) 150 #define P2BOUNDARY(off, len, align) \ 151 (((off) ^ ((off) + (len) - 1)) > (align) - 1) 152 153 /* 154 * Typed version of the P2* macros. These macros should be used to ensure 155 * that the result is correctly calculated based on the data type of (x), 156 * which is passed in as the last argument, regardless of the data 157 * type of the alignment. For example, if (x) is of type uint64_t, 158 * and we want to round it up to a page boundary using "PAGESIZE" as 159 * the alignment, we can do either 160 * 161 * P2ROUNDUP(x, (uint64_t)PAGESIZE) 162 * or 163 * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t) 164 */ 165 #define P2ALIGN_TYPED(x, align, type) \ 166 ((type)(x) & -(type)(align)) 167 #define P2PHASE_TYPED(x, align, type) \ 168 ((type)(x) & ((type)(align) - 1)) 169 #define P2NPHASE_TYPED(x, align, type) \ 170 (-(type)(x) & ((type)(align) - 1)) 171 #define P2ROUNDUP_TYPED(x, align, type) \ 172 ((((type)(x) - 1) | ((type)(align) - 1)) + 1) 173 #define P2END_TYPED(x, align, type) \ 174 (-(~(type)(x) & -(type)(align))) 175 #define P2PHASEUP_TYPED(x, align, phase, type) \ 176 ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align))) 177 #define P2CROSS_TYPED(x, y, align, type) \ 178 (((type)(x) ^ (type)(y)) > (type)(align) - 1) 179 #define P2SAMEHIGHBIT_TYPED(x, y, type) \ 180 (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y))) 181 182 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) 183 #define RLIM64_INFINITY RLIM_INFINITY 184 #ifndef HAVE_ERESTART 185 #define ERESTART EAGAIN 186 #endif 187 #define ABS(a) ((a) < 0 ? -(a) : (a)) 188 189 #endif 190 #ifdef __cplusplus 191 } 192 #endif 193 194 #endif /* _SYS_CCOMPILE_H */ 195