Brandon Potter has submitted this change and it was merged. ( https://gem5-review.googlesource.com/c/public/gem5/+/12123 )

Change subject: sim-se: add socket ioctls
......................................................................

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+kok...@google.com>
Reviewed-by: Jason Lowe-Power <ja...@lowepower.com>
Maintainer: Jason Lowe-Power <ja...@lowepower.com>
---
M src/sim/syscall_emul.hh
1 file changed, 57 insertions(+), 10 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index 1d14af9..892d9d7 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 @@
         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

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12123
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: I687b31f375a846f0bab2debd9b9472605a4d2c7d
Gerrit-Change-Number: 12123
Gerrit-PatchSet: 25
Gerrit-Owner: Brandon Potter <brandon.pot...@amd.com>
Gerrit-Reviewer: Alexandru Duțu <alexandru.d...@amd.com>
Gerrit-Reviewer: Brandon Potter <brandon.pot...@amd.com>
Gerrit-Reviewer: Hoa Nguyen <hoangu...@ucdavis.edu>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: John Alsop <johnathan.al...@amd.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to