xref: /illumos-gate/usr/src/compat/bhyve/sys/cdefs.h (revision 069b2ef0)
1bf21cd93STycho Nightingale /*
2bf21cd93STycho Nightingale  * This file and its contents are supplied under the terms of the
3bf21cd93STycho Nightingale  * Common Development and Distribution License ("CDDL"), version 1.0.
4bf21cd93STycho Nightingale  * You may only use this file in accordance with the terms of version
5bf21cd93STycho Nightingale  * 1.0 of the CDDL.
6bf21cd93STycho Nightingale  *
7bf21cd93STycho Nightingale  * A full copy of the text of the CDDL should have accompanied this
8bf21cd93STycho Nightingale  * source.  A copy of the CDDL is also available via the Internet at
9bf21cd93STycho Nightingale  * http://www.illumos.org/license/CDDL.
10bf21cd93STycho Nightingale  */
11bf21cd93STycho Nightingale 
12bf21cd93STycho Nightingale /*
13bf21cd93STycho Nightingale  * Copyright 2013 Pluribus Networks Inc.
144c87aefeSPatrick Mooney  * Copyright 2017 Joyent, Inc.
15*069b2ef0SAndy Fiddaman  * Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
16bf21cd93STycho Nightingale  */
17bf21cd93STycho Nightingale 
18bf21cd93STycho Nightingale #ifndef _COMPAT_FREEBSD_SYS_CDEFS_H_
19bf21cd93STycho Nightingale #define	_COMPAT_FREEBSD_SYS_CDEFS_H_
20bf21cd93STycho Nightingale 
214c87aefeSPatrick Mooney /*
224c87aefeSPatrick Mooney  * Testing against Clang-specific extensions.
234c87aefeSPatrick Mooney  */
244c87aefeSPatrick Mooney #ifndef __has_extension
254c87aefeSPatrick Mooney #define	__has_extension		__has_feature
264c87aefeSPatrick Mooney #endif
274c87aefeSPatrick Mooney #ifndef __has_feature
284c87aefeSPatrick Mooney #define	__has_feature(x)	0
294c87aefeSPatrick Mooney #endif
304c87aefeSPatrick Mooney 
314c87aefeSPatrick Mooney /*
324c87aefeSPatrick Mooney  * Macro to test if we're using a specific version of gcc or later.
334c87aefeSPatrick Mooney  */
344c87aefeSPatrick Mooney #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
354c87aefeSPatrick Mooney #define __GNUC_PREREQ__(ma, mi) \
364c87aefeSPatrick Mooney 	(__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
374c87aefeSPatrick Mooney #else
384c87aefeSPatrick Mooney #define __GNUC_PREREQ__(ma, mi) 0
394c87aefeSPatrick Mooney #endif
404c87aefeSPatrick Mooney 
41bf21cd93STycho Nightingale #define	__FBSDID(s)
42bf21cd93STycho Nightingale 
43bf21cd93STycho Nightingale #ifdef	__GNUC__
444c87aefeSPatrick Mooney #define	asm		__asm
45bf21cd93STycho Nightingale #define	inline		__inline
46bf21cd93STycho Nightingale 
47bf21cd93STycho Nightingale #define	__GNUCLIKE___SECTION		1
48bf21cd93STycho Nightingale 
49bf21cd93STycho Nightingale #define	__dead2		__attribute__((__noreturn__))
50bf21cd93STycho Nightingale #define	__used		__attribute__((__used__))
51bf21cd93STycho Nightingale #define	__packed	__attribute__((__packed__))
52bf21cd93STycho Nightingale #define	__aligned(x)	__attribute__((__aligned__(x)))
53bf21cd93STycho Nightingale #define	__section(x)	__attribute__((__section__(x)))
544c87aefeSPatrick Mooney #define	__weak_symbol   __attribute__((__weak__))
55bf21cd93STycho Nightingale #endif
56bf21cd93STycho Nightingale 
574c87aefeSPatrick Mooney #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint)
584c87aefeSPatrick Mooney 
59154972afSPatrick Mooney #if defined(__cplusplus) && __cplusplus >= 201103L
60154972afSPatrick Mooney #define	_Alignof(x)		alignof(x)
61154972afSPatrick Mooney #else
62154972afSPatrick Mooney #define	_Alignof(x)		__alignof(x)
63154972afSPatrick Mooney #endif
64154972afSPatrick Mooney 
65*069b2ef0SAndy Fiddaman #if defined(__cplusplus) && __cplusplus >= 201103L
66*069b2ef0SAndy Fiddaman #define	_Noreturn		[[noreturn]]
67*069b2ef0SAndy Fiddaman #else
68*069b2ef0SAndy Fiddaman #define	_Noreturn		__dead2
69*069b2ef0SAndy Fiddaman #endif
70*069b2ef0SAndy Fiddaman 
714c87aefeSPatrick Mooney #if !__has_extension(c_static_assert)
724c87aefeSPatrick Mooney #if (defined(__cplusplus) && __cplusplus >= 201103L) || \
734c87aefeSPatrick Mooney     __has_extension(cxx_static_assert)
744c87aefeSPatrick Mooney #define _Static_assert(x, y)    static_assert(x, y)
754c87aefeSPatrick Mooney #elif __GNUC_PREREQ__(4,6)
764c87aefeSPatrick Mooney /* Nothing, gcc 4.6 and higher has _Static_assert built-in */
774c87aefeSPatrick Mooney #elif defined(__COUNTER__)
784c87aefeSPatrick Mooney #define _Static_assert(x, y)    __Static_assert(x, __COUNTER__)
794c87aefeSPatrick Mooney #define __Static_assert(x, y)   ___Static_assert(x, y)
804c87aefeSPatrick Mooney #define ___Static_assert(x, y)  typedef char __assert_ ## y[(x) ? 1 : -1] \
814c87aefeSPatrick Mooney                                 __unused
824c87aefeSPatrick Mooney #else
834c87aefeSPatrick Mooney #define _Static_assert(x, y)    struct __hack
844c87aefeSPatrick Mooney #endif
854c87aefeSPatrick Mooney #endif
864c87aefeSPatrick Mooney #define	static_assert(x, y)	_Static_assert(x, y)
874c87aefeSPatrick Mooney 
884c87aefeSPatrick Mooney #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */
89bf21cd93STycho Nightingale 
90154972afSPatrick Mooney #if __GNUC_PREREQ__(4, 1)
91154972afSPatrick Mooney #define	__offsetof(type, field)	 __builtin_offsetof(type, field)
92154972afSPatrick Mooney #else
93154972afSPatrick Mooney #ifndef __cplusplus
94154972afSPatrick Mooney #define	__offsetof(type, field) \
95154972afSPatrick Mooney 	((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field))
96154972afSPatrick Mooney #else
97154972afSPatrick Mooney #define	__offsetof(type, field)					\
98154972afSPatrick Mooney   (__offsetof__ (reinterpret_cast <__size_t>			\
99154972afSPatrick Mooney                  (&reinterpret_cast <const volatile char &>	\
100154972afSPatrick Mooney                   (static_cast<type *> (0)->field))))
101154972afSPatrick Mooney #endif
102154972afSPatrick Mooney #endif
103154972afSPatrick Mooney 
104bf21cd93STycho Nightingale #endif	/* _COMPAT_FREEBSD_SYS_CDEFS_H_ */
105