From nobody Mon Feb 9 01:00:55 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=1667921714; cv=none; d=zohomail.com; s=zohoarc; b=dNxNY1sFc+lYGSNgyANtQGTyamcwtlEB1sqw1wgDkK6Gjt6htu9JAGSPwIYtdIxhxJvqOn6imb3e0CAF3YyLGkWsGmQK7BcNOXNi5jclu0M+pe3dzJvXi4jnB4PH/OyJbA8K1BoBfD9Lg0qks6NQri5/ozNwo2iZ00Z3hGpDJjQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667921714; 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=JAiLVCJPplolzBTCWrQSMUADtuJsVSR8ZVkf2qI2sq8=; b=UtoVdQieIW5S0o9bYAGq2+RPp7ictRkWbSPhS0QQgSD2pzpMjFaCGZLcvslv49h7w9Ac+aNHk50YgUVNfMRNdm2NwnsAgaJcSEIKJy9J84dTpFlW3MvEe/ic81N4NAwJKS22X+8TljMfvNN6P4Ken5QkIiQQCcn6dz/fCbhCjCk= 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 1667921714782884.662207507185; Tue, 8 Nov 2022 07:35:14 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.440126.694252 (Exim 4.92) (envelope-from ) id 1osQcn-0003Yw-GV; Tue, 08 Nov 2022 15:34:53 +0000 Received: by outflank-mailman (output) from mailman id 440126.694252; Tue, 08 Nov 2022 15:34:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1osQcn-0003Xi-8e; Tue, 08 Nov 2022 15:34:53 +0000 Received: by outflank-mailman (input) for mailman id 440126; Tue, 08 Nov 2022 15:34:51 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1osQcl-0001RY-Gs for xen-devel@lists.xenproject.org; Tue, 08 Nov 2022 15:34:51 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e0ef84aa-5f7a-11ed-91b5-6bf2151ebd3b; Tue, 08 Nov 2022 16:34:49 +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: e0ef84aa-5f7a-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1667921689; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8ZXiX9ItGs2cbrZyrTgiP7zufiQzcqMjhU4Bz6aA7bo=; b=QCdChhoGm43hsmE+1+edlUuHhyNoKL7Rgghp7jpV/rATFoOk4ckvePYu j/unOBHLxXr/ghnpIGfOggmcS4yATolVulgSSn7URVVn+ASJCeZyGs5RR 9X37WRB1dsz6feCU76wItMEcuU247pmf0pU0s2ml7RUIE0ZFB8st28F9O s=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: None X-MesageID: 84416530 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:QJrAg68xziy/qLbiSl7tDrUDjH6TJUtcMsCJ2f8bNWPcYEJGY0x3y mtKWG6HPa6KajCjeYx0PYq28E5X6pWDytdrS1Nuq388E34SpcT7XtnIdU2Y0wF+jCHgZBk+s 5hBMImowOQcFCK0SsKFa+C5xZVE/fjUAOG6UKucYHsZqTZMEE8JkQhkl/MynrlmiN24BxLlk d7pqojUNUTNNwRcawr40Ire7kIx1BjOkGlA5AZnPKgb5AW2e0Q9V/rzG4ngdxMUfaEMdgKKb 76r5K20+Grf4yAsBruN+losWhRXKlJ6FVHmZkt+A8BOsDAbzsAB+v9T2M4nQVVWk120c+VZk 72hg3ASpTABZcUgkMxFO/VR/roX0aduoNcrKlDn2SCfItGvn9IBDJyCAWlvVbD09NqbDklRq dkbdBsWfiu8iuSU7p2nUPs1uO08eZyD0IM34hmMzBncBPciB5vCX7/L9ZlT2zJYasJmRKiEI ZBDMHw2MUqGM0Yn1lQ/UfrSmM+limf+dXtEr0iSpoI84nTJzRw327/oWDbQUozWGZwLwx3Az o7A12vHJD8/bP+89WuMzVaLhM/KpXzxZJ1HQdVU8dY12QbOlwT/EiY+Sl+TsfS/zEmkVLp3O 0ESvyYjs6U23EiqVcXmGQ21pmaeuRwRUMYWFPc1gCmtx6zO8kCmD24LZjdbbZots8pebTAjy FKhhd7iAj1r9rqPRhqgGqy89G3of3JPdClbOHFCHVBtD8TfTJ8bkU7qTYpIC76OsdDzOx/f3 yqY9RYXmOBG5SIU7JmT8VfCijOqg5HGSA8p+wnaNl6YAhNFiJ2NPNLxtwWChRpUBMPAFwTa4 iBY8ySLxLpWZaxhghBhVwnk8FuBw/+eeAPRjld0d3XK32T8oiXzFWy8DdwXGauIDirmUWW3C KMwkVkLjHO2AJdNRf4fXm5JI552pZUM7Py8Ph0UB/IXCnSLSCeJ/Tt1eWmb1H33nU4nnMkXY MnFLpbwUy9CUf45nFJaotvxNpdymEgDKZ77H8inn3xLL5LCDJJqdVv1GATXNb1ohE91iA7U7 8xeJ6O3J+Z3CYXDj+i+2dB7EG3m2lBiVM2p8ZcMLr7aSuekcUl4Y8LsLXoaU9QNt8xoei3gp xlRhmcwJILDuED6 IronPort-HdrOrdr: A9a23:H+TIP6HUiUxyFGElpLqE0MeALOsnbusQ8zAXP0AYc3Jom6uj5r mTdZUgpHnJYVkqOE3I9ertBEDEewK4yXcX2/h3AV7BZniEhILAFugLhuGO/9SjIVybygc079 YZT0EUMrzN5DZB4voSmDPIceod/A== X-IronPort-AV: E=Sophos;i="5.96,148,1665460800"; d="scan'208";a="84416530" From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= To: CC: Henry Wang , =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , Christian Lindig , David Scott , Wei Liu , Anthony PERARD Subject: [PATCH for-4.17 v3 08/15] tools/ocaml/libs/evtchn: add xenevtchn_fdopen bindings Date: Tue, 8 Nov 2022 15:34:00 +0000 Message-ID: <3e7f15778ffb5d5d7adde8567c4d50197607f7b2.1667920496.git.edvin.torok@citrix.com> 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: 1667921717053100004 Signed-off-by: Edwin T=C3=B6r=C3=B6k Acked-by: Christian Lindig > --- Reason for inclusion in 4.17: - needed for a bugfix in a followup commit Changes since v2: - new in v3 --- tools/ocaml/libs/eventchn/xeneventchn.ml | 6 +++- tools/ocaml/libs/eventchn/xeneventchn.mli | 9 +++++- tools/ocaml/libs/eventchn/xeneventchn_stubs.c | 28 +++++++++++++++++-- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/tools/ocaml/libs/eventchn/xeneventchn.ml b/tools/ocaml/libs/ev= entchn/xeneventchn.ml index dd00a1f0ea..34f7391f5e 100644 --- a/tools/ocaml/libs/eventchn/xeneventchn.ml +++ b/tools/ocaml/libs/eventchn/xeneventchn.ml @@ -16,7 +16,11 @@ =20 type handle =20 -external init: unit -> handle =3D "stub_eventchn_init" +external init_cloexec: bool -> handle =3D "stub_eventchn_init" + +let init ?(cloexec=3Dtrue) () =3D init_cloexec cloexec + +external fdopen: Unix.file_descr -> handle =3D "stub_eventchn_fdopen" external fd: handle -> Unix.file_descr =3D "stub_eventchn_fd" =20 type t =3D int diff --git a/tools/ocaml/libs/eventchn/xeneventchn.mli b/tools/ocaml/libs/e= ventchn/xeneventchn.mli index 08c7337643..3965b29621 100644 --- a/tools/ocaml/libs/eventchn/xeneventchn.mli +++ b/tools/ocaml/libs/eventchn/xeneventchn.mli @@ -43,7 +43,14 @@ val to_int: t -> int =20 val of_int: int -> t =20 -val init: unit -> handle +val init: ?cloexec:bool -> unit -> handle +(** [init ?cloexec ()] + Return an initialised event channel interface. + The default is to close the underlying file descriptor + on [execve], which can be overriden with [~cloexec:false]. + On error it will throw a Failure exception. *) + +val fdopen: Unix.file_descr -> handle (** Return an initialised event channel interface. On error it will throw a Failure exception. *) =20 diff --git a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c b/tools/ocaml/li= bs/eventchn/xeneventchn_stubs.c index 2263c4caa1..92092ca31e 100644 --- a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c +++ b/tools/ocaml/libs/eventchn/xeneventchn_stubs.c @@ -58,14 +58,36 @@ static struct custom_operations xenevtchn_ops =3D { custom_compare_ext_default /* raises Failure */ }; =20 -CAMLprim value stub_eventchn_init(void) +CAMLprim value stub_eventchn_init(value cloexec) { - CAMLparam0(); + CAMLparam1(cloexec); CAMLlocal1(result); xenevtchn_handle *xce; =20 caml_enter_blocking_section(); - xce =3D xenevtchn_open(NULL, 0); + xce =3D xenevtchn_open(NULL, Bool_val(cloexec) ? 0 : XENEVTCHN_NO_CLOE= XEC); + caml_leave_blocking_section(); + + if ( xce =3D=3D NULL ) + caml_failwith("open failed"); + + /* contains file descriptors, trigger full GC at least every 128 + * allocations + */ + result =3D caml_alloc_custom(&xenevtchn_ops, sizeof(xce), 0, 1); + _H(result) =3D xce; + CAMLreturn(result); +} + +CAMLprim value stub_eventchn_fdopen(value fdval) +{ + CAMLparam1(fdval); + CAMLlocal1(result); + xenevtchn_handle *xce; + + caml_enter_blocking_section(); + /* having any flags here would raise EINVAL */ + xce =3D xenevtchn_fdopen(NULL, Int_val(fdval), 0); caml_leave_blocking_section(); =20 if (xce =3D=3D NULL) --=20 2.34.1