Skip to content

Commit 068186c

Browse files
committed
Fix aarch64 macOS crash when SIP disabled (JLJITLinkMemoryManager)
Apple ARM CPUs treat the `ic ivau` as a memory read, which causes a confusing crash in DualMapAllocator if we try using it on a wr_addr that has been mprotected to `Prot::NO`, since we are still holding the allocator lock. For Apple aarch64 systems with SIP disabled, this will result in some memory savings, since DualMapAllocator will now work there. Like before, other JITLink platforms, namely Linux aarch64 and RISC-V, will benefit too. This re-lands #60105, after it was reverted in #60196. Thanks @giordano!
1 parent 0546450 commit 068186c

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/cgmemmgr.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,12 @@ class ROAllocator {
548548
virtual ~ROAllocator() JL_NOTSAFEPOINT {}
549549
virtual void finalize() JL_NOTSAFEPOINT
550550
{
551-
for (auto &alloc: allocations) {
552-
// ensure the mapped pages are consistent
553-
sys::Memory::InvalidateInstructionCache(alloc.wr_addr,
554-
alloc.sz);
555-
sys::Memory::InvalidateInstructionCache(alloc.rt_addr,
556-
alloc.sz);
557-
}
551+
// Note: on some aarch64 platforms, like Apple CPUs, we need read
552+
// permission in order to invalidate instruction cache lines. We are
553+
// not guaranteed to have read permission on the wr_addr when using
554+
// DualMapAllocator.
555+
for (auto &alloc : allocations)
556+
sys::Memory::InvalidateInstructionCache(alloc.rt_addr, alloc.sz);
558557
completed.clear();
559558
allocations.clear();
560559
}

0 commit comments

Comments
 (0)