-
Notifications
You must be signed in to change notification settings - Fork 5k
Crash in Mono when calling default method on generic interface (DIM) due to uninitialized vtable slot #113958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Tagging subscribers to this area: @steveisok, @vitek-karas |
A couple observations:
Probably there's a missing write barrier somewhere <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseMonoRuntime>true</UseMonoRuntime>
<SelfContained>true</SelfContained>
</PropertyGroup>
</Project> |
This feels very similar to #94437 - it feels like runtime/src/mono/mono/mini/mini-trampolines.c Line 478 in 27604b5
and then we use that location as the slot to patch runtime/src/mono/mono/mini/mini-trampolines.c Line 495 in 27604b5
and since it's not really the vtable but some unrelated memory, it sometimes has a NULL and sometimes a non-NULL. I had started a follow-up PR to try and add some extra assertions to the IMT slot calculation, but I don't remember why i never finished - whether it didn't work or i just got pulled away to something else: e2f058c |
In case of a generic interface, build_imt_slots calculate the vt_slot to find the index in the vtable for the implementation. Currently implementation assumed interface methods are either static or virtual, but it's possible to have private/sealed methods that won't end up as virtual. This is handled when building the vtable, by not including these methods, but we didn't handle that scenario when building the IMT slots, ending up with wrong vtable slot, potentially outside of allocated memory. Fixes dotnet#113958.
Description
When running a minimal test using a generic interface with default method implementations (DIM) on Mono (built from the dotnet/runtime repository), a crash occurs in mini-trampolines.c due to a NULL vtable slot during DIM invocation.
The crash happens intermittently, but is reproducible after a few repeated runs.
Reproduction Steps
cd runtime/src/mono make
Expected behavior
Program should print:
Actual behavior
Occasional crash with assertion:
Full log and stacktrace:
Regression?
Unknown. Reproduced on main of dotnet/runtime as of March 2025(ead91c5).
Known Workarounds
Configuration
Other information
The text was updated successfully, but these errors were encountered: