interface_close xc;
r
-external _domain_create: handle -> int32 -> domain_create_flag list -> int array -> arch_domainconfig -> domid
+external domain_create: handle -> int32 -> domain_create_flag list -> string -> arch_domainconfig -> domid
= "stub_xc_domain_create"
-let int_array_of_uuid_string s =
- try
- Scanf.sscanf s
- "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
- (fun a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 ->
- [| a0; a1; a2; a3; a4; a5; a6; a7;
- a8; a9; a10; a11; a12; a13; a14; a15 |])
- with _ -> invalid_arg ("Xc.int_array_of_uuid_string: " ^ s)
-
-let domain_create handle n flags uuid =
- _domain_create handle n flags (int_array_of_uuid_string uuid)
-
-external _domain_sethandle: handle -> domid -> int array -> unit
- = "stub_xc_domain_sethandle"
-
-let domain_sethandle handle n uuid =
- _domain_sethandle handle n (int_array_of_uuid_string uuid)
+external domain_sethandle: handle -> domid -> string -> unit
+ = "stub_xc_domain_sethandle"
external domain_max_vcpus: handle -> domid -> int -> unit
= "stub_xc_domain_max_vcpus"
external interface_open : unit -> handle = "stub_xc_interface_open"
external interface_close : handle -> unit = "stub_xc_interface_close"
val with_intf : (handle -> 'a) -> 'a
-val domain_create : handle -> int32 -> domain_create_flag list -> string -> arch_domainconfig -> domid
-val domain_sethandle : handle -> domid -> string -> unit
+external domain_create : handle -> int32 -> domain_create_flag list -> string -> arch_domainconfig -> domid
+ = "stub_xc_domain_create"
+external domain_sethandle : handle -> domid -> string -> unit = "stub_xc_domain_sethandle"
external domain_max_vcpus : handle -> domid -> int -> unit
= "stub_xc_domain_max_vcpus"
external domain_pause : handle -> domid -> unit = "stub_xc_domain_pause"
#include <sys/mman.h>
#include <stdint.h>
#include <string.h>
+#include <inttypes.h>
#define XC_WANT_COMPAT_MAP_FOREIGN_API
#include <xenctrl.h>
CAMLreturn(Val_unit);
}
+static void domain_handle_of_uuid_string(xen_domain_handle_t h,
+ const char *uuid)
+{
+#define X "%02"SCNx8
+#define UUID_FMT (X X X X "-" X X "-" X X "-" X X "-" X X X X X X)
+
+ if ( sscanf(uuid, UUID_FMT, &h[0], &h[1], &h[2], &h[3], &h[4],
+ &h[5], &h[6], &h[7], &h[8], &h[9], &h[10], &h[11],
+ &h[12], &h[13], &h[14], &h[15]) != 16 )
+ {
+ char buf[128];
+
+ snprintf(buf, sizeof(buf),
+ "Xc.int_array_of_uuid_string: %s", uuid);
+
+ caml_invalid_argument(buf);
+ }
+
+#undef X
+}
+
CAMLprim value stub_xc_domain_create(value xch, value ssidref,
value flags, value handle,
value domconfig)
CAMLparam4(xch, ssidref, flags, handle);
uint32_t domid = 0;
- xen_domain_handle_t h = { 0 };
+ xen_domain_handle_t h;
int result;
- int i;
uint32_t c_ssidref = Int32_val(ssidref);
unsigned int c_flags = 0;
value l;
xc_domain_configuration_t config = {};
- if (Wosize_val(handle) != 16)
- caml_invalid_argument("Handle not a 16-integer array");
-
- for (i = 0; i < sizeof(h); i++) {
- h[i] = Int_val(Field(handle, i)) & 0xff;
- }
+ domain_handle_of_uuid_string(h, String_val(handle));
for (l = flags; l != Val_none; l = Field(l, 1))
c_flags |= 1u << Int_val(Field(l, 0));
value stub_xc_domain_sethandle(value xch, value domid, value handle)
{
CAMLparam3(xch, domid, handle);
- xen_domain_handle_t h = { 0 };
+ xen_domain_handle_t h;
int i;
- if (Wosize_val(handle) != 16)
- caml_invalid_argument("Handle not a 16-integer array");
-
- for (i = 0; i < sizeof(h); i++) {
- h[i] = Int_val(Field(handle, i)) & 0xff;
- }
+ domain_handle_of_uuid_string(h, String_val(handle));
i = xc_domain_sethandle(_H(xch), _D(domid), h);
if (i)