sim: implement getdents/getdents64 in user mode
authorMichael Adler <Michael.Adler@intel.com>
Mon, 20 Oct 2014 21:44:53 +0000 (16:44 -0500)
committerMichael Adler <Michael.Adler@intel.com>
Mon, 20 Oct 2014 21:44:53 +0000 (16:44 -0500)
Has been tested only for alpha.
Committed by: Nilay Vaish <nilay@cs.wisc.edu>

src/arch/alpha/linux/process.cc
src/arch/arm/linux/process.cc
src/arch/mips/linux/process.cc
src/arch/power/linux/process.cc
src/arch/sparc/linux/syscalls.cc
src/arch/x86/linux/syscalls.cc
src/sim/syscall_emul.cc
src/sim/syscall_emul.hh

index ebe06510dcd935fefa76cdc7cb0d3ef5993ced37..fab758f473644e8a7e6182a2e267115b5f5a7e40 100644 (file)
@@ -431,7 +431,7 @@ SyscallDesc AlphaLinuxProcess::syscallDescs[] = {
     /* 302 */ SyscallDesc("mount", unimplementedFunc),
     /* 303 */ SyscallDesc("old_adjtimex", unimplementedFunc),
     /* 304 */ SyscallDesc("swapoff", unimplementedFunc),
-    /* 305 */ SyscallDesc("getdents", unimplementedFunc),
+    /* 305 */ SyscallDesc("getdents", getdentsFunc),
     /* 306 */ SyscallDesc("create_module", unimplementedFunc),
     /* 307 */ SyscallDesc("init_module", unimplementedFunc),
     /* 308 */ SyscallDesc("delete_module", unimplementedFunc),
@@ -503,7 +503,7 @@ SyscallDesc AlphaLinuxProcess::syscallDescs[] = {
     /* 374 */ SyscallDesc("pivot_root", unimplementedFunc),
     /* 375 */ SyscallDesc("mincore", unimplementedFunc),
     /* 376 */ SyscallDesc("pciconfig_iobase", unimplementedFunc),
-    /* 377 */ SyscallDesc("getdents64", unimplementedFunc),
+    /* 377 */ SyscallDesc("getdents64", getdents64Func),
     /* 378 */ SyscallDesc("gettid", unimplementedFunc),
     /* 379 */ SyscallDesc("readahead", unimplementedFunc),
     /* 380 */ SyscallDesc("security", unimplementedFunc),
index faa39fd3419650eab94b768801fef9f0dacbfd3e..7f53eaae8e15796672a62606018fc4e7dd6ceb6c 100644 (file)
@@ -260,7 +260,7 @@ static SyscallDesc syscallDescs32[] = {
     /* 138 */ SyscallDesc("setfsuid", unimplementedFunc),
     /* 139 */ SyscallDesc("setfsgid", unimplementedFunc),
     /* 140 */ SyscallDesc("llseek", _llseekFunc),
-    /* 141 */ SyscallDesc("getdents", unimplementedFunc),
+    /* 141 */ SyscallDesc("getdents", getdentsFunc),
     /* 142 */ SyscallDesc("newselect", unimplementedFunc),
     /* 143 */ SyscallDesc("flock", unimplementedFunc),
     /* 144 */ SyscallDesc("msync", unimplementedFunc),
@@ -336,7 +336,7 @@ static SyscallDesc syscallDescs32[] = {
     /* 214 */ SyscallDesc("setgid", unimplementedFunc),
     /* 215 */ SyscallDesc("setfsuid", unimplementedFunc),
     /* 216 */ SyscallDesc("setfsgid", unimplementedFunc),
-    /* 217 */ SyscallDesc("getdents64", unimplementedFunc),
+    /* 217 */ SyscallDesc("getdents64", getdents64Func),
     /* 218 */ SyscallDesc("pivot_root", unimplementedFunc),
     /* 219 */ SyscallDesc("mincore", unimplementedFunc),
     /* 220 */ SyscallDesc("madvise", unimplementedFunc),
index ef21179e52e04bace1ad76dc6897dc079c14b7ae..375288290e2bfdf86d4a936c9d60e6dbbab4683f 100644 (file)
@@ -277,7 +277,7 @@ SyscallDesc MipsLinuxProcess::syscallDescs[] = {
     /* 138 */ SyscallDesc("setfsuid", unimplementedFunc),
     /* 139 */ SyscallDesc("setfsgid", unimplementedFunc),
     /* 140 */ SyscallDesc("llseek", unimplementedFunc),
-    /* 141 */ SyscallDesc("getdents", unimplementedFunc),
+    /* 141 */ SyscallDesc("getdents", getdentsFunc),
     /* 142 */ SyscallDesc("newselect", unimplementedFunc),
     /* 143 */ SyscallDesc("flock", unimplementedFunc),
     /* 144 */ SyscallDesc("msync", unimplementedFunc),
@@ -355,7 +355,7 @@ SyscallDesc MipsLinuxProcess::syscallDescs[] = {
     /* 216 */ SyscallDesc("pivot_root", unimplementedFunc),
     /* 217 */ SyscallDesc("mincore", unimplementedFunc),
     /* 218 */ SyscallDesc("madvise", unimplementedFunc),
-    /* 219 */ SyscallDesc("getdents64", unimplementedFunc),
+    /* 219 */ SyscallDesc("getdents64", getdents64Func),
     /* 220 */ SyscallDesc("fcntl64", fcntl64Func),
     /* 221 */ SyscallDesc("reserved#221", unimplementedFunc),
     /* 222 */ SyscallDesc("gettid", unimplementedFunc),
index b00e02a872ad54e2232cf6f9ad75caaf7089d7b5..eef334d01a4453083ae640f80a9df7fd074f8805 100644 (file)
@@ -205,7 +205,7 @@ SyscallDesc PowerLinuxProcess::syscallDescs[] = {
     /* 138 */ SyscallDesc("setfsuid", unimplementedFunc),
     /* 139 */ SyscallDesc("setfsgid", unimplementedFunc),
     /* 140 */ SyscallDesc("llseek", _llseekFunc),
-    /* 141 */ SyscallDesc("getdents", unimplementedFunc),
+    /* 141 */ SyscallDesc("getdents", getdentsFunc),
     /* 142 */ SyscallDesc("newselect", unimplementedFunc),
     /* 143 */ SyscallDesc("flock", unimplementedFunc),
     /* 144 */ SyscallDesc("msync", unimplementedFunc),
@@ -281,7 +281,7 @@ SyscallDesc PowerLinuxProcess::syscallDescs[] = {
     /* 214 */ SyscallDesc("setgid", unimplementedFunc),
     /* 215 */ SyscallDesc("setfsuid", unimplementedFunc),
     /* 216 */ SyscallDesc("setfsgid", unimplementedFunc),
-    /* 217 */ SyscallDesc("getdents64", unimplementedFunc),
+    /* 217 */ SyscallDesc("getdents64", getdents64Func),
     /* 218 */ SyscallDesc("pivot_root", unimplementedFunc),
     /* 219 */ SyscallDesc("mincore", unimplementedFunc),
     /* 220 */ SyscallDesc("madvise", unimplementedFunc),
index 66e8e1fe182f403959fa65fe01e1b06e7b386a0a..232ff714036a36c7026dd8c6515c59be5b5bd3ed 100644 (file)
@@ -241,7 +241,7 @@ SyscallDesc SparcLinuxProcess::syscall32Descs[] = {
     /* 151 */ SyscallDesc("inotify_init", unimplementedFunc),
     /* 152 */ SyscallDesc("inotify_add_watch", unimplementedFunc),
     /* 153 */ SyscallDesc("poll", unimplementedFunc),
-    /* 154 */ SyscallDesc("getdents64", unimplementedFunc),
+    /* 154 */ SyscallDesc("getdents64", getdents64Func),
     /* 155 */ SyscallDesc("fcntl64", unimplementedFunc),
     /* 156 */ SyscallDesc("inotify_rm_watch", unimplementedFunc),
     /* 157 */ SyscallDesc("statfs", unimplementedFunc),
@@ -261,7 +261,7 @@ SyscallDesc SparcLinuxProcess::syscall32Descs[] = {
     /* 171 */ SyscallDesc("fsetxattr", unimplementedFunc), // 32 bit
     /* 172 */ SyscallDesc("getxattr", unimplementedFunc),
     /* 173 */ SyscallDesc("lgetxattr", unimplementedFunc),
-    /* 174 */ SyscallDesc("getdents", unimplementedFunc),
+    /* 174 */ SyscallDesc("getdents", getdentsFunc),
     /* 175 */ SyscallDesc("setsid", unimplementedFunc),
     /* 176 */ SyscallDesc("fchdir", unimplementedFunc),
     /* 177 */ SyscallDesc("fgetxattr", unimplementedFunc), // 32 bit
@@ -547,7 +547,7 @@ SyscallDesc SparcLinuxProcess::syscallDescs[] = {
     /* 151 */ SyscallDesc("inotify_init", unimplementedFunc),
     /* 152 */ SyscallDesc("inotify_add_watch", unimplementedFunc),
     /* 153 */ SyscallDesc("poll", unimplementedFunc),
-    /* 154 */ SyscallDesc("getdents64", unimplementedFunc),
+    /* 154 */ SyscallDesc("getdents64", getdents64Func),
     /* 155 */ SyscallDesc("fcntl64", unimplementedFunc),
     /* 156 */ SyscallDesc("inotify_rm_watch", unimplementedFunc),
     /* 157 */ SyscallDesc("statfs", unimplementedFunc),
@@ -567,7 +567,7 @@ SyscallDesc SparcLinuxProcess::syscallDescs[] = {
     /* 171 */ SyscallDesc("fsetxattr", unimplementedFunc),
     /* 172 */ SyscallDesc("getxattr", unimplementedFunc),
     /* 173 */ SyscallDesc("lgetxattr", unimplementedFunc),
-    /* 174 */ SyscallDesc("getdents", unimplementedFunc),
+    /* 174 */ SyscallDesc("getdents", getdentsFunc),
     /* 175 */ SyscallDesc("setsid", unimplementedFunc),
     /* 176 */ SyscallDesc("fchdir", unimplementedFunc),
     /* 177 */ SyscallDesc("fgetxattr", unimplementedFunc),
index 8e2d0da016cffe5b9bd51c7fa02b2c62885b2992..7b3be28f51f50d661743e68539cfd936a35da89c 100644 (file)
@@ -291,7 +291,7 @@ SyscallDesc X86_64LinuxProcess::syscallDescs[] = {
     /*  75 */ SyscallDesc("fdatasync", unimplementedFunc),
     /*  76 */ SyscallDesc("truncate", truncateFunc),
     /*  77 */ SyscallDesc("ftruncate", ftruncateFunc),
-    /*  78 */ SyscallDesc("getdents", unimplementedFunc),
+    /*  78 */ SyscallDesc("getdents", getdentsFunc),
     /*  79 */ SyscallDesc("getcwd", getcwdFunc),
     /*  80 */ SyscallDesc("chdir", unimplementedFunc),
     /*  81 */ SyscallDesc("fchdir", unimplementedFunc),
@@ -430,7 +430,7 @@ SyscallDesc X86_64LinuxProcess::syscallDescs[] = {
     /* 214 */ SyscallDesc("epoll_ctl_old", unimplementedFunc),
     /* 215 */ SyscallDesc("epoll_wait_old", unimplementedFunc),
     /* 216 */ SyscallDesc("remap_file_pages", unimplementedFunc),
-    /* 217 */ SyscallDesc("getdents64", unimplementedFunc),
+    /* 217 */ SyscallDesc("getdents64", getdents64Func),
     /* 218 */ SyscallDesc("set_tid_address", unimplementedFunc),
     /* 219 */ SyscallDesc("restart_syscall", unimplementedFunc),
     /* 220 */ SyscallDesc("semtimedop", unimplementedFunc),
index d8df891dde4a5c223953b1b5cc9974d6eb5f2db0..7eeacd31957a7cd3aa13abd93dbcbadfc3cf32e0 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <fcntl.h>
 #include <unistd.h>
+#include <sys/syscall.h>
 
 #include <cstdio>
 #include <iostream>
@@ -867,6 +868,41 @@ cloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
     }
 }
 
+SyscallReturn
+getdentsFunc(SyscallDesc *desc, int num, LiveProcess *p,
+             ThreadContext *tc)
+{
+    int index = 0;
+    int fd = p->sim_fd(p->getSyscallArg(tc, index));
+    Addr bufPtr = p->getSyscallArg(tc, index);
+    int nbytes = p->getSyscallArg(tc, index);
+    BufferArg bufArg(bufPtr, nbytes);
+
+    int bytes_read = syscall(SYS_getdents, fd, bufArg.bufferPtr(), nbytes);
+
+    if (bytes_read != -1)
+        bufArg.copyOut(tc->getMemProxy());
+
+    return bytes_read;
+}
+
+SyscallReturn
+getdents64Func(SyscallDesc *desc, int num, LiveProcess *p,
+               ThreadContext *tc)
+{
+    int index = 0;
+    int fd = p->sim_fd(p->getSyscallArg(tc, index));
+    Addr bufPtr = p->getSyscallArg(tc, index);
+    int nbytes = p->getSyscallArg(tc, index);
+    BufferArg bufArg(bufPtr, nbytes);
+
+    int bytes_read = syscall(SYS_getdents64, fd, bufArg.bufferPtr(), nbytes);
+
+    if (bytes_read != -1)
+        bufArg.copyOut(tc->getMemProxy());
+
+    return bytes_read;
+}
 SyscallReturn
 accessFunc(SyscallDesc *desc, int callnum, LiveProcess *p, ThreadContext *tc,
         int index)
index 66c12f07de30b2a0ef85f51bcf9a816de01aad61..a106a1939bb83b093f1815163c5ecfd00a6859f5 100644 (file)
@@ -439,6 +439,14 @@ futexFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
 
 }
 
+/// Target getdents() handler.
+SyscallReturn getdentsFunc(SyscallDesc *desc, int num,
+                           LiveProcess *process, ThreadContext *tc);
+
+/// Target getdents64() handler.
+SyscallReturn getdents64Func(SyscallDesc *desc, int num,
+                             LiveProcess *process, ThreadContext *tc);
+
 
 /// Pseudo Funcs  - These functions use a different return convension,
 /// returning a second value in a register other than the normal return register