Skip to content

Commit

Permalink
Fix crash on Apple Silicon when mprotect() fails expectedly
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus authored and github-actions[bot] committed Feb 3, 2025
1 parent 10d6fed commit 942f987
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/base/platform/platform-posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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));
Expand Down

0 comments on commit 942f987

Please sign in to comment.