[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH for-4.17 v3 08/15] tools/ocaml/libs/evtchn: add xenevtchn_fdopen bindings


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Edwin Török <edvin.torok@xxxxxxxxxx>
  • Date: Tue, 8 Nov 2022 15:34:00 +0000
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Henry Wang <Henry.Wang@xxxxxxx>, Edwin Török <edvin.torok@xxxxxxxxxx>, Christian Lindig <christian.lindig@xxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • Delivery-date: Tue, 08 Nov 2022 15:34:53 +0000
  • 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==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Signed-off-by: Edwin Török <edvin.torok@xxxxxxxxxx>
---
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/eventchn/xeneventchn.ml
index dd00a1f0ea..34f7391f5e 100644
--- a/tools/ocaml/libs/eventchn/xeneventchn.ml
+++ b/tools/ocaml/libs/eventchn/xeneventchn.ml
@@ -16,7 +16,11 @@
 
 type handle
 
-external init: unit -> handle = "stub_eventchn_init"
+external init_cloexec: bool -> handle = "stub_eventchn_init"
+
+let init ?(cloexec=true) () = init_cloexec cloexec
+
+external fdopen: Unix.file_descr -> handle = "stub_eventchn_fdopen"
 external fd: handle -> Unix.file_descr = "stub_eventchn_fd"
 
 type t = int
diff --git a/tools/ocaml/libs/eventchn/xeneventchn.mli 
b/tools/ocaml/libs/eventchn/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
 
 val of_int: int -> t
 
-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. *)
 
diff --git a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c 
b/tools/ocaml/libs/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 = {
     custom_compare_ext_default /* raises Failure */
 };
 
-CAMLprim value stub_eventchn_init(void)
+CAMLprim value stub_eventchn_init(value cloexec)
 {
-    CAMLparam0();
+    CAMLparam1(cloexec);
     CAMLlocal1(result);
     xenevtchn_handle *xce;
 
     caml_enter_blocking_section();
-    xce = xenevtchn_open(NULL, 0);
+    xce = xenevtchn_open(NULL, Bool_val(cloexec) ? 0 : XENEVTCHN_NO_CLOEXEC);
+    caml_leave_blocking_section();
+
+    if ( xce == NULL )
+        caml_failwith("open failed");
+
+    /* contains file descriptors, trigger full GC at least every 128
+     * allocations
+     */
+    result = caml_alloc_custom(&xenevtchn_ops, sizeof(xce), 0, 1);
+    _H(result) = 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 = xenevtchn_fdopen(NULL, Int_val(fdval), 0);
     caml_leave_blocking_section();
 
     if (xce == NULL)
-- 
2.34.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.