summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Adler <Michael.Adler@intel.com>2014-10-20 16:44:53 -0500
committerMichael Adler <Michael.Adler@intel.com>2014-10-20 16:44:53 -0500
commita3fe4c06620439aa317f257d3bcdde34508d3d43 (patch)
treee6bd4f80dddbe7404fcf87f82a2deeb803f93ab2
parente72736aaf0508dd545ae9949c31ed91ba41d761b (diff)
downloadgem5-a3fe4c06620439aa317f257d3bcdde34508d3d43.tar.xz
sim: implement getdents/getdents64 in user mode
Has been tested only for alpha. Committed by: Nilay Vaish <nilay@cs.wisc.edu>
-rw-r--r--src/arch/alpha/linux/process.cc4
-rw-r--r--src/arch/arm/linux/process.cc4
-rw-r--r--src/arch/mips/linux/process.cc4
-rw-r--r--src/arch/power/linux/process.cc4
-rw-r--r--src/arch/sparc/linux/syscalls.cc8
-rw-r--r--src/arch/x86/linux/syscalls.cc4
-rw-r--r--src/sim/syscall_emul.cc36
-rw-r--r--src/sim/syscall_emul.hh8
8 files changed, 58 insertions, 14 deletions
diff --git a/src/arch/alpha/linux/process.cc b/src/arch/alpha/linux/process.cc
index ebe06510d..fab758f47 100644
--- a/src/arch/alpha/linux/process.cc
+++ b/src/arch/alpha/linux/process.cc
@@ -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),
diff --git a/src/arch/arm/linux/process.cc b/src/arch/arm/linux/process.cc
index faa39fd34..7f53eaae8 100644
--- a/src/arch/arm/linux/process.cc
+++ b/src/arch/arm/linux/process.cc
@@ -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),
diff --git a/src/arch/mips/linux/process.cc b/src/arch/mips/linux/process.cc
index ef21179e5..375288290 100644
--- a/src/arch/mips/linux/process.cc
+++ b/src/arch/mips/linux/process.cc
@@ -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),
diff --git a/src/arch/power/linux/process.cc b/src/arch/power/linux/process.cc
index b00e02a87..eef334d01 100644
--- a/src/arch/power/linux/process.cc
+++ b/src/arch/power/linux/process.cc
@@ -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),
diff --git a/src/arch/sparc/linux/syscalls.cc b/src/arch/sparc/linux/syscalls.cc
index 66e8e1fe1..232ff7140 100644
--- a/src/arch/sparc/linux/syscalls.cc
+++ b/src/arch/sparc/linux/syscalls.cc
@@ -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),
diff --git a/src/arch/x86/linux/syscalls.cc b/src/arch/x86/linux/syscalls.cc
index 8e2d0da01..7b3be28f5 100644
--- a/src/arch/x86/linux/syscalls.cc
+++ b/src/arch/x86/linux/syscalls.cc
@@ -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),
diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc
index d8df891dd..7eeacd319 100644
--- a/src/sim/syscall_emul.cc
+++ b/src/sim/syscall_emul.cc
@@ -31,6 +31,7 @@
#include <fcntl.h>
#include <unistd.h>
+#include <sys/syscall.h>
#include <cstdio>
#include <iostream>
@@ -868,6 +869,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)
{
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index 66c12f07d..a106a1939 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -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