Repository navigation
Description
Description
While looking for a different instability, someone internally found that we are occasionally seeing the nativeaot'd il2cpp executable crash on Windows x64. The crash seems rare. We don't have reproduction steps yet. We will spend some time trying to reproduce. If we get more information I'll update the issue.
The info we do have is a crash dump. Here is some info from the dump.
il2cpp.exe!RhpInterfaceDispatch4() Line 68
at D:\a\_work\1\s\src\coreclr\nativeaot\Runtime\amd64\StubDispatch.asm(68)
il2cpp.exe!Unity_IL2CPP_DataModel_Unity_IL2CPP_DataModel_CustomAttributeProviderExtensions__HasAttribute() Line 7
at C:\build\output\unity\il2cpp\Unity.IL2CPP.DataModel\CustomAttributeProviderExtensions.cs(7)
il2cpp.exe!Unity_IL2CPP_Unity_IL2CPP_AssemblyConversion_PrimaryCollection_Steps_Global_AnalyticsCollection__ProcessItem() Line 37
at C:\build\output\unity\il2cpp\Unity.IL2CPP\AssemblyConversion\PrimaryCollection\Steps.Global\AnalyticsCollection.cs(37)
il2cpp.exe!Unity_IL2CPP_Unity_IL2CPP_AssemblyConversion_Steps_Base_ScheduledItemsStepFunc_5<System___Canon__System___Canon__System___Canon__System___Canon__System___Canon>__WorkerWrapper() Line 45
at C:\build\output\unity\il2cpp\Unity.IL2CPP\AssemblyConversion\Steps.Base\ScheduledItemsStepFunc.cs(45)
il2cpp.exe!Unity_IL2CPP_Unity_IL2CPP_Contexts_Scheduling_PhaseWorkScheduler_1_ContinueWithResultsWorkItem_4<System___Canon__System___Canon__System___Canon__System___Canon__System___Canon>__InvokeWorker() Line 620
at C:\build\output\unity\il2cpp\Unity.IL2CPP\Contexts.Scheduling\PhaseWorkScheduler.cs(620)
il2cpp.exe!Unity_IL2CPP_Unity_IL2CPP_Contexts_Scheduling_PhaseWorkScheduler_1_BaseContinueWorkItem_2<System___Canon__System___Canon__System___Canon>__Invoke() Line 534
at C:\build\output\unity\il2cpp\Unity.IL2CPP\Contexts.Scheduling\PhaseWorkScheduler.cs(534)
il2cpp.exe!Unity_IL2CPP_Unity_IL2CPP_Contexts_Scheduling_PhaseWorkScheduler_1<System___Canon>__WorkerLoop() Line 338
at C:\build\output\unity\il2cpp\Unity.IL2CPP\Contexts.Scheduling\PhaseWorkScheduler.cs(338)
il2cpp.exe!S_P_CoreLib_System_Threading_Thread__StartThread() Line 447
at /_/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs(447)
il2cpp.exe!S_P_CoreLib_System_Threading_Thread__ThreadEntryPoint() Line 225
at /_/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Windows.cs(225)
kernel32.dll!BaseThreadInitThunk()
ntdll.dll!RtlUserThreadStart()
The code it's crashing during is pretty unremarkable
public static class CustomAttributeProviderExtensions
{
public static bool HasAttribute(this ICustomAttributeProvider customAttributeProvider, string @namespace, string name)
{
for (int i = 0; i < customAttributeProvider.CustomAttributes.Count; i++)
{
if (customAttributeProvider.CustomAttributes[i].AttributeType.Name == name &&
customAttributeProvider.CustomAttributes[i].AttributeType.Namespace == @namespace)
return true;
}
return false;
}
}
Looking at the assembly we see that
DEFINE_INTERFACE_DISPATCH_STUB 4
00007FF627326BE0 mov r11,qword ptr [r10+8]
00007FF627326BE4 mov rax,qword ptr [rcx]
00007FF627326BE7 cmp rax,qword ptr [r11+20h]
00007FF627326BEB jne Attempt1 (07FF627326BF1h)
00007FF627326BED jmp qword ptr [r11+28h]
00007FF627326BF1 cmp rax,qword ptr [r11+30h]
00007FF627326BF5 jne Attempt1+0Ah (07FF627326BFBh)
00007FF627326BF7 jmp qword ptr [r11+38h]
00007FF627326BFB cmp rax,qword ptr [r11+40h]
00007FF627326BFF jne Attempt1+14h (07FF627326C05h)
00007FF627326C01 jmp qword ptr [r11+48h]
00007FF627326C05 cmp rax,qword ptr [r11+50h] <---- crashes here
00007FF627326C09 jne Attempt1+1Eh (07FF627326C0Fh)
00007FF627326C0B jmp qword ptr [r11+58h]
00007FF627326C0F jmp RhpInterfaceDispatchSlow (07FF627327380h)
00007FF627326C14 nop word ptr [rax+rax]
Note the previous probe locations are accessible. This one seems to be on a new page which is not accessible.
- (void**)(r11+48h) 0x000002cd88540ff8 {0x0000000000000000} void * *
0x0000000000000000 void *
- (void**)(r11+50h) 0x000002cd88541000 {???} void * *
<Unable to read memory> void *
This code seems to be where the crash happens : https://github.com/Unity-Technologies/runtime/blob/unity-main/src/coreclr/nativeaot/Runtime/amd64/StubDispatch.asm#L68
As a side note, we've had reports of the nativeaot'd il2cpp executable crashing on macOS arm64. This led to us recently switching back to using the coreclr il2cpp executable. You can see reports of this issue by Unity users
https://discussions.unity.com/t/6000-2-cant-build-with-unsafe-il2cpp-via-cli/1686652/17
https://discussions.unity.com/t/ci-compilations-throw-exit-code-139-only-macosx-builds/1683807
We've had 1 report of it internally. We've haven't collected any information from the macOS arm64 crash. Whether or not the macOS arm64 crash and the windows x64 crash are related I don't know. I thought I'd mention the macOS arm64 crash just in case.
Reproduction Steps
We don't have repro steps.
Expected behavior
il2cpp.exe doesn't crash
Actual behavior
il2cpp.exe crashes
Regression?
We don't know. It is suspicious that we just spotted the issue. We've been using the nativeaot'd il2cpp.exe on windows x64 since .NET 7. We are now on .NET8, we've used a few different versions of .NET8. Then again, this crash seems to be fairly rare so maybe we just haven't noticed.
Known Workarounds
No response
Configuration
Windows x64. The crash happened on a Windows 10 machine on our CI. We haven't tried to reproduce on windows 11.
We used the 8.0.204 .NET SDK to build the nativeaot'd il2cpp.exe. il2cpp.exe is targeting net8.
Other information
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
dotnet-policy-service commentedon Nov 14, 2025
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.
jkotas commentedon Nov 14, 2025
cc @davidwrighton
joncham commentedon Nov 14, 2025
I looked at two more crashes. Both manifest the same behavior of trying to read a memory address on a page boundary (0x1000 aligned) in the middle of the dispatch stub logic.
davidwrighton commentedon Nov 14, 2025
This appears to be some form of memory corruption. Notably, the allocator for these structures in NativeAOT is umm... not good and now having looked at it merits replacement with just about any other allocator, but one of its more interesting properties is that it should never allocate any memory which crosses a page boundary. Given that this fault is at a page crossing, something clearly has gone wrong. What is the value in the dump at r10+8, and r10? Also, what are the values at r11? (i.e. is there an obvious race condition to look at here)
So, I'd like to see the addresses from 0x2CD88540FB0 to 0x2CD88540FF0, and the data for the pointer in r10 and r10+8.
joncham commentedon Nov 14, 2025
mrvoorhe commentedon Nov 17, 2025
We ran il2cpp in a loop all weekend on a developers Windows 11 x64 machine. We saw a crash ~1 in every 5000 runs. All crashes match the same pattern, access violation on a new page. It occurs in multiple places.
jkotas commentedon Nov 17, 2025
Does it always occur in one of the RhpInterfaceDispatch methods, or does it occur in different methods?
joncham commentedon Nov 17, 2025
Always in
RhpInterfaceDispatch*. Always at a page aligned memory address.8 remaining items
jkotas commentedon Nov 18, 2025
Yes. This bug is ~15 years old. It can happen in all versions of NativeAOT and all versions of .NET Native for UWP.
jkotas commentedon Nov 18, 2025
The implementation checks that the value is not smaller than 4k. Do we need to worry about that? I am not able to tell.
runtime/src/coreclr/nativeaot/Runtime/inc/rhbinder.h
Line 218 in 57a83de
Otherwise, (1) seems to be the best servicing-grade fix.
This won't work.
ldapris armv8.3-a+. Our baseline is armv8-a.Directionally (not as the servicing fix), we may want to lean more into a static helper that computes the target followed by an indirect call. We have WIP implementation of that in #112406 for other reasons. Also, I expect that it is what we are going to use for wasm since the low-level tricks won't work there.
MichalStrehovsky commentedon Nov 18, 2025
I don't have better ideas - I agree with what Jan wrote, (1) seems like the best with respect to servicing. My hope with #112406 is/was that the static helper that computes the target would have better performance (due to it being more friendly to branch predictor than "jump into a helper that is used by every interface dispatch with the same cache size in the program").
Also cc @jakobbotsch
jkotas commentedon Nov 18, 2025
We can further tune the scheme to be friendlier to branch predictor. We may want to get some inspiration from Objective-C dispatch scheme. They use static helper and I believe that they have near zero mis-predicted branches in steady state (the only branch that needs predicting is the indirect call itself).
mrvoorhe commentedon Nov 19, 2025
I spent some time trying to come up with a test we can run on CI to flush this bug out. I thought I'd share my findings in case it helps pin down a way to reproduce.
I was trying to reproduce on macOS arm64, Linux, and Windows 10. Our CI machines are not as hefty as our developer machines. The linux and windows machines report either 4 or 8 cores from
Environment.ProcessorCount. I can't remember off hand, I don't think the exact number matters, the point being it's way less than 24 @joncham had when he reproduced locally.First I tried running two instance of
il2cppin parallel, running in a loop. Each il2cpp process will useEnvironment.ProcessorCountthreads. Not much luck. I ran for roughly 50hrs evenly split across the 3 platforms and there were no crashes.Next I tried running a single instance of il2cpp in a loop, but this time I had the il2cpp process use
Environment.ProcessorCount * 4threads. In roughly 50hrs Linux crashed once and Windows crashed once.Maybe it was a fluke or maybe the second approach does have better odds of reproducing. Just thought I'd share.
MichalStrehovsky commentedon Jan 7, 2026
Now that #122639 is getting close to merge - do we want to consider changing interface dispatch to use the new resolve helper everywhere to address this issue?
We might need to replace the cache with a hashtable (depending on measurements). If we use a hashtable, we already have one that we use for generic virtual methods. We might need a reader for it written in assembly so that we have good control over registers in the fast (cached) path.
Optimize AllocHeap: use new/delete with 4KB blocks and static allocat…
Fix race condition in cached interface dispatch stubs
MichalStrehovsky commentedon Apr 2, 2026
I don't think we need to worry about it in
RhpInterfaceDispatch*because we never go from initial to vtable to cache (it's only initial to cache), but it looks likeRhpVTableOffsetDispatchis probably vulnerable to the same race since the mechanism looks the same (we update the pointer to call and update the data in the cell hoping the called method will see the new data, but I assume there's a theoretical chance we call theRhpVTableOffsetDispatchand the cell contents is still the old one). It would be the same kind of race as callingRhpInterfaceDispatch*and not seeing a cache yet (seeing the initial state instead). If we have to protect from that ("detect if the cache pointer is both a cache pointer (the lower 2 bits are 0, and the cache size is the right size" above), we need to protect from it inRhpVTableOffsetDispatchtoo.Fix race condition in cached interface dispatch stubs
[release/10.0] Fix race condition in cached interface dispatch stubs (#…