-
Notifications
You must be signed in to change notification settings - Fork 516
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
Incorrect handling of nil
blocks in Managed Static Registrar
#20920
Comments
Repro: https://github.com/filipnavara/ios-msr-menu-repro Click anywhere on the main screen, it opens menu. Dismiss the menu by clicking outside it => crash. |
Affects both NativeAOT and MonoVM. |
Presumably the fix is just to flip the order of these two conditions: xamarin-macios/src/ObjCRuntime/Runtime.cs Lines 2590 to 2594 in 261a603
The MSR generates this code: [UnmanagedCallersOnly(EntryPoint = "callback_0_menu_repro_AppDelegate_ViewController_DismissViewController")]
public unsafe static void callback_0_menu_repro_AppDelegate_ViewController_DismissViewController(nint pobj, nint sel, byte p0, nint p1, nint* exception_gchandle)
{
try
{
ViewController nSObject = Runtime.GetNSObject<ViewController>(pobj, sel, (RuntimeMethodHandle)/*OpCode not supported: LdMemberToken*/, true);
nint num = BlockLiteral.Copy(p1);
nSObject.DismissViewController(p0 != 0, (Action)Runtime.ReleaseBlockWhenDelegateIsCollected(num, Trampolines.NIDAction.Create(num)));
}
catch (Exception ex)
{
*exception_gchandle = Runtime.AllocGCHandle(ex);
}
} The trampolines were always created with the [UnmanagedCallersOnly(EntryPoint = "callback_0_menu_repro_AppDelegate_ViewController_DismissViewController")]
public unsafe static void callback_0_menu_repro_AppDelegate_ViewController_DismissViewController(nint pobj, nint sel, byte p0, nint p1, nint* exception_gchandle)
{
try
{
ViewController nSObject = Runtime.GetNSObject<ViewController>(pobj, sel, (RuntimeMethodHandle)/*OpCode not supported: LdMemberToken*/, true);
nint num = BlockLiteral.Copy(p1);
nSObject.DismissViewController(p0 != 0, (Action)Runtime.ReleaseBlockWhenDelegateIsCollected(num, Trampolines.NIDAction.Create(num)));
}
catch (Exception ex)
{
*exception_gchandle = Runtime.AllocGCHandle(ex);
}
} |
Since this is an absolute blocker for us I created a custom ILLink step to patch the code: https://github.com/emclient/MailClient.Linker |
nil
blocks in Managed Static Registrar
/cc: @rolfbjarne |
We started experimenting with MSR in release builds of our app and we can reproducibly hit this on device when going through a certain UI path:
The code comes from MAUI:
https://github.com/dotnet/maui/blob/515c8986efefc83a7b21b30f32a8d44dd9748959/src/Controls/src/Core/Platform/iOS/ControlsModalWrapper.cs#L88-L91
It makes me wonder what happens if
DismissViewController
is called withcompletionHandler == null
and how would that get marshalled between ObjC and C#.The text was updated successfully, but these errors were encountered: