Rizin
unix-like reverse engineering framework and cli tools
io_map.c File Reference
#include <rz_io.h>
#include <stdlib.h>
#include <sdb.h>
#include "rz_util.h"
#include "rz_vector.h"

Go to the source code of this file.

Macros

#define END_OF_MAP_IDS   UT32_MAX
 

Functions

void io_map_calculate_skyline (RzIO *io)
 
RzIOMapio_map_new (RzIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size)
 
RZ_API RzIOMaprz_io_map_new (RzIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size)
 
RZ_API bool rz_io_map_remap (RzIO *io, ut32 id, ut64 addr)
 
RZ_API bool rz_io_map_remap_fd (RzIO *io, int fd, ut64 addr)
 
static void map_free (void *p)
 Free-only. Be careful to only call this after sending RZ_EVENT_IO_MAP_DEL! (map_del does this) More...
 
static void map_del (RzIO *io, RzIOMap *map)
 Free the map, also sending the appropriate event. More...
 
RZ_API void rz_io_map_init (RzIO *io)
 
RZ_API bool rz_io_map_exists (RzIO *io, RzIOMap *map)
 
RZ_API bool rz_io_map_exists_for_id (RzIO *io, ut32 id)
 
RZ_API RzIOMaprz_io_map_resolve (RzIO *io, ut32 id)
 
RzIOMapio_map_add (RzIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size)
 
RZ_API RzIOMaprz_io_map_add (RzIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size)
 
RZ_API RzIOMaprz_io_map_add_batch (RzIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size)
 
RZ_API void rz_io_update (RzIO *io)
 
RZ_API RzIOMaprz_io_map_get_paddr (RzIO *io, ut64 paddr)
 
RZ_API RzIOMaprz_io_map_get (RzIO *io, ut64 addr)
 
RZ_API bool rz_io_map_is_mapped (RzIO *io, ut64 addr)
 
RZ_API void rz_io_map_reset (RzIO *io)
 
RZ_API bool rz_io_map_del (RzIO *io, ut32 id)
 
RZ_API bool rz_io_map_del_for_fd (RzIO *io, int fd)
 
RZ_API bool rz_io_map_priorize (RzIO *io, ut32 id)
 
RZ_API bool rz_io_map_depriorize (RzIO *io, ut32 id)
 
RZ_API bool rz_io_map_priorize_for_fd (RzIO *io, int fd)
 
RZ_API void rz_io_map_cleanup (RzIO *io)
 
RZ_API void rz_io_map_fini (RzIO *io)
 
RZ_API void rz_io_map_set_name (RzIOMap *map, const char *name)
 
RZ_API void rz_io_map_del_name (RzIOMap *map)
 
RZ_API ut64 rz_io_map_next_available (RzIO *io, ut64 addr, ut64 size, ut64 load_align)
 
RZ_API ut64 rz_io_map_next_address (RzIO *io, ut64 addr)
 
RZ_API RzListrz_io_map_get_for_fd (RzIO *io, int fd)
 
RZ_API bool rz_io_map_resize (RzIO *io, ut32 id, ut64 newsize)
 
RZ_API ut64 rz_io_map_location (RzIO *io, ut64 size)
 Returns a memory location that can hold enough bytes without overlapping. More...
 
RZ_API RZ_BORROW RzPVectorrz_io_maps (RzIO *io)
 Returns the pointer to vector containing maps list. More...
 

Macro Definition Documentation

◆ END_OF_MAP_IDS

#define END_OF_MAP_IDS   UT32_MAX

Definition at line 11 of file io_map.c.

Function Documentation

◆ io_map_add()

RzIOMap* io_map_add ( RzIO io,
int  fd,
int  perm,
ut64  delta,
ut64  addr,
ut64  size 
)

Definition at line 140 of file io_map.c.

140  {
141  // check if desc exists
142  RzIODesc *desc = rz_io_desc_get(io, fd);
143  if (desc) {
144  // a map cannot have higher permissions than the desc belonging to it
145  return io_map_new(io, fd, (perm & desc->perm) | (perm & RZ_PERM_X),
146  delta, addr, size);
147  }
148  return NULL;
149 }
const char * desc
Definition: bin_vsf.c:19
#define NULL
Definition: cris-opc.c:27
RzIOMap * io_map_new(RzIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size)
Definition: io_map.c:24
voidpf void uLong size
Definition: ioapi.h:138
RZ_API RzIODesc * rz_io_desc_get(RzIO *io, int fd)
Definition: io_desc.c:73
#define RZ_PERM_X
Definition: rz_types.h:95
static st64 delta
Definition: vmenus.c:2425
static const z80_opcode fd[]
Definition: z80_tab.h:997
static int addr
Definition: z80asm.c:58

References addr, delta, desc, fd, io_map_new(), NULL, rz_io_desc_get(), and RZ_PERM_X.

Referenced by rz_io_map_add(), and rz_io_map_add_batch().

◆ io_map_calculate_skyline()

void io_map_calculate_skyline ( RzIO io)

Definition at line 14 of file io_map.c.

14  {
16  // Last map has highest priority (it shadows previous maps)
17  void **it;
18  rz_pvector_foreach (&io->maps, it) {
19  RzIOMap *map = (RzIOMap *)*it;
20  rz_skyline_add(&io->map_skyline, map->itv, map);
21  }
22 }
size_t map(int syms, int left, int len)
Definition: enough.c:237
static void rz_skyline_clear(RzSkyline *skyline)
Definition: rz_skyline.h:29
RZ_API bool rz_skyline_add(RzSkyline *skyline, RzInterval itv, void *user)
Definition: skyline.c:12
#define rz_pvector_foreach(vec, it)
Definition: rz_vector.h:334
RzPVector maps
Definition: rz_io.h:73
RzSkyline map_skyline
Definition: rz_io.h:74

References map(), rz_io_t::map_skyline, rz_io_t::maps, rz_pvector_foreach, rz_skyline_add(), and rz_skyline_clear().

Referenced by rz_io_map_cleanup(), rz_io_map_del(), rz_io_map_del_for_fd(), rz_io_map_depriorize(), rz_io_map_priorize_for_fd(), rz_io_map_remap(), rz_io_map_reset(), rz_io_map_resize(), and rz_io_update().

◆ io_map_new()

RzIOMap* io_map_new ( RzIO io,
int  fd,
int  perm,
ut64  delta,
ut64  addr,
ut64  size 
)

XXX: this is leaking a map!!!

Definition at line 24 of file io_map.c.

24  {
25  if (!io || !io->map_ids) {
26  return NULL;
27  }
29  if (!map || !io->map_ids || !rz_id_pool_grab_id(io->map_ids, &map->id)) {
30  free(map);
31  return NULL;
32  }
33  map->fd = fd;
34  map->delta = delta;
35  if (size && (UT64_MAX - size + 1) < addr) {
37  io_map_new(io, fd, perm, delta - addr, 0LL, size + addr);
38  size = -(st64)addr;
39  }
40  // RzIOMap describes an interval of addresses (map->from; map->to)
41  map->itv = (RzInterval){ addr, size };
42  map->perm = perm;
43  map->delta = delta;
44  // new map lives on the top, being top the list's tail
45  rz_pvector_push(&io->maps, map);
46  rz_skyline_add(&io->map_skyline, map->itv, map);
47  return map;
48 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API bool rz_id_pool_grab_id(RzIDPool *pool, ut32 *grabber)
Definition: idpool.c:34
struct rz_interval_t RzInterval
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define st64
Definition: rz_types_base.h:10
#define UT64_MAX
Definition: rz_types_base.h:86
static void ** rz_pvector_push(RzPVector *vec, void *x)
Definition: rz_vector.h:300
RzIDPool * map_ids
Definition: rz_io.h:72

References addr, delta, fd, free(), map(), rz_io_t::map_ids, rz_io_t::map_skyline, rz_io_t::maps, NULL, rz_id_pool_grab_id(), RZ_NEW0, rz_pvector_push(), rz_skyline_add(), st64, and UT64_MAX.

Referenced by io_map_add(), rz_io_map_new(), and rz_io_open_at().

◆ map_del()

static void map_del ( RzIO io,
RzIOMap map 
)
static

Free the map, also sending the appropriate event.

Definition at line 93 of file io_map.c.

93  {
94  rz_return_if_fail(io && map);
95  RzEventIOMapDel ev = { map };
97  rz_id_pool_kick_id(io->map_ids, map->id);
98  map_free(map);
99 }
static void map_free(void *p)
Free-only. Be careful to only call this after sending RZ_EVENT_IO_MAP_DEL! (map_del does this)
Definition: io_map.c:84
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
RZ_API void rz_event_send(RzEvent *ev, int type, void *data)
Definition: event.c:115
@ RZ_EVENT_IO_MAP_DEL
Definition: rz_event.h:44
RZ_API bool rz_id_pool_kick_id(RzIDPool *pool, ut32 kick)
Definition: idpool.c:53
RzEvent * event
Definition: rz_io.h:90

References rz_io_t::event, map(), map_free(), rz_io_t::map_ids, RZ_EVENT_IO_MAP_DEL, rz_event_send(), rz_id_pool_kick_id(), and rz_return_if_fail.

Referenced by rz_io_map_cleanup(), rz_io_map_del(), and rz_io_map_del_for_fd().

◆ map_free()

static void map_free ( void *  p)
static

Free-only. Be careful to only call this after sending RZ_EVENT_IO_MAP_DEL! (map_del does this)

Definition at line 84 of file io_map.c.

84  {
85  RzIOMap *map = (RzIOMap *)p;
86  if (map) {
87  free(map->name);
88  free(map);
89  }
90 }
void * p
Definition: libc.cpp:67

References free(), map(), and p.

Referenced by map_del(), and rz_io_map_init().

◆ rz_io_map_add()

RZ_API RzIOMap* rz_io_map_add ( RzIO io,
int  fd,
int  perm,
ut64  delta,
ut64  addr,
ut64  size 
)

Definition at line 151 of file io_map.c.

151  {
152  return io_map_add(io, fd, perm, delta, addr, size);
153 }
RzIOMap * io_map_add(RzIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size)
Definition: io_map.c:140

References addr, delta, fd, and io_map_add().

Referenced by ds_init(), rz_core_analysis_esil_init_mem(), rz_core_serve(), rz_io_bind(), rz_open_maps_all_fd_handler(), rz_open_maps_map_fd_handler(), and rz_open_maps_map_handler().

◆ rz_io_map_add_batch()

RZ_API RzIOMap* rz_io_map_add_batch ( RzIO io,
int  fd,
int  perm,
ut64  delta,
ut64  addr,
ut64  size 
)

Definition at line 155 of file io_map.c.

155  {
156  return io_map_add(io, fd, perm, delta, addr, size);
157 }

References addr, delta, fd, and io_map_add().

Referenced by add_map(), and io_create_mem_map().

◆ rz_io_map_cleanup()

RZ_API void rz_io_map_cleanup ( RzIO io)

Definition at line 287 of file io_map.c.

287  {
288  rz_return_if_fail(io);
289  // remove all maps if no descs exist
290  if (!io->files) {
291  rz_io_map_fini(io);
292  rz_io_map_init(io);
293  return;
294  }
295  bool del = false;
296  size_t i;
297  for (i = 0; i < rz_pvector_len(&io->maps);) {
298  RzIOMap *map = rz_pvector_at(&io->maps, i);
299  if (!map) {
300  // remove iter if the map is a null-ptr, this may fix some segfaults. This should never happen.
302  rz_pvector_remove_at(&io->maps, i);
303  del = true;
304  } else if (!rz_io_desc_get(io, map->fd)) {
305  // delete map and iter if no desc exists for map->fd in io->files
306  map = rz_pvector_remove_at(&io->maps, i);
307  map_del(io, map);
308  del = true;
309  } else {
310  i++;
311  }
312  }
313  if (del) {
315  }
316 }
lzma_index ** i
Definition: index.h:629
void io_map_calculate_skyline(RzIO *io)
Definition: io_map.c:14
RZ_API void rz_io_map_init(RzIO *io)
Definition: io_map.c:101
static void map_del(RzIO *io, RzIOMap *map)
Free the map, also sending the appropriate event.
Definition: io_map.c:93
RZ_API void rz_io_map_fini(RzIO *io)
Definition: io_map.c:318
static void del(RzAnalysis *a, RzAnalysisMetaType type, const RzSpace *space, ut64 addr, ut64 size)
Definition: meta.c:155
#define rz_warn_if_reached()
Definition: rz_assert.h:29
static size_t rz_pvector_len(const RzPVector *vec)
Definition: rz_vector.h:231
RZ_API void * rz_pvector_remove_at(RzPVector *vec, size_t index)
Definition: vector.c:355
static void * rz_pvector_at(const RzPVector *vec, size_t index)
Definition: rz_vector.h:236
RzIDStorage * files
Definition: rz_io.h:75

References del(), rz_io_t::files, i, io_map_calculate_skyline(), map(), map_del(), rz_io_t::maps, rz_io_desc_get(), rz_io_map_fini(), rz_io_map_init(), rz_pvector_at(), rz_pvector_len(), rz_pvector_remove_at(), rz_return_if_fail, and rz_warn_if_reached.

Referenced by rz_io_desc_close(), rz_io_desc_del(), and rz_io_map_priorize_for_fd().

◆ rz_io_map_del()

RZ_API bool rz_io_map_del ( RzIO io,
ut32  id 
)

Definition at line 192 of file io_map.c.

192  {
193  rz_return_val_if_fail(io, false);
194  size_t i;
195  for (i = 0; i < rz_pvector_len(&io->maps); i++) {
196  RzIOMap *map = rz_pvector_at(&io->maps, i);
197  if (map->id == id) {
198  rz_pvector_remove_at(&io->maps, i);
199  map_del(io, map);
201  return true;
202  }
203  }
204  return false;
205 }
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108

References i, io_map_calculate_skyline(), map(), map_del(), rz_io_t::maps, rz_pvector_at(), rz_pvector_len(), rz_pvector_remove_at(), and rz_return_val_if_fail.

Referenced by rz_core_file_close(), rz_debug_dmp_init(), and rz_open_maps_remove_handler().

◆ rz_io_map_del_for_fd()

RZ_API bool rz_io_map_del_for_fd ( RzIO io,
int  fd 
)

Definition at line 208 of file io_map.c.

208  {
209  rz_return_val_if_fail(io, false);
210  bool ret = false;
211  size_t i;
212  for (i = 0; i < rz_pvector_len(&io->maps);) {
213  RzIOMap *map = rz_pvector_at(&io->maps, i);
214  if (!map) {
215  rz_pvector_remove_at(&io->maps, i);
216  } else if (map->fd == fd) {
217  rz_pvector_remove_at(&io->maps, i);
218  map_del(io, map);
219  ret = true;
220  } else {
221  i++;
222  }
223  }
224  if (ret) {
226  }
227  return ret;
228 }

References fd, i, io_map_calculate_skyline(), map(), map_del(), rz_io_t::maps, rz_pvector_at(), rz_pvector_len(), rz_pvector_remove_at(), and rz_return_val_if_fail.

◆ rz_io_map_del_name()

RZ_API void rz_io_map_del_name ( RzIOMap map)

Definition at line 340 of file io_map.c.

340  {
341  if (map) {
342  RZ_FREE(map->name);
343  }
344 }
#define RZ_FREE(x)
Definition: rz_types.h:369

References map(), and RZ_FREE.

Referenced by rz_open_maps_name_del_handler(), and rz_open_maps_name_id_del_handler().

◆ rz_io_map_depriorize()

RZ_API bool rz_io_map_depriorize ( RzIO io,
ut32  id 
)

Definition at line 248 of file io_map.c.

248  {
249  rz_return_val_if_fail(io, false);
250  size_t i;
251  for (i = 0; i < rz_pvector_len(&io->maps); i++) {
252  RzIOMap *map = rz_pvector_at(&io->maps, i);
253  // search for iter with the correct map
254  if (map->id == id) {
255  rz_pvector_remove_at(&io->maps, i);
258  return true;
259  }
260  }
261  return false;
262 }
static void ** rz_pvector_push_front(RzPVector *vec, void *x)
Definition: rz_vector.h:305

References i, io_map_calculate_skyline(), map(), rz_io_t::maps, rz_pvector_at(), rz_pvector_len(), rz_pvector_push_front(), rz_pvector_remove_at(), and rz_return_val_if_fail.

Referenced by rz_open_maps_deprioritize_handler().

◆ rz_io_map_exists()

RZ_API bool rz_io_map_exists ( RzIO io,
RzIOMap map 
)

Definition at line 111 of file io_map.c.

111  {
112  rz_return_val_if_fail(io && map, false);
113  void **it;
114  rz_pvector_foreach (&io->maps, it) {
115  RzIOMap *m = *it;
116  if (!memcmp(m, map, sizeof(RzIOMap))) {
117  return true;
118  }
119  }
120  return false;
121 }

References regress::m, map(), rz_io_t::maps, rz_pvector_foreach, and rz_return_val_if_fail.

◆ rz_io_map_exists_for_id()

RZ_API bool rz_io_map_exists_for_id ( RzIO io,
ut32  id 
)

Definition at line 124 of file io_map.c.

124  {
125  return rz_io_map_resolve(io, id) != NULL;
126 }
RZ_API RzIOMap * rz_io_map_resolve(RzIO *io, ut32 id)
Definition: io_map.c:128

References NULL, and rz_io_map_resolve().

Referenced by rz_open_maps_deprioritize_handler(), and rz_open_maps_prioritize_handler().

◆ rz_io_map_fini()

RZ_API void rz_io_map_fini ( RzIO io)

Definition at line 318 of file io_map.c.

318  {
319  rz_return_if_fail(io);
320  void **it;
321  rz_pvector_foreach (&io->maps, it) {
322  RzIOMap *map = *it;
323  RzEventIOMapDel ev = { map };
325  }
326  rz_pvector_clear(&io->maps);
328  io->map_ids = NULL;
330 }
RZ_API void rz_id_pool_free(RzIDPool *pool)
Definition: idpool.c:72
RZ_API void rz_pvector_clear(RzPVector *vec)
Definition: vector.c:326

References rz_io_t::event, map(), rz_io_t::map_ids, rz_io_t::map_skyline, rz_io_t::maps, NULL, RZ_EVENT_IO_MAP_DEL, rz_event_send(), rz_id_pool_free(), rz_pvector_clear(), rz_pvector_foreach, rz_return_if_fail, and rz_skyline_clear().

Referenced by rz_io_fini(), rz_io_map_cleanup(), and rz_io_map_reset().

◆ rz_io_map_get()

◆ rz_io_map_get_for_fd()

RZ_API RzList* rz_io_map_get_for_fd ( RzIO io,
int  fd 
)

Definition at line 388 of file io_map.c.

388  {
389  RzList *map_list = rz_list_newf(NULL);
390  if (!map_list) {
391  return NULL;
392  }
393  void **it;
394  rz_pvector_foreach (&io->maps, it) {
395  RzIOMap *map = *it;
396  if (map && map->fd == fd) {
397  rz_list_append(map_list, map);
398  }
399  }
400  return map_list;
401 }
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288

References fd, map(), rz_io_t::maps, NULL, rz_list_append(), rz_list_newf(), and rz_pvector_foreach.

Referenced by DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), rz_core_cmd_foreach3(), rz_core_raw_file_print(), rz_io_bind(), rz_io_map_remap_fd(), and rz_io_resize().

◆ rz_io_map_get_paddr()

RZ_API RzIOMap* rz_io_map_get_paddr ( RzIO io,
ut64  paddr 
)

Definition at line 163 of file io_map.c.

163  {
165  void **it;
166  rz_pvector_foreach_prev(&io->maps, it) {
167  RzIOMap *map = *it;
168  if (map->delta <= paddr && paddr <= map->delta + (map->itv.size ? map->itv.size - 1 : 0)) {
169  return map;
170  }
171  }
172  return NULL;
173 }
#define rz_pvector_foreach_prev(vec, it)
Definition: rz_vector.h:338

References delta, map(), rz_io_t::maps, NULL, rz_pvector_foreach_prev, and rz_return_val_if_fail.

Referenced by rz_core_pava(), rz_io_bind(), and rz_io_p2v().

◆ rz_io_map_init()

RZ_API void rz_io_map_init ( RzIO io)

Definition at line 101 of file io_map.c.

101  {
102  rz_return_if_fail(io);
104  if (io->map_ids) {
106  }
108 }
#define END_OF_MAP_IDS
Definition: io_map.c:11
RZ_API RzIDPool * rz_id_pool_new(ut32 start_id, ut32 last_id)
Definition: idpool.c:22
RZ_API void rz_pvector_init(RzPVector *vec, RzPVectorFree free)
Definition: vector.c:298

References END_OF_MAP_IDS, map_free(), rz_io_t::map_ids, rz_io_t::maps, rz_id_pool_free(), rz_id_pool_new(), rz_pvector_init(), and rz_return_if_fail.

Referenced by rz_io_init(), rz_io_map_cleanup(), and rz_io_map_reset().

◆ rz_io_map_is_mapped()

RZ_API bool rz_io_map_is_mapped ( RzIO io,
ut64  addr 
)

Definition at line 181 of file io_map.c.

181  {
182  rz_return_val_if_fail(io, false);
183  return (bool)rz_io_map_get(io, addr);
184 }
RZ_API RzIOMap * rz_io_map_get(RzIO *io, ut64 addr)
Definition: io_map.c:176

References addr, rz_io_map_get(), and rz_return_val_if_fail.

Referenced by bp_is_mapped().

◆ rz_io_map_location()

RZ_API ut64 rz_io_map_location ( RzIO io,
ut64  size 
)

Returns a memory location that can hold enough bytes without overlapping.

Parameters
ioRzIO instance
sizeSize of the section

Definition at line 425 of file io_map.c.

425  {
426  ut64 base = (io->bits == 64) ? 0x60000000000ULL : 0x60000000ULL;
427  return rz_io_map_next_available(io, base, size, 0x200000);
428 }
RZ_API ut64 rz_io_map_next_available(RzIO *io, ut64 addr, ut64 size, ut64 load_align)
Definition: io_map.c:347
int bits
Definition: rz_io.h:62
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_io_t::bits, rz_io_map_next_available(), and ut64().

Referenced by rz_core_bin_load().

◆ rz_io_map_new()

RZ_API RzIOMap* rz_io_map_new ( RzIO io,
int  fd,
int  perm,
ut64  delta,
ut64  addr,
ut64  size 
)

◆ rz_io_map_next_address()

RZ_API ut64 rz_io_map_next_address ( RzIO io,
ut64  addr 
)

Definition at line 371 of file io_map.c.

371  {
372  ut64 lowest = UT64_MAX;
373  void **it;
374  rz_pvector_foreach (&io->maps, it) {
375  RzIOMap *map = *it;
376  ut64 from = rz_itv_begin(map->itv);
377  if (from > addr && addr < lowest) {
378  lowest = from;
379  }
380  ut64 to = rz_itv_end(map->itv);
381  if (to > addr && to < lowest) {
382  lowest = to;
383  }
384  }
385  return lowest;
386 }
static ut64 rz_itv_begin(RzInterval itv)
Definition: rz_itv.h:34
static ut64 rz_itv_end(RzInterval itv)
Definition: rz_itv.h:42
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125

References addr, from, map(), rz_io_t::maps, rz_itv_begin(), rz_itv_end(), rz_pvector_foreach, to, ut64(), and UT64_MAX.

Referenced by rz_core_search_value_in_range().

◆ rz_io_map_next_available()

RZ_API ut64 rz_io_map_next_available ( RzIO io,
ut64  addr,
ut64  size,
ut64  load_align 
)

Definition at line 347 of file io_map.c.

347  {
348  if (load_align == 0) {
349  load_align = 1;
350  }
351  void **it;
352  ut64 next_addr = addr,
353  end_addr = next_addr + size;
354  rz_pvector_foreach (&io->maps, it) {
355  RzIOMap *map = *it;
356  if (!rz_itv_size(map->itv)) {
357  break;
358  }
359  ut64 to = rz_itv_end(map->itv);
360  next_addr = RZ_MAX(next_addr, to + (load_align - (to % load_align)) % load_align);
361  if ((map->itv.addr <= next_addr && next_addr < to) || rz_itv_contain(map->itv, end_addr)) {
362  next_addr = to + (load_align - (to % load_align)) % load_align;
363  continue;
364  }
365  break;
366  }
367  return next_addr;
368 }
static bool rz_itv_contain(RzInterval itv, ut64 addr)
Definition: rz_itv.h:52
static ut64 rz_itv_size(RzInterval itv)
Definition: rz_itv.h:38
#define RZ_MAX(x, y)

References addr, map(), rz_io_t::maps, rz_itv_contain(), rz_itv_end(), rz_itv_size(), RZ_MAX, rz_pvector_foreach, to, and ut64().

Referenced by get_esil_stack_name(), perform_mapped_file_yank(), and rz_io_map_location().

◆ rz_io_map_priorize()

RZ_API bool rz_io_map_priorize ( RzIO io,
ut32  id 
)

Definition at line 232 of file io_map.c.

232  {
233  rz_return_val_if_fail(io, false);
234  size_t i;
235  for (i = 0; i < rz_pvector_len(&io->maps); i++) {
236  RzIOMap *map = rz_pvector_at(&io->maps, i);
237  // search for iter with the correct map
238  if (map->id == id) {
239  rz_pvector_remove_at(&io->maps, i);
240  rz_pvector_push(&io->maps, map);
241  rz_skyline_add(&io->map_skyline, map->itv, map);
242  return true;
243  }
244  }
245  return false;
246 }

References i, map(), rz_io_t::map_skyline, rz_io_t::maps, rz_pvector_at(), rz_pvector_len(), rz_pvector_push(), rz_pvector_remove_at(), rz_return_val_if_fail, and rz_skyline_add().

Referenced by rz_open_maps_prioritize_binid_handler(), and rz_open_maps_prioritize_handler().

◆ rz_io_map_priorize_for_fd()

RZ_API bool rz_io_map_priorize_for_fd ( RzIO io,
int  fd 
)

Definition at line 264 of file io_map.c.

264  {
265  rz_return_val_if_fail(io, false);
266  // we need a clean list for this, or this becomes a segfault-field
267  rz_io_map_cleanup(io);
268  RzPVector temp;
269  rz_pvector_init(&temp, NULL);
270  size_t i;
271  for (i = 0; i < rz_pvector_len(&io->maps);) {
272  RzIOMap *map = rz_pvector_at(&io->maps, i);
273  if (map->fd == fd) {
274  rz_pvector_push(&temp, map);
275  rz_pvector_remove_at(&io->maps, i);
276  continue;
277  }
278  i++;
279  }
280  rz_pvector_insert_range(&io->maps, rz_pvector_len(&io->maps), temp.v.a, rz_pvector_len(&temp));
281  rz_pvector_clear(&temp);
283  return true;
284 }
RZ_API void rz_io_map_cleanup(RzIO *io)
Definition: io_map.c:287
static void ** rz_pvector_insert_range(RzPVector *vec, size_t index, void **first, size_t count)
Definition: rz_vector.h:289
RzVector v
Definition: rz_vector.h:56
void * a
Definition: rz_vector.h:46

References rz_vector_t::a, fd, i, io_map_calculate_skyline(), map(), rz_io_t::maps, NULL, rz_io_map_cleanup(), rz_pvector_at(), rz_pvector_clear(), rz_pvector_init(), rz_pvector_insert_range(), rz_pvector_len(), rz_pvector_push(), rz_pvector_remove_at(), rz_return_val_if_fail, and rz_pvector_t::v.

Referenced by rz_open_maps_prioritize_fd_handler().

◆ rz_io_map_remap()

RZ_API bool rz_io_map_remap ( RzIO io,
ut32  id,
ut64  addr 
)

Definition at line 54 of file io_map.c.

54  {
55  RzIOMap *map = rz_io_map_resolve(io, id);
56  if (map) {
57  ut64 size = map->itv.size;
58  map->itv.addr = addr;
59  if (size && UT64_MAX - size + 1 < addr) {
60  map->itv.size = -addr;
61  rz_io_map_new(io, map->fd, map->perm, map->delta - addr, 0, size + addr);
62  }
64  return true;
65  }
66  return false;
67 }
RZ_API RzIOMap * rz_io_map_new(RzIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size)
Definition: io_map.c:50

References addr, io_map_calculate_skyline(), map(), rz_io_map_new(), rz_io_map_resolve(), ut64(), and UT64_MAX.

Referenced by rz_debug_dmp_init(), rz_io_map_remap_fd(), rz_open_maps_relocate_current_handler(), and rz_open_maps_relocate_handler().

◆ rz_io_map_remap_fd()

RZ_API bool rz_io_map_remap_fd ( RzIO io,
int  fd,
ut64  addr 
)

Definition at line 69 of file io_map.c.

69  {
70  RzIOMap *map;
71  bool retval = false;
73  if (maps) {
74  map = rz_list_get_n(maps, 0);
75  if (map) {
76  retval = rz_io_map_remap(io, map->id, addr);
77  }
79  }
80  return retval;
81 }
static RzList * maps(RzBinFile *bf)
Definition: bin_bf.c:116
RZ_API bool rz_io_map_remap(RzIO *io, ut32 id, ut64 addr)
Definition: io_map.c:54
RZ_API RzList * rz_io_map_get_for_fd(RzIO *io, int fd)
Definition: io_map.c:388
RZ_API RZ_BORROW void * rz_list_get_n(RZ_NONNULL const RzList *list, ut32 n)
Returns the N-th element of the list.
Definition: list.c:574
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137

References addr, fd, map(), maps(), rz_io_map_get_for_fd(), rz_io_map_remap(), rz_list_free(), and rz_list_get_n().

Referenced by rz_io_bind().

◆ rz_io_map_reset()

RZ_API void rz_io_map_reset ( RzIO io)

Definition at line 186 of file io_map.c.

186  {
187  rz_io_map_fini(io);
188  rz_io_map_init(io);
190 }

References io_map_calculate_skyline(), rz_io_map_fini(), and rz_io_map_init().

Referenced by rz_io_close_all(), and rz_open_maps_remove_all_handler().

◆ rz_io_map_resize()

RZ_API bool rz_io_map_resize ( RzIO io,
ut32  id,
ut64  newsize 
)

Definition at line 403 of file io_map.c.

403  {
404  RzIOMap *map;
405  if (!(map = rz_io_map_resolve(io, id))) {
406  return false;
407  }
408  ut64 addr = map->itv.addr;
409  if (newsize && UT64_MAX - newsize + 1 < addr) {
410  map->itv.size = -addr;
411  rz_io_map_new(io, map->fd, map->perm, map->delta - addr, 0, newsize + addr);
412  return true;
413  }
414  map->itv.size = newsize;
416  return true;
417 }

References addr, io_map_calculate_skyline(), map(), rz_io_map_new(), rz_io_map_resolve(), ut64(), and UT64_MAX.

Referenced by rz_io_resize(), and rz_open_maps_resize_handler().

◆ rz_io_map_resolve()

RZ_API RzIOMap* rz_io_map_resolve ( RzIO io,
ut32  id 
)

Definition at line 128 of file io_map.c.

128  {
129  rz_return_val_if_fail(io && id, false);
130  void **it;
131  rz_pvector_foreach (&io->maps, it) {
132  RzIOMap *map = *it;
133  if (map->id == id) {
134  return map;
135  }
136  }
137  return NULL;
138 }

References map(), rz_io_t::maps, NULL, rz_pvector_foreach, and rz_return_val_if_fail.

Referenced by rz_io_map_exists_for_id(), rz_io_map_remap(), rz_io_map_resize(), rz_open_maps_flags_handler(), rz_open_maps_name_id_del_handler(), and rz_open_maps_name_id_handler().

◆ rz_io_map_set_name()

RZ_API void rz_io_map_set_name ( RzIOMap map,
const char *  name 
)

Definition at line 332 of file io_map.c.

332  {
333  if (!map || !name) {
334  return;
335  }
336  free(map->name);
337  map->name = strdup(name);
338 }
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
Definition: z80asm.h:102

References free(), map(), and strdup().

Referenced by ds_init(), rz_core_analysis_esil_init_mem(), rz_open_maps_all_fd_handler(), rz_open_maps_map_fd_handler(), rz_open_maps_map_handler(), rz_open_maps_name_handler(), and rz_open_maps_name_id_handler().

◆ rz_io_maps()

◆ rz_io_update()

RZ_API void rz_io_update ( RzIO io)

Definition at line 159 of file io_map.c.

159  {
161 }

References io_map_calculate_skyline().