xref: /illumos-gate/usr/src/compat/bhyve/sys/cdefs.h (revision 154972af)
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.
15bf21cd93STycho Nightingale  */
16bf21cd93STycho Nightingale 
17bf21cd93STycho Nightingale #ifndef _COMPAT_FREEBSD_SYS_CDEFS_H_
18bf21cd93STycho Nightingale #define	_COMPAT_FREEBSD_SYS_CDEFS_H_
19bf21cd93STycho Nightingale 
204c87aefeSPatrick Mooney /*
214c87aefeSPatrick Mooney  * Testing against Clang-specific extensions.
224c87aefeSPatrick Mooney  */
234c87aefeSPatrick Mooney #ifndef __has_extension
244c87aefeSPatrick Mooney #define	__has_extension		__has_feature
254c87aefeSPatrick Mooney #endif
264c87aefeSPatrick Mooney #ifndef __has_feature
274c87aefeSPatrick Mooney #define	__has_feature(x)	0
284c87aefeSPatrick Mooney #endif
294c87aefeSPatrick Mooney 
304c87aefeSPatrick Mooney /*
314c87aefeSPatrick Mooney  * Macro to test if we're using a specific version of gcc or later.
324c87aefeSPatrick Mooney  */
334c87aefeSPatrick Mooney #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
344c87aefeSPatrick Mooney #define __GNUC_PREREQ__(ma, mi) \
354c87aefeSPatrick Mooney 	(__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
364c87aefeSPatrick Mooney #else
374c87aefeSPatrick Mooney #define __GNUC_PREREQ__(ma, mi) 0
384c87aefeSPatrick Mooney #endif
394c87aefeSPatrick Mooney 
40bf21cd93STycho Nightingale #define	__FBSDID(s)
41bf21cd93STycho Nightingale 
42bf21cd93STycho Nightingale #ifdef	__GNUC__
434c87aefeSPatrick Mooney #define	asm		__asm
44bf21cd93STycho Nightingale #define	inline		__inline
45bf21cd93STycho Nightingale 
46bf21cd93STycho Nightingale #define	__GNUCLIKE___SECTION		1
47bf21cd93STycho Nightingale 
48bf21cd93STycho Nightingale #define	__dead2		__attribute__((__noreturn__))
49bf21cd93STycho Nightingale #define	__used		__attribute__((__used__))
50bf21cd93STycho Nightingale #define	__packed	__attribute__((__packed__))
51bf21cd93STycho Nightingale #define	__aligned(x)	__attribute__((__aligned__(x)))
52bf21cd93STycho Nightingale #define	__section(x)	__attribute__((__section__(x)))
534c87aefeSPatrick Mooney #define	__weak_symbol   __attribute__((__weak__))
54bf21cd93STycho Nightingale #endif
55bf21cd93STycho Nightingale 
564c87aefeSPatrick Mooney #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint)
574c87aefeSPatrick Mooney 
58*154972afSPatrick Mooney #if defined(__cplusplus) && __cplusplus >= 201103L
59*154972afSPatrick Mooney #define	_Alignof(x)		alignof(x)
60*154972afSPatrick Mooney #else
61*154972afSPatrick Mooney #define	_Alignof(x)		__alignof(x)
62*154972afSPatrick Mooney #endif
63*154972afSPatrick Mooney 
644c87aefeSPatrick Mooney #if !__has_extension(c_static_assert)
654c87aefeSPatrick Mooney #if (defined(__cplusplus) && __cplusplus >= 201103L) || \
664c87aefeSPatrick Mooney     __has_extension(cxx_static_assert)
674c87aefeSPatrick Mooney #define _Static_assert(x, y)    static_assert(x, y)
684c87aefeSPatrick Mooney #elif __GNUC_PREREQ__(4,6)
694c87aefeSPatrick Mooney /* Nothing, gcc 4.6 and higher has _Static_assert built-in */
704c87aefeSPatrick Mooney #elif defined(__COUNTER__)
714c87aefeSPatrick Mooney #define _Static_assert(x, y)    __Static_assert(x, __COUNTER__)
724c87aefeSPatrick Mooney #define __Static_assert(x, y)   ___Static_assert(x, y)
734c87aefeSPatrick Mooney #define ___Static_assert(x, y)  typedef char __assert_ ## y[(x) ? 1 : -1] \
744c87aefeSPatrick Mooney                                 __unused
754c87aefeSPatrick Mooney #else
764c87aefeSPatrick Mooney #define _Static_assert(x, y)    struct __hack
774c87aefeSPatrick Mooney #endif
784c87aefeSPatrick Mooney #endif
794c87aefeSPatrick Mooney #define	static_assert(x, y)	_Static_assert(x, y)
804c87aefeSPatrick Mooney 
814c87aefeSPatrick Mooney #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */
82bf21cd93STycho Nightingale 
83*154972afSPatrick Mooney #if __GNUC_PREREQ__(4, 1)
84*154972afSPatrick Mooney #define	__offsetof(type, field)	 __builtin_offsetof(type, field)
85*154972afSPatrick Mooney #else
86*154972afSPatrick Mooney #ifndef __cplusplus
87*154972afSPatrick Mooney #define	__offsetof(type, field) \
88*154972afSPatrick Mooney 	((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field))
89*154972afSPatrick Mooney #else
90*154972afSPatrick Mooney #define	__offsetof(type, field)					\
91*154972afSPatrick Mooney   (__offsetof__ (reinterpret_cast <__size_t>			\
92*154972afSPatrick Mooney                  (&reinterpret_cast <const volatile char &>	\
93*154972afSPatrick Mooney                   (static_cast<type *> (0)->field))))
94*154972afSPatrick Mooney #endif
95*154972afSPatrick Mooney #endif
96*154972afSPatrick Mooney 
97bf21cd93STycho Nightingale #endif	/* _COMPAT_FREEBSD_SYS_CDEFS_H_ */
98