Rizin
unix-like reverse engineering framework and cli tools
esil_interrupt.c File Reference
#include <rz_analysis.h>
#include <rz_util.h>
#include <rz_lib.h>

Go to the source code of this file.

Functions

static void interrupt_free (HtUPKv *kv)
 
RZ_API void rz_analysis_esil_interrupts_init (RzAnalysisEsil *esil)
 
RZ_API RzAnalysisEsilInterruptrz_analysis_esil_interrupt_new (RzAnalysisEsil *esil, ut32 src_id, RzAnalysisEsilInterruptHandler *ih)
 
RZ_API void rz_analysis_esil_interrupt_free (RzAnalysisEsil *esil, RzAnalysisEsilInterrupt *intr)
 
RZ_API bool rz_analysis_esil_set_interrupt (RzAnalysisEsil *esil, RzAnalysisEsilInterrupt *intr)
 
RZ_API int rz_analysis_esil_fire_interrupt (RzAnalysisEsil *esil, ut32 intr_num)
 
RZ_API bool rz_analysis_esil_load_interrupts (RzAnalysisEsil *esil, RzAnalysisEsilInterruptHandler *handlers[], ut32 src_id)
 
RZ_API bool rz_analysis_esil_load_interrupts_from_lib (RzAnalysisEsil *esil, const char *path)
 
RZ_API void rz_analysis_esil_interrupts_fini (RzAnalysisEsil *esil)
 

Function Documentation

◆ interrupt_free()

static void interrupt_free ( HtUPKv *  kv)
static

Definition at line 8 of file esil_interrupt.c.

8  {
11 }
lzma_index ** i
Definition: index.h:629
RZ_API void rz_analysis_esil_interrupt_free(RzAnalysisEsil *esil, RzAnalysisEsilInterrupt *intr)

References i, and rz_analysis_esil_interrupt_free().

Referenced by rz_analysis_esil_interrupts_init().

◆ rz_analysis_esil_fire_interrupt()

RZ_API int rz_analysis_esil_fire_interrupt ( RzAnalysisEsil esil,
ut32  intr_num 
)

Definition at line 50 of file esil_interrupt.c.

50  {
51  rz_return_val_if_fail(esil, false);
52 
53  if (esil->cmd && esil->cmd(esil, esil->cmd_intr, intr_num, 0)) { // compatibility
54  return true;
55  }
56 
57  if (!esil->interrupts) {
58  RZ_LOG_ERROR("no interrupts initialized\n");
59  return false;
60  }
61  RzAnalysisEsilInterrupt *intr = ht_up_find(esil->interrupts, intr_num, NULL);
62 #if 0
63  // we don't want this warning
64  if (!intr) {
65  RZ_LOG_WARN("no interrupt handler registered for 0x%x\n", intr_num);
66  }
67 #endif
68  return (intr && intr->handler && intr->handler->cb) ? intr->handler->cb(esil, intr_num, intr->user) : false;
69 }
#define NULL
Definition: cris-opc.c:27
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RzAnalysisEsilInterruptCB cb
Definition: rz_analysis.h:998
RzAnalysisEsilInterruptHandler * handler
Definition: rz_analysis.h:1171
bool(* cmd)(ANALYSIS_ESIL *esil, const char *name, ut64 a0, ut64 a1)
Definition: rz_analysis.h:1089

References rz_analysis_esil_interrupt_handler_t::cb, rz_analysis_esil_t::cmd, rz_analysis_esil_t::cmd_intr, rz_analysis_esil_interrupt_t::handler, rz_analysis_esil_t::interrupts, NULL, RZ_LOG_ERROR, RZ_LOG_WARN, rz_return_val_if_fail, and rz_analysis_esil_interrupt_t::user.

Referenced by esil_interrupt().

◆ rz_analysis_esil_interrupt_free()

RZ_API void rz_analysis_esil_interrupt_free ( RzAnalysisEsil esil,
RzAnalysisEsilInterrupt intr 
)

Definition at line 34 of file esil_interrupt.c.

34  {
35  rz_return_if_fail(esil);
36  if (intr) {
37  if (intr->user) {
38  intr->handler->fini(intr->user); // fini must exist when user is !NULL
39  }
41  free(intr);
42  }
43 }
RZ_API void rz_analysis_esil_release_source(RzAnalysisEsil *esil, ut32 src_id)
Definition: esil_sources.c:60
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100

References rz_analysis_esil_interrupt_handler_t::fini, free(), rz_analysis_esil_interrupt_t::handler, rz_analysis_esil_release_source(), rz_return_if_fail, rz_analysis_esil_interrupt_t::src_id, and rz_analysis_esil_interrupt_t::user.

Referenced by interrupt_free().

◆ rz_analysis_esil_interrupt_new()

RZ_API RzAnalysisEsilInterrupt* rz_analysis_esil_interrupt_new ( RzAnalysisEsil esil,
ut32  src_id,
RzAnalysisEsilInterruptHandler ih 
)

Definition at line 18 of file esil_interrupt.c.

18  {
19  rz_return_val_if_fail(esil && ih && ih->cb, NULL);
21  if (!intr) {
22  return NULL;
23  }
24  intr->esil = esil;
25  intr->handler = ih;
26  if (ih->init && ih->fini) {
27  intr->user = ih->init(esil);
28  }
29  intr->src_id = src_id;
30  rz_analysis_esil_claim_source(esil, src_id);
31  return intr;
32 }
RZ_API bool rz_analysis_esil_claim_source(RzAnalysisEsil *esil, ut32 src_id)
Definition: esil_sources.c:50
#define RZ_NEW0(x)
Definition: rz_types.h:284
void *(* init)(ANALYSIS_ESIL *esil)
Definition: rz_analysis.h:997

References rz_analysis_esil_interrupt_handler_t::cb, rz_analysis_esil_interrupt_t::esil, rz_analysis_esil_interrupt_handler_t::fini, rz_analysis_esil_interrupt_t::handler, rz_analysis_esil_interrupt_handler_t::init, NULL, rz_analysis_esil_claim_source(), RZ_NEW0, rz_return_val_if_fail, rz_analysis_esil_interrupt_t::src_id, and rz_analysis_esil_interrupt_t::user.

Referenced by rz_analysis_esil_load_interrupts().

◆ rz_analysis_esil_interrupts_fini()

RZ_API void rz_analysis_esil_interrupts_fini ( RzAnalysisEsil esil)

Definition at line 106 of file esil_interrupt.c.

106  {
107  rz_return_if_fail(esil && esil->interrupts);
108  ht_up_free(esil->interrupts);
109  esil->interrupts = NULL;
110 }

References rz_analysis_esil_t::interrupts, NULL, and rz_return_if_fail.

Referenced by rz_analysis_esil_free().

◆ rz_analysis_esil_interrupts_init()

RZ_API void rz_analysis_esil_interrupts_init ( RzAnalysisEsil esil)

Definition at line 13 of file esil_interrupt.c.

13  {
14  rz_return_if_fail(esil);
15  esil->interrupts = ht_up_new(NULL, interrupt_free, NULL);
16 }
static void interrupt_free(HtUPKv *kv)
Definition: esil_interrupt.c:8

References interrupt_free(), rz_analysis_esil_t::interrupts, NULL, and rz_return_if_fail.

Referenced by rz_analysis_esil_new().

◆ rz_analysis_esil_load_interrupts()

RZ_API bool rz_analysis_esil_load_interrupts ( RzAnalysisEsil esil,
RzAnalysisEsilInterruptHandler handlers[],
ut32  src_id 
)

Definition at line 71 of file esil_interrupt.c.

71  {
73  ut32 i = 0;
74 
75  rz_return_val_if_fail(esil && esil->interrupts && handlers, false);
76 
77  while (handlers[i]) {
78  intr = rz_analysis_esil_interrupt_new(esil, src_id, handlers[i]);
79  if (!intr) {
80  return false;
81  }
82  if (!rz_analysis_esil_set_interrupt(esil, intr)) {
83  free(intr);
84  }
85  i++;
86  }
87 
88  return true;
89 }
uint32_t ut32
RZ_API RzAnalysisEsilInterrupt * rz_analysis_esil_interrupt_new(RzAnalysisEsil *esil, ut32 src_id, RzAnalysisEsilInterruptHandler *ih)
RZ_API bool rz_analysis_esil_set_interrupt(RzAnalysisEsil *esil, RzAnalysisEsilInterrupt *intr)

References free(), i, rz_analysis_esil_t::interrupts, rz_analysis_esil_interrupt_new(), rz_analysis_esil_set_interrupt(), and rz_return_val_if_fail.

Referenced by rz_analysis_esil_load_interrupts_from_lib().

◆ rz_analysis_esil_load_interrupts_from_lib()

RZ_API bool rz_analysis_esil_load_interrupts_from_lib ( RzAnalysisEsil esil,
const char *  path 
)

Definition at line 91 of file esil_interrupt.c.

91  {
92  rz_return_val_if_fail(esil, false);
93  ut32 src_id = rz_analysis_esil_load_source(esil, path);
94  if (!src_id) { // why id=0 is invalid?
95  return false;
96  }
98  rz_lib_dl_sym(rz_analysis_esil_get_source(esil, src_id), "interrupts");
99  if (!handlers) {
100  rz_analysis_esil_release_source(esil, src_id); // unload
101  return false;
102  }
103  return rz_analysis_esil_load_interrupts(esil, handlers, src_id);
104 }
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
RZ_API bool rz_analysis_esil_load_interrupts(RzAnalysisEsil *esil, RzAnalysisEsilInterruptHandler *handlers[], ut32 src_id)
RZ_API void * rz_analysis_esil_get_source(RzAnalysisEsil *esil, ut32 src_id)
Definition: esil_sources.c:44
RZ_API ut32 rz_analysis_esil_load_source(RzAnalysisEsil *esil, const char *path)
Definition: esil_sources.c:14
RZ_API void * rz_lib_dl_sym(void *handler, const char *name)
Definition: lib.c:90

References path, rz_analysis_esil_get_source(), rz_analysis_esil_load_interrupts(), rz_analysis_esil_load_source(), rz_analysis_esil_release_source(), rz_lib_dl_sym(), and rz_return_val_if_fail.

Referenced by cmd_analysis_esil().

◆ rz_analysis_esil_set_interrupt()

RZ_API bool rz_analysis_esil_set_interrupt ( RzAnalysisEsil esil,
RzAnalysisEsilInterrupt intr 
)