sim: Use variadic GuestABI arguments in a few additional syscalls.
authorGabe Black <gabeblack@google.com>
Thu, 28 Nov 2019 06:53:47 +0000 (22:53 -0800)
committerGabe Black <gabeblack@google.com>
Thu, 12 Mar 2020 00:43:28 +0000 (00:43 +0000)
Jira Issue: https://gem5.atlassian.net/browse/GEM5-187

Change-Id: Ib2f193e7409859469c853e11f121eba82b3c0ddc
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23196
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
src/sim/syscall_emul.cc
src/sim/syscall_emul.hh

index 4e69d76c81af92d37180e134296d8d262fd6afa5..4084009bab6ec953407d7c02b831001ae3464a3a 100644 (file)
@@ -740,13 +740,10 @@ dup2Func(SyscallDesc *desc, int num, ThreadContext *tc,
 }
 
 SyscallReturn
-fcntlFunc(SyscallDesc *desc, int num, ThreadContext *tc)
+fcntlFunc(SyscallDesc *desc, int num, ThreadContext *tc,
+          int tgt_fd, int cmd, GuestABI::VarArgs<int> varargs)
 {
-    int arg;
-    int index = 0;
     auto p = tc->getProcessPtr();
-    int tgt_fd = p->getSyscallArg(tc, index);
-    int cmd = p->getSyscallArg(tc, index);
 
     auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*p->fds)[tgt_fd]);
     if (!hbfdp)
@@ -760,7 +757,7 @@ fcntlFunc(SyscallDesc *desc, int num, ThreadContext *tc)
         return coe & FD_CLOEXEC;
 
       case F_SETFD: {
-        arg = p->getSyscallArg(tc, index);
+        int arg = varargs.get<int>();
         arg ? hbfdp->setCOE(true) : hbfdp->setCOE(false);
         return 0;
       }
@@ -773,7 +770,7 @@ fcntlFunc(SyscallDesc *desc, int num, ThreadContext *tc)
       // subsequent fcntls.
       case F_GETFL:
       case F_SETFL: {
-        arg = p->getSyscallArg(tc, index);
+        int arg = varargs.get<int>();
         int rv = fcntl(sim_fd, cmd, arg);
         return (rv == -1) ? -errno : rv;
       }
@@ -785,18 +782,16 @@ fcntlFunc(SyscallDesc *desc, int num, ThreadContext *tc)
 }
 
 SyscallReturn
-fcntl64Func(SyscallDesc *desc, int num, ThreadContext *tc)
+fcntl64Func(SyscallDesc *desc, int num, ThreadContext *tc,
+            int tgt_fd, int cmd)
 {
-    int index = 0;
     auto p = tc->getProcessPtr();
-    int tgt_fd = p->getSyscallArg(tc, index);
 
     auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*p->fds)[tgt_fd]);
     if (!hbfdp)
         return -EBADF;
     int sim_fd = hbfdp->getSimFD();
 
-    int cmd = p->getSyscallArg(tc, index);
     switch (cmd) {
       case 33: //F_GETLK64
         warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", tgt_fd);
index a6f04097f89168ff5a8e2e432f43b9f3fda3746f..5a4811fb2c40737ccbb1e36451499f616bd22148 100644 (file)
@@ -99,6 +99,7 @@
 #include "params/Process.hh"
 #include "sim/emul_driver.hh"
 #include "sim/futex_map.hh"
+#include "sim/guest_abi.hh"
 #include "sim/process.hh"
 #include "sim/syscall_debug_macros.hh"
 #include "sim/syscall_desc.hh"
@@ -267,10 +268,12 @@ SyscallReturn dup2Func(SyscallDesc *desc, int num, ThreadContext *tc,
                        int old_tgt_fd, int new_tgt_fd);
 
 /// Target fcntl() handler.
-SyscallReturn fcntlFunc(SyscallDesc *desc, int num, ThreadContext *tc);
+SyscallReturn fcntlFunc(SyscallDesc *desc, int num, ThreadContext *tc,
+                        int tgt_fd, int cmd, GuestABI::VarArgs<int> varargs);
 
 /// Target fcntl64() handler.
-SyscallReturn fcntl64Func(SyscallDesc *desc, int num, ThreadContext *tc);
+SyscallReturn fcntl64Func(SyscallDesc *desc, int num, ThreadContext *tc,
+                          int tgt_fd, int cmd);
 
 /// Target pipe() handler.
 SyscallReturn pipeFunc(SyscallDesc *desc, int num, ThreadContext *tc);
@@ -709,14 +712,11 @@ copyOutStatfsBuf(PortProxy &mem, Addr addr,
 /// not TTYs to provide repeatable results.
 template <class OS>
 SyscallReturn
-ioctlFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
+ioctlFunc(SyscallDesc *desc, int callnum, ThreadContext *tc,
+        int tgt_fd, unsigned req, GuestABI::VarArgs<Addr> varargs)
 {
-    int index = 0;
     auto p = tc->getProcessPtr();
 
-    int tgt_fd = p->getSyscallArg(tc, index);
-    unsigned req = p->getSyscallArg(tc, index);
-
     DPRINTF_SYSCALL(Verbose, "ioctl(%d, 0x%x, ...)\n", tgt_fd, req);
 
     if (OS::isTtyReq(req))
@@ -735,7 +735,7 @@ ioctlFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
 
         switch (req) {
           case SIOCGIFCONF: {
-            Addr conf_addr = p->getSyscallArg(tc, index);
+            Addr conf_addr = varargs.get<Addr>();
             BufferArg conf_arg(conf_addr, sizeof(ifconf));
             conf_arg.copyIn(tc->getVirtProxy());
 
@@ -765,7 +765,7 @@ ioctlFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
           case SIOCGIFHWADDR:
 #endif
           case SIOCGIFMTU: {
-            Addr req_addr = p->getSyscallArg(tc, index);
+            Addr req_addr = varargs.get<Addr>();
             BufferArg req_arg(req_addr, sizeof(ifreq));
             req_arg.copyIn(tc->getVirtProxy());
 
@@ -1134,19 +1134,16 @@ fchmodFunc(SyscallDesc *desc, int callnum, ThreadContext *tc,
 /// Target mremap() handler.
 template <class OS>
 SyscallReturn
-mremapFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
+mremapFunc(SyscallDesc *desc, int callnum, ThreadContext *tc,
+        Addr start, uint64_t old_length, uint64_t new_length, uint64_t flags,
+        GuestABI::VarArgs<uint64_t> varargs)
 {
-    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);
-    uint64_t flags = process->getSyscallArg(tc, index);
     uint64_t provided_address = 0;
     bool use_provided_address = flags & OS::TGT_MREMAP_FIXED;
 
     if (use_provided_address)
-        provided_address = process->getSyscallArg(tc, index);
+        provided_address = varargs.get<uint64_t>();
 
     if ((start % TheISA::PageBytes != 0) ||
         (provided_address % TheISA::PageBytes != 0)) {