aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2026-06-16 11:13:38 +0200
committerMike Pall <mike>2026-06-16 11:13:38 +0200
commit0bf26146d6deb15dcb8e02bdb6afe5ed8f4d813f (patch)
tree4f22a908d418b1b265f358be8b10e0b4fe8f07c2
parent194d7f2d635a11193177f0ed820ae419148f0b70 (diff)
parentd2c1327f57dc96f6ed8b11474f3bc5e09a9d227a (diff)
downloadluajit-0bf26146d6deb15dcb8e02bdb6afe5ed8f4d813f.tar.gz
luajit-0bf26146d6deb15dcb8e02bdb6afe5ed8f4d813f.tar.bz2
luajit-0bf26146d6deb15dcb8e02bdb6afe5ed8f4d813f.zip
Merge branch 'master' into v2.1
-rw-r--r--src/lj_state.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/lj_state.c b/src/lj_state.c
index 0b997c6e8..db7118ee2 100644
--- a/src/lj_state.c
+++ b/src/lj_state.c
@@ -37,8 +37,9 @@
37#define LJ_STACK_MAX LUAI_MAXSTACK /* Max. stack size. */ 37#define LJ_STACK_MAX LUAI_MAXSTACK /* Max. stack size. */
38#define LJ_STACK_START (2*LJ_STACK_MIN) /* Starting stack size. */ 38#define LJ_STACK_START (2*LJ_STACK_MIN) /* Starting stack size. */
39#define LJ_STACK_MAXEX (LJ_STACK_MAX + 1 + LJ_STACK_EXTRA) 39#define LJ_STACK_MAXEX (LJ_STACK_MAX + 1 + LJ_STACK_EXTRA)
40#define LJ_STACK_ERREX (1 + 2*LJ_STACK_MIN) /* Extra for error handling. */
40 41
41/* Explanation of LJ_STACK_EXTRA: 42/* Explanation for LJ_STACK_EXTRA:
42** 43**
43** Calls to metamethods store their arguments beyond the current top 44** Calls to metamethods store their arguments beyond the current top
44** without checking for the stack limit. This avoids stack resizes which 45** without checking for the stack limit. This avoids stack resizes which
@@ -51,6 +52,11 @@
51** slots above top, but then mobj is always a function. So we can get by 52** slots above top, but then mobj is always a function. So we can get by
52** with 5 extra slots. 53** with 5 extra slots.
53** LJ_FR2: We need 2 more slots for the frame PC and the continuation PC. 54** LJ_FR2: We need 2 more slots for the frame PC and the continuation PC.
55**
56** Explanation for LJ_STACK_ERREX:
57**
58** The 1 is space for the error message, and 2 * LJ_STACK_MIN is for
59** the lj_state_checkstack() call in lj_err_run().
54*/ 60*/
55 61
56/* Resize stack slots and adjust pointers in state. */ 62/* Resize stack slots and adjust pointers in state. */
@@ -83,7 +89,8 @@ static void resizestack(lua_State *L, MSize n)
83/* Relimit stack after error, in case the limit was overdrawn. */ 89/* Relimit stack after error, in case the limit was overdrawn. */
84void lj_state_relimitstack(lua_State *L) 90void lj_state_relimitstack(lua_State *L)
85{ 91{
86 if (L->stacksize > LJ_STACK_MAXEX && L->top-tvref(L->stack) < LJ_STACK_MAX-1) 92 if (L->stacksize > LJ_STACK_MAXEX &&
93 L->top-tvref(L->stack) < LJ_STACK_MAX - 1 - LJ_STACK_ERREX)
87 resizestack(L, LJ_STACK_MAX); 94 resizestack(L, LJ_STACK_MAX);
88} 95}
89 96
@@ -129,11 +136,9 @@ void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need)
129 /* An error handler might want to inspect the stack overflow error, but 136 /* An error handler might want to inspect the stack overflow error, but
130 ** will need some stack space to run in. We give it a stack size beyond 137 ** will need some stack space to run in. We give it a stack size beyond
131 ** the normal limit in order to do so, then rely on lj_state_relimitstack 138 ** the normal limit in order to do so, then rely on lj_state_relimitstack
132 ** calls during unwinding to bring us back to a convential stack size. 139 ** calls during unwinding to bring us back to a conventional stack size.
133 ** The + 1 is space for the error message, and 2 * LUA_MINSTACK is for
134 ** the lj_state_checkstack() call in lj_err_run().
135 */ 140 */
136 resizestack(L, LJ_STACK_MAX + 1 + 2 * LUA_MINSTACK); 141 resizestack(L, LJ_STACK_MAX + LJ_STACK_ERREX);
137 lj_err_stkov(L); /* May invoke an error handler. */ 142 lj_err_stkov(L); /* May invoke an error handler. */
138 } else { 143 } else {
139 /* If we're here, then the stack overflow error handler is requesting 144 /* If we're here, then the stack overflow error handler is requesting