From 081da0f51882e54d5218d3c645c30b236315061c Mon Sep 17 00:00:00 2001 From: Brandon Potter Date: Wed, 18 Apr 2018 16:57:46 -0400 Subject: [PATCH] sim-se: add socket ioctls The OpenMPI 1.8.2 runtime needs the ioctl code included in this patch to issue socket operations on the host machine. Change-Id: I687b31f375a846f0bab2debd9b9472605a4d2c7d Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/12123 Tested-by: kokoro Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power --- src/sim/syscall_emul.hh | 67 +++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 10 deletions(-) diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index 1d14af921..892d9d729 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -78,14 +78,19 @@ #endif #include +#include #include +#include #include #include #include + #if (NO_STATFS == 0) #include + #else #include + #endif #include #include @@ -755,17 +760,59 @@ ioctlFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) return -ENOTTY; auto dfdp = std::dynamic_pointer_cast((*p->fds)[tgt_fd]); - if (!dfdp) - return -EBADF; + if (dfdp) { + EmulatedDriver *emul_driver = dfdp->getDriver(); + if (emul_driver) + return emul_driver->ioctl(p, tc, req); + } - /** - * If the driver is valid, issue the ioctl through it. Otherwise, - * there's an implicit assumption that the device is a TTY type and we - * return that we do not have a valid TTY. - */ - EmulatedDriver *emul_driver = dfdp->getDriver(); - if (emul_driver) - return emul_driver->ioctl(p, tc, req); + auto sfdp = std::dynamic_pointer_cast((*p->fds)[tgt_fd]); + if (sfdp) { + int status; + + switch (req) { + case SIOCGIFCONF: { + Addr conf_addr = p->getSyscallArg(tc, index); + BufferArg conf_arg(conf_addr, sizeof(ifconf)); + conf_arg.copyIn(tc->getMemProxy()); + + ifconf *conf = (ifconf*)conf_arg.bufferPtr(); + Addr ifc_buf_addr = (Addr)conf->ifc_buf; + BufferArg ifc_buf_arg(ifc_buf_addr, conf->ifc_len); + ifc_buf_arg.copyIn(tc->getMemProxy()); + + conf->ifc_buf = (char*)ifc_buf_arg.bufferPtr(); + + status = ioctl(sfdp->getSimFD(), req, conf_arg.bufferPtr()); + if (status != -1) { + conf->ifc_buf = (char*)ifc_buf_addr; + ifc_buf_arg.copyOut(tc->getMemProxy()); + conf_arg.copyOut(tc->getMemProxy()); + } + + return status; + } + case SIOCGIFFLAGS: +#ifdef __linux__ + case SIOCGIFINDEX: +#endif + case SIOCGIFNETMASK: + case SIOCGIFADDR: +#ifdef __linux__ + case SIOCGIFHWADDR: +#endif + case SIOCGIFMTU: { + Addr req_addr = p->getSyscallArg(tc, index); + BufferArg req_arg(req_addr, sizeof(ifreq)); + req_arg.copyIn(tc->getMemProxy()); + + status = ioctl(sfdp->getSimFD(), req, req_arg.bufferPtr()); + if (status != -1) + req_arg.copyOut(tc->getMemProxy()); + return status; + } + } + } /** * For lack of a better return code, return ENOTTY. Ideally, we should -- 2.30.2