Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove static variables from RzAnalysis plugins #3721

Closed
XVilka opened this issue Aug 3, 2023 · 15 comments · Fixed by #4282
Closed

Remove static variables from RzAnalysis plugins #3721

XVilka opened this issue Aug 3, 2023 · 15 comments · Fixed by #4282

Comments

@XVilka
Copy link
Member

XVilka commented Aug 3, 2023

$ rg --pcre2 "\tstatic (?\!const)" librz/analysis/p/
librz/analysis/p/analysis_sparc_cs.c
74:	static RzRegItem reg;
100:	static csh handle = 0;
101:	static int omode;

librz/analysis/p/analysis_pic.c
32:	static void _inst__##OPCODE_NAME(RzAnalysis *analysis, RzAnalysisOp *op, \
663:	static bool init_done = false;

librz/analysis/p/analysis_xtensa.c
16:	static int length_table[16] = { 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 8, 8 };
1969:	static xtensa_insnbuf insn_buffer = NULL;
1970:	static xtensa_insnbuf slot_buffer = NULL;

librz/analysis/p/analysis_ppc_cs.c
43:	static char cmask[32];
57:	static char cmask[32];
73:	static char words[8][64];
141:	static char cspr[16];
925:	static csh handle = 0;
926:	static int omode = -1, obits = -1;

librz/analysis/p/analysis_x86_cs.c
230:	static char buf[AR_DIM][BUF_SZ];

librz/analysis/p/analysis_m680x_cs.c
50:	static csh handle = 0;
51:	static int omode = -1;
52:	static int obits = 32;

librz/analysis/p/analysis_m68k_cs.c
131:	static RzRegItem reg;
164:	static csh handle = 0;
165:	static int omode = -1;
166:	static int obits = 32;

librz/analysis/p/analysis_xcore_cs.c
54:	static csh handle = 0;
55:	static int omode = 0;

librz/analysis/p/analysis_mips_cs.c
619:	static RzRegItem reg;

librz/analysis/p/analysis_tms320c64x.c
63:	static csh handle = 0;
64:	static int omode;

librz/analysis/p/analysis_riscv_cs.c
221:	static RzRegItem reg;
320:	static csh hndl = 0;
321:	static int omode = -1;
322:	static int obits = 32;

See 2c9a700 as an example how to handle this.

@khardikk
Copy link

khardikk commented Aug 8, 2023

Hey @XVilka I would like to work on this issue! it will be my first time contributing

@XVilka
Copy link
Member Author

XVilka commented Aug 9, 2023

Sure, @Hady68, go ahead.

@khardikk
Copy link

khardikk commented Aug 9, 2023

Sure, @Hady68, go ahead.

Can you please list down the steps that are needed to solve this one?

@XVilka
Copy link
Member Author

XVilka commented Aug 9, 2023

See the commit mentioned in the issue, just do similarly.

@khardikk
Copy link

khardikk commented Aug 9, 2023

See the commit mentioned in the issue, just do similarly.

Sure okay, can you please assign this to me

@XVilka
Copy link
Member Author

XVilka commented Aug 9, 2023

See the commit mentioned in the issue, just do similarly.

Sure okay, can you please assign this to me

GitHub doesn't allow assigning people who aren't part of the organization. Just send a PR and link to this issue, that should be enough. Don't forget to check https://github.com/rizinorg/rizin/blob/dev/CONTRIBUTING.md and https://github.com/rizinorg/rizin/blob/dev/DEVELOPERS.md

@khardikk
Copy link

khardikk commented Aug 9, 2023

See the commit mentioned in the issue, just do similarly.

Sure okay, can you please assign this to me

GitHub doesn't allow assigning people who aren't part of the organization. Just send a PR and link to this issue, that should be enough. Don't forget to check https://github.com/rizinorg/rizin/blob/dev/CONTRIBUTING.md and https://github.com/rizinorg/rizin/blob/dev/DEVELOPERS.md

Got it thanks will do so

@XVilka
Copy link
Member Author

XVilka commented Aug 9, 2023

@Hady68 sorry, there is actually a better example - see how the state is saved into the context in librz/analysis/p/analysis_asm_cs.c

@khardikk
Copy link

khardikk commented Aug 9, 2023

Hi @XVilka, I have worked on one of the files, and wanted to cross-check if this is what you're looking for, then I can go forward for other files as well, attaching the link to a PR in my forked repo, please have a look and let me know.
khardikk#1

@XVilka
Copy link
Member Author

XVilka commented Aug 9, 2023

@Hady68 no, you need to introduce a context structure since the omode of that code is cached between different disassemble() function calls.

@khardikk
Copy link

khardikk commented Aug 9, 2023

of that code is cached between different disassemble() function calls.

Added the above here -> khardikk@af37dc3 please check

@XVilka
Copy link
Member Author

XVilka commented Aug 10, 2023

@Hady68 yes, the crux of it is right. Please fix the indentation though (use sys/clang-format.py)

@khardikk
Copy link

@Hady68 yes, the crux of it is right. Please fix the indentation though (use sys/clang-format.py)

Alright will fix it, working on the other files now

@HN026
Copy link
Contributor

HN026 commented Jan 19, 2024

Removed static Variables from RzAsm #4100

@XVilka
Copy link
Member Author

XVilka commented Jan 21, 2024

@imbillow could you please remove the one static var left in RzAsm tricore plugin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants