Files
tinygo/src/runtime/signal.c
T
Ayke van Laethem dd1ebbd31b runtime: implement race-free signals using futexes
This requires an API introduced in MacOS 11. I think that's fine, since
the version before that (MacOS 10.15) is EOL since 2022. Though if
needed, we could certainly work around it by using an older and slightly
less nice API.
2024-11-20 18:50:34 +01:00

33 lines
790 B
C

//go:build none
// Ignore the //go:build above. This file is manually included on Linux and
// MacOS to provide os/signal support.
#include <stdint.h>
#include <signal.h>
#include <time.h>
#include <unistd.h>
// Signal handler in the runtime.
void tinygo_signal_handler(int sig);
// Enable a signal from the runtime.
void tinygo_signal_enable(uint32_t sig) {
struct sigaction act = { 0 };
act.sa_handler = &tinygo_signal_handler;
act.sa_flags = SA_RESTART;
sigaction(sig, &act, NULL);
}
void tinygo_signal_ignore(uint32_t sig) {
struct sigaction act = { 0 };
act.sa_handler = SIG_IGN;
sigaction(sig, &act, NULL);
}
void tinygo_signal_disable(uint32_t sig) {
struct sigaction act = { 0 };
act.sa_handler = SIG_DFL;
sigaction(sig, &act, NULL);
}