diff options
author | Mike Pall <mike> | 2024-03-10 17:29:48 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2024-03-10 17:29:48 +0100 |
commit | d06beb0480c5d1eb53b3343e78063950275aa281 (patch) | |
tree | cf9af3aa9929ac4f98b5325f5d88f6721340c74f | |
parent | bcc5125a9188179d23c223b8865ed94951fb91b3 (diff) | |
download | luajit-d06beb0480c5d1eb53b3343e78063950275aa281.tar.gz luajit-d06beb0480c5d1eb53b3343e78063950275aa281.tar.bz2 luajit-d06beb0480c5d1eb53b3343e78063950275aa281.zip |
Handle all types of errors during trace stitching.
Thanks to Sergey Kaplun and Peter Cawley. #1166 #720
-rw-r--r-- | src/lj_ffrecord.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 30dc6bfc..03d0e6ec 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c | |||
@@ -98,6 +98,14 @@ static ptrdiff_t results_wanted(jit_State *J) | |||
98 | return -1; | 98 | return -1; |
99 | } | 99 | } |
100 | 100 | ||
101 | static TValue *rec_stop_stitch_cp(lua_State *L, lua_CFunction dummy, void *ud) | ||
102 | { | ||
103 | jit_State *J = (jit_State *)ud; | ||
104 | lj_record_stop(J, LJ_TRLINK_STITCH, 0); | ||
105 | UNUSED(L); UNUSED(dummy); | ||
106 | return NULL; | ||
107 | } | ||
108 | |||
101 | /* Trace stitching: add continuation below frame to start a new trace. */ | 109 | /* Trace stitching: add continuation below frame to start a new trace. */ |
102 | static void recff_stitch(jit_State *J) | 110 | static void recff_stitch(jit_State *J) |
103 | { | 111 | { |
@@ -108,10 +116,7 @@ static void recff_stitch(jit_State *J) | |||
108 | TValue *nframe = base + 1 + LJ_FR2; | 116 | TValue *nframe = base + 1 + LJ_FR2; |
109 | const BCIns *pc = frame_pc(base-1); | 117 | const BCIns *pc = frame_pc(base-1); |
110 | TValue *pframe = frame_prevl(base-1); | 118 | TValue *pframe = frame_prevl(base-1); |
111 | 119 | int errcode; | |
112 | /* Check for this now. Throwing in lj_record_stop messes up the stack. */ | ||
113 | if (J->cur.nsnap >= (MSize)J->param[JIT_P_maxsnap]) | ||
114 | lj_trace_err(J, LJ_TRERR_SNAPOV); | ||
115 | 120 | ||
116 | /* Move func + args up in Lua stack and insert continuation. */ | 121 | /* Move func + args up in Lua stack and insert continuation. */ |
117 | memmove(&base[1], &base[-1-LJ_FR2], sizeof(TValue)*nslot); | 122 | memmove(&base[1], &base[-1-LJ_FR2], sizeof(TValue)*nslot); |
@@ -136,13 +141,19 @@ static void recff_stitch(jit_State *J) | |||
136 | J->baseslot += 2 + LJ_FR2; | 141 | J->baseslot += 2 + LJ_FR2; |
137 | J->framedepth++; | 142 | J->framedepth++; |
138 | 143 | ||
139 | lj_record_stop(J, LJ_TRLINK_STITCH, 0); | 144 | errcode = lj_vm_cpcall(L, NULL, J, rec_stop_stitch_cp); |
140 | 145 | ||
141 | /* Undo Lua stack changes. */ | 146 | /* Undo Lua stack changes. */ |
142 | memmove(&base[-1-LJ_FR2], &base[1], sizeof(TValue)*nslot); | 147 | memmove(&base[-1-LJ_FR2], &base[1], sizeof(TValue)*nslot); |
143 | setframe_pc(base-1, pc); | 148 | setframe_pc(base-1, pc); |
144 | L->base -= 2 + LJ_FR2; | 149 | L->base -= 2 + LJ_FR2; |
145 | L->top -= 2 + LJ_FR2; | 150 | L->top -= 2 + LJ_FR2; |
151 | |||
152 | if (errcode) { | ||
153 | if (errcode == LUA_ERRRUN) | ||
154 | copyTV(L, L->top-1, L->top + (1 + LJ_FR2)); | ||
155 | lj_err_throw(L, errcode); /* Propagate errors. */ | ||
156 | } | ||
146 | } | 157 | } |
147 | 158 | ||
148 | /* Fallback handler for fast functions that are not recorded (yet). */ | 159 | /* Fallback handler for fast functions that are not recorded (yet). */ |