Skip to content

Instantly share code, notes, and snippets.

@andreialecu
Created February 15, 2021 10:38
Show Gist options
  • Save andreialecu/54b17d7872d047a61e85dcf0261a6105 to your computer and use it in GitHub Desktop.
Save andreialecu/54b17d7872d047a61e85dcf0261a6105 to your computer and use it in GitHub Desktop.
diff --git a/deps/v8/src/base/platform/platform-posix.cc b/deps/v8/src/base/platform/platform-posix.cc
index 68d651b15fe..d5624cb8ace 100644
--- a/deps/v8/src/base/platform/platform-posix.cc
+++ b/deps/v8/src/base/platform/platform-posix.cc
@@ -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));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment