Commit 639e8563 authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

[wasm] Disable MAP_JIT functionality on iOS

pthread_jit_write_protect* functions are only available on arm64 Mac,
not on iOS (which also sets V8_{TARGET_,}OS_MACOSX).
This CL refactors the logic to detect whether pthread_jit_write_protect
and MAP_JIT are available and defines a global preprocessor macro which
can subsequently be used instead of the existing complex condition.

R=jkummerow@chromium.org, mlippautz@chromium.org

Change-Id: I63894f42df35406d6eee90a4ce5070c2fde7b566
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3077154Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Adam Klein <adamk@chromium.org>
Auto-Submit: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76143}
parent d3b5b63d
...@@ -553,6 +553,13 @@ V8 shared library set USING_V8_SHARED. ...@@ -553,6 +553,13 @@ V8 shared library set USING_V8_SHARED.
#endif // V8_OS_WIN #endif // V8_OS_WIN
// pthread_jit_write_protect is only available on arm64 Mac.
#if defined(V8_OS_MACOSX) && !defined(V8_OS_IOS) && defined(V8_HOST_ARCH_ARM64)
# define V8_HAS_PTHREAD_JIT_WRITE_PROTECT 1
#else
# define V8_HAS_PTHREAD_JIT_WRITE_PROTECT 0
#endif
// clang-format on // clang-format on
#undef V8_HAS_CPP_ATTRIBUTE #undef V8_HAS_CPP_ATTRIBUTE
......
...@@ -45,7 +45,7 @@ void* PageAllocator::GetRandomMmapAddr() { ...@@ -45,7 +45,7 @@ void* PageAllocator::GetRandomMmapAddr() {
void* PageAllocator::AllocatePages(void* hint, size_t size, size_t alignment, void* PageAllocator::AllocatePages(void* hint, size_t size, size_t alignment,
PageAllocator::Permission access) { PageAllocator::Permission access) {
#if !(V8_OS_MACOSX && V8_HOST_ARCH_ARM64 && defined(MAP_JIT)) #if !V8_HAS_PTHREAD_JIT_WRITE_PROTECT
// kNoAccessWillJitLater is only used on Apple Silicon. Map it to regular // kNoAccessWillJitLater is only used on Apple Silicon. Map it to regular
// kNoAccess on other platforms, so code doesn't have to handle both enum // kNoAccess on other platforms, so code doesn't have to handle both enum
// values. // values.
......
...@@ -153,7 +153,7 @@ int GetFlagsForMemoryPermission(OS::MemoryPermission access, ...@@ -153,7 +153,7 @@ int GetFlagsForMemoryPermission(OS::MemoryPermission access,
flags |= MAP_LAZY; flags |= MAP_LAZY;
#endif // V8_OS_QNX #endif // V8_OS_QNX
} }
#if V8_OS_MACOSX && V8_HOST_ARCH_ARM64 && defined(MAP_JIT) #if V8_HAS_PTHREAD_JIT_WRITE_PROTECT
if (access == OS::MemoryPermission::kNoAccessWillJitLater) { if (access == OS::MemoryPermission::kNoAccessWillJitLater) {
flags |= MAP_JIT; flags |= MAP_JIT;
} }
......
...@@ -14,16 +14,16 @@ namespace wasm { ...@@ -14,16 +14,16 @@ namespace wasm {
thread_local int CodeSpaceWriteScope::code_space_write_nesting_level_ = 0; thread_local int CodeSpaceWriteScope::code_space_write_nesting_level_ = 0;
// The thread-local counter (above) is only valid if a single thread only works // The thread-local counter (above) is only valid if a single thread only works
// on one module at a time. This second thread-local checks that. // on one module at a time. This second thread-local checks that.
#if defined(DEBUG) && (!defined(V8_OS_MACOSX) || !defined(V8_HOST_ARCH_ARM64)) #if defined(DEBUG) && !V8_HAS_PTHREAD_JIT_WRITE_PROTECT
thread_local NativeModule* CodeSpaceWriteScope::current_native_module_ = thread_local NativeModule* CodeSpaceWriteScope::current_native_module_ =
nullptr; nullptr;
#endif #endif
// TODO(jkummerow): Background threads could permanently stay in // TODO(jkummerow): Background threads could permanently stay in
// writable mode; only the main thread has to switch back and forth. // writable mode; only the main thread has to switch back and forth.
#if defined(V8_OS_MACOSX) && defined(V8_HOST_ARCH_ARM64) #if V8_HAS_PTHREAD_JIT_WRITE_PROTECT
CodeSpaceWriteScope::CodeSpaceWriteScope(NativeModule*) { CodeSpaceWriteScope::CodeSpaceWriteScope(NativeModule*) {
#else // !defined(V8_OS_MACOSX) || !defined(V8_HOST_ARCH_ARM64) #else // !V8_HAS_PTHREAD_JIT_WRITE_PROTECT
CodeSpaceWriteScope::CodeSpaceWriteScope(NativeModule* native_module) CodeSpaceWriteScope::CodeSpaceWriteScope(NativeModule* native_module)
: native_module_(native_module) { : native_module_(native_module) {
#ifdef DEBUG #ifdef DEBUG
...@@ -32,7 +32,7 @@ CodeSpaceWriteScope::CodeSpaceWriteScope(NativeModule* native_module) ...@@ -32,7 +32,7 @@ CodeSpaceWriteScope::CodeSpaceWriteScope(NativeModule* native_module)
} }
DCHECK_EQ(native_module, current_native_module_); DCHECK_EQ(native_module, current_native_module_);
#endif // DEBUG #endif // DEBUG
#endif // !defined(V8_OS_MACOSX) || !defined(V8_HOST_ARCH_ARM64) #endif // !V8_HAS_PTHREAD_JIT_WRITE_PROTECT
if (code_space_write_nesting_level_ == 0) { if (code_space_write_nesting_level_ == 0) {
SetWritable(); SetWritable();
} }
...@@ -44,7 +44,7 @@ CodeSpaceWriteScope::~CodeSpaceWriteScope() { ...@@ -44,7 +44,7 @@ CodeSpaceWriteScope::~CodeSpaceWriteScope() {
if (code_space_write_nesting_level_ == 0) SetExecutable(); if (code_space_write_nesting_level_ == 0) SetExecutable();
} }
#if defined(V8_OS_MACOSX) && defined(V8_HOST_ARCH_ARM64) #if V8_HAS_PTHREAD_JIT_WRITE_PROTECT
// Ignoring this warning is considered better than relying on // Ignoring this warning is considered better than relying on
// __builtin_available. // __builtin_available.
...@@ -59,7 +59,7 @@ void CodeSpaceWriteScope::SetExecutable() const { ...@@ -59,7 +59,7 @@ void CodeSpaceWriteScope::SetExecutable() const {
} }
#pragma clang diagnostic pop #pragma clang diagnostic pop
#else // !defined(V8_OS_MACOSX) || !defined(V8_HOST_ARCH_ARM64) #else // !V8_HAS_PTHREAD_JIT_WRITE_PROTECT
void CodeSpaceWriteScope::SetWritable() const { void CodeSpaceWriteScope::SetWritable() const {
DCHECK_NOT_NULL(native_module_); DCHECK_NOT_NULL(native_module_);
...@@ -82,7 +82,7 @@ void CodeSpaceWriteScope::SetExecutable() const { ...@@ -82,7 +82,7 @@ void CodeSpaceWriteScope::SetExecutable() const {
} }
} }
#endif // !defined(V8_OS_MACOSX) || !defined(V8_HOST_ARCH_ARM64) #endif // !V8_HAS_PTHREAD_JIT_WRITE_PROTECT
} // namespace wasm } // namespace wasm
} // namespace internal } // namespace internal
......
...@@ -55,7 +55,7 @@ class V8_NODISCARD CodeSpaceWriteScope final { ...@@ -55,7 +55,7 @@ class V8_NODISCARD CodeSpaceWriteScope final {
private: private:
static thread_local int code_space_write_nesting_level_; static thread_local int code_space_write_nesting_level_;
#if defined(DEBUG) && (!defined(V8_OS_MACOSX) || !defined(V8_HOST_ARCH_ARM64)) #if defined(DEBUG) && !V8_HAS_PTHREAD_JIT_WRITE_PROTECT
static thread_local NativeModule* current_native_module_; static thread_local NativeModule* current_native_module_;
#endif #endif
...@@ -66,7 +66,7 @@ class V8_NODISCARD CodeSpaceWriteScope final { ...@@ -66,7 +66,7 @@ class V8_NODISCARD CodeSpaceWriteScope final {
// allocation which region to switch permissions for. On non-M1 hardware // allocation which region to switch permissions for. On non-M1 hardware
// without memory protection key support, we need the code space from the // without memory protection key support, we need the code space from the
// {native_module_}. // {native_module_}.
#if !defined(V8_OS_MACOSX) || !defined(V8_HOST_ARCH_ARM64) #if !V8_HAS_PTHREAD_JIT_WRITE_PROTECT
NativeModule* const native_module_; NativeModule* const native_module_;
#endif #endif
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment