]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commitdiff
tools/libs/foreignmemory: provide xenforeignmemory_unmap.
authorIan Campbell <ian.campbell@citrix.com>
Tue, 28 Jul 2015 13:20:01 +0000 (14:20 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Fri, 22 Jan 2016 12:24:18 +0000 (12:24 +0000)
And require it be used instead of direct munmap.

This will allow e.g. Valgrind hooks to help track incorrect use of
foreign mappings.

Switch all uses of xenforeignmemory_map to use
xenforeignmemory_unmap, not that foreign mappings via the libxc compat
xc_map_foreign_* interface will not take advantage of this and will
need converting.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libs/foreignmemory/freebsd.c
tools/libs/foreignmemory/include/xenforeignmemory.h
tools/libs/foreignmemory/libxenforeignmemory.map
tools/libs/foreignmemory/linux.c
tools/libs/foreignmemory/minios.c
tools/libs/foreignmemory/netbsd.c
tools/libs/foreignmemory/solaris.c
tools/libxc/xc_sr_restore.c
tools/libxc/xc_sr_save.c
tools/libxc/xc_vm_event.c

index 4b2815d94359d26e72c239ed49cd879bc3d891d6..3c3ad093d068a85e516cc9128aaafe22545a6c9a 100644 (file)
@@ -118,6 +118,12 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
     return addr;
 }
 
+int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                                 void *addr, unsigned int num)
+{
+       return munmap(addr, num << PAGE_SHIFT);
+}
+
 /*
  * Local variables:
  * mode: C
index 5b3fa7a49194c1c21578405a46aa44285720a736..b783af3a4392467c297c137d899fab4ba5c7ae10 100644 (file)
@@ -44,8 +44,8 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem);
 
 /*
  * Maps a range within one domain to a local address range.  Mappings
- * should be unmapped with munmap and should follow the same rules as mmap
- * regarding page alignment.
+ * must be unmapped with xenforeignmemory_unmap and should follow the
+ * same rules as mmap regarding page alignment.
  *
  * prot is as for mmap(2).
  *
@@ -57,6 +57,13 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem);
 void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom,
                            int prot, const xen_pfn_t *arr, int *err,
                            unsigned int num);
+/*
+ * Unmap a mapping previous created with xenforeignmemory_map().
+ *
+ * Returns 0 on success on failure sets errno and returns -1.
+ */
+int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                           void *addr, unsigned int num);
 
 #endif
 
index 11f0d2be512f71c5d620fc591569e7da1e70d907..df206b3cfbcf63a1ac75709b09ee7dd53fc3acdc 100644 (file)
@@ -3,5 +3,6 @@ VERS_1.0 {
                xenforeignmemory_open;
                xenforeignmemory_close;
                xenforeignmemory_map;
+               xenforeignmemory_unmap;
        local: *; /* Do not expose anything by default */
 };
index b403ca7706ba994fccad547b4cc53bc96f0f5f32..40ecd417b89a19688ebd59d56b2fe68013ac2fc3 100644 (file)
@@ -282,6 +282,12 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
     return addr;
 }
 
+int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                                 void *addr, unsigned int num)
+{
+    return munmap(addr, (unsigned long)num << PAGE_SHIFT);
+}
+
 /*
  * Local variables:
  * mode: C
index a542e3dbfe186b1d3d3f91e959c9cd8ab202b61c..5fcb861364707d840cda48ec064e93640bbceab8 100644 (file)
@@ -51,6 +51,12 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
     return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
 }
 
+int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                                 void *addr, unsigned int num)
+{
+       return munmap(addr, num << PAGE_SHIFT);
+}
+
 /*
  * Local variables:
  * mode: C
index 704a09639f4ad68d7d2b16cd9c6c712db5da92a4..740c26f199e79566817159823719220f3be88db8 100644 (file)
@@ -94,6 +94,12 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom,
 
 }
 
+int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                                 void *addr, unsigned int num)
+{
+       return munmap(addr, num*XC_PAGE_SIZE);
+}
+
 /*
  * Local variables:
  * mode: C
index f4dd634d0f85aad818bcc90f77aedec2ca0b2e33..966fccb9ab6af3938cd0bfe49f7c6050cd79b8b2 100644 (file)
@@ -91,3 +91,9 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom,
     }
     return addr;
 }
+
+int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                                 void *addr, unsigned int num)
+{
+       return munmap(addr, num*XC_PAGE_SIZE);
+}
index 4f44d20b3e9a8c94bd528a27549edec1800db1de..5a51f262bc20d9a76894d6810b4758aa1e16691a 100644 (file)
@@ -378,7 +378,7 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count,
 
  err:
     if ( mapping )
-        munmap(mapping, nr_pages * PAGE_SIZE);
+        xenforeignmemory_unmap(xch->fmem, mapping, nr_pages);
 
     free(map_errs);
     free(mfns);
index 8ee07196dc0c112fc2634b389a15036340930f3a..fba4e40eb04faef85761bb46ae05b6bbd9135386 100644 (file)
@@ -263,7 +263,7 @@ static int write_batch(struct xc_sr_context *ctx)
  err:
     free(rec_pfns);
     if ( guest_mapping )
-        munmap(guest_mapping, nr_pages_mapped * PAGE_SIZE);
+        xenforeignmemory_unmap(xch->fmem, guest_mapping, nr_pages_mapped);
     for ( i = 0; local_pages && i < nr_pfns; ++i )
         free(local_pages[i]);
     free(iov);
index d2d99e4e5cd01804c0984ed3623c9680e99b8ffc..57abce0922b5768b9ba2fdd2236b9c34428ec575 100644 (file)
@@ -148,7 +148,7 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,
         }
 
         if ( ring_page )
-            munmap(ring_page, XC_PAGE_SIZE);
+            xenforeignmemory_unmap(xch->fmem, ring_page, 1);
         ring_page = NULL;
 
         errno = saved_errno;