Skip to content
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

[Crossgen2] PInvoke stubs with EH blocks cause a runtime assert when an exception is thrown #248

Closed
fadimounir opened this issue Nov 25, 2019 · 0 comments

Comments

@fadimounir
Copy link
Contributor

fadimounir commented Nov 25, 2019

Simple repro (make NativeMethod2 throw a divide-by-zero exception):

        [DllImport("nativelib")]
        public extern static int NativeMethod1(int a);
        [DllImport("nativelib")]
        [MethodImpl(MethodImplOptions.NoInlining)]
        public extern static int NativeMethod2(int a);
        [DllImport("nativelib")]
        [MethodImpl(MethodImplOptions.NoInlining)]
        public extern static int NativeMethod3(int a);

        static void TestPInvokeSimple()
        {
            for (int i = 0; i < 4; i++)
            {
                var a = NativeMethod1(1);
                Console.WriteLine("NativeMethod1 = " + a);

                try
                {
                    a = NativeMethod2(0);
                    Console.WriteLine("NativeMethod2 = " + a);
                }
                catch (Exception ex) 
                {
                    Console.WriteLine(ex); 
                }

                a = NativeMethod3(1);
                Console.WriteLine("NativeMethod3 = " + a);
            }
        }

Causes the following assert after the catch block executes:

Assert failure(PID 20440 [0x00004fd8], Thread: 4548 [0x11c4]): false

CORECLR! ExceptionTracker::UpdateNonvolatileRegisters + 0x17B (0x00007fff`0284fa0b)
CORECLR! FixNonvolatileRegisters + 0x287 (0x00007fff`028430a7)
CORECLR! ProcessCLRException + 0xE43 (0x00007fff`02852683)
NTDLL! chkstk + 0x19F (0x00007fff`8e5c127f)
NTDLL! RtlUnwindEx + 0x522 (0x00007fff`8e53da32)
CORECLR! ClrUnwindEx + 0x88 (0x00007fff`0283e768)
CORECLR! ProcessCLRException + 0xBE1 (0x00007fff`02852421)
NTDLL! chkstk + 0x11F (0x00007fff`8e5c11ff)
NTDLL! RtlRaiseException + 0x399 (0x00007fff`8e58a289)
NTDLL! KiUserExceptionDispatcher + 0x2E (0x00007fff`8e5bfe6e)
    File: D:\GIT\runtime\src\coreclr\src\vm\exceptionhandling.cpp Line: 494
@fadimounir fadimounir self-assigned this Nov 25, 2019
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-ReadyToRun-coreclr untriaged New issue has not been triaged by the area owner labels Nov 25, 2019
@fadimounir fadimounir added area-crossgen2-coreclr and removed untriaged New issue has not been triaged by the area owner labels Nov 25, 2019
@fadimounir fadimounir added the bug label Nov 25, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants