sim: Add a returnInto function to the SyscallDesc class.
authorGabe Black <gabeblack@google.com>
Tue, 10 Dec 2019 00:55:36 +0000 (16:55 -0800)
committerGabe Black <gabeblack@google.com>
Thu, 12 Mar 2020 07:21:13 +0000 (07:21 +0000)
This method lets system call implementations return values into
ThreadContexts other than the one they were called from. That's useful
for, for instance, clone() which creates new ThreadContexts.

By making it a virtual function in the SyscallDesc, we can delegate the
actual implementation to the SyscallDescABI subclass which knows the
ABI and how to use it to set the return value.

Change-Id: I61c6e60e4c2a8863c885cd818e4ff053fc3312ee
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23503
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
Maintainer: Gabe Black <gabeblack@google.com>

src/sim/syscall_desc.hh

index 4f1aa1877ca5d52bed99b7cf4ef0953e9145d7bb..b8d993b333b4ff9a1cc4ffc9065a59c048827a48 100644 (file)
@@ -76,6 +76,12 @@ class SyscallDesc {
 
     std::string name() { return _name; }
 
+    /**
+     * For use within the system call executor if new threads are created and
+     * need something returned into them.
+     */
+    virtual void returnInto(ThreadContext *tc, const SyscallReturn &ret) = 0;
+
   protected:
     using Executor =
         std::function<SyscallReturn(SyscallDesc *, int num, ThreadContext *)>;
@@ -162,6 +168,12 @@ class SyscallDescABI : public SyscallDesc
     SyscallDescABI(const char *name) :
         SyscallDescABI(name, ABIExecutor<>(unimplementedFunc))
     {}
+
+    void
+    returnInto(ThreadContext *tc, const SyscallReturn &ret) override
+    {
+        GuestABI::Result<ABI, SyscallReturn>::store(tc, ret);
+    }
 };
 
 #endif // __SIM_SYSCALL_DESC_HH__