xref: /illumos-gate/usr/src/compat/bhyve/sys/cdefs.h (revision fdb2a7e9480266dfaa0b5aaa0e1237456552f332)
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  */
16 
17 #ifndef _COMPAT_FREEBSD_SYS_CDEFS_H_
18 #define	_COMPAT_FREEBSD_SYS_CDEFS_H_
19 
20 /*
21  * Testing against Clang-specific extensions.
22  */
23 #ifndef __has_extension
24 #define	__has_extension		__has_feature
25 #endif
26 #ifndef __has_feature
27 #define	__has_feature(x)	0
28 #endif
29 
30 /*
31  * Macro to test if we're using a specific version of gcc or later.
32  */
33 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
34 #define __GNUC_PREREQ__(ma, mi) \
35 	(__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
36 #else
37 #define __GNUC_PREREQ__(ma, mi) 0
38 #endif
39 
40 #define	__FBSDID(s)
41 
42 #ifdef	__GNUC__
43 #define	asm		__asm
44 #define	inline		__inline
45 
46 #define	__GNUCLIKE___SECTION		1
47 
48 #define	__dead2		__attribute__((__noreturn__))
49 #define	__used		__attribute__((__used__))
50 #define	__packed	__attribute__((__packed__))
51 #define	__aligned(x)	__attribute__((__aligned__(x)))
52 #define	__section(x)	__attribute__((__section__(x)))
53 #define	__weak_symbol   __attribute__((__weak__))
54 #endif
55 
56 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint)
57 
58 #if defined(__cplusplus) && __cplusplus >= 201103L
59 #define	_Alignof(x)		alignof(x)
60 #else
61 #define	_Alignof(x)		__alignof(x)
62 #endif
63 
64 #if !__has_extension(c_static_assert)
65 #if (defined(__cplusplus) && __cplusplus >= 201103L) || \
66     __has_extension(cxx_static_assert)
67 #define _Static_assert(x, y)    static_assert(x, y)
68 #elif __GNUC_PREREQ__(4,6)
69 /* Nothing, gcc 4.6 and higher has _Static_assert built-in */
70 #elif defined(__COUNTER__)
71 #define _Static_assert(x, y)    __Static_assert(x, __COUNTER__)
72 #define __Static_assert(x, y)   ___Static_assert(x, y)
73 #define ___Static_assert(x, y)  typedef char __assert_ ## y[(x) ? 1 : -1] \
74                                 __unused
75 #else
76 #define _Static_assert(x, y)    struct __hack
77 #endif
78 #endif
79 #define	static_assert(x, y)	_Static_assert(x, y)
80 
81 #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */
82 
83 #if __GNUC_PREREQ__(4, 1)
84 #define	__offsetof(type, field)	 __builtin_offsetof(type, field)
85 #else
86 #ifndef __cplusplus
87 #define	__offsetof(type, field) \
88 	((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field))
89 #else
90 #define	__offsetof(type, field)					\
91   (__offsetof__ (reinterpret_cast <__size_t>			\
92                  (&reinterpret_cast <const volatile char &>	\
93                   (static_cast<type *> (0)->field))))
94 #endif
95 #endif
96 
97 #endif	/* _COMPAT_FREEBSD_SYS_CDEFS_H_ */
98