From a04e6b5b2923a657669ca23ef51c470dd3b5f6d7 Mon Sep 17 00:00:00 2001 From: hong Date: Thu, 6 Jun 2019 11:13:19 +0800 Subject: [PATCH] lua_checksig LUA_CACHELIB --- 3rd/lua/lua.h | 5 +++++ 3rd/lua/lualib.h | 2 ++ 3rd/lua/lvm.c | 15 +++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/3rd/lua/lua.h b/3rd/lua/lua.h index a944404b..675bc0ff 100644 --- a/3rd/lua/lua.h +++ b/3rd/lua/lua.h @@ -459,6 +459,11 @@ struct lua_Debug { /* }====================================================================== */ +/* Add by skynet */ + +LUA_API lua_State * skynet_sig_L; +LUA_API void (lua_checksig_)(lua_State *L); +#define lua_checksig(L) if (skynet_sig_L) { lua_checksig_(L); } /****************************************************************************** * Copyright (C) 1994-2018 Lua.org, PUC-Rio. diff --git a/3rd/lua/lualib.h b/3rd/lua/lualib.h index f5304aa0..422b9ea5 100644 --- a/3rd/lua/lualib.h +++ b/3rd/lua/lualib.h @@ -47,6 +47,8 @@ LUAMOD_API int (luaopen_debug) (lua_State *L); #define LUA_LOADLIBNAME "package" LUAMOD_API int (luaopen_package) (lua_State *L); +#define LUA_CACHELIB +LUAMOD_API int (luaopen_cache) (lua_State *L); /* open all previous libraries */ LUALIB_API void (luaL_openlibs) (lua_State *L); diff --git a/3rd/lua/lvm.c b/3rd/lua/lvm.c index 334cc9d8..a2393d50 100644 --- a/3rd/lua/lvm.c +++ b/3rd/lua/lvm.c @@ -63,7 +63,17 @@ #endif +/* Add by skynet */ +lua_State * skynet_sig_L = NULL; +LUA_API void +lua_checksig_(lua_State *L) { + if (skynet_sig_L == G(L)->mainthread) { + skynet_sig_L = NULL; + lua_pushnil(L); + lua_error(L); + } +} /* ** Try to convert a value to a float. The float case is already handled @@ -1057,6 +1067,7 @@ void luaV_execute (lua_State *L) { vmbreak; } vmcase(OP_JMP) { + lua_checksig(L); dojump(ci, i, 0); vmbreak; } @@ -1109,6 +1120,7 @@ void luaV_execute (lua_State *L) { vmcase(OP_CALL) { int b = GETARG_B(i); int nresults = GETARG_C(i) - 1; + lua_checksig(L); if (b != 0) L->top = ra+b; /* else previous instruction set top */ if (luaD_precall(L, ra, nresults)) { /* C function? */ if (nresults >= 0) @@ -1123,6 +1135,7 @@ void luaV_execute (lua_State *L) { } vmcase(OP_TAILCALL) { int b = GETARG_B(i); + lua_checksig(L); if (b != 0) L->top = ra+b; /* else previous instruction set top */ lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); if (luaD_precall(L, ra, LUA_MULTRET)) { /* C function? */ @@ -1167,6 +1180,7 @@ void luaV_execute (lua_State *L) { } } vmcase(OP_FORLOOP) { + lua_checksig(L); if (ttisinteger(ra)) { /* integer loop? */ lua_Integer step = ivalue(ra + 2); lua_Integer idx = intop(+, ivalue(ra), step); /* increment index */ @@ -1233,6 +1247,7 @@ void luaV_execute (lua_State *L) { } vmcase(OP_TFORLOOP) { l_tforloop: + lua_checksig(L); if (!ttisnil(ra + 1)) { /* continue loop? */ setobjs2s(L, ra, ra + 1); /* save control variable */ ci->u.l.savedpc += GETARG_sBx(i); /* jump back */