diff options
author | Alec Roelke <ar4jc@virginia.edu> | 2017-01-27 15:05:01 -0600 |
---|---|---|
committer | Alec Roelke <ar4jc@virginia.edu> | 2017-01-27 15:05:01 -0600 |
commit | e4c57275d38c864798cb04a4644bac90a83572fd (patch) | |
tree | 3f26d0e4e89347a9bbead74471e4a16a00695659 /src/arch/riscv | |
parent | c5df9308c99bd4af41b24119e2d86bde9eafdfa4 (diff) | |
download | gem5-e4c57275d38c864798cb04a4644bac90a83572fd.tar.xz |
riscv: Fix crash when syscall argument reg index is too high
By default, doSyscall gets the values of six registers to be used for
system call arguments. RISC-V, by convention, only has four. Because
RISC-V's implementation of these indices is as arrays of integers rather
than as base indices plus offsets, trying to get the fifth argument
register's value will cause a crash. This patch fixes that by returning 0
for any index higher than 3.
Signed-off-by: Jason Lowe-Power <jason@lowepower.com>
Diffstat (limited to 'src/arch/riscv')
-rw-r--r-- | src/arch/riscv/process.cc | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/arch/riscv/process.cc b/src/arch/riscv/process.cc index c1a67ec15..4eb3159af 100644 --- a/src/arch/riscv/process.cc +++ b/src/arch/riscv/process.cc @@ -217,7 +217,13 @@ RiscvLiveProcess::argsInit(int pageSize) RiscvISA::IntReg RiscvLiveProcess::getSyscallArg(ThreadContext *tc, int &i) { - return tc->readIntReg(SyscallArgumentRegs[i++]); + // RISC-V only has four system call argument registers by convention, so + // if a larger index is requested return 0 + RiscvISA::IntReg retval = 0; + if (i < 4) + retval = tc->readIntReg(SyscallArgumentRegs[i]); + i++; + return retval; } void |