From nobody Wed Nov 13 07:19:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1675200601; cv=none; d=zohomail.com; s=zohoarc; b=iPfbruZRnI/zd093A4bDAQUTMvkUhH7vN9HdPk0/i32Cy03Iy3sC3XptIxyzDPAKQA/nFTNwQslFSOpSRTnuJEfl8Fqn5biU0FK75RZFhLse/+rLLZ4wy7617xXx7uvX+YCGE9oDt1+xsKHOHwg52R5fNe4LC/v/j1wpSf8eqb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675200601; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GJgGl/n8kVPBQafhcBQAxx1GIxT0M3Nh4gvH+y0Vrpw=; b=ZHnK/sNP5rY4lClu8zBY4xiZD6JQzXYhPuGu+YuE012wsr8c+hWY/FkVWmtpNm8zQvUyA/Ni81cCqKe9aT6uXIgjzrRqSUj6nzjQye+Hm6HDwFDhSkNdBOCgMpd/ryxaP5YEnvHMzXRUxN+nMSBj+3HHsd1iphALJWlfOKGOTPw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 167520060192812.480629982920163; Tue, 31 Jan 2023 13:30:01 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.487848.755601 (Exim 4.92) (envelope-from ) id 1pMyC7-0001NM-EG; Tue, 31 Jan 2023 21:29:35 +0000 Received: by outflank-mailman (output) from mailman id 487848.755601; Tue, 31 Jan 2023 21:29:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMyC7-0001NA-9y; Tue, 31 Jan 2023 21:29:35 +0000 Received: by outflank-mailman (input) for mailman id 487848; Tue, 31 Jan 2023 21:29:33 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMyC4-0000Nm-Ku for xen-devel@lists.xenproject.org; Tue, 31 Jan 2023 21:29:33 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5645ffb5-a1ae-11ed-b63b-5f92e7d2e73a; Tue, 31 Jan 2023 22:29:27 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5645ffb5-a1ae-11ed-b63b-5f92e7d2e73a DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1675200567; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tJ4tTGgnhHKyde+wF8qU4LPiC92eyP3hCl2+Pked3dE=; b=h0RIaL/CLB2RtKjhN19reXDuj+bnJZI4CkqtOSzxdvot/NfOX9gbYNeq LHjrL/ZM75xHvyaBL7giR6WQk9kQC8YRhZ2bELP3EHGJVE6KsZ7dzjKEM OhR+Rffut5fpnwEilSmol6HdB32rbB36TXdH0E+Z7d3jG1brKmKKcd9a1 s=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 95097287 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:rLtUSq9AKfsAhmGvWTVPDrUDgX6TJUtcMsCJ2f8bNWPcYEJGY0x3x jAZXG3TbP2MNzajedp3Ydvn8UNS6JKEmoRgTQFsqyo8E34SpcT7XtnIdU2Y0wF+jCHgZBk+s 5hBMImowOQcFCK0SsKFa+C5xZVE/fjUAOG6UKucYHsZqTZMEE8JkQhkl/MynrlmiN24BxLlk d7pqojUNUTNNwRcawr40Ire7kIw1BjOkGlA5AdmPKsS5AS2e0Q9V/rzG4ngdxMUfaEMdgKKb 76r5K20+Grf4yAsBruN+losWhRXKlJ6FVHmZkt+A8BOsDAbzsAB+v9T2M4nQVVWk120c+VZk 72hg3ASpTABZcUgkMxFO/VR/roX0aduoNcrKlDn2SCfItGvn9IBDJyCAWlvVbD09NqbDklz2 acxGmAiciucrMvn3rPiE+RQlpkaeZyD0IM34hmMzBncBPciB5vCX7/L9ZlT2zJYasJmRKiEI ZBDMHw2MUqGOkcUUrsUIMtWcOOAr3/zaTBH7nmSorI6+TP7xw1tyrn9dtHSf7RmQO0Ewx7J+ TiWoAwVBDlBKYyHxBG3wEmK3MPdlATpWqkIBIWRo6sCbFq7mTVIVUx+uUGAifWwlEOWQd9UL E0QvC00osAa5EGtC9XwQRC8iHqFpQIHHcpdFfUg7wOAwbaS5ByWblXoVRYYNoZg7pVvA2V3i BnQxYiB6SFTXKO9dF7G34XEgi+JJgM8fHEDPHYJcRtY2oy2yG0stS7nQtFmGa+zq9T6HzDs3 jyHxBQDa6UvYd0jjPviow2e6964jt2QF1NuuF2LNo6wxlkhDLNJcbBE/rQyARxoCI+CBmeMs 3Ef8yR1xLBfVMrd/MBhrQhkIV1I2xpnGGeE6bKMN8N7n9hIx5JEVd443d2GDB01WvvogBewC KMphStf5YVIIFyhZrJtboS6BqwClPa/SI20DqiMM4AUPfCdkTNrGwk3NSatM53FyhBwwcnTx 7/EGSpTMZrqIfs+l2fnLwvs+bQq2jo/1QvuqWPTlnyaPU6lTCfNE98taQLeBt3VGYvY+G05B f4DbZrVo/ieOcWiChTqHXk7dglWcyNkWMys+6S6tIere2JbJY3oMNeJqZtJRmCvt/49ejvgl p1lZnJl9Q== IronPort-HdrOrdr: A9a23:Mzq3j6hycse6p0DbZoBFeMqRMnBQXuUji2hC6mlwRA09TyVXrb HWoB17726NtN91YhsdcL+7Scy9qB/nhPxICMwqTNSftWrd2VdATrsSibcKqgeIc0bDH6xmtZ uIGJIOb+EYY2IK6/oSIzPVLz/j+rS6GWyT6ts2Bk0CcT1X X-IronPort-AV: E=Sophos;i="5.97,261,1669093200"; d="scan'208";a="95097287" From: Andrew Cooper To: Xen-devel CC: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , "Christian Lindig" , David Scott , Rob Hoes Subject: [PATCH 7/7] tools/ocaml/xc: Don't reference Custom objects with the GC lock released Date: Tue, 31 Jan 2023 21:29:13 +0000 Message-ID: <20230131212913.6199-8-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20230131212913.6199-1-andrew.cooper3@citrix.com> References: <20230131212913.6199-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1675200603650100011 From: Edwin T=C3=B6r=C3=B6k The modification to the _H() macro for Ocaml 5 support introduced a subtle bug. From the manual: https://ocaml.org/manual/intfc.html#ss:parallel-execution-long-running-c-= code "After caml_release_runtime_system() was called and until caml_acquire_runtime_system() is called, the C code must not access any OCa= ml data, nor call any function of the run-time system, nor call back into OCaml code." Previously, the value was a naked C pointer, so dereferencing it wasn't "accessing any Ocaml data", but the fix to avoid naked C pointers added a layer of indirection through an Ocaml Custom object, meaning that the common pattern of using _H() in a blocking section is unsafe. In order to fix: * Drop the _H() macro and replace it with a static inline xch_of_val(). * Opencode the assignment into Data_custom_val() in the constructors. * Rename "value xch" parameters to "value xch_val" so we can consistently have "xc_interface *xch" on the stack, and obtain the pointer with the GC lock still held. * Drop the _D() macro while at it, because it's just pointless indirection. Fixes: 8b3c06a3e545 ("tools/ocaml/xenctrl: OCaml 5 support, fix use-after-f= ree") Signed-off-by: Edwin T=C3=B6r=C3=B6k --- CC: Christian Lindig CC: David Scott CC: Edwin T=C3=B6r=C3=B6k CC: Rob Hoes --- tools/ocaml/libs/xc/xenctrl_stubs.c | 454 ++++++++++++++++++++------------= ---- 1 file changed, 251 insertions(+), 203 deletions(-) diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index e5277f6f19a2..f9006c662382 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -37,9 +37,6 @@ =20 #include "mmap_stubs.h" =20 -#define _H(__h) (*((xc_interface **)Data_custom_val(__h))) -#define _D(__d) ((uint32_t)Int_val(__d)) - #ifndef Val_none #define Val_none (Val_int(0)) #endif @@ -48,9 +45,18 @@ #define Tag_some 0 #endif =20 +static inline xc_interface *xch_of_val(value v) +{ + xc_interface *xch =3D *(xc_interface **)Data_custom_val(v); + + return xch; +} + static void stub_xenctrl_finalize(value v) { - xc_interface_close(_H(v)); + xc_interface *xch =3D xch_of_val(v); + + xc_interface_close(xch); } =20 static struct custom_operations xenctrl_ops =3D { @@ -100,7 +106,7 @@ CAMLprim value stub_xc_interface_open(value unit) failwith_xc(xch); =20 result =3D caml_alloc_custom(&xenctrl_ops, sizeof(xch), 0, 1); - _H(result) =3D xch; + *(xc_interface **)Data_custom_val(result) =3D xch; =20 CAMLreturn(result); } @@ -187,10 +193,11 @@ static unsigned int ocaml_list_to_c_bitmap(value l) return val; } =20 -CAMLprim value stub_xc_domain_create(value xch, value wanted_domid, value = config) +CAMLprim value stub_xc_domain_create(value xch_val, value wanted_domid, va= lue config) { - CAMLparam3(xch, wanted_domid, config); + CAMLparam3(xch_val, wanted_domid, config); CAMLlocal2(l, arch_domconfig); + xc_interface *xch =3D xch_of_val(xch_val); =20 /* Mnemonics for the named fields inside domctl_create_config */ #define VAL_SSIDREF Field(config, 0) @@ -282,98 +289,104 @@ CAMLprim value stub_xc_domain_create(value xch, valu= e wanted_domid, value config #undef VAL_SSIDREF =20 caml_enter_blocking_section(); - result =3D xc_domain_create(_H(xch), &domid, &cfg); + result =3D xc_domain_create(xch, &domid, &cfg); caml_leave_blocking_section(); =20 if (result < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_int(domid)); } =20 -CAMLprim value stub_xc_domain_max_vcpus(value xch, value domid, +CAMLprim value stub_xc_domain_max_vcpus(value xch_val, value domid, value max_vcpus) { - CAMLparam3(xch, domid, max_vcpus); + CAMLparam3(xch_val, domid, max_vcpus); + xc_interface *xch =3D xch_of_val(xch_val); int r; =20 - r =3D xc_domain_max_vcpus(_H(xch), _D(domid), Int_val(max_vcpus)); + r =3D xc_domain_max_vcpus(xch, Int_val(domid), Int_val(max_vcpus)); if (r) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 =20 -value stub_xc_domain_sethandle(value xch, value domid, value handle) +value stub_xc_domain_sethandle(value xch_val, value domid, value handle) { - CAMLparam3(xch, domid, handle); + CAMLparam3(xch_val, domid, handle); + xc_interface *xch =3D xch_of_val(xch_val); xen_domain_handle_t h; int i; =20 domain_handle_of_uuid_string(h, String_val(handle)); =20 - i =3D xc_domain_sethandle(_H(xch), _D(domid), h); + i =3D xc_domain_sethandle(xch, Int_val(domid), h); if (i) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 -static value dom_op(value xch, value domid, int (*fn)(xc_interface *, uint= 32_t)) +static value dom_op(value xch_val, value domid, + int (*fn)(xc_interface *, uint32_t)) { - CAMLparam2(xch, domid); + CAMLparam2(xch_val, domid); + xc_interface *xch =3D xch_of_val(xch_val); int result; =20 - uint32_t c_domid =3D _D(domid); + uint32_t c_domid =3D Int_val(domid); =20 caml_enter_blocking_section(); - result =3D fn(_H(xch), c_domid); + result =3D fn(xch, c_domid); caml_leave_blocking_section(); if (result) - failwith_xc(_H(xch)); + failwith_xc(xch); CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_pause(value xch, value domid) +CAMLprim value stub_xc_domain_pause(value xch_val, value domid) { - return dom_op(xch, domid, xc_domain_pause); + return dom_op(xch_val, domid, xc_domain_pause); } =20 =20 -CAMLprim value stub_xc_domain_unpause(value xch, value domid) +CAMLprim value stub_xc_domain_unpause(value xch_val, value domid) { - return dom_op(xch, domid, xc_domain_unpause); + return dom_op(xch_val, domid, xc_domain_unpause); } =20 -CAMLprim value stub_xc_domain_destroy(value xch, value domid) +CAMLprim value stub_xc_domain_destroy(value xch_val, value domid) { - return dom_op(xch, domid, xc_domain_destroy); + return dom_op(xch_val, domid, xc_domain_destroy); } =20 -CAMLprim value stub_xc_domain_resume_fast(value xch, value domid) +CAMLprim value stub_xc_domain_resume_fast(value xch_val, value domid) { - CAMLparam2(xch, domid); + CAMLparam2(xch_val, domid); + xc_interface *xch =3D xch_of_val(xch_val); int result; =20 - uint32_t c_domid =3D _D(domid); + uint32_t c_domid =3D Int_val(domid); =20 caml_enter_blocking_section(); - result =3D xc_domain_resume(_H(xch), c_domid, 1); + result =3D xc_domain_resume(xch, c_domid, 1); caml_leave_blocking_section(); if (result) - failwith_xc(_H(xch)); + failwith_xc(xch); CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_shutdown(value xch, value domid, value reaso= n) +CAMLprim value stub_xc_domain_shutdown(value xch_val, value domid, value r= eason) { - CAMLparam3(xch, domid, reason); + CAMLparam3(xch_val, domid, reason); + xc_interface *xch =3D xch_of_val(xch_val); int ret; =20 - ret =3D xc_domain_shutdown(_H(xch), _D(domid), Int_val(reason)); + ret =3D xc_domain_shutdown(xch, Int_val(domid), Int_val(reason)); if (ret < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } @@ -433,10 +446,11 @@ static value alloc_domaininfo(xc_domaininfo_t * info) CAMLreturn(result); } =20 -CAMLprim value stub_xc_domain_getinfolist(value xch, value first_domain, v= alue nb) +CAMLprim value stub_xc_domain_getinfolist(value xch_val, value first_domai= n, value nb) { - CAMLparam3(xch, first_domain, nb); + CAMLparam3(xch_val, first_domain, nb); CAMLlocal2(result, temp); + xc_interface *xch =3D xch_of_val(xch_val); xc_domaininfo_t * info; int i, ret, toalloc, retval; unsigned int c_max_domains; @@ -450,16 +464,16 @@ CAMLprim value stub_xc_domain_getinfolist(value xch, = value first_domain, value n =20 result =3D temp =3D Val_emptylist; =20 - c_first_domain =3D _D(first_domain); + c_first_domain =3D Int_val(first_domain); c_max_domains =3D Int_val(nb); caml_enter_blocking_section(); - retval =3D xc_domain_getinfolist(_H(xch), c_first_domain, + retval =3D xc_domain_getinfolist(xch, c_first_domain, c_max_domains, info); caml_leave_blocking_section(); =20 if (retval < 0) { free(info); - failwith_xc(_H(xch)); + failwith_xc(xch); } for (i =3D 0; i < retval; i++) { result =3D caml_alloc_small(2, Tag_cons); @@ -474,38 +488,39 @@ CAMLprim value stub_xc_domain_getinfolist(value xch, = value first_domain, value n CAMLreturn(result); } =20 -CAMLprim value stub_xc_domain_getinfo(value xch, value domid) +CAMLprim value stub_xc_domain_getinfo(value xch_val, value domid) { - CAMLparam2(xch, domid); + CAMLparam2(xch_val, domid); CAMLlocal1(result); + xc_interface *xch =3D xch_of_val(xch_val); xc_domaininfo_t info; int ret; =20 - ret =3D xc_domain_getinfolist(_H(xch), _D(domid), 1, &info); + ret =3D xc_domain_getinfolist(xch, Int_val(domid), 1, &info); if (ret !=3D 1) - failwith_xc(_H(xch)); - if (info.domain !=3D _D(domid)) - failwith_xc(_H(xch)); + failwith_xc(xch); + if (info.domain !=3D Int_val(domid)) + failwith_xc(xch); =20 result =3D alloc_domaininfo(&info); CAMLreturn(result); } =20 -CAMLprim value stub_xc_vcpu_getinfo(value xch, value domid, value vcpu) +CAMLprim value stub_xc_vcpu_getinfo(value xch_val, value domid, value vcpu) { - CAMLparam3(xch, domid, vcpu); + CAMLparam3(xch_val, domid, vcpu); CAMLlocal1(result); + xc_interface *xch =3D xch_of_val(xch_val); xc_vcpuinfo_t info; int retval; =20 - uint32_t c_domid =3D _D(domid); + uint32_t c_domid =3D Int_val(domid); uint32_t c_vcpu =3D Int_val(vcpu); caml_enter_blocking_section(); - retval =3D xc_vcpu_getinfo(_H(xch), c_domid, - c_vcpu, &info); + retval =3D xc_vcpu_getinfo(xch, c_domid, c_vcpu, &info); caml_leave_blocking_section(); if (retval < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 result =3D caml_alloc_tuple(5); Store_field(result, 0, Val_bool(info.online)); @@ -517,17 +532,18 @@ CAMLprim value stub_xc_vcpu_getinfo(value xch, value = domid, value vcpu) CAMLreturn(result); } =20 -CAMLprim value stub_xc_vcpu_context_get(value xch, value domid, +CAMLprim value stub_xc_vcpu_context_get(value xch_val, value domid, value cpu) { - CAMLparam3(xch, domid, cpu); + CAMLparam3(xch_val, domid, cpu); + xc_interface *xch =3D xch_of_val(xch_val); CAMLlocal1(context); int ret; vcpu_guest_context_any_t ctxt; =20 - ret =3D xc_vcpu_getcontext(_H(xch), _D(domid), Int_val(cpu), &ctxt); + ret =3D xc_vcpu_getcontext(xch, Int_val(domid), Int_val(cpu), &ctxt); if ( ret < 0 ) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 context =3D caml_alloc_string(sizeof(ctxt)); memcpy((char *) String_val(context), &ctxt.c, sizeof(ctxt.c)); @@ -535,10 +551,10 @@ CAMLprim value stub_xc_vcpu_context_get(value xch, va= lue domid, CAMLreturn(context); } =20 -static int get_cpumap_len(value xch, value cpumap) +static int get_cpumap_len(xc_interface *xch, value cpumap) { int ml_len =3D Wosize_val(cpumap); - int xc_len =3D xc_get_max_cpus(_H(xch)); + int xc_len =3D xc_get_max_cpus(xch); =20 if (ml_len < xc_len) return ml_len; @@ -546,56 +562,58 @@ static int get_cpumap_len(value xch, value cpumap) return xc_len; } =20 -CAMLprim value stub_xc_vcpu_setaffinity(value xch, value domid, +CAMLprim value stub_xc_vcpu_setaffinity(value xch_val, value domid, value vcpu, value cpumap) { - CAMLparam4(xch, domid, vcpu, cpumap); + CAMLparam4(xch_val, domid, vcpu, cpumap); + xc_interface *xch =3D xch_of_val(xch_val); int i, len =3D get_cpumap_len(xch, cpumap); xc_cpumap_t c_cpumap; int retval; =20 - c_cpumap =3D xc_cpumap_alloc(_H(xch)); + c_cpumap =3D xc_cpumap_alloc(xch); if (c_cpumap =3D=3D NULL) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 for (i=3D0; i=3D 0) { @@ -755,7 +779,7 @@ CAMLprim value stub_xc_readconsolering(value xch) count =3D size - count; =20 caml_enter_blocking_section(); - ret =3D xc_readconsolering(_H(xch), str, &count, 0, 1, &index); + ret =3D xc_readconsolering(xch, str, &count, 0, 1, &index); caml_leave_blocking_section(); =20 count +=3D str - ptr; @@ -777,30 +801,32 @@ CAMLprim value stub_xc_readconsolering(value xch) CAMLreturn(ring); } =20 -CAMLprim value stub_xc_send_debug_keys(value xch, value keys) +CAMLprim value stub_xc_send_debug_keys(value xch_val, value keys) { - CAMLparam2(xch, keys); + CAMLparam2(xch_val, keys); + xc_interface *xch =3D xch_of_val(xch_val); int r; =20 - r =3D xc_send_debug_keys(_H(xch), String_val(keys)); + r =3D xc_send_debug_keys(xch, String_val(keys)); if (r) - failwith_xc(_H(xch)); + failwith_xc(xch); CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_physinfo(value xch) +CAMLprim value stub_xc_physinfo(value xch_val) { - CAMLparam1(xch); + CAMLparam1(xch_val); CAMLlocal4(physinfo, cap_list, arch_cap_flags, arch_cap_list); + xc_interface *xch =3D xch_of_val(xch_val); xc_physinfo_t c_physinfo; int r, arch_cap_flags_tag; =20 caml_enter_blocking_section(); - r =3D xc_physinfo(_H(xch), &c_physinfo); + r =3D xc_physinfo(xch, &c_physinfo); caml_leave_blocking_section(); =20 if (r) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 /* * capabilities: physinfo_cap_flag list; @@ -837,10 +863,11 @@ CAMLprim value stub_xc_physinfo(value xch) CAMLreturn(physinfo); } =20 -CAMLprim value stub_xc_pcpu_info(value xch, value nr_cpus) +CAMLprim value stub_xc_pcpu_info(value xch_val, value nr_cpus) { - CAMLparam2(xch, nr_cpus); + CAMLparam2(xch_val, nr_cpus); CAMLlocal2(pcpus, v); + xc_interface *xch =3D xch_of_val(xch_val); xc_cpuinfo_t *info; int r, size; =20 @@ -852,12 +879,12 @@ CAMLprim value stub_xc_pcpu_info(value xch, value nr_= cpus) caml_raise_out_of_memory(); =20 caml_enter_blocking_section(); - r =3D xc_getcpuinfo(_H(xch), Int_val(nr_cpus), info, &size); + r =3D xc_getcpuinfo(xch, Int_val(nr_cpus), info, &size); caml_leave_blocking_section(); =20 if (r) { free(info); - failwith_xc(_H(xch)); + failwith_xc(xch); } =20 if (size > 0) { @@ -873,79 +900,82 @@ CAMLprim value stub_xc_pcpu_info(value xch, value nr_= cpus) CAMLreturn(pcpus); } =20 -CAMLprim value stub_xc_domain_setmaxmem(value xch, value domid, +CAMLprim value stub_xc_domain_setmaxmem(value xch_val, value domid, value max_memkb) { - CAMLparam3(xch, domid, max_memkb); + CAMLparam3(xch_val, domid, max_memkb); + xc_interface *xch =3D xch_of_val(xch_val); int retval; =20 - uint32_t c_domid =3D _D(domid); + uint32_t c_domid =3D Int_val(domid); unsigned int c_max_memkb =3D Int64_val(max_memkb); caml_enter_blocking_section(); - retval =3D xc_domain_setmaxmem(_H(xch), c_domid, - c_max_memkb); + retval =3D xc_domain_setmaxmem(xch, c_domid, c_max_memkb); caml_leave_blocking_section(); if (retval) - failwith_xc(_H(xch)); + failwith_xc(xch); CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_set_memmap_limit(value xch, value domid, +CAMLprim value stub_xc_domain_set_memmap_limit(value xch_val, value domid, value map_limitkb) { - CAMLparam3(xch, domid, map_limitkb); + CAMLparam3(xch_val, domid, map_limitkb); + xc_interface *xch =3D xch_of_val(xch_val); unsigned long v; int retval; =20 v =3D Int64_val(map_limitkb); - retval =3D xc_domain_set_memmap_limit(_H(xch), _D(domid), v); + retval =3D xc_domain_set_memmap_limit(xch, Int_val(domid), v); if (retval) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_memory_increase_reservation(value xch, +CAMLprim value stub_xc_domain_memory_increase_reservation(value xch_val, value domid, value mem_kb) { - CAMLparam3(xch, domid, mem_kb); + CAMLparam3(xch_val, domid, mem_kb); + xc_interface *xch =3D xch_of_val(xch_val); int retval; =20 unsigned long nr_extents =3D ((unsigned long)(Int64_val(mem_kb))) >> (XC_= PAGE_SHIFT - 10); =20 - uint32_t c_domid =3D _D(domid); + uint32_t c_domid =3D Int_val(domid); caml_enter_blocking_section(); - retval =3D xc_domain_increase_reservation_exact(_H(xch), c_domid, + retval =3D xc_domain_increase_reservation_exact(xch, c_domid, nr_extents, 0, 0, NULL); caml_leave_blocking_section(); =20 if (retval) - failwith_xc(_H(xch)); + failwith_xc(xch); CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_version_version(value xch) +CAMLprim value stub_xc_version_version(value xch_val) { - CAMLparam1(xch); + CAMLparam1(xch_val); CAMLlocal1(result); + xc_interface *xch =3D xch_of_val(xch_val); xen_extraversion_t extra; long packed; int retval; =20 caml_enter_blocking_section(); - packed =3D xc_version(_H(xch), XENVER_version, NULL); + packed =3D xc_version(xch, XENVER_version, NULL); caml_leave_blocking_section(); =20 if (packed < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 caml_enter_blocking_section(); - retval =3D xc_version(_H(xch), XENVER_extraversion, &extra); + retval =3D xc_version(xch, XENVER_extraversion, &extra); caml_leave_blocking_section(); =20 if (retval) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 result =3D caml_alloc_tuple(3); =20 @@ -957,19 +987,20 @@ CAMLprim value stub_xc_version_version(value xch) } =20 =20 -CAMLprim value stub_xc_version_compile_info(value xch) +CAMLprim value stub_xc_version_compile_info(value xch_val) { - CAMLparam1(xch); + CAMLparam1(xch_val); CAMLlocal1(result); + xc_interface *xch =3D xch_of_val(xch_val); xen_compile_info_t ci; int retval; =20 caml_enter_blocking_section(); - retval =3D xc_version(_H(xch), XENVER_compile_info, &ci); + retval =3D xc_version(xch, XENVER_compile_info, &ci); caml_leave_blocking_section(); =20 if (retval) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 result =3D caml_alloc_tuple(4); =20 @@ -982,35 +1013,36 @@ CAMLprim value stub_xc_version_compile_info(value xc= h) } =20 =20 -static value xc_version_single_string(value xch, int code, void *info) +static value xc_version_single_string(value xch_val, int code, void *info) { - CAMLparam1(xch); + CAMLparam1(xch_val); + xc_interface *xch =3D xch_of_val(xch_val); int retval; =20 caml_enter_blocking_section(); - retval =3D xc_version(_H(xch), code, info); + retval =3D xc_version(xch, code, info); caml_leave_blocking_section(); =20 if (retval) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(caml_copy_string((char *)info)); } =20 =20 -CAMLprim value stub_xc_version_changeset(value xch) +CAMLprim value stub_xc_version_changeset(value xch_val) { xen_changeset_info_t ci; =20 - return xc_version_single_string(xch, XENVER_changeset, &ci); + return xc_version_single_string(xch_val, XENVER_changeset, &ci); } =20 =20 -CAMLprim value stub_xc_version_capabilities(value xch) +CAMLprim value stub_xc_version_capabilities(value xch_val) { xen_capabilities_info_t ci; =20 - return xc_version_single_string(xch, XENVER_capabilities, &ci); + return xc_version_single_string(xch_val, XENVER_capabilities, &ci); } =20 =20 @@ -1022,11 +1054,12 @@ CAMLprim value stub_pages_to_kib(value pages) } =20 =20 -CAMLprim value stub_map_foreign_range(value xch, value dom, +CAMLprim value stub_map_foreign_range(value xch_val, value dom, value size, value mfn) { - CAMLparam4(xch, dom, size, mfn); + CAMLparam4(xch_val, dom, size, mfn); CAMLlocal1(result); + xc_interface *xch =3D xch_of_val(xch_val); struct mmap_interface *intf; unsigned long c_mfn =3D Nativeint_val(mfn); int len =3D Int_val(size); @@ -1037,7 +1070,7 @@ CAMLprim value stub_map_foreign_range(value xch, valu= e dom, Abstract_tag); =20 caml_enter_blocking_section(); - ptr =3D xc_map_foreign_range(_H(xch), _D(dom), len, + ptr =3D xc_map_foreign_range(xch, Int_val(dom), len, PROT_READ|PROT_WRITE, c_mfn); caml_leave_blocking_section(); =20 @@ -1050,18 +1083,19 @@ CAMLprim value stub_map_foreign_range(value xch, va= lue dom, CAMLreturn(result); } =20 -CAMLprim value stub_sched_credit_domain_get(value xch, value domid) +CAMLprim value stub_sched_credit_domain_get(value xch_val, value domid) { - CAMLparam2(xch, domid); + CAMLparam2(xch_val, domid); CAMLlocal1(sdom); + xc_interface *xch =3D xch_of_val(xch_val); struct xen_domctl_sched_credit c_sdom; int ret; =20 caml_enter_blocking_section(); - ret =3D xc_sched_credit_domain_get(_H(xch), _D(domid), &c_sdom); + ret =3D xc_sched_credit_domain_get(xch, Int_val(domid), &c_sdom); caml_leave_blocking_section(); if (ret !=3D 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 sdom =3D caml_alloc_tuple(2); Store_field(sdom, 0, Val_int(c_sdom.weight)); @@ -1070,67 +1104,71 @@ CAMLprim value stub_sched_credit_domain_get(value x= ch, value domid) CAMLreturn(sdom); } =20 -CAMLprim value stub_sched_credit_domain_set(value xch, value domid, +CAMLprim value stub_sched_credit_domain_set(value xch_val, value domid, value sdom) { - CAMLparam3(xch, domid, sdom); + CAMLparam3(xch_val, domid, sdom); + xc_interface *xch =3D xch_of_val(xch_val); struct xen_domctl_sched_credit c_sdom; int ret; =20 c_sdom.weight =3D Int_val(Field(sdom, 0)); c_sdom.cap =3D Int_val(Field(sdom, 1)); caml_enter_blocking_section(); - ret =3D xc_sched_credit_domain_set(_H(xch), _D(domid), &c_sdom); + ret =3D xc_sched_credit_domain_set(xch, Int_val(domid), &c_sdom); caml_leave_blocking_section(); if (ret !=3D 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 -CAMLprim value stub_shadow_allocation_get(value xch, value domid) +CAMLprim value stub_shadow_allocation_get(value xch_val, value domid) { - CAMLparam2(xch, domid); + CAMLparam2(xch_val, domid); CAMLlocal1(mb); + xc_interface *xch =3D xch_of_val(xch_val); unsigned int c_mb; int ret; =20 caml_enter_blocking_section(); - ret =3D xc_shadow_control(_H(xch), _D(domid), + ret =3D xc_shadow_control(xch, Int_val(domid), XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION, &c_mb, 0); caml_leave_blocking_section(); if (ret !=3D 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 mb =3D Val_int(c_mb); CAMLreturn(mb); } =20 -CAMLprim value stub_shadow_allocation_set(value xch, value domid, +CAMLprim value stub_shadow_allocation_set(value xch_val, value domid, value mb) { - CAMLparam3(xch, domid, mb); + CAMLparam3(xch_val, domid, mb); + xc_interface *xch =3D xch_of_val(xch_val); unsigned int c_mb; int ret; =20 c_mb =3D Int_val(mb); caml_enter_blocking_section(); - ret =3D xc_shadow_control(_H(xch), _D(domid), + ret =3D xc_shadow_control(xch, Int_val(domid), XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION, &c_mb, 0); caml_leave_blocking_section(); if (ret !=3D 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_ioport_permission(value xch, value domid, +CAMLprim value stub_xc_domain_ioport_permission(value xch_val, value domid, value start_port, value nr_ports, value allow) { - CAMLparam5(xch, domid, start_port, nr_ports, allow); + CAMLparam5(xch_val, domid, start_port, nr_ports, allow); + xc_interface *xch =3D xch_of_val(xch_val); uint32_t c_start_port, c_nr_ports; uint8_t c_allow; int ret; @@ -1139,19 +1177,20 @@ CAMLprim value stub_xc_domain_ioport_permission(val= ue xch, value domid, c_nr_ports =3D Int_val(nr_ports); c_allow =3D Bool_val(allow); =20 - ret =3D xc_domain_ioport_permission(_H(xch), _D(domid), + ret =3D xc_domain_ioport_permission(xch, Int_val(domid), c_start_port, c_nr_ports, c_allow); if (ret < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_iomem_permission(value xch, value domid, +CAMLprim value stub_xc_domain_iomem_permission(value xch_val, value domid, value start_pfn, value nr_pfns, value allow) { - CAMLparam5(xch, domid, start_pfn, nr_pfns, allow); + CAMLparam5(xch_val, domid, start_pfn, nr_pfns, allow); + xc_interface *xch =3D xch_of_val(xch_val); unsigned long c_start_pfn, c_nr_pfns; uint8_t c_allow; int ret; @@ -1160,18 +1199,19 @@ CAMLprim value stub_xc_domain_iomem_permission(valu= e xch, value domid, c_nr_pfns =3D Nativeint_val(nr_pfns); c_allow =3D Bool_val(allow); =20 - ret =3D xc_domain_iomem_permission(_H(xch), _D(domid), + ret =3D xc_domain_iomem_permission(xch, Int_val(domid), c_start_pfn, c_nr_pfns, c_allow); if (ret < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_irq_permission(value xch, value domid, +CAMLprim value stub_xc_domain_irq_permission(value xch_val, value domid, value pirq, value allow) { - CAMLparam4(xch, domid, pirq, allow); + CAMLparam4(xch_val, domid, pirq, allow); + xc_interface *xch =3D xch_of_val(xch_val); uint32_t c_pirq; bool c_allow; int ret; @@ -1179,41 +1219,44 @@ CAMLprim value stub_xc_domain_irq_permission(value = xch, value domid, c_pirq =3D Int_val(pirq); c_allow =3D Bool_val(allow); =20 - ret =3D xc_domain_irq_permission(_H(xch), _D(domid), + ret =3D xc_domain_irq_permission(xch, Int_val(domid), c_pirq, c_allow); if (ret < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_hvm_param_get(value xch, value domid, value param) +CAMLprim value stub_xc_hvm_param_get(value xch_val, value domid, value par= am) { - CAMLparam3(xch, domid, param); + CAMLparam3(xch_val, domid, param); + xc_interface *xch =3D xch_of_val(xch_val); uint64_t val; int ret; =20 caml_enter_blocking_section(); - ret =3D xc_hvm_param_get(_H(xch), _D(domid), Int_val(param), &val); + ret =3D xc_hvm_param_get(xch, Int_val(domid), Int_val(param), &val); caml_leave_blocking_section(); =20 if ( ret ) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(caml_copy_int64(val)); } =20 -CAMLprim value stub_xc_hvm_param_set(value xch, value domid, value param, = value val) +CAMLprim value stub_xc_hvm_param_set(value xch_val, value domid, value par= am, value val) { - CAMLparam4(xch, domid, param, val); + CAMLparam4(xch_val, domid, param, val); + xc_interface *xch =3D xch_of_val(xch_val); + uint64_t val64 =3D Int64_val(val); int ret; =20 caml_enter_blocking_section(); - ret =3D xc_hvm_param_set(_H(xch), _D(domid), Int_val(param), Int64_val(va= l)); + ret =3D xc_hvm_param_set(xch, Int_val(domid), Int_val(param), val64); caml_leave_blocking_section(); =20 if ( ret ) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_unit); } @@ -1226,9 +1269,10 @@ static uint32_t encode_sbdf(int domain, int bus, int= dev, int func) ((uint32_t)func & 0x7); } =20 -CAMLprim value stub_xc_domain_test_assign_device(value xch, value domid, v= alue desc) +CAMLprim value stub_xc_domain_test_assign_device(value xch_val, value domi= d, value desc) { - CAMLparam3(xch, domid, desc); + CAMLparam3(xch_val, domid, desc); + xc_interface *xch =3D xch_of_val(xch_val); int ret; int domain, bus, dev, func; uint32_t sbdf; @@ -1239,14 +1283,15 @@ CAMLprim value stub_xc_domain_test_assign_device(va= lue xch, value domid, value d func =3D Int_val(Field(desc, 3)); sbdf =3D encode_sbdf(domain, bus, dev, func); =20 - ret =3D xc_test_assign_device(_H(xch), _D(domid), sbdf); + ret =3D xc_test_assign_device(xch, Int_val(domid), sbdf); =20 CAMLreturn(Val_bool(ret =3D=3D 0)); } =20 -CAMLprim value stub_xc_domain_assign_device(value xch, value domid, value = desc) +CAMLprim value stub_xc_domain_assign_device(value xch_val, value domid, va= lue desc) { - CAMLparam3(xch, domid, desc); + CAMLparam3(xch_val, domid, desc); + xc_interface *xch =3D xch_of_val(xch_val); int ret; int domain, bus, dev, func; uint32_t sbdf; @@ -1257,17 +1302,18 @@ CAMLprim value stub_xc_domain_assign_device(value x= ch, value domid, value desc) func =3D Int_val(Field(desc, 3)); sbdf =3D encode_sbdf(domain, bus, dev, func); =20 - ret =3D xc_assign_device(_H(xch), _D(domid), sbdf, + ret =3D xc_assign_device(xch, Int_val(domid), sbdf, XEN_DOMCTL_DEV_RDM_RELAXED); =20 if (ret < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_domain_deassign_device(value xch, value domid, valu= e desc) +CAMLprim value stub_xc_domain_deassign_device(value xch_val, value domid, = value desc) { - CAMLparam3(xch, domid, desc); + CAMLparam3(xch_val, domid, desc); + xc_interface *xch =3D xch_of_val(xch_val); int ret; int domain, bus, dev, func; uint32_t sbdf; @@ -1278,28 +1324,29 @@ CAMLprim value stub_xc_domain_deassign_device(value= xch, value domid, value desc func =3D Int_val(Field(desc, 3)); sbdf =3D encode_sbdf(domain, bus, dev, func); =20 - ret =3D xc_deassign_device(_H(xch), _D(domid), sbdf); + ret =3D xc_deassign_device(xch, Int_val(domid), sbdf); =20 if (ret < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); CAMLreturn(Val_unit); } =20 -CAMLprim value stub_xc_get_cpu_featureset(value xch, value idx) +CAMLprim value stub_xc_get_cpu_featureset(value xch_val, value idx) { - CAMLparam2(xch, idx); + CAMLparam2(xch_val, idx); CAMLlocal1(bitmap_val); #if defined(__i386__) || defined(__x86_64__) + xc_interface *xch =3D xch_of_val(xch_val); =20 /* Safe, because of the global ocaml lock. */ static uint32_t fs_len; =20 if (fs_len =3D=3D 0) { - int ret =3D xc_get_cpu_featureset(_H(xch), 0, &fs_len, NULL); + int ret =3D xc_get_cpu_featureset(xch, 0, &fs_len, NULL); =20 if (ret || (fs_len =3D=3D 0)) - failwith_xc(_H(xch)); + failwith_xc(xch); } =20 { @@ -1307,10 +1354,10 @@ CAMLprim value stub_xc_get_cpu_featureset(value xch= , value idx) uint32_t fs[fs_len], len =3D fs_len; unsigned int i; =20 - int ret =3D xc_get_cpu_featureset(_H(xch), Int_val(idx), &len, fs); + int ret =3D xc_get_cpu_featureset(xch, Int_val(idx), &len, fs); =20 if (ret) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 bitmap_val =3D caml_alloc(len, 0); =20 @@ -1323,15 +1370,16 @@ CAMLprim value stub_xc_get_cpu_featureset(value xch= , value idx) CAMLreturn(bitmap_val); } =20 -CAMLprim value stub_xc_watchdog(value xch, value domid, value timeout) +CAMLprim value stub_xc_watchdog(value xch_val, value domid, value timeout) { - CAMLparam3(xch, domid, timeout); + CAMLparam3(xch_val, domid, timeout); + xc_interface *xch =3D xch_of_val(xch_val); int ret; unsigned int c_timeout =3D Int32_val(timeout); =20 - ret =3D xc_watchdog(_H(xch), _D(domid), c_timeout); + ret =3D xc_watchdog(xch, Int_val(domid), c_timeout); if (ret < 0) - failwith_xc(_H(xch)); + failwith_xc(xch); =20 CAMLreturn(Val_int(ret)); } --=20 2.11.0