diff options
author | Ben Gamari <ben@smart-cactus.org> | 2019-09-28 17:35:41 +0000 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2020-10-24 21:00:57 -0400 |
commit | 9e5c7f6de8e3d4cda0c07e0f210d9d5004fc6131 (patch) | |
tree | 75a5efa75ba0ac49def00bbf1b943795d9a163e9 /includes | |
parent | d0d07cffeded2b1d1b4ffed1f8b06eddc9f06600 (diff) | |
download | haskell-9e5c7f6de8e3d4cda0c07e0f210d9d5004fc6131.tar.gz |
rts: Avoid data races in StablePtr implementation
This fixes two potentially problematic data races in the StablePtr
implementation:
* We would fail to RELEASE the stable pointer table when enlarging it,
causing other cores to potentially see uninitialized memory.
* We would fail to ACQUIRE when dereferencing a stable pointer.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/rts/StablePtr.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/includes/rts/StablePtr.h b/includes/rts/StablePtr.h index f42c353d2b..56113b9f81 100644 --- a/includes/rts/StablePtr.h +++ b/includes/rts/StablePtr.h @@ -31,5 +31,9 @@ extern DLL_IMPORT_RTS spEntry *stable_ptr_table; EXTERN_INLINE StgPtr deRefStablePtr(StgStablePtr sp) { - return stable_ptr_table[(StgWord)sp].addr; + // acquire load to ensure that we see the new SPT if it has been recently + // enlarged. + const spEntry *spt = ACQUIRE_LOAD(&stable_ptr_table); + // acquire load to ensure that the referenced object is visible. + return ACQUIRE_LOAD(&spt[(StgWord)sp].addr); } |