summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '0011-tools-ocaml-evtchn-OCaml-5-support-fix-potential-res.patch')
-rw-r--r--0011-tools-ocaml-evtchn-OCaml-5-support-fix-potential-res.patch68
1 files changed, 68 insertions, 0 deletions
diff --git a/0011-tools-ocaml-evtchn-OCaml-5-support-fix-potential-res.patch b/0011-tools-ocaml-evtchn-OCaml-5-support-fix-potential-res.patch
new file mode 100644
index 0000000..c9cf630
--- /dev/null
+++ b/0011-tools-ocaml-evtchn-OCaml-5-support-fix-potential-res.patch
@@ -0,0 +1,68 @@
+From d11528a993f80c6a86f4cb0c30578c026348e3e4 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= <edvin.torok@citrix.com>
+Date: Tue, 18 Jan 2022 15:04:48 +0000
+Subject: [PATCH 11/89] tools/ocaml/evtchn: OCaml 5 support, fix potential
+ resource leak
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+There is no binding for xenevtchn_close(). In principle, this is a resource
+leak, but the typical usage is as a singleton that lives for the lifetime of
+the program.
+
+Ocaml 5 no longer permits storing a naked C pointer in an Ocaml value.
+
+Therefore, use a Custom block. This allows us to use the finaliser callback
+to call xenevtchn_close(), if the Ocaml object goes out of scope.
+
+Signed-off-by: Edwin Török <edvin.torok@citrix.com>
+Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
+Acked-by: Christian Lindig <christian.lindig@citrix.com>
+(cherry picked from commit 22d5affdf0cecfa6faae46fbaec68b8018835220)
+---
+ tools/ocaml/libs/eventchn/xeneventchn_stubs.c | 21 +++++++++++++++++--
+ 1 file changed, 19 insertions(+), 2 deletions(-)
+
+diff --git a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c b/tools/ocaml/libs/eventchn/xeneventchn_stubs.c
+index f889a7a2e4..37f1cc4e14 100644
+--- a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c
++++ b/tools/ocaml/libs/eventchn/xeneventchn_stubs.c
+@@ -33,7 +33,22 @@
+ #include <caml/fail.h>
+ #include <caml/signals.h>
+
+-#define _H(__h) ((xenevtchn_handle *)(__h))
++#define _H(__h) (*((xenevtchn_handle **)Data_custom_val(__h)))
++
++static void stub_evtchn_finalize(value v)
++{
++ xenevtchn_close(_H(v));
++}
++
++static struct custom_operations xenevtchn_ops = {
++ .identifier = "xenevtchn",
++ .finalize = stub_evtchn_finalize,
++ .compare = custom_compare_default, /* Can't compare */
++ .hash = custom_hash_default, /* Can't hash */
++ .serialize = custom_serialize_default, /* Can't serialize */
++ .deserialize = custom_deserialize_default, /* Can't deserialize */
++ .compare_ext = custom_compare_ext_default, /* Can't compare */
++};
+
+ CAMLprim value stub_eventchn_init(void)
+ {
+@@ -48,7 +63,9 @@ CAMLprim value stub_eventchn_init(void)
+ if (xce == NULL)
+ caml_failwith("open failed");
+
+- result = (value)xce;
++ result = caml_alloc_custom(&xenevtchn_ops, sizeof(xce), 0, 1);
++ _H(result) = xce;
++
+ CAMLreturn(result);
+ }
+
+--
+2.40.0
+