4 #if defined(_MINIX) || defined(_MINIX_SYSTEM)
14 #define MAGIC_LONG_LONG_SUPPORTED 1
15 #define MAGIC_LONG_DOUBLE_SUPPORTED 0
18 #define MAGIC_LONG_LONG_SUPPORTED 1
21 #define MAGIC_LONG_DOUBLE_SUPPORTED 1
25 /* Modifier macros. */
27 #define PRIVATE static
35 #define INLINE __inline__
38 #define FUNCTION_BLOCK(B) B
41 #define THREAD_LOCAL __thread
43 #define FUNCTION_BLOCK(B) extern "C"{ B }
45 #define FUNCTION_BLOCK(B) B
49 #define UNUSED(VAR) VAR __attribute__((unused))
50 #define USED __attribute__((used))
51 #define VOLATILE volatile
54 #define MAGIC_VAR USED
55 #define MAGIC_FUNC PUBLIC USED __attribute__((noinline))
56 #define MAGIC_FUNC_BODY() __asm__("")
57 #define MAGIC_HOOK PUBLIC USED __attribute__((always_inline)) inline
58 #define MAGIC_MACRO_FUNC static __attribute__((always_inline))
64 #define SYS_PAGESIZE 4096
66 #define SYS_PAGESIZE sysconf(_SC_PAGESIZE)
68 #define MAGIC_ROUND_DOWN(val, round) ((val) & ~((round) - 1))
69 #define MAGIC_ROUND_UP(val, round) (MAGIC_ROUND_DOWN(val, round) == \
70 (val) ? (val) : MAGIC_ROUND_DOWN((val) + (round), (round)))
71 #define MAGIC_ROUND_DOWN_TO_PAGESIZE(addr) MAGIC_ROUND_DOWN(addr, SYS_PAGESIZE)
72 #define MAGIC_ROUND_UP_TO_PAGESIZE(addr) MAGIC_ROUND_UP(addr, SYS_PAGESIZE)
75 #define _MAGIC_CAS(P, O, N) (*(P) == (O) ? *(P)=(N) : (N)+1)
76 #define MAGIC_CAS(P, O, N) (_MAGIC_CAS(P, O, N) == (N) ? (O) : *(P))
77 #define _MAGIC_PCAS(P, O, N) (*(P) == (O) ? *(P)=(N) : (void *)((intptr_t)(N)+1))
78 #define MAGIC_PCAS(P, O, N) (_MAGIC_PCAS(P, O, N) == (N) ? (O) : *(P))
79 #define MAGIC_FAA(P, V) (((*P)+=V)-V)
80 #define MAGIC_FAS(P, V) (((*P)-=V)+V)
82 #define MAGIC_CAS(P, O, N) __sync_val_compare_and_swap((P), (O), (N))
83 #define MAGIC_PCAS(P, O, N) MAGIC_CAS(P, O, N)
84 #define MAGIC_FAA(P, V) __sync_fetch_and_add(P, V)
85 #define MAGIC_FAS(P, V) __sync_fetch_and_sub(P, V)
88 /* Magic arch-specific macros. */
89 #define MAGIC_FRAMEADDR_TO_RETADDR_PTR(F) (((char*)(F))+4)
92 #define MAGIC_LINKER_VAR_NAMES "end", "etext", "edata", NULL
95 #define MAGIC_TEXT_START ((void*)(0x1000))
96 #define MAGIC_STACK_GAP (4*1024)
98 #define MAGIC_TEXT_START ((void*)(0x08048000))
99 #define MAGIC_STACK_GAP (4*1024*1024)
102 #define MAGIC_TEXT_END 0 /* 0 if right before data. */
103 #define MAGIC_HEAP_START 0 /* 0 if right after data. */
104 #define MAGIC_HEAP_GAP (4*1024)
105 #define MAGIC_RANGE_ROUND_DATA 1
106 #define MAGIC_RANGE_ROUND_TEXT 1
107 #define MAGIC_RANGE_ROUND_STACK 1
110 #define MAGIC_ID_NONE 0
111 #define MAGIC_ID_FORCE_LONG 1
112 #if defined(__MINIX) || MAGIC_ID_FORCE_LONG
113 typedef unsigned long _magic_id_t
;
114 #define MAGIC_ID_MAX ULONG_MAX
115 #define MAGIC_ID_FORMAT "%lu"
117 typedef unsigned long long _magic_id_t
;
118 #define MAGIC_ID_MAX ULLONG_MAX
119 #define MAGIC_ID_FORMAT "%llu"
122 /* Magic error codes. */
123 #define MAGIC_ENOENT (-100)
124 #define MAGIC_EBADENT (-101)
125 #define MAGIC_EBADMSTATE (-102)
126 #define MAGIC_EINVAL (-103)
127 #define MAGIC_EGENERIC (-104)
128 #define MAGIC_EBADWALK (-105)
129 #define MAGIC_ERANGE (-106)
130 #define MAGIC_ESIGN (-107)
131 #define MAGIC_ENOMEM (-108)
132 #define MAGIC_ENOPTR ((void*)-1)
135 * Basic return type definitions. Not really needed, but they make
136 * the code easier to read.
147 #define MAGIC_PRINTF_DEFAULT printf
149 #define MAGIC_PRINTF_DEFAULT magic_err_printf
154 typedef int (*printf_ptr_t
) (char const *str
, ...);
155 EXTERN printf_ptr_t _magic_printf
;
156 EXTERN
void magic_assert_failed(const char *assertion
, const char *file
,
157 const char *function
, const int line
);
161 /* assert() override. */
162 #define ENABLE_ASSERTIONS 1
164 #define CUSTOM_ASSERTIONS 0
166 #define CUSTOM_ASSERTIONS 1
171 #if CUSTOM_ASSERTIONS
175 #ifndef __ASSERT_FUNCTION
176 #define __ASSERT_FUNCTION ""
179 #if ENABLE_ASSERTIONS
180 #define assert(X) do{ \
182 magic_assert_failed(#X, __FILE__, __ASSERT_FUNCTION, __LINE__); \