33package runtime
44
55import (
6- "syscall"
76 "unsafe"
87)
98
@@ -267,7 +266,17 @@ func init() {
267266}
268267
269268var signalChan chan uint32
270- var signalIgnored []bool // TODO: replace with more efficient bitmap?
269+ var signalIgnored []bool
270+
271+ // SignalIgnored returns the signalIgnored array.
272+ // Do not expose signalIgnored directly, as it is mutable.
273+ //
274+ //export SignalIgnored
275+ func SignalIgnored () []bool {
276+ sigs := make ([]bool , len (signalIgnored ))
277+ copy (sigs , signalIgnored )
278+ return sigs
279+ }
271280
272281//go:linkname signal_enable os/signal.signal_enable
273282func signal_enable (sig uint32 ) {
@@ -278,6 +287,7 @@ func signal_enable(sig uint32) {
278287//export tinygo_signal_enable
279288func tinygo_signal_enable (s uint32 )
280289
290+ // go: link signal_disable os/signal.signal_disable
281291func signal_disable (sig uint32 ) {
282292 tinygo_signal_disable (sig )
283293}
@@ -288,10 +298,22 @@ func tinygo_signal_disable(sig uint32)
288298// Ignore the given signal by adding it into the signalIgnored array.
289299// If the signal is received, it will be ignored in the tinygo_signal_handler.
290300// The signals SIGKILL and SIGSTOP cannot be caught or ignored. man (2) signal
291- func tinygo_signal_ignore (sig uint32 ) {
292- if syscall .Signal (sig ) != syscall .SIGKILL && syscall .Signal (sig ) != syscall .SIGSTOP {
293- signalIgnored [sig ] = true
294- }
301+ //
302+ // func tinygo_signal_ignore(sig uint32) {
303+ // if syscall.Signal(sig) != syscall.SIGKILL && syscall.Signal(sig) != syscall.SIGSTOP {
304+ // signalIgnored[sig] = true
305+ // }
306+ // }
307+
308+ //export tinygo_signal_ignore
309+ func tinygo_signal_ignore (sig uint32 )
310+
311+ // go: link signal_ignore os/signal.signal_ignore
312+ func signal_ignore (sig uint32 ) {
313+ // keep track of ignored signal for Ignore(sig os.Signal)
314+ // the ignore logic itself is tracked by the kernel https://elixir.bootlin.com/linux/v6.10/source/kernel/signal.c#L4142
315+ signalIgnored [sig ] = true
316+ tinygo_signal_ignore (sig )
295317}
296318
297319// void tinygo_signal_handler(int sig);
0 commit comments