Revert "Fix race condition in memory_decommit/memory_reset on Apple ARM64"
This reverts commit 4cac76caad.
This commit is contained in:
@@ -347,11 +347,12 @@ namespace utils
|
|||||||
#else
|
#else
|
||||||
const u64 ptr64 = reinterpret_cast<u64>(pointer);
|
const u64 ptr64 = reinterpret_cast<u64>(pointer);
|
||||||
#if defined(__APPLE__) && defined(ARCH_ARM64)
|
#if defined(__APPLE__) && defined(ARCH_ARM64)
|
||||||
// Use MAP_FIXED without MAP_JIT to atomically replace the mapping.
|
// Hack: on macOS, Apple explicitly fails mmap if you combine MAP_FIXED and MAP_JIT.
|
||||||
// Apple rejects MAP_FIXED | MAP_JIT, but MAP_FIXED alone works and
|
// So we unmap the space and just hope it maps to the same address we got before instead.
|
||||||
// avoids the race condition of the previous munmap+mmap approach
|
// The Xcode manpage says the pointer is a hint and the OS will try to map at the hint location
|
||||||
// where another thread could claim the address range between the two calls.
|
// so this isn't completely undefined behavior.
|
||||||
ensure(::mmap(pointer, size, PROT_NONE, MAP_FIXED | MAP_ANON | MAP_PRIVATE | c_map_noreserve, -1, 0) != reinterpret_cast<void*>(uptr{umax}));
|
ensure(::munmap(pointer, size) != -1);
|
||||||
|
ensure(::mmap(pointer, size, PROT_NONE, MAP_ANON | MAP_PRIVATE | MAP_JIT, -1, 0) == pointer);
|
||||||
#else
|
#else
|
||||||
ensure(::mmap(pointer, size, PROT_NONE, MAP_FIXED | MAP_ANON | MAP_PRIVATE | c_map_noreserve, -1, 0) != reinterpret_cast<void*>(uptr{umax}));
|
ensure(::mmap(pointer, size, PROT_NONE, MAP_FIXED | MAP_ANON | MAP_PRIVATE | c_map_noreserve, -1, 0) != reinterpret_cast<void*>(uptr{umax}));
|
||||||
#endif
|
#endif
|
||||||
@@ -380,9 +381,8 @@ namespace utils
|
|||||||
#else
|
#else
|
||||||
const u64 ptr64 = reinterpret_cast<u64>(pointer);
|
const u64 ptr64 = reinterpret_cast<u64>(pointer);
|
||||||
#if defined(__APPLE__) && defined(ARCH_ARM64)
|
#if defined(__APPLE__) && defined(ARCH_ARM64)
|
||||||
// Use MAP_FIXED without MAP_JIT to atomically replace the mapping.
|
ensure(::munmap(pointer, size) != -1);
|
||||||
// See memory_decommit for details on why the munmap+mmap approach is unsafe.
|
ensure(::mmap(pointer, size, +prot, MAP_ANON | MAP_PRIVATE | MAP_JIT, -1, 0) == pointer);
|
||||||
ensure(::mmap(pointer, size, +prot, MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0) != reinterpret_cast<void*>(uptr{umax}));
|
|
||||||
#else
|
#else
|
||||||
ensure(::mmap(pointer, size, +prot, MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0) != reinterpret_cast<void*>(uptr{umax}));
|
ensure(::mmap(pointer, size, +prot, MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0) != reinterpret_cast<void*>(uptr{umax}));
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user