@@ -2,7 +2,7 @@ XEN_ROOT = $(CURDIR)/../../..
include $(XEN_ROOT)/tools/Rules.mk
MAJOR = 1
-MINOR = 1
+MINOR = 2
SHLIB_LDFLAGS += -Wl,--version-script=libxenforeignmemory.map
CFLAGS += -Werror -Wmissing-prototypes
@@ -21,8 +21,8 @@
#include "private.h"
-void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
- uint32_t dom, int prot, size_t num,
+void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom,
+ void *addr, int prot, int flags, size_t num,
const xen_pfn_t arr[/*num*/], int err[/*num*/])
{
xen_pfn_t *pfn;
@@ -41,7 +41,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
}
memcpy(pfn, arr, num * sizeof(*arr));
- ret = osdep_map_foreign_batch(fmem, dom, prot, pfn, num);
+ ret = osdep_map_foreign_batch(fmem, dom, addr, prot, flags, pfn, num);
if (ret) {
for (i = 0; i < num; ++i)
@@ -63,10 +63,10 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem)
return rc;
}
-void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
- uint32_t dom, int prot,
- size_t num,
- const xen_pfn_t arr[/*num*/], int err[/*num*/])
+void *xenforeignmemory_map2(xenforeignmemory_handle *fmem,
+ uint32_t dom, void *addr,
+ int prot, int flags, size_t num,
+ const xen_pfn_t arr[/*num*/], int err[/*num*/])
{
void *ret;
int *err_to_free = NULL;
@@ -77,7 +77,7 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
if ( err == NULL )
return NULL;
- ret = osdep_xenforeignmemory_map(fmem, dom, prot, num, arr, err);
+ ret = osdep_xenforeignmemory_map(fmem, dom, addr, prot, flags, num, arr, err);
if ( ret && err_to_free )
{
@@ -100,6 +100,14 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
return ret;
}
+void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
+ uint32_t dom, int prot,
+ size_t num,
+ const xen_pfn_t arr[/*num*/], int err[/*num*/])
+{
+ return xenforeignmemory_map2(fmem, dom, NULL, prot, 0, num, arr, err);
+}
+
int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
void *addr, size_t num)
{
@@ -55,16 +55,15 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
}
void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
- uint32_t dom, int prot,
- size_t num,
+ uint32_t dom, void *addr,
+ int prot, int flags, size_t num,
const xen_pfn_t arr[/*num*/], int err[/*num*/])
{
int fd = fmem->fd;
privcmd_mmapbatch_t ioctlx;
- void *addr;
int rc;
- addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, fd, 0);
+ addr = mmap(addr, num << PAGE_SHIFT, prot, flags | MAP_SHARED, fd, 0);
if ( addr == MAP_FAILED )
{
PERROR("xc_map_foreign_bulk: mmap failed");
@@ -108,6 +108,18 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom,
const xen_pfn_t arr[/*pages*/], int err[/*pages*/]);
/*
+ * Almost like the previous one but also accepts two additional parameters:
+ *
+ * @addr is used as a hint address for foreign map placement (see mmap(2)).
+ * @flags is a set of additional flags as for mmap(2). Not all of the flag
+ * combinations are possible due to implementation details on different
+ * platforms.
+ */
+void *xenforeignmemory_map2(xenforeignmemory_handle *fmem, uint32_t dom,
+ void *addr, int prot, int flags, size_t pages,
+ const xen_pfn_t arr[/*pages*/], int err[/*pages*/]);
+
+/*
* Unmap a mapping previous created with xenforeignmemory_map().
*
* Returns 0 on success on failure sets errno and returns -1.
@@ -10,3 +10,7 @@ VERS_1.1 {
global:
xenforeignmemory_restrict;
} VERS_1.0;
+VERS_1.2 {
+ global:
+ xenforeignmemory_map2;
+} VERS_1.1;
@@ -142,17 +142,16 @@ out:
}
void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
- uint32_t dom, int prot,
- size_t num,
+ uint32_t dom, void *addr,
+ int prot, int flags, size_t num,
const xen_pfn_t arr[/*num*/], int err[/*num*/])
{
int fd = fmem->fd;
privcmd_mmapbatch_v2_t ioctlx;
- void *addr;
size_t i;
int rc;
- addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED,
+ addr = mmap(addr, num << PAGE_SHIFT, prot, flags | MAP_SHARED,
fd, 0);
if ( addr == MAP_FAILED )
{
@@ -40,8 +40,8 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
}
void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
- uint32_t dom, int prot,
- size_t num,
+ uint32_t dom, void *addr,
+ int prot, int flags, size_t num,
const xen_pfn_t arr[/*num*/], int err[/*num*/])
{
unsigned long pt_prot = 0;
@@ -67,12 +67,12 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
}
void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom,
- int prot, xen_pfn_t *arr, int num)
+ void *addr, int prot, int flags,
+ xen_pfn_t *arr, int num)
{
int fd = fmem->fd;
privcmd_mmapbatch_t ioctlx;
- void *addr;
- addr = mmap(NULL, num*XC_PAGE_SIZE, prot, MAP_ANON | MAP_SHARED, -1, 0);
+ addr = mmap(addr, num*XC_PAGE_SIZE, prot, flags | MAP_ANON | MAP_SHARED, -1, 0);
if ( addr == MAP_FAILED ) {
PERROR("osdep_map_foreign_batch: mmap failed");
return NULL;
@@ -26,8 +26,8 @@ int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem);
int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem);
void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
- uint32_t dom, int prot,
- size_t num,
+ uint32_t dom, void *addr,
+ int prot, int flags, size_t num,
const xen_pfn_t arr[num], int err[num]);
int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
void *addr, size_t num);
@@ -38,7 +38,8 @@ int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
#if defined(__NetBSD__) || defined(__sun__)
/* Strictly compat for those two only only */
void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom,
- int prot, xen_pfn_t *arr, int num);
+ void *addr, int prot, int flags,
+ xen_pfn_t *arr, int num);
#endif
#define PERROR(_f...) \
@@ -68,12 +68,11 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
}
void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom,
- int prot, xen_pfn_t *arr, int num)
+ void *addr, int prot, int flags, xen_pfn_t *arr, int num)
{
int fd = fmem->fd;
privcmd_mmapbatch_t ioctlx;
- void *addr;
- addr = mmap(NULL, num*XC_PAGE_SIZE, prot, MAP_SHARED, fd, 0);
+ addr = mmap(addr, num*XC_PAGE_SIZE, prot, flags | MAP_SHARED, fd, 0);
if ( addr == MAP_FAILED )
return NULL;
The new function repeats the behavior of the first version except it has an extended list of arguments which are subsequently passed to mmap() call. This is needed for QEMU depriviledging. Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com> --- Cc: Ian Jackson <ian.jackson@eu.citrix.com> Cc: Wei Liu <wei.liu2@citrix.com> Cc: Andrew Cooper <andrew.cooper3@citrix.com> --- tools/libs/foreignmemory/Makefile | 2 +- tools/libs/foreignmemory/compat.c | 6 +++--- tools/libs/foreignmemory/core.c | 18 +++++++++++++----- tools/libs/foreignmemory/freebsd.c | 7 +++---- tools/libs/foreignmemory/include/xenforeignmemory.h | 12 ++++++++++++ tools/libs/foreignmemory/libxenforeignmemory.map | 4 ++++ tools/libs/foreignmemory/linux.c | 7 +++---- tools/libs/foreignmemory/minios.c | 4 ++-- tools/libs/foreignmemory/netbsd.c | 6 +++--- tools/libs/foreignmemory/private.h | 7 ++++--- tools/libs/foreignmemory/solaris.c | 5 ++--- 11 files changed, 50 insertions(+), 28 deletions(-)