@@ -64,6 +64,7 @@ stubdom/libs-*
stubdom/libxc-*
stubdom/libxencall-*
stubdom/libxenevtchn-*
+stubdom/libxenforeignmemory-*
stubdom/libxengnttab-*
stubdom/libxentoollog-*
stubdom/lwip-*
@@ -93,6 +94,7 @@ tools/libs/toollog/headers.chk
tools/libs/evtchn/headers.chk
tools/libs/gnttab/headers.chk
tools/libs/call/headers.chk
+tools/libs/foreignmemory/headers.chk
tools/blktap2/daemon/blktapctrl
tools/blktap2/drivers/img2qcow
tools/blktap2/drivers/lock-util
@@ -337,6 +337,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
ln -sf $(XEN_ROOT)/tools/libs/call/include/*.h include/ && \
ln -sf $(XEN_ROOT)/tools/libs/call/*.c . && \
ln -sf $(XEN_ROOT)/tools/libs/call/Makefile . )
+ mkdir -p libs-$(XEN_TARGET_ARCH)/foreignmemory/include
+ [ -h libs-$(XEN_TARGET_ARCH)/foreignmemory/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/foreignmemory && \
+ ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/*.h . && \
+ ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/include/*.h include/ && \
+ ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/*.c . && \
+ ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/Makefile . )
mkdir -p libxc-$(XEN_TARGET_ARCH)
[ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \
ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -396,12 +402,21 @@ libs-$(XEN_TARGET_ARCH)/call/libxencall.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLI
CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call
#######
+# libxenforeignmemory
+#######
+
+.PHONY: libxenforeignmemory
+libxenforeignmemory: libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a
+libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
+ CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/foreignmemory
+
+#######
# libxc
#######
.PHONY: libxc
libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab libxencall cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab libxencall libxenforeignmemory cross-zlib
CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
@@ -250,6 +250,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
--source-path=$$source \
--extra-cflags="-DXC_WANT_COMPAT_EVTCHN_API=1 \
-DXC_WANT_COMPAT_GNTTAB_API=1 \
+ -DXC_WANT_COMPAT_MAP_FOREIGN_API=1 \
-I$(XEN_ROOT)/tools/include \
-I$(XEN_ROOT)/tools/libs/toollog/include \
-I$(XEN_ROOT)/tools/libs/evtchn/include \
@@ -264,6 +265,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \
-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/gnttab \
-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/call \
+ -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/foreignmemory \
$(QEMU_UPSTREAM_RPATH)" \
--bindir=$(LIBEXEC_BIN) \
--datadir=$(SHAREDIR)/qemu-xen \
@@ -14,6 +14,7 @@ XEN_LIBXENTOOLLOG = $(XEN_ROOT)/tools/libs/toollog
XEN_LIBXENEVTCHN = $(XEN_ROOT)/tools/libs/evtchn
XEN_LIBXENGNTTAB = $(XEN_ROOT)/tools/libs/gnttab
XEN_LIBXENCALL = $(XEN_ROOT)/tools/libs/call
+XEN_LIBXENFOREIGNMEMORY = $(XEN_ROOT)/tools/libs/foreignmemory
XEN_LIBXC = $(XEN_ROOT)/tools/libxc
XEN_XENLIGHT = $(XEN_ROOT)/tools/libxl
XEN_XENSTORE = $(XEN_ROOT)/tools/xenstore
@@ -103,12 +104,16 @@ CFLAGS_libxencall = -I$(XEN_LIBXENCALL)/include $(CFLAGS_xeninclude)
LDLIBS_libxencall = $(XEN_LIBXENCALL)/libxencall$(libextension)
SHLIB_libxencall = -Wl,-rpath-link=$(XEN_LIBXENCALL)
-CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_xeninclude)
-SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr) $(SHLIB_libxencall)
+CFLAGS_libxenforeignmemory = -I$(XEN_LIBXENFOREIGNMEMORY)/include $(CFLAGS_xeninclude)
+LDLIBS_libxenforeignmemory = $(XEN_LIBXENFOREIGNMEMORY)/libxenforeignmemory$(libextension)
+SHLIB_libxenforeignmemory = -Wl,-rpath-link=$(XEN_LIBXENFOREIGNMEMORY)
+
+CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_xeninclude)
+SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr) $(SHLIB_libxencall) $(SHLIB_libxenforeignmemory)
LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_LIBXC)/libxenctrl$(libextension)
SHLIB_libxenctrl = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_LIBXC)
-CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_libxenevtchn) $(CFLAGS_xeninclude)
+CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_libxenevtchn) $(CFLAGS_libxenforeignmemory) $(CFLAGS_xeninclude)
SHDEPS_libxenguest = $(SHLIB_libxenevtchn)
LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_LIBXC)/libxenguest$(libextension)
SHLIB_libxenguest = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_LIBXC)
@@ -33,7 +33,6 @@
#include <string.h>
#include <signal.h>
-#include "xenctrl.h"
#include "utils.h"
struct xs_handle *xs;
@@ -23,6 +23,7 @@
#include <stdbool.h>
#include <syslog.h>
#include <stdio.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
#include <xenctrl.h>
#include <xenstore.h>
@@ -6,5 +6,6 @@ SUBDIRS-y += toollog
SUBDIRS-y += evtchn
SUBDIRS-y += gnttab
SUBDIRS-y += call
+SUBDIRS-y += foreignmemory
all clean install distclean: %: subdirs-%
new file mode 100644
@@ -0,0 +1,71 @@
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+MAJOR = 1
+MINOR = 0
+SHLIB_LDFLAGS += -Wl,--version-script=libxenforeignmemory.map
+
+CFLAGS += -Werror -Wmissing-prototypes
+CFLAGS += -I./include $(CFLAGS_xeninclude)
+CFLAGS += $(CFLAGS_libxentoollog)
+
+SRCS-y += core.c
+SRCS-$(CONFIG_Linux) += linux.c
+SRCS-$(CONFIG_FreeBSD) += freebsd.c
+SRCS-$(CONFIG_SunOS) += compat.c solaris.c
+SRCS-$(CONFIG_NetBSD) += compat.c netbsd.c
+SRCS-$(CONFIG_MiniOS) += minios.c
+
+LIB_OBJS := $(patsubst %.c,%.o,$(SRCS-y))
+PIC_OBJS := $(patsubst %.c,%.opic,$(SRCS-y))
+
+LIB := libxenforeignmemory.a
+ifneq ($(nosharedlibs),y)
+LIB += libxenforeignmemory.so
+endif
+
+.PHONY: all
+all: build
+
+.PHONY: build
+build:
+ $(MAKE) libs
+
+.PHONY: libs
+libs: headers.chk $(LIB)
+
+headers.chk: $(wildcard include/*.h)
+
+libxenforeignmemory.a: $(LIB_OBJS)
+ $(AR) rc $@ $^
+
+libxenforeignmemory.so: libxenforeignmemory.so.$(MAJOR)
+ $(SYMLINK_SHLIB) $< $@
+libxenforeignmemory.so.$(MAJOR): libxenforeignmemory.so.$(MAJOR).$(MINOR)
+ $(SYMLINK_SHLIB) $< $@
+
+libxenforeignmemory.so.$(MAJOR).$(MINOR): $(PIC_OBJS) libxenforeignmemory.map
+ $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenforeignmemory.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) $(LDLIBS_libxentoollog) $(APPEND_LDFLAGS)
+
+.PHONY: install
+install: build
+ $(INSTALL_DIR) $(DESTDIR)$(libdir)
+ $(INSTALL_DIR) $(DESTDIR)$(includedir)
+ $(INSTALL_SHLIB) libxenforeignmemory.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
+ $(INSTALL_DATA) libxenforeignmemory.a $(DESTDIR)$(libdir)
+ $(SYMLINK_SHLIB) libxenforeignmemory.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenforeignmemory.so.$(MAJOR)
+ $(SYMLINK_SHLIB) libxenforeignmemory.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenforeignmemory.so
+ $(INSTALL_DATA) include/xenforeignmemory.h $(DESTDIR)$(includedir)
+
+.PHONY: TAGS
+TAGS:
+ etags -t *.c *.h
+
+.PHONY: clean
+clean:
+ rm -rf *.rpm $(LIB) *~ $(DEPS) $(LIB_OBJS) $(PIC_OBJS)
+ rm -f libxenforeignmemory.so.$(MAJOR).$(MINOR) libxenforeignmemory.so.$(MAJOR)
+ rm -f headers.chk
+
+.PHONY: distclean
+distclean: clean
new file mode 100644
@@ -0,0 +1,72 @@
+/* Compatibility functions for mapping foreign domain's memory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Split out from xc_foreign_memory.c
+ */
+#if !defined(__NetBSD__) && !defined(__sun__)
+#error Please implement osdep_xenforeignmemory_map directly for new ports.
+#endif
+
+#include "private.h"
+
+void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
+ uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num)
+{
+ xen_pfn_t *pfn;
+ unsigned int i;
+ void *ret;
+
+ if ((int)num <= 0) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ pfn = malloc(num * sizeof(*pfn));
+ if (!pfn) {
+ errno = ENOMEM;
+ return NULL;
+ }
+
+ memcpy(pfn, arr, num * sizeof(*arr));
+ ret = osdep_map_foreign_batch(fmem, dom, prot, pfn, num);
+
+ if (ret) {
+ for (i = 0; i < num; ++i)
+ switch (pfn[i] ^ arr[i]) {
+ case 0:
+ err[i] = 0;
+ break;
+ default:
+ err[i] = -EINVAL;
+ break;
+ }
+ } else
+ memset(err, 0, num * sizeof(*err));
+
+ free(pfn);
+
+ return ret;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
new file mode 100644
@@ -0,0 +1,84 @@
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+
+#include "private.h"
+
+xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger,
+ unsigned open_flags)
+{
+ xenforeignmemory_handle *fmem = malloc(sizeof(*fmem));
+ int rc;
+
+ if (!fmem) return NULL;
+
+ fmem->logger = logger;
+ fmem->logger_tofree = NULL;
+
+ if (!fmem->logger) {
+ fmem->logger = fmem->logger_tofree =
+ (xentoollog_logger*)
+ xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
+ if (!fmem->logger) goto err;
+ }
+
+ rc = osdep_xenforeignmemory_open(fmem);
+ if ( rc < 0 ) goto err;
+
+ return fmem;
+
+err:
+ osdep_xenforeignmemory_close(fmem);
+ xtl_logger_destroy(fmem->logger_tofree);
+ free(fmem);
+ return NULL;
+}
+
+int xenforeignmemory_close(xenforeignmemory_handle *fmem)
+{
+ int rc;
+
+ if ( !fmem )
+ return 0;
+
+ rc = osdep_xenforeignmemory_close(fmem);
+ xtl_logger_destroy(fmem->logger_tofree);
+ free(fmem);
+ return rc;
+}
+
+void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
+ uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, size_t num)
+{
+ return osdep_xenforeignmemory_map(fmem, dom, prot, arr, err, num);
+}
+
+int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+ void *addr, size_t num)
+{
+ return osdep_xenforeignmemory_unmap(fmem, addr, num);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
similarity index 76%
rename from tools/libxc/xc_freebsd_osdep.c
rename to tools/libs/foreignmemory/freebsd.c
@@ -3,9 +3,6 @@
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
- * xc_gnttab functions:
- * Copyright (c) 2007-2008, D G Murray <Derek.Murray@cl.cam.ac.uk>
- *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
@@ -30,14 +27,11 @@
#include <sys/mman.h>
#include <sys/ioctl.h>
-#include <xen/memory.h>
-
-#include "xc_private.h"
+#include "private.h"
#define PRIVCMD_DEV "/dev/xen/privcmd"
-/*------------------------- Privcmd device interface -------------------------*/
-int osdep_privcmd_open(xc_interface *xch)
+int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem)
{
int flags, saved_errno;
int fd = open(PRIVCMD_DEV, O_RDWR);
@@ -46,7 +40,7 @@ int osdep_privcmd_open(xc_interface *xch)
{
PERROR("Could not obtain handle on privileged command interface "
PRIVCMD_DEV);
- return -1
+ return -1;
}
/*
@@ -69,7 +63,7 @@ int osdep_privcmd_open(xc_interface *xch)
goto error;
}
- xch->privcmdfd = fd;
+ fmem->fd = fd;
return 0;
error:
@@ -80,26 +74,25 @@ int osdep_privcmd_open(xc_interface *xch)
return -1;
}
-int osdep_privcmd_close(xc_interface *xch)
+int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
{
- int fd = xch->privcmdfd;
+ int fd = fmem->fd;
if ( fd == -1 )
return 0;
return close(fd);
}
-/*----------------------- Privcmd foreign map interface ----------------------*/
-void *xc_map_foreign_bulk(xc_interface *xch,
- uint32_t dom, int prot,
- const xen_pfn_t *arr, int *err,
- unsigned int num)
+void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
+ uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err,
+ unsigned int num)
{
- int fd = xch->privcmdfd;
+ int fd = fmem->fd;
privcmd_mmapbatch_t ioctlx;
void *addr;
int rc;
- addr = mmap(NULL, num << XC_PAGE_SHIFT, prot, MAP_SHARED, fd, 0);
+ addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, fd, 0);
if ( addr == MAP_FAILED )
{
PERROR("xc_map_foreign_bulk: mmap failed");
@@ -117,7 +110,7 @@ void *xc_map_foreign_bulk(xc_interface *xch,
{
int saved_errno = errno;
PERROR("xc_map_foreign_bulk: ioctl failed");
- (void)munmap(addr, num << XC_PAGE_SHIFT);
+ (void)munmap(addr, num << PAGE_SHIFT);
errno = saved_errno;
return NULL;
}
new file mode 100644
@@ -0,0 +1,71 @@
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef XENFOREIGNMEMORY_H
+#define XENFOREIGNMEMORY_H
+
+/*
+ * This library allows you to map foreign domain memory, subject to
+ * permissions for both the process and the domain in which the
+ * process runs.
+ */
+
+#include <stdint.h>
+#include <stddef.h>
+
+#include <xen/xen.h>
+
+/* Callers who don't care don't need to #include <xentoollog.h> */
+typedef struct xentoollog_logger xentoollog_logger;
+
+typedef struct xenforeignmemory_handle xenforeignmemory_handle;
+
+/*
+ * Return a handle onto the hypercall driver. Logs errors.
+ */
+xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger,
+ unsigned open_flags);
+
+/*
+ * Close a handle previously allocated with xenforeignmemory_open().
+ */
+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.
+ *
+ * prot is as for mmap(2).
+ *
+ * Can partially succeed. When a page cannot be mapped, its respective
+ * field in @err is set to the corresponding errno value.
+ *
+ * Returns NULL if no pages can be mapped.
+ */
+void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom,
+ int prot, const xen_pfn_t *arr, int *err,
+ unsigned int num);
+
+#endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
new file mode 100644
@@ -0,0 +1,7 @@
+VERS_1.0 {
+ global:
+ xenforeignmemory_open;
+ xenforeignmemory_close;
+ xenforeignmemory_map;
+ local: *; /* Do not expose anything by default */
+};
similarity index 83%
rename from tools/libxc/xc_linux_osdep.c
rename to tools/libs/foreignmemory/linux.c
@@ -1,11 +1,4 @@
- /******************************************************************************
- *
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- *
- * xc_gnttab functions:
- * Copyright (c) 2007-2008, D G Murray <Derek.Murray@cl.cam.ac.uk>
- *
+/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
@@ -18,27 +11,26 @@
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Split out from xc_linus_osdep.c:
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
*/
+#include <alloca.h>
#include <errno.h>
#include <fcntl.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
#include <unistd.h>
+#include <string.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
-#include <xen/memory.h>
-
-#include "xenctrl.h"
-
-#include "xc_private.h"
+#include "private.h"
#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
-int osdep_privcmd_open(xc_interface *xch)
+int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem)
{
int flags, saved_errno;
int fd = open("/dev/xen/privcmd", O_RDWR); /* prefer this newer interface */
@@ -73,7 +65,7 @@ int osdep_privcmd_open(xc_interface *xch)
goto error;
}
- xch->privcmdfd = fd;
+ fmem->fd = fd;
return 0;
error:
@@ -83,9 +75,9 @@ int osdep_privcmd_open(xc_interface *xch)
return -1;
}
-int osdep_privcmd_close(xc_interface *xch)
+int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
{
- int fd = xch->privcmdfd;
+ int fd = fmem->fd;
if (fd == -1)
return 0;
return close(fd);
@@ -127,7 +119,7 @@ static int retry_paged(int fd, uint32_t dom, void *addr,
{
privcmd_mmapbatch_v2_t ioctlx;
int rc, paged = 0, i = 0;
-
+
do
{
/* Skip gfns not in paging state */
@@ -142,10 +134,10 @@ static int retry_paged(int fd, uint32_t dom, void *addr,
/* At least one gfn is still in paging state */
ioctlx.num = 1;
ioctlx.dom = dom;
- ioctlx.addr = (unsigned long)addr + ((unsigned long)i<<XC_PAGE_SHIFT);
+ ioctlx.addr = (unsigned long)addr + ((unsigned long)i<<PAGE_SHIFT);
ioctlx.arr = arr + i;
ioctlx.err = err + i;
-
+
/* Assemble a batch of requests */
while ( ++i < num )
{
@@ -153,34 +145,34 @@ static int retry_paged(int fd, uint32_t dom, void *addr,
break;
ioctlx.num++;
}
-
+
/* Send request and abort on fatal error */
rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
if ( rc < 0 && errno != ENOENT )
goto out;
} while ( i < num );
-
+
rc = paged;
out:
return rc;
}
-void *xc_map_foreign_bulk(xc_interface *xch,
- uint32_t dom, int prot,
- const xen_pfn_t *arr, int *err, unsigned int num)
+void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
+ uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num)
{
- int fd = xch->privcmdfd;
+ int fd = fmem->fd;
privcmd_mmapbatch_v2_t ioctlx;
void *addr;
unsigned int i;
int rc;
- addr = mmap(NULL, (unsigned long)num << XC_PAGE_SHIFT, prot, MAP_SHARED,
+ addr = mmap(NULL, (unsigned long)num << PAGE_SHIFT, prot, MAP_SHARED,
fd, 0);
if ( addr == MAP_FAILED )
{
- PERROR("xc_map_foreign_bulk: mmap failed");
+ PERROR("mmap failed");
return NULL;
}
@@ -209,9 +201,9 @@ void *xc_map_foreign_bulk(xc_interface *xch,
*/
privcmd_mmapbatch_t ioctlx;
xen_pfn_t *pfn;
- unsigned int pfn_arr_size = ROUNDUP((num * sizeof(*pfn)), XC_PAGE_SHIFT);
+ unsigned int pfn_arr_size = ROUNDUP((num * sizeof(*pfn)), PAGE_SHIFT);
- if ( pfn_arr_size <= XC_PAGE_SIZE )
+ if ( pfn_arr_size <= PAGE_SIZE )
pfn = alloca(num * sizeof(*pfn));
else
{
@@ -219,8 +211,8 @@ void *xc_map_foreign_bulk(xc_interface *xch,
MAP_PRIVATE | MAP_ANON | MAP_POPULATE, -1, 0);
if ( pfn == MAP_FAILED )
{
- PERROR("xc_map_foreign_bulk: mmap of pfn array failed");
- (void)munmap(addr, (unsigned long)num << XC_PAGE_SHIFT);
+ PERROR("mmap of pfn array failed");
+ (void)munmap(addr, (unsigned long)num << PAGE_SHIFT);
return NULL;
}
}
@@ -253,7 +245,7 @@ void *xc_map_foreign_bulk(xc_interface *xch,
continue;
}
rc = map_foreign_batch_single(fd, dom, pfn + i,
- (unsigned long)addr + ((unsigned long)i<<XC_PAGE_SHIFT));
+ (unsigned long)addr + ((unsigned long)i<<PAGE_SHIFT));
if ( rc < 0 )
{
rc = -errno;
@@ -265,7 +257,7 @@ void *xc_map_foreign_bulk(xc_interface *xch,
break;
}
- if ( pfn_arr_size > XC_PAGE_SIZE )
+ if ( pfn_arr_size > PAGE_SIZE )
munmap(pfn, pfn_arr_size);
if ( rc == -ENOENT && i == num )
@@ -281,8 +273,8 @@ void *xc_map_foreign_bulk(xc_interface *xch,
{
int saved_errno = errno;
- PERROR("xc_map_foreign_bulk: ioctl failed");
- (void)munmap(addr, (unsigned long)num << XC_PAGE_SHIFT);
+ PERROR("ioctl failed");
+ (void)munmap(addr, (unsigned long)num << PAGE_SHIFT);
errno = saved_errno;
return NULL;
}
new file mode 100644
@@ -0,0 +1,62 @@
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Split out from xc_minios.c
+ *
+ * Copyright 2007-2008 Samuel Thibault <samuel.thibault@eu.citrix.com>.
+ */
+
+#include <mini-os/types.h>
+#include <mini-os/os.h>
+#include <mini-os/mm.h>
+#include <mini-os/lib.h>
+
+#include <errno.h>
+
+#include <sys/mman.h>
+
+#include "private.h"
+
+int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem)
+{
+ /* No fd required */
+ return 0;
+}
+
+int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
+{
+ return 0;
+}
+
+void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
+ uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num)
+{
+ unsigned long pt_prot = 0;
+ if (prot & PROT_READ)
+ pt_prot = L1_PROT_RO;
+ if (prot & PROT_WRITE)
+ pt_prot = L1_PROT;
+ return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
new file mode 100644
@@ -0,0 +1,105 @@
+/******************************************************************************
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#include "private.h"
+
+int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem)
+{
+ int flags, saved_errno;
+ int fd = open("/kern/xen/privcmd", O_RDWR);
+
+ if ( fd == -1 )
+ {
+ PERROR("Could not obtain handle on privileged command interface");
+ return -1;
+ }
+
+ /* Although we return the file handle as the 'xc handle' the API
+ does not specify / guarentee that this integer is in fact
+ a file handle. Thus we must take responsiblity to ensure
+ it doesn't propagate (ie leak) outside the process */
+ if ( (flags = fcntl(fd, F_GETFD)) < 0 )
+ {
+ PERROR("Could not get file handle flags");
+ goto error;
+ }
+ flags |= FD_CLOEXEC;
+ if ( fcntl(fd, F_SETFD, flags) < 0 )
+ {
+ PERROR("Could not set file handle flags");
+ goto error;
+ }
+
+ fmem->fd = fd;
+ return 0;
+
+ error:
+ saved_errno = errno;
+ close(fd);
+ errno = saved_errno;
+ return -1;
+}
+
+int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
+{
+ int fd = fmem->fd;
+ return close(fd);
+}
+
+void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom,
+ int prot, 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);
+ if ( addr == MAP_FAILED ) {
+ PERROR("osdep_map_foreign_batch: mmap failed");
+ return NULL;
+ }
+
+ ioctlx.num=num;
+ ioctlx.dom=dom;
+ ioctlx.addr=(unsigned long)addr;
+ ioctlx.arr=arr;
+ if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
+ {
+ int saved_errno = errno;
+ PERROR("osdep_map_foreign_batch: ioctl failed");
+ (void)munmap(addr, num*XC_PAGE_SIZE);
+ errno = saved_errno;
+ return NULL;
+ }
+ return addr;
+
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
new file mode 100644
@@ -0,0 +1,53 @@
+#ifndef XENFOREIGNMEMORY_PRIVATE_H
+#define XENFOREIGNMEMORY_PRIVATE_H
+
+#include <xentoollog.h>
+
+#include <xenforeignmemory.h>
+
+#include <xen/xen.h>
+#include <xen/sys/privcmd.h>
+
+#ifndef PAGE_SHIFT /* Mini-os, Yukk */
+#define PAGE_SHIFT 12
+#endif
+#ifndef __MINIOS__ /* Yukk */
+#define PAGE_SIZE (1UL << PAGE_SHIFT)
+#define PAGE_MASK (~(PAGE_SIZE-1))
+#endif
+
+struct xenforeignmemory_handle {
+ xentoollog_logger *logger, *logger_tofree;
+ unsigned flags;
+ int fd;
+};
+
+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,
+ const xen_pfn_t *arr, int *err, size_t num);
+int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+ void *addr, size_t num);
+
+#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);
+#endif
+
+#define PERROR(_f...) \
+ xtl_log(fmem->logger, XTL_ERROR, errno, "xenforeignmemory", _f)
+
+#endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
new file mode 100644
@@ -0,0 +1,93 @@
+/******************************************************************************
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "xc_private.h"
+
+#include <xen/memory.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <malloc.h>
+
+int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem)
+{
+ int flags, saved_errno;
+ int fd = open("/dev/xen/privcmd", O_RDWR);
+
+ if ( fd == -1 )
+ {
+ PERROR("Could not obtain handle on privileged command interface");
+ return -1;
+ }
+
+ /* Although we return the file handle as the 'xc handle' the API
+ does not specify / guarentee that this integer is in fact
+ a file handle. Thus we must take responsiblity to ensure
+ it doesn't propagate (ie leak) outside the process */
+ if ( (flags = fcntl(fd, F_GETFD)) < 0 )
+ {
+ PERROR("Could not get file handle flags");
+ goto error;
+ }
+ flags |= FD_CLOEXEC;
+ if ( fcntl(fd, F_SETFD, flags) < 0 )
+ {
+ PERROR("Could not set file handle flags");
+ goto error;
+ }
+
+ fmem->fd = fd;
+ return 0;
+
+ error:
+ saved_errno = errno;
+ close(fd);
+ errno = saved_errno;
+ return -1;
+}
+
+int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
+{
+ int fd = fmem->fd;
+ return close(fd);
+}
+
+void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom,
+ int prot, 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);
+ if ( addr == MAP_FAILED )
+ return NULL;
+
+ ioctlx.num=num;
+ ioctlx.dom=dom;
+ ioctlx.addr=(unsigned long)addr;
+ ioctlx.arr=arr;
+ if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
+ {
+ int saved_errno = errno;
+ PERROR("XXXXXXXX");
+ (void)munmap(addr, num*XC_PAGE_SIZE);
+ errno = saved_errno;
+ return NULL;
+ }
+ return addr;
+}
@@ -42,8 +42,8 @@ CTRL_SRCS-y += xc_kexec.c
CTRL_SRCS-y += xc_resource.c
CTRL_SRCS-$(CONFIG_X86) += xc_psr.c
CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
-CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c
-CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c
+CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c
+CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c
CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c
@@ -125,7 +125,7 @@ $(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.
# libxenguest includes xc_private.h, so needs this despite not using
# this functionality directly.
$(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) \
-$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += $(CFLAGS_libxencall)
+$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += $(CFLAGS_libxencall) $(CFLAGS_libxenforeignmemory)
$(CTRL_LIB_OBJS) $(CTRL_PIC_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxengntshr)
@@ -207,7 +207,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR)
$(SYMLINK_SHLIB) $< $@
libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
- $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(LDLIBS_libxencall) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
+ $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(LDLIBS_libxencall) $(LDLIBS_libxenforeignmemory) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
# libxenguest
@@ -1369,32 +1369,6 @@ int xc_lockprof_query(xc_interface *xch,
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
- * regarding page alignment. Returns NULL on failure.
- *
- * @parm xch a handle on an open hypervisor interface
- * @parm dom the domain to map memory from
- * @parm size the amount of memory to map (in multiples of page size)
- * @parm prot same flag as in mmap().
- * @parm mfn the frame address to map.
- */
-void *xc_map_foreign_range(xc_interface *xch, uint32_t dom,
- int size, int prot,
- unsigned long mfn );
-
-void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
- const xen_pfn_t *arr, int num );
-
-/**
- * Like xc_map_foreign_pages(), except it can succeed partially.
- * When a page cannot be mapped, its respective field in @err is
- * set to the corresponding errno value.
- */
-void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
- const xen_pfn_t *arr, int *err, unsigned int num);
-
-/**
* Translates a virtual address in the context of a given domain and
* vcpu returning the GFN containing the address (that is, an MFN for
* PV guests, a PFN for HVM guests). Returns 0 for failure.
@@ -12,6 +12,42 @@
#ifndef XENCTRL_COMPAT_H
#define XENCTRL_COMPAT_H
+#ifdef XC_WANT_COMPAT_MAP_FOREIGN_API
+/**
+ * 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
+ * regarding page alignment. Returns NULL on failure.
+ *
+ * @parm xch a handle on an open hypervisor interface
+ * @parm dom the domain to map memory from
+ * @parm size the amount of memory to map (in multiples of page size)
+ * @parm prot same flag as in mmap().
+ * @parm mfn the frame address to map.
+ */
+void *xc_map_foreign_range(xc_interface *xch, uint32_t dom,
+ int size, int prot,
+ unsigned long mfn );
+
+void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
+ const xen_pfn_t *arr, int num );
+
+/* Nothing within the library itself other than the compat wrapper
+ * itself should be using this, everything inside has access to
+ * xenforeignmemory_map().
+ */
+#if !defined(XC_INTERNAL_COMPAT_MAP_FOREIGN_API) || \
+ defined(XC_BUILDING_COMPAT_MAP_FOREIGN_API)
+/**
+ * Like xc_map_foreign_pages(), except it can succeed partially.
+ * When a page cannot be mapped, its respective field in @err is
+ * set to the corresponding errno value.
+ */
+void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num);
+#endif
+
+#endif
+
#ifdef XC_WANT_COMPAT_EVTCHN_API
typedef struct xenevtchn_handle xc_evtchn;
@@ -17,6 +17,7 @@
* License along with this library; If not, see <http://www.gnu.org/licenses/>.
*/
+#define XC_BUILDING_COMPAT_MAP_FOREIGN_API
#include "xc_private.h"
void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
@@ -34,7 +35,7 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
if (!err)
return NULL;
- res = xc_map_foreign_bulk(xch, dom, prot, arr, err, num);
+ res = xenforeignmemory_map(xch->fmem, dom, prot, arr, err, num);
if (res) {
for (i = 0; i < num; i++) {
if (err[i]) {
@@ -100,53 +101,11 @@ void *xc_map_foreign_ranges(xc_interface *xch,
return ret;
}
-/*
- * stub for all not yet converted OSes (NetBSD and Solaris). New OSes should
- * just implement xc_map_foreign_bulk.
- */
-#if defined(__NetBSD__) || defined(__sun__)
-void *osdep_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
- xen_pfn_t *arr, int num );
-void *xc_map_foreign_bulk(xc_interface *xch,
- uint32_t dom, int prot,
+void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
const xen_pfn_t *arr, int *err, unsigned int num)
{
- xen_pfn_t *pfn;
- unsigned int i;
- void *ret;
-
- if ((int)num <= 0) {
- errno = EINVAL;
- return NULL;
- }
-
- pfn = malloc(num * sizeof(*pfn));
- if (!pfn) {
- errno = ENOMEM;
- return NULL;
- }
-
- memcpy(pfn, arr, num * sizeof(*arr));
- ret = osdep_map_foreign_batch(xch, dom, prot, pfn, num);
-
- if (ret) {
- for (i = 0; i < num; ++i)
- switch (pfn[i] ^ arr[i]) {
- case 0:
- err[i] = 0;
- break;
- default:
- err[i] = -EINVAL;
- break;
- }
- } else
- memset(err, 0, num * sizeof(*err));
-
- free(pfn);
-
- return ret;
+ return xenforeignmemory_map(xch->fmem, dom, prot, arr, err, num);
}
-#endif
/*
* Local variables:
@@ -39,40 +39,11 @@ void minios_interface_close_fd(int fd);
extern void minios_interface_close_fd(int fd);
-int osdep_privcmd_open(xc_interface *xch)
-{
- int fd = alloc_fd(FTYPE_XC);
-
- if ( fd == -1)
- return -1;
-
- xch->privcmdfd = fd;
- return 0;
-}
-
-int osdep_privcmd_close(xc_interface *xch)
-{
- int fd = xch->privcmdfd;
- return close(fd);
-}
-
void minios_interface_close_fd(int fd)
{
files[fd].type = FTYPE_NONE;
}
-void *xc_map_foreign_bulk(xc_interface *xch,
- uint32_t dom, int prot,
- const xen_pfn_t *arr, int *err, unsigned int num)
-{
- unsigned long pt_prot = 0;
- if (prot & PROT_READ)
- pt_prot = L1_PROT_RO;
- if (prot & PROT_WRITE)
- pt_prot = L1_PROT;
- return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
-}
-
/* Optionally flush file to disk and discard page cache */
void discard_file_cache(xc_interface *xch, int fd, int flush)
{
@@ -22,79 +22,6 @@
#include <unistd.h>
#include <fcntl.h>
#include <malloc.h>
-#include <sys/mman.h>
-
-int osdep_privcmd_open(xc_interface *xch)
-{
- int flags, saved_errno;
- int fd = open("/kern/xen/privcmd", O_RDWR);
-
- if ( fd == -1 )
- {
- PERROR("Could not obtain handle on privileged command interface");
- return -1;
- }
-
- /* Although we return the file handle as the 'xc handle' the API
- does not specify / guarentee that this integer is in fact
- a file handle. Thus we must take responsiblity to ensure
- it doesn't propagate (ie leak) outside the process */
- if ( (flags = fcntl(fd, F_GETFD)) < 0 )
- {
- PERROR("Could not get file handle flags");
- goto error;
- }
- flags |= FD_CLOEXEC;
- if ( fcntl(fd, F_SETFD, flags) < 0 )
- {
- PERROR("Could not set file handle flags");
- goto error;
- }
-
- xch->privcmdfd = fd;
- return 0;
-
- error:
- saved_errno = errno;
- close(fd);
- errno = saved_errno;
- return -1;
-}
-
-int osdep_privcmd_close(xc_interface *xch)
-{
- int fd = xch->privcmdfd;
- return close(fd);
-}
-
-void *osdep_map_foreign_batch(xc_interface *xch,
- uint32_t dom, int prot,
- xen_pfn_t *arr, int num)
-{
- int fd = xch->privcmdfd;
- privcmd_mmapbatch_t ioctlx;
- void *addr;
- addr = mmap(NULL, num*XC_PAGE_SIZE, prot, MAP_ANON | MAP_SHARED, -1, 0);
- if ( addr == MAP_FAILED ) {
- PERROR("osdep_map_foreign_batch: mmap failed");
- return NULL;
- }
-
- ioctlx.num=num;
- ioctlx.dom=dom;
- ioctlx.addr=(unsigned long)addr;
- ioctlx.arr=arr;
- if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
- {
- int saved_errno = errno;
- PERROR("osdep_map_foreign_batch: ioctl failed");
- (void)munmap(addr, num*XC_PAGE_SIZE);
- errno = saved_errno;
- return NULL;
- }
- return addr;
-
-}
/* Optionally flush file to disk and discard page cache */
void discard_file_cache(xc_interface *xch, int fd, int flush)
@@ -58,11 +58,12 @@ struct xc_interface_core *xc_interface_open(xentoollog_logger *logger,
if (open_flags & XC_OPENFLAG_DUMMY)
return xch; /* We are done */
- if ( osdep_privcmd_open(xch) < 0 )
- goto err;
-
xch->xcall = xencall_open(xch->error_handler,
open_flags & XC_OPENFLAG_NON_REENTRANT ? XENCALL_OPENFLAG_NON_REENTRANT : 0U);
+ if ( xch->xcall == NULL )
+ goto err;
+
+ xch->fmem = xenforeignmemory_open(xch->error_handler, 0);
if ( xch->xcall == NULL )
goto err;
@@ -70,7 +71,7 @@ struct xc_interface_core *xc_interface_open(xentoollog_logger *logger,
return xch;
err:
- osdep_privcmd_close(xch);
+ xencall_close(xch->xcall);
xtl_logger_destroy(xch->error_handler_tofree);
if (xch != &xch_buf) free(xch);
return NULL;
@@ -86,8 +87,8 @@ int xc_interface_close(xc_interface *xch)
rc = xencall_close(xch->xcall);
if (rc) PERROR("Could not close xencall interface");
- rc = osdep_privcmd_close(xch);
- if (rc) PERROR("Could not close hypervisor interface");
+ rc = xenforeignmemory_close(xch->fmem);
+ if (rc) PERROR("Could not close foreign memory interface");
xtl_logger_destroy(xch->dombuild_logger_tofree);
xtl_logger_destroy(xch->error_handler_tofree);
@@ -29,8 +29,13 @@
#include <sys/ioctl.h>
#include "_paths.h"
+
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
+#define XC_INTERNAL_COMPAT_MAP_FOREIGN_API
#include "xenctrl.h"
+
#include <xencall.h>
+#include <xenforeignmemory.h>
#include <xen/sys/privcmd.h>
@@ -94,11 +99,11 @@ struct xc_interface_core {
FILE *dombuild_logger_file;
const char *currently_progress_reporting;
- /* Privcmd interface */
- int privcmdfd;
-
/* Hypercall interface */
xencall_handle *xcall;
+
+ /* Foreign mappings */
+ xenforeignmemory_handle *fmem;
};
int osdep_privcmd_open(xc_interface *xch);
@@ -19,81 +19,8 @@
#include "xc_private.h"
-#include <xen/memory.h>
-#include <unistd.h>
-#include <fcntl.h>
#include <malloc.h>
-int osdep_privcmd_open(xc_interface *xch)
-{
- int flags, saved_errno;
- int fd = open("/dev/xen/privcmd", O_RDWR);
-
- if ( fd == -1 )
- {
- PERROR("Could not obtain handle on privileged command interface");
- return -1;
- }
-
- /* Although we return the file handle as the 'xc handle' the API
- does not specify / guarentee that this integer is in fact
- a file handle. Thus we must take responsiblity to ensure
- it doesn't propagate (ie leak) outside the process */
- if ( (flags = fcntl(fd, F_GETFD)) < 0 )
- {
- PERROR("Could not get file handle flags");
- goto error;
- }
- flags |= FD_CLOEXEC;
- if ( fcntl(fd, F_SETFD, flags) < 0 )
- {
- PERROR("Could not set file handle flags");
- goto error;
- }
-
- xch->privcmdfd = fd;
- return 0;
-
- error:
- saved_errno = errno;
- close(fd);
- errno = saved_errno;
- return -1;
-}
-
-int osdep_privcmd_close(xc_interface *xch)
-{
- int fd = xch->privcmdfd;
- return close(fd);
-}
-
-void *osdep_map_foreign_batch(xc_interface *xch,
- uint32_t dom, int prot,
- xen_pfn_t *arr, int num)
-{
- int fd = xch->privcmdfd;
- privcmd_mmapbatch_t ioctlx;
- void *addr;
- addr = mmap(NULL, num*XC_PAGE_SIZE, prot, MAP_SHARED, fd, 0);
- if ( addr == MAP_FAILED )
- return NULL;
-
- ioctlx.num=num;
- ioctlx.dom=dom;
- ioctlx.addr=(unsigned long)addr;
- ioctlx.arr=arr;
- if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
- {
- int saved_errno = errno;
- PERROR("XXXXXXXX");
- (void)munmap(addr, num*XC_PAGE_SIZE);
- errno = saved_errno;
- return NULL;
- }
- return addr;
-
-}
-
/* Optionally flush file to disk and discard page cache */
void discard_file_cache(xc_interface *xch, int fd, int flush)
{
@@ -316,8 +316,8 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count,
if ( nr_pages == 0 )
goto done;
- mapping = guest_page = xc_map_foreign_bulk(
- xch, ctx->domid, PROT_READ | PROT_WRITE,
+ mapping = guest_page = xenforeignmemory_map(xch->fmem,
+ ctx->domid, PROT_READ | PROT_WRITE,
mfns, map_errs, nr_pages);
if ( !mapping )
{
@@ -153,8 +153,8 @@ static int write_batch(struct xc_sr_context *ctx)
if ( nr_pages > 0 )
{
- guest_mapping = xc_map_foreign_bulk(
- xch, ctx->domid, PROT_READ, mfns, errors, nr_pages);
+ guest_mapping = xenforeignmemory_map(xch->fmem,
+ ctx->domid, PROT_READ, mfns, errors, nr_pages);
if ( !guest_mapping )
{
PERROR("Failed to map guest pages");
@@ -26,9 +26,8 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include "xenctrl.h"
-#include "xenguest.h"
#include "xc_private.h"
+#include "xenguest.h"
#include <xen/memory.h>
#include <xen/elfnote.h>
@@ -50,6 +50,7 @@
#include <xenevtchn.h>
#include <xenstore.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
#include <xenctrl.h>
#include <xenguest.h>
#include <xc_dom.h>
@@ -1,3 +1,4 @@
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
#include <xenctrl.h>
#include <xc_private.h>
#include <xc_core.h>
@@ -29,6 +29,7 @@
#include <stdint.h>
#include <string.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
#include <xenctrl.h>
#include "mmap_stubs.h"
@@ -5,6 +5,7 @@
*/
#include <Python.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
#include <xenctrl.h>
#include <fcntl.h>
#include <netinet/in.h>
@@ -15,6 +16,7 @@
#include <netdb.h>
#include <arpa/inet.h>
+#include <xen/elfnote.h>
#include <xen/tmem.h>
#include "xc_dom.h"
#include <xen/hvm/hvm_info_table.h>
@@ -30,6 +30,7 @@
#include <signal.h>
#include <stdarg.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
#include <xenctrl.h>
#include <xenguest.h>
#include <inttypes.h>
@@ -11,6 +11,7 @@
#include <string.h>
#include <sys/mman.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
#include "xenctrl.h"
static int usage(const char* prog)
@@ -38,6 +38,7 @@
#include <errno.h>
#include <signal.h>
#include <xenevtchn.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
#include <xenctrl.h>
#include <xen/xen.h>
#include <string.h>
@@ -1,6 +1,5 @@
/* Trigger a page-in in a separate thread-of-execution to avoid deadlock */
#include <pthread.h>
-#include <xc_private.h>
#include "xenpaging.h"
struct page_in_args {
@@ -27,7 +27,6 @@
#include <signal.h>
#include <unistd.h>
#include <poll.h>
-#include <xc_private.h>
#include <xenstore.h>
#include <getopt.h>
@@ -25,6 +25,8 @@
#include <xenevtchn.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
+#include <xenctrl.h>
#include <xc_private.h>
#include <xen/event_channel.h>
#include <xen/vm_event.h>
@@ -50,7 +50,6 @@
#include "xenstored_watch.h"
#include "xenstored_transaction.h"
#include "xenstored_domain.h"
-#include "xenctrl.h"
#include "tdb.h"
#include "hashtable.h"
@@ -19,6 +19,7 @@
#ifndef _XENSTORED_CORE_H
#define _XENSTORED_CORE_H
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
#include <xenctrl.h>
#include <xengnttab.h>
@@ -25,7 +25,8 @@
#include <getopt.h>
#include <limits.h>
-#include "xenctrl.h"
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
+#include <xenctrl.h>
#include <xen/foreign/x86_32.h>
#include <xen/foreign/x86_64.h>
#include <xen/hvm/save.h>
@@ -30,6 +30,7 @@
#include <xen/xen.h>
#include <xen/trace.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
#include <xenevtchn.h>
#include <xenctrl.h>