diff --git a/dom0/restore/xenfreepages.c b/dom0/restore/xenfreepages.c index ced36dbb..90d2a514 100644 --- a/dom0/restore/xenfreepages.c +++ b/dom0/restore/xenfreepages.c @@ -4,8 +4,13 @@ struct xen_sysctl_physinfo xphysinfo; main() { +#ifdef XENCTRL_HAS_XC_INTERFACE + xc_interface *handle = xc_interface_open(NULL, NULL, 0); + if (!handle) { +#else int handle = xc_interface_open(); if (handle == -1) { +#endif perror("xc_interface_open"); exit(1); } diff --git a/qrexec/txrx-vchan.c b/qrexec/txrx-vchan.c index 2a95180f..01e54c5a 100644 --- a/qrexec/txrx-vchan.c +++ b/qrexec/txrx-vchan.c @@ -83,7 +83,11 @@ int buffer_space_vchan_ext() // if the remote domain is destroyed, we get no notification // thus, we check for the status periodically +#ifdef XENCTRL_HAS_XC_INTERFACE +static xc_interface *xc_handle = NULL; +#else static int xc_handle = -1; +#endif void slow_check_for_libvchan_is_eof(struct libvchan *ctrl) { struct evtchn_status evst; @@ -198,8 +202,13 @@ char *peer_client_init(int dom, int port) // now client init should succeed; "while" is redundant while (!(ctrl = libvchan_client_init(dom, port))); +#ifdef XENCTRL_HAS_XC_INTERFACE + xc_handle = xc_interface_open(NULL, 0, 0); + if (!xc_handle) { +#else xc_handle = xc_interface_open(); if (xc_handle < 0) { +#endif perror("xc_interface_open"); exit(1); } diff --git a/vchan/init.c b/vchan/init.c index 4a3da4f2..30cc2001 100644 --- a/vchan/init.c +++ b/vchan/init.c @@ -65,15 +65,25 @@ static int server_interface_init(struct libvchan *ctrl, int devno) struct xs_handle *xs; char buf[64]; char ref[16]; +#ifdef XENCTRL_HAS_XC_INTERFACE + xc_evtchn *evfd; +#else int evfd; +#endif evtchn_port_or_error_t port; xs = xs_domain_open(); if (!xs) { return ret; } +#ifdef XENCTRL_HAS_XC_INTERFACE + evfd = xc_evtchn_open(NULL, 0); + if (!evfd) + goto fail; +#else evfd = xc_evtchn_open(); if (evfd < 0) goto fail; +#endif ctrl->evfd = evfd; // the following hardcoded 0 is the peer domain id port = xc_evtchn_bind_unbound_port(evfd, 0); @@ -98,7 +108,11 @@ static int server_interface_init(struct libvchan *ctrl, int devno) ret = 0; fail2: if (ret) +#ifdef XENCTRL_HAS_XC_INTERFACE + xc_evtchn_close(evfd); +#else close(evfd); +#endif fail: xs_daemon_close(xs); return ret; @@ -152,10 +166,18 @@ static int client_interface_init(struct libvchan *ctrl, int domain, int devno) int ret = -1; unsigned int len; struct xs_handle *xs; +#ifdef XENCTRL_HAS_XC_INTERFACE + xc_interface *xcfd; +#else int xcfd; +#endif char buf[64]; char *ref; +#ifdef XENCTRL_HAS_XC_INTERFACE + xc_evtchn *evfd; +#else int evfd; +#endif int remote_port; xs = xs_daemon_open(); if (!xs) { @@ -181,23 +203,43 @@ static int client_interface_init(struct libvchan *ctrl, int domain, int devno) if (!remote_port) goto fail; free(ref); +#ifdef XENCTRL_HAS_XC_INTERFACE + xcfd = xc_interface_open(NULL, NULL, 0); + if (!xcfd) + goto fail; +#else xcfd = xc_interface_open(); if (xcfd < 0) goto fail; +#endif ctrl->ring = (struct vchan_interface *) xc_map_foreign_range(xcfd, domain, 4096, PROT_READ | PROT_WRITE, ctrl->ring_ref); +#ifdef XENCTRL_HAS_XC_INTERFACE + xc_interface_close(xcfd); +#else close(xcfd); +#endif if (ctrl->ring == 0 || ctrl->ring == MAP_FAILED) goto fail; +#ifdef XENCTRL_HAS_XC_INTERFACE + evfd = xc_evtchn_open(NULL, 0); + if (!evfd) + goto fail; +#else evfd = xc_evtchn_open(); if (evfd < 0) goto fail; +#endif ctrl->evfd = evfd; ctrl->evport = xc_evtchn_bind_interdomain(evfd, domain, remote_port); if (ctrl->evport < 0 || xc_evtchn_notify(evfd, ctrl->evport)) +#ifdef XENCTRL_HAS_XC_INTERFACE + xc_evtchn_close(evfd); +#else close(evfd); +#endif else ret = 0; fail: diff --git a/vchan/io.c b/vchan/io.c index 7b524279..6b16f406 100644 --- a/vchan/io.c +++ b/vchan/io.c @@ -149,7 +149,7 @@ int libvchan_close(struct libvchan *ctrl) /// The fd to use for select() set int libvchan_fd_for_select(struct libvchan *ctrl) { - return ctrl->evfd; + return xc_evtchn_fd(ctrl->evfd); } /// Unmasks event channel; must be called before calling select(), and only then diff --git a/vchan/libvchan.h b/vchan/libvchan.h index 652284ba..6a6025fb 100644 --- a/vchan/libvchan.h +++ b/vchan/libvchan.h @@ -20,6 +20,7 @@ */ #include +#include typedef uint32_t VCHAN_RING_IDX; /// struct vchan_interface is placed in memory shared between domains @@ -37,7 +38,11 @@ struct libvchan { struct vchan_interface *ring; uint32_t ring_ref; /// descriptor to event channel interface +#ifdef XENCTRL_HAS_XC_INTERFACE + xc_evtchn *evfd; +#else int evfd; +#endif int evport; VCHAN_RING_IDX *wr_cons, *wr_prod, *rd_cons, *rd_prod; char *rd_ring, *wr_ring;