]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/mini-os.git/commitdiff
stubdom: mmap on /dev/mem support
authorKeir Fraser <keir.fraser@citrix.com>
Wed, 21 Oct 2009 15:08:28 +0000 (16:08 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Wed, 21 Oct 2009 15:08:28 +0000 (16:08 +0100)
This patch adds support for mmap on /dev/mem in a stubdom; it is
secure because it only works for memory areas that have been
explicitly allowed by the toolstack (xc_domain_iomem_permission).
Incidentally this is all that is needed to make MSI-X passthrough work
with stubdoms.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
include/lib.h
lib/sys.c

index 0834a18c6273a44e786025c6e13f538f0f21e99f..9102d55b81e4dff8a361e8ed462245e1da91f1d2 100644 (file)
@@ -145,6 +145,7 @@ enum fd_type {
     FTYPE_BLK,
     FTYPE_KBD,
     FTYPE_FB,
+    FTYPE_MEM,
 };
 
 #define MAX_EVTCHN_PORTS 16
index 8cb5d28479633237146bbb0611ff776e3696dcb1..1284f5a7144293f8e490edfbb1687d73e4f6b9a1 100644 (file)
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -190,6 +190,11 @@ int open(const char *pathname, int flags, ...)
         printk("open(%s) -> %d\n", pathname, fd);
         return fd;
     }
+    if (!strncmp(pathname, "/dev/mem", strlen("/dev/mem"))) {
+        fd = alloc_fd(FTYPE_MEM);
+        printk("open(/dev/mem) -> %d\n", fd);
+        return fd;
+    }
     if (!strncmp(pathname, "/dev/ptmx", strlen("/dev/ptmx")))
         return posix_openpt(flags);
     printk("open(%s, %x)", pathname, flags);
@@ -1244,13 +1249,18 @@ void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset
     ASSERT(prot == (PROT_READ|PROT_WRITE));
     ASSERT((fd == -1 && (flags == (MAP_SHARED|MAP_ANON) || flags == (MAP_PRIVATE|MAP_ANON)))
         || (fd != -1 && flags == MAP_SHARED));
-    ASSERT(offset == 0);
 
     if (fd == -1)
         return map_zero(n, 1);
     else if (files[fd].type == FTYPE_XC) {
         unsigned long zero = 0;
         return map_frames_ex(&zero, n, 0, 0, 1, DOMID_SELF, 0, 0);
+    } else if (files[fd].type == FTYPE_MEM) {
+        int i;
+        unsigned long mfns[n];
+        for (i = 0; i < n; i++)
+            mfns[i] = ((unsigned long) offset + (i * PAGE_SIZE)) >> PAGE_SHIFT;
+        return map_frames_ex(mfns, n, 1, 0, 1, DOMID_IO, 0, _PAGE_PRESENT|_PAGE_RW);
     } else ASSERT(0);
 }