From: Ivan Maidanski Date: Mon, 5 Dec 2016 21:49:33 +0000 (+0300) Subject: Fix potential data race in GC_SysVGetDataStart (SPARC) X-Git-Tag: v7.6.2~296 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c927774c0907b31c3d5e8c0ec5c3d5c19a6c0204;p=gc Fix potential data race in GC_SysVGetDataStart (SPARC) * os_dep.c [SVR4 || AUX || DGUX || LINUX && SPARC] (GC_SysVGetDataStart): Use AO_fetch_and_add(p,0) if available instead of non-atomic read/write in *p = *p statement (thus, to avoid data race though it is highly unlikely). --- diff --git a/os_dep.c b/os_dep.c index ae9c338e..b78943a0 100644 --- a/os_dep.c +++ b/os_dep.c @@ -1872,11 +1872,17 @@ void GC_register_data_segments(void) GC_setup_temporary_fault_handler(); if (SETJMP(GC_jmp_buf) == 0) { /* Try writing to the address. */ - char v = *result; -# if defined(CPPCHECK) - GC_noop1((word)&v); +# ifdef AO_HAVE_fetch_and_add + volatile AO_t zero = 0; + (void)AO_fetch_and_add((volatile AO_t *)result, zero); +# else + /* Fallback to non-atomic fetch-and-store. */ + char v = *result; +# if defined(CPPCHECK) + GC_noop1((word)&v); +# endif + *result = v; # endif - *result = v; GC_reset_fault_handler(); } else { GC_reset_fault_handler();