@@ -3172,7 +3172,7 @@ GenTree* Lowering::LowerDelegateInvoke(GenTreeCall* call)
3172
3172
#else // !TARGET_X86
3173
3173
// In case of helper dispatched tail calls, "thisptr" will be the third arg.
3174
3174
// The first two args are: real call target and addr of args copy routine.
3175
- const unsigned argNum = 2 ;
3175
+ const unsigned argNum = 2 ;
3176
3176
#endif // !TARGET_X86
3177
3177
3178
3178
fgArgTabEntry* thisArgTabEntry = comp->gtArgEntryByArgNum (call, argNum);
@@ -3439,7 +3439,7 @@ void Lowering::InsertPInvokeMethodProlog()
3439
3439
#if defined(TARGET_X86) || defined(TARGET_ARM)
3440
3440
GenTreeCall::Use* argList = comp->gtNewCallArgs (frameAddr);
3441
3441
#else
3442
- GenTreeCall::Use* argList = comp->gtNewCallArgs (frameAddr, PhysReg (REG_SECRET_STUB_PARAM));
3442
+ GenTreeCall::Use* argList = comp->gtNewCallArgs (frameAddr, PhysReg (REG_SECRET_STUB_PARAM));
3443
3443
#endif
3444
3444
3445
3445
GenTree* call = comp->gtNewHelperCallNode (CORINFO_HELP_INIT_PINVOKE_FRAME, TYP_I_IMPL, argList);
@@ -3620,9 +3620,18 @@ void Lowering::InsertPInvokeCallProlog(GenTreeCall* call)
3620
3620
GenTree* frameAddr =
3621
3621
new (comp, GT_LCL_VAR_ADDR) GenTreeLclVar (GT_LCL_VAR_ADDR, TYP_BYREF, comp->lvaInlinedPInvokeFrameVar );
3622
3622
3623
+ #if defined(TARGET_X86) && !defined(UNIX_X86_ABI)
3624
+ // On x86 targets, PInvoke calls need the size of the stack args in InlinedCallFrame.m_Datum.
3625
+ // This is because the callee pops stack arguments, and we need to keep track of this during stack
3626
+ // walking
3627
+ const unsigned numStkArgBytes = call->fgArgInfo ->GetNextSlotNum () * TARGET_POINTER_SIZE;
3628
+ GenTree* stackBytes = comp->gtNewIconNode (numStkArgBytes, TYP_INT);
3629
+ GenTreeCall::Use* args = comp->gtNewCallArgs (frameAddr, stackBytes);
3630
+ #else
3631
+ GenTreeCall::Use* args = comp->gtNewCallArgs (frameAddr);
3632
+ #endif
3623
3633
// Insert call to CORINFO_HELP_JIT_PINVOKE_BEGIN
3624
- GenTree* helperCall =
3625
- comp->gtNewHelperCallNode (CORINFO_HELP_JIT_PINVOKE_BEGIN, TYP_VOID, comp->gtNewCallArgs (frameAddr));
3634
+ GenTree* helperCall = comp->gtNewHelperCallNode (CORINFO_HELP_JIT_PINVOKE_BEGIN, TYP_VOID, args);
3626
3635
3627
3636
comp->fgMorphTree (helperCall);
3628
3637
BlockRange ().InsertBefore (insertBefore, LIR::SeqTree (comp, helperCall));
0 commit comments