From: Gabe Black Date: Thu, 12 Mar 2020 01:05:25 +0000 (-0700) Subject: sim: Provide an implementation for the pread64 system call. X-Git-Tag: v20.0.0.0~335 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0fedeb873d16fb3eee4d847bbe76111e44d701fd;p=gem5.git 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 --- 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,