1 #ifndef _MAGIC_COMMON_H
2 #define _MAGIC_COMMON_H
5 #define MAGIC_PREFIX magic_
6 #define MAGIC_PREFIX_STR "magic_"
7 #define MAGIC_ASR_PREFIX magic_asr_
8 #define MAGIC_ASR_PREFIX_STR "magic_asr_"
9 #define MAGIC_NESTED_PREFIX_STR "nested_"
10 #define MAGIC_EVAL_FUNC_PREFIX "me_"
11 #define MAGIC_ANON_MEMBER_PREFIX "magic.anon"
12 #define MAGIC_STRINGREF_HAS_MAGIC_HIDDEN_PREFIX(S) \
13 ((S).startswith(MAGIC_HIDDEN_ARRAY_PREFIX) \
14 || (S).startswith(MAGIC_HIDDEN_STR_PREFIX))
16 #define MAGIC_VOID_PTR _____magic_instr_void_ptr
17 #define MAGIC_VOID_PTR_NAME "_____magic_instr_void_ptr"
18 #define MAGIC_VOID_ARRAY _____magic_instr_void_arr
19 #define MAGIC_VOID_ARRAY_NAME "_____magic_instr_void_arr"
21 #define MAGIC_VOID_PTR_TYPE _magic_void_ptr_type_ptr
22 #define MAGIC_VOID_PTR_TYPE_ID 1
23 #define MAGIC_VOID_PTR_INT_CAST_TYPE _magic_void_ptr_int_cast_type_ptr
24 #define MAGIC_VOID_PTR_INT_CAST_TYPE_ID 2
25 #define MAGIC_VOID_ARRAY_TYPE _magic_void_array_type_ptr
26 #define MAGIC_VOID_ARRAY_TYPE_ID 3
27 #define MAGIC_PTRINT_TYPE _magic_ptrint_type_ptr
28 #define MAGIC_PTRINT_TYPE_ID 4
29 #define MAGIC_PTRINT_ARRAY_TYPE _magic_ptrint_array_type_ptr
30 #define MAGIC_PTRINT_ARRAY_TYPE_ID 5
31 #define MAGIC_VOID_TYPE (MAGIC_VOID_PTR_TYPE->contained_types[0])
34 #define GLOBAL_VARS_IN_SECTION 1
36 #define GLOBAL_VARS_IN_SECTION 0
38 #define GLOBAL_VARS_SECTION_PREFIX ".gvars"
39 #define GLOBAL_VARS_SECTION_DATA GLOBAL_VARS_SECTION_PREFIX
40 #define GLOBAL_VARS_SECTION_RO (GLOBAL_VARS_SECTION_PREFIX "_ro")
42 #define MAGIC_LLVM_METADATA_SECTION "llvm.metadata"
43 #define MAGIC_DEFAULT_EXT_LIB_SECTION_REGEX "^.lib.*"
44 #define MAGIC_STATIC_FUNCTIONS_SECTION "magic_functions"
46 #define MAGIC_STATIC_VARS_SECTION_PREFIX "magic_data"
47 #define MAGIC_STATIC_VARS_SECTION_DATA MAGIC_STATIC_VARS_SECTION_PREFIX
48 #define MAGIC_STATIC_VARS_SECTION_RO (MAGIC_STATIC_VARS_SECTION_PREFIX "_ro")
50 #define MAGIC_SHADOW_VARS_SECTION_PREFIX "magic_shadow_data"
51 #define MAGIC_SHADOW_VARS_SECTION_DATA MAGIC_SHADOW_VARS_SECTION_PREFIX
52 #define MAGIC_SHADOW_VARS_SECTION_RO (MAGIC_SHADOW_VARS_SECTION_PREFIX "_ro")
54 #define UNBL_SECTION_PREFIX "unblockify"
55 #define MAGIC_SHADOW_VAR_PREFIX ".magic_shadow_"
56 #define MAGIC_HIDDEN_ARRAY_PREFIX ".arr.magic"
57 #define MAGIC_HIDDEN_STR_PREFIX ".str.magic"
59 #define MAGIC_MALLOC_VARS_SECTION_PREFIX "magic_malloc_data"
61 /* Magic configuration. */
62 #ifndef MAGIC_OUTPUT_CTL
63 #define MAGIC_OUTPUT_CTL 0
65 /* 0=disabled, 1=force no debug output, 2=force no output (for perf. testing).*/
66 #define MAGIC_CHECK_LEVEL 1
67 /* 2=extra checks, 1=standard checks, 0=no checks (for perf. testing). */
68 #define MAGIC_FLATTEN_FUNCTION_ARGS 0 /* XXX was 1 but header was not included, seems to break on variadic functions */
69 #define MAGIC_CHECK_INVARIANTS 1
70 #define MAGIC_SHRINK_TYPE_STR 1
71 #define MAGIC_MAX_NAME_LEN 64
72 #define MAGIC_MAX_TYPE_STR_LEN 256
73 #define MAGIC_MAX_RECURSIVE_TYPES 1024
74 #define MAGIC_TYPE_STR_PRINT_MAX 5000
75 #define MAGIC_TYPE_STR_PRINT_MAX_LEVEL 10
76 #define MAGIC_MAX_DEAD_DSENTRIES 10
77 #define MAGIC_MAX_DEAD_DSENTRIES_SIZE (1024 * 4 * 10)
78 #define MAGIC_NAMED_ALLOC_USE_DBG_INFO 0
79 /* 1=for more verbose dsentry naming. */
80 #define MAGIC_FORCE_ALLOC_EXT_NAMES 0
81 /* 1=to force external names for allocations made inside library functions. */
82 #define MAGIC_ABORT_ON_UNSUPPORTED_LOCAL_EXTERNAL_TYPE 0
83 /* 0=to resort to void* type when a local external type is not supported. */
84 #ifndef MAGIC_MEM_USAGE_OUTPUT_CTL
85 #define MAGIC_MEM_USAGE_OUTPUT_CTL 0
87 /* 0=disabled, 1=use call site info 2=use stacktrace */
89 #define MAGIC_INSTRUMENT_MEM_FUNCS_ASR_ONLY 0
90 #define MAGIC_INSTRUMENT_MEM_CUSTOM_WRAPPERS 1
91 #define MAGIC_INSTRUMENT_MEM_FUNCS 1
92 #define MAGIC_INSTRUMENT_STACK 1
93 #define MAGIC_FORCE_RAW_UNIONS 0
94 #define MAGIC_FORCE_RAW_BITFIELDS 0
95 #define MAGIC_FORCE_DYN_MEM_ZERO_INIT 0
96 /* 1=for accurate dsentry analysis. */
97 #define MAGIC_INDEX_DYN_LIBS 1
98 #define MAGIC_USE_DYN_MEM_WRAPPERS 1
99 #define MAGIC_USE_DYN_DL_WRAPPERS 1
100 #define MAGIC_ALLOW_DYN_MEM_WRAPPER_NESTING 1
102 /* qprof-related settings */
104 #define MAGIC_USE_QPROF_INSTRUMENTATION 0
106 #define MAGIC_USE_QPROF_INSTRUMENTATION 1
108 #define MAGIC_DEEPEST_LL_LOOP_HOOK magic_deepest_ll_loop
109 #define MAGIC_DEEPEST_LL_LIB_HOOK magic_deepest_ll_lib
110 #define MAGIC_DEEPEST_LL_LOOP_HOOK_NAME "magic_deepest_ll_loop"
111 #define MAGIC_DEEPEST_LL_LIB_HOOK_NAME "magic_deepest_ll_lib"
112 #define MAGIC_NUM_LL_TASK_CLASSES magic_num_ll_task_classes
113 #define MAGIC_NUM_LL_BLOCK_EXT_TASK_CLASSES magic_num_ll_block_ext_task_classes
114 #define MAGIC_NUM_LL_BLOCK_INT_TASK_CLASSES magic_num_ll_block_int_task_classes
115 #define MAGIC_NUM_LL_BLOCK_EXT_LIBS magic_num_ll_block_ext_libs
116 #define MAGIC_NUM_LL_BLOCK_INT_LIBS magic_num_ll_block_int_libs
117 #define MAGIC_NUM_LL_TASK_CLASSES_NAME "magic_num_ll_task_classes"
118 #define MAGIC_NUM_LL_BLOCK_EXT_TASK_CLASSES_NAME "magic_num_ll_block_ext_task_classes"
119 #define MAGIC_NUM_LL_BLOCK_INT_TASK_CLASSES_NAME "magic_num_ll_block_int_task_classes"
120 #define MAGIC_NUM_LL_BLOCK_EXT_LIBS_NAME "magic_num_ll_block_ext_libs"
121 #define MAGIC_NUM_LL_BLOCK_INT_LIBS_NAME "magic_num_ll_block_int_libs"
123 #define MAGIC_THREAD_SAFE 1
124 #define MAGIC_FORCE_LOCKS 0
125 #define MAGIC_LOOKUP_SENTRY 1
126 #define MAGIC_LOOKUP_DSENTRY 1
127 #define MAGIC_LOOKUP_FUNCTION 1
128 #define MAGIC_LOOKUP_DFUNCTION 1
129 #define MAGIC_LOOKUP_TYPE 1
130 #define MAGIC_LOOKUP_SENTRY_ALLOW_RANGE_INDEX 1
131 #define MAGIC_LOOKUP_SENTRY_ALLOW_NAME_HASH 1
132 #define MAGIC_LOOKUP_FUNCTION_ALLOW_ADDR_HASH 1
134 #define MAGIC_INDEX_INT_CAST 1
135 #define MAGIC_INDEX_FUN_PTR_INT_CAST 1
136 #define MAGIC_INDEX_STR_PTR_INT_CAST 1
137 #define MAGIC_INDEX_VOID_PTR_INT_CAST 1
138 #define MAGIC_INDEX_OTH_PTR_INT_CAST 1
140 #define MAGIC_INDEX_BIT_CAST 1
141 #define MAGIC_INDEX_TRANSITIVE_BIT_CASTS 0
142 #define MAGIC_INDEX_FUN_PTR_BIT_CAST 1
143 #define MAGIC_INDEX_STR_PTR_BIT_CAST 1
144 #define MAGIC_INDEX_VOID_PTR_BIT_CAST 0
145 #define MAGIC_INDEX_OTH_PTR_BIT_CAST 1
148 #define MAGIC_SKIP_TOVOID_PTR_BIT_CAST 0
150 #define MAGIC_SKIP_TOVOID_PTR_BIT_CAST 1
153 #define MAGIC_COMPACT_COMP_TYPES 0
155 #define MAGIC_OFF_BY_N_PROTECTION_N 0
157 #define MAGIC_VARSIZED_STRUCTS_SUPPORT 1
159 #define MAGIC_ALLOW_DEAD_DSENTRIES_DEFAULT 0
161 #define MAGIC_WALK_UNIONS_AS_VOID_ARRAYS_DEFAULT 1
163 #define MAGIC_DEBUG_SELECT(D,ND) (MAGIC_OUTPUT_CTL>=1 ? (ND) : (D))
164 #define MAGIC_OUTPUT_SELECT(D,ND,NO) \
165 (MAGIC_OUTPUT_CTL>=2 ? (NO) : MAGIC_DEBUG_SELECT(D,ND))
166 #define MAGIC_DEBUG_SET(D) MAGIC_DEBUG_SELECT(D,0)
168 #define MAGIC_ENABLED "_magic_enabled"
170 #define MAGIC_ARRAY_NAME "_magic_sentries_array"
171 #define MAGIC_TYPE_ARRAY_NAME "_magic_types_array"
172 #define MAGIC_FUNC_ARRAY_NAME "_magic_functions_array"
173 #define MAGIC_DSINDEX_ARRAY_NAME "_magic_dsindexes_array"
175 #define MAGIC_ROOT_VAR_NAME "_magic_vars_buff"
176 #define MAGIC_RSTRUCT_FIELD_ASR_SEED "asr_seed"
177 #define MAGIC_RSTRUCT_FIELD_ASR_HEAP_MAP_DO_PERMUTATE "asr_heap_map_do_permutate"
178 #define MAGIC_RSTRUCT_FIELD_ASR_HEAP_MAX_OFFSET "asr_heap_max_offset"
179 #define MAGIC_RSTRUCT_FIELD_ASR_HEAP_MAX_PADDING "asr_heap_max_padding"
180 #define MAGIC_RSTRUCT_FIELD_ASR_MAP_MAX_OFFSET_PAGES "asr_map_max_offset_pages"
181 #define MAGIC_RSTRUCT_FIELD_ASR_MAP_MAX_PADDING_PAGES "asr_map_max_padding_pages"
182 #define MAGIC_RSTRUCT_FIELD_NO_MEM_INST "no_mem_inst"
183 #define MAGIC_RSTRUCT_FIELD_TYPES "types"
184 #define MAGIC_RSTRUCT_FIELD_TYPES_NUM "types_num"
185 #define MAGIC_RSTRUCT_FIELD_TYPES_NEXT_ID "types_next_id"
186 #define MAGIC_RSTRUCT_FIELD_FUNCTIONS "functions"
187 #define MAGIC_RSTRUCT_FIELD_FUNCTIONS_NUM "functions_num"
188 #define MAGIC_RSTRUCT_FIELD_FUNCTIONS_NEXT_ID "functions_next_id"
189 #define MAGIC_RSTRUCT_FIELD_SENTRIES "sentries"
190 #define MAGIC_RSTRUCT_FIELD_SENTRIES_NUM "sentries_num"
191 #define MAGIC_RSTRUCT_FIELD_SENTRIES_STR_NUM "sentries_str_num"
192 #define MAGIC_RSTRUCT_FIELD_SENTRIES_NEXT_ID "sentries_next_id"
193 #define MAGIC_RSTRUCT_FIELD_DSINDEXES "dsindexes"
194 #define MAGIC_RSTRUCT_FIELD_DSINDEXES_NUM "dsindexes_num"
195 #define MAGIC_RSTRUCT_FIELD_FIRST_DSENTRY "first_dsentry"
196 #define MAGIC_RSTRUCT_FIELDS \
197 MAGIC_RSTRUCT_FIELD_ASR_SEED, \
198 MAGIC_RSTRUCT_FIELD_ASR_HEAP_MAP_DO_PERMUTATE, \
199 MAGIC_RSTRUCT_FIELD_ASR_HEAP_MAX_OFFSET, \
200 MAGIC_RSTRUCT_FIELD_ASR_HEAP_MAX_PADDING, \
201 MAGIC_RSTRUCT_FIELD_ASR_MAP_MAX_OFFSET_PAGES, \
202 MAGIC_RSTRUCT_FIELD_ASR_MAP_MAX_PADDING_PAGES, \
203 MAGIC_RSTRUCT_FIELD_NO_MEM_INST, \
204 MAGIC_RSTRUCT_FIELD_TYPES, \
205 MAGIC_RSTRUCT_FIELD_TYPES_NUM, \
206 MAGIC_RSTRUCT_FIELD_TYPES_NEXT_ID, \
207 MAGIC_RSTRUCT_FIELD_FUNCTIONS, \
208 MAGIC_RSTRUCT_FIELD_FUNCTIONS_NUM, \
209 MAGIC_RSTRUCT_FIELD_FUNCTIONS_NEXT_ID, \
210 MAGIC_RSTRUCT_FIELD_SENTRIES, \
211 MAGIC_RSTRUCT_FIELD_SENTRIES_NUM, \
212 MAGIC_RSTRUCT_FIELD_SENTRIES_STR_NUM, \
213 MAGIC_RSTRUCT_FIELD_SENTRIES_NEXT_ID, \
214 MAGIC_RSTRUCT_FIELD_DSINDEXES, \
215 MAGIC_RSTRUCT_FIELD_DSINDEXES_NUM, \
216 MAGIC_RSTRUCT_FIELD_FIRST_DSENTRY
218 #define MAGIC_ENTRY_POINT "main"
219 #define MAGIC_INIT_FUNC_NAME "magic_init"
220 #define MAGIC_DATA_INIT_FUNC_NAME "magic_data_init"
222 #define MAGIC_STACK_DSENTRIES_CREATE_FUNC_NAME "magic_stack_dsentries_create"
223 #define MAGIC_STACK_DSENTRIES_DESTROY_FUNC_NAME "magic_stack_dsentries_destroy"
225 #define MAGIC_GET_PAGE_SIZE_FUNC_NAME "magic_get_sys_pagesize"
227 #define MAGIC_VOID_PTR_TYPE_PTR_NAME "_magic_void_ptr_type_ptr"
229 #define MAGIC_ALLOC_NAME_SUFFIX "#"
230 #define MAGIC_ALLOC_NAME_SEP "%"
231 #define MAGIC_ALLOC_NONAME "%UNKNOWN"
232 #define MAGIC_ALLOC_EXT_NAME "%EXT"
233 #define MAGIC_ALLOC_EXT_PARENT_NAME "%EXT_PARENT"
234 #define MAGIC_ALLOC_RET_ADDR_NAME "%RET_ADDR"
235 #define MAGIC_ALLOC_INITIAL_STACK_NAME "%INITIAL_STACK_AREA"
236 #define MAGIC_OBDSENTRY_DEFAULT_PARENT_NAME "%OUT_OF_BAND_PARENT"
237 #define MAGIC_DSENTRY_DATA_SEGMENT_NAME "%LIB_DATA_SEGMENT"
238 #define MAGIC_DSENTRY_ABS_NAME_SEP "~"
239 #define MAGIC_SELEMENT_SEP "/"
240 #define MAGIC_NAME_INVALID "%INVALID"
242 #define MAGIC_SSTRUCT_FIELD_ID "id"
243 #define MAGIC_SSTRUCT_FIELD_NAME "name"
244 #define MAGIC_SSTRUCT_FIELD_TYPE "type"
245 #define MAGIC_SSTRUCT_FIELD_FLAGS "flags"
246 #define MAGIC_SSTRUCT_FIELD_ADDRESS "address"
247 #define MAGIC_SSTRUCT_FIELD_SHADOW_ADDRESS "shadow_address"
248 #define MAGIC_SSTRUCT_FIELDS \
249 MAGIC_SSTRUCT_FIELD_ID, \
250 MAGIC_SSTRUCT_FIELD_NAME, \
251 MAGIC_SSTRUCT_FIELD_TYPE, \
252 MAGIC_SSTRUCT_FIELD_FLAGS, \
253 MAGIC_SSTRUCT_FIELD_ADDRESS, \
254 MAGIC_SSTRUCT_FIELD_SHADOW_ADDRESS
256 #define MAGIC_TSTRUCT_FIELD_ID "id"
257 #define MAGIC_TSTRUCT_FIELD_NAME "name"
258 #define MAGIC_TSTRUCT_FIELD_NAMES "names"
259 #define MAGIC_TSTRUCT_FIELD_NUM_NAMES "num_names"
260 #define MAGIC_TSTRUCT_FIELD_TYPE_STR "type_str"
261 #define MAGIC_TSTRUCT_FIELD_SIZE "size"
262 #define MAGIC_TSTRUCT_FIELD_NUM_CHILD_TYPES "num_child_types"
263 #define MAGIC_TSTRUCT_FIELD_CONTAINED_TYPES "contained_types"
264 #define MAGIC_TSTRUCT_FIELD_COMPATIBLE_TYPES "compatible_types"
265 #define MAGIC_TSTRUCT_FIELD_MEMBER_NAMES "member_names"
266 #define MAGIC_TSTRUCT_FIELD_MEMBER_OFFSETS "member_offsets"
267 #define MAGIC_TSTRUCT_FIELD_VALUE_SET "value_set"
268 #define MAGIC_TSTRUCT_FIELD_TYPE_ID "type_id"
269 #define MAGIC_TSTRUCT_FIELD_FLAGS "flags"
270 #define MAGIC_TSTRUCT_FIELD_BIT_WIDTH "bit_width"
271 #define MAGIC_TSTRUCT_FIELDS \
272 MAGIC_TSTRUCT_FIELD_ID, \
273 MAGIC_TSTRUCT_FIELD_NAME, \
274 MAGIC_TSTRUCT_FIELD_NAMES, \
275 MAGIC_TSTRUCT_FIELD_NUM_NAMES, \
276 MAGIC_TSTRUCT_FIELD_TYPE_STR, \
277 MAGIC_TSTRUCT_FIELD_SIZE, \
278 MAGIC_TSTRUCT_FIELD_NUM_CHILD_TYPES, \
279 MAGIC_TSTRUCT_FIELD_CONTAINED_TYPES, \
280 MAGIC_TSTRUCT_FIELD_COMPATIBLE_TYPES, \
281 MAGIC_TSTRUCT_FIELD_MEMBER_NAMES, \
282 MAGIC_TSTRUCT_FIELD_MEMBER_OFFSETS, \
283 MAGIC_TSTRUCT_FIELD_VALUE_SET, \
284 MAGIC_TSTRUCT_FIELD_TYPE_ID, \
285 MAGIC_TSTRUCT_FIELD_FLAGS, \
286 MAGIC_TSTRUCT_FIELD_BIT_WIDTH
288 #define MAGIC_FSTRUCT_FIELD_ID "id"
289 #define MAGIC_FSTRUCT_FIELD_NAME "name"
290 #define MAGIC_FSTRUCT_FIELD_TYPE "type"
291 #define MAGIC_FSTRUCT_FIELD_FLAGS "flags"
292 #define MAGIC_FSTRUCT_FIELD_ADDRESS "address"
293 #define MAGIC_FSTRUCT_FIELDS \
294 MAGIC_FSTRUCT_FIELD_ID, \
295 MAGIC_FSTRUCT_FIELD_NAME, \
296 MAGIC_FSTRUCT_FIELD_TYPE, \
297 MAGIC_FSTRUCT_FIELD_FLAGS, \
298 MAGIC_FSTRUCT_FIELD_ADDRESS
300 #define MAGIC_DSTRUCT_FIELD_TYPE "type"
301 #define MAGIC_DSTRUCT_FIELD_NAME "name"
302 #define MAGIC_DSTRUCT_FIELD_PARENT_NAME "parent_name"
303 #define MAGIC_DSTRUCT_FIELD_FLAGS "flags"
304 #define MAGIC_DSTRUCT_FIELDS \
305 MAGIC_DSTRUCT_FIELD_TYPE, \
306 MAGIC_DSTRUCT_FIELD_NAME, \
307 MAGIC_DSTRUCT_FIELD_PARENT_NAME, \
308 MAGIC_DSTRUCT_FIELD_FLAGS
310 #define MAGIC_TYPE_ISUNION 0x01
311 #define MAGIC_TYPE_ISPADDED 0x02
314 #define MAGIC_TYPE_VOID 1
315 #define MAGIC_TYPE_FLOAT 2
316 #define MAGIC_TYPE_INTEGER 3
317 #define MAGIC_TYPE_FUNCTION 4
318 #define MAGIC_TYPE_ARRAY 5
319 #define MAGIC_TYPE_ENUM 6
320 #define MAGIC_TYPE_VECTOR 7
321 #define MAGIC_TYPE_UNION 8
322 #define MAGIC_TYPE_STRUCT 9
323 #define MAGIC_TYPE_POINTER 10
324 #define MAGIC_TYPE_OPAQUE 11
327 #define MAGIC_TYPE_EXTERNAL 0x001
328 #define MAGIC_TYPE_IS_ROOT 0x002
329 #define MAGIC_TYPE_DYNAMIC 0x004
330 #define MAGIC_TYPE_INT_CAST 0x008
331 #define MAGIC_TYPE_STRICT_VALUE_SET 0x010
332 #define MAGIC_TYPE_VARSIZE 0x020
333 #define MAGIC_TYPE_UNSIGNED 0x040
334 #define MAGIC_TYPE_NO_INNER_PTRS 0x080
336 /* State flags for sentries and functions. */
337 #define MAGIC_STATE_DIRTY 0x00000001
338 #define MAGIC_STATE_CONSTANT 0x00000002
339 #define MAGIC_STATE_DYNAMIC 0x00000004
340 #define MAGIC_STATE_DETACHED 0x00000008
341 #define MAGIC_STATE_DATA 0x00000010
342 #define MAGIC_STATE_HEAP 0x00000020
343 #define MAGIC_STATE_MAP 0x00000040
344 #define MAGIC_STATE_SHM 0x00000080
345 #define MAGIC_STATE_STACK 0x00000100
346 #define MAGIC_STATE_TEXT 0x00000200
348 #define MAGIC_STATE_LIB 0x00000400
349 /* Dynamically linked libraries. */
350 #define MAGIC_STATE_LIB_SO 0x00000800
351 /* Dynamically loaded libraries. */
352 #define MAGIC_STATE_LIB_DSO 0x00001000
353 #define MAGIC_STATE_ADDR_NOT_TAKEN 0x00002000
354 #define MAGIC_STATE_EXT 0x00004000
355 #define MAGIC_STATE_OUT_OF_BAND 0x00008000
356 #define MAGIC_STATE_STRING 0x00010000
357 #define MAGIC_STATE_NAMED_STRING 0x00020000
358 #define MAGIC_STATE_MODE_R 0x00040000
359 #define MAGIC_STATE_MODE_W 0x00080000
360 #define MAGIC_STATE_MODE_X 0x00100000
361 #define MAGIC_STATE_THREAD_LOCAL 0x00200000
362 #define MAGIC_STATE_MEMPOOL 0x00400000
363 #define MAGIC_STATE_MEMBLOCK 0x00800000
364 #define MAGIC_STATE_EXTERNAL 0x01000000
365 #define MAGIC_STATE_TYPE_SIZE_MISMATCH 0x02000000
366 #define MAGIC_STATE_IMMUTABLE 0x04000000
367 #define MAGIC_STATE_INIT 0x08000000
368 #define MAGIC_STATE_DIRTY_PAGE 0x10000000
369 /* Skip char* and void* entries in arrays */
370 #define MAGIC_STATE_SKIP_BYTE_INDICES 0x20000000
372 #define MAGIC_STATE_ANNOTATION_MASK \
373 (MAGIC_STATE_MODE_R | MAGIC_STATE_MODE_W | MAGIC_STATE_MODE_X)
375 #define MAGIC_ASR_FLAG_INIT 0x40000
377 #define MAGIC_STATE_EXTF_MASK 0xFF000000
378 #define MAGIC_STATE_EXTF_SHIFT 24
380 #define MAGIC_STATE_FLAG(E,F) (((E)->flags & (F)) != 0)
381 #define MAGIC_STATE_FLAGS(E,F) (((E)->flags & (F)) == (F))
382 #define MAGIC_STATE_FLAGS_REGION(F) \
383 ((F) & (MAGIC_STATE_DATA | MAGIC_STATE_HEAP | MAGIC_STATE_MAP \
384 | MAGIC_STATE_SHM | MAGIC_STATE_STACK | MAGIC_STATE_TEXT))
385 #define MAGIC_STATE_FLAGS_LIBSPEC(F) \
386 ((F) & (MAGIC_STATE_LIB | MAGIC_STATE_LIB_SO | MAGIC_STATE_LIB_DSO))
387 #define MAGIC_STATE_REGION(E) MAGIC_STATE_FLAGS_REGION((E)->flags)
388 #define MAGIC_STATE_LIBSPEC(E) MAGIC_STATE_FLAGS_LIBSPEC((E)->flags)
389 #define MAGIC_STATE_FLAGS_REGION_C(F) \
390 (((F) & MAGIC_STATE_DATA) ? 'D' : ((F) & MAGIC_STATE_HEAP) ? 'H' \
391 : ((F) & MAGIC_STATE_SHM) ? 'X' : ((F) & MAGIC_STATE_MAP) ? 'M' \
392 : ((F) & MAGIC_STATE_STACK) ? 'S' : ((F) & MAGIC_STATE_TEXT) ? 'T' : '?')
393 #define MAGIC_STATE_FLAGS_LIBSPEC_C(F) \
394 (((F) & MAGIC_STATE_LIB) ? (((F) & MAGIC_STATE_LIB_SO) ? 'l' \
395 : ((F) & MAGIC_STATE_LIB_DSO) ? 'o' : 'L') : '0')
396 #define MAGIC_STATE_REGION_C(E) MAGIC_STATE_FLAGS_REGION_C((E)->flags)
397 #define MAGIC_STATE_LIBSPEC_C(E) MAGIC_STATE_FLAGS_LIBSPEC_C((E)->flags)
399 #define MAGIC_STATE_IS_EXTF(F) (((F) & MAGIC_STATE_EXTF_MASK) == (F))
400 #define MAGIC_STATE_FLAGS_TO_EXTF(F) \
401 (((F) & MAGIC_STATE_EXTF_MASK) >> MAGIC_STATE_EXTF_SHIFT)
402 #define MAGIC_STATE_FLAGS_TO_NONEXTF(F) ((F) & (~MAGIC_STATE_EXTF_MASK))
403 #define MAGIC_STATE_EXTF_TO_FLAGS(F) \
404 (((F) << MAGIC_STATE_EXTF_SHIFT) & MAGIC_STATE_EXTF_MASK)
405 #define MAGIC_STATE_EXTF_FLAG(E,F) (MAGIC_STATE_EXTF_GET(E,F) != 0)
406 #define MAGIC_STATE_EXTF_GET(E,F) \
407 ((MAGIC_STATE_FLAGS_TO_EXTF((E)->flags) & (F)))
408 #define MAGIC_STATE_EXTF_ADD(E,F) \
409 ((E)->flags |= MAGIC_STATE_EXTF_TO_FLAGS(F))
410 #define MAGIC_STATE_EXTF_DEL(E,F) \
411 ((E)->flags &= ~MAGIC_STATE_EXTF_TO_FLAGS(F))
412 #define MAGIC_STATE_EXTF_SET(E,F) \
414 MAGIC_STATE_EXTF_CLEAR(E); \
415 (E)->flags |= MAGIC_STATE_EXTF_TO_FLAGS(F); \
417 #define MAGIC_STATE_EXTF_CLEAR(E) ((E)->flags &= ~MAGIC_STATE_EXTF_MASK)
420 #define MAGIC_CALL_ANNOTATION_VAR _magic_call_annotation_var
421 #define MAGIC_CALL_ANNOTATION_VAR_NAME "_magic_call_annotation_var"
422 #define MAGIC_CALL_ANNOTATE(C, VALUE) \
423 do { C; MAGIC_CALL_ANNOTATION_VAR = VALUE; } while(0)
424 #define MAGIC_CALL_MEM_SKIP_INSTRUMENTATION 0x01
426 #define MAGIC_VAR_ANNOTATION_PREFIX_NAME "_magic_var_annotation_"
428 #define MAGIC_VAR_ANNOTATE(T,V,A) \
430 volatile int _magic_var_annotation_ ## V = A
431 #define MAGIC_VAR_INIT_ANNOTATE(T,V,I,A) \
433 volatile int _magic_var_annotation_ ## V = A
435 #define MAGIC_MEMCPY_FUNC_NAME "memcpy"
436 #define MAGIC_MALLOC_FUNC_NAME "malloc"
438 /* Magic memory pool management functions. */
439 #define MAGIC_MEMPOOL_BLOCK_ALLOC_TEMPLATE_FUNC_NAME \
440 "mempool_block_alloc_template"
442 /* Wrapper functions. */
443 #define MAGIC_MEMPOOL_CREATE_FUNCS \
444 __X(magic_mempool_create_begin), __X(magic_mempool_create_end)
445 #define MAGIC_MEMPOOL_DESTROY_FUNCS \
446 __X(magic_mempool_destroy_begin), __X(magic_mempool_destroy_end)
447 #define MAGIC_MEMPOOL_MGMT_FUNCS \
448 __X(magic_mempool_mgmt_begin), __X(magic_mempool_mgmt_end)
449 #define MAGIC_MEMPOOL_RESET_FUNCS \
450 __X(magic_mempool_reset_begin), __X(magic_mempool_mgmt_end)
451 #define MAGIC_MEMPOOL_FUNCS \
452 MAGIC_MEMPOOL_CREATE_FUNCS, \
453 MAGIC_MEMPOOL_DESTROY_FUNCS, \
454 MAGIC_MEMPOOL_MGMT_FUNCS, \
455 MAGIC_MEMPOOL_RESET_FUNCS
457 #define MAGIC_MEMPOOL_CREATE_FUNC_NAMES MAGIC_MEMPOOL_CREATE_FUNCS, ""
458 #define MAGIC_MEMPOOL_DESTROY_FUNC_NAMES MAGIC_MEMPOOL_DESTROY_FUNCS, ""
459 #define MAGIC_MEMPOOL_MGMT_FUNC_NAMES MAGIC_MEMPOOL_MGMT_FUNCS, ""
460 #define MAGIC_MEMPOOL_RESET_FUNC_NAMES MAGIC_MEMPOOL_RESET_FUNCS, ""
461 #define MAGIC_MEMPOOL_FUNC_NAMES MAGIC_MEMPOOL_FUNCS, ""
463 /* Flags for inlining wrapper calls. */
464 #define MAGIC_PRE_HOOK_SIMPLE_CALL 0x0001
465 #define MAGIC_PRE_HOOK_FORWARDING_CALL 0x0002
466 #define MAGIC_POST_HOOK_SIMPLE_CALL 0x0004
467 #define MAGIC_POST_HOOK_FORWARDING_CALL 0x0008
468 #define MAGIC_PRE_HOOK_DEBUG 0x0010
469 #define MAGIC_POST_HOOK_DEBUG 0x0020
470 #define MAGIC_PRE_HOOK_FLAGS_MASK \
471 (MAGIC_PRE_HOOK_SIMPLE_CALL | MAGIC_PRE_HOOK_FORWARDING_CALL)
472 #define MAGIC_POST_HOOK_FLAGS_MASK \
473 (MAGIC_POST_HOOK_SIMPLE_CALL | MAGIC_POST_HOOK_FORWARDING_CALL)
474 #define MAGIC_HOOK_DEBUG_MASK \
475 (MAGIC_PRE_HOOK_DEBUG | MAGIC_POST_HOOK_DEBUG)
477 #if (MAGIC_MEM_USAGE_OUTPUT_CTL == 1)
478 #define MAGIC_MEMPOOL_CREATE_FUNC_FLAGS MAGIC_PRE_HOOK_SIMPLE_CALL | MAGIC_POST_HOOK_FORWARDING_CALL | MAGIC_PRE_HOOK_DEBUG
480 #define MAGIC_MEMPOOL_CREATE_FUNC_FLAGS MAGIC_PRE_HOOK_SIMPLE_CALL | MAGIC_POST_HOOK_FORWARDING_CALL
482 #define MAGIC_MEMPOOL_DESTROY_FUNC_FLAGS \
483 MAGIC_PRE_HOOK_FORWARDING_CALL | MAGIC_POST_HOOK_SIMPLE_CALL
484 #define MAGIC_MEMPOOL_MGMT_FUNC_FLAGS \
485 MAGIC_PRE_HOOK_FORWARDING_CALL | MAGIC_POST_HOOK_SIMPLE_CALL
486 #define MAGIC_MEMPOOL_RESET_FUNC_FLAGS \
487 MAGIC_PRE_HOOK_FORWARDING_CALL | MAGIC_POST_HOOK_SIMPLE_CALL
488 #define MAGIC_MEMPOOL_FUNC_FLAGS \
489 MAGIC_MEMPOOL_CREATE_FUNC_FLAGS, \
490 MAGIC_MEMPOOL_DESTROY_FUNC_FLAGS, \
491 MAGIC_MEMPOOL_MGMT_FUNC_FLAGS, \
492 MAGIC_MEMPOOL_RESET_FUNC_FLAGS
494 #define MAGIC_CHECKPOINT_ENABLED "_magic_checkpoint_enabled"
495 #define MAGIC_CHECKPOINT_FUNC_NAME "sef_receive_status"
497 #define MAGIC_SHADOW_FUNC_PREFIX "llvm_shadow"
499 #define MAGIC_LAZY_CHECKPOINT_ENABLED "_magic_lazy_checkpoint_enabled"
500 #define MAGIC_LAZY_CHECKPOINT_CLEARDF_FUNC_NAME "sef_receive_status"
502 #define MAGIC_LAZY_CHECKPOINT_SHADOW_TAG "llvm_shadow"
504 /* Magic memory functions. */
505 #define MAGIC_MEMA_FUNCS \
506 __X(malloc), __X(calloc), __X(realloc), \
507 __X(posix_memalign), __X(valloc), __X(memalign), \
509 __X(brk), __X(sbrk), \
512 #define MAGIC_MEMA_FUNC_ALLOC_FLAGS \
513 MAGIC_STATE_HEAP, MAGIC_STATE_HEAP, MAGIC_STATE_HEAP, \
514 MAGIC_STATE_HEAP, MAGIC_STATE_HEAP, MAGIC_STATE_HEAP, \
516 MAGIC_STATE_HEAP, MAGIC_STATE_HEAP, \
521 #define MAGIC_MEMA_EXTRA_FUNCS , __X(vm_map_cacheblock)
522 #define MAGIC_MEMA_EXTRA_FUNC_ALLOC_FLAGS , MAGIC_STATE_MAP
524 #define MAGIC_MEMA_EXTRA_FUNCS
525 #define MAGIC_MEMA_EXTRA_FUNC_ALLOC_FLAGS
528 #define MAGIC_MEMD_FUNCS \
529 __X(free), __X(munmap), __X(shmdt)
530 #define MAGIC_MEMD_FUNC_ALLOC_FLAGS \
533 #define MAGIC_MEM_FUNCS MAGIC_MEMA_FUNCS MAGIC_MEMA_EXTRA_FUNCS, MAGIC_MEMD_FUNCS
534 #define MAGIC_MEM_UNS_FUNCS \
535 __X(mmap2), __X(remap_file_pages), __X(mremap)
536 #define MAGIC_MEM_FUNC_ALLOC_FLAGS \
537 MAGIC_MEMA_FUNC_ALLOC_FLAGS MAGIC_MEMA_EXTRA_FUNC_ALLOC_FLAGS, MAGIC_MEMD_FUNC_ALLOC_FLAGS
540 /* Nested allocation functions to hook. That is, functions that are being
541 * called as part of allocation functions - in particular, malloc - and need to
542 * be intercepted for tracking purposes - in particular, so that mmap'ed malloc
543 * page directories can be unmapped in order to avoid memory leaks. MINIX3 only.
545 #define MAGIC_MEMN_FUNCS \
546 __X(mmap), __X(munmap)
548 #define MAGIC_MEMN_FUNCS ""
551 #define MAGIC_DL_FUNCS \
552 __X(dlopen), __X(dlclose)
554 #define MAGIC_MEMA_FUNC_NAMES MAGIC_MEMA_FUNCS MAGIC_MEMA_EXTRA_FUNCS, ""
555 #define MAGIC_MEMD_FUNC_NAMES MAGIC_MEMD_FUNCS, ""
556 #define MAGIC_MEMN_FUNC_NAMES MAGIC_MEMN_FUNCS, ""
557 #define MAGIC_MEM_FUNC_NAMES MAGIC_MEM_FUNCS, ""
558 #define MAGIC_DL_FUNC_NAMES MAGIC_DL_FUNCS, ""
560 #if MAGIC_INSTRUMENT_MEM_FUNCS_ASR_ONLY
561 #define MAGIC_MEM_PREFIX_STRS MAGIC_ASR_PREFIX_STR, MAGIC_PREFIX_STR, ""
563 #define MAGIC_MEM_PREFIX_STRS MAGIC_PREFIX_STR, ""
566 #endif /* _MAGIC_COMMON_H */