Skip to content

Commit

Permalink
chore: cherry-pick 0c8b6e41 from v8 (#27684)
Browse files Browse the repository at this point in the history
* chore: cherry-pick 0c8b6e41 from v8

Backports https://chromium-review.googlesource.com/c/v8/v8/+/2679688

* update patches

* Update .patches

* update patches

Co-authored-by: deepak1556 <hop2deep@gmail.com>
Co-authored-by: Electron Bot <electron@github.com>
  • Loading branch information
3 people committed Feb 11, 2021
1 parent 3bcdc27 commit 99eb8ac
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions patches/v8/.patches
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ cherry-pick-ffd6ff5a61b9.patch
merged_deoptimizer_stricter_checks_during_deoptimization.patch
merged_compiler_mark_jsstoreinarrayliteral_as_needing_a_frame.patch
cherry-pick-36abafa0a316.patch
mac_wasm_work_around_macos_11_2_code_page_decommit_failures.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: deepak1556 <hop2deep@gmail.com>
Date: Mon, 8 Feb 2021 13:20:09 -0800
Subject: Work around MacOS 11.2 code page decommit failures

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}

diff --git a/src/base/platform/platform-posix.cc b/src/base/platform/platform-posix.cc
index 89173b593a6ce887c0f3cea082f2d31e17f8f5db..0afaa5269bd4b61cb62532a8ffc6debcfc508dfb 100644
--- a/src/base/platform/platform-posix.cc
+++ b/src/base/platform/platform-posix.cc
@@ -417,6 +417,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));

0 comments on commit 99eb8ac

Please sign in to comment.