mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-26 00:55:59 +00:00
Get rid of some globals and tls-ify others
This commit is contained in:
parent
6947ea44ae
commit
9f12bfd0a8
@ -220,7 +220,7 @@ static int parse_reg_name(RRegItem *reg, csh handle, cs_insn *insn, int reg_num)
|
||||
}
|
||||
|
||||
static void op_fillval(RAnalOp *op, csh handle, cs_insn *insn) {
|
||||
static RRegItem reg;
|
||||
static R_TH_LOCAL RRegItem reg;
|
||||
switch (op->type & R_ANAL_OP_TYPE_MASK) {
|
||||
case R_ANAL_OP_TYPE_MOV:
|
||||
ZERO_FILL (reg);
|
||||
|
@ -222,7 +222,7 @@ static int parse_reg_name(RRegItem *reg, csh handle, cs_insn *insn, int reg_num)
|
||||
}
|
||||
|
||||
static void op_fillval(RAnal *anal, RAnalOp *op, csh *handle, cs_insn *insn) {
|
||||
static RRegItem reg;
|
||||
static R_TH_LOCAL RRegItem reg;
|
||||
switch (op->type & R_ANAL_OP_TYPE_MASK) {
|
||||
case R_ANAL_OP_TYPE_LOAD:
|
||||
if (OPERAND(1).type == RISCV_OP_MEM) {
|
||||
|
@ -1149,7 +1149,7 @@ DECLARE_GENERIC_PRINT_ADDRESS_FUNC()
|
||||
DECLARE_GENERIC_FPRINTF_FUNC()
|
||||
|
||||
static int disassemble(RAnal *a, RAnalOp *op, const ut8 *buf, int len) {
|
||||
static struct disassemble_info disasm_obj = {0};
|
||||
struct disassemble_info disasm_obj = {0};
|
||||
if (len < 2) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -145,8 +145,8 @@ static void opex(RStrBuf *buf, csh handle, cs_insn *insn) {
|
||||
}
|
||||
|
||||
static int tms320c64x_analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) {
|
||||
static csh handle = 0;
|
||||
static int omode;
|
||||
static R_TH_LOCAL csh handle = 0;
|
||||
static R_TH_LOCAL int omode;
|
||||
cs_insn *insn;
|
||||
int mode = 0, n, ret;
|
||||
|
||||
|
@ -44,7 +44,7 @@ DECLARE_GENERIC_PRINT_ADDRESS_FUNC()
|
||||
DECLARE_GENERIC_FPRINTF_FUNC()
|
||||
|
||||
static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, int len) {
|
||||
static struct disassemble_info disasm_obj;
|
||||
struct disassemble_info disasm_obj = {0};
|
||||
if (len < 4) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -54,7 +54,8 @@ static int decompile_ps(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
static int omode = -1, obits = -1;
|
||||
static R_TH_LOCAL int omode = -1;
|
||||
static R_TH_LOCAL int obits = -1;
|
||||
int n, ret;
|
||||
ut64 off = a->pc;
|
||||
cs_insn* insn;
|
||||
|
@ -38,7 +38,7 @@ DECLARE_GENERIC_PRINT_ADDRESS_FUNC()
|
||||
DECLARE_GENERIC_FPRINTF_FUNC()
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
static struct disassemble_info disasm_obj;
|
||||
struct disassemble_info disasm_obj;
|
||||
if (len < 4) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -799,7 +799,7 @@ static void print_function_labels(RAnal *anal, RAnalFunction *fcn, int rad) {
|
||||
}
|
||||
|
||||
static int cmd_flag(void *data, const char *input) {
|
||||
static int flagenum = 0;
|
||||
static R_TH_LOCAL int flagenum = 0;
|
||||
RCore *core = (RCore *)data;
|
||||
ut64 off = core->offset;
|
||||
char *ptr, *str = NULL;
|
||||
|
@ -3794,7 +3794,7 @@ reaccept:
|
||||
cmd_len = 0;
|
||||
}
|
||||
#if DEMO_SERVER_SENDS_CMD_TO_CLIENT
|
||||
static bool once = true;
|
||||
static R_TH_LOCAL bool once = true;
|
||||
/* TODO: server can reply a command request to the client only here */
|
||||
if (once) {
|
||||
const char *cmd = "pd 4";
|
||||
|
@ -443,8 +443,8 @@ static void get_bits_comment(RCore *core, RAnalFunction *f, char *cmt, int cmt_s
|
||||
}
|
||||
|
||||
R_API const char *r_core_get_section_name(RCore *core, ut64 addr) {
|
||||
static char section[128] = "";
|
||||
static ut64 oaddr = UT64_MAX;
|
||||
static R_TH_LOCAL char section[128] = "";
|
||||
static R_TH_LOCAL ut64 oaddr = UT64_MAX;
|
||||
if (oaddr == addr) {
|
||||
return section;
|
||||
}
|
||||
@ -1209,7 +1209,7 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) {
|
||||
}
|
||||
|
||||
R_API RAnalHint *r_core_hint_begin(RCore *core, RAnalHint* hint, ut64 at) {
|
||||
static char *hint_syntax = NULL;
|
||||
static R_TH_LOCAL char *hint_syntax = NULL;
|
||||
r_anal_hint_free (hint);
|
||||
hint = r_anal_hint_get (core->anal, at);
|
||||
if (hint_syntax) {
|
||||
@ -2877,7 +2877,7 @@ static void ds_print_lines_left(RDisasmState *ds) {
|
||||
free (sect);
|
||||
}
|
||||
if (ds->show_symbols) {
|
||||
static RFlagItem sfi = {0};
|
||||
static R_TH_LOCAL RFlagItem sfi = {0};
|
||||
const char *name = "";
|
||||
int delta = 0;
|
||||
if (ds->fcn) {
|
||||
@ -2956,7 +2956,7 @@ static void ds_print_offset(RDisasmState *ds) {
|
||||
}
|
||||
r_print_set_screenbounds (core->print, at);
|
||||
if (ds->show_offset) {
|
||||
static RFlagItem sfi = {0};
|
||||
static R_TH_LOCAL RFlagItem sfi = {0};
|
||||
const char *label = NULL;
|
||||
int delta = -1;
|
||||
bool show_trace = false;
|
||||
@ -5757,7 +5757,7 @@ toro:
|
||||
ds->at -= skip_bytes_flag;
|
||||
}
|
||||
if (ds->pdf) {
|
||||
static bool sparse = false;
|
||||
static R_TH_LOCAL bool sparse = false;
|
||||
RAnalBlock *bb = r_anal_function_bbget_in (core->anal, ds->pdf, ds->at);
|
||||
if (!bb) {
|
||||
for (inc = 1; inc < ds->oplen; inc++) {
|
||||
|
@ -38,7 +38,7 @@ static bool aes_wrap_use(const char *algo) {
|
||||
static bool update(RCrypto *cry, const ut8 *buf, int len) {
|
||||
struct aes_state st;
|
||||
ut64 blocks = len / BLOCK_SIZE;
|
||||
static ut8 tmp[16];
|
||||
ut8 tmp[16] = {0};
|
||||
long *tmp_ptr = (long *)tmp;
|
||||
ut64 t = 0;
|
||||
int i, j;
|
||||
|
@ -61,12 +61,12 @@ R_API void r_debug_signal_init(RDebug *dbg) {
|
||||
}
|
||||
|
||||
static bool siglistcb(void *p, const char *k, const char *v) {
|
||||
static char key[32] = "cfg.";
|
||||
RDebug *dbg = (RDebug *)p;
|
||||
int opt, mode = dbg->_mode;
|
||||
if (atoi (k) > 0) {
|
||||
strncpy (key + 4, k, 20);
|
||||
opt = sdb_num_get (DB, key, 0);
|
||||
int mode = dbg->_mode;
|
||||
char *key = r_str_newf ("cfg.%s", k);
|
||||
int opt = sdb_num_get (DB, key, 0);
|
||||
free (key);
|
||||
if (opt) {
|
||||
r_cons_printf ("%s %s", k, v);
|
||||
if (opt & R_DBG_SIGNAL_CONT) {
|
||||
|
@ -45,7 +45,7 @@
|
||||
|
||||
#ifndef COMPILE_ONLY
|
||||
void file_mdump(struct r_magic *m) {
|
||||
static const char optyp[] = { FILE_OPS };
|
||||
static R_TH_LOCAL const char optyp[] = { FILE_OPS };
|
||||
char pp[ASCTIME_BUF_MAXLEN];
|
||||
|
||||
(void) eprintf ("[%u", m->lineno);
|
||||
@ -196,9 +196,9 @@ const char *file_fmttime(ut32 v, int local, char *pp) {
|
||||
r_ctime_r (&t, pp);
|
||||
} else {
|
||||
#ifndef HAVE_DAYLIGHT
|
||||
static int daylight = 0;
|
||||
static R_TH_LOCAL int daylight = 0;
|
||||
#ifdef HAVE_TM_ISDST
|
||||
static time_t now = (time_t)0;
|
||||
static R_TH_LOCAL time_t now = (time_t)0;
|
||||
|
||||
if (now == (time_t)0) {
|
||||
struct tm *tm1;
|
||||
|
@ -1785,7 +1785,7 @@ static void unary(TCCState *s1) {
|
||||
CType type = {0};
|
||||
Sym *s;
|
||||
AttributeDef ad;
|
||||
static int in_sizeof = 0;
|
||||
static R_TH_LOCAL int in_sizeof = 0;
|
||||
|
||||
sizeof_caller = in_sizeof;
|
||||
in_sizeof = 0;
|
||||
|
@ -120,7 +120,7 @@ static int can_replace(const char *str, int idx, int max_operands) {
|
||||
}
|
||||
|
||||
static const char* getspr(const char *reg) {
|
||||
static char cspr[16];
|
||||
static R_TH_LOCAL char cspr[16];
|
||||
ut32 spr = 0;
|
||||
if (!reg) {
|
||||
return NULL;
|
||||
|
@ -291,7 +291,7 @@ R_API bool r_socket_connect(RSocket *s, const char *host, const char *port, int
|
||||
if (fd == -1) {
|
||||
return false;
|
||||
}
|
||||
static struct can_isotp_options opts = {
|
||||
struct can_isotp_options opts = {
|
||||
.txpad_content = 0xcc,
|
||||
.rxpad_content = 0xcc,
|
||||
.frame_txtime = 0x1000,
|
||||
@ -300,14 +300,14 @@ R_API bool r_socket_connect(RSocket *s, const char *host, const char *port, int
|
||||
close (fd);
|
||||
return false;
|
||||
}
|
||||
static struct can_isotp_fc_options fcopts = {
|
||||
struct can_isotp_fc_options fcopts = {
|
||||
.stmin = 0xf3
|
||||
};
|
||||
if (setsockopt (fd, SOL_CAN_ISOTP, CAN_ISOTP_RECV_FC, &fcopts, sizeof (fcopts)) == -1) {
|
||||
close (fd);
|
||||
return false;
|
||||
}
|
||||
static struct can_isotp_ll_options llopts = {
|
||||
struct can_isotp_ll_options llopts = {
|
||||
.mtu = 8,
|
||||
.tx_dl = 8,
|
||||
};
|
||||
|
@ -3315,7 +3315,7 @@ R_API int r_str_do_until_token(str_operation op, char *str, const char tok) {
|
||||
}
|
||||
|
||||
R_API const char *r_str_pad(const char ch, int sz) {
|
||||
static char pad[1024];
|
||||
static R_TH_LOCAL char pad[1024];
|
||||
if (sz < 0) {
|
||||
sz = 0;
|
||||
}
|
||||
@ -3323,7 +3323,7 @@ R_API const char *r_str_pad(const char ch, int sz) {
|
||||
if (sz < sizeof (pad)) {
|
||||
pad[sz] = 0;
|
||||
}
|
||||
pad[sizeof(pad) - 1] = 0;
|
||||
pad[sizeof (pad) - 1] = 0;
|
||||
return pad;
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ R_API ut64 r_time_now_mono(void) {
|
||||
return v.QuadPart;
|
||||
#elif __APPLE__ && !defined(MAC_OS_X_VERSION_10_12)
|
||||
ut64 ticks = mach_absolute_time ();
|
||||
static mach_timebase_info_data_t tb;
|
||||
static R_TH_LOCAL mach_timebase_info_data_t tb;
|
||||
mach_timebase_info (&tb);
|
||||
return ((ticks * tb.numer) / tb.denom) / R_NSEC_PER_USEC;
|
||||
#elif HAS_CLOCK_MONOTONIC
|
||||
|
@ -15,6 +15,7 @@
|
||||
(git grep 'r_str_startswith ("' libr ) && exit 1
|
||||
|
||||
# pending cleanups
|
||||
# git grep -e "`printf '\x09static'`" libr | grep -v R_TH_LOCAL|grep -v const | grep -v '(' && exit 1
|
||||
# (git grep 'TODO' libr) # && exit 1 # use r_str_startswith()
|
||||
# (git grep 'XXX' libr) # && exit 1 # use r_str_startswith()
|
||||
# (git grep 'strncmp' libr) # && exit 1 # use r_str_startswith()
|
||||
|
Loading…
x
Reference in New Issue
Block a user