1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /* 13 * Copyright 2013 Pluribus Networks Inc. 14 * Copyright 2017 Joyent, Inc. 15 * Copyright 2021 OmniOS Community Edition (OmniOSce) Association. 16 */ 17 18 #ifndef _COMPAT_FREEBSD_SYS_CDEFS_H_ 19 #define _COMPAT_FREEBSD_SYS_CDEFS_H_ 20 21 /* 22 * Testing against Clang-specific extensions. 23 */ 24 #ifndef __has_extension 25 #define __has_extension __has_feature 26 #endif 27 #ifndef __has_feature 28 #define __has_feature(x) 0 29 #endif 30 31 /* 32 * Macro to test if we're using a specific version of gcc or later. 33 */ 34 #if defined(__GNUC__) && !defined(__INTEL_COMPILER) 35 #define __GNUC_PREREQ__(ma, mi) \ 36 (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)) 37 #else 38 #define __GNUC_PREREQ__(ma, mi) 0 39 #endif 40 41 #ifdef __GNUC__ 42 #define asm __asm 43 #define inline __inline 44 45 #define __GNUCLIKE___SECTION 1 46 47 #define __dead2 __attribute__((__noreturn__)) 48 #define __used __attribute__((__used__)) 49 #define __packed __attribute__((__packed__)) 50 #define __aligned(x) __attribute__((__aligned__(x))) 51 #define __section(x) __attribute__((__section__(x))) 52 #define __weak_symbol __attribute__((__weak__)) 53 #endif 54 55 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint) 56 57 #if defined(__cplusplus) && __cplusplus >= 201103L 58 #define _Alignof(x) alignof(x) 59 #else 60 #define _Alignof(x) __alignof(x) 61 #endif 62 63 #if defined(__cplusplus) && __cplusplus >= 201103L 64 #define _Noreturn [[noreturn]] 65 #else 66 #define _Noreturn __dead2 67 #endif 68 69 #if !__has_extension(c_static_assert) 70 #if (defined(__cplusplus) && __cplusplus >= 201103L) || \ 71 __has_extension(cxx_static_assert) 72 #define _Static_assert(x, y) static_assert(x, y) 73 #elif __GNUC_PREREQ__(4,6) 74 /* Nothing, gcc 4.6 and higher has _Static_assert built-in */ 75 #elif defined(__COUNTER__) 76 #define _Static_assert(x, y) __Static_assert(x, __COUNTER__) 77 #define __Static_assert(x, y) ___Static_assert(x, y) 78 #define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] \ 79 __unused 80 #else 81 #define _Static_assert(x, y) struct __hack 82 #endif 83 #endif 84 #define static_assert(x, y) _Static_assert(x, y) 85 86 #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */ 87 88 #if __GNUC_PREREQ__(4, 1) 89 #define __offsetof(type, field) __builtin_offsetof(type, field) 90 #else 91 #ifndef __cplusplus 92 #define __offsetof(type, field) \ 93 ((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field)) 94 #else 95 #define __offsetof(type, field) \ 96 (__offsetof__ (reinterpret_cast <__size_t> \ 97 (&reinterpret_cast <const volatile char &> \ 98 (static_cast<type *> (0)->field)))) 99 #endif 100 #endif 101 102 #ifndef __DECONST 103 #define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) 104 #endif 105 106 #endif /* _COMPAT_FREEBSD_SYS_CDEFS_H_ */ 107