From nobody Mon Feb 9 10:57:44 2026 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=1664277366; cv=none; d=zohomail.com; s=zohoarc; b=l+SS6A/MfjtBL6BZr2run9K3a/d929sGTzaxiZOPvxrnWe5Rj0AFWkHSgZpeT48zkxT72goIdC3UV0XezQFo71uuJD3UwiqLbmfS9CtIgHm46y50qr8xbokru6giM5ZVRig0pcKeczZEVTe+MQrvFK+tUTaIAsmqmU/ZYCdCLj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664277366; 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=ahv2+5Wd2wi75xIln38f9FxpEcCoP+qT5zbhhmi/ZLQ=; b=aWZK2HBcQlbT3PiuJisCBwN5KXIDa/bz+Xfik1Kh4wU5HHIvkjSA0VLrE8ftt4H3TCKKtFz5OoemyF14T8RyYv3FOG+1bGZ1aCUjrBQVsXHNWlLg6pPIjIaX4rdJIoWAAftP2z4eAhXAjBFcA0P2a0q65TRGhqqABMS7XWkmlkY= 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 1664277366803600.3690742553052; Tue, 27 Sep 2022 04:16:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.412491.655847 (Exim 4.92) (envelope-from ) id 1od8Yz-0008Cf-E2; Tue, 27 Sep 2022 11:15:45 +0000 Received: by outflank-mailman (output) from mailman id 412491.655847; Tue, 27 Sep 2022 11:15:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1od8Yz-0008CY-BA; Tue, 27 Sep 2022 11:15:45 +0000 Received: by outflank-mailman (input) for mailman id 412491; Tue, 27 Sep 2022 11:15:44 +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 1od8Yy-0008Aw-Dw for xen-devel@lists.xenproject.org; Tue, 27 Sep 2022 11:15:44 +0000 Received: from esa4.hc3370-68.iphmx.com (esa4.hc3370-68.iphmx.com [216.71.155.144]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b895e39a-3e55-11ed-9374-c1cf23e5d27e; Tue, 27 Sep 2022 13:15:42 +0200 (CEST) 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: b895e39a-3e55-11ed-9374-c1cf23e5d27e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1664277342; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FDvDgX7AxBcpgWMVzYo5l6lVSFhVUQDnFTbkDG8AAP4=; b=VfzeFkjrp58JMhRmLOKVq1oOdeYS1HPmeik4NCDGNQYoYbECgkH0sAG4 VvzOkTS6VZUF8/Hm2OnvO4DBU7jD/oUIZxhbDNDzS8R07OaD6+H6dY0Fe N1FzxTPmoxfkyq0HT5aPrGTqdLYdKjIkD5WrlgKWB9HfXwH8aoSb2JcM1 M=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 2.7 X-MesageID: 83941730 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:OuIcr643ljqtc0Opum9JfQxRtEfHchMFZxGqfqrLsTDasY5as4F+v jRKXWzQP/uOMzPzLt53YYu2o0tT7ZODzNUwQVFr+yg9Hi5G8cbLO4+Ufxz6V8+wwm8vb2o8t plDNYOQRCwQZiWBzvt4GuG59RGQ7YnRGvymTras1hlZHWdMUD0mhQ9oh9k3i4tphcnRKw6Ws Jb5rta31GWNglaYCUpJrfPYwP9TlK6q4mlA7wZhPaojUGL2zBH5MrpOfcldEFOgKmVkNrbSb /rOyri/4lTY838FYj9yuu+mGqGiaue60Tmm0hK6aYD76vRxjnVaPpIAHOgdcS9qZwChxLid/ jnvWauYEm/FNoWU8AgUvoIx/ytWZcWq85efSZSzXFD6I+QrvBIAzt03ZHzaM7H09c5FCkNSz 9xBdwwuLQq7vaWd7KmKVc9V05FLwMnDZOvzu1llxDDdS/0nXYrCU+PB4towMDUY354UW6yEP oxANGQpPE+ojx5nYz/7DLozkPmpgD/jdCdfq3qepLYt4niVxwt0uFToGIqOK4DTGp4N9qqej m7d7Vb9GzsYD4W86nmitWuvnv6VvyyuDer+E5Xnr6U30TV/3Fc7Fxk+RVa95/6jhSaWV9tBJ mQO9yEprKx081akJvHtUhv9rHOasxo0X9tLD/Z8+AyL0rDT4QuSGi4DVDEpVTA9nJZoH3pwj AbPxo63Q2w02FGIdZ6D3oWfjy+IGXFKEUxBfxc+CiAp+Oj8hrhm23ojUe1fOKKyi9T0HxT5z DaLsDUyit0vsCIb60mo1QuZ2mzx//AlWiZwv1yKBTz9smuVcab/P+SVBU7nAeGsxWpzZn2Ip zA6lseX94ji5rndxXXWEI3h8FxEjstp0QEwY3Y1R/HNFBz3oRZPmLy8BxkhTHqFyu5eJVfUj Lb74Gu9HqN7MnqwdrNQaImsEcksxqWIPY27CKyON4UTM8ggLF7vEMRSiam4gAjQfLUEy/lja f93j+71ZZrlNUiX5GXvHLpMuVPa7is/2XnSVfjG8vhT6pLHPSb9dFvwGAHRBgzPxP/b/V69H hc2H5fi9iizp8WlO3GLrNJOcTjn7xETXPjLliCeTcbbSiIOJY3rI6W5LW8JE2C9o5loqw== IronPort-HdrOrdr: A9a23:Up+ZiK/jWUvzldOMOFtuk+DiI+orL9Y04lQ7vn2YSXRuE/Bw8P re5MjztCWE8Qr5N0tQ+uxoVJPufZqYz+8Q3WBzB8bFYOCFghrLEGgK1+KLqFeMdxEWtNQtsp uIG5IOc+EYZmIbsS+V2meF+q4bsby6zJw= X-IronPort-AV: E=Sophos;i="5.93,349,1654574400"; d="scan'208";a="83941730" From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= To: CC: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , "Christian Lindig" , David Scott , Wei Liu , Anthony PERARD Subject: [PATCH v2 3/5] tools/ocaml/libs/eventchn: do not leak event channels and OCaml 5.0 compat Date: Tue, 27 Sep 2022 12:14:59 +0100 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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: 1664277367519100006 Add a finalizer on the event channel value, so that it calls `xenevtchn_close` when the value would be GCed. In practice oxenstored seems to be the only user of this, and it creates a single global event channel only, but freeing this could still be useful when run with OCAMLRUNPARAM=3Dc The code was previously casting a C pointer to an OCaml value, which should be avoided: OCaml 5.0 won't support it. (all "naked" C pointers must be wrapped inside an OCaml value, either an Abstract tag, or Nativeint, see the manual https://ocaml.org/manual/intfc.html#ss:c-outside-head) Signed-off-by: Edwin T=C3=B6r=C3=B6k Acked-by: Christian Lindig --- tools/ocaml/libs/eventchn/xeneventchn_stubs.c | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c b/tools/ocaml/li= bs/eventchn/xeneventchn_stubs.c index f889a7a2e4..67af116377 100644 --- a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c +++ b/tools/ocaml/libs/eventchn/xeneventchn_stubs.c @@ -33,7 +33,30 @@ #include #include =20 -#define _H(__h) ((xenevtchn_handle *)(__h)) +/* We want to close the event channel when it is no longer in use, + which can only be done safely with a finalizer. + Event channels are typically long lived, so we don't need tighter contr= ol over resource deallocation. + Use a custom block +*/ + +/* Access the xenevtchn_t* part of the OCaml custom block */ +#define _H(__h) (*((xenevtchn_handle**)Data_custom_val(__h))) + +static void stub_evtchn_finalize(value v) +{ + /* docs say to not use any CAMLparam* macros here */ + xenevtchn_close(_H(v)); +} + +static struct custom_operations xenevtchn_ops =3D { + "xenevtchn", + stub_evtchn_finalize, + custom_compare_default, /* raises Failure, cannot compare */ + custom_hash_default, /* ignored */ + custom_serialize_default, /* raises Failure, can't serialize */ + custom_deserialize_default, /* raises Failure, can't deserialize */ + custom_compare_ext_default /* raises Failure */ +}; =20 CAMLprim value stub_eventchn_init(void) { @@ -48,7 +71,9 @@ CAMLprim value stub_eventchn_init(void) if (xce =3D=3D NULL) caml_failwith("open failed"); =20 - result =3D (value)xce; + /* contains file descriptors, trigger full GC at least every 128 allocati= ons */ + result =3D caml_alloc_custom(&xenevtchn_ops, sizeof(xce), 0, 1); + _H(result) =3D xce; CAMLreturn(result); } =20 --=20 2.34.1