From bc39359c2dec398492eb104ac2eb276a672d9e31 Mon Sep 17 00:00:00 2001 From: monojenkins Date: Thu, 3 Sep 2020 17:56:36 -0400 Subject: [PATCH] [runtime] Allocate code memory using MAP_JIT on apple silicon, patching code randomly crashes without it. (#41798) Co-authored-by: vargaz --- src/mono/mono/utils/mono-mmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mono/mono/utils/mono-mmap.c b/src/mono/mono/utils/mono-mmap.c index 2dff889..fa4686f 100644 --- a/src/mono/mono/utils/mono-mmap.c +++ b/src/mono/mono/utils/mono-mmap.c @@ -305,6 +305,9 @@ mono_valloc (void *addr, size_t length, int flags, MonoMemAccountType type) } if ((flags & MONO_MMAP_JIT) && (use_mmap_jit || is_hardened_runtime == 1)) mflags |= MAP_JIT; + /* Patching code on apple silicon seems to cause random crashes without this flag */ + if (__builtin_available (macOS 11, *)) + mflags |= MAP_JIT; } #endif -- 2.7.4