Skip to content

Commit

Permalink
Remove hidden static in rz_analysis_cc_max_arg
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio committed Jan 5, 2024
1 parent e1af458 commit 4086e4e
Show file tree
Hide file tree
Showing 24 changed files with 66 additions and 21 deletions.
33 changes: 15 additions & 18 deletions librz/analysis/cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ RZ_API void rz_analysis_cc_del(RzAnalysis *analysis, const char *name) {
rz_return_if_fail(analysis && name);
sdb_unset(DB, name, 0);
cc_sdb_unsetf(DB, "cc.%s.ret", name);
cc_sdb_unsetf(DB, "cc.%s.maxargs", name);
cc_sdb_unsetf(DB, "cc.%s.argn", name);
for (int i = 0; i < RZ_ANALYSIS_CC_MAXARG; i++) {
cc_sdb_unsetf(DB, "cc.%s.arg%d", name, i);
Expand Down Expand Up @@ -77,6 +78,11 @@ RZ_API bool rz_analysis_cc_set(RzAnalysis *analysis, const char *expr) {
n++;
}
}
if (n > rz_analysis_cc_max_arg(analysis, ccname)) {
char maxargs[256];
rz_strf(maxargs, "%d", n);
cc_sdb_setf(DB, maxargs, "cc.%s.maxargs", ccname);
}
rz_list_free(ccArgs);
free(e);
free(args);
Expand Down Expand Up @@ -197,27 +203,18 @@ RZ_API void rz_analysis_cc_set_error(RzAnalysis *analysis, const char *conventio
}

RZ_API int rz_analysis_cc_max_arg(RzAnalysis *analysis, const char *cc) {
int i = 0;
rz_return_val_if_fail(analysis && DB && cc, 0);
static void *oldDB = NULL;
static char *oldCC = NULL;
static int oldArg = 0;
if (oldDB == DB && !strcmp(cc, oldCC)) {
return oldArg;
char *query = rz_str_newf("cc.%s.maxargs", cc);
if (!query) {
return 0;
}
oldDB = DB;
free(oldCC);
oldCC = strdup(cc);
for (i = 0; i < RZ_ANALYSIS_CC_MAXARG; i++) {
char *query = rz_str_newf("cc.%s.arg%d", cc, i);
const char *res = query ? sdb_const_get(DB, query, 0) : NULL;
free(query);
if (!res) {
break;
}
const char *res = sdb_const_get(DB, query, 0);
free(query);
int maxargs = res ? atoi(res) : 0;
if (maxargs < 0 || maxargs > RZ_ANALYSIS_CC_MAXARG) {
return 0;
}
oldArg = i;
return i;
return maxargs;
}

RZ_API const char *rz_analysis_cc_ret(RzAnalysis *analysis, const char *convention) {
Expand Down
2 changes: 2 additions & 0 deletions librz/analysis/d/cc-arm-16.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ cc.arm16.arg1=r1
cc.arm16.arg2=r2
cc.arm16.arg3=r3
cc.arm16.argn=stack
cc.arm16.maxargs=4
cc.arm16.ret=r0

arm32=cc
cc.arm32.arg0=r0
cc.arm32.arg1=r1
cc.arm32.arg2=r2
cc.arm32.argn=stack
cc.arm16.maxargs=3
cc.arm32.ret=r0
3 changes: 3 additions & 0 deletions librz/analysis/d/cc-arm-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ default.cc=arm32
arm32=cc
cc.arm32.arg0=r0
cc.arm32.arg1=r1
cc.arm32.maxargs=2
cc.arm32.ret=r0

arm16=cc
Expand All @@ -11,6 +12,7 @@ cc.arm16.arg1=r1
cc.arm16.arg2=r2
cc.arm16.arg3=r3
cc.arm16.argn=stack
cc.arm16.maxargs=4
cc.arm16.ret=r0

swift=cc
Expand All @@ -19,6 +21,7 @@ cc.swift.arg1=r1
cc.swift.arg2=r2
cc.swift.arg3=r3
cc.swift.argn=stack
cc.swift.maxargs=4
cc.swift.self=r10
cc.swift.self=r8
cc.swift.ret=r0
2 changes: 2 additions & 0 deletions librz/analysis/d/cc-arm-64.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cc.arm64.arg5=x5
cc.arm64.arg6=x6
cc.arm64.arg7=x7
cc.arm64.argn=stack
cc.arm64.maxargs=8
cc.arm64.ret=x0

swift=cc
Expand All @@ -22,6 +23,7 @@ cc.swift.arg5=x5
cc.swift.arg6=x6
cc.swift.arg7=x7
cc.swift.argn=stack
cc.swift.maxargs=8
cc.swift.self=x20
cc.swift.error=x21
cc.swift.ret=x0
1 change: 1 addition & 0 deletions librz/analysis/d/cc-avr-8.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ cc.avr.arg4=r22
cc.avr.arg5=r21
cc.avr.arg6=r18
cc.avr.argn=stack
cc.avr.maxargs=7
cc.avr.ret=r24
2 changes: 2 additions & 0 deletions librz/analysis/d/cc-hexagon-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cc.hexagon.arg3=r3
cc.hexagon.arg4=r4
cc.hexagon.arg5=r5
cc.hexagon.argn=stack_rev
cc.hexagon.maxargs=6
cc.hexagon.ret=r0

hvx=cc
Expand All @@ -28,4 +29,5 @@ cc.hvx.arg12=v12
cc.hvx.arg13=v13
cc.hvx.arg14=v14
cc.hvx.arg15=v15
cc.hvx.maxargs=16
cc.hvx.ret=v0
1 change: 1 addition & 0 deletions librz/analysis/d/cc-m68k-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ default.cc=m68k

m68k=cc
cc.m68k.arg0=stack_rev
cc.m68k.maxargs=1
cc.m68k.ret=d0
2 changes: 2 additions & 0 deletions librz/analysis/d/cc-mips-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cc.o32.arg1=a1
cc.o32.arg2=a2
cc.o32.arg3=a3
cc.o32.argn=stack
cc.o32.maxargs=4
cc.o32.ret=v0

n32=cc
Expand All @@ -18,5 +19,6 @@ cc.n32.arg5=a5
cc.n32.arg6=a6
cc.n32.arg7=a7
cc.n32.argn=stack
cc.n32.maxargs=8
cc.n32.ret=v0

2 changes: 2 additions & 0 deletions librz/analysis/d/cc-mips-64.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cc.o32.arg1=a1
cc.o32.arg2=a2
cc.o32.arg3=a3
cc.o32.argn=stack
cc.o32.maxargs=4
cc.o32.ret=v0

n32=cc
Expand All @@ -18,5 +19,6 @@ cc.n32.arg5=a5
cc.n32.arg6=a6
cc.n32.arg7=a7
cc.n32.argn=stack
cc.n32.maxargs=8
cc.n32.ret=v0

1 change: 1 addition & 0 deletions librz/analysis/d/cc-ppc-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ cc.ppc-32.arg5=r8
cc.ppc-32.arg6=r9
cc.ppc-32.arg7=r10
cc.ppc-32.argn=stack_rev
cc.ppc-32.maxargs=8
cc.ppc-32.ret=r3

1 change: 1 addition & 0 deletions librz/analysis/d/cc-ppc-64.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ cc.ppc-64.arg5=r8
cc.ppc-64.arg6=r9
cc.ppc-64.arg7=r10
cc.ppc-64.argn=stack_rev
cc.ppc-64.maxargs=8
cc.ppc-64.ret=r3

1 change: 1 addition & 0 deletions librz/analysis/d/cc-riscv-64.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ cc.rvg.arg4=a4
cc.rvg.arg5=a5
cc.rvg.arg6=a6
cc.rvg.arg7=a7
cc.rvg.maxargs=8
cc.rvg.ret=a0
1 change: 1 addition & 0 deletions librz/analysis/d/cc-sh-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ cc.sh4.arg0=r4
cc.sh4.arg1=r5
cc.sh4.arg2=r6
cc.sh4.arg3=r7
cc.sh4.maxargs=4
cc.sh4.ret=r0
1 change: 1 addition & 0 deletions librz/analysis/d/cc-sparc-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ cc.sparc.arg3=i3
cc.sparc.arg4=i4
cc.sparc.arg5=i5
cc.sparc.argn=stack
cc.sparc.maxargs=6
cc.sparc.ret=o0
1 change: 1 addition & 0 deletions librz/analysis/d/cc-spc700-16.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ spc700=cc
cc.spc700.arg0=a
cc.spc700.arg1=x
cc.spc700.arg2=y
cc.spc700.maxargs=3
cc.spc700.ret=a
1 change: 1 addition & 0 deletions librz/analysis/d/cc-sysz-64.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ cc.sysz.arg1=r3
cc.sysz.arg2=r4
cc.sysz.arg3=r5
cc.sysz.arg4=r6
cc.sysz.maxargs=5
cc.sysz.ret=r2
2 changes: 2 additions & 0 deletions librz/analysis/d/cc-tricore-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ cc.reg.arg5=a5
cc.reg.arg6=a6
cc.reg.arg7=a7
cc.reg.argn=stack
cc.reg.maxargs=8
cc.reg.ret=d2

stack=cc
cc.stack.argn=stack
cc.stack.maxargs=0
cc.stack.ret=d2
5 changes: 5 additions & 0 deletions librz/analysis/d/cc-x86-16.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cc.fastcall.arg1=dx
cc.fastcall.arg2=bx
cc.fastcall.arg3=cx
cc.fastcall.argn=stack
cc.fastcall.maxargs=4
cc.fastcall.ret=ax

watcom=cc
Expand All @@ -14,24 +15,28 @@ cc.watcom.arg1=dx
cc.watcom.arg2=bx
cc.watcom.arg3=cx
cc.watcom.argn=stack
cc.watcom.maxargs=4
cc.watcom.ret=si

turboc=cc
cc.turboc.arg0=ax
cc.turboc.arg1=dx
cc.turboc.arg2=bx
cc.turboc.argn=stack
cc.turboc.maxargs=3
cc.turboc.ret=ax

ms=cc
cc.ms.arg0=ax
cc.ms.arg1=dx
cc.ms.argn=stack
cc.ms.maxargs=2
cc.ms.ret=ax

msm=cc
cc.msm.arg0=ax
cc.msm.arg1=dx
cc.msm.arg2=bx
cc.msm.argn=stack
cc.msm.maxargs=3
cc.msm.ret=bx
8 changes: 8 additions & 0 deletions librz/analysis/d/cc-x86-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@ default.cc=cdecl

cdecl=cc
cc.cdecl.argn=stack
cc.cdecl.maxargs=0
cc.cdecl.ret=eax

cdecl-thiscall-ms=cc
cc.cdecl-thiscall-ms.arg0=ecx
cc.cdecl-fastcall-ms.argn=stack
cc.cdecl-fastcall-ms.maxargs=1
cc.cdecl-fastcall-ms.ret=eax

optlink=cc
cc.optlink.arg0=eax
cc.optlink.arg1=edx
cc.optlink.arg2=ecx
cc.optlink.argn=stack
cc.optlink.maxargs=3
cc.optlink.ret=eax

stdcall=cc
cc.stdcall.argn=stack
cc.stdcall.maxargs=0
cc.stdcall.ret=eax

fastcall=cc
cc.fastcall.arg0=ecx
cc.fastcall.arg1=edx
cc.fastcall.argn=stack
cc.fastcall.maxargs=2
cc.fastcall.ret=eax

borland=cc
cc.borland.arg0=eax
cc.borland.arg1=edx
cc.borland.arg2=ecx
cc.borland.maxargs=3
cc.borland.argn=stack_rev

watcom=cc
Expand All @@ -38,6 +44,8 @@ cc.watcom.arg1=edx
cc.watcom.arg2=ebx
cc.watcom.arg3=ecx
cc.watcom.argn=stack
cc.watcom.maxargs=4

pascal=cc
cc.pascal.argn=stack_rev
cc.pascal.maxargs=0
4 changes: 4 additions & 0 deletions librz/analysis/d/cc-x86-64.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cc.ms.arg1=rdx
cc.ms.arg2=r8
cc.ms.arg3=r9
cc.ms.argn=stack
cc.ms.maxargs=4
cc.ms.ret=rax

amd64=cc
Expand All @@ -20,6 +21,7 @@ cc.amd64.arg7=xmm1
cc.amd64.arg8=xmm2
cc.amd64.arg9=xmm3
cc.amd64.arg10=xmm4
cc.amd64.maxargs=11
cc.amd64.ret=rax

swift=cc
Expand All @@ -34,6 +36,7 @@ cc.swift.arg7=xmm1
cc.swift.arg8=xmm2
cc.swift.arg9=xmm3
cc.swift.arg10=xmm4
cc.swift.maxargs=11
cc.swift.self=r13
cc.swift.error=r12
cc.swift.ret=rax
Expand All @@ -45,4 +48,5 @@ cc.amd64syscall.arg2=rdx
cc.amd64syscall.arg3=r10
cc.amd64syscall.arg4=r8
cc.amd64syscall.arg5=r9
cc.amd64syscall.maxargs=6
cc.amd64syscall.ret=rax
1 change: 1 addition & 0 deletions librz/analysis/d/cc-xtensa-32.sdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ cc.call0.arg3=a5
cc.call0.arg4=a6
cc.call0.arg5=a7
cc.call0.argn=stack
cc.call0.maxargs=6
cc.call0.ret=a2
8 changes: 5 additions & 3 deletions librz/analysis/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,11 @@ RZ_API int rz_analysis_var_get_argnum(RzAnalysisVar *var) {
if (!reg) {
return -1;
}
int i;
int arg_max = var->fcn->cc ? rz_analysis_cc_max_arg(analysis, var->fcn->cc) : 0;
for (i = 0; i < arg_max; i++) {
int arg_max = 0;
if (RZ_STR_ISNOTEMPTY(var->fcn->cc)) {
arg_max = rz_analysis_cc_max_arg(analysis, var->fcn->cc);
}
for (int i = 0; i < arg_max; i++) {
const char *reg_arg = rz_analysis_cc_arg(analysis, var->fcn->cc, i);
if (reg_arg && !strcmp(reg->name, reg_arg)) {
return i;
Expand Down
2 changes: 2 additions & 0 deletions test/unit/test_analysis_cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ static Sdb *ref_db() {
sdb_set(db, "cc.sectarian.arg1", "rcx", 0);
sdb_set(db, "cc.sectarian.arg0", "rdx", 0);
sdb_set(db, "cc.sectarian.argn", "stack", 0);
sdb_set(db, "cc.sectarian.maxargs", "2", 0);
sdb_set(db, "sectarian", "cc", 0);
return db;
}
Expand All @@ -24,6 +25,7 @@ static Sdb *ref_db_self_err() {
sdb_set(db, "cc.sectarian.arg1", "rcx", 0);
sdb_set(db, "cc.sectarian.arg0", "rdx", 0);
sdb_set(db, "cc.sectarian.argn", "stack", 0);
sdb_set(db, "cc.sectarian.maxargs", "2", 0);
sdb_set(db, "sectarian", "cc", 0);
return db;
}
Expand Down
2 changes: 2 additions & 0 deletions test/unit/test_serialize_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,7 @@ static Sdb *cc_ref_db() {
sdb_set(db, "cc.sectarian.arg1", "rcx", 0);
sdb_set(db, "cc.sectarian.arg0", "rdx", 0);
sdb_set(db, "cc.sectarian.argn", "stack", 0);
sdb_set(db, "cc.sectarian.maxargs", "2", 0);
sdb_set(db, "sectarian", "cc", 0);
return db;
}
Expand Down Expand Up @@ -1352,6 +1353,7 @@ Sdb *analysis_ref_db() {
sdb_set(cc, "cc.sectarian.arg1", "rcx", 0);
sdb_set(cc, "cc.sectarian.arg0", "rdx", 0);
sdb_set(cc, "cc.sectarian.argn", "stack", 0);
sdb_set(cc, "cc.sectarian.maxargs", "2", 0);
sdb_set(cc, "sectarian", "cc", 0);

sdb_ns(db, "types", true);
Expand Down

0 comments on commit 4086e4e

Please sign in to comment.