mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
FFI: Fix stack adjustment for calls to stdcall/fastcall functions.
This commit is contained in:
parent
ff7e9bc464
commit
e162d8cef0
@ -593,13 +593,14 @@ static void asm_callx(ASMState *as, IRIns *ir)
|
|||||||
CCallInfo ci;
|
CCallInfo ci;
|
||||||
IRRef func;
|
IRRef func;
|
||||||
IRIns *irf;
|
IRIns *irf;
|
||||||
|
int32_t spadj = 0;
|
||||||
ci.flags = asm_callx_flags(as, ir);
|
ci.flags = asm_callx_flags(as, ir);
|
||||||
asm_collectargs(as, ir, &ci, args);
|
asm_collectargs(as, ir, &ci, args);
|
||||||
asm_setupresult(as, ir, &ci);
|
asm_setupresult(as, ir, &ci);
|
||||||
#if LJ_32
|
#if LJ_32
|
||||||
/* Have to readjust stack after non-cdecl calls due to callee cleanup. */
|
/* Have to readjust stack after non-cdecl calls due to callee cleanup. */
|
||||||
if ((ci.flags & CCI_CC_MASK) != CCI_CC_CDECL)
|
if ((ci.flags & CCI_CC_MASK) != CCI_CC_CDECL)
|
||||||
emit_spsub(as, 4 * asm_count_call_slots(as, &ci, args));
|
spadj = 4 * asm_count_call_slots(as, &ci, args);
|
||||||
#endif
|
#endif
|
||||||
func = ir->op2; irf = IR(func);
|
func = ir->op2; irf = IR(func);
|
||||||
if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }
|
if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }
|
||||||
@ -608,7 +609,10 @@ static void asm_callx(ASMState *as, IRIns *ir)
|
|||||||
/* Use a (hoistable) non-scratch register for indirect calls. */
|
/* Use a (hoistable) non-scratch register for indirect calls. */
|
||||||
RegSet allow = (RSET_GPR & ~RSET_SCRATCH);
|
RegSet allow = (RSET_GPR & ~RSET_SCRATCH);
|
||||||
Reg r = ra_alloc1(as, func, allow);
|
Reg r = ra_alloc1(as, func, allow);
|
||||||
|
if (LJ_32) emit_spsub(as, spadj); /* Above code may cause restores! */
|
||||||
emit_rr(as, XO_GROUP5, XOg_CALL, r);
|
emit_rr(as, XO_GROUP5, XOg_CALL, r);
|
||||||
|
} else if (LJ_32) {
|
||||||
|
emit_spsub(as, spadj);
|
||||||
}
|
}
|
||||||
asm_gencall(as, &ci, args);
|
asm_gencall(as, &ci, args);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user