diff --git a/runtime/vm/code_patcher.cc b/runtime/vm/code_patcher.cc index 0f6105c2c80b..72ec8f84d7d1 100644 --- a/runtime/vm/code_patcher.cc +++ b/runtime/vm/code_patcher.cc @@ -10,7 +10,20 @@ namespace dart { -DEFINE_FLAG(bool, write_protect_code, true, "Write protect jitted code"); +#if defined(DART_HOST_OS_MACOS) || defined(DART_HOST_OS_MACOS_IOS) +// On iOS even with debugger attached we must still guarantee that memory +// is never executable and writable at the same time. On Mac OS X +// com.apple.security.cs.allow-jit entitelement allows WX memory regions to be +// created - but we should not rely on this entitelement to be present. +static constexpr bool kShouldWriteProtectCodeByDefault = true; +#else +static constexpr bool kShouldWriteProtectCodeByDefault = false; +#endif + +DEFINE_FLAG(bool, + write_protect_code, + kShouldWriteProtectCodeByDefault, + "Write protect jitted code"); #if defined(TARGET_ARCH_IA32) WritableInstructionsScope::WritableInstructionsScope(uword address,