34 get_hook_tbl(
const uint8_t hook_type,
hook_storage_t **hook_storage );
43 pack_hook_tbl(
hook_tbl_t hook_tbl[],
unsigned int idx);
50 EM_PRINT(
"EM callbacks init\n");
62 em_shm->dispatch_enter_cb_tbl =
63 &
em_shm->dispatch_enter_cb_storage.hook_tbl_storage[0];
65 &
em_shm->dispatch_exit_cb_storage.hook_tbl_storage[0];
67 &
em_shm->alloc_hook_storage.hook_tbl_storage[0];
69 &
em_shm->free_hook_storage.hook_tbl_storage[0];
71 &
em_shm->send_hook_storage.hook_tbl_storage[0];
80 em_shm->dispatch_enter_cb_storage.idx = 0;
81 em_shm->dispatch_exit_cb_storage.idx = 0;
82 em_shm->alloc_hook_storage.idx = 0;
83 em_shm->free_hook_storage.idx = 0;
84 em_shm->send_hook_storage.idx = 0;
90 env_spinlock_init(&
em_shm->dispatch_enter_cb_storage.lock);
91 env_spinlock_init(&
em_shm->dispatch_exit_cb_storage.lock);
92 env_spinlock_init(&
em_shm->alloc_hook_storage.lock);
93 env_spinlock_init(&
em_shm->free_hook_storage.lock);
94 env_spinlock_init(&
em_shm->send_hook_storage.lock);
103 if (unlikely(stat !=
EM_OK))
108 if (unlikely(stat !=
EM_OK))
113 if (unlikely(stat !=
EM_OK))
121 if (unlikely(stat !=
EM_OK))
126 if (unlikely(stat !=
EM_OK))
131 if (unlikely(stat !=
EM_OK))
151 active_tbl_ptr = get_hook_tbl(hook_type, &hook_storage);
152 if (unlikely(active_tbl_ptr == NULL))
155 env_spinlock_lock(&hook_storage->
lock);
159 idx = hook_storage->
idx;
161 if (next_idx >= API_HOOKS_MAX_TBL_SIZE)
170 memcpy(next_tbl->tbl, hook_tbl->tbl,
sizeof(next_tbl->tbl));
173 if (next_tbl->tbl[i].void_hook == NULL)
177 env_spinlock_unlock(&hook_storage->
lock);
181 next_tbl->tbl[i] = hook_fn;
184 *active_tbl_ptr = next_tbl;
186 hook_storage->
idx = next_idx;
188 env_spinlock_unlock(&hook_storage->
lock);
205 active_tbl_ptr = get_hook_tbl(hook_type, &hook_storage);
206 if (unlikely(active_tbl_ptr == NULL))
209 env_spinlock_lock(&hook_storage->
lock);
213 idx = hook_storage->
idx;
215 if (next_idx >= API_HOOKS_MAX_TBL_SIZE)
224 memcpy(next_tbl->tbl, hook_tbl->tbl,
sizeof(next_tbl->tbl));
227 if (next_tbl->tbl[i].void_hook == hook_fn.void_hook)
230 env_spinlock_unlock(&hook_storage->
lock);
238 next_tbl->tbl[i].void_hook = NULL;
239 ret = pack_hook_tbl(next_tbl, i);
240 if (unlikely(ret != 0)) {
241 env_spinlock_unlock(&hook_storage->
lock);
246 *active_tbl_ptr = next_tbl;
248 hook_storage->
idx = next_idx;
250 env_spinlock_unlock(&hook_storage->
lock);
256 get_hook_tbl(
const uint8_t hook_type,
hook_storage_t **hook_storage )
262 *hook_storage = &
em_shm->alloc_hook_storage;
266 *hook_storage = &
em_shm->free_hook_storage;
270 *hook_storage = &
em_shm->send_hook_storage;
273 case DISPATCH_CALLBACK_ENTER:
274 *hook_storage = &
em_shm->dispatch_enter_cb_storage;
275 active_tbl_ptr = &
em_shm->dispatch_enter_cb_tbl;
277 case DISPATCH_CALLBACK_EXIT:
278 *hook_storage = &
em_shm->dispatch_exit_cb_storage;
289 case WHILE_IDLE_HOOK:
297 return active_tbl_ptr;
301 pack_hook_tbl(
hook_tbl_t *
const hook_tbl,
unsigned int idx)
306 fn_tbl[idx].void_hook != NULL))
310 if (fn_tbl[i + 1].void_hook != NULL) {
311 fn_tbl[i].void_hook = fn_tbl[i + 1].void_hook;
312 fn_tbl[i + 1].void_hook = NULL;