Skip to content

Commit c078733

Browse files
authored
Fix RISCV arch detection (#790)
* Add RISCV alias so arch can be determined by ELF * Add ptrsize property to RISCV arch * Allow riscv tests to run
1 parent 48d39bb commit c078733

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

gef.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2306,7 +2306,7 @@ def mprotect_asm(cls, addr: int, size: int, perm: Permission) -> str:
23062306
class RISCV(Architecture):
23072307
arch = "RISCV"
23082308
mode = "RISCV"
2309-
aliases = ("RISCV",)
2309+
aliases = ("RISCV", Elf.Abi.RISCV)
23102310

23112311
all_registers = ["$zero", "$ra", "$sp", "$gp", "$tp", "$t0", "$t1",
23122312
"$t2", "$fp", "$s1", "$a0", "$a1", "$a2", "$a3",
@@ -2345,6 +2345,15 @@ def is_ret(self, insn: Instruction) -> bool:
23452345
def mprotect_asm(cls, addr: int, size: int, perm: Permission) -> str:
23462346
raise OSError(f"Architecture {cls.arch} not supported yet")
23472347

2348+
@property
2349+
def ptrsize(self) -> int:
2350+
if self._ptrsize is not None:
2351+
return self._ptrsize
2352+
if is_alive():
2353+
self._ptrsize = gdb.parse_and_eval("$pc").type.sizeof
2354+
return self._ptrsize
2355+
return 4
2356+
23482357
def is_conditional_branch(self, insn: Instruction) -> bool:
23492358
return insn.mnemonic.startswith("b")
23502359

tests/binaries/utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
// #elif defined(__sparc) || defined(__sparc64__) || defined(__sparc__)
3838
// #define DebugBreak() { raise( SIGINT ) ; }
3939

40+
/* RISC V */
41+
#elif defined(__riscv)
42+
#define DebugBreak() { raise( SIGINT ) ; }
43+
4044
/* the rest */
4145
#else
4246
#error "Unsupported architecture"

tests/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
DEFAULT_CONTEXT = "-code -stack"
1515
ARCH = (os.getenv("GEF_CI_ARCH") or platform.machine()).lower()
1616
CI_VALID_ARCHITECTURES_32B = ("i686", "armv7l")
17-
CI_VALID_ARCHITECTURES_64B = ("x86_64", "aarch64", "mips64el", "ppc64le")
17+
CI_VALID_ARCHITECTURES_64B = ("x86_64", "aarch64", "mips64el", "ppc64le", "riscv64")
1818
CI_VALID_ARCHITECTURES = CI_VALID_ARCHITECTURES_64B + CI_VALID_ARCHITECTURES_32B
1919
COVERAGE_DIR = os.getenv("COVERAGE_DIR", "")
2020

0 commit comments

Comments
 (0)