From f3a438e58d836ec283af6eef8bb34b57958303d6 Mon Sep 17 00:00:00 2001 From: Javier Setoain Date: Wed, 9 Jan 2019 14:24:31 +0000 Subject: sim-se, arch-arm: Add support for getdents64 Change-Id: Ib27950144d4c9802ffb842db98aec9e433ccbfc5 Signed-off-by: Andreas Sandberg Cc: Giacomo Travaglini Cc: Javier Setoain Cc: Brandon Potter Reviewed-on: https://gem5-review.googlesource.com/c/15438 Maintainer: Brandon Potter Reviewed-by: Jason Lowe-Power --- src/arch/arm/linux/process.cc | 10 +++++++++ src/sim/syscall_emul.cc | 48 ++++++++++++++++++++++++++++++++----------- src/sim/syscall_emul.hh | 6 ++++++ 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/arch/arm/linux/process.cc b/src/arch/arm/linux/process.cc index cb62e6ee7..61caa456b 100644 --- a/src/arch/arm/linux/process.cc +++ b/src/arch/arm/linux/process.cc @@ -46,6 +46,8 @@ #include "arch/arm/linux/process.hh" +#include + #include "arch/arm/isa_traits.hh" #include "arch/arm/linux/linux.hh" #include "base/trace.hh" @@ -342,7 +344,11 @@ static SyscallDesc syscallDescs32[] = { /* 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 +561,11 @@ static SyscallDesc syscallDescs64[] = { /* 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 3d17b5d75..e79e79c62 100644 --- a/src/sim/syscall_emul.cc +++ b/src/sim/syscall_emul.cc @@ -1151,9 +1151,10 @@ rmdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) return (result == -1) ? -errno : result; } -#if defined(SYS_getdents) -SyscallReturn -getdentsFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +#if defined(SYS_getdents) || defined(SYS_getdents64) +template +static SyscallReturn +getdentsImpl(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) { int index = 0; int tgt_fd = p->getSyscallArg(tc, index); @@ -1166,21 +1167,14 @@ getdentsFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) int sim_fd = hbfdp->getSimFD(); BufferArg buf_arg(buf_ptr, count); - auto status = syscall(SYS_getdents, sim_fd, buf_arg.bufferPtr(), count); + auto status = syscall(SYS_NUM, sim_fd, buf_arg.bufferPtr(), count); if (status == -1) return -errno; - typedef struct linux_dirent { - unsigned long d_ino; - unsigned long d_off; - unsigned short d_reclen; - char dname[]; - } LinDent; - unsigned traversed = 0; while (traversed < status) { - LinDent *buffer = (LinDent*)((Addr)buf_arg.bufferPtr() + traversed); + DE *buffer = (DE*)((Addr)buf_arg.bufferPtr() + traversed); auto host_reclen = buffer->d_reclen; @@ -1200,3 +1194,33 @@ getdentsFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) return status; } #endif + +#if defined(SYS_getdents) +SyscallReturn +getdentsFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +{ + typedef struct linux_dirent { + unsigned long d_ino; + unsigned long d_off; + unsigned short d_reclen; + char dname[]; + } LinDent; + + return getdentsImpl(desc, callnum, p, tc); +} +#endif + +#if defined(SYS_getdents64) +SyscallReturn +getdents64Func(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) +{ + typedef struct linux_dirent64 { + ino64_t d_ino; + off64_t d_off; + unsigned short d_reclen; + char dname[]; + } LinDent64; + + return getdentsImpl(desc, callnum, p, tc); +} +#endif diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index 343fb2731..91e115de0 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -309,6 +309,12 @@ SyscallReturn getdentsFunc(SyscallDesc *desc, int num, 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); -- cgit v1.2.3