kernel
Loading...
Searching...
No Matches
annotations.h
Go to the documentation of this file.
1#ifndef X86_ANNOTATIONS_H
2#define X86_ANNOTATIONS_H
3
4// Annotations (and macros) for documentation, and potential future analyzing.
5// These are almost all for the compiler to decide how the variable, function, code blocks (etc), would execute.
6
7// Parameter Annotations
8#define IN // Takes REQUIRED INPUT
9#define OUT // Supplies REQUIRED OUTPUT
10#define _In_Opt // Optional input (NULL allowed)
11#define _Out_Opt // Optional output (NULL allowed)
12
13// Function will not return.
14#define NORETURN __attribute__((noreturn))
15
16// Function will be forcefully inlined by the compiler.
17#ifndef FORCEINLINE
18#if defined(__clang__) || defined(__GNUC__)
19#define FORCEINLINE static inline __attribute__((always_inline))
20#elif defined(_MSC_VER)
21#define FORCEINLINE static __forceinline
22#else
23#define FORCEINLINE static inline
24#endif
25#endif
26
27// Function will be forcefully inlined by the compiler. (between translation files)
28#ifndef FORCEINLINE_NOHEADER
29#if defined(__clang__) || defined(__GNUC__)
30#define FORCEINLINE_NOHEADER __attribute__((always_inline))
31#elif defined(_MSC_VER)
32#define FORCEINLINE_NOHEADER __forceinline
33#else
34#define FORCEINLINE_NOHEADER inline
35#endif
36#endif
37
38// Function / Object is signaled as used, even though it is not used in any translation unit.
39#define USED __attribute__((used))
40
41// Caller MUST use return value (e.g., pool allocation, status codes)
42#define MUST_USE_RESULT __attribute__((warn_unused_result))
43
44// Function is cold (unlikely to be executed)
45#define COLD __attribute__((cold))
46
47// Function is hot (frequently executed)
48#define HOT __attribute__((hot))
49
50// Object or type is packed (no padding)
51#define PACKED __attribute__((packed))
52
53// Emit compile-time error if condition is false
54#define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
55
56// Force a compile-time warning
57#define COMPILE_WARNING(msg) __attribute__((warning(msg)))
58
59// Force a compile-time error
60#define COMPILE_ERROR(msg) __attribute__((error(msg)))
61
62// SysV ABI (explicit) (always used in this kernel)
63#define SYSV_ABI __attribute__((sysv_abi))
64
65// MS ABI (for interop)
66#define MS_ABI __attribute__((ms_abi))
67
68// Prevent function from being inlined
69#define NOINLINE __attribute__((noinline))
70
71// Execution must never reach this point, reaching it is undefined behavior.
72#define UNREACHABLE_CODE() __builtin_unreachable()
73
74// Ensures the size of struct 'struc' must be 'size' size in bytes.
75#define VALIDATE_SIZE(struc, size) _Static_assert(sizeof(struc) == size, "Invalid structure size of " #struc)
76
77// Ensures the offset of 'member' field in the struct 'struc', must be 'offset' bytes from the start.
78#define VALIDATE_OFFSET(struc, member, offset) _Static_assert(offsetof(struc, member) == offset, "The offset of " #member " in " #struc " is not " #offset "...")
79
80#endif