From: Brandon Potter Date: Wed, 18 Apr 2018 19:02:34 +0000 (-0400) Subject: sim-se add readv and modifies writev X-Git-Tag: v19.0.0.0~1247 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e9d957592a2467be72ca1eb6c885e8b80b374f0b;p=gem5.git sim-se add readv and modifies writev Change-Id: I6cbce4389d5697da34058dc910306394e48c6582 Reviewed-on: https://gem5-review.googlesource.com/c/12117 Reviewed-by: Anthony Gutierrez Maintainer: Anthony Gutierrez --- diff --git a/src/arch/x86/linux/process.cc b/src/arch/x86/linux/process.cc index 2fe99e0be..6a9aea85b 100644 --- a/src/arch/x86/linux/process.cc +++ b/src/arch/x86/linux/process.cc @@ -241,7 +241,7 @@ static SyscallDesc syscallDescs64[] = { /* 16 */ SyscallDesc("ioctl", ioctlFunc), /* 17 */ SyscallDesc("pread64", unimplementedFunc), /* 18 */ SyscallDesc("pwrite64", pwrite64Func), - /* 19 */ SyscallDesc("readv", unimplementedFunc), + /* 19 */ SyscallDesc("readv", readvFunc), /* 20 */ SyscallDesc("writev", writevFunc), /* 21 */ SyscallDesc("access", ignoreFunc), /* 22 */ SyscallDesc("pipe", pipeFunc), @@ -704,7 +704,7 @@ static SyscallDesc syscallDescs32[] = { /* 142 */ SyscallDesc("_newselect", unimplementedFunc), /* 143 */ SyscallDesc("flock", unimplementedFunc), /* 144 */ SyscallDesc("msync", unimplementedFunc), - /* 145 */ SyscallDesc("readv", unimplementedFunc), + /* 145 */ SyscallDesc("readv", readvFunc), /* 146 */ SyscallDesc("writev", writevFunc), /* 147 */ SyscallDesc("getsid", unimplementedFunc), /* 148 */ SyscallDesc("fdatasync", unimplementedFunc), diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index c52589f3a..ceeacd39b 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -1531,6 +1531,44 @@ fstatfsFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) return 0; } +/// Target readv() handler. +template +SyscallReturn +readvFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +{ + int index = 0; + int tgt_fd = p->getSyscallArg(tc, index); + + auto ffdp = std::dynamic_pointer_cast((*p->fds)[tgt_fd]); + if (!ffdp) + return -EBADF; + int sim_fd = ffdp->getSimFD(); + + SETranslatingPortProxy &prox = tc->getMemProxy(); + uint64_t tiov_base = p->getSyscallArg(tc, index); + size_t count = p->getSyscallArg(tc, index); + typename OS::tgt_iovec tiov[count]; + struct iovec hiov[count]; + for (size_t i = 0; i < count; ++i) { + prox.readBlob(tiov_base + (i * sizeof(typename OS::tgt_iovec)), + (uint8_t*)&tiov[i], sizeof(typename OS::tgt_iovec)); + hiov[i].iov_len = TheISA::gtoh(tiov[i].iov_len); + hiov[i].iov_base = new char [hiov[i].iov_len]; + } + + int result = readv(sim_fd, hiov, count); + int local_errno = errno; + + for (size_t i = 0; i < count; ++i) { + if (result != -1) { + prox.writeBlob(TheISA::htog(tiov[i].iov_base), + (uint8_t*)hiov[i].iov_base, hiov[i].iov_len); + } + delete [] (char *)hiov[i].iov_base; + } + + return (result == -1) ? -local_errno : result; +} /// Target writev() handler. template @@ -1565,10 +1603,7 @@ writevFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) for (size_t i = 0; i < count; ++i) delete [] (char *)hiov[i].iov_base; - if (result < 0) - return -errno; - - return result; + return (result == -1) ? -errno : result; } /// Real mmap handler.