Looks like the second parameter to the signal handler is null.
use unix::signal;
use rt;
use fmt;
fn handle(sig: signal::sig, info: *signal::siginfo, uctx: *opaque) void = {
fmt::printfln("signal={} errno={} code={}",
signal::signame(sig), rt::strerror(info.errno), info.code: int)!;
abort();
};
export fn main() void = {
signal::handle(signal::sig::FPE, &handle);
fmt::println(1 / 0)!;
};
Process 988 stopped
* thread 1, name = 'b', stop reason = signal SIGFPE: integer divide by zero
frame 0: 0x00000000080181c2 b`main at sigtest.ha:15
12 export fn main() void = {
13 signal::handle(signal::sig::FPE, &handle);
14
-> 15 fmt::println(1 / 0)!;
16 };
Process 988 resuming
Process 988 stopped
* thread 1, name = 'b', stop reason = signal SIGSEGV: invalid address (fault address: 0x6)
frame 0: 0x00000000080182ca b`handle at sigtest.ha:7
4
5 fn handle(sig: signal::sig, info: *signal::siginfo, uctx: *opaque) void = {
6 fmt::printfln("signal={} errno={} code={}",
-> 7 signal::signame(sig), rt::strerror(info.errno),
8 info.code: int)!;
9 abort();
10 };
Oops, turns out you need to pass
SA_SIGINFO
to get a validsiginfo
pointer. The real solution is to warn about this somewhere in the documentation, as well as providingflag::SIGINFO
.