From dd8a7694806e3f816ba688d2094106db68b46b53 Mon Sep 17 00:00:00 2001 From: Brandon Potter Date: Tue, 28 Aug 2018 10:13:04 -0400 Subject: [PATCH] sim-se: change syscall function signature The system calls had four parameters. One of the parameters is ThreadContext and another is Process. The ThreadContext holds the value of the current process so the Process parameter is redundant since the system call functions already have indirect access. With the old API, it is possible to call into the functions with the wrong supplied Process which could end up being a confusing error. This patch removes the redundancy by forcing access through the ThreadContext field within each system call. Change-Id: Ib43d3f65824f6d425260dfd9f67de1892b6e8b7c Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/12299 Reviewed-by: Brandon Potter Maintainer: Brandon Potter Tested-by: kokoro --- src/arch/alpha/linux/process.cc | 12 +- src/arch/arm/freebsd/process.cc | 8 +- src/arch/arm/linux/process.cc | 16 +- src/arch/mips/linux/process.cc | 16 +- src/arch/power/linux/process.cc | 4 +- src/arch/riscv/linux/process.cc | 8 +- src/arch/sparc/linux/syscalls.cc | 7 +- src/arch/sparc/solaris/process.cc | 4 +- src/arch/x86/linux/process.cc | 13 +- src/gpu-compute/cl_driver.cc | 6 +- src/gpu-compute/cl_driver.hh | 4 +- src/sim/emul_driver.hh | 11 +- src/sim/process.cc | 2 +- src/sim/syscall_desc.cc | 6 +- src/sim/syscall_desc.hh | 7 +- src/sim/syscall_emul.cc | 235 ++++++++++-------- src/sim/syscall_emul.hh | 396 +++++++++++++----------------- 17 files changed, 372 insertions(+), 383 deletions(-) diff --git a/src/arch/alpha/linux/process.cc b/src/arch/alpha/linux/process.cc index cbf45f16c..de89410ac 100644 --- a/src/arch/alpha/linux/process.cc +++ b/src/arch/alpha/linux/process.cc @@ -77,10 +77,10 @@ AlphaLinuxObjectFileLoader loader; /// Target uname() handler. static SyscallReturn -unameFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +unameFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); TypedBufferArg name(process->getSyscallArg(tc, index)); strcpy(name->sysname, "Linux"); @@ -97,10 +97,10 @@ unameFunc(SyscallDesc *desc, int callnum, Process *process, /// borrowed from Tru64, the subcases that get used appear to be /// different in practice from those used by Tru64 processes. static SyscallReturn -osf_getsysinfoFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +osf_getsysinfoFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); unsigned op = process->getSyscallArg(tc, index); Addr bufPtr = process->getSyscallArg(tc, index); // unsigned nbytes = process->getSyscallArg(tc, 2); @@ -126,10 +126,10 @@ osf_getsysinfoFunc(SyscallDesc *desc, int callnum, Process *process, /// Target osf_setsysinfo() handler. static SyscallReturn -osf_setsysinfoFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +osf_setsysinfoFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); unsigned op = process->getSyscallArg(tc, index); Addr bufPtr = process->getSyscallArg(tc, index); // unsigned nbytes = process->getSyscallArg(tc, 2); diff --git a/src/arch/arm/freebsd/process.cc b/src/arch/arm/freebsd/process.cc index ba79eb18b..41549eaab 100644 --- a/src/arch/arm/freebsd/process.cc +++ b/src/arch/arm/freebsd/process.cc @@ -85,20 +85,18 @@ ArmFreebsdObjectFileLoader loader; } // anonymous namespace static SyscallReturn -issetugidFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +issetugidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { - return 0; } static SyscallReturn -sysctlFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +sysctlFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; uint64_t ret; + auto process = tc->getProcessPtr(); Addr namep = process->getSyscallArg(tc, index); size_t namelen = process->getSyscallArg(tc, index); Addr oldp = process->getSyscallArg(tc, index); diff --git a/src/arch/arm/linux/process.cc b/src/arch/arm/linux/process.cc index cd37c770a..1bb754870 100644 --- a/src/arch/arm/linux/process.cc +++ b/src/arch/arm/linux/process.cc @@ -105,10 +105,10 @@ ArmLinuxObjectFileLoader loader; /// Target uname() handler. static SyscallReturn -unameFunc32(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +unameFunc32(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); TypedBufferArg name(process->getSyscallArg(tc, index)); strcpy(name->sysname, "Linux"); @@ -123,10 +123,10 @@ unameFunc32(SyscallDesc *desc, int callnum, Process *process, /// Target uname() handler. static SyscallReturn -unameFunc64(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +unameFunc64(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); TypedBufferArg name(process->getSyscallArg(tc, index)); strcpy(name->sysname, "Linux"); @@ -141,10 +141,10 @@ unameFunc64(SyscallDesc *desc, int callnum, Process *process, /// Target set_tls() handler. static SyscallReturn -setTLSFunc32(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +setTLSFunc32(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); uint32_t tlsPtr = process->getSyscallArg(tc, index); tc->getMemProxy().writeBlob(ArmLinuxProcess32::commPage + 0x0ff0, @@ -154,10 +154,10 @@ setTLSFunc32(SyscallDesc *desc, int callnum, Process *process, } static SyscallReturn -setTLSFunc64(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +setTLSFunc64(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); uint32_t tlsPtr = process->getSyscallArg(tc, index); tc->setMiscReg(MISCREG_TPIDRRO_EL0, tlsPtr); diff --git a/src/arch/mips/linux/process.cc b/src/arch/mips/linux/process.cc index 71d20eaae..8a4811a04 100644 --- a/src/arch/mips/linux/process.cc +++ b/src/arch/mips/linux/process.cc @@ -80,10 +80,10 @@ MipsLinuxObjectFileLoader loader; /// Target uname() handler. static SyscallReturn -unameFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +unameFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); TypedBufferArg name(process->getSyscallArg(tc, index)); strcpy(name->sysname, "Linux"); @@ -100,10 +100,10 @@ unameFunc(SyscallDesc *desc, int callnum, Process *process, /// borrowed from Tru64, the subcases that get used appear to be /// different in practice from those used by Tru64 processes. static SyscallReturn -sys_getsysinfoFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +sys_getsysinfoFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); unsigned op = process->getSyscallArg(tc, index); unsigned bufPtr = process->getSyscallArg(tc, index); // unsigned nbytes = process->getSyscallArg(tc, index); @@ -129,10 +129,10 @@ sys_getsysinfoFunc(SyscallDesc *desc, int callnum, Process *process, /// Target sys_setsysinfo() handler. static SyscallReturn -sys_setsysinfoFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +sys_setsysinfoFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); unsigned op = process->getSyscallArg(tc, index); Addr bufPtr = process->getSyscallArg(tc, index); // unsigned nbytes = process->getSyscallArg(tc, index); @@ -159,10 +159,10 @@ sys_setsysinfoFunc(SyscallDesc *desc, int callnum, Process *process, } static SyscallReturn -setThreadAreaFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +setThreadAreaFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); Addr addr = process->getSyscallArg(tc, index); tc->setMiscRegNoEffect(MISCREG_TP_VALUE, addr); return 0; diff --git a/src/arch/power/linux/process.cc b/src/arch/power/linux/process.cc index ea0fc9021..58e7eb507 100644 --- a/src/arch/power/linux/process.cc +++ b/src/arch/power/linux/process.cc @@ -80,10 +80,10 @@ PowerLinuxObjectFileLoader loader; /// Target uname() handler. static SyscallReturn -unameFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +unameFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); TypedBufferArg name(process->getSyscallArg(tc, index)); strcpy(name->sysname, "Linux"); diff --git a/src/arch/riscv/linux/process.cc b/src/arch/riscv/linux/process.cc index b2d030523..f3f328e48 100644 --- a/src/arch/riscv/linux/process.cc +++ b/src/arch/riscv/linux/process.cc @@ -88,10 +88,10 @@ RiscvLinuxObjectFileLoader loader; /// Target uname() handler. static SyscallReturn -unameFunc64(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +unameFunc64(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); TypedBufferArg name(process->getSyscallArg(tc, index)); strcpy(name->sysname, "Linux"); @@ -106,10 +106,10 @@ unameFunc64(SyscallDesc *desc, int callnum, Process *process, /// Target uname() handler. static SyscallReturn -unameFunc32(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +unameFunc32(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); TypedBufferArg name(process->getSyscallArg(tc, index)); strcpy(name->sysname, "Linux"); diff --git a/src/arch/sparc/linux/syscalls.cc b/src/arch/sparc/linux/syscalls.cc index 773982a50..9cf08b7b3 100644 --- a/src/arch/sparc/linux/syscalls.cc +++ b/src/arch/sparc/linux/syscalls.cc @@ -39,10 +39,10 @@ namespace SparcISA { /// Target uname() handler. static SyscallReturn -unameFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +unameFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); TypedBufferArg name(process->getSyscallArg(tc, index)); strcpy(name->sysname, "Linux"); @@ -58,10 +58,11 @@ unameFunc(SyscallDesc *desc, int callnum, Process *process, SyscallReturn -getresuidFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +getresuidFunc(SyscallDesc *desc, int num, ThreadContext *tc) { const uint64_t id = htog(100); int index = 0; + auto p = tc->getProcessPtr(); Addr ruid = p->getSyscallArg(tc, index); Addr euid = p->getSyscallArg(tc, index); Addr suid = p->getSyscallArg(tc, index); diff --git a/src/arch/sparc/solaris/process.cc b/src/arch/sparc/solaris/process.cc index 70381c5d8..0b67f53d3 100644 --- a/src/arch/sparc/solaris/process.cc +++ b/src/arch/sparc/solaris/process.cc @@ -72,10 +72,10 @@ SparcSolarisObjectFileLoader loader; /// Target uname() handler. static SyscallReturn -unameFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +unameFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); TypedBufferArg name(process->getSyscallArg(tc, index)); strcpy(name->sysname, "SunOS"); diff --git a/src/arch/x86/linux/process.cc b/src/arch/x86/linux/process.cc index 95f4ee91d..98a68b409 100644 --- a/src/arch/x86/linux/process.cc +++ b/src/arch/x86/linux/process.cc @@ -91,10 +91,10 @@ X86LinuxObjectFileLoader loader; /// Target uname() handler. static SyscallReturn -unameFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +unameFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); TypedBufferArg name(process->getSyscallArg(tc, index)); strcpy(name->sysname, "Linux"); @@ -109,8 +109,7 @@ unameFunc(SyscallDesc *desc, int callnum, Process *process, } static SyscallReturn -archPrctlFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +archPrctlFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { enum ArchPrctlCodes { @@ -122,6 +121,7 @@ archPrctlFunc(SyscallDesc *desc, int callnum, Process *process, // First argument is the code, second is the address int index = 0; + auto process = tc->getProcessPtr(); int code = process->getSyscallArg(tc, index); uint64_t addr = process->getSyscallArg(tc, index); uint64_t fsBase, gsBase; @@ -175,13 +175,14 @@ struct UserDesc64 { }; static SyscallReturn -setThreadArea32Func(SyscallDesc *desc, int callnum, - Process *process, ThreadContext *tc) +setThreadArea32Func(SyscallDesc *desc, int callnum, ThreadContext *tc) { const int minTLSEntry = 6; const int numTLSEntries = 3; const int maxTLSEntry = minTLSEntry + numTLSEntries - 1; + auto process = tc->getProcessPtr(); + X86Process *x86p = dynamic_cast(process); assert(x86p); diff --git a/src/gpu-compute/cl_driver.cc b/src/gpu-compute/cl_driver.cc index 119091fc5..229734328 100644 --- a/src/gpu-compute/cl_driver.cc +++ b/src/gpu-compute/cl_driver.cc @@ -93,8 +93,9 @@ ClDriver::handshake(GpuDispatcher *_dispatcher) } int -ClDriver::open(Process *p, ThreadContext *tc, int mode, int flags) +ClDriver::open(ThreadContext *tc, int mode, int flags) { + auto p = tc->getProcessPtr(); std::shared_ptr fdp; fdp = std::make_shared(this, filename); int tgt_fd = p->fds->allocFD(fdp); @@ -102,9 +103,10 @@ ClDriver::open(Process *p, ThreadContext *tc, int mode, int flags) } int -ClDriver::ioctl(Process *process, ThreadContext *tc, unsigned req) +ClDriver::ioctl(ThreadContext *tc, unsigned req) { int index = 2; + auto process = tc->getProcessPtr(); Addr buf_addr = process->getSyscallArg(tc, index); switch (req) { diff --git a/src/gpu-compute/cl_driver.hh b/src/gpu-compute/cl_driver.hh index 595aa029a..5dbb27d84 100644 --- a/src/gpu-compute/cl_driver.hh +++ b/src/gpu-compute/cl_driver.hh @@ -53,8 +53,8 @@ class ClDriver final : public EmulatedDriver public: ClDriver(ClDriverParams *p); void handshake(GpuDispatcher *_dispatcher); - int open(Process *p, ThreadContext *tc, int mode, int flags); - int ioctl(Process *p, ThreadContext *tc, unsigned req); + int open(ThreadContext *tc, int mode, int flags); + int ioctl(ThreadContext *tc, unsigned req); const char* codeOffToKernelName(uint64_t code_ptr); private: diff --git a/src/sim/emul_driver.hh b/src/sim/emul_driver.hh index 97ba57224..fe13d9077 100644 --- a/src/sim/emul_driver.hh +++ b/src/sim/emul_driver.hh @@ -74,8 +74,7 @@ class EmulatedDriver : public SimObject * to openFunc() (q.v.). * @return A newly allocated target fd, or -1 on error. */ - virtual int open(Process *p, ThreadContext *tc, - int mode, int flags) = 0; + virtual int open(ThreadContext *tc, int mode, int flags) = 0; /** * Abstract method, invoked when the user program calls ioctl() on @@ -84,7 +83,7 @@ class EmulatedDriver : public SimObject * @return The return code for the ioctl, or the negation of the errno * (see the SyscallReturn class). */ - virtual int ioctl(Process *p, ThreadContext *tc, unsigned req) = 0; + virtual int ioctl(ThreadContext *tc, unsigned req) = 0; /** * Virtual method, invoked when the user program calls mmap() on @@ -93,9 +92,9 @@ class EmulatedDriver : public SimObject * @return The return ptr for the mmap, or the negation of the errno * (see the SyscallReturn class). */ - virtual Addr mmap(Process *p, ThreadContext *tc, Addr start, - uint64_t length, int prot, int tgtFlags, int tgtFd, - int offset) { return -EBADF; } + virtual Addr mmap(ThreadContext *tc, Addr start, uint64_t length, + int prot, int tgtFlags, int tgtFd, int offset) + { return -EBADF; } }; #endif // __SIM_EMUL_DRIVER_HH diff --git a/src/sim/process.cc b/src/sim/process.cc index 352c17926..90d0e5d55 100644 --- a/src/sim/process.cc +++ b/src/sim/process.cc @@ -395,7 +395,7 @@ Process::syscall(int64_t callnum, ThreadContext *tc, Fault *fault) if (desc == nullptr) fatal("Syscall %d out of range", callnum); - desc->doSyscall(callnum, this, tc, fault); + desc->doSyscall(callnum, tc, fault); } RegVal diff --git a/src/sim/syscall_desc.cc b/src/sim/syscall_desc.cc index 841998da5..fb39c11b2 100644 --- a/src/sim/syscall_desc.cc +++ b/src/sim/syscall_desc.cc @@ -46,10 +46,10 @@ #include "sim/syscall_return.hh" void -SyscallDesc::doSyscall(int callnum, Process *process, ThreadContext *tc, - Fault *fault) +SyscallDesc::doSyscall(int callnum, ThreadContext *tc, Fault *fault) { RegVal arg[6] M5_VAR_USED; + auto process = tc->getProcessPtr(); /** * Step through the first six parameters for the system call and @@ -69,7 +69,7 @@ SyscallDesc::doSyscall(int callnum, Process *process, ThreadContext *tc, _name, arg[0], arg[1], arg[2], arg[3], arg[4], arg[5]); /** Invoke the system call */ - SyscallReturn retval = (*executor)(this, callnum, process, tc); + SyscallReturn retval = (*executor)(this, callnum, tc); /** * If the system call needs to be restarted, most likely due to diff --git a/src/sim/syscall_desc.hh b/src/sim/syscall_desc.hh index 451db084b..0b226438a 100644 --- a/src/sim/syscall_desc.hh +++ b/src/sim/syscall_desc.hh @@ -56,7 +56,7 @@ class SyscallReturn; class ThreadContext; SyscallReturn unimplementedFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); + ThreadContext *tc); /** * This class provides the wrapper interface for the system call @@ -68,7 +68,7 @@ class SyscallDesc { public: /** Typedef the function pointer here to clean up code below */ typedef SyscallReturn (*SyscallExecutor)(SyscallDesc*, int num, - Process*, ThreadContext*); + ThreadContext*); SyscallDesc(const char *name, SyscallExecutor sys_exec=unimplementedFunc, int flags=0) @@ -98,8 +98,7 @@ class SyscallDesc { * @param proc Handle for the owning Process to pass information * @param tc Handle for owning ThreadContext to pass information */ - void doSyscall(int callnum, Process *proc, ThreadContext *tc, - Fault *fault); + void doSyscall(int callnum, ThreadContext *tc, Fault *fault); /** * Return false if WarnOnce is set and a warning has already been issued. diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc index ba84250de..442a28c41 100644 --- a/src/sim/syscall_emul.cc +++ b/src/sim/syscall_emul.cc @@ -64,8 +64,7 @@ warnUnsupportedOS(std::string syscall_name) } SyscallReturn -unimplementedFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +unimplementedFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { fatal("syscall %s (#%d) unimplemented.", desc->name(), callnum); @@ -74,8 +73,7 @@ unimplementedFunc(SyscallDesc *desc, int callnum, Process *process, SyscallReturn -ignoreFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +ignoreFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { if (desc->needWarning()) { warn("ignoring syscall %s(...)%s", desc->name(), desc->warnOnce() ? @@ -100,10 +98,10 @@ exitFutexWake(ThreadContext *tc, Addr addr, uint64_t tgid) } static SyscallReturn -exitImpl(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, - bool group) +exitImpl(SyscallDesc *desc, int callnum, ThreadContext *tc, bool group) { int index = 0; + auto p = tc->getProcessPtr(); int status = p->getSyscallArg(tc, index); System *sys = tc->getSystemPtr(); @@ -222,29 +220,30 @@ exitImpl(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, } SyscallReturn -exitFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +exitFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { - return exitImpl(desc, callnum, p, tc, false); + return exitImpl(desc, callnum, tc, false); } SyscallReturn -exitGroupFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +exitGroupFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { - return exitImpl(desc, callnum, p, tc, true); + return exitImpl(desc, callnum, tc, true); } SyscallReturn -getpagesizeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +getpagesizeFunc(SyscallDesc *desc, int num, ThreadContext *tc) { return (int)PageBytes; } SyscallReturn -brkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +brkFunc(SyscallDesc *desc, int num, ThreadContext *tc) { // change brk addr to first arg int index = 0; + auto p = tc->getProcessPtr(); Addr new_brk = p->getSyscallArg(tc, index); std::shared_ptr mem_state = p->memState; @@ -289,10 +288,10 @@ brkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -setTidAddressFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +setTidAddressFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); uint64_t tidPtr = process->getSyscallArg(tc, index); process->childClearTID = tidPtr; @@ -300,18 +299,20 @@ setTidAddressFunc(SyscallDesc *desc, int callnum, Process *process, } SyscallReturn -closeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +closeFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); return p->fds->closeFDEntry(tgt_fd); } SyscallReturn -lseekFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +lseekFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); uint64_t offs = p->getSyscallArg(tc, index); int whence = p->getSyscallArg(tc, index); @@ -328,9 +329,10 @@ lseekFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) SyscallReturn -_llseekFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +_llseekFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); uint64_t offset_high = p->getSyscallArg(tc, index); uint32_t offset_low = p->getSyscallArg(tc, index); @@ -358,7 +360,7 @@ _llseekFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) SyscallReturn -munmapFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +munmapFunc(SyscallDesc *desc, int num, ThreadContext *tc) { // With mmap more fully implemented, it might be worthwhile to bite // the bullet and implement munmap. Should allow us to reuse simulated @@ -370,9 +372,10 @@ munmapFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) const char *hostname = "m5.eecs.umich.edu"; SyscallReturn -gethostnameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +gethostnameFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); Addr buf_ptr = p->getSyscallArg(tc, index); int name_len = p->getSyscallArg(tc, index); BufferArg name(buf_ptr, name_len); @@ -385,10 +388,11 @@ gethostnameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -getcwdFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +getcwdFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int result = 0; int index = 0; + auto p = tc->getProcessPtr(); Addr buf_ptr = p->getSyscallArg(tc, index); unsigned long size = p->getSyscallArg(tc, index); BufferArg buf(buf_ptr, size); @@ -416,17 +420,16 @@ getcwdFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -readlinkFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +readlinkFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { - return readlinkFunc(desc, callnum, process, tc, 0); + return readlinkFunc(desc, callnum, tc, 0); } SyscallReturn -readlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, - int index) +readlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc, int index) { string path; + auto p = tc->getProcessPtr(); if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) return -EFAULT; @@ -483,16 +486,16 @@ readlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, } SyscallReturn -unlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +unlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc) { - return unlinkHelper(desc, num, p, tc, 0); + return unlinkHelper(desc, num, tc, 0); } SyscallReturn -unlinkHelper(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, - int index) +unlinkHelper(SyscallDesc *desc, int num, ThreadContext *tc, int index) { string path; + auto p = tc->getProcessPtr(); if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) return -EFAULT; @@ -504,10 +507,11 @@ unlinkHelper(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, } SyscallReturn -linkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +linkFunc(SyscallDesc *desc, int num, ThreadContext *tc) { string path; string new_path; + auto p = tc->getProcessPtr(); int index = 0; auto &virt_mem = tc->getMemProxy(); @@ -524,10 +528,11 @@ linkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -symlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +symlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc) { string path; string new_path; + auto p = tc->getProcessPtr(); int index = 0; auto &virt_mem = tc->getMemProxy(); @@ -544,8 +549,9 @@ symlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -mkdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +mkdirFunc(SyscallDesc *desc, int num, ThreadContext *tc) { + auto p = tc->getProcessPtr(); int index = 0; std::string path; if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) @@ -559,9 +565,10 @@ mkdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -renameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +renameFunc(SyscallDesc *desc, int num, ThreadContext *tc) { string old_name; + auto p = tc->getProcessPtr(); int index = 0; if (!tc->getMemProxy().tryReadString(old_name, p->getSyscallArg(tc, index))) @@ -581,9 +588,10 @@ renameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -truncateFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +truncateFunc(SyscallDesc *desc, int num, ThreadContext *tc) { string path; + auto p = tc->getProcessPtr(); int index = 0; if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) @@ -599,9 +607,10 @@ truncateFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -ftruncateFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +ftruncateFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); off_t length = p->getSyscallArg(tc, index); @@ -615,10 +624,10 @@ ftruncateFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -truncate64Func(SyscallDesc *desc, int num, - Process *process, ThreadContext *tc) +truncate64Func(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); string path; if (!tc->getMemProxy().tryReadString(path, process->getSyscallArg(tc, index))) @@ -638,9 +647,10 @@ truncate64Func(SyscallDesc *desc, int num, } SyscallReturn -ftruncate64Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +ftruncate64Func(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); int64_t length = p->getSyscallArg(tc, index, 64); @@ -658,7 +668,7 @@ ftruncate64Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -umaskFunc(SyscallDesc *desc, int num, Process *process, ThreadContext *tc) +umaskFunc(SyscallDesc *desc, int num, ThreadContext *tc) { // Letting the simulated program change the simulator's umask seems like // a bad idea. Compromise by just returning the current umask but not @@ -669,9 +679,10 @@ umaskFunc(SyscallDesc *desc, int num, Process *process, ThreadContext *tc) } SyscallReturn -chownFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +chownFunc(SyscallDesc *desc, int num, ThreadContext *tc) { string path; + auto p = tc->getProcessPtr(); int index = 0; if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) @@ -691,9 +702,10 @@ chownFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -fchownFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +fchownFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); auto ffdp = std::dynamic_pointer_cast((*p->fds)[tgt_fd]); @@ -718,9 +730,10 @@ fchownFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) * for the fd entries that we maintain for checkpoint restoration. */ SyscallReturn -dupFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +dupFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); auto old_hbfdp = std::dynamic_pointer_cast((*p->fds)[tgt_fd]); @@ -739,10 +752,10 @@ dupFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -dup2Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +dup2Func(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; - + auto p = tc->getProcessPtr(); int old_tgt_fd = p->getSyscallArg(tc, index); auto old_hbp = std::dynamic_pointer_cast((*p->fds)[old_tgt_fd]); if (!old_hbp) @@ -770,10 +783,11 @@ dup2Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -fcntlFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +fcntlFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int arg; int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); int cmd = p->getSyscallArg(tc, index); @@ -814,9 +828,10 @@ fcntlFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -fcntl64Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +fcntl64Func(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); auto hbfdp = std::dynamic_pointer_cast((*p->fds)[tgt_fd]); @@ -845,10 +860,10 @@ fcntl64Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -pipeImpl(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, - bool pseudoPipe) +pipeImpl(SyscallDesc *desc, int callnum, ThreadContext *tc, bool pseudoPipe) { int sim_fds[2], tgt_fds[2]; + auto p = tc->getProcessPtr(); int pipe_retval = pipe(sim_fds); if (pipe_retval == -1) @@ -893,23 +908,22 @@ pipeImpl(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, } SyscallReturn -pipePseudoFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +pipePseudoFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { - return pipeImpl(desc, callnum, process, tc, true); + return pipeImpl(desc, callnum, tc, true); } SyscallReturn -pipeFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc) +pipeFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { - return pipeImpl(desc, callnum, process, tc, false); + return pipeImpl(desc, callnum, tc, false); } SyscallReturn -setpgidFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +setpgidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); int pid = process->getSyscallArg(tc, index); int pgid = process->getSyscallArg(tc, index); @@ -942,105 +956,106 @@ setpgidFunc(SyscallDesc *desc, int callnum, Process *process, } SyscallReturn -getpidPseudoFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +getpidPseudoFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { // Make up a PID. There's no interprocess communication in // fake_syscall mode, so there's no way for a process to know it's // not getting a unique value. + auto process = tc->getProcessPtr(); tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); return process->pid(); } SyscallReturn -getuidPseudoFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +getuidPseudoFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { // Make up a UID and EUID... it shouldn't matter, and we want the // simulation to be deterministic. // EUID goes in r20. + auto process = tc->getProcessPtr(); tc->setIntReg(SyscallPseudoReturnReg, process->euid()); // EUID return process->uid(); // UID } SyscallReturn -getgidPseudoFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +getgidPseudoFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { // Get current group ID. EGID goes in r20. + auto process = tc->getProcessPtr(); tc->setIntReg(SyscallPseudoReturnReg, process->egid()); // EGID return process->gid(); } SyscallReturn -setuidFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +setuidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { // can't fathom why a benchmark would call this. int index = 0; + auto process = tc->getProcessPtr(); warn("Ignoring call to setuid(%d)\n", process->getSyscallArg(tc, index)); return 0; } SyscallReturn -getpidFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +getpidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { + auto process = tc->getProcessPtr(); return process->tgid(); } SyscallReturn -gettidFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +gettidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { + auto process = tc->getProcessPtr(); return process->pid(); } SyscallReturn -getppidFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +getppidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { + auto process = tc->getProcessPtr(); return process->ppid(); } SyscallReturn -getuidFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +getuidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { + auto process = tc->getProcessPtr(); return process->uid(); // UID } SyscallReturn -geteuidFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +geteuidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { + auto process = tc->getProcessPtr(); return process->euid(); // UID } SyscallReturn -getgidFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +getgidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { + auto process = tc->getProcessPtr(); return process->gid(); } SyscallReturn -getegidFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +getegidFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { + auto process = tc->getProcessPtr(); return process->egid(); } SyscallReturn -fallocateFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +fallocateFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { #if defined(__linux__) int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); int mode = p->getSyscallArg(tc, index); off_t offset = p->getSyscallArg(tc, index); @@ -1062,10 +1077,10 @@ fallocateFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) } SyscallReturn -accessFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, - int index) +accessFunc(SyscallDesc *desc, int callnum, ThreadContext *tc, int index) { string path; + auto p = tc->getProcessPtr(); if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) return -EFAULT; @@ -1079,14 +1094,15 @@ accessFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, } SyscallReturn -accessFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +accessFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { - return accessFunc(desc, callnum, p, tc, 0); + return accessFunc(desc, callnum, tc, 0); } SyscallReturn -mknodFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +mknodFunc(SyscallDesc *desc, int num, ThreadContext *tc) { + auto p = tc->getProcessPtr(); int index = 0; std::string path; if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) @@ -1101,8 +1117,9 @@ mknodFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -chdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +chdirFunc(SyscallDesc *desc, int num, ThreadContext *tc) { + auto p = tc->getProcessPtr(); int index = 0; std::string path; if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) @@ -1128,8 +1145,9 @@ chdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -rmdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +rmdirFunc(SyscallDesc *desc, int num, ThreadContext *tc) { + auto p = tc->getProcessPtr(); int index = 0; std::string path; if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index))) @@ -1144,9 +1162,10 @@ rmdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) #if defined(SYS_getdents) || defined(SYS_getdents64) template static SyscallReturn -getdentsImpl(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +getdentsImpl(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr buf_ptr = p->getSyscallArg(tc, index); unsigned count = p->getSyscallArg(tc, index); @@ -1187,7 +1206,7 @@ getdentsImpl(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) #if defined(SYS_getdents) SyscallReturn -getdentsFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +getdentsFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { typedef struct linux_dirent { unsigned long d_ino; @@ -1196,13 +1215,13 @@ getdentsFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) char dname[]; } LinDent; - return getdentsImpl(desc, callnum, p, tc); + return getdentsImpl(desc, callnum, tc); } #endif #if defined(SYS_getdents64) SyscallReturn -getdents64Func(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +getdents64Func(SyscallDesc *desc, int callnum, ThreadContext *tc) { typedef struct linux_dirent64 { ino64_t d_ino; @@ -1211,14 +1230,15 @@ getdents64Func(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) char dname[]; } LinDent64; - return getdentsImpl(desc, callnum, p, tc); + return getdentsImpl(desc, callnum, tc); } #endif SyscallReturn -shutdownFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +shutdownFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); int how = p->getSyscallArg(tc, index); @@ -1233,9 +1253,10 @@ shutdownFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -bindFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +bindFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr buf_ptr = p->getSyscallArg(tc, index); int addrlen = p->getSyscallArg(tc, index); @@ -1256,9 +1277,10 @@ bindFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -listenFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +listenFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); int backlog = p->getSyscallArg(tc, index); @@ -1273,9 +1295,10 @@ listenFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -connectFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +connectFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr buf_ptr = p->getSyscallArg(tc, index); int addrlen = p->getSyscallArg(tc, index); @@ -1296,9 +1319,10 @@ connectFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -recvfromFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +recvfromFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr bufrPtr = p->getSyscallArg(tc, index); size_t bufrLen = p->getSyscallArg(tc, index); @@ -1360,9 +1384,10 @@ recvfromFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -sendtoFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +sendtoFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr bufrPtr = p->getSyscallArg(tc, index); size_t bufrLen = p->getSyscallArg(tc, index); @@ -1396,9 +1421,10 @@ sendtoFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -recvmsgFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +recvmsgFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr msgPtr = p->getSyscallArg(tc, index); int flags = p->getSyscallArg(tc, index); @@ -1536,9 +1562,10 @@ recvmsgFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -sendmsgFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +sendmsgFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr msgPtr = p->getSyscallArg(tc, index); int flags = p->getSyscallArg(tc, index); @@ -1605,7 +1632,7 @@ sendmsgFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -getsockoptFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +getsockoptFunc(SyscallDesc *desc, int num, ThreadContext *tc) { // union of all possible return value types from getsockopt union val { @@ -1616,6 +1643,7 @@ getsockoptFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } val; int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); int level = p->getSyscallArg(tc, index); int optname = p->getSyscallArg(tc, index); @@ -1647,9 +1675,10 @@ getsockoptFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -getsocknameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +getsocknameFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr addrPtr = p->getSyscallArg(tc, index); Addr lenPtr = p->getSyscallArg(tc, index); @@ -1686,9 +1715,10 @@ getsocknameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -getpeernameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +getpeernameFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr sockAddrPtr = p->getSyscallArg(tc, index); Addr addrlenPtr = p->getSyscallArg(tc, index); @@ -1715,9 +1745,10 @@ getpeernameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) } SyscallReturn -setsockoptFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +setsockoptFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); int level = p->getSyscallArg(tc, index); int optname = p->getSyscallArg(tc, index); diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index 92fb8bf3e..2230b62c0 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -123,276 +123,215 @@ void warnUnsupportedOS(std::string syscall_name); /// Handler for unimplemented syscalls that we haven't thought about. -SyscallReturn unimplementedFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn unimplementedFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Handler for unimplemented syscalls that we never intend to /// implement (signal handling, etc.) and should not affect the correct /// behavior of the program. Print a warning only if the appropriate /// trace flag is enabled. Return success to the target program. -SyscallReturn ignoreFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn ignoreFunc(SyscallDesc *desc, int num, ThreadContext *tc); // Target fallocateFunc() handler. -SyscallReturn fallocateFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn fallocateFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target exit() handler: terminate current context. -SyscallReturn exitFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn exitFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target exit_group() handler: terminate simulation. (exit all threads) -SyscallReturn exitGroupFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn exitGroupFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target set_tid_address() handler. -SyscallReturn setTidAddressFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn setTidAddressFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target getpagesize() handler. -SyscallReturn getpagesizeFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getpagesizeFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target brk() handler: set brk address. -SyscallReturn brkFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn brkFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target close() handler. -SyscallReturn closeFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn closeFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target lseek() handler. -SyscallReturn lseekFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn lseekFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target _llseek() handler. -SyscallReturn _llseekFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn _llseekFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target munmap() handler. -SyscallReturn munmapFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn munmapFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target shutdown() handler. -SyscallReturn shutdownFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn shutdownFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target gethostname() handler. -SyscallReturn gethostnameFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn gethostnameFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target getcwd() handler. -SyscallReturn getcwdFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getcwdFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target readlink() handler. -SyscallReturn readlinkFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc, +SyscallReturn readlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc, int index = 0); -SyscallReturn readlinkFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn readlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target unlink() handler. -SyscallReturn unlinkHelper(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc, +SyscallReturn unlinkHelper(SyscallDesc *desc, int num, ThreadContext *tc, int index); -SyscallReturn unlinkFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn unlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target link() handler -SyscallReturn linkFunc(SyscallDesc *desc, int num, Process *p, - ThreadContext *tc); +SyscallReturn linkFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target symlink() handler. -SyscallReturn symlinkFunc(SyscallDesc *desc, int num, Process *p, - ThreadContext *tc); +SyscallReturn symlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target mkdir() handler. -SyscallReturn mkdirFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn mkdirFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target mknod() handler. -SyscallReturn mknodFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn mknodFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target chdir() handler. -SyscallReturn chdirFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn chdirFunc(SyscallDesc *desc, int num, ThreadContext *tc); // Target rmdir() handler. -SyscallReturn rmdirFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn rmdirFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target rename() handler. -SyscallReturn renameFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn renameFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target truncate() handler. -SyscallReturn truncateFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn truncateFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target ftruncate() handler. -SyscallReturn ftruncateFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn ftruncateFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target truncate64() handler. -SyscallReturn truncate64Func(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn truncate64Func(SyscallDesc *desc, int num, ThreadContext *tc); /// Target ftruncate64() handler. -SyscallReturn ftruncate64Func(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn ftruncate64Func(SyscallDesc *desc, int num, ThreadContext *tc); /// Target umask() handler. -SyscallReturn umaskFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn umaskFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target gettid() handler. -SyscallReturn gettidFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn gettidFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target chown() handler. -SyscallReturn chownFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn chownFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target setpgid() handler. -SyscallReturn setpgidFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn setpgidFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target fchown() handler. -SyscallReturn fchownFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn fchownFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target dup() handler. -SyscallReturn dupFunc(SyscallDesc *desc, int num, - Process *process, ThreadContext *tc); +SyscallReturn dupFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target dup2() handler. -SyscallReturn dup2Func(SyscallDesc *desc, int num, - Process *process, ThreadContext *tc); +SyscallReturn dup2Func(SyscallDesc *desc, int num, ThreadContext *tc); /// Target fcntl() handler. -SyscallReturn fcntlFunc(SyscallDesc *desc, int num, - Process *process, ThreadContext *tc); +SyscallReturn fcntlFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target fcntl64() handler. -SyscallReturn fcntl64Func(SyscallDesc *desc, int num, - Process *process, ThreadContext *tc); +SyscallReturn fcntl64Func(SyscallDesc *desc, int num, ThreadContext *tc); /// Target setuid() handler. -SyscallReturn setuidFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn setuidFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target pipe() handler. -SyscallReturn pipeFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn pipeFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Internal pipe() handler. -SyscallReturn pipeImpl(SyscallDesc *desc, int num, Process *p, - ThreadContext *tc, bool pseudoPipe); +SyscallReturn pipeImpl(SyscallDesc *desc, int num, ThreadContext *tc, + bool pseudoPipe); /// Target getpid() handler. -SyscallReturn getpidFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getpidFunc(SyscallDesc *desc, int num, ThreadContext *tc); // Target getpeername() handler. -SyscallReturn getpeernameFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getpeernameFunc(SyscallDesc *desc, int num, ThreadContext *tc); // Target bind() handler. -SyscallReturn bindFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn bindFunc(SyscallDesc *desc, int num, ThreadContext *tc); // Target listen() handler. -SyscallReturn listenFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn listenFunc(SyscallDesc *desc, int num, ThreadContext *tc); // Target connect() handler. -SyscallReturn connectFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn connectFunc(SyscallDesc *desc, int num, ThreadContext *tc); #if defined(SYS_getdents) // Target getdents() handler. -SyscallReturn getdentsFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getdentsFunc(SyscallDesc *desc, int num, ThreadContext *tc); #endif #if defined(SYS_getdents64) // Target getdents() handler. -SyscallReturn getdents64Func(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getdents64Func(SyscallDesc *desc, int num, ThreadContext *tc); #endif // Target sendto() handler. -SyscallReturn sendtoFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn sendtoFunc(SyscallDesc *desc, int num, ThreadContext *tc); // Target recvfrom() handler. -SyscallReturn recvfromFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn recvfromFunc(SyscallDesc *desc, int num, ThreadContext *tc); // Target recvmsg() handler. -SyscallReturn recvmsgFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn recvmsgFunc(SyscallDesc *desc, int num, ThreadContext *tc); // Target sendmsg() handler. -SyscallReturn sendmsgFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn sendmsgFunc(SyscallDesc *desc, int num, ThreadContext *tc); // Target getuid() handler. -SyscallReturn getuidFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getuidFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target getgid() handler. -SyscallReturn getgidFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getgidFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target getppid() handler. -SyscallReturn getppidFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getppidFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target geteuid() handler. -SyscallReturn geteuidFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn geteuidFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target getegid() handler. -SyscallReturn getegidFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getegidFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target access() handler -SyscallReturn accessFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); -SyscallReturn accessFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc, +SyscallReturn accessFunc(SyscallDesc *desc, int num, ThreadContext *tc); +SyscallReturn accessFunc(SyscallDesc *desc, int num, ThreadContext *tc, int index); // Target getsockopt() handler. -SyscallReturn getsockoptFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getsockoptFunc(SyscallDesc *desc, int num, ThreadContext *tc); // Target setsockopt() handler. -SyscallReturn setsockoptFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn setsockoptFunc(SyscallDesc *desc, int num, ThreadContext *tc); // Target getsockname() handler. -SyscallReturn getsocknameFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getsocknameFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Futex system call /// Implemented by Daniel Sanchez /// Used by printf's in multi-threaded apps template SyscallReturn -futexFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +futexFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { using namespace std; int index = 0; + auto process = tc->getProcessPtr(); + Addr uaddr = process->getSyscallArg(tc, index); int op = process->getSyscallArg(tc, index); int val = process->getSyscallArg(tc, index); @@ -527,20 +466,16 @@ futexFunc(SyscallDesc *desc, int callnum, Process *process, /// Pseudo Funcs - These functions use a different return convension, /// returning a second value in a register other than the normal return register -SyscallReturn pipePseudoFunc(SyscallDesc *desc, int num, - Process *process, ThreadContext *tc); +SyscallReturn pipePseudoFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target getpidPseudo() handler. -SyscallReturn getpidPseudoFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getpidPseudoFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target getuidPseudo() handler. -SyscallReturn getuidPseudoFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getuidPseudoFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// Target getgidPseudo() handler. -SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num, - Process *p, ThreadContext *tc); +SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num, ThreadContext *tc); /// A readable name for 1,000,000, for converting microseconds to seconds. @@ -736,9 +671,11 @@ copyOutStatfsBuf(SETranslatingPortProxy &mem, Addr addr, /// not TTYs to provide repeatable results. template SyscallReturn -ioctlFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +ioctlFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); + int tgt_fd = p->getSyscallArg(tc, index); unsigned req = p->getSyscallArg(tc, index); @@ -751,7 +688,7 @@ ioctlFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) if (dfdp) { EmulatedDriver *emul_driver = dfdp->getDriver(); if (emul_driver) - return emul_driver->ioctl(p, tc, req); + return emul_driver->ioctl(tc, req); } auto sfdp = std::dynamic_pointer_cast((*p->fds)[tgt_fd]); @@ -813,10 +750,10 @@ ioctlFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) template SyscallReturn -openImpl(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, - bool isopenat) +openImpl(SyscallDesc *desc, int callnum, ThreadContext *tc, bool isopenat) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_dirfd = -1; /** @@ -899,7 +836,7 @@ openImpl(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, DPRINTF_SYSCALL(Verbose, "open%s: passing call to " "driver open with path[%s]\n", isopenat ? "at" : "", abs_path.c_str()); - return drv->open(p, tc, mode, host_flags); + return drv->open(tc, mode, host_flags); } /** * Fall through here for pass through to host devices, such @@ -972,68 +909,66 @@ openImpl(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, /// Target open() handler. template SyscallReturn -openFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +openFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { - return openImpl(desc, callnum, process, tc, false); + return openImpl(desc, callnum, tc, false); } /// Target openat() handler. template SyscallReturn -openatFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +openatFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { - return openImpl(desc, callnum, process, tc, true); + return openImpl(desc, callnum, tc, true); } /// Target unlinkat() handler. template SyscallReturn -unlinkatFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +unlinkatFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); int dirfd = process->getSyscallArg(tc, index); if (dirfd != OS::TGT_AT_FDCWD) warn("unlinkat: first argument not AT_FDCWD; unlikely to work"); - return unlinkHelper(desc, callnum, process, tc, 1); + return unlinkHelper(desc, callnum, tc, 1); } /// Target facessat() handler template SyscallReturn -faccessatFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +faccessatFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); int dirfd = process->getSyscallArg(tc, index); if (dirfd != OS::TGT_AT_FDCWD) warn("faccessat: first argument not AT_FDCWD; unlikely to work"); - return accessFunc(desc, callnum, process, tc, 1); + return accessFunc(desc, callnum, tc, 1); } /// Target readlinkat() handler template SyscallReturn -readlinkatFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +readlinkatFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); int dirfd = process->getSyscallArg(tc, index); if (dirfd != OS::TGT_AT_FDCWD) warn("openat: first argument not AT_FDCWD; unlikely to work"); - return readlinkFunc(desc, callnum, process, tc, 1); + return readlinkFunc(desc, callnum, tc, 1); } /// Target renameat() handler. template SyscallReturn -renameatFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +renameatFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); int olddirfd = process->getSyscallArg(tc, index); if (olddirfd != OS::TGT_AT_FDCWD) @@ -1066,11 +1001,11 @@ renameatFunc(SyscallDesc *desc, int callnum, Process *process, /// Target sysinfo() handler. template SyscallReturn -sysinfoFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +sysinfoFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { - int index = 0; + auto process = tc->getProcessPtr(); + TypedBufferArg sysinfo(process->getSyscallArg(tc, index)); @@ -1086,10 +1021,10 @@ sysinfoFunc(SyscallDesc *desc, int callnum, Process *process, /// Target chmod() handler. template SyscallReturn -chmodFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +chmodFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { std::string path; + auto process = tc->getProcessPtr(); int index = 0; if (!tc->getMemProxy().tryReadString(path, @@ -1116,9 +1051,10 @@ chmodFunc(SyscallDesc *desc, int callnum, Process *process, template SyscallReturn -pollFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +pollFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); Addr fdsPtr = p->getSyscallArg(tc, index); int nfds = p->getSyscallArg(tc, index); int tmout = p->getSyscallArg(tc, index); @@ -1192,9 +1128,10 @@ pollFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) /// Target fchmod() handler. template SyscallReturn -fchmodFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +fchmodFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); uint32_t mode = p->getSyscallArg(tc, index); @@ -1213,9 +1150,10 @@ fchmodFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) /// Target mremap() handler. template SyscallReturn -mremapFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc) +mremapFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); Addr start = process->getSyscallArg(tc, index); uint64_t old_length = process->getSyscallArg(tc, index); uint64_t new_length = process->getSyscallArg(tc, index); @@ -1292,10 +1230,10 @@ mremapFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc) /// Target stat() handler. template SyscallReturn -statFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +statFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { std::string path; + auto process = tc->getProcessPtr(); int index = 0; if (!tc->getMemProxy().tryReadString(path, @@ -1322,10 +1260,10 @@ statFunc(SyscallDesc *desc, int callnum, Process *process, /// Target stat64() handler. template SyscallReturn -stat64Func(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +stat64Func(SyscallDesc *desc, int callnum, ThreadContext *tc) { std::string path; + auto process = tc->getProcessPtr(); int index = 0; if (!tc->getMemProxy().tryReadString(path, @@ -1356,10 +1294,10 @@ stat64Func(SyscallDesc *desc, int callnum, Process *process, /// Target fstatat64() handler. template SyscallReturn -fstatat64Func(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +fstatat64Func(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); int dirfd = process->getSyscallArg(tc, index); if (dirfd != OS::TGT_AT_FDCWD) warn("fstatat64: first argument not AT_FDCWD; unlikely to work"); @@ -1393,9 +1331,10 @@ fstatat64Func(SyscallDesc *desc, int callnum, Process *process, /// Target fstat64() handler. template SyscallReturn -fstat64Func(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +fstat64Func(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr bufPtr = p->getSyscallArg(tc, index); @@ -1424,10 +1363,10 @@ fstat64Func(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) /// Target lstat() handler. template SyscallReturn -lstatFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +lstatFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { std::string path; + auto process = tc->getProcessPtr(); int index = 0; if (!tc->getMemProxy().tryReadString(path, @@ -1453,10 +1392,10 @@ lstatFunc(SyscallDesc *desc, int callnum, Process *process, /// Target lstat64() handler. template SyscallReturn -lstat64Func(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +lstat64Func(SyscallDesc *desc, int callnum, ThreadContext *tc) { std::string path; + auto process = tc->getProcessPtr(); int index = 0; if (!tc->getMemProxy().tryReadString(path, @@ -1487,9 +1426,10 @@ lstat64Func(SyscallDesc *desc, int callnum, Process *process, /// Target fstat() handler. template SyscallReturn -fstatFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +fstatFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr bufPtr = p->getSyscallArg(tc, index); @@ -1514,11 +1454,11 @@ fstatFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) /// Target statfs() handler. template SyscallReturn -statfsFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +statfsFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { #if defined(__linux__) std::string path; + auto process = tc->getProcessPtr(); int index = 0; if (!tc->getMemProxy().tryReadString(path, @@ -1546,10 +1486,11 @@ statfsFunc(SyscallDesc *desc, int callnum, Process *process, template SyscallReturn -cloneFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +cloneFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); RegVal flags = p->getSyscallArg(tc, index); RegVal newStack = p->getSyscallArg(tc, index); Addr ptidPtr = p->getSyscallArg(tc, index); @@ -1685,9 +1626,10 @@ cloneFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) /// Target fstatfs() handler. template SyscallReturn -fstatfsFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +fstatfsFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr bufPtr = p->getSyscallArg(tc, index); @@ -1710,9 +1652,10 @@ fstatfsFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) /// Target readv() handler. template SyscallReturn -readvFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +readvFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); auto ffdp = std::dynamic_pointer_cast((*p->fds)[tgt_fd]); @@ -1749,9 +1692,10 @@ readvFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) /// Target writev() handler. template SyscallReturn -writevFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +writevFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); auto hbfdp = std::dynamic_pointer_cast((*p->fds)[tgt_fd]); @@ -1785,10 +1729,10 @@ writevFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) /// Real mmap handler. template SyscallReturn -mmapImpl(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, - bool is_mmap2) +mmapImpl(SyscallDesc *desc, int num, ThreadContext *tc, bool is_mmap2) { int index = 0; + auto p = tc->getProcessPtr(); Addr start = p->getSyscallArg(tc, index); uint64_t length = p->getSyscallArg(tc, index); int prot = p->getSyscallArg(tc, index); @@ -1845,8 +1789,8 @@ mmapImpl(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, auto dfdp = std::dynamic_pointer_cast(fdep); if (dfdp) { EmulatedDriver *emul_driver = dfdp->getDriver(); - return emul_driver->mmap(p, tc, start, length, prot, - tgt_flags, tgt_fd, offset); + return emul_driver->mmap(tc, start, length, prot, tgt_flags, + tgt_fd, offset); } auto ffdp = std::dynamic_pointer_cast(fdep); @@ -1963,9 +1907,10 @@ mmapImpl(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, template SyscallReturn -pwrite64Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +pwrite64Func(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr bufPtr = p->getSyscallArg(tc, index); int nbytes = p->getSyscallArg(tc, index); @@ -1987,26 +1932,26 @@ pwrite64Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) /// Target mmap() handler. template SyscallReturn -mmapFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +mmapFunc(SyscallDesc *desc, int num, ThreadContext *tc) { - return mmapImpl(desc, num, p, tc, false); + return mmapImpl(desc, num, tc, false); } /// Target mmap2() handler. template SyscallReturn -mmap2Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +mmap2Func(SyscallDesc *desc, int num, ThreadContext *tc) { - return mmapImpl(desc, num, p, tc, true); + return mmapImpl(desc, num, tc, true); } /// Target getrlimit() handler. template SyscallReturn -getrlimitFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +getrlimitFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); unsigned resource = process->getSyscallArg(tc, index); TypedBufferArg rlp(process->getSyscallArg(tc, index)); @@ -2037,10 +1982,10 @@ getrlimitFunc(SyscallDesc *desc, int callnum, Process *process, template SyscallReturn -prlimitFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +prlimitFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); if (process->getSyscallArg(tc, index) != 0) { warn("prlimit: ignoring rlimits for nonzero pid"); @@ -2080,9 +2025,10 @@ prlimitFunc(SyscallDesc *desc, int callnum, Process *process, /// Target clock_gettime() function. template SyscallReturn -clock_gettimeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +clock_gettimeFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 1; + auto p = tc->getProcessPtr(); //int clk_id = p->getSyscallArg(tc, index); TypedBufferArg tp(p->getSyscallArg(tc, index)); @@ -2099,9 +2045,10 @@ clock_gettimeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) /// Target clock_getres() function. template SyscallReturn -clock_getresFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +clock_getresFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 1; + auto p = tc->getProcessPtr(); TypedBufferArg tp(p->getSyscallArg(tc, index)); // Set resolution at ns, which is what clock_gettime() returns @@ -2116,10 +2063,10 @@ clock_getresFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) /// Target gettimeofday() handler. template SyscallReturn -gettimeofdayFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +gettimeofdayFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); TypedBufferArg tp(process->getSyscallArg(tc, index)); getElapsedTimeMicro(tp->tv_sec, tp->tv_usec); @@ -2136,10 +2083,10 @@ gettimeofdayFunc(SyscallDesc *desc, int callnum, Process *process, /// Target utimes() handler. template SyscallReturn -utimesFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +utimesFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { std::string path; + auto process = tc->getProcessPtr(); int index = 0; if (!tc->getMemProxy().tryReadString(path, @@ -2170,9 +2117,10 @@ utimesFunc(SyscallDesc *desc, int callnum, Process *process, template SyscallReturn -execveFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +execveFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { desc->setFlags(0); + auto p = tc->getProcessPtr(); int index = 0; std::string path; @@ -2263,10 +2211,10 @@ execveFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) /// Target getrusage() function. template SyscallReturn -getrusageFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +getrusageFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); int who = process->getSyscallArg(tc, index); // THREAD, SELF, or CHILDREN TypedBufferArg rup(process->getSyscallArg(tc, index)); @@ -2315,10 +2263,10 @@ getrusageFunc(SyscallDesc *desc, int callnum, Process *process, /// Target times() function. template SyscallReturn -timesFunc(SyscallDesc *desc, int callnum, Process *process, - ThreadContext *tc) +timesFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); TypedBufferArg bufp(process->getSyscallArg(tc, index)); // Fill in the time structure (in clocks) @@ -2341,13 +2289,14 @@ timesFunc(SyscallDesc *desc, int callnum, Process *process, /// Target time() function. template SyscallReturn -timeFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc) +timeFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { typename OS::time_t sec, usec; getElapsedTimeMicro(sec, usec); sec += seconds_since_epoch; int index = 0; + auto process = tc->getProcessPtr(); Addr taddr = (Addr)process->getSyscallArg(tc, index); if (taddr != 0) { typename OS::time_t t = sec; @@ -2360,9 +2309,10 @@ timeFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc) template SyscallReturn -tgkillFunc(SyscallDesc *desc, int num, Process *process, ThreadContext *tc) +tgkillFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto process = tc->getProcessPtr(); int tgid = process->getSyscallArg(tc, index); int tid = process->getSyscallArg(tc, index); int sig = process->getSyscallArg(tc, index); @@ -2402,16 +2352,17 @@ tgkillFunc(SyscallDesc *desc, int num, Process *process, ThreadContext *tc) return -ESRCH; if (sig == OS::TGT_SIGABRT) - exitGroupFunc(desc, 252, process, tc); + exitGroupFunc(desc, 252, tc); return 0; } template SyscallReturn -socketFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +socketFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int domain = p->getSyscallArg(tc, index); int type = p->getSyscallArg(tc, index); int prot = p->getSyscallArg(tc, index); @@ -2428,9 +2379,10 @@ socketFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) template SyscallReturn -socketpairFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +socketpairFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int domain = p->getSyscallArg(tc, index); int type = p->getSyscallArg(tc, index); int prot = p->getSyscallArg(tc, index); @@ -2454,11 +2406,12 @@ socketpairFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) template SyscallReturn -selectFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +selectFunc(SyscallDesc *desc, int callnum, ThreadContext *tc) { int retval; int index = 0; + auto p = tc->getProcessPtr(); int nfds_t = p->getSyscallArg(tc, index); Addr fds_read_ptr = p->getSyscallArg(tc, index); Addr fds_writ_ptr = p->getSyscallArg(tc, index); @@ -2649,9 +2602,10 @@ selectFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) template SyscallReturn -readFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +readFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr buf_ptr = p->getSyscallArg(tc, index); int nbytes = p->getSyscallArg(tc, index); @@ -2679,9 +2633,10 @@ readFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) template SyscallReturn -writeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +writeFunc(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr buf_ptr = p->getSyscallArg(tc, index); int nbytes = p->getSyscallArg(tc, index); @@ -2720,9 +2675,10 @@ writeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) template SyscallReturn -wait4Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +wait4Func(SyscallDesc *desc, int num, ThreadContext *tc) { int index = 0; + auto p = tc->getProcessPtr(); pid_t pid = p->getSyscallArg(tc, index); Addr statPtr = p->getSyscallArg(tc, index); int options = p->getSyscallArg(tc, index); @@ -2781,12 +2737,13 @@ success: template SyscallReturn -acceptFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +acceptFunc(SyscallDesc *desc, int num, ThreadContext *tc) { struct sockaddr sa; socklen_t addrLen; int host_fd; int index = 0; + auto p = tc->getProcessPtr(); int tgt_fd = p->getSyscallArg(tc, index); Addr addrPtr = p->getSyscallArg(tc, index); Addr lenPtr = p->getSyscallArg(tc, index); @@ -2851,10 +2808,11 @@ acceptFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) /// Target eventfd() function. template SyscallReturn -eventfdFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +eventfdFunc(SyscallDesc *desc, int num, ThreadContext *tc) { #if defined(__linux__) int index = 0; + auto p = tc->getProcessPtr(); unsigned initval = p->getSyscallArg(tc, index); int in_flags = p->getSyscallArg(tc, index); -- 2.30.2