diff --git a/src/base/platform/platform-posix.cc b/src/base/platform/platform-posix.cc index 1e9af2e486..f53dde5816 100644 --- a/src/base/platform/platform-posix.cc +++ b/src/base/platform/platform-posix.cc @@ -499,12 +499,6 @@ bool OS::SetPermissions(void* address, size_t size, MemoryPermission access) { int prot = GetProtectionFromMemoryPermission(access); int ret = mprotect(address, size, prot); - // Setting permissions can fail if the limit of VMAs is exceeded. - // Any failure that's not OOM likely indicates a bug in the caller (e.g. - // using an invalid mapping) so attempt to catch that here to facilitate - // debugging of these failures. - if (ret != 0) CHECK_EQ(ENOMEM, errno); - // MacOS 11.2 on Apple Silicon refuses to switch permissions from // rwx to none. Just use madvise instead. #if defined(V8_OS_DARWIN) @@ -514,6 +508,12 @@ bool OS::SetPermissions(void* address, size_t size, MemoryPermission access) { } #endif + // Setting permissions can fail if the limit of VMAs is exceeded. + // Any failure that's not OOM likely indicates a bug in the caller (e.g. + // using an invalid mapping) so attempt to catch that here to facilitate + // debugging of these failures. + if (ret != 0) CHECK_EQ(ENOMEM, errno); + if (ret == 0 && access == OS::MemoryPermission::kNoAccess) { // This is advisory; ignore errors and continue execution. USE(DiscardSystemPages(address, size));