Re: SEGV in in lua_resume after lua_yield from hook.

  • From: Theo Schlossnagle <jesus@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 31 Mar 2022 11:29:20 -0400

On Thu, Mar 31, 2022 at 11:18 AM Mike Pall <mikelj-2203@xxxxxxx> wrote:

Theo Schlossnagle wrote:
I have a (rather large) luajit runtime (on x86_64) and we implement
preempting by using timers on Linux to singal and lua_sethook with a
count
of 1.

Since XmiliaH tried for a repro (thanks!) in
  https://github.com/LuaJIT/LuaJIT/issues/824
and was unaware of the precise restrictions for lua_sethook(),
I'll leave this here as well:

  lua_sethook() (only when SETTING a count hook) is signal-safe, but NOT
thread-safe.

Your description sounds like you're aware of that. But please
double-check that the signal handler is called on the exact same
thread which is currently executing Lua code.


Yes. As far as I know this is signalling correctly... Linux only here.

   struct sigevent sev;
   sev.sigev_notify = SIGEV_THREAD_ID;
   sev.sigev_signo = SIGUSR1;
   sev._sigev_un._tid = syscall(SYS_gettid);
   sev.sigev_value.sival_ptr = ...;
   if (timer_create(CLOCK_MONOTONIC, &sev, &timer) == -1) {

And, in the case of the crash, my logging shows lua_sethook is always set
on the same OS thread as the state in question.

Your pointers before were great, I've not had time to dive back in to
diagnosis yet.

-- 

Theo Schlossnagle

Other related posts: