[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] libxc: eliminate static variables, use xentoollog; API change



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1275035419 -3600
# Node ID 779c0ef9682c994d2354844295a1f921cce2857c
# Parent  54eb305da6a8150d8a41fa4b285186feb9ebfccc
libxc: eliminate static variables, use xentoollog; API change

This patch eliminate the global variables in libxenctrl (used for
logging and error reporting).

Instead the information which was in the global variables is now in a
new xc_interface* opaque structure, which xc_interface open returns
instead of the raw file descriptor; furthermore, logging is done via
xentoollog.

There are three new parameters to xc_interface_open to control the
logging, but existing callers can just pass "0" for all three to get
the old behaviour.

All libxc callers have been adjusted accordingly.

Also update QEMU_TAG for corresponding qemu change.

Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 Config.mk                                                             |    6 
 extras/mini-os/lib/sys.c                                              |    5 
 stubdom/grub/kexec.c                                                  |   14 
 tools/console/daemon/io.c                                             |   15 
 tools/console/daemon/utils.c                                          |    8 
 tools/console/daemon/utils.h                                          |    3 
 tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c |    2 
 tools/debugger/xenitp/xenitp.c                                        |   10 
 tools/flask/libflask/flask_op.c                                       |   41 
 tools/flask/libflask/include/libflask.h                               |   39 
 tools/flask/utils/getenforce.c                                        |    6 
 tools/flask/utils/loadpolicy.c                                        |    6 
 tools/flask/utils/setenforce.c                                        |    6 
 tools/fs-back/fs-backend.c                                            |   21 
 tools/fs-back/fs-backend.h                                            |    1 
 tools/fs-back/fs-ops.c                                                |   40 
 tools/libxc/ia64/xc_ia64.h                                            |    4 
 tools/libxc/ia64/xc_ia64_hvm_build.c                                  |   32 
 tools/libxc/ia64/xc_ia64_linux_restore.c                              |   26 
 tools/libxc/ia64/xc_ia64_linux_save.c                                 |   16 
 tools/libxc/ia64/xc_ia64_stubs.c                                      |   14 
 tools/libxc/xc_acm.c                                                  |    4 
 tools/libxc/xc_core.c                                                 |  153 +-
 tools/libxc/xc_core.h                                                 |   12 
 tools/libxc/xc_core_ia64.c                                            |   30 
 tools/libxc/xc_core_ia64.h                                            |    2 
 tools/libxc/xc_core_x86.c                                             |   28 
 tools/libxc/xc_core_x86.h                                             |    2 
 tools/libxc/xc_cpu_hotplug.c                                          |    8 
 tools/libxc/xc_cpuid_x86.c                                            |   57 
 tools/libxc/xc_cpupool.c                                              |   32 
 tools/libxc/xc_csched.c                                               |    8 
 tools/libxc/xc_csched2.c                                              |    8 
 tools/libxc/xc_dom.h                                                  |   34 
 tools/libxc/xc_dom_binloader.c                                        |   42 
 tools/libxc/xc_dom_boot.c                                             |  107 -
 tools/libxc/xc_dom_bzimageloader.c                                    |   69 -
 tools/libxc/xc_dom_compat_linux.c                                     |   31 
 tools/libxc/xc_dom_core.c                                             |  273 
++--
 tools/libxc/xc_dom_elfloader.c                                        |   65 -
 tools/libxc/xc_dom_ia64.c                                             |   18 
 tools/libxc/xc_dom_x86.c                                              |  127 +-
 tools/libxc/xc_domain.c                                               |  328 
++---
 tools/libxc/xc_domain_restore.c                                       |  192 
+--
 tools/libxc/xc_domain_save.c                                          |  203 
+--
 tools/libxc/xc_evtchn.c                                               |   16 
 tools/libxc/xc_flask.c                                                |    4 
 tools/libxc/xc_hvm_build.c                                            |   63 -
 tools/libxc/xc_linux.c                                                |  156 +-
 tools/libxc/xc_mem_event.c                                            |   12 
 tools/libxc/xc_mem_paging.c                                           |   16 
 tools/libxc/xc_memshr.c                                               |   32 
 tools/libxc/xc_minios.c                                               |   44 
 tools/libxc/xc_misc.c                                                 |   72 -
 tools/libxc/xc_netbsd.c                                               |   50 
 tools/libxc/xc_offline_page.c                                         |  111 -
 tools/libxc/xc_pagetab.c                                              |   12 
 tools/libxc/xc_physdev.c                                              |   14 
 tools/libxc/xc_pm.c                                                   |  128 +-
 tools/libxc/xc_private.c                                              |  295 
++---
 tools/libxc/xc_private.h                                              |   98 -
 tools/libxc/xc_ptrace.c                                               |   87 -
 tools/libxc/xc_ptrace.h                                               |    9 
 tools/libxc/xc_ptrace_core.c                                          |   36 
 tools/libxc/xc_resume.c                                               |   60 -
 tools/libxc/xc_sedf.c                                                 |    8 
 tools/libxc/xc_solaris.c                                              |   62 -
 tools/libxc/xc_suspend.c                                              |   20 
 tools/libxc/xc_tbuf.c                                                 |   34 
 tools/libxc/xc_tmem.c                                                 |   77 -
 tools/libxc/xenctrl.h                                                 |  589 
+++++-----
 tools/libxc/xenguest.h                                                |   47 
 tools/libxc/xg_private.c                                              |   12 
 tools/libxc/xg_private.h                                              |    8 
 tools/libxc/xg_save_restore.h                                         |   10 
 tools/libxl/libxl.c                                                   |    4 
 tools/libxl/libxl.h                                                   |    2 
 tools/libxl/libxl_dom.c                                               |    6 
 tools/libxl/libxl_internal.h                                          |    2 
 tools/libxl/xenguest.c                                                |    2 
 tools/memshr/interface.c                                              |    6 
 tools/misc/xen-hptool.c                                               |   34 
 tools/misc/xen-hvmctx.c                                               |    7 
 tools/misc/xenlockprof.c                                              |    4 
 tools/misc/xenperf.c                                                  |    5 
 tools/misc/xenpm.c                                                    |  130 +-
 tools/python/xen/lowlevel/acm/acm.c                                   |   26 
 tools/python/xen/lowlevel/checkpoint/checkpoint.h                     |    2 
 tools/python/xen/lowlevel/checkpoint/libcheckpoint.c                  |   12 
 tools/python/xen/lowlevel/flask/flask.c                               |   48 
 tools/python/xen/lowlevel/xc/xc.c                                     |  198 
+--
 tools/security/secpol_tool.c                                          |   16 
 tools/xcutils/lsevtchn.c                                              |   11 
 tools/xcutils/readnotes.c                                             |   11 
 tools/xcutils/xc_restore.c                                            |   11 
 tools/xcutils/xc_save.c                                               |   18 
 tools/xenmon/setmask.c                                                |    2 
 tools/xenmon/xenbaked.c                                               |   19 
 tools/xenpaging/file_ops.c                                            |    1 
 tools/xenpaging/policy.h                                              |    3 
 tools/xenpaging/policy_default.c                                      |    3 
 tools/xenpaging/xc.c                                                  |    9 
 tools/xenpaging/xc.h                                                  |    7 
 tools/xenpaging/xenpaging.c                                           |   44 
 tools/xenpaging/xenpaging.h                                           |    2 
 tools/xenstat/libxenstat/src/xenstat.c                                |    4 
 tools/xenstat/libxenstat/src/xenstat_priv.h                           |    2 
 tools/xenstore/xenstored_domain.c                                     |   11 
 tools/xentrace/setsize.c                                              |    2 
 tools/xentrace/xenctx.c                                               |    6 
 tools/xentrace/xentrace.c                                             |   16 
 111 files changed, 2610 insertions(+), 2406 deletions(-)

diff -r 54eb305da6a8 -r 779c0ef9682c Config.mk
--- a/Config.mk Fri May 28 09:29:15 2010 +0100
+++ b/Config.mk Fri May 28 09:30:19 2010 +0100
@@ -154,9 +154,9 @@ QEMU_REMOTE=http://xenbits.xensource.com
 # CONFIG_QEMU ?= ../qemu-xen.git
 CONFIG_QEMU ?= $(QEMU_REMOTE)
 
-QEMU_TAG ?= 805ed3b20492d2f4bb465bfda65cedd286e23209
-# Fri May 21 15:46:55 2010 +0100
-# Wait for frontend state Connected before connecting the backend
+QEMU_TAG ?= ffb0cf2ad55e952dae55e6166c4fcea79be6cd30
+# Thu Apr 15 17:01:15 2010 +0100
+# Change callers of libxc to use new libxc API.
 
 # Optional components
 XENSTAT_XENTOP     ?= y
diff -r 54eb305da6a8 -r 779c0ef9682c extras/mini-os/lib/sys.c
--- a/extras/mini-os/lib/sys.c  Fri May 28 09:29:15 2010 +0100
+++ b/extras/mini-os/lib/sys.c  Fri May 28 09:30:19 2010 +0100
@@ -84,7 +84,8 @@
 
 #define NOFILE 32
 extern int xc_evtchn_close(int fd);
-extern int xc_interface_close(int fd);
+struct xc_interface;
+extern int xc_interface_close_core(struct xc_interface*, int fd);
 extern int xc_gnttab_close(int fd);
 
 pthread_mutex_t fd_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -413,7 +414,7 @@ int close(int fd)
        }
 #endif
        case FTYPE_XC:
-           xc_interface_close(fd);
+           xc_interface_close_core(0,fd);
            return 0;
        case FTYPE_EVTCHN:
             xc_evtchn_close(fd);
diff -r 54eb305da6a8 -r 779c0ef9682c stubdom/grub/kexec.c
--- a/stubdom/grub/kexec.c      Fri May 28 09:29:15 2010 +0100
+++ b/stubdom/grub/kexec.c      Fri May 28 09:30:19 2010 +0100
@@ -50,7 +50,7 @@ static unsigned long *pages_mfns;
 static unsigned long *pages_mfns;
 static unsigned long allocated;
 
-int pin_table(int xc_handle, unsigned int type, unsigned long mfn,
+int pin_table(xc_interface *xc_handle, unsigned int type, unsigned long mfn,
               domid_t dom);
 
 /* We need mfn to appear as target_pfn, so exchange with the MFN there */
@@ -109,7 +109,7 @@ void kexec(void *kernel, long kernel_siz
     int rc;
     domid_t domid = DOMID_SELF;
     xen_pfn_t pfn;
-    int xc_handle;
+    xc_interface *xc_handle;
     unsigned long i;
     void *seg;
     xen_pfn_t boot_page_mfn = virt_to_mfn(&_boot_page);
@@ -118,9 +118,9 @@ void kexec(void *kernel, long kernel_siz
     unsigned long nr_m2p_updates;
 
     DEBUG("booting with cmdline %s\n", cmdline);
-    xc_handle = xc_interface_open();
-
-    dom = xc_dom_allocate(cmdline, features);
+    xc_handle = xc_interface_open(0,0,0);
+
+    dom = xc_dom_allocate(xc_handle, cmdline, features);
     dom->allocate = kexec_allocate;
 
     dom->kernel_blob = kernel;
@@ -160,7 +160,7 @@ void kexec(void *kernel, long kernel_siz
 #endif
 
     /* equivalent of xc_dom_mem_init */
-    dom->arch_hooks = xc_dom_find_arch_hooks(dom->guest_type);
+    dom->arch_hooks = xc_dom_find_arch_hooks(xc_handle, dom->guest_type);
     dom->total_pages = start_info.nr_pages;
 
     /* equivalent of arch_setup_meminit */
@@ -238,7 +238,7 @@ void kexec(void *kernel, long kernel_siz
         munmap((void*) pages[pfn], PAGE_SIZE);
 
     /* Pin the boot page table base */
-    if ( (rc = pin_table(dom->guest_xc, 
+    if ( (rc = pin_table(dom->xch,
 #ifdef __i386__
                 MMUEXT_PIN_L3_TABLE,
 #endif
diff -r 54eb305da6a8 -r 779c0ef9682c tools/console/daemon/io.c
--- a/tools/console/daemon/io.c Fri May 28 09:29:15 2010 +0100
+++ b/tools/console/daemon/io.c Fri May 28 09:30:19 2010 +0100
@@ -24,7 +24,6 @@
 #include "io.h"
 #include <xs.h>
 #include <xen/io/console.h>
-#include <xenctrl.h>
 
 #include <stdlib.h>
 #include <errno.h>
@@ -68,7 +67,7 @@ static int log_time_guest_needts = 1;
 static int log_time_guest_needts = 1;
 static int log_hv_fd = -1;
 static evtchn_port_or_error_t log_hv_evtchn = -1;
-static int xc_handle = -1;
+static xc_interface *xch; /* why does xenconsoled have two xc handles ? */
 static int xce_handle = -1;
 
 struct buffer {
@@ -932,7 +931,7 @@ static void handle_hv_logs(void)
        if ((port = xc_evtchn_pending(xce_handle)) == -1)
                return;
 
-       if (xc_readconsolering(xc_handle, &bufptr, &size, 0, 1, &index) == 0 && 
size > 0) {
+       if (xc_readconsolering(xch, &bufptr, &size, 0, 1, &index) == 0 && size 
> 0) {
                int logret;
                if (log_time_hv)
                        logret = write_with_timestamp(log_hv_fd, buffer, size,
@@ -972,8 +971,8 @@ void handle_io(void)
        int ret;
 
        if (log_hv) {
-               xc_handle = xc_interface_open();
-               if (xc_handle == -1) {
+               xch = xc_interface_open(0,0,0);
+               if (!xch) {
                        dolog(LOG_ERR, "Failed to open xc handle: %d (%s)",
                              errno, strerror(errno));
                        goto out;
@@ -1124,9 +1123,9 @@ void handle_io(void)
                close(log_hv_fd);
                log_hv_fd = -1;
        }
-       if (xc_handle != -1) {
-               xc_interface_close(xc_handle);
-               xc_handle = -1;
+       if (xch) {
+               xc_interface_close(xch);
+               xch = 0;
        }
        if (xce_handle != -1) {
                xc_evtchn_close(xce_handle);
diff -r 54eb305da6a8 -r 779c0ef9682c tools/console/daemon/utils.c
--- a/tools/console/daemon/utils.c      Fri May 28 09:29:15 2010 +0100
+++ b/tools/console/daemon/utils.c      Fri May 28 09:30:19 2010 +0100
@@ -38,7 +38,7 @@
 #include "utils.h"
 
 struct xs_handle *xs;
-int xc;
+xc_interface *xc;
 
 static void child_exit(int sig)
 {
@@ -116,8 +116,8 @@ bool xen_setup(void)
                goto out;
        }
 
-       xc = xc_interface_open();
-       if (xc == -1) {
+       xc = xc_interface_open(0,0,0);
+       if (!xc) {
                dolog(LOG_ERR, "Failed to contact hypervisor (%m)");
                goto out;
        }
@@ -137,7 +137,7 @@ bool xen_setup(void)
  out:
        if (xs)
                xs_daemon_close(xs);
-       if (xc != -1)
+       if (xc)
                xc_interface_close(xc);
        return false;
 }
diff -r 54eb305da6a8 -r 779c0ef9682c tools/console/daemon/utils.h
--- a/tools/console/daemon/utils.h      Fri May 28 09:29:15 2010 +0100
+++ b/tools/console/daemon/utils.h      Fri May 28 09:30:19 2010 +0100
@@ -24,6 +24,7 @@
 #include <stdbool.h>
 #include <syslog.h>
 #include <stdio.h>
+#include <xenctrl.h>
 
 #include "xs.h"
 
@@ -31,7 +32,7 @@ bool xen_setup(void);
 bool xen_setup(void);
 
 extern struct xs_handle *xs;
-extern int xc;
+extern xc_interface *xc;
 
 #if 1
 #define dolog(val, fmt, ...) do {                              \
diff -r 54eb305da6a8 -r 779c0ef9682c 
tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c
--- a/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c     
Fri May 28 09:29:15 2010 +0100
+++ b/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c     
Fri May 28 09:30:19 2010 +0100
@@ -39,7 +39,7 @@
 
 #define TRACE_ENTER /* printf("enter %s\n", __FUNCTION__) */
 
-static int xc_handle;
+static xc_interface *xc_handle;
 
 static inline int
 curvcpuid()
diff -r 54eb305da6a8 -r 779c0ef9682c tools/debugger/xenitp/xenitp.c
--- a/tools/debugger/xenitp/xenitp.c    Fri May 28 09:29:15 2010 +0100
+++ b/tools/debugger/xenitp/xenitp.c    Fri May 28 09:30:19 2010 +0100
@@ -40,7 +40,7 @@
 #include <xen/arch-ia64/debug_op.h>
 #endif
 
-static int xc_handle = 0;
+static xc_interface *xc_handle = 0;
 static int domid = 0;
 static vcpu_guest_context_t *cur_ctx;
 static int cur_vcpu;
@@ -59,7 +59,7 @@ int virt_to_phys (int is_inst, unsigned 
 int virt_to_phys (int is_inst, unsigned long vaddr, unsigned long *paddr);
 
 /* wrapper for vcpu_gest_context_any_t */
-static int xc_ia64_vcpu_getcontext(int xc_handle,
+static int xc_ia64_vcpu_getcontext(xc_interface *xc_handle,
                                    uint32_t domid,
                                    uint32_t vcpu,
                                    vcpu_guest_context_t *ctxt)
@@ -660,10 +660,10 @@ void print_tr (vcpu_guest_context_t *ctx
 
 int lock_pages (void *addr, size_t len);
 void unlock_pages (void *addr, size_t len);
-int do_xen_hypercall (int xc_handle, privcmd_hypercall_t *hypercall);
+int do_xen_hypercall (xc_interface *xc_handle, privcmd_hypercall_t *hypercall);
 
 #ifdef HAVE_DEBUG_OP
-static int do_ia64_debug_op (int xc_handle,
+static int do_ia64_debug_op (xc_interface *xc_handle,
                             unsigned long cmd, unsigned long domain,
                             xen_ia64_debug_op_t *op)
 {
@@ -1663,7 +1663,7 @@ void xenitp (int vcpu)
         }
     }
 
-    xc_interface_close (xc_handle);
+    ret = xc_interface_close (xc_handle);
     if (ret < 0) {
         perror ("xc_interface_close");
         exit (-1);
diff -r 54eb305da6a8 -r 779c0ef9682c tools/flask/libflask/flask_op.c
--- a/tools/flask/libflask/flask_op.c   Fri May 28 09:29:15 2010 +0100
+++ b/tools/flask/libflask/flask_op.c   Fri May 28 09:30:19 2010 +0100
@@ -20,9 +20,8 @@
 #include <stdint.h>
 #include <sys/ioctl.h>
 #include <libflask.h>
-#include <xenctrl.h>
-
-int flask_load(int xc_handle, char *buf, uint32_t size)
+
+int flask_load(xc_interface *xc_handle, char *buf, uint32_t size)
 {
     int err;
     flask_op_t op;
@@ -37,7 +36,7 @@ int flask_load(int xc_handle, char *buf,
     return 0;
 }
 
-int flask_context_to_sid(int xc_handle, char *buf, uint32_t size, uint32_t 
*sid)
+int flask_context_to_sid(xc_interface *xc_handle, char *buf, uint32_t size, 
uint32_t *sid)
 {
     int err;
     flask_op_t op;
@@ -54,7 +53,7 @@ int flask_context_to_sid(int xc_handle, 
     return 0;
 }
 
-int flask_sid_to_context(int xc_handle, int sid, char *buf, uint32_t size)
+int flask_sid_to_context(xc_interface *xc_handle, int sid, char *buf, uint32_t 
size)
 {
     int err;
     flask_op_t op;
@@ -71,7 +70,7 @@ int flask_sid_to_context(int xc_handle, 
     return 0;
 }
 
-int flask_getenforce(int xc_handle)
+int flask_getenforce(xc_interface *xc_handle)
 {
     int err;
     flask_op_t op;
@@ -91,7 +90,7 @@ int flask_getenforce(int xc_handle)
     return mode;
 }
 
-int flask_setenforce(int xc_handle, int mode)
+int flask_setenforce(xc_interface *xc_handle, int mode)
 {
     int err;
     flask_op_t op;
@@ -110,7 +109,7 @@ int flask_setenforce(int xc_handle, int 
     return 0;
 }
 
-int flask_add_pirq(int xc_handle, unsigned int pirq, char *scontext)
+int flask_add_pirq(xc_interface *xc_handle, unsigned int pirq, char *scontext)
 {
     int err;
     flask_op_t op;
@@ -139,7 +138,7 @@ int flask_add_pirq(int xc_handle, unsign
 
 }
 
-int flask_add_ioport(int xc_handle, unsigned long low, unsigned long high,
+int flask_add_ioport(xc_interface *xc_handle, unsigned long low, unsigned long 
high,
                       char *scontext)
 {
     int err;
@@ -169,7 +168,7 @@ int flask_add_ioport(int xc_handle, unsi
 
 }
 
-int flask_add_iomem(int xc_handle, unsigned long low, unsigned long high,
+int flask_add_iomem(xc_interface *xc_handle, unsigned long low, unsigned long 
high,
                      char *scontext)
 {
     int err;
@@ -199,7 +198,7 @@ int flask_add_iomem(int xc_handle, unsig
 
 }
 
-int flask_add_device(int xc_handle, unsigned long device, char *scontext)
+int flask_add_device(xc_interface *xc_handle, unsigned long device, char 
*scontext)
 {
     int err;
     flask_op_t op;
@@ -228,7 +227,7 @@ int flask_add_device(int xc_handle, unsi
 
 }
 
-int flask_del_pirq(int xc_handle, unsigned int pirq)
+int flask_del_pirq(xc_interface *xc_handle, unsigned int pirq)
 {
     int err;
     flask_op_t op;
@@ -257,7 +256,7 @@ int flask_del_pirq(int xc_handle, unsign
 
 }
 
-int flask_del_ioport(int xc_handle, unsigned long low, unsigned long high)
+int flask_del_ioport(xc_interface *xc_handle, unsigned long low, unsigned long 
high)
 {
     int err;
     flask_op_t op;
@@ -286,7 +285,7 @@ int flask_del_ioport(int xc_handle, unsi
 
 }
 
-int flask_del_iomem(int xc_handle, unsigned long low, unsigned long high)
+int flask_del_iomem(xc_interface *xc_handle, unsigned long low, unsigned long 
high)
 {
     int err;
     flask_op_t op;
@@ -315,7 +314,7 @@ int flask_del_iomem(int xc_handle, unsig
 
 }
 
-int flask_del_device(int xc_handle, unsigned long device)
+int flask_del_device(xc_interface *xc_handle, unsigned long device)
 {
     int err;
     flask_op_t op;
@@ -343,7 +342,7 @@ int flask_del_device(int xc_handle, unsi
 
 }
 
-int flask_access(int xc_handle, const char *scon, const char *tcon,
+int flask_access(xc_interface *xc_handle, const char *scon, const char *tcon,
                 u_int16_t tclass, u_int32_t req,
                 u_int32_t *allowed, u_int32_t *decided,
                 u_int32_t *auditallow, u_int32_t *auditdeny,
@@ -407,7 +406,7 @@ int flask_access(int xc_handle, const ch
 
 }
 
-int flask_avc_hashstats(int xc_handle, char *buf, int size)
+int flask_avc_hashstats(xc_interface *xc_handle, char *buf, int size)
 {
     int err;
     flask_op_t op;
@@ -425,7 +424,7 @@ int flask_avc_hashstats(int xc_handle, c
     return 0;
 }
 
-int flask_avc_cachestats(int xc_handle, char *buf, int size)
+int flask_avc_cachestats(xc_interface *xc_handle, char *buf, int size)
 {
     int err;
     flask_op_t op;
@@ -443,7 +442,7 @@ int flask_avc_cachestats(int xc_handle, 
     return 0;
 }
 
-int flask_policyvers(int xc_handle, char *buf, int size)
+int flask_policyvers(xc_interface *xc_handle, char *buf, int size)
 {
     int err;
     flask_op_t op;
@@ -461,7 +460,7 @@ int flask_policyvers(int xc_handle, char
     return 0;
 }
 
-int flask_getavc_threshold(int xc_handle)
+int flask_getavc_threshold(xc_interface *xc_handle)
 {
     int err;
     flask_op_t op;
@@ -481,7 +480,7 @@ int flask_getavc_threshold(int xc_handle
     return threshold;
 }
 
-int flask_setavc_threshold(int xc_handle, int threshold)
+int flask_setavc_threshold(xc_interface *xc_handle, int threshold)
 {
     int err;
     flask_op_t op;
diff -r 54eb305da6a8 -r 779c0ef9682c tools/flask/libflask/include/libflask.h
--- a/tools/flask/libflask/include/libflask.h   Fri May 28 09:29:15 2010 +0100
+++ b/tools/flask/libflask/include/libflask.h   Fri May 28 09:30:19 2010 +0100
@@ -14,32 +14,33 @@
 #include <stdint.h>
 #include <xen/xen.h>
 #include <xen/xsm/flask_op.h>
+#include <xenctrl.h>
 
-int flask_load(int xc_handle, char *buf, uint32_t size);
-int flask_context_to_sid(int xc_handle, char *buf, uint32_t size, uint32_t 
*sid);
-int flask_sid_to_context(int xc_handle, int sid, char *buf, uint32_t size);
-int flask_getenforce(int xc_handle);
-int flask_setenforce(int xc_handle, int mode);
-int flask_add_pirq(int xc_handle, unsigned int pirq, char *scontext);
-int flask_add_ioport(int xc_handle, unsigned long low, unsigned long high,
+int flask_load(xc_interface *xc_handle, char *buf, uint32_t size);
+int flask_context_to_sid(xc_interface *xc_handle, char *buf, uint32_t size, 
uint32_t *sid);
+int flask_sid_to_context(xc_interface *xc_handle, int sid, char *buf, uint32_t 
size);
+int flask_getenforce(xc_interface *xc_handle);
+int flask_setenforce(xc_interface *xc_handle, int mode);
+int flask_add_pirq(xc_interface *xc_handle, unsigned int pirq, char *scontext);
+int flask_add_ioport(xc_interface *xc_handle, unsigned long low, unsigned long 
high,
                       char *scontext);
-int flask_add_iomem(int xc_handle, unsigned long low, unsigned long high,
+int flask_add_iomem(xc_interface *xc_handle, unsigned long low, unsigned long 
high,
                      char *scontext);
-int flask_add_device(int xc_handle, unsigned long device, char *scontext);
-int flask_del_pirq(int xc_handle, unsigned int pirq);
-int flask_del_ioport(int xc_handle, unsigned long low, unsigned long high);
-int flask_del_iomem(int xc_handle, unsigned long low, unsigned long high);
-int flask_del_device(int xc_handle, unsigned long device);
-int flask_access(int xc_handle, const char *scon, const char *tcon,
+int flask_add_device(xc_interface *xc_handle, unsigned long device, char 
*scontext);
+int flask_del_pirq(xc_interface *xc_handle, unsigned int pirq);
+int flask_del_ioport(xc_interface *xc_handle, unsigned long low, unsigned long 
high);
+int flask_del_iomem(xc_interface *xc_handle, unsigned long low, unsigned long 
high);
+int flask_del_device(xc_interface *xc_handle, unsigned long device);
+int flask_access(xc_interface *xc_handle, const char *scon, const char *tcon,
                   u_int16_t tclass, u_int32_t req,
                   u_int32_t *allowed, u_int32_t *decided,
                   u_int32_t *auditallow, u_int32_t *auditdeny,
                   u_int32_t *seqno);
-int flask_avc_cachestats(int xc_handle, char *buf, int size);
-int flask_policyvers(int xc_handle, char *buf, int size);
-int flask_avc_hashstats(int xc_handle, char *buf, int size);
-int flask_getavc_threshold(int xc_handle);
-int flask_setavc_threshold(int xc_handle, int threshold);
+int flask_avc_cachestats(xc_interface *xc_handle, char *buf, int size);
+int flask_policyvers(xc_interface *xc_handle, char *buf, int size);
+int flask_avc_hashstats(xc_interface *xc_handle, char *buf, int size);
+int flask_getavc_threshold(xc_interface *xc_handle);
+int flask_setavc_threshold(xc_interface *xc_handle, int threshold);
 #define flask_add_single_ioport(x, l, s) flask_add_ioport(x, l, l, s)
 #define flask_add_single_iomem(x, l, s) flask_add_iomem(x, l, l, s)
 #define flask_del_single_ioport(x, l) flask_del_ioport(x, l, l)
diff -r 54eb305da6a8 -r 779c0ef9682c tools/flask/utils/getenforce.c
--- a/tools/flask/utils/getenforce.c    Fri May 28 09:29:15 2010 +0100
+++ b/tools/flask/utils/getenforce.c    Fri May 28 09:30:19 2010 +0100
@@ -27,13 +27,13 @@ int main (int argCnt, const char *args[]
 int main (int argCnt, const char *args[])
 {
     int ret;
-    int xch = 0;
+    xc_interface *xch = 0;
 
     if (argCnt != 1)
         usage(argCnt, args);
 
-    xch = xc_interface_open();
-    if ( xch < 0 )
+    xch = xc_interface_open(0,0,0);
+    if ( !xch )
     {
         fprintf(stderr, "Unable to create interface to xenctrl: %s\n",
                 strerror(errno));
diff -r 54eb305da6a8 -r 779c0ef9682c tools/flask/utils/loadpolicy.c
--- a/tools/flask/utils/loadpolicy.c    Fri May 28 09:29:15 2010 +0100
+++ b/tools/flask/utils/loadpolicy.c    Fri May 28 09:30:19 2010 +0100
@@ -35,7 +35,7 @@ int main (int argCnt, const char *args[]
     void *polMemCp = NULL;
     struct stat info;
     int ret;
-    int xch = 0;
+    xc_interface *xch = 0;
 
     if (argCnt != 2)
         usage(argCnt, args);
@@ -70,8 +70,8 @@ int main (int argCnt, const char *args[]
         goto cleanup;
     }
 
-    xch = xc_interface_open();
-    if ( xch < 0 )
+    xch = xc_interface_open(0,0,0);
+    if ( !xch )
     {
         fprintf(stderr, "Unable to create interface to xenctrl: %s\n",
                 strerror(errno));
diff -r 54eb305da6a8 -r 779c0ef9682c tools/flask/utils/setenforce.c
--- a/tools/flask/utils/setenforce.c    Fri May 28 09:29:15 2010 +0100
+++ b/tools/flask/utils/setenforce.c    Fri May 28 09:30:19 2010 +0100
@@ -27,15 +27,15 @@ int main (int argCnt, const char *args[]
 int main (int argCnt, const char *args[])
 {
     int ret = 0;
-    int xch = 0;
+    xc_interface *xch = 0;
     long mode = 0;
     char *end;
 
     if (argCnt != 2)
         usage(argCnt, args);
 
-    xch = xc_interface_open();
-    if ( xch < 0 )
+    xch = xc_interface_open(0,0,0);
+    if ( !xch )
     {
         fprintf(stderr, "Unable to create interface to xenctrl: %s\n",
                 strerror(errno));
diff -r 54eb305da6a8 -r 779c0ef9682c tools/fs-back/fs-backend.c
--- a/tools/fs-back/fs-backend.c        Fri May 28 09:29:15 2010 +0100
+++ b/tools/fs-back/fs-backend.c        Fri May 28 09:30:19 2010 +0100
@@ -168,8 +168,9 @@ void terminate_mount_request(struct fs_m
     }
     xenbus_write_backend_state(mount, STATE_CLOSED);
 
-    xc_gnttab_munmap(mount->gnth, mount->ring.sring, mount->shared_ring_size);
-    xc_gnttab_close(mount->gnth);
+    xc_gnttab_munmap(mount->xch, mount->gnth,
+                     mount->ring.sring, mount->shared_ring_size);
+    xc_gnttab_close(mount->xch, mount->gnth);
     xc_evtchn_unbind(mount->evth, mount->local_evtchn);
     xc_evtchn_close(mount->evth);
 
@@ -213,6 +214,9 @@ static void handle_connection(int fronte
 
     mount = (struct fs_mount*)malloc(sizeof(struct fs_mount));
     memset(mount, 0, sizeof(struct fs_mount));
+    mount->xch = xc_interface_open(0,0,XC_OPENFLAG_DUMMY);
+    if (!mount->xch) goto error;
+
     mount->dom_id = frontend_dom_id;
     mount->export = export;
     mount->mount_id = mount_id++;
@@ -239,14 +243,14 @@ static void handle_connection(int fronte
         goto error;
     }
     mount->gnth = -1;
-    mount->gnth = xc_gnttab_open(); 
+    mount->gnth = xc_gnttab_open(mount->xch);
     if (mount->gnth < 0) {
         FS_DEBUG("ERROR: Couldn't open gnttab!\n");
         goto error;
     }
     for(i=0; i<mount->shared_ring_size; i++)
         dom_ids[i] = mount->dom_id;
-    sring = xc_gnttab_map_grant_refs(mount->gnth,
+    sring = xc_gnttab_map_grant_refs(mount->xch, mount->gnth,
                                      mount->shared_ring_size,
                                      dom_ids,
                                      mount->grefs,
@@ -279,13 +283,16 @@ error:
 error:
     xenbus_write_backend_state(mount, STATE_CLOSED);
     if (sring)
-        xc_gnttab_munmap(mount->gnth, mount->ring.sring, 
mount->shared_ring_size);
+        xc_gnttab_munmap(mount->xch, mount->gnth,
+                         mount->ring.sring, mount->shared_ring_size);
     if (mount->gnth > 0)
-        xc_gnttab_close(mount->gnth);
+        xc_gnttab_close(mount->xch, mount->gnth);
     if (mount->local_evtchn > 0)
         xc_evtchn_unbind(mount->evth, mount->local_evtchn);
     if (mount->evth > 0)
         xc_evtchn_close(mount->evth);
+    if (mount->xch)
+        xc_interface_close(mount->xch);
 }
 
 static void await_connections(void)
@@ -472,7 +479,7 @@ int main(void)
     /* Close the connection to XenStore when we are finished with everything */
     xs_daemon_close(xsh);
 #if 0
-    int xc_handle;
+    xc_interface *xc_handle;
     char *shared_page;
     int prot = PROT_READ | PROT_WRITE;
   
diff -r 54eb305da6a8 -r 779c0ef9682c tools/fs-back/fs-backend.h
--- a/tools/fs-back/fs-backend.h        Fri May 28 09:29:15 2010 +0100
+++ b/tools/fs-back/fs-backend.h        Fri May 28 09:30:19 2010 +0100
@@ -44,6 +44,7 @@ struct fs_mount
     int mount_id;                     /* = backend id */
     grant_ref_t grefs[MAX_RING_SIZE];
     evtchn_port_t remote_evtchn;
+    xc_interface *xch; /* just for error logging, so a dummy */
     int evth;                         /* Handle to the event channel */
     evtchn_port_t local_evtchn;
     int gnth;
diff -r 54eb305da6a8 -r 779c0ef9682c tools/fs-back/fs-ops.c
--- a/tools/fs-back/fs-ops.c    Fri May 28 09:29:15 2010 +0100
+++ b/tools/fs-back/fs-ops.c    Fri May 28 09:30:19 2010 +0100
@@ -75,7 +75,7 @@ static void dispatch_file_open(struct fs
 
     FS_DEBUG("Dispatching file open operation (gref=%d).\n", 
req->u.fopen.gref);
     /* Read the request, and open file */
-    file_name = xc_gnttab_map_grant_ref(mount->gnth,
+    file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth,
                                         mount->dom_id,
                                         req->u.fopen.gref,
                                         PROT_READ);
@@ -99,7 +99,7 @@ static void dispatch_file_open(struct fs
         }
     }
 out:
-    if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) {
+    if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
     }
@@ -159,7 +159,7 @@ static void dispatch_file_read(struct fs
     assert(req->u.fread.len > 0); 
     count = (req->u.fread.len - 1) / XC_PAGE_SIZE + 1;
     assert(count <= FSIF_NR_READ_GNTS);
-    buf = xc_gnttab_map_domain_grant_refs(mount->gnth,
+    buf = xc_gnttab_map_domain_grant_refs(mount->xch, mount->gnth,
                                           count,
                                           mount->dom_id,
                                           req->u.fread.grefs,
@@ -192,7 +192,8 @@ static void dispatch_file_read(struct fs
     priv_req->aiocb.aio_sigevent.sigev_value.sival_ptr = priv_req;
     if (aio_read(&priv_req->aiocb) < 0) {
         FS_DEBUG("ERROR: aio_read failed errno=%d\n", errno);
-        xc_gnttab_munmap(mount->gnth, priv_req->page, priv_req->count);
+        xc_gnttab_munmap(mount->xch, mount->gnth,
+                         priv_req->page, priv_req->count);
         terminate_mount_request(mount);
     }
 
@@ -208,7 +209,8 @@ static void end_file_read(struct fs_moun
     uint16_t req_id;
 
     /* Release the grant */
-    if (xc_gnttab_munmap(mount->gnth, priv_req->page, priv_req->count) != 0) {
+    if (xc_gnttab_munmap(mount->xch, mount->gnth,
+                         priv_req->page, priv_req->count) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
     }
@@ -234,7 +236,7 @@ static void dispatch_file_write(struct f
     assert(req->u.fwrite.len > 0); 
     count = (req->u.fwrite.len - 1) / XC_PAGE_SIZE + 1;
     assert(count <= FSIF_NR_WRITE_GNTS);
-    buf = xc_gnttab_map_domain_grant_refs(mount->gnth,
+    buf = xc_gnttab_map_domain_grant_refs(mount->xch, mount->gnth,
                                           count,
                                           mount->dom_id,
                                           req->u.fwrite.grefs,
@@ -267,7 +269,8 @@ static void dispatch_file_write(struct f
     priv_req->aiocb.aio_sigevent.sigev_value.sival_ptr = priv_req;
     if (aio_write(&priv_req->aiocb) < 0) {
         FS_DEBUG("ERROR: aio_write failed errno=%d\n", errno);
-        xc_gnttab_munmap(mount->gnth, priv_req->page, priv_req->count);
+        xc_gnttab_munmap(mount->xch, mount->gnth,
+                         priv_req->page, priv_req->count);
         terminate_mount_request(mount);
     }
 
@@ -284,7 +287,8 @@ static void end_file_write(struct fs_mou
     uint16_t req_id;
 
     /* Release the grant */
-    if (xc_gnttab_munmap(mount->gnth, priv_req->page, priv_req->count) != 0) {
+    if (xc_gnttab_munmap(mount->xch, mount->gnth,
+                         priv_req->page, priv_req->count) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
     }
@@ -391,7 +395,7 @@ static void dispatch_remove(struct fs_mo
 
     FS_DEBUG("Dispatching remove operation (gref=%d).\n", req->u.fremove.gref);
     /* Read the request, and open file */
-    file_name = xc_gnttab_map_grant_ref(mount->gnth,
+    file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth,
                                         mount->dom_id,
                                         req->u.fremove.gref,
                                         PROT_READ);
@@ -405,7 +409,7 @@ static void dispatch_remove(struct fs_mo
         ret = remove(file_name);
     }
     FS_DEBUG("Got ret: %d\n", ret);
-    if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) {
+    if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
     }
@@ -433,7 +437,7 @@ static void dispatch_rename(struct fs_mo
 
     FS_DEBUG("Dispatching rename operation (gref=%d).\n", req->u.fremove.gref);
     /* Read the request, and open file */
-    buf = xc_gnttab_map_grant_ref(mount->gnth,
+    buf = xc_gnttab_map_grant_ref(mount->xch, mount->gnth,
                                   mount->dom_id,
                                   req->u.frename.gref,
                                   PROT_READ);
@@ -451,7 +455,7 @@ static void dispatch_rename(struct fs_mo
         ret = rename(old_file_name, new_file_name);
     }
     FS_DEBUG("Got ret: %d\n", ret);
-    if (xc_gnttab_munmap(mount->gnth, buf, 1) != 0) {
+    if (xc_gnttab_munmap(mount->xch, mount->gnth, buf, 1) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
     }
@@ -483,7 +487,7 @@ static void dispatch_create(struct fs_mo
     /* Read the request, and create file/directory */
     mode = req->u.fcreate.mode;
     directory = req->u.fcreate.directory;
-    file_name = xc_gnttab_map_grant_ref(mount->gnth,
+    file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth,
                                         mount->dom_id,
                                         req->u.fcreate.gref,
                                         PROT_READ);
@@ -519,7 +523,7 @@ static void dispatch_create(struct fs_mo
         }
     }
 out:
-    if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) {
+    if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
     }
@@ -547,7 +551,7 @@ static void dispatch_list(struct fs_moun
     FS_DEBUG("Dispatching list operation (gref=%d).\n", req->u.flist.gref);
     /* Read the request, and list directory */
     offset = req->u.flist.offset;
-    buf = file_name = xc_gnttab_map_grant_ref(mount->gnth,
+    buf = file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth,
                                         mount->dom_id,
                                         req->u.flist.gref,
                                         PROT_READ | PROT_WRITE);
@@ -595,7 +599,7 @@ error_out:
     ret_val = ((nr_files << NR_FILES_SHIFT) & NR_FILES_MASK) | 
               ((error_code << ERROR_SHIFT) & ERROR_MASK) | 
               (dirent != NULL ? HAS_MORE_FLAG : 0);
-    if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) {
+    if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
     }
@@ -650,7 +654,7 @@ static void dispatch_fs_space(struct fs_
 
     FS_DEBUG("Dispatching fs space operation (gref=%d).\n", 
req->u.fspace.gref);
     /* Read the request, and open file */
-    file_name = xc_gnttab_map_grant_ref(mount->gnth,
+    file_name = xc_gnttab_map_grant_ref(mount->xch, mount->gnth,
                                         mount->dom_id,
                                         req->u.fspace.gref,
                                         PROT_READ);
@@ -666,7 +670,7 @@ static void dispatch_fs_space(struct fs_
     if(ret >= 0)
         ret = stat.f_bsize * stat.f_bfree;
 
-    if (xc_gnttab_munmap(mount->gnth, file_name, 1) != 0) {
+    if (xc_gnttab_munmap(mount->xch, mount->gnth, file_name, 1) != 0) {
         FS_DEBUG("ERROR: xc_gnttab_munmap failed errno=%d\n", errno);
         terminate_mount_request(mount);
     }
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/ia64/xc_ia64.h
--- a/tools/libxc/ia64/xc_ia64.h        Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/ia64/xc_ia64.h        Fri May 28 09:30:19 2010 +0100
@@ -21,7 +21,7 @@
 #ifndef _XC_IA64_H_
 #define _XC_IA64_H_
 
-int xc_ia64_copy_memmap(int xc_handle, uint32_t domid,
+int xc_ia64_copy_memmap(xc_interface *xc_handle, uint32_t domid,
                         shared_info_t *live_shinfo,
                         xen_ia64_memmap_info_t **memmap_info_p,
                         unsigned long *memmap_info_num_pages_p);
@@ -32,7 +32,7 @@ struct xen_ia64_p2m_table {
 };
 
 void xc_ia64_p2m_init(struct xen_ia64_p2m_table *p2m_table);
-int xc_ia64_p2m_map(struct xen_ia64_p2m_table *p2m_table, int xc_handle,
+int xc_ia64_p2m_map(struct xen_ia64_p2m_table *p2m_table, xc_interface 
*xc_handle,
                     uint32_t domid, struct xen_ia64_memmap_info *memmap_info,
                     unsigned long flag);
 void xc_ia64_p2m_unmap(struct xen_ia64_p2m_table *p2m_table);
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/ia64/xc_ia64_hvm_build.c
--- a/tools/libxc/ia64/xc_ia64_hvm_build.c      Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/ia64/xc_ia64_hvm_build.c      Fri May 28 09:30:19 2010 +0100
@@ -13,7 +13,7 @@
 #include <xen/hvm/params.h>
 
 static int
-xc_ia64_copy_to_domain_pages(int xc_handle, uint32_t domid, void* src_page,
+xc_ia64_copy_to_domain_pages(xc_interface *xc_handle, uint32_t domid, void* 
src_page,
                              unsigned long dst_pfn, int nr_pages)
 {
     // N.B. gva should be page aligned
@@ -90,10 +90,10 @@ static int build_hob(void* hob_buf, unsi
 static int build_hob(void* hob_buf, unsigned long hob_buf_size,
                      unsigned long dom_mem_size, unsigned long vcpus,
                      unsigned long nvram_addr);
-static int load_hob(int xc_handle,uint32_t dom, void *hob_buf);
-
-static int
-xc_ia64_build_hob(int xc_handle, uint32_t dom,
+static int load_hob(xc_interface *xc_handle,uint32_t dom, void *hob_buf);
+
+static int
+xc_ia64_build_hob(xc_interface *xc_handle, uint32_t dom,
                   unsigned long memsize, unsigned long vcpus,
                   unsigned long nvram_addr)
 {
@@ -239,7 +239,7 @@ err_out:
 }
 
 static int
-load_hob(int xc_handle, uint32_t dom, void *hob_buf)
+load_hob(xc_interface *xc_handle, uint32_t dom, void *hob_buf)
 {
     // hob_buf should be page aligned
     int hob_size;
@@ -545,7 +545,7 @@ nvram_init(const char *nvram_path)
 }
 
 static int 
-copy_from_nvram_to_GFW(int xc_handle, uint32_t dom, int nvram_fd)
+copy_from_nvram_to_GFW(xc_interface *xc_handle, uint32_t dom, int nvram_fd)
 {
     unsigned int nr_pages = NVRAM_SIZE >> PAGE_SHIFT;
     struct stat file_stat;
@@ -597,7 +597,7 @@ static int is_valid_address(void *addr)
  * can be got.
  */
 static int
-copy_from_GFW_to_nvram(int xc_handle, uint32_t dom, int nvram_fd)
+copy_from_GFW_to_nvram(xc_interface *xc_handle, uint32_t dom, int nvram_fd)
 {
     xen_pfn_t *pfn_list = NULL;
     char *tmp_ptr = NULL;
@@ -686,7 +686,7 @@ copy_from_GFW_to_nvram(int xc_handle, ui
     return 0;
 }
 
-int xc_ia64_save_to_nvram(int xc_handle, uint32_t dom) 
+int xc_ia64_save_to_nvram(xc_interface *xc_handle, uint32_t dom) 
 {
     xc_dominfo_t info;
     uint64_t nvram_fd = 0;
@@ -717,7 +717,7 @@ int xc_ia64_save_to_nvram(int xc_handle,
 #define NVRAM_DIR         "/var/lib/xen/nvram/"
 #define NVRAM_FILE_PREFIX "nvram_"
 
-int xc_ia64_nvram_init(int xc_handle, char *dom_name, uint32_t dom)
+int xc_ia64_nvram_init(xc_interface *xc_handle, char *dom_name, uint32_t dom)
 {
     uint64_t nvram_fd;
     char nvram_path[PATH_MAX] = NVRAM_DIR;
@@ -784,7 +784,7 @@ min(unsigned long lhs, unsigned long rhs
 }
 
 static int
-xc_ia64_setup_memmap_info(int xc_handle, uint32_t dom,
+xc_ia64_setup_memmap_info(xc_interface *xc_handle, uint32_t dom,
                           unsigned long dom_memsize, /* in bytes */
                           unsigned long *pfns_special_pages, 
                           unsigned long nr_special_pages,
@@ -861,7 +861,7 @@ xc_ia64_setup_memmap_info(int xc_handle,
 
 /* setup shared_info page */
 static int
-xc_ia64_setup_shared_info(int xc_handle, uint32_t dom,
+xc_ia64_setup_shared_info(xc_interface *xc_handle, uint32_t dom,
                           unsigned long shared_info_pfn,
                           unsigned long memmap_info_pfn,
                           unsigned long memmap_info_num_pages)
@@ -891,7 +891,7 @@ xc_ia64_setup_shared_info(int xc_handle,
  * convenient to allocate discontiguous memory with different size.
  */
 static int
-setup_guest(int xc_handle, uint32_t dom, unsigned long memsize,
+setup_guest(xc_interface *xc_handle, uint32_t dom, unsigned long memsize,
             char *image, unsigned long image_size)
 {
     xen_pfn_t *pfn_list;
@@ -1055,7 +1055,7 @@ error_out:
 }
 
 int
-xc_hvm_build(int xc_handle, uint32_t domid, int memsize, const char 
*image_name)
+xc_hvm_build(xc_interface *xc_handle, uint32_t domid, int memsize, const char 
*image_name)
 {
     vcpu_guest_context_any_t st_ctxt_any;
     vcpu_guest_context_t *ctxt = &st_ctxt_any.c;
@@ -1105,7 +1105,7 @@ error_out:
  * memsize pages marked populate-on-demand, and with a PoD cache size
  * of target.  If target == memsize, pages are populated normally.
  */
-int xc_hvm_build_target_mem(int xc_handle,
+int xc_hvm_build_target_mem(xc_interface *xc_handle,
                             uint32_t domid,
                             int memsize,
                             int target,
@@ -1131,7 +1131,7 @@ int xc_hvm_build_target_mem(int xc_handl
 #define _PAGE_AR_RW     (2 <<  9)       /* read & write */
 
 int
-xc_ia64_set_os_type(int xc_handle, char *guest_os_type, uint32_t dom)
+xc_ia64_set_os_type(xc_interface *xc_handle, char *guest_os_type, uint32_t dom)
 {
     DECLARE_DOMCTL;
 
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/ia64/xc_ia64_linux_restore.c
--- a/tools/libxc/ia64/xc_ia64_linux_restore.c  Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/ia64/xc_ia64_linux_restore.c  Fri May 28 09:30:19 2010 +0100
@@ -29,7 +29,7 @@ static unsigned long nr_pfns;
 static unsigned long nr_pfns;
 
 static int
-populate_page_if_necessary(int xc_handle, uint32_t dom, unsigned long gmfn,
+populate_page_if_necessary(xc_interface *xc_handle, uint32_t dom, unsigned 
long gmfn,
                            struct xen_ia64_p2m_table *p2m_table)
 {
     if (xc_ia64_p2m_present(p2m_table, gmfn))
@@ -39,7 +39,7 @@ populate_page_if_necessary(int xc_handle
 }
 
 static int
-read_page(int xc_handle, int io_fd, uint32_t dom, unsigned long pfn)
+read_page(xc_interface *xc_handle, int io_fd, uint32_t dom, unsigned long pfn)
 {
     void *mem;
 
@@ -65,7 +65,7 @@ read_page(int xc_handle, int io_fd, uint
  * pages here.
  */
 static int
-xc_ia64_recv_unallocated_list(int xc_handle, int io_fd, uint32_t dom,
+xc_ia64_recv_unallocated_list(xc_interface *xc_handle, int io_fd, uint32_t dom,
                               struct xen_ia64_p2m_table *p2m_table)
 {
     int rc = -1;
@@ -116,7 +116,7 @@ xc_ia64_recv_unallocated_list(int xc_han
 }
 
 static int
-xc_ia64_recv_vcpu_context(int xc_handle, int io_fd, uint32_t dom,
+xc_ia64_recv_vcpu_context(xc_interface *xc_handle, int io_fd, uint32_t dom,
                           uint32_t vcpu, vcpu_guest_context_any_t *ctxt_any)
 {
     vcpu_guest_context_t *ctxt = &ctxt_any->c;
@@ -147,7 +147,7 @@ xc_ia64_recv_vcpu_context(int xc_handle,
 
 /* Read shared info.  */
 static int
-xc_ia64_recv_shared_info(int xc_handle, int io_fd, uint32_t dom,
+xc_ia64_recv_shared_info(xc_interface *xc_handle, int io_fd, uint32_t dom,
                          unsigned long shared_info_frame,
                          unsigned long *start_info_pfn)
 {
@@ -222,7 +222,7 @@ xc_ia64_recv_vcpumap(const xc_dominfo_t 
 }
 
 static int
-xc_ia64_pv_recv_vcpu_context(int xc_handle, int io_fd, int32_t dom,
+xc_ia64_pv_recv_vcpu_context(xc_interface *xc_handle, int io_fd, int32_t dom,
                              uint32_t vcpu)
 {
     int rc = -1;
@@ -254,7 +254,7 @@ xc_ia64_pv_recv_vcpu_context(int xc_hand
 }
 
 static int
-xc_ia64_pv_recv_shared_info(int xc_handle, int io_fd, int32_t dom, 
+xc_ia64_pv_recv_shared_info(xc_interface *xc_handle, int io_fd, int32_t dom, 
                             unsigned long shared_info_frame,
                             struct xen_ia64_p2m_table *p2m_table,
                             unsigned int store_evtchn,
@@ -296,7 +296,7 @@ xc_ia64_pv_recv_shared_info(int xc_handl
 }
 
 static int
-xc_ia64_pv_recv_context_ver_one_or_two(int xc_handle, int io_fd, uint32_t dom,
+xc_ia64_pv_recv_context_ver_one_or_two(xc_interface *xc_handle, int io_fd, 
uint32_t dom,
                                        unsigned long shared_info_frame,
                                        struct xen_ia64_p2m_table *p2m_table,
                                        unsigned int store_evtchn,
@@ -320,7 +320,7 @@ xc_ia64_pv_recv_context_ver_one_or_two(i
 }
 
 static int
-xc_ia64_pv_recv_context_ver_three(int xc_handle, int io_fd, uint32_t dom,
+xc_ia64_pv_recv_context_ver_three(xc_interface *xc_handle, int io_fd, uint32_t 
dom,
                                   unsigned long shared_info_frame,
                                   struct xen_ia64_p2m_table *p2m_table,
                                   unsigned int store_evtchn,
@@ -365,7 +365,7 @@ xc_ia64_pv_recv_context_ver_three(int xc
 
 static int
 xc_ia64_pv_recv_context(unsigned long format_version,
-                        int xc_handle, int io_fd, uint32_t dom,
+                        xc_interface *xc_handle, int io_fd, uint32_t dom,
                         unsigned long shared_info_frame,
                         struct xen_ia64_p2m_table *p2m_table,
                         unsigned int store_evtchn,
@@ -399,7 +399,7 @@ xc_ia64_pv_recv_context(unsigned long fo
 }
 
 static int
-xc_ia64_hvm_recv_context(int xc_handle, int io_fd, uint32_t dom,
+xc_ia64_hvm_recv_context(xc_interface *xc_handle, int io_fd, uint32_t dom,
                          unsigned long shared_info_frame,
                          struct xen_ia64_p2m_table *p2m_table,
                          unsigned int store_evtchn, unsigned long *store_mfn,
@@ -521,7 +521,7 @@ out:
  * hvm domain requires IO pages allocated when XEN_DOMCTL_arch_setup
  */
 static int
-xc_ia64_hvm_domain_setup(int xc_handle, uint32_t dom)
+xc_ia64_hvm_domain_setup(xc_interface *xc_handle, uint32_t dom)
 {
     int rc;
     xen_pfn_t pfn_list[] = {
@@ -539,7 +539,7 @@ xc_ia64_hvm_domain_setup(int xc_handle, 
 }
 
 int
-xc_domain_restore(int xc_handle, int io_fd, uint32_t dom,
+xc_domain_restore(xc_interface *xc_handle, int io_fd, uint32_t dom,
                   unsigned int store_evtchn, unsigned long *store_mfn,
                   unsigned int console_evtchn, unsigned long *console_mfn,
                   unsigned int hvm, unsigned int pae, int superpages)
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/ia64/xc_ia64_linux_save.c
--- a/tools/libxc/ia64/xc_ia64_linux_save.c     Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/ia64/xc_ia64_linux_save.c     Fri May 28 09:30:19 2010 +0100
@@ -54,7 +54,7 @@ static inline void set_bit(int nr, volat
 
 static int
 suspend_and_state(int (*suspend)(void*), void* data,
-                  int xc_handle, int io_fd,
+                  xc_interface *xc_handle, int io_fd,
                   int dom, xc_dominfo_t *info)
 {
     if ( !(*suspend)(data) ) {
@@ -86,7 +86,7 @@ md_is_not_ram(const efi_memory_desc_t *m
  * page after pausing the domain.
  */
 static int
-xc_ia64_send_unallocated_list(int xc_handle, int io_fd, 
+xc_ia64_send_unallocated_list(xc_interface *xc_handle, int io_fd, 
                               struct xen_ia64_p2m_table *p2m_table,
                               xen_ia64_memmap_info_t *memmap_info, 
                               void *memmap_desc_start, void *memmap_desc_end)
@@ -155,7 +155,7 @@ xc_ia64_send_unallocated_list(int xc_han
 }
 
 static int
-xc_ia64_send_vcpu_context(int xc_handle, int io_fd, uint32_t dom,
+xc_ia64_send_vcpu_context(xc_interface *xc_handle, int io_fd, uint32_t dom,
                           uint32_t vcpu, vcpu_guest_context_any_t *ctxt_any)
 {
     vcpu_guest_context_t *ctxt = &ctxt_any->c;
@@ -174,7 +174,7 @@ xc_ia64_send_vcpu_context(int xc_handle,
 }
 
 static int
-xc_ia64_send_shared_info(int xc_handle, int io_fd, shared_info_t *live_shinfo)
+xc_ia64_send_shared_info(xc_interface *xc_handle, int io_fd, shared_info_t 
*live_shinfo)
 {
     if (write_exact(io_fd, live_shinfo, PAGE_SIZE)) {
         ERROR("Error when writing to state file (1)");
@@ -184,7 +184,7 @@ xc_ia64_send_shared_info(int xc_handle, 
 }
 
 static int
-xc_ia64_send_vcpumap(int xc_handle, int io_fd, uint32_t dom,
+xc_ia64_send_vcpumap(xc_interface *xc_handle, int io_fd, uint32_t dom,
                      const xc_dominfo_t *info, uint64_t max_virt_cpus,
                      uint64_t **vcpumapp)
 {
@@ -231,7 +231,7 @@ xc_ia64_send_vcpumap(int xc_handle, int 
 
 
 static int
-xc_ia64_pv_send_context(int xc_handle, int io_fd, uint32_t dom,
+xc_ia64_pv_send_context(xc_interface *xc_handle, int io_fd, uint32_t dom,
                         const xc_dominfo_t *info, shared_info_t *live_shinfo)
 {
     int rc = -1;
@@ -280,7 +280,7 @@ xc_ia64_pv_send_context(int xc_handle, i
 }
 
 static int
-xc_ia64_hvm_send_context(int xc_handle, int io_fd, uint32_t dom,
+xc_ia64_hvm_send_context(xc_interface *xc_handle, int io_fd, uint32_t dom,
                          const xc_dominfo_t *info, shared_info_t *live_shinfo)
 {
     int rc = -1;
@@ -381,7 +381,7 @@ out:
 }
 
 int
-xc_domain_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
+xc_domain_save(xc_interface *xc_handle, int io_fd, uint32_t dom, uint32_t 
max_iters,
                uint32_t max_factor, uint32_t flags,
                struct save_callbacks* callbacks,
                int hvm, void (*switch_qemu_logdirty)(int, unsigned))
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/ia64/xc_ia64_stubs.c
--- a/tools/libxc/ia64/xc_ia64_stubs.c  Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/ia64/xc_ia64_stubs.c  Fri May 28 09:30:19 2010 +0100
@@ -19,7 +19,7 @@ xc_ia64_fpsr_default(void)
 }
 
 static int
-xc_ia64_get_pfn_list(int xc_handle, uint32_t domid, xen_pfn_t *pfn_buf,
+xc_ia64_get_pfn_list(xc_interface *xc_handle, uint32_t domid, xen_pfn_t 
*pfn_buf,
                      unsigned int start_page, unsigned int nr_pages)
 {
     DECLARE_DOMCTL;
@@ -43,7 +43,7 @@ xc_ia64_get_pfn_list(int xc_handle, uint
 }
 
 int
-xc_get_pfn_list(int xc_handle, uint32_t domid, uint64_t *pfn_buf,
+xc_get_pfn_list(xc_interface *xc_handle, uint32_t domid, uint64_t *pfn_buf,
                 unsigned long max_pfns)
 {
     return xc_ia64_get_pfn_list(xc_handle, domid, (xen_pfn_t *)pfn_buf,
@@ -51,7 +51,7 @@ xc_get_pfn_list(int xc_handle, uint32_t 
 }
 
 long
-xc_get_max_pages(int xc_handle, uint32_t domid)
+xc_get_max_pages(xc_interface *xc_handle, uint32_t domid)
 {
     struct xen_domctl domctl;
     domctl.cmd = XEN_DOMCTL_getdomaininfo;
@@ -63,7 +63,7 @@ xc_get_max_pages(int xc_handle, uint32_t
 /* It is possible to get memmap_info and memmap by
    foreign domain page mapping. But it's racy. Use hypercall to avoid race. */
 static int
-xc_ia64_get_memmap(int xc_handle,
+xc_ia64_get_memmap(xc_interface *xc_handle,
                    uint32_t domid, char *buf, unsigned long bufsize)
 {
     privcmd_hypercall_t hypercall;
@@ -84,7 +84,7 @@ xc_ia64_get_memmap(int xc_handle,
 }
 
 int
-xc_ia64_copy_memmap(int xc_handle, uint32_t domid, shared_info_t *live_shinfo,
+xc_ia64_copy_memmap(xc_interface *xc_handle, uint32_t domid, shared_info_t 
*live_shinfo,
                     xen_ia64_memmap_info_t **memmap_info_p,
                     unsigned long *memmap_info_num_pages_p)
 {
@@ -163,7 +163,7 @@ xc_ia64_copy_memmap(int xc_handle, uint3
 #define PTRS_PER_PTE    (1UL << (PAGE_SHIFT - 3))
 
 static void*
-xc_ia64_map_foreign_p2m(int xc_handle, uint32_t dom,
+xc_ia64_map_foreign_p2m(xc_interface *xc_handle, uint32_t dom,
                         struct xen_ia64_memmap_info *memmap_info,
                         unsigned long flags, unsigned long *p2m_size_p)
 {
@@ -219,7 +219,7 @@ xc_ia64_p2m_init(struct xen_ia64_p2m_tab
 }
 
 int
-xc_ia64_p2m_map(struct xen_ia64_p2m_table *p2m_table, int xc_handle,
+xc_ia64_p2m_map(struct xen_ia64_p2m_table *p2m_table, xc_interface *xc_handle,
                 uint32_t domid, struct xen_ia64_memmap_info *memmap_info,
                 unsigned long flag)
 {
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_acm.c
--- a/tools/libxc/xc_acm.c      Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_acm.c      Fri May 28 09:30:19 2010 +0100
@@ -14,7 +14,7 @@
 
 #include "xc_private.h"
 
-int xc_acm_op(int xc_handle, int cmd, void *arg, unsigned long arg_size)
+int xc_acm_op(xc_interface *xch, int cmd, void *arg, unsigned long arg_size)
 {
     int ret;
     DECLARE_HYPERCALL;
@@ -88,7 +88,7 @@ int xc_acm_op(int xc_handle, int cmd, vo
         PERROR("Could not lock memory for Xen hypercall");
         return -EFAULT;
     }
-    if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0)
+    if ( (ret = do_xen_hypercall(xch, &hypercall)) < 0)
     {
         if ( errno == EACCES )
             DPRINTF("acmctl operation failed -- need to"
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_core.c
--- a/tools/libxc/xc_core.c     Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_core.c     Fri May 28 09:30:19 2010 +0100
@@ -66,7 +66,7 @@ struct xc_core_strtab {
 };
 
 static struct xc_core_strtab*
-xc_core_strtab_init(void)
+xc_core_strtab_init(xc_interface *xch)
 {
     struct xc_core_strtab *strtab;
     char *strings;
@@ -99,7 +99,7 @@ xc_core_strtab_free(struct xc_core_strta
 }
 
 static uint16_t
-xc_core_strtab_get(struct xc_core_strtab *strtab, const char *name)
+xc_core_strtab_get(xc_interface *xch, struct xc_core_strtab *strtab, const 
char *name)
 {
     uint16_t ret = 0;
     uint16_t len = strlen(name) + 1;
@@ -150,7 +150,7 @@ struct xc_core_section_headers {
 #define SHDR_INC        ((uint16_t)4)
 
 static struct xc_core_section_headers*
-xc_core_shdr_init(void)
+xc_core_shdr_init(xc_interface *xch)
 {
     struct xc_core_section_headers *sheaders;
     sheaders = malloc(sizeof(*sheaders));
@@ -176,7 +176,8 @@ xc_core_shdr_free(struct xc_core_section
 }
 
 Elf64_Shdr*
-xc_core_shdr_get(struct xc_core_section_headers *sheaders)
+xc_core_shdr_get(xc_interface *xch,
+                 struct xc_core_section_headers *sheaders)
 {
     Elf64_Shdr *shdr;
 
@@ -203,13 +204,14 @@ xc_core_shdr_get(struct xc_core_section_
 }
 
 int
-xc_core_shdr_set(Elf64_Shdr *shdr,
+xc_core_shdr_set(xc_interface *xch,
+                 Elf64_Shdr *shdr,
                  struct xc_core_strtab *strtab,
                  const char *name, uint32_t type,
                  uint64_t offset, uint64_t size,
                  uint64_t addralign, uint64_t entsize)
 {
-    uint64_t name_idx = xc_core_strtab_get(strtab, name);
+    uint64_t name_idx = xc_core_strtab_get(xch, strtab, name);
     if ( name_idx == 0 )
         return -1;
 
@@ -252,44 +254,44 @@ xc_core_ehdr_init(Elf64_Ehdr *ehdr)
 }
 
 static int
-elfnote_fill_xen_version(int xc_handle,
+elfnote_fill_xen_version(xc_interface *xch,
                          struct xen_dumpcore_elfnote_xen_version_desc
                          *xen_version)
 {
     int rc;
     memset(xen_version, 0, sizeof(*xen_version));
 
-    rc = xc_version(xc_handle, XENVER_version, NULL);
+    rc = xc_version(xch, XENVER_version, NULL);
     if ( rc < 0 )
         return rc;
     xen_version->major_version = rc >> 16;
     xen_version->minor_version = rc & ((1 << 16) - 1);
 
-    rc = xc_version(xc_handle, XENVER_extraversion,
+    rc = xc_version(xch, XENVER_extraversion,
                     &xen_version->extra_version);
     if ( rc < 0 )
         return rc;
 
-    rc = xc_version(xc_handle, XENVER_compile_info,
+    rc = xc_version(xch, XENVER_compile_info,
                     &xen_version->compile_info);
     if ( rc < 0 )
         return rc;
 
-    rc = xc_version(xc_handle,
+    rc = xc_version(xch,
                     XENVER_capabilities, &xen_version->capabilities);
     if ( rc < 0 )
         return rc;
 
-    rc = xc_version(xc_handle, XENVER_changeset, &xen_version->changeset);
+    rc = xc_version(xch, XENVER_changeset, &xen_version->changeset);
     if ( rc < 0 )
         return rc;
 
-    rc = xc_version(xc_handle, XENVER_platform_parameters,
+    rc = xc_version(xch, XENVER_platform_parameters,
                     &xen_version->platform_parameters);
     if ( rc < 0 )
         return rc;
 
-    rc = xc_version(xc_handle, XENVER_pagesize, NULL);
+    rc = xc_version(xch, XENVER_pagesize, NULL);
     if ( rc < 0 )
         return rc;
     xen_version->pagesize = rc;
@@ -314,7 +316,7 @@ elfnote_init(struct elfnote *elfnote)
 }
 
 static int
-elfnote_dump_none(void *args, dumpcore_rtn_t dump_rtn)
+elfnote_dump_none(xc_interface *xch, void *args, dumpcore_rtn_t dump_rtn)
 {
     int sts;
     struct elfnote elfnote;
@@ -326,14 +328,15 @@ elfnote_dump_none(void *args, dumpcore_r
 
     elfnote.descsz = sizeof(none);
     elfnote.type = XEN_ELFNOTE_DUMPCORE_NONE;
-    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
+    sts = dump_rtn(xch, args, (char*)&elfnote, sizeof(elfnote));
     if ( sts != 0 )
         return sts;
-    return dump_rtn(args, (char*)&none, sizeof(none));
+    return dump_rtn(xch, args, (char*)&none, sizeof(none));
 }
 
 static int
 elfnote_dump_core_header(
+    xc_interface *xch,
     void *args, dumpcore_rtn_t dump_rtn, const xc_dominfo_t *info,
     int nr_vcpus, unsigned long nr_pages)
 {
@@ -350,15 +353,15 @@ elfnote_dump_core_header(
     header.xch_nr_vcpus = nr_vcpus;
     header.xch_nr_pages = nr_pages;
     header.xch_page_size = PAGE_SIZE;
-    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
+    sts = dump_rtn(xch, args, (char*)&elfnote, sizeof(elfnote));
     if ( sts != 0 )
         return sts;
-    return dump_rtn(args, (char*)&header, sizeof(header));
+    return dump_rtn(xch, args, (char*)&header, sizeof(header));
 }
 
 static int
-elfnote_dump_xen_version(void *args, dumpcore_rtn_t dump_rtn, int xc_handle,
-                         unsigned int guest_width)
+elfnote_dump_xen_version(xc_interface *xch, void *args,
+                         dumpcore_rtn_t dump_rtn, unsigned int guest_width)
 {
     int sts;
     struct elfnote elfnote;
@@ -369,21 +372,22 @@ elfnote_dump_xen_version(void *args, dum
 
     elfnote.descsz = sizeof(xen_version);
     elfnote.type = XEN_ELFNOTE_DUMPCORE_XEN_VERSION;
-    elfnote_fill_xen_version(xc_handle, &xen_version);
+    elfnote_fill_xen_version(xch, &xen_version);
     if (guest_width < sizeof(unsigned long))
     {
         // 32 bit elf file format differs in pagesize's alignment
         char *p = (char *)&xen_version.pagesize;
         memmove(p - 4, p, sizeof(xen_version.pagesize));
     }
-    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
+    sts = dump_rtn(xch, args, (char*)&elfnote, sizeof(elfnote));
     if ( sts != 0 )
         return sts;
-    return dump_rtn(args, (char*)&xen_version, sizeof(xen_version));
+    return dump_rtn(xch, args, (char*)&xen_version, sizeof(xen_version));
 }
 
 static int
-elfnote_dump_format_version(void *args, dumpcore_rtn_t dump_rtn)
+elfnote_dump_format_version(xc_interface *xch,
+                            void *args, dumpcore_rtn_t dump_rtn)
 {
     int sts;
     struct elfnote elfnote;
@@ -395,14 +399,14 @@ elfnote_dump_format_version(void *args, 
     elfnote.descsz = sizeof(format_version);
     elfnote.type = XEN_ELFNOTE_DUMPCORE_FORMAT_VERSION;
     elfnote_fill_format_version(&format_version);
-    sts = dump_rtn(args, (char*)&elfnote, sizeof(elfnote));
+    sts = dump_rtn(xch, args, (char*)&elfnote, sizeof(elfnote));
     if ( sts != 0 )
         return sts;
-    return dump_rtn(args, (char*)&format_version, sizeof(format_version));
+    return dump_rtn(xch, args, (char*)&format_version, sizeof(format_version));
 }
 
 static int
-get_guest_width(int xc_handle,
+get_guest_width(xc_interface *xch,
                 uint32_t domid,
                 unsigned int *guest_width)
 {
@@ -412,7 +416,7 @@ get_guest_width(int xc_handle,
     domctl.domain = domid;
     domctl.cmd = XEN_DOMCTL_get_address_size;
 
-    if ( do_domctl(xc_handle, &domctl) != 0 )
+    if ( do_domctl(xch, &domctl) != 0 )
         return 1;
         
     *guest_width = domctl.u.address_size.size / 8;
@@ -420,7 +424,7 @@ get_guest_width(int xc_handle,
 }
 
 int
-xc_domain_dumpcore_via_callback(int xc_handle,
+xc_domain_dumpcore_via_callback(xc_interface *xch,
                                 uint32_t domid,
                                 void *args,
                                 dumpcore_rtn_t dump_rtn)
@@ -463,7 +467,7 @@ xc_domain_dumpcore_via_callback(int xc_h
     struct xc_core_section_headers *sheaders = NULL;
     Elf64_Shdr *shdr;
  
-    if ( get_guest_width(xc_handle, domid, &dinfo->guest_width) != 0 )
+    if ( get_guest_width(xch, domid, &dinfo->guest_width) != 0 )
     {
         PERROR("Could not get address size for domain");
         return sts;
@@ -476,13 +480,13 @@ xc_domain_dumpcore_via_callback(int xc_h
         goto out;
     }
 
-    if ( xc_domain_getinfo(xc_handle, domid, 1, &info) != 1 )
+    if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 )
     {
         PERROR("Could not get info for domain");
         goto out;
     }
     /* Map the shared info frame */
-    live_shinfo = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
+    live_shinfo = xc_map_foreign_range(xch, domid, PAGE_SIZE,
                                        PROT_READ, info.shared_info_frame);
     if ( !live_shinfo && !info.hvm )
     {
@@ -506,10 +510,10 @@ xc_domain_dumpcore_via_callback(int xc_h
 
     for ( i = 0; i <= info.max_vcpu_id; i++ )
     {
-        if ( xc_vcpu_getcontext(xc_handle, domid, i, &ctxt[nr_vcpus]) == 0 )
+        if ( xc_vcpu_getcontext(xch, domid, i, &ctxt[nr_vcpus]) == 0 )
         {
             if ( xc_core_arch_context_get(&arch_ctxt, &ctxt[nr_vcpus],
-                                          xc_handle, domid) )
+                                          xch, domid) )
                 continue;
             nr_vcpus++;
         }
@@ -521,7 +525,7 @@ xc_domain_dumpcore_via_callback(int xc_h
     }
 
     /* obtain memory map */
-    sts = xc_core_arch_memory_map_get(xc_handle, &arch_ctxt, &info,
+    sts = xc_core_arch_memory_map_get(xch, &arch_ctxt, &info,
                                       live_shinfo, &memory_map,
                                       &nr_memory_map);
     if ( sts != 0 )
@@ -548,7 +552,7 @@ xc_domain_dumpcore_via_callback(int xc_h
             goto out;
         }
 
-        sts = xc_core_arch_map_p2m(xc_handle, dinfo->guest_width, &info, 
live_shinfo,
+        sts = xc_core_arch_map_p2m(xch, dinfo->guest_width, &info, live_shinfo,
                                    &p2m, &p2m_size);
         if ( sts != 0 )
             goto out;
@@ -567,20 +571,20 @@ xc_domain_dumpcore_via_callback(int xc_h
     xc_core_ehdr_init(&ehdr);
 
     /* create section header */
-    strtab = xc_core_strtab_init();
+    strtab = xc_core_strtab_init(xch);
     if ( strtab == NULL )
     {
         PERROR("Could not allocate string table");
         goto out;
     }
-    sheaders = xc_core_shdr_init();
+    sheaders = xc_core_shdr_init(xch);
     if ( sheaders == NULL )
     {
         PERROR("Could not allocate section headers");
         goto out;
     }
     /* null section */
-    shdr = xc_core_shdr_get(sheaders);
+    shdr = xc_core_shdr_get(xch,sheaders);
     if ( shdr == NULL )
     {
         PERROR("Could not get section header for null section");
@@ -588,7 +592,7 @@ xc_domain_dumpcore_via_callback(int xc_h
     }
 
     /* .shstrtab */
-    shdr = xc_core_shdr_get(sheaders);
+    shdr = xc_core_shdr_get(xch,sheaders);
     if ( shdr == NULL )
     {
         PERROR("Could not get section header for shstrtab");
@@ -598,7 +602,7 @@ xc_domain_dumpcore_via_callback(int xc_h
     /* strtab_shdr.sh_offset, strtab_shdr.sh_size aren't unknown.
      * fill it later
      */
-    sts = xc_core_shdr_set(shdr, strtab, ELF_SHSTRTAB, SHT_STRTAB, 0, 0, 0, 0);
+    sts = xc_core_shdr_set(xch, shdr, strtab, ELF_SHSTRTAB, SHT_STRTAB, 0, 0, 
0, 0);
     if ( sts != 0 )
         goto out;
 
@@ -610,27 +614,27 @@ xc_domain_dumpcore_via_callback(int xc_h
         sizeof(struct xen_dumpcore_elfnote_header) +       /* core header */
         sizeof(struct xen_dumpcore_elfnote_xen_version) +  /* xen version */
         sizeof(struct xen_dumpcore_elfnote_format_version);/* format version */
-    shdr = xc_core_shdr_get(sheaders);
+    shdr = xc_core_shdr_get(xch,sheaders);
     if ( shdr == NULL )
     {
         PERROR("Could not get section header for note section");
         goto out;
     }
-    sts = xc_core_shdr_set(shdr, strtab, XEN_DUMPCORE_SEC_NOTE, SHT_NOTE,
+    sts = xc_core_shdr_set(xch, shdr, strtab, XEN_DUMPCORE_SEC_NOTE, SHT_NOTE,
                            offset, filesz, 0, 0);
     if ( sts != 0 )
         goto out;
     offset += filesz;
 
     /* prstatus */
-    shdr = xc_core_shdr_get(sheaders);
+    shdr = xc_core_shdr_get(xch,sheaders);
     if ( shdr == NULL )
     {
         PERROR("Could not get section header for .xen_prstatus");
         goto out;
     }
     filesz = sizeof(*ctxt) * nr_vcpus;
-    sts = xc_core_shdr_set(shdr, strtab, XEN_DUMPCORE_SEC_PRSTATUS,
+    sts = xc_core_shdr_set(xch, shdr, strtab, XEN_DUMPCORE_SEC_PRSTATUS,
                            SHT_PROGBITS, offset, filesz,
                            __alignof__(*ctxt), sizeof(*ctxt));
     if ( sts != 0 )
@@ -647,14 +651,14 @@ xc_domain_dumpcore_via_callback(int xc_h
     /* shared_info */
     if ( live_shinfo != NULL )
     {
-        shdr = xc_core_shdr_get(sheaders);
+        shdr = xc_core_shdr_get(xch,sheaders);
         if ( shdr == NULL )
         {
             PERROR("Could not get section header for .xen_shared_info");
             goto out;
         }
         filesz = PAGE_SIZE;
-        sts = xc_core_shdr_set(shdr, strtab, XEN_DUMPCORE_SEC_SHARED_INFO,
+        sts = xc_core_shdr_set(xch, shdr, strtab, XEN_DUMPCORE_SEC_SHARED_INFO,
                                SHT_PROGBITS, offset, filesz,
                                __alignof__(*live_shinfo), PAGE_SIZE);
         if ( sts != 0 )
@@ -676,21 +680,21 @@ xc_domain_dumpcore_via_callback(int xc_h
     offset += dummy_len;
 
     /* pages */
-    shdr = xc_core_shdr_get(sheaders);
+    shdr = xc_core_shdr_get(xch,sheaders);
     if ( shdr == NULL )
     {
         PERROR("could not get section headers for .xen_pages");
         goto out;
     }
     filesz = (uint64_t)nr_pages * PAGE_SIZE;
-    sts = xc_core_shdr_set(shdr, strtab, XEN_DUMPCORE_SEC_PAGES, SHT_PROGBITS,
+    sts = xc_core_shdr_set(xch, shdr, strtab, XEN_DUMPCORE_SEC_PAGES, 
SHT_PROGBITS,
                            offset, filesz, PAGE_SIZE, PAGE_SIZE);
     if ( sts != 0 )
         goto out;
     offset += filesz;
 
     /* p2m/pfn table */
-    shdr = xc_core_shdr_get(sheaders);
+    shdr = xc_core_shdr_get(xch,sheaders);
     if ( shdr == NULL )
     {
         PERROR("Could not get section header for .xen_{p2m, pfn} table");
@@ -699,7 +703,7 @@ xc_domain_dumpcore_via_callback(int xc_h
     if ( !auto_translated_physmap )
     {
         filesz = (uint64_t)nr_pages * sizeof(p2m_array[0]);
-        sts = xc_core_shdr_set(shdr, strtab, XEN_DUMPCORE_SEC_P2M,
+        sts = xc_core_shdr_set(xch, shdr, strtab, XEN_DUMPCORE_SEC_P2M,
                                SHT_PROGBITS,
                                offset, filesz, __alignof__(p2m_array[0]),
                                sizeof(p2m_array[0]));
@@ -707,7 +711,7 @@ xc_domain_dumpcore_via_callback(int xc_h
     else
     {
         filesz = (uint64_t)nr_pages * sizeof(pfn_array[0]);
-        sts = xc_core_shdr_set(shdr, strtab, XEN_DUMPCORE_SEC_PFN,
+        sts = xc_core_shdr_set(xch, shdr, strtab, XEN_DUMPCORE_SEC_PFN,
                                SHT_PROGBITS,
                                offset, filesz, __alignof__(pfn_array[0]),
                                sizeof(pfn_array[0]));
@@ -725,45 +729,45 @@ xc_domain_dumpcore_via_callback(int xc_h
     ehdr.e_shnum = sheaders->num;
     ehdr.e_shstrndx = strtab_idx;
     ehdr.e_machine = ELF_ARCH_MACHINE;
-    sts = dump_rtn(args, (char*)&ehdr, sizeof(ehdr));
+    sts = dump_rtn(xch, args, (char*)&ehdr, sizeof(ehdr));
     if ( sts != 0 )
         goto out;
 
     /* section headers */
-    sts = dump_rtn(args, (char*)sheaders->shdrs,
+    sts = dump_rtn(xch, args, (char*)sheaders->shdrs,
                    sheaders->num * sizeof(sheaders->shdrs[0]));
     if ( sts != 0 )
         goto out;
 
     /* elf note section: xen core header */
-    sts = elfnote_dump_none(args, dump_rtn);
+    sts = elfnote_dump_none(xch, args, dump_rtn);
     if ( sts != 0 )
         goto out;
 
     /* elf note section: xen core header */
-    sts = elfnote_dump_core_header(args, dump_rtn, &info, nr_vcpus, nr_pages);
+    sts = elfnote_dump_core_header(xch, args, dump_rtn, &info, nr_vcpus, 
nr_pages);
     if ( sts != 0 )
         goto out;
 
     /* elf note section: xen version */
-    sts = elfnote_dump_xen_version(args, dump_rtn, xc_handle, 
dinfo->guest_width);
+    sts = elfnote_dump_xen_version(xch, args, dump_rtn, dinfo->guest_width);
     if ( sts != 0 )
         goto out;
 
     /* elf note section: format version */
-    sts = elfnote_dump_format_version(args, dump_rtn);
+    sts = elfnote_dump_format_version(xch, args, dump_rtn);
     if ( sts != 0 )
         goto out;
 
     /* prstatus: .xen_prstatus */
-    sts = dump_rtn(args, (char *)ctxt, sizeof(*ctxt) * nr_vcpus);
+    sts = dump_rtn(xch, args, (char *)ctxt, sizeof(*ctxt) * nr_vcpus);
     if ( sts != 0 )
         goto out;
 
     if ( live_shinfo != NULL )
     {
         /* shared_info: .xen_shared_info */
-        sts = dump_rtn(args, (char*)live_shinfo, PAGE_SIZE);
+        sts = dump_rtn(xch, args, (char*)live_shinfo, PAGE_SIZE);
         if ( sts != 0 )
             goto out;
     }
@@ -775,7 +779,7 @@ xc_domain_dumpcore_via_callback(int xc_h
 
     /* Pad the output data to page alignment. */
     memset(dummy, 0, PAGE_SIZE);
-    sts = dump_rtn(args, dummy, dummy_len);
+    sts = dump_rtn(xch, args, dummy, dummy_len);
     if ( sts != 0 )
         goto out;
 
@@ -835,7 +839,7 @@ xc_domain_dumpcore_via_callback(int xc_h
             }
 
             vaddr = xc_map_foreign_range(
-                xc_handle, domid, PAGE_SIZE, PROT_READ, gmfn);
+                xch, domid, PAGE_SIZE, PROT_READ, gmfn);
             if ( vaddr == NULL )
                 continue;
             memcpy(dump_mem, vaddr, PAGE_SIZE);
@@ -844,7 +848,7 @@ xc_domain_dumpcore_via_callback(int xc_h
             if ( (j + 1) % DUMP_INCREMENT == 0 )
             {
                 sts = dump_rtn(
-                    args, dump_mem_start, dump_mem - dump_mem_start);
+                    xch, args, dump_mem_start, dump_mem - dump_mem_start);
                 if ( sts != 0 )
                     goto out;
                 dump_mem = dump_mem_start;
@@ -855,7 +859,7 @@ xc_domain_dumpcore_via_callback(int xc_h
     }
 
 copy_done:
-    sts = dump_rtn(args, dump_mem_start, dump_mem - dump_mem_start);
+    sts = dump_rtn(xch, args, dump_mem_start, dump_mem - dump_mem_start);
     if ( sts != 0 )
         goto out;
     if ( j < nr_pages )
@@ -866,7 +870,7 @@ copy_done:
         IPRINTF("j (%ld) != nr_pages (%ld)", j, nr_pages);
         memset(dump_mem_start, 0, PAGE_SIZE);
         for (; j < nr_pages; j++) {
-            sts = dump_rtn(args, dump_mem_start, PAGE_SIZE);
+            sts = dump_rtn(xch, args, dump_mem_start, PAGE_SIZE);
             if ( sts != 0 )
                 goto out;
             if ( !auto_translated_physmap )
@@ -882,15 +886,15 @@ copy_done:
     /* p2m/pfn table: .xen_p2m/.xen_pfn */
     if ( !auto_translated_physmap )
         sts = dump_rtn(
-            args, (char *)p2m_array, sizeof(p2m_array[0]) * nr_pages);
+            xch, args, (char *)p2m_array, sizeof(p2m_array[0]) * nr_pages);
     else
         sts = dump_rtn(
-            args, (char *)pfn_array, sizeof(pfn_array[0]) * nr_pages);
+            xch, args, (char *)pfn_array, sizeof(pfn_array[0]) * nr_pages);
     if ( sts != 0 )
         goto out;
 
     /* elf section header string table: .shstrtab */
-    sts = dump_rtn(args, strtab->strings, strtab->length);
+    sts = dump_rtn(xch, args, strtab->strings, strtab->length);
     if ( sts != 0 )
         goto out;
 
@@ -926,7 +930,8 @@ struct dump_args {
 };
 
 /* Callback routine for writing to a local dump file. */
-static int local_file_dump(void *args, char *buffer, unsigned int length)
+static int local_file_dump(xc_interface *xch,
+                           void *args, char *buffer, unsigned int length)
 {
     struct dump_args *da = args;
 
@@ -940,14 +945,14 @@ static int local_file_dump(void *args, c
     {
         // Now dumping pages -- make sure we discard clean pages from
         // the cache after each write
-        discard_file_cache(da->fd, 0 /* no flush */);
+        discard_file_cache(xch, da->fd, 0 /* no flush */);
     }
 
     return 0;
 }
 
 int
-xc_domain_dumpcore(int xc_handle,
+xc_domain_dumpcore(xc_interface *xch,
                    uint32_t domid,
                    const char *corename)
 {
@@ -961,10 +966,10 @@ xc_domain_dumpcore(int xc_handle,
     }
 
     sts = xc_domain_dumpcore_via_callback(
-        xc_handle, domid, &da, &local_file_dump);
+        xch, domid, &da, &local_file_dump);
 
     /* flush and discard any remaining portion of the file from cache */
-    discard_file_cache(da.fd, 1/* flush first*/);
+    discard_file_cache(xch, da.fd, 1/* flush first*/);
 
     close(da.fd);
 
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_core.h
--- a/tools/libxc/xc_core.h     Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_core.h     Fri May 28 09:30:19 2010 +0100
@@ -119,9 +119,11 @@ struct xc_core_section_headers;
 struct xc_core_section_headers;
 
 Elf64_Shdr*
-xc_core_shdr_get(struct xc_core_section_headers *sheaders);
+xc_core_shdr_get(xc_interface *xch,
+                 struct xc_core_section_headers *sheaders);
 int
-xc_core_shdr_set(Elf64_Shdr *shdr,
+xc_core_shdr_set(xc_interface *xch,
+                 Elf64_Shdr *shdr,
                  struct xc_core_strtab *strtab,
                  const char *name, uint32_t type,
                  uint64_t offset, uint64_t size,
@@ -134,16 +136,16 @@ typedef struct xc_core_memory_map xc_cor
 typedef struct xc_core_memory_map xc_core_memory_map_t;
 int xc_core_arch_auto_translated_physmap(const xc_dominfo_t *info);
 struct xc_core_arch_context;
-int xc_core_arch_memory_map_get(int xc_handle,
+int xc_core_arch_memory_map_get(xc_interface *xch,
                                 struct xc_core_arch_context *arch_ctxt,
                                 xc_dominfo_t *info, shared_info_any_t 
*live_shinfo,
                                 xc_core_memory_map_t **mapp,
                                 unsigned int *nr_entries);
-int xc_core_arch_map_p2m(int xc_handle, unsigned int guest_width,
+int xc_core_arch_map_p2m(xc_interface *xch, unsigned int guest_width,
                          xc_dominfo_t *info, shared_info_any_t *live_shinfo,
                          xen_pfn_t **live_p2m, unsigned long *pfnp);
 
-int xc_core_arch_map_p2m_writable(int xc_handle, unsigned int guest_width,
+int xc_core_arch_map_p2m_writable(xc_interface *xch, unsigned int guest_width,
                                   xc_dominfo_t *info,
                                   shared_info_any_t *live_shinfo,
                                   xen_pfn_t **live_p2m, unsigned long *pfnp);
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_core_ia64.c
--- a/tools/libxc/xc_core_ia64.c        Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_core_ia64.c        Fri May 28 09:30:19 2010 +0100
@@ -67,7 +67,7 @@ xc_core_arch_auto_translated_physmap(con
 
 /* see setup_guest() @ xc_linux_build.c */
 static int
-memory_map_get_old_domu(int xc_handle, xc_dominfo_t *info,
+memory_map_get_old_domu(xc_interface *xch, xc_dominfo_t *info,
                         shared_info_any_t *live_shinfo,
                         xc_core_memory_map_t **mapp, unsigned int *nr_entries)
 {
@@ -95,7 +95,7 @@ out:
 
 /* see setup_guest() @ xc_ia64_hvm_build.c */
 static int
-memory_map_get_old_hvm(int xc_handle, xc_dominfo_t *info, 
+memory_map_get_old_hvm(xc_interface *xch, xc_dominfo_t *info, 
                        shared_info_any_t *live_shinfo,
                        xc_core_memory_map_t **mapp, unsigned int *nr_entries)
 {
@@ -154,21 +154,21 @@ out:
 }
 
 static int
-memory_map_get_old(int xc_handle, xc_dominfo_t *info, 
+memory_map_get_old(xc_interface *xch, xc_dominfo_t *info, 
                    shared_info_any_t *live_shinfo,
                    xc_core_memory_map_t **mapp, unsigned int *nr_entries)
 {
     if ( info->hvm )
-        return memory_map_get_old_hvm(xc_handle, info, live_shinfo,
+        return memory_map_get_old_hvm(xch, info, live_shinfo,
                                       mapp, nr_entries);
     if ( live_shinfo == NULL )
         return -1;
-    return memory_map_get_old_domu(xc_handle, info, live_shinfo,
+    return memory_map_get_old_domu(xch, info, live_shinfo,
                                    mapp, nr_entries);
 }
 
 int
-xc_core_arch_memory_map_get(int xc_handle,
+xc_core_arch_memory_map_get(xc_interface *xch,
                             struct xc_core_arch_context *arch_ctxt,
                             xc_dominfo_t *info,
                             shared_info_any_t *live_shinfo,
@@ -191,7 +191,7 @@ xc_core_arch_memory_map_get(int xc_handl
     }
 
     /* copy before use in case someone updating them */
-    if (xc_ia64_copy_memmap(xc_handle, info->domid, &live_shinfo->s,
+    if (xc_ia64_copy_memmap(xch, info->domid, &live_shinfo->s,
                             &memmap_info, NULL)) {
         goto old;
     }
@@ -223,7 +223,7 @@ xc_core_arch_memory_map_get(int xc_handl
     }
     ret = 0;
 
-    xc_ia64_p2m_map(&arch_ctxt->p2m_table, xc_handle, info->domid,
+    xc_ia64_p2m_map(&arch_ctxt->p2m_table, xch, info->domid,
                     memmap_info, 0);
     if ( memmap_info != NULL )
         free(memmap_info);
@@ -232,11 +232,11 @@ xc_core_arch_memory_map_get(int xc_handl
     
 old:
     DPRINTF("Falling back old method.\n");
-    return memory_map_get_old(xc_handle, info, live_shinfo, mapp, nr_entries);
-}
-
-int
-xc_core_arch_map_p2m(int xc_handle, unsigned int guest_width, xc_dominfo_t 
*info,
+    return memory_map_get_old(xch, info, live_shinfo, mapp, nr_entries);
+}
+
+int
+xc_core_arch_map_p2m(xc_interface *xch, unsigned int guest_width, xc_dominfo_t 
*info,
                      shared_info_any_t *live_shinfo, xen_pfn_t **live_p2m,
                      unsigned long *pfnp)
 {
@@ -273,7 +273,7 @@ int
 int
 xc_core_arch_context_get(struct xc_core_arch_context* arch_ctxt,
                          vcpu_guest_context_any_t* ctxt_any,
-                         int xc_handle, uint32_t domid)
+                         xc_interface *xch, uint32_t domid)
 {
     vcpu_guest_context_t *ctxt = &ctxt_any->c;
     mapped_regs_t* mapped_regs;
@@ -302,7 +302,7 @@ xc_core_arch_context_get(struct xc_core_
         arch_ctxt->mapped_regs = new;
     }
 
-    mapped_regs = xc_map_foreign_range(xc_handle, domid,
+    mapped_regs = xc_map_foreign_range(xch, domid,
                                        arch_ctxt->mapped_regs_size,
                                        PROT_READ, ctxt->privregs_pfn);
     if ( mapped_regs == NULL )
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_core_ia64.h
--- a/tools/libxc/xc_core_ia64.h        Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_core_ia64.h        Fri May 28 09:30:19 2010 +0100
@@ -41,7 +41,7 @@ int
 int
 xc_core_arch_context_get(struct xc_core_arch_context* arch_ctxt,
                          vcpu_guest_context_any_t* ctxt,
-                         int xc_handle, uint32_t domid);
+                         xc_interface *xch, uint32_t domid);
 int
 xc_core_arch_context_get_shdr(struct xc_core_arch_context* arch_ctxt, 
                               struct xc_core_section_headers *sheaders,
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_core_x86.c
--- a/tools/libxc/xc_core_x86.c Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_core_x86.c Fri May 28 09:30:19 2010 +0100
@@ -40,9 +40,9 @@ xc_core_arch_gpfn_may_present(struct xc_
 }
 
 
-static int nr_gpfns(int xc_handle, domid_t domid)
-{
-    return xc_memory_op(xc_handle, XENMEM_maximum_gpfn, &domid) + 1;
+static int nr_gpfns(xc_interface *xch, domid_t domid)
+{
+    return xc_memory_op(xch, XENMEM_maximum_gpfn, &domid) + 1;
 }
 
 int
@@ -52,12 +52,12 @@ xc_core_arch_auto_translated_physmap(con
 }
 
 int
-xc_core_arch_memory_map_get(int xc_handle, struct xc_core_arch_context *unused,
+xc_core_arch_memory_map_get(xc_interface *xch, struct xc_core_arch_context 
*unused,
                             xc_dominfo_t *info, shared_info_any_t *live_shinfo,
                             xc_core_memory_map_t **mapp,
                             unsigned int *nr_entries)
 {
-    unsigned long p2m_size = nr_gpfns(xc_handle, info->domid);
+    unsigned long p2m_size = nr_gpfns(xch, info->domid);
     xc_core_memory_map_t *map;
 
     map = malloc(sizeof(*map));
@@ -76,7 +76,7 @@ xc_core_arch_memory_map_get(int xc_handl
 }
 
 static int
-xc_core_arch_map_p2m_rw(int xc_handle, struct domain_info_context *dinfo, 
xc_dominfo_t *info,
+xc_core_arch_map_p2m_rw(xc_interface *xch, struct domain_info_context *dinfo, 
xc_dominfo_t *info,
                         shared_info_any_t *live_shinfo, xen_pfn_t **live_p2m,
                         unsigned long *pfnp, int rw)
 {
@@ -92,7 +92,7 @@ xc_core_arch_map_p2m_rw(int xc_handle, s
     int err;
     int i;
 
-    dinfo->p2m_size = nr_gpfns(xc_handle, info->domid);
+    dinfo->p2m_size = nr_gpfns(xch, info->domid);
     if ( dinfo->p2m_size < info->nr_pages  )
     {
         ERROR("p2m_size < nr_pages -1 (%lx < %lx", dinfo->p2m_size, 
info->nr_pages - 1);
@@ -100,7 +100,7 @@ xc_core_arch_map_p2m_rw(int xc_handle, s
     }
 
     live_p2m_frame_list_list =
-        xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ,
+        xc_map_foreign_range(xch, dom, PAGE_SIZE, PROT_READ,
                              GET_FIELD(live_shinfo, 
arch.pfn_to_mfn_frame_list_list));
 
     if ( !live_p2m_frame_list_list )
@@ -129,7 +129,7 @@ xc_core_arch_map_p2m_rw(int xc_handle, s
             p2m_frame_list_list[i] = ((uint32_t *)p2m_frame_list_list)[i];
 
     live_p2m_frame_list =
-        xc_map_foreign_pages(xc_handle, dom, PROT_READ,
+        xc_map_foreign_pages(xch, dom, PROT_READ,
                              p2m_frame_list_list,
                              P2M_FLL_ENTRIES);
 
@@ -156,7 +156,7 @@ xc_core_arch_map_p2m_rw(int xc_handle, s
         for ( i = P2M_FL_ENTRIES - 1; i >= 0; i-- )
             p2m_frame_list[i] = ((uint32_t *)p2m_frame_list)[i];
 
-    *live_p2m = xc_map_foreign_pages(xc_handle, dom,
+    *live_p2m = xc_map_foreign_pages(xch, dom,
                                     rw ? (PROT_READ | PROT_WRITE) : PROT_READ,
                                     p2m_frame_list,
                                     P2M_FL_ENTRIES);
@@ -191,24 +191,24 @@ out:
 }
 
 int
-xc_core_arch_map_p2m(int xc_handle, unsigned int guest_width, xc_dominfo_t 
*info,
+xc_core_arch_map_p2m(xc_interface *xch, unsigned int guest_width, xc_dominfo_t 
*info,
                         shared_info_any_t *live_shinfo, xen_pfn_t **live_p2m,
                         unsigned long *pfnp)
 {
     struct domain_info_context _dinfo = { .guest_width = guest_width };
     struct domain_info_context *dinfo = &_dinfo;
-    return xc_core_arch_map_p2m_rw(xc_handle, dinfo, info,
+    return xc_core_arch_map_p2m_rw(xch, dinfo, info,
                                    live_shinfo, live_p2m, pfnp, 0);
 }
 
 int
-xc_core_arch_map_p2m_writable(int xc_handle, unsigned int guest_width, 
xc_dominfo_t *info,
+xc_core_arch_map_p2m_writable(xc_interface *xch, unsigned int guest_width, 
xc_dominfo_t *info,
                               shared_info_any_t *live_shinfo, xen_pfn_t 
**live_p2m,
                               unsigned long *pfnp)
 {
     struct domain_info_context _dinfo = { .guest_width = guest_width };
     struct domain_info_context *dinfo = &_dinfo;
-    return xc_core_arch_map_p2m_rw(xc_handle, dinfo, info,
+    return xc_core_arch_map_p2m_rw(xch, dinfo, info,
                                    live_shinfo, live_p2m, pfnp, 1);
 }
 /*
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_core_x86.h
--- a/tools/libxc/xc_core_x86.h Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_core_x86.h Fri May 28 09:30:19 2010 +0100
@@ -30,7 +30,7 @@ struct xc_core_arch_context {
 
 #define xc_core_arch_context_init(arch_ctxt)            do {} while (0)
 #define xc_core_arch_context_free(arch_ctxt)            do {} while (0)
-#define xc_core_arch_context_get(arch_ctxt, ctxt, xc_handle, domid) \
+#define xc_core_arch_context_get(arch_ctxt, ctxt, xch, domid) \
                                                                 (0)
 #define xc_core_arch_context_dump(arch_ctxt, args, dump_rtn)    (0)
 
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_cpu_hotplug.c
--- a/tools/libxc/xc_cpu_hotplug.c      Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_cpu_hotplug.c      Fri May 28 09:30:19 2010 +0100
@@ -25,7 +25,7 @@
 
 #include "xc_private.h"
 
-int xc_cpu_online(int xc_handle, int cpu)
+int xc_cpu_online(xc_interface *xch, int cpu)
 {
     DECLARE_SYSCTL;
     int ret;
@@ -33,12 +33,12 @@ int xc_cpu_online(int xc_handle, int cpu
     sysctl.cmd = XEN_SYSCTL_cpu_hotplug;
     sysctl.u.cpu_hotplug.cpu = cpu;
     sysctl.u.cpu_hotplug.op = XEN_SYSCTL_CPU_HOTPLUG_ONLINE;
-    ret = xc_sysctl(xc_handle, &sysctl);
+    ret = xc_sysctl(xch, &sysctl);
 
     return ret;
 }
 
-int xc_cpu_offline(int xc_handle, int cpu)
+int xc_cpu_offline(xc_interface *xch, int cpu)
 {
     DECLARE_SYSCTL;
     int ret;
@@ -46,7 +46,7 @@ int xc_cpu_offline(int xc_handle, int cp
     sysctl.cmd = XEN_SYSCTL_cpu_hotplug;
     sysctl.u.cpu_hotplug.cpu = cpu;
     sysctl.u.cpu_hotplug.op = XEN_SYSCTL_CPU_HOTPLUG_OFFLINE;
-    ret = xc_sysctl(xc_handle, &sysctl);
+    ret = xc_sysctl(xch, &sysctl);
 
     return ret;
 }
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_cpuid_x86.c
--- a/tools/libxc/xc_cpuid_x86.c        Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_cpuid_x86.c        Fri May 28 09:30:19 2010 +0100
@@ -31,10 +31,10 @@
 #define DEF_MAX_BASE 0x0000000du
 #define DEF_MAX_EXT  0x80000008u
 
-static int hypervisor_is_64bit(int xc)
+static int hypervisor_is_64bit(xc_interface *xch)
 {
     xen_capabilities_info_t xen_caps = "";
-    return ((xc_version(xc, XENVER_capabilities, &xen_caps) == 0) &&
+    return ((xc_version(xch, XENVER_capabilities, &xen_caps) == 0) &&
             (strstr(xen_caps, "x86_64") != NULL));
 }
 
@@ -75,7 +75,8 @@ static void xc_cpuid_brand_get(char *str
 }
 
 static void amd_xc_cpuid_policy(
-    int xc, domid_t domid, const unsigned int *input, unsigned int *regs,
+    xc_interface *xch, domid_t domid,
+    const unsigned int *input, unsigned int *regs,
     int is_pae)
 {
     switch ( input[0] )
@@ -86,7 +87,7 @@ static void amd_xc_cpuid_policy(
         break;
 
     case 0x80000001: {
-        int is_64bit = hypervisor_is_64bit(xc) && is_pae;
+        int is_64bit = hypervisor_is_64bit(xch) && is_pae;
 
         if ( !is_pae )
             clear_bit(X86_FEATURE_PAE, regs[3]);
@@ -123,7 +124,8 @@ static void amd_xc_cpuid_policy(
 }
 
 static void intel_xc_cpuid_policy(
-    int xc, domid_t domid, const unsigned int *input, unsigned int *regs,
+    xc_interface *xch, domid_t domid,
+    const unsigned int *input, unsigned int *regs,
     int is_pae)
 {
     switch ( input[0] )
@@ -139,7 +141,7 @@ static void intel_xc_cpuid_policy(
         break;
 
     case 0x80000001: {
-        int is_64bit = hypervisor_is_64bit(xc) && is_pae;
+        int is_64bit = hypervisor_is_64bit(xch) && is_pae;
 
         /* Only a few features are advertised in Intel's 0x80000001. */
         regs[2] &= (is_64bit ? bitmaskof(X86_FEATURE_LAHF_LM) : 0);
@@ -162,13 +164,14 @@ static void intel_xc_cpuid_policy(
 }
 
 static void xc_cpuid_hvm_policy(
-    int xc, domid_t domid, const unsigned int *input, unsigned int *regs)
+    xc_interface *xch, domid_t domid,
+    const unsigned int *input, unsigned int *regs)
 {
     char brand[13];
     unsigned long pae;
     int is_pae;
 
-    xc_get_hvm_param(xc, domid, HVM_PARAM_PAE_ENABLED, &pae);
+    xc_get_hvm_param(xch, domid, HVM_PARAM_PAE_ENABLED, &pae);
     is_pae = !!pae;
 
     switch ( input[0] )
@@ -265,17 +268,18 @@ static void xc_cpuid_hvm_policy(
 
     xc_cpuid_brand_get(brand);
     if ( strstr(brand, "AMD") )
-        amd_xc_cpuid_policy(xc, domid, input, regs, is_pae);
+        amd_xc_cpuid_policy(xch, domid, input, regs, is_pae);
     else
-        intel_xc_cpuid_policy(xc, domid, input, regs, is_pae);
+        intel_xc_cpuid_policy(xch, domid, input, regs, is_pae);
 
 }
 
 static void xc_cpuid_pv_policy(
-    int xc, domid_t domid, const unsigned int *input, unsigned int *regs)
+    xc_interface *xch, domid_t domid,
+    const unsigned int *input, unsigned int *regs)
 {
     DECLARE_DOMCTL;
-    int guest_64bit, xen_64bit = hypervisor_is_64bit(xc);
+    int guest_64bit, xen_64bit = hypervisor_is_64bit(xch);
     char brand[13];
 
     xc_cpuid_brand_get(brand);
@@ -283,7 +287,7 @@ static void xc_cpuid_pv_policy(
     memset(&domctl, 0, sizeof(domctl));
     domctl.domain = domid;
     domctl.cmd = XEN_DOMCTL_get_address_size;
-    do_domctl(xc, &domctl);
+    do_domctl(xch, &domctl);
     guest_64bit = (domctl.u.address_size.size == 64);
 
     if ( (input[0] & 0x7fffffff) == 1 )
@@ -352,23 +356,24 @@ static void xc_cpuid_pv_policy(
 }
 
 static int xc_cpuid_policy(
-    int xc, domid_t domid, const unsigned int *input, unsigned int *regs)
+    xc_interface *xch, domid_t domid,
+    const unsigned int *input, unsigned int *regs)
 {
     xc_dominfo_t        info;
 
-    if ( xc_domain_getinfo(xc, domid, 1, &info) == 0 )
+    if ( xc_domain_getinfo(xch, domid, 1, &info) == 0 )
         return -EINVAL;
 
     if ( info.hvm )
-        xc_cpuid_hvm_policy(xc, domid, input, regs);
+        xc_cpuid_hvm_policy(xch, domid, input, regs);
     else
-        xc_cpuid_pv_policy(xc, domid, input, regs);
+        xc_cpuid_pv_policy(xch, domid, input, regs);
 
     return 0;
 }
 
 static int xc_cpuid_do_domctl(
-    int xc, domid_t domid,
+    xc_interface *xch, domid_t domid,
     const unsigned int *input, const unsigned int *regs)
 {
     DECLARE_DOMCTL;
@@ -383,7 +388,7 @@ static int xc_cpuid_do_domctl(
     domctl.u.cpuid.ecx = regs[2];
     domctl.u.cpuid.edx = regs[3];
 
-    return do_domctl(xc, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
 static char *alloc_str(void)
@@ -405,7 +410,7 @@ void xc_cpuid_to_str(const unsigned int 
     }
 }
 
-int xc_cpuid_apply_policy(int xc, domid_t domid)
+int xc_cpuid_apply_policy(xc_interface *xch, domid_t domid)
 {
     unsigned int input[2] = { 0, 0 }, regs[4];
     unsigned int base_max, ext_max;
@@ -422,11 +427,11 @@ int xc_cpuid_apply_policy(int xc, domid_
     for ( ; ; )
     {
         cpuid(input, regs);
-        xc_cpuid_policy(xc, domid, input, regs);
+        xc_cpuid_policy(xch, domid, input, regs);
 
         if ( regs[0] || regs[1] || regs[2] || regs[3] )
         {
-            rc = xc_cpuid_do_domctl(xc, domid, input, regs);
+            rc = xc_cpuid_do_domctl(xch, domid, input, regs);
             if ( rc )
                 return rc;
 
@@ -462,7 +467,7 @@ int xc_cpuid_apply_policy(int xc, domid_
  *  's' -> (same) must be the same
  */
 int xc_cpuid_check(
-    int xc, const unsigned int *input,
+    xc_interface *xch, const unsigned int *input,
     const char **config,
     char **config_transformed)
 {
@@ -522,7 +527,7 @@ int xc_cpuid_check(
  * For 's' and 'x' the configuration is overwritten with the value applied.
  */
 int xc_cpuid_set(
-    int xc, domid_t domid, const unsigned int *input,
+    xc_interface *xch, domid_t domid, const unsigned int *input,
     const char **config, char **config_transformed)
 {
     int rc;
@@ -533,7 +538,7 @@ int xc_cpuid_set(
     cpuid(input, regs);
 
     memcpy(polregs, regs, sizeof(regs));
-    xc_cpuid_policy(xc, domid, input, polregs);
+    xc_cpuid_policy(xch, domid, input, polregs);
 
     for ( i = 0; i < 4; i++ )
     {
@@ -572,7 +577,7 @@ int xc_cpuid_set(
         }
     }
 
-    rc = xc_cpuid_do_domctl(xc, domid, input, regs);
+    rc = xc_cpuid_do_domctl(xch, domid, input, regs);
     if ( rc == 0 )
         return 0;
 
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_cpupool.c
--- a/tools/libxc/xc_cpupool.c  Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_cpupool.c  Fri May 28 09:30:19 2010 +0100
@@ -9,18 +9,18 @@
 #include <stdarg.h>
 #include "xc_private.h"
 
-static int do_sysctl_save(int xc_handle, struct xen_sysctl *sysctl)
+static int do_sysctl_save(xc_interface *xch, struct xen_sysctl *sysctl)
 {
     int ret;
 
     do {
-        ret = do_sysctl(xc_handle, sysctl);
+        ret = do_sysctl(xch, sysctl);
     } while ( (ret < 0) && (errno == EAGAIN) );
 
     return ret;
 }
 
-int xc_cpupool_create(int xc_handle,
+int xc_cpupool_create(xc_interface *xch,
                       uint32_t *ppoolid,
                       uint32_t sched_id)
 {
@@ -32,14 +32,14 @@ int xc_cpupool_create(int xc_handle,
     sysctl.u.cpupool_op.cpupool_id = (*ppoolid == 0) ?
         XEN_SYSCTL_CPUPOOL_PAR_ANY : *ppoolid;
     sysctl.u.cpupool_op.sched_id = sched_id;
-    if ( (err = do_sysctl_save(xc_handle, &sysctl)) != 0 )
+    if ( (err = do_sysctl_save(xch, &sysctl)) != 0 )
         return err;
 
     *ppoolid = sysctl.u.cpupool_op.cpupool_id;
     return 0;
 }
 
-int xc_cpupool_destroy(int xc_handle,
+int xc_cpupool_destroy(xc_interface *xch,
                        uint32_t poolid)
 {
     DECLARE_SYSCTL;
@@ -47,10 +47,10 @@ int xc_cpupool_destroy(int xc_handle,
     sysctl.cmd = XEN_SYSCTL_cpupool_op;
     sysctl.u.cpupool_op.op = XEN_SYSCTL_CPUPOOL_OP_DESTROY;
     sysctl.u.cpupool_op.cpupool_id = poolid;
-    return do_sysctl_save(xc_handle, &sysctl);
+    return do_sysctl_save(xch, &sysctl);
 }
 
-int xc_cpupool_getinfo(int xc_handle, 
+int xc_cpupool_getinfo(xc_interface *xch, 
                        uint32_t first_poolid,
                        uint32_t n_max, 
                        xc_cpupoolinfo_t *info)
@@ -76,7 +76,7 @@ int xc_cpupool_getinfo(int xc_handle,
             PERROR("Could not lock memory for Xen hypercall");
             break;
         }
-        err = do_sysctl_save(xc_handle, &sysctl);
+        err = do_sysctl_save(xch, &sysctl);
         unlock_pages(local, sizeof (local));
 
         if ( err < 0 )
@@ -96,7 +96,7 @@ int xc_cpupool_getinfo(int xc_handle,
     return p;
 }
 
-int xc_cpupool_addcpu(int xc_handle,
+int xc_cpupool_addcpu(xc_interface *xch,
                       uint32_t poolid,
                       int cpu)
 {
@@ -106,10 +106,10 @@ int xc_cpupool_addcpu(int xc_handle,
     sysctl.u.cpupool_op.op = XEN_SYSCTL_CPUPOOL_OP_ADDCPU;
     sysctl.u.cpupool_op.cpupool_id = poolid;
     sysctl.u.cpupool_op.cpu = (cpu < 0) ? XEN_SYSCTL_CPUPOOL_PAR_ANY : cpu;
-    return do_sysctl_save(xc_handle, &sysctl);
+    return do_sysctl_save(xch, &sysctl);
 }
 
-int xc_cpupool_removecpu(int xc_handle,
+int xc_cpupool_removecpu(xc_interface *xch,
                          uint32_t poolid,
                          int cpu)
 {
@@ -119,10 +119,10 @@ int xc_cpupool_removecpu(int xc_handle,
     sysctl.u.cpupool_op.op = XEN_SYSCTL_CPUPOOL_OP_RMCPU;
     sysctl.u.cpupool_op.cpupool_id = poolid;
     sysctl.u.cpupool_op.cpu = (cpu < 0) ? XEN_SYSCTL_CPUPOOL_PAR_ANY : cpu;
-    return do_sysctl_save(xc_handle, &sysctl);
+    return do_sysctl_save(xch, &sysctl);
 }
 
-int xc_cpupool_movedomain(int xc_handle,
+int xc_cpupool_movedomain(xc_interface *xch,
                           uint32_t poolid,
                           uint32_t domid)
 {
@@ -132,10 +132,10 @@ int xc_cpupool_movedomain(int xc_handle,
     sysctl.u.cpupool_op.op = XEN_SYSCTL_CPUPOOL_OP_MOVEDOMAIN;
     sysctl.u.cpupool_op.cpupool_id = poolid;
     sysctl.u.cpupool_op.domid = domid;
-    return do_sysctl_save(xc_handle, &sysctl);
+    return do_sysctl_save(xch, &sysctl);
 }
 
-int xc_cpupool_freeinfo(int xc_handle,
+int xc_cpupool_freeinfo(xc_interface *xch,
                         uint64_t *cpumap)
 {
     int err;
@@ -153,7 +153,7 @@ int xc_cpupool_freeinfo(int xc_handle,
         return err;
     }
 
-    err = do_sysctl_save(xc_handle, &sysctl);
+    err = do_sysctl_save(xch, &sysctl);
     unlock_pages(local, sizeof (local));
 
     if (err < 0)
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_csched.c
--- a/tools/libxc/xc_csched.c   Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_csched.c   Fri May 28 09:30:19 2010 +0100
@@ -13,7 +13,7 @@
 
 int
 xc_sched_credit_domain_set(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     struct xen_domctl_sched_credit *sdom)
 {
@@ -25,12 +25,12 @@ xc_sched_credit_domain_set(
     domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_putinfo;
     domctl.u.scheduler_op.u.credit = *sdom;
 
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
 int
 xc_sched_credit_domain_get(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     struct xen_domctl_sched_credit *sdom)
 {
@@ -42,7 +42,7 @@ xc_sched_credit_domain_get(
     domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_CREDIT;
     domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_getinfo;
 
-    err = do_domctl(xc_handle, &domctl);
+    err = do_domctl(xch, &domctl);
     if ( err == 0 )
         *sdom = domctl.u.scheduler_op.u.credit;
 
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_csched2.c
--- a/tools/libxc/xc_csched2.c  Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_csched2.c  Fri May 28 09:30:19 2010 +0100
@@ -13,7 +13,7 @@
 
 int
 xc_sched_credit2_domain_set(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     struct xen_domctl_sched_credit2 *sdom)
 {
@@ -25,12 +25,12 @@ xc_sched_credit2_domain_set(
     domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_putinfo;
     domctl.u.scheduler_op.u.credit2 = *sdom;
 
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
 int
 xc_sched_credit2_domain_get(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     struct xen_domctl_sched_credit2 *sdom)
 {
@@ -42,7 +42,7 @@ xc_sched_credit2_domain_get(
     domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_CREDIT2;
     domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_getinfo;
 
-    err = do_domctl(xc_handle, &domctl);
+    err = do_domctl(xch, &domctl);
     if ( err == 0 )
         *sdom = domctl.u.scheduler_op.u.credit2;
 
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_dom.h
--- a/tools/libxc/xc_dom.h      Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_dom.h      Fri May 28 09:30:19 2010 +0100
@@ -93,7 +93,7 @@ struct xc_dom_image {
     unsigned int xenstore_evtchn;
     xen_pfn_t shared_info_mfn;
 
-    int guest_xc;
+    xc_interface *xch;
     domid_t guest_domid;
     int8_t vhpt_size_log2; /* for IA64 */
     int8_t superpages;
@@ -153,13 +153,16 @@ void xc_dom_register_arch_hooks(struct x
 
 /* --- main functions ---------------------------------------------- */
 
-struct xc_dom_image *xc_dom_allocate(const char *cmdline, const char 
*features);
+struct xc_dom_image *xc_dom_allocate(xc_interface *xch,
+                                     const char *cmdline, const char 
*features);
 void xc_dom_release_phys(struct xc_dom_image *dom);
 void xc_dom_release(struct xc_dom_image *dom);
 int xc_dom_mem_init(struct xc_dom_image *dom, unsigned int mem_mb);
 
-size_t xc_dom_check_gzip(void *blob, size_t ziplen);
-int xc_dom_do_gunzip(void *src, size_t srclen, void *dst, size_t dstlen);
+size_t xc_dom_check_gzip(xc_interface *xch,
+                     void *blob, size_t ziplen);
+int xc_dom_do_gunzip(xc_interface *xch,
+                     void *src, size_t srclen, void *dst, size_t dstlen);
 int xc_dom_try_gunzip(struct xc_dom_image *dom, void **blob, size_t * size);
 
 int xc_dom_kernel_file(struct xc_dom_image *dom, const char *filename);
@@ -170,11 +173,12 @@ int xc_dom_ramdisk_mem(struct xc_dom_ima
                        size_t memsize);
 
 int xc_dom_parse_image(struct xc_dom_image *dom);
-struct xc_dom_arch *xc_dom_find_arch_hooks(char *guest_type);
+struct xc_dom_arch *xc_dom_find_arch_hooks(xc_interface *xch, char 
*guest_type);
 int xc_dom_build_image(struct xc_dom_image *dom);
 int xc_dom_update_guest_p2m(struct xc_dom_image *dom);
 
-int xc_dom_boot_xen_init(struct xc_dom_image *dom, int xc, domid_t domid);
+int xc_dom_boot_xen_init(struct xc_dom_image *dom, xc_interface *xch,
+                     domid_t domid);
 int xc_dom_boot_mem_init(struct xc_dom_image *dom);
 void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn,
                            xen_pfn_t count);
@@ -183,15 +187,17 @@ int xc_dom_compat_check(struct xc_dom_im
 
 /* --- debugging bits ---------------------------------------------- */
 
-extern FILE *xc_dom_logfile;
-
-void xc_dom_loginit(void);
-int xc_dom_printf(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
-int xc_dom_panic_func(const char *file, int line, xc_error_code err,
+int xc_dom_loginit(xc_interface *xch);
+
+void xc_dom_printf(xc_interface *xch, const char *fmt, ...)
+     __attribute__ ((format(printf, 2, 3)));
+void xc_dom_panic_func(xc_interface *xch,
+                      const char *file, int line, xc_error_code err,
                       const char *fmt, ...)
-    __attribute__ ((format(printf, 4, 5)));
-#define xc_dom_panic(err, fmt, args...) \
-    xc_dom_panic_func(__FILE__, __LINE__, err, fmt, ## args)
+    __attribute__ ((format(printf, 5, 6)));
+
+#define xc_dom_panic(xch, err, fmt, args...) \
+    xc_dom_panic_func(xch, __FILE__, __LINE__, err, fmt, ## args)
 #define xc_dom_trace(mark) \
     xc_dom_printf("%s:%d: trace %s\n", __FILE__, __LINE__, mark)
 
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_dom_binloader.c
--- a/tools/libxc/xc_dom_binloader.c    Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_dom_binloader.c    Fri May 28 09:30:19 2010 +0100
@@ -143,20 +143,20 @@ static int xc_dom_parse_bin_kernel(struc
     if ( !image_info )
         return -EINVAL;
 
-    xc_dom_printf("%s: multiboot header fields\n", __FUNCTION__);
-    xc_dom_printf("  flags:         0x%" PRIx32 "\n", image_info->flags);
-    xc_dom_printf("  header_addr:   0x%" PRIx32 "\n", image_info->header_addr);
-    xc_dom_printf("  load_addr:     0x%" PRIx32 "\n", image_info->load_addr);
-    xc_dom_printf("  load_end_addr: 0x%" PRIx32 "\n", 
image_info->load_end_addr);
-    xc_dom_printf("  bss_end_addr:  0x%" PRIx32 "\n", 
image_info->bss_end_addr);
-    xc_dom_printf("  entry_addr:    0x%" PRIx32 "\n", image_info->entry_addr);
+    DOMPRINTF("%s: multiboot header fields", __FUNCTION__);
+    DOMPRINTF("  flags:         0x%" PRIx32 "", image_info->flags);
+    DOMPRINTF("  header_addr:   0x%" PRIx32 "", image_info->header_addr);
+    DOMPRINTF("  load_addr:     0x%" PRIx32 "", image_info->load_addr);
+    DOMPRINTF("  load_end_addr: 0x%" PRIx32 "", image_info->load_end_addr);
+    DOMPRINTF("  bss_end_addr:  0x%" PRIx32 "", image_info->bss_end_addr);
+    DOMPRINTF("  entry_addr:    0x%" PRIx32 "", image_info->entry_addr);
 
     /* Check the flags */
     if ( (image_info->flags & FLAGS_MASK) != FLAGS_REQUIRED )
     {
-        xc_dom_panic(XC_INVALID_KERNEL,
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
                      "%s: xen_bin_image_table flags required "
-                     "0x%08" PRIx32 " found 0x%08" PRIx32 "\n",
+                     "0x%08" PRIx32 " found 0x%08" PRIx32 "",
                      __FUNCTION__, FLAGS_REQUIRED, image_info->flags & 
FLAGS_MASK);
         return -EINVAL;
     }
@@ -166,7 +166,7 @@ static int xc_dom_parse_bin_kernel(struc
          ((char *) image_info - image) <
          (image_info->header_addr - image_info->load_addr) )
     {
-        xc_dom_panic(XC_INVALID_KERNEL, "%s: Invalid header_addr.",
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: Invalid header_addr.",
                      __FUNCTION__);
         return -EINVAL;
     }
@@ -175,21 +175,21 @@ static int xc_dom_parse_bin_kernel(struc
     load_end_addr = image_info->load_end_addr ?: start_addr + image_size;
     bss_end_addr = image_info->bss_end_addr ?: load_end_addr;
 
-    xc_dom_printf("%s: calculated addresses\n", __FUNCTION__);
-    xc_dom_printf("  start_addr:    0x%" PRIx32 "\n", start_addr);
-    xc_dom_printf("  load_end_addr: 0x%" PRIx32 "\n", load_end_addr);
-    xc_dom_printf("  bss_end_addr:  0x%" PRIx32 "\n", bss_end_addr);
+    DOMPRINTF("%s: calculated addresses", __FUNCTION__);
+    DOMPRINTF("  start_addr:    0x%" PRIx32 "", start_addr);
+    DOMPRINTF("  load_end_addr: 0x%" PRIx32 "", load_end_addr);
+    DOMPRINTF("  bss_end_addr:  0x%" PRIx32 "", bss_end_addr);
 
     if ( (start_addr + image_size) < load_end_addr )
     {
-        xc_dom_panic(XC_INVALID_KERNEL, "%s: Invalid load_end_addr.\n",
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: Invalid load_end_addr.",
                      __FUNCTION__);
         return -EINVAL;
     }
 
     if ( bss_end_addr < load_end_addr)
     {
-        xc_dom_panic(XC_INVALID_KERNEL, "%s: Invalid bss_end_addr.\n",
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: Invalid bss_end_addr.",
                      __FUNCTION__);
         return -EINVAL;
     }
@@ -217,7 +217,7 @@ static int xc_dom_parse_bin_kernel(struc
         dom->guest_type = "xen-3.0-x86_32";
         if ( strstr(dom->xen_caps, "xen-3.0-x86_32p") )
         {
-            xc_dom_printf("%s: PAE fixup\n", __FUNCTION__);
+            DOMPRINTF("%s: PAE fixup", __FUNCTION__);
             dom->guest_type = "xen-3.0-x86_32p";
             dom->parms.pae  = 2;
         }
@@ -250,10 +250,10 @@ static int xc_dom_load_bin_kernel(struct
     text_size = load_end_addr - image_info->load_addr;
     bss_size = bss_end_addr - load_end_addr;
 
-    xc_dom_printf("%s: calculated sizes\n", __FUNCTION__);
-    xc_dom_printf("  skip:      0x%" PRIx32 "\n", skip);
-    xc_dom_printf("  text_size: 0x%" PRIx32 "\n", text_size);
-    xc_dom_printf("  bss_size:  0x%" PRIx32 "\n", bss_size);
+    DOMPRINTF("%s: calculated sizes", __FUNCTION__);
+    DOMPRINTF("  skip:      0x%" PRIx32 "", skip);
+    DOMPRINTF("  text_size: 0x%" PRIx32 "", text_size);
+    DOMPRINTF("  bss_size:  0x%" PRIx32 "", bss_size);
 
     dest = xc_dom_vaddr_to_ptr(dom, dom->kernel_seg.vstart);
     memcpy(dest, image + skip, text_size);
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_dom_boot.c
--- a/tools/libxc/xc_dom_boot.c Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_dom_boot.c Fri May 28 09:30:19 2010 +0100
@@ -34,33 +34,34 @@ static int setup_hypercall_page(struct x
     pfn = (dom->parms.virt_hypercall - dom->parms.virt_base)
         >> XC_DOM_PAGE_SHIFT(dom);
 
-    xc_dom_printf("%s: vaddr=0x%" PRIx64 " pfn=0x%" PRIpfn "\n", __FUNCTION__,
+    DOMPRINTF("%s: vaddr=0x%" PRIx64 " pfn=0x%" PRIpfn "", __FUNCTION__,
                   dom->parms.virt_hypercall, pfn);
     domctl.cmd = XEN_DOMCTL_hypercall_init;
     domctl.domain = dom->guest_domid;
     domctl.u.hypercall_init.gmfn = xc_dom_p2m_guest(dom, pfn);
-    rc = do_domctl(dom->guest_xc, &domctl);
-    if ( rc != 0 )
-        xc_dom_panic(XC_INTERNAL_ERROR, "%s: HYPERCALL_INIT failed (rc=%d)\n",
+    rc = do_domctl(dom->xch, &domctl);
+    if ( rc != 0 )
+        xc_dom_panic(dom->xch,
+                     XC_INTERNAL_ERROR, "%s: HYPERCALL_INIT failed (rc=%d)",
                      __FUNCTION__, rc);
     return rc;
 }
 
-static int launch_vm(int xc, domid_t domid, void *ctxt)
-{
-    DECLARE_DOMCTL;
-    int rc;
-
-    xc_dom_printf("%s: called, ctxt=%p\n", __FUNCTION__, ctxt);
+static int launch_vm(xc_interface *xch, domid_t domid, void *ctxt)
+{
+    DECLARE_DOMCTL;
+    int rc;
+
+    xc_dom_printf(xch, "%s: called, ctxt=%p", __FUNCTION__, ctxt);
     memset(&domctl, 0, sizeof(domctl));
     domctl.cmd = XEN_DOMCTL_setvcpucontext;
     domctl.domain = domid;
     domctl.u.vcpucontext.vcpu = 0;
     set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt);
-    rc = do_domctl(xc, &domctl);
-    if ( rc != 0 )
-        xc_dom_panic(XC_INTERNAL_ERROR,
-                     "%s: SETVCPUCONTEXT failed (rc=%d)\n", __FUNCTION__, rc);
+    rc = do_domctl(xch, &domctl);
+    if ( rc != 0 )
+        xc_dom_panic(xch, XC_INTERNAL_ERROR,
+                     "%s: SETVCPUCONTEXT failed (rc=%d)", __FUNCTION__, rc);
     return rc;
 }
 
@@ -73,13 +74,13 @@ static int clear_page(struct xc_dom_imag
         return 0;
 
     dst = xc_dom_p2m_host(dom, pfn);
-    xc_dom_printf("%s: pfn 0x%" PRIpfn ", mfn 0x%" PRIpfn "\n",
-                  __FUNCTION__, pfn, dst);
-    rc = xc_clear_domain_page(dom->guest_xc, dom->guest_domid, dst);
-    if ( rc != 0 )
-        xc_dom_panic(XC_INTERNAL_ERROR,
+    DOMPRINTF("%s: pfn 0x%" PRIpfn ", mfn 0x%" PRIpfn "",
+              __FUNCTION__, pfn, dst);
+    rc = xc_clear_domain_page(dom->xch, dom->guest_domid, dst);
+    if ( rc != 0 )
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
                      "%s: xc_clear_domain_page failed (pfn 0x%" PRIpfn
-                     ", rc=%d)\n", __FUNCTION__, pfn, rc);
+                     ", rc=%d)", __FUNCTION__, pfn, rc);
     return rc;
 }
 
@@ -99,33 +100,33 @@ int xc_dom_compat_check(struct xc_dom_im
           item != NULL ; item = strtok_r(NULL, " ", &ptr) )
     {
         match = !strcmp(dom->guest_type, item);
-        xc_dom_printf("%s: supported guest type: %s%s\n", __FUNCTION__,
-                      item, match ? " <= matches" : "");
+        DOMPRINTF("%s: supported guest type: %s%s", __FUNCTION__,
+                  item, match ? " <= matches" : "");
         if ( match )
             found++;
     }
     if ( !found )
-        xc_dom_panic(XC_INVALID_KERNEL,
-                     "%s: guest type %s not supported by xen kernel, sorry\n",
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
+                     "%s: guest type %s not supported by xen kernel, sorry",
                      __FUNCTION__, dom->guest_type);
 
     return found;
 }
 
-int xc_dom_boot_xen_init(struct xc_dom_image *dom, int xc, domid_t domid)
-{
-    dom->guest_xc = xc;
+int xc_dom_boot_xen_init(struct xc_dom_image *dom, xc_interface *xch, domid_t 
domid)
+{
+    dom->xch = xch;
     dom->guest_domid = domid;
 
-    dom->xen_version = xc_version(dom->guest_xc, XENVER_version, NULL);
-    if ( xc_version(xc, XENVER_capabilities, &dom->xen_caps) < 0 )
-    {
-        xc_dom_panic(XC_INTERNAL_ERROR, "can't get xen capabilities");
-        return -1;
-    }
-    xc_dom_printf("%s: ver %d.%d, caps %s\n", __FUNCTION__,
-                  dom->xen_version >> 16, dom->xen_version & 0xff,
-                  dom->xen_caps);
+    dom->xen_version = xc_version(xch, XENVER_version, NULL);
+    if ( xc_version(xch, XENVER_capabilities, &dom->xen_caps) < 0 )
+    {
+        xc_dom_panic(xch, XC_INTERNAL_ERROR, "can't get xen capabilities");
+        return -1;
+    }
+    DOMPRINTF("%s: ver %d.%d, caps %s", __FUNCTION__,
+              dom->xen_version >> 16, dom->xen_version & 0xff,
+              dom->xen_caps);
     return 0;
 }
 
@@ -133,13 +134,13 @@ int xc_dom_boot_mem_init(struct xc_dom_i
 {
     long rc;
 
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
 
     rc = arch_setup_meminit(dom);
     if ( rc != 0 )
     {
-        xc_dom_panic(XC_OUT_OF_MEMORY,
-                     "%s: can't allocate low memory for domain\n",
+        xc_dom_panic(dom->xch, XC_OUT_OF_MEMORY,
+                     "%s: can't allocate low memory for domain",
                      __FUNCTION__);
         return rc;
     }
@@ -159,24 +160,24 @@ void *xc_dom_boot_domU_map(struct xc_dom
     entries = xc_dom_malloc(dom, count * sizeof(privcmd_mmap_entry_t));
     if ( entries == NULL )
     {
-        xc_dom_panic(XC_INTERNAL_ERROR,
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
                      "%s: failed to mmap domU pages 0x%" PRIpfn "+0x%" PRIpfn
-                     " [malloc]\n", __FUNCTION__, pfn, count);
+                     " [malloc]", __FUNCTION__, pfn, count);
         return NULL;
     }
 
     for ( i = 0; i < count; i++ )
         entries[i].mfn = xc_dom_p2m_host(dom, pfn + i);
 
-    ptr = xc_map_foreign_ranges(dom->guest_xc, dom->guest_domid,
+    ptr = xc_map_foreign_ranges(dom->xch, dom->guest_domid,
                 count << page_shift, PROT_READ | PROT_WRITE, 1 << page_shift,
                 entries, count);
     if ( ptr == NULL )
     {
         err = errno;
-        xc_dom_panic(XC_INTERNAL_ERROR,
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
                      "%s: failed to mmap domU pages 0x%" PRIpfn "+0x%" PRIpfn
-                     " [mmap, errno=%i (%s)]\n", __FUNCTION__, pfn, count,
+                     " [mmap, errno=%i (%s)]", __FUNCTION__, pfn, count,
                      err, strerror(err));
         return NULL;
     }
@@ -190,7 +191,7 @@ int xc_dom_boot_image(struct xc_dom_imag
     vcpu_guest_context_any_t ctxt;
     int rc;
 
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
 
     /* misc ia64 stuff*/
     if ( (rc = arch_setup_bootearly(dom)) != 0 )
@@ -199,17 +200,17 @@ int xc_dom_boot_image(struct xc_dom_imag
     /* collect some info */
     domctl.cmd = XEN_DOMCTL_getdomaininfo;
     domctl.domain = dom->guest_domid;
-    rc = do_domctl(dom->guest_xc, &domctl);
-    if ( rc != 0 )
-    {
-        xc_dom_panic(XC_INTERNAL_ERROR,
-                     "%s: getdomaininfo failed (rc=%d)\n", __FUNCTION__, rc);
+    rc = do_domctl(dom->xch, &domctl);
+    if ( rc != 0 )
+    {
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: getdomaininfo failed (rc=%d)", __FUNCTION__, rc);
         return rc;
     }
     if ( domctl.domain != dom->guest_domid )
     {
-        xc_dom_panic(XC_INTERNAL_ERROR,
-                     "%s: Huh? domid mismatch (%d != %d)\n", __FUNCTION__,
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: Huh? domid mismatch (%d != %d)", __FUNCTION__,
                      domctl.domain, dom->guest_domid);
         return -1;
     }
@@ -249,7 +250,7 @@ int xc_dom_boot_image(struct xc_dom_imag
     if ( (rc = dom->arch_hooks->vcpu(dom, &ctxt)) != 0 )
         return rc;
     xc_dom_unmap_all(dom);
-    rc = launch_vm(dom->guest_xc, dom->guest_domid, &ctxt);
+    rc = launch_vm(dom->xch, dom->guest_domid, &ctxt);
 
     return rc;
 }
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_dom_bzimageloader.c
--- a/tools/libxc/xc_dom_bzimageloader.c        Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_dom_bzimageloader.c        Fri May 28 09:30:19 2010 +0100
@@ -43,7 +43,7 @@ static int xc_try_bzip2_decode(
     ret = BZ2_bzDecompressInit(&stream, 0, 0);
     if ( ret != BZ_OK )
     {
-        xc_dom_printf("BZIP2: Error initting stream\n");
+        DOMPRINTF("BZIP2: Error initting stream");
         return -1;
     }
 
@@ -55,7 +55,7 @@ static int xc_try_bzip2_decode(
     out_buf = malloc(outsize);
     if ( out_buf == NULL )
     {
-        xc_dom_printf("BZIP2: Failed to alloc memory\n");
+        DOMPRINTF("BZIP2: Failed to alloc memory");
         goto bzip2_cleanup;
     }
 
@@ -73,7 +73,7 @@ static int xc_try_bzip2_decode(
             tmp_buf = realloc(out_buf, outsize * 2);
             if ( tmp_buf == NULL )
             {
-                xc_dom_printf("BZIP2: Failed to realloc memory\n");
+                DOMPRINTF("BZIP2: Failed to realloc memory");
                 free(out_buf);
                 goto bzip2_cleanup;
             }
@@ -88,18 +88,18 @@ static int xc_try_bzip2_decode(
         {
             if ( ret == BZ_STREAM_END )
             {
-                xc_dom_printf("BZIP2: Saw data stream end\n");
+                DOMPRINTF("BZIP2: Saw data stream end");
                 retval = 0;
                 break;
             }
-            xc_dom_printf("BZIP2: error\n");
+            DOMPRINTF("BZIP2: error");
         }
     }
 
     total = (((uint64_t)stream.total_out_hi32) << 32) | stream.total_out_lo32;
 
-    xc_dom_printf("%s: BZIP2 decompress OK, 0x%zx -> 0x%lx\n",
-                  __FUNCTION__, *size, (long unsigned int) total);
+    DOMPRINTF("%s: BZIP2 decompress OK, 0x%zx -> 0x%lx",
+              __FUNCTION__, *size, (long unsigned int) total);
 
     *blob = out_buf;
     *size = total;
@@ -115,8 +115,8 @@ static int xc_try_bzip2_decode(
 static int xc_try_bzip2_decode(
     struct xc_dom_image *dom, void **blob, size_t *size)
 {
-    xc_dom_printf("%s: BZIP2 decompress support unavailable\n",
-                  __FUNCTION__);
+    DOMPRINTF("%s: BZIP2 decompress support unavailable",
+              __FUNCTION__);
     return -1;
 }
 
@@ -162,7 +162,7 @@ static int xc_try_lzma_decode(
     ret = lzma_alone_decoder(&stream, physmem() / 3);
     if ( ret != LZMA_OK )
     {
-        xc_dom_printf("LZMA: Failed to init stream decoder\n");
+        DOMPRINTF("LZMA: Failed to init stream decoder");
         return -1;
     }
 
@@ -174,7 +174,7 @@ static int xc_try_lzma_decode(
     out_buf = malloc(outsize);
     if ( out_buf == NULL )
     {
-        xc_dom_printf("LZMA: Failed to alloc memory\n");
+        DOMPRINTF("LZMA: Failed to alloc memory");
         goto lzma_cleanup;
     }
 
@@ -192,7 +192,7 @@ static int xc_try_lzma_decode(
             tmp_buf = realloc(out_buf, outsize * 2);
             if ( tmp_buf == NULL )
             {
-                xc_dom_printf("LZMA: Failed to realloc memory\n");
+                DOMPRINTF("LZMA: Failed to realloc memory");
                 free(out_buf);
                 goto lzma_cleanup;
             }
@@ -207,7 +207,7 @@ static int xc_try_lzma_decode(
         {
             if ( ret == LZMA_STREAM_END )
             {
-                xc_dom_printf("LZMA: Saw data stream end\n");
+                DOMPRINTF("LZMA: Saw data stream end");
                 retval = 0;
                 break;
             }
@@ -243,14 +243,14 @@ static int xc_try_lzma_decode(
                 msg = "Internal program error (bug)";
                 break;
             }
-            xc_dom_printf("%s: LZMA decompression error %s\n",
-                          __FUNCTION__, msg);
+            DOMPRINTF("%s: LZMA decompression error %s",
+                      __FUNCTION__, msg);
             break;
         }
     }
 
-    xc_dom_printf("%s: LZMA decompress OK, 0x%zx -> 0x%zx\n",
-                  __FUNCTION__, *size, (size_t)stream.total_out);
+    DOMPRINTF("%s: LZMA decompress OK, 0x%zx -> 0x%zx",
+              __FUNCTION__, *size, (size_t)stream.total_out);
 
     *blob = out_buf;
     *size = stream.total_out;
@@ -266,8 +266,8 @@ static int xc_try_lzma_decode(
 static int xc_try_lzma_decode(
     struct xc_dom_image *dom, void **blob, size_t *size)
 {
-    xc_dom_printf("%s: LZMA decompress support unavailable\n",
-                  __FUNCTION__);
+    DOMPRINTF("%s: LZMA decompress support unavailable",
+              __FUNCTION__);
     return -1;
 }
 
@@ -330,15 +330,15 @@ static int xc_dom_probe_bzimage_kernel(s
 
     if ( dom->kernel_blob == NULL )
     {
-        xc_dom_panic(XC_INTERNAL_ERROR, "%s: no kernel image loaded\n",
-                     __FUNCTION__);
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: no kernel image loaded", __FUNCTION__);
         return -EINVAL;
     }
 
     if ( dom->kernel_size < sizeof(struct setup_header) )
     {
-        xc_dom_panic(XC_INTERNAL_ERROR, "%s: kernel image too small\n",
-                     __FUNCTION__);
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: kernel image too small", __FUNCTION__);
         return -EINVAL;
     }
 
@@ -346,15 +346,15 @@ static int xc_dom_probe_bzimage_kernel(s
 
     if ( memcmp(&hdr->header, HDR_MAGIC, HDR_MAGIC_SZ) != 0 )
     {
-        xc_dom_panic(XC_INVALID_KERNEL, "%s: kernel is not a bzImage\n",
-                     __FUNCTION__);
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
+                     "%s: kernel is not a bzImage", __FUNCTION__);
         return -EINVAL;
     }
 
     if ( hdr->version < VERSION(2,8) )
     {
-        xc_dom_panic(XC_INVALID_KERNEL, "%s: boot protocol too old (%04x)\n",
-                     __FUNCTION__, hdr->version);
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: boot protocol"
+                     " too old (%04x)", __FUNCTION__, hdr->version);
         return -EINVAL;
     }
 
@@ -366,9 +366,8 @@ static int xc_dom_probe_bzimage_kernel(s
         ret = xc_dom_try_gunzip(dom, &dom->kernel_blob, &dom->kernel_size);
         if ( ret == -1 )
         {
-            xc_dom_panic(XC_INVALID_KERNEL,
-                         "%s: unable to gzip decompress kernel\n",
-                         __FUNCTION__);
+            xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: unable to"
+                         " gzip decompress kernel", __FUNCTION__);
             return -EINVAL;
         }
     }
@@ -377,7 +376,7 @@ static int xc_dom_probe_bzimage_kernel(s
         ret = xc_try_bzip2_decode(dom, &dom->kernel_blob, &dom->kernel_size);
         if ( ret < 0 )
         {
-            xc_dom_panic(XC_INVALID_KERNEL,
+            xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
                          "%s unable to BZIP2 decompress kernel",
                          __FUNCTION__);
             return -EINVAL;
@@ -388,16 +387,16 @@ static int xc_dom_probe_bzimage_kernel(s
         ret = xc_try_lzma_decode(dom, &dom->kernel_blob, &dom->kernel_size);
         if ( ret < 0 )
         {
-            xc_dom_panic(XC_INVALID_KERNEL,
-                         "%s unable to LZMA decompress kernel\n",
+            xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
+                         "%s unable to LZMA decompress kernel",
                          __FUNCTION__);
             return -EINVAL;
         }
     }
     else
     {
-        xc_dom_panic(XC_INVALID_KERNEL, "%s: unknown compression format\n",
-                     __FUNCTION__);
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
+                     "%s: unknown compression format", __FUNCTION__);
         return -EINVAL;
     }
 
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_dom_compat_linux.c
--- a/tools/libxc/xc_dom_compat_linux.c Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_dom_compat_linux.c Fri May 28 09:30:19 2010 +0100
@@ -22,7 +22,7 @@
 /* ------------------------------------------------------------------------ */
 
 static int xc_linux_build_internal(struct xc_dom_image *dom,
-                                   int xc_handle, uint32_t domid,
+                                   xc_interface *xch, uint32_t domid,
                                    unsigned int mem_mb,
                                    unsigned long flags,
                                    unsigned int store_evtchn,
@@ -36,7 +36,7 @@ static int xc_linux_build_internal(struc
     dom->console_evtchn = console_evtchn;
     dom->xenstore_evtchn = store_evtchn;
 
-    if ( (rc = xc_dom_boot_xen_init(dom, xc_handle, domid)) != 0 )
+    if ( (rc = xc_dom_boot_xen_init(dom, xch, domid)) != 0 )
         goto out;
     if ( (rc = xc_dom_parse_image(dom)) != 0 )
         goto out;
@@ -56,7 +56,7 @@ static int xc_linux_build_internal(struc
     return rc;
 }
 
-int xc_linux_build_mem(int xc_handle, uint32_t domid,
+int xc_linux_build_mem(xc_interface *xch, uint32_t domid,
                        unsigned int mem_mb,
                        const char *image_buffer,
                        unsigned long image_size,
@@ -73,14 +73,14 @@ int xc_linux_build_mem(int xc_handle, ui
     struct xc_dom_image *dom;
     int rc;
 
-    xc_dom_loginit();
-    dom = xc_dom_allocate(cmdline, features);
+    xc_dom_loginit(xch);
+    dom = xc_dom_allocate(xch, cmdline, features);
     if ( (rc = xc_dom_kernel_mem(dom, image_buffer, image_size)) != 0 )
         goto out;
     if ( initrd && ((rc = xc_dom_ramdisk_mem(dom, initrd, initrd_len)) != 0) )
         goto out;
 
-    rc = xc_linux_build_internal(dom, xc_handle, domid,
+    rc = xc_linux_build_internal(dom, xch, domid,
                                  mem_mb, flags,
                                  store_evtchn, store_mfn,
                                  console_evtchn, console_mfn);
@@ -90,7 +90,7 @@ int xc_linux_build_mem(int xc_handle, ui
     return rc;
 }
 
-int xc_linux_build(int xc_handle, uint32_t domid,
+int xc_linux_build(xc_interface *xch, uint32_t domid,
                    unsigned int mem_mb,
                    const char *image_name,
                    const char *initrd_name,
@@ -105,15 +105,15 @@ int xc_linux_build(int xc_handle, uint32
     struct xc_dom_image *dom;
     int rc;
 
-    xc_dom_loginit();
-    dom = xc_dom_allocate(cmdline, features);
+    xc_dom_loginit(xch);
+    dom = xc_dom_allocate(xch, cmdline, features);
     if ( (rc = xc_dom_kernel_file(dom, image_name)) != 0 )
         goto out;
     if ( initrd_name && strlen(initrd_name) &&
          ((rc = xc_dom_ramdisk_file(dom, initrd_name)) != 0) )
         goto out;
 
-    rc = xc_linux_build_internal(dom, xc_handle, domid,
+    rc = xc_linux_build_internal(dom, xch, domid,
                                  mem_mb, flags,
                                  store_evtchn, store_mfn,
                                  console_evtchn, console_mfn);
@@ -122,13 +122,14 @@ int xc_linux_build(int xc_handle, uint32
     xc_dom_release(dom);
     return rc;
 }
-int xc_get_bit_size(const char *image_name, const char *cmdline, 
-                      const char *features, int *bit_size)
+int xc_get_bit_size(xc_interface *xch,
+                    const char *image_name, const char *cmdline, 
+                    const char *features, int *bit_size)
 {
     struct xc_dom_image *dom;
     int rc;
     *bit_size = 0;
-    dom = xc_dom_allocate(cmdline, features);
+    dom = xc_dom_allocate(xch, cmdline, features);
     if ( (rc = xc_dom_kernel_file(dom, image_name)) != 0 )
         goto out;
     if ( (rc = xc_dom_parse_image(dom)) != 0 )
@@ -145,7 +146,7 @@ out:
     return rc;
 }
 
-int xc_dom_linux_build(int xc_handle,
+int xc_dom_linux_build(xc_interface *xch,
                        struct xc_dom_image *dom,
                        uint32_t domid,
                        unsigned int mem_mb,
@@ -164,7 +165,7 @@ int xc_dom_linux_build(int xc_handle,
          ((rc = xc_dom_ramdisk_file(dom, initrd_name)) != 0) )
         return rc;
 
-    return xc_linux_build_internal(dom, xc_handle, domid,
+    return xc_linux_build_internal(dom, xch, domid,
                                    mem_mb, flags,
                                    store_evtchn, store_mfn,
                                    console_evtchn, console_mfn);
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_dom_core.c
--- a/tools/libxc/xc_dom_core.c Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_dom_core.c Fri May 28 09:30:19 2010 +0100
@@ -16,6 +16,7 @@
 #include <stdarg.h>
 #include <inttypes.h>
 #include <zlib.h>
+#include <assert.h>
 
 #include "xg_private.h"
 #include "xc_dom.h"
@@ -23,74 +24,79 @@
 /* ------------------------------------------------------------------------ */
 /* debugging                                                                */
 
-FILE *xc_dom_logfile = NULL;
-
-void xc_dom_loginit(void)
-{
-    if ( xc_dom_logfile )
-        return;
-    xc_dom_logfile = fopen("/var/log/xen/domain-builder-ng.log", "a");
-    setvbuf(xc_dom_logfile, NULL, _IONBF, 0);
-    xc_dom_printf("### ----- xc domain builder logfile opened -----\n");
-}
-
-int xc_dom_printf(const char *fmt, ...)
+
+
+static const char *default_logfile = "/var/log/xen/domain-builder-ng.log";
+
+int xc_dom_loginit(xc_interface *xch) {
+    if (xch->dombuild_logger) return 0;
+
+    if (!xch->dombuild_logger_file) {
+        xch->dombuild_logger_file = fopen(default_logfile, "a");
+        if (!xch->dombuild_logger_file) {
+            PERROR("Could not open logfile `%s'", default_logfile);
+            return -1;
+        }
+    }
+    
+    xch->dombuild_logger = xch->dombuild_logger_tofree =
+        (xentoollog_logger*)
+        xtl_createlogger_stdiostream(xch->dombuild_logger_file, XTL_DETAIL,
+             XTL_STDIOSTREAM_SHOW_DATE|XTL_STDIOSTREAM_SHOW_PID);
+    if (!xch->dombuild_logger)
+        return -1;
+
+    xc_dom_printf(xch, "### ----- xc domain builder logfile opened -----");
+
+    return 0;
+}
+
+void xc_dom_printf(xc_interface *xch, const char *fmt, ...)
 {
     va_list args;
-    char buf[1024];
-    int rc;
-
-    if ( !xc_dom_logfile )
-        return 0;
-
+    if (!xch->dombuild_logger) return;
     va_start(args, fmt);
-    rc = vsnprintf(buf, sizeof(buf), fmt, args);
+    xtl_logv(xch->dombuild_logger, XTL_DETAIL, -1, "domainbuilder", fmt, args);
     va_end(args);
-    rc = fwrite(buf, rc, 1, xc_dom_logfile);
-
-    return rc;
-}
-
-int xc_dom_panic_func(const char *file, int line, xc_error_code err,
-                      const char *fmt, ...)
+}
+
+void xc_dom_panic_func(xc_interface *xch,
+                       const char *file, int line, xc_error_code err,
+                       const char *fmt, ...)
 {
     va_list args;
-    FILE *fp = stderr;
-    int rc = 0;
-    char pos[256];
     char msg[XC_MAX_ERROR_MSG_LEN];
 
-    if ( xc_dom_logfile )
-        fp = xc_dom_logfile;
-
-    snprintf(pos, sizeof(pos), "%s:%d: panic: ", file, line);
     va_start(args, fmt);
     vsnprintf(msg, sizeof(msg), fmt, args);
     va_end(args);
-    xc_set_error(err, "%s", msg);
-    rc = fprintf(fp, "%s%s", pos, msg);
-    return rc;
-}
-
-static void print_mem(const char *name, size_t mem)
+    msg[sizeof(msg)-1] = 0;
+    
+    xc_report(xch,
+              xch->dombuild_logger ? xch->dombuild_logger : xch->error_handler,
+              XTL_ERROR, err, "panic: %s:%d: %s",
+              file, line, msg);
+}
+
+static void print_mem(struct xc_dom_image *dom, const char *name, size_t mem)
 {
     if ( mem > (32 * 1024 * 1024) )
-        xc_dom_printf("%-24s : %zd MB\n", name, mem / (1024 * 1024));
+        DOMPRINTF("%-24s : %zd MB", name, mem / (1024 * 1024));
     else if ( mem > (32 * 1024) )
-        xc_dom_printf("%-24s : %zd kB\n", name, mem / 1024);
+        DOMPRINTF("%-24s : %zd kB", name, mem / 1024);
     else
-        xc_dom_printf("%-24s : %zd bytes\n", name, mem);
+        DOMPRINTF("%-24s : %zd bytes", name, mem);
 }
 
 void xc_dom_log_memory_footprint(struct xc_dom_image *dom)
 {
-    xc_dom_printf("domain builder memory footprint\n");
-    xc_dom_printf("   allocated\n");
-    print_mem("      malloc", dom->alloc_malloc);
-    print_mem("      anon mmap", dom->alloc_mem_map);
-    xc_dom_printf("   mapped\n");
-    print_mem("      file mmap", dom->alloc_file_map);
-    print_mem("      domU mmap", dom->alloc_domU_map);
+    DOMPRINTF("domain builder memory footprint");
+    DOMPRINTF("   allocated");
+    print_mem(dom, "      malloc", dom->alloc_malloc);
+    print_mem(dom, "      anon mmap", dom->alloc_mem_map);
+    DOMPRINTF("   mapped");
+    print_mem(dom, "      file mmap", dom->alloc_file_map);
+    print_mem(dom, "      domU mmap", dom->alloc_domU_map);
 }
 
 /* ------------------------------------------------------------------------ */
@@ -108,7 +114,7 @@ void *xc_dom_malloc(struct xc_dom_image 
     dom->memblocks = block;
     dom->alloc_malloc += sizeof(*block) + size;
     if ( size > (100 * 1024) )
-        print_mem(__FUNCTION__, size);
+        print_mem(dom, __FUNCTION__, size);
     return block->memory;
 }
 
@@ -134,7 +140,7 @@ void *xc_dom_malloc_page_aligned(struct 
     dom->alloc_malloc += sizeof(*block);
     dom->alloc_mem_map += block->mmap_len;
     if ( size > (100 * 1024) )
-        print_mem(__FUNCTION__, size);
+        print_mem(dom, __FUNCTION__, size);
     return block->mmap_ptr;
 }
 
@@ -166,7 +172,7 @@ void *xc_dom_malloc_filemap(struct xc_do
     dom->alloc_file_map += block->mmap_len;
     close(fd);
     if ( *size > (100 * 1024) )
-        print_mem(__FUNCTION__, *size);
+        print_mem(dom, __FUNCTION__, *size);
     return block->mmap_ptr;
 
  err:
@@ -204,7 +210,7 @@ char *xc_dom_strdup(struct xc_dom_image 
 /* ------------------------------------------------------------------------ */
 /* read files, copy memory blocks, with transparent gunzip                  */
 
-size_t xc_dom_check_gzip(void *blob, size_t ziplen)
+size_t xc_dom_check_gzip(xc_interface *xch, void *blob, size_t ziplen)
 {
     unsigned char *gzlen;
     size_t unziplen;
@@ -218,7 +224,8 @@ size_t xc_dom_check_gzip(void *blob, siz
     if ( (unziplen < 0) || (unziplen > (1024*1024*1024)) ) /* 1GB limit */
     {
         xc_dom_printf
-            ("%s: size (zip %zd, unzip %zd) looks insane, skip gunzip\n",
+            (xch,
+             "%s: size (zip %zd, unzip %zd) looks insane, skip gunzip",
              __FUNCTION__, ziplen, unziplen);
         return 0;
     }
@@ -226,7 +233,8 @@ size_t xc_dom_check_gzip(void *blob, siz
     return unziplen + 16;
 }
 
-int xc_dom_do_gunzip(void *src, size_t srclen, void *dst, size_t dstlen)
+int xc_dom_do_gunzip(xc_interface *xch,
+                     void *src, size_t srclen, void *dst, size_t dstlen)
 {
     z_stream zStream;
     int rc;
@@ -239,20 +247,20 @@ int xc_dom_do_gunzip(void *src, size_t s
     rc = inflateInit2(&zStream, (MAX_WBITS + 32)); /* +32 means "handle gzip" 
*/
     if ( rc != Z_OK )
     {
-        xc_dom_panic(XC_INTERNAL_ERROR,
-                     "%s: inflateInit2 failed (rc=%d)\n", __FUNCTION__, rc);
+        xc_dom_panic(xch, XC_INTERNAL_ERROR,
+                     "%s: inflateInit2 failed (rc=%d)", __FUNCTION__, rc);
         return -1;
     }
     rc = inflate(&zStream, Z_FINISH);
     inflateEnd(&zStream);
     if ( rc != Z_STREAM_END )
     {
-        xc_dom_panic(XC_INTERNAL_ERROR,
-                     "%s: inflate failed (rc=%d)\n", __FUNCTION__, rc);
-        return -1;
-    }
-
-    xc_dom_printf("%s: unzip ok, 0x%zx -> 0x%zx\n",
+        xc_dom_panic(xch, XC_INTERNAL_ERROR,
+                     "%s: inflate failed (rc=%d)", __FUNCTION__, rc);
+        return -1;
+    }
+
+    xc_dom_printf(xch, "%s: unzip ok, 0x%zx -> 0x%zx",
                   __FUNCTION__, srclen, dstlen);
     return 0;
 }
@@ -262,7 +270,7 @@ int xc_dom_try_gunzip(struct xc_dom_imag
     void *unzip;
     size_t unziplen;
 
-    unziplen = xc_dom_check_gzip(*blob, *size);
+    unziplen = xc_dom_check_gzip(dom->xch, *blob, *size);
     if ( unziplen == 0 )
         return 0;
 
@@ -270,7 +278,7 @@ int xc_dom_try_gunzip(struct xc_dom_imag
     if ( unzip == NULL )
         return -1;
 
-    if ( xc_dom_do_gunzip(*blob, *size, unzip, unziplen) == -1 )
+    if ( xc_dom_do_gunzip(dom->xch, *blob, *size, unzip, unziplen) == -1 )
         return -1;
 
     *blob = unzip;
@@ -292,8 +300,8 @@ void *xc_dom_pfn_to_ptr(struct xc_dom_im
          count > dom->total_pages ||
          pfn > dom->total_pages - count )
     {
-        xc_dom_printf("%s: pfn out of range (0x%" PRIpfn " > 0x%" PRIpfn ")\n",
-                      __FUNCTION__, pfn, dom->total_pages);
+        DOMPRINTF("%s: pfn out of range (0x%" PRIpfn " > 0x%" PRIpfn ")",
+                  __FUNCTION__, pfn, dom->total_pages);
         return NULL;
     }
 
@@ -310,11 +318,11 @@ void *xc_dom_pfn_to_ptr(struct xc_dom_im
             if ( (pfn < phys->first) ||
                  ((pfn + count) > (phys->first + phys->count)) )
             {
-                xc_dom_printf("%s: request overlaps allocated block"
-                              " (req 0x%" PRIpfn "+0x%" PRIpfn ","
-                              " blk 0x%" PRIpfn "+0x%" PRIpfn ")\n",
-                              __FUNCTION__, pfn, count, phys->first,
-                              phys->count);
+                DOMPRINTF("%s: request overlaps allocated block"
+                          " (req 0x%" PRIpfn "+0x%" PRIpfn ","
+                          " blk 0x%" PRIpfn "+0x%" PRIpfn ")",
+                          __FUNCTION__, pfn, count, phys->first,
+                          phys->count);
                 return NULL;
             }
         }
@@ -331,9 +339,9 @@ void *xc_dom_pfn_to_ptr(struct xc_dom_im
     /* allocating is allowed with size specified only */
     if ( count == 0 )
     {
-        xc_dom_printf("%s: no block found, no size given,"
-                      " can't malloc (pfn 0x%" PRIpfn ")\n",
-                      __FUNCTION__, pfn);
+        DOMPRINTF("%s: no block found, no size given,"
+                  " can't malloc (pfn 0x%" PRIpfn ")",
+                  __FUNCTION__, pfn);
         return NULL;
     }
 
@@ -364,9 +372,9 @@ void *xc_dom_pfn_to_ptr(struct xc_dom_im
         if ( phys->ptr == MAP_FAILED )
         {
             err = errno;
-            xc_dom_panic(XC_OUT_OF_MEMORY,
+            xc_dom_panic(dom->xch, XC_OUT_OF_MEMORY,
                          "%s: oom: can't allocate 0x%" PRIpfn " pages"
-                         " [mmap, errno=%i (%s)]\n",
+                         " [mmap, errno=%i (%s)]",
                          __FUNCTION__, count, err, strerror(err));
             return NULL;
         }
@@ -374,8 +382,8 @@ void *xc_dom_pfn_to_ptr(struct xc_dom_im
     }
 
 #if 1
-    xc_dom_printf("%s: %s: pfn 0x%" PRIpfn "+0x%" PRIpfn " at %p\n",
-                  __FUNCTION__, mode, phys->first, phys->count, phys->ptr);
+    DOMPRINTF("%s: %s: pfn 0x%" PRIpfn "+0x%" PRIpfn " at %p",
+              __FUNCTION__, mode, phys->first, phys->count, phys->ptr);
 #endif
     phys->next = dom->phys_pages;
     dom->phys_pages = phys;
@@ -395,16 +403,16 @@ int xc_dom_alloc_segment(struct xc_dom_i
 
     if ( start & (page_size - 1) )
     {
-        xc_dom_panic(XC_INTERNAL_ERROR,
-                     "%s: segment start isn't page aligned (0x%" PRIx64 ")\n",
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: segment start isn't page aligned (0x%" PRIx64 ")",
                      __FUNCTION__, start);
         return -1;
     }
     if ( start < dom->virt_alloc_end )
     {
-        xc_dom_panic(XC_INTERNAL_ERROR,
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
                      "%s: segment start too low (0x%" PRIx64 " < 0x%" PRIx64
-                     ")\n", __FUNCTION__, start, dom->virt_alloc_end);
+                     ")", __FUNCTION__, start, dom->virt_alloc_end);
         return -1;
     }
 
@@ -414,9 +422,9 @@ int xc_dom_alloc_segment(struct xc_dom_i
     if ( pages > dom->total_pages || /* double test avoids overflow probs */
          pages > dom->total_pages - seg->pfn)
     {
-        xc_dom_panic(XC_OUT_OF_MEMORY,
+        xc_dom_panic(dom->xch, XC_OUT_OF_MEMORY,
                      "%s: segment %s too large (0x%"PRIpfn" > "
-                     "0x%"PRIpfn" - 0x%"PRIpfn" pages)\n",
+                     "0x%"PRIpfn" - 0x%"PRIpfn" pages)",
                      __FUNCTION__, name, pages, dom->total_pages, seg->pfn);
         return -1;
     }
@@ -426,9 +434,9 @@ int xc_dom_alloc_segment(struct xc_dom_i
     if (dom->allocate)
         dom->allocate(dom, dom->virt_alloc_end);
 
-    xc_dom_printf("%-20s:   %-12s : 0x%" PRIx64 " -> 0x%" PRIx64
-                  "  (pfn 0x%" PRIpfn " + 0x%" PRIpfn " pages)\n",
-                  __FUNCTION__, name, seg->vstart, seg->vend, seg->pfn, pages);
+    DOMPRINTF("%-20s:   %-12s : 0x%" PRIx64 " -> 0x%" PRIx64
+              "  (pfn 0x%" PRIpfn " + 0x%" PRIpfn " pages)",
+              __FUNCTION__, name, seg->vstart, seg->vend, seg->pfn, pages);
 
     /* map and clear pages */
     ptr = xc_dom_seg_to_ptr(dom, seg);
@@ -451,8 +459,8 @@ int xc_dom_alloc_page(struct xc_dom_imag
         dom->allocate(dom, dom->virt_alloc_end);
     pfn = (start - dom->parms.virt_base) / page_size;
 
-    xc_dom_printf("%-20s:   %-12s : 0x%" PRIx64 " (pfn 0x%" PRIpfn ")\n",
-                  __FUNCTION__, name, start, pfn);
+    DOMPRINTF("%-20s:   %-12s : 0x%" PRIx64 " (pfn 0x%" PRIpfn ")",
+              __FUNCTION__, name, start, pfn);
     return pfn;
 }
 
@@ -469,8 +477,8 @@ void xc_dom_unmap_one(struct xc_dom_imag
     }
     if ( !phys )
     {
-        xc_dom_printf("%s: Huh? no mapping with pfn 0x%" PRIpfn "\n",
-                      __FUNCTION__, pfn);
+        DOMPRINTF("%s: Huh? no mapping with pfn 0x%" PRIpfn "",
+                  __FUNCTION__, pfn);
         return;
     }
 
@@ -505,16 +513,17 @@ static struct xc_dom_loader *xc_dom_find
 
     while ( loader != NULL )
     {
-        xc_dom_printf("%s: trying %s loader ... ", __FUNCTION__, loader->name);
+        DOMPRINTF("%s: trying %s loader ... ", __FUNCTION__, loader->name);
         if ( loader->probe(dom) == 0 )
         {
-            xc_dom_printf("OK\n");
+            DOMPRINTF("loader probe OK");
             return loader;
         }
-        xc_dom_printf("failed\n");
+        DOMPRINTF("loader probe failed");
         loader = loader->next;
     }
-    xc_dom_panic(XC_INVALID_KERNEL, "%s: no loader found\n", __FUNCTION__);
+    xc_dom_panic(dom->xch,
+                 XC_INVALID_KERNEL, "%s: no loader found", __FUNCTION__);
     return NULL;
 }
 
@@ -524,7 +533,7 @@ void xc_dom_register_arch_hooks(struct x
     first_hook = hooks;
 }
 
-struct xc_dom_arch *xc_dom_find_arch_hooks(char *guest_type)
+struct xc_dom_arch *xc_dom_find_arch_hooks(xc_interface *xch, char *guest_type)
 {
     struct xc_dom_arch *hooks = first_hook;
 
@@ -534,8 +543,8 @@ struct xc_dom_arch *xc_dom_find_arch_hoo
             return hooks;
         hooks = hooks->next;
     }
-    xc_dom_panic(XC_INVALID_KERNEL,
-                 "%s: not found (type %s)\n", __FUNCTION__, guest_type);
+    xc_dom_panic(xch, XC_INVALID_KERNEL,
+                 "%s: not found (type %s)", __FUNCTION__, guest_type);
     return NULL;
 }
 
@@ -544,24 +553,27 @@ struct xc_dom_arch *xc_dom_find_arch_hoo
 
 void xc_dom_release(struct xc_dom_image *dom)
 {
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
     if ( dom->phys_pages )
         xc_dom_unmap_all(dom);
     xc_dom_free_all(dom);
     free(dom);
 }
 
-struct xc_dom_image *xc_dom_allocate(const char *cmdline, const char *features)
+struct xc_dom_image *xc_dom_allocate(xc_interface *xch,
+                                     const char *cmdline, const char *features)
 {
     struct xc_dom_image *dom;
 
-    xc_dom_printf("%s: cmdline=\"%s\", features=\"%s\"\n",
+    xc_dom_printf(xch, "%s: cmdline=\"%s\", features=\"%s\"",
                   __FUNCTION__, cmdline, features);
     dom = malloc(sizeof(*dom));
     if ( !dom )
         goto err;
 
     memset(dom, 0, sizeof(*dom));
+    dom->xch = xch;
+
     if ( cmdline )
         dom->cmdline = xc_dom_strdup(dom, cmdline);
     if ( features )
@@ -584,7 +596,7 @@ struct xc_dom_image *xc_dom_allocate(con
 
 int xc_dom_kernel_file(struct xc_dom_image *dom, const char *filename)
 {
-    xc_dom_printf("%s: filename=\"%s\"\n", __FUNCTION__, filename);
+    DOMPRINTF("%s: filename=\"%s\"", __FUNCTION__, filename);
     dom->kernel_blob = xc_dom_malloc_filemap(dom, filename, &dom->kernel_size);
     if ( dom->kernel_blob == NULL )
         return -1;
@@ -593,7 +605,7 @@ int xc_dom_kernel_file(struct xc_dom_ima
 
 int xc_dom_ramdisk_file(struct xc_dom_image *dom, const char *filename)
 {
-    xc_dom_printf("%s: filename=\"%s\"\n", __FUNCTION__, filename);
+    DOMPRINTF("%s: filename=\"%s\"", __FUNCTION__, filename);
     dom->ramdisk_blob =
         xc_dom_malloc_filemap(dom, filename, &dom->ramdisk_size);
     if ( dom->ramdisk_blob == NULL )
@@ -604,7 +616,7 @@ int xc_dom_ramdisk_file(struct xc_dom_im
 
 int xc_dom_kernel_mem(struct xc_dom_image *dom, const void *mem, size_t 
memsize)
 {
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
     dom->kernel_blob = (void *)mem;
     dom->kernel_size = memsize;
     return xc_dom_try_gunzip(dom, &dom->kernel_blob, &dom->kernel_size);
@@ -613,7 +625,7 @@ int xc_dom_ramdisk_mem(struct xc_dom_ima
 int xc_dom_ramdisk_mem(struct xc_dom_image *dom, const void *mem,
                        size_t memsize)
 {
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
     dom->ramdisk_blob = (void *)mem;
     dom->ramdisk_size = memsize;
 //    return xc_dom_try_gunzip(dom, &dom->ramdisk_blob, &dom->ramdisk_size);
@@ -624,7 +636,7 @@ int xc_dom_parse_image(struct xc_dom_ima
 {
     int i;
 
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
 
     /* parse kernel image */
     dom->kernel_loader = xc_dom_find_loader(dom);
@@ -634,8 +646,8 @@ int xc_dom_parse_image(struct xc_dom_ima
         goto err;
     if ( dom->guest_type == NULL )
     {
-        xc_dom_panic(XC_INTERNAL_ERROR,
-                     "%s: guest_type not set\n", __FUNCTION__);
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: guest_type not set", __FUNCTION__);
         goto err;
     }
 
@@ -647,8 +659,8 @@ int xc_dom_parse_image(struct xc_dom_ima
         if ( (dom->f_active[i] & dom->parms.f_supported[i]) !=
              dom->f_active[i] )
         {
-            xc_dom_panic(XC_INVALID_PARAM,
-                         "%s: unsupported feature requested\n", __FUNCTION__);
+            xc_dom_panic(dom->xch, XC_INVALID_PARAM,
+                         "%s: unsupported feature requested", __FUNCTION__);
             goto err;
         }
     }
@@ -663,10 +675,10 @@ int xc_dom_mem_init(struct xc_dom_image 
     unsigned int page_shift;
     xen_pfn_t nr_pages;
 
-    dom->arch_hooks = xc_dom_find_arch_hooks(dom->guest_type);
+    dom->arch_hooks = xc_dom_find_arch_hooks(dom->xch, dom->guest_type);
     if ( dom->arch_hooks == NULL )
     {
-        xc_dom_panic(XC_INTERNAL_ERROR, "%s: arch hooks not set\n",
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR, "%s: arch hooks not set",
                      __FUNCTION__);
         return -1;
     }
@@ -674,12 +686,12 @@ int xc_dom_mem_init(struct xc_dom_image 
     page_shift = XC_DOM_PAGE_SHIFT(dom);
     nr_pages = mem_mb << (20 - page_shift);
 
-    xc_dom_printf("%s: mem %d MB, pages 0x%" PRIpfn " pages, %dk each\n",
-                  __FUNCTION__, mem_mb, nr_pages, 1 << (page_shift-10));
+    DOMPRINTF("%s: mem %d MB, pages 0x%" PRIpfn " pages, %dk each",
+               __FUNCTION__, mem_mb, nr_pages, 1 << (page_shift-10));
     dom->total_pages = nr_pages;
 
-    xc_dom_printf("%s: 0x%" PRIpfn " pages\n",
-                  __FUNCTION__, dom->total_pages);
+    DOMPRINTF("%s: 0x%" PRIpfn " pages",
+              __FUNCTION__, dom->total_pages);
 
     return 0;
 }
@@ -696,8 +708,8 @@ int xc_dom_update_guest_p2m(struct xc_do
     switch ( dom->arch_hooks->sizeof_pfn )
     {
     case 4:
-        xc_dom_printf("%s: dst 32bit, pages 0x%" PRIpfn " \n",
-                      __FUNCTION__, dom->total_pages);
+        DOMPRINTF("%s: dst 32bit, pages 0x%" PRIpfn "",
+                  __FUNCTION__, dom->total_pages);
         p2m_32 = dom->p2m_guest;
         for ( i = 0; i < dom->total_pages; i++ )
             if ( dom->p2m_host[i] != INVALID_P2M_ENTRY )
@@ -706,8 +718,8 @@ int xc_dom_update_guest_p2m(struct xc_do
                 p2m_32[i] = (uint32_t) - 1;
         break;
     case 8:
-        xc_dom_printf("%s: dst 64bit, pages 0x%" PRIpfn " \n",
-                      __FUNCTION__, dom->total_pages);
+        DOMPRINTF("%s: dst 64bit, pages 0x%" PRIpfn "",
+                  __FUNCTION__, dom->total_pages);
         p2m_64 = dom->p2m_guest;
         for ( i = 0; i < dom->total_pages; i++ )
             if ( dom->p2m_host[i] != INVALID_P2M_ENTRY )
@@ -716,7 +728,7 @@ int xc_dom_update_guest_p2m(struct xc_do
                 p2m_64[i] = (uint64_t) - 1;
         break;
     default:
-        xc_dom_panic(XC_INTERNAL_ERROR,
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
                      "sizeof_pfn is invalid (is %d, can be 4 or 8)",
                      dom->arch_hooks->sizeof_pfn);
         return -1;
@@ -728,12 +740,12 @@ int xc_dom_build_image(struct xc_dom_ima
 {
     unsigned int page_size;
 
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
 
     /* check for arch hooks */
     if ( dom->arch_hooks == NULL )
     {
-        xc_dom_panic(XC_INTERNAL_ERROR, "%s: arch hooks not set\n",
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR, "%s: arch hooks not set",
                      __FUNCTION__);
         goto err;
     }
@@ -754,7 +766,7 @@ int xc_dom_build_image(struct xc_dom_ima
         size_t unziplen, ramdisklen;
         void *ramdiskmap;
 
-        unziplen = xc_dom_check_gzip(dom->ramdisk_blob, dom->ramdisk_size);
+        unziplen = xc_dom_check_gzip(dom->xch, dom->ramdisk_blob, 
dom->ramdisk_size);
         ramdisklen = unziplen ? unziplen : dom->ramdisk_size;
         if ( xc_dom_alloc_segment(dom, &dom->ramdisk_seg, "ramdisk", 0,
                                   ramdisklen) != 0 )
@@ -762,7 +774,8 @@ int xc_dom_build_image(struct xc_dom_ima
         ramdiskmap = xc_dom_seg_to_ptr(dom, &dom->ramdisk_seg);
         if ( unziplen )
         {
-            if ( xc_dom_do_gunzip(dom->ramdisk_blob, dom->ramdisk_size,
+            if ( xc_dom_do_gunzip(dom->xch,
+                                  dom->ramdisk_blob, dom->ramdisk_size,
                                   ramdiskmap, ramdisklen) == -1 )
                 goto err;
         }
@@ -783,10 +796,10 @@ int xc_dom_build_image(struct xc_dom_ima
     }
     if ( dom->alloc_bootstack )
         dom->bootstack_pfn = xc_dom_alloc_page(dom, "boot stack");
-    xc_dom_printf("%-20s: virt_alloc_end : 0x%" PRIx64 "\n",
-                  __FUNCTION__, dom->virt_alloc_end);
-    xc_dom_printf("%-20s: virt_pgtab_end : 0x%" PRIx64 "\n",
-                  __FUNCTION__, dom->virt_pgtab_end);
+    DOMPRINTF("%-20s: virt_alloc_end : 0x%" PRIx64 "",
+              __FUNCTION__, dom->virt_alloc_end);
+    DOMPRINTF("%-20s: virt_pgtab_end : 0x%" PRIx64 "",
+              __FUNCTION__, dom->virt_pgtab_end);
     return 0;
 
  err:
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_dom_elfloader.c
--- a/tools/libxc/xc_dom_elfloader.c    Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_dom_elfloader.c    Fri May 28 09:30:19 2010 +0100
@@ -21,11 +21,18 @@
 
 static void log_callback(struct elf_binary *elf, void *caller_data,
                          int iserr, const char *fmt, va_list al) {
-    vfprintf(caller_data,fmt,al);
-}
-
-void xc_elf_set_logfile(struct elf_binary *elf, FILE *f, int verbose) {
-    elf_set_log(elf, log_callback, f, verbose);
+    struct xc_interface *xch = caller_data;
+
+    xc_reportv(xch,
+          xch->dombuild_logger ? xch->dombuild_logger : xch->error_handler,
+                       iserr ? XTL_ERROR : XTL_DETAIL,
+                       iserr ? XC_INVALID_KERNEL : XC_ERROR_NONE,
+                       fmt, al);
+}
+
+void xc_elf_set_logfile(struct xc_interface *xch, struct elf_binary *elf,
+                        int verbose) {
+    elf_set_log(elf, log_callback, xch, verbose);
 }
 
 /* ------------------------------------------------------------------------ */
@@ -68,7 +75,8 @@ static int check_elf_kernel(struct xc_do
     if ( dom->kernel_blob == NULL )
     {
         if ( verbose )
-            xc_dom_panic(XC_INTERNAL_ERROR, "%s: no kernel image loaded\n",
+            xc_dom_panic(dom->xch,
+                         XC_INTERNAL_ERROR, "%s: no kernel image loaded",
                          __FUNCTION__);
         return -EINVAL;
     }
@@ -76,7 +84,8 @@ static int check_elf_kernel(struct xc_do
     if ( !elf_is_elfbinary(dom->kernel_blob) )
     {
         if ( verbose )
-            xc_dom_panic(XC_INVALID_KERNEL, "%s: kernel is not an ELF image\n",
+            xc_dom_panic(dom->xch,
+                         XC_INVALID_KERNEL, "%s: kernel is not an ELF image",
                          __FUNCTION__);
         return -EINVAL;
     }
@@ -100,8 +109,8 @@ static int xc_dom_load_elf_symtab(struct
 
     if ( elf_swap(elf) )
     {
-        xc_dom_printf("%s: non-native byte order, bsd symtab not supported\n",
-                      __FUNCTION__);
+        DOMPRINTF("%s: non-native byte order, bsd symtab not supported",
+                  __FUNCTION__);
         return 0;
     }
 
@@ -150,18 +159,17 @@ static int xc_dom_load_elf_symtab(struct
     if ( elf_init(&syms, hdr + sizeof(int), size - sizeof(int)) )
         return -1;
 
-    if ( xc_dom_logfile )
-        xc_elf_set_logfile(&syms, xc_dom_logfile, 1);
+    xc_elf_set_logfile(dom->xch, &syms, 1);
 
     symtab = dom->bsd_symtab_start + sizeof(int);
     maxaddr = elf_round_up(&syms, symtab + elf_size(&syms, syms.ehdr) +
                            elf_shdr_count(&syms) * elf_size(&syms, shdr));
 
-    xc_dom_printf("%s/%s: bsd_symtab_start=%" PRIx64 ", kernel.end=0x%" PRIx64
-                  " -- symtab=0x%" PRIx64 ", maxaddr=0x%" PRIx64 "\n",
-                  __FUNCTION__, load ? "load" : "parse",
-                  dom->bsd_symtab_start, dom->kernel_seg.vend,
-                  symtab, maxaddr);
+    DOMPRINTF("%s/%s: bsd_symtab_start=%" PRIx64 ", kernel.end=0x%" PRIx64
+              " -- symtab=0x%" PRIx64 ", maxaddr=0x%" PRIx64 "",
+              __FUNCTION__, load ? "load" : "parse",
+              dom->bsd_symtab_start, dom->kernel_seg.vend,
+              symtab, maxaddr);
 
     count = elf_shdr_count(&syms);
     for ( h = 0; h < count; h++ )
@@ -199,10 +207,10 @@ static int xc_dom_load_elf_symtab(struct
             size = elf_uval(&syms, shdr, sh_size);
             maxaddr = elf_round_up(&syms, maxaddr + size);
             tables++;
-            xc_dom_printf("%s: h=%d %s, size=0x%zx, maxaddr=0x%" PRIx64 "\n",
-                          __FUNCTION__, h,
-                          type == SHT_SYMTAB ? "symtab" : "strtab",
-                          size, maxaddr);
+            DOMPRINTF("%s: h=%d %s, size=0x%zx, maxaddr=0x%" PRIx64 "",
+                      __FUNCTION__, h,
+                      type == SHT_SYMTAB ? "symtab" : "strtab",
+                      size, maxaddr);
 
             if ( load )
             {
@@ -222,7 +230,7 @@ static int xc_dom_load_elf_symtab(struct
 
     if ( tables == 0 )
     {
-        xc_dom_printf("%s: no symbol table present\n", __FUNCTION__);
+        DOMPRINTF("%s: no symbol table present", __FUNCTION__);
         dom->bsd_symtab_start = 0;
         return 0;
     }
@@ -243,11 +251,10 @@ static int xc_dom_parse_elf_kernel(struc
     elf = xc_dom_malloc(dom, sizeof(*elf));
     dom->private_loader = elf;
     rc = elf_init(elf, dom->kernel_blob, dom->kernel_size);
-    if ( xc_dom_logfile )
-        xc_elf_set_logfile(elf, xc_dom_logfile, 1);
+    xc_elf_set_logfile(dom->xch, elf, 1);
     if ( rc != 0 )
     {
-        xc_dom_panic(XC_INVALID_KERNEL, "%s: corrupted ELF image\n",
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: corrupted ELF image",
                      __FUNCTION__);
         return rc;
     }
@@ -255,8 +262,8 @@ static int xc_dom_parse_elf_kernel(struc
     /* Find the section-header strings table. */
     if ( elf->sec_strtab == NULL )
     {
-        xc_dom_panic(XC_INVALID_KERNEL, "%s: ELF image has no shstrtab\n",
-                     __FUNCTION__);
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: ELF image"
+                     " has no shstrtab", __FUNCTION__);
         return -EINVAL;
     }
 
@@ -273,9 +280,9 @@ static int xc_dom_parse_elf_kernel(struc
         xc_dom_load_elf_symtab(dom, elf, 0);
 
     dom->guest_type = xc_dom_guest_type(dom, elf);
-    xc_dom_printf("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "\n",
-                  __FUNCTION__, dom->guest_type,
-                  dom->kernel_seg.vstart, dom->kernel_seg.vend);
+    DOMPRINTF("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "",
+              __FUNCTION__, dom->guest_type,
+              dom->kernel_seg.vstart, dom->kernel_seg.vend);
     return 0;
 }
 
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_dom_ia64.c
--- a/tools/libxc/xc_dom_ia64.c Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_dom_ia64.c Fri May 28 09:30:19 2010 +0100
@@ -44,7 +44,7 @@ int start_info_ia64(struct xc_dom_image 
     struct xen_ia64_boot_param_ia64 *bp =
         (struct xen_ia64_boot_param_ia64 *)(start_info + 1);
 
-    xc_dom_printf("%s\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
 
     memset(start_info, 0, sizeof(*start_info));
     sprintf(start_info->magic, dom->guest_type);
@@ -84,7 +84,7 @@ int shared_info_ia64(struct xc_dom_image
     shared_info_ia64_t *shared_info = ptr;
     int i;
 
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
 
     memset(shared_info, 0, sizeof(*shared_info));
     for (i = 0; i < XEN_LEGACY_MAX_VCPUS; i++)
@@ -101,7 +101,7 @@ static int vcpu_ia64(struct xc_dom_image
 {
     vcpu_guest_context_ia64_t *ctxt = ptr;
 
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
 
     /* clear everything */
     memset(ctxt, 0, sizeof(*ctxt));
@@ -193,8 +193,8 @@ static int ia64_setup_memmap(struct xc_d
     /* setup memmap page */
     memmap_info_num_pages = 1;
     memmap_info_pfn = dom->start_info_pfn - 1;
-    xc_dom_printf("%s: memmap: mfn 0x%" PRIpfn " pages 0x%lx\n",
-                  __FUNCTION__, memmap_info_pfn, memmap_info_num_pages);
+    DOMPRINTF("%s: memmap: mfn 0x%" PRIpfn " pages 0x%lx",
+              __FUNCTION__, memmap_info_pfn, memmap_info_num_pages);
     memmap_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
                                        page_size * memmap_info_num_pages,
                                        PROT_READ | PROT_WRITE,
@@ -244,7 +244,7 @@ int arch_setup_bootearly(struct xc_dom_i
     DECLARE_DOMCTL;
     int rc;
 
-    xc_dom_printf("%s: setup firmware for %s\n", __FUNCTION__, 
dom->guest_type);
+    DOMPRINTF("%s: setup firmware for %s", __FUNCTION__, dom->guest_type);
 
     if (dom->guest_type && strcmp(dom->guest_type,
                                   "hvm-3.0-ia64-sioemu") == 0) {
@@ -255,7 +255,7 @@ int arch_setup_bootearly(struct xc_dom_i
         domctl.cmd = XEN_DOMCTL_arch_setup;
         domctl.domain = dom->guest_domid;
         rc = xc_domctl(dom->guest_xc, &domctl);
-        xc_dom_printf("%s: hvm-3.0-ia64-sioemu: %d\n", __FUNCTION__, rc);
+        DOMPRINTF("%s: hvm-3.0-ia64-sioemu: %d", __FUNCTION__, rc);
         return rc;
     }
 
@@ -296,8 +296,8 @@ int arch_setup_bootlate(struct xc_dom_im
     shared_info_t *shared_info;
 
     /* setup shared_info page */
-    xc_dom_printf("%s: shared_info: mfn 0x%" PRIpfn "\n",
-                  __FUNCTION__, dom->shared_info_mfn);
+    DOMPRINTF("%s: shared_info: mfn 0x%" PRIpfn "",
+              __FUNCTION__, dom->shared_info_mfn);
     shared_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
                                        page_size,
                                        PROT_READ | PROT_WRITE,
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_dom_x86.c
--- a/tools/libxc/xc_dom_x86.c  Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_dom_x86.c  Fri May 28 09:30:19 2010 +0100
@@ -34,7 +34,8 @@
 #define round_up(addr, mask)     ((addr) | (mask))
 
 static unsigned long
-nr_page_tables(xen_vaddr_t start, xen_vaddr_t end, unsigned long bits)
+nr_page_tables(struct xc_dom_image *dom,
+               xen_vaddr_t start, xen_vaddr_t end, unsigned long bits)
 {
     xen_vaddr_t mask = bits_to_mask(bits);
     int tables;
@@ -56,9 +57,9 @@ nr_page_tables(xen_vaddr_t start, xen_va
         tables = ((end - start) >> bits) + 1;
     }
 
-    xc_dom_printf("%s: 0x%016" PRIx64 "/%ld: 0x%016" PRIx64
-                  " -> 0x%016" PRIx64 ", %d table(s)\n",
-                  __FUNCTION__, mask, bits, start, end, tables);
+    DOMPRINTF("%s: 0x%016" PRIx64 "/%ld: 0x%016" PRIx64
+              " -> 0x%016" PRIx64 ", %d table(s)",
+              __FUNCTION__, mask, bits, start, end, tables);
     return tables;
 }
 
@@ -77,17 +78,17 @@ static int count_pgtables(struct xc_dom_
         try_virt_end = round_up(dom->virt_alloc_end + pages * PAGE_SIZE_X86,
                                 bits_to_mask(22)); /* 4MB alignment */
         dom->pg_l4 =
-            nr_page_tables(dom->parms.virt_base, try_virt_end, l4_bits);
+            nr_page_tables(dom, dom->parms.virt_base, try_virt_end, l4_bits);
         dom->pg_l3 =
-            nr_page_tables(dom->parms.virt_base, try_virt_end, l3_bits);
+            nr_page_tables(dom, dom->parms.virt_base, try_virt_end, l3_bits);
         dom->pg_l2 =
-            nr_page_tables(dom->parms.virt_base, try_virt_end, l2_bits);
+            nr_page_tables(dom, dom->parms.virt_base, try_virt_end, l2_bits);
         dom->pg_l1 =
-            nr_page_tables(dom->parms.virt_base, try_virt_end, l1_bits);
+            nr_page_tables(dom, dom->parms.virt_base, try_virt_end, l1_bits);
         if (pae && try_virt_end < 0xc0000000)
         {
-            xc_dom_printf("%s: PAE: extra l2 page table for l3#3\n",
-                          __FUNCTION__);
+            DOMPRINTF("%s: PAE: extra l2 page table for l3#3",
+                      __FUNCTION__);
             dom->pg_l2++;
         }
         dom->pgtables = dom->pg_l4 + dom->pg_l3 + dom->pg_l2 + dom->pg_l1;
@@ -168,18 +169,17 @@ static xen_pfn_t move_l3_below_4G(struct
     xen_pfn_t new_l3mfn;
     struct xc_mmu *mmu;
     void *l3tab;
-    int xc = dom->guest_xc;
-
-    mmu = xc_alloc_mmu_updates(xc, dom->guest_domid);
+
+    mmu = xc_alloc_mmu_updates(dom->xch, dom->guest_domid);
     if ( mmu == NULL )
     {
-        xc_dom_printf("%s: failed at %d\n", __FUNCTION__, __LINE__);
+        DOMPRINTF("%s: failed at %d", __FUNCTION__, __LINE__);
         return l3mfn;
     }
 
     xc_dom_unmap_one(dom, l3pfn);
 
-    new_l3mfn = xc_make_page_below_4G(dom->guest_xc, dom->guest_domid, l3mfn);
+    new_l3mfn = xc_make_page_below_4G(dom->xch, dom->guest_domid, l3mfn);
     if ( !new_l3mfn )
         goto out;
 
@@ -187,13 +187,13 @@ static xen_pfn_t move_l3_below_4G(struct
     if ( xc_dom_update_guest_p2m(dom) != 0 )
         goto out;
 
-    if ( xc_add_mmu_update(xc, mmu,
+    if ( xc_add_mmu_update(dom->xch, mmu,
                            (((unsigned long long)new_l3mfn)
                             << XC_DOM_PAGE_SHIFT(dom)) |
                            MMU_MACHPHYS_UPDATE, l3pfn) )
         goto out;
 
-    if ( xc_flush_mmu_updates(xc, mmu) )
+    if ( xc_flush_mmu_updates(dom->xch, mmu) )
         goto out;
 
     /*
@@ -207,9 +207,9 @@ static xen_pfn_t move_l3_below_4G(struct
     l3tab = xc_dom_pfn_to_ptr(dom, l3pfn, 1);
     memset(l3tab, 0, XC_DOM_PAGE_SIZE(dom));
 
-    xc_dom_printf("%s: successfully relocated L3 below 4G. "
-                  "(L3 PFN %#"PRIpfn" MFN %#"PRIpfn"=>%#"PRIpfn")\n",
-                  __FUNCTION__, l3pfn, l3mfn, new_l3mfn);
+    DOMPRINTF("%s: successfully relocated L3 below 4G. "
+              "(L3 PFN %#"PRIpfn" MFN %#"PRIpfn"=>%#"PRIpfn")",
+              __FUNCTION__, l3pfn, l3mfn, new_l3mfn);
 
     l3mfn = new_l3mfn;
 
@@ -239,9 +239,9 @@ static int setup_pgtables_x86_32_pae(str
 
         if ( l3mfn >= 0x100000 )
         {
-            xc_dom_panic(XC_INTERNAL_ERROR,"%s: cannot move L3 below 4G. "
-                         "extended-cr3 not supported by guest. "
-                         "(L3 PFN %#"PRIpfn" MFN %#"PRIpfn")\n",
+            xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,"%s: cannot move L3"
+                         " below 4G. extended-cr3 not supported by guest. "
+                         "(L3 PFN %#"PRIpfn" MFN %#"PRIpfn")",
                          __FUNCTION__, l3pfn, l3mfn);
             return -EINVAL;
         }
@@ -288,7 +288,7 @@ static int setup_pgtables_x86_32_pae(str
 
     if ( dom->virt_pgtab_end <= 0xc0000000 )
     {
-        xc_dom_printf("%s: PAE: extra l2 page table for l3#3\n", __FUNCTION__);
+        DOMPRINTF("%s: PAE: extra l2 page table for l3#3", __FUNCTION__);
         l3tab[3] = pfn_to_paddr(xc_dom_p2m_guest(dom, l2pfn)) | L3_PROT;
     }
     return 0;
@@ -418,7 +418,7 @@ static int start_info_x86_32(struct xc_d
         xc_dom_feature_translated(dom) ? dom->shared_info_pfn : dom->
         shared_info_mfn;
 
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
 
     memset(start_info, 0, sizeof(*start_info));
     strncpy(start_info->magic, dom->guest_type, sizeof(start_info->magic));
@@ -458,7 +458,7 @@ static int start_info_x86_64(struct xc_d
         xc_dom_feature_translated(dom) ? dom->shared_info_pfn : dom->
         shared_info_mfn;
 
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
 
     memset(start_info, 0, sizeof(*start_info));
     strncpy(start_info->magic, dom->guest_type, sizeof(start_info->magic));
@@ -495,7 +495,7 @@ static int shared_info_x86_32(struct xc_
     shared_info_x86_32_t *shared_info = ptr;
     int i;
 
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
 
     memset(shared_info, 0, sizeof(*shared_info));
     for ( i = 0; i < XEN_LEGACY_MAX_VCPUS; i++ )
@@ -508,7 +508,7 @@ static int shared_info_x86_64(struct xc_
     shared_info_x86_64_t *shared_info = ptr;
     int i;
 
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
 
     memset(shared_info, 0, sizeof(*shared_info));
     for ( i = 0; i < XEN_LEGACY_MAX_VCPUS; i++ )
@@ -523,7 +523,7 @@ static int vcpu_x86_32(struct xc_dom_ima
     vcpu_guest_context_x86_32_t *ctxt = ptr;
     xen_pfn_t cr3_pfn;
 
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
 
     /* clear everything */
     memset(ctxt, 0, sizeof(*ctxt));
@@ -551,8 +551,8 @@ static int vcpu_x86_32(struct xc_dom_ima
 
     cr3_pfn = xc_dom_p2m_guest(dom, dom->pgtables_seg.pfn);
     ctxt->ctrlreg[3] = xen_pfn_to_cr3_x86_32(cr3_pfn);
-    xc_dom_printf("%s: cr3: pfn 0x%" PRIpfn " mfn 0x%" PRIpfn "\n",
-                  __FUNCTION__, dom->pgtables_seg.pfn, cr3_pfn);
+    DOMPRINTF("%s: cr3: pfn 0x%" PRIpfn " mfn 0x%" PRIpfn "",
+              __FUNCTION__, dom->pgtables_seg.pfn, cr3_pfn);
 
     return 0;
 }
@@ -562,7 +562,7 @@ static int vcpu_x86_64(struct xc_dom_ima
     vcpu_guest_context_x86_64_t *ctxt = ptr;
     xen_pfn_t cr3_pfn;
 
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(dom->xch);
 
     /* clear everything */
     memset(ctxt, 0, sizeof(*ctxt));
@@ -586,8 +586,8 @@ static int vcpu_x86_64(struct xc_dom_ima
     ctxt->flags = VGCF_in_kernel_X86_64 | VGCF_online_X86_64;
     cr3_pfn = xc_dom_p2m_guest(dom, dom->pgtables_seg.pfn);
     ctxt->ctrlreg[3] = xen_pfn_to_cr3_x86_64(cr3_pfn);
-    xc_dom_printf("%s: cr3: pfn 0x%" PRIpfn " mfn 0x%" PRIpfn "\n",
-                  __FUNCTION__, dom->pgtables_seg.pfn, cr3_pfn);
+    DOMPRINTF("%s: cr3: pfn 0x%" PRIpfn " mfn 0x%" PRIpfn "",
+              __FUNCTION__, dom->pgtables_seg.pfn, cr3_pfn);
 
     return 0;
 }
@@ -639,7 +639,7 @@ static void __init register_arch_hooks(v
     xc_dom_register_arch_hooks(&xc_dom_64);
 }
 
-static int x86_compat(int xc, domid_t domid, char *guest_type)
+static int x86_compat(xc_interface *xch, domid_t domid, char *guest_type)
 {
     static const struct {
         char           *guest;
@@ -661,36 +661,36 @@ static int x86_compat(int xc, domid_t do
         /* nothing to do */
         return 0;
 
-    xc_dom_printf("%s: guest %s, address size %" PRId32 "\n", __FUNCTION__,
+    xc_dom_printf(xch, "%s: guest %s, address size %" PRId32 "", __FUNCTION__,
                   guest_type, domctl.u.address_size.size);
-    rc = do_domctl(xc, &domctl);
+    rc = do_domctl(xch, &domctl);
     if ( rc != 0 )
-        xc_dom_printf("%s: warning: failed (rc=%d)\n",
+        xc_dom_printf(xch, "%s: warning: failed (rc=%d)",
                       __FUNCTION__, rc);
     return rc;
 }
 
 
-static int x86_shadow(int xc, domid_t domid)
+static int x86_shadow(xc_interface *xch, domid_t domid)
 {
     int rc, mode;
 
-    xc_dom_printf("%s: called\n", __FUNCTION__);
+    DOMPRINTF_CALLED(xch);
 
     mode = XEN_DOMCTL_SHADOW_ENABLE_REFCOUNT |
         XEN_DOMCTL_SHADOW_ENABLE_TRANSLATE;
 
-    rc = xc_shadow_control(xc, domid,
+    rc = xc_shadow_control(xch, domid,
                            XEN_DOMCTL_SHADOW_OP_ENABLE,
                            NULL, 0, NULL, mode, NULL);
     if ( rc != 0 )
     {
-        xc_dom_panic(XC_INTERNAL_ERROR,
-                     "%s: SHADOW_OP_ENABLE (mode=0x%x) failed (rc=%d)\n",
+        xc_dom_panic(xch, XC_INTERNAL_ERROR,
+                     "%s: SHADOW_OP_ENABLE (mode=0x%x) failed (rc=%d)",
                      __FUNCTION__, mode, rc);
         return rc;
     }
-    xc_dom_printf("%s: shadow enabled (mode=0x%x)\n", __FUNCTION__, mode);
+    xc_dom_printf(xch, "%s: shadow enabled (mode=0x%x)", __FUNCTION__, mode);
     return rc;
 }
 
@@ -699,13 +699,13 @@ int arch_setup_meminit(struct xc_dom_ima
     int rc;
     xen_pfn_t pfn, allocsz, i, j, mfn;
 
-    rc = x86_compat(dom->guest_xc, dom->guest_domid, dom->guest_type);
+    rc = x86_compat(dom->xch, dom->guest_domid, dom->guest_type);
     if ( rc )
         return rc;
     if ( xc_dom_feature_translated(dom) )
     {
         dom->shadow_enabled = 1;
-        rc = x86_shadow(dom->guest_xc, dom->guest_domid);
+        rc = x86_shadow(dom->xch, dom->guest_domid);
         if ( rc )
             return rc;
     }
@@ -716,10 +716,10 @@ int arch_setup_meminit(struct xc_dom_ima
         int count = dom->total_pages >> SUPERPAGE_PFN_SHIFT;
         xen_pfn_t extents[count];
 
-        xc_dom_printf("Populating memory with %d superpages\n", count);
+        DOMPRINTF("Populating memory with %d superpages", count);
         for ( pfn = 0; pfn < count; pfn++ )
             extents[pfn] = pfn << SUPERPAGE_PFN_SHIFT;
-        rc = xc_domain_memory_populate_physmap(dom->guest_xc, dom->guest_domid,
+        rc = xc_domain_memory_populate_physmap(dom->xch, dom->guest_domid,
                                                count, SUPERPAGE_PFN_SHIFT, 0,
                                                extents);
         if ( rc )
@@ -749,7 +749,7 @@ int arch_setup_meminit(struct xc_dom_ima
             if ( allocsz > 1024*1024 )
                 allocsz = 1024*1024;
             rc = xc_domain_memory_populate_physmap(
-                dom->guest_xc, dom->guest_domid, allocsz,
+                dom->xch, dom->guest_domid, allocsz,
                 0, 0, &dom->p2m_host[i]);
         }
     }
@@ -759,7 +759,7 @@ int arch_setup_meminit(struct xc_dom_ima
 
 int arch_setup_bootearly(struct xc_dom_image *dom)
 {
-    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
+    DOMPRINTF("%s: doing nothing", __FUNCTION__);
     return 0;
 }
 
@@ -786,13 +786,13 @@ int arch_setup_bootlate(struct xc_dom_im
     {
         /* paravirtualized guest */
         xc_dom_unmap_one(dom, dom->pgtables_seg.pfn);
-        rc = pin_table(dom->guest_xc, pgd_type,
+        rc = pin_table(dom->xch, pgd_type,
                        xc_dom_p2m_host(dom, dom->pgtables_seg.pfn),
                        dom->guest_domid);
         if ( rc != 0 )
         {
-            xc_dom_panic(XC_INTERNAL_ERROR,
-                         "%s: pin_table failed (pfn 0x%" PRIpfn ", rc=%d)\n",
+            xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                         "%s: pin_table failed (pfn 0x%" PRIpfn ", rc=%d)",
                          __FUNCTION__, dom->pgtables_seg.pfn, rc);
             return rc;
         }
@@ -809,11 +809,11 @@ int arch_setup_bootlate(struct xc_dom_im
         xatp.space = XENMAPSPACE_shared_info;
         xatp.idx = 0;
         xatp.gpfn = dom->shared_info_pfn;
-        rc = xc_memory_op(dom->guest_xc, XENMEM_add_to_physmap, &xatp);
+        rc = xc_memory_op(dom->xch, XENMEM_add_to_physmap, &xatp);
         if ( rc != 0 )
         {
-            xc_dom_panic(XC_INTERNAL_ERROR, "%s: mapping shared_info failed "
-                         "(pfn=0x%" PRIpfn ", rc=%d)\n",
+            xc_dom_panic(dom->xch, XC_INTERNAL_ERROR, "%s: mapping"
+                         " shared_info failed (pfn=0x%" PRIpfn ", rc=%d)",
                          __FUNCTION__, xatp.gpfn, rc);
             return rc;
         }
@@ -825,18 +825,17 @@ int arch_setup_bootlate(struct xc_dom_im
             xatp.space = XENMAPSPACE_grant_table;
             xatp.idx = i;
             xatp.gpfn = dom->total_pages + i;
-            rc = xc_memory_op(dom->guest_xc, XENMEM_add_to_physmap, &xatp);
+            rc = xc_memory_op(dom->xch, XENMEM_add_to_physmap, &xatp);
             if ( rc != 0 )
             {
                 if ( (i > 0) && (errno == EINVAL) )
                 {
-                    xc_dom_printf("%s: %d grant tables mapped\n", __FUNCTION__,
-                                  i);
+                    DOMPRINTF("%s: %d grant tables mapped", __FUNCTION__, i);
                     break;
                 }
-                xc_dom_panic(XC_INTERNAL_ERROR,
+                xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
                              "%s: mapping grant tables failed " "(pfn=0x%"
-                             PRIpfn ", rc=%d)\n", __FUNCTION__, xatp.gpfn, rc);
+                             PRIpfn ", rc=%d)", __FUNCTION__, xatp.gpfn, rc);
                 return rc;
             }
         }
@@ -844,9 +843,9 @@ int arch_setup_bootlate(struct xc_dom_im
     }
 
     /* setup shared_info page */
-    xc_dom_printf("%s: shared_info: pfn 0x%" PRIpfn ", mfn 0x%" PRIpfn "\n",
-                  __FUNCTION__, dom->shared_info_pfn, dom->shared_info_mfn);
-    shared_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
+    DOMPRINTF("%s: shared_info: pfn 0x%" PRIpfn ", mfn 0x%" PRIpfn "",
+              __FUNCTION__, dom->shared_info_pfn, dom->shared_info_mfn);
+    shared_info = xc_map_foreign_range(dom->xch, dom->guest_domid,
                                        PAGE_SIZE_X86,
                                        PROT_READ | PROT_WRITE,
                                        shinfo);
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_domain.c
--- a/tools/libxc/xc_domain.c   Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_domain.c   Fri May 28 09:30:19 2010 +0100
@@ -11,7 +11,7 @@
 #include <xen/memory.h>
 #include <xen/hvm/hvm_op.h>
 
-int xc_domain_create(int xc_handle,
+int xc_domain_create(xc_interface *xch,
                      uint32_t ssidref,
                      xen_domain_handle_t handle,
                      uint32_t flags,
@@ -25,7 +25,7 @@ int xc_domain_create(int xc_handle,
     domctl.u.createdomain.ssidref = ssidref;
     domctl.u.createdomain.flags   = flags;
     memcpy(domctl.u.createdomain.handle, handle, sizeof(xen_domain_handle_t));
-    if ( (err = do_domctl(xc_handle, &domctl)) != 0 )
+    if ( (err = do_domctl(xch, &domctl)) != 0 )
         return err;
 
     *pdomid = (uint16_t)domctl.domain;
@@ -33,27 +33,27 @@ int xc_domain_create(int xc_handle,
 }
 
 
-int xc_domain_pause(int xc_handle,
+int xc_domain_pause(xc_interface *xch,
                     uint32_t domid)
 {
     DECLARE_DOMCTL;
     domctl.cmd = XEN_DOMCTL_pausedomain;
     domctl.domain = (domid_t)domid;
-    return do_domctl(xc_handle, &domctl);
-}
-
-
-int xc_domain_unpause(int xc_handle,
+    return do_domctl(xch, &domctl);
+}
+
+
+int xc_domain_unpause(xc_interface *xch,
                       uint32_t domid)
 {
     DECLARE_DOMCTL;
     domctl.cmd = XEN_DOMCTL_unpausedomain;
     domctl.domain = (domid_t)domid;
-    return do_domctl(xc_handle, &domctl);
-}
-
-
-int xc_domain_destroy(int xc_handle,
+    return do_domctl(xch, &domctl);
+}
+
+
+int xc_domain_destroy(xc_interface *xch,
                       uint32_t domid)
 {
     int ret;
@@ -61,12 +61,12 @@ int xc_domain_destroy(int xc_handle,
     domctl.cmd = XEN_DOMCTL_destroydomain;
     domctl.domain = (domid_t)domid;
     do {
-        ret = do_domctl(xc_handle, &domctl);
+        ret = do_domctl(xch, &domctl);
     } while ( ret && (errno == EAGAIN) );
     return ret;
 }
 
-int xc_domain_shutdown(int xc_handle,
+int xc_domain_shutdown(xc_interface *xch,
                        uint32_t domid,
                        int reason)
 {
@@ -86,7 +86,7 @@ int xc_domain_shutdown(int xc_handle,
         goto out1;
     }
 
-    ret = do_xen_hypercall(xc_handle, &hypercall);
+    ret = do_xen_hypercall(xch, &hypercall);
 
     unlock_pages(&arg, sizeof(arg));
 
@@ -95,7 +95,7 @@ int xc_domain_shutdown(int xc_handle,
 }
 
 
-int xc_vcpu_setaffinity(int xc_handle,
+int xc_vcpu_setaffinity(xc_interface *xch,
                         uint32_t domid,
                         int vcpu,
                         uint64_t *cpumap, int cpusize)
@@ -125,7 +125,7 @@ int xc_vcpu_setaffinity(int xc_handle,
         goto out;
     }
 
-    ret = do_domctl(xc_handle, &domctl);
+    ret = do_domctl(xch, &domctl);
 
     unlock_pages(local, cpusize);
 
@@ -135,7 +135,7 @@ int xc_vcpu_setaffinity(int xc_handle,
 }
 
 
-int xc_vcpu_getaffinity(int xc_handle,
+int xc_vcpu_getaffinity(xc_interface *xch,
                         uint32_t domid,
                         int vcpu,
                         uint64_t *cpumap, int cpusize)
@@ -164,7 +164,7 @@ int xc_vcpu_getaffinity(int xc_handle,
         goto out;
     }
 
-    ret = do_domctl(xc_handle, &domctl);
+    ret = do_domctl(xch, &domctl);
 
     unlock_pages(local, sizeof (local));
     bitmap_byte_to_64(cpumap, local, cpusize * 8);
@@ -174,7 +174,7 @@ out:
 }
 
 
-int xc_domain_getinfo(int xc_handle,
+int xc_domain_getinfo(xc_interface *xch,
                       uint32_t first_domid,
                       unsigned int max_doms,
                       xc_dominfo_t *info)
@@ -190,7 +190,7 @@ int xc_domain_getinfo(int xc_handle,
     {
         domctl.cmd = XEN_DOMCTL_getdomaininfo;
         domctl.domain = (domid_t)next_domid;
-        if ( (rc = do_domctl(xc_handle, &domctl)) < 0 )
+        if ( (rc = do_domctl(xch, &domctl)) < 0 )
             break;
         info->domid      = (uint16_t)domctl.domain;
 
@@ -235,7 +235,7 @@ int xc_domain_getinfo(int xc_handle,
     return nr_doms;
 }
 
-int xc_domain_getinfolist(int xc_handle,
+int xc_domain_getinfolist(xc_interface *xch,
                           uint32_t first_domain,
                           unsigned int max_domains,
                           xc_domaininfo_t *info)
@@ -251,7 +251,7 @@ int xc_domain_getinfolist(int xc_handle,
     sysctl.u.getdomaininfolist.max_domains  = max_domains;
     set_xen_guest_handle(sysctl.u.getdomaininfolist.buffer, info);
 
-    if ( xc_sysctl(xc_handle, &sysctl) < 0 )
+    if ( xc_sysctl(xch, &sysctl) < 0 )
         ret = -1;
     else
         ret = sysctl.u.getdomaininfolist.num_domains;
@@ -262,7 +262,7 @@ int xc_domain_getinfolist(int xc_handle,
 }
 
 /* get info from hvm guest for save */
-int xc_domain_hvm_getcontext(int xc_handle,
+int xc_domain_hvm_getcontext(xc_interface *xch,
                              uint32_t domid,
                              uint8_t *ctxt_buf,
                              uint32_t size)
@@ -279,7 +279,7 @@ int xc_domain_hvm_getcontext(int xc_hand
         if ( (ret = lock_pages(ctxt_buf, size)) != 0 )
             return ret;
 
-    ret = do_domctl(xc_handle, &domctl);
+    ret = do_domctl(xch, &domctl);
 
     if ( ctxt_buf ) 
         unlock_pages(ctxt_buf, size);
@@ -289,7 +289,7 @@ int xc_domain_hvm_getcontext(int xc_hand
 
 /* Get just one element of the HVM guest context.
  * size must be >= HVM_SAVE_LENGTH(type) */
-int xc_domain_hvm_getcontext_partial(int xc_handle,
+int xc_domain_hvm_getcontext_partial(xc_interface *xch,
                                      uint32_t domid,
                                      uint16_t typecode,
                                      uint16_t instance,
@@ -311,7 +311,7 @@ int xc_domain_hvm_getcontext_partial(int
     if ( (ret = lock_pages(ctxt_buf, size)) != 0 )
         return ret;
     
-    ret = do_domctl(xc_handle, &domctl);
+    ret = do_domctl(xch, &domctl);
 
     if ( ctxt_buf ) 
         unlock_pages(ctxt_buf, size);
@@ -320,7 +320,7 @@ int xc_domain_hvm_getcontext_partial(int
 }
 
 /* set info to hvm guest for restore */
-int xc_domain_hvm_setcontext(int xc_handle,
+int xc_domain_hvm_setcontext(xc_interface *xch,
                              uint32_t domid,
                              uint8_t *ctxt_buf,
                              uint32_t size)
@@ -336,14 +336,14 @@ int xc_domain_hvm_setcontext(int xc_hand
     if ( (ret = lock_pages(ctxt_buf, size)) != 0 )
         return ret;
 
-    ret = do_domctl(xc_handle, &domctl);
+    ret = do_domctl(xch, &domctl);
 
     unlock_pages(ctxt_buf, size);
 
     return ret;
 }
 
-int xc_vcpu_getcontext(int xc_handle,
+int xc_vcpu_getcontext(xc_interface *xch,
                        uint32_t domid,
                        uint32_t vcpu,
                        vcpu_guest_context_any_t *ctxt)
@@ -360,14 +360,14 @@ int xc_vcpu_getcontext(int xc_handle,
     
     if ( (rc = lock_pages(ctxt, sz)) != 0 )
         return rc;
-    rc = do_domctl(xc_handle, &domctl);
+    rc = do_domctl(xch, &domctl);
     unlock_pages(ctxt, sz);
 
     return rc;
 }
 
 
-int xc_shadow_control(int xc_handle,
+int xc_shadow_control(xc_interface *xch,
                       uint32_t domid,
                       unsigned int sop,
                       unsigned long *dirty_bitmap,
@@ -387,7 +387,7 @@ int xc_shadow_control(int xc_handle,
     set_xen_guest_handle(domctl.u.shadow_op.dirty_bitmap,
                          (uint8_t *)dirty_bitmap);
 
-    rc = do_domctl(xc_handle, &domctl);
+    rc = do_domctl(xch, &domctl);
 
     if ( stats )
         memcpy(stats, &domctl.u.shadow_op.stats,
@@ -399,7 +399,7 @@ int xc_shadow_control(int xc_handle,
     return (rc == 0) ? domctl.u.shadow_op.pages : rc;
 }
 
-int xc_domain_setmaxmem(int xc_handle,
+int xc_domain_setmaxmem(xc_interface *xch,
                         uint32_t domid,
                         unsigned int max_memkb)
 {
@@ -407,10 +407,10 @@ int xc_domain_setmaxmem(int xc_handle,
     domctl.cmd = XEN_DOMCTL_max_mem;
     domctl.domain = (domid_t)domid;
     domctl.u.max_mem.max_memkb = max_memkb;
-    return do_domctl(xc_handle, &domctl);
-}
-
-int xc_domain_pin_memory_cacheattr(int xc_handle,
+    return do_domctl(xch, &domctl);
+}
+
+int xc_domain_pin_memory_cacheattr(xc_interface *xch,
                                    uint32_t domid,
                                    uint64_t start,
                                    uint64_t end,
@@ -422,12 +422,12 @@ int xc_domain_pin_memory_cacheattr(int x
     domctl.u.pin_mem_cacheattr.start = start;
     domctl.u.pin_mem_cacheattr.end = end;
     domctl.u.pin_mem_cacheattr.type = type;
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
 #if defined(__i386__) || defined(__x86_64__)
 #include "xc_e820.h"
-int xc_domain_set_memmap_limit(int xc_handle,
+int xc_domain_set_memmap_limit(xc_interface *xch,
                                uint32_t domid,
                                unsigned long map_limitkb)
 {
@@ -453,7 +453,7 @@ int xc_domain_set_memmap_limit(int xc_ha
         goto out;
     }
 
-    rc = xc_memory_op(xc_handle, XENMEM_set_memory_map, &fmap);
+    rc = xc_memory_op(xch, XENMEM_set_memory_map, &fmap);
 
  out:
     unlock_pages(&fmap, sizeof(fmap));
@@ -461,7 +461,7 @@ int xc_domain_set_memmap_limit(int xc_ha
     return rc;
 }
 #else
-int xc_domain_set_memmap_limit(int xc_handle,
+int xc_domain_set_memmap_limit(xc_interface *xch,
                                uint32_t domid,
                                unsigned long map_limitkb)
 {
@@ -471,7 +471,7 @@ int xc_domain_set_memmap_limit(int xc_ha
 }
 #endif
 
-int xc_domain_set_time_offset(int xc_handle,
+int xc_domain_set_time_offset(xc_interface *xch,
                               uint32_t domid,
                               int32_t time_offset_seconds)
 {
@@ -479,19 +479,19 @@ int xc_domain_set_time_offset(int xc_han
     domctl.cmd = XEN_DOMCTL_settimeoffset;
     domctl.domain = (domid_t)domid;
     domctl.u.settimeoffset.time_offset_seconds = time_offset_seconds;
-    return do_domctl(xc_handle, &domctl);
-}
-
-int xc_domain_disable_migrate(int xc_handle, uint32_t domid)
+    return do_domctl(xch, &domctl);
+}
+
+int xc_domain_disable_migrate(xc_interface *xch, uint32_t domid)
 {
     DECLARE_DOMCTL;
     domctl.cmd = XEN_DOMCTL_disable_migrate;
     domctl.domain = (domid_t)domid;
     domctl.u.disable_migrate.disable = 1;
-    return do_domctl(xc_handle, &domctl);
-}
-
-int xc_domain_set_tsc_info(int xc_handle,
+    return do_domctl(xch, &domctl);
+}
+
+int xc_domain_set_tsc_info(xc_interface *xch,
                            uint32_t domid,
                            uint32_t tsc_mode,
                            uint64_t elapsed_nsec,
@@ -505,10 +505,10 @@ int xc_domain_set_tsc_info(int xc_handle
     domctl.u.tsc_info.info.elapsed_nsec = elapsed_nsec;
     domctl.u.tsc_info.info.gtsc_khz = gtsc_khz;
     domctl.u.tsc_info.info.incarnation = incarnation;
-    return do_domctl(xc_handle, &domctl);
-}
-
-int xc_domain_get_tsc_info(int xc_handle,
+    return do_domctl(xch, &domctl);
+}
+
+int xc_domain_get_tsc_info(xc_interface *xch,
                            uint32_t domid,
                            uint32_t *tsc_mode,
                            uint64_t *elapsed_nsec,
@@ -524,7 +524,7 @@ int xc_domain_get_tsc_info(int xc_handle
     set_xen_guest_handle(domctl.u.tsc_info.out_info, &info);
     if ( (rc = lock_pages(&info, sizeof(info))) != 0 )
         return rc;
-    rc = do_domctl(xc_handle, &domctl);
+    rc = do_domctl(xch, &domctl);
     if ( rc == 0 )
     {
         *tsc_mode = info.tsc_mode;
@@ -537,7 +537,7 @@ int xc_domain_get_tsc_info(int xc_handle
 }
 
 
-int xc_domain_memory_increase_reservation(int xc_handle,
+int xc_domain_memory_increase_reservation(xc_interface *xch,
                                           uint32_t domid,
                                           unsigned long nr_extents,
                                           unsigned int extent_order,
@@ -555,7 +555,7 @@ int xc_domain_memory_increase_reservatio
     /* may be NULL */
     set_xen_guest_handle(reservation.extent_start, extent_start);
 
-    err = xc_memory_op(xc_handle, XENMEM_increase_reservation, &reservation);
+    err = xc_memory_op(xch, XENMEM_increase_reservation, &reservation);
     if ( err == nr_extents )
         return 0;
 
@@ -571,7 +571,7 @@ int xc_domain_memory_increase_reservatio
     return err;
 }
 
-int xc_domain_memory_decrease_reservation(int xc_handle,
+int xc_domain_memory_decrease_reservation(xc_interface *xch,
                                           uint32_t domid,
                                           unsigned long nr_extents,
                                           unsigned int extent_order,
@@ -594,7 +594,7 @@ int xc_domain_memory_decrease_reservatio
         return -1;
     }
 
-    err = xc_memory_op(xc_handle, XENMEM_decrease_reservation, &reservation);
+    err = xc_memory_op(xch, XENMEM_decrease_reservation, &reservation);
     if ( err == nr_extents )
         return 0;
 
@@ -609,7 +609,7 @@ int xc_domain_memory_decrease_reservatio
     return err;
 }
 
-int xc_domain_memory_populate_physmap(int xc_handle,
+int xc_domain_memory_populate_physmap(xc_interface *xch,
                                       uint32_t domid,
                                       unsigned long nr_extents,
                                       unsigned int extent_order,
@@ -625,7 +625,7 @@ int xc_domain_memory_populate_physmap(in
     };
     set_xen_guest_handle(reservation.extent_start, extent_start);
 
-    err = xc_memory_op(xc_handle, XENMEM_populate_physmap, &reservation);
+    err = xc_memory_op(xch, XENMEM_populate_physmap, &reservation);
     if ( err == nr_extents )
         return 0;
 
@@ -640,7 +640,7 @@ int xc_domain_memory_populate_physmap(in
     return err;
 }
 
-static int xc_domain_memory_pod_target(int xc_handle,
+static int xc_domain_memory_pod_target(xc_interface *xch,
                                        int op,
                                        uint32_t domid,
                                        uint64_t target_pages,
@@ -655,7 +655,7 @@ static int xc_domain_memory_pod_target(i
         .target_pages = target_pages
     };
 
-    err = xc_memory_op(xc_handle, op, &pod_target);
+    err = xc_memory_op(xch, op, &pod_target);
 
     if ( err < 0 )
     {
@@ -679,14 +679,14 @@ static int xc_domain_memory_pod_target(i
 }
                                        
 
-int xc_domain_memory_set_pod_target(int xc_handle,
+int xc_domain_memory_set_pod_target(xc_interface *xch,
                                     uint32_t domid,
                                     uint64_t target_pages,
                                     uint64_t *tot_pages,
                                     uint64_t *pod_cache_pages,
                                     uint64_t *pod_entries)
 {
-    return xc_domain_memory_pod_target(xc_handle,
+    return xc_domain_memory_pod_target(xch,
                                        XENMEM_set_pod_target,
                                        domid,
                                        target_pages,
@@ -695,13 +695,13 @@ int xc_domain_memory_set_pod_target(int 
                                        pod_entries);
 }
 
-int xc_domain_memory_get_pod_target(int xc_handle,
+int xc_domain_memory_get_pod_target(xc_interface *xch,
                                     uint32_t domid,
                                     uint64_t *tot_pages,
                                     uint64_t *pod_cache_pages,
                                     uint64_t *pod_entries)
 {
-    return xc_domain_memory_pod_target(xc_handle,
+    return xc_domain_memory_pod_target(xch,
                                        XENMEM_get_pod_target,
                                        domid,
                                        -1,
@@ -710,16 +710,16 @@ int xc_domain_memory_get_pod_target(int 
                                        pod_entries);
 }
 
-int xc_domain_max_vcpus(int xc_handle, uint32_t domid, unsigned int max)
+int xc_domain_max_vcpus(xc_interface *xch, uint32_t domid, unsigned int max)
 {
     DECLARE_DOMCTL;
     domctl.cmd = XEN_DOMCTL_max_vcpus;
     domctl.domain = (domid_t)domid;
     domctl.u.max_vcpus.max    = max;
-    return do_domctl(xc_handle, &domctl);
-}
-
-int xc_domain_sethandle(int xc_handle, uint32_t domid,
+    return do_domctl(xch, &domctl);
+}
+
+int xc_domain_sethandle(xc_interface *xch, uint32_t domid,
                         xen_domain_handle_t handle)
 {
     DECLARE_DOMCTL;
@@ -727,10 +727,10 @@ int xc_domain_sethandle(int xc_handle, u
     domctl.domain = (domid_t)domid;
     memcpy(domctl.u.setdomainhandle.handle, handle,
            sizeof(xen_domain_handle_t));
-    return do_domctl(xc_handle, &domctl);
-}
-
-int xc_vcpu_getinfo(int xc_handle,
+    return do_domctl(xch, &domctl);
+}
+
+int xc_vcpu_getinfo(xc_interface *xch,
                     uint32_t domid,
                     uint32_t vcpu,
                     xc_vcpuinfo_t *info)
@@ -742,14 +742,14 @@ int xc_vcpu_getinfo(int xc_handle,
     domctl.domain = (domid_t)domid;
     domctl.u.getvcpuinfo.vcpu   = (uint16_t)vcpu;
 
-    rc = do_domctl(xc_handle, &domctl);
+    rc = do_domctl(xch, &domctl);
 
     memcpy(info, &domctl.u.getvcpuinfo, sizeof(*info));
 
     return rc;
 }
 
-int xc_domain_ioport_permission(int xc_handle,
+int xc_domain_ioport_permission(xc_interface *xch,
                                 uint32_t domid,
                                 uint32_t first_port,
                                 uint32_t nr_ports,
@@ -763,10 +763,10 @@ int xc_domain_ioport_permission(int xc_h
     domctl.u.ioport_permission.nr_ports = nr_ports;
     domctl.u.ioport_permission.allow_access = allow_access;
 
-    return do_domctl(xc_handle, &domctl);
-}
-
-int xc_availheap(int xc_handle,
+    return do_domctl(xch, &domctl);
+}
+
+int xc_availheap(xc_interface *xch,
                  int min_width,
                  int max_width,
                  int node,
@@ -780,14 +780,14 @@ int xc_availheap(int xc_handle,
     sysctl.u.availheap.max_bitwidth = max_width;
     sysctl.u.availheap.node = node;
 
-    rc = xc_sysctl(xc_handle, &sysctl);
+    rc = xc_sysctl(xch, &sysctl);
 
     *bytes = sysctl.u.availheap.avail_bytes;
 
     return rc;
 }
 
-int xc_vcpu_setcontext(int xc_handle,
+int xc_vcpu_setcontext(xc_interface *xch,
                        uint32_t domid,
                        uint32_t vcpu,
                        vcpu_guest_context_any_t *ctxt)
@@ -809,14 +809,14 @@ int xc_vcpu_setcontext(int xc_handle,
 
     if ( (rc = lock_pages(ctxt, sz)) != 0 )
         return rc;
-    rc = do_domctl(xc_handle, &domctl);
+    rc = do_domctl(xch, &domctl);
     
     unlock_pages(ctxt, sz);
 
     return rc;
 }
 
-int xc_domain_irq_permission(int xc_handle,
+int xc_domain_irq_permission(xc_interface *xch,
                              uint32_t domid,
                              uint8_t pirq,
                              uint8_t allow_access)
@@ -828,10 +828,10 @@ int xc_domain_irq_permission(int xc_hand
     domctl.u.irq_permission.pirq = pirq;
     domctl.u.irq_permission.allow_access = allow_access;
 
-    return do_domctl(xc_handle, &domctl);
-}
-
-int xc_domain_iomem_permission(int xc_handle,
+    return do_domctl(xch, &domctl);
+}
+
+int xc_domain_iomem_permission(xc_interface *xch,
                                uint32_t domid,
                                unsigned long first_mfn,
                                unsigned long nr_mfns,
@@ -845,10 +845,10 @@ int xc_domain_iomem_permission(int xc_ha
     domctl.u.iomem_permission.nr_mfns = nr_mfns;
     domctl.u.iomem_permission.allow_access = allow_access;
 
-    return do_domctl(xc_handle, &domctl);
-}
-
-int xc_domain_send_trigger(int xc_handle,
+    return do_domctl(xch, &domctl);
+}
+
+int xc_domain_send_trigger(xc_interface *xch,
                            uint32_t domid,
                            uint32_t trigger,
                            uint32_t vcpu)
@@ -860,10 +860,10 @@ int xc_domain_send_trigger(int xc_handle
     domctl.u.sendtrigger.trigger = trigger;
     domctl.u.sendtrigger.vcpu = vcpu;
 
-    return do_domctl(xc_handle, &domctl);
-}
-
-int xc_set_hvm_param(int handle, domid_t dom, int param, unsigned long value)
+    return do_domctl(xch, &domctl);
+}
+
+int xc_set_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned 
long value)
 {
     DECLARE_HYPERCALL;
     xen_hvm_param_t arg;
@@ -882,7 +882,7 @@ int xc_set_hvm_param(int handle, domid_t
     return rc;
 }
 
-int xc_get_hvm_param(int handle, domid_t dom, int param, unsigned long *value)
+int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned 
long *value)
 {
     DECLARE_HYPERCALL;
     xen_hvm_param_t arg;
@@ -901,7 +901,7 @@ int xc_get_hvm_param(int handle, domid_t
     return rc;
 }
 
-int xc_domain_setdebugging(int xc_handle,
+int xc_domain_setdebugging(xc_interface *xch,
                            uint32_t domid,
                            unsigned int enable)
 {
@@ -910,11 +910,11 @@ int xc_domain_setdebugging(int xc_handle
     domctl.cmd = XEN_DOMCTL_setdebugging;
     domctl.domain = domid;
     domctl.u.setdebugging.enable = enable;
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
 int xc_assign_device(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     uint32_t machine_bdf)
 {
@@ -924,11 +924,11 @@ int xc_assign_device(
     domctl.domain = domid;
     domctl.u.assign_device.machine_bdf = machine_bdf;
 
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
 int xc_get_device_group(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     uint32_t machine_bdf,
     uint32_t max_sdevs,
@@ -951,7 +951,7 @@ int xc_get_device_group(
         PERROR("Could not lock memory for xc_get_device_group\n");
         return -ENOMEM;
     }
-    rc = do_domctl(xc_handle, &domctl);
+    rc = do_domctl(xch, &domctl);
     unlock_pages(sdev_array, max_sdevs * sizeof(*sdev_array));
 
     *num_sdevs = domctl.u.get_device_group.num_sdevs;
@@ -959,7 +959,7 @@ int xc_get_device_group(
 }
 
 int xc_test_assign_device(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     uint32_t machine_bdf)
 {
@@ -969,11 +969,11 @@ int xc_test_assign_device(
     domctl.domain = domid;
     domctl.u.assign_device.machine_bdf = machine_bdf;
 
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
 int xc_deassign_device(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     uint32_t machine_bdf)
 {
@@ -983,11 +983,11 @@ int xc_deassign_device(
     domctl.domain = domid;
     domctl.u.assign_device.machine_bdf = machine_bdf;
  
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
 int xc_domain_update_msi_irq(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     uint32_t gvec,
     uint32_t pirq,
@@ -1010,12 +1010,12 @@ int xc_domain_update_msi_irq(
     bind->u.msi.gflags = gflags;
     bind->u.msi.gtable = gtable;
 
-    rc = do_domctl(xc_handle, &domctl);
+    rc = do_domctl(xch, &domctl);
     return rc;
 }
 
 int xc_domain_unbind_msi_irq(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     uint32_t gvec,
     uint32_t pirq,
@@ -1036,13 +1036,13 @@ int xc_domain_unbind_msi_irq(
     bind->u.msi.gvec = gvec;
     bind->u.msi.gflags = gflags;
 
-    rc = do_domctl(xc_handle, &domctl);
+    rc = do_domctl(xch, &domctl);
     return rc;
 }
 
 /* Pass-through: binds machine irq to guests irq */
 int xc_domain_bind_pt_irq(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     uint8_t machine_irq,
     uint8_t irq_type,
@@ -1072,12 +1072,12 @@ int xc_domain_bind_pt_irq(
     else if ( irq_type == PT_IRQ_TYPE_ISA )
         bind->u.isa.isa_irq = isa_irq;
     
-    rc = do_domctl(xc_handle, &domctl);
+    rc = do_domctl(xch, &domctl);
     return rc;
 }
 
 int xc_domain_unbind_pt_irq(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     uint8_t machine_irq,
     uint8_t irq_type,
@@ -1102,12 +1102,12 @@ int xc_domain_unbind_pt_irq(
     bind->u.pci.intx = intx;
     bind->u.isa.isa_irq = isa_irq;
     
-    rc = do_domctl(xc_handle, &domctl);
+    rc = do_domctl(xch, &domctl);
     return rc;
 }
 
 int xc_domain_bind_pt_pci_irq(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     uint8_t machine_irq,
     uint8_t bus,
@@ -1115,22 +1115,22 @@ int xc_domain_bind_pt_pci_irq(
     uint8_t intx)
 {
 
-    return (xc_domain_bind_pt_irq(xc_handle, domid, machine_irq,
+    return (xc_domain_bind_pt_irq(xch, domid, machine_irq,
                                   PT_IRQ_TYPE_PCI, bus, device, intx, 0));
 }
 
 int xc_domain_bind_pt_isa_irq(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     uint8_t machine_irq)
 {
 
-    return (xc_domain_bind_pt_irq(xc_handle, domid, machine_irq,
+    return (xc_domain_bind_pt_irq(xch, domid, machine_irq,
                                   PT_IRQ_TYPE_ISA, 0, 0, 0, machine_irq));
 }
 
 int xc_domain_memory_mapping(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     unsigned long first_gfn,
     unsigned long first_mfn,
@@ -1146,11 +1146,11 @@ int xc_domain_memory_mapping(
     domctl.u.memory_mapping.nr_mfns = nr_mfns;
     domctl.u.memory_mapping.add_mapping = add_mapping;
 
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
 int xc_domain_ioport_mapping(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     uint32_t first_gport,
     uint32_t first_mport,
@@ -1166,11 +1166,11 @@ int xc_domain_ioport_mapping(
     domctl.u.ioport_mapping.nr_ports = nr_ports;
     domctl.u.ioport_mapping.add_mapping = add_mapping;
 
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
 int xc_domain_set_target(
-    int xc_handle,
+    xc_interface *xch,
     uint32_t domid,
     uint32_t target)
 {
@@ -1180,11 +1180,11 @@ int xc_domain_set_target(
     domctl.domain = domid;
     domctl.u.set_target.target = target;
 
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
 int xc_domain_subscribe_for_suspend(
-    int xc_handle, domid_t dom, evtchn_port_t port)
+    xc_interface *xch, domid_t dom, evtchn_port_t port)
 {
     DECLARE_DOMCTL;
 
@@ -1192,10 +1192,10 @@ int xc_domain_subscribe_for_suspend(
     domctl.domain = dom;
     domctl.u.subscribe.port = port;
 
-    return do_domctl(xc_handle, &domctl);
-}
-
-int xc_domain_set_machine_address_size(int xc,
+    return do_domctl(xch, &domctl);
+}
+
+int xc_domain_set_machine_address_size(xc_interface *xch,
                                        uint32_t domid,
                                        unsigned int width)
 {
@@ -1206,37 +1206,37 @@ int xc_domain_set_machine_address_size(i
     domctl.cmd    = XEN_DOMCTL_set_machine_address_size;
     domctl.u.address_size.size = width;
 
+    return do_domctl(xch, &domctl);
+}
+
+
+int xc_domain_get_machine_address_size(xc_interface *xch, uint32_t domid)
+{
+    DECLARE_DOMCTL;
+    int rc;
+
+    memset(&domctl, 0, sizeof(domctl));
+    domctl.domain = domid;
+    domctl.cmd    = XEN_DOMCTL_get_machine_address_size;
+
+    rc = do_domctl(xch, &domctl);
+
+    return rc == 0 ? domctl.u.address_size.size : rc;
+}
+
+int xc_domain_suppress_spurious_page_faults(xc_interface *xc, uint32_t domid)
+{
+    DECLARE_DOMCTL;
+
+    memset(&domctl, 0, sizeof(domctl));
+    domctl.domain = domid;
+    domctl.cmd    = XEN_DOMCTL_suppress_spurious_page_faults;
+
     return do_domctl(xc, &domctl);
-}
-
-
-int xc_domain_get_machine_address_size(int xc, uint32_t domid)
-{
-    DECLARE_DOMCTL;
-    int rc;
-
-    memset(&domctl, 0, sizeof(domctl));
-    domctl.domain = domid;
-    domctl.cmd    = XEN_DOMCTL_get_machine_address_size;
-
-    rc = do_domctl(xc, &domctl);
-
-    return rc == 0 ? domctl.u.address_size.size : rc;
-}
-
-int xc_domain_suppress_spurious_page_faults(int xc, uint32_t domid)
-{
-    DECLARE_DOMCTL;
-
-    memset(&domctl, 0, sizeof(domctl));
-    domctl.domain = domid;
-    domctl.cmd    = XEN_DOMCTL_suppress_spurious_page_faults;
-
-    return do_domctl(xc, &domctl);
-
-}
-
-int xc_domain_debug_control(int xc, uint32_t domid, uint32_t sop, uint32_t 
vcpu)
+
+}
+
+int xc_domain_debug_control(xc_interface *xc, uint32_t domid, uint32_t sop, 
uint32_t vcpu)
 {
     DECLARE_DOMCTL;
 
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_domain_restore.c
--- a/tools/libxc/xc_domain_restore.c   Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_domain_restore.c   Fri May 28 09:30:19 2010 +0100
@@ -62,7 +62,8 @@ struct restore_ctx {
 #define SUPER_PAGE_TRACKING(pfn) ( (pfn) != INVALID_SUPER_PAGE )
 #define SUPER_PAGE_DONE(pfn)     ( SUPER_PAGE_START(pfn) )
 
-static int super_page_populated(struct restore_ctx *ctx, unsigned long pfn)
+static int super_page_populated(xc_interface *xch,
+                                struct restore_ctx *ctx, unsigned long pfn)
 {
     int i;
     pfn &= ~(SUPERPAGE_NR_PFNS - 1);
@@ -78,7 +79,7 @@ static int super_page_populated(struct r
  * Break a 2M page and move contents of [extent start, next_pfn-1] to
  * some new allocated 4K pages
  */
-static int break_super_page(int xc_handle,
+static int break_super_page(xc_interface *xch,
                             uint32_t dom,
                             struct restore_ctx *ctx,
                             xen_pfn_t next_pfn)
@@ -118,7 +119,7 @@ static int break_super_page(int xc_handl
         page_array[i] = start_pfn + i;
     }
 
-    ram_base = xc_map_foreign_pages(xc_handle, dom, PROT_READ,
+    ram_base = xc_map_foreign_pages(xch, dom, PROT_READ,
                                     page_array, tot_pfns);
 
     if ( ram_base == NULL )
@@ -132,7 +133,7 @@ static int break_super_page(int xc_handl
     munmap(ram_base, tot_pfns * PAGE_SIZE);
 
     /* free the super page */
-    if ( xc_domain_memory_decrease_reservation(xc_handle, dom, 1,
+    if ( xc_domain_memory_decrease_reservation(xch, dom, 1,
                                    SUPERPAGE_PFN_SHIFT, &start_pfn) != 0 )
     {
         ERROR("free 2M page failure @ 0x%ld.\n", next_pfn);
@@ -149,7 +150,7 @@ static int break_super_page(int xc_handl
     for ( i = start_pfn; i < start_pfn + tot_pfns; i++ )
     {
         mfn = i;
-        if (xc_domain_memory_populate_physmap(xc_handle, dom, 1, 0,
+        if (xc_domain_memory_populate_physmap(xch, dom, 1, 0,
                                               0, &mfn) != 0)
         {
             ERROR("Failed to allocate physical memory.!\n");
@@ -166,7 +167,7 @@ static int break_super_page(int xc_handl
         page_array[i] = start_pfn + i;
     }
 
-    ram_base = xc_map_foreign_pages(xc_handle, dom, PROT_WRITE,
+    ram_base = xc_map_foreign_pages(xch, dom, PROT_WRITE,
                                     page_array, tot_pfns);
     if ( ram_base == NULL )
     {
@@ -192,7 +193,7 @@ out:
  * If new pages fit the missing one in the 2M extent, do nothing; Else take
  * place of the original 2M page by some 4K pages.
  */
-static int allocate_mfn_list(int xc_handle,
+static int allocate_mfn_list(xc_interface *xch,
                               uint32_t dom,
                               struct restore_ctx *ctx,
                               unsigned long nr_extents,
@@ -221,7 +222,7 @@ static int allocate_mfn_list(int xc_hand
              !SUPER_PAGE_DONE(sp_pfn))
         {
             /* break previously allocated super page*/
-            if ( break_super_page(xc_handle, dom, ctx, sp_pfn) != 0 )
+            if ( break_super_page(xch, dom, ctx, sp_pfn) != 0 )
             {
                 ERROR("Break previous super page fail!\n");
                 return 1;
@@ -244,13 +245,13 @@ static int allocate_mfn_list(int xc_hand
         goto normal_page;
 
     pfn = batch_buf[0] & ~XEN_DOMCTL_PFINFO_LTAB_MASK;
-    if  ( super_page_populated(ctx, pfn) )
+    if  ( super_page_populated(xch, ctx, pfn) )
         goto normal_page;
 
     pfn &= ~(SUPERPAGE_NR_PFNS - 1);
     mfn =  pfn;
 
-    if ( xc_domain_memory_populate_physmap(xc_handle, dom, 1,
+    if ( xc_domain_memory_populate_physmap(xch, dom, 1,
                 SUPERPAGE_PFN_SHIFT, 0, &mfn) == 0)
     {
         for ( i = pfn; i < pfn + SUPERPAGE_NR_PFNS; i++, mfn++ )
@@ -279,7 +280,7 @@ normal_page:
         pfn = mfn = batch_buf[i] & ~XEN_DOMCTL_PFINFO_LTAB_MASK;
         if ( ctx->p2m[pfn] == INVALID_P2M_ENTRY )
         {
-            if (xc_domain_memory_populate_physmap(xc_handle, dom, 1, 0,
+            if (xc_domain_memory_populate_physmap(xch, dom, 1, 0,
                         0, &mfn) != 0)
             {
                 ERROR("Failed to allocate physical memory.! pfn=0x%lx, 
mfn=0x%lx.\n",
@@ -294,7 +295,7 @@ normal_page:
     return 0;
 }
 
-static int allocate_physmem(int xc_handle, uint32_t dom,
+static int allocate_physmem(xc_interface *xch, uint32_t dom,
                             struct restore_ctx *ctx,
                             unsigned long *region_pfn_type, int region_size,
                             unsigned int hvm, xen_pfn_t *region_mfn, int 
superpages)
@@ -337,7 +338,7 @@ static int allocate_physmem(int xc_handl
         if ( SUPER_PAGE_START(pfn) )
         {
             /* Start of a 2M extent, populate previsous buf */
-            if ( allocate_mfn_list(xc_handle, dom, ctx,
+            if ( allocate_mfn_list(xch, dom, ctx,
                                    batch_buf_len, batch_buf,
                                    &required_pfn, superpages) != 0 )
             {
@@ -359,7 +360,7 @@ static int allocate_physmem(int xc_handl
         else if ( SUPER_PAGE_TRACKING(required_pfn) )
         {
             /* break of a 2M extent, populate previous buf */
-            if ( allocate_mfn_list(xc_handle, dom, ctx,
+            if ( allocate_mfn_list(xch, dom, ctx,
                                    batch_buf_len, batch_buf,
                                    &required_pfn, superpages) != 0 )
             {
@@ -400,7 +401,7 @@ alloc_page:
 alloc_page:
     if ( batch_buf )
     {
-        if ( allocate_mfn_list(xc_handle, dom, ctx,
+        if ( allocate_mfn_list(xch, dom, ctx,
                     batch_buf_len, batch_buf,
                     &required_pfn,
                     superpages) != 0 )
@@ -493,7 +494,7 @@ static ssize_t read_exact_timed(int fd, 
 ** This function inverts that operation, replacing the pfn values with
 ** the (now known) appropriate mfn values.
 */
-static int uncanonicalize_pagetable(int xc_handle, uint32_t dom, struct 
restore_ctx *ctx,
+static int uncanonicalize_pagetable(xc_interface *xch, uint32_t dom, struct 
restore_ctx *ctx,
                                     void *page, int superpages)
 {
     int i, pte_last;
@@ -520,7 +521,7 @@ static int uncanonicalize_pagetable(int 
         if ( ctx->p2m[pfn] == INVALID_P2M_ENTRY )
         {
             unsigned long force_pfn = superpages ? FORCE_SP_MASK : pfn;
-            if (allocate_mfn_list(xc_handle, dom, ctx,
+            if (allocate_mfn_list(xch, dom, ctx,
                         1, &pfn, &force_pfn, superpages) != 0)
                 return 0;
         }
@@ -538,7 +539,8 @@ static int uncanonicalize_pagetable(int 
 
 
 /* Load the p2m frame list, plus potential extended info chunk */
-static xen_pfn_t *load_p2m_frame_list(struct restore_ctx *ctx,
+static xen_pfn_t *load_p2m_frame_list(
+    xc_interface *xch, struct restore_ctx *ctx,
     int io_fd, int *pae_extended_cr3, int *ext_vcpucontext)
 {
     xen_pfn_t *p2m_frame_list;
@@ -685,7 +687,8 @@ typedef struct {
 } tailbuf_t;
 
 /* read stream until EOF, growing buffer as necssary */
-static int compat_buffer_qemu(int fd, struct tailbuf_hvm *buf)
+static int compat_buffer_qemu(xc_interface *xch,
+                              int fd, struct tailbuf_hvm *buf)
 {
     uint8_t *qbuf, *tmp;
     int blen = 0, dlen = 0;
@@ -733,7 +736,8 @@ static int compat_buffer_qemu(int fd, st
     return 0;
 }
 
-static int buffer_qemu(int fd, struct tailbuf_hvm *buf)
+static int buffer_qemu(xc_interface *xch,
+                       int fd, struct tailbuf_hvm *buf)
 {
     uint32_t qlen;
     uint8_t *tmp;
@@ -770,7 +774,7 @@ static int buffer_qemu(int fd, struct ta
     return 0;
 }
 
-static int dump_qemu(uint32_t dom, struct tailbuf_hvm *buf)
+static int dump_qemu(xc_interface *xch, uint32_t dom, struct tailbuf_hvm *buf)
 {
     int saved_errno;
     char path[256];
@@ -794,7 +798,8 @@ static int dump_qemu(uint32_t dom, struc
     return 0;
 }
 
-static int buffer_tail_hvm(struct restore_ctx *ctx, struct tailbuf_hvm *buf, 
int fd,
+static int buffer_tail_hvm(xc_interface *xch, struct restore_ctx *ctx,
+                           struct tailbuf_hvm *buf, int fd,
                            unsigned int max_vcpu_id, uint64_t vcpumap,
                            int ext_vcpucontext)
 {
@@ -846,16 +851,17 @@ static int buffer_tail_hvm(struct restor
      * until EOF. Remus gets around this by sending a different signature
      * which includes a length prefix */
     if ( !memcmp(qemusig, "QemuDeviceModelRecord", sizeof(qemusig)) )
-        return compat_buffer_qemu(fd, buf);
+        return compat_buffer_qemu(xch, fd, buf);
     else if ( !memcmp(qemusig, "RemusDeviceModelState", sizeof(qemusig)) )
-        return buffer_qemu(fd, buf);
+        return buffer_qemu(xch, fd, buf);
 
     qemusig[20] = '\0';
     ERROR("Invalid QEMU signature: %s", qemusig);
     return -1;
 }
 
-static int buffer_tail_pv(struct restore_ctx *ctx, struct tailbuf_pv *buf, int 
fd,
+static int buffer_tail_pv(xc_interface *xch, struct restore_ctx *ctx,
+                          struct tailbuf_pv *buf, int fd,
                           unsigned int max_vcpu_id, uint64_t vcpumap,
                           int ext_vcpucontext)
 {
@@ -933,14 +939,15 @@ static int buffer_tail_pv(struct restore
     return -1;
 }
 
-static int buffer_tail(struct restore_ctx *ctx, tailbuf_t *buf, int fd, 
unsigned int max_vcpu_id,
+static int buffer_tail(xc_interface *xch, struct restore_ctx *ctx,
+                       tailbuf_t *buf, int fd, unsigned int max_vcpu_id,
                        uint64_t vcpumap, int ext_vcpucontext)
 {
     if ( buf->ishvm )
-        return buffer_tail_hvm(ctx, &buf->u.hvm, fd, max_vcpu_id, vcpumap,
+        return buffer_tail_hvm(xch, ctx, &buf->u.hvm, fd, max_vcpu_id, vcpumap,
                                ext_vcpucontext);
     else
-        return buffer_tail_pv(ctx, &buf->u.pv, fd, max_vcpu_id, vcpumap,
+        return buffer_tail_pv(xch, ctx, &buf->u.pv, fd, max_vcpu_id, vcpumap,
                               ext_vcpucontext);
 }
 
@@ -1011,7 +1018,8 @@ static void pagebuf_free(pagebuf_t* buf)
     }
 }
 
-static int pagebuf_get_one(pagebuf_t* buf, int fd, int xch, uint32_t dom)
+static int pagebuf_get_one(xc_interface *xch,
+                           pagebuf_t* buf, int fd, uint32_t dom)
 {
     int count, countpages, oldcount, i;
     void* ptmp;
@@ -1030,7 +1038,7 @@ static int pagebuf_get_one(pagebuf_t* bu
     } else if (count == -1) {
         DPRINTF("Entering page verify mode\n");
         buf->verify = 1;
-        return pagebuf_get_one(buf, fd, xch, dom);
+        return pagebuf_get_one(xch, buf, fd, dom);
     } else if (count == -2) {
         buf->new_ctxt_format = 1;
         if ( read_exact(fd, &buf->max_vcpu_id, sizeof(buf->max_vcpu_id)) ||
@@ -1040,7 +1048,7 @@ static int pagebuf_get_one(pagebuf_t* bu
             return -1;
         }
         // DPRINTF("Max VCPU ID: %d, vcpumap: %llx\n", buf->max_vcpu_id, 
buf->vcpumap);
-        return pagebuf_get_one(buf, fd, xch, dom);
+        return pagebuf_get_one(xch, buf, fd, dom);
     } else if (count == -3) {
         /* Skip padding 4 bytes then read the EPT identity PT location. */
         if ( read_exact(fd, &buf->identpt, sizeof(uint32_t)) ||
@@ -1050,7 +1058,7 @@ static int pagebuf_get_one(pagebuf_t* bu
             return -1;
         }
         // DPRINTF("EPT identity map address: %llx\n", buf->identpt);
-        return pagebuf_get_one(buf, fd, xch, dom);
+        return pagebuf_get_one(xch, buf, fd, dom);
     } else if ( count == -4 )  {
         /* Skip padding 4 bytes then read the vm86 TSS location. */
         if ( read_exact(fd, &buf->vm86_tss, sizeof(uint32_t)) ||
@@ -1060,21 +1068,21 @@ static int pagebuf_get_one(pagebuf_t* bu
             return -1;
         }
         // DPRINTF("VM86 TSS location: %llx\n", buf->vm86_tss);
-        return pagebuf_get_one(buf, fd, xch, dom);
+        return pagebuf_get_one(xch, buf, fd, dom);
     } else if ( count == -5 ) {
         DPRINTF("xc_domain_restore start tmem\n");
         if ( xc_tmem_restore(xch, dom, fd) ) {
             ERROR("error reading/restoring tmem");
             return -1;
         }
-        return pagebuf_get_one(buf, fd, xch, dom);
+        return pagebuf_get_one(xch, buf, fd, dom);
     }
     else if ( count == -6 ) {
         if ( xc_tmem_restore_extra(xch, dom, fd) ) {
             ERROR("error reading/restoring tmem extra");
             return -1;
         }
-        return pagebuf_get_one(buf, fd, xch, dom);
+        return pagebuf_get_one(xch, buf, fd, dom);
     } else if ( count == -7 ) {
         uint32_t tsc_mode, khz, incarn;
         uint64_t nsec;
@@ -1086,7 +1094,7 @@ static int pagebuf_get_one(pagebuf_t* bu
             ERROR("error reading/restoring tsc info");
             return -1;
         }
-        return pagebuf_get_one(buf, fd, xch, dom);
+        return pagebuf_get_one(xch, buf, fd, dom);
     } else if ( (count > MAX_BATCH_SIZE) || (count < 0) ) {
         ERROR("Max batch size exceeded (%d). Giving up.", count);
         return -1;
@@ -1141,14 +1149,14 @@ static int pagebuf_get_one(pagebuf_t* bu
     return count;
 }
 
-static int pagebuf_get(pagebuf_t* buf, int fd, int xch, uint32_t dom)
+static int pagebuf_get(xc_interface *xch, pagebuf_t* buf, int fd, uint32_t dom)
 {
     int rc;
 
     buf->nr_physpages = buf->nr_pages = 0;
 
     do {
-        rc = pagebuf_get_one(buf, fd, xch, dom);
+        rc = pagebuf_get_one(xch, buf, fd, dom);
     } while (rc > 0);
 
     if (rc < 0)
@@ -1157,7 +1165,7 @@ static int pagebuf_get(pagebuf_t* buf, i
     return rc;
 }
 
-static int apply_batch(int xc_handle, uint32_t dom, struct restore_ctx *ctx,
+static int apply_batch(xc_interface *xch, uint32_t dom, struct restore_ctx 
*ctx,
                        xen_pfn_t* region_mfn, unsigned long* pfn_type, int 
pae_extended_cr3,
                        unsigned int hvm, struct xc_mmu* mmu,
                        pagebuf_t* pagebuf, int curbatch, int superpages)
@@ -1180,7 +1188,7 @@ static int apply_batch(int xc_handle, ui
     if (j > MAX_BATCH_SIZE)
         j = MAX_BATCH_SIZE;
 
-    if (allocate_physmem(xc_handle, dom, ctx, &pagebuf->pfn_types[curbatch],
+    if (allocate_physmem(xch, dom, ctx, &pagebuf->pfn_types[curbatch],
                          j, hvm, region_mfn, superpages) != 0)
     {
         ERROR("allocate_physmem() failed\n");
@@ -1190,7 +1198,7 @@ static int apply_batch(int xc_handle, ui
     /* Map relevant mfns */
     pfn_err = calloc(j, sizeof(*pfn_err));
     region_base = xc_map_foreign_bulk(
-        xc_handle, dom, PROT_WRITE, region_mfn, pfn_err, j);
+        xch, dom, PROT_WRITE, region_mfn, pfn_err, j);
 
     if ( region_base == NULL )
     {
@@ -1249,7 +1257,7 @@ static int apply_batch(int xc_handle, ui
                 pae_extended_cr3 ||
                 (pagetype != XEN_DOMCTL_PFINFO_L1TAB)) {
 
-                if (!uncanonicalize_pagetable(xc_handle, dom, ctx,
+                if (!uncanonicalize_pagetable(xch, dom, ctx,
                                               page, superpages)) {
                     /*
                     ** Failing to uncanonicalize a page table can be ok
@@ -1293,7 +1301,7 @@ static int apply_batch(int xc_handle, ui
         }
 
         if ( !hvm &&
-             xc_add_mmu_update(xc_handle, mmu,
+             xc_add_mmu_update(xch, mmu,
                                (((unsigned long long)mfn) << PAGE_SHIFT)
                                | MMU_MACHPHYS_UPDATE, pfn) )
         {
@@ -1311,7 +1319,7 @@ static int apply_batch(int xc_handle, ui
     return rc;
 }
 
-int xc_domain_restore(int xc_handle, int io_fd, uint32_t dom,
+int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
                       unsigned int store_evtchn, unsigned long *store_mfn,
                       unsigned int console_evtchn, unsigned long *console_mfn,
                       unsigned int hvm, unsigned int pae, int superpages)
@@ -1319,7 +1327,7 @@ int xc_domain_restore(int xc_handle, int
     DECLARE_DOMCTL;
     int rc = 1, frc, i, j, n, m, pae_extended_cr3 = 0, ext_vcpucontext = 0;
     unsigned long mfn, pfn;
-    unsigned int prev_pc, this_pc;
+    unsigned int prev_pc;
     int nraces = 0;
 
     /* The new domain's shared-info frame number. */
@@ -1386,7 +1394,7 @@ int xc_domain_restore(int xc_handle, int
     }
     DPRINTF("xc_domain_restore start: p2m_size = %lx\n", dinfo->p2m_size);
 
-    if ( !get_platform_info(xc_handle, dom,
+    if ( !get_platform_info(xch, dom,
                             &ctx->max_mfn, &ctx->hvirt_start, &ctx->pt_levels, 
&dinfo->guest_width) )
     {
         ERROR("Unable to get platform info.");
@@ -1402,7 +1410,7 @@ int xc_domain_restore(int xc_handle, int
     if ( !hvm ) 
     {
         /* Load the p2m frame list, plus potential extended info chunk */
-        p2m_frame_list = load_p2m_frame_list(ctx,
+        p2m_frame_list = load_p2m_frame_list(xch, ctx,
             io_fd, &pae_extended_cr3, &ext_vcpucontext);
         if ( !p2m_frame_list )
             goto out;
@@ -1412,7 +1420,7 @@ int xc_domain_restore(int xc_handle, int
         domctl.domain = dom;
         domctl.cmd    = XEN_DOMCTL_set_address_size;
         domctl.u.address_size.size = dinfo->guest_width * 8;
-        frc = do_domctl(xc_handle, &domctl);
+        frc = do_domctl(xch, &domctl);
         if ( frc != 0 )
         {
             ERROR("Unable to set guest address size.");
@@ -1447,7 +1455,7 @@ int xc_domain_restore(int xc_handle, int
     /* Get the domain's shared-info frame. */
     domctl.cmd = XEN_DOMCTL_getdomaininfo;
     domctl.domain = (domid_t)dom;
-    if ( xc_domctl(xc_handle, &domctl) < 0 )
+    if ( xc_domctl(xch, &domctl) < 0 )
     {
         ERROR("Could not get information on new domain");
         goto out;
@@ -1458,14 +1466,14 @@ int xc_domain_restore(int xc_handle, int
     for ( pfn = 0; pfn < dinfo->p2m_size; pfn++ )
         ctx->p2m[pfn] = INVALID_P2M_ENTRY;
 
-    mmu = xc_alloc_mmu_updates(xc_handle, dom);
+    mmu = xc_alloc_mmu_updates(xch, dom);
     if ( mmu == NULL )
     {
         ERROR("Could not initialise for MMU updates");
         goto out;
     }
 
-    DPRINTF("Reloading memory pages:   0%%\n");
+    xc_report_progress_start(xch, "Reloading memory pages", dinfo->p2m_size);
 
     /*
      * Now simply read each saved frame into its new machine frame.
@@ -1479,23 +1487,18 @@ int xc_domain_restore(int xc_handle, int
     {
         int j, curbatch;
 
-        this_pc = (n * 100) / dinfo->p2m_size;
-        if ( (this_pc - prev_pc) >= 5 )
-        {
-            PPRINTF("\b\b\b\b%3d%%", this_pc);
-            prev_pc = this_pc;
-        }
+        xc_report_progress_step(xch, n, dinfo->p2m_size);
 
         if ( !completed ) {
             pagebuf.nr_physpages = pagebuf.nr_pages = 0;
-            if ( pagebuf_get_one(&pagebuf, io_fd, xc_handle, dom) < 0 ) {
+            if ( pagebuf_get_one(xch, &pagebuf, io_fd, dom) < 0 ) {
                 ERROR("Error when reading batch\n");
                 goto out;
             }
         }
         j = pagebuf.nr_pages;
 
-        PPRINTF("batch %d\n",j);
+        DPRINTF("batch %d\n",j);
 
         if ( j == 0 ) {
             /* catch vcpu updates */
@@ -1505,9 +1508,9 @@ int xc_domain_restore(int xc_handle, int
             }
             /* should this be deferred? does it change? */
             if ( pagebuf.identpt )
-                xc_set_hvm_param(xc_handle, dom, HVM_PARAM_IDENT_PT, 
pagebuf.identpt);
+                xc_set_hvm_param(xch, dom, HVM_PARAM_IDENT_PT, 
pagebuf.identpt);
             if ( pagebuf.vm86_tss )
-                xc_set_hvm_param(xc_handle, dom, HVM_PARAM_VM86_TSS, 
pagebuf.vm86_tss);
+                xc_set_hvm_param(xch, dom, HVM_PARAM_VM86_TSS, 
pagebuf.vm86_tss);
             break;  /* our work here is done */
         }
 
@@ -1516,7 +1519,7 @@ int xc_domain_restore(int xc_handle, int
         while ( curbatch < j ) {
             int brc;
 
-            brc = apply_batch(xc_handle, dom, ctx, region_mfn, pfn_type,
+            brc = apply_batch(xch, dom, ctx, region_mfn, pfn_type,
                               pae_extended_cr3, hvm, mmu, &pagebuf, curbatch, 
superpages);
             if ( brc < 0 )
                 goto out;
@@ -1537,7 +1540,7 @@ int xc_domain_restore(int xc_handle, int
         m += j;
         if ( m > MAX_PAGECACHE_USAGE )
         {
-            discard_file_cache(io_fd, 0 /* no flush */);
+            discard_file_cache(xch, io_fd, 0 /* no flush */);
             m = 0;
         }
     }
@@ -1546,7 +1549,7 @@ int xc_domain_restore(int xc_handle, int
      * Ensure we flush all machphys updates before potential PAE-specific
      * reallocations below.
      */
-    if ( !hvm && xc_flush_mmu_updates(xc_handle, mmu) )
+    if ( !hvm && xc_flush_mmu_updates(xch, mmu) )
     {
         ERROR("Error doing flush_mmu_updates()");
         goto out;
@@ -1557,7 +1560,7 @@ int xc_domain_restore(int xc_handle, int
     if ( !completed ) {
         int flags = 0;
 
-        if ( buffer_tail(ctx, &tailbuf, io_fd, max_vcpu_id, vcpumap,
+        if ( buffer_tail(xch, ctx, &tailbuf, io_fd, max_vcpu_id, vcpumap,
                          ext_vcpucontext) < 0 ) {
             ERROR ("error buffering image tail");
             goto out;
@@ -1571,13 +1574,13 @@ int xc_domain_restore(int xc_handle, int
 
     // DPRINTF("Buffered checkpoint\n");
 
-    if ( pagebuf_get(&pagebuf, io_fd, xc_handle, dom) ) {
+    if ( pagebuf_get(xch, &pagebuf, io_fd, dom) ) {
         ERROR("error when buffering batch, finishing\n");
         goto finish;
     }
     memset(&tmptail, 0, sizeof(tmptail));
     tmptail.ishvm = hvm;
-    if ( buffer_tail(ctx, &tmptail, io_fd, max_vcpu_id, vcpumap,
+    if ( buffer_tail(xch, ctx, &tmptail, io_fd, max_vcpu_id, vcpumap,
                      ext_vcpucontext) < 0 ) {
         ERROR ("error buffering image tail, finishing");
         goto finish;
@@ -1619,7 +1622,7 @@ int xc_domain_restore(int xc_handle, int
                 uint64_t *l3tab;
 
                 l3tab = (uint64_t *)
-                    xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
+                    xc_map_foreign_range(xch, dom, PAGE_SIZE,
                                          PROT_READ, ctx->p2m[i]);
 
                 for ( j = 0; j < 4; j++ )
@@ -1627,7 +1630,7 @@ int xc_domain_restore(int xc_handle, int
 
                 munmap(l3tab, PAGE_SIZE);
 
-                new_mfn = xc_make_page_below_4G(xc_handle, dom, ctx->p2m[i]);
+                new_mfn = xc_make_page_below_4G(xch, dom, ctx->p2m[i]);
                 if ( !new_mfn )
                 {
                     ERROR("Couldn't get a page below 4GB :-(");
@@ -1635,7 +1638,7 @@ int xc_domain_restore(int xc_handle, int
                 }
 
                 ctx->p2m[i] = new_mfn;
-                if ( xc_add_mmu_update(xc_handle, mmu,
+                if ( xc_add_mmu_update(xch, mmu,
                                        (((unsigned long long)new_mfn)
                                         << PAGE_SHIFT) |
                                        MMU_MACHPHYS_UPDATE, i) )
@@ -1645,7 +1648,7 @@ int xc_domain_restore(int xc_handle, int
                 }
 
                 l3tab = (uint64_t *)
-                    xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
+                    xc_map_foreign_range(xch, dom, PAGE_SIZE,
                                          PROT_READ | PROT_WRITE, ctx->p2m[i]);
 
                 for ( j = 0; j < 4; j++ )
@@ -1670,7 +1673,7 @@ int xc_domain_restore(int xc_handle, int
             if ( (i == (dinfo->p2m_size-1)) || (j == MAX_BATCH_SIZE) )
             {
                 region_base = xc_map_foreign_pages(
-                    xc_handle, dom, PROT_READ | PROT_WRITE, region_mfn, j);
+                    xch, dom, PROT_READ | PROT_WRITE, region_mfn, j);
                 if ( region_base == NULL )
                 {
                     ERROR("map batch failed");
@@ -1680,7 +1683,7 @@ int xc_domain_restore(int xc_handle, int
                 for ( k = 0; k < j; k++ )
                 {
                     if ( !uncanonicalize_pagetable(
-                        xc_handle, dom, ctx,
+                        xch, dom, ctx,
                         region_base + k*PAGE_SIZE, superpages) )
                     {
                         ERROR("failed uncanonicalize pt!");
@@ -1693,7 +1696,7 @@ int xc_domain_restore(int xc_handle, int
             }
         }
 
-        if ( xc_flush_mmu_updates(xc_handle, mmu) )
+        if ( xc_flush_mmu_updates(xch, mmu) )
         {
             ERROR("Error doing xc_flush_mmu_updates()");
             goto out;
@@ -1738,7 +1741,7 @@ int xc_domain_restore(int xc_handle, int
         /* Batch full? Then flush. */
         if ( nr_pins == MAX_PIN_BATCH )
         {
-            if ( xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0 )
+            if ( xc_mmuext_op(xch, pin, nr_pins, dom) < 0 )
             {
                 ERROR("Failed to pin batch of %d page tables", nr_pins);
                 goto out;
@@ -1748,13 +1751,12 @@ int xc_domain_restore(int xc_handle, int
     }
 
     /* Flush final partial batch. */
-    if ( (nr_pins != 0) && (xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0) )
+    if ( (nr_pins != 0) && (xc_mmuext_op(xch, pin, nr_pins, dom) < 0) )
     {
         ERROR("Failed to pin batch of %d page tables", nr_pins);
         goto out;
     }
 
-    DPRINTF("\b\b\b\b100%%\n");
     DPRINTF("Memory reloaded (%ld pages)\n", ctx->nr_pfns);
 
     /* Get the list of PFNs that are not in the psuedo-phys map */
@@ -1783,7 +1785,7 @@ int xc_domain_restore(int xc_handle, int
             };
             set_xen_guest_handle(reservation.extent_start, 
tailbuf.u.pv.pfntab);
 
-            if ( (frc = xc_memory_op(xc_handle, XENMEM_decrease_reservation,
+            if ( (frc = xc_memory_op(xch, XENMEM_decrease_reservation,
                                      &reservation)) != nr_frees )
             {
                 ERROR("Could not decrease reservation : %d", frc);
@@ -1831,7 +1833,7 @@ int xc_domain_restore(int xc_handle, int
             mfn = ctx->p2m[pfn];
             SET_FIELD(&ctxt, user_regs.edx, mfn);
             start_info = xc_map_foreign_range(
-                xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE, mfn);
+                xch, dom, PAGE_SIZE, PROT_READ | PROT_WRITE, mfn);
             SET_FIELD(start_info, nr_pages, dinfo->p2m_size);
             SET_FIELD(start_info, shared_info, shared_info_frame<<PAGE_SHIFT);
             SET_FIELD(start_info, flags, 0);
@@ -1906,7 +1908,7 @@ int xc_domain_restore(int xc_handle, int
         domctl.domain = (domid_t)dom;
         domctl.u.vcpucontext.vcpu = i;
         set_xen_guest_handle(domctl.u.vcpucontext.ctxt, &ctxt.c);
-        frc = xc_domctl(xc_handle, &domctl);
+        frc = xc_domctl(xch, &domctl);
         if ( frc != 0 )
         {
             ERROR("Couldn't build vcpu%d", i);
@@ -1919,7 +1921,7 @@ int xc_domain_restore(int xc_handle, int
         vcpup += 128;
         domctl.cmd = XEN_DOMCTL_set_ext_vcpucontext;
         domctl.domain = dom;
-        frc = xc_domctl(xc_handle, &domctl);
+        frc = xc_domctl(xch, &domctl);
         if ( frc != 0 )
         {
             ERROR("Couldn't set extended vcpu%d info\n", i);
@@ -1933,7 +1935,7 @@ int xc_domain_restore(int xc_handle, int
 
     /* Restore contents of shared-info page. No checking needed. */
     new_shared_info = xc_map_foreign_range(
-        xc_handle, dom, PAGE_SIZE, PROT_WRITE, shared_info_frame);
+        xch, dom, PAGE_SIZE, PROT_WRITE, shared_info_frame);
 
     /* restore saved vcpu_info and arch specific info */
     MEMCPY_FIELD(new_shared_info, old_shared_info, vcpu_info);
@@ -1963,7 +1965,7 @@ int xc_domain_restore(int xc_handle, int
     }
 
     /* Copy the P2M we've constructed to the 'live' P2M */
-    if ( !(ctx->live_p2m = xc_map_foreign_pages(xc_handle, dom, PROT_WRITE,
+    if ( !(ctx->live_p2m = xc_map_foreign_pages(xch, dom, PROT_WRITE,
                                            p2m_frame_list, P2M_FL_ENTRIES)) )
     {
         ERROR("Couldn't map p2m table");
@@ -1988,29 +1990,29 @@ int xc_domain_restore(int xc_handle, int
 
   finish_hvm:
     /* Dump the QEMU state to a state file for QEMU to load */
-    if ( dump_qemu(dom, &tailbuf.u.hvm) ) {
+    if ( dump_qemu(xch, dom, &tailbuf.u.hvm) ) {
         ERROR("Error dumping QEMU state to file");
         goto out;
     }
 
     /* These comms pages need to be zeroed at the start of day */
-    if ( xc_clear_domain_page(xc_handle, dom, tailbuf.u.hvm.magicpfns[0]) ||
-         xc_clear_domain_page(xc_handle, dom, tailbuf.u.hvm.magicpfns[1]) ||
-         xc_clear_domain_page(xc_handle, dom, tailbuf.u.hvm.magicpfns[2]) )
+    if ( xc_clear_domain_page(xch, dom, tailbuf.u.hvm.magicpfns[0]) ||
+         xc_clear_domain_page(xch, dom, tailbuf.u.hvm.magicpfns[1]) ||
+         xc_clear_domain_page(xch, dom, tailbuf.u.hvm.magicpfns[2]) )
     {
         ERROR("error zeroing magic pages");
         goto out;
     }
 
-    if ( (frc = xc_set_hvm_param(xc_handle, dom,
+    if ( (frc = xc_set_hvm_param(xch, dom,
                                  HVM_PARAM_IOREQ_PFN, 
tailbuf.u.hvm.magicpfns[0]))
-         || (frc = xc_set_hvm_param(xc_handle, dom,
+         || (frc = xc_set_hvm_param(xch, dom,
                                     HVM_PARAM_BUFIOREQ_PFN, 
tailbuf.u.hvm.magicpfns[1]))
-         || (frc = xc_set_hvm_param(xc_handle, dom,
+         || (frc = xc_set_hvm_param(xch, dom,
                                     HVM_PARAM_STORE_PFN, 
tailbuf.u.hvm.magicpfns[2]))
-         || (frc = xc_set_hvm_param(xc_handle, dom,
+         || (frc = xc_set_hvm_param(xch, dom,
                                     HVM_PARAM_PAE_ENABLED, pae))
-         || (frc = xc_set_hvm_param(xc_handle, dom,
+         || (frc = xc_set_hvm_param(xch, dom,
                                     HVM_PARAM_STORE_EVTCHN,
                                     store_evtchn)) )
     {
@@ -2019,7 +2021,7 @@ int xc_domain_restore(int xc_handle, int
     }
     *store_mfn = tailbuf.u.hvm.magicpfns[2];
 
-    frc = xc_domain_hvm_setcontext(xc_handle, dom, tailbuf.u.hvm.hvmbuf,
+    frc = xc_domain_hvm_setcontext(xch, dom, tailbuf.u.hvm.hvmbuf,
                                    tailbuf.u.hvm.reclen);
     if ( frc )
     {
@@ -2032,14 +2034,14 @@ int xc_domain_restore(int xc_handle, int
 
  out:
     if ( (rc != 0) && (dom != 0) )
-        xc_domain_destroy(xc_handle, dom);
+        xc_domain_destroy(xch, dom);
     free(mmu);
     free(ctx->p2m);
     free(pfn_type);
     tailbuf_free(&tailbuf);
 
     /* discard cache for save file  */
-    discard_file_cache(io_fd, 1 /*flush*/);
+    discard_file_cache(xch, io_fd, 1 /*flush*/);
 
     DPRINTF("Restore exit with rc=%d\n", rc);
     
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_domain_save.c
--- a/tools/libxc/xc_domain_save.c      Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_domain_save.c      Fri May 28 09:30:19 2010 +0100
@@ -137,7 +137,8 @@ static uint64_t tv_delta(struct timeval 
             (new->tv_usec - old->tv_usec));
 }
 
-static int noncached_write(int fd, int live, void *buffer, int len) 
+static int noncached_write(xc_interface *xch,
+                           int fd, int live, void *buffer, int len) 
 {
     static int write_count = 0;
     int rc = (write_exact(fd, buffer, len) == 0) ? len : -1;
@@ -146,14 +147,14 @@ static int noncached_write(int fd, int l
     if ( write_count >= (MAX_PAGECACHE_USAGE * PAGE_SIZE) )
     {
         /* Time to discard cache - dont care if this fails */
-        discard_file_cache(fd, 0 /* no flush */);
+        discard_file_cache(xch, fd, 0 /* no flush */);
         write_count = 0;
     }
 
     return rc;
 }
 
-static int outbuf_init(struct outbuf* ob, size_t size)
+static int outbuf_init(xc_interface *xch, struct outbuf* ob, size_t size)
 {
     memset(ob, 0, sizeof(*ob));
 
@@ -167,7 +168,8 @@ static int outbuf_init(struct outbuf* ob
     return 0;
 }
 
-static inline int outbuf_write(struct outbuf* ob, void* buf, size_t len)
+static inline int outbuf_write(xc_interface *xch,
+                               struct outbuf* ob, void* buf, size_t len)
 {
     if ( len > ob->size - ob->pos ) {
         DPRINTF("outbuf_write: %zu > %zu@%zu\n", len, ob->size - ob->pos, 
ob->pos);
@@ -181,7 +183,7 @@ static inline int outbuf_write(struct ou
 }
 
 /* prep for nonblocking I/O */
-static int outbuf_flush(struct outbuf* ob, int fd)
+static int outbuf_flush(xc_interface *xch, struct outbuf* ob, int fd)
 {
     int rc;
     int cur = 0;
@@ -207,27 +209,29 @@ static int outbuf_flush(struct outbuf* o
 }
 
 /* if there's no room in the buffer, flush it and try again. */
-static inline int outbuf_hardwrite(struct outbuf* ob, int fd, void* buf,
+static inline int outbuf_hardwrite(xc_interface *xch,
+                                   struct outbuf* ob, int fd, void* buf,
                                    size_t len)
 {
     if ( !len )
         return 0;
 
-    if ( !outbuf_write(ob, buf, len) )
+    if ( !outbuf_write(xch, ob, buf, len) )
         return 0;
 
-    if ( outbuf_flush(ob, fd) < 0 )
+    if ( outbuf_flush(xch, ob, fd) < 0 )
         return -1;
 
-    return outbuf_write(ob, buf, len);
+    return outbuf_write(xch, ob, buf, len);
 }
 
 /* start buffering output once we've reached checkpoint mode. */
-static inline int write_buffer(int dobuf, struct outbuf* ob, int fd, void* buf,
+static inline int write_buffer(xc_interface *xch,
+                               int dobuf, struct outbuf* ob, int fd, void* buf,
                                size_t len)
 {
     if ( dobuf )
-        return outbuf_hardwrite(ob, fd, buf, len);
+        return outbuf_hardwrite(xch, ob, fd, buf, len);
     else
         return write_exact(fd, buf, len);
 }
@@ -259,7 +263,7 @@ static inline void initialize_mbit_rate(
     mbit_rate = START_MBIT_RATE;
 }
 
-static int ratewrite(int io_fd, int live, void *buf, int n)
+static int ratewrite(xc_interface *xch, int io_fd, int live, void *buf, int n)
 {
     static int budget = 0;
     static int burst_time_us = -1;
@@ -319,22 +323,23 @@ static int ratewrite(int io_fd, int live
 #else /* ! ADAPTIVE SAVE */
 
 #define RATE_IS_MAX() (0)
-#define ratewrite(_io_fd, _live, _buf, _n) noncached_write((_io_fd), (_live), 
(_buf), (_n))
+#define ratewrite(xch, _io_fd, _live, _buf, _n) noncached_write((xch), 
(_io_fd), (_live), (_buf), (_n))
 #define initialize_mbit_rate()
 
 #endif
 
 /* like write_buffer for ratewrite, which returns number of bytes written */
-static inline int ratewrite_buffer(int dobuf, struct outbuf* ob, int fd,
+static inline int ratewrite_buffer(xc_interface *xch,
+                                   int dobuf, struct outbuf* ob, int fd,
                                    int live, void* buf, size_t len)
 {
     if ( dobuf )
-        return outbuf_hardwrite(ob, fd, buf, len) ? -1 : len;
+        return outbuf_hardwrite(xch, ob, fd, buf, len) ? -1 : len;
     else
-        return ratewrite(fd, live, buf, len);
-}
-
-static int print_stats(int xc_handle, uint32_t domid, int pages_sent,
+        return ratewrite(xch, fd, live, buf, len);
+}
+
+static int print_stats(xc_interface *xch, uint32_t domid, int pages_sent,
                        xc_shadow_op_stats_t *stats, int print)
 {
     static struct timeval wall_last;
@@ -348,8 +353,8 @@ static int print_stats(int xc_handle, ui
 
     gettimeofday(&wall_now, NULL);
 
-    d0_cpu_now = xc_domain_get_cpu_usage(xc_handle, 0, /* FIXME */ 0)/1000;
-    d1_cpu_now = xc_domain_get_cpu_usage(xc_handle, domid, /* FIXME */ 0)/1000;
+    d0_cpu_now = xc_domain_get_cpu_usage(xch, 0, /* FIXME */ 0)/1000;
+    d1_cpu_now = xc_domain_get_cpu_usage(xch, domid, /* FIXME */ 0)/1000;
 
     if ( (d0_cpu_now == -1) || (d1_cpu_now == -1) )
         DPRINTF("ARRHHH!!\n");
@@ -389,7 +394,7 @@ static int print_stats(int xc_handle, ui
 }
 
 
-static int analysis_phase(int xc_handle, uint32_t domid, struct save_ctx *ctx,
+static int analysis_phase(xc_interface *xch, uint32_t domid, struct save_ctx 
*ctx,
                           unsigned long *arr, int runs)
 {
     long long start, now;
@@ -403,14 +408,14 @@ static int analysis_phase(int xc_handle,
     {
         int i;
 
-        xc_shadow_control(xc_handle, domid, XEN_DOMCTL_SHADOW_OP_CLEAN,
+        xc_shadow_control(xch, domid, XEN_DOMCTL_SHADOW_OP_CLEAN,
                           arr, dinfo->p2m_size, NULL, 0, NULL);
         DPRINTF("#Flush\n");
         for ( i = 0; i < 40; i++ )
         {
             usleep(50000);
             now = llgettimeofday();
-            xc_shadow_control(xc_handle, domid, XEN_DOMCTL_SHADOW_OP_PEEK,
+            xc_shadow_control(xch, domid, XEN_DOMCTL_SHADOW_OP_PEEK,
                               NULL, 0, NULL, 0, &stats);
             DPRINTF("now= %lld faults= %"PRId32" dirty= %"PRId32"\n",
                     ((now-start)+500)/1000,
@@ -422,7 +427,7 @@ static int analysis_phase(int xc_handle,
 }
 
 static int suspend_and_state(int (*suspend)(void*), void* data,
-                             int xc_handle, int io_fd, int dom,
+                             xc_interface *xch, int io_fd, int dom,
                              xc_dominfo_t *info)
 {
     if ( !(*suspend)(data) )
@@ -431,7 +436,7 @@ static int suspend_and_state(int (*suspe
         return -1;
     }
 
-    if ( (xc_domain_getinfo(xc_handle, dom, 1, info) != 1) ||
+    if ( (xc_domain_getinfo(xch, dom, 1, info) != 1) ||
          !info->shutdown || (info->shutdown_reason != SHUTDOWN_suspend) )
     {
         ERROR("Domain not in suspended state");
@@ -446,7 +451,7 @@ static int suspend_and_state(int (*suspe
 ** finished resuming from a previous restore operation, so we wait a while for
 ** it to update the MFN to a reasonable value.
 */
-static void *map_frame_list_list(int xc_handle, uint32_t dom,
+static void *map_frame_list_list(xc_interface *xch, uint32_t dom,
                                  struct save_ctx *ctx,
                                  shared_info_any_t *shinfo)
 {
@@ -467,7 +472,7 @@ static void *map_frame_list_list(int xc_
         return NULL;
     }
 
-    p = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ, fll);
+    p = xc_map_foreign_range(xch, dom, PAGE_SIZE, PROT_READ, fll);
     if ( p == NULL )
         ERROR("Couldn't map p2m_frame_list_list (errno %d)", errno);
 
@@ -597,7 +602,7 @@ static int canonicalize_pagetable(struct
     return race;
 }
 
-xen_pfn_t *xc_map_m2p(int xc_handle,
+xen_pfn_t *xc_map_m2p(xc_interface *xch,
                                  unsigned long max_mfn,
                                  int prot,
                                  unsigned long *mfn0)
@@ -623,7 +628,7 @@ xen_pfn_t *xc_map_m2p(int xc_handle,
     }
     set_xen_guest_handle(xmml.extent_start, extent_start);
 
-    if ( xc_memory_op(xc_handle, XENMEM_machphys_mfn_list, &xmml) ||
+    if ( xc_memory_op(xch, XENMEM_machphys_mfn_list, &xmml) ||
          (xmml.nr_extents != m2p_chunks) )
     {
         ERROR("xc_get_m2p_mfns");
@@ -640,7 +645,7 @@ xen_pfn_t *xc_map_m2p(int xc_handle,
     for ( i = 0; i < m2p_chunks; i++ )
         entries[i].mfn = extent_start[i];
 
-    m2p = xc_map_foreign_ranges(xc_handle, DOMID_XEN,
+    m2p = xc_map_foreign_ranges(xch, DOMID_XEN,
                        m2p_size, prot, M2P_CHUNK_SIZE,
                        entries, m2p_chunks);
     if (m2p == NULL)
@@ -662,7 +667,7 @@ err0:
 }
 
 
-static xen_pfn_t *map_and_save_p2m_table(int xc_handle, 
+static xen_pfn_t *map_and_save_p2m_table(xc_interface *xch, 
                                          int io_fd, 
                                          uint32_t dom,
                                          struct save_ctx *ctx,
@@ -684,7 +689,7 @@ static xen_pfn_t *map_and_save_p2m_table
 
     int i, success = 0;
 
-    live_p2m_frame_list_list = map_frame_list_list(xc_handle, dom, ctx,
+    live_p2m_frame_list_list = map_frame_list_list(xch, dom, ctx,
                                                    live_shinfo);
     if ( !live_p2m_frame_list_list )
         goto out;
@@ -709,7 +714,7 @@ static xen_pfn_t *map_and_save_p2m_table
             p2m_frame_list_list[i] = ((uint32_t *)p2m_frame_list_list)[i];
 
     live_p2m_frame_list =
-        xc_map_foreign_pages(xc_handle, dom, PROT_READ,
+        xc_map_foreign_pages(xch, dom, PROT_READ,
                              p2m_frame_list_list,
                              P2M_FLL_ENTRIES);
     if ( !live_p2m_frame_list )
@@ -744,7 +749,7 @@ static xen_pfn_t *map_and_save_p2m_table
        (its not clear why it would want to change them, and we'll be OK
        from a safety POV anyhow. */
 
-    p2m = xc_map_foreign_pages(xc_handle, dom, PROT_READ,
+    p2m = xc_map_foreign_pages(xch, dom, PROT_READ,
                                p2m_frame_list,
                                P2M_FL_ENTRIES);
     if ( !p2m )
@@ -777,7 +782,7 @@ static xen_pfn_t *map_and_save_p2m_table
         p2m_frame_list[i/FPP] = mfn_to_pfn(p2m_frame_list[i/FPP]);
     }
 
-    if ( xc_vcpu_getcontext(xc_handle, dom, 0, &ctxt) )
+    if ( xc_vcpu_getcontext(xch, dom, 0, &ctxt) )
     {
         ERROR("Could not get vcpu context");
         goto out;
@@ -838,13 +843,13 @@ static xen_pfn_t *map_and_save_p2m_table
 }
 
 /* must be done AFTER suspend_and_state() */
-static int save_tsc_info(int xc_handle, uint32_t dom, int io_fd)
+static int save_tsc_info(xc_interface *xch, uint32_t dom, int io_fd)
 {
     int marker = -7;
     uint32_t tsc_mode, khz, incarn;
     uint64_t nsec;
 
-    if ( xc_domain_get_tsc_info(xc_handle, dom, &tsc_mode,
+    if ( xc_domain_get_tsc_info(xch, dom, &tsc_mode,
                                 &nsec, &khz, &incarn) < 0  ||
          write_exact(io_fd, &marker, sizeof(marker)) ||
          write_exact(io_fd, &tsc_mode, sizeof(tsc_mode)) ||
@@ -855,7 +860,7 @@ static int save_tsc_info(int xc_handle, 
     return 0;
 }
 
-int xc_domain_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
+int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t 
max_iters,
                    uint32_t max_factor, uint32_t flags,
                    struct save_callbacks* callbacks,
                    int hvm, void (*switch_qemu_logdirty)(int, unsigned))
@@ -866,7 +871,8 @@ int xc_domain_save(int xc_handle, int io
     int rc = 1, frc, i, j, last_iter = 0, iter = 0;
     int live  = (flags & XCFLAGS_LIVE);
     int debug = (flags & XCFLAGS_DEBUG);
-    int race = 0, sent_last_iter, skip_this_iter;
+    int race = 0, sent_last_iter, skip_this_iter = 0;
+    unsigned int sent_this_iter = 0;
     int tmem_saved = 0;
 
     /* The new domain's shared-info frame number. */
@@ -921,7 +927,7 @@ int xc_domain_save(int xc_handle, int io
 
     int completed = 0;
 
-    outbuf_init(&ob, OUTBUF_SIZE);
+    outbuf_init(xch, &ob, OUTBUF_SIZE);
 
     /* If no explicit control parameters given, use defaults */
     max_iters  = max_iters  ? : DEF_MAX_ITERS;
@@ -929,14 +935,14 @@ int xc_domain_save(int xc_handle, int io
 
     initialize_mbit_rate();
 
-    if ( !get_platform_info(xc_handle, dom,
+    if ( !get_platform_info(xch, dom,
                             &ctx->max_mfn, &ctx->hvirt_start, &ctx->pt_levels, 
&dinfo->guest_width) )
     {
         ERROR("Unable to get platform info.");
         return 1;
     }
 
-    if ( xc_domain_getinfo(xc_handle, dom, 1, &info) != 1 )
+    if ( xc_domain_getinfo(xch, dom, 1, &info) != 1 )
     {
         ERROR("Could not get domain info");
         return 1;
@@ -947,7 +953,7 @@ int xc_domain_save(int xc_handle, int io
     /* Map the shared info frame */
     if ( !hvm )
     {
-        live_shinfo = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
+        live_shinfo = xc_map_foreign_range(xch, dom, PAGE_SIZE,
                                            PROT_READ, shared_info_frame);
         if ( !live_shinfo )
         {
@@ -957,7 +963,7 @@ int xc_domain_save(int xc_handle, int io
     }
 
     /* Get the size of the P2M table */
-    dinfo->p2m_size = xc_memory_op(xc_handle, XENMEM_maximum_gpfn, &dom) + 1;
+    dinfo->p2m_size = xc_memory_op(xch, XENMEM_maximum_gpfn, &dom) + 1;
 
     if ( dinfo->p2m_size > ~XEN_DOMCTL_PFINFO_LTAB_MASK )
     {
@@ -969,17 +975,17 @@ int xc_domain_save(int xc_handle, int io
     if ( live )
     {
         /* Live suspend. Enable log-dirty mode. */
-        if ( xc_shadow_control(xc_handle, dom,
+        if ( xc_shadow_control(xch, dom,
                                XEN_DOMCTL_SHADOW_OP_ENABLE_LOGDIRTY,
                                NULL, 0, NULL, 0, NULL) < 0 )
         {
             /* log-dirty already enabled? There's no test op,
                so attempt to disable then reenable it */
-            frc = xc_shadow_control(xc_handle, dom, XEN_DOMCTL_SHADOW_OP_OFF,
+            frc = xc_shadow_control(xch, dom, XEN_DOMCTL_SHADOW_OP_OFF,
                                     NULL, 0, NULL, 0, NULL);
             if ( frc >= 0 )
             {
-                frc = xc_shadow_control(xc_handle, dom,
+                frc = xc_shadow_control(xch, dom,
                                         XEN_DOMCTL_SHADOW_OP_ENABLE_LOGDIRTY,
                                         NULL, 0, NULL, 0, NULL);
             }
@@ -998,7 +1004,7 @@ int xc_domain_save(int xc_handle, int io
     else
     {
         /* This is a non-live suspend. Suspend the domain .*/
-        if ( suspend_and_state(callbacks->suspend, callbacks->data, xc_handle,
+        if ( suspend_and_state(callbacks->suspend, callbacks->data, xch,
                                io_fd, dom, &info) )
         {
             ERROR("Domain appears not to have suspended");
@@ -1040,7 +1046,7 @@ int xc_domain_save(int xc_handle, int io
     if ( hvm ) 
     {
         /* Need another buffer for HVM context */
-        hvm_buf_size = xc_domain_hvm_getcontext(xc_handle, dom, 0, 0);
+        hvm_buf_size = xc_domain_hvm_getcontext(xch, dom, 0, 0);
         if ( hvm_buf_size == -1 )
         {
             ERROR("Couldn't get HVM context size from Xen");
@@ -1054,7 +1060,7 @@ int xc_domain_save(int xc_handle, int io
         }
     }
 
-    analysis_phase(xc_handle, dom, ctx, to_skip, 0);
+    analysis_phase(xch, dom, ctx, to_skip, 0);
 
     pfn_type   = xc_memalign(PAGE_SIZE, ROUNDUP(
                               MAX_BATCH_SIZE * sizeof(*pfn_type), PAGE_SHIFT));
@@ -1076,7 +1082,7 @@ int xc_domain_save(int xc_handle, int io
     }
 
     /* Setup the mfn_to_pfn table mapping */
-    if ( !(ctx->live_m2p = xc_map_m2p(xc_handle, ctx->max_mfn, PROT_READ, 
&ctx->m2p_mfn0)) )
+    if ( !(ctx->live_m2p = xc_map_m2p(xch, ctx->max_mfn, PROT_READ, 
&ctx->m2p_mfn0)) )
     {
         ERROR("Failed to map live M2P table");
         goto out;
@@ -1094,7 +1100,7 @@ int xc_domain_save(int xc_handle, int io
         int err = 0;
 
         /* Map the P2M table, and write the list of P2M frames */
-        ctx->live_p2m = map_and_save_p2m_table(xc_handle, io_fd, dom, ctx, 
live_shinfo);
+        ctx->live_p2m = map_and_save_p2m_table(xch, io_fd, dom, ctx, 
live_shinfo);
         if ( ctx->live_p2m == NULL )
         {
             ERROR("Failed to map/save the p2m frame list");
@@ -1118,57 +1124,55 @@ int xc_domain_save(int xc_handle, int io
         DPRINTF("Had %d unexplained entries in p2m table\n", err);
     }
 
-    print_stats(xc_handle, dom, 0, &stats, 0);
-
-    tmem_saved = xc_tmem_save(xc_handle, dom, io_fd, live, -5);
+    print_stats(xch, dom, 0, &stats, 0);
+
+    tmem_saved = xc_tmem_save(xch, dom, io_fd, live, -5);
     if ( tmem_saved == -1 )
     {
         ERROR("Error when writing to state file (tmem)");
         goto out;
     }
 
-    if ( !live && save_tsc_info(xc_handle, dom, io_fd) < 0 )
+    if ( !live && save_tsc_info(xch, dom, io_fd) < 0 )
     {
         ERROR("Error when writing to state file (tsc)");
         goto out;
     }
 
   copypages:
-#define wrexact(fd, buf, len) write_buffer(last_iter, &ob, (fd), (buf), (len))
+#define wrexact(fd, buf, len) write_buffer(xch, last_iter, &ob, (fd), (buf), 
(len))
 #ifdef ratewrite
 #undef ratewrite
 #endif
-#define ratewrite(fd, live, buf, len) ratewrite_buffer(last_iter, &ob, (fd), 
(live), (buf), (len))
+#define ratewrite(fd, live, buf, len) ratewrite_buffer(xch, last_iter, &ob, 
(fd), (live), (buf), (len))
 
     /* Now write out each data page, canonicalising page tables as we go... */
     for ( ; ; )
     {
-        unsigned int prev_pc, sent_this_iter, N, batch, run;
+        unsigned int N, batch, run;
+        char reportbuf[80];
+
+        snprintf(reportbuf, sizeof(reportbuf),
+                 "Saving memory: iter %d (last sent %u skipped %u)",
+                 iter, sent_this_iter, skip_this_iter);
+
+        xc_report_progress_start(xch, reportbuf, dinfo->p2m_size);
 
         iter++;
         sent_this_iter = 0;
         skip_this_iter = 0;
-        prev_pc = 0;
         N = 0;
 
-        DPRINTF("Saving memory pages: iter %d   0%%", iter);
-
         while ( N < dinfo->p2m_size )
         {
-            unsigned int this_pc = (N * 100) / dinfo->p2m_size;
-
-            if ( (this_pc - prev_pc) >= 5 )
-            {
-                DPRINTF("\b\b\b\b%3d%%", this_pc);
-                prev_pc = this_pc;
-            }
+            xc_report_progress_step(xch, N, dinfo->p2m_size);
 
             if ( !last_iter )
             {
                 /* Slightly wasteful to peek the whole array evey time,
                    but this is fast enough for the moment. */
                 frc = xc_shadow_control(
-                    xc_handle, dom, XEN_DOMCTL_SHADOW_OP_PEEK, to_skip, 
+                    xch, dom, XEN_DOMCTL_SHADOW_OP_PEEK, to_skip, 
                     dinfo->p2m_size, NULL, 0, NULL);
                 if ( frc != dinfo->p2m_size )
                 {
@@ -1275,7 +1279,7 @@ int xc_domain_save(int xc_handle, int io
                 goto skip; /* vanishingly unlikely... */
 
             region_base = xc_map_foreign_bulk(
-                xc_handle, dom, PROT_READ, pfn_type, pfn_err, batch);
+                xch, dom, PROT_READ, pfn_type, pfn_err, batch);
             if ( region_base == NULL )
             {
                 ERROR("map batch failed");
@@ -1303,7 +1307,7 @@ int xc_domain_save(int xc_handle, int io
             else
             {
                 /* Get page types */
-                if ( xc_get_pfn_type_batch(xc_handle, dom, batch, pfn_type) )
+                if ( xc_get_pfn_type_batch(xch, dom, batch, pfn_type) )
                 {
                     ERROR("get_pfn_type_batch failed");
                     goto out;
@@ -1437,12 +1441,9 @@ int xc_domain_save(int xc_handle, int io
 
         total_sent += sent_this_iter;
 
-        DPRINTF("\r %d: sent %d, skipped %d, ",
-                iter, sent_this_iter, skip_this_iter );
-
         if ( last_iter )
         {
-            print_stats( xc_handle, dom, sent_this_iter, &stats, 1);
+            print_stats( xch, dom, sent_this_iter, &stats, 1);
 
             DPRINTF("Total pages sent= %ld (%.2fx)\n",
                     total_sent, ((float)total_sent)/dinfo->p2m_size );
@@ -1480,7 +1481,7 @@ int xc_domain_save(int xc_handle, int io
                 last_iter = 1;
 
                 if ( suspend_and_state(callbacks->suspend, callbacks->data,
-                                       xc_handle, io_fd, dom, &info) )
+                                       xch, io_fd, dom, &info) )
                 {
                     ERROR("Domain appears not to have suspended");
                     goto out;
@@ -1488,13 +1489,13 @@ int xc_domain_save(int xc_handle, int io
 
                 DPRINTF("SUSPEND shinfo %08lx\n", info.shared_info_frame);
                 if ( (tmem_saved > 0) &&
-                     (xc_tmem_save_extra(xc_handle,dom,io_fd,-6) == -1) )
+                     (xc_tmem_save_extra(xch,dom,io_fd,-6) == -1) )
                 {
                         ERROR("Error when writing to state file (tmem)");
                         goto out;
                 }
 
-                if ( save_tsc_info(xc_handle, dom, io_fd) < 0 )
+                if ( save_tsc_info(xch, dom, io_fd) < 0 )
                 {
                     ERROR("Error when writing to state file (tsc)");
                     goto out;
@@ -1503,7 +1504,7 @@ int xc_domain_save(int xc_handle, int io
 
             }
 
-            if ( xc_shadow_control(xc_handle, dom, 
+            if ( xc_shadow_control(xch, dom, 
                                    XEN_DOMCTL_SHADOW_OP_CLEAN, to_send, 
                                    dinfo->p2m_size, NULL, 0, &stats) != 
dinfo->p2m_size )
             {
@@ -1513,7 +1514,7 @@ int xc_domain_save(int xc_handle, int io
 
             sent_last_iter = sent_this_iter;
 
-            print_stats(xc_handle, dom, sent_this_iter, &stats, 1);
+            print_stats(xch, dom, sent_this_iter, &stats, 1);
 
         }
     } /* end of infinite for loop */
@@ -1536,7 +1537,7 @@ int xc_domain_save(int xc_handle, int io
         for ( i = 1; i <= info.max_vcpu_id; i++ )
         {
             xc_vcpuinfo_t vinfo;
-            if ( (xc_vcpu_getinfo(xc_handle, dom, i, &vinfo) == 0) &&
+            if ( (xc_vcpu_getinfo(xch, dom, i, &vinfo) == 0) &&
                  vinfo.online )
                 vcpumap |= 1ULL << i;
         }
@@ -1558,7 +1559,7 @@ int xc_domain_save(int xc_handle, int io
         } chunk = { 0, };
 
         chunk.id = -3;
-        xc_get_hvm_param(xc_handle, dom, HVM_PARAM_IDENT_PT,
+        xc_get_hvm_param(xch, dom, HVM_PARAM_IDENT_PT,
                          (unsigned long *)&chunk.data);
 
         if ( (chunk.data != 0) &&
@@ -1569,7 +1570,7 @@ int xc_domain_save(int xc_handle, int io
         }
 
         chunk.id = -4;
-        xc_get_hvm_param(xc_handle, dom, HVM_PARAM_VM86_TSS,
+        xc_get_hvm_param(xch, dom, HVM_PARAM_VM86_TSS,
                          (unsigned long *)&chunk.data);
 
         if ( (chunk.data != 0) &&
@@ -1594,11 +1595,11 @@ int xc_domain_save(int xc_handle, int io
 
         /* Save magic-page locations. */
         memset(magic_pfns, 0, sizeof(magic_pfns));
-        xc_get_hvm_param(xc_handle, dom, HVM_PARAM_IOREQ_PFN,
+        xc_get_hvm_param(xch, dom, HVM_PARAM_IOREQ_PFN,
                          (unsigned long *)&magic_pfns[0]);
-        xc_get_hvm_param(xc_handle, dom, HVM_PARAM_BUFIOREQ_PFN,
+        xc_get_hvm_param(xch, dom, HVM_PARAM_BUFIOREQ_PFN,
                          (unsigned long *)&magic_pfns[1]);
-        xc_get_hvm_param(xc_handle, dom, HVM_PARAM_STORE_PFN,
+        xc_get_hvm_param(xch, dom, HVM_PARAM_STORE_PFN,
                          (unsigned long *)&magic_pfns[2]);
         if ( wrexact(io_fd, magic_pfns, sizeof(magic_pfns)) )
         {
@@ -1607,7 +1608,7 @@ int xc_domain_save(int xc_handle, int io
         }
 
         /* Get HVM context from Xen and save it too */
-        if ( (rec_size = xc_domain_hvm_getcontext(xc_handle, dom, hvm_buf, 
+        if ( (rec_size = xc_domain_hvm_getcontext(xch, dom, hvm_buf, 
                                                   hvm_buf_size)) == -1 )
         {
             ERROR("HVM:Could not get hvm buffer");
@@ -1668,7 +1669,7 @@ int xc_domain_save(int xc_handle, int io
         }
     }
 
-    if ( xc_vcpu_getcontext(xc_handle, dom, 0, &ctxt) )
+    if ( xc_vcpu_getcontext(xch, dom, 0, &ctxt) )
     {
         ERROR("Could not get vcpu context");
         goto out;
@@ -1688,7 +1689,7 @@ int xc_domain_save(int xc_handle, int io
         if ( !(vcpumap & (1ULL << i)) )
             continue;
 
-        if ( (i != 0) && xc_vcpu_getcontext(xc_handle, dom, i, &ctxt) )
+        if ( (i != 0) && xc_vcpu_getcontext(xch, dom, i, &ctxt) )
         {
             ERROR("No context for VCPU%d", i);
             goto out;
@@ -1740,7 +1741,7 @@ int xc_domain_save(int xc_handle, int io
         domctl.cmd = XEN_DOMCTL_get_ext_vcpucontext;
         domctl.domain = dom;
         domctl.u.ext_vcpucontext.vcpu = i;
-        if ( xc_domctl(xc_handle, &domctl) < 0 )
+        if ( xc_domctl(xch, &domctl) < 0 )
         {
             ERROR("No extended context for VCPU%d", i);
             goto out;
@@ -1781,32 +1782,32 @@ int xc_domain_save(int xc_handle, int io
         callbacks->postcopy(callbacks->data);
 
     /* Flush last write and discard cache for file. */
-    if ( outbuf_flush(&ob, io_fd) < 0 ) {
+    if ( outbuf_flush(xch, &ob, io_fd) < 0 ) {
         ERROR("Error when flushing output buffer\n");
         rc = 1;
     }
 
-    discard_file_cache(io_fd, 1 /* flush */);
+    discard_file_cache(xch, io_fd, 1 /* flush */);
 
     /* checkpoint_cb can spend arbitrarily long in between rounds */
     if (!rc && callbacks->checkpoint &&
         callbacks->checkpoint(callbacks->data) > 0)
     {
         /* reset stats timer */
-        print_stats(xc_handle, dom, 0, &stats, 0);
+        print_stats(xch, dom, 0, &stats, 0);
 
         rc = 1;
         /* last_iter = 1; */
-        if ( suspend_and_state(callbacks->suspend, callbacks->data, xc_handle,
+        if ( suspend_and_state(callbacks->suspend, callbacks->data, xch,
                                io_fd, dom, &info) )
         {
             ERROR("Domain appears not to have suspended");
             goto out;
         }
         DPRINTF("SUSPEND shinfo %08lx\n", info.shared_info_frame);
-        print_stats(xc_handle, dom, 0, &stats, 1);
-
-        if ( xc_shadow_control(xc_handle, dom,
+        print_stats(xch, dom, 0, &stats, 1);
+
+        if ( xc_shadow_control(xch, dom,
                                XEN_DOMCTL_SHADOW_OP_CLEAN, to_send,
                                dinfo->p2m_size, NULL, 0, &stats) != 
dinfo->p2m_size )
         {
@@ -1817,11 +1818,11 @@ int xc_domain_save(int xc_handle, int io
     }
 
     if ( tmem_saved != 0 && live )
-        xc_tmem_save_done(xc_handle, dom);
+        xc_tmem_save_done(xch, dom);
 
     if ( live )
     {
-        if ( xc_shadow_control(xc_handle, dom, 
+        if ( xc_shadow_control(xch, dom, 
                                XEN_DOMCTL_SHADOW_OP_OFF,
                                NULL, 0, NULL, 0, NULL) < 0 )
             DPRINTF("Warning - couldn't disable shadow mode");
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_evtchn.c
--- a/tools/libxc/xc_evtchn.c   Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_evtchn.c   Fri May 28 09:30:19 2010 +0100
@@ -9,7 +9,7 @@
 #include "xc_private.h"
 
 
-static int do_evtchn_op(int xc_handle, int cmd, void *arg,
+static int do_evtchn_op(xc_interface *xch, int cmd, void *arg,
                         size_t arg_size, int silently_fail)
 {
     int ret = -1;
@@ -25,7 +25,7 @@ static int do_evtchn_op(int xc_handle, i
         goto out;
     }
 
-    if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 && !silently_fail)
+    if ((ret = do_xen_hypercall(xch, &hypercall)) < 0 && !silently_fail)
         ERROR("do_evtchn_op: HYPERVISOR_event_channel_op failed: %d", ret);
 
     unlock_pages(arg, arg_size);
@@ -35,7 +35,7 @@ static int do_evtchn_op(int xc_handle, i
 
 
 evtchn_port_or_error_t
-xc_evtchn_alloc_unbound(int xc_handle,
+xc_evtchn_alloc_unbound(xc_interface *xch,
                         uint32_t dom,
                         uint32_t remote_dom)
 {
@@ -45,22 +45,22 @@ xc_evtchn_alloc_unbound(int xc_handle,
         .remote_dom = (domid_t)remote_dom
     };
 
-    rc = do_evtchn_op(xc_handle, EVTCHNOP_alloc_unbound, &arg, sizeof(arg), 0);
+    rc = do_evtchn_op(xch, EVTCHNOP_alloc_unbound, &arg, sizeof(arg), 0);
     if ( rc == 0 )
         rc = arg.port;
 
     return rc;
 }
 
-int xc_evtchn_reset(int xc_handle,
+int xc_evtchn_reset(xc_interface *xch,
                     uint32_t dom)
 {
     struct evtchn_reset arg = { .dom = (domid_t)dom };
-    return do_evtchn_op(xc_handle, EVTCHNOP_reset, &arg, sizeof(arg), 0);
+    return do_evtchn_op(xch, EVTCHNOP_reset, &arg, sizeof(arg), 0);
 }
 
-int xc_evtchn_status(int xc_handle, xc_evtchn_status_t *status)
+int xc_evtchn_status(xc_interface *xch, xc_evtchn_status_t *status)
 {
-    return do_evtchn_op(xc_handle, EVTCHNOP_status, status,
+    return do_evtchn_op(xch, EVTCHNOP_status, status,
                         sizeof(*status), 1);
 }
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_flask.c
--- a/tools/libxc/xc_flask.c    Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_flask.c    Fri May 28 09:30:19 2010 +0100
@@ -9,7 +9,7 @@
 
 #include "xc_private.h"
 
-int xc_flask_op(int xc_handle, flask_op_t *op)
+int xc_flask_op(xc_interface *xch, flask_op_t *op)
 {
     int ret = -1;
     DECLARE_HYPERCALL;
@@ -23,7 +23,7 @@ int xc_flask_op(int xc_handle, flask_op_
         goto out;
     }
 
-    if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
+    if ( (ret = do_xen_hypercall(xch, &hypercall)) < 0 )
     {
         if ( errno == EACCES )
             fprintf(stderr, "XSM operation failed!\n");
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_hvm_build.c
--- a/tools/libxc/xc_hvm_build.c        Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_hvm_build.c        Fri May 28 09:30:19 2010 +0100
@@ -69,7 +69,8 @@ static void build_hvm_info(void *hvm_inf
 }
 
 static int loadelfimage(
-    struct elf_binary *elf, int xch, uint32_t dom, unsigned long *parray)
+    xc_interface *xch,
+    struct elf_binary *elf, uint32_t dom, unsigned long *parray)
 {
     privcmd_mmap_entry_t *entries = NULL;
     size_t pages = (elf->pend - elf->pstart + PAGE_SIZE - 1) >> PAGE_SHIFT;
@@ -115,7 +116,7 @@ static int check_mmio_hole(uint64_t star
         return 1;
 }
 
-static int setup_guest(int xc_handle,
+static int setup_guest(xc_interface *xch,
                        uint32_t dom, int memsize, int target,
                        char *image, unsigned long image_size)
 {
@@ -149,7 +150,7 @@ static int setup_guest(int xc_handle,
     v_start = 0;
     v_end = (unsigned long long)memsize << 20;
 
-    if ( xc_version(xc_handle, XENVER_capabilities, &caps) != 0 )
+    if ( xc_version(xch, XENVER_capabilities, &caps) != 0 )
     {
         PERROR("Could not get Xen capabilities\n");
         goto error_out;
@@ -191,7 +192,7 @@ static int setup_guest(int xc_handle,
      * ensure that we can be preempted and hence dom0 remains responsive.
      */
     rc = xc_domain_memory_populate_physmap(
-        xc_handle, dom, 0xa0, 0, 0, &page_array[0x00]);
+        xch, dom, 0xa0, 0, 0, &page_array[0x00]);
     cur_pages = 0xc0;
     stat_normal_pages = 0xc0;
     while ( (rc == 0) && (nr_pages > cur_pages) )
@@ -233,7 +234,7 @@ static int setup_guest(int xc_handle,
             set_xen_guest_handle(sp_req.extent_start, sp_extents);
             for ( i = 0; i < sp_req.nr_extents; i++ )
                 sp_extents[i] = page_array[cur_pages+(i<<SUPERPAGE_1GB_SHIFT)];
-            done = xc_memory_op(xc_handle, XENMEM_populate_physmap, &sp_req);
+            done = xc_memory_op(xch, XENMEM_populate_physmap, &sp_req);
             if ( done > 0 )
             {
                 stat_1gb_pages += done;
@@ -280,7 +281,7 @@ static int setup_guest(int xc_handle,
                 set_xen_guest_handle(sp_req.extent_start, sp_extents);
                 for ( i = 0; i < sp_req.nr_extents; i++ )
                     sp_extents[i] = 
page_array[cur_pages+(i<<SUPERPAGE_2MB_SHIFT)];
-                done = xc_memory_op(xc_handle, XENMEM_populate_physmap, 
&sp_req);
+                done = xc_memory_op(xch, XENMEM_populate_physmap, &sp_req);
                 if ( done > 0 )
                 {
                     stat_2mb_pages += done;
@@ -300,7 +301,7 @@ static int setup_guest(int xc_handle,
         if ( count != 0 )
         {
             rc = xc_domain_memory_populate_physmap(
-                xc_handle, dom, count, 0, 0, &page_array[cur_pages]);
+                xch, dom, count, 0, 0, &page_array[cur_pages]);
             cur_pages += count;
             stat_normal_pages += count;
             if ( pod_mode )
@@ -309,7 +310,7 @@ static int setup_guest(int xc_handle,
     }
 
     if ( pod_mode )
-        rc = xc_domain_memory_set_pod_target(xc_handle,
+        rc = xc_domain_memory_set_pod_target(xch,
                                              dom,
                                              pod_pages,
                                              NULL, NULL, NULL);
@@ -326,11 +327,11 @@ static int setup_guest(int xc_handle,
             "  1GB PAGES: 0x%016lx\n",
             stat_normal_pages, stat_2mb_pages, stat_1gb_pages);
     
-    if ( loadelfimage(&elf, xc_handle, dom, page_array) != 0 )
+    if ( loadelfimage(xch, &elf, dom, page_array) != 0 )
         goto error_out;
 
     if ( (hvm_info_page = xc_map_foreign_range(
-              xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
+              xch, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
               HVM_INFO_PFN)) == NULL )
         goto error_out;
     build_hvm_info(hvm_info_page, v_end);
@@ -341,9 +342,9 @@ static int setup_guest(int xc_handle,
     xatp.space = XENMAPSPACE_shared_info;
     xatp.idx   = 0;
     xatp.gpfn  = special_pfn(SPECIALPAGE_SHINFO);
-    if ( (xc_memory_op(xc_handle, XENMEM_add_to_physmap, &xatp) != 0) ||
+    if ( (xc_memory_op(xch, XENMEM_add_to_physmap, &xatp) != 0) ||
          ((shared_info = xc_map_foreign_range(
-             xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
+             xch, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
              special_pfn(SPECIALPAGE_SHINFO))) == NULL) )
         goto error_out;
     memset(shared_info, 0, PAGE_SIZE);
@@ -358,21 +359,21 @@ static int setup_guest(int xc_handle,
         xen_pfn_t pfn = special_pfn(i);
         if ( i == SPECIALPAGE_SHINFO )
             continue;
-        rc = xc_domain_memory_populate_physmap(xc_handle, dom, 1, 0, 0, &pfn);
+        rc = xc_domain_memory_populate_physmap(xch, dom, 1, 0, 0, &pfn);
         if ( rc != 0 )
         {
             PERROR("Could not allocate %d'th special page.\n", i);
             goto error_out;
         }
-        if ( xc_clear_domain_page(xc_handle, dom, special_pfn(i)) )
+        if ( xc_clear_domain_page(xch, dom, special_pfn(i)) )
             goto error_out;
     }
 
-    xc_set_hvm_param(xc_handle, dom, HVM_PARAM_STORE_PFN,
+    xc_set_hvm_param(xch, dom, HVM_PARAM_STORE_PFN,
                      special_pfn(SPECIALPAGE_XENSTORE));
-    xc_set_hvm_param(xc_handle, dom, HVM_PARAM_BUFIOREQ_PFN,
+    xc_set_hvm_param(xch, dom, HVM_PARAM_BUFIOREQ_PFN,
                      special_pfn(SPECIALPAGE_BUFIOREQ));
-    xc_set_hvm_param(xc_handle, dom, HVM_PARAM_IOREQ_PFN,
+    xc_set_hvm_param(xch, dom, HVM_PARAM_IOREQ_PFN,
                      special_pfn(SPECIALPAGE_IOREQ));
 
     /*
@@ -380,14 +381,14 @@ static int setup_guest(int xc_handle,
      * using Intel EPT. Create a 32-bit non-PAE page directory of superpages.
      */
     if ( (ident_pt = xc_map_foreign_range(
-              xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
+              xch, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
               special_pfn(SPECIALPAGE_IDENT_PT))) == NULL )
         goto error_out;
     for ( i = 0; i < PAGE_SIZE / sizeof(*ident_pt); i++ )
         ident_pt[i] = ((i << 22) | _PAGE_PRESENT | _PAGE_RW | _PAGE_USER |
                        _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_PSE);
     munmap(ident_pt, PAGE_SIZE);
-    xc_set_hvm_param(xc_handle, dom, HVM_PARAM_IDENT_PT,
+    xc_set_hvm_param(xch, dom, HVM_PARAM_IDENT_PT,
                      special_pfn(SPECIALPAGE_IDENT_PT) << PAGE_SHIFT);
 
     /* Insert JMP <rel32> instruction at address 0x0 to reach entry point. */
@@ -395,7 +396,7 @@ static int setup_guest(int xc_handle,
     if ( entry_eip != 0 )
     {
         char *page0 = xc_map_foreign_range(
-            xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE, 0);
+            xch, dom, PAGE_SIZE, PROT_READ | PROT_WRITE, 0);
         if ( page0 == NULL )
             goto error_out;
         page0[0] = 0xe9;
@@ -411,7 +412,7 @@ static int setup_guest(int xc_handle,
     return -1;
 }
 
-static int xc_hvm_build_internal(int xc_handle,
+static int xc_hvm_build_internal(xc_interface *xch,
                                  uint32_t domid,
                                  int memsize,
                                  int target,
@@ -424,13 +425,13 @@ static int xc_hvm_build_internal(int xc_
         return -1;
     }
 
-    return setup_guest(xc_handle, domid, memsize, target, image, image_size);
+    return setup_guest(xch, domid, memsize, target, image, image_size);
 }
 
 /* xc_hvm_build:
  * Create a domain for a virtualized Linux, using files/filenames.
  */
-int xc_hvm_build(int xc_handle,
+int xc_hvm_build(xc_interface *xch,
                  uint32_t domid,
                  int memsize,
                  const char *image_name)
@@ -440,10 +441,10 @@ int xc_hvm_build(int xc_handle,
     unsigned long image_size;
 
     if ( (image_name == NULL) ||
-         ((image = xc_read_image(image_name, &image_size)) == NULL) )
+         ((image = xc_read_image(xch, image_name, &image_size)) == NULL) )
         return -1;
 
-    sts = xc_hvm_build_internal(xc_handle, domid, memsize, memsize, image, 
image_size);
+    sts = xc_hvm_build_internal(xch, domid, memsize, memsize, image, 
image_size);
 
     free(image);
 
@@ -456,7 +457,7 @@ int xc_hvm_build(int xc_handle,
  * memsize pages marked populate-on-demand, and with a PoD cache size
  * of target.  If target == memsize, pages are populated normally.
  */
-int xc_hvm_build_target_mem(int xc_handle,
+int xc_hvm_build_target_mem(xc_interface *xch,
                            uint32_t domid,
                            int memsize,
                            int target,
@@ -467,10 +468,10 @@ int xc_hvm_build_target_mem(int xc_handl
     unsigned long image_size;
 
     if ( (image_name == NULL) ||
-         ((image = xc_read_image(image_name, &image_size)) == NULL) )
+         ((image = xc_read_image(xch, image_name, &image_size)) == NULL) )
         return -1;
 
-    sts = xc_hvm_build_internal(xc_handle, domid, memsize, target, image, 
image_size);
+    sts = xc_hvm_build_internal(xch, domid, memsize, target, image, 
image_size);
 
     free(image);
 
@@ -480,7 +481,7 @@ int xc_hvm_build_target_mem(int xc_handl
 /* xc_hvm_build_mem:
  * Create a domain for a virtualized Linux, using memory buffers.
  */
-int xc_hvm_build_mem(int xc_handle,
+int xc_hvm_build_mem(xc_interface *xch,
                      uint32_t domid,
                      int memsize,
                      const char *image_buffer,
@@ -498,14 +499,14 @@ int xc_hvm_build_mem(int xc_handle,
         return -1;
     }
 
-    img = xc_inflate_buffer(image_buffer, image_size, &img_len);
+    img = xc_inflate_buffer(xch, image_buffer, image_size, &img_len);
     if ( img == NULL )
     {
         ERROR("unable to inflate ram disk buffer");
         return -1;
     }
 
-    sts = xc_hvm_build_internal(xc_handle, domid, memsize, memsize,
+    sts = xc_hvm_build_internal(xch, domid, memsize, memsize,
                                 img, img_len);
 
     /* xc_inflate_buffer may return the original buffer pointer (for
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_linux.c
--- a/tools/libxc/xc_linux.c    Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_linux.c    Fri May 28 09:30:19 2010 +0100
@@ -20,7 +20,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-int xc_interface_open(void)
+int xc_interface_open_core(xc_interface *xch)
 {
     int flags, saved_errno;
     int fd = open("/proc/xen/privcmd", O_RDWR);
@@ -59,12 +59,12 @@ int xc_interface_open(void)
     return -1;
 }
 
-int xc_interface_close(int xc_handle)
-{
-    return close(xc_handle);
-}
-
-static int xc_map_foreign_batch_single(int xc_handle, uint32_t dom,
+int xc_interface_close_core(xc_interface *xch, int fd)
+{
+    return close(fd);
+}
+
+static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom,
                                        xen_pfn_t *mfn, unsigned long addr)
 {
     privcmd_mmapbatch_t ioctlx;
@@ -79,24 +79,24 @@ static int xc_map_foreign_batch_single(i
     {
         *mfn ^= XEN_DOMCTL_PFINFO_PAGEDTAB;
         usleep(100);
-        rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+        rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
     }
     while ( (rc < 0) && (errno == ENOENT) );
 
     return rc;
 }
 
-void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
+void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
                            xen_pfn_t *arr, int num)
 {
     privcmd_mmapbatch_t ioctlx;
     void *addr;
     int rc;
 
-    addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, xc_handle, 0);
+    addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, xch->fd, 0);
     if ( addr == MAP_FAILED )
     {
-        perror("xc_map_foreign_batch: mmap failed");
+        PERROR("xc_map_foreign_batch: mmap failed");
         return NULL;
     }
 
@@ -105,7 +105,7 @@ void *xc_map_foreign_batch(int xc_handle
     ioctlx.addr = (unsigned long)addr;
     ioctlx.arr = arr;
 
-    rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+    rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
     if ( (rc < 0) && (errno == ENOENT) )
     {
         int i;
@@ -116,7 +116,7 @@ void *xc_map_foreign_batch(int xc_handle
                  XEN_DOMCTL_PFINFO_PAGEDTAB )
             {
                 unsigned long paged_addr = (unsigned long)addr + (i << 
PAGE_SHIFT);
-                rc = xc_map_foreign_batch_single(xc_handle, dom, &arr[i],
+                rc = xc_map_foreign_batch_single(xch, dom, &arr[i],
                                                  paged_addr);
                 if ( rc < 0 )
                     goto out;
@@ -128,7 +128,7 @@ void *xc_map_foreign_batch(int xc_handle
     if ( rc < 0 )
     {
         int saved_errno = errno;
-        perror("xc_map_foreign_batch: ioctl failed");
+        PERROR("xc_map_foreign_batch: ioctl failed");
         (void)munmap(addr, num << PAGE_SHIFT);
         errno = saved_errno;
         return NULL;
@@ -137,7 +137,7 @@ void *xc_map_foreign_batch(int xc_handle
     return addr;
 }
 
-void *xc_map_foreign_bulk(int xc_handle, 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)
 {
     privcmd_mmapbatch_v2_t ioctlx;
@@ -146,10 +146,10 @@ void *xc_map_foreign_bulk(int xc_handle,
     int rc;
 
     addr = mmap(NULL, (unsigned long)num << PAGE_SHIFT, prot, MAP_SHARED,
-                xc_handle, 0);
+                xch->fd, 0);
     if ( addr == MAP_FAILED )
     {
-        perror("xc_map_foreign_batch: mmap failed");
+        PERROR("xc_map_foreign_batch: mmap failed");
         return NULL;
     }
 
@@ -159,7 +159,7 @@ void *xc_map_foreign_bulk(int xc_handle,
     ioctlx.arr = arr;
     ioctlx.err = err;
 
-    rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
+    rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
 
     if ( rc < 0 && errno == ENOENT )
     {
@@ -175,7 +175,7 @@ void *xc_map_foreign_bulk(int xc_handle,
             ioctlx.err = err + i;
             do {
                 usleep(100);
-                rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
+                rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
             } while ( rc < 0 && err[i] == -ENOENT );
         }
     }
@@ -199,7 +199,7 @@ void *xc_map_foreign_bulk(int xc_handle,
             ioctlx.addr = (unsigned long)addr;
             ioctlx.arr = pfn;
 
-            rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+            rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
 
             rc = rc < 0 ? -errno : 0;
 
@@ -219,7 +219,7 @@ void *xc_map_foreign_bulk(int xc_handle,
                         err[i] = rc ?: -EINVAL;
                         continue;
                     }
-                    rc = xc_map_foreign_batch_single(xc_handle, dom, pfn + i,
+                    rc = xc_map_foreign_batch_single(xch, dom, pfn + i,
                         (unsigned long)addr + ((unsigned long)i<<PAGE_SHIFT));
                     if ( rc < 0 )
                     {
@@ -253,7 +253,7 @@ void *xc_map_foreign_bulk(int xc_handle,
     {
         int saved_errno = errno;
 
-        perror("xc_map_foreign_bulk: ioctl failed");
+        PERROR("xc_map_foreign_bulk: ioctl failed");
         (void)munmap(addr, (unsigned long)num << PAGE_SHIFT);
         errno = saved_errno;
         return NULL;
@@ -262,7 +262,7 @@ void *xc_map_foreign_bulk(int xc_handle,
     return addr;
 }
 
-void *xc_map_foreign_range(int xc_handle, uint32_t dom, int size, int prot,
+void *xc_map_foreign_range(xc_interface *xch, uint32_t dom, int size, int prot,
                            unsigned long mfn)
 {
     xen_pfn_t *arr;
@@ -276,12 +276,12 @@ void *xc_map_foreign_range(int xc_handle
     for ( i = 0; i < num; i++ )
         arr[i] = mfn + i;
 
-    ret = xc_map_foreign_pages(xc_handle, dom, prot, arr, num);
+    ret = xc_map_foreign_pages(xch, dom, prot, arr, num);
     free(arr);
     return ret;
 }
 
-void *xc_map_foreign_ranges(int xc_handle, uint32_t dom, size_t size, int prot,
+void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom, size_t size, int 
prot,
                             size_t chunksize, privcmd_mmap_entry_t entries[],
                             int nentries)
 {
@@ -300,19 +300,19 @@ void *xc_map_foreign_ranges(int xc_handl
         for ( j = 0; j < num_per_entry; j++ )
             arr[i * num_per_entry + j] = entries[i].mfn + j;
 
-    ret = xc_map_foreign_pages(xc_handle, dom, prot, arr, num);
+    ret = xc_map_foreign_pages(xch, dom, prot, arr, num);
     free(arr);
     return ret;
 }
 
-static int do_privcmd(int xc_handle, unsigned int cmd, unsigned long data)
-{
-    return ioctl(xc_handle, cmd, data);
-}
-
-int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall)
-{
-    return do_privcmd(xc_handle, IOCTL_PRIVCMD_HYPERCALL,
+static int do_privcmd(xc_interface *xch, int cmd, unsigned long data)
+{
+    return ioctl(xch->fd, cmd, data);
+}
+
+int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
+{
+    return do_privcmd(xch, IOCTL_PRIVCMD_HYPERCALL,
                       (unsigned long)hypercall);
 }
 
@@ -401,7 +401,6 @@ int xc_evtchn_open(void)
              (mknod(EVTCHN_DEV_NAME, S_IFCHR|0600, devnum) == 0) )
             goto reopen;
 
-        PERROR("Could not open event channel interface");
         return -1;
     }
 
@@ -485,7 +484,7 @@ int xc_evtchn_unmask(int xce_handle, evt
 }
 
 /* Optionally flush file to disk and discard page cache */
-void discard_file_cache(int fd, int flush) 
+void discard_file_cache(xc_interface *xch, int fd, int flush) 
 {
     off_t cur = 0;
     int saved_errno = errno;
@@ -521,7 +520,7 @@ void discard_file_cache(int fd, int flus
 
 #define GNTTAB_DEV_NAME "/dev/xen/gntdev"
 
-int xc_gnttab_open(void)
+int xc_gnttab_open(xc_interface *xch)
 {
     struct stat st;
     int fd;
@@ -549,13 +548,13 @@ reopen:
     return fd;
 }
 
-int xc_gnttab_close(int xcg_handle)
+int xc_gnttab_close(xc_interface *xch, int xcg_handle)
 {
     return close(xcg_handle);
 }
 
-void *xc_gnttab_map_grant_ref(int xcg_handle, uint32_t domid, uint32_t ref,
-                              int prot)
+void *xc_gnttab_map_grant_ref(xc_interface *xch, int xcg_handle,
+                              uint32_t domid, uint32_t ref, int prot)
 {
     struct ioctl_gntdev_map_grant_ref map;
     void *addr;
@@ -564,8 +563,10 @@ void *xc_gnttab_map_grant_ref(int xcg_ha
     map.refs[0].domid = domid;
     map.refs[0].ref = ref;
 
-    if ( ioctl(xcg_handle, IOCTL_GNTDEV_MAP_GRANT_REF, &map) )
-        return NULL;
+    if ( ioctl(xcg_handle, IOCTL_GNTDEV_MAP_GRANT_REF, &map) ) {
+        PERROR("xc_gnttab_map_grant_ref: ioctl MAP_GRANT_REF failed");
+        return NULL;
+    }
 
 mmap_again:    
     addr = mmap(NULL, PAGE_SIZE, prot, MAP_SHARED, xcg_handle, map.index);
@@ -580,7 +581,7 @@ mmap_again:
             goto mmap_again;
         }
          /* Unmap the driver slots used to store the grant information. */
-        perror("xc_gnttab_map_grant_ref: mmap failed");
+        PERROR("xc_gnttab_map_grant_ref: mmap failed");
         unmap_grant.index = map.index;
         unmap_grant.count = 1;
         ioctl(xcg_handle, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant);
@@ -591,7 +592,8 @@ mmap_again:
     return addr;
 }
 
-static void *do_gnttab_map_grant_refs(int xcg_handle, uint32_t count,
+static void *do_gnttab_map_grant_refs(xc_interface *xch,
+                                      int xcg_handle, uint32_t count,
                                       uint32_t *domids, int domids_stride,
                                       uint32_t *refs, int prot)
 {
@@ -612,8 +614,10 @@ static void *do_gnttab_map_grant_refs(in
 
     map->count = count;
 
-    if ( ioctl(xcg_handle, IOCTL_GNTDEV_MAP_GRANT_REF, map) )
+    if ( ioctl(xcg_handle, IOCTL_GNTDEV_MAP_GRANT_REF, map) ) {
+        PERROR("xc_gnttab_map_grant_refs: ioctl MAP_GRANT_REF failed");
         goto out;
+    }
 
     addr = mmap(NULL, PAGE_SIZE * count, prot, MAP_SHARED, xcg_handle,
                 map->index);
@@ -623,7 +627,7 @@ static void *do_gnttab_map_grant_refs(in
         struct ioctl_gntdev_unmap_grant_ref unmap_grant;
 
         /* Unmap the driver slots used to store the grant information. */
-        perror("xc_gnttab_map_grant_refs: mmap failed");
+        PERROR("xc_gnttab_map_grant_refs: mmap failed");
         unmap_grant.index = map->index;
         unmap_grant.count = count;
         ioctl(xcg_handle, IOCTL_GNTDEV_UNMAP_GRANT_REF, &unmap_grant);
@@ -637,19 +641,22 @@ static void *do_gnttab_map_grant_refs(in
     return addr;
 }
 
-void *xc_gnttab_map_grant_refs(int xcg_handle, uint32_t count, uint32_t 
*domids,
+void *xc_gnttab_map_grant_refs(xc_interface *xch,
+                               int xcg_handle, uint32_t count, uint32_t 
*domids,
                                uint32_t *refs, int prot)
 {
-    return do_gnttab_map_grant_refs(xcg_handle, count, domids, 1, refs, prot);
-}
-
-void *xc_gnttab_map_domain_grant_refs(int xcg_handle, uint32_t count,
+    return do_gnttab_map_grant_refs(xch, xcg_handle, count, domids, 1, refs, 
prot);
+}
+
+void *xc_gnttab_map_domain_grant_refs(xc_interface *xch,
+                                      int xcg_handle, uint32_t count,
                                       uint32_t domid, uint32_t *refs, int prot)
 {
-    return do_gnttab_map_grant_refs(xcg_handle, count, &domid, 0, refs, prot);
-}
-
-int xc_gnttab_munmap(int xcg_handle, void *start_address, uint32_t count)
+    return do_gnttab_map_grant_refs(xch, xcg_handle, count, &domid, 0, refs, 
prot);
+}
+
+int xc_gnttab_munmap(xc_interface *xch,
+                     int xcg_handle, void *start_address, uint32_t count)
 {
     struct ioctl_gntdev_get_offset_for_vaddr get_offset;
     struct ioctl_gntdev_unmap_grant_ref unmap_grant;
@@ -688,7 +695,8 @@ int xc_gnttab_munmap(int xcg_handle, voi
     return 0;
 }
 
-int xc_gnttab_set_max_grants(int xcg_handle, uint32_t count)
+int xc_gnttab_set_max_grants(xc_interface *xch,
+                             int xcg_handle, uint32_t count)
 {
     struct ioctl_gntdev_set_max_grants set_max;
     int rc;
@@ -700,7 +708,7 @@ int xc_gnttab_set_max_grants(int xcg_han
     return 0;
 }
 
-int xc_gnttab_op(int xc_handle, int cmd, void * op, int op_size, int count)
+int xc_gnttab_op(xc_interface *xch, int cmd, void * op, int op_size, int count)
 {
     int ret = 0;
     DECLARE_HYPERCALL;
@@ -716,7 +724,7 @@ int xc_gnttab_op(int xc_handle, int cmd,
         goto out1;
     }
 
-    ret = do_xen_hypercall(xc_handle, &hypercall);
+    ret = do_xen_hypercall(xch, &hypercall);
 
     unlock_pages(op, count * op_size);
 
@@ -724,13 +732,13 @@ int xc_gnttab_op(int xc_handle, int cmd,
     return ret;
 }
 
-int xc_gnttab_get_version(int xc_handle, int domid)
+int xc_gnttab_get_version(xc_interface *xch, int domid)
 {
     struct gnttab_get_version query;
     int rc;
 
     query.dom = domid;
-    rc = xc_gnttab_op(xc_handle, GNTTABOP_get_version, &query, sizeof(query),
+    rc = xc_gnttab_op(xch, GNTTABOP_get_version, &query, sizeof(query),
                       1);
     if ( rc < 0 )
         return rc;
@@ -738,7 +746,7 @@ int xc_gnttab_get_version(int xc_handle,
         return query.version;
 }
 
-static void *_gnttab_map_table(int xc_handle, int domid, int *gnt_num)
+static void *_gnttab_map_table(xc_interface *xch, int domid, int *gnt_num)
 {
     int rc, i;
     struct gnttab_query_size query;
@@ -751,7 +759,7 @@ static void *_gnttab_map_table(int xc_ha
         return NULL;
 
     query.dom = domid;
-    rc = xc_gnttab_op(xc_handle, GNTTABOP_query_size, &query, sizeof(query), 
1);
+    rc = xc_gnttab_op(xch, GNTTABOP_query_size, &query, sizeof(query), 1);
 
     if ( rc || (query.status != GNTST_okay) )
     {
@@ -783,7 +791,7 @@ static void *_gnttab_map_table(int xc_ha
     set_xen_guest_handle(setup.frame_list, frame_list);
 
     /* XXX Any race with other setup_table hypercall? */
-    rc = xc_gnttab_op(xc_handle, GNTTABOP_setup_table, &setup, sizeof(setup),
+    rc = xc_gnttab_op(xch, GNTTABOP_setup_table, &setup, sizeof(setup),
                       1);
 
     if ( rc || (setup.status != GNTST_okay) )
@@ -795,7 +803,7 @@ static void *_gnttab_map_table(int xc_ha
     for ( i = 0; i < setup.nr_frames; i++ )
         pfn_list[i] = frame_list[i];
 
-    gnt = xc_map_foreign_pages(xc_handle, domid, PROT_READ, pfn_list,
+    gnt = xc_map_foreign_pages(xch, domid, PROT_READ, pfn_list,
                                setup.nr_frames);
     if ( !gnt )
     {
@@ -815,20 +823,20 @@ err:
     return gnt;
 }
 
-grant_entry_v1_t *xc_gnttab_map_table_v1(int xc_handle, int domid,
+grant_entry_v1_t *xc_gnttab_map_table_v1(xc_interface *xch, int domid,
                                          int *gnt_num)
 {
-    if (xc_gnttab_get_version(xc_handle, domid) == 2)
-        return NULL;
-    return _gnttab_map_table(xc_handle, domid, gnt_num);
-}
-
-grant_entry_v2_t *xc_gnttab_map_table_v2(int xc_handle, int domid,
+    if (xc_gnttab_get_version(xch, domid) == 2)
+        return NULL;
+    return _gnttab_map_table(xch, domid, gnt_num);
+}
+
+grant_entry_v2_t *xc_gnttab_map_table_v2(xc_interface *xch, int domid,
                                          int *gnt_num)
 {
-    if (xc_gnttab_get_version(xc_handle, domid) != 2)
-        return NULL;
-    return _gnttab_map_table(xc_handle, domid, gnt_num);
+    if (xc_gnttab_get_version(xch, domid) != 2)
+        return NULL;
+    return _gnttab_map_table(xch, domid, gnt_num);
 }
 
 /*
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_mem_event.c
--- a/tools/libxc/xc_mem_event.c        Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_mem_event.c        Fri May 28 09:30:19 2010 +0100
@@ -23,7 +23,7 @@
 
 #include "xc_private.h"
 
-int xc_mem_event_control(int xc_handle, domid_t domain_id, unsigned int op,
+int xc_mem_event_control(xc_interface *xch, domid_t domain_id, unsigned int op,
                          unsigned int mode, void *shared_page,
                          void *ring_page, unsigned long gfn)
 {
@@ -39,20 +39,20 @@ int xc_mem_event_control(int xc_handle, 
 
     domctl.u.mem_event_op.gfn = gfn;
     
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
-int xc_mem_event_enable(int xc_handle, domid_t domain_id,
+int xc_mem_event_enable(xc_interface *xch, domid_t domain_id,
                         void *shared_page, void *ring_page)
 {
-    return xc_mem_event_control(xc_handle, domain_id,
+    return xc_mem_event_control(xch, domain_id,
                                 XEN_DOMCTL_MEM_EVENT_OP_ENABLE, 0,
                                 shared_page, ring_page, INVALID_MFN);
 }
 
-int xc_mem_event_disable(int xc_handle, domid_t domain_id)
+int xc_mem_event_disable(xc_interface *xch, domid_t domain_id)
 {
-    return xc_mem_event_control(xc_handle, domain_id,
+    return xc_mem_event_control(xch, domain_id,
                                 XEN_DOMCTL_MEM_EVENT_OP_DISABLE, 0,
                                 NULL, NULL, INVALID_MFN);
 }
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_mem_paging.c
--- a/tools/libxc/xc_mem_paging.c       Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_mem_paging.c       Fri May 28 09:30:19 2010 +0100
@@ -25,33 +25,33 @@
 #include "xc_private.h"
 
 
-int xc_mem_paging_nominate(int xc_handle, domid_t domain_id, unsigned long gfn)
+int xc_mem_paging_nominate(xc_interface *xch, domid_t domain_id, unsigned long 
gfn)
 {
-    return xc_mem_event_control(xc_handle, domain_id,
+    return xc_mem_event_control(xch, domain_id,
                                 XEN_DOMCTL_MEM_EVENT_OP_PAGING_NOMINATE,
                                 XEN_DOMCTL_MEM_EVENT_OP_PAGING, NULL, NULL,
                                 gfn);
 }
 
-int xc_mem_paging_evict(int xc_handle, domid_t domain_id, unsigned long gfn)
+int xc_mem_paging_evict(xc_interface *xch, domid_t domain_id, unsigned long 
gfn)
 {
-    return xc_mem_event_control(xc_handle, domain_id,
+    return xc_mem_event_control(xch, domain_id,
                                 XEN_DOMCTL_MEM_EVENT_OP_PAGING_EVICT,
                                 XEN_DOMCTL_MEM_EVENT_OP_PAGING, NULL, NULL,
                                 gfn);
 }
 
-int xc_mem_paging_prep(int xc_handle, domid_t domain_id, unsigned long gfn)
+int xc_mem_paging_prep(xc_interface *xch, domid_t domain_id, unsigned long gfn)
 {
-    return xc_mem_event_control(xc_handle, domain_id,
+    return xc_mem_event_control(xch, domain_id,
                                 XEN_DOMCTL_MEM_EVENT_OP_PAGING_PREP,
                                 XEN_DOMCTL_MEM_EVENT_OP_PAGING, NULL, NULL,
                                 gfn);
 }
 
-int xc_mem_paging_resume(int xc_handle, domid_t domain_id, unsigned long gfn)
+int xc_mem_paging_resume(xc_interface *xch, domid_t domain_id, unsigned long 
gfn)
 {
-    return xc_mem_event_control(xc_handle, domain_id,
+    return xc_mem_event_control(xch, domain_id,
                                 XEN_DOMCTL_MEM_EVENT_OP_PAGING_RESUME,
                                 XEN_DOMCTL_MEM_EVENT_OP_PAGING, NULL, NULL,
                                 gfn);
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_memshr.c
--- a/tools/libxc/xc_memshr.c   Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_memshr.c   Fri May 28 09:30:19 2010 +0100
@@ -25,7 +25,7 @@
 #include <xen/memory.h>
 #include <xen/grant_table.h>
 
-int xc_memshr_control(int xc_handle,
+int xc_memshr_control(xc_interface *xch,
                       uint32_t domid,
                       int enable)
 {
@@ -39,10 +39,10 @@ int xc_memshr_control(int xc_handle,
     op->op = XEN_DOMCTL_MEM_SHARING_OP_CONTROL;
     op->u.enable = enable;
 
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
-int xc_memshr_nominate_gfn(int xc_handle,
+int xc_memshr_nominate_gfn(xc_interface *xch,
                            uint32_t domid,
                            unsigned long gfn,
                            uint64_t *handle)
@@ -58,13 +58,13 @@ int xc_memshr_nominate_gfn(int xc_handle
     op->op = XEN_DOMCTL_MEM_SHARING_OP_NOMINATE_GFN;
     op->u.nominate.u.gfn = gfn;
 
-    ret = do_domctl(xc_handle, &domctl);
+    ret = do_domctl(xch, &domctl);
     if(!ret) *handle = op->u.nominate.handle; 
 
     return ret;
 }
 
-int xc_memshr_nominate_gref(int xc_handle,
+int xc_memshr_nominate_gref(xc_interface *xch,
                             uint32_t domid,
                             grant_ref_t gref,
                             uint64_t *handle)
@@ -80,13 +80,13 @@ int xc_memshr_nominate_gref(int xc_handl
     op->op = XEN_DOMCTL_MEM_SHARING_OP_NOMINATE_GREF;
     op->u.nominate.u.grant_ref = gref;
 
-    ret = do_domctl(xc_handle, &domctl);
+    ret = do_domctl(xch, &domctl);
     if(!ret) *handle = op->u.nominate.handle; 
 
     return ret;
 }
 
-int xc_memshr_share(int xc_handle,
+int xc_memshr_share(xc_interface *xch,
                     uint64_t source_handle,
                     uint64_t client_handle)
 {
@@ -101,10 +101,10 @@ int xc_memshr_share(int xc_handle,
     op->u.share.source_handle = source_handle;
     op->u.share.client_handle = client_handle;
 
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
-int xc_memshr_domain_resume(int xc_handle,
+int xc_memshr_domain_resume(xc_interface *xch,
                             uint32_t domid)
 {
     DECLARE_DOMCTL;
@@ -116,10 +116,10 @@ int xc_memshr_domain_resume(int xc_handl
     op = &(domctl.u.mem_sharing_op);
     op->op = XEN_DOMCTL_MEM_SHARING_OP_RESUME;
 
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
-int xc_memshr_debug_gfn(int xc_handle,
+int xc_memshr_debug_gfn(xc_interface *xch,
                         uint32_t domid,
                         unsigned long gfn)
 {
@@ -133,10 +133,10 @@ int xc_memshr_debug_gfn(int xc_handle,
     op->op = XEN_DOMCTL_MEM_SHARING_OP_DEBUG_GFN;
     op->u.debug.u.gfn = gfn;
 
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
-int xc_memshr_debug_mfn(int xc_handle,
+int xc_memshr_debug_mfn(xc_interface *xch,
                         uint32_t domid,
                         unsigned long mfn)
 {
@@ -150,10 +150,10 @@ int xc_memshr_debug_mfn(int xc_handle,
     op->op = XEN_DOMCTL_MEM_SHARING_OP_DEBUG_MFN;
     op->u.debug.u.mfn = mfn;
 
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
-int xc_memshr_debug_gref(int xc_handle,
+int xc_memshr_debug_gref(xc_interface *xch,
                          uint32_t domid,
                          grant_ref_t gref)
 {
@@ -167,6 +167,6 @@ int xc_memshr_debug_gref(int xc_handle,
     op->op = XEN_DOMCTL_MEM_SHARING_OP_DEBUG_GREF;
     op->u.debug.u.gref = gref;
 
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_minios.c
--- a/tools/libxc/xc_minios.c   Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_minios.c   Fri May 28 09:30:19 2010 +0100
@@ -33,18 +33,18 @@
 
 extern struct wait_queue_head event_queue;
 
-int xc_interface_open(void)
+int xc_interface_open_core(xc_interface *xch)
 {
     return alloc_fd(FTYPE_XC);
 }
 
-int xc_interface_close(int xc_handle)
-{
-    files[xc_handle].type = FTYPE_NONE;
-    return 0;
-}
-
-void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
+int xc_interface_close_core(xc_interface *xch, int fd)
+{
+    files[fd].type = FTYPE_NONE;
+    return 0;
+}
+
+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;
@@ -59,7 +59,7 @@ void *xc_map_foreign_bulk(int xc_handle,
     return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);    
 }
 
-void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
+void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
                            xen_pfn_t *arr, int num)
 {
     unsigned long pt_prot = 0;
@@ -83,7 +83,7 @@ void *xc_map_foreign_batch(int xc_handle
     return (void *) addr;
 }
 
-void *xc_map_foreign_range(int xc_handle, uint32_t dom,
+void *xc_map_foreign_range(xc_interface *xch, uint32_t dom,
                            int size, int prot,
                            unsigned long mfn)
 {
@@ -100,7 +100,7 @@ void *xc_map_foreign_range(int xc_handle
     return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom, NULL, 
pt_prot);
 }
 
-void *xc_map_foreign_ranges(int xc_handle, uint32_t dom,
+void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom,
                             size_t size, int prot, size_t chunksize,
                             privcmd_mmap_entry_t entries[], int nentries)
 {
@@ -130,7 +130,7 @@ void *xc_map_foreign_ranges(int xc_handl
 }
 
 
-int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall)
+int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
 {
     multicall_entry_t call;
     int i, ret;
@@ -351,13 +351,13 @@ int xc_evtchn_unmask(int xce_handle, evt
 }
 
 /* Optionally flush file to disk and discard page cache */
-void discard_file_cache(int fd, int flush)
+void discard_file_cache(xc_interface *xch, int fd, int flush)
 {
     if (flush)
         fsync(fd);
 }
 
-int xc_gnttab_open(void)
+int xc_gnttab_open(xc_interface *xch)
 {
     int xcg_handle;
     xcg_handle = alloc_fd(FTYPE_GNTMAP);
@@ -365,14 +365,14 @@ int xc_gnttab_open(void)
     return xcg_handle;
 }
 
-int xc_gnttab_close(int xcg_handle)
+int xc_gnttab_close(xc_interface *xch, int xcg_handle)
 {
     gntmap_fini(&files[xcg_handle].gntmap);
     files[xcg_handle].type = FTYPE_NONE;
     return 0;
 }
 
-void *xc_gnttab_map_grant_ref(int xcg_handle,
+void *xc_gnttab_map_grant_ref(xc_interface *xch, int xcg_handle,
                               uint32_t domid,
                               uint32_t ref,
                               int prot)
@@ -384,7 +384,7 @@ void *xc_gnttab_map_grant_ref(int xcg_ha
                                  prot & PROT_WRITE);
 }
 
-void *xc_gnttab_map_grant_refs(int xcg_handle,
+void *xc_gnttab_map_grant_refs(xc_interface *xch, int xcg_handle,
                                uint32_t count,
                                uint32_t *domids,
                                uint32_t *refs,
@@ -397,7 +397,7 @@ void *xc_gnttab_map_grant_refs(int xcg_h
                                  prot & PROT_WRITE);
 }
 
-void *xc_gnttab_map_domain_grant_refs(int xcg_handle,
+void *xc_gnttab_map_domain_grant_refs(xc_interface *xch, int xcg_handle,
                                       uint32_t count,
                                       uint32_t domid,
                                       uint32_t *refs,
@@ -410,7 +410,7 @@ void *xc_gnttab_map_domain_grant_refs(in
                                  prot & PROT_WRITE);
 }
 
-int xc_gnttab_munmap(int xcg_handle,
+int xc_gnttab_munmap(xc_interface *xch, int xcg_handle,
                      void *start_address,
                      uint32_t count)
 {
@@ -425,7 +425,7 @@ int xc_gnttab_munmap(int xcg_handle,
     return ret;
 }
 
-int xc_gnttab_set_max_grants(int xcg_handle,
+int xc_gnttab_set_max_grants(xc_interface *xch, int xcg_handle,
                              uint32_t count)
 {
     int ret;
@@ -439,13 +439,13 @@ int xc_gnttab_set_max_grants(int xcg_han
 }
 
 grant_entry_v1_t *xc_gnttab_map_table_v1(
-    int xc_handle, int domid, int *gnt_num)
+    xc_interface *xch, int domid, int *gnt_num)
 {
     return NULL;
 }
 
 grant_entry_v2_t *xc_gnttab_map_table_v2(
-    int xc_handle, int domid, int *gnt_num)
+    xc_interface *xch, int domid, int *gnt_num)
 {
     return NULL;
 }
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_misc.c
--- a/tools/libxc/xc_misc.c     Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_misc.c     Fri May 28 09:30:19 2010 +0100
@@ -7,7 +7,7 @@
 #include "xc_private.h"
 #include <xen/hvm/hvm_op.h>
 
-int xc_readconsolering(int xc_handle,
+int xc_readconsolering(xc_interface *xch,
                        char **pbuffer,
                        unsigned int *pnr_chars,
                        int clear, int incremental, uint32_t *pindex)
@@ -31,7 +31,7 @@ int xc_readconsolering(int xc_handle,
     if ( (ret = lock_pages(buffer, nr_chars)) != 0 )
         return ret;
 
-    if ( (ret = do_sysctl(xc_handle, &sysctl)) == 0 )
+    if ( (ret = do_sysctl(xch, &sysctl)) == 0 )
     {
         *pnr_chars = sysctl.u.readconsole.count;
         if ( pindex )
@@ -43,7 +43,7 @@ int xc_readconsolering(int xc_handle,
     return ret;
 }
 
-int xc_send_debug_keys(int xc_handle, char *keys)
+int xc_send_debug_keys(xc_interface *xch, char *keys)
 {
     int ret, len = strlen(keys);
     DECLARE_SYSCTL;
@@ -55,14 +55,14 @@ int xc_send_debug_keys(int xc_handle, ch
     if ( (ret = lock_pages(keys, len)) != 0 )
         return ret;
 
-    ret = do_sysctl(xc_handle, &sysctl);
+    ret = do_sysctl(xch, &sysctl);
 
     unlock_pages(keys, len);
 
     return ret;
 }
 
-int xc_physinfo(int xc_handle,
+int xc_physinfo(xc_interface *xch,
                 xc_physinfo_t *put_info)
 {
     int ret;
@@ -72,7 +72,7 @@ int xc_physinfo(int xc_handle,
 
     memcpy(&sysctl.u.physinfo, put_info, sizeof(*put_info));
 
-    if ( (ret = do_sysctl(xc_handle, &sysctl)) != 0 )
+    if ( (ret = do_sysctl(xch, &sysctl)) != 0 )
         return ret;
 
     memcpy(put_info, &sysctl.u.physinfo, sizeof(*put_info));
@@ -80,7 +80,7 @@ int xc_physinfo(int xc_handle,
     return 0;
 }
 
-int xc_topologyinfo(int xc_handle,
+int xc_topologyinfo(xc_interface *xch,
                 xc_topologyinfo_t *put_info)
 {
     int ret;
@@ -90,7 +90,7 @@ int xc_topologyinfo(int xc_handle,
 
     memcpy(&sysctl.u.topologyinfo, put_info, sizeof(*put_info));
 
-    if ( (ret = do_sysctl(xc_handle, &sysctl)) != 0 )
+    if ( (ret = do_sysctl(xch, &sysctl)) != 0 )
         return ret;
 
     memcpy(put_info, &sysctl.u.topologyinfo, sizeof(*put_info));
@@ -98,7 +98,7 @@ int xc_topologyinfo(int xc_handle,
     return 0;
 }
 
-int xc_numainfo(int xc_handle,
+int xc_numainfo(xc_interface *xch,
                 xc_numainfo_t *put_info)
 {
     int ret;
@@ -108,7 +108,7 @@ int xc_numainfo(int xc_handle,
 
     memcpy(&sysctl.u.numainfo, put_info, sizeof(*put_info));
 
-    if ((ret = do_sysctl(xc_handle, &sysctl)) != 0)
+    if ((ret = do_sysctl(xch, &sysctl)) != 0)
         return ret;
 
     memcpy(put_info, &sysctl.u.numainfo, sizeof(*put_info));
@@ -117,7 +117,7 @@ int xc_numainfo(int xc_handle,
 }
 
 
-int xc_sched_id(int xc_handle,
+int xc_sched_id(xc_interface *xch,
                 int *sched_id)
 {
     int ret;
@@ -125,7 +125,7 @@ int xc_sched_id(int xc_handle,
 
     sysctl.cmd = XEN_SYSCTL_sched_id;
 
-    if ( (ret = do_sysctl(xc_handle, &sysctl)) != 0 )
+    if ( (ret = do_sysctl(xch, &sysctl)) != 0 )
         return ret;
 
     *sched_id = sysctl.u.sched_id.sched_id;
@@ -134,7 +134,7 @@ int xc_sched_id(int xc_handle,
 }
 
 #if defined(__i386__) || defined(__x86_64__)
-int xc_mca_op(int xc_handle, struct xen_mc *mc)
+int xc_mca_op(xc_interface *xch, struct xen_mc *mc)
 {
     int ret = 0;
     DECLARE_HYPERCALL;
@@ -148,13 +148,13 @@ int xc_mca_op(int xc_handle, struct xen_
 
     hypercall.op = __HYPERVISOR_mca;
     hypercall.arg[0] = (unsigned long)mc;
-    ret = do_xen_hypercall(xc_handle, &hypercall);
+    ret = do_xen_hypercall(xch, &hypercall);
     unlock_pages(mc, sizeof(mc));
     return ret;
 }
 #endif
 
-int xc_perfc_control(int xc_handle,
+int xc_perfc_control(xc_interface *xch,
                      uint32_t opcode,
                      xc_perfc_desc_t *desc,
                      xc_perfc_val_t *val,
@@ -169,7 +169,7 @@ int xc_perfc_control(int xc_handle,
     set_xen_guest_handle(sysctl.u.perfc_op.desc, desc);
     set_xen_guest_handle(sysctl.u.perfc_op.val, val);
 
-    rc = do_sysctl(xc_handle, &sysctl);
+    rc = do_sysctl(xch, &sysctl);
 
     if ( nbr_desc )
         *nbr_desc = sysctl.u.perfc_op.nr_counters;
@@ -179,7 +179,7 @@ int xc_perfc_control(int xc_handle,
     return rc;
 }
 
-int xc_lockprof_control(int xc_handle,
+int xc_lockprof_control(xc_interface *xch,
                         uint32_t opcode,
                         uint32_t *n_elems,
                         uint64_t *time,
@@ -193,7 +193,7 @@ int xc_lockprof_control(int xc_handle,
     sysctl.u.lockprof_op.max_elem = n_elems ? *n_elems : 0;
     set_xen_guest_handle(sysctl.u.lockprof_op.data, data);
 
-    rc = do_sysctl(xc_handle, &sysctl);
+    rc = do_sysctl(xch, &sysctl);
 
     if (n_elems)
         *n_elems = sysctl.u.lockprof_op.nr_elem;
@@ -203,7 +203,7 @@ int xc_lockprof_control(int xc_handle,
     return rc;
 }
 
-int xc_getcpuinfo(int xc_handle, int max_cpus,
+int xc_getcpuinfo(xc_interface *xch, int max_cpus,
                   xc_cpuinfo_t *info, int *nr_cpus)
 {
     int rc;
@@ -216,7 +216,7 @@ int xc_getcpuinfo(int xc_handle, int max
     if ( (rc = lock_pages(info, max_cpus*sizeof(*info))) != 0 )
         return rc;
 
-    rc = do_sysctl(xc_handle, &sysctl);
+    rc = do_sysctl(xch, &sysctl);
 
     unlock_pages(info, max_cpus*sizeof(*info));
 
@@ -228,7 +228,7 @@ int xc_getcpuinfo(int xc_handle, int max
 
 
 int xc_hvm_set_pci_intx_level(
-    int xc_handle, domid_t dom,
+    xc_interface *xch, domid_t dom,
     uint8_t domain, uint8_t bus, uint8_t device, uint8_t intx,
     unsigned int level)
 {
@@ -253,7 +253,7 @@ int xc_hvm_set_pci_intx_level(
     arg->intx   = intx;
     arg->level  = level;
 
-    rc = do_xen_hypercall(xc_handle, &hypercall);
+    rc = do_xen_hypercall(xch, &hypercall);
 
     hcall_buf_release((void **)&arg, sizeof(*arg));
 
@@ -261,7 +261,7 @@ int xc_hvm_set_pci_intx_level(
 }
 
 int xc_hvm_set_isa_irq_level(
-    int xc_handle, domid_t dom,
+    xc_interface *xch, domid_t dom,
     uint8_t isa_irq,
     unsigned int level)
 {
@@ -283,7 +283,7 @@ int xc_hvm_set_isa_irq_level(
     arg->isa_irq = isa_irq;
     arg->level   = level;
 
-    rc = do_xen_hypercall(xc_handle, &hypercall);
+    rc = do_xen_hypercall(xch, &hypercall);
 
     hcall_buf_release((void **)&arg, sizeof(*arg));
 
@@ -291,7 +291,7 @@ int xc_hvm_set_isa_irq_level(
 }
 
 int xc_hvm_set_pci_link_route(
-    int xc_handle, domid_t dom, uint8_t link, uint8_t isa_irq)
+    xc_interface *xch, domid_t dom, uint8_t link, uint8_t isa_irq)
 {
     DECLARE_HYPERCALL;
     struct xen_hvm_set_pci_link_route arg;
@@ -311,7 +311,7 @@ int xc_hvm_set_pci_link_route(
         return rc;
     }
 
-    rc = do_xen_hypercall(xc_handle, &hypercall);
+    rc = do_xen_hypercall(xch, &hypercall);
 
     unlock_pages(&arg, sizeof(arg));
 
@@ -319,7 +319,7 @@ int xc_hvm_set_pci_link_route(
 }
 
 int xc_hvm_track_dirty_vram(
-    int xc_handle, domid_t dom,
+    xc_interface *xch, domid_t dom,
     uint64_t first_pfn, uint64_t nr,
     unsigned long *dirty_bitmap)
 {
@@ -342,7 +342,7 @@ int xc_hvm_track_dirty_vram(
         return rc;
     }
 
-    rc = do_xen_hypercall(xc_handle, &hypercall);
+    rc = do_xen_hypercall(xch, &hypercall);
 
     unlock_pages(&arg, sizeof(arg));
 
@@ -350,7 +350,7 @@ int xc_hvm_track_dirty_vram(
 }
 
 int xc_hvm_modified_memory(
-    int xc_handle, domid_t dom, uint64_t first_pfn, uint64_t nr)
+    xc_interface *xch, domid_t dom, uint64_t first_pfn, uint64_t nr)
 {
     DECLARE_HYPERCALL;
     struct xen_hvm_modified_memory arg;
@@ -370,7 +370,7 @@ int xc_hvm_modified_memory(
         return rc;
     }
 
-    rc = do_xen_hypercall(xc_handle, &hypercall);
+    rc = do_xen_hypercall(xch, &hypercall);
 
     unlock_pages(&arg, sizeof(arg));
 
@@ -378,7 +378,7 @@ int xc_hvm_modified_memory(
 }
 
 int xc_hvm_set_mem_type(
-    int xc_handle, domid_t dom, hvmmem_type_t mem_type, uint64_t first_pfn, 
uint64_t nr)
+    xc_interface *xch, domid_t dom, hvmmem_type_t mem_type, uint64_t 
first_pfn, uint64_t nr)
 {
     DECLARE_HYPERCALL;
     struct xen_hvm_set_mem_type arg;
@@ -399,7 +399,7 @@ int xc_hvm_set_mem_type(
         return rc;
     }
 
-    rc = do_xen_hypercall(xc_handle, &hypercall);
+    rc = do_xen_hypercall(xch, &hypercall);
 
     unlock_pages(&arg, sizeof(arg));
 
@@ -412,7 +412,7 @@ void *
 #ifdef __GNUC__
 __attribute__((__weak__))
 #endif
-xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
+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;
@@ -431,7 +431,7 @@ xc_map_foreign_bulk(int xc_handle, uint3
     }
 
     memcpy(pfn, arr, num * sizeof(*arr));
-    ret = xc_map_foreign_batch(xc_handle, dom, prot, pfn, num);
+    ret = xc_map_foreign_batch(xch, dom, prot, pfn, num);
 
     if (ret) {
         for (i = 0; i < num; ++i)
@@ -451,7 +451,7 @@ xc_map_foreign_bulk(int xc_handle, uint3
     return ret;
 }
 
-void *xc_map_foreign_pages(int xc_handle, uint32_t dom, int prot,
+void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
                            const xen_pfn_t *arr, int num)
 {
     void *res;
@@ -466,7 +466,7 @@ void *xc_map_foreign_pages(int xc_handle
     if (!err)
         return NULL;
 
-    res = xc_map_foreign_bulk(xc_handle, dom, prot, arr, err, num);
+    res = xc_map_foreign_bulk(xch, dom, prot, arr, err, num);
     if (res) {
         for (i = 0; i < num; i++) {
             if (err[i]) {
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_netbsd.c
--- a/tools/libxc/xc_netbsd.c   Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_netbsd.c   Fri May 28 09:30:19 2010 +0100
@@ -15,7 +15,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-int xc_interface_open(void)
+int xc_interface_open_core(xc_interface *xch)
 {
     int flags, saved_errno;
     int fd = open("/kern/xen/privcmd", O_RDWR);
@@ -51,19 +51,19 @@ int xc_interface_open(void)
     return -1;
 }
 
-int xc_interface_close(int xc_handle)
-{
-    return close(xc_handle);
-}
-
-void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
+int xc_interface_close(xc_interface *xch, int fd)
+{
+    return close(fd);
+}
+
+void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
                            xen_pfn_t *arr, int num)
 {
     privcmd_mmapbatch_t ioctlx;
     void *addr;
     addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_ANON | MAP_SHARED, -1, 0);
     if ( addr == MAP_FAILED ) {
-        perror("xc_map_foreign_batch: mmap failed");
+        PERROR("xc_map_foreign_batch: mmap failed");
         return NULL;
     }
 
@@ -71,10 +71,10 @@ void *xc_map_foreign_batch(int xc_handle
     ioctlx.dom=dom;
     ioctlx.addr=(unsigned long)addr;
     ioctlx.arr=arr;
-    if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
+    if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
     {
         int saved_errno = errno;
-        perror("xc_map_foreign_batch: ioctl failed");
+        PERROR("xc_map_foreign_batch: ioctl failed");
         (void)munmap(addr, num*PAGE_SIZE);
         errno = saved_errno;
         return NULL;
@@ -83,7 +83,7 @@ void *xc_map_foreign_batch(int xc_handle
 
 }
 
-void *xc_map_foreign_range(int xc_handle, uint32_t dom,
+void *xc_map_foreign_range(xc_interface *xch, uint32_t dom,
                            int size, int prot,
                            unsigned long mfn)
 {
@@ -92,7 +92,7 @@ void *xc_map_foreign_range(int xc_handle
     void *addr;
     addr = mmap(NULL, size, prot, MAP_ANON | MAP_SHARED, -1, 0);
     if ( addr == MAP_FAILED ) {
-        perror("xc_map_foreign_range: mmap failed");
+        PERROR("xc_map_foreign_range: mmap failed");
         return NULL;
     }
 
@@ -102,10 +102,10 @@ void *xc_map_foreign_range(int xc_handle
     entry.va=(unsigned long) addr;
     entry.mfn=mfn;
     entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
-    if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 )
+    if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 )
     {
         int saved_errno = errno;
-        perror("xc_map_foreign_range: ioctl failed");
+        PERROR("xc_map_foreign_range: ioctl failed");
         (void)munmap(addr, size);
         errno = saved_errno;
         return NULL;
@@ -113,7 +113,7 @@ void *xc_map_foreign_range(int xc_handle
     return addr;
 }
 
-void *xc_map_foreign_ranges(int xc_handle, uint32_t dom,
+void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom,
                             size_t size, int prot, size_t chunksize,
                             privcmd_mmap_entry_t entries[], int nentries)
 {
@@ -134,7 +134,7 @@ void *xc_map_foreign_ranges(int xc_handl
        ioctlx.dom   = dom;
        ioctlx.entry = entries;
 
-       rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx);
+       rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAP, &ioctlx);
        if (rc)
                goto ioctl_failed;
 
@@ -150,18 +150,18 @@ mmap_failed:
 }
 
 
-static int do_privcmd(int xc_handle, unsigned int cmd, unsigned long data)
-{
-    int err = ioctl(xc_handle, cmd, data);
+static int do_privcmd(xc_interface *xch, unsigned int cmd, unsigned long data)
+{
+    int err = ioctl(xch->fd, cmd, data);
     if (err == 0)
        return 0;
     else
        return -errno;
 }
 
-int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall)
-{
-    int error = do_privcmd(xc_handle,
+int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
+{
+    int error = do_privcmd(xch,
                       IOCTL_PRIVCMD_HYPERCALL,
                       (unsigned long)hypercall);
     if (error)
@@ -254,7 +254,7 @@ int xc_evtchn_unmask(int xce_handle, evt
 }
 
 /* Optionally flush file to disk and discard page cache */
-void discard_file_cache(int fd, int flush) 
+void discard_file_cache(xc_interface *xch, int fd, int flush) 
 {
 
     if ( flush && (fsync(fd) < 0) )
@@ -264,13 +264,13 @@ void discard_file_cache(int fd, int flus
 }
 
 grant_entry_v1_t *xc_gnttab_map_table_v1(
-    int xc_handle, int domid, int *gnt_num)
+    xc_interface *xch, int domid, int *gnt_num)
 {
     return NULL;
 }
 
 grant_entry_v2_t *xc_gnttab_map_table_v2(
-    int xc_handle, int domid, int *gnt_num)
+    xc_interface *xch, int domid, int *gnt_num)
 {
     return NULL;
 }
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_offline_page.c
--- a/tools/libxc/xc_offline_page.c     Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_offline_page.c     Fri May 28 09:30:19 2010 +0100
@@ -48,7 +48,7 @@ static struct domain_info_context _dinfo
 static struct domain_info_context _dinfo;
 static struct domain_info_context *dinfo = &_dinfo;
 
-int xc_mark_page_online(int xc, unsigned long start,
+int xc_mark_page_online(xc_interface *xch, unsigned long start,
                         unsigned long end, uint32_t *status)
 {
     DECLARE_SYSCTL;
@@ -68,14 +68,14 @@ int xc_mark_page_online(int xc, unsigned
     sysctl.u.page_offline.cmd = sysctl_page_online;
     sysctl.u.page_offline.end = end;
     set_xen_guest_handle(sysctl.u.page_offline.status, status);
-    ret = xc_sysctl(xc, &sysctl);
+    ret = xc_sysctl(xch, &sysctl);
 
     unlock_pages(status, sizeof(uint32_t)*(end - start + 1));
 
     return ret;
 }
 
-int xc_mark_page_offline(int xc, unsigned long start,
+int xc_mark_page_offline(xc_interface *xch, unsigned long start,
                           unsigned long end, uint32_t *status)
 {
     DECLARE_SYSCTL;
@@ -95,14 +95,14 @@ int xc_mark_page_offline(int xc, unsigne
     sysctl.u.page_offline.cmd = sysctl_page_offline;
     sysctl.u.page_offline.end = end;
     set_xen_guest_handle(sysctl.u.page_offline.status, status);
-    ret = xc_sysctl(xc, &sysctl);
+    ret = xc_sysctl(xch, &sysctl);
 
     unlock_pages(status, sizeof(uint32_t)*(end - start + 1));
 
     return ret;
 }
 
-int xc_query_page_offline_status(int xc, unsigned long start,
+int xc_query_page_offline_status(xc_interface *xch, unsigned long start,
                                  unsigned long end, uint32_t *status)
 {
     DECLARE_SYSCTL;
@@ -122,7 +122,7 @@ int xc_query_page_offline_status(int xc,
     sysctl.u.page_offline.cmd = sysctl_query_page_offline;
     sysctl.u.page_offline.end = end;
     set_xen_guest_handle(sysctl.u.page_offline.status, status);
-    ret = xc_sysctl(xc, &sysctl);
+    ret = xc_sysctl(xch, &sysctl);
 
     unlock_pages(status, sizeof(uint32_t)*(end - start + 1));
 
@@ -132,7 +132,7 @@ int xc_query_page_offline_status(int xc,
  /*
   * There should no update to the grant when domain paused
   */
-static int xc_is_page_granted_v1(int xc_handle, xen_pfn_t gpfn,
+static int xc_is_page_granted_v1(xc_interface *xch, xen_pfn_t gpfn,
                                  grant_entry_v1_t *gnttab, int gnt_num)
 {
     int i = 0;
@@ -148,7 +148,7 @@ static int xc_is_page_granted_v1(int xc_
    return (i != gnt_num);
 }
 
-static int xc_is_page_granted_v2(int xc_handle, xen_pfn_t gpfn,
+static int xc_is_page_granted_v2(xc_interface *xch, xen_pfn_t gpfn,
                                  grant_entry_v2_t *gnttab, int gnt_num)
 {
     int i = 0;
@@ -173,21 +173,21 @@ static xen_pfn_t pfn_to_mfn(xen_pfn_t pf
                             (((uint32_t *)p2m)[(pfn)]))));
 }
 
-static int get_pt_level(int xc_handle, uint32_t domid,
+static int get_pt_level(xc_interface *xch, uint32_t domid,
                         unsigned int *pt_level,
                         unsigned int *gwidth)
 {
     DECLARE_DOMCTL;
     xen_capabilities_info_t xen_caps = "";
 
-    if (xc_version(xc_handle, XENVER_capabilities, &xen_caps) != 0)
+    if (xc_version(xch, XENVER_capabilities, &xen_caps) != 0)
         return -1;
 
     memset(&domctl, 0, sizeof(domctl));
     domctl.domain = domid;
     domctl.cmd = XEN_DOMCTL_get_address_size;
 
-    if ( do_domctl(xc_handle, &domctl) != 0 )
+    if ( do_domctl(xch, &domctl) != 0 )
         return -1;
 
     *gwidth = domctl.u.address_size.size / 8;
@@ -205,7 +205,7 @@ static int get_pt_level(int xc_handle, u
     return 0;
 }
 
-static int close_mem_info(int xc_handle, struct domain_mem_info *minfo)
+static int close_mem_info(xc_interface *xch, struct domain_mem_info *minfo)
 {
     if (minfo->pfn_type)
         free(minfo->pfn_type);
@@ -216,7 +216,7 @@ static int close_mem_info(int xc_handle,
     return 0;
 }
 
-static int init_mem_info(int xc_handle, int domid,
+static int init_mem_info(xc_interface *xch, int domid,
                  struct domain_mem_info *minfo,
                  xc_dominfo_t *info)
 {
@@ -228,7 +228,7 @@ static int init_mem_info(int xc_handle, 
     if (minfo->pfn_type || minfo->m2p_table || minfo->p2m_table)
         return -EINVAL;
 
-    if ( get_pt_level(xc_handle, domid, &minfo->pt_level,
+    if ( get_pt_level(xch, domid, &minfo->pt_level,
                       &minfo->guest_width) )
     {
         ERROR("Unable to get PT level info.");
@@ -238,7 +238,7 @@ static int init_mem_info(int xc_handle, 
 
     shared_info_frame = info->shared_info_frame;
 
-    live_shinfo = xc_map_foreign_range(xc_handle, domid,
+    live_shinfo = xc_map_foreign_range(xch, domid,
                      PAGE_SIZE, PROT_READ, shared_info_frame);
     if ( !live_shinfo )
     {
@@ -246,7 +246,7 @@ static int init_mem_info(int xc_handle, 
         return -EFAULT;
     }
 
-    if ( (rc = xc_core_arch_map_p2m_writable(xc_handle, minfo->guest_width,
+    if ( (rc = xc_core_arch_map_p2m_writable(xch, minfo->guest_width,
               info, live_shinfo, &minfo->p2m_table,  &minfo->p2m_size)) )
     {
         ERROR("Couldn't map p2m table %x\n", rc);
@@ -257,9 +257,9 @@ static int init_mem_info(int xc_handle, 
 
     dinfo->p2m_size = minfo->p2m_size;
 
-    minfo->max_mfn = xc_memory_op(xc_handle, XENMEM_maximum_ram_page, NULL);
+    minfo->max_mfn = xc_memory_op(xch, XENMEM_maximum_ram_page, NULL);
     if ( !(minfo->m2p_table =
-        xc_map_m2p(xc_handle, minfo->max_mfn, PROT_READ, NULL)) )
+        xc_map_m2p(xch, minfo->max_mfn, PROT_READ, NULL)) )
     {
         ERROR("Failed to map live M2P table");
         goto failed;
@@ -286,7 +286,7 @@ static int init_mem_info(int xc_handle, 
     for (i = 0; i < minfo->p2m_size ; i+=1024)
     {
         int count = ((dinfo->p2m_size - i ) > 1024 ) ? 1024: (dinfo->p2m_size 
- i);
-        if ( ( rc = xc_get_pfn_type_batch(xc_handle, domid, count,
+        if ( ( rc = xc_get_pfn_type_batch(xch, domid, count,
                   minfo->pfn_type + i)) )
         {
             ERROR("Failed to get pfn_type %x\n", rc);
@@ -340,12 +340,14 @@ static int backup_ptes(xen_pfn_t table_m
  * 0 when no changes
  * <0 when error happen
  */
-typedef int (*pte_func)(uint64_t pte, uint64_t *new_pte,
+typedef int (*pte_func)(xc_interface *xch,
+                       uint64_t pte, uint64_t *new_pte,
                        unsigned long table_mfn, int table_offset,
                        struct pte_backup *backup,
                        unsigned long no_use);
 
-static int __clear_pte(uint64_t pte, uint64_t *new_pte,
+static int __clear_pte(xc_interface *xch,
+                       uint64_t pte, uint64_t *new_pte,
                        unsigned long table_mfn, int table_offset,
                        struct pte_backup *backup,
                        unsigned long mfn)
@@ -369,7 +371,8 @@ static int __clear_pte(uint64_t pte, uin
     return 0;
 }
 
-static int __update_pte(uint64_t pte, uint64_t *new_pte,
+static int __update_pte(xc_interface *xch,
+                      uint64_t pte, uint64_t *new_pte,
                       unsigned long table_mfn, int table_offset,
                       struct pte_backup *backup,
                       unsigned long new_mfn)
@@ -397,7 +400,7 @@ static int __update_pte(uint64_t pte, ui
     return 0;
 }
 
-static int change_pte(int xc_handle, int domid,
+static int change_pte(xc_interface *xch, int domid,
                      struct domain_mem_info *minfo,
                      struct pte_backup *backup,
                      struct xc_mmu *mmu,
@@ -424,7 +427,7 @@ static int change_pte(int xc_handle, int
 
         if ( minfo->pfn_type[i] & XEN_DOMCTL_PFINFO_LTABTYPE_MASK )
         {
-            content = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
+            content = xc_map_foreign_range(xch, domid, PAGE_SIZE,
                                             PROT_READ, table_mfn);
             if (!content)
                 goto failed;
@@ -436,12 +439,12 @@ static int change_pte(int xc_handle, int
                 else
                     pte = ((const uint64_t*)content)[j];
 
-                rc = func(pte, &new_pte, table_mfn, j, backup, data);
+                rc = func(xch, pte, &new_pte, table_mfn, j, backup, data);
 
                 switch (rc)
                 {
                     case 1:
-                    if ( xc_add_mmu_update(xc_handle, mmu,
+                    if ( xc_add_mmu_update(xch, mmu,
                           table_mfn << PAGE_SHIFT |
                           j * ( (minfo->pt_level == 2) ?
                               sizeof(uint32_t): sizeof(uint64_t)) |
@@ -463,7 +466,7 @@ static int change_pte(int xc_handle, int
         content = NULL;
     }
 
-    if ( xc_flush_mmu_updates(xc_handle, mmu) )
+    if ( xc_flush_mmu_updates(xch, mmu) )
         goto failed;
 
     return 0;
@@ -475,27 +478,27 @@ failed:
     return -1;
 }
 
-static int update_pte(int xc_handle, int domid,
+static int update_pte(xc_interface *xch, int domid,
                      struct domain_mem_info *minfo,
                      struct pte_backup *backup,
                      struct xc_mmu *mmu,
                      unsigned long new_mfn)
 {
-    return change_pte(xc_handle, domid,  minfo, backup, mmu,
+    return change_pte(xch, domid,  minfo, backup, mmu,
                       __update_pte, new_mfn);
 }
 
-static int clear_pte(int xc_handle, int domid,
+static int clear_pte(xc_interface *xch, int domid,
                      struct domain_mem_info *minfo,
                      struct pte_backup *backup,
                      struct xc_mmu *mmu,
                      xen_pfn_t mfn)
 {
-    return change_pte(xc_handle, domid, minfo, backup, mmu,
+    return change_pte(xch, domid, minfo, backup, mmu,
                       __clear_pte, mfn);
 }
 
-static int exchange_page(int xc_handle, xen_pfn_t mfn,
+static int exchange_page(xc_interface *xch, xen_pfn_t mfn,
                      xen_pfn_t *new_mfn, int domid)
 {
     int rc;
@@ -516,7 +519,7 @@ static int exchange_page(int xc_handle, 
     set_xen_guest_handle(exchange.in.extent_start, &mfn);
     set_xen_guest_handle(exchange.out.extent_start, &out_mfn);
 
-    rc = xc_memory_op(xc_handle, XENMEM_exchange, &exchange);
+    rc = xc_memory_op(xch, XENMEM_exchange, &exchange);
 
     if (!rc)
         *new_mfn = out_mfn;
@@ -528,7 +531,7 @@ static int exchange_page(int xc_handle, 
  * Check if a page can be exchanged successfully
  */
 
-static int is_page_exchangable(int xc_handle, int domid, xen_pfn_t mfn,
+static int is_page_exchangable(xc_interface *xch, int domid, xen_pfn_t mfn,
                                xc_dominfo_t *info)
 {
     uint32_t status;
@@ -547,7 +550,7 @@ static int is_page_exchangable(int xc_ha
     }
 
     /* Check if pages are offline pending or not */
-    rc = xc_query_page_offline_status(xc_handle, mfn, mfn, &status);
+    rc = xc_query_page_offline_status(xch, mfn, mfn, &status);
 
     if ( rc || !(status & PG_OFFLINE_STATUS_OFFLINE_PENDING) )
     {
@@ -560,7 +563,7 @@ static int is_page_exchangable(int xc_ha
 }
 
 /* The domain should be suspended when called here */
-int xc_exchange_page(int xc_handle, int domid, xen_pfn_t mfn)
+int xc_exchange_page(xc_interface *xch, int domid, xen_pfn_t mfn)
 {
     xc_dominfo_t info;
     struct domain_mem_info minfo;
@@ -575,7 +578,7 @@ int xc_exchange_page(int xc_handle, int 
     uint32_t status;
     xen_pfn_t new_mfn, gpfn;
 
-    if ( xc_domain_getinfo(xc_handle, domid, 1, &info) != 1 )
+    if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 )
     {
         ERROR("Could not get domain info");
         return -EFAULT;
@@ -587,7 +590,7 @@ int xc_exchange_page(int xc_handle, int 
         return -EINVAL;
     }
 
-    if (!is_page_exchangable(xc_handle, domid, mfn, &info))
+    if (!is_page_exchangable(xch, domid, mfn, &info))
     {
         ERROR("Could not exchange page\n");
         return -EINVAL;
@@ -595,7 +598,7 @@ int xc_exchange_page(int xc_handle, int 
 
     /* Get domain's memory information */
     memset(&minfo, 0, sizeof(minfo));
-    init_mem_info(xc_handle, domid, &minfo, &info);
+    init_mem_info(xch, domid, &minfo, &info);
     gpfn = minfo.m2p_table[mfn];
 
     /* Don't exchange CR3 for PAE guest in PAE host environment */
@@ -606,10 +609,10 @@ int xc_exchange_page(int xc_handle, int 
             goto failed;
     }
 
-    gnttab_v2 = xc_gnttab_map_table_v2(xc_handle, domid, &gnt_num);
+    gnttab_v2 = xc_gnttab_map_table_v2(xch, domid, &gnt_num);
     if (!gnttab_v2)
     {
-        gnttab_v1 = xc_gnttab_map_table_v1(xc_handle, domid, &gnt_num);
+        gnttab_v1 = xc_gnttab_map_table_v1(xch, domid, &gnt_num);
         if (!gnttab_v1)
         {
             ERROR("Failed to map grant table\n");
@@ -618,8 +621,8 @@ int xc_exchange_page(int xc_handle, int 
     }
 
     if (gnttab_v1
-        ? xc_is_page_granted_v1(xc_handle, mfn, gnttab_v1, gnt_num)
-        : xc_is_page_granted_v2(xc_handle, mfn, gnttab_v2, gnt_num))
+        ? xc_is_page_granted_v1(xch, mfn, gnttab_v1, gnt_num)
+        : xc_is_page_granted_v2(xch, mfn, gnttab_v2, gnt_num))
     {
         ERROR("Page %lx is granted now\n", mfn);
         goto failed;
@@ -650,7 +653,7 @@ int xc_exchange_page(int xc_handle, int 
         mops.cmd = MMUEXT_UNPIN_TABLE;
         mops.arg1.mfn = mfn;
 
-        if ( xc_mmuext_op(xc_handle, &mops, 1, domid) < 0 )
+        if ( xc_mmuext_op(xch, &mops, 1, domid) < 0 )
         {
             ERROR("Failed to unpin page %lx", mfn);
             goto failed;
@@ -660,7 +663,7 @@ int xc_exchange_page(int xc_handle, int 
     }
 
     /* backup the content */
-    old_p = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
+    old_p = xc_map_foreign_range(xch, domid, PAGE_SIZE,
       PROT_READ, mfn);
     if (!old_p)
     {
@@ -671,7 +674,7 @@ int xc_exchange_page(int xc_handle, int 
     memcpy(backup, old_p, PAGE_SIZE);
     munmap(old_p, PAGE_SIZE);
 
-    mmu = xc_alloc_mmu_updates(xc_handle, domid);
+    mmu = xc_alloc_mmu_updates(xch, domid);
     if ( mmu == NULL )
     {
         ERROR("%s: failed at %d\n", __FUNCTION__, __LINE__);
@@ -679,7 +682,7 @@ int xc_exchange_page(int xc_handle, int 
     }
 
     /* Firstly update all pte to be invalid to remove the reference */
-    rc = clear_pte(xc_handle, domid,  &minfo, &old_ptes, mmu, mfn);
+    rc = clear_pte(xch, domid,  &minfo, &old_ptes, mmu, mfn);
 
     if (rc)
     {
@@ -687,19 +690,19 @@ int xc_exchange_page(int xc_handle, int 
         goto failed;
     }
 
-    rc = exchange_page(xc_handle, mfn, &new_mfn, domid);
+    rc = exchange_page(xch, mfn, &new_mfn, domid);
 
     if (rc)
     {
         ERROR("Exchange the page failed\n");
         /* Exchange fail means there are refere to the page still */
-        rc = update_pte(xc_handle, domid, &minfo, &old_ptes, mmu, mfn);
+        rc = update_pte(xch, domid, &minfo, &old_ptes, mmu, mfn);
         if (rc)
             result = -2;
         goto failed;
     }
 
-    rc = update_pte(xc_handle, domid, &minfo, &old_ptes, mmu, new_mfn);
+    rc = update_pte(xch, domid, &minfo, &old_ptes, mmu, new_mfn);
 
     if (rc)
     {
@@ -710,7 +713,7 @@ int xc_exchange_page(int xc_handle, int 
     }
 
     /* Check if pages are offlined already */
-    rc = xc_query_page_offline_status(xc_handle, mfn, mfn,
+    rc = xc_query_page_offline_status(xch, mfn, mfn,
                             &status);
 
     if (rc)
@@ -728,7 +731,7 @@ int xc_exchange_page(int xc_handle, int 
         /* Update the p2m table */
         minfo.p2m_table[gpfn] = new_mfn;
 
-        new_p = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
+        new_p = xc_map_foreign_range(xch, domid, PAGE_SIZE,
                                      PROT_READ|PROT_WRITE, new_mfn);
         memcpy(new_p, backup, PAGE_SIZE);
         munmap(new_p, PAGE_SIZE);
@@ -763,7 +766,7 @@ failed:
                 break;
         }
 
-        if ( xc_mmuext_op(xc_handle, &mops, 1, domid) < 0 )
+        if ( xc_mmuext_op(xch, &mops, 1, domid) < 0 )
         {
             ERROR("failed to pin the mfn again\n");
             result = -2;
@@ -784,7 +787,7 @@ failed:
     if (gnttab_v2)
         munmap(gnttab_v2, gnt_num / (PAGE_SIZE/sizeof(grant_entry_v2_t)));
 
-    close_mem_info(xc_handle, &minfo);
+    close_mem_info(xch, &minfo);
 
     return result;
 }
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_pagetab.c
--- a/tools/libxc/xc_pagetab.c  Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_pagetab.c  Fri May 28 09:30:19 2010 +0100
@@ -12,7 +12,7 @@
 #define EFER_LMA 0x400
 
 
-unsigned long xc_translate_foreign_address(int xc_handle, uint32_t dom,
+unsigned long xc_translate_foreign_address(xc_interface *xch, uint32_t dom,
                                            int vcpu, unsigned long long virt)
 {
     xc_dominfo_t dominfo;
@@ -20,14 +20,14 @@ unsigned long xc_translate_foreign_addre
     int size, level, pt_levels = 2;
     void *map;
 
-    if (xc_domain_getinfo(xc_handle, dom, 1, &dominfo) != 1 
+    if (xc_domain_getinfo(xch, dom, 1, &dominfo) != 1 
         || dominfo.domid != dom)
         return 0;
 
     /* What kind of paging are we dealing with? */
     if (dominfo.hvm) {
         struct hvm_hw_cpu ctx;
-        if (xc_domain_hvm_getcontext_partial(xc_handle, dom,
+        if (xc_domain_hvm_getcontext_partial(xch, dom,
                                              HVM_SAVE_CODE(CPU), vcpu,
                                              &ctx, sizeof ctx) != 0)
             return 0;
@@ -38,11 +38,11 @@ unsigned long xc_translate_foreign_addre
     } else {
         DECLARE_DOMCTL;
         vcpu_guest_context_any_t ctx;
-        if (xc_vcpu_getcontext(xc_handle, dom, vcpu, &ctx) != 0)
+        if (xc_vcpu_getcontext(xch, dom, vcpu, &ctx) != 0)
             return 0;
         domctl.domain = dom;
         domctl.cmd = XEN_DOMCTL_get_address_size;
-        if ( do_domctl(xc_handle, &domctl) != 0 )
+        if ( do_domctl(xch, &domctl) != 0 )
             return 0;
         if (domctl.u.address_size.size == 64) {
             pt_levels = 4;
@@ -69,7 +69,7 @@ unsigned long xc_translate_foreign_addre
     /* Walk the pagetables */
     for (level = pt_levels; level > 0; level--) {
         paddr += ((virt & mask) >> (xc_ffs64(mask) - 1)) * size;
-        map = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ, 
+        map = xc_map_foreign_range(xch, dom, PAGE_SIZE, PROT_READ, 
                                    paddr >>PAGE_SHIFT);
         if (!map) 
             return 0;
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_physdev.c
--- a/tools/libxc/xc_physdev.c  Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_physdev.c  Fri May 28 09:30:19 2010 +0100
@@ -9,7 +9,7 @@
 
 #include "xc_private.h"
 
-int xc_physdev_pci_access_modify(int xc_handle,
+int xc_physdev_pci_access_modify(xc_interface *xch,
                                  uint32_t domid,
                                  int bus,
                                  int dev,
@@ -20,7 +20,7 @@ int xc_physdev_pci_access_modify(int xc_
     return -1;
 }
 
-int xc_physdev_map_pirq(int xc_handle,
+int xc_physdev_map_pirq(xc_interface *xch,
                         int domid,
                         int index,
                         int *pirq)
@@ -37,7 +37,7 @@ int xc_physdev_map_pirq(int xc_handle,
     map.index = index;
     map.pirq = *pirq;
 
-    rc = do_physdev_op(xc_handle, PHYSDEVOP_map_pirq, &map, sizeof(map));
+    rc = do_physdev_op(xch, PHYSDEVOP_map_pirq, &map, sizeof(map));
 
     if ( !rc )
         *pirq = map.pirq;
@@ -45,7 +45,7 @@ int xc_physdev_map_pirq(int xc_handle,
     return rc;
 }
 
-int xc_physdev_map_pirq_msi(int xc_handle,
+int xc_physdev_map_pirq_msi(xc_interface *xch,
                             int domid,
                             int index,
                             int *pirq,
@@ -70,7 +70,7 @@ int xc_physdev_map_pirq_msi(int xc_handl
     map.entry_nr = entry_nr;
     map.table_base = table_base;
 
-    rc = do_physdev_op(xc_handle, PHYSDEVOP_map_pirq, &map, sizeof(map));
+    rc = do_physdev_op(xch, PHYSDEVOP_map_pirq, &map, sizeof(map));
 
     if ( !rc )
         *pirq = map.pirq;
@@ -78,7 +78,7 @@ int xc_physdev_map_pirq_msi(int xc_handl
     return rc;
 }
 
-int xc_physdev_unmap_pirq(int xc_handle,
+int xc_physdev_unmap_pirq(xc_interface *xch,
                           int domid,
                           int pirq)
 {
@@ -89,7 +89,7 @@ int xc_physdev_unmap_pirq(int xc_handle,
     unmap.domid = domid;
     unmap.pirq = pirq;
 
-    rc = do_physdev_op(xc_handle, PHYSDEVOP_unmap_pirq, &unmap, sizeof(unmap));
+    rc = do_physdev_op(xch, PHYSDEVOP_unmap_pirq, &unmap, sizeof(unmap));
 
     return rc;
 }
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_pm.c
--- a/tools/libxc/xc_pm.c       Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_pm.c       Fri May 28 09:30:19 2010 +0100
@@ -30,7 +30,7 @@
 /*
  * Get PM statistic info
  */
-int xc_pm_get_max_px(int xc_handle, int cpuid, int *max_px)
+int xc_pm_get_max_px(xc_interface *xch, int cpuid, int *max_px)
 {
     DECLARE_SYSCTL;
     int ret;
@@ -38,7 +38,7 @@ int xc_pm_get_max_px(int xc_handle, int 
     sysctl.cmd = XEN_SYSCTL_get_pmstat;
     sysctl.u.get_pmstat.type = PMSTAT_get_max_px;
     sysctl.u.get_pmstat.cpuid = cpuid;
-    ret = xc_sysctl(xc_handle, &sysctl);
+    ret = xc_sysctl(xch, &sysctl);
     if ( ret )
         return ret;
 
@@ -46,7 +46,7 @@ int xc_pm_get_max_px(int xc_handle, int 
     return ret;
 }
 
-int xc_pm_get_pxstat(int xc_handle, int cpuid, struct xc_px_stat *pxpt)
+int xc_pm_get_pxstat(xc_interface *xch, int cpuid, struct xc_px_stat *pxpt)
 {
     DECLARE_SYSCTL;
     int max_px, ret;
@@ -54,7 +54,7 @@ int xc_pm_get_pxstat(int xc_handle, int 
     if ( !pxpt || !(pxpt->trans_pt) || !(pxpt->pt) )
         return -EINVAL;
 
-    if ( (ret = xc_pm_get_max_px(xc_handle, cpuid, &max_px)) != 0)
+    if ( (ret = xc_pm_get_max_px(xch, cpuid, &max_px)) != 0)
         return ret;
 
     if ( (ret = lock_pages(pxpt->trans_pt, 
@@ -76,7 +76,7 @@ int xc_pm_get_pxstat(int xc_handle, int 
     set_xen_guest_handle(sysctl.u.get_pmstat.u.getpx.pt, 
                         (pm_px_val_t *)pxpt->pt);
 
-    ret = xc_sysctl(xc_handle, &sysctl);
+    ret = xc_sysctl(xch, &sysctl);
     if ( ret )
     {
         unlock_pages(pxpt->trans_pt, max_px * max_px * sizeof(uint64_t));
@@ -95,7 +95,7 @@ int xc_pm_get_pxstat(int xc_handle, int 
     return ret;
 }
 
-int xc_pm_reset_pxstat(int xc_handle, int cpuid)
+int xc_pm_reset_pxstat(xc_interface *xch, int cpuid)
 {
     DECLARE_SYSCTL;
 
@@ -103,10 +103,10 @@ int xc_pm_reset_pxstat(int xc_handle, in
     sysctl.u.get_pmstat.type = PMSTAT_reset_pxstat;
     sysctl.u.get_pmstat.cpuid = cpuid;
 
-    return xc_sysctl(xc_handle, &sysctl);
-}
-
-int xc_pm_get_max_cx(int xc_handle, int cpuid, int *max_cx)
+    return xc_sysctl(xch, &sysctl);
+}
+
+int xc_pm_get_max_cx(xc_interface *xch, int cpuid, int *max_cx)
 {
     DECLARE_SYSCTL;
     int ret = 0;
@@ -114,14 +114,14 @@ int xc_pm_get_max_cx(int xc_handle, int 
     sysctl.cmd = XEN_SYSCTL_get_pmstat;
     sysctl.u.get_pmstat.type = PMSTAT_get_max_cx;
     sysctl.u.get_pmstat.cpuid = cpuid;
-    if ( (ret = xc_sysctl(xc_handle, &sysctl)) != 0 )
+    if ( (ret = xc_sysctl(xch, &sysctl)) != 0 )
         return ret;
 
     *max_cx = sysctl.u.get_pmstat.u.getcx.nr;
     return ret;
 }
 
-int xc_pm_get_cxstat(int xc_handle, int cpuid, struct xc_cx_stat *cxpt)
+int xc_pm_get_cxstat(xc_interface *xch, int cpuid, struct xc_cx_stat *cxpt)
 {
     DECLARE_SYSCTL;
     int max_cx, ret;
@@ -129,7 +129,7 @@ int xc_pm_get_cxstat(int xc_handle, int 
     if( !cxpt || !(cxpt->triggers) || !(cxpt->residencies) )
         return -EINVAL;
 
-    if ( (ret = xc_pm_get_max_cx(xc_handle, cpuid, &max_cx)) )
+    if ( (ret = xc_pm_get_max_cx(xch, cpuid, &max_cx)) )
         goto unlock_0;
 
     if ( (ret = lock_pages(cxpt, sizeof(struct xc_cx_stat))) )
@@ -146,7 +146,7 @@ int xc_pm_get_cxstat(int xc_handle, int 
     set_xen_guest_handle(sysctl.u.get_pmstat.u.getcx.residencies, 
                          cxpt->residencies);
 
-    if ( (ret = xc_sysctl(xc_handle, &sysctl)) )
+    if ( (ret = xc_sysctl(xch, &sysctl)) )
         goto unlock_3;
 
     cxpt->nr = sysctl.u.get_pmstat.u.getcx.nr;
@@ -163,7 +163,7 @@ unlock_0:
     return ret;
 }
 
-int xc_pm_reset_cxstat(int xc_handle, int cpuid)
+int xc_pm_reset_cxstat(xc_interface *xch, int cpuid)
 {
     DECLARE_SYSCTL;
 
@@ -171,7 +171,7 @@ int xc_pm_reset_cxstat(int xc_handle, in
     sysctl.u.get_pmstat.type = PMSTAT_reset_cxstat;
     sysctl.u.get_pmstat.cpuid = cpuid;
 
-    return xc_sysctl(xc_handle, &sysctl);
+    return xc_sysctl(xch, &sysctl);
 }
 
 
@@ -179,7 +179,7 @@ int xc_pm_reset_cxstat(int xc_handle, in
  * 1. Get PM parameter
  * 2. Provide user PM control
  */
-int xc_get_cpufreq_para(int xc_handle, int cpuid,
+int xc_get_cpufreq_para(xc_interface *xch, int cpuid,
                         struct xc_get_cpufreq_para *user_para)
 {
     DECLARE_SYSCTL;
@@ -189,7 +189,7 @@ int xc_get_cpufreq_para(int xc_handle, i
                      user_para->freq_num &&
                      user_para->gov_num;
 
-    if ( (xc_handle < 0) || !user_para )
+    if ( (xch < 0) || !user_para )
         return -EINVAL;
 
     if ( has_num )
@@ -224,7 +224,7 @@ int xc_get_cpufreq_para(int xc_handle, i
     sys_para->freq_num = user_para->freq_num;
     sys_para->gov_num  = user_para->gov_num;
 
-    ret = xc_sysctl(xc_handle, &sysctl);
+    ret = xc_sysctl(xch, &sysctl);
     if ( ret )
     {
         if ( errno == EAGAIN )
@@ -274,12 +274,12 @@ unlock_1:
     return ret;
 }
 
-int xc_set_cpufreq_gov(int xc_handle, int cpuid, char *govname)
+int xc_set_cpufreq_gov(xc_interface *xch, int cpuid, char *govname)
 {
     DECLARE_SYSCTL;
     char *scaling_governor = sysctl.u.pm_op.u.set_gov.scaling_governor;
 
-    if ( (xc_handle < 0) || (!govname) )
+    if ( (xch < 0) || (!govname) )
         return -EINVAL;
 
     sysctl.cmd = XEN_SYSCTL_pm_op;
@@ -288,15 +288,15 @@ int xc_set_cpufreq_gov(int xc_handle, in
     strncpy(scaling_governor, govname, CPUFREQ_NAME_LEN);
     scaling_governor[CPUFREQ_NAME_LEN - 1] = '\0';
 
-    return xc_sysctl(xc_handle, &sysctl);
-}
-
-int xc_set_cpufreq_para(int xc_handle, int cpuid, 
+    return xc_sysctl(xch, &sysctl);
+}
+
+int xc_set_cpufreq_para(xc_interface *xch, int cpuid, 
                         int ctrl_type, int ctrl_value)
 {
     DECLARE_SYSCTL;
 
-    if ( xc_handle < 0 )
+    if ( xch < 0 )
         return -EINVAL;
 
     sysctl.cmd = XEN_SYSCTL_pm_op;
@@ -305,21 +305,21 @@ int xc_set_cpufreq_para(int xc_handle, i
     sysctl.u.pm_op.u.set_para.ctrl_type = ctrl_type;
     sysctl.u.pm_op.u.set_para.ctrl_value = ctrl_value;
 
-    return xc_sysctl(xc_handle, &sysctl);
-}
-
-int xc_get_cpufreq_avgfreq(int xc_handle, int cpuid, int *avg_freq)
+    return xc_sysctl(xch, &sysctl);
+}
+
+int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq)
 {
     int ret = 0;
     DECLARE_SYSCTL;
 
-    if ( (xc_handle < 0) || (!avg_freq) )
+    if ( (xch < 0) || (!avg_freq) )
         return -EINVAL;
 
     sysctl.cmd = XEN_SYSCTL_pm_op;
     sysctl.u.pm_op.cmd = GET_CPUFREQ_AVGFREQ;
     sysctl.u.pm_op.cpuid = cpuid;
-    ret = xc_sysctl(xc_handle, &sysctl);
+    ret = xc_sysctl(xch, &sysctl);
 
     *avg_freq = sysctl.u.pm_op.u.get_avgfreq;
 
@@ -329,7 +329,7 @@ int xc_get_cpufreq_avgfreq(int xc_handle
 /* value:   0 - disable sched_smt_power_savings 
             1 - enable sched_smt_power_savings
  */
-int xc_set_sched_opt_smt(int xc_handle, uint32_t value)
+int xc_set_sched_opt_smt(xc_interface *xch, uint32_t value)
 {
    int rc;
    DECLARE_SYSCTL;
@@ -338,12 +338,12 @@ int xc_set_sched_opt_smt(int xc_handle, 
    sysctl.u.pm_op.cmd = XEN_SYSCTL_pm_op_set_sched_opt_smt;
    sysctl.u.pm_op.cpuid = 0;
    sysctl.u.pm_op.u.set_sched_opt_smt = value;
-   rc = do_sysctl(xc_handle, &sysctl);
+   rc = do_sysctl(xch, &sysctl);
 
    return rc;
 }
 
-int xc_set_vcpu_migration_delay(int xc_handle, uint32_t value)
+int xc_set_vcpu_migration_delay(xc_interface *xch, uint32_t value)
 {
    int rc;
    DECLARE_SYSCTL;
@@ -352,12 +352,12 @@ int xc_set_vcpu_migration_delay(int xc_h
    sysctl.u.pm_op.cmd = XEN_SYSCTL_pm_op_set_vcpu_migration_delay;
    sysctl.u.pm_op.cpuid = 0;
    sysctl.u.pm_op.u.set_vcpu_migration_delay = value;
-   rc = do_sysctl(xc_handle, &sysctl);
+   rc = do_sysctl(xch, &sysctl);
 
    return rc;
 }
 
-int xc_get_vcpu_migration_delay(int xc_handle, uint32_t *value)
+int xc_get_vcpu_migration_delay(xc_interface *xch, uint32_t *value)
 {
    int rc;
    DECLARE_SYSCTL;
@@ -365,7 +365,7 @@ int xc_get_vcpu_migration_delay(int xc_h
    sysctl.cmd = XEN_SYSCTL_pm_op;
    sysctl.u.pm_op.cmd = XEN_SYSCTL_pm_op_get_vcpu_migration_delay;
    sysctl.u.pm_op.cpuid = 0;
-   rc = do_sysctl(xc_handle, &sysctl);
+   rc = do_sysctl(xch, &sysctl);
 
    if (!rc && value)
        *value = sysctl.u.pm_op.u.get_vcpu_migration_delay;
@@ -373,29 +373,29 @@ int xc_get_vcpu_migration_delay(int xc_h
    return rc;
 }
 
-int xc_get_cpuidle_max_cstate(int xc_handle, uint32_t *value)
+int xc_get_cpuidle_max_cstate(xc_interface *xch, uint32_t *value)
 {
     int rc;
     DECLARE_SYSCTL;
 
-    if ( xc_handle < 0 || !value )
+    if ( xch < 0 || !value )
         return -EINVAL;
 
     sysctl.cmd = XEN_SYSCTL_pm_op;
     sysctl.u.pm_op.cmd = XEN_SYSCTL_pm_op_get_max_cstate;
     sysctl.u.pm_op.cpuid = 0;
     sysctl.u.pm_op.u.get_max_cstate = 0;
-    rc = do_sysctl(xc_handle, &sysctl);
+    rc = do_sysctl(xch, &sysctl);
     *value = sysctl.u.pm_op.u.get_max_cstate;
 
     return rc;
 }
 
-int xc_set_cpuidle_max_cstate(int xc_handle, uint32_t value)
-{
-    DECLARE_SYSCTL;
-
-    if ( xc_handle < 0 )
+int xc_set_cpuidle_max_cstate(xc_interface *xch, uint32_t value)
+{
+    DECLARE_SYSCTL;
+
+    if ( xch < 0 )
         return -EINVAL;
 
     sysctl.cmd = XEN_SYSCTL_pm_op;
@@ -403,31 +403,31 @@ int xc_set_cpuidle_max_cstate(int xc_han
     sysctl.u.pm_op.cpuid = 0;
     sysctl.u.pm_op.u.set_max_cstate = value;
 
-    return do_sysctl(xc_handle, &sysctl);
-}
-
-int xc_enable_turbo(int xc_handle, int cpuid)
-{
-    DECLARE_SYSCTL;
-
-    if ( xc_handle < 0 )
+    return do_sysctl(xch, &sysctl);
+}
+
+int xc_enable_turbo(xc_interface *xch, int cpuid)
+{
+    DECLARE_SYSCTL;
+
+    if ( xch < 0 )
         return -EINVAL;
 
     sysctl.cmd = XEN_SYSCTL_pm_op;
     sysctl.u.pm_op.cmd = XEN_SYSCTL_pm_op_enable_turbo;
     sysctl.u.pm_op.cpuid = cpuid;
-    return do_sysctl(xc_handle, &sysctl);
-}
-
-int xc_disable_turbo(int xc_handle, int cpuid)
-{
-    DECLARE_SYSCTL;
-
-    if ( xc_handle < 0 )
+    return do_sysctl(xch, &sysctl);
+}
+
+int xc_disable_turbo(xc_interface *xch, int cpuid)
+{
+    DECLARE_SYSCTL;
+
+    if ( xch < 0 )
         return -EINVAL;
 
     sysctl.cmd = XEN_SYSCTL_pm_op;
     sysctl.u.pm_op.cmd = XEN_SYSCTL_pm_op_disable_turbo;
     sysctl.u.pm_op.cpuid = cpuid;
-    return do_sysctl(xc_handle, &sysctl);
-}
+    return do_sysctl(xch, &sysctl);
+}
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_private.c
--- a/tools/libxc/xc_private.c  Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_private.c  Fri May 28 09:30:19 2010 +0100
@@ -7,70 +7,83 @@
 #include <inttypes.h>
 #include "xc_private.h"
 #include "xg_private.h"
+#include "xc_dom.h"
 #include <stdarg.h>
 #include <stdlib.h>
 #include <malloc.h>
 #include <unistd.h>
 #include <pthread.h>
-
-static pthread_key_t last_error_pkey;
-static pthread_once_t last_error_pkey_once = PTHREAD_ONCE_INIT;
+#include <assert.h>
+
+xc_interface *xc_interface_open(xentoollog_logger *logger,
+                                xentoollog_logger *dombuild_logger,
+                                unsigned open_flags) {
+    xc_interface xch_buf, *xch = &xch_buf;
+
+    xch->fd = -1;
+    xch->dombuild_logger_file = 0;
+    xc_clear_last_error(xch);
+
+    xch->error_handler   = logger;           xch->error_handler_tofree   = 0;
+    xch->dombuild_logger = dombuild_logger;  xch->dombuild_logger_tofree = 0;
+
+    if (!xch->error_handler) {
+        xch->error_handler = xch->error_handler_tofree =
+            (xentoollog_logger*)
+            xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
+        if (!xch->error_handler)
+            goto err;
+    }
+
+    xch = malloc(sizeof(*xch));
+    if (!xch) {
+        xch = &xch_buf;
+        PERROR("Could not allocate new xc_interface struct");
+        goto err;
+    }
+    *xch = xch_buf;
+
+    if (!(open_flags & XC_OPENFLAG_DUMMY)) {
+        xch->fd = xc_interface_open_core(xch);
+        if (xch->fd < 0)
+            goto err;
+    }
+
+    return xch;
+
+ err:
+    if (xch) xtl_logger_destroy(xch->error_handler);
+    if (xch != &xch_buf) free(xch);
+    return 0;
+}
+
+int xc_interface_close(xc_interface *xch)
+{
+    int rc = 0;
+
+    xtl_logger_destroy(xch->dombuild_logger_tofree);
+    xtl_logger_destroy(xch->error_handler_tofree);
+
+    if (xch->fd >= 0) {
+        rc = xc_interface_close_core(xch, xch->fd);
+        if (rc) PERROR("Could not close hypervisor interface");
+    }
+    free(xch);
+    return rc;
+}
 
 static pthread_key_t errbuf_pkey;
 static pthread_once_t errbuf_pkey_once = PTHREAD_ONCE_INIT;
 
-#if DEBUG
-static xc_error_handler error_handler = xc_default_error_handler;
-#else
-static xc_error_handler error_handler = NULL;
-#endif
-
-void xc_default_error_handler(const xc_error *err)
-{
-    const char *desc = xc_error_code_to_desc(err->code);
-    fprintf(stderr, "ERROR %s: %s\n", desc, err->message);
-}
-
-static void
-_xc_clean_last_error(void *m)
-{
-    free(m);
-    pthread_setspecific(last_error_pkey, NULL);
-}
-
-static void
-_xc_init_last_error(void)
-{
-    pthread_key_create(&last_error_pkey, _xc_clean_last_error);
-}
-
-static xc_error *
-_xc_get_last_error(void)
-{
-    xc_error *last_error;
-
-    pthread_once(&last_error_pkey_once, _xc_init_last_error);
-
-    last_error = pthread_getspecific(last_error_pkey);
-    if (last_error == NULL) {
-        last_error = malloc(sizeof(xc_error));
-        pthread_setspecific(last_error_pkey, last_error);
-        xc_clear_last_error();
-    }
-
-    return last_error;
-}
-
-const xc_error *xc_get_last_error(void)
-{
-    return _xc_get_last_error();
-}
-
-void xc_clear_last_error(void)
-{
-    xc_error *last_error = _xc_get_last_error();
-    last_error->code = XC_ERROR_NONE;
-    last_error->message[0] = '\0';
+const xc_error *xc_get_last_error(xc_interface *xch)
+{
+    return &xch->last_error;
+}
+
+void xc_clear_last_error(xc_interface *xch)
+{
+    xch->last_error.code = XC_ERROR_NONE;
+    xch->last_error.message[0] = '\0';
 }
 
 const char *xc_error_code_to_desc(int code)
@@ -93,40 +106,70 @@ const char *xc_error_code_to_desc(int co
     return "Unknown error code";
 }
 
-xc_error_handler xc_set_error_handler(xc_error_handler handler)
-{
-    xc_error_handler old = error_handler;
-    error_handler = handler;
-    return old;
-}
-
-static void _xc_set_error(int code, const char *msg)
-{
-    xc_error *last_error = _xc_get_last_error();
-    last_error->code = code;
-    strncpy(last_error->message, msg, XC_MAX_ERROR_MSG_LEN - 1);
-    last_error->message[XC_MAX_ERROR_MSG_LEN-1] = '\0';
-}
-
-void xc_set_error(int code, const char *fmt, ...)
-{
+void xc_reportv(xc_interface *xch, xentoollog_logger *lg,
+                xentoollog_level level, int code,
+                const char *fmt, va_list args) {
     int saved_errno = errno;
-    char msg[XC_MAX_ERROR_MSG_LEN];
-    va_list args;
-
-    va_start(args, fmt);
+    char msgbuf[XC_MAX_ERROR_MSG_LEN];
+    char *msg;
+
+    /* Strip newlines from messages.
+     * XXX really the messages themselves should have the newlines removed.
+     */
+    char fmt_nonewline[512];
+    int fmt_l;
+
+    fmt_l = strlen(fmt);
+    if (fmt_l && fmt[fmt_l-1]=='\n' && fmt_l < sizeof(fmt_nonewline)) {
+        memcpy(fmt_nonewline, fmt, fmt_l-1);
+        fmt_nonewline[fmt_l-1] = 0;
+        fmt = fmt_nonewline;
+    }
+
+    if ( level >= XTL_ERROR ) {
+        msg = xch->last_error.message;
+        xch->last_error.code = code;
+    } else {
+        msg = msgbuf;
+    }
     vsnprintf(msg, XC_MAX_ERROR_MSG_LEN-1, fmt, args);
     msg[XC_MAX_ERROR_MSG_LEN-1] = '\0';
+
+    xtl_log(lg, level, -1, "xc",
+            "%s" "%s%s", msg,
+            code?": ":"", code ? xc_error_code_to_desc(code) : "");
+
+    errno = saved_errno;
+}
+
+void xc_report(xc_interface *xch, xentoollog_logger *lg,
+               xentoollog_level level, int code, const char *fmt, ...) {
+    va_list args;
+    va_start(args,fmt);
+    xc_reportv(xch,lg,level,code,fmt,args);
     va_end(args);
-
-    _xc_set_error(code, msg);
-
-    errno = saved_errno;
-
-    if ( error_handler != NULL ) {
-        xc_error *last_error = _xc_get_last_error();
-        error_handler(last_error);
-    }
+}
+
+void xc_report_error(xc_interface *xch, int code, const char *fmt, ...)
+{
+    va_list args;
+    va_start(args, fmt);
+    xc_reportv(xch, xch->error_handler, XTL_ERROR, code, fmt, args);
+    va_end(args);
+}
+
+void xc_report_progress_start(xc_interface *xch, const char *doing,
+                              unsigned long total) {
+    xch->currently_progress_reporting = doing;
+    xtl_progress(xch->error_handler, "xc", xch->currently_progress_reporting,
+                 0, total);
+}
+
+void xc_report_progress_step(xc_interface *xch,
+                             unsigned long done, unsigned long total) {
+    assert(xch->currently_progress_reporting);
+    xtl_progress(xch->error_handler, "xc", xch->currently_progress_reporting,
+                 done, total);
 }
 
 #ifdef __sun__
@@ -244,7 +287,7 @@ void hcall_buf_release(void **addr, size
 #endif
 
 /* NB: arr must be locked */
-int xc_get_pfn_type_batch(int xc_handle, uint32_t dom,
+int xc_get_pfn_type_batch(xc_interface *xch, uint32_t dom,
                           unsigned int num, xen_pfn_t *arr)
 {
     DECLARE_DOMCTL;
@@ -252,11 +295,11 @@ int xc_get_pfn_type_batch(int xc_handle,
     domctl.domain = (domid_t)dom;
     domctl.u.getpageframeinfo3.num = num;
     set_xen_guest_handle(domctl.u.getpageframeinfo3.array, arr);
-    return do_domctl(xc_handle, &domctl);
+    return do_domctl(xch, &domctl);
 }
 
 int xc_mmuext_op(
-    int xc_handle,
+    xc_interface *xch,
     struct mmuext_op *op,
     unsigned int nr_ops,
     domid_t dom)
@@ -276,7 +319,7 @@ int xc_mmuext_op(
     hypercall.arg[2] = (unsigned long)0;
     hypercall.arg[3] = (unsigned long)dom;
 
-    ret = do_xen_hypercall(xc_handle, &hypercall);
+    ret = do_xen_hypercall(xch, &hypercall);
 
     hcall_buf_release((void **)&op, nr_ops*sizeof(*op));
 
@@ -284,7 +327,7 @@ int xc_mmuext_op(
     return ret;
 }
 
-static int flush_mmu_updates(int xc_handle, struct xc_mmu *mmu)
+static int flush_mmu_updates(xc_interface *xch, struct xc_mmu *mmu)
 {
     int err = 0;
     DECLARE_HYPERCALL;
@@ -305,7 +348,7 @@ static int flush_mmu_updates(int xc_hand
         goto out;
     }
 
-    if ( do_xen_hypercall(xc_handle, &hypercall) < 0 )
+    if ( do_xen_hypercall(xch, &hypercall) < 0 )
     {
         ERROR("Failure when submitting mmu updates");
         err = 1;
@@ -319,7 +362,7 @@ static int flush_mmu_updates(int xc_hand
     return err;
 }
 
-struct xc_mmu *xc_alloc_mmu_updates(int xc_handle, domid_t dom)
+struct xc_mmu *xc_alloc_mmu_updates(xc_interface *xch, domid_t dom)
 {
     struct xc_mmu *mmu = malloc(sizeof(*mmu));
     if ( mmu == NULL )
@@ -329,24 +372,24 @@ struct xc_mmu *xc_alloc_mmu_updates(int 
     return mmu;
 }
 
-int xc_add_mmu_update(int xc_handle, struct xc_mmu *mmu,
+int xc_add_mmu_update(xc_interface *xch, struct xc_mmu *mmu,
                       unsigned long long ptr, unsigned long long val)
 {
     mmu->updates[mmu->idx].ptr = ptr;
     mmu->updates[mmu->idx].val = val;
 
     if ( ++mmu->idx == MAX_MMU_UPDATES )
-        return flush_mmu_updates(xc_handle, mmu);
+        return flush_mmu_updates(xch, mmu);
 
     return 0;
 }
 
-int xc_flush_mmu_updates(int xc_handle, struct xc_mmu *mmu)
-{
-    return flush_mmu_updates(xc_handle, mmu);
-}
-
-int xc_memory_op(int xc_handle,
+int xc_flush_mmu_updates(xc_interface *xch, struct xc_mmu *mmu)
+{
+    return flush_mmu_updates(xch, mmu);
+}
+
+int xc_memory_op(xc_interface *xch,
                  int cmd,
                  void *arg)
 {
@@ -421,7 +464,7 @@ int xc_memory_op(int xc_handle,
         break;
     }
 
-    ret = do_xen_hypercall(xc_handle, &hypercall);
+    ret = do_xen_hypercall(xch, &hypercall);
 
     switch ( cmd )
     {
@@ -459,14 +502,14 @@ int xc_memory_op(int xc_handle,
 }
 
 
-long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid, int vcpu )
+long long xc_domain_get_cpu_usage( xc_interface *xch, domid_t domid, int vcpu )
 {
     DECLARE_DOMCTL;
 
     domctl.cmd = XEN_DOMCTL_getvcpuinfo;
     domctl.domain = (domid_t)domid;
     domctl.u.getvcpuinfo.vcpu   = (uint16_t)vcpu;
-    if ( (do_domctl(xc_handle, &domctl) < 0) )
+    if ( (do_domctl(xch, &domctl) < 0) )
     {
         PERROR("Could not get info on domain");
         return -1;
@@ -476,7 +519,7 @@ long long xc_domain_get_cpu_usage( int x
 
 
 #ifndef __ia64__
-int xc_get_pfn_list(int xc_handle,
+int xc_get_pfn_list(xc_interface *xch,
                     uint32_t domid,
                     uint64_t *pfn_buf,
                     unsigned long max_pfns)
@@ -498,7 +541,7 @@ int xc_get_pfn_list(int xc_handle,
         return -1;
     }
 
-    ret = do_domctl(xc_handle, &domctl);
+    ret = do_domctl(xch, &domctl);
 
     unlock_pages(pfn_buf, max_pfns * sizeof(*pfn_buf));
 
@@ -506,22 +549,22 @@ int xc_get_pfn_list(int xc_handle,
 }
 #endif
 
-long xc_get_tot_pages(int xc_handle, uint32_t domid)
+long xc_get_tot_pages(xc_interface *xch, uint32_t domid)
 {
     DECLARE_DOMCTL;
     domctl.cmd = XEN_DOMCTL_getdomaininfo;
     domctl.domain = (domid_t)domid;
-    return (do_domctl(xc_handle, &domctl) < 0) ?
+    return (do_domctl(xch, &domctl) < 0) ?
         -1 : domctl.u.getdomaininfo.tot_pages;
 }
 
-int xc_copy_to_domain_page(int xc_handle,
+int xc_copy_to_domain_page(xc_interface *xch,
                            uint32_t domid,
                            unsigned long dst_pfn,
                            const char *src_page)
 {
     void *vaddr = xc_map_foreign_range(
-        xc_handle, domid, PAGE_SIZE, PROT_WRITE, dst_pfn);
+        xch, domid, PAGE_SIZE, PROT_WRITE, dst_pfn);
     if ( vaddr == NULL )
         return -1;
     memcpy(vaddr, src_page, PAGE_SIZE);
@@ -529,12 +572,12 @@ int xc_copy_to_domain_page(int xc_handle
     return 0;
 }
 
-int xc_clear_domain_page(int xc_handle,
+int xc_clear_domain_page(xc_interface *xch,
                          uint32_t domid,
                          unsigned long dst_pfn)
 {
     void *vaddr = xc_map_foreign_range(
-        xc_handle, domid, PAGE_SIZE, PROT_WRITE, dst_pfn);
+        xch, domid, PAGE_SIZE, PROT_WRITE, dst_pfn);
     if ( vaddr == NULL )
         return -1;
     memset(vaddr, 0, PAGE_SIZE);
@@ -542,17 +585,17 @@ int xc_clear_domain_page(int xc_handle,
     return 0;
 }
 
-int xc_domctl(int xc_handle, struct xen_domctl *domctl)
-{
-    return do_domctl(xc_handle, domctl);
-}
-
-int xc_sysctl(int xc_handle, struct xen_sysctl *sysctl)
-{
-    return do_sysctl(xc_handle, sysctl);
-}
-
-int xc_version(int xc_handle, int cmd, void *arg)
+int xc_domctl(xc_interface *xch, struct xen_domctl *domctl)
+{
+    return do_domctl(xch, domctl);
+}
+
+int xc_sysctl(xc_interface *xch, struct xen_sysctl *sysctl)
+{
+    return do_sysctl(xch, sysctl);
+}
+
+int xc_version(xc_interface *xch, int cmd, void *arg)
 {
     int rc, argsize = 0;
 
@@ -586,7 +629,7 @@ int xc_version(int xc_handle, int cmd, v
         memset(arg, 0, argsize);
 #endif
 
-    rc = do_xen_version(xc_handle, cmd, arg);
+    rc = do_xen_version(xch, cmd, arg);
 
     if ( argsize != 0 )
         unlock_pages(arg, argsize);
@@ -595,20 +638,20 @@ int xc_version(int xc_handle, int cmd, v
 }
 
 unsigned long xc_make_page_below_4G(
-    int xc_handle, uint32_t domid, unsigned long mfn)
+    xc_interface *xch, uint32_t domid, unsigned long mfn)
 {
     xen_pfn_t old_mfn = mfn;
     xen_pfn_t new_mfn;
 
     if ( xc_domain_memory_decrease_reservation(
-        xc_handle, domid, 1, 0, &old_mfn) != 0 )
+        xch, domid, 1, 0, &old_mfn) != 0 )
     {
         DPRINTF("xc_make_page_below_4G decrease failed. mfn=%lx\n",mfn);
         return 0;
     }
 
     if ( xc_domain_memory_increase_reservation(
-        xc_handle, domid, 1, 0, XENMEMF_address_bits(32), &new_mfn) != 0 )
+        xch, domid, 1, 0, XENMEMF_address_bits(32), &new_mfn) != 0 )
     {
         DPRINTF("xc_make_page_below_4G increase failed. mfn=%lx\n",mfn);
         return 0;
diff -r 54eb305da6a8 -r 779c0ef9682c tools/libxc/xc_private.h
--- a/tools/libxc/xc_private.h  Fri May 28 09:29:15 2010 +0100
+++ b/tools/libxc/xc_private.h  Fri May 28 09:30:19 2010 +0100
@@ -3,6 +3,7 @@
 #define XC_PRIVATE_H
 
 #include <unistd.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -39,10 +40,6 @@
 #define PAGE_SIZE               (1UL << PAGE_SHIFT)
 #define PAGE_MASK               (~(PAGE_SIZE-1))
 
-#define DEBUG    1
-#define INFO     1
-#define PROGRESS 0
-
 /* Force a compilation error if condition is true */
 #define XC_BUILD_BUG_ON(p) ((void)sizeof(struct { int:-!!(p); }))
 
@@ -53,30 +50,37 @@
 */
 #define MAX_PAGECACHE_USAGE (4*1024)
 
-#if INFO
-#define IPRINTF(_f, _a...) printf(_f , ## _a)
-#else
-#define IPRINTF(_f, _a...) ((void)0)
-#endif
-
-#if DEBUG
-#define DPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
-#else
-#define DPRINTF(_f, _a...) ((void)0)
-#endif
-
-#if PROGRESS
-#define PPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
-#else
-#define PPRINTF(_f, _a...)
-#endif
+struct xc_interface {
+    int fd;
+    xentoollog_logger *error_handler,   *error_handler_tofree;
+    xentoollog_logger *dombuild_logger, *dombuild_logger_tofree;
+    struct xc_error last_error; /* for xc_get_last_error */
+    FILE *dombuild_logger_file;
+    const char *currently_progress_reporting;
+};
 
 char *safe_strerror(int errcode);
-void xc_set_error(int code, const char *fmt, ...);
-
-#define ERROR(_m, _a...)  xc_set_error(XC_INTERNAL_ERROR, _m , ## _a )
-#define PERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m " (%d = %s)", \
-                                       ## _a , errno, safe_strerror(errno))
+void xc_report_error(xc_interface *xch, int code, const char *fmt, ...);
+void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
+                int code, const char *fmt, va_list args)
+     __attribute__((format(printf,5,0)));
+void xc_report(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
+               int code, const char *fmt, ...)
+     __attribute__((format(printf,5,6)));
+
+void xc_report_progress_start(xc_interface *xch, const char *doing,
+                              unsigned long total);
+void xc_report_progress_step(xc_interface *xch,
+                             unsigned long done, unsigned long total);
+
+/* anamorphic macros:  struct xc_interface *xch  must be in scope */
+
+#define IPRINTF(_f, _a...) xc_report(xch, xch->error_handler, XTL_INFO,0, _f , 
## _a)
+#define DPRINTF(_f, _a...) xc_report(xch, xch->error_handler, XTL_DETAIL,0, _f 
, ## _a)
+
+#define ERROR(_m, _a...)  xc_report_error(xch,XC_INTERNAL_ERROR,_m , ## _a )
+#define PERROR(_m, _a...) xc_report_error(xch,XC_INTERNAL_ERROR,_m \
+                  " (%d = %s)", ## _a , errno, safe_strerror(errno))
 
 void *xc_memalign(size_t alignment, size_t size);
 
@@ -93,9 +97,9 @@ static inline void safe_munlock(const vo
     errno = saved_errno;
 }
 
-int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall);
-
-static inline int do_xen_version(int xc_handle, int cmd, void *dest)
+int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall);
+
+static inline int do_xen_version(xc_interface *xch, int cmd, void *dest)
 {
     DECLARE_HYPERCALL;
 
@@ -103,10 +107,10 @@ static inline int do_xen_version(int xc_
     hypercall.arg[0] = (unsigned long) cmd;
     hypercall.arg[1] = (unsigned long) dest;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.