Remove all globals & static variables where possible
Currently rizin contains a lot of global variables, ideally we want to remove most of them.
Many fields shall not be touched like the float.c ones, etc..
Can be found via $ find librz/ -type f -name "*.c" -o -name "*.h" -o -name "*.inc" | xargs -I % ctags -x --c-kinds=v % | grep 'static ' | grep -v ' static const \|{\|\[\]' | grep -v ' const static \|{\|\[\]'
is_interrupted_cb variable 35 librz/util/print.c static RzPrintIsInterruptedCallback is_interrupted_cb = NULL;
env variable 39 librz/util/sys.c static char **env = NULL;
fd2close variable 1487 librz/util/sys.c static HtUU *fd2close;
is_child variable 1414 librz/util/sys.c static bool is_child = false;
is_child variable 1491 librz/util/sys.c static bool is_child = false;
sys_pipe_mutex variable 1413 librz/util/sys.c static RzThreadLock *sys_pipe_mutex;
sys_pipe_mutex variable 1490 librz/util/sys.c static RzThreadLock *sys_pipe_mutex;
has_procthreadattr variable 53 librz/util/subprocess.c static bool has_procthreadattr = false;
lpDeleteProcThreadAttributeList variable 35 librz/util/subprocess.c static DeleteProcThreadAttributeList_t lpDeleteProcThreadAttributeList = NULL;
lpInitializeProcThreadAttributeList variable 33 librz/util/subprocess.c static InitializeProcThreadAttributeList_t lpInitializeProcThreadAttributeList = NULL;
lpUpdateProcThreadAttribute variable 34 librz/util/subprocess.c static UpdateProcThreadAttribute_t lpUpdateProcThreadAttribute = NULL;
mode_stderr variable 57 librz/util/subprocess.c static DWORD mode_stderr;
mode_stdin variable 55 librz/util/subprocess.c static DWORD mode_stdin;
mode_stdout variable 56 librz/util/subprocess.c static DWORD mode_stdout;
pipe_id variable 54 librz/util/subprocess.c static volatile long pipe_id = 0;
refcount variable 52 librz/util/subprocess.c static long refcount = 0;
sigchld_pipe variable 761 librz/util/subprocess.c static int sigchld_pipe[2];
sigchld_thread variable 762 librz/util/subprocess.c static RzThread *sigchld_thread;
subproc_mutex variable 51 librz/util/subprocess.c static RzThreadLock *subproc_mutex = NULL;
subprocs variable 759 librz/util/subprocess.c static RzPVector subprocs;
subprocs_mutex variable 760 librz/util/subprocess.c static RzThreadLock *subprocs_mutex;
dyn_forkpty variable 63 librz/socket/run.c static id_t (*dyn_forkpty)(int *amaster, char *name, struct termios *termp, struct winsize *winp) = NULL;
dyn_login_tty variable 62 librz/socket/run.c static int (*dyn_login_tty)(int fd) = NULL;
dyn_openpty variable 61 librz/socket/run.c static int (*dyn_openpty)(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp) = NULL;
breaked variable 7 librz/socket/socket_http_server.c static bool *breaked = NULL;
errno variable 10 librz/include/sflib/linux-arm-32/sfsyscall.h static int errno = 1234;
errno variable 31 librz/include/sflib/linux-x86-64/sfsyscall.h static int errno=1234;
errno variable 10 librz/include/sflib/linux-arm-64/sfsyscall.h static int errno = 1234;
errno variable 31 librz/include/sflib/linux-x86-32/sfsyscall.h static int errno=1234;
default_plugin variable 12 librz/io/io_plugin.c static volatile RzIOPlugin *default_plugin = NULL;
c_addr variable 19 librz/io/p/io_qnx.c static ut64 c_addr = UT64_MAX;
c_buff variable 21 librz/io/p/io_qnx.c static ut8 *c_buff = NULL;
c_size variable 20 librz/io/p/io_qnx.c static ut32 c_size = UT32_MAX;
gs variable 13 librz/io/p/io_winedbg.c static RzSocket *gs = NULL;
c variable 417 librz/core/cmd/cmd_search.c static int c = 0;
preludecnt variable 32 librz/core/cmd/cmd_search.c static int preludecnt = 0;
_core variable 1245 librz/core/cmd/cmd_debug.c static RzCore *_core = NULL;
LOOP_CONTINUE_VALUE variable 7 librz/core/rtr_http.c static int LOOP_CONTINUE_VALUE = 66;
rapthread variable 24 librz/core/rtr.c static RzThread *rapthread = NULL;
s variable 23 librz/core/rtr.c static RzSocket *s = NULL;
w32_GetFileInformationByHandleEx variable 1559 librz/cons/cons.c static GetFileInformationByHandleEx_t w32_GetFileInformationByHandleEx;
has_match variable 24 librz/debug/desil.c static int has_match = 0;
opc variable 26 librz/debug/desil.c static ut64 opc = 0;
prestep variable 25 librz/debug/desil.c static int prestep = 1; // TODO: make it configurable
buf_size variable 35 librz/debug/p/debug_qnx.c static int buf_size = 0;
desc variable 33 librz/debug/p/debug_qnx.c static libqnxr_t *desc = NULL;
reg_buf variable 34 librz/debug/p/debug_qnx.c static ut8 *reg_buf = NULL;
do_break variable 137 librz/debug/p/debug_windbg.c static bool do_break = false;
note_info variable 40 librz/debug/p/native/linux/linux_coredump.c static note_info_t note_info[NT_LENGHT_T];
coredump_nflavors variable 196 librz/debug/p/native/xnu/xnu_debug.h static int coredump_nflavors = 4;
coredump_nflavors variable 208 librz/debug/p/native/xnu/xnu_debug.h static int coredump_nflavors = 4;
coredump_nflavors variable 219 librz/debug/p/native/xnu/xnu_debug.h static int coredump_nflavors = 3;
coredump_nflavors variable 230 librz/debug/p/native/xnu/xnu_debug.h static int coredump_nflavors = 3;
coredump_nflavors variable 239 librz/debug/p/native/xnu/xnu_debug.h static int coredump_nflavors = 1;
coredump_nflavors variable 248 librz/debug/p/native/xnu/xnu_debug.h static int coredump_nflavors = 1;
breaked variable 815 librz/debug/p/native/windows/windows_debug.c static bool breaked = false;
lib_list variable 12 librz/debug/p/native/windows/windows_debug.c static RzList *lib_list = NULL;
kdctx variable 13 librz/debug/p/debug_winkd.c static KdCtx *kdctx = NULL;
openssl_lib variable 44 librz/hash/hash.c static RzHashOpenSSL *openssl_lib = NULL;
bfd_riscv_num_opcodes variable 687 librz/arch/isa_gnu/riscv/riscv-opc.c static int bfd_riscv_num_opcodes = RISCV_NUM_OPCODES;
riscv_opcodes variable 685 librz/arch/isa_gnu/riscv/riscv-opc.c static struct riscv_opcode *riscv_opcodes =
init_asm variable 41 librz/arch/isa_gnu/riscv/riscv.c static bool init_asm = 0;
opcodes_sorted variable 117 librz/arch/isa_gnu/lanai/lanai-dis.c static int opcodes_sorted = 0;
arc_extension_map variable 108 librz/arch/isa_gnu/arc/arc-ext.c static struct arcExtMap arc_extension_map;
addrwb_p variable 113 librz/arch/isa_gnu/arc/arc-opc.c static int addrwb_p;
arc_operand_map_a4 variable 148 librz/arch/isa_gnu/arc/arc-opc.c static unsigned char arc_operand_map_a4[256];
arc_operand_map_ac variable 149 librz/arch/isa_gnu/arc/arc-opc.c static unsigned char arc_operand_map_ac[256];
cpu_type variable 143 librz/arch/isa_gnu/arc/arc-opc.c static int cpu_type;
flag_p variable 107 librz/arch/isa_gnu/arc/arc-opc.c static int flag_p;
flagshimm_handled_p variable 110 librz/arch/isa_gnu/arc/arc-opc.c static int flagshimm_handled_p;
icode_map variable 4272 librz/arch/isa_gnu/arc/arc-opc.c static struct arc_opcode *icode_map[32];
jumpflags_p variable 122 librz/arch/isa_gnu/arc/arc-opc.c static int jumpflags_p;
limm variable 137 librz/arch/isa_gnu/arc/arc-opc.c static long limm;
limm_p variable 133 librz/arch/isa_gnu/arc/arc-opc.c static int limm_p;
ls_operand variable 154 librz/arch/isa_gnu/arc/arc-opc.c static enum operand ls_operand[OPERANDS];
nullify variable 119 librz/arch/isa_gnu/arc/arc-opc.c static int nullify;
nullify_p variable 116 librz/arch/isa_gnu/arc/arc-opc.c static int nullify_p;
opcode_map variable 4269 librz/arch/isa_gnu/arc/arc-opc.c static struct arc_opcode *opcode_map[26 + 1];
shimm variable 129 librz/arch/isa_gnu/arc/arc-opc.c static int shimm;
shimm_p variable 125 librz/arch/isa_gnu/arc/arc-opc.c static int shimm_p;
enable_insn_stream variable 283 librz/arch/isa_gnu/arc/arcompact-dis.c static short int enable_insn_stream = 0;
enable_simd variable 282 librz/arch/isa_gnu/arc/arcompact-dis.c static short int enable_simd = 0;
has_failed variable 9 librz/arch/isa/tms320/c55x_plus/ins.c static unsigned int has_failed = 0;
err variable 435 librz/arch/isa/arm/armass.c static bool err;
init_analysis variable 19 librz/arch/p_gnu/analysis/analysis_riscv_gnu.c static bool init_analysis = false;
opcodes_cache variable 12 librz/arch/p/asm/asm_pyc.c static pyc_opcodes *opcodes_cache = NULL;
cpu_enable variable 10 librz/arch/p/analysis/analysis_or1k.c static ut32 cpu_enable; /* allows to treat only registers with known value as
base_regs variable 868 librz/arch/p/analysis/analysis_ppc_cs.c static RzRegItem base_regs[4];
hPipeInOut variable 32 librz/lang/p/pipe_helper.c static HANDLE hPipeInOut = NULL;
hproc variable 33 librz/lang/p/pipe_helper.c static HANDLE hproc = NULL;
ac variable 13 librz/lang/p/c.c static int ac = 0;
Extra via command: grep -R -e '^\s\+static.\+;' . | grep '\.c:\|\.inc:' | grep -v -e 'static const\|static inline\|./subprojects/\|/test/'
/librz/main/rz-bin.c: static char *stdin_buf = NULL;
./librz/util/sys.c: static bool win_ver_initialized = false;
./librz/util/sys.c: static bool is_win_7_or_greater = false;
./librz/util/unum.c: static bool rand_initialized = false;
./librz/util/unum.c: static bool rand_initialized = false;
./librz/util/float/float.c: static ftype zero = 0; \
./librz/util/float/float.c: static ftype zero = 0; \
./librz/util/float/float.c: static ftype one = 1.0; \
./librz/core/cmd/cmd_shell.c: static int needs_newline = 0;
./librz/core/cmd/cmd_shell.c: static int needs_newline = 0;
./librz/core/cmd/cmd_shell.c: static char *olddir = NULL;
./librz/core/cmd/cmd.c: static RzCmdStatus handle_ts_##name##_internal(struct tsr2cmd_state *state, TSNode node, char *node_string); \
./librz/core/cmd/cmd.c: static_str = rz_cons_get_buffer();
./librz/core/cmd/cmd.c: static_str = rz_cons_get_buffer();
./librz/cons/grep.c: static char buf[RZ_CONS_GREP_BUFSIZE];
./librz/cons/less.c: static int in_help = false;
./librz/cons/cons.c: static HANDLE hStdout = NULL;
./librz/cons/cons.c: static DWORD size = -1;
./librz/cons/output.c: static HANDLE hStdout = NULL;
./librz/cons/output.c: static CONSOLE_SCREEN_BUFFER_INFO csbi;
./librz/cons/output.c: static HANDLE hStdout = NULL;
./librz/cons/output.c: static HANDLE hStderr = NULL;
./librz/debug/debug.c: static bool (*linux_attach_new_process)(RzDebug *dbg, int pid) = NULL;
./librz/debug/trace.c: static ut64 oldpc = UT64_MAX; // Must trace the previously traced instruction
./librz/debug/p/debug_windbg.c: static volatile LONG bp_idx = 0;
./librz/debug/p/native/linux/linux_coredump.c: static size_t size_note_hdr = sizeof(elf_nhdr_t);
./librz/debug/p/native/bt/windows-all.c: static bool initialized = false;
./librz/debug/p/native/bt/windows-all.c: static RzThreadLock *lock = NULL;
./librz/debug/p/native/xnu/xnu_excthreads.c: static ut64 chained_address = 0; // TODO: static is bad, move this into RzXnuDebug or handle differently somehow
./librz/debug/p/native/windows/windows_debug.c: static int exited_already = 0;
./librz/debug/p/native/windows/windows_message.c: static Sdb *msg_types = NULL;
./librz/arch/isa_gnu/arc/arc-dis.c: static char id[3 * ARRAY_SIZE(state->addresses)];
./librz/arch/isa_gnu/arc/arc-opc.c: static char buf[100];
./librz/arch/isa_gnu/arc/arc-opc.c: static int init_p = 0;
./librz/arch/isa_gnu/arc/arcompact-dis.c: static char id[3 * _NELEM(state->addresses)];
./librz/arch/isa/avr/avr_esil.c: static CPU_MODEL *cpu = NULL;
./librz/arch/isa/hexagon/hexagon_il.c: static bool might_has_jumped = false;
Linked to https://github.com/rizinorg/rizin/issues/276
This seems to miss some. E.g. the internal plugin state for Hexagon.
@wargio please update the issue since I removed a bunch of those.
updated