aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxc/xc_netbsd.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_netbsd.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_netbsd.c')
-rw-r--r--tools/libxc/xc_netbsd.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/libxc/xc_netbsd.c b/tools/libxc/xc_netbsd.c
index 8c82e36645..72e1c28517 100644
--- a/tools/libxc/xc_netbsd.c
+++ b/tools/libxc/xc_netbsd.c
@@ -23,6 +23,8 @@
#include <xen/sys/evtchn.h>
#include <unistd.h>
#include <fcntl.h>
+#include <malloc.h>
+#include <sys/mman.h>
static xc_osdep_handle netbsd_privcmd_open(xc_interface *xch)
{
@@ -66,6 +68,28 @@ static int netbsd_privcmd_close(xc_interface *xch, xc_osdep_handle h)
return close(fd);
}
+static void *netbsd_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
+{
+ size_t size = npages * XC_PAGE_SIZE;
+ void *p = valloc(size);
+
+ if (!p)
+ return NULL;
+
+ if ( mlock(p, size) < 0 )
+ {
+ free(p);
+ return NULL;
+ }
+ return p;
+}
+
+static void netbsd_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 netbsd_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
{
int fd = (int)h;
@@ -181,6 +205,9 @@ static struct xc_osdep_ops netbsd_privcmd_ops = {
.close = &netbsd_privcmd_close,
.u.privcmd = {
+ .alloc_hypercall_buffer = &netbsd_privcmd_alloc_hypercall_buffer,
+ .free_hypercall_buffer = &netbsd_privcmd_free_hypercall_buffer,
+
.hypercall = &netbsd_privcmd_hypercall,
.map_foreign_batch = &netbsd_privcmd_map_foreign_batch,