/* register a hook */
void register_hook(hook_type_t hook, hook_entry_t *entry) {
+ /* check if a hook function is specifyed. It's a union, so no matter which one */
if (! entry->hook._hook_turn_into_id)
return;
hooks[hook] = entry;
}
+/* unregister a hook */
+void unregister_hook(hook_type_t hook, hook_entry_t *entry) {
+ hook_entry_t *p;
+
+ if (hooks[hook] == entry) {
+ hooks[hook] = entry->next;
+ entry->next = NULL;
+ return;
+ }
+
+ for (p = hooks[hook]; p && p->next != entry; p = p->next);
+
+ if (p) {
+ p->next = entry->next;
+ entry->next = NULL;
+ }
+}
+
+
#else
void register_hook(hook_type_t hook, hook_entry_t *entry) {}
+void unregister_hook(hook_type_t hook, hook_entry_t *entry) {}
#endif /* FIRM_ENABLE_HOOKS */
-int init_hooks(void)
-{
- return (int)register_hook;
+int init_hooks(void) {
+ return (int)register_hook + (int)unregister_hook;
}
hook_arch_dep_replace_mul_with_shifts,
hook_arch_dep_replace_division_by_const,
hook_new_mode,
- hook_last,
+ hook_last
} hook_type_t;
/**
- * register the hook entry.
+ * register a hook entry.
*
* @param hook the hook type
* @param entry the hook entry
*/
void register_hook(hook_type_t hook, hook_entry_t *entry);
+/**
+ * unregister a hook entry.
+ *
+ * @param hook the hook type
+ * @param entry the hook entry
+ */
+void unregister_hook(hook_type_t hook, hook_entry_t *entry);
+
#ifdef FIRM_ENABLE_HOOKS
extern hook_entry_t *hooks[hook_last];