Skip to content

Commit 2dae0c5

Browse files
Use MAP_JIT flag when allocating executable memory on macOS ARM64.
1 parent c1ee877 commit 2dae0c5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

mono/utils/dlmalloc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,14 @@ extern void* sbrk(ptrdiff_t);
13141314
#define MAP_ANONYMOUS MAP_ANON
13151315
#endif /* MAP_ANON */
13161316
#ifdef MAP_ANONYMOUS
1317+
1318+
#if defined(__APPLE__) && defined(__arm64__)
1319+
/* macOS on ARM64 requires using MAP_JIT in order to allocate executable memory. */
1320+
#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS|MAP_JIT)
1321+
#else
13171322
#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS)
1323+
#endif
1324+
13181325
#define CALL_MMAP(s) mmap(0, (s), MMAP_PROT, MMAP_FLAGS, -1, 0)
13191326
#else /* MAP_ANONYMOUS */
13201327
/*

mono/utils/mono-mmap.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ mono_valloc (void *addr, size_t length, int flags, MonoMemAccountType type)
228228
mflags |= MAP_ANONYMOUS;
229229
mflags |= MAP_PRIVATE;
230230

231+
#if defined(__APPLE__) && defined(__arm64__)
232+
/* macOS on ARM64 requires using MAP_JIT in order
233+
to allocate executable memory. */
234+
if (type == MONO_MEM_ACCOUNT_CODE)
235+
mflags |= MAP_JIT;
236+
#endif
237+
231238
BEGIN_CRITICAL_SECTION;
232239
ptr = mmap (addr, length, prot, mflags, -1, 0);
233240
if (ptr == MAP_FAILED) {

0 commit comments

Comments
 (0)