1 /*
2  * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3  *
4  * SPDX-License-Identifier: BSD-2-Clause
5  */
6 
7 #pragma once
8 
9 #include <autoconf.h>
10 
11 #ifndef CONST
12 #define CONST   __attribute__((__const__))
13 #endif
14 
15 #ifndef PURE
16 #define PURE    __attribute__((__pure__))
17 #endif
18 
19 #define SEL4_PACKED             __attribute__((packed))
20 #define SEL4_DEPRECATED(x)      __attribute__((deprecated(x)))
21 #define SEL4_DEPRECATE_MACRO(x) _Pragma("deprecated") x
22 #define SEL4_OFFSETOF(type, member) __builtin_offsetof(type, member)
23 
24 #define LIBSEL4_UNUSED          __attribute__((unused))
25 #define LIBSEL4_WEAK            __attribute__((weak))
26 #define LIBSEL4_NOINLINE        __attribute__((noinline))
27 
28 
29 #ifdef CONFIG_LIB_SEL4_INLINE_INVOCATIONS
30 
31 #define LIBSEL4_INLINE          static inline
32 #define LIBSEL4_INLINE_FUNC     static inline
33 
34 #elif defined(CONFIG_LIB_SEL4_PUBLIC_SYMBOLS)
35 
36 #define LIBSEL4_INLINE          LIBSEL4_UNUSED LIBSEL4_WEAK
37 #define LIBSEL4_INLINE_FUNC     LIBSEL4_UNUSED LIBSEL4_WEAK
38 
39 #else
40 
41 #define LIBSEL4_INLINE          LIBSEL4_NOINLINE LIBSEL4_UNUSED LIBSEL4_WEAK
42 #define LIBSEL4_INLINE_FUNC     static inline
43 
44 #endif
45 
46 /* _Static_assert() is a c11 feature. Since the kernel is currently compiled
47  * with c99, we have to emulate it. */
48 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
49 #define SEL4_COMPILE_ASSERT(name, expr)   _Static_assert(expr, #name);
50 #else
51 #define SEL4_COMPILE_ASSERT(name, expr) \
52     typedef int __assert_failed_##name[(expr) ? 1 : -1] LIBSEL4_UNUSED;
53 #endif
54 
55 
56 #define SEL4_SIZE_SANITY(index, entry, size) \
57     SEL4_COMPILE_ASSERT(index##_##entry##_##size, (index) + (entry) == size)
58 
59 
60 /*
61  * Some compilers attempt to pack enums into the smallest possible type.
62  * For ABI compatibility with the kernel, we need to ensure they remain
63  * the same size as a 'long'.
64  */
65 #define SEL4_FORCE_LONG_ENUM(type) \
66     _enum_pad_ ## type = ((1ULL << ((sizeof(long)*8) - 1)) - 1)
67 
68 #define LIBSEL4_BIT(n)  (1ul<<(n))
69