Skip to content

Commit

Permalink
[mac][wasm] Work around MacOS 11.2 code page decommit failures
Browse files Browse the repository at this point in the history
MacOS 11.2 refuses to set "no access" permissions on memory that
we previously used for JIT-compiled code. It is still unclear
whether this is WAI on the part of the kernel. In the meantime,
as a workaround, we use madvise(..., MADV_FREE_REUSABLE) instead
of mprotect(..., NONE) when discarding code pages. This is inspired
by what Chromium's gin platform does.

Fixed: v8:11389
Change-Id: I866586932573b4253002436ae5eee4e0411c45fc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2679688
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Auto-Submit: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72559}
  • Loading branch information
jakobkummerow authored and Commit Bot committed Feb 8, 2021
1 parent 392a025 commit 0c8b6e4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/base/platform/platform-posix.cc
Expand Up @@ -415,6 +415,16 @@ bool OS::SetPermissions(void* address, size_t size, MemoryPermission access) {

int prot = GetProtectionFromMemoryPermission(access);
int ret = mprotect(address, size, prot);

// MacOS 11.2 on Apple Silicon refuses to switch permissions from
// rwx to none. Just use madvise instead.
#if defined(V8_OS_MACOSX)
if (ret != 0 && access == OS::MemoryPermission::kNoAccess) {
ret = madvise(address, size, MADV_FREE_REUSABLE);
return ret == 0;
}
#endif

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 0c8b6e4

Please sign in to comment.