From 6bce6b118eeb2bb7f36157de158e5cccf0ea68e5 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Wed, 19 Jan 2011 02:05:37 +0100 Subject: [PATCH] Add compile-time option LUAJIT_ENABLE_CHECKHOOK. Disabled by default. This checks for asynchronously set hooks from compiled code. --- src/lj_record.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lj_record.c b/src/lj_record.c index 90779f92..f1dd8e3e 100644 --- a/src/lj_record.c +++ b/src/lj_record.c @@ -2033,6 +2033,27 @@ void lj_record_setup(jit_State *J) if (1 + J->pt->framesize >= LJ_MAX_JSLOTS) lj_trace_err(J, LJ_TRERR_STACKOV); } +#ifdef LUAJIT_ENABLE_CHECKHOOK + /* Regularly check for instruction/line hooks from compiled code and + ** exit to the interpreter if the hooks are set. + ** + ** This is a compile-time option and disabled by default, since the + ** hook checks may be quite expensive in tight loops. + ** + ** Note this is only useful if hooks are *not* set most of the time. + ** Use this only if you want to *asynchronously* interrupt the execution. + ** + ** You can set the instruction hook via lua_sethook() with a count of 1 + ** from a signal handler or another native thread. Please have a look + ** at the first few functions in luajit.c for an example (Ctrl-C handler). + */ + { + TRef tr = emitir(IRT(IR_XLOAD, IRT_U8), + lj_ir_kptr(J, &J2G(J)->hookmask), IRXLOAD_VOLATILE); + tr = emitir(IRTI(IR_BAND), tr, lj_ir_kint(J, (LUA_MASKLINE|LUA_MASKCOUNT))); + emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, 0)); + } +#endif } #undef IR