public sealed override bool GeneratesPInvoke(MethodDesc method) { // PInvokes depend on details of the core library, so for now only compile them if: // 1) We're compiling the core library module, or // 2) We're compiling any module, and no marshalling is needed // // TODO Future: consider compiling PInvokes with complex marshalling in version bubble // mode when the core library is included in the bubble. Debug.Assert(method is EcmaMethod); // If the PInvoke is declared on an external module, we can only compile it if // that module is part of the version bubble. if (!_versionBubbleModuleSet.Contains(((EcmaMethod)method).Module)) { return(false); } if (((EcmaMethod)method).Module.Equals(method.Context.SystemModule)) { return(true); } return(!Marshaller.IsMarshallingRequired(method)); }
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(); } if (_targetMethod.HasCustomAttribute("System.Runtime.InteropServices", "LCIDConversionAttribute")) { throw new NotSupportedException(); } PInvokeILCodeStreams pInvokeILCodeStreams = new PInvokeILCodeStreams(); ILEmitter emitter = pInvokeILCodeStreams.Emitter; ILCodeStream marshallingCodestream = pInvokeILCodeStreams.MarshallingCodeStream; 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);*/ // Marshal the arguments for (int i = 0; i < _marshallers.Length; i++) { _marshallers[i].EmitMarshallingIL(pInvokeILCodeStreams); } 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.EmitLabel(lReturn); _marshallers[0].LoadReturnValue(cleanupCodestream); cleanupCodestream.Emit(ILOpcode.ret); return(new PInvokeILStubMethodIL((ILStubMethodIL)emitter.Link(_targetMethod))); }
public override bool GeneratesPInvoke(MethodDesc method) { // PInvokes depend on details of the core library, so for now only compile them if: // 1) We're compiling the core library module, or // 2) We're compiling any module, and no marshalling is needed // // TODO Future: consider compiling PInvokes with complex marshalling in version bubble // mode when the core library is included in the bubble. Debug.Assert(method is EcmaMethod); if (((EcmaMethod)method).Module.Equals(method.Context.SystemModule)) { return(true); } return(!Marshaller.IsMarshallingRequired(method)); }
public PInvokeILStubMethodIL(ILStubMethodIL methodIL) : base(methodIL) { IsMarshallingRequired = Marshaller.IsMarshallingRequired(methodIL.OwningMethod); }
public sealed override bool GeneratesPInvoke(MethodDesc method) { return(!Marshaller.IsMarshallingRequired(method)); }