Skip to content

Commit 558ab65

Browse files
committed
[scudo] Select stricter atomic memory_order in MemMapFuchsia
Previously, all operations were relaxed except for the atomic_compare_exchange call, which was implicitly acquire (but did not compile anymore because of the changes in commit 3ef766a). In addition to making MemMapFuchsia compile again, this CL selects memory_order values that better express the intent of the code. Reviewed By: Chia-hungDuan Differential Revision: https://reviews.llvm.org/D157097
1 parent 7095a86 commit 558ab65

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

compiler-rt/lib/scudo/standalone/mem_map_fuchsia.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static void setVmoName(zx_handle_t Vmo, const char *Name) {
4141
static uptr getRootVmarBase() {
4242
static atomic_uptr CachedResult = {0};
4343

44-
uptr Result = atomic_load_relaxed(&CachedResult);
44+
uptr Result = atomic_load(&CachedResult, memory_order_acquire);
4545
if (UNLIKELY(!Result)) {
4646
zx_info_vmar_t VmarInfo;
4747
zx_status_t Status =
@@ -50,7 +50,7 @@ static uptr getRootVmarBase() {
5050
CHECK_EQ(Status, ZX_OK);
5151
CHECK_NE(VmarInfo.base, 0);
5252

53-
atomic_store_relaxed(&CachedResult, VmarInfo.base);
53+
atomic_store(&CachedResult, VmarInfo.base, memory_order_release);
5454
Result = VmarInfo.base;
5555
}
5656

@@ -61,7 +61,7 @@ static uptr getRootVmarBase() {
6161
static zx_handle_t getPlaceholderVmo() {
6262
static atomic_u32 StoredVmo = {ZX_HANDLE_INVALID};
6363

64-
zx_handle_t Vmo = atomic_load_relaxed(&StoredVmo);
64+
zx_handle_t Vmo = atomic_load(&StoredVmo, memory_order_acquire);
6565
if (UNLIKELY(Vmo == ZX_HANDLE_INVALID)) {
6666
// Create a zero-sized placeholder VMO.
6767
zx_status_t Status = _zx_vmo_create(0, 0, &Vmo);
@@ -72,9 +72,9 @@ static zx_handle_t getPlaceholderVmo() {
7272

7373
// Atomically store its handle. If some other thread wins the race, use its
7474
// handle and discard ours.
75-
zx_handle_t OldValue =
76-
atomic_compare_exchange(&StoredVmo, ZX_HANDLE_INVALID, Vmo);
77-
if (OldValue != ZX_HANDLE_INVALID) {
75+
zx_handle_t OldValue = atomic_compare_exchange_strong(
76+
&StoredVmo, ZX_HANDLE_INVALID, Vmo, memory_order_acq_rel);
77+
if (UNLIKELY(OldValue != ZX_HANDLE_INVALID)) {
7878
Status = _zx_handle_close(Vmo);
7979
CHECK_EQ(Status, ZX_OK);
8080

0 commit comments

Comments
 (0)