20#ifndef KERNEL_COMPILER_H
21#define KERNEL_COMPILER_H
33#define DEPRECATED __attribute__((deprecated))
35#define NORETURN __attribute__((noreturn))
37#define PURE __attribute__((pure))
40#define CONST __attribute__((const))
42#define ALWAYS_INLINE __attribute__((always_inline))
44#define NEVER_INLINE __attribute__((noinline))
46#define ALIGN(x) __attribute__((aligned(x)))
48#define PACKED __attribute__((packed))
50#define MAY_ALIAS __attribute__((may_alias))
52#define CONSTRUCTOR __attribute__((constructor))
54#define LIKELY(exp) __builtin_expect(!!(exp), 1)
56#define UNLIKELY(exp) __builtin_expect(!!(exp), 0)
58#define UNREACHABLE __builtin_unreachable()
60#define FORMAT(type, idx, first) __attribute__((format(type, idx, first)))
62#define IS_CONSTANT(x) __builtin_constant_p(x)
67#define SECTION(x) __attribute__((__section__(x)))
70#define MUST_USE_RESULT __attribute__((warn_unused_result))
72#define USED __attribute__((used))
74#define WEAK __attribute__((weak))
76#if defined(__GNUC__) && __GNUC__ >= 7
77#define FALLSTHROUGH __attribute__((fallthrough));
83#define MALLOC __attribute__((malloc))
85#define ALLOC_SIZE(...) __attribute__((alloc_size(__VA_ARGS__)))
87#define C_NOTHROW __attribute__((nothrow))
89#define EMIT_IF(...) if constexpr (__VA_ARGS__)
95#define EXPORTED_PUBLIC __attribute__((visibility("default")))
96#define SYMBOL_HIDDEN __attribute__((visibility("hidden")))
100#define __has_builtin(x) 0
104#define __has_feature(x) 0
107#if __has_builtin(__builtin_assume_aligned) || !defined(__clang__)
108#define ASSUME_ALIGNMENT(b, sz) __builtin_assume_aligned((b), sz)
110#define ASSUME_ALIGNMENT(b, sz) \
111 ((reinterpret_cast<uintptr_t>(b) % (sz)) == 0) ? (b) : (UNREACHABLE, (b))
116#define INITIALISATION_ONLY SECTION(".init.text")
117#define INITIALISATION_ONLY_DATA SECTION(".init.data")
121#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer) || \
122 __has_feature(memory_sanitizer)
123#define HAS_ADDRESS_SANITIZER 1
125#define HAS_ADDRESS_SANITIZER 0
128#if defined(__SANITIZE_THREAD__) || __has_feature(thread_sanitizer)
129#define HAS_THREAD_SANITIZER 1
131#define HAS_THREAD_SANITIZER 0
134#if HAS_ADDRESS_SANITIZER || HAS_THREAD_SANITIZER
135#define HAS_SANITIZERS 1
139#define NOT_COPY_CONSTRUCTIBLE(Type) Type(const Type&) = delete
140#define NOT_ASSIGNABLE(Type) Type& operator=(const Type&) = delete
141#define NOT_COPYABLE_OR_ASSIGNABLE(Type) \
142 NOT_COPY_CONSTRUCTIBLE(Type); \
145#define WITHOUT_IMPLICIT_CONSTRUCTORS(Type) \
147 NOT_COPYABLE_OR_ASSIGNABLE(Type)
151#define BARRIER() __asm__ __volatile__("" ::: "memory")
154#define FENCE() __sync_synchronize()
157#include "pedigree/kernel/utilities/threadsafety.h"