changeset 9796e43e751d in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=9796e43e751d
description:
        sim, syscall_emul: Add mmap to EmulatedDriver
        Add support for calling mmap on an EmulatedDriver file descriptor.

diffstat:

 src/sim/emul_driver.hh  |  15 +++++++++++++--
 src/sim/syscall_emul.hh |  12 +++++++++++-
 2 files changed, 24 insertions(+), 3 deletions(-)

diffs (54 lines):

diff -r b56cbe6b63a2 -r 9796e43e751d src/sim/emul_driver.hh
--- a/src/sim/emul_driver.hh    Tue Sep 13 23:11:20 2016 -0400
+++ b/src/sim/emul_driver.hh    Tue Sep 13 23:12:46 2016 -0400
@@ -46,8 +46,8 @@
  * hardware inside gem5 can be created by deriving from this class and
  * overriding the abstract virtual methods.
  *
- * Currently only open() and ioctl() calls are supported, but other calls
- * (e.g., read(), write(), mmap()) could be added as needed.
+ * Currently only open(), ioctl(), and mmap() calls are supported, but other
+ * calls (e.g., read(), write()) could be added as needed.
  */
 class EmulatedDriver : public SimObject
 {
@@ -85,6 +85,17 @@
      * (see the SyscallReturn class).
      */
     virtual int ioctl(LiveProcess *p, ThreadContext *tc, unsigned req) = 0;
+
+    /**
+     * Virtual method, invoked when the user program calls mmap() on
+     * the file descriptor returned by a previous open().  The parameters
+     * are the same as those passed in to mmapFunc() (q.v.).
+     * @return The return ptr for the mmap, or the negation of the errno
+     * (see the SyscallReturn class).
+     */
+    virtual Addr mmap(LiveProcess *p, ThreadContext *tc, Addr start,
+                      uint64_t length, int prot, int tgtFlags, int tgtFd,
+                      int offset) { return -EBADF; }
 };
 
 #endif // __SIM_EMUL_DRIVER_HH
diff -r b56cbe6b63a2 -r 9796e43e751d src/sim/syscall_emul.hh
--- a/src/sim/syscall_emul.hh   Tue Sep 13 23:11:20 2016 -0400
+++ b/src/sim/syscall_emul.hh   Tue Sep 13 23:12:46 2016 -0400
@@ -1284,7 +1284,17 @@
     int sim_fd = -1;
     uint8_t *pmap = nullptr;
     if (!(tgt_flags & OS::TGT_MAP_ANONYMOUS)) {
-        sim_fd = p->getSimFD(tgt_fd);
+        // Check for EmulatedDriver mmap
+        FDEntry *fde = p->getFDEntry(tgt_fd);
+        if (fde == NULL)
+            return -EBADF;
+
+        if (fde->driver != NULL) {
+            return fde->driver->mmap(p, tc, start, length, prot,
+                                     tgt_flags, tgt_fd, offset);
+        }
+        sim_fd = fde->fd;
+
         if (sim_fd < 0)
             return -EBADF;
 
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to