xref: /illumos-gate/usr/src/compat/bhyve/sys/cdefs.h (revision 9e7f7d5d77f695e9980dbb0f9fb1b969272eb207)
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 #define	__FBSDID(s)
42 
43 #ifdef	__GNUC__
44 #define	asm		__asm
45 #define	inline		__inline
46 
47 #define	__GNUCLIKE___SECTION		1
48 
49 #define	__dead2		__attribute__((__noreturn__))
50 #define	__used		__attribute__((__used__))
51 #define	__packed	__attribute__((__packed__))
52 #define	__aligned(x)	__attribute__((__aligned__(x)))
53 #define	__section(x)	__attribute__((__section__(x)))
54 #define	__weak_symbol   __attribute__((__weak__))
55 #endif
56 
57 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint)
58 
59 #if defined(__cplusplus) && __cplusplus >= 201103L
60 #define	_Alignof(x)		alignof(x)
61 #else
62 #define	_Alignof(x)		__alignof(x)
63 #endif
64 
65 #if defined(__cplusplus) && __cplusplus >= 201103L
66 #define	_Noreturn		[[noreturn]]
67 #else
68 #define	_Noreturn		__dead2
69 #endif
70 
71 #if !__has_extension(c_static_assert)
72 #if (defined(__cplusplus) && __cplusplus >= 201103L) || \
73     __has_extension(cxx_static_assert)
74 #define _Static_assert(x, y)    static_assert(x, y)
75 #elif __GNUC_PREREQ__(4,6)
76 /* Nothing, gcc 4.6 and higher has _Static_assert built-in */
77 #elif defined(__COUNTER__)
78 #define _Static_assert(x, y)    __Static_assert(x, __COUNTER__)
79 #define __Static_assert(x, y)   ___Static_assert(x, y)
80 #define ___Static_assert(x, y)  typedef char __assert_ ## y[(x) ? 1 : -1] \
81                                 __unused
82 #else
83 #define _Static_assert(x, y)    struct __hack
84 #endif
85 #endif
86 #define	static_assert(x, y)	_Static_assert(x, y)
87 
88 #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */
89 
90 #if __GNUC_PREREQ__(4, 1)
91 #define	__offsetof(type, field)	 __builtin_offsetof(type, field)
92 #else
93 #ifndef __cplusplus
94 #define	__offsetof(type, field) \
95 	((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field))
96 #else
97 #define	__offsetof(type, field)					\
98   (__offsetof__ (reinterpret_cast <__size_t>			\
99                  (&reinterpret_cast <const volatile char &>	\
100                   (static_cast<type *> (0)->field))))
101 #endif
102 #endif
103 
104 #endif	/* _COMPAT_FREEBSD_SYS_CDEFS_H_ */
105