Skip to content

Commit 63f27a6

Browse files
authored
macOS: Enable wasm and allow to load .wasm on Apple silicon (#23257)
* macOS: Allow to load .wasm on Apple silicon This applies https://chromium-review.googlesource.com/c/v8/v8/+/3700352 as a fix for MemoryAllocator::PartialFreeMemory() which shouldn't try to change permissions of RWX pages. This mainly affects macOS > 11.2 due to mprotect behavior changes (#23243) on Apple silicon.
1 parent 45f0624 commit 63f27a6

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

.bazelrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ build:macos --cxxopt=-std=c++17
102102
build:macos --action_env=PATH=/opt/homebrew/bin:/opt/local/bin:/usr/local/bin:/usr/bin:/bin
103103
build:macos --host_action_env=PATH=/opt/homebrew/bin:/opt/local/bin:/usr/local/bin:/usr/bin:/bin
104104
build:macos --define tcmalloc=disabled
105-
build:macos --define wasm=disabled
106105

107106
# macOS ASAN/UBSAN
108107
build:macos-asan --config=asan

bazel/v8.patch

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
# 7. Fix build errors in SIMD IndexOf/includes (https://crrev.com/c/3749192).
88
# 8. Fix build on arm64.
99
# 9. Fix build on older versions of Linux.
10+
# 10. Fix MemoryAllocator::PartialFreeMemory() which shouldn't try to change permissions of RWX pages,
11+
# mainly affecting macOS on Apple silicon (https://crrev.com/c/3700352). This can be removed
12+
# when we adopt 10.5 or higher (https://github.com/envoyproxy/envoy/issues/23258).
1013

1114
diff --git a/BUILD.bazel b/BUILD.bazel
1215
index 13f2a5bebf..2197568c48 100644
@@ -363,3 +366,37 @@ index 131ff9614e..6455f8757d 100644
363366
char filename[] = "/tmp/v8_tmp_file_for_testing_XXXXXX";
364367
fd = mkstemp(filename);
365368
if (fd != -1) CHECK_EQ(0, unlink(filename));
369+
diff --git a/src/heap/memory-allocator.cc b/src/heap/memory-allocator.cc
370+
index de143d8ea7..cca4dfe5dd 100644
371+
--- a/src/heap/memory-allocator.cc
372+
+++ b/src/heap/memory-allocator.cc
373+
@@ -416,8 +416,14 @@ void MemoryAllocator::PartialFreeMemory(BasicMemoryChunk* chunk,
374+
DCHECK_EQ(0, chunk->area_end() % static_cast<Address>(page_size));
375+
DCHECK_EQ(chunk->address() + chunk->size(),
376+
chunk->area_end() + MemoryChunkLayout::CodePageGuardSize());
377+
- reservation->SetPermissions(chunk->area_end(), page_size,
378+
- PageAllocator::kNoAccess);
379+
+
380+
+ if (V8_HEAP_USE_PTHREAD_JIT_WRITE_PROTECT && !isolate_->jitless()) {
381+
+ DCHECK(isolate_->RequiresCodeRange());
382+
+ reservation->DiscardSystemPages(chunk->area_end(), page_size);
383+
+ } else {
384+
+ reservation->SetPermissions(chunk->area_end(), page_size,
385+
+ PageAllocator::kNoAccess);
386+
+ }
387+
}
388+
// On e.g. Windows, a reservation may be larger than a page and releasing
389+
// partially starting at |start_free| will also release the potentially
390+
@@ -686,10 +692,10 @@ bool MemoryAllocator::SetPermissionsOnExecutableMemoryChunk(VirtualMemory* vm,
391+
const Address code_area = start + code_area_offset;
392+
const Address post_guard_page = start + chunk_size - guard_size;
393+
394+
- bool jitless = unmapper_.heap_->isolate()->jitless();
395+
+ bool jitless = isolate_->jitless();
396+
397+
if (V8_HEAP_USE_PTHREAD_JIT_WRITE_PROTECT && !jitless) {
398+
- DCHECK(unmapper_.heap_->isolate()->RequiresCodeRange());
399+
+ DCHECK(isolate_->RequiresCodeRange());
400+
// Commit the header, from start to pre-code guard page.
401+
// We have to commit it as executable becase otherwise we'll not be able
402+
// to change permissions to anything else.

0 commit comments

Comments
 (0)