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

[PATCH v1 8/9] tools/ocaml/libs/mmap: mark mmap/munmap as blocking


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Edwin Török <edvin.torok@xxxxxxxxxx>
  • Date: Thu, 27 Aug 2020 18:35:59 +0100
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Edwin Török <edvin.torok@xxxxxxxxxx>, "Christian Lindig" <christian.lindig@xxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, "Ian Jackson" <ian.jackson@xxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Thu, 27 Aug 2020 17:36:49 +0000
  • Ironport-sdr: E27MO3U+SpUGqyCWEqLeJvxJUxgSSkU9mV9fBNw9FTOYknKMWUsS0HfeiNFeD/Owxq8/5JQPP1 zkcBO5G8oIy8fVFbHJHvmUr40jcxySR+HJ1A7NS3oC7khcR4rpJn3qgU/6RdXvAvzEAfl/Jfkk s57JimTRlbceEDftuPdGt/E3gDPBuIr9vabt/2bnP/AHhZMSJR0LahXGEjdPKRgFKgArcE8p2b 4H8dujc5HRGIf4Y9qQ5UO83gkGS3/m9xJ+/+DVrtpabLHo3WsO/8B+V5M4EEek8AeAfFokE1Hx idE=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

These functions can potentially take some time,
so allow other OCaml code to proceed meanwhile (if any).

Signed-off-by: Edwin Török <edvin.torok@xxxxxxxxxx>
---
 tools/ocaml/libs/mmap/xenmmap_stubs.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/ocaml/libs/mmap/xenmmap_stubs.c 
b/tools/ocaml/libs/mmap/xenmmap_stubs.c
index 9c1126c6a2..21feceea0e 100644
--- a/tools/ocaml/libs/mmap/xenmmap_stubs.c
+++ b/tools/ocaml/libs/mmap/xenmmap_stubs.c
@@ -28,6 +28,7 @@
 #include <caml/fail.h>
 #include <caml/callback.h>
 #include <caml/unixsupport.h>
+#include <caml/signals.h>
 
 #define Wsize_bsize_round(n) (Wsize_bsize( (n) + sizeof(value) - 1 ))
 
@@ -69,7 +70,9 @@ CAMLprim value stub_mmap_init(value fd, value pflag, value 
mflag,
                caml_invalid_argument("negative offset");
        length = Int_val(len);
 
+       caml_enter_blocking_section();
        addr = mmap(NULL, length, c_pflag, c_mflag, fd, Int_val(offset));
+       caml_leave_blocking_section();
        if (MAP_FAILED == addr)
                uerror("mmap", Nothing);
 
@@ -80,10 +83,15 @@ CAMLprim value stub_mmap_init(value fd, value pflag, value 
mflag,
 CAMLprim value stub_mmap_final(value intf)
 {
        CAMLparam1(intf);
+       struct mmap_interface interface = *Intf_val(intf);
 
-       if (Intf_val(intf)->addr != MAP_FAILED)
-               munmap(Intf_val(intf)->addr, Intf_val(intf)->len);
+       /* mark it as freed, in case munmap below fails, so we don't retry it */
        Intf_val(intf)->addr = MAP_FAILED;
+       if (interface.addr != MAP_FAILED) {
+               caml_enter_blocking_section();
+               munmap(interface.addr, interface.len);
+               caml_leave_blocking_section();
+       }
 
        CAMLreturn(Val_unit);
 }
-- 
2.25.1




 


Rackspace

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