Fixing 23941 (#24199)
authorFadi Hanna <fadim@microsoft.com>
Thu, 25 Apr 2019 14:17:19 +0000 (07:17 -0700)
committerGitHub <noreply@github.com>
Thu, 25 Apr 2019 14:17:19 +0000 (07:17 -0700)
commite966022128c67163e04be4ab2360d314d7d9c062
treeadc79d52d94ebcbd826e8065ff2360ac88f719d0
parent4dc324887a85bc90ef6830b2d27ba49c31058d72
Fixing 23941 (#24199)

* Fixing 23941

The issue here is that in R2R code, unlike jitted IL code, the pinvoke calls are wrapped by a pair of calls to the JIT_PInvokeBegin and JIT_PInvokeEnd helpers, which link and unlink the InlinedCallFrame to the current thread. We do not initialize and link the ICF in the method prolog, and unlink it in the epilog, like jitted code does. We do this in the JIT helpers, right before/after the pinvoke call.
When an exception is thrown, the JIT_PInvokeEnd helper will be skipped since execution will resume at the nearest valid catch block, and the ICF will remain linked to the thread, which poses a problem if the method attempts another pinvoke operation (it will try to link the ICF which is already the top frame, and we'll end up in an infinite loop). Therefore, for the R2R case, we need to pop the ICF from the chain during exception unwinding.
src/vm/codeman.cpp
src/vm/codeman.h
src/vm/exceptionhandling.cpp
src/vm/i386/excepx86.cpp
tests/src/Interop/NativeLibraryResolveCallback/CallbackStressTest.cs [new file with mode: 0644]
tests/src/Interop/NativeLibraryResolveCallback/CallbackStressTest.csproj [new file with mode: 0644]
tests/src/Interop/NativeLibraryResolveCallback/CallbackTests.csproj