Merge pull request #1633 from BrzVlad/fix-w32-pinvoke
authorZoltan Varga <vargaz@gmail.com>
Tue, 17 Mar 2015 01:34:41 +0000 (21:34 -0400)
committerZoltan Varga <vargaz@gmail.com>
Tue, 17 Mar 2015 01:34:41 +0000 (21:34 -0400)
[x86] Handle stack pop done by native stdcalls.

mono/mini/mini-x86.c

index 9d42da2b5d30874c8240c5c6142d088fd1253002..474ea72c771723c0e372bb5b8547a8aff42d9dd0 100644 (file)
@@ -586,17 +586,20 @@ get_call_info_internal (MonoGenericSharingContext *gsctx, CallInfo *cinfo, MonoM
                add_general (&gr, param_regs, &stack_size, &cinfo->sig_cookie);
        }
 
+       if (cinfo->vtype_retaddr) {
+               /* if the function returns a struct on stack, the called method already does a ret $0x4 */
+               cinfo->callee_stack_pop = 4;
+       } else if (CALLCONV_IS_STDCALL (sig) && sig->pinvoke) {
+               /* Have to compensate for the stack space popped by the native callee */
+               cinfo->callee_stack_pop = stack_size;
+       }
+
        if (mono_do_x86_stack_align && (stack_size % MONO_ARCH_FRAME_ALIGNMENT) != 0) {
                cinfo->need_stack_align = TRUE;
                cinfo->stack_align_amount = MONO_ARCH_FRAME_ALIGNMENT - (stack_size % MONO_ARCH_FRAME_ALIGNMENT);
                stack_size += cinfo->stack_align_amount;
        }
 
-       if (cinfo->vtype_retaddr) {
-               /* if the function returns a struct on stack, the called method already does a ret $0x4 */
-               cinfo->callee_stack_pop = 4;
-       }
-
        cinfo->stack_usage = stack_size;
        cinfo->reg_usage = gr;
        cinfo->freg_usage = fr;