1 #ifndef _MAGIC_STRUCTS_H
2 #define _MAGIC_STRUCTS_H
5 #include <magic_common.h>
7 #include <common/ut/uthash.h>
9 /* Magic state type struct. */
17 unsigned num_child_types
;
18 struct _magic_type
**contained_types
;
19 struct _magic_type
**compatible_types
;
20 const char **member_names
;
21 unsigned *member_offsets
;
29 /* Magic state entry struct. */
30 struct _magic_sentry
{
33 struct _magic_type
*type
;
39 /* Magic state entry list struct. */
40 struct _magic_sentry_list
{
41 struct _magic_sentry
*sentry
;
42 struct _magic_sentry_list
*next
;
45 /* Magic state entry hash struct. */
46 #define MAGIC_SENTRY_NAME_MAX_KEY_LEN 512
47 struct _magic_sentry_hash
{
48 struct _magic_sentry_list
*sentry_list
;
49 char key
[MAGIC_SENTRY_NAME_MAX_KEY_LEN
];
53 /* Magic state function struct. */
54 struct _magic_function
{
57 struct _magic_type
*type
;
62 /* Magic state function hash struct. */
63 struct _magic_function_hash
{
64 struct _magic_function
*function
;
69 /* Magic dynamic function struct. */
70 struct _magic_dfunction
{
71 unsigned long magic_number
;
72 const char *parent_name
;
73 struct _magic_function function
;
74 struct _magic_dfunction
*prev
;
75 struct _magic_dfunction
*next
;
78 /* Magic dynamic state index struct. */
79 struct _magic_dsindex
{
80 struct _magic_type
*type
;
82 const char *parent_name
;
86 /* Magic dynamic state entry struct. */
87 #define MAGIC_DSENTRY_ALLOW_PREV 0
89 * The name of an externally allocated dsentry will be:
90 * strlen("MAGIC_EXT_ALLOC_NAME") + strlen("MAGIC_ALLOC_NAME_SEP") +
91 * strlen(0xffffffff) + strlen("MAGIC_ALLOC_NAME_SUFFIX") + 1 =
92 * 4 + 1 + 10 + 1 + 1 = 17
94 #define MAGIC_DSENTRY_EXT_NAME_BUFF_SIZE 17
96 struct _magic_dsentry
{
97 unsigned long magic_number
;
98 const char *parent_name
;
99 char name_ext_buff
[MAGIC_DSENTRY_EXT_NAME_BUFF_SIZE
];
100 struct _magic_sentry sentry
;
101 struct _magic_type type
;
102 struct _magic_type
*type_array
[1];
103 #if MAGIC_DSENTRY_ALLOW_PREV
104 struct _magic_dsentry
*prev
;
106 struct _magic_dsentry
*next
;
107 struct _magic_dsentry
*next_mpool
;
108 struct _magic_dsentry
*next_mblock
;
110 * The following 2 fields are only set if the dsentry
111 * is part of a super object.
112 * See llvm/shared/magic/libst/include/heap.h for more details.
115 struct _magic_dsentry
*next_sobject
;
116 void *sobject_base_addr
;
119 unsigned long magic_state
;
120 union __alloc_flags
{
125 #define mmap_flags mmap_call.flags
126 #define mmap_prot mmap_call.prot
131 #define shmat_flags shmat_call.flags
132 #define shmat_shmid shmat_call.shmid
134 #define alloc_mmap_flags alloc_flags.mmap_call.flags
135 #define alloc_mmap_prot alloc_flags.mmap_call.prot
136 #define alloc_shmat_flags alloc_flags.shmat_call.flags
137 #define alloc_shmat_shmid alloc_flags.shmat_call.shmid
138 _magic_id_t site_id
; /* Identifier of the call at a callsite. */
141 /* Magic out-of-band dynamic state entry struct. */
142 #define MAGIC_MAX_OBDSENTRIES 32
143 #define MAGIC_MAX_OBDSENTRY_NAME_LEN 32
144 #define MAGIC_MAX_OBDSENTRY_PARENT_NAME_LEN 32
145 struct _magic_obdsentry
{
146 char name
[MAGIC_MAX_OBDSENTRY_NAME_LEN
];
147 char parent_name
[MAGIC_MAX_OBDSENTRY_PARENT_NAME_LEN
];
148 struct _magic_dsentry dsentry
;
150 EXTERN
struct _magic_obdsentry _magic_obdsentries
[MAGIC_MAX_OBDSENTRIES
];
152 /* Magic memory pool state struct. */
153 #define MAGIC_MAX_MEMPOOLS 1024
154 #define MAGIC_MAX_MEMPOOL_NAME_LEN 32
155 #define MAGIC_MEMPOOL_NAME_PREFIX "_magic_mempool_"
156 EXTERN
const char *const MAGIC_MEMPOOL_NAME_UNKNOWN
;
157 EXTERN
const char *const MAGIC_MEMPOOL_NAME_DETACHED
;
159 struct _magic_mpdesc
{
161 char name
[MAGIC_MAX_MEMPOOL_NAME_LEN
];
162 /* pointer to the pool object */
164 #if MAGIC_MEM_USAGE_OUTPUT_CTL
165 unsigned long dtype_id
;
168 EXTERN
struct _magic_mpdesc _magic_mpdescs
[MAGIC_MAX_MEMPOOLS
];
170 /* Magic state element. */
171 struct _magic_selement_s
{
172 struct _magic_dsentry dsentry_buff
;
173 struct _magic_sentry
*sentry
;
174 const struct _magic_type
*parent_type
;
175 void *parent_address
;
177 const struct _magic_type
*type
;
183 typedef struct _magic_selement_s _magic_selement_t
;
185 /* Magic external library descriptor. */
186 struct _magic_libdesc
{
194 /* Magic SO library descriptor. */
195 struct _magic_sodesc
{
196 struct _magic_libdesc lib
;
197 struct _magic_sodesc
*prev
;
198 struct _magic_sodesc
*next
;
201 /* Magic DSO library descriptor. */
202 struct _magic_dsodesc
{
203 struct _magic_libdesc lib
;
206 struct _magic_dsodesc
*prev
;
207 struct _magic_dsodesc
*next
;
210 /* The following constant is specific to MINIX3; on other platforms, this
211 * functionality is unused altogether. On MINIX3, the libc malloc code uses
212 * mmap to create page directories. Since malloc state is discarded upon state
213 * transfer, we must not instrument its mmap calls in the regular way. On the
214 * other hand, since mmap'ed regions are transferred to new instances, we end
215 * up with a memory leak if we do not unmap those mmap'ed regions. Therefore,
216 * we specifically track the mmap/munmap calls made from the malloc code, and
217 * explicitly unmap its regions during state transfer. The following constant
218 * defines how many ranges can be mmap'ed at once. The malloc code uses only
219 * one page directory, but it may enlarge it by first allocating a new area
220 * and then unmapping the old one. Therefore, we need two entries.
223 #define MAGIC_UNMAP_MEM_ENTRIES 2
227 struct _magic_vars_t
{
229 /* Magic Address Space Randomization (ASRPass) */
231 int asr_heap_map_do_permutate
;
232 int asr_heap_max_offset
;
233 int asr_heap_max_padding
;
234 int asr_map_max_offset_pages
;
235 int asr_map_max_padding_pages
;
240 /* Magic type array. */
241 struct _magic_type
*types
;
243 _magic_id_t types_next_id
;
245 /* Magic function array. */
246 struct _magic_function
*functions
;
248 _magic_id_t functions_next_id
;
250 /* Magic state entry array. */
251 struct _magic_sentry
*sentries
;
253 int sentries_str_num
;
254 _magic_id_t sentries_next_id
;
256 /* Magic dynamic state index array. */
257 struct _magic_dsindex
*dsindexes
;
260 /* Magic dynamic state entry list. */
261 struct _magic_dsentry
*first_dsentry
;
262 unsigned long num_dead_dsentries
;
263 unsigned long size_dead_dsentries
;
265 /* Magic memory pool dynamic state entry list. */
266 struct _magic_dsentry
*first_mempool_dsentry
;
268 /* Magic dynamic function list. */
269 struct _magic_dfunction
*first_dfunction
;
270 struct _magic_dfunction
*last_dfunction
;
273 /* Magic SO library descriptor list. */
274 struct _magic_sodesc
*first_sodesc
;
275 struct _magic_sodesc
*last_sodesc
;
278 /* Magic DSO library descriptor list. */
279 struct _magic_dsodesc
*first_dsodesc
;
280 struct _magic_dsodesc
*last_dsodesc
;
283 /* Magic stack-related variables. */
284 struct _magic_dsentry
*first_stack_dsentry
;
285 struct _magic_dsentry
*last_stack_dsentry
;
287 /* Magic memory ranges */
293 void *stack_range
[2];
296 void *sentry_range
[2];
297 void *function_range
[2];
298 void *dfunction_range
[2];
302 int update_dsentry_ranges
;
303 int update_dfunction_ranges
;
306 /* Memory to unmap after state transfer (MINIX3 only) */
310 } unmap_mem
[MAGIC_UNMAP_MEM_ENTRIES
];
313 /* Range lookup index */
314 void *sentry_rl_buff
;
315 size_t sentry_rl_buff_offset
;
316 size_t sentry_rl_buff_size
;
317 void *sentry_rl_index
;
320 void *sentry_hash_buff
;
321 size_t sentry_hash_buff_offset
;
322 size_t sentry_hash_buff_size
;
323 void *sentry_hash_head
;
326 void *function_hash_buff
;
327 size_t function_hash_buff_offset
;
328 size_t function_hash_buff_size
;
329 void *function_hash_head
;
332 * Don't call malloc() in magic_malloc_positioned().
333 * Used in ST after RAW COPY.
339 #endif /* _MAGIC_STRUCTS_H */