diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 8067246f7..81826f032 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -1061,12 +1061,22 @@ typedef word page_hash_table[PHT_SIZE]; # define set_pht_entry_from_index_concurrent(bl, index) \ AO_or((volatile AO_t *)&(bl)[divWORDSZ(index)], \ (AO_t)((word)1 << modWORDSZ(index))) +# ifdef MPROTECT_VDB +# define set_pht_entry_from_index_concurrent_volatile(bl, index) \ + set_pht_entry_from_index_concurrent(bl, index) +# endif #else # define set_pht_entry_from_index_concurrent(bl, index) \ set_pht_entry_from_index(bl, index) +# ifdef MPROTECT_VDB + /* Same as set_pht_entry_from_index() but avoiding the compound */ + /* assignment for a volatile array. */ +# define set_pht_entry_from_index_concurrent_volatile(bl, index) \ + (void)((bl)[divWORDSZ(index)] \ + = (bl)[divWORDSZ(index)] | ((word)1 << modWORDSZ(index))) +# endif #endif - /********************************************/ /* */ /* H e a p B l o c k s */ diff --git a/os_dep.c b/os_dep.c index 6cc39a046..481b64a5a 100644 --- a/os_dep.c +++ b/os_dep.c @@ -552,7 +552,9 @@ GC_INNER const char * GC_get_maps(void) if ((word)result >= (word)bound - pgsz) { result = bound; } else { - result += pgsz; /* no overflow expected */ + result = result + pgsz; + /* no overflow expected; do not use compound */ + /* assignment with volatile-qualified left operand */ GC_noop1((word)(*result)); } } @@ -1000,7 +1002,9 @@ GC_INNER void GC_setpagesize(void) result = bound; break; } - result += MIN_PAGE_SIZE; /* no overflow expected */ + result = result + MIN_PAGE_SIZE; + /* no overflow expected; do not use compound */ + /* assignment with volatile-qualified left operand */ } else { if ((word)result <= (word)bound + MIN_PAGE_SIZE) { result = bound - MIN_PAGE_SIZE; @@ -1011,16 +1015,15 @@ GC_INNER void GC_setpagesize(void) /* by setjmp otherwise). */ break; } - result -= MIN_PAGE_SIZE; /* no underflow expected */ + result = result - MIN_PAGE_SIZE; + /* no underflow expected; do not use compound */ + /* assignment with volatile-qualified left operand */ } GC_noop1((word)(*result)); } } GC_reset_fault_handler(); - if (!up) { - result += MIN_PAGE_SIZE; - } - return result; + return up ? result : result + MIN_PAGE_SIZE; } void * GC_find_limit(void * p, int up) @@ -3056,8 +3059,13 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void) #if !defined(NO_MANUAL_VDB) || defined(MPROTECT_VDB) # if !defined(THREADS) || defined(HAVE_LOCKFREE_AO_OR) -# define async_set_pht_entry_from_index(db, index) \ - set_pht_entry_from_index_concurrent(db, index) +# ifdef MPROTECT_VDB +# define async_set_pht_entry_from_index(db, index) \ + set_pht_entry_from_index_concurrent_volatile(db, index) +# else +# define async_set_pht_entry_from_index(db, index) \ + set_pht_entry_from_index_concurrent(db, index) +# endif # elif defined(AO_HAVE_test_and_set_acquire) /* We need to lock around the bitmap update (in the write fault */ /* handler or GC_dirty) in order to avoid the risk of losing a bit. */ diff --git a/tests/gctest.c b/tests/gctest.c index 1b8da7a7f..c0a73c106 100644 --- a/tests/gctest.c +++ b/tests/gctest.c @@ -240,13 +240,12 @@ static void *checkOOM(void *p) #endif /* Allocation Statistics. Synchronization is not strictly necessary. */ -static volatile AO_t uncollectable_count = 0; -static volatile AO_t collectable_count = 0; -static volatile AO_t atomic_count = 0; -static volatile AO_t realloc_count = 0; +static AO_t uncollectable_count = 0; +static AO_t collectable_count = 0; +static AO_t atomic_count = 0; +static AO_t realloc_count = 0; -static volatile AO_t extra_count = 0; - /* Amount of space wasted in cons node; */ +static AO_t extra_count = 0; /* Amount of space wasted in cons node; */ /* also used in gcj_cons, mktree and */ /* chktree (for other purposes). */ @@ -1454,7 +1453,7 @@ static void typed_test(void) #ifdef DBG_HDRS_ALL # define set_print_procs() (void)(A.dummy = 17) #else - static volatile AO_t fail_count = 0; + static AO_t fail_count = 0; static void GC_CALLBACK fail_proc1(void *arg) { @@ -1908,7 +1907,7 @@ static void run_one_test(void) /* Run reverse_test a second time, so we hopefully notice corruption. */ reverse_test(); # ifndef NO_DEBUGGING - (void)GC_is_tmp_root((/* no volatile */ void *)(GC_word)&atomic_count); + (void)GC_is_tmp_root(&atomic_count); # endif # ifndef NO_CLOCK if (print_stats) { @@ -2700,7 +2699,7 @@ int main(void) set_print_procs(); /* Minimal testing of some API functions. */ - GC_exclude_static_roots((/* no volatile */ void *)(GC_word)&atomic_count, + GC_exclude_static_roots(&atomic_count, (void *)((GC_word)&atomic_count + sizeof(atomic_count))); GC_register_has_static_roots_callback(has_static_roots); GC_register_describe_type_fn(GC_I_NORMAL, describe_norm_type); diff --git a/tests/weakmap.c b/tests/weakmap.c index 3739bde1a..f4f1ff3a1 100644 --- a/tests/weakmap.c +++ b/tests/weakmap.c @@ -98,11 +98,11 @@ static unsigned memhash(void *src, size_t len) return acc; } -static volatile AO_t stat_added; -static volatile AO_t stat_found; -static volatile AO_t stat_removed; -static volatile AO_t stat_skip_locked; -static volatile AO_t stat_skip_marked; +static AO_t stat_added; +static AO_t stat_found; +static AO_t stat_removed; +static AO_t stat_skip_locked; +static AO_t stat_skip_marked; struct weakmap_link { GC_hidden_pointer obj;