33package runtime
44
55import (
6- "syscall"
76 "unsafe"
87)
98
@@ -318,7 +317,17 @@ func init() {
318317}
319318
320319var signalChan chan uint32
321- var signalIgnored []bool // TODO: replace with more efficient bitmap?
320+ var signalIgnored []bool
321+
322+ // SignalIgnored returns the signalIgnored array.
323+ // Do not expose signalIgnored directly, as it is mutable.
324+ //
325+ //export SignalIgnored
326+ func SignalIgnored () []bool {
327+ sigs := make ([]bool , len (signalIgnored ))
328+ copy (sigs , signalIgnored )
329+ return sigs
330+ }
322331
323332//go:linkname signal_enable os/signal.signal_enable
324333func signal_enable (sig uint32 ) {
@@ -329,6 +338,7 @@ func signal_enable(sig uint32) {
329338//export tinygo_signal_enable
330339func tinygo_signal_enable (s uint32 )
331340
341+ // go: link signal_disable os/signal.signal_disable
332342func signal_disable (sig uint32 ) {
333343 tinygo_signal_disable (sig )
334344}
@@ -339,10 +349,22 @@ func tinygo_signal_disable(sig uint32)
339349// Ignore the given signal by adding it into the signalIgnored array.
340350// If the signal is received, it will be ignored in the tinygo_signal_handler.
341351// The signals SIGKILL and SIGSTOP cannot be caught or ignored. man (2) signal
342- func tinygo_signal_ignore (sig uint32 ) {
343- if syscall .Signal (sig ) != syscall .SIGKILL && syscall .Signal (sig ) != syscall .SIGSTOP {
344- signalIgnored [sig ] = true
345- }
352+ //
353+ // func tinygo_signal_ignore(sig uint32) {
354+ // if syscall.Signal(sig) != syscall.SIGKILL && syscall.Signal(sig) != syscall.SIGSTOP {
355+ // signalIgnored[sig] = true
356+ // }
357+ // }
358+
359+ //export tinygo_signal_ignore
360+ func tinygo_signal_ignore (sig uint32 )
361+
362+ // go: link signal_ignore os/signal.signal_ignore
363+ func signal_ignore (sig uint32 ) {
364+ // keep track of ignored signal for Ignore(sig os.Signal)
365+ // the ignore logic itself is tracked by the kernel https://elixir.bootlin.com/linux/v6.10/source/kernel/signal.c#L4142
366+ signalIgnored [sig ] = true
367+ tinygo_signal_ignore (sig )
346368}
347369
348370// void tinygo_signal_handler(int sig);
0 commit comments