From 7eaa5952f994c07a801fbef81f8097a5e9a5828f Mon Sep 17 00:00:00 2001 From: Brandon Potter Date: Thu, 17 Mar 2016 10:25:53 -0700 Subject: [PATCH] syscall_emul: fix bugs for mmap2 system call and x86-32 syscalls --- src/arch/x86/linux/process.cc | 2 +- src/arch/x86/process.cc | 1 + src/sim/syscall_emul.hh | 27 +++++++++++++++++++++------ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/arch/x86/linux/process.cc b/src/arch/x86/linux/process.cc index 9651f7436..665815c30 100644 --- a/src/arch/x86/linux/process.cc +++ b/src/arch/x86/linux/process.cc @@ -733,7 +733,7 @@ static SyscallDesc syscallDescs32[] = { /* 189 */ SyscallDesc("putpmsg", unimplementedFunc), /* 190 */ SyscallDesc("vfork", unimplementedFunc), /* 191 */ SyscallDesc("ugetrlimit", ignoreFunc), - /* 192 */ SyscallDesc("mmap2", mmapFunc), + /* 192 */ SyscallDesc("mmap2", mmap2Func), /* 193 */ SyscallDesc("truncate64", truncate64Func), /* 194 */ SyscallDesc("ftruncate64", ftruncate64Func), /* 195 */ SyscallDesc("stat64", stat64Func), diff --git a/src/arch/x86/process.cc b/src/arch/x86/process.cc index 82a23027d..13cbf6edd 100644 --- a/src/arch/x86/process.cc +++ b/src/arch/x86/process.cc @@ -80,6 +80,7 @@ static const int ArgumentReg32[] = { INTREG_EDX, INTREG_ESI, INTREG_EDI, + INTREG_EBP }; static const int NumArgumentRegs32 = sizeof(ArgumentReg) / sizeof(const int); diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index 34fbc6618..a859fbe43 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -1223,11 +1223,11 @@ writevFunc(SyscallDesc *desc, int callnum, LiveProcess *process, return result; } - -/// Target mmap() handler. +/// Real mmap handler. template SyscallReturn -mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) +mmapImpl(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc, + bool is_mmap2) { int index = 0; Addr start = p->getSyscallArg(tc, index); @@ -1237,9 +1237,8 @@ mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) int tgt_fd = p->getSyscallArg(tc, index); int offset = p->getSyscallArg(tc, index); - DPRINTF_SYSCALL(Verbose, "mmap(0x%x, len %d, prot %d, flags %d, fd %d, " - "offs %d)\n", start, length, prot, tgt_flags, tgt_fd, - offset); + if (is_mmap2) + offset *= TheISA::PageBytes; if (start & (TheISA::PageBytes - 1) || offset & (TheISA::PageBytes - 1) || @@ -1363,6 +1362,22 @@ mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) return start; } +/// Target mmap() handler. +template +SyscallReturn +mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) +{ + return mmapImpl(desc, num, p, tc, false); +} + +/// Target mmap2() handler. +template +SyscallReturn +mmap2Func(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc) +{ + return mmapImpl(desc, num, p, tc, true); +} + /// Target getrlimit() handler. template SyscallReturn -- 2.30.2