aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxc/xc_linux_osdep.c
diff options
context:
space:
mode:
authorIan Campbell <ian.campbell@citrix.com>2011-03-11 18:18:18 +0000
committerIan Campbell <ian.campbell@citrix.com>2011-03-11 18:18:18 +0000
commit44baceec2d35beb902ddf909d667f2329576381f (patch)
treef972cba285df51123bf1c6488e642efa1c4200c0 /tools/libxc/xc_linux_osdep.c
parent8627dcc084e9f84eaad8ec4723d86186440df8dd (diff)
downloadxen-44baceec2d35beb902ddf909d667f2329576381f.tar.gz
xen-44baceec2d35beb902ddf909d667f2329576381f.tar.bz2
xen-44baceec2d35beb902ddf909d667f2329576381f.zip
libxc: osdep: convert hypercall buffer allocation
This will allow us to use OS specific interfaces to ensure that the allocated memory is safe for use as a hypercall buffer in the future. Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'tools/libxc/xc_linux_osdep.c')
-rw-r--r--tools/libxc/xc_linux_osdep.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/libxc/xc_linux_osdep.c b/tools/libxc/xc_linux_osdep.c
index 377c93867a..dca6718370 100644
--- a/tools/libxc/xc_linux_osdep.c
+++ b/tools/libxc/xc_linux_osdep.c
@@ -86,6 +86,30 @@ static int linux_privcmd_close(xc_interface *xch, xc_osdep_handle h)
return close(fd);
}
+static void *linux_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
+{
+ size_t size = npages * XC_PAGE_SIZE;
+ void *p;
+ int ret;
+
+ ret = posix_memalign(&p, XC_PAGE_SIZE, size);
+ if (ret != 0 || !p)
+ return NULL;
+
+ if ( mlock(p, size) < 0 )
+ {
+ free(p);
+ return NULL;
+ }
+ return p;
+}
+
+static void linux_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages)
+{
+ (void) munlock(ptr, npages * XC_PAGE_SIZE);
+ free(ptr);
+}
+
static int linux_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
{
int fd = (int)h;
@@ -344,6 +368,9 @@ static struct xc_osdep_ops linux_privcmd_ops = {
.close = &linux_privcmd_close,
.u.privcmd = {
+ .alloc_hypercall_buffer = &linux_privcmd_alloc_hypercall_buffer,
+ .free_hypercall_buffer = &linux_privcmd_free_hypercall_buffer,
+
.hypercall = &linux_privcmd_hypercall,
.map_foreign_batch = &linux_privcmd_map_foreign_batch,