Run VM events and finalizers in separate state.

Reported by Sergey Kaplun. #1403
This commit is contained in:
Mike Pall
2025-11-10 18:11:26 +01:00
parent fdf2379ccb
commit 5c647754a6
7 changed files with 76 additions and 67 deletions

View File

@@ -38,6 +38,7 @@ ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev)
void lj_vmevent_call(lua_State *L, ptrdiff_t argbase)
{
global_State *g = G(L);
lua_State *oldL = gco2th(gcref(g->cur_L));
uint8_t oldmask = g->vmevmask;
uint8_t oldh = hook_save(g);
int status;
@@ -51,6 +52,10 @@ void lj_vmevent_call(lua_State *L, ptrdiff_t argbase)
fputs(tvisstr(L->top) ? strVdata(L->top) : "?", stderr);
fputc('\n', stderr);
}
setgcref(g->cur_L, obj2gco(oldL));
#if LJ_HASJIT
G2J(g)->L = oldL;
#endif
hook_restore(g, oldh);
if (g->vmevmask != VMEVENT_NOCACHE)
g->vmevmask = oldmask; /* Restore event mask, but not if not modified. */