sim-se add readv and modifies writev
authorBrandon Potter <brandon.potter@amd.com>
Wed, 18 Apr 2018 19:02:34 +0000 (15:02 -0400)
committerAnthony Gutierrez <anthony.gutierrez@amd.com>
Tue, 22 Jan 2019 02:14:47 +0000 (02:14 +0000)
Change-Id: I6cbce4389d5697da34058dc910306394e48c6582
Reviewed-on: https://gem5-review.googlesource.com/c/12117
Reviewed-by: Anthony Gutierrez <anthony.gutierrez@amd.com>
Maintainer: Anthony Gutierrez <anthony.gutierrez@amd.com>

src/arch/x86/linux/process.cc
src/sim/syscall_emul.hh

index 2fe99e0bef8f0d8f234bb6694f6b6d865247307b..6a9aea85b1ce92eba49a3ec670f19403ab1f884c 100644 (file)
@@ -241,7 +241,7 @@ static SyscallDesc syscallDescs64[] = {
     /*  16 */ SyscallDesc("ioctl", ioctlFunc<X86Linux64>),
     /*  17 */ SyscallDesc("pread64", unimplementedFunc),
     /*  18 */ SyscallDesc("pwrite64", pwrite64Func<X86Linux64>),
-    /*  19 */ SyscallDesc("readv", unimplementedFunc),
+    /*  19 */ SyscallDesc("readv", readvFunc<X86Linux64>),
     /*  20 */ SyscallDesc("writev", writevFunc<X86Linux64>),
     /*  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<X86Linux32>),
     /* 146 */ SyscallDesc("writev", writevFunc<X86Linux32>),
     /* 147 */ SyscallDesc("getsid", unimplementedFunc),
     /* 148 */ SyscallDesc("fdatasync", unimplementedFunc),
index c52589f3a863ed9260b9e76afde43df2d8366532..ceeacd39bf69770721649ba151f86de2aba5da7c 100644 (file)
@@ -1531,6 +1531,44 @@ fstatfsFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
     return 0;
 }
 
+/// Target readv() handler.
+template <class OS>
+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<FileFDEntry>((*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 <class OS>
@@ -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.