Mark all globals (or most of them) as TLS variables ##core
This commit is contained in:
parent
cf2ae64e88
commit
d3d0e8f3ec
|
@ -1,4 +1,4 @@
|
|||
/* radare2 - LGPL - Copyright 2013-2021 - pancake */
|
||||
/* radare2 - LGPL - Copyright 2013-2022 - pancake */
|
||||
|
||||
#include <r_anal.h>
|
||||
#include <r_lib.h>
|
||||
|
@ -62,8 +62,8 @@
|
|||
#define ISPREINDEX64() (((OPCOUNT64() == 2) && (ISMEM64(1)) && (ISWRITEBACK64())) || ((OPCOUNT64() == 3) && (ISMEM64(2)) && (ISWRITEBACK64())))
|
||||
#define ISPOSTINDEX64() (((OPCOUNT64() == 3) && (ISIMM64(2)) && (ISWRITEBACK64())) || ((OPCOUNT64() == 4) && (ISIMM64(3)) && (ISWRITEBACK64())))
|
||||
|
||||
static HtUU *ht_itblock = NULL;
|
||||
static HtUU *ht_it = NULL;
|
||||
static R_TH_LOCAL HtUU *ht_itblock = NULL;
|
||||
static R_TH_LOCAL HtUU *ht_it = NULL;
|
||||
|
||||
#define BITMASK_BY_WIDTH_COUNT 64
|
||||
static const ut64 bitmask_by_width[BITMASK_BY_WIDTH_COUNT] = {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2015 - condret */
|
||||
/* radare - LGPL - Copyright 2015-2022 - condret */
|
||||
|
||||
#include <string.h>
|
||||
#include <r_types.h>
|
||||
|
@ -8,7 +8,7 @@
|
|||
#include "../../asm/arch/snes/snes_op_table.h"
|
||||
#include "../../asm/p/asm_snes.h"
|
||||
|
||||
static struct snes_asm_flags* snesflags = NULL;
|
||||
static R_TH_LOCAL struct snes_asm_flags* snesflags = NULL;
|
||||
|
||||
static int snes_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) {
|
||||
op->size = snes_op_get_size(snesflags->M, snesflags->X, &snes_op[data[0]]);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "anal_tms320c64x.c"
|
||||
#include "../../asm/arch/tms320/tms320_dasm.h"
|
||||
|
||||
static tms320_dasm_t engine = { 0 };
|
||||
static R_TH_LOCAL tms320_dasm_t engine = { 0 };
|
||||
|
||||
typedef int (* TMS_ANAL_OP_FN)(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len);
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ struct Getarg {
|
|||
int bits;
|
||||
};
|
||||
|
||||
static csh handle = 0;
|
||||
static R_TH_LOCAL csh handle = 0;
|
||||
|
||||
static void hidden_op(cs_insn *insn, cs_x86 *x, int mode) {
|
||||
unsigned int id = insn->id;
|
||||
|
@ -3328,7 +3328,7 @@ static int cs_len_prefix_opcode(uint8_t *item) {
|
|||
}
|
||||
|
||||
static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) {
|
||||
static int omode = 0;
|
||||
static R_TH_LOCAL int omode = 0;
|
||||
cs_insn *insn = NULL;
|
||||
int mode = (a->bits==64)? CS_MODE_64:
|
||||
(a->bits==32)? CS_MODE_32:
|
||||
|
|
|
@ -94,8 +94,8 @@ int run_f_list(tms320_dasm_t * dasm) {
|
|||
break;
|
||||
|
||||
case TMS320_FLAG_l1:
|
||||
temp = get_bits(dasm->opcode64, flag->f, 1);
|
||||
set_field_value(dasm, l1, temp);
|
||||
temp = get_bits (dasm->opcode64, flag->f, 1);
|
||||
set_field_value (dasm, l1, temp);
|
||||
break;
|
||||
case TMS320_FLAG_l3:
|
||||
temp = get_bits(dasm->opcode64, flag->f, 3);
|
||||
|
@ -1026,9 +1026,8 @@ insn_item_t * decode_insn(tms320_dasm_t * dasm)
|
|||
|
||||
}
|
||||
|
||||
insn_item_t * decode_insn_head(tms320_dasm_t * dasm)
|
||||
{
|
||||
run_f_list(dasm);
|
||||
insn_item_t * decode_insn_head(tms320_dasm_t * dasm) {
|
||||
run_f_list (dasm);
|
||||
|
||||
if (dasm->insn->i_list) {
|
||||
dasm->insn = dasm->insn->i_list;
|
||||
|
@ -1112,8 +1111,7 @@ static int full_insn_size(tms320_dasm_t *dasm)
|
|||
* TMS320 disassembly engine public interface
|
||||
*/
|
||||
|
||||
int tms320_dasm(tms320_dasm_t * dasm, const ut8 * stream, int len)
|
||||
{
|
||||
int tms320_dasm(tms320_dasm_t * dasm, const ut8 * stream, int len) {
|
||||
init_dasm(dasm, stream, len);
|
||||
|
||||
if (tms320_f_get_cpu(dasm) != TMS320_F_CPU_C55X_PLUS) {
|
||||
|
@ -1140,25 +1138,23 @@ int tms320_dasm(tms320_dasm_t * dasm, const ut8 * stream, int len)
|
|||
// insn_head_t c55x_list[]
|
||||
#include "c55x/table.h"
|
||||
|
||||
int tms320_dasm_init(tms320_dasm_t * dasm) {
|
||||
bool tms320_dasm_init(tms320_dasm_t * dasm) {
|
||||
int i = 0;
|
||||
|
||||
if (dasm->map) {
|
||||
/* already initialized */
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
dasm->map = ht_up_new0 ();
|
||||
if (!dasm->map) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < ARRAY_SIZE(c55x_list); i++) {
|
||||
ht_up_insert (dasm->map, c55x_list[i].byte, &c55x_list[i]);
|
||||
}
|
||||
|
||||
tms320_f_set_cpu(dasm, TMS320_F_CPU_C55X);
|
||||
|
||||
return 0;
|
||||
tms320_f_set_cpu (dasm, TMS320_F_CPU_C55X);
|
||||
return true;
|
||||
}
|
||||
|
||||
int tms320_dasm_fini(tms320_dasm_t * dasm) {
|
||||
|
|
|
@ -239,7 +239,7 @@ typedef struct {
|
|||
|
||||
extern int tms320_dasm(tms320_dasm_t *, const ut8 *, int);
|
||||
|
||||
extern int tms320_dasm_init(tms320_dasm_t *);
|
||||
extern bool tms320_dasm_init(tms320_dasm_t *);
|
||||
extern int tms320_dasm_fini(tms320_dasm_t *);
|
||||
|
||||
#endif /* __TMS320_DASM_H__ */
|
||||
|
|
|
@ -8,9 +8,10 @@
|
|||
#include "./asm_arm_hacks.inc"
|
||||
|
||||
bool arm64ass(const char *str, ut64 addr, ut32 *op);
|
||||
static csh cd = 0;
|
||||
static HtUU *ht_itblock = NULL;
|
||||
static HtUU *ht_it = NULL;
|
||||
// XXX kill globals
|
||||
static R_TH_LOCAL csh cd = 0;
|
||||
static R_TH_LOCAL HtUU *ht_itblock = NULL;
|
||||
static R_TH_LOCAL HtUU *ht_it = NULL;
|
||||
|
||||
#include "cs_mnemonics.c"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2012-2015 - condret, pancake */
|
||||
/* radare - LGPL - Copyright 2012-2021 - condret, pancake */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
|
@ -7,7 +7,7 @@
|
|||
#include "../arch/snes/snesdis.c"
|
||||
#include "asm_snes.h"
|
||||
|
||||
static struct snes_asm_flags* snesflags = NULL;
|
||||
static R_TH_LOCAL struct snes_asm_flags* snesflags = NULL;
|
||||
|
||||
static bool snes_asm_init(void* user) {
|
||||
if (!snesflags) {
|
||||
|
|
|
@ -72,7 +72,7 @@ static int tms320c64x_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len)
|
|||
|
||||
#include "../arch/tms320/tms320_dasm.h"
|
||||
|
||||
static tms320_dasm_t engine = { 0 };
|
||||
static R_TH_LOCAL tms320_dasm_t engine = { 0 };
|
||||
|
||||
static int tms320_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
if (a->cpu && r_str_casecmp (a->cpu, "c54x") == 0) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare2 - LGPL - Copyright 2013-2021 - pancake */
|
||||
/* radare2 - LGPL - Copyright 2013-2022 - pancake */
|
||||
|
||||
#include <r_asm.h>
|
||||
#include <r_lib.h>
|
||||
|
@ -6,8 +6,8 @@
|
|||
|
||||
#define USE_ITER_API 1
|
||||
|
||||
static csh cd = 0;
|
||||
static int n = 0;
|
||||
static R_TH_LOCAL csh cd = 0;
|
||||
static R_TH_LOCAL int n = 0;
|
||||
|
||||
static bool the_end(void *p) {
|
||||
#if 0
|
||||
|
@ -57,7 +57,7 @@ static bool check_features(RAsm *a, cs_insn *insn) {
|
|||
}
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
static int omode = 0;
|
||||
static R_TH_LOCAL int omode = 0;
|
||||
int mode, ret;
|
||||
ut64 off = a->pc;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare2 - LGPL - Copyright 2018-2021 - pancake, keegan */
|
||||
/* radare2 - LGPL - Copyright 2018-2022 - pancake, mrmacete, keegan */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
|
@ -113,9 +113,29 @@ typedef struct _r_bin_image {
|
|||
ut32 nlist_count;
|
||||
} RDyldBinImage;
|
||||
|
||||
static RList *pending_bin_files = NULL;
|
||||
static R_TH_LOCAL RList *pending_bin_files = NULL;
|
||||
|
||||
static ut64 va2pa(uint64_t addr, ut32 n_maps, cache_map_t *maps, RBuffer *cache_buf, ut64 slide, ut32 *offset, ut32 *left);
|
||||
static ut64 va2pa(uint64_t addr, ut32 n_maps, cache_map_t *maps, RBuffer *cache_buf, ut64 slide, ut32 *offset, ut32 *left) {
|
||||
ut64 res = UT64_MAX;
|
||||
ut32 i;
|
||||
|
||||
addr -= slide;
|
||||
|
||||
for (i = 0; i < n_maps; i++) {
|
||||
if (addr >= maps[i].address && addr < maps[i].address + maps[i].size) {
|
||||
res = maps[i].fileOffset + addr - maps[i].address;
|
||||
if (offset) {
|
||||
*offset = addr - maps[i].address;
|
||||
}
|
||||
if (left) {
|
||||
*left = maps[i].size - (addr - maps[i].address);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static void free_bin(RDyldBinImage *bin) {
|
||||
if (!bin) {
|
||||
|
@ -426,28 +446,6 @@ static void r_dyldcache_free(RDyldCache *cache) {
|
|||
R_FREE (cache);
|
||||
}
|
||||
|
||||
static ut64 va2pa(uint64_t addr, ut32 n_maps, cache_map_t *maps, RBuffer *cache_buf, ut64 slide, ut32 *offset, ut32 *left) {
|
||||
ut64 res = UT64_MAX;
|
||||
ut32 i;
|
||||
|
||||
addr -= slide;
|
||||
|
||||
for (i = 0; i < n_maps; i++) {
|
||||
if (addr >= maps[i].address && addr < maps[i].address + maps[i].size) {
|
||||
res = maps[i].fileOffset + addr - maps[i].address;
|
||||
if (offset) {
|
||||
*offset = addr - maps[i].address;
|
||||
}
|
||||
if (left) {
|
||||
*left = maps[i].size - (addr - maps[i].address);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static ut64 bin_obj_va2pa(ut64 p, ut32 *offset, ut32 *left, RBinFile *bf) {
|
||||
if (!bf || !bf->o || !bf->o->bin_obj) {
|
||||
return 0;
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
|
||||
#define IFDBG_BIN_JAVA if (0)
|
||||
|
||||
static Sdb *DB = NULL;
|
||||
static R_TH_LOCAL Sdb *DB = NULL;
|
||||
|
||||
static void add_bin_obj_to_sdb(RBinJavaObj *bin);
|
||||
static int add_sdb_bin_obj(const char *key, RBinJavaObj *bin_obj);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare2 - LGPL - Copyright 2019-2021 - mrmacete */
|
||||
/* radare2 - LGPL - Copyright 2019-2022 - mrmacete */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
|
@ -174,7 +174,7 @@ static void ensure_kexts_initialized(RKernelCacheObj *obj, RBinFile *bf);
|
|||
|
||||
static void r_kernel_cache_free(RKernelCacheObj *obj);
|
||||
|
||||
static RList *pending_bin_files = NULL;
|
||||
static R_TH_LOCAL RList *pending_bin_files = NULL;
|
||||
|
||||
static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) {
|
||||
RBuffer *fbuf = r_buf_ref (buf);
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
#define DEBUG_DISASM 0
|
||||
|
||||
// ugly globals but meh
|
||||
static ut64 emustack_min = 0LL;
|
||||
static ut64 emustack_max = 0LL;
|
||||
static R_TH_LOCAL ut64 emustack_min = 0LL;
|
||||
static R_TH_LOCAL ut64 emustack_max = 0LL;
|
||||
|
||||
static const char* r_vline_a[] = {
|
||||
"|", // LINE_VERT
|
||||
|
@ -881,7 +881,7 @@ static RDisasmState *ds_init(RCore *core) {
|
|||
return ds;
|
||||
}
|
||||
|
||||
static ut64 lastaddr = UT64_MAX;
|
||||
static R_TH_LOCAL ut64 lastaddr = UT64_MAX;
|
||||
|
||||
static void ds_reflines_fini(RDisasmState *ds) {
|
||||
RAnal *anal = ds->core->anal;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2014-2019 - pancake, thestr4ng3r */
|
||||
/* radare - LGPL - Copyright 2014-2022 - pancake, thestr4ng3r */
|
||||
|
||||
#include <r_core.h>
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2009-2021 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2022 - pancake */
|
||||
|
||||
#include <r_core.h>
|
||||
#include <r_cons.h>
|
||||
|
|
|
@ -20,7 +20,7 @@ R_LIB_VERSION(r_lang);
|
|||
#include "p/go.c" // hardcoded
|
||||
#include "p/lib.c"
|
||||
|
||||
static RLang *__lang = NULL;
|
||||
static R_TH_LOCAL RLang *__lang = NULL;
|
||||
|
||||
R_API void r_lang_plugin_free(RLangPlugin *p) {
|
||||
if (p && p->fini) {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "r_lang.h"
|
||||
#define USE_R2 1
|
||||
|
||||
static RLang *Glang = NULL;
|
||||
static R_TH_LOCAL RLang *Glang = NULL;
|
||||
#undef S_API
|
||||
// #include "../../../shlr/spp/spp.c"
|
||||
#include "../../../shlr/spp/spp.h"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2008-2021 - pancake */
|
||||
/* radare - LGPL - Copyright 2008-2022 - pancake */
|
||||
|
||||
#include <r_util.h>
|
||||
#include <r_lib.h>
|
||||
|
@ -7,7 +7,7 @@ R_LIB_VERSION(r_lib);
|
|||
|
||||
/* TODO: avoid globals */
|
||||
#define IFDBG if(__has_debug)
|
||||
static bool __has_debug = false;
|
||||
static R_TH_LOCAL bool __has_debug = false;
|
||||
|
||||
/* XXX : this must be registered in runtime */
|
||||
static const char *r_lib_types[] = {
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
/* radare - LGPL - Copyright 2007-2018 - pancake, ret2libc */
|
||||
/* radare - LGPL - Copyright 2007-2022 - pancake, ret2libc */
|
||||
|
||||
#define LOG_CONFIGSTR_SIZE 512
|
||||
#define LOG_CONFIGSTR_SIZE 128
|
||||
#define LOG_OUTPUTBUF_SIZE 512
|
||||
|
||||
#include <r_core.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
// TODO: Use thread-local storage to make these variables thread-safe
|
||||
static RList *log_cbs = NULL; // Functions to call when outputting log string
|
||||
static int cfg_loglvl = R_LOGLVL_ERROR; // Log level output
|
||||
static int cfg_logtraplvl = R_LOGLVL_FATAL; // Log trap level
|
||||
static bool cfg_logsrcinfo = false; // Print out debug source info with the output
|
||||
static bool cfg_logcolors = false; // Output colored log text based on level
|
||||
static char cfg_logfile[LOG_CONFIGSTR_SIZE] = ""; // Output text to filename
|
||||
static R_TH_LOCAL RList *log_cbs = NULL; // Functions to call when outputting log string
|
||||
static R_TH_LOCAL int cfg_loglvl = R_LOGLVL_ERROR; // Log level output
|
||||
static R_TH_LOCAL int cfg_logtraplvl = R_LOGLVL_FATAL; // Log trap level
|
||||
static R_TH_LOCAL bool cfg_logsrcinfo = false; // Print out debug source info with the output
|
||||
static R_TH_LOCAL bool cfg_logcolors = false; // Output colored log text based on level
|
||||
static R_TH_LOCAL char cfg_logfile[LOG_CONFIGSTR_SIZE] = ""; // Output text to filename
|
||||
static const char *level_tags[] = { // Log level to tag string lookup array
|
||||
[R_LOGLVL_SILLY] = "SILLY",
|
||||
[R_LOGLVL_VERBOSE] = "VERBOSE",
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
|
||||
#define DFLT_ROWS 16
|
||||
|
||||
// global
|
||||
static const char hex[16] = "0123456789ABCDEF";
|
||||
// global mutable
|
||||
static R_TH_LOCAL RPrintIsInterruptedCallback is_interrupted_cb = NULL;
|
||||
|
||||
static int nullprinter(const char *a, ...) {
|
||||
return 0;
|
||||
|
@ -27,8 +30,6 @@ static int libc_eprintf(const char *format, ...) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static RPrintIsInterruptedCallback is_interrupted_cb = NULL;
|
||||
|
||||
R_API void r_print_portionbar(RPrint *p, const ut64 *portions, int n_portions) {
|
||||
const int use_color = p->flags & R_PRINT_FLAGS_COLOR;
|
||||
int i, j;
|
||||
|
@ -2059,9 +2060,9 @@ R_API const char* r_print_color_op_type(RPrint *p, ut32 anal_type) {
|
|||
}
|
||||
}
|
||||
|
||||
// Global buffer to speed up colorizing performance
|
||||
// XXX Global buffer to speed up colorizing performance
|
||||
#define COLORIZE_BUFSIZE 1024
|
||||
static char o[COLORIZE_BUFSIZE];
|
||||
static R_TH_LOCAL char o[COLORIZE_BUFSIZE];
|
||||
|
||||
static bool issymbol(char c) {
|
||||
switch (c) {
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
#include <priv.h>
|
||||
#endif
|
||||
|
||||
static bool G_enabled = false;
|
||||
static bool G_disabled = false;
|
||||
static int G_graintype = R_SANDBOX_GRAIN_NONE;
|
||||
static R_TH_LOCAL bool G_enabled = false;
|
||||
static R_TH_LOCAL bool G_disabled = false;
|
||||
static R_TH_LOCAL int G_graintype = R_SANDBOX_GRAIN_NONE;
|
||||
|
||||
#define R_SANDBOX_GUARD(x,y) if (G_enabled && !(G_graintype & (x))) { return (y); }
|
||||
|
||||
|
|
|
@ -1247,7 +1247,11 @@ R_API char *r_sys_whoami(void) {
|
|||
}
|
||||
#elif __wasi__
|
||||
strcpy (buf, "user");
|
||||
#elif HAVE_TH_LOCAL
|
||||
char *user = r_sys_getenv ("USER");
|
||||
return user? user: r_str_newf ("uid%d", getuid ());
|
||||
#else
|
||||
// XXX this is not thread safe and getpwuid_r is not available
|
||||
struct passwd *pw = getpwuid (getuid ());
|
||||
if (pw) {
|
||||
return strdup (pw->pw_name);
|
||||
|
@ -1308,7 +1312,7 @@ R_API bool r_sys_tts(const char *txt, bool bg) {
|
|||
}
|
||||
|
||||
R_API const char *r_sys_prefix(const char *pfx) {
|
||||
static char *prefix = NULL;
|
||||
static R_TH_LOCAL char *prefix = NULL;
|
||||
if (!prefix) {
|
||||
#if __WINDOWS__
|
||||
prefix = r_sys_get_src_dir_w32 ();
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#!/bin/sh
|
||||
# SANITIZE="address leak memory undefined"
|
||||
# SANITIZE="address signed-integer-overflow" # Faster build
|
||||
# default:
|
||||
SANITIZE=${SANITIZE:="address undefined signed-integer-overflow"}
|
||||
# SANITIZE=${SANITIZE:="thread undefined signed-integer-overflow"}
|
||||
|
||||
printf "\033[32m"
|
||||
echo "========================================================================="
|
||||
|
|
Loading…
Reference in New Issue