From: Ivan Maidanski Date: Tue, 10 Apr 2018 07:31:57 +0000 (+0300) Subject: Avoid potential race in print_static_roots called by dyld_image_add/remove X-Git-Tag: v8.0.0~247 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eeab59b3015c8629edeadcf097d0a12515cc8ccd;p=gc 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. --- 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 }