diff options
author | Shriram Rajagopalan <rshriram@cs.ubc.ca> | 2011-12-01 15:35:02 +0000 |
---|---|---|
committer | Shriram Rajagopalan <rshriram@cs.ubc.ca> | 2011-12-01 15:35:02 +0000 |
commit | de869779a0b7c411a69b787ec01b485492b40f32 (patch) | |
tree | f1fb58a194fbb928a560b40f9c8b58b09daa470a /tools/libxc | |
parent | 3a313ac80e9e0316393c8034a32aae34e8f3373c (diff) | |
download | xen-de869779a0b7c411a69b787ec01b485492b40f32.tar.gz xen-de869779a0b7c411a69b787ec01b485492b40f32.tar.bz2 xen-de869779a0b7c411a69b787ec01b485492b40f32.zip |
tools/libxc: introduce xc_memalign in xc_{minios,linux,solaris,netbsd}.c
Move (page aligned) buffer allocations in {os}_privcmd_alloc_hypercall_buffer
into a global function xc_memalign. This API is also used by Remus
compression code to allocate compression caches that need to be page aligned.
Signed-off-by: Shriram Rajagopalan <rshriram@cs.ubc.ca>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Brendan Cully <brendan@cs.ubc.ca>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/libxc')
-rw-r--r-- | tools/libxc/xc_linux.c | 12 | ||||
-rw-r--r-- | tools/libxc/xc_linux_osdep.c | 5 | ||||
-rw-r--r-- | tools/libxc/xc_minios.c | 7 | ||||
-rw-r--r-- | tools/libxc/xc_netbsd.c | 8 | ||||
-rw-r--r-- | tools/libxc/xc_solaris.c | 7 | ||||
-rw-r--r-- | tools/libxc/xenctrl.h | 2 |
6 files changed, 35 insertions, 6 deletions
diff --git a/tools/libxc/xc_linux.c b/tools/libxc/xc_linux.c index 9acf27573e..5504df6cba 100644 --- a/tools/libxc/xc_linux.c +++ b/tools/libxc/xc_linux.c @@ -55,6 +55,18 @@ void discard_file_cache(xc_interface *xch, int fd, int flush) errno = saved_errno; } +void *xc_memalign(xc_interface *xch, size_t alignment, size_t size) +{ + int ret; + void *ptr; + + ret = posix_memalign(&ptr, alignment, size); + if (ret != 0 || !ptr) + return NULL; + + return ptr; +} + /* * Local variables: * mode: C diff --git a/tools/libxc/xc_linux_osdep.c b/tools/libxc/xc_linux_osdep.c index 04059b8126..0da20091db 100644 --- a/tools/libxc/xc_linux_osdep.c +++ b/tools/libxc/xc_linux_osdep.c @@ -91,10 +91,9 @@ static void *linux_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_ha { size_t size = npages * XC_PAGE_SIZE; void *p; - int ret; - ret = posix_memalign(&p, XC_PAGE_SIZE, size); - if (ret != 0 || !p) + p = xc_memalign(xch, XC_PAGE_SIZE, size); + if (!p) return NULL; if ( mlock(p, size) < 0 ) diff --git a/tools/libxc/xc_minios.c b/tools/libxc/xc_minios.c index ff9c0d8d19..8bbfd186d5 100644 --- a/tools/libxc/xc_minios.c +++ b/tools/libxc/xc_minios.c @@ -73,7 +73,7 @@ void minios_interface_close_fd(int fd) static void *minios_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages) { - return memalign(PAGE_SIZE, npages * PAGE_SIZE); + return xc_memalign(xch, PAGE_SIZE, npages * PAGE_SIZE); } static void minios_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages) @@ -437,6 +437,11 @@ void discard_file_cache(xc_interface *xch, int fd, int flush) fsync(fd); } +void *xc_memalign(xc_interface *xch, size_t alignment, size_t size) +{ + return memalign(alignment, size); +} + static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg) { int fd = alloc_fd(FTYPE_GNTMAP); diff --git a/tools/libxc/xc_netbsd.c b/tools/libxc/xc_netbsd.c index 0f49e30ad1..9782a3423a 100644 --- a/tools/libxc/xc_netbsd.c +++ b/tools/libxc/xc_netbsd.c @@ -71,8 +71,9 @@ static int netbsd_privcmd_close(xc_interface *xch, xc_osdep_handle h) 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); + void *p; + p = xc_memalign(xch, XC_PAGE_SIZE, size); if (!p) return NULL; @@ -378,6 +379,11 @@ void discard_file_cache(xc_interface *xch, int fd, int flush) errno = saved_errno; } +void *xc_memalign(xc_interface *xch, size_t alignment, size_t size) +{ + return valloc(size); +} + static struct xc_osdep_ops *netbsd_osdep_init(xc_interface *xch, enum xc_osdep_type type) { switch ( type ) diff --git a/tools/libxc/xc_solaris.c b/tools/libxc/xc_solaris.c index eba4358c9d..497c923ead 100644 --- a/tools/libxc/xc_solaris.c +++ b/tools/libxc/xc_solaris.c @@ -70,7 +70,7 @@ static int solaris_privcmd_close(xc_interface *xch, xc_osdep_handle h) static void *solaris_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages) { - return memalign(XC_PAGE_SIZE, npages * XC_PAGE_SIZE); + return xc_memalign(xch, XC_PAGE_SIZE, npages * XC_PAGE_SIZE); } static void solaris_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages) @@ -314,6 +314,11 @@ void discard_file_cache(xc_interface *xch, int fd, int flush) // TODO: Implement for Solaris! } +void *xc_memalign(xc_interface *xch, size_t alignment, size_t size) +{ + return memalign(alignment, size); +} + static struct xc_osdep_ops *solaris_osdep_init(xc_interface *xch, enum xc_osdep_type type) { switch ( type ) diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index 9e2a4373f4..ee482f28ab 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -1156,6 +1156,8 @@ int xc_lockprof_query(xc_interface *xch, uint64_t *time, xc_hypercall_buffer_t *data); +void *xc_memalign(xc_interface *xch, size_t alignment, size_t size); + /** * Memory 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 |