mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-03 12:12:06 +00:00
io: make r_io_map_new always update skyline
keep a "private" version, named io_map_new, which can be called by the io module for performance reasons (e.g. loading many maps, you don't want to sync the status every time when you can do that only one time at the end of the batch insertion).
This commit is contained in:
parent
f75a4bcd5d
commit
be8ece36a7
@ -1086,8 +1086,7 @@ int main(int argc, char **argv, char **envp) {
|
||||
(void)r_core_bin_load (&r, filepath, baddr);
|
||||
}
|
||||
} else {
|
||||
r_io_map_new (r.io, iod->fd, perms, 0LL, mapaddr, r_io_desc_size (iod), true);
|
||||
// r_io_map_new (r.io, iod->fd, iod->flags, 0LL, 0LL, r_io_desc_size (iod));
|
||||
r_io_map_new (r.io, iod->fd, perms, 0LL, mapaddr, r_io_desc_size (iod));
|
||||
if (run_anal < 0) {
|
||||
// PoC -- must move -rk functionalitiy into rcore
|
||||
// this may be used with caution (r2 -nn $FILE)
|
||||
@ -1115,7 +1114,7 @@ int main(int argc, char **argv, char **envp) {
|
||||
iod = r.io ? r_io_desc_get (r.io, fh->fd) : NULL;
|
||||
if (iod) {
|
||||
perms = iod->flags;
|
||||
r_io_map_new (r.io, iod->fd, perms, 0LL, 0LL, r_io_desc_size (iod), true);
|
||||
r_io_map_new (r.io, iod->fd, perms, 0LL, 0LL, r_io_desc_size (iod));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -563,7 +563,7 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
|
||||
if (plugin && plugin->name) {
|
||||
if (!strncmp (plugin->name, "any", 3)) {
|
||||
r_io_map_new (r->io, desc->fd, desc->flags, 0, laddr, r_io_desc_size (desc), true);
|
||||
r_io_map_new (r->io, desc->fd, desc->flags, 0, laddr, r_io_desc_size (desc));
|
||||
// set use of raw strings
|
||||
//r_config_set (r->config, "bin.rawstr", "true");
|
||||
// r_config_set_i (r->config, "io.va", false);
|
||||
@ -575,7 +575,7 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
|
||||
//workaround to map correctly malloc:// and raw binaries
|
||||
if (r_io_desc_is_dbg (desc) || (obj && (!obj->sections || !va))) {
|
||||
r_io_map_new (r->io, desc->fd, desc->flags, 0, laddr, r_io_desc_size (desc), true);
|
||||
r_io_map_new (r->io, desc->fd, desc->flags, 0, laddr, r_io_desc_size (desc));
|
||||
}
|
||||
|
||||
RBinInfo *info = obj? obj->info: NULL;
|
||||
@ -589,7 +589,7 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
r_io_map_new (r->io, desc->fd, desc->flags, 0, laddr, r_io_desc_size (desc), true);
|
||||
r_io_map_new (r->io, desc->fd, desc->flags, 0, laddr, r_io_desc_size (desc));
|
||||
if (binfile) {
|
||||
r_core_bin_set_arch_bits (r, binfile->file,
|
||||
r_config_get (r->config, "asm.arch"),
|
||||
|
@ -298,7 +298,7 @@ typedef struct r_io_bind_t {
|
||||
} RIOBind;
|
||||
|
||||
//map.c
|
||||
R_API RIOMap *r_io_map_new (RIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size, bool do_skyline);
|
||||
R_API RIOMap *r_io_map_new(RIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size);
|
||||
R_API ut64 r_io_map_next_address(RIO* io, ut64 addr);
|
||||
R_API void r_io_map_init (RIO *io);
|
||||
R_API bool r_io_map_remap (RIO *io, ut32 id, ut64 addr);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <r_io.h>
|
||||
#include <sdb.h>
|
||||
#include <config.h>
|
||||
#include "io_private.h"
|
||||
|
||||
R_LIB_VERSION (r_io);
|
||||
|
||||
@ -252,7 +253,7 @@ R_API RIODesc* r_io_open(RIO* io, const char* uri, int flags, int mode) {
|
||||
if (!desc) {
|
||||
return NULL;
|
||||
}
|
||||
r_io_map_new (io, desc->fd, desc->flags, 0LL, 0LL, r_io_desc_size (desc), true);
|
||||
r_io_map_new (io, desc->fd, desc->flags, 0LL, 0LL, r_io_desc_size (desc));
|
||||
return desc;
|
||||
}
|
||||
|
||||
@ -271,12 +272,12 @@ R_API RIODesc* r_io_open_at(RIO* io, const char* uri, int flags, int mode, ut64
|
||||
// second map
|
||||
if (size && ((UT64_MAX - size + 1) < at)) {
|
||||
// split map into 2 maps if only 1 big map results into interger overflow
|
||||
r_io_map_new (io, desc->fd, desc->flags, UT64_MAX - at + 1, 0LL, size - (UT64_MAX - at) - 1, false);
|
||||
io_map_new (io, desc->fd, desc->flags, UT64_MAX - at + 1, 0LL, size - (UT64_MAX - at) - 1, false);
|
||||
// someone pls take a look at this confusing stuff
|
||||
size = UT64_MAX - at + 1;
|
||||
}
|
||||
// skyline not updated
|
||||
r_io_map_new (io, desc->fd, desc->flags, 0LL, at, size, false);
|
||||
r_io_map_new (io, desc->fd, desc->flags, 0LL, at, size);
|
||||
return desc;
|
||||
}
|
||||
|
||||
|
6
libr/io/io_private.h
Normal file
6
libr/io/io_private.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef _IO_PRIVATE_H_
|
||||
#define _IO_PRIVATE_H_
|
||||
|
||||
RIOMap *io_map_new(RIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size, bool do_skyline);
|
||||
|
||||
#endif
|
@ -3,6 +3,7 @@
|
||||
#include <r_io.h>
|
||||
#include <r_util.h>
|
||||
#include <r_types.h>
|
||||
#include "io_private.h"
|
||||
|
||||
// TODO: we may probably take care of this when the binfiles have an associated list of fds
|
||||
#define REUSE_NULL_MAPS 1
|
||||
@ -64,7 +65,7 @@ R_API bool r_io_create_mem_map(RIO *io, RIOSection *sec, ut64 at, bool null, boo
|
||||
if (desc) {
|
||||
RIOMap *map = r_io_map_get (io, at);
|
||||
if (!map) {
|
||||
r_io_map_new (io, desc->fd, desc->flags, 0LL, at, gap, false);
|
||||
io_map_new (io, desc->fd, desc->flags, 0LL, at, gap, false);
|
||||
}
|
||||
reused = true;
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ out:
|
||||
free (deleted);
|
||||
}
|
||||
|
||||
R_API RIOMap* r_io_map_new(RIO* io, int fd, int flags, ut64 delta, ut64 addr, ut64 size, bool do_skyline) {
|
||||
RIOMap* io_map_new(RIO* io, int fd, int flags, ut64 delta, ut64 addr, ut64 size, bool do_skyline) {
|
||||
if (!size || !io || !io->maps || !io->map_ids) {
|
||||
return NULL;
|
||||
}
|
||||
@ -158,7 +158,7 @@ R_API RIOMap* r_io_map_new(RIO* io, int fd, int flags, ut64 delta, ut64 addr, ut
|
||||
map->delta = delta;
|
||||
if ((UT64_MAX - size + 1) < addr) {
|
||||
/// XXX: this is leaking a map!!!
|
||||
r_io_map_new (io, fd, flags, delta - addr, 0LL, size + addr, do_skyline);
|
||||
io_map_new (io, fd, flags, delta - addr, 0LL, size + addr, do_skyline);
|
||||
size = -(st64)addr;
|
||||
}
|
||||
// RIOMap describes an interval of addresses (map->from; map->to)
|
||||
@ -173,6 +173,10 @@ R_API RIOMap* r_io_map_new(RIO* io, int fd, int flags, ut64 delta, ut64 addr, ut
|
||||
return map;
|
||||
}
|
||||
|
||||
R_API RIOMap *r_io_map_new (RIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size) {
|
||||
return io_map_new (io, fd, flags, delta, addr, size, true);
|
||||
}
|
||||
|
||||
R_API bool r_io_map_remap (RIO *io, ut32 id, ut64 addr) {
|
||||
RIOMap *map = r_io_map_resolve (io, id);
|
||||
if (map) {
|
||||
@ -180,7 +184,7 @@ R_API bool r_io_map_remap (RIO *io, ut32 id, ut64 addr) {
|
||||
map->itv.addr = addr;
|
||||
if (UT64_MAX - size + 1 < addr) {
|
||||
map->itv.size = -addr;
|
||||
r_io_map_new (io, map->fd, map->flags, map->delta - addr, 0, size + addr, true);
|
||||
r_io_map_new (io, map->fd, map->flags, map->delta - addr, 0, size + addr);
|
||||
return true;
|
||||
}
|
||||
r_io_map_calculate_skyline (io);
|
||||
@ -261,7 +265,7 @@ R_API RIOMap* r_io_map_add(RIO* io, int fd, int flags, ut64 delta, ut64 addr, ut
|
||||
RIODesc* desc = r_io_desc_get (io, fd);
|
||||
if (desc) {
|
||||
//a map cannot have higher permissions than the desc belonging to it
|
||||
return r_io_map_new (io, fd, (flags & desc->flags) | (flags & R_IO_EXEC),
|
||||
return io_map_new (io, fd, (flags & desc->flags) | (flags & R_IO_EXEC),
|
||||
delta, addr, size, do_skyline);
|
||||
}
|
||||
return NULL;
|
||||
@ -483,7 +487,7 @@ R_API RIOMap* r_io_map_add_next_available(RIO* io, int fd, int flags, ut64 delta
|
||||
}
|
||||
break;
|
||||
}
|
||||
return r_io_map_new (io, fd, flags, delta, next_addr, size, true);
|
||||
return r_io_map_new (io, fd, flags, delta, next_addr, size);
|
||||
}
|
||||
|
||||
R_API ut64 r_io_map_next_address(RIO* io, ut64 addr) {
|
||||
@ -527,7 +531,7 @@ R_API bool r_io_map_resize(RIO *io, ut32 id, ut64 newsize) {
|
||||
ut64 addr = map->itv.addr;
|
||||
if (UT64_MAX - newsize + 1 < addr) {
|
||||
map->itv.size = -addr;
|
||||
r_io_map_new (io, map->fd, map->flags, map->delta - addr, 0, newsize + addr, true);
|
||||
r_io_map_new (io, map->fd, map->flags, map->delta - addr, 0, newsize + addr);
|
||||
return true;
|
||||
}
|
||||
map->itv.size = newsize;
|
||||
|
Loading…
x
Reference in New Issue
Block a user