Drop main() prototype. Syncs with NetBSD-8
[minix.git] / minix / lib / libmagicrt / include / st / state_transfer.h
blobfcb1217d37ab1424db53faafb33dce5578307de1
1 #ifndef ST_STATE_TRANSFER_H
2 #define ST_STATE_TRANSFER_H
5 #include <magic.h>
6 #include <magic_mem.h>
7 #include <magic_analysis.h>
8 #include <magic_asr.h>
9 #include <stdarg.h>
10 #include <stdint.h>
12 #ifdef __MINIX
13 #include <minix/com.h>
14 #include <minix/sef.h>
15 #endif
18 * Used for debugging: Iterate the type transformations X times.
20 #define MAGIC_ST_TYPE_TRANS_ITERATIONS 1
22 #include <st/os_callback.h>
23 #include <st/special.h>
25 #define ST_LU_ASR (1 << 1)
26 #define ST_LU_NOMMAP (1 << 2)
29 * Type definitions. These need to be OS independent.
31 typedef struct _st_init_info_t {
32 int flags;
33 void *init_buff_start;
34 void *init_buff_cleanup_start;
35 size_t init_buff_len;
36 struct st_cbs_os_t st_cbs_os;
37 void *info_opaque;
38 } st_init_info_t;
40 typedef struct st_alloc_pages {
41 int num_pages;
42 void *virt_addr;
43 uint32_t phys_addr;
44 struct st_alloc_pages *previous;
45 } st_alloc_pages;
47 #include <st/callback.h>
49 /* struct for holding a mapping between pointers */
50 typedef struct {
51 void *counterpart;
52 } st_ptr_mapping;
54 /* struct for holding arrays of local counterparts to cached variables */
55 typedef struct {
56 st_ptr_mapping *functions;
57 int functions_size;
58 st_ptr_mapping *types;
59 st_ptr_mapping *ptr_types;
60 int types_size;
61 st_ptr_mapping *sentries;
62 st_ptr_mapping *sentries_data;
63 int sentries_size;
64 } st_counterparts_t;
66 #define ST_STATE_CHECKING_DEFAULT_MAX_CYCLES LONG_MAX
67 #define ST_STATE_CHECKING_DEFAULT_MAX_VIOLATIONS 50
69 #define ST_SEL_ANALYZE_FLAGS (MAGIC_SEL_ANALYZE_ALL & (~MAGIC_SEL_ANALYZE_OUT_OF_BAND))
71 #define ST_MAX_COMPATIBLE_TYPES 32
73 /* Fields of _magic_vars_t that need to be zeroed out after transferring. */
74 #define ST_MAGIC_VARS_PTR_CLEAR_LIST \
75 __X(first_sodesc), __X(last_sodesc), \
76 __X(first_dsodesc), __X(last_dsodesc), \
77 __X(sentry_rl_buff), __X(sentry_rl_index), \
78 __X(sentry_hash_buff), __X(sentry_hash_head), \
79 __X(function_hash_buff), __X(function_hash_head)
81 /* Public utility functions. */
82 PUBLIC int st_strcmp_wildcard(const char *with_wildcard, const char *without_wildcard);
83 PUBLIC void st_cb_print(int level, const char *msg, _magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info);
84 PUBLIC void st_map_str_sentries(struct _magic_sentry **cached_sentry_ptr, struct _magic_sentry **local_sentry_ptr);
85 PUBLIC void st_map_sentries(struct _magic_sentry **cached_sentry_ptr, struct _magic_sentry **local_sentry_ptr);
86 PUBLIC void st_lookup_sentry_pair(struct _magic_sentry **cached_sentry_ptr, struct _magic_sentry **local_sentry_ptr);
87 PUBLIC void st_add_sentry_pair(struct _magic_sentry *cached_sentry, struct _magic_sentry *local_sentry);
88 PUBLIC int st_add_sentry_pair_alloc_by_dsindex(st_init_info_t *info, struct _magic_sentry *cached_sentry, struct _magic_dsindex *local_dsindex, int num_elements, const union __alloc_flags *p_alloc_flags);
89 PUBLIC void st_map_functions(struct _magic_function **cached_function_ptr, struct _magic_function **local_function_ptr);
90 PUBLIC void st_lookup_function_pair(struct _magic_function **cached_function_ptr, struct _magic_function **local_function_ptr);
91 PUBLIC void st_add_function_pair(struct _magic_function *cached_function, struct _magic_function *local_function);
92 PUBLIC int st_sentry_equals(struct _magic_sentry *cached_sentry, struct _magic_sentry *local_sentry);
93 PUBLIC int st_function_equals(struct _magic_function *cached_function, struct _magic_function *local_function);
94 PUBLIC void st_print_sentry_diff(st_init_info_t *info, struct _magic_sentry *cached_sentry, struct _magic_sentry *local_sentry, int raw_diff, int print_changed);
95 PUBLIC void st_print_function_diff(st_init_info_t *info, struct _magic_function *cached_function, struct _magic_function *local_function, int raw_diff, int print_changed);
96 PUBLIC void st_cb_selement_type_cast(const struct _magic_type* new_selement_type, const struct _magic_type* new_local_selement_type, _magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info);
97 PUBLIC void st_map_local_selement_from_child_num(_magic_selement_t *local_selement, struct st_cb_info *cb_info, int child_num);
99 /* Stack refs save/restore. */
100 PUBLIC void st_stack_refs_save_restore(char *stack_buff, int is_save);
102 #define st_stack_refs_save(B) st_stack_refs_save_restore(B,1)
103 #define st_stack_refs_restore(B) st_stack_refs_save_restore(B,0)
105 #define ST_STACK_REFS_BUFF_SIZE (sizeof(struct st_stack_refs_buff))
108 * The stack pointers to the environment and arguments differ from MINIX
109 * to Linux.
111 #if defined(__MINIX)
112 #define ST_STACK_REFS_INT_NUM 3
113 #define ST_STACK_REFS_INT_LIST \
114 __X(environ), __X(env_argv), __X(env_argc)
115 #define ST_STACK_REFS_CUSTOM_NUM 0
116 #define ST_STACK_REFS_CUSTOM_LIST
118 #else
120 * TODO: Complete the list of Linux stack pointer aliases.
122 #define ST_STACK_REFS_INT_NUM 3
123 #define ST_STACK_REFS_INT_LIST __X(_environ), __X(__progname), \
124 __X(__progname_full)
126 #ifndef __USE_GNU
127 extern char *program_invocation_name, *program_invocation_short_name;
128 extern char **environ;
129 #endif
130 #define ST_STACK_REFS_CUSTOM_NUM 4
131 #define ST_STACK_REFS_CUSTOM_LIST __X(environ), __X(__environ), \
132 __X(program_invocation_name), __X(program_invocation_short_name)
134 #endif
136 #define ST_STACK_REFS_NUM (ST_STACK_REFS_INT_NUM + ST_STACK_REFS_CUSTOM_NUM)
138 struct st_stack_refs_buff {
139 struct _magic_dsentry *first_stack_dsentry;
140 struct _magic_dsentry *last_stack_dsentry;
141 struct _magic_obdsentry first_stack_obdsentry_buff;
142 void* stack_range[2];
143 int stack_int_refs[ST_STACK_REFS_NUM];
146 /* Public functions for metadata transfer. */
147 PUBLIC int st_transfer_metadata_types(st_init_info_t *info,
148 struct _magic_vars_t *cached_magic_vars,
149 struct _magic_vars_t *remote_magic_vars,
150 st_counterparts_t *counterparts);
151 PUBLIC int st_transfer_metadata_dsentries(st_init_info_t *info,
152 struct _magic_vars_t *cached_magic_vars,
153 struct _magic_vars_t *remote_magic_vars, st_counterparts_t *counterparts,
154 size_t *max_buff_sz, int *dsentries_num);
156 /* Public functions for state transfer. */
157 PUBLIC int st_state_transfer(st_init_info_t *info);
158 PUBLIC void st_msync_all_shm_dsentries(void);
160 PUBLIC int st_init(st_init_info_t *info);
161 PUBLIC void st_set_status_defaults(st_init_info_t *info);
162 PUBLIC int st_data_transfer(st_init_info_t *info);
163 PUBLIC void st_cleanup(st_init_info_t *info);
165 PUBLIC void st_set_unpaired_types_ratios(float unpaired_types_ratio, float unpaired_struct_types_ratio);
167 PUBLIC struct _magic_sentry* st_cached_to_remote_sentry(st_init_info_t *info, struct _magic_sentry *cached_sentry);
169 PUBLIC void st_print_sentries_diff(st_init_info_t *info, int raw_diff, int print_changed);
170 PUBLIC void st_print_dsentries_diff(st_init_info_t *info, int raw_diff, int print_changed);
171 PUBLIC void st_print_functions_diff(st_init_info_t *info, int raw_diff, int print_changed);
172 PUBLIC void st_print_state_diff(st_init_info_t *info, int raw_diff, int print_changed);
174 PUBLIC void st_set_status_by_state_flags(int status_flags, int status_op, int match_state_flags, int skip_state_flags);
175 PUBLIC int st_set_status_by_function_ids(int status_flags, int status_op, unsigned long *ids);
176 PUBLIC int st_set_status_by_sentry_ids(int status_flags, int status_op, unsigned long *ids);
177 PUBLIC int st_set_status_by_names(int status_flags, int status_op, const char **parent_names, const char **names, _magic_id_t *dsentry_site_ids);
178 PUBLIC int st_set_status_by_local_addrs(int status_flags, int status_op, void **addrs);
179 PUBLIC void st_set_status_by_sentry(int status_flags, int status_op, void *cached_sentry);
180 PUBLIC void st_set_status_by_function(int status_flags, int status_op, void *cached_function);
181 PUBLIC int st_set_status_by_function_id(int status_flags, int status_op, unsigned long id);
182 PUBLIC int st_set_status_by_sentry_id(int status_flags, int status_op, unsigned long id);
183 PUBLIC int st_set_status_by_name(int status_flags, int status_op, const char *parent_name, const char *name, _magic_id_t dsentry_site_id);
184 PUBLIC int st_set_status_by_local_addr(int status_flags, int status_op, void *addr);
186 PUBLIC int st_pair_by_function_ids(unsigned long *cached_ids, unsigned long *local_ids, int status_flags, int status_op);
187 PUBLIC int st_pair_by_sentry_ids(unsigned long *cached_ids, unsigned long *local_ids, int status_flags, int status_op);
188 PUBLIC int st_pair_by_names(char **cached_parent_names, char **cached_names, char **local_parent_names, char **local_names, _magic_id_t *dsentry_site_ids, int status_flags, int status_op);
189 PUBLIC void st_pair_by_sentry(void *cached_sentry, void *local_sentry, int status_flags, int status_op);
190 PUBLIC void st_pair_by_function(void *cached_function, void* local_function, int status_flags, int status_op);
191 PUBLIC int st_pair_alloc_by_dsindex(st_init_info_t *info, void *cached_sentry, void *local_dsindex, int num_elements, const union __alloc_flags *p_alloc_flags, int status_flags, int status_op);
192 PUBLIC int st_pair_by_function_id(unsigned long cached_id, unsigned long local_id, int status_flags, int status_op);
193 PUBLIC int st_pair_by_sentry_id(unsigned long cached_id, unsigned long local_id, int status_flags, int status_op);
194 PUBLIC int st_pair_by_name(char *cached_parent_name, char *cached_name, char *local_parent_name, char *local_name, _magic_id_t dsentry_site_id, int status_flags, int status_op);
195 PUBLIC int st_pair_by_alloc_name(st_init_info_t *info, char *cached_parent_name, char *cached_name, _magic_id_t cached_dsentry_site_id, char *local_parent_name, char *local_name, _magic_id_t local_dsentry_site_id, int num_elements, const union __alloc_flags *p_alloc_flags, int status_flags, int status_op);
196 PUBLIC int st_pair_by_alloc_name_policies(st_init_info_t *info, char *cached_parent_name, char *cached_name, _magic_id_t cached_dsentry_site_id, char *local_parent_name, char *local_name, _magic_id_t local_dsentry_site_id, int num_elements, const union __alloc_flags *p_alloc_flags, int alloc_policies, int status_flags, int status_op);
198 /* Public functions for state checking. */
199 PUBLIC int st_do_state_cleanup(void);
200 PUBLIC int st_do_state_checking(void);
201 PUBLIC int st_state_checking_before_receive_is_enabled(void);
202 PUBLIC int st_state_checking_before_receive_set_enabled(int enabled, int max_cycles, int max_violations);
204 /* State transfer status flags and operations. */
205 #define ST_NEEDS_TRANSFER 0x01
206 #define ST_TRANSFER_DONE 0x02
207 #define ST_ON_PTRXFER_CASCADE 0x04
208 #define ST_ON_PTRXFER_SET_NULL 0x08
209 #define ST_ON_PTRXFER_SET_DEFAULT 0x10
210 #define ST_ON_PTRXFER_SKIP 0x20
212 #define ST_OP_NONE 0
213 #define ST_OP_ADD 1
214 #define ST_OP_DEL 2
215 #define ST_OP_SET 3
216 #define ST_OP_CLEAR 4
218 /* State transfer policies. */
219 #define ST_DEFAULT_TRANSFER_NONE 0x00000001
220 #define ST_DEFAULT_ALLOC_CASCADE_XFER 0x00000002
221 #define ST_DEFAULT_SKIP_STACK 0x00000004
222 #define ST_DEFAULT_SKIP_LIB_STATE 0x00000008
223 #define ST_TRANSFER_DIRTY_ONLY 0x00000010
224 #define ST_IXFER_UNCAUGHT_UNIONS 0x00000020
225 #define ST_REPORT_UNCAUGHT_UNIONS 0x00000040
226 #define ST_REPORT_NONXFERRED_ALLOCS 0x00000080
227 #define ST_REPORT_NONXFERRED_UNPAIRED_ALLOCS 0x00000100
228 #define ST_REPORT_UNPAIRED_SENTRIES 0x00000200
229 #define ST_REPORT_UNPAIRED_DSENTRIES 0x00000400
230 #define ST_REPORT_UNPAIRED_STRINGS 0x00000800
231 #define ST_REPORT_UNPAIRED_SELEMENTS 0x00001000
232 #define ST_MAP_NAMED_STRINGS_BY_NAME 0x00002000
233 #define ST_MAP_NAMED_STRINGS_BY_CONTENT 0x00004000
234 #define ST_MAP_STRINGS_BY_CONTENT 0x00008000
235 #define ST_ON_ALLOC_UNPAIR_ERROR 0x00010000
236 #define ST_ON_ALLOC_UNPAIR_DEALLOCATE 0x00020000
237 #define ST_ON_ALLOC_UNPAIR_IGNORE 0x00040000
238 #define ST_DEFAULT_MAP_GUARD_PTRS_TO_ARRAY_END 0x00080000
239 #define ST_DEFAULT_MAP_GUARD_PTRS_TO_STR_END 0x00100000
240 #define ST_REPORT_PRECISION_LOSS 0x00200000
241 #define ST_REPORT_SIGN_CHANGE 0x00400000
242 #define ST_REPORT_SMALLER_ARRAYS 0x00800000
243 #define ST_REPORT_LARGER_ARRAYS 0x01000000
244 #define ST_REPORT_SMALLER_STRINGS 0x02000000
245 #define ST_REPORT_LARGER_STRINGS 0x04000000
247 #define ST_REPORT_UNPAIRED_ALL \
248 (ST_REPORT_UNPAIRED_SENTRIES | ST_REPORT_UNPAIRED_DSENTRIES | \
249 ST_REPORT_UNPAIRED_STRINGS | ST_REPORT_UNPAIRED_SELEMENTS)
250 #define ST_MAP_STRINGS_DEFAULT \
251 (ST_MAP_NAMED_STRINGS_BY_NAME | ST_MAP_STRINGS_BY_CONTENT)
252 #define ST_ON_ALLOC_UNPAIR_DEFAULT (ST_ON_ALLOC_UNPAIR_ERROR)
253 #define ST_ON_ALLOC_UNPAIR_MASK \
254 (ST_ON_ALLOC_UNPAIR_ERROR | ST_ON_ALLOC_UNPAIR_DEALLOCATE | \
255 ST_ON_ALLOC_UNPAIR_IGNORE)
256 #define ST_TYPE_TRANSFORM_DEFAULT \
257 (ST_DEFAULT_MAP_GUARD_PTRS_TO_STR_END | ST_REPORT_PRECISION_LOSS | \
258 ST_REPORT_SIGN_CHANGE | ST_REPORT_SMALLER_ARRAYS | ST_REPORT_LARGER_ARRAYS)
260 #define ST_POLICIES_DEFAULT_TRANSFER_ALL \
261 (ST_DEFAULT_ALLOC_CASCADE_XFER | ST_DEFAULT_SKIP_STACK | \
262 ST_DEFAULT_SKIP_LIB_STATE | ST_REPORT_NONXFERRED_ALLOCS | \
263 ST_REPORT_NONXFERRED_UNPAIRED_ALLOCS | ST_MAP_STRINGS_DEFAULT | \
264 ST_ON_ALLOC_UNPAIR_DEFAULT | ST_TYPE_TRANSFORM_DEFAULT)
265 #define ST_POLICIES_DEFAULT_TRANSFER_NONE \
266 (ST_DEFAULT_TRANSFER_NONE | ST_DEFAULT_SKIP_STACK | \
267 ST_DEFAULT_SKIP_LIB_STATE | ST_REPORT_NONXFERRED_ALLOCS | \
268 ST_REPORT_NONXFERRED_UNPAIRED_ALLOCS | ST_MAP_STRINGS_DEFAULT | \
269 ST_ON_ALLOC_UNPAIR_DEFAULT | ST_TYPE_TRANSFORM_DEFAULT)
270 #define ST_POLICIES_DEFAULT_TRANSFER_ASR \
271 (ST_POLICIES_DEFAULT_TRANSFER_ALL | ST_REPORT_UNPAIRED_ALL)
273 #define ST_POLICIES_DEFAULT ST_POLICIES_DEFAULT_TRANSFER_ALL
275 /* Macros for predefined state transfer names. */
277 #define ADJUST_POINTER(local, remote, pointer) ( (local) + ((pointer) - (remote)) )
278 #define ST_STR_BUFF_SIZE (MAGIC_MAX_NAME_LEN > MAGIC_MAX_TYPE_STR_LEN ? MAGIC_MAX_NAME_LEN : MAGIC_MAX_TYPE_STR_LEN)
279 #define USE_PRE_ALLOCATED_BUFFER(INFO) ((INFO)->init_buff_start)
280 #define EXEC_WITH_MAGIC_VARS(CMD, MAGIC_VARS) \
281 do { \
282 struct _magic_vars_t *__saved_vars = _magic_vars; \
283 _magic_vars = (MAGIC_VARS); \
284 CMD; \
285 _magic_vars = __saved_vars; \
286 } while(0);
288 #define MAX_NUM_TYPENAMES 20
290 #define CHECK_SENTITY_PAIRS 1
291 #define ST_DEBUG_LEVEL 1
292 #define ST_DEBUG_DATA_TRANSFER 0
293 #define CHECK_ASR 0
295 #define ST_ALLOW_RAW_UNPAIRED_TYPES 1
296 #define ST_UNPAIRED_TYPES_RATIO_DEFAULT 0
297 #define ST_UNPAIRED_STRUCT_TYPES_RATIO_DEFAULT 0
298 #define FORCE_SOME_UNPAIRED_TYPES 1
299 #define ST_TRANSFER_IDENTITY_FOR_NO_INNER_PTRS 1
301 #ifndef ST_ASSUME_RAW_COPY_BEFORE_TRANSFER
302 #define ST_ASSUME_RAW_COPY_BEFORE_TRANSFER 0
303 #endif
305 #if defined(__MINIX)
306 #define ST_IS_UNPAIRABLE_TYPE_OS(T) (sef_self_endpoint != VM_PROC_NR || strcmp((T)->name, "void"))
307 #else
308 #define ST_IS_UNPAIRABLE_TYPE_OS(T) 1
309 #endif
311 #if ST_ALLOW_RAW_UNPAIRED_TYPES
312 #define ST_IS_UNPAIRABLE_TYPE(T) (ST_IS_UNPAIRABLE_TYPE_OS(T) && (T)->type_id != MAGIC_TYPE_UNION)
313 #else
314 #define ST_IS_UNPAIRABLE_TYPE(T) \
315 (ST_IS_UNPAIRABLE_TYPE_OS(T) \
316 && !MAGIC_TYPE_IS_RAW_ARRAY(T) \
317 && !((T)->type_id == MAGIC_TYPE_ARRAY && !strcmp((T)->contained_types[0]->type_str, "i8")) \
318 && !(T)->ext)
319 #endif
321 #define ST_IS_UNPAIRABLE_STRUCT_TYPE(T) \
322 ((T)->type_id == MAGIC_TYPE_STRUCT)
324 #define ST_FLAGS_PRINT(E) printf(", sf_flags(NDndsc)=%d%d%d%d%d%d", \
325 MAGIC_STATE_EXTF_FLAG(E,ST_NEEDS_TRANSFER), MAGIC_STATE_EXTF_FLAG(E,ST_TRANSFER_DONE), \
326 MAGIC_STATE_EXTF_FLAG(E,ST_ON_PTRXFER_SET_NULL), MAGIC_STATE_EXTF_FLAG(E,ST_ON_PTRXFER_SET_DEFAULT), \
327 MAGIC_STATE_EXTF_FLAG(E,ST_ON_PTRXFER_SKIP), MAGIC_STATE_EXTF_FLAG(E,ST_ON_PTRXFER_CASCADE));
329 #define ST_SENTRY_PRINT(E,T) do { MAGIC_SENTRY_PRINT(E, T); ST_FLAGS_PRINT(E); if (MAGIC_SENTRY_IS_STRING(E)) printf(", string=\"%s\"", (ST_SENTRY_IS_CACHED(E) ? st_lookup_str_local_data(E) : (char*)(E)->address)); } while(0)
330 #define ST_DSENTRY_PRINT(E,T) do { MAGIC_DSENTRY_PRINT(E, T); ST_FLAGS_PRINT(&E->sentry); } while(0)
331 #define ST_FUNCTION_PRINT(E,T) do { MAGIC_FUNCTION_PRINT(E, T); ST_FLAGS_PRINT(E); } while(0)
333 #define ST_CHECK_INIT() assert(st_init_done && "st_init() should be called first!")
335 #define ST_SENTRY_IS_CACHED(E) (MAGIC_SENTRY_ID(E) >= 1 && (int)MAGIC_SENTRY_ID(E) <= st_cached_magic_vars.sentries_num && st_cached_magic_vars.sentries[MAGIC_SENTRY_ID(E)-1].address == (E)->address)
336 #define ST_GET_CACHED_COUNTERPART(CE,T,CT,LE) do { \
337 int _i = (CE)->id - 1; \
338 assert(_i >= 0 && _i < st_counterparts.T##_size); \
339 LE = st_counterparts.CT[_i].counterpart; \
340 } while(0)
341 #define ST_SET_CACHED_COUNTERPART(CE,T,CT,LE) do { \
342 int _i = (CE)->id - 1; \
343 assert(_i >= 0 && _i < st_counterparts.T##_size); \
344 st_counterparts.CT[_i].counterpart = LE; \
345 } while(0)
346 #define ST_HAS_CACHED_COUNTERPART(CE,CT) (st_counterparts.CT[(CE)->id - 1].counterpart != NULL)
348 #define ST_TYPE_IS_STATIC_CACHED_COUNTERPART(CE,LE) (((CE) >= &st_cached_magic_vars.types[0] && (CE) < &st_cached_magic_vars.types[st_cached_magic_vars.types_num]) && st_counterparts.types[(CE)->id - 1].counterpart == (LE))
349 #define ST_TYPE_IS_DYNAMIC_CACHED_COUNTERPART(CE,LE) (MAGIC_TYPE_FLAG(CE,MAGIC_TYPE_DYNAMIC) && (CE)->type_id == MAGIC_TYPE_ARRAY && (LE)->type_id == MAGIC_TYPE_ARRAY && (CE)->num_child_types == (LE)->num_child_types && ST_TYPE_IS_STATIC_CACHED_COUNTERPART((CE)->contained_types[0], (LE)->contained_types[0]))
350 #define ST_TYPE_IS_CACHED_COUNTERPART(CE,LE) (ST_TYPE_IS_STATIC_CACHED_COUNTERPART(CE,LE) || ST_TYPE_IS_DYNAMIC_CACHED_COUNTERPART(CE,LE))
351 #define ST_PTR_TYPE_IS_STATIC_CACHED_COUNTERPART(CE,LE) (((CE) >= &st_cached_magic_vars.types[0] && (CE) < &st_cached_magic_vars.types[st_cached_magic_vars.types_num]) && st_counterparts.ptr_types[(CE)->id - 1].counterpart == (LE))
352 #define ST_PTR_TYPE_IS_DYNAMIC_CACHED_COUNTERPART(CE,LE) (MAGIC_TYPE_FLAG(CE,MAGIC_TYPE_DYNAMIC) && (CE)->type_id == MAGIC_TYPE_ARRAY && (LE)->type_id == MAGIC_TYPE_ARRAY && (CE)->num_child_types == (LE)->num_child_types && ST_PTR_TYPE_IS_STATIC_CACHED_COUNTERPART((CE)->contained_types[0], (LE)->contained_types[0]))
353 #define ST_PTR_TYPE_IS_CACHED_COUNTERPART(CE,LE) (ST_PTR_TYPE_IS_STATIC_CACHED_COUNTERPART(CE,LE) || ST_PTR_TYPE_IS_DYNAMIC_CACHED_COUNTERPART(CE,LE))
356 /* Buffer allocation */
357 PUBLIC void *st_cb_pages_allocate(st_init_info_t *info, uint32_t *phys, int num_pages);
358 PUBLIC void st_cb_pages_free(st_init_info_t *info, st_alloc_pages *current_page);
359 PUBLIC void *st_buff_allocate(st_init_info_t *info, size_t size);
360 PUBLIC void st_buff_cleanup(st_init_info_t *info);
362 #endif /* ST_STATE_TRANSFER_H */