sim: Provide an implementation for the pread64 system call.
authorGabe Black <gabeblack@google.com>
Thu, 12 Mar 2020 01:05:25 +0000 (18:05 -0700)
committerGabe Black <gabeblack@google.com>
Mon, 16 Mar 2020 21:57:01 +0000 (21:57 +0000)
This implementation is very similar to the pwrite64 system call, just
with data going the other direction as you'd expect.

Change-Id: I4f8ec9d83bf2339f9c84e31f25309c58e6157304
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/26603
Reviewed-by: Matthew Poremba <matthew.poremba@amd.com>
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
src/sim/syscall_emul.hh

index 2503635a9d85bec68b498ec484a5013d6be1c03d..f999e4525847e979bc2cf392863bb0ebd3b908ce 100644 (file)
@@ -1816,6 +1816,27 @@ mmapFunc(SyscallDesc *desc, int num, ThreadContext *tc,
     return start;
 }
 
+template <class OS>
+SyscallReturn
+pread64Func(SyscallDesc *desc, int num, ThreadContext *tc,
+            int tgt_fd, Addr bufPtr, int nbytes, int offset)
+{
+    auto p = tc->getProcessPtr();
+
+    auto ffdp = std::dynamic_pointer_cast<FileFDEntry>((*p->fds)[tgt_fd]);
+    if (!ffdp)
+        return -EBADF;
+    int sim_fd = ffdp->getSimFD();
+
+    BufferArg bufArg(bufPtr, nbytes);
+
+    int bytes_read = pread(sim_fd, bufArg.bufferPtr(), nbytes, offset);
+
+    bufArg.copyOut(tc->getVirtProxy());
+
+    return (bytes_read == -1) ? -errno : bytes_read;
+}
+
 template <class OS>
 SyscallReturn
 pwrite64Func(SyscallDesc *desc, int num, ThreadContext *tc,