From 0fedeb873d16fb3eee4d847bbe76111e44d701fd Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Wed, 11 Mar 2020 18:05:25 -0700 Subject: [PATCH] sim: Provide an implementation for the pread64 system call. 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 Maintainer: Bobby R. Bruce Tested-by: kokoro --- src/sim/syscall_emul.hh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index 2503635a9..f999e4525 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -1816,6 +1816,27 @@ mmapFunc(SyscallDesc *desc, int num, ThreadContext *tc, return start; } +template +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((*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 SyscallReturn pwrite64Func(SyscallDesc *desc, int num, ThreadContext *tc, -- 2.30.2