static void handle(int sig) { if(!signal_queue) { /* Store the existing debug hook (if any) and its parameters */ Hsig = lua_gethook(Lsig); Hmask = lua_gethookmask(Lsig); Hcount = lua_gethookcount(Lsig); signal_queue = malloc(sizeof(struct signal_event)); signal_queue->Nsig = sig; signal_queue->next_event = NULL; last_event = signal_queue; /* Set our new debug hook */ lua_sethook(Lsig, sighook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); } else { last_event->next_event = malloc(sizeof(struct signal_event)); last_event->next_event->Nsig = sig; last_event->next_event->next_event = NULL; last_event = last_event->next_event; } }
static void vx_sighandler(int sig) { sign = sig; sigh = lua_gethook(GL); hcnt = lua_gethookcount(GL); hmask = lua_gethookmask(GL); lua_sethook(GL, vx_sighook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); }
static void l_signal(int i) { /* assert(i==SIGALRM); */ signal(i,SIG_DFL); oldhook=lua_gethook(LL); oldmask=lua_gethookmask(LL); oldcount=lua_gethookcount(LL); lua_sethook(LL,l_handler,LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT,1); }
static void handle (int sig) { assert(ML != NULL); if (old_hook.hook == NULL) /* replace it */ { old_hook.hook = lua_gethook(ML); old_hook.mask = lua_gethookmask(ML); old_hook.count = lua_gethookcount(ML); lua_sethook(ML, hook, LUA_MASKCOUNT, 1); } signal_stack[sig]++; }
static void signal_handler(int sig) { if (q.size == 0) { old_hook = lua_gethook(gL); old_mask = lua_gethookmask(gL); old_count = lua_gethookcount(gL); lua_sethook(gL, lua_signal_handler, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); } enqueue(&q, sig); }
static int gethook (lua_State *L) { char buff[5]; int mask = lua_gethookmask(L); lua_Hook hook = lua_gethook(L); if (hook != NULL && hook != hookf) /* external hook? */ lua_pushliteral(L, "external hook"); else { lua_pushlightuserdata(L, (void *)&KEY_HOOK); lua_rawget(L, LUA_REGISTRYINDEX); /* get hook */ } lua_pushstring(L, unmakemask(mask, buff)); lua_pushnumber(L, (lua_Number)lua_gethookcount(L)); return 3; }
static int db_gethook (lua_State *L) { int arg; lua_State *L1 = getthread(L, &arg); char buff[5]; int mask = lua_gethookmask(L1); lua_Hook hook = lua_gethook(L1); if (hook != NULL && hook != hookf) /* external hook? */ lua_pushliteral(L, "external hook"); else { gethooktable(L); lua_rawgetp(L, -1, L1); /* get hook */ lua_remove(L, -2); /* remove hook table */ } lua_pushstring(L, unmakemask(mask, buff)); lua_pushinteger(L, lua_gethookcount(L1)); return 3; }
void luaQ_getfield(struct lua_State *L, int index, const char *name) { lua_pushvalue(L, index); lua_pushcfunction(L, luaQ_gettable); lua_insert(L, -2); lua_pushstring(L, name); lua_Hook hf = lua_gethook(L); int hm = lua_gethookmask(L); int hc = lua_gethookcount(L); lua_sethook(L, 0, 0, 0); if (lua_pcall(L, 2, 1, 0)) { lua_pop(L, 1); lua_pushnil(L); } lua_sethook(L, hf, hm, hc); }
static int db_gethook (lua_State *L) { int arg; lua_State *L1 = getthread(L, &arg); char buff[5]; int mask = lua_gethookmask(L1); lua_Hook hook = lua_gethook(L1); if (hook == NULL) /* no hook? */ lua_pushnil(L); else if (hook != hookf) /* external hook? */ lua_pushliteral(L, "external hook"); else { /* hook table must exist */ lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY); lua_pushthread(L1); lua_xmove(L1, L, 1); lua_rawget(L, -2); /* 1st result = hooktable[L1] */ lua_remove(L, -2); /* remove hook table */ } lua_pushstring(L, unmakemask(mask, buff)); /* 2nd result = mask */ lua_pushinteger(L, lua_gethookcount(L1)); /* 3rd result = count */ return 3; }
size_t instruction_usage(lua_sandbox* lsb) { return lua_gethookcount(lsb->m_lua) - lua_gethookcountremaining(lsb->m_lua); }
int LuaDebug::GetHookCount() const { return lua_gethookcount(L()); }