summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrandon Potter <brandon.potter@amd.com>2018-04-18 16:57:46 -0400
committerBrandon Potter <Brandon.Potter@amd.com>2019-04-30 02:12:45 +0000
commit081da0f51882e54d5218d3c645c30b236315061c (patch)
treec8a81df03352759b37130d048f65078549b77bbe /src
parentca3dd5087800a3400f60589ce2063d30ce602580 (diff)
downloadgem5-081da0f51882e54d5218d3c645c30b236315061c.tar.xz
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 <noreply+kokoro@google.com> Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Maintainer: Jason Lowe-Power <jason@lowepower.com>
Diffstat (limited to 'src')
-rw-r--r--src/sim/syscall_emul.hh67
1 files 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 <fcntl.h>
+#include <net/if.h>
#include <poll.h>
+#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/stat.h>
+
#if (NO_STATFS == 0)
#include <sys/statfs.h>
+
#else
#include <sys/mount.h>
+
#endif
#include <sys/time.h>
#include <sys/types.h>
@@ -755,17 +760,59 @@ ioctlFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
return -ENOTTY;
auto dfdp = std::dynamic_pointer_cast<DeviceFDEntry>((*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<SocketFDEntry>((*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