From db09743948c766f502a4da30e9a19a116757db4b Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Thu, 27 May 2021 19:04:31 +0600 Subject: [PATCH] Do not support reverse direction for marshalling of VARIANT --- .../Common/TypeSystem/Interop/IL/Marshaller.Aot.cs | 10 ++++++++++ .../tools/Common/TypeSystem/Interop/IL/Marshaller.cs | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/Marshaller.Aot.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/Marshaller.Aot.cs index 1f4e77d59dbd..6a77dbffcbcc 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/Marshaller.Aot.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/Marshaller.Aot.cs @@ -1079,6 +1079,11 @@ protected override void AllocManagedToNative(ILCodeStream codeStream) protected override void TransformManagedToNative(ILCodeStream codeStream) { + if (this.MarshalDirection == MarshalDirection.Reverse) + { + throw new NotSupportedException(); + } + ILEmitter emitter = _ilCodeStreams.Emitter; LoadManagedValue(codeStream); @@ -1090,6 +1095,11 @@ protected override void TransformManagedToNative(ILCodeStream codeStream) protected override void TransformNativeToManaged(ILCodeStream codeStream) { + if (this.MarshalDirection == MarshalDirection.Reverse) + { + throw new NotSupportedException(); + } + ILEmitter emitter = _ilCodeStreams.Emitter; LoadNativeAddr(codeStream); diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/Marshaller.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/Marshaller.cs index 46c53157b465..aefe2efca3fd 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/Marshaller.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/Marshaller.cs @@ -1438,6 +1438,9 @@ protected override void AllocAndTransformManagedToNative(ILCodeStream codeStream codeStream.Emit(ILOpcode.brfalse, pLoadFalseLabel); codeStream.EmitLdc(_trueValue); codeStream.Emit(ILOpcode.br, pDoneLabel); +#if DEBUG + codeStream.Emit(ILOpcode.pop); // keep the simple stack level calculator happy +#endif // DEBUG codeStream.EmitLabel(pLoadFalseLabel); codeStream.EmitLdc(0);