Andreas Sandberg has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/15438

Change subject: arch-arm, sim-se: Add support for getdents64
......................................................................

arch-arm, sim-se: Add support for getdents64

Change-Id: Ib27950144d4c9802ffb842db98aec9e433ccbfc5
Cc: Giacomo Travaglini <[email protected]>
Cc: Javier Setoain <[email protected]>
Cc: Brandon Potter <[email protected]>
---
M src/arch/arm/linux/process.cc
M src/sim/syscall_emul.cc
M src/sim/syscall_emul.hh
3 files changed, 65 insertions(+), 0 deletions(-)



diff --git a/src/arch/arm/linux/process.cc b/src/arch/arm/linux/process.cc
index cb62e6e..d26e69d 100644
--- a/src/arch/arm/linux/process.cc
+++ b/src/arch/arm/linux/process.cc
@@ -342,7 +342,11 @@
     /* 214 */ SyscallDesc("setgid", unimplementedFunc),
     /* 215 */ SyscallDesc("setfsuid", unimplementedFunc),
     /* 216 */ SyscallDesc("setfsgid", unimplementedFunc),
+#if defined(SYS_getdents64)
+    /* 217 */ SyscallDesc("getdents64", getdents64Func),
+#else
     /* 217 */ SyscallDesc("getdents64", unimplementedFunc),
+#endif
     /* 218 */ SyscallDesc("pivot_root", unimplementedFunc),
     /* 219 */ SyscallDesc("mincore", unimplementedFunc),
     /* 220 */ SyscallDesc("madvise", ignoreFunc),
@@ -555,7 +559,11 @@
     /*   58 */ SyscallDesc("vhangup", unimplementedFunc),
     /*   59 */ SyscallDesc("pipe2", unimplementedFunc),
     /*   60 */ SyscallDesc("quotactl", unimplementedFunc),
+#if defined(SYS_getdents64)
+    /*   61 */ SyscallDesc("getdents64", getdents64Func),
+#else
     /*   61 */ SyscallDesc("getdents64", unimplementedFunc),
+#endif
     /*   62 */ SyscallDesc("llseek", lseekFunc),
     /*   63 */ SyscallDesc("read", readFunc),
     /*   64 */ SyscallDesc("write", writeFunc),
diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc
index 3d17b5d..b42431c 100644
--- a/src/sim/syscall_emul.cc
+++ b/src/sim/syscall_emul.cc
@@ -1200,3 +1200,54 @@
     return status;
 }
 #endif
+
+#if defined(SYS_getdents64)
+SyscallReturn
+getdents64Func(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
+{
+    int index = 0;
+    int tgt_fd = p->getSyscallArg(tc, index);
+    Addr buf_ptr = p->getSyscallArg(tc, index);
+    unsigned count = p->getSyscallArg(tc, index);
+
+    auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*p->fds)[tgt_fd]);
+    if (!hbfdp)
+        return -EBADF;
+    int sim_fd = hbfdp->getSimFD();
+
+    BufferArg buf_arg(buf_ptr, count);
+ auto status = syscall(SYS_getdents64, sim_fd, buf_arg.bufferPtr(), count);
+
+    if (status == -1)
+        return -errno;
+
+    typedef struct linux_dirent64 {
+        ino64_t d_ino;
+        off64_t d_off;
+        unsigned short d_reclen;
+        char dname[];
+    } LinDent64;
+
+    unsigned traversed = 0;
+    while (traversed < status) {
+        LinDent64 *buffer =
+            (LinDent64*)((Addr)buf_arg.bufferPtr() + traversed);
+
+        auto host_reclen = buffer->d_reclen;
+
+        /**
+         * Convert the byte ordering from the host to the target before
+ * passing the data back into the target's address space to preserve
+         * endianness.
+         */
+        buffer->d_ino = htog(buffer->d_ino);
+        buffer->d_off = htog(buffer->d_off);
+        buffer->d_reclen = htog(buffer->d_reclen);
+
+        traversed += host_reclen;
+    }
+
+    buf_arg.copyOut(tc->getMemProxy());
+    return status;
+}
+#endif
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index 343fb27..91e115d 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -309,6 +309,12 @@
                            Process *p, ThreadContext *tc);
 #endif

+#if defined(SYS_getdents64)
+// Target getdents() handler.
+SyscallReturn getdents64Func(SyscallDesc *desc, int num,
+                           Process *p, ThreadContext *tc);
+#endif
+
 // Target getuid() handler.
 SyscallReturn getuidFunc(SyscallDesc *desc, int num,
                          Process *p, ThreadContext *tc);

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/15438
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ib27950144d4c9802ffb842db98aec9e433ccbfc5
Gerrit-Change-Number: 15438
Gerrit-PatchSet: 1
Gerrit-Owner: Andreas Sandberg <[email protected]>
Gerrit-CC: Brandon Potter <[email protected]>
Gerrit-CC: Giacomo Travaglini <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to