Rizin
unix-like reverse engineering framework and cli tools
rz_event.h File Reference
#include <ht_up.h>
#include <rz_vector.h>

Go to the source code of this file.

Classes

struct  rz_event_t
 
struct  rz_event_callback_handle_t
 
struct  rz_event_meta_t
 
struct  rz_event_class_t
 
struct  rz_event_class_rename_t
 
struct  rz_event_class_attr_t
 
struct  rz_event_class_attr_set_t
 
struct  rz_event_class_attr_rename_t
 
struct  rz_event_debug_process_finished_t
 

Typedefs

typedef struct rz_event_t RzEvent
 
typedef struct rz_event_callback_handle_t RzEventCallbackHandle
 
typedef void(* RzEventCallback) (RzEvent *ev, int type, void *user, void *data)
 
typedef struct rz_event_meta_t RzEventMeta
 
typedef struct rz_event_class_t RzEventClass
 
typedef struct rz_event_class_rename_t RzEventClassRename
 
typedef struct rz_event_class_attr_t RzEventClassAttr
 
typedef struct rz_event_class_attr_set_t RzEventClassAttrSet
 
typedef struct rz_event_class_attr_rename_t RzEventClassAttrRename
 
typedef struct rz_event_debug_process_finished_t RzEventDebugProcessFinished
 

Enumerations

enum  RzEventType {
  RZ_EVENT_ALL = 0 , RZ_EVENT_META_SET , RZ_EVENT_META_DEL , RZ_EVENT_META_CLEAR ,
  RZ_EVENT_CLASS_NEW , RZ_EVENT_CLASS_DEL , RZ_EVENT_CLASS_RENAME , RZ_EVENT_CLASS_ATTR_SET ,
  RZ_EVENT_CLASS_ATTR_DEL , RZ_EVENT_CLASS_ATTR_RENAME , RZ_EVENT_DEBUG_PROCESS_FINISHED , RZ_EVENT_IO_WRITE ,
  RZ_EVENT_IO_DESC_CLOSE , RZ_EVENT_IO_MAP_DEL , RZ_EVENT_BIN_FILE_DEL , RZ_EVENT_MAX
}
 

Functions

RZ_API RzEventrz_event_new (void *user)
 
RZ_API void rz_event_free (RzEvent *ev)
 
RZ_API RzEventCallbackHandle rz_event_hook (RzEvent *ev, int type, RzEventCallback cb, void *user)
 
RZ_API void rz_event_unhook (RzEvent *ev, RzEventCallbackHandle handle)
 
RZ_API void rz_event_send (RzEvent *ev, int type, void *data)
 

Typedef Documentation

◆ RzEvent

typedef struct rz_event_t RzEvent

◆ RzEventCallback

typedef void(* RzEventCallback) (RzEvent *ev, int type, void *user, void *data)

Definition at line 28 of file rz_event.h.

◆ RzEventCallbackHandle

◆ RzEventClass

◆ RzEventClassAttr

◆ RzEventClassAttrRename

◆ RzEventClassAttrSet

◆ RzEventClassRename

◆ RzEventDebugProcessFinished

◆ RzEventMeta

typedef struct rz_event_meta_t RzEventMeta

Enumeration Type Documentation

◆ RzEventType

Enumerator
RZ_EVENT_ALL 
RZ_EVENT_META_SET 
RZ_EVENT_META_DEL 
RZ_EVENT_META_CLEAR 
RZ_EVENT_CLASS_NEW 
RZ_EVENT_CLASS_DEL 
RZ_EVENT_CLASS_RENAME 
RZ_EVENT_CLASS_ATTR_SET 
RZ_EVENT_CLASS_ATTR_DEL 
RZ_EVENT_CLASS_ATTR_RENAME 
RZ_EVENT_DEBUG_PROCESS_FINISHED 
RZ_EVENT_IO_WRITE 
RZ_EVENT_IO_DESC_CLOSE 
RZ_EVENT_IO_MAP_DEL 
RZ_EVENT_BIN_FILE_DEL 
RZ_EVENT_MAX 

Definition at line 30 of file rz_event.h.

30  {
31  RZ_EVENT_ALL = 0,
32  RZ_EVENT_META_SET, // RzEventMeta
33  RZ_EVENT_META_DEL, // RzEventMeta
34  RZ_EVENT_META_CLEAR, // RzEventMeta
35  RZ_EVENT_CLASS_NEW, // RzEventClass
36  RZ_EVENT_CLASS_DEL, // RzEventClass
37  RZ_EVENT_CLASS_RENAME, // RzEventClassRename
38  RZ_EVENT_CLASS_ATTR_SET, // RzEventClassAttr
39  RZ_EVENT_CLASS_ATTR_DEL, // RzEventClassAttrSet
40  RZ_EVENT_CLASS_ATTR_RENAME, // RzEventClassAttrRename
41  RZ_EVENT_DEBUG_PROCESS_FINISHED, // RzEventDebugProcessFinished
42  RZ_EVENT_IO_WRITE, // RzEventIOWrite
43  RZ_EVENT_IO_DESC_CLOSE, // RzEventIODescClose
44  RZ_EVENT_IO_MAP_DEL, // RzEventIOMapDel
45  RZ_EVENT_BIN_FILE_DEL, // RzEventBinFileDel
47 } RzEventType;
RzEventType
Definition: rz_event.h:30
@ RZ_EVENT_CLASS_ATTR_SET
Definition: rz_event.h:38
@ RZ_EVENT_MAX
Definition: rz_event.h:46
@ RZ_EVENT_META_CLEAR
Definition: rz_event.h:34
@ RZ_EVENT_META_SET
Definition: rz_event.h:32
@ RZ_EVENT_CLASS_DEL
Definition: rz_event.h:36
@ RZ_EVENT_IO_DESC_CLOSE
Definition: rz_event.h:43
@ RZ_EVENT_CLASS_NEW
Definition: rz_event.h:35
@ RZ_EVENT_IO_MAP_DEL
Definition: rz_event.h:44
@ RZ_EVENT_CLASS_ATTR_DEL
Definition: rz_event.h:39
@ RZ_EVENT_CLASS_ATTR_RENAME
Definition: rz_event.h:40
@ RZ_EVENT_BIN_FILE_DEL
Definition: rz_event.h:45
@ RZ_EVENT_ALL
Definition: rz_event.h:31
@ RZ_EVENT_CLASS_RENAME
Definition: rz_event.h:37
@ RZ_EVENT_IO_WRITE
Definition: rz_event.h:42
@ RZ_EVENT_META_DEL
Definition: rz_event.h:33
@ RZ_EVENT_DEBUG_PROCESS_FINISHED
Definition: rz_event.h:41

Function Documentation

◆ rz_event_free()

RZ_API void rz_event_free ( RzEvent ev)

Definition at line 37 of file event.c.

37  {
38  if (!ev) {
39  return;
40  }
42  ht_up_free(ev->callbacks);
44  free(ev);
45 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API void rz_vector_fini(RzVector *vec)
Definition: vector.c:61
RzVector all_callbacks
Definition: rz_event.h:18
HtUP * callbacks
Definition: rz_event.h:17
RzVector pending_unhook
while inside of a call and a handle is unhooked, the unhook is deferred and saved here
Definition: rz_event.h:19

References rz_event_t::all_callbacks, rz_event_t::callbacks, free(), rz_event_t::pending_unhook, and rz_vector_fini().

Referenced by rz_bin_free(), rz_bin_new(), rz_core_fini(), rz_event_new(), rz_io_fini(), and rz_spaces_fini().

◆ rz_event_hook()

RZ_API RzEventCallbackHandle rz_event_hook ( RzEvent ev,
int  type,
RzEventCallback  cb,
void *  user 
)

Definition at line 58 of file event.c.

58  {
61 
63  hook.cb = cb;
64  hook.user = user;
65  hook.handle = ev->next_handle++;
66  if (type == RZ_EVENT_ALL) {
67  rz_vector_push(&ev->all_callbacks, &hook);
68  } else {
69  RzVector *cbs = get_cbs(ev, type);
70  if (!cbs) {
71  return handle;
72  }
73  rz_vector_push(cbs, &hook);
74  }
75  handle.handle = hook.handle;
76  handle.type = type;
77  return handle;
78 }
static mcore_handle handle
Definition: asm_mcore.c:8
static RzVector * get_cbs(RzEvent *ev, int type)
Definition: event.c:47
int type
Definition: mipsasm.c:17
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API void * rz_vector_push(RzVector *vec, void *x)
Definition: vector.c:197
RzEventCallback cb
Definition: event.c:8
int next_handle
Definition: rz_event.h:20
static const char * cb[]
Definition: z80_tab.h:176

References rz_event_t::all_callbacks, cb, rz_event_callback_hook_t::cb, get_cbs(), handle, rz_event_callback_hook_t::handle, rz_event_t::next_handle, RZ_EVENT_ALL, rz_return_val_if_fail, rz_vector_push(), type, and rz_event_callback_hook_t::user.

Referenced by new_spaces(), rz_analysis_new(), and rz_core_init().

◆ rz_event_new()

RZ_API RzEvent* rz_event_new ( void *  user)

Definition at line 17 of file event.c.

17  {
18  RzEvent *ev = RZ_NEW0(RzEvent);
19  if (!ev) {
20  return NULL;
21  }
22 
23  ev->user = user;
24  ev->next_handle = 0;
25  ev->callbacks = ht_up_new(NULL, ht_callback_free, NULL);
26  if (!ev->callbacks) {
27  goto err;
28  }
31  return ev;
32 err:
33  rz_event_free(ev);
34  return NULL;
35 }
static bool err
Definition: armass.c:435
#define NULL
Definition: cris-opc.c:27
RZ_API void rz_event_free(RzEvent *ev)
Definition: event.c:37
static void ht_callback_free(HtUPKv *kv)
Definition: event.c:13
#define RZ_NEW0(x)
Definition: rz_types.h:284
RZ_API void rz_vector_init(RzVector *vec, size_t elem_size, RzVectorFree free, void *free_user)
Definition: vector.c:33
void * user
Definition: rz_event.h:15

References rz_event_t::all_callbacks, rz_event_t::callbacks, err, ht_callback_free(), rz_event_t::next_handle, NULL, rz_event_t::pending_unhook, rz_event_free(), RZ_NEW0, rz_vector_init(), and rz_event_t::user.

Referenced by rz_bin_new(), rz_core_init(), rz_io_init(), and rz_spaces_init().

◆ rz_event_send()

RZ_API void rz_event_send ( RzEvent ev,
int  type,
void *  data 
)

Definition at line 115 of file event.c.

115  {
116  RzEventCallbackHook *hook;
117  rz_return_if_fail(ev && !ev->incall);
118 
119  // send to both the per-type callbacks and to the all_callbacks
120  ev->incall = true;
121  rz_vector_foreach(&ev->all_callbacks, hook) {
122  hook->cb(ev, type, hook->user, data);
123  }
124  ev->incall = false;
125 
126  RzVector *cbs = ht_up_find(ev->callbacks, (ut64)type, NULL);
127  if (cbs) {
128  ev->incall = true;
129  rz_vector_foreach(cbs, hook) {
130  hook->cb(ev, type, hook->user, data);
131  }
132  ev->incall = false;
133  }
134 
135  RzEventCallbackHandle *unhook_handle;
136  rz_vector_foreach(&ev->pending_unhook, unhook_handle) {
137  rz_event_unhook(ev, *unhook_handle);
138  }
140 }
RZ_API void rz_event_unhook(RzEvent *ev, RzEventCallbackHandle handle)
Definition: event.c:95
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
#define rz_vector_foreach(vec, it)
Definition: rz_vector.h:169
RZ_API void rz_vector_clear(RzVector *vec)
Definition: vector.c:68
bool incall
Definition: rz_event.h:16
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_event_t::all_callbacks, rz_event_t::callbacks, rz_event_callback_hook_t::cb, rz_event_t::incall, NULL, rz_event_t::pending_unhook, rz_event_unhook(), rz_return_if_fail, rz_vector_clear(), rz_vector_foreach, type, rz_event_callback_hook_t::user, and ut64().

Referenced by map_del(), rz_analysis_class_create(), rz_analysis_class_delete(), rz_analysis_class_delete_attr_raw(), rz_analysis_class_rename(), rz_analysis_class_rename_attr_raw(), rz_analysis_class_set_attr_raw(), rz_bin_file_delete(), rz_bin_file_delete_all(), rz_debug_wait(), rz_io_cache_write(), rz_io_desc_cache_write(), rz_io_desc_close(), rz_io_map_fini(), rz_io_plugin_write(), rz_spaces_count(), rz_spaces_rename(), and spaces_unset_single().

◆ rz_event_unhook()

RZ_API void rz_event_unhook ( RzEvent ev,
RzEventCallbackHandle  handle 
)

Definition at line 95 of file event.c.

95  {
97  if (ev->incall) {
98  // when inside a call (meaning rz_event_send currently iterates over the callback vectors),
99  // defer the unhook to after the rz_event_send is done.
101  return;
102  }
103  if (handle.type == RZ_EVENT_ALL) {
104  // try to delete it both from each list of callbacks and from
105  // the "all_callbacks" vector
106  ht_up_foreach(ev->callbacks, del_hook, &handle.handle);
107  del_hook(&handle.handle, 0, &ev->all_callbacks);
108  } else {
109  RzVector *cbs = ht_up_find(ev->callbacks, (ut64)handle.type, NULL);
110  rz_return_if_fail(cbs);
111  del_hook(&handle.handle, 0, cbs);
112  }
113 }
static bool del_hook(void *user, const ut64 k, const void *v)
Definition: event.c:80

References rz_event_t::all_callbacks, rz_event_t::callbacks, del_hook(), handle, rz_event_t::incall, NULL, rz_event_t::pending_unhook, RZ_EVENT_ALL, rz_return_if_fail, rz_vector_push(), and ut64().

Referenced by rz_event_send().