Skip to content

Commit 712239e

Browse files
committed
Optimized is_string_at makes aae 20% faster on x86 ##analysis
1 parent e9bdcbe commit 712239e

File tree

8 files changed

+270
-185
lines changed

8 files changed

+270
-185
lines changed

libr/core/canal.c

Lines changed: 228 additions & 170 deletions
Large diffs are not rendered by default.

libr/core/cbin.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#undef R_LOG_ORIGIN
66
#define R_LOG_ORIGIN "core.bin"
77
#include <r_core.h>
8+
#include <r_core_priv.h>
89

910
#define is_in_range(at, from, sz) ((at) >= (from) && (at) < ((from) + (sz)))
1011

@@ -268,6 +269,7 @@ R_API bool r_core_bin_load_structs(RCore *core, const char *file) {
268269
RBinFile *bf = r_bin_cur (core->bin);
269270
if (bf) {
270271
r_core_bin_export_info (core, R_MODE_SET);
272+
r_core_sec_ranges_invalidate (core);
271273
r_bin_file_delete (core->bin, bf->id);
272274
return true;
273275
}
@@ -5472,6 +5474,7 @@ R_API bool r_core_bin_delete(RCore *core, ut32 bf_id) {
54725474
if (bf_id == UT32_MAX) {
54735475
return false;
54745476
}
5477+
r_core_sec_ranges_invalidate (core);
54755478
r_bin_file_delete (core->bin, bf_id);
54765479
RBinFile *bf = r_bin_file_at (core->bin, core->addr);
54775480
if (bf) {

libr/core/cfile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define R_LOG_ORIGIN "cfile"
44

55
#include <r_core.h>
6+
#include <r_core_priv.h>
67

78
static bool close_but_cb(void *user, void *data, ut32 id) {
89
RCore *core = (RCore *)user;
@@ -153,6 +154,7 @@ R_API bool r_core_file_reopen(RCore *core, const char *args, int perm, int loadb
153154
bool had_rbin_info = false;
154155

155156
if (odesc && bf) {
157+
r_core_sec_ranges_invalidate (core);
156158
if (r_bin_file_delete (core->bin, bf->id)) {
157159
had_rbin_info = true;
158160
}
@@ -694,6 +696,8 @@ static bool mustreopen(RCore *core, RIODesc *desc, const char *fn) {
694696

695697
R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) {
696698
R_RETURN_VAL_IF_FAIL (r && r->io, false);
699+
// Invalidate section ranges cache when loading new binary
700+
r_core_sec_ranges_invalidate (r);
697701
R_CRITICAL_ENTER (r);
698702
ut64 laddr = r_config_get_i (r->config, "bin.laddr");
699703
RIODesc *desc = r->io->desc;

libr/core/cmd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define INTERACTIVE_MAX_REP 1024
44

55
#include <r_core.h>
6+
#include <r_core_priv.h>
67
#include <r_vec.h>
78
#include <r_util/r_json.h>
89
#if R2__UNIX__

libr/core/cmd_open.inc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ static void cmd_open_bin(RCore *core, const char *input) {
415415
}
416416
r_core_cmd_callf (core, "op %d", dst->fd);
417417
r_bin_file_set_cur_binfile (core->bin, dst);
418+
r_core_sec_ranges_invalidate (core);
418419
r_bin_file_delete (core->bin, current);
419420
if (curfd >= 0) {
420421
r_io_fd_close (core->io, curfd);
@@ -442,6 +443,7 @@ static void cmd_open_bin(RCore *core, const char *input) {
442443
break;
443444
case '-': // "ob-"
444445
if (input[2] == '*') {
446+
r_core_sec_ranges_invalidate (core);
445447
r_bin_file_delete_all (core->bin);
446448
} else if (input[2] == '-') {
447449
RBinFile *bf = r_bin_cur (core->bin);
@@ -2600,6 +2602,7 @@ static int cmd_open(void *data, const char *input) {
26002602
r_core_cmd_help_match (core, help_msg_o_dash, "o-*");
26012603
} else {
26022604
r_io_close_all (core->io);
2605+
r_core_sec_ranges_invalidate (core);
26032606
r_bin_file_delete_all (core->bin);
26042607
}
26052608
break;
@@ -2608,6 +2611,7 @@ static int cmd_open(void *data, const char *input) {
26082611
r_core_cmd_help_match (core, help_msg_o_dash, "o--");
26092612
} else {
26102613
r_io_close_all (core->io);
2614+
r_core_sec_ranges_invalidate (core);
26112615
r_bin_file_delete_all (core->bin);
26122616
r_core_cmd0 (core, "o-*;om-*");
26132617
r_anal_purge (core->anal);

libr/core/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define R_LOG_ORIGIN "core"
44

55
#include "../include/r_core.h"
6+
#include "../include/r_core_priv.h"
67
#include <r_vec.h>
78

89
R_LIB_VERSION(r_core);
@@ -2762,6 +2763,8 @@ R_API void r_core_bind_cons(RCore *core) {
27622763

27632764
R_API void r_core_fini(RCore *c) {
27642765
R_RETURN_IF_FAIL (c);
2766+
// Free cached section ranges in priv
2767+
r_core_sec_ranges_invalidate (c);
27652768
if (c->chan) {
27662769
r_th_channel_free (c->chan);
27672770
}

libr/include/r_core.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ R_LIB_VERSION_HEADER(r_core);
6666
#define R_FLAGS_FS_SYMBOLS_SECTIONS "symbols.sections"
6767
#define R_FLAGS_FS_SYSCALLS "syscalls"
6868

69-
#define R_GRAPH_FORMAT_NO 0
70-
#define R_GRAPH_FORMAT_GMLFCN 1
71-
#define R_GRAPH_FORMAT_JSON 2
72-
#define R_GRAPH_FORMAT_GML 3
73-
#define R_GRAPH_FORMAT_DOT 4
74-
#define R_GRAPH_FORMAT_CMD 5
69+
#define R_GRAPH_FORMAT_NO 0
70+
#define R_GRAPH_FORMAT_GMLFCN 1
71+
#define R_GRAPH_FORMAT_JSON 2
72+
#define R_GRAPH_FORMAT_GML 3
73+
#define R_GRAPH_FORMAT_DOT 4
74+
#define R_GRAPH_FORMAT_CMD 5
7575

7676
///
7777
#define R_CONS_COLOR_DEF(x, def) ((core->cons && core->cons->context->pal.x)? core->cons->context->pal.x: def)
@@ -318,14 +318,14 @@ typedef struct r_core_esil_t {
318318
ut32 tr_reg;
319319
ut32 tr_mem;
320320
RReg *reg;
321-
char *cmd_step; // command to run before a step is performed
322-
char *cmd_step_out; // command to run after a step is performed
323-
char *cmd_intr; // command to run when an interrupt occurs
324-
char *cmd_trap; // command to run when a trap occurs
325-
char *cmd_mdev; // command to run when an memory mapped device address is used
326-
char *cmd_todo; // command to run when esil expr contains TODO
327-
char *cmd_ioer; // command to run when esil fails to IO
328-
char *mdev_range; // string containing the r_str_range to match for read/write accesses
321+
char *cmd_step; // command to run before a step is performed
322+
char *cmd_step_out; // command to run after a step is performed
323+
char *cmd_intr; // command to run when an interrupt occurs
324+
char *cmd_trap; // command to run when a trap occurs
325+
char *cmd_mdev; // command to run when an memory mapped device address is used
326+
char *cmd_todo; // command to run when esil expr contains TODO
327+
char *cmd_ioer; // command to run when esil fails to IO
328+
char *mdev_range; // string containing the r_str_range to match for read/write accesses
329329
ut8 cfg;
330330
} RCoreEsil;
331331

libr/include/r_core_priv.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* radare - LGPL - Copyright 2024-2025 - pancake */
1+
/* radare - LGPL - Copyright 2024-2026 - pancake */
22

33
#include "r_core.h"
44

@@ -8,6 +8,16 @@
88
#ifdef __cplusplus
99
extern "C" {
1010
#endif
11+
12+
typedef struct r_core_sec_range_t {
13+
ut64 from;
14+
ut64 to;
15+
} RCoreSecRange;
16+
17+
R_VEC_TYPE (RVecRCoreSecRange, RCoreSecRange);
18+
19+
R_IPI void r_core_sec_ranges_invalidate(RCore *core);
20+
1121
typedef struct r_core_priv_t {
1222
// arch cache
1323
int old_bits;
@@ -23,6 +33,8 @@ typedef struct r_core_priv_t {
2333
// disasm cache
2434
ut64 goaddr;
2535
char *section;
36+
// analysis cache
37+
RVecRCoreSecRange *sec_ranges;
2638
} RCorePriv;
2739

2840
#ifdef __cplusplus

0 commit comments

Comments
 (0)