My Project
Loading...
Searching...
No Matches
macros.h
Go to the documentation of this file.
1#ifndef X86_MATANEL_MACROS_H
2#define X86_MATANEL_MACROS_H
3#include <stdint.h>
4
10#ifndef CONTAINING_RECORD
11#define CONTAINING_RECORD(ptr, type, member) \
12 ((type *)((char *)(ptr) - offsetof(type, member)))
13#endif
14
15#undef SIZE_T_MAX
16#ifndef SIZE_T_MAX
17#define SIZE_T_MAX (size_t)-1
18#endif
19
20#undef UINT64_T_MAX
21#ifndef UINT64_T_MAX
22#define UINT64_T_MAX (uint64_t)-1
23#endif
24
25extern uint8_t kernel_start;
26#define LK_KERNEL_START &kernel_start
27
28extern uint8_t kernel_end;
29#define LK_KERNEL_END &kernel_end
30
31#define LK_KERNEL_SIZE (LK_KERNEL_END - LK_KERNEL_START)
32
33#define MAX(a, b) (((a) > (b)) ? (a) : (b))
34
35#if defined __GNUC__
36#define RETADDR(level) __builtin_return_address(level)
37#else
38#define RETADDR(level) (void)(level)
39#endif
40
41// 'likely' hints to the compiler that the condition is expected to be true most of the time.
42// It allows the compiler to optimize branch prediction.
43#define likely(x) __builtin_expect(!!(x), 1)
44
45// 'unlikely' hints to the compiler that the condition is expected to be false most of the time.
46// Useful for error handling or rare cases.
47#define unlikely(x) __builtin_expect(!!(x), 0)
48
49#define FREEZE() __cli(); __hlt()
50
51#if !defined(__GNUC__)
52#define FIELD_OFFSET(t,f) ((uint32_t)(uint32_t*)&(((t*) 0)->f))
53#else
54#define FIELD_OFFSET(t,f) ((uint32_t)__builtin_offsetof(t,f))
55#endif
56
57#endif
uint8_t kernel_start
uint8_t kernel_end