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/*
12 * Some compilers attempt to pack enums into the smallest possible type.
13 * For ABI compatibility with the kernel, we need to ensure they remain
14 * the same size as a 'long'.
15 */
16#define SEL4_FORCE_LONG_ENUM(type) \
17        _enum_pad_ ## type = (1ULL << ((sizeof(long)*8) - 1)) - 1
18
19#ifndef CONST
20#define CONST        __attribute__((__const__))
21#endif
22
23#ifndef PURE
24#define PURE         __attribute__((__pure__))
25#endif
26
27#define SEL4_OFFSETOF(type, member) __builtin_offsetof(type, member)
28
29#define SEL4_PACKED __attribute__((packed))
30
31#ifdef CONFIG_LIB_SEL4_INLINE_INVOCATIONS
32#define LIBSEL4_INLINE static inline
33#define LIBSEL4_INLINE_FUNC static inline
34
35#elif defined(CONFIG_LIB_SEL4_PUBLIC_SYMBOLS)
36#define LIBSEL4_INLINE __attribute__((unused)) __attribute__((weak))
37#define LIBSEL4_INLINE_FUNC __attribute__((unused)) __attribute__((weak))
38
39#else
40#define LIBSEL4_INLINE __attribute__((noinline)) __attribute__((unused)) __attribute__((weak))
41#define LIBSEL4_INLINE_FUNC static inline
42#endif
43
44#define LIBSEL4_UNUSED __attribute__((unused))
45
46#define SEL4_DEPRECATED(x) __attribute__((deprecated(x)))
47#define SEL4_DEPRECATE_MACRO(x) _Pragma("deprecated") x
48
49#define SEL4_COMPILE_ASSERT(name, expr) typedef int __assert_failed_##name[(expr) ? 1 : -1];
50#define SEL4_SIZE_SANITY(index, entry, size) SEL4_COMPILE_ASSERT(index##entry##size, index + entry == size)
51