|
| 1 | +diff --git a/src/base/build_config.h b/src/base/build_config.h |
| 2 | +index ee745539dfd..4182c592472 100644 |
| 3 | +--- a/src/base/build_config.h |
| 4 | ++++ b/src/base/build_config.h |
| 5 | +@@ -36,8 +36,16 @@ |
| 6 | + #endif |
| 7 | + #define V8_HAS_PKU_JIT_WRITE_PROTECT V8_HAS_PKU_SUPPORT |
| 8 | + |
| 9 | ++// Mac Catalyst compiles as iOS (TARGET_OS_IPHONE) but runs on macOS, so its |
| 10 | ++// JIT pages follow the macOS MAP_JIT + pthread_jit_write_protect_np rules. |
| 11 | ++#if defined(V8_OS_IOS) && defined(TARGET_OS_MACCATALYST) && \ |
| 12 | ++ TARGET_OS_MACCATALYST |
| 13 | ++#define V8_OS_MACCATALYST 1 |
| 14 | ++#endif |
| 15 | ++ |
| 16 | + // pthread_jit_write_protect is only available on arm64 Mac. |
| 17 | +-#if defined(V8_HOST_ARCH_ARM64) && defined(V8_OS_MACOS) |
| 18 | ++#if defined(V8_HOST_ARCH_ARM64) && \ |
| 19 | ++ (defined(V8_OS_MACOS) || defined(V8_OS_MACCATALYST)) |
| 20 | + #define V8_HAS_PTHREAD_JIT_WRITE_PROTECT 1 |
| 21 | + #else |
| 22 | + #define V8_HAS_PTHREAD_JIT_WRITE_PROTECT 0 |
| 23 | +diff --git a/src/base/platform/platform-darwin.cc b/src/base/platform/platform-darwin.cc |
| 24 | +index 41fc5ec3302..004ae7c002b 100644 |
| 25 | +--- a/src/base/platform/platform-darwin.cc |
| 26 | ++++ b/src/base/platform/platform-darwin.cc |
| 27 | +@@ -234,6 +234,24 @@ V8_BASE_EXPORT void SetJitWriteProtected(int enable) { |
| 28 | + } |
| 29 | + |
| 30 | + #pragma clang diagnostic pop |
| 31 | ++#elif V8_HAS_PTHREAD_JIT_WRITE_PROTECT && defined(V8_OS_MACCATALYST) |
| 32 | ++// The SDK marks pthread_jit_write_protect_np unavailable on Mac Catalyst, but |
| 33 | ++// a Catalyst process runs against macOS's libpthread, which exports it. |
| 34 | ++namespace { |
| 35 | ++using JitWriteProtectFn = void (*)(int); |
| 36 | ++ |
| 37 | ++JitWriteProtectFn ResolveJitWriteProtect() { |
| 38 | ++ auto fn = reinterpret_cast<JitWriteProtectFn>( |
| 39 | ++ dlsym(RTLD_DEFAULT, "pthread_jit_write_protect_np")); |
| 40 | ++ CHECK_NOT_NULL(fn); |
| 41 | ++ return fn; |
| 42 | ++} |
| 43 | ++} // namespace |
| 44 | ++ |
| 45 | ++V8_BASE_EXPORT void SetJitWriteProtected(int enable) { |
| 46 | ++ static const JitWriteProtectFn jit_write_protect = ResolveJitWriteProtect(); |
| 47 | ++ jit_write_protect(enable); |
| 48 | ++} |
| 49 | + #endif |
| 50 | + |
| 51 | + } // namespace base |
| 52 | +diff --git a/src/heap/code-range.cc b/src/heap/code-range.cc |
| 53 | +index ca0b1742b38..b979862d76f 100644 |
| 54 | +--- a/src/heap/code-range.cc |
| 55 | ++++ b/src/heap/code-range.cc |
| 56 | +@@ -382,8 +382,8 @@ bool CodeRange::InitReservation(v8::PageAllocator* page_allocator, |
| 57 | + // Don't pre-commit the code cage on Windows since it uses memory and it's not |
| 58 | + // required for recommit. |
| 59 | + // iOS cannot adjust page permissions for MAP_JIT'd pages, they are set as RWX |
| 60 | +-// at the start. |
| 61 | +-#if !defined(V8_OS_WIN) && !defined(V8_OS_IOS) |
| 62 | ++// at the start. Mac Catalyst runs on macOS and needs the pre-commit. |
| 63 | ++#if !defined(V8_OS_WIN) && (!defined(V8_OS_IOS) || defined(V8_OS_MACCATALYST)) |
| 64 | + if (params.page_initialization_mode == |
| 65 | + base::PageInitializationMode::kRecommitOnly) { |
| 66 | + void* base = reinterpret_cast<void*>(page_allocator_->begin() + |
| 67 | +@@ -605,7 +605,7 @@ uint8_t* CodeRange::RemapEmbeddedBuiltins(Isolate* isolate, |
| 68 | + if (V8_HEAP_USE_PTHREAD_JIT_WRITE_PROTECT || |
| 69 | + V8_HEAP_USE_BECORE_JIT_WRITE_PROTECT || ThreadIsolation::Enabled()) { |
| 70 | + // iOS code pages are already RWX and don't need to be modified. |
| 71 | +-#if !defined(V8_TARGET_OS_IOS) |
| 72 | ++#if !defined(V8_TARGET_OS_IOS) || defined(V8_OS_MACCATALYST) |
| 73 | + if (!page_allocator()->RecommitPages(embedded_blob_code_copy, code_size, |
| 74 | + PageAllocator::kReadWriteExecute)) { |
| 75 | + V8::FatalProcessOutOfMemory(isolate, |
| 76 | +diff --git a/src/heap/code-range.h b/src/heap/code-range.h |
| 77 | +index b42081b8aa1..acb2f57d420 100644 |
| 78 | +--- a/src/heap/code-range.h |
| 79 | ++++ b/src/heap/code-range.h |
| 80 | +@@ -177,7 +177,8 @@ class CodeRange final : public VirtualMemoryCage { |
| 81 | + // Red zones that we should not allocate in. |
| 82 | + RedZones red_zones_; |
| 83 | + |
| 84 | +-#if !defined(V8_OS_WIN) && !defined(V8_OS_IOS) && defined(DEBUG) |
| 85 | ++#if !defined(V8_OS_WIN) && \ |
| 86 | ++ (!defined(V8_OS_IOS) || defined(V8_OS_MACCATALYST)) && defined(DEBUG) |
| 87 | + bool immutable_ = false; |
| 88 | + #endif |
| 89 | + }; |
0 commit comments