tools/libs/foreignmemory: provide xenforeignmemory_unmap.

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>
This commit is contained in:
Ian Campbell committed 2016-01-22 12:24:18 +00:00
1 parent 3248691679
commit 0be403a41f
10 files changed
+43 -5

No files matched your search

+6
View 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
@@ -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
@@ -3,5 +3,6 @@ VERS_1.0 {
xenforeignmemory_open;
xenforeignmemory_close;
xenforeignmemory_map;
xenforeignmemory_unmap;
local: *; /* Do not expose anything by default */
};
+6
View 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
+6
View 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
+6
View 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
+6
View 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);
}
+1 -1
View 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);
+1 -1
View 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);
+1 -1
View 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;
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.