4 #include <st/state_transfer.h>
6 #define NUM_CB_ARRAYS 8
9 /* Struct for holding info for selement transfer callbacks. */
11 _magic_selement_t
*local_selement
;
12 _magic_selement_t
*local_selements
;
15 int *st_cb_saved_flags
;
16 st_init_info_t
*init_info
;
19 /* Callback type definitions and call registration helpers. */
21 #define CALLBACK_PREFIX st
22 #undef CALLBACK_FAMILY
23 #include <st/cb_template.h>
25 DEFINE_DECL_CALLBACK(void *, pages_allocate
, (st_init_info_t
*info
, uint32_t *phys
, int num_pages
));
26 DEFINE_DECL_CALLBACK(void, pages_free
, (st_init_info_t
*info
, st_alloc_pages
*current_page
));
27 DEFINE_DECL_CALLBACK(int, state_cleanup
, (void));
28 typedef magic_sentry_analyze_cb_t st_cb_state_checking_t
;
29 PUBLIC
void st_setcb_state_checking(st_cb_state_checking_t cb
);
30 DEFINE_DECL_CALLBACK(void, selement_map
, (_magic_selement_t
*cached_selement
, _magic_selement_t
*local_selement
, struct st_cb_info
*cb_info
, int is_trg_mapping
));
31 DEFINE_DECL_CALLBACK_CUSTOM(int, selement_transfer
, (_magic_selement_t
*selement
, _magic_sel_analyzed_t
*sel_analyzed
, _magic_sel_stats_t
*sel_stats
, struct st_cb_info
*cb_info
), (CALLBACK_TYPENAME(selement_transfer
) cb
, int flags
));
33 /* Struct for holding state transfer callback functions. */
35 st_cb_pages_allocate_t st_cb_pages_allocate
;
36 st_cb_pages_free_t st_cb_pages_free
;
37 st_cb_state_cleanup_t st_cb_state_cleanup
;
38 st_cb_state_checking_t st_cb_state_checking
;
39 st_cb_selement_map_t st_cb_selement_map
;
40 st_cb_selement_transfer_t st_cb_selement_transfer
[NUM_CB_ARRAYS
][MAX_NUM_CBS
];
43 /* Predefined callback implementations. */
44 PUBLIC
void *st_cb_pages_allocate(st_init_info_t
*info
, uint32_t *phys
, int num_pages
);
45 PUBLIC
void st_cb_pages_free(st_init_info_t
*info
, st_alloc_pages
*current_page
);
46 PUBLIC
int st_cb_state_cleanup_null(void);
47 PUBLIC
int st_cb_state_checking_null(_magic_selement_t
* selement
,
48 _magic_sel_analyzed_t
*sel_analyzed
, _magic_sel_stats_t
*sel_stats
,
50 PUBLIC
int st_cb_state_checking_print(_magic_selement_t
* selement
,
51 _magic_sel_analyzed_t
*sel_analyzed
, _magic_sel_stats_t
*sel_stats
,
53 PUBLIC
int st_cb_state_checking_panic(_magic_selement_t
* selement
,
54 _magic_sel_analyzed_t
*sel_analyzed
, _magic_sel_stats_t
*sel_stats
,
57 PUBLIC
int st_cb_transfer_sentry_default(_magic_selement_t
*selement
, _magic_sel_analyzed_t
*sel_analyzed
, _magic_sel_stats_t
*sel_stats
, struct st_cb_info
*cb_info
);
58 PUBLIC
int st_cb_transfer_typename_default(_magic_selement_t
*selement
, _magic_sel_analyzed_t
*sel_analyzed
, _magic_sel_stats_t
*sel_stats
, struct st_cb_info
*cb_info
);
59 PUBLIC
int st_cb_transfer_walkable(_magic_selement_t
*selement
, _magic_sel_analyzed_t
*sel_analyzed
, _magic_sel_stats_t
*sel_stats
, struct st_cb_info
*cb_info
);
60 PUBLIC
int st_cb_transfer_ptr(_magic_selement_t
*selement
, _magic_sel_analyzed_t
*sel_analyzed
, _magic_sel_stats_t
*sel_stats
, struct st_cb_info
*cb_info
);
61 PUBLIC
int st_cb_transfer_identity(_magic_selement_t
*selement
, _magic_sel_analyzed_t
*sel_analyzed
, _magic_sel_stats_t
*sel_stats
, struct st_cb_info
*cb_info
);
62 PUBLIC
int st_cb_transfer_cond_identity(_magic_selement_t
*selement
, _magic_sel_analyzed_t
*sel_analyzed
, _magic_sel_stats_t
*sel_stats
, struct st_cb_info
*cb_info
);
63 PUBLIC
int st_cb_transfer_nonptr(_magic_selement_t
*selement
, _magic_sel_analyzed_t
*sel_analyzed
, _magic_sel_stats_t
*sel_stats
, struct st_cb_info
*cb_info
);
64 PUBLIC
int st_cb_transfer_struct(_magic_selement_t
*selement
, _magic_sel_analyzed_t
*sel_analyzed
, _magic_sel_stats_t
*sel_stats
, struct st_cb_info
*cb_info
);
65 PUBLIC
int st_cb_transfer_selement_base(_magic_selement_t
*selement
, _magic_sel_analyzed_t
*sel_analyzed
, _magic_sel_stats_t
*sel_stats
, struct st_cb_info
*cb_info
);
66 PUBLIC
int st_cb_transfer_selement_generic(_magic_selement_t
*selement
, _magic_sel_analyzed_t
*sel_analyzed
, _magic_sel_stats_t
*sel_stats
, struct st_cb_info
*cb_info
);
68 PUBLIC
void st_cb_map_from_parent_array_selement_generic(_magic_selement_t
*cached_selement
, _magic_selement_t
*local_selement
, struct st_cb_info
*cb_info
, int is_trg_mapping
);
69 PUBLIC
void st_cb_map_child_array_selement_generic(_magic_selement_t
*cached_selement
, _magic_selement_t
*local_selement
, struct st_cb_info
*cb_info
, int is_trg_mapping
);
70 PUBLIC
void st_cb_map_from_parent_union_selement_generic(_magic_selement_t
*cached_selement
, _magic_selement_t
*local_selement
, struct st_cb_info
*cb_info
, int is_trg_mapping
);
71 PUBLIC
void st_cb_map_child_union_selement_generic(_magic_selement_t
*cached_selement
, _magic_selement_t
*local_selement
, struct st_cb_info
*cb_info
, int is_trg_mapping
);
72 PUBLIC
void st_cb_map_from_parent_struct_selement_generic(_magic_selement_t
*cached_selement
, _magic_selement_t
*local_selement
, struct st_cb_info
*cb_info
, int is_trg_mapping
);
73 PUBLIC
void st_cb_map_child_nonaggr_selement_generic(_magic_selement_t
*cached_selement
, _magic_selement_t
*local_selement
, struct st_cb_info
*cb_info
, int is_trg_mapping
);
74 PUBLIC
void st_cb_map_child_struct_selement_generic(_magic_selement_t
*cached_selement
, _magic_selement_t
*local_selement
, struct st_cb_info
*cb_info
, int is_trg_mapping
);
75 PUBLIC
void st_cb_map_child_primitive_selement_generic(_magic_selement_t
*cached_selement
, _magic_selement_t
*local_selement
, struct st_cb_info
*cb_info
, int is_trg_mapping
);
76 PUBLIC
void st_cb_map_child_ptr_selement_generic(_magic_selement_t
*cached_selement
, _magic_selement_t
*local_selement
, struct st_cb_info
*cb_info
, int is_trg_mapping
);
77 PUBLIC
void st_cb_map_from_parent_selement_generic(_magic_selement_t
*cached_selement
, _magic_selement_t
*local_selement
, struct st_cb_info
*cb_info
, int is_trg_mapping
);
78 PUBLIC
void st_cb_map_child_selement_generic(_magic_selement_t
*cached_selement
, _magic_selement_t
*local_selement
, struct st_cb_info
*cb_info
, int is_trg_mapping
);
79 PUBLIC
void st_cb_map_selement_generic(_magic_selement_t
*cached_selement
, _magic_selement_t
*local_selement
, struct st_cb_info
*cb_info
, int is_trg_mapping
);
81 /* Macros for callbacks not defined statically. */
82 #define ST_CB_SELEMENT_TRANSFER_EMPTY {{0}}
84 /* Macros for predefined callback implementations. */
85 #define ST_CB_PAGES_ALLOCATE_DEFAULT st_cb_pages_allocate
86 #define ST_CB_PAGES_FREE_DEFAULT st_cb_pages_free
87 #define ST_CB_STATE_CLEANUP_DEFAULT st_cb_state_cleanup_null
88 #define ST_CB_STATE_CHECKING_DEFAULT st_cb_state_checking_print
89 #define ST_CB_SELEMENT_MAP_DEFAULT st_cb_map_selement_generic
91 #define ST_CB_PRINT st_cb_print
93 #define ST_TYPE_NAME_KEY(TYPE) ((const char *) (TYPE)->ext)
95 #define ST_TYPE_NAME_MATCH(REGISTERED_TYPE_NAME_KEY, KEY) \
96 (REGISTERED_TYPE_NAME_KEY == KEY)
97 #define ST_TYPE_NAME_MATCH_ANY(REGISTERED_TYPE_NAME_KEYS, KEY) \
98 st_type_name_match_any(REGISTERED_TYPE_NAME_KEYS, KEY)
99 #define ST_SENTRY_NAME_MATCH(SENTRY_WILDCARD_NAME, NAME) \
100 (!st_strcmp_wildcard(SENTRY_WILDCARD_NAME, NAME))
101 #define ST_SENTRY_NAME_MATCH_ANY(SENTRY_WILDCARD_NAMES, NAME) \
102 st_sentry_name_match_any(SENTRY_WILDCARD_NAMES, NAME)
103 #define ST_DSENTRY_PARENT_NAME_MATCH(DSENTRY_WILDCARD_PARENT_NAME, PARENT_NAME)\
104 (!st_strcmp_wildcard(DSENTRY_WILDCARD_PARENT_NAME, PARENT_NAME))
105 #define ST_DSENTRY_PARENT_NAME_MATCH_ANY(DSENTRY_WILDCARD_PARENT_NAMES, \
107 st_dsentry_parent_name_match_any(DSENTRY_WILDCARD_PARENT_NAMES, PARENT_NAME)
109 #define ST_CB_TYPE_TYPENAME 1
110 #define ST_CB_TYPE_SENTRY 2
111 #define ST_CB_TYPE_SELEMENT 4
112 #define ST_CB_NOT_PROCESSED 1000
114 #define ST_CB_CHECK_ONLY 0x01
115 #define ST_CB_PRINT_DBG 0x02
116 #define ST_CB_PRINT_ERR 0x04
117 #define ST_CB_FORCE_IXFER 0x08
118 #define ST_CB_DEFAULT_FLAGS (ST_CB_PRINT_ERR)
119 #define ST_CB_FLAG(F) (cb_info->st_cb_flags & F)
121 #define ST_CB_DBG ST_CB_PRINT_DBG
122 #define ST_CB_ERR ST_CB_PRINT_ERR
123 #define ST_CB_PRINT_LEVEL(L) ST_CB_FLAG(L)
124 #define ST_CB_LEVEL_TO_STR(L) \
125 (L == ST_CB_DBG ? "DEBUG" : \
126 L == ST_CB_ERR ? "ERROR" : "???")
128 #endif /* ST_CALLBACK_H */