New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SIGILL when using interrupts #446
Comments
I am not sure it's safe to change the stack from interrupts in any way; we haven't fully defined the semantics there, but interrupts are not the same as normal C functions. This is sort of intentional because interrupt facility is expected to be extremely performant, so doing any sort of reservation/preparation is not great. The code above is likely tripping an assert (they are enabled unless you specify -DNDEBUG). You can register the assertion handler like so (no C-only interface atm...):
Once you do, you should get an actual assertion text assuming handler prints it to output. |
I added assertion handler, it prints:
Does it means that I can only (safely) inspect stack and yield? |
Also I see the following code in void interrupt(lua_State* L, int gc)
{
if (gc >= 0)
return;
if (std::chrono::system_clock::now() > interruptDeadline)
{
lua_checkstack(L, 1);
luaL_error(L, "execution timed out");
}
} if I right, the code has UB (undefined behaviour)? |
All great questions :) We'll look into this... To emit an error you need to reserve stack space so it's not fully clear to me why checkstack doesn't work. As I noted we don't really have a documented set of APIs that are safe to use from interrupts but it looks like we need one. |
Ahh I see, this is fascinating. The assertion happens during handling of Luau stack overflow. That seems to be a bug. The reason why Luau stack overflow happens in the first place is the odd interaction between how interpreter loop handles stack frame restore, and checkstack. So using checkstack followed by an error is safe. Using checkstack that's not followed by an error is not safe because the stack seems to grow on every iteration. Do you need to reserve stack space in case the error is not emitted? If you don't that's an easy workaround. I'll need to look into what we can fix in the VM here in either case. |
Thanks for the explanation! In Rust in mlua I have a special wrapper function that does some checks before every function call. The wrapper is also used to capture Rust exceptions and enabled for interrupt handler. Given that it's not safe to do any arbitrary operations in interrupts (like execting Lua functions / etc) seems would be reasonable to change interface on my side and allow only throwing errors / yielding / continue execution. |
Hello,
Initially discovered in mlua-rs/mlua#142
The following program:
Generates SIGILL (illegal hardware instruction):
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: x86_64-apple-darwin21.4.0
Obviously the issue related to inability to allocate more stack, but I'm not sure is this right behaviour?
The text was updated successfully, but these errors were encountered: