]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
LJ_FR2: Fix stack checks in vararg calls.
authorMike Pall <mike>
Thu, 21 Sep 2023 03:19:55 +0000 (05:19 +0200)
committerMike Pall <mike>
Thu, 21 Sep 2023 03:19:55 +0000 (05:19 +0200)
Thanks to Peter Cawley. #1048

src/lj_def.h
src/lj_dispatch.c
src/vm_arm64.dasc
src/vm_mips64.dasc

index 1461d3d79333a4b52e486e6cfafd92e845e33d46..0d6c346bcc747059262af662f193a962d506e5d5 100644 (file)
@@ -69,7 +69,7 @@ typedef unsigned int uintptr_t;
 #define LJ_MAX_UPVAL   60              /* Max. # of upvalues. */
 
 #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. */
 
index 57809e6275f8f1d0ee2ed9becbd05d163d38cf45..b9748bba7fa63fadcc836fe9ef9cbd67ad4a4a5d 100644 (file)
@@ -453,7 +453,7 @@ static int call_init(lua_State *L, GCfunc *fn)
     int numparams = pt->numparams;
     int gotparams = (int)(L->top - L->base);
     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);
     numparams -= gotparams;
     return numparams >= 0 ? numparams : 0;
index 61a3ba6d8f6b4e947e4710090691bfc618f0a00d..3044a8ac4ecb8be8db39233ef0c0dfedfedc82a5 100644 (file)
@@ -3916,6 +3916,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
     |   add TMP2, BASE, RC
     |   add LFUNC:CARG3, CARG3, TMP0, lsl #47
     |  add RA, RA, RC
+    |  sub CARG1, CARG1, #8
     |   add TMP0, RC, #16+FRAME_VARG
     |   str LFUNC:CARG3, [TMP2], #8    // Store (tagged) copy of LFUNC.
     |    ldr KBASE, [PC, #-4+PC2PROTO(k)]
index 6c215f2bba9eba8a86350ed470b5c37e8fa22e46..ef0d901da9a17ca938b77e1fb55d63a5420ff6cb 100644 (file)
@@ -5396,6 +5396,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
     |   settp LFUNC:RB, TMP0
     |  daddu TMP0, RA, RC
     |   sd LFUNC:RB, 0(TMP1)           // Store (tagged) copy of LFUNC.
+    |  daddiu TMP2, TMP2, -8
     |   daddiu TMP3, RC, 16+FRAME_VARG
     |  sltu AT, TMP0, TMP2
     |    ld KBASE, -4+PC2PROTO(k)(PC)