From: Brandon Potter Date: Wed, 18 Apr 2018 21:39:26 +0000 (-0400) Subject: sim-se: add eventfd system call X-Git-Tag: v19.0.0.0~886 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d692552e9097f432740d676f8c30e7dd5011c417;p=gem5.git sim-se: add eventfd system call Change-Id: I7aeb4fe808d0c8f2fb8041e3662d330d8458f09c Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/12125 Tested-by: kokoro Reviewed-by: Ciro Santilli Maintainer: Brandon Potter --- diff --git a/src/arch/x86/linux/process.cc b/src/arch/x86/linux/process.cc index 9e8997afc..f19dce358 100644 --- a/src/arch/x86/linux/process.cc +++ b/src/arch/x86/linux/process.cc @@ -510,13 +510,13 @@ static SyscallDesc syscallDescs64[] = { /* 281 */ SyscallDesc("epoll_pwait", unimplementedFunc), /* 282 */ SyscallDesc("signalfd", unimplementedFunc), /* 283 */ SyscallDesc("timerfd_create", unimplementedFunc), - /* 284 */ SyscallDesc("eventfd", unimplementedFunc), + /* 284 */ SyscallDesc("eventfd", eventfdFunc), /* 285 */ SyscallDesc("fallocate", fallocateFunc), /* 286 */ SyscallDesc("timerfd_settime", unimplementedFunc), /* 287 */ SyscallDesc("timerfd_gettime", unimplementedFunc), /* 288 */ SyscallDesc("accept4", unimplementedFunc), /* 289 */ SyscallDesc("signalfd4", unimplementedFunc), - /* 290 */ SyscallDesc("eventfd2", unimplementedFunc), + /* 290 */ SyscallDesc("eventfd2", eventfdFunc), /* 291 */ SyscallDesc("epoll_create1", unimplementedFunc), /* 292 */ SyscallDesc("dup3", unimplementedFunc), /* 293 */ SyscallDesc("pipe2", unimplementedFunc), @@ -882,7 +882,7 @@ static SyscallDesc syscallDescs32[] = { /* 320 */ SyscallDesc("utimensat", unimplementedFunc), /* 321 */ SyscallDesc("signalfd", unimplementedFunc), /* 322 */ SyscallDesc("timerfd", unimplementedFunc), - /* 323 */ SyscallDesc("eventfd", unimplementedFunc) + /* 323 */ SyscallDesc("eventfd", eventfdFunc) }; I386LinuxProcess::I386LinuxProcess(ProcessParams * params, ObjectFile *objFile) diff --git a/src/sim/fd_entry.hh b/src/sim/fd_entry.hh index 15e174ae6..94c874af9 100644 --- a/src/sim/fd_entry.hh +++ b/src/sim/fd_entry.hh @@ -80,6 +80,16 @@ class HBFDEntry: public FDEntry : FDEntry(close_on_exec), _flags(flags), _simFD(sim_fd) { } + HBFDEntry(HBFDEntry const& reg, bool close_on_exec = false) + : FDEntry(close_on_exec), _flags(reg._flags), _simFD(reg._simFD) + { } + + std::shared_ptr + clone() const override + { + return std::make_shared(*this); + } + int getFlags() const { return _flags; } int getSimFD() const { return _simFD; } diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc index a9490fa57..bfec1f5a5 100644 --- a/src/sim/syscall_emul.cc +++ b/src/sim/syscall_emul.cc @@ -57,6 +57,12 @@ using namespace std; using namespace TheISA; +void +warnUnsupportedOS(std::string syscall_name) +{ + warn("Cannot invoke %s on host operating system.", syscall_name); +} + SyscallReturn unimplementedFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc) @@ -1036,9 +1042,7 @@ getegidFunc(SyscallDesc *desc, int callnum, Process *process, SyscallReturn fallocateFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) { -#if NO_FALLOCATE - warn("Host OS cannot support calls to fallocate. Ignoring syscall"); -#else +#if __linux__ int index = 0; int tgt_fd = p->getSyscallArg(tc, index); int mode = p->getSyscallArg(tc, index); @@ -1053,8 +1057,11 @@ fallocateFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) int result = fallocate(sim_fd, mode, offset, len); if (result < 0) return -errno; -#endif return 0; +#else + warnUnsupportedOS("fallocate"); + return -1; +#endif } SyscallReturn diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index 799602780..91db9ae49 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -53,26 +53,18 @@ #define NO_STAT64 0 #endif -#if (defined(__APPLE__) || defined(__OpenBSD__) || \ - defined(__FreeBSD__) || defined(__NetBSD__)) -#define NO_STATFS 1 -#else -#define NO_STATFS 0 -#endif - -#if (defined(__APPLE__) || defined(__OpenBSD__) || \ - defined(__FreeBSD__) || defined(__NetBSD__)) -#define NO_FALLOCATE 1 -#else -#define NO_FALLOCATE 0 -#endif - /// /// @file syscall_emul.hh /// /// This file defines objects used to emulate syscalls from the target /// application on the host machine. +#ifdef __linux__ +#include +#include + +#endif + #ifdef __CYGWIN32__ #include @@ -84,14 +76,6 @@ #include #include #include - -#if (NO_STATFS == 0) -#include - -#else -#include - -#endif #include #include #include @@ -133,6 +117,7 @@ // ////////////////////////////////////////////////////////////////////// +void warnUnsupportedOS(std::string syscall_name); /// Handler for unimplemented syscalls that we haven't thought about. SyscallReturn unimplementedFunc(SyscallDesc *desc, int num, @@ -1530,9 +1515,7 @@ SyscallReturn statfsFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc) { -#if NO_STATFS - warn("Host OS cannot support calls to statfs. Ignoring syscall"); -#else +#ifdef __linux__ std::string path; int index = 0; @@ -1552,8 +1535,11 @@ statfsFunc(SyscallDesc *desc, int callnum, Process *process, return -errno; copyOutStatfsBuf(tc->getMemProxy(), bufPtr, &hostBuf); -#endif return 0; +#else + warnUnsupportedOS("statfs"); + return -1; +#endif } template @@ -2860,4 +2846,32 @@ acceptFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) return p->fds->allocFD(afdp); } +/// Target eventfd() function. +template +SyscallReturn +eventfdFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc) +{ +#ifdef __linux__ + int index = 0; + unsigned initval = p->getSyscallArg(tc, index); + int in_flags = p->getSyscallArg(tc, index); + + int sim_fd = eventfd(initval, in_flags); + if (sim_fd == -1) + return -errno; + + bool cloexec = in_flags & OS::TGT_O_CLOEXEC; + + int flags = cloexec ? OS::TGT_O_CLOEXEC : 0; + flags |= (in_flags & OS::TGT_O_NONBLOCK) ? OS::TGT_O_NONBLOCK : 0; + + auto hbfdp = std::make_shared(flags, sim_fd, cloexec); + int tgt_fd = p->fds->allocFD(hbfdp); + return tgt_fd; +#else + warnUnsupportedOS("eventfd"); + return -1; +#endif +} + #endif // __SIM_SYSCALL_EMUL_HH__