-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[mono] invoke delegate method thunk hit asset. #83823
Comments
this line should set runtime/src/mono/mono/metadata/marshal.c Line 6192 in 316d286
and the stacktrace:
|
@lambdageek @vargaz @BrzVlad can you take the time to check this? |
Tagging subscribers to this area: @BrzVlad, @kotlarmilos Issue DetailsDescriptionwe embed mono, use jit mix with interp, use we get MonoDelegate invoke method thunk and invoke it, it hit asset at line:
Reproduction Steps// pass delegate from c# to c. MonoMethod* InvokeMethod = mono_get_delegate_invoke(DelegateClass); void * ThunkMethod = mono_method_get_unmanaged_thunk(InvokeMethod ); it works well in aot_interp or jit mode. Expected behaviorwork correctly Actual behaviorcrash Regression?no Known WorkaroundsNo response Configurationdotnet7.0.3 mono Other informationNo response
|
any idea about it? |
It would be better to use normal apis like passing delegates directly to native code, Marshal.GetFunctionPointerForDelegate, [UnmanagedCallersOnly] etc. |
got it, but hope you can take the time to fix this problem, make monovm more and more robust. |
internal class DelegateInvokeTests
{
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void InvokeDelegate(IntPtr d6);
[Test("DelegateInvoke")]
private static void Entry()
{
DelegateInvokeTests instance = new DelegateInvokeTests();
var a = new Func<int>(instance.DelegateIntVoid);
InvokeDelegate(Marshal.GetFunctionPointerForDelegate(a));
}
private int DelegateIntVoid() { return 0; }
} // add internal call
mono_add_internal_call("DelegateInvokeTests::InvokeDelegate", &InvokeDelegate);
void InvokeDelegate(void* InDelegate)
{
int (*Delegate)() = (int(*)())InDelegate;
int Result = Delegate(); // when execute this line will cause crash: 0xC0000005
} I have try the above code in jit mode on win-x64 .net8.0.0 version, it will hit crash. @vargaz can you help me? |
I found the delegate function pointer signature is:
but we don't keep referenece the target in native side, so this solution is useless. and the |
Description
we embed mono, use jit mix with interp, use
mono_jit_set_aot_mode(MONO_AOT_MODE_INTERP_ONLY);
we get MonoDelegate invoke method thunk and invoke it, it hit asset at line:
runtime/src/mono/mono/metadata/marshal-lightweight.c
Line 2015 in 07f5fca
Reproduction Steps
// pass delegate from c# to c.
MonoDelegate* InDelegate;
MonoClass* DelegateClass = mono_object_get_class(InDelegate);
MonoMethod* InvokeMethod = mono_get_delegate_invoke(DelegateClass);
void * ThunkMethod = mono_method_get_unmanaged_thunk(InvokeMethod );
typedef bool(STDCALL ThunkWithMonoObjectDeclaration) (MonoObject, float, MonoObject**);
bool result = (ThunkWithMonoObjectDeclaration)ThunkMethod(InDelegate, 1, nullptr); // hit crash
it works well in aot_interp or jit mode.
Expected behavior
work correctly
Actual behavior
crash
Regression?
no
Known Workarounds
No response
Configuration
dotnet7.0.3 mono
Other information
No response
The text was updated successfully, but these errors were encountered: