From 9729402e7524964f216c6232ebc4e2e3eaa03886 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 26 Jul 2011 18:57:19 +0100 Subject: [PATCH] ocaml: Fix locking in event callbacks. We weren't acquiring the GC lock around some allocations, resulting in segfaults when an event callback ran at the same time as a main thread allocation or garbage collection. In particular this fixes a noticable crash in guestfs-browser. (Cherry picked from commit 2b8b3f9794ceb43eabd3083e225c669896d8b186) --- ocaml/guestfs_c.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ocaml/guestfs_c.c b/ocaml/guestfs_c.c index 1324fb6..deb1026 100644 --- a/ocaml/guestfs_c.c +++ b/ocaml/guestfs_c.c @@ -225,8 +225,8 @@ clear_progress_callback (guestfs_h *g) } static void -progress_callback (guestfs_h *g ATTRIBUTE_UNUSED, void *root, - int proc_nr, int serial, uint64_t position, uint64_t total) +progress_callback_locked (guestfs_h *g ATTRIBUTE_UNUSED, void *root, + int proc_nr, int serial, uint64_t position, uint64_t total) { CAMLparam0 (); CAMLlocal5 (proc_nrv, serialv, positionv, totalv, rv); @@ -238,9 +238,7 @@ progress_callback (guestfs_h *g ATTRIBUTE_UNUSED, void *root, value args[4] = { proc_nrv, serialv, positionv, totalv }; - caml_leave_blocking_section (); rv = caml_callbackN_exn (*(value*)root, 4, args); - caml_enter_blocking_section (); /* Callbacks shouldn't throw exceptions. There's not much we can do * except to print it. @@ -251,3 +249,17 @@ progress_callback (guestfs_h *g ATTRIBUTE_UNUSED, void *root, CAMLreturn0; } + +static void +progress_callback (guestfs_h *g ATTRIBUTE_UNUSED, void *root, + int proc_nr, int serial, uint64_t position, uint64_t total) +{ + /* Ensure we are holding the GC lock before any GC operations are + * possible. (RHBZ#725824) + */ + caml_leave_blocking_section (); + + progress_callback_locked (g, root, proc_nr, serial, position, total); + + caml_enter_blocking_section (); +} -- 1.8.3.1