From dbf507ba871566b5a989b353744976f6560b3611 Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Sat, 24 Feb 2018 20:52:01 +0200 Subject: [PATCH] Fix calling convention gap in DynamicILGenerator.EmitCalli (#16546) --- .../System/Reflection/Emit/DynamicILGenerator.cs | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs b/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs index 5570233..5ecf0be 100644 --- a/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs +++ b/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs @@ -241,6 +241,41 @@ namespace System.Reflection.Emit PutInteger4(token); } + public override void EmitCalli(OpCode opcode, CallingConvention unmanagedCallConv, Type returnType, Type[] parameterTypes) + { + int stackchange = 0; + int cParams = 0; + int i; + SignatureHelper sig; + + if (parameterTypes != null) + cParams = parameterTypes.Length; + + sig = SignatureHelper.GetMethodSigHelper(unmanagedCallConv, returnType); + + if (parameterTypes != null) + for (i = 0; i < cParams; i++) + sig.AddArgument(parameterTypes[i]); + + // If there is a non-void return type, push one. + if (returnType != typeof(void)) + stackchange++; + + // Pop off arguments if any. + if (parameterTypes != null) + stackchange -= cParams; + + // Pop the native function pointer. + stackchange--; + UpdateStackSize(OpCodes.Calli, stackchange); + + EnsureCapacity(7); + Emit(OpCodes.Calli); + + int token = GetTokenForSig(sig.GetSignature(true)); + PutInteger4(token); + } + public override void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[] optionalParameterTypes) { if (methodInfo == null) @@ -305,7 +340,7 @@ namespace System.Reflection.Emit UpdateStackSize(opcode, stackchange); } - int token = GetTokenForSig(signature.GetSignature(true)); ; + int token = GetTokenForSig(signature.GetSignature(true)); PutInteger4(token); } -- 2.7.4