debuggers.hg

changeset 22709:4e120cb427f4

ocaml: evtchn+xc bindings: use libxenctrl and libxenguest

Now that tools/libxc is licensed under LGPL I don't think there is any need for
an LGPL reimplementation under tools/ocaml.

For the most part the conversion to the up-to-date libxc API (xc_lib.c
essentially implemented the same interface as an older libxc) was pretty
automatic. There are some functions which appear to no longer exist in libxc
which I therefore simply removed the bindings for and a small number of
interfaces which had changed.

Many of the functions bound by the stubs have no in-tree users (which I think
is fine for a language binding) so I have no way to confirm correctness other
than by eye. I was however able to confirm that oxenstored still worked and to
build a XCP toolstack which could successfully start a PV guest.

Uses the new XC_OPENFLAG_NON_REENTRANT option to avoid potential conflicts
between pthreads and the ocaml runtime.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Cc: Vincent Hanquez <Vincent.Hanquez@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Thu Jan 06 17:37:00 2011 +0000 (2011-01-06)
parents 2e1bd6baee28
children 2c487c02d8d7
files tools/ocaml/Makefile.rules tools/ocaml/libs/eventchn/eventchn.ml tools/ocaml/libs/eventchn/eventchn.mli tools/ocaml/libs/eventchn/eventchn_stubs.c tools/ocaml/libs/xc/Makefile tools/ocaml/libs/xc/xc.h tools/ocaml/libs/xc/xc.ml tools/ocaml/libs/xc/xc.mli tools/ocaml/libs/xc/xc_cpufeature.h tools/ocaml/libs/xc/xc_cpuid.h tools/ocaml/libs/xc/xc_e820.h tools/ocaml/libs/xc/xc_lib.c tools/ocaml/libs/xc/xc_stubs.c tools/ocaml/xenstored/Makefile tools/ocaml/xenstored/event.ml tools/ocaml/xenstored/xenstored.ml
line diff
     1.1 --- a/tools/ocaml/Makefile.rules	Thu Jan 06 17:34:46 2011 +0000
     1.2 +++ b/tools/ocaml/Makefile.rules	Thu Jan 06 17:37:00 2011 +0000
     1.3 @@ -54,18 +54,18 @@ mk-caml-lib-bytecode = $(call quiet-comm
     1.4  
     1.5  mk-caml-stubs = $(call quiet-command, $(OCAMLMKLIB) -o `basename $1 .a` $2,MKLIB,$1)
     1.6  mk-caml-lib-stubs = \
     1.7 -	$(call quiet-command, $(AR) rcs $1 $2 && $(OCAMLMKLIB) -o `basename $1 .a | sed -e 's/^lib//'` $2,MKLIB,$1)
     1.8 +	$(call quiet-command, $(AR) rcs $1 $2 && $(OCAMLMKLIB) -o `basename $1 .a | sed -e 's/^lib//'` $3 $2,MKLIB,$1)
     1.9  
    1.10  # define a library target <name>.cmxa and <name>.cma
    1.11  define OCAML_LIBRARY_template
    1.12   $(1).cmxa: lib$(1)_stubs.a $(foreach obj,$($(1)_OBJS),$(obj).cmx)
    1.13 -	$(call mk-caml-lib-native,$$@, -cclib -l$(1)_stubs, $(foreach obj,$($(1)_OBJS),$(obj).cmx))
    1.14 +	$(call mk-caml-lib-native,$$@, -cclib -l$(1)_stubs $(foreach lib,$(LIBS_$(1)),-cclib $(lib)), $(foreach obj,$($(1)_OBJS),$(obj).cmx))
    1.15   $(1).cma: $(foreach obj,$($(1)_OBJS),$(obj).cmo)
    1.16  	$(call mk-caml-lib-bytecode,$$@, -dllib dll$(1)_stubs.so -cclib -l$(1)_stubs, $$+)
    1.17   $(1)_stubs.a: $(foreach obj,$$($(1)_C_OBJS),$(obj).o)
    1.18  	$(call mk-caml-stubs,$$@, $$+)
    1.19   lib$(1)_stubs.a: $(foreach obj,$($(1)_C_OBJS),$(obj).o)
    1.20 -	$(call mk-caml-lib-stubs,$$@, $$+)
    1.21 +	$(call mk-caml-lib-stubs,$$@, $$+, $(LIBS_$(1)))
    1.22  endef
    1.23  
    1.24  define OCAML_NOC_LIBRARY_template
     2.1 --- a/tools/ocaml/libs/eventchn/eventchn.ml	Thu Jan 06 17:34:46 2011 +0000
     2.2 +++ b/tools/ocaml/libs/eventchn/eventchn.ml	Thu Jan 06 17:37:00 2011 +0000
     2.3 @@ -16,12 +16,15 @@
     2.4  
     2.5  exception Error of string
     2.6  
     2.7 -external init: unit -> Unix.file_descr = "stub_eventchn_init"
     2.8 -external notify: Unix.file_descr -> int -> unit = "stub_eventchn_notify"
     2.9 -external bind_interdomain: Unix.file_descr -> int -> int -> int = "stub_eventchn_bind_interdomain"
    2.10 -external bind_dom_exc_virq: Unix.file_descr -> int = "stub_eventchn_bind_dom_exc_virq"
    2.11 -external unbind: Unix.file_descr -> int -> unit = "stub_eventchn_unbind"
    2.12 -external read_port: Unix.file_descr -> int = "stub_eventchn_read_port"
    2.13 -external write_port: Unix.file_descr -> int -> unit = "stub_eventchn_write_port"
    2.14 +type handle
    2.15 +
    2.16 +external init: unit -> handle = "stub_eventchn_init"
    2.17 +external fd: handle -> Unix.file_descr = "stub_eventchn_fd"
    2.18 +external notify: handle -> int -> unit = "stub_eventchn_notify"
    2.19 +external bind_interdomain: handle -> int -> int -> int = "stub_eventchn_bind_interdomain"
    2.20 +external bind_dom_exc_virq: handle -> int = "stub_eventchn_bind_dom_exc_virq"
    2.21 +external unbind: handle -> int -> unit = "stub_eventchn_unbind"
    2.22 +external pending: handle -> int = "stub_eventchn_pending"
    2.23 +external unmask: handle -> int -> unit = "stub_eventchn_unmask"
    2.24  
    2.25  let _ = Callback.register_exception "eventchn.error" (Error "register_callback")
     3.1 --- a/tools/ocaml/libs/eventchn/eventchn.mli	Thu Jan 06 17:34:46 2011 +0000
     3.2 +++ b/tools/ocaml/libs/eventchn/eventchn.mli	Thu Jan 06 17:37:00 2011 +0000
     3.3 @@ -15,12 +15,17 @@
     3.4   *)
     3.5  
     3.6  exception Error of string
     3.7 -external init : unit -> Unix.file_descr = "stub_eventchn_init"
     3.8 -external notify : Unix.file_descr -> int -> unit = "stub_eventchn_notify"
     3.9 -external bind_interdomain : Unix.file_descr -> int -> int -> int
    3.10 +
    3.11 +type handle
    3.12 +
    3.13 +external init : unit -> handle = "stub_eventchn_init"
    3.14 +external fd: handle -> Unix.file_descr = "stub_eventchn_fd"
    3.15 +
    3.16 +external notify : handle -> int -> unit = "stub_eventchn_notify"
    3.17 +external bind_interdomain : handle -> int -> int -> int
    3.18    = "stub_eventchn_bind_interdomain"
    3.19 -external bind_dom_exc_virq : Unix.file_descr -> int = "stub_eventchn_bind_dom_exc_virq"
    3.20 -external unbind : Unix.file_descr -> int -> unit = "stub_eventchn_unbind"
    3.21 -external read_port : Unix.file_descr -> int = "stub_eventchn_read_port"
    3.22 -external write_port : Unix.file_descr -> int -> unit
    3.23 -  = "stub_eventchn_write_port"
    3.24 +external bind_dom_exc_virq : handle -> int = "stub_eventchn_bind_dom_exc_virq"
    3.25 +external unbind : handle -> int -> unit = "stub_eventchn_unbind"
    3.26 +external pending : handle -> int = "stub_eventchn_pending"
    3.27 +external unmask : handle -> int -> unit
    3.28 +  = "stub_eventchn_unmask"
     4.1 --- a/tools/ocaml/libs/eventchn/eventchn_stubs.c	Thu Jan 06 17:34:46 2011 +0000
     4.2 +++ b/tools/ocaml/libs/eventchn/eventchn_stubs.c	Thu Jan 06 17:37:00 2011 +0000
     4.3 @@ -34,119 +34,110 @@
     4.4  #include <caml/callback.h>
     4.5  #include <caml/fail.h>
     4.6  
     4.7 -#define EVENTCHN_PATH "/dev/xen/evtchn"
     4.8 +#define _H(__h) ((xc_interface *)(__h))
     4.9  
    4.10 -static int do_ioctl(int handle, int cmd, void *arg)
    4.11 +CAMLprim value stub_eventchn_init(void)
    4.12  {
    4.13 -	return ioctl(handle, cmd, arg);
    4.14 -}
    4.15 +	CAMLparam0();
    4.16 +	CAMLlocal1(result);
    4.17  
    4.18 -static int do_read_port(int handle, evtchn_port_t *port)
    4.19 -{
    4.20 -	return (read(handle, port, sizeof(evtchn_port_t)) != sizeof(evtchn_port_t));
    4.21 -}
    4.22 +	xc_interface *xce = xc_evtchn_open(NULL, XC_OPENFLAG_NON_REENTRANT);
    4.23 +	if (xce == NULL)
    4.24 +		caml_failwith("open failed");
    4.25  
    4.26 -static int do_write_port(int handle, evtchn_port_t port)
    4.27 -{
    4.28 -	return (write(handle, &port, sizeof(evtchn_port_t)) != sizeof(evtchn_port_t));
    4.29 +	result = (value)xce;
    4.30 +	CAMLreturn(result);
    4.31  }
    4.32  
    4.33 -int eventchn_do_open(void)
    4.34 +CAMLprim value stub_eventchn_fd(value xce)
    4.35  {
    4.36 -	return open(EVENTCHN_PATH, O_RDWR);
    4.37 +	CAMLparam1(xce);
    4.38 +	CAMLlocal1(result);
    4.39 +	int fd;
    4.40 +
    4.41 +	fd = xc_evtchn_fd(_H(xce));
    4.42 +	if (fd == -1)
    4.43 +		caml_failwith("evtchn fd failed");
    4.44 +
    4.45 +	result = Val_int(fd);
    4.46 +
    4.47 +	CAMLreturn(result);
    4.48  }
    4.49  
    4.50 -CAMLprim value stub_eventchn_init(value unit)
    4.51 +CAMLprim value stub_eventchn_notify(value xce, value port)
    4.52  {
    4.53 -	CAMLparam1(unit);
    4.54 -	int fd = eventchn_do_open();
    4.55 -	if (fd == -1)
    4.56 -		caml_failwith("open failed");
    4.57 -	CAMLreturn(Val_int(fd));
    4.58 -}
    4.59 -
    4.60 -CAMLprim value stub_eventchn_notify(value fd, value port)
    4.61 -{
    4.62 -	CAMLparam2(fd, port);
    4.63 -	struct ioctl_evtchn_notify notify;
    4.64 +	CAMLparam2(xce, port);
    4.65  	int rc;
    4.66  
    4.67 -	notify.port = Int_val(port);
    4.68 -	rc = do_ioctl(Int_val(fd), IOCTL_EVTCHN_NOTIFY, &notify);
    4.69 +	rc = xc_evtchn_notify(_H(xce), Int_val(port));
    4.70  	if (rc == -1)
    4.71 -		caml_failwith("ioctl notify failed");
    4.72 +		caml_failwith("evtchn notify failed");
    4.73  
    4.74  	CAMLreturn(Val_unit);
    4.75  }
    4.76  
    4.77 -CAMLprim value stub_eventchn_bind_interdomain(value fd, value domid,
    4.78 +CAMLprim value stub_eventchn_bind_interdomain(value xce, value domid,
    4.79                                                value remote_port)
    4.80  {
    4.81 -	CAMLparam3(fd, domid, remote_port);
    4.82 +	CAMLparam3(xce, domid, remote_port);
    4.83  	CAMLlocal1(port);
    4.84 -	struct ioctl_evtchn_bind_interdomain bind;
    4.85 -	int rc;
    4.86 +	evtchn_port_or_error_t rc;
    4.87  
    4.88 -	bind.remote_domain = Int_val(domid);
    4.89 -	bind.remote_port = Int_val(remote_port);
    4.90 -	rc = do_ioctl(Int_val(fd), IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
    4.91 +	rc = xc_evtchn_bind_interdomain(_H(xce), Int_val(domid), Int_val(remote_port));
    4.92  	if (rc == -1)
    4.93 -		caml_failwith("ioctl bind_interdomain failed");
    4.94 +		caml_failwith("evtchn bind_interdomain failed");
    4.95  	port = Val_int(rc);
    4.96  
    4.97  	CAMLreturn(port);
    4.98  }
    4.99  
   4.100 -CAMLprim value stub_eventchn_bind_dom_exc_virq(value fd)
   4.101 +CAMLprim value stub_eventchn_bind_dom_exc_virq(value xce)
   4.102  {
   4.103 -	CAMLparam1(fd);
   4.104 +	CAMLparam1(xce);
   4.105  	CAMLlocal1(port);
   4.106 -	struct ioctl_evtchn_bind_virq bind;
   4.107 -	int rc;
   4.108 +	evtchn_port_or_error_t rc;
   4.109  
   4.110 -	bind.virq = VIRQ_DOM_EXC;
   4.111 -	rc = do_ioctl(Int_val(fd), IOCTL_EVTCHN_BIND_VIRQ, &bind);
   4.112 +	rc = xc_evtchn_bind_virq(_H(xce), VIRQ_DOM_EXC);
   4.113  	if (rc == -1)
   4.114 -		caml_failwith("ioctl bind_virq failed");
   4.115 +		caml_failwith("evtchn bind_dom_exc_virq failed");
   4.116  	port = Val_int(rc);
   4.117  
   4.118  	CAMLreturn(port);
   4.119  }
   4.120  
   4.121 -CAMLprim value stub_eventchn_unbind(value fd, value port)
   4.122 +CAMLprim value stub_eventchn_unbind(value xce, value port)
   4.123  {
   4.124 -	CAMLparam2(fd, port);
   4.125 -	struct ioctl_evtchn_unbind unbind;
   4.126 +	CAMLparam2(xce, port);
   4.127  	int rc;
   4.128  
   4.129 -	unbind.port = Int_val(port);
   4.130 -	rc = do_ioctl(Int_val(fd), IOCTL_EVTCHN_UNBIND, &unbind);
   4.131 +	rc = xc_evtchn_unbind(_H(xce), Int_val(port));
   4.132  	if (rc == -1)
   4.133 -		caml_failwith("ioctl unbind failed");
   4.134 +		caml_failwith("evtchn unbind failed");
   4.135  
   4.136  	CAMLreturn(Val_unit);
   4.137  }
   4.138  
   4.139 -CAMLprim value stub_eventchn_read_port(value fd)
   4.140 +CAMLprim value stub_eventchn_pending(value xce)
   4.141  {
   4.142 -	CAMLparam1(fd);
   4.143 +	CAMLparam1(xce);
   4.144  	CAMLlocal1(result);
   4.145 -	evtchn_port_t port;
   4.146 +	evtchn_port_or_error_t port;
   4.147  
   4.148 -	if (do_read_port(Int_val(fd), &port))
   4.149 -		caml_failwith("read port failed");
   4.150 +	port = xc_evtchn_pending(_H(xce));
   4.151 +	if (port == -1)
   4.152 +		caml_failwith("evtchn pending failed");
   4.153  	result = Val_int(port);
   4.154  
   4.155  	CAMLreturn(result);
   4.156  }
   4.157  
   4.158 -CAMLprim value stub_eventchn_write_port(value fd, value _port)
   4.159 +CAMLprim value stub_eventchn_unmask(value xce, value _port)
   4.160  {
   4.161 -	CAMLparam2(fd, _port);
   4.162 +	CAMLparam2(xce, _port);
   4.163  	evtchn_port_t port;
   4.164  
   4.165  	port = Int_val(_port);
   4.166 -	if (do_write_port(Int_val(fd), port))
   4.167 -		caml_failwith("write port failed");
   4.168 +	if (xc_evtchn_unmask(_H(xce), port))
   4.169 +		caml_failwith("evtchn unmask failed");
   4.170  	CAMLreturn(Val_unit);
   4.171  }
     5.1 --- a/tools/ocaml/libs/xc/Makefile	Thu Jan 06 17:34:46 2011 +0000
     5.2 +++ b/tools/ocaml/libs/xc/Makefile	Thu Jan 06 17:37:00 2011 +0000
     5.3 @@ -2,15 +2,17 @@ TOPLEVEL=../..
     5.4  XEN_ROOT=$(TOPLEVEL)/../..
     5.5  include $(TOPLEVEL)/common.make
     5.6  
     5.7 -CFLAGS += -I../mmap -I./
     5.8 -OCAMLINCLUDE += -I ../mmap -I ../uuid
     5.9 +CFLAGS += -I../mmap -I./ -I$(XEN_ROOT)/tools/libxc
    5.10 +OCAMLINCLUDE += -I ../mmap -I ../uuid -I $(XEN_ROOT)/tools/libxc
    5.11  
    5.12  OBJS = xc
    5.13  INTF = xc.cmi
    5.14  LIBS = xc.cma xc.cmxa
    5.15  
    5.16 +LIBS_xc = -L$(XEN_ROOT)/tools/libxc -lxenctrl -lxenguest
    5.17 +
    5.18  xc_OBJS = $(OBJS)
    5.19 -xc_C_OBJS = xc_lib xc_stubs
    5.20 +xc_C_OBJS = xc_stubs
    5.21  
    5.22  OCAML_LIBRARY = xc
    5.23  
     6.1 --- a/tools/ocaml/libs/xc/xc.h	Thu Jan 06 17:34:46 2011 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,186 +0,0 @@
     6.4 -/*
     6.5 - * Copyright (C) 2006-2007 XenSource Ltd.
     6.6 - * Copyright (C) 2008      Citrix Ltd.
     6.7 - * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
     6.8 - *
     6.9 - * This program is free software; you can redistribute it and/or modify
    6.10 - * it under the terms of the GNU Lesser General Public License as published
    6.11 - * by the Free Software Foundation; version 2.1 only. with the special
    6.12 - * exception on linking described in file LICENSE.
    6.13 - *
    6.14 - * This program is distributed in the hope that it will be useful,
    6.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.17 - * GNU Lesser General Public License for more details.
    6.18 - */
    6.19 -
    6.20 -#include <xen/xen.h>
    6.21 -#include <xen/memory.h>
    6.22 -#include <xen/sysctl.h>
    6.23 -#include <xen/domctl.h>
    6.24 -#include <xen/sched.h>
    6.25 -#include <xen/sysctl.h>
    6.26 -#include <xen/sys/privcmd.h>
    6.27 -#include <xen/version.h>
    6.28 -#include <xen/foreign/x86_32.h>
    6.29 -#include <xen/foreign/x86_64.h>
    6.30 -#include <xen/hvm/params.h>
    6.31 -#include "xc_e820.h"
    6.32 -
    6.33 -typedef xen_domctl_getdomaininfo_t xc_domaininfo_t;
    6.34 -typedef xen_domctl_getvcpuinfo_t xc_vcpuinfo_t;
    6.35 -typedef xen_sysctl_physinfo_t xc_physinfo_t;
    6.36 -
    6.37 -struct xc_core_header {
    6.38 -	unsigned int xch_magic;
    6.39 -	unsigned int xch_nr_vcpus;
    6.40 -	unsigned int xch_nr_pages;
    6.41 -	unsigned int xch_ctxt_offset;
    6.42 -	unsigned int xch_index_offset;
    6.43 -	unsigned int xch_pages_offset;
    6.44 -};
    6.45 -
    6.46 -typedef union {
    6.47 -#if defined(__i386__) || defined(__x86_64__)
    6.48 -	vcpu_guest_context_x86_64_t x64;
    6.49 -	vcpu_guest_context_x86_32_t x32;
    6.50 -#endif
    6.51 -	vcpu_guest_context_t c;
    6.52 -} vcpu_guest_context_any_t;
    6.53 -
    6.54 -char * xc_error_get(void);
    6.55 -void xc_error_clear(void);
    6.56 -
    6.57 -int xc_using_injection(void);
    6.58 -
    6.59 -int xc_interface_open(void);
    6.60 -int xc_interface_close(int handle);
    6.61 -
    6.62 -int xc_domain_create(int handle, unsigned int ssidref,
    6.63 -                     xen_domain_handle_t dhandle,
    6.64 -                     unsigned int flags, unsigned int *pdomid);
    6.65 -int xc_domain_pause(int handle, unsigned int domid);
    6.66 -int xc_domain_unpause(int handle, unsigned int domid);
    6.67 -int xc_domain_resume_fast(int handle, unsigned int domid);
    6.68 -int xc_domain_destroy(int handle, unsigned int domid);
    6.69 -int xc_domain_shutdown(int handle, int domid, int reason);
    6.70 -
    6.71 -int xc_vcpu_setaffinity(int handle, unsigned int domid, int vcpu,
    6.72 -                        uint64_t cpumap);
    6.73 -int xc_vcpu_getaffinity(int handle, unsigned int domid, int vcpu,
    6.74 -                        uint64_t *cpumap);
    6.75 -
    6.76 -int xc_domain_getinfolist(int handle, unsigned int first_domain,
    6.77 -                          unsigned int max_domains, xc_domaininfo_t *info);
    6.78 -int xc_domain_getinfo(int handle, unsigned int first_domain,
    6.79 -                      xc_domaininfo_t *info);
    6.80 -
    6.81 -int xc_domain_setmaxmem(int handle, unsigned int domid, unsigned int max_memkb);
    6.82 -int xc_domain_set_memmap_limit(int handle, unsigned int domid,
    6.83 -                               unsigned long map_limitkb);
    6.84 -
    6.85 -int xc_domain_set_time_offset(int handle, unsigned int domid, int time_offset);
    6.86 -
    6.87 -int xc_domain_memory_increase_reservation(int handle, unsigned int domid,
    6.88 -                                          unsigned long nr_extents,
    6.89 -                                          unsigned int extent_order,
    6.90 -                                          unsigned int address_bits,
    6.91 -                                          xen_pfn_t *extent_start);
    6.92 -int xc_domain_memory_decrease_reservation(int handle, unsigned int domid,
    6.93 -                                          unsigned long nr_extents,
    6.94 -                                          unsigned int extent_order,
    6.95 -                                          unsigned int address_bits,
    6.96 -                                          xen_pfn_t *extent_start);
    6.97 -int xc_domain_memory_populate_physmap(int handle, unsigned int domid,
    6.98 -                                      unsigned long nr_extents,
    6.99 -                                      unsigned int extent_order,
   6.100 -                                      unsigned int address_bits,
   6.101 -                                      xen_pfn_t *extent_start);
   6.102 -int xc_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist);
   6.103 -int xc_domain_max_vcpus(int handle, unsigned int domid, unsigned int max);
   6.104 -int xc_domain_sethandle(int handle, unsigned int domid,
   6.105 -                        xen_domain_handle_t dhandle);
   6.106 -int xc_vcpu_getinfo(int handle, unsigned int domid, unsigned int vcpu,
   6.107 -                    xc_vcpuinfo_t *info);
   6.108 -int xc_domain_ioport_permission(int handle, unsigned int domid,
   6.109 -                                unsigned int first_port, unsigned int nr_ports,
   6.110 -                                unsigned int allow_access);
   6.111 -int xc_vcpu_setcontext(int handle, unsigned int domid,
   6.112 -                       unsigned int vcpu, vcpu_guest_context_any_t *ctxt);
   6.113 -int xc_vcpu_getcontext(int handle, unsigned int domid,
   6.114 -                       unsigned int vcpu, vcpu_guest_context_any_t *ctxt);
   6.115 -int xc_domain_irq_permission(int handle, unsigned int domid,
   6.116 -                             unsigned char pirq, unsigned char allow_access);
   6.117 -int xc_domain_iomem_permission(int handle, unsigned int domid,
   6.118 -                               unsigned long first_mfn, unsigned long nr_mfns,
   6.119 -                               unsigned char allow_access);
   6.120 -long long xc_domain_get_cpu_usage(int handle, unsigned int domid,
   6.121 -                                  unsigned int vcpu);
   6.122 -void *xc_map_foreign_range(int handle, unsigned int domid,
   6.123 -                           int size, int prot, unsigned long mfn);
   6.124 -int xc_map_foreign_ranges(int handle, unsigned int domid,
   6.125 -                          privcmd_mmap_entry_t *entries, int nr);
   6.126 -int xc_readconsolering(int handle, char **pbuffer,
   6.127 -                       unsigned int *pnr_chars, int clear);
   6.128 -int xc_send_debug_keys(int handle, char *keys);
   6.129 -int xc_physinfo(int handle, xc_physinfo_t *put_info);
   6.130 -int xc_pcpu_info(
   6.131 -	int handle, int max_cpus, xen_sysctl_cpuinfo_t *info, int *nr_cpus);
   6.132 -int xc_sched_id(int handle, int *sched_id);
   6.133 -int xc_version(int handle, int cmd, void *arg);
   6.134 -int xc_evtchn_alloc_unbound(int handle, unsigned int domid,
   6.135 -                            unsigned int remote_domid);
   6.136 -int xc_evtchn_reset(int handle, unsigned int domid);
   6.137 -
   6.138 -int xc_sched_credit_domain_set(int handle, unsigned int domid,
   6.139 -                               struct xen_domctl_sched_credit *sdom);
   6.140 -int xc_sched_credit_domain_get(int handle, unsigned int domid,
   6.141 -                               struct xen_domctl_sched_credit *sdom);
   6.142 -int xc_shadow_allocation_get(int handle, unsigned int domid,
   6.143 -			     uint32_t *mb);
   6.144 -int xc_shadow_allocation_set(int handle, unsigned int domid,
   6.145 -			     uint32_t mb);
   6.146 -int xc_domain_get_pfn_list(int handle, unsigned int domid,
   6.147 -                           uint64_t *pfn_array, unsigned long max_pfns);
   6.148 -int xc_hvm_check_pvdriver(int handle, unsigned int domid);
   6.149 -
   6.150 -int xc_domain_assign_device(int handle, unsigned int domid,
   6.151 -                            int domain, int bus, int slot, int func);
   6.152 -int xc_domain_deassign_device(int handle, unsigned int domid,
   6.153 -                              int domain, int bus, int slot, int func);
   6.154 -int xc_domain_test_assign_device(int handle, unsigned int domid,
   6.155 -                                 int domain, int bus, int slot, int func);
   6.156 -int xc_domain_watchdog(int handle, int id, uint32_t timeout);
   6.157 -int xc_domain_set_machine_address_size(int xc, uint32_t domid, unsigned int width);
   6.158 -int xc_domain_get_machine_address_size(int xc, uint32_t domid);
   6.159 -
   6.160 -int xc_domain_cpuid_set(int xc, unsigned int domid, int hvm,
   6.161 -                        uint32_t input, uint32_t oinput,
   6.162 -                        char *config[4], char *config_out[4]);
   6.163 -int xc_domain_cpuid_apply(int xc, unsigned int domid, int hvm);
   6.164 -int xc_cpuid_check(uint32_t input, uint32_t optsubinput,
   6.165 -                   char *config[4], char *config_out[4]);
   6.166 -
   6.167 -int xc_domain_send_s3resume(int handle, unsigned int domid);
   6.168 -int xc_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align);
   6.169 -int xc_domain_set_hpet(int handle, unsigned int domid, int hpet);
   6.170 -int xc_domain_set_timer_mode(int handle, unsigned int domid, int mode);
   6.171 -int xc_domain_get_acpi_s_state(int handle, unsigned int domid);
   6.172 -
   6.173 -#if XEN_SYSCTL_INTERFACE_VERSION >= 6
   6.174 -#define SAFEDIV(a, b)					(((b) > 0) ? (a) / (b) : (a))
   6.175 -#define COMPAT_FIELD_physinfo_get_nr_cpus(p)		(p).nr_cpus
   6.176 -#define COMPAT_FIELD_physinfo_get_sockets_per_node(p)	\
   6.177 -	SAFEDIV((p).nr_cpus, ((p).threads_per_core * (p).cores_per_socket * (p).nr_nodes))
   6.178 -#else
   6.179 -#define COMPAT_FIELD_physinfo_get_nr_cpus(p)		\
   6.180 -	((p).threads_per_core * (p).sockets_per_node *	\
   6.181 -	 (p).cores_per_socket * (p).threads_per_core)
   6.182 -#define COMPAT_FIELD_physinfo_get_sockets_per_node(p)	(p).sockets_per_node
   6.183 -#endif
   6.184 -
   6.185 -#if __XEN_LATEST_INTERFACE_VERSION__ >= 0x00030209
   6.186 -#define COMPAT_FIELD_ADDRESS_BITS		mem_flags
   6.187 -#else
   6.188 -#define COMPAT_FIELD_ADDRESS_BITS		address_bits
   6.189 -#endif
     7.1 --- a/tools/ocaml/libs/xc/xc.ml	Thu Jan 06 17:34:46 2011 +0000
     7.2 +++ b/tools/ocaml/libs/xc/xc.ml	Thu Jan 06 17:37:00 2011 +0000
     7.3 @@ -107,7 +107,7 @@ external sizeof_xen_pfn: unit -> int = "
     7.4  external interface_open: unit -> handle = "stub_xc_interface_open"
     7.5  external interface_close: handle -> unit = "stub_xc_interface_close"
     7.6  
     7.7 -external using_injection: unit -> bool = "stub_xc_using_injection"
     7.8 +external is_fake: unit -> bool = "stub_xc_interface_is_fake"
     7.9  
    7.10  let with_intf f =
    7.11  	let xc = interface_open () in
    7.12 @@ -127,9 +127,6 @@ external _domain_sethandle: handle -> do
    7.13  let domain_sethandle handle n uuid =
    7.14  	_domain_sethandle handle n (Uuid.int_array_of_uuid uuid)
    7.15  
    7.16 -external domain_setvmxassist: handle -> domid -> bool -> unit
    7.17 -       = "stub_xc_domain_setvmxassist"
    7.18 -
    7.19  external domain_max_vcpus: handle -> domid -> int -> unit
    7.20         = "stub_xc_domain_max_vcpus"
    7.21  
    7.22 @@ -165,9 +162,9 @@ external domain_iomem_permission: handle
    7.23  external domain_irq_permission: handle -> domid -> int -> bool -> unit
    7.24         = "stub_xc_domain_irq_permission"
    7.25  
    7.26 -external vcpu_affinity_set: handle -> domid -> int -> int64 -> unit
    7.27 +external vcpu_affinity_set: handle -> domid -> int -> bool array -> unit
    7.28         = "stub_xc_vcpu_setaffinity"
    7.29 -external vcpu_affinity_get: handle -> domid -> int -> int64
    7.30 +external vcpu_affinity_get: handle -> domid -> int -> bool array
    7.31         = "stub_xc_vcpu_getaffinity"
    7.32  
    7.33  external vcpu_context_get: handle -> domid -> int -> string
    7.34 @@ -207,13 +204,13 @@ external domain_set_machine_address_size
    7.35  external domain_get_machine_address_size: handle -> domid -> int
    7.36         = "stub_xc_domain_get_machine_address_size"
    7.37  
    7.38 -external domain_cpuid_set: handle -> domid -> bool -> (int64 * (int64 option))
    7.39 +external domain_cpuid_set: handle -> domid -> (int64 * (int64 option))
    7.40                          -> string option array
    7.41                          -> string option array
    7.42         = "stub_xc_domain_cpuid_set"
    7.43 -external domain_cpuid_apply: handle -> domid -> bool -> unit
    7.44 -       = "stub_xc_domain_cpuid_apply"
    7.45 -external cpuid_check: (int64 * (int64 option)) -> string option array -> (bool * string option array)
    7.46 +external domain_cpuid_apply_policy: handle -> domid -> unit
    7.47 +       = "stub_xc_domain_cpuid_apply_policy"
    7.48 +external cpuid_check: handle -> (int64 * (int64 option)) -> string option array -> (bool * string option array)
    7.49         = "stub_xc_cpuid_check"
    7.50  
    7.51  external map_foreign_range: handle -> domid -> int
    7.52 @@ -230,17 +227,6 @@ external domain_deassign_device: handle 
    7.53  external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
    7.54         = "stub_xc_domain_test_assign_device"
    7.55  
    7.56 -external domain_set_timer_mode: handle -> domid -> int -> unit = "stub_xc_domain_set_timer_mode"
    7.57 -external domain_set_hpet: handle -> domid -> int -> unit = "stub_xc_domain_set_hpet"
    7.58 -external domain_set_vpt_align: handle -> domid -> int -> unit = "stub_xc_domain_set_vpt_align"
    7.59 -
    7.60 -external domain_send_s3resume: handle -> domid -> unit = "stub_xc_domain_send_s3resume"
    7.61 -external domain_get_acpi_s_state: handle -> domid -> int = "stub_xc_domain_get_acpi_s_state"
    7.62 -
    7.63 -(** check if some hvm domain got pv driver or not *)
    7.64 -external hvm_check_pvdriver: handle -> domid -> bool
    7.65 -       = "stub_xc_hvm_check_pvdriver"
    7.66 -
    7.67  external version: handle -> version = "stub_xc_version_version"
    7.68  external version_compile_info: handle -> compile_info
    7.69         = "stub_xc_version_compile_info"
     8.1 --- a/tools/ocaml/libs/xc/xc.mli	Thu Jan 06 17:34:46 2011 +0000
     8.2 +++ b/tools/ocaml/libs/xc/xc.mli	Thu Jan 06 17:37:00 2011 +0000
     8.3 @@ -71,7 +71,7 @@ external sizeof_vcpu_guest_context : uni
     8.4    = "stub_sizeof_vcpu_guest_context"
     8.5  external sizeof_xen_pfn : unit -> int = "stub_sizeof_xen_pfn"
     8.6  external interface_open : unit -> handle = "stub_xc_interface_open"
     8.7 -external using_injection : unit -> bool = "stub_xc_using_injection"
     8.8 +external is_fake : unit -> bool = "stub_xc_interface_is_fake"
     8.9  external interface_close : handle -> unit = "stub_xc_interface_close"
    8.10  val with_intf : (handle -> 'a) -> 'a
    8.11  external _domain_create : handle -> int32 -> domain_create_flag list -> int array -> domid
    8.12 @@ -80,8 +80,6 @@ val domain_create : handle -> int32 -> d
    8.13  external _domain_sethandle : handle -> domid -> int array -> unit
    8.14    = "stub_xc_domain_sethandle"
    8.15  val domain_sethandle : handle -> domid -> 'a Uuid.t -> unit
    8.16 -external domain_setvmxassist: handle -> domid -> bool -> unit
    8.17 -  = "stub_xc_domain_setvmxassist"
    8.18  external domain_max_vcpus : handle -> domid -> int -> unit
    8.19    = "stub_xc_domain_max_vcpus"
    8.20  external domain_pause : handle -> domid -> unit = "stub_xc_domain_pause"
    8.21 @@ -104,9 +102,9 @@ external domain_iomem_permission: handle
    8.22         = "stub_xc_domain_iomem_permission"
    8.23  external domain_irq_permission: handle -> domid -> int -> bool -> unit
    8.24         = "stub_xc_domain_irq_permission"
    8.25 -external vcpu_affinity_set : handle -> domid -> int -> int64 -> unit
    8.26 +external vcpu_affinity_set : handle -> domid -> int -> bool array -> unit
    8.27    = "stub_xc_vcpu_setaffinity"
    8.28 -external vcpu_affinity_get : handle -> domid -> int -> int64
    8.29 +external vcpu_affinity_get : handle -> domid -> int -> bool array
    8.30    = "stub_xc_vcpu_getaffinity"
    8.31  external vcpu_context_get : handle -> domid -> int -> string
    8.32    = "stub_xc_vcpu_context_get"
    8.33 @@ -147,16 +145,6 @@ external domain_deassign_device: handle 
    8.34  external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
    8.35         = "stub_xc_domain_test_assign_device"
    8.36  
    8.37 -external domain_set_timer_mode: handle -> domid -> int -> unit = "stub_xc_domain_set_timer_mode"
    8.38 -external domain_set_hpet: handle -> domid -> int -> unit = "stub_xc_domain_set_hpet"
    8.39 -external domain_set_vpt_align: handle -> domid -> int -> unit = "stub_xc_domain_set_vpt_align"
    8.40 -
    8.41 -external domain_send_s3resume: handle -> domid -> unit
    8.42 -  = "stub_xc_domain_send_s3resume"
    8.43 -external domain_get_acpi_s_state: handle -> domid -> int = "stub_xc_domain_get_acpi_s_state"
    8.44 -
    8.45 -external hvm_check_pvdriver : handle -> domid -> bool
    8.46 -  = "stub_xc_hvm_check_pvdriver"
    8.47  external version : handle -> version = "stub_xc_version_version"
    8.48  external version_compile_info : handle -> compile_info
    8.49    = "stub_xc_version_compile_info"
    8.50 @@ -185,12 +173,12 @@ external domain_set_machine_address_size
    8.51  external domain_get_machine_address_size: handle -> domid -> int
    8.52         = "stub_xc_domain_get_machine_address_size"
    8.53  
    8.54 -external domain_cpuid_set: handle -> domid -> bool -> (int64 * (int64 option))
    8.55 +external domain_cpuid_set: handle -> domid -> (int64 * (int64 option))
    8.56                          -> string option array
    8.57                          -> string option array
    8.58         = "stub_xc_domain_cpuid_set"
    8.59 -external domain_cpuid_apply: handle -> domid -> bool -> unit
    8.60 -       = "stub_xc_domain_cpuid_apply"
    8.61 -external cpuid_check: (int64 * (int64 option)) -> string option array -> (bool * string option array)
    8.62 +external domain_cpuid_apply_policy: handle -> domid -> unit
    8.63 +       = "stub_xc_domain_cpuid_apply_policy"
    8.64 +external cpuid_check: handle -> (int64 * (int64 option)) -> string option array -> (bool * string option array)
    8.65         = "stub_xc_cpuid_check"
    8.66  
     9.1 --- a/tools/ocaml/libs/xc/xc_cpufeature.h	Thu Jan 06 17:34:46 2011 +0000
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,116 +0,0 @@
     9.4 -#ifndef __LIBXC_CPUFEATURE_H
     9.5 -#define __LIBXC_CPUFEATURE_H
     9.6 -
     9.7 -/* Intel-defined CPU features, CPUID level 0x00000001 (edx), word 0 */
     9.8 -#define X86_FEATURE_FPU		(0*32+ 0) /* Onboard FPU */
     9.9 -#define X86_FEATURE_VME		(0*32+ 1) /* Virtual Mode Extensions */
    9.10 -#define X86_FEATURE_DE		(0*32+ 2) /* Debugging Extensions */
    9.11 -#define X86_FEATURE_PSE 	(0*32+ 3) /* Page Size Extensions */
    9.12 -#define X86_FEATURE_TSC		(0*32+ 4) /* Time Stamp Counter */
    9.13 -#define X86_FEATURE_MSR		(0*32+ 5) /* Model-Specific Registers, RDMSR, WRMSR */
    9.14 -#define X86_FEATURE_PAE		(0*32+ 6) /* Physical Address Extensions */
    9.15 -#define X86_FEATURE_MCE		(0*32+ 7) /* Machine Check Architecture */
    9.16 -#define X86_FEATURE_CX8		(0*32+ 8) /* CMPXCHG8 instruction */
    9.17 -#define X86_FEATURE_APIC	(0*32+ 9) /* Onboard APIC */
    9.18 -#define X86_FEATURE_SEP		(0*32+11) /* SYSENTER/SYSEXIT */
    9.19 -#define X86_FEATURE_MTRR	(0*32+12) /* Memory Type Range Registers */
    9.20 -#define X86_FEATURE_PGE		(0*32+13) /* Page Global Enable */
    9.21 -#define X86_FEATURE_MCA		(0*32+14) /* Machine Check Architecture */
    9.22 -#define X86_FEATURE_CMOV	(0*32+15) /* CMOV instruction (FCMOVCC and FCOMI too if FPU present) */
    9.23 -#define X86_FEATURE_PAT		(0*32+16) /* Page Attribute Table */
    9.24 -#define X86_FEATURE_PSE36	(0*32+17) /* 36-bit PSEs */
    9.25 -#define X86_FEATURE_PN		(0*32+18) /* Processor serial number */
    9.26 -#define X86_FEATURE_CLFLSH	(0*32+19) /* Supports the CLFLUSH instruction */
    9.27 -#define X86_FEATURE_DS		(0*32+21) /* Debug Store */
    9.28 -#define X86_FEATURE_ACPI	(0*32+22) /* ACPI via MSR */
    9.29 -#define X86_FEATURE_MMX		(0*32+23) /* Multimedia Extensions */
    9.30 -#define X86_FEATURE_FXSR	(0*32+24) /* FXSAVE and FXRSTOR instructions (fast save and restore */
    9.31 -				          /* of FPU context), and CR4.OSFXSR available */
    9.32 -#define X86_FEATURE_XMM		(0*32+25) /* Streaming SIMD Extensions */
    9.33 -#define X86_FEATURE_XMM2	(0*32+26) /* Streaming SIMD Extensions-2 */
    9.34 -#define X86_FEATURE_SELFSNOOP	(0*32+27) /* CPU self snoop */
    9.35 -#define X86_FEATURE_HT		(0*32+28) /* Hyper-Threading */
    9.36 -#define X86_FEATURE_ACC		(0*32+29) /* Automatic clock control */
    9.37 -#define X86_FEATURE_IA64	(0*32+30) /* IA-64 processor */
    9.38 -#define X86_FEATURE_PBE		(0*32+31) /* Pending Break Enable */
    9.39 -
    9.40 -/* AMD-defined CPU features, CPUID level 0x80000001, word 1 */
    9.41 -/* Don't duplicate feature flags which are redundant with Intel! */
    9.42 -#define X86_FEATURE_SYSCALL	(1*32+11) /* SYSCALL/SYSRET */
    9.43 -#define X86_FEATURE_MP		(1*32+19) /* MP Capable. */
    9.44 -#define X86_FEATURE_NX		(1*32+20) /* Execute Disable */
    9.45 -#define X86_FEATURE_MMXEXT	(1*32+22) /* AMD MMX extensions */
    9.46 -#define X86_FEATURE_FFXSR       (1*32+25) /* FFXSR instruction optimizations */
    9.47 -#define X86_FEATURE_PAGE1GB	(1*32+26) /* 1Gb large page support */
    9.48 -#define X86_FEATURE_RDTSCP	(1*32+27) /* RDTSCP */
    9.49 -#define X86_FEATURE_LM		(1*32+29) /* Long Mode (x86-64) */
    9.50 -#define X86_FEATURE_3DNOWEXT	(1*32+30) /* AMD 3DNow! extensions */
    9.51 -#define X86_FEATURE_3DNOW	(1*32+31) /* 3DNow! */
    9.52 -
    9.53 -/* Transmeta-defined CPU features, CPUID level 0x80860001, word 2 */
    9.54 -#define X86_FEATURE_RECOVERY	(2*32+ 0) /* CPU in recovery mode */
    9.55 -#define X86_FEATURE_LONGRUN	(2*32+ 1) /* Longrun power control */
    9.56 -#define X86_FEATURE_LRTI	(2*32+ 3) /* LongRun table interface */
    9.57 -
    9.58 -/* Other features, Linux-defined mapping, word 3 */
    9.59 -/* This range is used for feature bits which conflict or are synthesized */
    9.60 -#define X86_FEATURE_CXMMX	(3*32+ 0) /* Cyrix MMX extensions */
    9.61 -#define X86_FEATURE_K6_MTRR	(3*32+ 1) /* AMD K6 nonstandard MTRRs */
    9.62 -#define X86_FEATURE_CYRIX_ARR	(3*32+ 2) /* Cyrix ARRs (= MTRRs) */
    9.63 -#define X86_FEATURE_CENTAUR_MCR	(3*32+ 3) /* Centaur MCRs (= MTRRs) */
    9.64 -/* cpu types for specific tunings: */
    9.65 -#define X86_FEATURE_K8		(3*32+ 4) /* Opteron, Athlon64 */
    9.66 -#define X86_FEATURE_K7		(3*32+ 5) /* Athlon */
    9.67 -#define X86_FEATURE_P3		(3*32+ 6) /* P3 */
    9.68 -#define X86_FEATURE_P4		(3*32+ 7) /* P4 */
    9.69 -#define X86_FEATURE_CONSTANT_TSC (3*32+ 8) /* TSC ticks at a constant rate */
    9.70 -
    9.71 -/* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */
    9.72 -#define X86_FEATURE_XMM3	(4*32+ 0) /* Streaming SIMD Extensions-3 */
    9.73 -#define X86_FEATURE_DTES64	(4*32+ 2) /* 64-bit Debug Store */
    9.74 -#define X86_FEATURE_MWAIT	(4*32+ 3) /* Monitor/Mwait support */
    9.75 -#define X86_FEATURE_DSCPL	(4*32+ 4) /* CPL Qualified Debug Store */
    9.76 -#define X86_FEATURE_VMXE	(4*32+ 5) /* Virtual Machine Extensions */
    9.77 -#define X86_FEATURE_SMXE	(4*32+ 6) /* Safer Mode Extensions */
    9.78 -#define X86_FEATURE_EST		(4*32+ 7) /* Enhanced SpeedStep */
    9.79 -#define X86_FEATURE_TM2		(4*32+ 8) /* Thermal Monitor 2 */
    9.80 -#define X86_FEATURE_SSSE3	(4*32+ 9) /* Supplemental Streaming SIMD Extensions-3 */
    9.81 -#define X86_FEATURE_CID		(4*32+10) /* Context ID */
    9.82 -#define X86_FEATURE_CX16        (4*32+13) /* CMPXCHG16B */
    9.83 -#define X86_FEATURE_XTPR	(4*32+14) /* Send Task Priority Messages */
    9.84 -#define X86_FEATURE_PDCM	(4*32+15) /* Perf/Debug Capability MSR */
    9.85 -#define X86_FEATURE_DCA		(4*32+18) /* Direct Cache Access */
    9.86 -#define X86_FEATURE_SSE4_1	(4*32+19) /* Streaming SIMD Extensions 4.1 */
    9.87 -#define X86_FEATURE_SSE4_2	(4*32+20) /* Streaming SIMD Extensions 4.2 */
    9.88 -#define X86_FEATURE_POPCNT	(4*32+23) /* POPCNT instruction */
    9.89 -#define X86_FEATURE_HYPERVISOR	(4*32+31) /* Running under some hypervisor */
    9.90 -
    9.91 -/* VIA/Cyrix/Centaur-defined CPU features, CPUID level 0xC0000001, word 5 */
    9.92 -#define X86_FEATURE_XSTORE	(5*32+ 2) /* on-CPU RNG present (xstore insn) */
    9.93 -#define X86_FEATURE_XSTORE_EN	(5*32+ 3) /* on-CPU RNG enabled */
    9.94 -#define X86_FEATURE_XCRYPT	(5*32+ 6) /* on-CPU crypto (xcrypt insn) */
    9.95 -#define X86_FEATURE_XCRYPT_EN	(5*32+ 7) /* on-CPU crypto enabled */
    9.96 -#define X86_FEATURE_ACE2	(5*32+ 8) /* Advanced Cryptography Engine v2 */
    9.97 -#define X86_FEATURE_ACE2_EN	(5*32+ 9) /* ACE v2 enabled */
    9.98 -#define X86_FEATURE_PHE		(5*32+ 10) /* PadLock Hash Engine */
    9.99 -#define X86_FEATURE_PHE_EN	(5*32+ 11) /* PHE enabled */
   9.100 -#define X86_FEATURE_PMM		(5*32+ 12) /* PadLock Montgomery Multiplier */
   9.101 -#define X86_FEATURE_PMM_EN	(5*32+ 13) /* PMM enabled */
   9.102 -
   9.103 -/* More extended AMD flags: CPUID level 0x80000001, ecx, word 6 */
   9.104 -#define X86_FEATURE_LAHF_LM	(6*32+ 0) /* LAHF/SAHF in long mode */
   9.105 -#define X86_FEATURE_CMP_LEGACY	(6*32+ 1) /* If yes HyperThreading not valid */
   9.106 -#define X86_FEATURE_SVME        (6*32+ 2) /* Secure Virtual Machine */
   9.107 -#define X86_FEATURE_EXTAPICSPACE (6*32+ 3) /* Extended APIC space */
   9.108 -#define X86_FEATURE_ALTMOVCR	(6*32+ 4) /* LOCK MOV CR accesses CR+8 */
   9.109 -#define X86_FEATURE_ABM		(6*32+ 5) /* Advanced Bit Manipulation */
   9.110 -#define X86_FEATURE_SSE4A	(6*32+ 6) /* AMD Streaming SIMD Extensions-4a */
   9.111 -#define X86_FEATURE_MISALIGNSSE	(6*32+ 7) /* Misaligned SSE Access */
   9.112 -#define X86_FEATURE_3DNOWPF	(6*32+ 8) /* 3DNow! Prefetch */
   9.113 -#define X86_FEATURE_OSVW	(6*32+ 9) /* OS Visible Workaround */
   9.114 -#define X86_FEATURE_IBS		(6*32+ 10) /* Instruction Based Sampling */
   9.115 -#define X86_FEATURE_SSE5	(6*32+ 11) /* AMD Streaming SIMD Extensions-5 */
   9.116 -#define X86_FEATURE_SKINIT	(6*32+ 12) /* SKINIT, STGI/CLGI, DEV */
   9.117 -#define X86_FEATURE_WDT		(6*32+ 13) /* Watchdog Timer */
   9.118 -
   9.119 -#endif /* __LIBXC_CPUFEATURE_H */
    10.1 --- a/tools/ocaml/libs/xc/xc_cpuid.h	Thu Jan 06 17:34:46 2011 +0000
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,285 +0,0 @@
    10.4 -#ifndef XC_CPUID_H
    10.5 -#define XC_CPUID_H
    10.6 -
    10.7 -#ifdef XEN_DOMCTL_set_cpuid
    10.8 -
    10.9 -#include "xc_cpufeature.h"
   10.10 -
   10.11 -#define bitmaskof(idx)      (1u << ((idx) & 31))
   10.12 -#define clear_bit(idx, dst) ((dst) &= ~(1u << ((idx) & 31)))
   10.13 -#define set_bit(idx, dst)   ((dst) |= (1u << ((idx) & 31)))
   10.14 -
   10.15 -#define DEF_MAX_BASE 0x00000004u
   10.16 -#define DEF_MAX_EXT  0x80000008u
   10.17 -
   10.18 -static void xc_cpuid(uint32_t eax, uint32_t ecx, uint32_t regs[4])
   10.19 -{
   10.20 -	unsigned int realecx = (ecx == XEN_CPUID_INPUT_UNUSED) ? 0 : ecx;
   10.21 -	asm (
   10.22 -#ifdef __i386__
   10.23 -	     "push %%ebx; cpuid; mov %%ebx,%1; pop %%ebx"
   10.24 -#else
   10.25 -	     "push %%rbx; cpuid; mov %%ebx,%1; pop %%rbx"
   10.26 -#endif
   10.27 -	    : "=a" (regs[0]), "=r" (regs[1]), "=c" (regs[2]), "=d" (regs[3])
   10.28 -	    : "0" (eax), "2" (realecx));
   10.29 -}
   10.30 -
   10.31 -enum { CPU_BRAND_INTEL, CPU_BRAND_AMD, CPU_BRAND_UNKNOWN };
   10.32 -
   10.33 -static int xc_cpuid_brand_get(void)
   10.34 -{
   10.35 -	uint32_t regs[4];
   10.36 -	char str[13];
   10.37 -	uint32_t *istr = (uint32_t *) str;
   10.38 -
   10.39 -	xc_cpuid(0, 0, regs);
   10.40 -	istr[0] = regs[1];
   10.41 -	istr[1] = regs[3];
   10.42 -	istr[2] = regs[2];
   10.43 -	str[12] = '\0';
   10.44 -	if      (strcmp(str, "AuthenticAMD") == 0) {
   10.45 -		return CPU_BRAND_AMD;
   10.46 -	} else if (strcmp(str, "GenuineIntel") == 0) {
   10.47 -		return CPU_BRAND_INTEL;
   10.48 -	} else
   10.49 -		return CPU_BRAND_UNKNOWN;
   10.50 -}
   10.51 -
   10.52 -static int hypervisor_is_64bit(int xc)
   10.53 -{
   10.54 -	xen_capabilities_info_t xen_caps;
   10.55 -	return ((xc_version(xc, XENVER_capabilities, &xen_caps) == 0) &&
   10.56 -	        (strstr(xen_caps, "x86_64") != NULL));
   10.57 -}
   10.58 -
   10.59 -static void do_hvm_cpuid_policy(int xc, int domid, uint32_t input, uint32_t regs[4])
   10.60 -{
   10.61 -	unsigned long is_pae;
   10.62 -	int brand;
   10.63 -
   10.64 -	/* pae ? */
   10.65 -	xc_get_hvm_param(xc, domid, HVM_PARAM_PAE_ENABLED, &is_pae);
   10.66 -	is_pae = !!is_pae;
   10.67 -
   10.68 -	switch (input) {
   10.69 -	case 0x00000000:
   10.70 -		if (regs[0] > DEF_MAX_BASE)
   10.71 -			regs[0] = DEF_MAX_BASE;
   10.72 -		break;
   10.73 -	case 0x00000001:
   10.74 -		regs[2] &= (bitmaskof(X86_FEATURE_XMM3) |
   10.75 -				bitmaskof(X86_FEATURE_SSSE3) |
   10.76 -				bitmaskof(X86_FEATURE_CX16) |
   10.77 -				bitmaskof(X86_FEATURE_SSE4_1) |
   10.78 -				bitmaskof(X86_FEATURE_SSE4_2) |
   10.79 -				bitmaskof(X86_FEATURE_POPCNT));
   10.80 -
   10.81 -                regs[2] |= bitmaskof(X86_FEATURE_HYPERVISOR);
   10.82 -
   10.83 -		regs[3] &= (bitmaskof(X86_FEATURE_FPU) |
   10.84 -				bitmaskof(X86_FEATURE_VME) |
   10.85 -				bitmaskof(X86_FEATURE_DE) |
   10.86 -				bitmaskof(X86_FEATURE_PSE) |
   10.87 -				bitmaskof(X86_FEATURE_TSC) |
   10.88 -				bitmaskof(X86_FEATURE_MSR) |
   10.89 -				bitmaskof(X86_FEATURE_PAE) |
   10.90 -				bitmaskof(X86_FEATURE_MCE) |
   10.91 -				bitmaskof(X86_FEATURE_CX8) |
   10.92 -				bitmaskof(X86_FEATURE_APIC) |
   10.93 -				bitmaskof(X86_FEATURE_SEP) |
   10.94 -				bitmaskof(X86_FEATURE_MTRR) |
   10.95 -				bitmaskof(X86_FEATURE_PGE) |
   10.96 -				bitmaskof(X86_FEATURE_MCA) |
   10.97 -				bitmaskof(X86_FEATURE_CMOV) |
   10.98 -				bitmaskof(X86_FEATURE_PAT) |
   10.99 -				bitmaskof(X86_FEATURE_CLFLSH) |
  10.100 -				bitmaskof(X86_FEATURE_MMX) |
  10.101 -				bitmaskof(X86_FEATURE_FXSR) |
  10.102 -				bitmaskof(X86_FEATURE_XMM) |
  10.103 -				bitmaskof(X86_FEATURE_XMM2));
  10.104 -		/* We always support MTRR MSRs. */
  10.105 -		regs[3] |= bitmaskof(X86_FEATURE_MTRR);
  10.106 -
  10.107 -		if (!is_pae)
  10.108 -			clear_bit(X86_FEATURE_PAE, regs[3]);
  10.109 -		break;
  10.110 -	case 0x80000000:
  10.111 -		if (regs[0] > DEF_MAX_EXT)
  10.112 -			regs[0] = DEF_MAX_EXT;
  10.113 -		break;
  10.114 -	case 0x80000001:
  10.115 -		if (!is_pae)
  10.116 -			clear_bit(X86_FEATURE_NX, regs[3]);
  10.117 -		break;
  10.118 -	case 0x80000008:
  10.119 -		regs[0] &= 0x0000ffffu;
  10.120 -		regs[1] = regs[2] = regs[3] = 0;
  10.121 -		break;
  10.122 -	case 0x00000002: /* Intel cache info (dumped by AMD policy) */
  10.123 -	case 0x00000004: /* Intel cache info (dumped by AMD policy) */
  10.124 -	case 0x80000002: /* Processor name string */
  10.125 -	case 0x80000003: /* ... continued         */
  10.126 -	case 0x80000004: /* ... continued         */
  10.127 -	case 0x80000005: /* AMD L1 cache/TLB info (dumped by Intel policy) */
  10.128 -	case 0x80000006: /* AMD L2/3 cache/TLB info ; Intel L2 cache features */
  10.129 -		break;
  10.130 -	default:
  10.131 -		regs[0] = regs[1] = regs[2] = regs[3] = 0;
  10.132 -		break;
  10.133 -	}
  10.134 -	
  10.135 -	brand = xc_cpuid_brand_get();
  10.136 -	if (brand == CPU_BRAND_AMD) {
  10.137 -		switch (input) {
  10.138 -		case 0x00000001:
  10.139 -			/* Mask Intel-only features. */
  10.140 -			regs[2] &= ~(bitmaskof(X86_FEATURE_SSSE3) |
  10.141 -					bitmaskof(X86_FEATURE_SSE4_1) |
  10.142 -					bitmaskof(X86_FEATURE_SSE4_2));
  10.143 -			break;
  10.144 -
  10.145 -		case 0x00000002:
  10.146 -		case 0x00000004:
  10.147 -			regs[0] = regs[1] = regs[2] = 0;
  10.148 -			break;
  10.149 -
  10.150 -		case 0x80000001: {
  10.151 -			int is_64bit = hypervisor_is_64bit(xc) && is_pae;
  10.152 -
  10.153 -			if (!is_pae)
  10.154 -				 clear_bit(X86_FEATURE_PAE, regs[3]);
  10.155 -			clear_bit(X86_FEATURE_PSE36, regs[3]);
  10.156 -
  10.157 -			/* Filter all other features according to a whitelist. */
  10.158 -			regs[2] &= ((is_64bit ? bitmaskof(X86_FEATURE_LAHF_LM) : 0) |
  10.159 -					 bitmaskof(X86_FEATURE_ALTMOVCR) |
  10.160 -					 bitmaskof(X86_FEATURE_ABM) |
  10.161 -					 bitmaskof(X86_FEATURE_SSE4A) |
  10.162 -					 bitmaskof(X86_FEATURE_MISALIGNSSE) |
  10.163 -					 bitmaskof(X86_FEATURE_3DNOWPF));
  10.164 -			regs[3] &= (0x0183f3ff | /* features shared with 0x00000001:EDX */
  10.165 -					 (is_pae ? bitmaskof(X86_FEATURE_NX) : 0) |
  10.166 -					 (is_64bit ? bitmaskof(X86_FEATURE_LM) : 0) |
  10.167 -					 bitmaskof(X86_FEATURE_SYSCALL) |
  10.168 -					 bitmaskof(X86_FEATURE_MP) |
  10.169 -					 bitmaskof(X86_FEATURE_MMXEXT) |
  10.170 -					 bitmaskof(X86_FEATURE_FFXSR) |
  10.171 -					 bitmaskof(X86_FEATURE_3DNOW) |
  10.172 -					 bitmaskof(X86_FEATURE_3DNOWEXT));
  10.173 -			break;
  10.174 -			}
  10.175 -		}
  10.176 -	} else if (brand == CPU_BRAND_INTEL) {
  10.177 -		switch (input) {
  10.178 -		case 0x00000001:
  10.179 -			/* Mask AMD-only features. */
  10.180 -			regs[2] &= ~(bitmaskof(X86_FEATURE_POPCNT));
  10.181 -			break;
  10.182 -
  10.183 -		case 0x00000004:
  10.184 -			regs[0] &= 0x3FF;
  10.185 -			regs[3] &= 0x3FF;
  10.186 -			break;
  10.187 -
  10.188 -		case 0x80000001:
  10.189 -			{
  10.190 -			int is_64bit = hypervisor_is_64bit(xc) && is_pae;
  10.191 -
  10.192 -			/* Only a few features are advertised in Intel's 0x80000001. */
  10.193 -			regs[2] &= (is_64bit ? bitmaskof(X86_FEATURE_LAHF_LM) : 0);
  10.194 -			regs[3] &= ((is_pae ? bitmaskof(X86_FEATURE_NX) : 0) |
  10.195 -					(is_64bit ? bitmaskof(X86_FEATURE_LM) : 0) |
  10.196 -					(is_64bit ? bitmaskof(X86_FEATURE_SYSCALL) : 0));
  10.197 -			break;
  10.198 -			}
  10.199 -		case 0x80000005:
  10.200 -			{
  10.201 -			regs[0] = regs[1] = regs[2] = 0;
  10.202 -			break;
  10.203 -			}
  10.204 -		}
  10.205 -	}
  10.206 -}
  10.207 -
  10.208 -static void do_pv_cpuid_policy(int xc, int domid, uint32_t input, uint32_t regs[4])
  10.209 -{
  10.210 -	int brand;
  10.211 -	int guest_64_bits, xen_64_bits;
  10.212 -	int ret;
  10.213 -	
  10.214 -	ret = xc_domain_get_machine_address_size(xc, domid);
  10.215 -	if (ret < 0)
  10.216 -		return;
  10.217 -	guest_64_bits = (ret == 64);
  10.218 -	xen_64_bits = hypervisor_is_64bit(xc);
  10.219 -	brand = xc_cpuid_brand_get();
  10.220 -
  10.221 -	if ((input & 0x7fffffff) == 1) {
  10.222 -		clear_bit(X86_FEATURE_VME, regs[3]);
  10.223 -		clear_bit(X86_FEATURE_PSE, regs[3]);
  10.224 -		clear_bit(X86_FEATURE_PGE, regs[3]);
  10.225 -		clear_bit(X86_FEATURE_MCE, regs[3]);
  10.226 -		clear_bit(X86_FEATURE_MCA, regs[3]);
  10.227 -		clear_bit(X86_FEATURE_MTRR, regs[3]);
  10.228 -		clear_bit(X86_FEATURE_PSE36, regs[3]);
  10.229 -	}
  10.230 -
  10.231 -	switch (input) {
  10.232 -	case 1:
  10.233 -		if (!xen_64_bits || brand == CPU_BRAND_AMD)
  10.234 -			clear_bit(X86_FEATURE_SEP, regs[3]);
  10.235 -		clear_bit(X86_FEATURE_DS, regs[3]);
  10.236 -		clear_bit(X86_FEATURE_ACC, regs[3]);
  10.237 -		clear_bit(X86_FEATURE_PBE, regs[3]);
  10.238 -
  10.239 -		clear_bit(X86_FEATURE_DTES64, regs[2]);
  10.240 -		clear_bit(X86_FEATURE_MWAIT, regs[2]);
  10.241 -		clear_bit(X86_FEATURE_DSCPL, regs[2]);
  10.242 -		clear_bit(X86_FEATURE_VMXE, regs[2]);
  10.243 -		clear_bit(X86_FEATURE_SMXE, regs[2]);
  10.244 -		clear_bit(X86_FEATURE_EST, regs[2]);
  10.245 -		clear_bit(X86_FEATURE_TM2, regs[2]);
  10.246 -		if (!guest_64_bits)
  10.247 -			clear_bit(X86_FEATURE_CX16, regs[2]);
  10.248 -		clear_bit(X86_FEATURE_XTPR, regs[2]);
  10.249 -		clear_bit(X86_FEATURE_PDCM, regs[2]);
  10.250 -		clear_bit(X86_FEATURE_DCA, regs[2]);
  10.251 -		break;
  10.252 -	case 0x80000001:
  10.253 -		if (!guest_64_bits) {
  10.254 -			clear_bit(X86_FEATURE_LM, regs[3]);
  10.255 -			clear_bit(X86_FEATURE_LAHF_LM, regs[2]);
  10.256 -			if (brand != CPU_BRAND_AMD)
  10.257 -				clear_bit(X86_FEATURE_SYSCALL, regs[3]);
  10.258 -		} else
  10.259 -			set_bit(X86_FEATURE_SYSCALL, regs[3]);
  10.260 -		clear_bit(X86_FEATURE_PAGE1GB, regs[3]);
  10.261 -		clear_bit(X86_FEATURE_RDTSCP, regs[3]);
  10.262 -
  10.263 -		clear_bit(X86_FEATURE_SVME, regs[2]);
  10.264 -		clear_bit(X86_FEATURE_OSVW, regs[2]);
  10.265 -		clear_bit(X86_FEATURE_IBS, regs[2]);
  10.266 -		clear_bit(X86_FEATURE_SKINIT, regs[2]);
  10.267 -		clear_bit(X86_FEATURE_WDT, regs[2]);
  10.268 -		break;
  10.269 -	case 5: /* MONITOR/MWAIT */
  10.270 -	case 0xa: /* Architectural Performance Monitor Features */
  10.271 -	case 0x8000000a: /* SVM revision and features */
  10.272 -	case 0x8000001b: /* Instruction Based Sampling */
  10.273 -		regs[0] = regs[1] = regs[2] = regs[3] = 0;
  10.274 -		break;
  10.275 -	}
  10.276 -}
  10.277 -
  10.278 -static void do_cpuid_policy(int xc, int domid, int hvm, uint32_t input, uint32_t regs[4])
  10.279 -{
  10.280 -	if (hvm)
  10.281 -		do_hvm_cpuid_policy(xc, domid, input, regs);
  10.282 -	else
  10.283 -		do_pv_cpuid_policy(xc, domid, input, regs);
  10.284 -}
  10.285 -
  10.286 -#endif
  10.287 -
  10.288 -#endif
    11.1 --- a/tools/ocaml/libs/xc/xc_e820.h	Thu Jan 06 17:34:46 2011 +0000
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,20 +0,0 @@
    11.4 -#ifndef __XC_E820_H__
    11.5 -#define __XC_E820_H__
    11.6 -
    11.7 -#include <xen/hvm/e820.h>
    11.8 -
    11.9 -/*
   11.10 - * PC BIOS standard E820 types and structure.
   11.11 - */
   11.12 -#define E820_RAM          1
   11.13 -#define E820_RESERVED     2
   11.14 -#define E820_ACPI         3
   11.15 -#define E820_NVS          4
   11.16 -
   11.17 -struct e820entry {
   11.18 -    uint64_t addr;
   11.19 -    uint64_t size;
   11.20 -    uint32_t type;
   11.21 -} __attribute__((packed));
   11.22 -
   11.23 -#endif /* __XC_E820_H__ */
    12.1 --- a/tools/ocaml/libs/xc/xc_lib.c	Thu Jan 06 17:34:46 2011 +0000
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,1537 +0,0 @@
    12.4 -/*
    12.5 - * Copyright (C) 2006-2007 XenSource Ltd.
    12.6 - * Copyright (C) 2008      Citrix Ltd.
    12.7 - * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
    12.8 - *
    12.9 - * This program is free software; you can redistribute it and/or modify
   12.10 - * it under the terms of the GNU Lesser General Public License as published
   12.11 - * by the Free Software Foundation; version 2.1 only. with the special
   12.12 - * exception on linking described in file LICENSE.
   12.13 - *
   12.14 - * This program is distributed in the hope that it will be useful,
   12.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.17 - * GNU Lesser General Public License for more details.
   12.18 - */
   12.19 -
   12.20 -#include <stdint.h>
   12.21 -#include <unistd.h>
   12.22 -#include <string.h>
   12.23 -#include <fcntl.h>
   12.24 -#include <stdio.h>
   12.25 -#include <errno.h>
   12.26 -#include <sys/ioctl.h>
   12.27 -#include <sys/mman.h>
   12.28 -#include <sys/types.h>
   12.29 -#include <sys/stat.h>
   12.30 -#include <stdlib.h>
   12.31 -#include <stdarg.h>
   12.32 -
   12.33 -#include "xc.h"
   12.34 -
   12.35 -#define PAGE_SHIFT		12
   12.36 -#define PAGE_SIZE               (1UL << PAGE_SHIFT)
   12.37 -#define PAGE_MASK               (~(PAGE_SIZE-1))
   12.38 -
   12.39 -#define MIN(a, b) 		(((a) < (b)) ? (a) : (b))
   12.40 -
   12.41 -#define DECLARE_DOMCTL(_cmd, _domain)	\
   12.42 -	struct xen_domctl domctl = {    \
   12.43 -		.cmd = _cmd,		\
   12.44 -		.domain = _domain,	\
   12.45 -		.interface_version = XEN_DOMCTL_INTERFACE_VERSION, \
   12.46 -	}
   12.47 -
   12.48 -#define DECLARE_SYSCTL(_cmd)		\
   12.49 -	struct xen_sysctl sysctl = {	\
   12.50 -		.cmd = _cmd,		\
   12.51 -		.interface_version = XEN_SYSCTL_INTERFACE_VERSION, \
   12.52 -	}
   12.53 -
   12.54 -#define DECLARE_HYPERCALL2(_cmd, _arg0, _arg1)	\
   12.55 -	privcmd_hypercall_t hypercall = {	\
   12.56 -		.op = _cmd,			\
   12.57 -		.arg[0] = (unsigned long) _arg0,\
   12.58 -		.arg[1] = (unsigned long) _arg1,\
   12.59 -	}
   12.60 -#define DECLARE_HYPERCALL0(_cmd)	DECLARE_HYPERCALL2(_cmd, 0, 0);
   12.61 -#define DECLARE_HYPERCALL1(_cmd, _arg0)	DECLARE_HYPERCALL2(_cmd, _arg0, 0);
   12.62 -
   12.63 -/*---- Errors handlings ----*/
   12.64 -#ifndef WITHOUT_GOOD_ERROR
   12.65 -#define ERROR_STRLEN 256
   12.66 -
   12.67 -static char __error_str[ERROR_STRLEN];
   12.68 -
   12.69 -char * xc_error_get(void)
   12.70 -{
   12.71 -	return __error_str;
   12.72 -}
   12.73 -
   12.74 -static void xc_error_set(const char *fmt, ...)
   12.75 -{
   12.76 -	va_list ap;
   12.77 -	char __errordup[ERROR_STRLEN];
   12.78 -
   12.79 -	va_start(ap, fmt);
   12.80 -	vsnprintf(__errordup, ERROR_STRLEN, fmt, ap);
   12.81 -	va_end(ap);
   12.82 -	memcpy(__error_str, __errordup, ERROR_STRLEN);
   12.83 -}
   12.84 -
   12.85 -static void xc_error_dom_set(unsigned int domid, const char *fmt, ...)
   12.86 -{
   12.87 -	va_list ap;
   12.88 -	char __errordup[ERROR_STRLEN];
   12.89 -	int i;
   12.90 -
   12.91 -	i = snprintf(__errordup, ERROR_STRLEN, "domain %u - ", domid);
   12.92 -	va_start(ap, fmt);
   12.93 -	i += vsnprintf(__errordup + i, ERROR_STRLEN - i, fmt, ap);
   12.94 -	va_end(ap);
   12.95 -	snprintf(__errordup + i, ERROR_STRLEN - i,
   12.96 -	         " failed: %s", xc_error_get());
   12.97 -	memcpy(__error_str, __errordup, ERROR_STRLEN);
   12.98 -}
   12.99 -
  12.100 -void xc_error_clear(void)
  12.101 -{
  12.102 -	memset(__error_str, '\0', ERROR_STRLEN);
  12.103 -}
  12.104 -#else
  12.105 -char * xc_error_get(void)
  12.106 -{
  12.107 -	return "";
  12.108 -}
  12.109 -#define xc_error_set(fmt, ...) do {} while (0)
  12.110 -#define xc_error_dom_set(id, fmt, ...) do {} while (0)
  12.111 -#define xc_error_clear() do {} while (0)
  12.112 -#endif
  12.113 -
  12.114 -#define xc_error_hypercall(_h, _r) \
  12.115 -	xc_error_set("hypercall %lld fail: %d: %s (ret %d)", _h.op, errno, errno ? strerror(errno) : strerror(-_r), _r)
  12.116 -
  12.117 -int xc_using_injection(void)
  12.118 -{
  12.119 -	return 0;
  12.120 -}
  12.121 -
  12.122 -/*---- Trivia ----*/
  12.123 -int xc_interface_open(void)
  12.124 -{
  12.125 -	int fd, ret;
  12.126 -
  12.127 -	fd = open("/proc/xen/privcmd", O_RDWR);
  12.128 -	if (fd == -1) {
  12.129 -		xc_error_set("open /proc/xen/privcmd failed: %s",
  12.130 -		             strerror(errno));
  12.131 -		return -1;
  12.132 -	}
  12.133 -
  12.134 -	ret = fcntl(fd, F_GETFD);
  12.135 -	if (ret < 0) {
  12.136 -		xc_error_set("cannot get handle flags: %s",
  12.137 -		             strerror(errno));
  12.138 -		goto out;
  12.139 -	}
  12.140 -
  12.141 -	ret = fcntl(fd, F_SETFD, ret | FD_CLOEXEC);
  12.142 -	if (ret < 0) {
  12.143 -		xc_error_set("cannot set handle flags: %s",
  12.144 -		             strerror(errno));
  12.145 -		goto out;
  12.146 -	}
  12.147 -
  12.148 -	return fd;
  12.149 -out:
  12.150 -	close(fd);
  12.151 -	return -1;
  12.152 -}
  12.153 -
  12.154 -int xc_interface_close(int handle)
  12.155 -{
  12.156 -	int ret;
  12.157 -
  12.158 -	ret = close(handle);
  12.159 -	if (ret != 0)
  12.160 -		xc_error_set("close xc failed: %s", strerror(errno));
  12.161 -	return ret;
  12.162 -}
  12.163 -
  12.164 -/*---- Low private operations ----*/
  12.165 -static int do_xen_hypercall(int handle, privcmd_hypercall_t *hypercall)
  12.166 -{
  12.167 -	return ioctl(handle, IOCTL_PRIVCMD_HYPERCALL, (unsigned long) hypercall);
  12.168 -}
  12.169 -
  12.170 -static int do_domctl(int handle, struct xen_domctl *domctl)
  12.171 -{
  12.172 -	int ret;
  12.173 -	DECLARE_HYPERCALL1(__HYPERVISOR_domctl, domctl);
  12.174 -
  12.175 -	if (mlock(domctl, sizeof(*domctl)) != 0) {
  12.176 -		xc_error_set("mlock failed: %s", strerror(errno));
  12.177 -		return -1;
  12.178 -	}
  12.179 -
  12.180 -	ret = do_xen_hypercall(handle, &hypercall);
  12.181 -	if (ret < 0)
  12.182 -		xc_error_hypercall(hypercall, ret);
  12.183 -
  12.184 -	munlock(domctl, sizeof(*domctl));
  12.185 -	return ret;
  12.186 -}
  12.187 -
  12.188 -static int do_sysctl(int handle, struct xen_sysctl *sysctl)
  12.189 -{
  12.190 -	int ret;
  12.191 -	DECLARE_HYPERCALL1(__HYPERVISOR_sysctl, sysctl);
  12.192 -
  12.193 -	if (mlock(sysctl, sizeof(*sysctl)) != 0) {
  12.194 -		xc_error_set("mlock failed: %s", strerror(errno));
  12.195 -		return -1;
  12.196 -	}
  12.197 -
  12.198 -	ret = do_xen_hypercall(handle, &hypercall);
  12.199 -	if (ret < 0)
  12.200 -		xc_error_hypercall(hypercall, ret);
  12.201 -
  12.202 -	munlock(sysctl, sizeof(*sysctl));
  12.203 -	return ret;
  12.204 -}
  12.205 -
  12.206 -static int do_evtchnctl(int handle, int cmd, void *arg, size_t arg_size)
  12.207 -{
  12.208 -	DECLARE_HYPERCALL2(__HYPERVISOR_event_channel_op, cmd, arg);
  12.209 -	int ret;
  12.210 -
  12.211 -	if (mlock(arg, arg_size) != 0) {
  12.212 -		xc_error_set("mlock failed: %s", strerror(errno));
  12.213 -		return -1;
  12.214 -	}
  12.215 -
  12.216 -	ret = do_xen_hypercall(handle, &hypercall);
  12.217 -	if (ret < 0)
  12.218 -		xc_error_hypercall(hypercall, ret);
  12.219 -	munlock(arg, arg_size);
  12.220 -	return ret;
  12.221 -}
  12.222 -
  12.223 -static int do_memctl_reservation(int handle, int cmd,
  12.224 -                                 struct xen_memory_reservation *reservation)
  12.225 -{
  12.226 -	int ret;
  12.227 -	DECLARE_HYPERCALL2(__HYPERVISOR_memory_op, cmd, reservation);
  12.228 -	xen_pfn_t *extent_start;
  12.229 -
  12.230 -	if (cmd != XENMEM_increase_reservation &&
  12.231 -	    cmd != XENMEM_decrease_reservation &&
  12.232 -	    cmd != XENMEM_populate_physmap) {
  12.233 -		xc_error_set("do_memctl_reservation: unknown cmd %d", cmd);
  12.234 -		return -EINVAL;
  12.235 -	}
  12.236 -
  12.237 -	if (mlock(reservation, sizeof(*reservation)) == -1) {
  12.238 -		xc_error_set("mlock failed: %s", strerror(errno));
  12.239 -		return -ENOMEM;
  12.240 -	}
  12.241 -	get_xen_guest_handle(extent_start, reservation->extent_start);
  12.242 -	if (extent_start && mlock(extent_start, reservation->nr_extents
  12.243 -	                                      * sizeof(xen_pfn_t)) == -1) {
  12.244 -		xc_error_set("mlock failed: %s", strerror(errno));
  12.245 -		munlock(reservation, sizeof(*reservation));
  12.246 -		return -3;
  12.247 -	}
  12.248 -
  12.249 -	ret = do_xen_hypercall(handle, &hypercall);
  12.250 -	if (ret)
  12.251 -		xc_error_hypercall(hypercall, ret);
  12.252 -	munlock(extent_start, reservation->nr_extents * sizeof(xen_pfn_t));
  12.253 -	get_xen_guest_handle(extent_start, reservation->extent_start);
  12.254 -	munlock(reservation, sizeof(*reservation));
  12.255 -	return ret;
  12.256 -}
  12.257 -
  12.258 -static int do_ioctl(int handle, int cmd, void *arg)
  12.259 -{
  12.260 -	return ioctl(handle, cmd, arg);
  12.261 -}
  12.262 -
  12.263 -static void * do_mmap(void *start, size_t length, int prot, int flags,
  12.264 -                      int fd, off_t offset)
  12.265 -{
  12.266 -	return mmap(start, length, prot, flags, fd, offset);
  12.267 -}
  12.268 -
  12.269 -int xc_get_hvm_param(int handle, unsigned int domid,
  12.270 -                     int param, unsigned long *value)
  12.271 -{
  12.272 -	struct xen_hvm_param arg = {
  12.273 -		.domid = domid,
  12.274 -		.index = param,
  12.275 -	};
  12.276 -	DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_get_param,
  12.277 -	                   (unsigned long) &arg);
  12.278 -	int ret;
  12.279 -
  12.280 -	if (mlock(&arg, sizeof(arg)) == -1) {
  12.281 -		xc_error_set("mlock failed: %s", strerror(errno));
  12.282 -		return -1;
  12.283 -	}
  12.284 -
  12.285 -	ret = do_xen_hypercall(handle, &hypercall);
  12.286 -	if (ret)
  12.287 -		xc_error_hypercall(hypercall, ret);
  12.288 -	*value = arg.value;
  12.289 -	munlock(&arg, sizeof(arg));
  12.290 -	return ret;
  12.291 -}
  12.292 -
  12.293 -static int xc_set_hvm_param(int handle, unsigned int domid,
  12.294 -                            int param, unsigned long value)
  12.295 -{
  12.296 -	struct xen_hvm_param arg = {
  12.297 -		.domid = domid,
  12.298 -		.index = param,
  12.299 -		.value = value,
  12.300 -	};
  12.301 -	DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_set_param, (unsigned long) &arg);
  12.302 -	int ret;
  12.303 -
  12.304 -	if (mlock(&arg, sizeof(arg)) == -1) {
  12.305 -		xc_error_set("mlock failed: %s", strerror(errno));
  12.306 -		return -1;
  12.307 -	}
  12.308 -
  12.309 -	ret = do_xen_hypercall(handle, &hypercall);
  12.310 -	if (ret)
  12.311 -		xc_error_hypercall(hypercall, ret);
  12.312 -	munlock(&arg, sizeof(arg));
  12.313 -	return ret;
  12.314 -}
  12.315 -
  12.316 -
  12.317 -/*---- XC API ----*/
  12.318 -int xc_domain_create(int handle, unsigned int ssidref,
  12.319 -                     xen_domain_handle_t dhandle,
  12.320 -                     unsigned int flags, unsigned int *pdomid)
  12.321 -{
  12.322 -	int ret;
  12.323 -	DECLARE_DOMCTL(XEN_DOMCTL_createdomain, *pdomid);
  12.324 -	domctl.u.createdomain.ssidref = ssidref;
  12.325 -	domctl.u.createdomain.flags = flags;
  12.326 -	memcpy(domctl.u.createdomain.handle, dhandle, sizeof(xen_domain_handle_t));
  12.327 -
  12.328 -	ret = do_domctl(handle, &domctl);
  12.329 -	if (ret != 0) {
  12.330 -		xc_error_set("creating domain failed: %s", xc_error_get());
  12.331 -		return ret;
  12.332 -	}
  12.333 -	*pdomid = domctl.domain;
  12.334 -	return 0;
  12.335 -}
  12.336 -
  12.337 -int xc_domain_pause(int handle, unsigned int domid)
  12.338 -{
  12.339 -	int ret;
  12.340 -	DECLARE_DOMCTL(XEN_DOMCTL_pausedomain, domid);
  12.341 -
  12.342 -	ret = do_domctl(handle, &domctl);
  12.343 -	if (ret != 0)
  12.344 -		xc_error_dom_set(domid, "pause");
  12.345 -	return ret;
  12.346 -}
  12.347 -
  12.348 -int xc_domain_unpause(int handle, unsigned int domid)
  12.349 -{
  12.350 -	int ret;
  12.351 -	DECLARE_DOMCTL(XEN_DOMCTL_unpausedomain, domid);
  12.352 -
  12.353 -	ret = do_domctl(handle, &domctl);
  12.354 -	if (ret != 0)
  12.355 -		xc_error_dom_set(domid, "unpause");
  12.356 -	return ret;
  12.357 -}
  12.358 -
  12.359 -/* return 1 if hvm domain got pv driver, 0 if not. -1 is error occurs */
  12.360 -int xc_hvm_check_pvdriver(int handle, unsigned int domid)
  12.361 -{
  12.362 -	int ret;
  12.363 -	unsigned long irq = 0;
  12.364 -	xc_domaininfo_t info;
  12.365 -
  12.366 -	ret = xc_domain_getinfolist(handle, domid, 1, &info);
  12.367 -	if (ret != 1) {
  12.368 -		xc_error_set("domain getinfo failed: %s", strerror(errno));
  12.369 -		xc_error_dom_set(domid, "hvm_check_pvdriver");
  12.370 -		return -1;
  12.371 -	}
  12.372 -
  12.373 -	if (!(info.flags & XEN_DOMINF_hvm_guest)) {
  12.374 -		xc_error_set("domain is not hvm");
  12.375 -		xc_error_dom_set(domid, "hvm_check_pvdriver");
  12.376 -		return -1;
  12.377 -	}
  12.378 -	xc_get_hvm_param(handle, domid, HVM_PARAM_CALLBACK_IRQ, &irq);
  12.379 -	return irq;
  12.380 -}
  12.381 -
  12.382 -static int modify_returncode_register(int handle, unsigned int domid)
  12.383 -{
  12.384 -	int ret;
  12.385 -	xc_domaininfo_t info;
  12.386 -	xen_capabilities_info_t caps;
  12.387 -	vcpu_guest_context_any_t context;
  12.388 -
  12.389 -	ret = xc_domain_getinfolist(handle, domid, 1, &info);
  12.390 -	if (ret != 1) {
  12.391 -		xc_error_set("domain getinfo failed: %s", strerror(errno));
  12.392 -		return -1;
  12.393 -	}
  12.394 -
  12.395 -	/* HVM guests without PV drivers do not have a return code to modify */
  12.396 -	if (info.flags & XEN_DOMINF_hvm_guest) {
  12.397 -		unsigned long irq = 0;
  12.398 -		xc_get_hvm_param(handle, domid, HVM_PARAM_CALLBACK_IRQ, &irq);
  12.399 -		if (!irq)
  12.400 -			return 0;
  12.401 -	}
  12.402 -
  12.403 -	ret = xc_version(handle, XENVER_capabilities, &caps);
  12.404 -	if (ret) {
  12.405 -		xc_error_set("could not get Xen capabilities");
  12.406 -		return ret;
  12.407 -	}
  12.408 -
  12.409 -	ret = xc_vcpu_getcontext(handle, domid, 0, &context);
  12.410 -	if (ret) {
  12.411 -		xc_error_set("could not get vcpu 0 context");
  12.412 -		return ret;
  12.413 -	}
  12.414 -
  12.415 -	if (!(info.flags & XEN_DOMINF_hvm_guest))
  12.416 -		context.c.user_regs.eax = 1;
  12.417 -	else if (strstr(caps, "x86_64"))
  12.418 -		context.x64.user_regs.eax = 1;
  12.419 -	else
  12.420 -		context.x32.user_regs.eax = 1;
  12.421 -
  12.422 -	ret = xc_vcpu_setcontext(handle, domid, 0, &context);
  12.423 -	if (ret) {
  12.424 -		xc_error_set("could not set vcpu 0 context");
  12.425 -		return ret;
  12.426 -	}
  12.427 -	return 0;
  12.428 -}
  12.429 -
  12.430 -int xc_domain_resume_fast(int handle, unsigned int domid)
  12.431 -{
  12.432 -	int ret;
  12.433 -	DECLARE_DOMCTL(XEN_DOMCTL_resumedomain, domid);
  12.434 -
  12.435 -	ret = modify_returncode_register(handle, domid);
  12.436 -	if (ret != 0) {
  12.437 -		xc_error_dom_set(domid, "resume_fast");
  12.438 -		return ret;
  12.439 -	}
  12.440 -
  12.441 -	ret = do_domctl(handle, &domctl);
  12.442 -	if (ret != 0)
  12.443 -		xc_error_dom_set(domid, "resume_fast");
  12.444 -	return ret;
  12.445 -}
  12.446 -
  12.447 -int xc_domain_destroy(int handle, unsigned int domid)
  12.448 -{
  12.449 -	int ret;
  12.450 -	DECLARE_DOMCTL(XEN_DOMCTL_destroydomain, domid);
  12.451 -
  12.452 -	do {
  12.453 -		ret = do_domctl(handle, &domctl);
  12.454 -	} while (ret && (errno == EAGAIN));
  12.455 -	if (ret != 0)
  12.456 -		xc_error_dom_set(domid, "destroy");
  12.457 -	return ret;
  12.458 -}
  12.459 -
  12.460 -int xc_domain_shutdown(int handle, int domid, int reason)
  12.461 -{
  12.462 -	sched_remote_shutdown_t arg = {
  12.463 -		.domain_id = domid,
  12.464 -		.reason = reason,
  12.465 -	};
  12.466 -	DECLARE_HYPERCALL2(__HYPERVISOR_sched_op, SCHEDOP_remote_shutdown, &arg);
  12.467 -	int ret;
  12.468 -
  12.469 -	if (mlock(&arg, sizeof(arg)) != 0) {
  12.470 -		xc_error_set("mlock failed: %s", strerror(errno));
  12.471 -		xc_error_dom_set(domid, "shutdown %d", reason);
  12.472 -		return -1;
  12.473 -	}
  12.474 -
  12.475 -	ret = do_xen_hypercall(handle, &hypercall);
  12.476 -	if (ret < 0) {
  12.477 -		xc_error_hypercall(hypercall, ret);
  12.478 -		xc_error_dom_set(domid, "shutdown %d", reason);
  12.479 -	}
  12.480 -	munlock(&arg, sizeof(arg));
  12.481 -	return ret;
  12.482 -}
  12.483 -
  12.484 -static void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits)
  12.485 -{
  12.486 -    uint64_t l;
  12.487 -    int i, j, b;
  12.488 -
  12.489 -    for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
  12.490 -        l = lp[i];
  12.491 -        for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
  12.492 -            bp[b+j] = l;
  12.493 -            l >>= 8;
  12.494 -            nbits -= 8;
  12.495 -        }
  12.496 -    }
  12.497 -}
  12.498 -
  12.499 -static void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits)
  12.500 -{
  12.501 -    uint64_t l;
  12.502 -    int i, j, b;
  12.503 -
  12.504 -    for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
  12.505 -        l = 0;
  12.506 -        for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
  12.507 -            l |= (uint64_t)bp[b+j] << (j*8);
  12.508 -            nbits -= 8;
  12.509 -        }
  12.510 -        lp[i] = l;
  12.511 -    }
  12.512 -}
  12.513 -
  12.514 -int xc_vcpu_setaffinity(int handle, unsigned int domid, int vcpu,
  12.515 -                        uint64_t cpumap)
  12.516 -{
  12.517 -	int ret;
  12.518 -	uint8_t local[sizeof(cpumap)];
  12.519 -	DECLARE_DOMCTL(XEN_DOMCTL_setvcpuaffinity, domid);
  12.520 -	domctl.u.vcpuaffinity.vcpu = vcpu;
  12.521 -	domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8;
  12.522 -
  12.523 -	bitmap_64_to_byte(local, &cpumap, sizeof(cpumap)*8);
  12.524 -	set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local);
  12.525 -
  12.526 -	if (mlock(&cpumap, sizeof(cpumap)) != 0) {
  12.527 -		xc_error_set("mlock failed: %s", strerror(errno));
  12.528 -		xc_error_dom_set(domid, "vcpu %d set affinity", vcpu);
  12.529 -		return -1;
  12.530 -	}
  12.531 -
  12.532 -	ret = do_domctl(handle, &domctl);
  12.533 -	if (ret < 0)
  12.534 -		xc_error_dom_set(domid, "vcpu %d set affinity", vcpu);
  12.535 -	munlock(&cpumap, sizeof(cpumap));
  12.536 -	return ret;
  12.537 -}
  12.538 -
  12.539 -int xc_vcpu_getaffinity(int handle, unsigned int domid, int vcpu,
  12.540 -                        uint64_t *cpumap)
  12.541 -{
  12.542 -	int ret;
  12.543 -	uint8_t local[sizeof(*cpumap)];
  12.544 -	DECLARE_DOMCTL(XEN_DOMCTL_getvcpuaffinity, domid);
  12.545 -	domctl.u.vcpuaffinity.vcpu = vcpu;
  12.546 -	domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(*cpumap) * 8;
  12.547 -
  12.548 -	set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local);
  12.549 -
  12.550 -	if (mlock(cpumap, sizeof(*cpumap)) != 0) {
  12.551 -		xc_error_set("mlock failed: %s", strerror(errno));
  12.552 -		xc_error_dom_set(domid, "vcpu %d get affinity", vcpu);
  12.553 -		return -1;
  12.554 -	}
  12.555 -
  12.556 -	ret = do_domctl(handle, &domctl);
  12.557 -	if (ret < 0)
  12.558 -		xc_error_dom_set(domid, "vcpu %d get affinity", vcpu);
  12.559 -	munlock(cpumap, sizeof(*cpumap));
  12.560 -	bitmap_byte_to_64(cpumap, local, sizeof(*cpumap) * 8);
  12.561 -	return ret;
  12.562 -}
  12.563 -
  12.564 -int xc_vcpu_context_get(int handle, unsigned int domid, unsigned short vcpu,
  12.565 -                        struct vcpu_guest_context *ctxt)
  12.566 -{
  12.567 -	int ret;
  12.568 -	DECLARE_DOMCTL(XEN_DOMCTL_getvcpucontext, domid);
  12.569 -	domctl.u.vcpucontext.vcpu = vcpu;
  12.570 -
  12.571 -	set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt);
  12.572 -
  12.573 -	if (mlock(ctxt, sizeof(struct vcpu_guest_context)) != 0) {
  12.574 -		xc_error_set("mlock failed: %s", strerror(errno));
  12.575 -		xc_error_dom_set(domid, "vcpu %d get context", vcpu);
  12.576 -		return -1;
  12.577 -	}
  12.578 -
  12.579 -	ret = do_domctl(handle, &domctl);
  12.580 -	if (ret < 0)
  12.581 -		xc_error_dom_set(domid, "vcpu %d get context", vcpu);
  12.582 -	munlock(ctxt, sizeof(struct vcpu_guest_context));
  12.583 -
  12.584 -	return ret;
  12.585 -}
  12.586 -
  12.587 -int xc_domain_getinfolist(int handle, unsigned int first_domain,
  12.588 -                          unsigned int max_domains, xc_domaininfo_t *info)
  12.589 -{
  12.590 -	int ret;
  12.591 -	DECLARE_SYSCTL(XEN_SYSCTL_getdomaininfolist);
  12.592 -	sysctl.u.getdomaininfolist.first_domain = first_domain;
  12.593 -	sysctl.u.getdomaininfolist.max_domains = max_domains;
  12.594 -	set_xen_guest_handle(sysctl.u.getdomaininfolist.buffer, info);
  12.595 -
  12.596 -	if (mlock(info, max_domains * sizeof(xc_domaininfo_t)) != 0) {
  12.597 -		xc_error_set("getinfolist(%d, %u, %u, %x (%d)) failed: mlock failed: %s",
  12.598 -			     handle, first_domain, max_domains, info, sizeof(xc_domaininfo_t),
  12.599 -		             strerror(errno));
  12.600 -		return -1;
  12.601 -	}
  12.602 -
  12.603 -	ret = do_sysctl(handle, &sysctl);
  12.604 -	if (ret < 0)
  12.605 -		xc_error_set("getinfolist(%d, %u, %u, %x (%d)) failed: %s", 
  12.606 -			     handle, first_domain, max_domains, info, sizeof(xc_domaininfo_t),
  12.607 -			     xc_error_get());
  12.608 -	else
  12.609 -		ret = sysctl.u.getdomaininfolist.num_domains;
  12.610 -
  12.611 -	munlock(info, max_domains * sizeof(xc_domaininfo_t));
  12.612 -	return ret;
  12.613 -}
  12.614 -
  12.615 -int xc_domain_getinfo(int handle, unsigned int domid, xc_domaininfo_t *info)
  12.616 -{
  12.617 -	int ret;
  12.618 -	ret = xc_domain_getinfolist(handle, domid, 1, info);
  12.619 -	if (ret != 1) {
  12.620 -		xc_error_set("getinfo failed: domain %d: %s", domid, xc_error_get());
  12.621 -		return -1;
  12.622 -	}
  12.623 -
  12.624 -	/* If the requested domain didn't exist but there exists one with a 
  12.625 -	   higher domain ID, this will be returned. We consider this an error since
  12.626 -	   we only wanted info about a specific domain. */
  12.627 -	if (info->domain != domid) {
  12.628 -		xc_error_set("getinfo failed: domain %d nolonger exists", domid);
  12.629 -		return -1;
  12.630 -	}
  12.631 -
  12.632 -	return 0;
  12.633 -}
  12.634 -
  12.635 -int xc_domain_setmaxmem(int handle, unsigned int domid, unsigned int max_memkb)
  12.636 -{
  12.637 -	int ret;
  12.638 -	DECLARE_DOMCTL(XEN_DOMCTL_max_mem, domid);
  12.639 -	domctl.u.max_mem.max_memkb = max_memkb;
  12.640 -
  12.641 -	ret = do_domctl(handle, &domctl);
  12.642 -	if (ret < 0)
  12.643 -		xc_error_dom_set(domid, "set max memory to %u", max_memkb);
  12.644 -	return ret;
  12.645 -}
  12.646 -
  12.647 -int xc_domain_set_memmap_limit(int handle, unsigned int domid,
  12.648 -                               unsigned long map_limitkb)
  12.649 -{
  12.650 -	int ret;
  12.651 -	struct xen_foreign_memory_map fmap = {
  12.652 -		.domid = domid,
  12.653 -		.map = { .nr_entries = 1 }
  12.654 -	};
  12.655 -	struct e820entry e820 = {
  12.656 -		.addr = 0,
  12.657 -		.size = (uint64_t)map_limitkb << 10,
  12.658 -		.type = E820_RAM
  12.659 -	};
  12.660 -	DECLARE_HYPERCALL2(__HYPERVISOR_memory_op, XENMEM_set_memory_map, &fmap);
  12.661 -
  12.662 -	set_xen_guest_handle(fmap.map.buffer, &e820);
  12.663 -
  12.664 -	if (mlock(&fmap, sizeof(fmap)) != 0) {
  12.665 -		xc_error_set("set_memmap_limit failed: mlock failed: %s",
  12.666 -		             strerror(errno));
  12.667 -		return -1;
  12.668 -	}
  12.669 -
  12.670 -	if (mlock(&e820, sizeof(e820)) != 0) {
  12.671 -		xc_error_set("set_memmap_limit failed: mlock failed: %s",
  12.672 -		             strerror(errno));
  12.673 -		munlock(&fmap, sizeof(fmap));
  12.674 -		return -1;
  12.675 -	}
  12.676 -
  12.677 -	ret = do_xen_hypercall(handle, &hypercall);
  12.678 -	if (ret)
  12.679 -		xc_error_hypercall(hypercall, ret);
  12.680 -
  12.681 -	munlock(&e820, sizeof(e820));
  12.682 -	munlock(&fmap, sizeof(fmap));
  12.683 -	return ret;
  12.684 -}
  12.685 -
  12.686 -int xc_domain_set_time_offset(int handle, unsigned int domid, int time_offset)
  12.687 -{
  12.688 -	int ret;
  12.689 -	DECLARE_DOMCTL(XEN_DOMCTL_settimeoffset, domid);
  12.690 -	domctl.u.settimeoffset.time_offset_seconds = time_offset;
  12.691 -
  12.692 -	ret = do_domctl(handle, &domctl);
  12.693 -	if (ret < 0)
  12.694 -		xc_error_dom_set(domid, "set time offset %d", time_offset);
  12.695 -	return ret;
  12.696 -}
  12.697 -
  12.698 -int xc_domain_memory_increase_reservation(int handle, unsigned int domid,
  12.699 -                                          unsigned long nr_extents,
  12.700 -                                          unsigned int extent_order,
  12.701 -                                          unsigned int address_bits,
  12.702 -                                          xen_pfn_t *extent_start)
  12.703 -{
  12.704 -	int ret;
  12.705 -	struct xen_memory_reservation reservation = {
  12.706 -		.nr_extents   = nr_extents,
  12.707 -		.extent_order = extent_order,
  12.708 -		.COMPAT_FIELD_ADDRESS_BITS = address_bits,
  12.709 -		.domid        = domid
  12.710 -	};
  12.711 -
  12.712 -	set_xen_guest_handle(reservation.extent_start, extent_start);
  12.713 -
  12.714 -	ret = do_memctl_reservation(handle, XENMEM_increase_reservation,
  12.715 -	                            &reservation);
  12.716 -	if (ret != nr_extents) {
  12.717 -		xc_error_dom_set(domid, "increase reservation to %lu",
  12.718 -		                 nr_extents);
  12.719 -		return (ret >= 0) ? -1 : ret;
  12.720 -	}
  12.721 -	return 0;
  12.722 -}
  12.723 -
  12.724 -int xc_domain_memory_decrease_reservation(int handle, unsigned int domid,
  12.725 -                                          unsigned long nr_extents,
  12.726 -                                          unsigned int extent_order,
  12.727 -                                          unsigned int address_bits,
  12.728 -                                          xen_pfn_t *extent_start)
  12.729 -{
  12.730 -	int ret;
  12.731 -	struct xen_memory_reservation reservation = {
  12.732 -		.nr_extents   = nr_extents,
  12.733 -		.extent_order = extent_order,
  12.734 -		.COMPAT_FIELD_ADDRESS_BITS = 0,
  12.735 -		.domid        = domid
  12.736 -	};
  12.737 -
  12.738 -	set_xen_guest_handle(reservation.extent_start, extent_start);
  12.739 -	if (!extent_start) {
  12.740 -		xc_error_set("decrease reservation: extent start is NULL");
  12.741 -		return -EINVAL;
  12.742 -	}
  12.743 -
  12.744 -	ret = do_memctl_reservation(handle, XENMEM_decrease_reservation,
  12.745 -	                            &reservation);
  12.746 -	if (ret < nr_extents) {
  12.747 -		xc_error_dom_set(domid, "decrease reservation to %lu",
  12.748 -		                 nr_extents);
  12.749 -		return (ret >= 0) ? -1 : ret;
  12.750 -	}
  12.751 -	return 0;
  12.752 -}
  12.753 -
  12.754 -int xc_domain_memory_populate_physmap(int handle, unsigned int domid,
  12.755 -                                      unsigned long nr_extents,
  12.756 -                                      unsigned int extent_order,
  12.757 -                                      unsigned int address_bits,
  12.758 -                                      xen_pfn_t *extent_start)
  12.759 -{
  12.760 -	int ret;
  12.761 -	struct xen_memory_reservation reservation = {
  12.762 -		.nr_extents   = nr_extents,
  12.763 -		.extent_order = extent_order,
  12.764 -		.COMPAT_FIELD_ADDRESS_BITS = address_bits,
  12.765 -		.domid        = domid
  12.766 -	};
  12.767 -
  12.768 -	set_xen_guest_handle(reservation.extent_start, extent_start);
  12.769 -	ret = do_memctl_reservation(handle, XENMEM_populate_physmap,
  12.770 -	                            &reservation);
  12.771 -	if (ret < nr_extents) {
  12.772 -		xc_error_dom_set(domid, "populate physmap");
  12.773 -		return (ret >= 0) ? -1 : ret;
  12.774 -	}
  12.775 -	return 0;
  12.776 -}
  12.777 -
  12.778 -int xc_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist)
  12.779 -{
  12.780 -	int ret = 0;
  12.781 -#ifdef XEN_DOMCTL_setvmxassist
  12.782 -	DECLARE_DOMCTL(XEN_DOMCTL_setvmxassist, domid);
  12.783 -	domctl.u.setvmxassist.use_vmxassist = use_vmxassist;
  12.784 -
  12.785 -	ret = do_domctl(handle, &domctl);
  12.786 -	if (ret)
  12.787 -		xc_error_dom_set(domid, "setting vmxassist to %d",
  12.788 -				 use_vmxassist);
  12.789 -#endif
  12.790 -	return ret;
  12.791 -}
  12.792 -
  12.793 -int xc_domain_max_vcpus(int handle, unsigned int domid, unsigned int max)
  12.794 -{
  12.795 -	int ret;
  12.796 -	DECLARE_DOMCTL(XEN_DOMCTL_max_vcpus, domid);
  12.797 -	domctl.u.max_vcpus.max = max;
  12.798 -
  12.799 -	ret = do_domctl(handle, &domctl);
  12.800 -	if (ret)
  12.801 -		xc_error_dom_set(domid, "setting max vcpus to %d", max);
  12.802 -	return ret;
  12.803 -}
  12.804 -
  12.805 -int xc_domain_sethandle(int handle, unsigned int domid,
  12.806 -                        xen_domain_handle_t dhandle)
  12.807 -{
  12.808 -	int ret;
  12.809 -	DECLARE_DOMCTL(XEN_DOMCTL_setdomainhandle, domid);
  12.810 -	memcpy(domctl.u.setdomainhandle.handle, dhandle, sizeof(xen_domain_handle_t));
  12.811 -
  12.812 -	ret = do_domctl(handle, &domctl);
  12.813 -	if (ret)
  12.814 -		xc_error_dom_set(domid, "set handle");
  12.815 -	return ret;
  12.816 -}
  12.817 -
  12.818 -int xc_vcpu_getinfo(int handle, unsigned int domid, unsigned int vcpu,
  12.819 -                    xc_vcpuinfo_t *info)
  12.820 -{
  12.821 -	int ret;
  12.822 -	DECLARE_DOMCTL(XEN_DOMCTL_getvcpuinfo, domid);
  12.823 -	domctl.u.getvcpuinfo.vcpu = vcpu;
  12.824 -
  12.825 -	ret = do_domctl(handle, &domctl);
  12.826 -	if (ret < 0) {
  12.827 -		xc_error_dom_set(domid, "vcpu %u getinfo", vcpu);
  12.828 -		return ret;
  12.829 -	}
  12.830 -	memcpy(info, &domctl.u.getvcpuinfo, sizeof(*info));
  12.831 -	return ret;
  12.832 -}
  12.833 -
  12.834 -int xc_domain_ioport_permission(int handle, unsigned int domid,
  12.835 -                                unsigned int first_port, unsigned int nr_ports,
  12.836 -                                unsigned int allow_access)
  12.837 -{
  12.838 -	DECLARE_DOMCTL(XEN_DOMCTL_ioport_permission, domid);
  12.839 -	domctl.u.ioport_permission.first_port = first_port;
  12.840 -	domctl.u.ioport_permission.nr_ports = nr_ports;
  12.841 -	domctl.u.ioport_permission.allow_access = allow_access;
  12.842 -
  12.843 -	return do_domctl(handle, &domctl);
  12.844 -}
  12.845 -
  12.846 -int xc_vcpu_getcontext(int handle, unsigned int domid,
  12.847 -                       unsigned int vcpu, vcpu_guest_context_any_t *ctxt)
  12.848 -{
  12.849 -	int ret;
  12.850 -	DECLARE_DOMCTL(XEN_DOMCTL_getvcpucontext, domid);
  12.851 -	domctl.u.vcpucontext.vcpu = vcpu;
  12.852 -	set_xen_guest_handle(domctl.u.vcpucontext.ctxt, &ctxt->c);
  12.853 -
  12.854 -	if (mlock(ctxt, sizeof(*ctxt)) != 0) {
  12.855 -		xc_error_set("mlock failed: %s", strerror(errno));
  12.856 -		return -1;
  12.857 -	}
  12.858 -
  12.859 -	ret = do_domctl(handle, &domctl);
  12.860 -	if (ret)
  12.861 -		xc_error_dom_set(domid, "vcpu %u getcontext", vcpu);
  12.862 -	munlock(ctxt, sizeof(*ctxt));
  12.863 -	return ret;
  12.864 -}
  12.865 -
  12.866 -int xc_vcpu_setcontext(int handle, unsigned int domid,
  12.867 -                       unsigned int vcpu, vcpu_guest_context_any_t *ctxt)
  12.868 -{
  12.869 -	int ret;
  12.870 -	DECLARE_DOMCTL(XEN_DOMCTL_setvcpucontext, domid);
  12.871 -	domctl.u.vcpucontext.vcpu = vcpu;
  12.872 -	set_xen_guest_handle(domctl.u.vcpucontext.ctxt, &ctxt->c);
  12.873 -
  12.874 -	if (mlock(ctxt, sizeof(*ctxt)) != 0) {
  12.875 -		xc_error_set("mlock failed: %s", strerror(errno));
  12.876 -		return -1;
  12.877 -	}
  12.878 -
  12.879 -	ret = do_domctl(handle, &domctl);
  12.880 -	if (ret)
  12.881 -		xc_error_dom_set(domid, "vcpu %u setcontext", vcpu);
  12.882 -
  12.883 -	munlock(ctxt, sizeof(*ctxt));
  12.884 -	return ret;
  12.885 -}
  12.886 -
  12.887 -int xc_domain_irq_permission(int handle, unsigned int domid,
  12.888 -                             unsigned char pirq, unsigned char allow_access)
  12.889 -{
  12.890 -	int ret;
  12.891 -	DECLARE_DOMCTL(XEN_DOMCTL_irq_permission, domid);
  12.892 -	domctl.u.irq_permission.pirq = pirq;
  12.893 -	domctl.u.irq_permission.allow_access = allow_access;
  12.894 -
  12.895 -	ret = do_domctl(handle, &domctl);
  12.896 -	if (ret)
  12.897 -		xc_error_dom_set(domid, "irq permission %u to %u",
  12.898 -		                 pirq, allow_access);
  12.899 -	return ret;
  12.900 -}
  12.901 -
  12.902 -int xc_domain_iomem_permission(int handle, unsigned int domid,
  12.903 -                               unsigned long first_mfn, unsigned long nr_mfns,
  12.904 -                               unsigned char allow_access)
  12.905 -{
  12.906 -	int ret;
  12.907 -	DECLARE_DOMCTL(XEN_DOMCTL_iomem_permission, domid);
  12.908 -	domctl.u.iomem_permission.first_mfn = first_mfn;
  12.909 -	domctl.u.iomem_permission.nr_mfns = nr_mfns;
  12.910 -	domctl.u.iomem_permission.allow_access = allow_access;
  12.911 -
  12.912 -	ret = do_domctl(handle, &domctl);
  12.913 -	if (ret)
  12.914 -		xc_error_dom_set(domid, "iomem permission [%lu, %lu] to %u",
  12.915 -		                 first_mfn, first_mfn + nr_mfns, allow_access);
  12.916 -	return ret;
  12.917 -}
  12.918 -
  12.919 -long long xc_domain_get_cpu_usage(int handle, unsigned int domid,
  12.920 -                                  unsigned int vcpu)
  12.921 -{
  12.922 -	DECLARE_DOMCTL(XEN_DOMCTL_getvcpuinfo, domid);
  12.923 -	domctl.u.getvcpuinfo.vcpu = vcpu;
  12.924 -
  12.925 -	if (do_domctl(handle, &domctl) < 0) {
  12.926 -		xc_error_dom_set(domid, "get cpu %d usage", vcpu);
  12.927 -		return -1;
  12.928 -	}
  12.929 -	return domctl.u.getvcpuinfo.cpu_time;
  12.930 -}
  12.931 -
  12.932 -void *xc_map_foreign_range(int handle, unsigned int domid,
  12.933 -                           int size, int prot, unsigned long mfn)
  12.934 -{
  12.935 -	privcmd_mmap_entry_t entry = {
  12.936 -		.mfn = mfn,
  12.937 -		.npages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT,
  12.938 -	};
  12.939 -	privcmd_mmap_t ioctlx = {
  12.940 -		.num = 1,
  12.941 -		.dom = domid,
  12.942 -		.entry = &entry,
  12.943 -	};
  12.944 -	void *addr;
  12.945 -
  12.946 -	addr = do_mmap(NULL, size, prot, MAP_SHARED, handle, 0);
  12.947 -	if (addr == MAP_FAILED) {
  12.948 -		xc_error_set("mmap failed: %s", strerror(errno));
  12.949 -		xc_error_dom_set(domid, "map foreign range [%lx,%lx] prot %u",
  12.950 -		                 mfn, mfn + size, prot);
  12.951 -		return NULL;
  12.952 -	}
  12.953 -	entry.va = (unsigned long) addr;
  12.954 -	if (do_ioctl(handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0) {
  12.955 -		xc_error_set("ioctl failed: %s", strerror(errno));
  12.956 -		xc_error_dom_set(domid, "map foreign range [%lx,%lx] prot %u",
  12.957 -		                 mfn, mfn + size, prot);
  12.958 -		munmap(addr, size);
  12.959 -		return NULL;
  12.960 -	}
  12.961 -	return addr;
  12.962 -}
  12.963 -
  12.964 -int xc_map_foreign_ranges(int handle, unsigned int domid,
  12.965 -                          privcmd_mmap_entry_t *entries, int nr)
  12.966 -{
  12.967 -	privcmd_mmap_t ioctlx = {
  12.968 -		.num = nr,
  12.969 -		.dom = domid,
  12.970 -		.entry = entries,
  12.971 -	};
  12.972 -	int ret;
  12.973 -
  12.974 -	ret = do_ioctl(handle, IOCTL_PRIVCMD_MMAP, &ioctlx);
  12.975 -	if (ret < 0) {
  12.976 -		xc_error_set("ioctl failed: %s", strerror(errno));
  12.977 -		xc_error_dom_set(domid, "map foreign ranges");
  12.978 -		return -1;
  12.979 -	}
  12.980 -	return ret;
  12.981 -}
  12.982 -
  12.983 -int xc_readconsolering(int handle, char **pbuffer,
  12.984 -                       unsigned int *pnr_chars, int clear)
  12.985 -{
  12.986 -	int ret;
  12.987 -	DECLARE_SYSCTL(XEN_SYSCTL_readconsole);
  12.988 -	char *buffer = *pbuffer;
  12.989 -	unsigned int nr_chars = *pnr_chars;
  12.990 -
  12.991 -	set_xen_guest_handle(sysctl.u.readconsole.buffer, buffer);
  12.992 -	sysctl.u.readconsole.count = nr_chars;
  12.993 -	sysctl.u.readconsole.clear = clear;
  12.994 -
  12.995 -	if (mlock(buffer, nr_chars) != 0) {
  12.996 -		xc_error_set("read console ring: mlock failed: %s",
  12.997 -		             strerror(errno));
  12.998 -		return -1;
  12.999 -	}
 12.1000 -
 12.1001 -	ret = do_sysctl(handle, &sysctl);
 12.1002 -	if (ret != 0)
 12.1003 -		xc_error_set("read console ring failed: %s", xc_error_get());
 12.1004 -	else
 12.1005 -		*pnr_chars = sysctl.u.readconsole.count;
 12.1006 -
 12.1007 -	munlock(buffer, nr_chars);
 12.1008 -	return ret;
 12.1009 -}
 12.1010 -
 12.1011 -int xc_send_debug_keys(int handle, char *keys)
 12.1012 -{
 12.1013 -	int ret;
 12.1014 -	DECLARE_SYSCTL(XEN_SYSCTL_debug_keys);
 12.1015 -
 12.1016 -	set_xen_guest_handle(sysctl.u.debug_keys.keys, keys);
 12.1017 -	sysctl.u.debug_keys.nr_keys = strlen(keys);
 12.1018 -
 12.1019 -	if (mlock(keys, sysctl.u.debug_keys.nr_keys) != 0) {
 12.1020 -		xc_error_set("send debug keys: mlock failed: %s",
 12.1021 -		             strerror(errno));
 12.1022 -		return -1;
 12.1023 -	}
 12.1024 -
 12.1025 -	ret = do_sysctl(handle, &sysctl);
 12.1026 -	if (ret != 0)
 12.1027 -		xc_error_set("send debug keys: %s", xc_error_get());
 12.1028 -
 12.1029 -	munlock(keys, sysctl.u.debug_keys.nr_keys);
 12.1030 -	return ret;
 12.1031 -}
 12.1032 -
 12.1033 -int xc_physinfo(int handle, xc_physinfo_t *put_info)
 12.1034 -{
 12.1035 -	DECLARE_SYSCTL(XEN_SYSCTL_physinfo);
 12.1036 -	int ret;
 12.1037 -
 12.1038 -	ret = do_sysctl(handle, &sysctl);
 12.1039 -	if (ret) {
 12.1040 -		xc_error_set("physinfo failed: %s", xc_error_get());
 12.1041 -		return ret;
 12.1042 -	}
 12.1043 -	memcpy(put_info, &sysctl.u.physinfo, sizeof(*put_info));
 12.1044 -	return 0;
 12.1045 -}
 12.1046 -
 12.1047 -int xc_pcpu_info(
 12.1048 -	int handle, int max_cpus, xen_sysctl_cpuinfo_t *info, int *nr_cpus)
 12.1049 -{
 12.1050 -	DECLARE_SYSCTL(XEN_SYSCTL_getcpuinfo);
 12.1051 -	int ret;
 12.1052 -
 12.1053 -	sysctl.u.getcpuinfo.max_cpus = max_cpus;
 12.1054 -	set_xen_guest_handle(sysctl.u.getcpuinfo.info, info);
 12.1055 -
 12.1056 -	if (mlock(info, sizeof(*info) * max_cpus) != 0) {
 12.1057 -		xc_error_set("mlock failed: %s", strerror(errno));
 12.1058 -		return -1;
 12.1059 -	}
 12.1060 -
 12.1061 -	ret = do_sysctl(handle, &sysctl);
 12.1062 -	if (ret)
 12.1063 -		xc_error_set("pcpu info failed: %s", xc_error_get());
 12.1064 -	else if (ret == 0 && nr_cpus)
 12.1065 -		*nr_cpus = sysctl.u.getcpuinfo.nr_cpus;
 12.1066 -	munlock(info, sizeof(*info) * max_cpus);
 12.1067 -	return ret;
 12.1068 -}
 12.1069 -
 12.1070 -int xc_sched_id(int handle, int *sched_id)
 12.1071 -{
 12.1072 -	DECLARE_SYSCTL(XEN_SYSCTL_sched_id);
 12.1073 -	int ret;
 12.1074 -
 12.1075 -	ret = do_sysctl(handle, &sysctl);
 12.1076 -	if (ret) {
 12.1077 -		xc_error_set("sched id failed: %s", xc_error_get());
 12.1078 -		return ret;
 12.1079 -	}
 12.1080 -	*sched_id = sysctl.u.sched_id.sched_id;
 12.1081 -	return 0;
 12.1082 -}
 12.1083 -
 12.1084 -int xc_version(int handle, int cmd, void *arg)
 12.1085 -{
 12.1086 -	int argsize;
 12.1087 -	int ret;
 12.1088 -	DECLARE_HYPERCALL2(__HYPERVISOR_xen_version, cmd, arg);
 12.1089 -
 12.1090 -	switch (cmd) {
 12.1091 -	case XENVER_extraversion:
 12.1092 -		argsize = sizeof(xen_extraversion_t); break;
 12.1093 -	case XENVER_compile_info:
 12.1094 -		argsize = sizeof(xen_compile_info_t); break;
 12.1095 -	case XENVER_capabilities:
 12.1096 -		argsize = sizeof(xen_capabilities_info_t); break;
 12.1097 -	case XENVER_changeset:
 12.1098 -		argsize = sizeof(xen_changeset_info_t); break;
 12.1099 -	case XENVER_platform_parameters:
 12.1100 -		argsize = sizeof(xen_platform_parameters_t); break;
 12.1101 -	case XENVER_version:
 12.1102 -		argsize = 0; break;
 12.1103 -	default:
 12.1104 -		xc_error_set("version: unknown command");
 12.1105 -		return -1;
 12.1106 -	}
 12.1107 -	if (argsize && mlock(arg, argsize) == -1) {
 12.1108 -		xc_error_set("version: mlock failed: %s", strerror(errno));
 12.1109 -		return -ENOMEM;
 12.1110 -	}
 12.1111 -
 12.1112 -	ret = do_xen_hypercall(handle, &hypercall);
 12.1113 -	if (ret)
 12.1114 -		xc_error_hypercall(hypercall, ret);
 12.1115 -
 12.1116 -	if (argsize)
 12.1117 -		munlock(arg, argsize);
 12.1118 -	return ret;
 12.1119 -}
 12.1120 -
 12.1121 -int xc_evtchn_alloc_unbound(int handle, unsigned int domid,
 12.1122 -                            unsigned int remote_domid)
 12.1123 -{
 12.1124 -	struct evtchn_alloc_unbound arg = {
 12.1125 -		.dom = domid,
 12.1126 -		.remote_dom = remote_domid,
 12.1127 -	};
 12.1128 -	int ret;
 12.1129 -
 12.1130 -	ret = do_evtchnctl(handle, EVTCHNOP_alloc_unbound, &arg, sizeof(arg));
 12.1131 -	if (ret) {
 12.1132 -		xc_error_dom_set(domid, "alloc unbound evtchn to %d",
 12.1133 -		                 remote_domid);
 12.1134 -		return ret;
 12.1135 -	}
 12.1136 -	return arg.port;
 12.1137 -}
 12.1138 -
 12.1139 -int xc_evtchn_reset(int handle, unsigned int domid)
 12.1140 -{
 12.1141 -	struct evtchn_reset arg = {
 12.1142 -		.dom = domid,
 12.1143 -	};
 12.1144 -	int ret;
 12.1145 -
 12.1146 -	ret = do_evtchnctl(handle, EVTCHNOP_reset, &arg, sizeof(arg));
 12.1147 -	if (ret)
 12.1148 -		xc_error_dom_set(domid, "reset evtchn of %d", domid);
 12.1149 -	return ret;
 12.1150 -}
 12.1151 -
 12.1152 -int xc_sched_credit_domain_set(int handle, unsigned int domid,
 12.1153 -                               struct xen_domctl_sched_credit *sdom)
 12.1154 -{
 12.1155 -	int ret;
 12.1156 -	DECLARE_DOMCTL(XEN_DOMCTL_scheduler_op, domid);
 12.1157 -	domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_CREDIT;
 12.1158 -	domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_putinfo;
 12.1159 -	domctl.u.scheduler_op.u.credit = *sdom;
 12.1160 -
 12.1161 -	ret = do_domctl(handle, &domctl);
 12.1162 -	if (ret < 0)
 12.1163 -		xc_error_dom_set(domid, "credit scheduler domain set");
 12.1164 -	return ret;
 12.1165 -}
 12.1166 -
 12.1167 -int xc_sched_credit_domain_get(int handle, unsigned int domid,
 12.1168 -                               struct xen_domctl_sched_credit *sdom)
 12.1169 -{
 12.1170 -	int ret;
 12.1171 -	DECLARE_DOMCTL(XEN_DOMCTL_scheduler_op, domid);
 12.1172 -
 12.1173 -	domctl.u.scheduler_op.sched_id = XEN_SCHEDULER_CREDIT;
 12.1174 -	domctl.u.scheduler_op.cmd = XEN_DOMCTL_SCHEDOP_getinfo;
 12.1175 -
 12.1176 -	ret = do_domctl(handle, &domctl);
 12.1177 -	if (ret < 0)
 12.1178 -		xc_error_dom_set(domid, "credit scheduler domain get");
 12.1179 -	else
 12.1180 -		*sdom = domctl.u.scheduler_op.u.credit;
 12.1181 -	return ret;
 12.1182 -}
 12.1183 -
 12.1184 -int xc_shadow_allocation_get(int handle, unsigned int domid, uint32_t *mb)
 12.1185 -{
 12.1186 -	int ret;
 12.1187 -	DECLARE_DOMCTL(XEN_DOMCTL_shadow_op, domid);
 12.1188 -
 12.1189 -	domctl.u.shadow_op.op = XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION;
 12.1190 -
 12.1191 -	ret = do_domctl(handle, &domctl);
 12.1192 -	if (ret < 0)
 12.1193 -		xc_error_dom_set(domid, "shadow allocation get");
 12.1194 -	else
 12.1195 -		*mb = domctl.u.shadow_op.mb;
 12.1196 -	return ret;
 12.1197 -}
 12.1198 -
 12.1199 -int xc_shadow_allocation_set(int handle, unsigned int domid, uint32_t mb)
 12.1200 -{
 12.1201 -	int ret;
 12.1202 -	DECLARE_DOMCTL(XEN_DOMCTL_shadow_op, domid);
 12.1203 -
 12.1204 -	domctl.u.shadow_op.op = XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION;
 12.1205 -	domctl.u.shadow_op.mb = mb;
 12.1206 -
 12.1207 -	ret = do_domctl(handle, &domctl);
 12.1208 -	if (ret < 0)
 12.1209 -		xc_error_dom_set(domid, "shadow allocation set");
 12.1210 -	return ret;
 12.1211 -}
 12.1212 -
 12.1213 -int xc_domain_get_pfn_list(int handle, unsigned int domid,
 12.1214 -                           uint64_t *pfn_array, unsigned long max_pfns)
 12.1215 -{
 12.1216 -	int ret;
 12.1217 -	DECLARE_DOMCTL(XEN_DOMCTL_getmemlist, domid);
 12.1218 -
 12.1219 -	domctl.u.getmemlist.max_pfns = max_pfns;
 12.1220 -	set_xen_guest_handle(domctl.u.getmemlist.buffer, pfn_array);
 12.1221 -
 12.1222 -	if (mlock(pfn_array, max_pfns * sizeof(xen_pfn_t)) != 0) {
 12.1223 -		xc_error_set("mlock failed: %s", strerror(errno));
 12.1224 -		return -1;
 12.1225 -	}
 12.1226 -
 12.1227 -	ret = do_domctl(handle, &domctl);
 12.1228 -	if (ret < 0)
 12.1229 -		xc_error_dom_set(domid, "get pfn list");
 12.1230 -
 12.1231 -	munlock(pfn_array, max_pfns * sizeof(xen_pfn_t));
 12.1232 -	return (ret < 0) ? ret : domctl.u.getmemlist.num_pfns;
 12.1233 -}
 12.1234 -
 12.1235 -#define MARSHALL_BDF(d,b,s,f) \
 12.1236 -	(((b) & 0xff) << 16 | ((s) & 0x1f) << 11 | ((f) & 0x7) << 8)
 12.1237 -
 12.1238 -int xc_domain_assign_device(int handle, unsigned int domid,
 12.1239 -                            int domain, int bus, int slot, int func)
 12.1240 -{
 12.1241 -	int ret = -EBADF;
 12.1242 -#ifdef XEN_DOMCTL_assign_device
 12.1243 -	DECLARE_DOMCTL(XEN_DOMCTL_assign_device, domid);
 12.1244 -
 12.1245 -	domctl.u.assign_device.machine_bdf = MARSHALL_BDF(domain, bus, slot, func);
 12.1246 -	ret = do_domctl(handle, &domctl);
 12.1247 -	if (ret < 0)
 12.1248 -		xc_error_dom_set(domid, "assign device");
 12.1249 -#endif
 12.1250 -	return ret;
 12.1251 -}
 12.1252 -
 12.1253 -int xc_domain_deassign_device(int handle, unsigned int domid,
 12.1254 -                              int domain, int bus, int slot, int func)
 12.1255 -{
 12.1256 -	int ret = -EBADF;
 12.1257 -#ifdef XEN_DOMCTL_deassign_device
 12.1258 -	DECLARE_DOMCTL(XEN_DOMCTL_deassign_device, domid);
 12.1259 -
 12.1260 -	domctl.u.assign_device.machine_bdf = MARSHALL_BDF(domain, bus, slot, func);
 12.1261 -	ret = do_domctl(handle, &domctl);
 12.1262 -	if (ret < 0)
 12.1263 -		xc_error_dom_set(domid, "deassign device");
 12.1264 -#endif
 12.1265 -	return ret;
 12.1266 -}
 12.1267 -
 12.1268 -int xc_domain_test_assign_device(int handle, unsigned int domid,
 12.1269 -                                 int domain, int bus, int slot, int func)
 12.1270 -{
 12.1271 -	int ret = -EBADF;
 12.1272 -#ifdef XEN_DOMCTL_test_assign_device
 12.1273 -	DECLARE_DOMCTL(XEN_DOMCTL_test_assign_device, domid);
 12.1274 -	domctl.u.assign_device.machine_bdf = MARSHALL_BDF(domain, bus, slot, func);
 12.1275 -
 12.1276 -	ret = do_domctl(handle, &domctl);
 12.1277 -	if (ret < 0)
 12.1278 -		xc_error_dom_set(domid, "test assign device");
 12.1279 -#endif
 12.1280 -	return ret;
 12.1281 -}
 12.1282 -
 12.1283 -int xc_domain_watchdog(int handle, int id, uint32_t timeout)
 12.1284 -{
 12.1285 -	int ret = -EBADF;
 12.1286 -#ifdef SCHEDOP_watchdog
 12.1287 -	sched_watchdog_t arg = {
 12.1288 -		.id = (uint32_t) id,
 12.1289 -		.timeout = timeout,
 12.1290 -	};
 12.1291 -	DECLARE_HYPERCALL2(__HYPERVISOR_sched_op, SCHEDOP_watchdog, &arg);
 12.1292 -
 12.1293 -	if (mlock(&arg, sizeof(arg)) != 0) {
 12.1294 -		xc_error_set("mlock failed: %s", strerror(errno));
 12.1295 -		return -1;
 12.1296 -	}
 12.1297 -
 12.1298 -	ret = do_xen_hypercall(handle, &hypercall);
 12.1299 -	if (ret < 0) {
 12.1300 -		xc_error_hypercall(hypercall, ret);
 12.1301 -	}
 12.1302 -	munlock(&arg, sizeof(arg));
 12.1303 -#endif
 12.1304 -	return ret;
 12.1305 -}
 12.1306 -
 12.1307 -int xc_domain_set_machine_address_size(int xc, uint32_t domid, unsigned int width)
 12.1308 -{
 12.1309 -	DECLARE_DOMCTL(XEN_DOMCTL_set_machine_address_size, domid);
 12.1310 -	int rc;
 12.1311 -
 12.1312 -	domctl.u.address_size.size = width;
 12.1313 -	rc = do_domctl(xc, &domctl);
 12.1314 -	if (rc != 0)
 12.1315 -		xc_error_dom_set(domid, "set machine address size");
 12.1316 -
 12.1317 -	return rc;
 12.1318 -}
 12.1319 -
 12.1320 -int xc_domain_get_machine_address_size(int xc, uint32_t domid)
 12.1321 -{
 12.1322 -	DECLARE_DOMCTL(XEN_DOMCTL_get_machine_address_size, domid);
 12.1323 -	int rc;
 12.1324 -
 12.1325 -	rc = do_domctl(xc, &domctl);
 12.1326 -	if (rc != 0)
 12.1327 -		xc_error_dom_set(domid, "get machine address size");
 12.1328 -	return rc == 0 ? domctl.u.address_size.size : rc;
 12.1329 -}
 12.1330 -
 12.1331 -#include "xc_cpuid.h"
 12.1332 -int xc_domain_cpuid_set(int xc, unsigned int domid, int hvm,
 12.1333 -                        uint32_t input, uint32_t oinput,
 12.1334 -                        char *config[4], char *config_out[4])
 12.1335 -{
 12.1336 -	int ret = -EBADF;
 12.1337 -#ifdef XEN_DOMCTL_set_cpuid
 12.1338 -	DECLARE_DOMCTL(XEN_DOMCTL_set_cpuid, domid);
 12.1339 -	uint32_t regs[4], polregs[4];
 12.1340 -	int i, j;
 12.1341 -
 12.1342 -	xc_cpuid(input, oinput, regs);
 12.1343 -	memcpy(polregs, regs, sizeof(regs));
 12.1344 -	do_cpuid_policy(xc, domid, hvm, input, polregs);
 12.1345 -
 12.1346 -	for (i = 0; i < 4; i++) {
 12.1347 -		if (!config[i]) {
 12.1348 -			regs[i] = polregs[i];
 12.1349 -			continue;
 12.1350 -		}
 12.1351 -		
 12.1352 -		for (j = 0; j < 32; j++) {
 12.1353 -			unsigned char val, polval;
 12.1354 -
 12.1355 -			val = !!((regs[i] & (1U << (31 - j))));
 12.1356 -			polval = !!((regs[i] & (1U << (31 - j))));
 12.1357 -
 12.1358 -			switch (config[i][j]) {
 12.1359 -			case '1': val = 1; break; /* force to true */
 12.1360 -			case '0': val = 0; break; /* force to false */
 12.1361 -			case 'x': val = polval; break;
 12.1362 -			case 'k': case 's': break;
 12.1363 -			default:
 12.1364 -				xc_error_dom_set(domid, "domain cpuid set: invalid config");
 12.1365 -				ret = -EINVAL;
 12.1366 -				goto out;
 12.1367 -			}
 12.1368 -
 12.1369 -			if (val)
 12.1370 -				set_bit(31 - j, regs[i]);
 12.1371 -			else
 12.1372 -				clear_bit(31 - j, regs[i]);
 12.1373 -
 12.1374 -			if (config_out && config_out[i]) {
 12.1375 -				config_out[i][j] = (config[i][j] == 's')
 12.1376 -				                   ? '0' + val
 12.1377 -						   : config[i][j];
 12.1378 -			}
 12.1379 -		}
 12.1380 -	}
 12.1381 -
 12.1382 -	domctl.u.cpuid.input[0] = input;
 12.1383 -	domctl.u.cpuid.input[1] = oinput;
 12.1384 -	domctl.u.cpuid.eax = regs[0];
 12.1385 -	domctl.u.cpuid.ebx = regs[1];
 12.1386 -	domctl.u.cpuid.ecx = regs[2];
 12.1387 -	domctl.u.cpuid.edx = regs[3];
 12.1388 -	ret = do_domctl(xc, &domctl);
 12.1389 -	if (ret) {
 12.1390 -		xc_error_dom_set(domid, "cpuid set");
 12.1391 -		goto out;
 12.1392 -	}
 12.1393 -out:
 12.1394 -#endif
 12.1395 -	return ret;
 12.1396 -}
 12.1397 -
 12.1398 -int xc_domain_cpuid_apply(int xc, unsigned int domid, int hvm)
 12.1399 -{
 12.1400 -	int ret = -EBADF;
 12.1401 -#ifdef XEN_DOMCTL_set_cpuid
 12.1402 -	uint32_t regs[4], base_max, ext_max, eax, ecx;
 12.1403 -
 12.1404 -	/* determinate cpuid range */
 12.1405 -	xc_cpuid(0, 0, regs);
 12.1406 -	base_max = MIN(regs[0], DEF_MAX_BASE);
 12.1407 -	xc_cpuid(0x80000000, 0, regs);
 12.1408 -	ext_max = MIN(regs[0], DEF_MAX_EXT);
 12.1409 -
 12.1410 -	eax = ecx = 0;
 12.1411 -	while (!(eax & 0x80000000) || (eax <= ext_max)) {
 12.1412 -		xc_cpuid(eax, ecx, regs);
 12.1413 -
 12.1414 -		do_cpuid_policy(xc, domid, hvm, eax, regs);
 12.1415 -		
 12.1416 -		if (regs[0] || regs[1] || regs[2] || regs[3]) {
 12.1417 -			DECLARE_DOMCTL(XEN_DOMCTL_set_cpuid, domid);
 12.1418 -			
 12.1419 -			domctl.u.cpuid.input[0] = eax;
 12.1420 -			domctl.u.cpuid.input[1] = (eax == 4) ? ecx : XEN_CPUID_INPUT_UNUSED;
 12.1421 -			domctl.u.cpuid.eax = regs[0];
 12.1422 -			domctl.u.cpuid.ebx = regs[1];
 12.1423 -			domctl.u.cpuid.ecx = regs[2];
 12.1424 -			domctl.u.cpuid.edx = regs[3];
 12.1425 -
 12.1426 -			ret = do_domctl(xc, &domctl);
 12.1427 -			if (ret) {
 12.1428 -				xc_error_dom_set(domid, "cpuid apply");
 12.1429 -				goto out;
 12.1430 -			}
 12.1431 -
 12.1432 -			/* we repeat when doing node 4 (cache descriptor leaves) increasing ecx 
 12.1433 -			 * until the cpuid eax value masked is 0 */
 12.1434 -			if (eax == 4) {
 12.1435 -				ecx++;
 12.1436 -				if ((regs[0] & 0x1f) != 0)
 12.1437 -					continue;
 12.1438 -				ecx = 0;
 12.1439 -			}
 12.1440 -		}
 12.1441 -
 12.1442 -		eax++;
 12.1443 -		if (!(eax & 0x80000000) && (eax > base_max))
 12.1444 -			eax = 0x80000000;
 12.1445 -	}
 12.1446 -	ret = 0;
 12.1447 -out:
 12.1448 -#endif
 12.1449 -	return ret;
 12.1450 -}
 12.1451 -
 12.1452 -/*
 12.1453 - * return 1 on checking success 
 12.1454 - *        0 on checking failure
 12.1455 - *        -EINVAL if the config contains unknown character
 12.1456 - */
 12.1457 -int xc_cpuid_check(uint32_t input, uint32_t optsubinput,
 12.1458 -                   char *config[4], char *config_out[4])
 12.1459 -{
 12.1460 -	int ret = -EBADF;
 12.1461 -#ifdef XEN_DOMCTL_set_cpuid
 12.1462 -	uint32_t regs[4];
 12.1463 -	int i, j;
 12.1464 -
 12.1465 -	xc_cpuid(input, optsubinput, regs);
 12.1466 -
 12.1467 -	ret = 1;
 12.1468 -	for (i = 0; i < 4; i++) {
 12.1469 -		if (!config[i])
 12.1470 -			continue;
 12.1471 -		for (j = 0; j < 32; j++) {
 12.1472 -			unsigned char val;
 12.1473 -
 12.1474 -			val = !!((regs[i] & (1U << (31 - j))));
 12.1475 -
 12.1476 -			switch (config[i][j]) {
 12.1477 -			case '1': if (!val) { ret = 0; goto out; }; break;
 12.1478 -			case '0': if (val) { ret = 0; goto out; }; break;
 12.1479 -			case 'x': case 's': break;
 12.1480 -			default:
 12.1481 -				xc_error_set("cpuid check: invalid config");
 12.1482 -				ret = -EINVAL;
 12.1483 -				goto out;
 12.1484 -			}
 12.1485 -
 12.1486 -			if (config_out && config_out[i]) {
 12.1487 -				config_out[i][j] = (config[i][j] == 's')
 12.1488 -				                   ? '0' + val
 12.1489 -						   : config[i][j];
 12.1490 -			}
 12.1491 -		}
 12.1492 -	} 
 12.1493 -out:
 12.1494 -#endif
 12.1495 -	return ret;
 12.1496 -}
 12.1497 -
 12.1498 -#ifndef HVM_PARAM_HPET_ENABLED
 12.1499 -#define HVM_PARAM_HPET_ENABLED 11
 12.1500 -#endif
 12.1501 -
 12.1502 -#ifndef HVM_PARAM_ACPI_S_STATE
 12.1503 -#define HVM_PARAM_ACPI_S_STATE 14
 12.1504 -#endif
 12.1505 -
 12.1506 -#ifndef HVM_PARAM_VPT_ALIGN
 12.1507 -#define HVM_PARAM_VPT_ALIGN 16
 12.1508 -#endif
 12.1509 -
 12.1510 -int xc_domain_send_s3resume(int handle, unsigned int domid)
 12.1511 -{
 12.1512 -	return xc_set_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, 0);
 12.1513 -}
 12.1514 -
 12.1515 -int xc_domain_set_timer_mode(int handle, unsigned int domid, int mode)
 12.1516 -{
 12.1517 -	return xc_set_hvm_param(handle, domid,
 12.1518 -	                        HVM_PARAM_TIMER_MODE, (unsigned long) mode);
 12.1519 -}
 12.1520 -
 12.1521 -int xc_domain_set_hpet(int handle, unsigned int domid, int hpet)
 12.1522 -{
 12.1523 -	return xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) hpet);
 12.1524 -}
 12.1525 -
 12.1526 -int xc_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align)
 12.1527 -{
 12.1528 -	return xc_set_hvm_param(handle, domid, HVM_PARAM_VPT_ALIGN, (unsigned long) vpt_align);
 12.1529 -}
 12.1530 -
 12.1531 -int xc_domain_get_acpi_s_state(int handle, unsigned int domid)
 12.1532 -{
 12.1533 -	int ret;
 12.1534 -	unsigned long value;
 12.1535 -
 12.1536 -	ret = xc_get_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, &value);
 12.1537 -	if (ret != 0)
 12.1538 -		xc_error_dom_set(domid, "get acpi s-state");
 12.1539 -	return value;
 12.1540 -}
    13.1 --- a/tools/ocaml/libs/xc/xc_stubs.c	Thu Jan 06 17:34:46 2011 +0000
    13.2 +++ b/tools/ocaml/libs/xc/xc_stubs.c	Thu Jan 06 17:37:00 2011 +0000
    13.3 @@ -16,6 +16,7 @@
    13.4  
    13.5  #define _XOPEN_SOURCE 600
    13.6  #include <stdlib.h>
    13.7 +#include <errno.h>
    13.8  
    13.9  #define CAML_NAME_SPACE
   13.10  #include <caml/alloc.h>
   13.11 @@ -28,7 +29,7 @@
   13.12  #include <stdint.h>
   13.13  #include <string.h>
   13.14  
   13.15 -#include "xc.h"
   13.16 +#include <xenctrl.h>
   13.17  
   13.18  #include "mmap_stubs.h"
   13.19  
   13.20 @@ -36,7 +37,7 @@
   13.21  #define PAGE_SIZE               (1UL << PAGE_SHIFT)
   13.22  #define PAGE_MASK               (~(PAGE_SIZE-1))
   13.23  
   13.24 -#define _H(__h) (Int_val(__h))
   13.25 +#define _H(__h) ((xc_interface *)(__h))
   13.26  #define _D(__d) ((uint32_t)Int_val(__d))
   13.27  
   13.28  #define Val_none (Val_int(0))
   13.29 @@ -50,12 +51,23 @@
   13.30  	i1 = (uint32_t) Int64_val(Field(input, 0)); \
   13.31  	i2 = ((Field(input, 1) == Val_none) ? 0xffffffff : (uint32_t) Int64_val(Field(Field(input, 1), 0)));
   13.32  
   13.33 -/**
   13.34 - * Convert the given number of pages to an amount in MiB, rounded up.
   13.35 - */
   13.36 -void failwith_xc(void)
   13.37 +#define ERROR_STRLEN 1024
   13.38 +void failwith_xc(xc_interface *xch)
   13.39  {
   13.40 -	caml_raise_with_string(*caml_named_value("xc.error"), xc_error_get());
   13.41 +	static char error_str[ERROR_STRLEN];
   13.42 +	if (xch) {
   13.43 +		const xc_error *error = xc_get_last_error(xch);
   13.44 +		if (error->code == XC_ERROR_NONE)
   13.45 +                	snprintf(error_str, ERROR_STRLEN, "%d: %s", errno, strerror(errno));
   13.46 +		else
   13.47 +			snprintf(error_str, ERROR_STRLEN, "%d: %s: %s",
   13.48 +				 error->code,
   13.49 +				 xc_error_code_to_desc(error->code),
   13.50 +				 error->message);
   13.51 +	} else {
   13.52 +		snprintf(error_str, ERROR_STRLEN, "Unable to open XC interface");
   13.53 +	}
   13.54 +	caml_raise_with_string(*caml_named_value("xc.error"), error_str);
   13.55  }
   13.56  
   13.57  CAMLprim value stub_sizeof_core_header(value unit)
   13.58 @@ -101,35 +113,28 @@ CAMLprim value stub_marshall_core_header
   13.59  
   13.60  CAMLprim value stub_xc_interface_open(void)
   13.61  {
   13.62 -        int handle;
   13.63 -        handle = xc_interface_open();
   13.64 -        if (handle == -1)
   13.65 -		failwith_xc();
   13.66 -        return Val_int(handle);
   13.67 +	CAMLparam0();
   13.68 +        xc_interface *xch;
   13.69 +        xch = xc_interface_open(NULL, NULL, XC_OPENFLAG_NON_REENTRANT);
   13.70 +        if (xch == NULL)
   13.71 +		failwith_xc(NULL);
   13.72 +        CAMLreturn((value)xch);
   13.73  }
   13.74  
   13.75  
   13.76 -CAMLprim value stub_xc_interface_open_fake(void)
   13.77 +CAMLprim value stub_xc_interface_is_fake(void)
   13.78  {
   13.79 -	return Val_int(-1);
   13.80 +	CAMLparam0();
   13.81 +	int is_fake = xc_interface_is_fake();
   13.82 +	CAMLreturn(Val_int(is_fake));
   13.83  }
   13.84  
   13.85 -CAMLprim value stub_xc_using_injection(void)
   13.86 +CAMLprim value stub_xc_interface_close(value xch)
   13.87  {
   13.88 -	if (xc_using_injection ()){
   13.89 -		return Val_int(1);
   13.90 -	} else {
   13.91 -		return Val_int(0);
   13.92 -	}
   13.93 -}
   13.94 +	CAMLparam1(xch);
   13.95  
   13.96 -CAMLprim value stub_xc_interface_close(value xc_handle)
   13.97 -{
   13.98 -	CAMLparam1(xc_handle);
   13.99 -
  13.100 -	int handle = _H(xc_handle);
  13.101  	// caml_enter_blocking_section();
  13.102 -	xc_interface_close(handle);
  13.103 +	xc_interface_close(_H(xch));
  13.104  	// caml_leave_blocking_section();
  13.105  
  13.106  	CAMLreturn(Val_unit);
  13.107 @@ -140,16 +145,15 @@ static int domain_create_flag_table[] = 
  13.108  	XEN_DOMCTL_CDF_hap,
  13.109  };
  13.110  
  13.111 -CAMLprim value stub_xc_domain_create(value xc_handle, value ssidref,
  13.112 +CAMLprim value stub_xc_domain_create(value xch, value ssidref,
  13.113                                       value flags, value handle)
  13.114  {
  13.115 -	CAMLparam4(xc_handle, ssidref, flags, handle);
  13.116 +	CAMLparam4(xch, ssidref, flags, handle);
  13.117  
  13.118  	uint32_t domid = 0;
  13.119  	xen_domain_handle_t h = { 0 };
  13.120  	int result;
  13.121  	int i;
  13.122 -	int c_xc_handle = _H(xc_handle);
  13.123  	uint32_t c_ssidref = Int32_val(ssidref);
  13.124  	unsigned int c_flags = 0;
  13.125  	value l;
  13.126 @@ -167,46 +171,32 @@ CAMLprim value stub_xc_domain_create(val
  13.127  	}
  13.128  
  13.129  	// caml_enter_blocking_section();
  13.130 -	result = xc_domain_create(c_xc_handle, c_ssidref, h, c_flags, &domid);
  13.131 +	result = xc_domain_create(_H(xch), c_ssidref, h, c_flags, &domid);
  13.132  	// caml_leave_blocking_section();
  13.133  
  13.134  	if (result < 0)
  13.135 -		failwith_xc();
  13.136 +		failwith_xc(_H(xch));
  13.137  
  13.138  	CAMLreturn(Val_int(domid));
  13.139  }
  13.140  
  13.141 -CAMLprim value stub_xc_domain_setvmxassist(value xc_handle, value domid,
  13.142 -					    value use_vmxassist)
  13.143 +CAMLprim value stub_xc_domain_max_vcpus(value xch, value domid,
  13.144 +                                        value max_vcpus)
  13.145  {
  13.146 -	CAMLparam3(xc_handle, domid, use_vmxassist);
  13.147 +	CAMLparam3(xch, domid, max_vcpus);
  13.148  	int r;
  13.149  
  13.150 -	r = xc_domain_setvmxassist(_H(xc_handle), _D(domid),
  13.151 -				   Bool_val(use_vmxassist));
  13.152 +	r = xc_domain_max_vcpus(_H(xch), _D(domid), Int_val(max_vcpus));
  13.153  	if (r)
  13.154 -		failwith_xc();
  13.155 -
  13.156 -	CAMLreturn(Val_unit);
  13.157 -}
  13.158 -
  13.159 -CAMLprim value stub_xc_domain_max_vcpus(value xc_handle, value domid,
  13.160 -                                        value max_vcpus)
  13.161 -{
  13.162 -	CAMLparam3(xc_handle, domid, max_vcpus);
  13.163 -	int r;
  13.164 -
  13.165 -	r = xc_domain_max_vcpus(_H(xc_handle), _D(domid), Int_val(max_vcpus));
  13.166 -	if (r)
  13.167 -		failwith_xc();
  13.168 +		failwith_xc(_H(xch));
  13.169  
  13.170  	CAMLreturn(Val_unit);
  13.171  }
  13.172  
  13.173  
  13.174 -value stub_xc_domain_sethandle(value xc_handle, value domid, value handle)
  13.175 +value stub_xc_domain_sethandle(value xch, value domid, value handle)
  13.176  {
  13.177 -	CAMLparam3(xc_handle, domid, handle);
  13.178 +	CAMLparam3(xch, domid, handle);
  13.179  	xen_domain_handle_t h = { 0 };
  13.180  	int i;
  13.181  
  13.182 @@ -217,57 +207,65 @@ value stub_xc_domain_sethandle(value xc_
  13.183  		h[i] = Int_val(Field(handle, i)) & 0xff;
  13.184  	}
  13.185  
  13.186 -	i = xc_domain_sethandle(_H(xc_handle), _D(domid), h);
  13.187 +	i = xc_domain_sethandle(_H(xch), _D(domid), h);
  13.188  	if (i)
  13.189 -		failwith_xc();
  13.190 +		failwith_xc(_H(xch));
  13.191  
  13.192  	CAMLreturn(Val_unit);
  13.193  }
  13.194  
  13.195 -static value dom_op(value xc_handle, value domid, int (*fn)(int, uint32_t))
  13.196 +static value dom_op(value xch, value domid, int (*fn)(xc_interface *, uint32_t))
  13.197  {
  13.198 -	CAMLparam2(xc_handle, domid);
  13.199 +	CAMLparam2(xch, domid);
  13.200  
  13.201 -	int c_xc_handle = _H(xc_handle);
  13.202  	uint32_t c_domid = _D(domid);
  13.203  
  13.204  	// caml_enter_blocking_section();
  13.205 -	int result = fn(c_xc_handle, c_domid);
  13.206 +	int result = fn(_H(xch), c_domid);
  13.207  	// caml_leave_blocking_section();
  13.208          if (result)
  13.209 -		failwith_xc();
  13.210 +		failwith_xc(_H(xch));
  13.211  	CAMLreturn(Val_unit);
  13.212  }
  13.213  
  13.214 -CAMLprim value stub_xc_domain_pause(value xc_handle, value domid)
  13.215 +CAMLprim value stub_xc_domain_pause(value xch, value domid)
  13.216  {
  13.217 -	return dom_op(xc_handle, domid, xc_domain_pause);
  13.218 +	return dom_op(xch, domid, xc_domain_pause);
  13.219  }
  13.220  
  13.221  
  13.222 -CAMLprim value stub_xc_domain_unpause(value xc_handle, value domid)
  13.223 +CAMLprim value stub_xc_domain_unpause(value xch, value domid)
  13.224  {
  13.225 -	return dom_op(xc_handle, domid, xc_domain_unpause);
  13.226 +	return dom_op(xch, domid, xc_domain_unpause);
  13.227  }
  13.228  
  13.229 -CAMLprim value stub_xc_domain_destroy(value xc_handle, value domid)
  13.230 +CAMLprim value stub_xc_domain_destroy(value xch, value domid)
  13.231  {
  13.232 -	return dom_op(xc_handle, domid, xc_domain_destroy);
  13.233 +	return dom_op(xch, domid, xc_domain_destroy);
  13.234  }
  13.235  
  13.236 -CAMLprim value stub_xc_domain_resume_fast(value xc_handle, value domid)
  13.237 +CAMLprim value stub_xc_domain_resume_fast(value xch, value domid)
  13.238  {
  13.239 -	return dom_op(xc_handle, domid, xc_domain_resume_fast);
  13.240 +	CAMLparam2(xch, domid);
  13.241 +
  13.242 +	uint32_t c_domid = _D(domid);
  13.243 +
  13.244 +	// caml_enter_blocking_section();
  13.245 +	int result = xc_domain_resume(_H(xch), c_domid, 1);
  13.246 +	// caml_leave_blocking_section();
  13.247 +        if (result)
  13.248 +		failwith_xc(_H(xch));
  13.249 +	CAMLreturn(Val_unit);
  13.250  }
  13.251  
  13.252 -CAMLprim value stub_xc_domain_shutdown(value handle, value domid, value reason)
  13.253 +CAMLprim value stub_xc_domain_shutdown(value xch, value domid, value reason)
  13.254  {
  13.255 -	CAMLparam3(handle, domid, reason);
  13.256 +	CAMLparam3(xch, domid, reason);
  13.257  	int ret;
  13.258  
  13.259 -	ret = xc_domain_shutdown(_H(handle), _D(domid), Int_val(reason));
  13.260 +	ret = xc_domain_shutdown(_H(xch), _D(domid), Int_val(reason));
  13.261  	if (ret < 0)
  13.262 -		failwith_xc();
  13.263 +		failwith_xc(_H(xch));
  13.264  
  13.265  	CAMLreturn(Val_unit);
  13.266  }
  13.267 @@ -307,12 +305,12 @@ static value alloc_domaininfo(xc_domaini
  13.268  	CAMLreturn(result);
  13.269  }
  13.270  
  13.271 -CAMLprim value stub_xc_domain_getinfolist(value xc_handle, value first_domain, value nb)
  13.272 +CAMLprim value stub_xc_domain_getinfolist(value xch, value first_domain, value nb)
  13.273  {
  13.274 -	CAMLparam3(xc_handle, first_domain, nb);
  13.275 +	CAMLparam3(xch, first_domain, nb);
  13.276  	CAMLlocal2(result, temp);
  13.277  	xc_domaininfo_t * info;
  13.278 -	int i, ret, toalloc, c_xc_handle, retval;
  13.279 +	int i, ret, toalloc, retval;
  13.280  	unsigned int c_max_domains;
  13.281  	uint32_t c_first_domain;
  13.282  
  13.283 @@ -324,17 +322,16 @@ CAMLprim value stub_xc_domain_getinfolis
  13.284  
  13.285  	result = temp = Val_emptylist;
  13.286  
  13.287 -	c_xc_handle = _H(xc_handle);
  13.288  	c_first_domain = _D(first_domain);
  13.289  	c_max_domains = Int_val(nb);
  13.290  	// caml_enter_blocking_section();
  13.291 -	retval = xc_domain_getinfolist(c_xc_handle, c_first_domain,
  13.292 +	retval = xc_domain_getinfolist(_H(xch), c_first_domain,
  13.293  				       c_max_domains, info);
  13.294  	// caml_leave_blocking_section();
  13.295  
  13.296  	if (retval < 0) {
  13.297  		free(info);
  13.298 -		failwith_xc();
  13.299 +		failwith_xc(_H(xch));
  13.300  	}
  13.301  	for (i = 0; i < retval; i++) {
  13.302  		result = caml_alloc_small(2, Tag_cons);
  13.303 @@ -349,37 +346,38 @@ CAMLprim value stub_xc_domain_getinfolis
  13.304  	CAMLreturn(result);
  13.305  }
  13.306  
  13.307 -CAMLprim value stub_xc_domain_getinfo(value xc_handle, value domid)
  13.308 +CAMLprim value stub_xc_domain_getinfo(value xch, value domid)
  13.309  {
  13.310 -	CAMLparam2(xc_handle, domid);
  13.311 +	CAMLparam2(xch, domid);
  13.312  	CAMLlocal1(result);
  13.313  	xc_domaininfo_t info;
  13.314  	int ret;
  13.315  
  13.316 -	ret = xc_domain_getinfo(_H(xc_handle), _D(domid), &info);
  13.317 -	if (ret != 0)
  13.318 -		failwith_xc();
  13.319 +	ret = xc_domain_getinfolist(_H(xch), _D(domid), 1, &info);
  13.320 +	if (ret != 1)
  13.321 +		failwith_xc(_H(xch));
  13.322 +	if (info.domain != _D(domid))
  13.323 +		failwith_xc(_H(xch));
  13.324  
  13.325  	result = alloc_domaininfo(&info);
  13.326  	CAMLreturn(result);
  13.327  }
  13.328  
  13.329 -CAMLprim value stub_xc_vcpu_getinfo(value xc_handle, value domid, value vcpu)
  13.330 +CAMLprim value stub_xc_vcpu_getinfo(value xch, value domid, value vcpu)
  13.331  {
  13.332 -	CAMLparam3(xc_handle, domid, vcpu);
  13.333 +	CAMLparam3(xch, domid, vcpu);
  13.334  	CAMLlocal1(result);
  13.335  	xc_vcpuinfo_t info;
  13.336  	int retval;
  13.337  
  13.338 -	int c_xc_handle = _H(xc_handle);
  13.339  	uint32_t c_domid = _D(domid);
  13.340  	uint32_t c_vcpu = Int_val(vcpu);
  13.341  	// caml_enter_blocking_section();
  13.342 -	retval = xc_vcpu_getinfo(c_xc_handle, c_domid,
  13.343 +	retval = xc_vcpu_getinfo(_H(xch), c_domid,
  13.344  	                         c_vcpu, &info);
  13.345  	// caml_leave_blocking_section();
  13.346  	if (retval < 0)
  13.347 -		failwith_xc();
  13.348 +		failwith_xc(_H(xch));
  13.349  
  13.350  	result = caml_alloc_tuple(5);
  13.351  	Store_field(result, 0, Val_bool(info.online));
  13.352 @@ -391,15 +389,15 @@ CAMLprim value stub_xc_vcpu_getinfo(valu
  13.353  	CAMLreturn(result);
  13.354  }
  13.355  
  13.356 -CAMLprim value stub_xc_vcpu_context_get(value xc_handle, value domid,
  13.357 +CAMLprim value stub_xc_vcpu_context_get(value xch, value domid,
  13.358                                          value cpu)
  13.359  {
  13.360 -	CAMLparam3(xc_handle, domid, cpu);
  13.361 +	CAMLparam3(xch, domid, cpu);
  13.362  	CAMLlocal1(context);
  13.363  	int ret;
  13.364  	vcpu_guest_context_any_t ctxt;
  13.365  
  13.366 -	ret = xc_vcpu_getcontext(_H(xc_handle), _D(domid), Int_val(cpu), &ctxt);
  13.367 +	ret = xc_vcpu_getcontext(_H(xch), _D(domid), Int_val(cpu), &ctxt);
  13.368  
  13.369  	context = caml_alloc_string(sizeof(ctxt));
  13.370  	memcpy(String_val(context), (char *) &ctxt.c, sizeof(ctxt.c));
  13.371 @@ -407,75 +405,115 @@ CAMLprim value stub_xc_vcpu_context_get(
  13.372  	CAMLreturn(context);
  13.373  }
  13.374  
  13.375 -CAMLprim value stub_xc_vcpu_setaffinity(value xc_handle, value domid,
  13.376 +static int get_cpumap_len(value xch, value cpumap)
  13.377 +{
  13.378 +	int ml_len = Wosize_val(cpumap);
  13.379 +	int xc_len = xc_get_max_cpus(_H(xch));
  13.380 +
  13.381 +	if (ml_len < xc_len)
  13.382 +		return ml_len;
  13.383 +	else
  13.384 +		return xc_len;
  13.385 +}
  13.386 +
  13.387 +CAMLprim value stub_xc_vcpu_setaffinity(value xch, value domid,
  13.388                                          value vcpu, value cpumap)
  13.389  {
  13.390 -	CAMLparam4(xc_handle, domid, vcpu, cpumap);
  13.391 -	uint64_t c_cpumap;
  13.392 +	CAMLparam4(xch, domid, vcpu, cpumap);
  13.393 +	int i, len = get_cpumap_len(xch, cpumap);
  13.394 +	xc_cpumap_t c_cpumap;
  13.395  	int retval;
  13.396  
  13.397 -	c_cpumap = Int64_val(cpumap);
  13.398 -	retval = xc_vcpu_setaffinity(_H(xc_handle), _D(domid),
  13.399 +	c_cpumap = xc_cpumap_alloc(_H(xch));
  13.400 +	if (c_cpumap == NULL)
  13.401 +		failwith_xc(_H(xch));
  13.402 +
  13.403 +	for (i=0; i<len; i++) {
  13.404 +		if (Bool_val(Field(cpumap, i)))
  13.405 +			c_cpumap[i/8] |= i << (i&7);
  13.406 +	}
  13.407 +	retval = xc_vcpu_setaffinity(_H(xch), _D(domid),
  13.408  	                             Int_val(vcpu), c_cpumap);
  13.409 +	free(c_cpumap);
  13.410 +
  13.411  	if (retval < 0)
  13.412 -		failwith_xc();
  13.413 +		failwith_xc(_H(xch));
  13.414  	CAMLreturn(Val_unit);
  13.415  }
  13.416  
  13.417 -CAMLprim value stub_xc_vcpu_getaffinity(value xc_handle, value domid,
  13.418 +CAMLprim value stub_xc_vcpu_getaffinity(value xch, value domid,
  13.419                                          value vcpu)
  13.420  {
  13.421 -	CAMLparam3(xc_handle, domid, vcpu);
  13.422 +	CAMLparam3(xch, domid, vcpu);
  13.423  	CAMLlocal1(ret);
  13.424 -	uint64_t cpumap;
  13.425 +	xc_cpumap_t c_cpumap;
  13.426 +	int i, len = xc_get_max_cpus(_H(xch));
  13.427  	int retval;
  13.428  
  13.429 -	retval = xc_vcpu_getaffinity(_H(xc_handle), _D(domid),
  13.430 -	                             Int_val(vcpu), &cpumap);
  13.431 -	if (retval < 0)
  13.432 -		failwith_xc();
  13.433 -	ret = caml_copy_int64(cpumap);
  13.434 +	c_cpumap = xc_cpumap_alloc(_H(xch));
  13.435 +	if (c_cpumap == NULL)
  13.436 +		failwith_xc(_H(xch));
  13.437 +
  13.438 +	retval = xc_vcpu_getaffinity(_H(xch), _D(domid),
  13.439 +	                             Int_val(vcpu), c_cpumap);
  13.440 +	free(c_cpumap);
  13.441 +
  13.442 +	if (retval < 0) {
  13.443 +		free(c_cpumap);
  13.444 +		failwith_xc(_H(xch));
  13.445 +	}
  13.446 +
  13.447 +	ret = caml_alloc(len, 0);
  13.448 +
  13.449 +	for (i=0; i<len; i++) {
  13.450 +		if (c_cpumap[i%8] & 1 << (i&7))
  13.451 +			Store_field(ret, i, Val_true);
  13.452 +		else
  13.453 +			Store_field(ret, i, Val_false);
  13.454 +	}
  13.455 +
  13.456 +	free(c_cpumap);
  13.457 +
  13.458  	CAMLreturn(ret);
  13.459  }
  13.460  
  13.461 -CAMLprim value stub_xc_sched_id(value xc_handle)
  13.462 +CAMLprim value stub_xc_sched_id(value xch)
  13.463  {
  13.464 -	CAMLparam1(xc_handle);
  13.465 +	CAMLparam1(xch);
  13.466  	int sched_id;
  13.467  
  13.468 -	if (xc_sched_id(_H(xc_handle), &sched_id))
  13.469 -		failwith_xc();
  13.470 +	if (xc_sched_id(_H(xch), &sched_id))
  13.471 +		failwith_xc(_H(xch));
  13.472  	CAMLreturn(Val_int(sched_id));
  13.473  }
  13.474  
  13.475 -CAMLprim value stub_xc_evtchn_alloc_unbound(value xc_handle,
  13.476 +CAMLprim value stub_xc_evtchn_alloc_unbound(value xch,
  13.477                                              value local_domid,
  13.478                                              value remote_domid)
  13.479  {
  13.480 -	CAMLparam3(xc_handle, local_domid, remote_domid);
  13.481 +	CAMLparam3(xch, local_domid, remote_domid);
  13.482  
  13.483 -	int c_xc_handle = _H(xc_handle);
  13.484  	uint32_t c_local_domid = _D(local_domid);
  13.485  	uint32_t c_remote_domid = _D(remote_domid);
  13.486  
  13.487  	// caml_enter_blocking_section();
  13.488 -	int result = xc_evtchn_alloc_unbound(c_xc_handle, c_local_domid,
  13.489 +	int result = xc_evtchn_alloc_unbound(_H(xch), c_local_domid,
  13.490  	                                     c_remote_domid);
  13.491  	// caml_leave_blocking_section();
  13.492  
  13.493  	if (result < 0)
  13.494 -		failwith_xc();
  13.495 +		failwith_xc(_H(xch));
  13.496  	CAMLreturn(Val_int(result));
  13.497  }
  13.498  
  13.499 -CAMLprim value stub_xc_evtchn_reset(value handle, value domid)
  13.500 +CAMLprim value stub_xc_evtchn_reset(value xch, value domid)
  13.501  {
  13.502 -	CAMLparam2(handle, domid);
  13.503 +	CAMLparam2(xch, domid);
  13.504  	int r;
  13.505  
  13.506 -	r = xc_evtchn_reset(_H(handle), _D(domid));
  13.507 +	r = xc_evtchn_reset(_H(xch), _D(domid));
  13.508  	if (r < 0)
  13.509 -		failwith_xc();
  13.510 +		failwith_xc(_H(xch));
  13.511  	CAMLreturn(Val_unit);
  13.512  }
  13.513  
  13.514 @@ -483,48 +521,47 @@ CAMLprim value stub_xc_evtchn_reset(valu
  13.515  #define RING_SIZE 32768
  13.516  static char ring[RING_SIZE];
  13.517  
  13.518 -CAMLprim value stub_xc_readconsolering(value xc_handle)
  13.519 +CAMLprim value stub_xc_readconsolering(value xch)
  13.520  {
  13.521  	unsigned int size = RING_SIZE;
  13.522  	char *ring_ptr = ring;
  13.523  
  13.524 -	CAMLparam1(xc_handle);
  13.525 -	int c_xc_handle = _H(xc_handle);
  13.526 +	CAMLparam1(xch);
  13.527  
  13.528  	// caml_enter_blocking_section();
  13.529 -	int retval = xc_readconsolering(c_xc_handle, &ring_ptr, &size, 0);
  13.530 +	int retval = xc_readconsolering(_H(xch), ring_ptr, &size, 0, 0, NULL);
  13.531  	// caml_leave_blocking_section();
  13.532  
  13.533  	if (retval)
  13.534 -		failwith_xc();
  13.535 +		failwith_xc(_H(xch));
  13.536  	ring[size] = '\0';
  13.537  	CAMLreturn(caml_copy_string(ring));
  13.538  }
  13.539  
  13.540 -CAMLprim value stub_xc_send_debug_keys(value xc_handle, value keys)
  13.541 +CAMLprim value stub_xc_send_debug_keys(value xch, value keys)
  13.542  {
  13.543 -	CAMLparam2(xc_handle, keys);
  13.544 +	CAMLparam2(xch, keys);
  13.545  	int r;
  13.546  
  13.547 -	r = xc_send_debug_keys(_H(xc_handle), String_val(keys));
  13.548 +	r = xc_send_debug_keys(_H(xch), String_val(keys));
  13.549  	if (r)
  13.550 -		failwith_xc();
  13.551 +		failwith_xc(_H(xch));
  13.552  	CAMLreturn(Val_unit);
  13.553  }
  13.554  
  13.555 -CAMLprim value stub_xc_physinfo(value xc_handle)
  13.556 +CAMLprim value stub_xc_physinfo(value xch)
  13.557  {
  13.558 -	CAMLparam1(xc_handle);
  13.559 +	CAMLparam1(xch);
  13.560  	CAMLlocal3(physinfo, cap_list, tmp);
  13.561  	xc_physinfo_t c_physinfo;
  13.562  	int r;
  13.563  
  13.564  	// caml_enter_blocking_section();
  13.565 -	r = xc_physinfo(_H(xc_handle), &c_physinfo);
  13.566 +	r = xc_physinfo(_H(xch), &c_physinfo);
  13.567  	// caml_leave_blocking_section();
  13.568  
  13.569  	if (r)
  13.570 -		failwith_xc();
  13.571 +		failwith_xc(_H(xch));
  13.572  
  13.573  	tmp = cap_list = Val_emptylist;
  13.574  	for (r = 0; r < 2; r++) {
  13.575 @@ -550,11 +587,11 @@ CAMLprim value stub_xc_physinfo(value xc
  13.576  	CAMLreturn(physinfo);
  13.577  }
  13.578  
  13.579 -CAMLprim value stub_xc_pcpu_info(value xc_handle, value nr_cpus)
  13.580 +CAMLprim value stub_xc_pcpu_info(value xch, value nr_cpus)
  13.581  {
  13.582 -	CAMLparam2(xc_handle, nr_cpus);
  13.583 +	CAMLparam2(xch, nr_cpus);
  13.584  	CAMLlocal2(pcpus, v);
  13.585 -	xen_sysctl_cpuinfo_t *info;
  13.586 +	xc_cpuinfo_t *info;
  13.587  	int r, size;
  13.588  
  13.589  	if (Int_val(nr_cpus) < 1)
  13.590 @@ -565,12 +602,12 @@ CAMLprim value stub_xc_pcpu_info(value x
  13.591  		caml_raise_out_of_memory();
  13.592  
  13.593  	// caml_enter_blocking_section();
  13.594 -	r = xc_pcpu_info(_H(xc_handle), Int_val(nr_cpus), info, &size);
  13.595 +	r = xc_getcpuinfo(_H(xch), Int_val(nr_cpus), info, &size);
  13.596  	// caml_leave_blocking_section();
  13.597  
  13.598  	if (r) {
  13.599  		free(info);
  13.600 -		failwith_xc();
  13.601 +		failwith_xc(_H(xch));
  13.602  	}
  13.603  
  13.604  	if (size > 0) {
  13.605 @@ -586,101 +623,98 @@ CAMLprim value stub_xc_pcpu_info(value x
  13.606  	CAMLreturn(pcpus);
  13.607  }
  13.608  
  13.609 -CAMLprim value stub_xc_domain_setmaxmem(value xc_handle, value domid,
  13.610 +CAMLprim value stub_xc_domain_setmaxmem(value xch, value domid,
  13.611                                          value max_memkb)
  13.612  {
  13.613 -	CAMLparam3(xc_handle, domid, max_memkb);
  13.614 +	CAMLparam3(xch, domid, max_memkb);
  13.615  
  13.616 -	int c_xc_handle = _H(xc_handle);
  13.617  	uint32_t c_domid = _D(domid);
  13.618  	unsigned int c_max_memkb = Int64_val(max_memkb);
  13.619  	// caml_enter_blocking_section();
  13.620 -	int retval = xc_domain_setmaxmem(c_xc_handle, c_domid,
  13.621 +	int retval = xc_domain_setmaxmem(_H(xch), c_domid,
  13.622  	                                 c_max_memkb);
  13.623  	// caml_leave_blocking_section();
  13.624  	if (retval)
  13.625 -		failwith_xc();
  13.626 +		failwith_xc(_H(xch));
  13.627  	CAMLreturn(Val_unit);
  13.628  }
  13.629  
  13.630 -CAMLprim value stub_xc_domain_set_memmap_limit(value xc_handle, value domid,
  13.631 +CAMLprim value stub_xc_domain_set_memmap_limit(value xch, value domid,
  13.632                                                 value map_limitkb)
  13.633  {
  13.634 -	CAMLparam3(xc_handle, domid, map_limitkb);
  13.635 +	CAMLparam3(xch, domid, map_limitkb);
  13.636  	unsigned long v;
  13.637  	int retval;
  13.638  
  13.639  	v = Int64_val(map_limitkb);
  13.640 -	retval = xc_domain_set_memmap_limit(_H(xc_handle), _D(domid), v);
  13.641 +	retval = xc_domain_set_memmap_limit(_H(xch), _D(domid), v);
  13.642  	if (retval)
  13.643 -		failwith_xc();
  13.644 +		failwith_xc(_H(xch));
  13.645  
  13.646  	CAMLreturn(Val_unit);
  13.647  }
  13.648  
  13.649 -CAMLprim value stub_xc_domain_memory_increase_reservation(value xc_handle,
  13.650 +CAMLprim value stub_xc_domain_memory_increase_reservation(value xch,
  13.651                                                            value domid,
  13.652                                                            value mem_kb)
  13.653  {
  13.654 -	CAMLparam3(xc_handle, domid, mem_kb);
  13.655 +	CAMLparam3(xch, domid, mem_kb);
  13.656  
  13.657  	unsigned long nr_extents = ((unsigned long)(Int64_val(mem_kb))) >> (PAGE_SHIFT - 10);
  13.658  
  13.659 -	int c_xc_handle = _H(xc_handle);
  13.660  	uint32_t c_domid = _D(domid);
  13.661  	// caml_enter_blocking_section();
  13.662 -	int retval = xc_domain_memory_increase_reservation(c_xc_handle, c_domid,
  13.663 -	                                                   nr_extents, 0, 0, NULL);
  13.664 +	int retval = xc_domain_increase_reservation_exact(_H(xch), c_domid,
  13.665 +							  nr_extents, 0, 0, NULL);
  13.666  	// caml_leave_blocking_section();
  13.667  
  13.668  	if (retval)
  13.669 -		failwith_xc();
  13.670 +		failwith_xc(_H(xch));
  13.671  	CAMLreturn(Val_unit);
  13.672  }
  13.673  
  13.674 -CAMLprim value stub_xc_domain_set_machine_address_size(value xc_handle,
  13.675 +CAMLprim value stub_xc_domain_set_machine_address_size(value xch,
  13.676  						       value domid,
  13.677  						       value width)
  13.678  {
  13.679 -	CAMLparam3(xc_handle, domid, width);
  13.680 -	int c_xc_handle = _H(xc_handle);
  13.681 +	CAMLparam3(xch, domid, width);
  13.682  	uint32_t c_domid = _D(domid);
  13.683  	int c_width = Int_val(width);
  13.684  
  13.685 -	int retval = xc_domain_set_machine_address_size(c_xc_handle, c_domid, c_width);
  13.686 +	int retval = xc_domain_set_machine_address_size(_H(xch), c_domid, c_width);
  13.687  	if (retval)
  13.688 -		failwith_xc();
  13.689 +		failwith_xc(_H(xch));
  13.690  	CAMLreturn(Val_unit);
  13.691  }
  13.692  
  13.693 -CAMLprim value stub_xc_domain_get_machine_address_size(value xc_handle,
  13.694 +CAMLprim value stub_xc_domain_get_machine_address_size(value xch,
  13.695                                                         value domid)
  13.696  {
  13.697 -	CAMLparam2(xc_handle, domid);
  13.698 +	CAMLparam2(xch, domid);
  13.699  	int retval;
  13.700  
  13.701 -	retval = xc_domain_get_machine_address_size(_H(xc_handle), _D(domid));
  13.702 +	retval = xc_domain_get_machine_address_size(_H(xch), _D(domid));
  13.703  	if (retval < 0)
  13.704 -		failwith_xc();
  13.705 +		failwith_xc(_H(xch));
  13.706  	CAMLreturn(Val_int(retval));
  13.707  }
  13.708  
  13.709 -CAMLprim value stub_xc_domain_cpuid_set(value xc_handle, value domid,
  13.710 -                                        value is_hvm, value input,
  13.711 +CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid,
  13.712 +                                        value input,
  13.713                                          value config)
  13.714  {
  13.715 -	CAMLparam5(xc_handle, domid, is_hvm, input, config);
  13.716 +	CAMLparam4(xch, domid, input, config);
  13.717  	CAMLlocal2(array, tmp);
  13.718  	int r;
  13.719 +	unsigned int c_input[2];
  13.720  	char *c_config[4], *out_config[4];
  13.721 -	uint32_t c_input, c_oinput;
  13.722  
  13.723  	c_config[0] = string_of_option_array(config, 0);
  13.724  	c_config[1] = string_of_option_array(config, 1);
  13.725  	c_config[2] = string_of_option_array(config, 2);
  13.726  	c_config[3] = string_of_option_array(config, 3);
  13.727  
  13.728 -	cpuid_input_of_val(c_input, c_oinput, input);
  13.729 +	cpuid_input_of_val(c_input[0], c_input[1], input);
  13.730  
  13.731  	array = caml_alloc(4, 0);
  13.732  	for (r = 0; r < 4; r++) {
  13.733 @@ -695,29 +729,30 @@ CAMLprim value stub_xc_domain_cpuid_set(
  13.734  	for (r = 0; r < 4; r++)
  13.735  		out_config[r] = (c_config[r]) ? String_val(Field(Field(array, r), 0)) : NULL;
  13.736  
  13.737 -	r = xc_domain_cpuid_set(_H(xc_handle), _D(domid), Bool_val(is_hvm),
  13.738 -	                        c_input, c_oinput, c_config, out_config);
  13.739 +	r = xc_cpuid_set(_H(xch), _D(domid),
  13.740 +			 c_input, (const char **)c_config, out_config);
  13.741  	if (r < 0)
  13.742 -		failwith_xc();
  13.743 +		failwith_xc(_H(xch));
  13.744  	CAMLreturn(array);
  13.745  }
  13.746  
  13.747 -CAMLprim value stub_xc_domain_cpuid_apply(value xc_handle, value domid, value is_hvm)
  13.748 +CAMLprim value stub_xc_domain_cpuid_apply_policy(value xch, value domid)
  13.749  {
  13.750 -	CAMLparam3(xc_handle, domid, is_hvm);
  13.751 +	CAMLparam2(xch, domid);
  13.752  	int r;
  13.753 -	r = xc_domain_cpuid_apply(_H(xc_handle), _D(domid), Bool_val(is_hvm));
  13.754 +
  13.755 +	r = xc_cpuid_apply_policy(_H(xch), _D(domid));
  13.756  	if (r < 0)
  13.757 -		failwith_xc();
  13.758 +		failwith_xc(_H(xch));
  13.759  	CAMLreturn(Val_unit);
  13.760  }
  13.761  
  13.762 -CAMLprim value stub_xc_cpuid_check(value input, value config)
  13.763 +CAMLprim value stub_xc_cpuid_check(value xch, value input, value config)
  13.764  {
  13.765 -	CAMLparam2(input, config);
  13.766 +	CAMLparam3(xch, input, config);
  13.767  	CAMLlocal3(ret, array, tmp);
  13.768  	int r;
  13.769 -	uint32_t c_input, c_oinput;
  13.770 +	unsigned int c_input[2];
  13.771  	char *c_config[4], *out_config[4];
  13.772  
  13.773  	c_config[0] = string_of_option_array(config, 0);
  13.774 @@ -725,7 +760,7 @@ CAMLprim value stub_xc_cpuid_check(value
  13.775  	c_config[2] = string_of_option_array(config, 2);
  13.776  	c_config[3] = string_of_option_array(config, 3);
  13.777  
  13.778 -	cpuid_input_of_val(c_input, c_oinput, input);
  13.779 +	cpuid_input_of_val(c_input[0], c_input[1], input);
  13.780  
  13.781  	array = caml_alloc(4, 0);
  13.782  	for (r = 0; r < 4; r++) {
  13.783 @@ -740,9 +775,9 @@ CAMLprim value stub_xc_cpuid_check(value
  13.784  	for (r = 0; r < 4; r++)
  13.785  		out_config[r] = (c_config[r]) ? String_val(Field(Field(array, r), 0)) : NULL;
  13.786  
  13.787 -	r = xc_cpuid_check(c_input, c_oinput, c_config, out_config);
  13.788 +	r = xc_cpuid_check(_H(xch), c_input, (const char **)c_config, out_config);
  13.789  	if (r < 0)
  13.790 -		failwith_xc();
  13.791 +		failwith_xc(_H(xch));
  13.792  
  13.793  	ret = caml_alloc_tuple(2);
  13.794  	Store_field(ret, 0, Val_bool(r));
  13.795 @@ -751,22 +786,21 @@ CAMLprim value stub_xc_cpuid_check(value
  13.796  	CAMLreturn(ret);
  13.797  }
  13.798  
  13.799 -CAMLprim value stub_xc_version_version(value xc_handle)
  13.800 +CAMLprim value stub_xc_version_version(value xch)
  13.801  {
  13.802 -	CAMLparam1(xc_handle);
  13.803 +	CAMLparam1(xch);
  13.804  	CAMLlocal1(result);
  13.805  	xen_extraversion_t extra;
  13.806  	long packed;
  13.807  	int retval;
  13.808  
  13.809 -	int c_xc_handle = _H(xc_handle);
  13.810  	// caml_enter_blocking_section();
  13.811 -	packed = xc_version(c_xc_handle, XENVER_version, NULL);
  13.812 -	retval = xc_version(c_xc_handle, XENVER_extraversion, &extra);
  13.813 +	packed = xc_version(_H(xch), XENVER_version, NULL);
  13.814 +	retval = xc_version(_H(xch), XENVER_extraversion, &extra);
  13.815  	// caml_leave_blocking_section();
  13.816  
  13.817  	if (retval)
  13.818 -		failwith_xc();
  13.819 +		failwith_xc(_H(xch));
  13.820  
  13.821  	result = caml_alloc_tuple(3);
  13.822  
  13.823 @@ -778,20 +812,19 @@ CAMLprim value stub_xc_version_version(v
  13.824  }
  13.825  
  13.826  
  13.827 -CAMLprim value stub_xc_version_compile_info(value xc_handle)
  13.828 +CAMLprim value stub_xc_version_compile_info(value xch)
  13.829  {
  13.830 -	CAMLparam1(xc_handle);
  13.831 +	CAMLparam1(xch);
  13.832  	CAMLlocal1(result);
  13.833  	xen_compile_info_t ci;
  13.834  	int retval;
  13.835  
  13.836 -	int c_xc_handle = _H(xc_handle);
  13.837  	// caml_enter_blocking_section();
  13.838 -	retval = xc_version(c_xc_handle, XENVER_compile_info, &ci);
  13.839 +	retval = xc_version(_H(xch), XENVER_compile_info, &ci);
  13.840  	// caml_leave_blocking_section();
  13.841  
  13.842  	if (retval)
  13.843 -		failwith_xc();
  13.844 +		failwith_xc(_H(xch));
  13.845  
  13.846  	result = caml_alloc_tuple(4);
  13.847  
  13.848 @@ -804,36 +837,35 @@ CAMLprim value stub_xc_version_compile_i
  13.849  }
  13.850  
  13.851  
  13.852 -static value xc_version_single_string(value xc_handle, int code, void *info)
  13.853 +static value xc_version_single_string(value xch, int code, void *info)
  13.854  {
  13.855 -	CAMLparam1(xc_handle);
  13.856 +	CAMLparam1(xch);
  13.857  	int retval;
  13.858  
  13.859 -	int c_xc_handle = _H(xc_handle);
  13.860  	// caml_enter_blocking_section();
  13.861 -	retval = xc_version(c_xc_handle, code, info);
  13.862 +	retval = xc_version(_H(xch), code, info);
  13.863  	// caml_leave_blocking_section();
  13.864  
  13.865  	if (retval)
  13.866 -		failwith_xc();
  13.867 +		failwith_xc(_H(xch));
  13.868  
  13.869  	CAMLreturn(caml_copy_string((char *)info));
  13.870  }
  13.871  
  13.872  
  13.873 -CAMLprim value stub_xc_version_changeset(value xc_handle)
  13.874 +CAMLprim value stub_xc_version_changeset(value xch)
  13.875  {
  13.876  	xen_changeset_info_t ci;
  13.877  
  13.878 -	return xc_version_single_string(xc_handle, XENVER_changeset, &ci);
  13.879 +	return xc_version_single_string(xch, XENVER_changeset, &ci);
  13.880  }
  13.881  
  13.882  
  13.883 -CAMLprim value stub_xc_version_capabilities(value xc_handle)
  13.884 +CAMLprim value stub_xc_version_capabilities(value xch)
  13.885  {
  13.886  	xen_capabilities_info_t ci;
  13.887  
  13.888 -	return xc_version_single_string(xc_handle, XENVER_capabilities, &ci);
  13.889 +	return xc_version_single_string(xch, XENVER_capabilities, &ci);
  13.890  }
  13.891  
  13.892  
  13.893 @@ -845,13 +877,12 @@ CAMLprim value stub_pages_to_kib(value p
  13.894  }
  13.895  
  13.896  
  13.897 -CAMLprim value stub_map_foreign_range(value xc_handle, value dom,
  13.898 +CAMLprim value stub_map_foreign_range(value xch, value dom,
  13.899                                        value size, value mfn)
  13.900  {
  13.901 -	CAMLparam4(xc_handle, dom, size, mfn);
  13.902 +	CAMLparam4(xch, dom, size, mfn);
  13.903  	CAMLlocal1(result);
  13.904  	struct mmap_interface *intf;
  13.905 -	int c_xc_handle;
  13.906  	uint32_t c_dom;
  13.907  	unsigned long c_mfn;
  13.908  
  13.909 @@ -860,11 +891,10 @@ CAMLprim value stub_map_foreign_range(va
  13.910  
  13.911  	intf->len = Int_val(size);
  13.912  
  13.913 -	c_xc_handle = _H(xc_handle);
  13.914  	c_dom = _D(dom);
  13.915  	c_mfn = Nativeint_val(mfn);
  13.916  	// caml_enter_blocking_section();
  13.917 -	intf->addr = xc_map_foreign_range(c_xc_handle, c_dom,
  13.918 +	intf->addr = xc_map_foreign_range(_H(xch), c_dom,
  13.919  	                                  intf->len, PROT_READ|PROT_WRITE,
  13.920  	                                  c_mfn);
  13.921  	// caml_leave_blocking_section();
  13.922 @@ -873,18 +903,18 @@ CAMLprim value stub_map_foreign_range(va
  13.923  	CAMLreturn(result);
  13.924  }
  13.925  
  13.926 -CAMLprim value stub_sched_credit_domain_get(value xc_handle, value domid)
  13.927 +CAMLprim value stub_sched_credit_domain_get(value xch, value domid)
  13.928  {
  13.929 -	CAMLparam2(xc_handle, domid);
  13.930 +	CAMLparam2(xch, domid);
  13.931  	CAMLlocal1(sdom);
  13.932  	struct xen_domctl_sched_credit c_sdom;
  13.933  	int ret;
  13.934  
  13.935  	// caml_enter_blocking_section();
  13.936 -	ret = xc_sched_credit_domain_get(_H(xc_handle), _D(domid), &c_sdom);
  13.937 +	ret = xc_sched_credit_domain_get(_H(xch), _D(domid), &c_sdom);
  13.938  	// caml_leave_blocking_section();
  13.939  	if (ret != 0)
  13.940 -		failwith_xc();
  13.941 +		failwith_xc(_H(xch));
  13.942  
  13.943  	sdom = caml_alloc_tuple(2);
  13.944  	Store_field(sdom, 0, Val_int(c_sdom.weight));
  13.945 @@ -893,62 +923,66 @@ CAMLprim value stub_sched_credit_domain_
  13.946  	CAMLreturn(sdom);
  13.947  }
  13.948  
  13.949 -CAMLprim value stub_sched_credit_domain_set(value xc_handle, value domid,
  13.950 +CAMLprim value stub_sched_credit_domain_set(value xch, value domid,
  13.951                                              value sdom)
  13.952  {
  13.953 -	CAMLparam3(xc_handle, domid, sdom);
  13.954 +	CAMLparam3(xch, domid, sdom);
  13.955  	struct xen_domctl_sched_credit c_sdom;
  13.956  	int ret;
  13.957  
  13.958  	c_sdom.weight = Int_val(Field(sdom, 0));
  13.959  	c_sdom.cap = Int_val(Field(sdom, 1));
  13.960  	// caml_enter_blocking_section();
  13.961 -	ret = xc_sched_credit_domain_set(_H(xc_handle), _D(domid), &c_sdom);
  13.962 +	ret = xc_sched_credit_domain_set(_H(xch), _D(domid), &c_sdom);
  13.963  	// caml_leave_blocking_section();
  13.964  	if (ret != 0)
  13.965 -		failwith_xc();
  13.966 +		failwith_xc(_H(xch));
  13.967  
  13.968  	CAMLreturn(Val_unit);
  13.969  }
  13.970  
  13.971 -CAMLprim value stub_shadow_allocation_get(value xc_handle, value domid)
  13.972 +CAMLprim value stub_shadow_allocation_get(value xch, value domid)
  13.973  {
  13.974 -	CAMLparam2(xc_handle, domid);
  13.975 +	CAMLparam2(xch, domid);
  13.976  	CAMLlocal1(mb);
  13.977 -	uint32_t c_mb;
  13.978 +	unsigned long c_mb;
  13.979  	int ret;
  13.980  
  13.981  	// caml_enter_blocking_section();
  13.982 -	ret = xc_shadow_allocation_get(_H(xc_handle), _D(domid), &c_mb);
  13.983 +	ret = xc_shadow_control(_H(xch), _D(domid),
  13.984 +				XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION,
  13.985 +				NULL, 0, &c_mb, 0, NULL);
  13.986  	// caml_leave_blocking_section();
  13.987  	if (ret != 0)
  13.988 -		failwith_xc();
  13.989 +		failwith_xc(_H(xch));
  13.990  
  13.991  	mb = Val_int(c_mb);
  13.992  	CAMLreturn(mb);
  13.993  }
  13.994  
  13.995 -CAMLprim value stub_shadow_allocation_set(value xc_handle, value domid,
  13.996 +CAMLprim value stub_shadow_allocation_set(value xch, value domid,
  13.997  					  value mb)
  13.998  {
  13.999 -	CAMLparam3(xc_handle, domid, mb);
 13.1000 -	uint32_t c_mb;
 13.1001 +	CAMLparam3(xch, domid, mb);
 13.1002 +	unsigned long c_mb;
 13.1003  	int ret;
 13.1004  
 13.1005  	c_mb = Int_val(mb);
 13.1006  	// caml_enter_blocking_section();
 13.1007 -	ret = xc_shadow_allocation_set(_H(xc_handle), _D(domid), c_mb);
 13.1008 +	ret = xc_shadow_control(_H(xch), _D(domid),
 13.1009 +				XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION,
 13.1010 +				NULL, 0, &c_mb, 0, NULL);
 13.1011  	// caml_leave_blocking_section();
 13.1012  	if (ret != 0)
 13.1013 -		failwith_xc();
 13.1014 +		failwith_xc(_H(xch));
 13.1015  
 13.1016  	CAMLreturn(Val_unit);
 13.1017  }
 13.1018  
 13.1019 -CAMLprim value stub_xc_domain_get_pfn_list(value xc_handle, value domid,
 13.1020 +CAMLprim value stub_xc_domain_get_pfn_list(value xch, value domid,
 13.1021                                             value nr_pfns)
 13.1022  {
 13.1023 -	CAMLparam3(xc_handle, domid, nr_pfns);
 13.1024 +	CAMLparam3(xch, domid, nr_pfns);
 13.1025  	CAMLlocal2(array, v);
 13.1026  	unsigned long c_nr_pfns;
 13.1027  	long ret, i;
 13.1028 @@ -960,11 +994,11 @@ CAMLprim value stub_xc_domain_get_pfn_li
 13.1029  	if (!c_array)
 13.1030  		caml_raise_out_of_memory();
 13.1031  
 13.1032 -	ret = xc_domain_get_pfn_list(_H(xc_handle), _D(domid),
 13.1033 -	                             c_array, c_nr_pfns);
 13.1034 +	ret = xc_get_pfn_list(_H(xch), _D(domid),
 13.1035 +			      c_array, c_nr_pfns);
 13.1036  	if (ret < 0) {
 13.1037  		free(c_array);
 13.1038 -		failwith_xc();
 13.1039 +		failwith_xc(_H(xch));
 13.1040  	}
 13.1041  
 13.1042  	array = caml_alloc(ret, 0);
 13.1043 @@ -977,11 +1011,11 @@ CAMLprim value stub_xc_domain_get_pfn_li
 13.1044  	CAMLreturn(array);
 13.1045  }
 13.1046  
 13.1047 -CAMLprim value stub_xc_domain_ioport_permission(value xc_handle, value domid,
 13.1048 +CAMLprim value stub_xc_domain_ioport_permission(value xch, value domid,
 13.1049  					       value start_port, value nr_ports,
 13.1050  					       value allow)
 13.1051  {
 13.1052 -	CAMLparam5(xc_handle, domid, start_port, nr_ports, allow);
 13.1053 +	CAMLparam5(xch, domid, start_port, nr_ports, allow);
 13.1054  	uint32_t c_start_port, c_nr_ports;
 13.1055  	uint8_t c_allow;
 13.1056  	int ret;
 13.1057 @@ -990,19 +1024,19 @@ CAMLprim value stub_xc_domain_ioport_per
 13.1058  	c_nr_ports = Int_val(nr_ports);
 13.1059  	c_allow = Bool_val(allow);
 13.1060  
 13.1061 -	ret = xc_domain_ioport_permission(_H(xc_handle), _D(domid),
 13.1062 +	ret = xc_domain_ioport_permission(_H(xch), _D(domid),
 13.1063  					 c_start_port, c_nr_ports, c_allow);
 13.1064  	if (ret < 0)
 13.1065 -		failwith_xc();
 13.1066 +		failwith_xc(_H(xch));
 13.1067  
 13.1068  	CAMLreturn(Val_unit);
 13.1069  }
 13.1070  
 13.1071 -CAMLprim value stub_xc_domain_iomem_permission(value xc_handle, value domid,
 13.1072 +CAMLprim value stub_xc_domain_iomem_permission(value xch, value domid,
 13.1073  					       value start_pfn, value nr_pfns,
 13.1074  					       value allow)
 13.1075  {
 13.1076 -	CAMLparam5(xc_handle, domid, start_pfn, nr_pfns, allow);
 13.1077 +	CAMLparam5(xch, domid, start_pfn, nr_pfns, allow);
 13.1078  	unsigned long c_start_pfn, c_nr_pfns;
 13.1079  	uint8_t c_allow;
 13.1080  	int ret;
 13.1081 @@ -1011,18 +1045,18 @@ CAMLprim value stub_xc_domain_iomem_perm
 13.1082  	c_nr_pfns = Nativeint_val(nr_pfns);
 13.1083  	c_allow = Bool_val(allow);
 13.1084  
 13.1085 -	ret = xc_domain_iomem_permission(_H(xc_handle), _D(domid),
 13.1086 +	ret = xc_domain_iomem_permission(_H(xch), _D(domid),
 13.1087  					 c_start_pfn, c_nr_pfns, c_allow);
 13.1088  	if (ret < 0)
 13.1089 -		failwith_xc();
 13.1090 +		failwith_xc(_H(xch));
 13.1091  
 13.1092  	CAMLreturn(Val_unit);
 13.1093  }
 13.1094  
 13.1095 -CAMLprim value stub_xc_domain_irq_permission(value xc_handle, value domid,
 13.1096 +CAMLprim value stub_xc_domain_irq_permission(value xch, value domid,
 13.1097  					     value pirq, value allow)
 13.1098  {
 13.1099 -	CAMLparam4(xc_handle, domid, pirq, allow);
 13.1100 +	CAMLparam4(xch, domid, pirq, allow);
 13.1101  	uint8_t c_pirq;
 13.1102  	uint8_t c_allow;
 13.1103  	int ret;
 13.1104 @@ -1030,138 +1064,90 @@ CAMLprim value stub_xc_domain_irq_permis
 13.1105  	c_pirq = Int_val(pirq);
 13.1106  	c_allow = Bool_val(allow);
 13.1107  
 13.1108 -	ret = xc_domain_irq_permission(_H(xc_handle), _D(domid),
 13.1109 +	ret = xc_domain_irq_permission(_H(xch), _D(domid),
 13.1110  				       c_pirq, c_allow);
 13.1111  	if (ret < 0)
 13.1112 -		failwith_xc();
 13.1113 +		failwith_xc(_H(xch));
 13.1114  
 13.1115  	CAMLreturn(Val_unit);
 13.1116  }
 13.1117  
 13.1118 -CAMLprim value stub_xc_hvm_check_pvdriver(value xc_handle, value domid)
 13.1119 +static uint32_t pci_dev_to_bdf(int domain, int bus, int slot, int func)
 13.1120  {
 13.1121 -	CAMLparam2(xc_handle, domid);
 13.1122 -	int ret;
 13.1123 -
 13.1124 -	ret = xc_hvm_check_pvdriver(_H(xc_handle), _D(domid));
 13.1125 -	if (ret < 0)
 13.1126 -		failwith_xc();
 13.1127 -	CAMLreturn(Val_bool(ret));
 13.1128 +	uint32_t bdf = 0;
 13.1129 +	bdf |= (bus & 0xff) << 16;
 13.1130 +	bdf |= (slot & 0x1f) << 11;
 13.1131 +	bdf |= (func & 0x7) << 8;
 13.1132 +	return bdf;
 13.1133  }
 13.1134  
 13.1135 -CAMLprim value stub_xc_domain_test_assign_device(value xc_handle, value domid, value desc)
 13.1136 +CAMLprim value stub_xc_domain_test_assign_device(value xch, value domid, value desc)
 13.1137  {
 13.1138 -	CAMLparam3(xc_handle, domid, desc);
 13.1139 +	CAMLparam3(xch, domid, desc);
 13.1140  	int ret;
 13.1141  	int domain, bus, slot, func;
 13.1142 -
 13.1143 -	domain = Int_val(Field(desc, 0));
 13.1144 -	bus = Int_val(Field(desc, 1));
 13.1145 -	slot = Int_val(Field(desc, 2));
 13.1146 -	func = Int_val(Field(desc, 3));
 13.1147 -
 13.1148 -	ret = xc_domain_test_assign_device(_H(xc_handle), _D(domid),
 13.1149 -	                                   domain, bus, slot, func);
 13.1150 -	CAMLreturn(Val_bool(ret == 0));
 13.1151 -}
 13.1152 -
 13.1153 -CAMLprim value stub_xc_domain_assign_device(value xc_handle, value domid, value desc)
 13.1154 -{
 13.1155 -	CAMLparam3(xc_handle, domid, desc);
 13.1156 -	int ret;
 13.1157 -	int domain, bus, slot, func;
 13.1158 -
 13.1159 -	domain = Int_val(Field(desc, 0));
 13.1160 -	bus = Int_val(Field(desc, 1));
 13.1161 -	slot = Int_val(Field(desc, 2));
 13.1162 -	func = Int_val(Field(desc, 3));
 13.1163 -
 13.1164 -	ret = xc_domain_assign_device(_H(xc_handle), _D(domid),
 13.1165 -	                              domain, bus, slot, func);
 13.1166 -	if (ret < 0)
 13.1167 -		failwith_xc();
 13.1168 -	CAMLreturn(Val_unit);
 13.1169 -}
 13.1170 -
 13.1171 -CAMLprim value stub_xc_domain_deassign_device(value xc_handle, value domid, value desc)
 13.1172 -{
 13.1173 -	CAMLparam3(xc_handle, domid, desc);
 13.1174 -	int ret;
 13.1175 -	int domain, bus, slot, func;
 13.1176 +	uint32_t bdf;
 13.1177  
 13.1178  	domain = Int_val(Field(desc, 0));
 13.1179  	bus = Int_val(Field(desc, 1));
 13.1180  	slot = Int_val(Field(desc, 2));
 13.1181  	func = Int_val(Field(desc, 3));
 13.1182 +	bdf = pci_dev_to_bdf(domain, bus, slot, func);
 13.1183  
 13.1184 -	ret = xc_domain_deassign_device(_H(xc_handle), _D(domid),
 13.1185 -	                                domain, bus, slot, func);
 13.1186 -	if (ret < 0)
 13.1187 -		failwith_xc();
 13.1188 -	CAMLreturn(Val_unit);
 13.1189 +	ret = xc_test_assign_device(_H(xch), _D(domid), bdf);
 13.1190 +
 13.1191 +	CAMLreturn(Val_bool(ret == 0));
 13.1192  }
 13.1193  
 13.1194 -CAMLprim value stub_xc_domain_set_timer_mode(value handle, value id, value mode)
 13.1195 +CAMLprim value stub_xc_domain_assign_device(value xch, value domid, value desc)
 13.1196  {
 13.1197 -	CAMLparam3(handle, id, mode);
 13.1198 +	CAMLparam3(xch, domid, desc);
 13.1199  	int ret;
 13.1200 +	int domain, bus, slot, func;
 13.1201 +	uint32_t bdf;
 13.1202  
 13.1203 -	ret = xc_domain_set_timer_mode(_H(handle), _D(id), Int_val(mode));
 13.1204 +	domain = Int_val(Field(desc, 0));
 13.1205 +	bus = Int_val(Field(desc, 1));
 13.1206 +	slot = Int_val(Field(desc, 2));
 13.1207 +	func = Int_val(Field(desc, 3));
 13.1208 +	bdf = pci_dev_to_bdf(domain, bus, slot, func);
 13.1209 +
 13.1210 +	ret = xc_assign_device(_H(xch), _D(domid), bdf);
 13.1211 +
 13.1212  	if (ret < 0)
 13.1213 -		failwith_xc();
 13.1214 -	CAMLreturn(Val_unit);
 13.1215 -}
 13.1216 -
 13.1217 -CAMLprim value stub_xc_domain_set_hpet(value handle, value id, value mode)
 13.1218 -{
 13.1219 -	CAMLparam3(handle, id, mode);
 13.1220 -	int ret;
 13.1221 -
 13.1222 -	ret = xc_domain_set_hpet(_H(handle), _D(id), Int_val(mode));
 13.1223 -	if (ret < 0)
 13.1224 -		failwith_xc();
 13.1225 +		failwith_xc(_H(xch));
 13.1226  	CAMLreturn(Val_unit);
 13.1227  }
 13.1228  
 13.1229 -CAMLprim value stub_xc_domain_set_vpt_align(value handle, value id, value mode)
 13.1230 +CAMLprim value stub_xc_domain_deassign_device(value xch, value domid, value desc)
 13.1231  {
 13.1232 -	CAMLparam3(handle, id, mode);
 13.1233 +	CAMLparam3(xch, domid, desc);
 13.1234  	int ret;
 13.1235 +	int domain, bus, slot, func;
 13.1236 +	uint32_t bdf;
 13.1237  
 13.1238 -	ret = xc_domain_set_vpt_align(_H(handle), _D(id), Int_val(mode));
 13.1239 +	domain = Int_val(Field(desc, 0));
 13.1240 +	bus = Int_val(Field(desc, 1));
 13.1241 +	slot = Int_val(Field(desc, 2));
 13.1242 +	func = Int_val(Field(desc, 3));
 13.1243 +	bdf = pci_dev_to_bdf(domain, bus, slot, func);
 13.1244 +
 13.1245 +	ret = xc_deassign_device(_H(xch), _D(domid), bdf);
 13.1246 +
 13.1247  	if (ret < 0)
 13.1248 -		failwith_xc();
 13.1249 +		failwith_xc(_H(xch));
 13.1250  	CAMLreturn(Val_unit);
 13.1251  }
 13.1252  
 13.1253 -CAMLprim value stub_xc_watchdog(value handle, value domid, value timeout)
 13.1254 +CAMLprim value stub_xc_watchdog(value xch, value domid, value timeout)
 13.1255  {
 13.1256 -	CAMLparam3(handle, domid, timeout);
 13.1257 +	CAMLparam3(xch, domid, timeout);
 13.1258  	int ret;
 13.1259  	unsigned int c_timeout = Int32_val(timeout);
 13.1260  
 13.1261 -	ret = xc_domain_watchdog(_H(handle), _D(domid), c_timeout);
 13.1262 +	ret = xc_watchdog(_H(xch), _D(domid), c_timeout);
 13.1263  	if (ret < 0)
 13.1264 -		failwith_xc();
 13.1265 -
 13.1266 -	CAMLreturn(Val_int(ret));
 13.1267 -}
 13.1268 -
 13.1269 -CAMLprim value stub_xc_domain_send_s3resume(value handle, value domid)
 13.1270 -{
 13.1271 -	CAMLparam2(handle, domid);
 13.1272 -	xc_domain_send_s3resume(_H(handle), _D(domid));
 13.1273 -	CAMLreturn(Val_unit);
 13.1274 -}
 13.1275 -
 13.1276 -CAMLprim value stub_xc_domain_get_acpi_s_state(value handle, value domid)
 13.1277 -{
 13.1278 -	CAMLparam2(handle, domid);
 13.1279 -	int ret;
 13.1280 -
 13.1281 -	ret = xc_domain_get_acpi_s_state(_H(handle), _D(domid));
 13.1282 -	if (ret < 0)
 13.1283 -		failwith_xc();
 13.1284 +		failwith_xc(_H(xch));
 13.1285  
 13.1286  	CAMLreturn(Val_int(ret));
 13.1287  }
    14.1 --- a/tools/ocaml/xenstored/Makefile	Thu Jan 06 17:34:46 2011 +0000
    14.2 +++ b/tools/ocaml/xenstored/Makefile	Thu Jan 06 17:37:00 2011 +0000
    14.3 @@ -39,7 +39,8 @@ XENSTOREDLIBS = \
    14.4  	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/log $(OCAML_TOPLEVEL)/libs/log/log.cmxa \
    14.5  	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/eventchn $(OCAML_TOPLEVEL)/libs/eventchn/eventchn.cmxa \
    14.6  	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xc $(OCAML_TOPLEVEL)/libs/xc/xc.cmxa \
    14.7 -	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xb $(OCAML_TOPLEVEL)/libs/xb/xb.cmxa
    14.8 +	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xb $(OCAML_TOPLEVEL)/libs/xb/xb.cmxa \
    14.9 +	-ccopt -L -ccopt $(XEN_ROOT)/tools/libxc
   14.10  
   14.11  PROGRAMS = oxenstored
   14.12  
    15.1 --- a/tools/ocaml/xenstored/event.ml	Thu Jan 06 17:34:46 2011 +0000
    15.2 +++ b/tools/ocaml/xenstored/event.ml	Thu Jan 06 17:37:00 2011 +0000
    15.3 @@ -16,14 +16,15 @@
    15.4  
    15.5  (**************** high level binding ****************)
    15.6  type t = {
    15.7 -	fd: Unix.file_descr;
    15.8 +	handle: Eventchn.handle;
    15.9  	mutable virq_port: int;
   15.10  }
   15.11  
   15.12 -let init () = { fd = Eventchn.init (); virq_port = -1; }
   15.13 -let bind_dom_exc_virq eventchn = eventchn.virq_port <- Eventchn.bind_dom_exc_virq eventchn.fd
   15.14 -let bind_interdomain eventchn domid port = Eventchn.bind_interdomain eventchn.fd domid port
   15.15 -let unbind eventchn port = Eventchn.unbind eventchn.fd port
   15.16 -let notify eventchn port = Eventchn.notify eventchn.fd port
   15.17 -let read_port eventchn = Eventchn.read_port eventchn.fd
   15.18 -let write_port eventchn port = Eventchn.write_port eventchn.fd port
   15.19 +let init () = { handle = Eventchn.init (); virq_port = -1; }
   15.20 +let fd eventchn = Eventchn.fd eventchn.handle
   15.21 +let bind_dom_exc_virq eventchn = eventchn.virq_port <- Eventchn.bind_dom_exc_virq eventchn.handle
   15.22 +let bind_interdomain eventchn domid port = Eventchn.bind_interdomain eventchn.handle domid port
   15.23 +let unbind eventchn port = Eventchn.unbind eventchn.handle port
   15.24 +let notify eventchn port = Eventchn.notify eventchn.handle port
   15.25 +let pending eventchn = Eventchn.pending eventchn.handle
   15.26 +let unmask eventchn port = Eventchn.unmask eventchn.handle port
    16.1 --- a/tools/ocaml/xenstored/xenstored.ml	Thu Jan 06 17:34:46 2011 +0000
    16.2 +++ b/tools/ocaml/xenstored/xenstored.ml	Thu Jan 06 17:37:00 2011 +0000
    16.3 @@ -282,7 +282,7 @@ let _ =
    16.4  			Store.mkdir store (Perms.Connection.create 0) localpath;
    16.5  
    16.6  		if cf.domain_init then (
    16.7 -			let usingxiu = Xc.using_injection () in
    16.8 +			let usingxiu = Xc.is_fake () in
    16.9  			Connections.add_domain cons (Domains.create0 usingxiu domains);
   16.10  			Event.bind_dom_exc_virq eventchn
   16.11  		);
   16.12 @@ -298,7 +298,7 @@ let _ =
   16.13  	let spec_fds =
   16.14  		(match rw_sock with None -> [] | Some x -> [ x ]) @
   16.15  		(match ro_sock with None -> [] | Some x -> [ x ]) @
   16.16 -		(if cf.domain_init then [ eventchn.Event.fd ] else [])
   16.17 +		(if cf.domain_init then [ Event.fd eventchn ] else [])
   16.18  		in
   16.19  
   16.20  	let xc = Xc.interface_open () in
   16.21 @@ -309,7 +309,7 @@ let _ =
   16.22  			debug "new connection through socket";
   16.23  			Connections.add_anonymous cons cfd can_write
   16.24  		and handle_eventchn fd =
   16.25 -			let port = Event.read_port eventchn in
   16.26 +			let port = Event.pending eventchn in
   16.27  			finally (fun () ->
   16.28  				if port = eventchn.Event.virq_port then (
   16.29  					let (notify, deaddom) = Domains.cleanup xc domains in
   16.30 @@ -317,14 +317,14 @@ let _ =
   16.31  					if deaddom <> [] || notify then
   16.32  						Connections.fire_spec_watches cons "@releaseDomain"
   16.33  				)
   16.34 -			) (fun () -> Event.write_port eventchn port);
   16.35 +			) (fun () -> Event.unmask eventchn port);
   16.36  		and do_if_set fd set fct =
   16.37  			if List.mem fd set then
   16.38  				fct fd in
   16.39  
   16.40  		maybe (fun fd -> do_if_set fd rset (accept_connection true)) rw_sock;
   16.41  		maybe (fun fd -> do_if_set fd rset (accept_connection false)) ro_sock;
   16.42 -		do_if_set eventchn.Event.fd rset (handle_eventchn)
   16.43 +		do_if_set (Event.fd eventchn) rset (handle_eventchn)
   16.44  		in
   16.45  
   16.46  	let last_stat_time = ref 0. in