From eeab59b3015c8629edeadcf097d0a12515cc8ccd Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Tue, 10 Apr 2018 10:31:57 +0300 Subject: [PATCH] Avoid potential race in print_static_roots called by dyld_image_add/remove * dyn_load.c [DARWIN && DARWIN_DEBUG && !NO_DEBUGGING] (GC_dyld_image_add, GC_dyld_image_remove): Place LOCK/UNLOCK around GC_print_static_roots() call. * dyn_load.c [DARWIN && DARWIN_DEBUG && !NO_DEBUGGING] (GC_dyld_image_remove): Add DCL_LOCK_STATE. --- dyn_load.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/dyn_load.c b/dyn_load.c index 7f36b0bb..190dc107 100644 --- a/dyn_load.c +++ b/dyn_load.c @@ -1373,8 +1373,10 @@ STATIC void GC_dyld_image_add(const struct GC_MACH_HEADER *hdr, } } -# ifdef DARWIN_DEBUG +# if defined(DARWIN_DEBUG) && !defined(NO_DEBUGGING) + LOCK(); GC_print_static_roots(); + UNLOCK(); # endif } @@ -1385,6 +1387,9 @@ STATIC void GC_dyld_image_remove(const struct GC_MACH_HEADER *hdr, unsigned long start, end; unsigned i, j; const struct GC_MACH_SECTION *sec; +# if defined(DARWIN_DEBUG) && !defined(NO_DEBUGGING) + DCL_LOCK_STATE; +# endif for (i = 0; i < sizeof(GC_dyld_sections)/sizeof(GC_dyld_sections[0]); i++) { sec = GC_GETSECTBYNAME(hdr, GC_dyld_sections[i].seg, @@ -1426,8 +1431,10 @@ STATIC void GC_dyld_image_remove(const struct GC_MACH_HEADER *hdr, } } -# ifdef DARWIN_DEBUG +# if defined(DARWIN_DEBUG) && !defined(NO_DEBUGGING) + LOCK(); GC_print_static_roots(); + UNLOCK(); # endif } -- 2.40.0