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

Fix EH handling in PInvoke stubs and remove workaround #327

Merged
merged 3 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/coreclr/src/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6393,6 +6393,13 @@ bool Compiler::impCanPInvokeInlineCallSite(BasicBlock* block)
// jit\jit64\ebvts\mcpp\sources2\ijw\__clrcall\vector_ctor_dtor.02\deldtor_clr.exe
if (block->hasTryIndex())
{
// This does not apply to the raw pinvoke call that is inside the pinvoke
// ILStub. In this case, we have to inline the raw pinvoke call into the stub,
// otherwise we would end up with a stub that recursively calls itself, and end
// up with a stack overflow.
if (opts.jitFlags->IsSet(JitFlags::JIT_FLAG_IL_STUB) && opts.ShouldUsePInvokeHelpers())
return true;

return false;
}
#endif // _TARGET_64BIT_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ private void EmitPInvokeCall(PInvokeILCodeStreams ilCodeStreams)

private MethodIL EmitIL()
{
// Temp workaround to disable PInvoke stubs that require marshalling.
// https://github.com/dotnet/runtime/issues/248
{
if (Marshaller.IsMarshallingRequired(_targetMethod))
throw new NotSupportedException();
}

if (!_importMetadata.Flags.PreserveSig)
throw new NotSupportedException();

Expand All @@ -95,13 +88,11 @@ private MethodIL EmitIL()
ILCodeStream unmarshallingCodestream = pInvokeILCodeStreams.UnmarshallingCodestream;
ILCodeStream cleanupCodestream = pInvokeILCodeStreams.CleanupCodeStream;

/* Temp workaround: disable EH blocks because of https://github.com/dotnet/runtime/issues/248

// Marshalling is wrapped in a finally block to guarantee cleanup
ILExceptionRegionBuilder tryFinally = emitter.NewFinallyRegion();

marshallingCodestream.BeginTry(tryFinally);
cleanupCodestream.BeginHandler(tryFinally);*/
cleanupCodestream.BeginHandler(tryFinally);

// Marshal the arguments
for (int i = 0; i < _marshallers.Length; i++)
Expand All @@ -112,12 +103,11 @@ private MethodIL EmitIL()
EmitPInvokeCall(pInvokeILCodeStreams);

ILCodeLabel lReturn = emitter.NewCodeLabel();
/* Temp workaround: disable EH blocks because of https://github.com/dotnet/runtime/issues/248
unmarshallingCodestream.Emit(ILOpcode.leave, lReturn);
unmarshallingCodestream.EndTry(tryFinally);

cleanupCodestream.Emit(ILOpcode.endfinally);
cleanupCodestream.EndHandler(tryFinally);*/
cleanupCodestream.EndHandler(tryFinally);

cleanupCodestream.EmitLabel(lReturn);

Expand Down