LJ_FR2: Fix stack checks in vararg calls.

Thanks to Peter Cawley. #1048
This commit is contained in:
Mike Pall 2023-09-21 05:19:55 +02:00
parent 234dbc481e
commit d1a2fef8a8
4 changed files with 4 additions and 2 deletions

View File

@ -69,7 +69,7 @@ typedef unsigned int uintptr_t;
#define LJ_MAX_UPVAL 60 /* Max. # of upvalues. */ #define LJ_MAX_UPVAL 60 /* Max. # of upvalues. */
#define LJ_MAX_IDXCHAIN 100 /* __index/__newindex chain limit. */ #define LJ_MAX_IDXCHAIN 100 /* __index/__newindex chain limit. */
#define LJ_STACK_EXTRA (5+2*LJ_FR2) /* Extra stack space (metamethods). */ #define LJ_STACK_EXTRA (5+3*LJ_FR2) /* Extra stack space (metamethods). */
#define LJ_NUM_CBPAGE 1 /* Number of FFI callback pages. */ #define LJ_NUM_CBPAGE 1 /* Number of FFI callback pages. */

View File

@ -453,7 +453,7 @@ static int call_init(lua_State *L, GCfunc *fn)
int numparams = pt->numparams; int numparams = pt->numparams;
int gotparams = (int)(L->top - L->base); int gotparams = (int)(L->top - L->base);
int need = pt->framesize; int need = pt->framesize;
if ((pt->flags & PROTO_VARARG)) need += 1+gotparams; if ((pt->flags & PROTO_VARARG)) need += 1+LJ_FR2+gotparams;
lj_state_checkstack(L, (MSize)need); lj_state_checkstack(L, (MSize)need);
numparams -= gotparams; numparams -= gotparams;
return numparams >= 0 ? numparams : 0; return numparams >= 0 ? numparams : 0;

View File

@ -3916,6 +3916,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
| add TMP2, BASE, RC | add TMP2, BASE, RC
| add LFUNC:CARG3, CARG3, TMP0, lsl #47 | add LFUNC:CARG3, CARG3, TMP0, lsl #47
| add RA, RA, RC | add RA, RA, RC
| sub CARG1, CARG1, #8
| add TMP0, RC, #16+FRAME_VARG | add TMP0, RC, #16+FRAME_VARG
| str LFUNC:CARG3, [TMP2], #8 // Store (tagged) copy of LFUNC. | str LFUNC:CARG3, [TMP2], #8 // Store (tagged) copy of LFUNC.
| ldr KBASE, [PC, #-4+PC2PROTO(k)] | ldr KBASE, [PC, #-4+PC2PROTO(k)]

View File

@ -5396,6 +5396,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
| settp LFUNC:RB, TMP0 | settp LFUNC:RB, TMP0
| daddu TMP0, RA, RC | daddu TMP0, RA, RC
| sd LFUNC:RB, 0(TMP1) // Store (tagged) copy of LFUNC. | sd LFUNC:RB, 0(TMP1) // Store (tagged) copy of LFUNC.
| daddiu TMP2, TMP2, -8
| daddiu TMP3, RC, 16+FRAME_VARG | daddiu TMP3, RC, 16+FRAME_VARG
| sltu AT, TMP0, TMP2 | sltu AT, TMP0, TMP2
| ld KBASE, -4+PC2PROTO(k)(PC) | ld KBASE, -4+PC2PROTO(k)(PC)