-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
UnmanagedCallersOnly does not work when called from a P/Invoke in Release mode #38192
Comments
+1, happens to me in similar situation with |
This is caused by runtime/src/coreclr/src/jit/lower.cpp Line 4058 in f004b91
This redundant operation is actively harmful for |
@dotnet/jit-contrib Could you please take a look at this soon? |
Talking this over with @jkotas a repro using no Win32 APIs is below. I am planning on adding additional test cases for function pointers soon and I will make sure this case is added. Managed: [DllImport(...)]
static extern void Test(void* callback);
[DllImport(...)]
static extern int Test2(int a);
[UnmanagedCallersOnly]
static int Callback(int a)
{
// Inlined P/Invoke
return Test2(a);
}
static void Main(string[] args)
{
var cb = (delegate* stdcall<int, int>)(delegate* managed<int, int>)&Callback;
Test(cb);
} Unmanaged: EXPORT_FUNC void CALLCONV Test(int (CALLCONV *cb)(int))
{
// Multiple calls to callback.
::printf("Test(): %d\n", cb(10));
::printf("Test(): %d\n", cb(20)); // Works if commented out.
}
EXPORT_FUNC int CALLCONV Test2(int a)
{
::printf("Test2(%d)\n", a);
return a;
} |
Does this issue explain OSX failures #38189? |
I am adding a disabled test in #38195 that can be uncommented and used for validation when this issue is fixed. |
@dotnet/jit-contrib I'll look at this; let me know if any of you have already begun working on it. |
The comment indicated this was necessary to keep the FrameListRoot live, but the code generated by `CreateFrameLinkUpdate` will do that if needed. Fix dotnet#38192
* Don't set GCState to 1 in PInvoke Epilog Remove the incorrect setting of GCState and fix the liveness computation for compLvFrameListRoot for tailcalls. Fix #38192
As per the title, the following program succeeds if run under
Debug
but fails underRelease
The csproj should resemble the following so function pointers can be used:
A more complete program will successfully display the window, handle the callbacks etc in
Debug
. Additionally it will all work as expected underRelease
if usingMarshal.GetFunctionPointerForDelegate
instead.However, under
Release
when usingUnmanagedCallersOnly
, it fails with the following:The text was updated successfully, but these errors were encountered: