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

Go to the source code of this file.

Functions

RZ_API void rz_analysis_esil_sources_init (RzAnalysisEsil *esil)
 
RZ_API ut32 rz_analysis_esil_load_source (RzAnalysisEsil *esil, const char *path)
 
static RzAnalysisEsilSource_get_source (RzAnalysisEsil *esil, ut32 src_id)
 
RZ_API void * rz_analysis_esil_get_source (RzAnalysisEsil *esil, ut32 src_id)
 
RZ_API bool rz_analysis_esil_claim_source (RzAnalysisEsil *esil, ut32 src_id)
 
RZ_API void rz_analysis_esil_release_source (RzAnalysisEsil *esil, ut32 src_id)
 
static bool _free_source_cb (void *user, void *data, ut32 id)
 
RZ_API void rz_analysis_esil_sources_fini (RzAnalysisEsil *esil)
 

Function Documentation

◆ _free_source_cb()

static bool _free_source_cb ( void *  user,
void *  data,
ut32  id 
)
static

Definition at line 75 of file esil_sources.c.

75  {
77 
78  if (src) {
79  rz_lib_dl_close(src->content);
80  }
81  free(src);
82  return true;
83 }
lzma_index * src
Definition: index.h:567
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API int rz_lib_dl_close(void *handler)
Definition: lib.c:104

References free(), rz_lib_dl_close(), and src.

Referenced by rz_analysis_esil_sources_fini().

◆ _get_source()

static RzAnalysisEsilSource* _get_source ( RzAnalysisEsil esil,
ut32  src_id 
)
static

Definition at line 37 of file esil_sources.c.

37  {
38  if (!esil || !esil->sources) {
39  return NULL;
40  }
41  return (RzAnalysisEsilSource *)rz_id_storage_get(esil->sources, src_id);
42 }
#define NULL
Definition: cris-opc.c:27
RZ_API void * rz_id_storage_get(RzIDStorage *storage, ut32 id)
Definition: idpool.c:162
RzIDStorage * sources
Definition: rz_analysis.h:1073

References NULL, rz_id_storage_get(), and rz_analysis_esil_t::sources.

Referenced by rz_analysis_esil_claim_source(), rz_analysis_esil_get_source(), and rz_analysis_esil_release_source().

◆ rz_analysis_esil_claim_source()

RZ_API bool rz_analysis_esil_claim_source ( RzAnalysisEsil esil,
ut32  src_id 
)

Definition at line 50 of file esil_sources.c.

50  {
51  RzAnalysisEsilSource *src = _get_source(esil, src_id);
52 
53  if (src) {
54  src->claimed++;
55  return true;
56  }
57  return false;
58 }
static RzAnalysisEsilSource * _get_source(RzAnalysisEsil *esil, ut32 src_id)
Definition: esil_sources.c:37

References _get_source(), and src.

Referenced by rz_analysis_esil_interrupt_new().

◆ rz_analysis_esil_get_source()

RZ_API void* rz_analysis_esil_get_source ( RzAnalysisEsil esil,
ut32  src_id 
)

Definition at line 44 of file esil_sources.c.

44  {
45  RzAnalysisEsilSource *src = _get_source(esil, src_id);
46 
47  return src ? src->content : NULL;
48 }

References _get_source(), NULL, and src.

Referenced by rz_analysis_esil_load_interrupts_from_lib().

◆ rz_analysis_esil_load_source()

RZ_API ut32 rz_analysis_esil_load_source ( RzAnalysisEsil esil,
const char *  path 
)

Definition at line 14 of file esil_sources.c.

14  {
17 
19  src->content = rz_lib_dl_open(path);
20  if (!src->content) {
21  RZ_LOG_ERROR("esil: cannot load library (no content)\n");
22  free(src);
23  return 0;
24  }
25 
27  if (!rz_id_storage_add(esil->sources, src, &src->id)) {
28  RZ_LOG_ERROR("esil: cannot add to id storage\n");
29  rz_lib_dl_close(src->content);
30  free(src);
31  return 0;
32  }
33 
34  return src->id;
35 }
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 void rz_analysis_esil_sources_init(RzAnalysisEsil *esil)
Definition: esil_sources.c:8
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API bool rz_id_storage_add(RzIDStorage *storage, void *data, ut32 *id)
Definition: idpool.c:155
RZ_API void * rz_lib_dl_open(const char *libname)
Definition: lib.c:54
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define RZ_STR_ISNOTEMPTY(x)
Definition: rz_str.h:68
#define RZ_NEW0(x)
Definition: rz_types.h:284

References free(), path, rz_analysis_esil_sources_init(), rz_id_storage_add(), rz_lib_dl_close(), rz_lib_dl_open(), RZ_LOG_ERROR, RZ_NEW0, rz_return_val_if_fail, RZ_STR_ISNOTEMPTY, rz_analysis_esil_t::sources, and src.

Referenced by rz_analysis_esil_load_interrupts_from_lib().

◆ rz_analysis_esil_release_source()

RZ_API void rz_analysis_esil_release_source ( RzAnalysisEsil esil,
ut32  src_id 
)

Definition at line 60 of file esil_sources.c.

60  {
61  RzAnalysisEsilSource *src = _get_source(esil, src_id);
62 
63  if (!src) {
64  return;
65  }
66  if (src->claimed <= 1) {
67  rz_id_storage_delete(esil->sources, src_id);
68  rz_lib_dl_close(src->content);
69  free(src);
70  } else {
71  src->claimed--;
72  }
73 }
RZ_API void rz_id_storage_delete(RzIDStorage *storage, ut32 id)
Definition: idpool.c:221

References _get_source(), free(), rz_id_storage_delete(), rz_lib_dl_close(), rz_analysis_esil_t::sources, and src.

Referenced by rz_analysis_esil_interrupt_free(), and rz_analysis_esil_load_interrupts_from_lib().

◆ rz_analysis_esil_sources_fini()

RZ_API void rz_analysis_esil_sources_fini ( RzAnalysisEsil esil)

Definition at line 85 of file esil_sources.c.

85  {
86  if (esil) {
89  }
90 }
static bool _free_source_cb(void *user, void *data, ut32 id)
Definition: esil_sources.c:75
RZ_API void rz_id_storage_free(RzIDStorage *storage)
Definition: idpool.c:270
RZ_API bool rz_id_storage_foreach(RzIDStorage *storage, RzIDStorageForeachCb cb, void *user)
Definition: idpool.c:254

References _free_source_cb(), NULL, rz_id_storage_foreach(), rz_id_storage_free(), and rz_analysis_esil_t::sources.

Referenced by rz_analysis_esil_free().

◆ rz_analysis_esil_sources_init()

RZ_API void rz_analysis_esil_sources_init ( RzAnalysisEsil esil)

Definition at line 8 of file esil_sources.c.

8  {
9  if (esil && !esil->sources) {
10  esil->sources = rz_id_storage_new(1, 0xffffffff); // 0 is reserved for stuff from plugins
11  }
12 }
RZ_API RzIDStorage * rz_id_storage_new(ut32 start_id, ut32 last_id)
Definition: idpool.c:80

References rz_id_storage_new(), and rz_analysis_esil_t::sources.

Referenced by rz_analysis_esil_load_source(), and rz_analysis_esil_new().