debuggers.hg

changeset 22624:60782cefa154

libxc: convert evtchn interfaces to use an opaque handle type

This makes the interface consistent with the changes made to the main
interface in 21483:779c0ef9682c.

Also fix some references to "struct xc_interface" which should have
been simply "xc_interface" in tools/xenpaging, and update QEMU_TAG to
pull in the corresponding qemu change.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Thu Dec 23 15:25:57 2010 +0000 (2010-12-23)
parents a3ace503d04b
children 9a1a0f77259e
files Config.mk tools/console/daemon/io.c tools/fs-back/fs-backend.c tools/fs-back/fs-backend.h tools/libxc/xc_dom_elfloader.c tools/libxc/xc_domain_restore.c tools/libxc/xc_linux.c tools/libxc/xc_minios.c tools/libxc/xc_netbsd.c tools/libxc/xc_private.c tools/libxc/xc_private.h tools/libxc/xc_solaris.c tools/libxc/xc_suspend.c tools/libxc/xenctrl.h tools/libxc/xenguest.h tools/libxl/libxl_dom.c tools/misc/xen-hptool.c tools/python/xen/lowlevel/checkpoint/checkpoint.h tools/python/xen/lowlevel/checkpoint/libcheckpoint.c tools/xcutils/xc_save.c tools/xenmon/xenbaked.c tools/xenpaging/mem_event.h tools/xenpaging/policy_default.c tools/xenpaging/xc.c tools/xenpaging/xc.h tools/xenpaging/xenpaging.c tools/xenstore/xenstored_core.c tools/xenstore/xenstored_domain.c tools/xenstore/xenstored_domain.h tools/xentrace/xentrace.c
line diff
     1.1 --- a/Config.mk	Thu Dec 23 15:08:21 2010 +0000
     1.2 +++ b/Config.mk	Thu Dec 23 15:25:57 2010 +0000
     1.3 @@ -185,9 +185,9 @@ endif
     1.4  # CONFIG_QEMU ?= ../qemu-xen.git
     1.5  CONFIG_QEMU ?= $(QEMU_REMOTE)
     1.6  
     1.7 -QEMU_TAG ?= 47a25c461b6b5ab67397f7bbb209590a0839e213
     1.8 -# Thu Dec 16 15:50:06 2010 +0000
     1.9 -# stubdom: fix stubdom build following dd9d12dc
    1.10 +QEMU_TAG ?= b7754ca4a80e9a53b848796c860d19d6fa7a6d08
    1.11 +# Thu Dec 23 15:21:52 2010 +0000
    1.12 +# qemu-xen: update for libxc evtchn interface change
    1.13  
    1.14  # Optional components
    1.15  XENSTAT_XENTOP     ?= y
     2.1 --- a/tools/console/daemon/io.c	Thu Dec 23 15:08:21 2010 +0000
     2.2 +++ b/tools/console/daemon/io.c	Thu Dec 23 15:25:57 2010 +0000
     2.3 @@ -68,7 +68,7 @@ static int log_time_guest_needts = 1;
     2.4  static int log_hv_fd = -1;
     2.5  static evtchn_port_or_error_t log_hv_evtchn = -1;
     2.6  static xc_interface *xch; /* why does xenconsoled have two xc handles ? */
     2.7 -static int xce_handle = -1;
     2.8 +static xc_evtchn *xce_handle = NULL;
     2.9  
    2.10  struct buffer {
    2.11  	char *data;
    2.12 @@ -90,7 +90,7 @@ struct domain {
    2.13  	int ring_ref;
    2.14  	evtchn_port_or_error_t local_port;
    2.15  	evtchn_port_or_error_t remote_port;
    2.16 -	int xce_handle;
    2.17 +	xc_evtchn *xce_handle;
    2.18  	struct xencons_interface *interface;
    2.19  	int event_count;
    2.20  	long long next_period;
    2.21 @@ -547,13 +547,13 @@ static int domain_create_ring(struct dom
    2.22  
    2.23  	dom->local_port = -1;
    2.24  	dom->remote_port = -1;
    2.25 -	if (dom->xce_handle != -1)
    2.26 +	if (dom->xce_handle != NULL)
    2.27  		xc_evtchn_close(dom->xce_handle);
    2.28  
    2.29  	/* Opening evtchn independently for each console is a bit
    2.30  	 * wasteful, but that's how the code is structured... */
    2.31 -	dom->xce_handle = xc_evtchn_open();
    2.32 -	if (dom->xce_handle == -1) {
    2.33 +	dom->xce_handle = xc_evtchn_open(NULL, 0);
    2.34 +	if (dom->xce_handle == NULL) {
    2.35  		err = errno;
    2.36  		goto out;
    2.37  	}
    2.38 @@ -564,7 +564,7 @@ static int domain_create_ring(struct dom
    2.39  	if (rc == -1) {
    2.40  		err = errno;
    2.41  		xc_evtchn_close(dom->xce_handle);
    2.42 -		dom->xce_handle = -1;
    2.43 +		dom->xce_handle = NULL;
    2.44  		goto out;
    2.45  	}
    2.46  	dom->local_port = rc;
    2.47 @@ -574,7 +574,7 @@ static int domain_create_ring(struct dom
    2.48  		if (!domain_create_tty(dom)) {
    2.49  			err = errno;
    2.50  			xc_evtchn_close(dom->xce_handle);
    2.51 -			dom->xce_handle = -1;
    2.52 +			dom->xce_handle = NULL;
    2.53  			dom->local_port = -1;
    2.54  			dom->remote_port = -1;
    2.55  			goto out;
    2.56 @@ -655,7 +655,7 @@ static struct domain *create_domain(int 
    2.57  	dom->local_port = -1;
    2.58  	dom->remote_port = -1;
    2.59  	dom->interface = NULL;
    2.60 -	dom->xce_handle = -1;
    2.61 +	dom->xce_handle = NULL;
    2.62  
    2.63  	if (!watch_domain(dom, true))
    2.64  		goto out;
    2.65 @@ -722,9 +722,9 @@ static void shutdown_domain(struct domai
    2.66  	if (d->interface != NULL)
    2.67  		munmap(d->interface, getpagesize());
    2.68  	d->interface = NULL;
    2.69 -	if (d->xce_handle != -1)
    2.70 +	if (d->xce_handle != NULL)
    2.71  		xc_evtchn_close(d->xce_handle);
    2.72 -	d->xce_handle = -1;
    2.73 +	d->xce_handle = NULL;
    2.74  }
    2.75  
    2.76  void enum_domains(void)
    2.77 @@ -933,8 +933,8 @@ void handle_io(void)
    2.78  			      errno, strerror(errno));
    2.79  			goto out;
    2.80  		}
    2.81 -		xce_handle = xc_evtchn_open();
    2.82 -		if (xce_handle == -1) {
    2.83 +		xce_handle = xc_evtchn_open(NULL, 0);
    2.84 +		if (xce_handle == NULL) {
    2.85  			dolog(LOG_ERR, "Failed to open xce handle: %d (%s)",
    2.86  			      errno, strerror(errno));
    2.87  			goto out;
    2.88 @@ -994,7 +994,7 @@ void handle_io(void)
    2.89  				if (!next_timeout ||
    2.90  				    d->next_period < next_timeout)
    2.91  					next_timeout = d->next_period;
    2.92 -			} else if (d->xce_handle != -1) {
    2.93 +			} else if (d->xce_handle != NULL) {
    2.94  				if (discard_overflowed_data ||
    2.95  				    !d->buffer.max_capacity ||
    2.96  				    d->buffer.size < d->buffer.max_capacity) {
    2.97 @@ -1055,7 +1055,7 @@ void handle_io(void)
    2.98  		for (d = dom_head; d; d = n) {
    2.99  			n = d->next;
   2.100  			if (d->event_count < RATE_LIMIT_ALLOWANCE) {
   2.101 -				if (d->xce_handle != -1 &&
   2.102 +				if (d->xce_handle != NULL &&
   2.103  				    FD_ISSET(xc_evtchn_fd(d->xce_handle),
   2.104  					     &readfds))
   2.105  					handle_ring_read(d);
   2.106 @@ -1083,9 +1083,9 @@ void handle_io(void)
   2.107  		xc_interface_close(xch);
   2.108  		xch = 0;
   2.109  	}
   2.110 -	if (xce_handle != -1) {
   2.111 +	if (xce_handle != NULL) {
   2.112  		xc_evtchn_close(xce_handle);
   2.113 -		xce_handle = -1;
   2.114 +		xce_handle = NULL;
   2.115  	}
   2.116  	log_hv_evtchn = -1;
   2.117  }
     3.1 --- a/tools/fs-back/fs-backend.c	Thu Dec 23 15:08:21 2010 +0000
     3.2 +++ b/tools/fs-back/fs-backend.c	Thu Dec 23 15:25:57 2010 +0000
     3.3 @@ -228,9 +228,9 @@ static void handle_connection(int fronte
     3.4          FS_DEBUG("ERROR: failed to write backend node on xenbus\n");
     3.5          goto error;
     3.6      }
     3.7 -    mount->evth = -1;
     3.8 -    mount->evth = xc_evtchn_open(); 
     3.9 -    if (mount->evth < 0) {
    3.10 +    mount->evth = NULL;
    3.11 +    mount->evth = xc_evtchn_open(NULL, 0);
    3.12 +    if (mount->evth == NULL) {
    3.13          FS_DEBUG("ERROR: Couldn't open evtchn!\n");
    3.14          goto error;
    3.15      }
    3.16 @@ -289,7 +289,7 @@ error:
    3.17          xc_gnttab_close(mount->xch, mount->gnth);
    3.18      if (mount->local_evtchn > 0)
    3.19          xc_evtchn_unbind(mount->evth, mount->local_evtchn);
    3.20 -    if (mount->evth > 0)
    3.21 +    if (mount->evth != NULL)
    3.22          xc_evtchn_close(mount->evth);
    3.23      if (mount->xch)
    3.24          xc_interface_close(mount->xch);
    3.25 @@ -343,8 +343,8 @@ static void await_connections(void)
    3.26                      FD_SET(tfd, &fds);
    3.27                      ret = select(tfd + 1, &fds, NULL, NULL, &timeout);
    3.28                      if (ret < 0) {
    3.29 -                        FS_DEBUG("fd %d is bogus, closing the related connection\n", tfd);
    3.30 -                        pointer->evth = fd;
    3.31 +                        FS_DEBUG("fd %d is bogus, closing the related connection %p\n", tfd, pointer->evth);
    3.32 +                        /*pointer->evth = fd;*/
    3.33                          terminate_mount_request(pointer);
    3.34                          continue;
    3.35                      }
     4.1 --- a/tools/fs-back/fs-backend.h	Thu Dec 23 15:08:21 2010 +0000
     4.2 +++ b/tools/fs-back/fs-backend.h	Thu Dec 23 15:25:57 2010 +0000
     4.3 @@ -45,7 +45,7 @@ struct fs_mount
     4.4      grant_ref_t grefs[MAX_RING_SIZE];
     4.5      evtchn_port_t remote_evtchn;
     4.6      xc_interface *xch; /* just for error logging, so a dummy */
     4.7 -    int evth;                         /* Handle to the event channel */
     4.8 +    xc_evtchn *evth;               /* Handle to the event channel */
     4.9      evtchn_port_t local_evtchn;
    4.10      int gnth;
    4.11      int shared_ring_size;             /* in pages */
     5.1 --- a/tools/libxc/xc_dom_elfloader.c	Thu Dec 23 15:08:21 2010 +0000
     5.2 +++ b/tools/libxc/xc_dom_elfloader.c	Thu Dec 23 15:25:57 2010 +0000
     5.3 @@ -35,7 +35,7 @@
     5.4  
     5.5  static void log_callback(struct elf_binary *elf, void *caller_data,
     5.6                           int iserr, const char *fmt, va_list al) {
     5.7 -    struct xc_interface *xch = caller_data;
     5.8 +    xc_interface *xch = caller_data;
     5.9  
    5.10      xc_reportv(xch,
    5.11            xch->dombuild_logger ? xch->dombuild_logger : xch->error_handler,
    5.12 @@ -44,7 +44,7 @@ static void log_callback(struct elf_bina
    5.13                         fmt, al);
    5.14  }
    5.15  
    5.16 -void xc_elf_set_logfile(struct xc_interface *xch, struct elf_binary *elf,
    5.17 +void xc_elf_set_logfile(xc_interface *xch, struct elf_binary *elf,
    5.18                          int verbose) {
    5.19      elf_set_log(elf, log_callback, xch, verbose);
    5.20  }
     6.1 --- a/tools/libxc/xc_domain_restore.c	Thu Dec 23 15:08:21 2010 +0000
     6.2 +++ b/tools/libxc/xc_domain_restore.c	Thu Dec 23 15:25:57 2010 +0000
     6.3 @@ -49,7 +49,7 @@ struct restore_ctx {
     6.4  #define HEARTBEAT_MS 1000
     6.5  
     6.6  #ifndef __MINIOS__
     6.7 -static ssize_t rdexact(struct xc_interface *xch, struct restore_ctx *ctx,
     6.8 +static ssize_t rdexact(xc_interface *xch, struct restore_ctx *ctx,
     6.9                         int fd, void* buf, size_t size)
    6.10  {
    6.11      size_t offset = 0;
     7.1 --- a/tools/libxc/xc_linux.c	Thu Dec 23 15:08:21 2010 +0000
     7.2 +++ b/tools/libxc/xc_linux.c	Thu Dec 23 15:25:57 2010 +0000
     7.3 @@ -68,9 +68,9 @@ int xc_interface_open_core(xc_interface 
     7.4      return -1;
     7.5  }
     7.6  
     7.7 -int xc_interface_close_core(xc_interface *xch, int fd)
     7.8 +int xc_interface_close_core(xc_interface *xch)
     7.9  {
    7.10 -    return close(fd);
    7.11 +    return close(xch->fd);
    7.12  }
    7.13  
    7.14  static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom,
    7.15 @@ -327,42 +327,42 @@ int do_xen_hypercall(xc_interface *xch, 
    7.16  
    7.17  #define DEVXEN "/dev/xen/"
    7.18  
    7.19 -int xc_evtchn_open(void)
    7.20 +int xc_evtchn_open_core(xc_evtchn *xce)
    7.21  {
    7.22      return open(DEVXEN "evtchn", O_RDWR);
    7.23  }
    7.24  
    7.25 -int xc_evtchn_close(int xce_handle)
    7.26 +int xc_evtchn_close_core(xc_evtchn *xce)
    7.27  {
    7.28 -    return close(xce_handle);
    7.29 +    return close(xce->fd);
    7.30  }
    7.31  
    7.32 -int xc_evtchn_fd(int xce_handle)
    7.33 +int xc_evtchn_fd(xc_evtchn *xce)
    7.34  {
    7.35 -    return xce_handle;
    7.36 +    return xce->fd;
    7.37  }
    7.38  
    7.39 -int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
    7.40 +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
    7.41  {
    7.42      struct ioctl_evtchn_notify notify;
    7.43  
    7.44      notify.port = port;
    7.45  
    7.46 -    return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, &notify);
    7.47 +    return ioctl(xce->fd, IOCTL_EVTCHN_NOTIFY, &notify);
    7.48  }
    7.49  
    7.50  evtchn_port_or_error_t
    7.51 -xc_evtchn_bind_unbound_port(int xce_handle, int domid)
    7.52 +xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid)
    7.53  {
    7.54      struct ioctl_evtchn_bind_unbound_port bind;
    7.55  
    7.56      bind.remote_domain = domid;
    7.57  
    7.58 -    return ioctl(xce_handle, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
    7.59 +    return ioctl(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
    7.60  }
    7.61  
    7.62  evtchn_port_or_error_t
    7.63 -xc_evtchn_bind_interdomain(int xce_handle, int domid,
    7.64 +xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
    7.65                             evtchn_port_t remote_port)
    7.66  {
    7.67      struct ioctl_evtchn_bind_interdomain bind;
    7.68 @@ -370,42 +370,42 @@ xc_evtchn_bind_interdomain(int xce_handl
    7.69      bind.remote_domain = domid;
    7.70      bind.remote_port = remote_port;
    7.71  
    7.72 -    return ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
    7.73 +    return ioctl(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
    7.74  }
    7.75  
    7.76  evtchn_port_or_error_t
    7.77 -xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
    7.78 +xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq)
    7.79  {
    7.80      struct ioctl_evtchn_bind_virq bind;
    7.81  
    7.82      bind.virq = virq;
    7.83  
    7.84 -    return ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind);
    7.85 +    return ioctl(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
    7.86  }
    7.87  
    7.88 -int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
    7.89 +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
    7.90  {
    7.91      struct ioctl_evtchn_unbind unbind;
    7.92  
    7.93      unbind.port = port;
    7.94  
    7.95 -    return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind);
    7.96 +    return ioctl(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind);
    7.97  }
    7.98  
    7.99  evtchn_port_or_error_t
   7.100 -xc_evtchn_pending(int xce_handle)
   7.101 +xc_evtchn_pending(xc_evtchn *xce)
   7.102  {
   7.103      evtchn_port_t port;
   7.104  
   7.105 -    if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 )
   7.106 +    if ( read_exact(xce->fd, (char *)&port, sizeof(port)) == -1 )
   7.107          return -1;
   7.108  
   7.109      return port;
   7.110  }
   7.111  
   7.112 -int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
   7.113 +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
   7.114  {
   7.115 -    return write_exact(xce_handle, (char *)&port, sizeof(port));
   7.116 +    return write_exact(xce->fd, (char *)&port, sizeof(port));
   7.117  }
   7.118  
   7.119  /* Optionally flush file to disk and discard page cache */
     8.1 --- a/tools/libxc/xc_minios.c	Thu Dec 23 15:08:21 2010 +0000
     8.2 +++ b/tools/libxc/xc_minios.c	Thu Dec 23 15:25:57 2010 +0000
     8.3 @@ -44,6 +44,9 @@ void minios_interface_close_fd(int fd);
     8.4  void minios_evtchn_close_fd(int fd);
     8.5  void minios_gnttab_close_fd(int fd);
     8.6  
     8.7 +extern void minios_interface_close_fd(int fd);
     8.8 +extern void minios_evtchn_close_fd(int fd);
     8.9 +
    8.10  extern struct wait_queue_head event_queue;
    8.11  
    8.12  int xc_interface_open_core(xc_interface *xch)
    8.13 @@ -51,9 +54,9 @@ int xc_interface_open_core(xc_interface 
    8.14      return alloc_fd(FTYPE_XC);
    8.15  }
    8.16  
    8.17 -int xc_interface_close_core(xc_interface *xch, int fd)
    8.18 +int xc_interface_close_core(xc_interface *xch)
    8.19  {
    8.20 -    return close(fd);
    8.21 +    return close(xch->fd);
    8.22  }
    8.23  
    8.24  void minios_interface_close_fd(int fd)
    8.25 @@ -169,7 +172,7 @@ int do_xen_hypercall(xc_interface *xch, 
    8.26      return call.result;
    8.27  }
    8.28  
    8.29 -int xc_evtchn_open(void)
    8.30 +int xc_evtchn_open_core(xc_evtchn *xce)
    8.31  {
    8.32      int fd = alloc_fd(FTYPE_EVTCHN), i;
    8.33      for (i = 0; i < MAX_EVTCHN_PORTS; i++) {
    8.34 @@ -180,9 +183,9 @@ int xc_evtchn_open(void)
    8.35      return fd;
    8.36  }
    8.37  
    8.38 -int xc_evtchn_close(int xce_handle)
    8.39 +int xc_evtchn_close_core(xc_evtchn *xce)
    8.40  {
    8.41 -    return close(xce_handle);
    8.42 +    return close(xce->fd);
    8.43  }
    8.44  
    8.45  void minios_evtchn_close_fd(int fd)
    8.46 @@ -194,12 +197,12 @@ void minios_evtchn_close_fd(int fd)
    8.47      files[fd].type = FTYPE_NONE;
    8.48  }
    8.49  
    8.50 -int xc_evtchn_fd(int xce_handle)
    8.51 +int xc_evtchn_fd(xc_evtchn *xce)
    8.52  {
    8.53 -    return xce_handle;
    8.54 +    return xce->fd;
    8.55  }
    8.56  
    8.57 -int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
    8.58 +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
    8.59  {
    8.60      int ret;
    8.61  
    8.62 @@ -213,144 +216,144 @@ int xc_evtchn_notify(int xce_handle, evt
    8.63  }
    8.64  
    8.65  /* XXX Note: This is not threadsafe */
    8.66 -static int port_alloc(int xce_handle) {
    8.67 +static int port_alloc(int fd) {
    8.68      int i;
    8.69      for (i= 0; i < MAX_EVTCHN_PORTS; i++)
    8.70 -	if (files[xce_handle].evtchn.ports[i].port == -1)
    8.71 +	if (files[fd].evtchn.ports[i].port == -1)
    8.72  	    break;
    8.73      if (i == MAX_EVTCHN_PORTS) {
    8.74  	printf("Too many ports in xc handle\n");
    8.75  	errno = EMFILE;
    8.76  	return -1;
    8.77      }
    8.78 -    files[xce_handle].evtchn.ports[i].pending = 0;
    8.79 +    files[fd].evtchn.ports[i].pending = 0;
    8.80      return i;
    8.81  }
    8.82  
    8.83  static void evtchn_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
    8.84  {
    8.85 -    int xce_handle = (intptr_t) data;
    8.86 +    int fd = (int)(intptr_t)data;
    8.87      int i;
    8.88 -    assert(files[xce_handle].type == FTYPE_EVTCHN);
    8.89 +    assert(files[fd].type == FTYPE_EVTCHN);
    8.90      mask_evtchn(port);
    8.91      for (i= 0; i < MAX_EVTCHN_PORTS; i++)
    8.92 -	if (files[xce_handle].evtchn.ports[i].port == port)
    8.93 +	if (files[fd].evtchn.ports[i].port == port)
    8.94  	    break;
    8.95      if (i == MAX_EVTCHN_PORTS) {
    8.96 -	printk("Unknown port for handle %d\n", xce_handle);
    8.97 +	printk("Unknown port for handle %d\n", fd);
    8.98  	return;
    8.99      }
   8.100 -    files[xce_handle].evtchn.ports[i].pending = 1;
   8.101 -    files[xce_handle].read = 1;
   8.102 +    files[fd].evtchn.ports[i].pending = 1;
   8.103 +    files[fd].read = 1;
   8.104      wake_up(&event_queue);
   8.105  }
   8.106  
   8.107 -evtchn_port_or_error_t xc_evtchn_bind_unbound_port(int xce_handle, int domid)
   8.108 +evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid)
   8.109  {
   8.110      int ret, i;
   8.111      evtchn_port_t port;
   8.112  
   8.113      assert(get_current() == main_thread);
   8.114 -    i = port_alloc(xce_handle);
   8.115 +    i = port_alloc(xce->fd);
   8.116      if (i == -1)
   8.117  	return -1;
   8.118  
   8.119      printf("xc_evtchn_bind_unbound_port(%d)", domid);
   8.120 -    ret = evtchn_alloc_unbound(domid, evtchn_handler, (void*)(intptr_t)xce_handle, &port);
   8.121 +    ret = evtchn_alloc_unbound(domid, evtchn_handler, (void*)(intptr_t)xce->fd, &port);
   8.122      printf(" = %d\n", ret);
   8.123  
   8.124      if (ret < 0) {
   8.125  	errno = -ret;
   8.126  	return -1;
   8.127      }
   8.128 -    files[xce_handle].evtchn.ports[i].bound = 1;
   8.129 -    files[xce_handle].evtchn.ports[i].port = port;
   8.130 +    files[xce->fd].evtchn.ports[i].bound = 1;
   8.131 +    files[xce->fd].evtchn.ports[i].port = port;
   8.132      unmask_evtchn(port);
   8.133      return port;
   8.134  }
   8.135  
   8.136 -evtchn_port_or_error_t xc_evtchn_bind_interdomain(int xce_handle, int domid,
   8.137 +evtchn_port_or_error_t xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
   8.138      evtchn_port_t remote_port)
   8.139  {
   8.140      evtchn_port_t local_port;
   8.141      int ret, i;
   8.142  
   8.143      assert(get_current() == main_thread);
   8.144 -    i = port_alloc(xce_handle);
   8.145 +    i = port_alloc(xce->fd);
   8.146      if (i == -1)
   8.147  	return -1;
   8.148  
   8.149      printf("xc_evtchn_bind_interdomain(%d, %"PRId32")", domid, remote_port);
   8.150 -    ret = evtchn_bind_interdomain(domid, remote_port, evtchn_handler, (void*)(intptr_t)xce_handle, &local_port);
   8.151 +    ret = evtchn_bind_interdomain(domid, remote_port, evtchn_handler, (void*)(intptr_t)xce->fd, &local_port);
   8.152      printf(" = %d\n", ret);
   8.153  
   8.154      if (ret < 0) {
   8.155  	errno = -ret;
   8.156  	return -1;
   8.157      }
   8.158 -    files[xce_handle].evtchn.ports[i].bound = 1;
   8.159 -    files[xce_handle].evtchn.ports[i].port = local_port;
   8.160 +    files[xce->fd].evtchn.ports[i].bound = 1;
   8.161 +    files[xce->fd].evtchn.ports[i].port = local_port;
   8.162      unmask_evtchn(local_port);
   8.163      return local_port;
   8.164  }
   8.165  
   8.166 -int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
   8.167 +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
   8.168  {
   8.169      int i;
   8.170      for (i = 0; i < MAX_EVTCHN_PORTS; i++)
   8.171 -	if (files[xce_handle].evtchn.ports[i].port == port) {
   8.172 -	    files[xce_handle].evtchn.ports[i].port = -1;
   8.173 +	if (files[xce->fd].evtchn.ports[i].port == port) {
   8.174 +	    files[xce->fd].evtchn.ports[i].port = -1;
   8.175  	    break;
   8.176  	}
   8.177      if (i == MAX_EVTCHN_PORTS) {
   8.178 -	printf("Warning: couldn't find port %"PRId32" for xc handle %x\n", port, xce_handle);
   8.179 +	printf("Warning: couldn't find port %"PRId32" for xc handle %x\n", port, xce->fd);
   8.180  	errno = -EINVAL;
   8.181  	return -1;
   8.182      }
   8.183 -    files[xce_handle].evtchn.ports[i].bound = 0;
   8.184 +    files[xce->fd].evtchn.ports[i].bound = 0;
   8.185      unbind_evtchn(port);
   8.186      return 0;
   8.187  }
   8.188  
   8.189 -evtchn_port_or_error_t xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
   8.190 +evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq)
   8.191  {
   8.192      evtchn_port_t port;
   8.193      int i;
   8.194  
   8.195      assert(get_current() == main_thread);
   8.196 -    i = port_alloc(xce_handle);
   8.197 +    i = port_alloc(xce->fd);
   8.198      if (i == -1)
   8.199  	return -1;
   8.200  
   8.201      printf("xc_evtchn_bind_virq(%d)", virq);
   8.202 -    port = bind_virq(virq, evtchn_handler, (void*)(intptr_t)xce_handle);
   8.203 +    port = bind_virq(virq, evtchn_handler, (void*)(intptr_t)xce->fd);
   8.204  
   8.205      if (port < 0) {
   8.206  	errno = -port;
   8.207  	return -1;
   8.208      }
   8.209 -    files[xce_handle].evtchn.ports[i].bound = 1;
   8.210 -    files[xce_handle].evtchn.ports[i].port = port;
   8.211 +    files[xce->fd].evtchn.ports[i].bound = 1;
   8.212 +    files[xce->fd].evtchn.ports[i].port = port;
   8.213      unmask_evtchn(port);
   8.214      return port;
   8.215  }
   8.216  
   8.217 -evtchn_port_or_error_t xc_evtchn_pending(int xce_handle)
   8.218 +evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce)
   8.219  {
   8.220      int i;
   8.221      unsigned long flags;
   8.222      evtchn_port_t ret = -1;
   8.223  
   8.224      local_irq_save(flags);
   8.225 -    files[xce_handle].read = 0;
   8.226 +    files[xce->fd].read = 0;
   8.227      for (i = 0; i < MAX_EVTCHN_PORTS; i++) {
   8.228 -        evtchn_port_t port = files[xce_handle].evtchn.ports[i].port;
   8.229 -        if (port != -1 && files[xce_handle].evtchn.ports[i].pending) {
   8.230 +        evtchn_port_t port = files[xce->fd].evtchn.ports[i].port;
   8.231 +        if (port != -1 && files[xce->fd].evtchn.ports[i].pending) {
   8.232              if (ret == -1) {
   8.233                  ret = port;
   8.234 -                files[xce_handle].evtchn.ports[i].pending = 0;
   8.235 +                files[xce->fd].evtchn.ports[i].pending = 0;
   8.236              } else {
   8.237 -                files[xce_handle].read = 1;
   8.238 +                files[xce->fd].read = 1;
   8.239                  break;
   8.240              }
   8.241          }
   8.242 @@ -359,7 +362,7 @@ evtchn_port_or_error_t xc_evtchn_pending
   8.243      return ret;
   8.244  }
   8.245  
   8.246 -int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
   8.247 +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
   8.248  {
   8.249      unmask_evtchn(port);
   8.250      return 0;
     9.1 --- a/tools/libxc/xc_netbsd.c	Thu Dec 23 15:08:21 2010 +0000
     9.2 +++ b/tools/libxc/xc_netbsd.c	Thu Dec 23 15:25:57 2010 +0000
     9.3 @@ -60,9 +60,9 @@ int xc_interface_open_core(xc_interface 
     9.4      return -1;
     9.5  }
     9.6  
     9.7 -int xc_interface_close_core(xc_interface *xch, int fd)
     9.8 +int xc_interface_close_core(xc_interface *xch)
     9.9  {
    9.10 -    return close(fd);
    9.11 +    return close(xch->fd);
    9.12  }
    9.13  
    9.14  void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
    9.15 @@ -181,39 +181,39 @@ int do_xen_hypercall(xc_interface *xch, 
    9.16  
    9.17  #define EVTCHN_DEV_NAME  "/dev/xenevt"
    9.18  
    9.19 -int xc_evtchn_open(void)
    9.20 +int xc_evtchn_open_core(xc_evtchn *xce)
    9.21  {
    9.22      return open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR);
    9.23  }
    9.24  
    9.25 -int xc_evtchn_close(int xce_handle)
    9.26 +int xc_evtchn_close_core(xc_evtchn *xce)
    9.27  {
    9.28 -    return close(xce_handle);
    9.29 +    return close(xce->fd);
    9.30  }
    9.31  
    9.32 -int xc_evtchn_fd(int xce_handle)
    9.33 +int xc_evtchn_fd(xc_evtchn *xce)
    9.34  {
    9.35 -    return xce_handle;
    9.36 +    return xce->fd;
    9.37  }
    9.38  
    9.39 -int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
    9.40 +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
    9.41  {
    9.42      struct ioctl_evtchn_notify notify;
    9.43  
    9.44      notify.port = port;
    9.45  
    9.46 -    return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, &notify);
    9.47 +    return ioctl(xce->fd, IOCTL_EVTCHN_NOTIFY, &notify);
    9.48  }
    9.49  
    9.50  evtchn_port_or_error_t
    9.51 -xc_evtchn_bind_unbound_port(int xce_handle, int domid)
    9.52 +xc_evtchn_bind_unbound_port(xc_evtchn * xce, int domid)
    9.53  {
    9.54      struct ioctl_evtchn_bind_unbound_port bind;
    9.55      int ret;
    9.56  
    9.57      bind.remote_domain = domid;
    9.58  
    9.59 -    ret = ioctl(xce_handle, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
    9.60 +    ret = ioctl(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
    9.61      if (ret == 0)
    9.62  	return bind.port;
    9.63      else
    9.64 @@ -221,7 +221,7 @@ xc_evtchn_bind_unbound_port(int xce_hand
    9.65  }
    9.66  
    9.67  evtchn_port_or_error_t
    9.68 -xc_evtchn_bind_interdomain(int xce_handle, int domid,
    9.69 +xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
    9.70                             evtchn_port_t remote_port)
    9.71  {
    9.72      struct ioctl_evtchn_bind_interdomain bind;
    9.73 @@ -230,31 +230,31 @@ xc_evtchn_bind_interdomain(int xce_handl
    9.74      bind.remote_domain = domid;
    9.75      bind.remote_port = remote_port;
    9.76  
    9.77 -    ret = ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
    9.78 +    ret = ioctl(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
    9.79      if (ret == 0)
    9.80  	return bind.port;
    9.81      else
    9.82  	return -1;
    9.83  }
    9.84  
    9.85 -int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
    9.86 +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
    9.87  {
    9.88      struct ioctl_evtchn_unbind unbind;
    9.89  
    9.90      unbind.port = port;
    9.91  
    9.92 -    return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind);
    9.93 +    return ioctl(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind);
    9.94  }
    9.95  
    9.96  evtchn_port_or_error_t
    9.97 -xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
    9.98 +xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq)
    9.99  {
   9.100      struct ioctl_evtchn_bind_virq bind;
   9.101      int err;
   9.102  
   9.103      bind.virq = virq;
   9.104  
   9.105 -    err = ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind);
   9.106 +    err = ioctl(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
   9.107      if (err)
   9.108  	return -1;
   9.109      else
   9.110 @@ -262,19 +262,19 @@ xc_evtchn_bind_virq(int xce_handle, unsi
   9.111  }
   9.112  
   9.113  evtchn_port_or_error_t
   9.114 -xc_evtchn_pending(int xce_handle)
   9.115 +xc_evtchn_pending(xc_evtchn *xce)
   9.116  {
   9.117      evtchn_port_t port;
   9.118  
   9.119 -    if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 )
   9.120 +    if ( read_exact(xce->fd, (char *)&port, sizeof(port)) == -1 )
   9.121          return -1;
   9.122  
   9.123      return port;
   9.124  }
   9.125  
   9.126 -int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
   9.127 +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
   9.128  {
   9.129 -    return write_exact(xce_handle, (char *)&port, sizeof(port));
   9.130 +    return write_exact(xce->fd, (char *)&port, sizeof(port));
   9.131  }
   9.132  
   9.133  /* Optionally flush file to disk and discard page cache */
    10.1 --- a/tools/libxc/xc_private.c	Thu Dec 23 15:08:21 2010 +0000
    10.2 +++ b/tools/libxc/xc_private.c	Thu Dec 23 15:25:57 2010 +0000
    10.3 @@ -27,11 +27,15 @@
    10.4  #include <pthread.h>
    10.5  #include <assert.h>
    10.6  
    10.7 -xc_interface *xc_interface_open(xentoollog_logger *logger,
    10.8 -                                xentoollog_logger *dombuild_logger,
    10.9 -                                unsigned open_flags) {
   10.10 -    xc_interface xch_buf, *xch = &xch_buf;
   10.11 +static struct xc_interface_core *xc_interface_open_common(xentoollog_logger *logger,
   10.12 +                                              xentoollog_logger *dombuild_logger,
   10.13 +                                              unsigned open_flags,
   10.14 +                                              enum xc_interface_type type,
   10.15 +                                              int (*open_core)(struct xc_interface_core *xch))
   10.16 +{
   10.17 +    struct xc_interface_core xch_buf, *xch = &xch_buf;
   10.18  
   10.19 +    xch->type = type;
   10.20      xch->flags = open_flags;
   10.21      xch->fd = -1;
   10.22      xch->dombuild_logger_file = 0;
   10.23 @@ -57,7 +61,7 @@ xc_interface *xc_interface_open(xentooll
   10.24      *xch = xch_buf;
   10.25  
   10.26      if (!(open_flags & XC_OPENFLAG_DUMMY)) {
   10.27 -        xch->fd = xc_interface_open_core(xch);
   10.28 +        xch->fd = open_core(xch);
   10.29          if (xch->fd < 0)
   10.30              goto err;
   10.31      }
   10.32 @@ -70,7 +74,7 @@ xc_interface *xc_interface_open(xentooll
   10.33      return 0;
   10.34  }
   10.35  
   10.36 -int xc_interface_close(xc_interface *xch)
   10.37 +static int xc_interface_close_common(xc_interface *xch, int (*close_core)(struct xc_interface_core *xch))
   10.38  {
   10.39      int rc = 0;
   10.40  
   10.41 @@ -78,7 +82,7 @@ int xc_interface_close(xc_interface *xch
   10.42      xtl_logger_destroy(xch->error_handler_tofree);
   10.43  
   10.44      if (xch->fd >= 0) {
   10.45 -        rc = xc_interface_close_core(xch, xch->fd);
   10.46 +        rc = close_core(xch);
   10.47          if (rc) PERROR("Could not close hypervisor interface");
   10.48      }
   10.49  
   10.50 @@ -86,6 +90,31 @@ int xc_interface_close(xc_interface *xch
   10.51      return rc;
   10.52  }
   10.53  
   10.54 +xc_interface *xc_interface_open(xentoollog_logger *logger,
   10.55 +                                xentoollog_logger *dombuild_logger,
   10.56 +                                unsigned open_flags)
   10.57 +{
   10.58 +    return xc_interface_open_common(logger, dombuild_logger, open_flags,
   10.59 +                                    XC_INTERFACE_PRIVCMD, &xc_interface_open_core);
   10.60 +}
   10.61 +
   10.62 +int xc_interface_close(xc_interface *xch)
   10.63 +{
   10.64 +    return xc_interface_close_common(xch, &xc_interface_close_core);
   10.65 +}
   10.66 +
   10.67 +xc_evtchn *xc_evtchn_open(xentoollog_logger *logger,
   10.68 +                             unsigned open_flags)
   10.69 +{
   10.70 +    return xc_interface_open_common(logger, NULL, open_flags,
   10.71 +                                    XC_INTERFACE_EVTCHN, &xc_evtchn_open_core);
   10.72 +}
   10.73 +
   10.74 +int xc_evtchn_close(xc_evtchn *xce)
   10.75 +{
   10.76 +    return xc_interface_close_common(xce, &xc_evtchn_close_core);
   10.77 +}
   10.78 +
   10.79  static pthread_key_t errbuf_pkey;
   10.80  static pthread_once_t errbuf_pkey_once = PTHREAD_ONCE_INIT;
   10.81  
    11.1 --- a/tools/libxc/xc_private.h	Thu Dec 23 15:08:21 2010 +0000
    11.2 +++ b/tools/libxc/xc_private.h	Thu Dec 23 15:25:57 2010 +0000
    11.3 @@ -65,7 +65,13 @@
    11.4  */
    11.5  #define MAX_PAGECACHE_USAGE (4*1024)
    11.6  
    11.7 -struct xc_interface {
    11.8 +enum xc_interface_type {
    11.9 +	XC_INTERFACE_PRIVCMD,
   11.10 +	XC_INTERFACE_EVTCHN,
   11.11 +};
   11.12 +
   11.13 +struct xc_interface_core {
   11.14 +    enum xc_interface_type type;
   11.15      int fd;
   11.16      int flags;
   11.17      xentoollog_logger *error_handler,   *error_handler_tofree;
   11.18 @@ -257,8 +263,11 @@ static inline int do_sysctl(xc_interface
   11.19  
   11.20  int do_memory_op(xc_interface *xch, int cmd, void *arg, size_t len);
   11.21  
   11.22 -int xc_interface_open_core(xc_interface *xch); /* returns fd, logs errors */
   11.23 -int xc_interface_close_core(xc_interface *xch, int fd); /* no logging */
   11.24 +int xc_interface_open_core(struct xc_interface_core *xch); /* returns fd, logs errors */
   11.25 +int xc_interface_close_core(struct xc_interface_core *xch); /* no logging */
   11.26 +
   11.27 +int xc_evtchn_open_core(struct xc_interface_core *xce); /* returns fd, logs errors */
   11.28 +int xc_evtchn_close_core(struct xc_interface_core *xce); /* no logging */
   11.29  
   11.30  void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom,
   11.31                              size_t size, int prot, size_t chunksize,
    12.1 --- a/tools/libxc/xc_solaris.c	Thu Dec 23 15:08:21 2010 +0000
    12.2 +++ b/tools/libxc/xc_solaris.c	Thu Dec 23 15:25:57 2010 +0000
    12.3 @@ -167,7 +167,7 @@ int do_xen_hypercall(xc_interface *xch, 
    12.4                        (unsigned long)hypercall);
    12.5  }
    12.6  
    12.7 -int xc_evtchn_open(void)
    12.8 +int xc_evtchn_open_core(xc_evtchn *xce)
    12.9  {
   12.10      int fd;
   12.11  
   12.12 @@ -180,37 +180,37 @@ int xc_evtchn_open(void)
   12.13      return fd;
   12.14  }
   12.15  
   12.16 -int xc_evtchn_close(int xce_handle)
   12.17 +int xc_evtchn_close_core(xc_evtchn *xce)
   12.18  {
   12.19 -    return close(xce_handle);
   12.20 +    return close(xce->fd);
   12.21  }
   12.22  
   12.23 -int xc_evtchn_fd(int xce_handle)
   12.24 +int xc_evtchn_fd(xc_evtchn *xce)
   12.25  {
   12.26 -    return xce_handle;
   12.27 +    return xce->fd;
   12.28  }
   12.29  
   12.30 -int xc_evtchn_notify(int xce_handle, evtchn_port_t port)
   12.31 +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
   12.32  {
   12.33      struct ioctl_evtchn_notify notify;
   12.34  
   12.35      notify.port = port;
   12.36  
   12.37 -    return ioctl(xce_handle, IOCTL_EVTCHN_NOTIFY, &notify);
   12.38 +    return ioctl(xce->fd, IOCTL_EVTCHN_NOTIFY, &notify);
   12.39  }
   12.40  
   12.41  evtchn_port_or_error_t
   12.42 -xc_evtchn_bind_unbound_port(int xce_handle, int domid)
   12.43 +xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid)
   12.44  {
   12.45      struct ioctl_evtchn_bind_unbound_port bind;
   12.46  
   12.47      bind.remote_domain = domid;
   12.48  
   12.49 -    return ioctl(xce_handle, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
   12.50 +    return ioctl(xce->fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
   12.51  }
   12.52  
   12.53  evtchn_port_or_error_t
   12.54 -xc_evtchn_bind_interdomain(int xce_handle, int domid,
   12.55 +xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
   12.56                             evtchn_port_t remote_port)
   12.57  {
   12.58      struct ioctl_evtchn_bind_interdomain bind;
   12.59 @@ -218,42 +218,42 @@ xc_evtchn_bind_interdomain(int xce_handl
   12.60      bind.remote_domain = domid;
   12.61      bind.remote_port = remote_port;
   12.62  
   12.63 -    return ioctl(xce_handle, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
   12.64 +    return ioctl(xce->fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
   12.65  }
   12.66  
   12.67  evtchn_port_or_error_t
   12.68 -xc_evtchn_bind_virq(int xce_handle, unsigned int virq)
   12.69 +xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq)
   12.70  {
   12.71      struct ioctl_evtchn_bind_virq bind;
   12.72  
   12.73      bind.virq = virq;
   12.74  
   12.75 -    return ioctl(xce_handle, IOCTL_EVTCHN_BIND_VIRQ, &bind);
   12.76 +    return ioctl(xce->fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
   12.77  }
   12.78  
   12.79 -int xc_evtchn_unbind(int xce_handle, evtchn_port_t port)
   12.80 +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
   12.81  {
   12.82      struct ioctl_evtchn_unbind unbind;
   12.83  
   12.84      unbind.port = port;
   12.85  
   12.86 -    return ioctl(xce_handle, IOCTL_EVTCHN_UNBIND, &unbind);
   12.87 +    return ioctl(xce->fd, IOCTL_EVTCHN_UNBIND, &unbind);
   12.88  }
   12.89  
   12.90  evtchn_port_or_error_t
   12.91 -xc_evtchn_pending(int xce_handle)
   12.92 +xc_evtchn_pending(xc_evtchn *xce)
   12.93  {
   12.94      evtchn_port_t port;
   12.95  
   12.96 -    if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 )
   12.97 +    if ( read_exact(xce->fd, (char *)&port, sizeof(port)) == -1 )
   12.98          return -1;
   12.99  
  12.100      return port;
  12.101  }
  12.102  
  12.103 -int xc_evtchn_unmask(int xce_handle, evtchn_port_t port)
  12.104 +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
  12.105  {
  12.106 -    return write_exact(xce_handle, (char *)&port, sizeof(port));
  12.107 +    return write_exact(xce->fd, (char *)&port, sizeof(port));
  12.108  }
  12.109  
  12.110  /* Optionally flush file to disk and discard page cache */
    13.1 --- a/tools/libxc/xc_suspend.c	Thu Dec 23 15:08:21 2010 +0000
    13.2 +++ b/tools/libxc/xc_suspend.c	Thu Dec 23 15:25:57 2010 +0000
    13.3 @@ -75,7 +75,7 @@ static int unlock_suspend_event(xc_inter
    13.4      return -EPERM;
    13.5  }
    13.6  
    13.7 -int xc_await_suspend(xc_interface *xch, int xce, int suspend_evtchn)
    13.8 +int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn)
    13.9  {
   13.10      int rc;
   13.11  
   13.12 @@ -94,7 +94,7 @@ int xc_await_suspend(xc_interface *xch, 
   13.13      return 0;
   13.14  }
   13.15  
   13.16 -int xc_suspend_evtchn_release(xc_interface *xch, int xce, int domid, int suspend_evtchn)
   13.17 +int xc_suspend_evtchn_release(xc_interface *xch, xc_evtchn *xce, int domid, int suspend_evtchn)
   13.18  {
   13.19      if (suspend_evtchn >= 0)
   13.20          xc_evtchn_unbind(xce, suspend_evtchn);
   13.21 @@ -102,7 +102,7 @@ int xc_suspend_evtchn_release(xc_interfa
   13.22      return unlock_suspend_event(xch, domid);
   13.23  }
   13.24  
   13.25 -int xc_suspend_evtchn_init(xc_interface *xch, int xce, int domid, int port)
   13.26 +int xc_suspend_evtchn_init(xc_interface *xch, xc_evtchn *xce, int domid, int port)
   13.27  {
   13.28      int rc, suspend_evtchn = -1;
   13.29  
    14.1 --- a/tools/libxc/xenctrl.h	Thu Dec 23 15:08:21 2010 +0000
    14.2 +++ b/tools/libxc/xenctrl.h	Thu Dec 23 15:25:57 2010 +0000
    14.3 @@ -104,7 +104,8 @@
    14.4   * the callback.
    14.5   */
    14.6  
    14.7 -typedef struct xc_interface xc_interface;
    14.8 +typedef struct xc_interface_core xc_interface;
    14.9 +typedef struct xc_interface_core xc_evtchn;
   14.10  typedef enum xc_error_code xc_error_code;
   14.11  
   14.12  
   14.13 @@ -826,38 +827,38 @@ int xc_evtchn_status(xc_interface *xch, 
   14.14   *
   14.15   * Before Xen pre-4.1 this function would sometimes report errors with perror.
   14.16   */
   14.17 -int xc_evtchn_open(void);
   14.18 +xc_evtchn *xc_evtchn_open(xentoollog_logger *logger,
   14.19 +                             unsigned open_flags);
   14.20  
   14.21  /*
   14.22   * Close a handle previously allocated with xc_evtchn_open().
   14.23   */
   14.24 -int xc_evtchn_close(int xce_handle);
   14.25 +int xc_evtchn_close(xc_evtchn *xce);
   14.26  
   14.27  /*
   14.28 - * Return an fd that can be select()ed on for further calls to
   14.29 - * xc_evtchn_pending().
   14.30 + * Return an fd that can be select()ed on.
   14.31   */
   14.32 -int xc_evtchn_fd(int xce_handle);
   14.33 +int xc_evtchn_fd(xc_evtchn *xce);
   14.34  
   14.35  /*
   14.36   * Notify the given event channel. Returns -1 on failure, in which case
   14.37   * errno will be set appropriately.
   14.38   */
   14.39 -int xc_evtchn_notify(int xce_handle, evtchn_port_t port);
   14.40 +int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port);
   14.41  
   14.42  /*
   14.43   * Returns a new event port awaiting interdomain connection from the given
   14.44   * domain ID, or -1 on failure, in which case errno will be set appropriately.
   14.45   */
   14.46  evtchn_port_or_error_t
   14.47 -xc_evtchn_bind_unbound_port(int xce_handle, int domid);
   14.48 +xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid);
   14.49  
   14.50  /*
   14.51   * Returns a new event port bound to the remote port for the given domain ID,
   14.52   * or -1 on failure, in which case errno will be set appropriately.
   14.53   */
   14.54  evtchn_port_or_error_t
   14.55 -xc_evtchn_bind_interdomain(int xce_handle, int domid,
   14.56 +xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
   14.57                             evtchn_port_t remote_port);
   14.58  
   14.59  /*
   14.60 @@ -865,26 +866,26 @@ xc_evtchn_bind_interdomain(int xce_handl
   14.61   * the VIRQ, or -1 on failure, in which case errno will be set appropriately.
   14.62   */
   14.63  evtchn_port_or_error_t
   14.64 -xc_evtchn_bind_virq(int xce_handle, unsigned int virq);
   14.65 +xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq);
   14.66  
   14.67  /*
   14.68   * Unbind the given event channel. Returns -1 on failure, in which case errno
   14.69   * will be set appropriately.
   14.70   */
   14.71 -int xc_evtchn_unbind(int xce_handle, evtchn_port_t port);
   14.72 +int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port);
   14.73  
   14.74  /*
   14.75   * Return the next event channel to become pending, or -1 on failure, in which
   14.76   * case errno will be set appropriately.  
   14.77   */
   14.78  evtchn_port_or_error_t
   14.79 -xc_evtchn_pending(int xce_handle);
   14.80 +xc_evtchn_pending(xc_evtchn *xce);
   14.81  
   14.82  /*
   14.83   * Unmask the given event channel. Returns -1 on failure, in which case errno
   14.84   * will be set appropriately.
   14.85   */
   14.86 -int xc_evtchn_unmask(int xce_handle, evtchn_port_t port);
   14.87 +int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port);
   14.88  
   14.89  int xc_physdev_pci_access_modify(xc_interface *xch,
   14.90                                   uint32_t domid,
   14.91 @@ -1754,7 +1755,7 @@ int xc_flask_getavc_threshold(xc_interfa
   14.92  int xc_flask_setavc_threshold(xc_interface *xc_handle, int threshold);
   14.93  
   14.94  struct elf_binary;
   14.95 -void xc_elf_set_logfile(struct xc_interface *xch, struct elf_binary *elf,
   14.96 +void xc_elf_set_logfile(xc_interface *xch, struct elf_binary *elf,
   14.97                          int verbose);
   14.98  /* Useful for callers who also use libelf. */
   14.99  
    15.1 --- a/tools/libxc/xenguest.h	Thu Dec 23 15:08:21 2010 +0000
    15.2 +++ b/tools/libxc/xenguest.h	Thu Dec 23 15:25:57 2010 +0000
    15.3 @@ -173,11 +173,11 @@ int xc_hvm_build_mem(xc_interface *xch,
    15.4                       const char *image_buffer,
    15.5                       unsigned long image_size);
    15.6  
    15.7 -int xc_suspend_evtchn_release(xc_interface *xch, int xce, int domid, int suspend_evtchn);
    15.8 +int xc_suspend_evtchn_release(xc_interface *xch, xc_evtchn *xce, int domid, int suspend_evtchn);
    15.9  
   15.10 -int xc_suspend_evtchn_init(xc_interface *xch, int xce, int domid, int port);
   15.11 +int xc_suspend_evtchn_init(xc_interface *xch, xc_evtchn *xce, int domid, int port);
   15.12  
   15.13 -int xc_await_suspend(xc_interface *xch, int xce, int suspend_evtchn);
   15.14 +int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn);
   15.15  
   15.16  int xc_get_bit_size(xc_interface *xch,
   15.17                      const char *image_name, const char *cmdline,
    16.1 --- a/tools/libxl/libxl_dom.c	Thu Dec 23 15:08:21 2010 +0000
    16.2 +++ b/tools/libxl/libxl_dom.c	Thu Dec 23 15:25:57 2010 +0000
    16.3 @@ -315,7 +315,7 @@ int libxl__domain_restore_common(libxl_c
    16.4  
    16.5  struct suspendinfo {
    16.6      libxl__gc *gc;
    16.7 -    int xce; /* event channel handle */
    16.8 +    xc_evtchn *xce; /* event channel handle */
    16.9      int suspend_eventchn;
   16.10      int domid;
   16.11      int hvm;
   16.12 @@ -419,11 +419,11 @@ int libxl__domain_suspend_common(libxl_c
   16.13      si.gc = &gc;
   16.14      si.suspend_eventchn = -1;
   16.15  
   16.16 -    si.xce = xc_evtchn_open();
   16.17 -    if (si.xce < 0)
   16.18 +    si.xce = xc_evtchn_open(NULL, 0);
   16.19 +    if (si.xce == NULL)
   16.20          goto out;
   16.21 -
   16.22 -    if (si.xce > 0) {
   16.23 +    else
   16.24 +    {
   16.25          port = xs_suspend_evtchn_port(si.domid);
   16.26  
   16.27          if (port >= 0) {
   16.28 @@ -447,7 +447,7 @@ int libxl__domain_suspend_common(libxl_c
   16.29  
   16.30      if (si.suspend_eventchn > 0)
   16.31          xc_suspend_evtchn_release(ctx->xch, si.xce, domid, si.suspend_eventchn);
   16.32 -    if (si.xce > 0)
   16.33 +    if (si.xce != NULL)
   16.34          xc_evtchn_close(si.xce);
   16.35  
   16.36  out:
    17.1 --- a/tools/misc/xen-hptool.c	Thu Dec 23 15:08:21 2010 +0000
    17.2 +++ b/tools/misc/xen-hptool.c	Thu Dec 23 15:25:57 2010 +0000
    17.3 @@ -98,7 +98,7 @@ static int hp_mem_query_func(int argc, c
    17.4  
    17.5  extern int xs_suspend_evtchn_port(int domid);
    17.6  
    17.7 -static int suspend_guest(xc_interface *xch, int xce, int domid, int *evtchn)
    17.8 +static int suspend_guest(xc_interface *xch, xc_evtchn *xce, int domid, int *evtchn)
    17.9  {
   17.10      int port, rc, suspend_evtchn = -1;
   17.11  
   17.12 @@ -192,10 +192,11 @@ static int hp_mem_offline_func(int argc,
   17.13                  }
   17.14                  else if (status & PG_OFFLINE_OWNED)
   17.15                  {
   17.16 -                    int result, xce, suspend_evtchn = -1;
   17.17 -                    xce = xc_evtchn_open();
   17.18 +                    int result, suspend_evtchn = -1;
   17.19 +                    xc_evtchn *xce;
   17.20 +                    xce = xc_evtchn_open(NULL, 0);
   17.21  
   17.22 -                    if (xce < 0)
   17.23 +                    if (xce == NULL)
   17.24                      {
   17.25                          fprintf(stderr, "When exchange page, fail"
   17.26                                  " to open evtchn\n");
    18.1 --- a/tools/python/xen/lowlevel/checkpoint/checkpoint.h	Thu Dec 23 15:08:21 2010 +0000
    18.2 +++ b/tools/python/xen/lowlevel/checkpoint/checkpoint.h	Thu Dec 23 15:25:57 2010 +0000
    18.3 @@ -19,7 +19,7 @@ typedef enum {
    18.4  
    18.5  typedef struct {
    18.6      xc_interface *xch;
    18.7 -    int xce;               /* event channel handle */
    18.8 +    xc_evtchn *xce;        /* event channel handle */
    18.9      struct xs_handle* xsh; /* xenstore handle */
   18.10      int watching_shutdown; /* state of watch on @releaseDomain */
   18.11  
    19.1 --- a/tools/python/xen/lowlevel/checkpoint/libcheckpoint.c	Thu Dec 23 15:08:21 2010 +0000
    19.2 +++ b/tools/python/xen/lowlevel/checkpoint/libcheckpoint.c	Thu Dec 23 15:25:57 2010 +0000
    19.3 @@ -48,7 +48,7 @@ char* checkpoint_error(checkpoint_state*
    19.4  void checkpoint_init(checkpoint_state* s)
    19.5  {
    19.6      s->xch = NULL;
    19.7 -    s->xce = -1;
    19.8 +    s->xce = NULL;
    19.9      s->xsh = NULL;
   19.10      s->watching_shutdown = 0;
   19.11  
   19.12 @@ -89,8 +89,8 @@ int checkpoint_open(checkpoint_state* s,
   19.13         return -1;
   19.14      }
   19.15  
   19.16 -    s->xce = xc_evtchn_open();
   19.17 -    if (s->xce < 0) {
   19.18 +    s->xce = xc_evtchn_open(NULL, 0);
   19.19 +    if (s->xce == NULL) {
   19.20         checkpoint_close(s);
   19.21         s->errstr = "could not open event channel handle";
   19.22  
   19.23 @@ -149,9 +149,9 @@ void checkpoint_close(checkpoint_state* 
   19.24      xc_interface_close(s->xch);
   19.25      s->xch = NULL;
   19.26    }
   19.27 -  if (s->xce >= 0) {
   19.28 +  if (s->xce != NULL) {
   19.29      xc_evtchn_close(s->xce);
   19.30 -    s->xce = -1;
   19.31 +    s->xce = NULL;
   19.32    }
   19.33    if (s->xsh) {
   19.34      xs_daemon_close(s->xsh);
   19.35 @@ -360,7 +360,7 @@ static int setup_suspend_evtchn(checkpoi
   19.36  static void release_suspend_evtchn(checkpoint_state *s)
   19.37  {
   19.38    /* TODO: teach xen to clean up if port is unbound */
   19.39 -  if (s->xce >= 0 && s->suspend_evtchn >= 0) {
   19.40 +  if (s->xce != NULL && s->suspend_evtchn >= 0) {
   19.41      xc_suspend_evtchn_release(s->xch, s->xce, s->domid, s->suspend_evtchn);
   19.42      s->suspend_evtchn = -1;
   19.43    }
    20.1 --- a/tools/xcutils/xc_save.c	Thu Dec 23 15:08:21 2010 +0000
    20.2 +++ b/tools/xcutils/xc_save.c	Thu Dec 23 15:25:57 2010 +0000
    20.3 @@ -25,7 +25,7 @@
    20.4  
    20.5  static struct suspendinfo {
    20.6      xc_interface *xch;
    20.7 -    int xce; /* event channel handle */
    20.8 +    xc_evtchn *xce; /* event channel handle */
    20.9      int suspend_evtchn;
   20.10      int domid;
   20.11      unsigned int flags;
   20.12 @@ -183,13 +183,12 @@ main(int argc, char **argv)
   20.13      max_f = atoi(argv[4]);
   20.14      si.flags = atoi(argv[5]);
   20.15  
   20.16 -    si.suspend_evtchn = si.xce = -1;
   20.17 +    si.suspend_evtchn = -1;
   20.18  
   20.19 -    si.xce = xc_evtchn_open();
   20.20 -    if (si.xce < 0)
   20.21 +    si.xce = xc_evtchn_open(NULL, 0);
   20.22 +    if (si.xce == NULL)
   20.23          warnx("failed to open event channel handle");
   20.24 -
   20.25 -    if (si.xce > 0)
   20.26 +    else
   20.27      {
   20.28          port = xs_suspend_evtchn_port(si.domid);
   20.29  
    21.1 --- a/tools/xenmon/xenbaked.c	Thu Dec 23 15:08:21 2010 +0000
    21.2 +++ b/tools/xenmon/xenbaked.c	Thu Dec 23 15:25:57 2010 +0000
    21.3 @@ -268,7 +268,7 @@ static void log_event(int event_id)
    21.4  }
    21.5  
    21.6  int virq_port;
    21.7 -int xce_handle = -1;
    21.8 +xc_evtchn *xce_handle = NULL;
    21.9  
   21.10  /* Returns the event channel handle. */
   21.11  /* Stolen from xenstore code */
   21.12 @@ -280,16 +280,16 @@ static int eventchn_init(void)
   21.13      if (0)
   21.14          return -1;
   21.15    
   21.16 -    xce_handle = xc_evtchn_open();
   21.17 +    xce_handle = xc_evtchn_open(NULL, 0);
   21.18  
   21.19 -    if (xce_handle < 0)
   21.20 +    if (xce_handle == NULL)
   21.21          perror("Failed to open evtchn device");
   21.22    
   21.23      if ((rc = xc_evtchn_bind_virq(xce_handle, VIRQ_TBUF)) == -1)
   21.24          perror("Failed to bind to domain exception virq port");
   21.25      virq_port = rc;
   21.26    
   21.27 -    return xce_handle;
   21.28 +    return xce_handle == NULL ? -1 : 0;
   21.29  }
   21.30  
   21.31  static void wait_for_event(void)
   21.32 @@ -300,7 +300,7 @@ static void wait_for_event(void)
   21.33      struct timeval tv;
   21.34      int evtchn_fd;
   21.35    
   21.36 -    if (xce_handle < 0) {
   21.37 +    if (xce_handle == NULL) {
   21.38          nanosleep(&opts.poll_sleep, NULL);
   21.39          return;
   21.40      }
    22.1 --- a/tools/xenpaging/mem_event.h	Thu Dec 23 15:08:21 2010 +0000
    22.2 +++ b/tools/xenpaging/mem_event.h	Thu Dec 23 15:25:57 2010 +0000
    22.3 @@ -40,7 +40,7 @@
    22.4  
    22.5  typedef struct mem_event {
    22.6      domid_t domain_id;
    22.7 -    int xce_handle;
    22.8 +    xc_evtchn *xce_handle;
    22.9      int port;
   22.10      mem_event_back_ring_t back_ring;
   22.11      mem_event_shared_page_t *shared_page;
    23.1 --- a/tools/xenpaging/policy_default.c	Thu Dec 23 15:08:21 2010 +0000
    23.2 +++ b/tools/xenpaging/policy_default.c	Thu Dec 23 15:25:57 2010 +0000
    23.3 @@ -70,7 +70,7 @@ int policy_init(xenpaging_t *paging)
    23.4  int policy_choose_victim(xenpaging_t *paging, domid_t domain_id,
    23.5                           xenpaging_victim_t *victim)
    23.6  {
    23.7 -    struct xc_interface *xch = paging->xc_handle;
    23.8 +    xc_interface *xch = paging->xc_handle;
    23.9      unsigned long wrap = current_gfn;
   23.10      ASSERT(victim != NULL);
   23.11  
    24.1 --- a/tools/xenpaging/xc.c	Thu Dec 23 15:08:21 2010 +0000
    24.2 +++ b/tools/xenpaging/xc.c	Thu Dec 23 15:25:57 2010 +0000
    24.3 @@ -65,9 +65,9 @@ int xc_mem_paging_flush_ioemu_cache(domi
    24.4      return rc;
    24.5  }
    24.6  
    24.7 -int xc_wait_for_event_or_timeout(xc_interface *xch, int xce_handle, unsigned long ms)
    24.8 +int xc_wait_for_event_or_timeout(xc_interface *xch, xc_evtchn *xce, unsigned long ms)
    24.9  {
   24.10 -    struct pollfd fd = { .fd = xce_handle, .events = POLLIN | POLLERR };
   24.11 +    struct pollfd fd = { .fd = xc_evtchn_fd(xce), .events = POLLIN | POLLERR };
   24.12      int port;
   24.13      int rc;
   24.14      
   24.15 @@ -83,14 +83,14 @@ int xc_wait_for_event_or_timeout(xc_inte
   24.16      
   24.17      if ( rc == 1 )
   24.18      {
   24.19 -        port = xc_evtchn_pending(xce_handle);
   24.20 +        port = xc_evtchn_pending(xce);
   24.21          if ( port == -1 )
   24.22          {
   24.23              ERROR("Failed to read port from event channel");
   24.24              goto err;
   24.25          }
   24.26          
   24.27 -        rc = xc_evtchn_unmask(xce_handle, port);
   24.28 +        rc = xc_evtchn_unmask(xce, port);
   24.29          if ( rc != 0 )
   24.30          {
   24.31              ERROR("Failed to unmask event channel port");
   24.32 @@ -106,9 +106,9 @@ int xc_wait_for_event_or_timeout(xc_inte
   24.33      return -errno;
   24.34  }
   24.35  
   24.36 -int xc_wait_for_event(xc_interface *xch, int xce_handle)
   24.37 +int xc_wait_for_event(xc_interface *xch, xc_evtchn *xce)
   24.38  {
   24.39 -    return xc_wait_for_event_or_timeout(xch, xce_handle, -1);
   24.40 +    return xc_wait_for_event_or_timeout(xch, xce, -1);
   24.41  }
   24.42  
   24.43  int xc_get_platform_info(xc_interface *xc_handle, domid_t domain_id,
    25.1 --- a/tools/xenpaging/xc.h	Thu Dec 23 15:08:21 2010 +0000
    25.2 +++ b/tools/xenpaging/xc.h	Thu Dec 23 15:25:57 2010 +0000
    25.3 @@ -53,8 +53,8 @@ typedef struct xc_platform_info {
    25.4  int alloc_bitmap(unsigned long **bitmap, unsigned long bitmap_size);
    25.5  
    25.6  int xc_mem_paging_flush_ioemu_cache(domid_t domain_id);
    25.7 -int xc_wait_for_event(xc_interface *xch, int xce_handle);
    25.8 -int xc_wait_for_event_or_timeout(xc_interface *xch, int xce_handle, unsigned long ms);
    25.9 +int xc_wait_for_event(xc_interface *xch, xc_evtchn *xce);
   25.10 +int xc_wait_for_event_or_timeout(xc_interface *xch, xc_evtchn *xce, unsigned long ms);
   25.11  
   25.12  int xc_get_platform_info(xc_interface *xc_handle, domid_t domain_id,
   25.13                           xc_platform_info_t *platform_info);
    26.1 --- a/tools/xenpaging/xenpaging.c	Thu Dec 23 15:08:21 2010 +0000
    26.2 +++ b/tools/xenpaging/xenpaging.c	Thu Dec 23 15:25:57 2010 +0000
    26.3 @@ -144,8 +144,8 @@ xenpaging_t *xenpaging_init(domid_t doma
    26.4      }
    26.5  
    26.6      /* Open event channel */
    26.7 -    paging->mem_event.xce_handle = xc_evtchn_open();
    26.8 -    if ( paging->mem_event.xce_handle < 0 )
    26.9 +    paging->mem_event.xce_handle = xc_evtchn_open(NULL, 0);
   26.10 +    if ( paging->mem_event.xce_handle == NULL )
   26.11      {
   26.12          ERROR("Failed to open event channel");
   26.13          goto err;
   26.14 @@ -246,7 +246,7 @@ xenpaging_t *xenpaging_init(domid_t doma
   26.15  int xenpaging_teardown(xenpaging_t *paging)
   26.16  {
   26.17      int rc;
   26.18 -    struct xc_interface *xch;
   26.19 +    xc_interface *xch;
   26.20  
   26.21      if ( paging == NULL )
   26.22          return 0;
   26.23 @@ -274,7 +274,7 @@ int xenpaging_teardown(xenpaging_t *pagi
   26.24      {
   26.25          ERROR("Error closing event channel");
   26.26      }
   26.27 -    paging->mem_event.xce_handle = -1;
   26.28 +    paging->mem_event.xce_handle = NULL;
   26.29      
   26.30      /* Close connection to Xen */
   26.31      rc = xc_interface_close(xch);
   26.32 @@ -338,7 +338,7 @@ static int put_response(mem_event_t *mem
   26.33  int xenpaging_evict_page(xenpaging_t *paging,
   26.34                           xenpaging_victim_t *victim, int fd, int i)
   26.35  {
   26.36 -    struct xc_interface *xch = paging->xc_handle;
   26.37 +    xc_interface *xch = paging->xc_handle;
   26.38      void *page;
   26.39      unsigned long gfn;
   26.40      int ret;
   26.41 @@ -412,7 +412,7 @@ static int xenpaging_resume_page(xenpagi
   26.42  static int xenpaging_populate_page(xenpaging_t *paging,
   26.43      uint64_t *gfn, int fd, int i)
   26.44  {
   26.45 -    struct xc_interface *xch = paging->xc_handle;
   26.46 +    xc_interface *xch = paging->xc_handle;
   26.47      unsigned long _gfn;
   26.48      void *page;
   26.49      int ret;
   26.50 @@ -467,7 +467,7 @@ static int xenpaging_populate_page(xenpa
   26.51  static int evict_victim(xenpaging_t *paging, domid_t domain_id,
   26.52                          xenpaging_victim_t *victim, int fd, int i)
   26.53  {
   26.54 -    struct xc_interface *xch = paging->xc_handle;
   26.55 +    xc_interface *xch = paging->xc_handle;
   26.56      int j = 0;
   26.57      int ret;
   26.58  
    27.1 --- a/tools/xenstore/xenstored_core.c	Thu Dec 23 15:08:21 2010 +0000
    27.2 +++ b/tools/xenstore/xenstored_core.c	Thu Dec 23 15:25:57 2010 +0000
    27.3 @@ -52,7 +52,7 @@
    27.4  
    27.5  #include "hashtable.h"
    27.6  
    27.7 -extern int xce_handle; /* in xenstored_domain.c */
    27.8 +extern xc_evtchn *xce_handle; /* in xenstored_domain.c */
    27.9  
   27.10  static bool verbose = false;
   27.11  LIST_HEAD(connections);
   27.12 @@ -323,7 +323,7 @@ static int initialize_set(fd_set *inset,
   27.13  	set_fd(ro_sock,            inset, &max);
   27.14  	set_fd(reopen_log_pipe[0], inset, &max);
   27.15  
   27.16 -	if (xce_handle != -1)
   27.17 +	if (xce_handle != NULL)
   27.18  		set_fd(xc_evtchn_fd(xce_handle), inset, &max);
   27.19  
   27.20  	list_for_each_entry(conn, &connections, list) {
   27.21 @@ -1901,7 +1901,7 @@ int main(int argc, char *argv[])
   27.22  
   27.23  	signal(SIGHUP, trigger_reopen_log);
   27.24  
   27.25 -	if (xce_handle != -1)
   27.26 +	if (xce_handle != NULL)
   27.27  		evtchn_fd = xc_evtchn_fd(xce_handle);
   27.28  
   27.29  	/* Get ready to listen to the tools. */
    28.1 --- a/tools/xenstore/xenstored_domain.c	Thu Dec 23 15:08:21 2010 +0000
    28.2 +++ b/tools/xenstore/xenstored_domain.c	Thu Dec 23 15:25:57 2010 +0000
    28.3 @@ -36,7 +36,7 @@
    28.4  static xc_interface **xc_handle;
    28.5  static evtchn_port_t virq_port;
    28.6  
    28.7 -int xce_handle = -1; 
    28.8 +xc_evtchn *xce_handle = NULL;
    28.9  
   28.10  struct domain
   28.11  {
   28.12 @@ -580,8 +580,7 @@ static int dom0_init(void)
   28.13  	return 0; 
   28.14  }
   28.15  
   28.16 -/* Returns the event channel handle. */
   28.17 -int domain_init(void)
   28.18 +void domain_init(void)
   28.19  {
   28.20  	int rc;
   28.21  
   28.22 @@ -595,9 +594,9 @@ int domain_init(void)
   28.23  
   28.24  	talloc_set_destructor(xc_handle, close_xc_handle);
   28.25  
   28.26 -	xce_handle = xc_evtchn_open();
   28.27 +	xce_handle = xc_evtchn_open(NULL, 0);
   28.28  
   28.29 -	if (xce_handle < 0)
   28.30 +	if (xce_handle == NULL)
   28.31  		barf_perror("Failed to open evtchn device");
   28.32  
   28.33  	if (dom0_init() != 0) 
   28.34 @@ -606,8 +605,6 @@ int domain_init(void)
   28.35  	if ((rc = xc_evtchn_bind_virq(xce_handle, VIRQ_DOM_EXC)) == -1)
   28.36  		barf_perror("Failed to bind to domain exception virq port");
   28.37  	virq_port = rc;
   28.38 -
   28.39 -	return xce_handle;
   28.40  }
   28.41  
   28.42  void domain_entry_inc(struct connection *conn, struct node *node)
    29.1 --- a/tools/xenstore/xenstored_domain.h	Thu Dec 23 15:08:21 2010 +0000
    29.2 +++ b/tools/xenstore/xenstored_domain.h	Thu Dec 23 15:25:57 2010 +0000
    29.3 @@ -40,8 +40,7 @@ void do_set_target(struct connection *co
    29.4  /* domid */
    29.5  void do_get_domain_path(struct connection *conn, const char *domid_str);
    29.6  
    29.7 -/* Returns the event channel handle */
    29.8 -int domain_init(void);
    29.9 +void domain_init(void);
   29.10  
   29.11  /* Returns the implicit path of a connection (only domains have this) */
   29.12  const char *get_implicit_path(const struct connection *conn);
    30.1 --- a/tools/xentrace/xentrace.c	Thu Dec 23 15:08:21 2010 +0000
    30.2 +++ b/tools/xentrace/xentrace.c	Thu Dec 23 15:25:57 2010 +0000
    30.3 @@ -73,7 +73,7 @@ settings_t opts;
    30.4  int interrupted = 0; /* gets set if we get a SIGHUP */
    30.5  
    30.6  static xc_interface *xc_handle;
    30.7 -static int event_fd = -1;
    30.8 +static xc_evtchn *xce_handle = NULL;
    30.9  static int virq_port = -1;
   30.10  static int outfd = 1;
   30.11  
   30.12 @@ -576,14 +576,13 @@ static void event_init(void)
   30.13  {
   30.14      int rc;
   30.15  
   30.16 -    rc = xc_evtchn_open();
   30.17 -    if (rc < 0) {
   30.18 +    xce_handle = xc_evtchn_open(NULL, 0);
   30.19 +    if (xce_handle == NULL) {
   30.20          perror("event channel open");
   30.21          exit(EXIT_FAILURE);
   30.22      }
   30.23 -    event_fd = rc;
   30.24  
   30.25 -    rc = xc_evtchn_bind_virq(event_fd, VIRQ_TBUF);
   30.26 +    rc = xc_evtchn_bind_virq(xce_handle, VIRQ_TBUF);
   30.27      if (rc == -1) {
   30.28          PERROR("failed to bind to VIRQ port");
   30.29          exit(EXIT_FAILURE);
   30.30 @@ -598,7 +597,7 @@ static void event_init(void)
   30.31  static void wait_for_event_or_timeout(unsigned long milliseconds)
   30.32  {
   30.33      int rc;
   30.34 -    struct pollfd fd = { .fd = event_fd,
   30.35 +    struct pollfd fd = { .fd = xc_evtchn_fd(xce_handle),
   30.36                           .events = POLLIN | POLLERR };
   30.37      int port;
   30.38  
   30.39 @@ -611,7 +610,7 @@ static void wait_for_event_or_timeout(un
   30.40      }
   30.41  
   30.42      if (rc == 1) {
   30.43 -        port = xc_evtchn_pending(event_fd);
   30.44 +        port = xc_evtchn_pending(xce_handle);
   30.45          if (port == -1) {
   30.46              PERROR("failed to read port from evtchn");
   30.47              exit(EXIT_FAILURE);
   30.48 @@ -622,7 +621,7 @@ static void wait_for_event_or_timeout(un
   30.49                      port, virq_port);
   30.50              exit(EXIT_FAILURE);
   30.51          }
   30.52 -        rc = xc_evtchn_unmask(event_fd, port);
   30.53 +        rc = xc_evtchn_unmask(xce_handle, port);
   30.54          if (rc == -1) {
   30.55              PERROR("failed to write port to evtchn");
   30.56              exit(EXIT_FAILURE);