signal.c raw
1 //go:build none
2
3 // Ignore the //go:build above. This file is manually included on Linux and
4 // MacOS to provide os/signal support.
5
6 #include <stdint.h>
7 #include <signal.h>
8 #include <time.h>
9 #include <unistd.h>
10
11 // Signal handler in the runtime.
12 void moxie_signal_handler(int sig);
13
14 // Enable a signal from the runtime.
15 void moxie_signal_enable(uint32_t sig) {
16 struct sigaction act = { 0 };
17 act.sa_handler = &moxie_signal_handler;
18 act.sa_flags = SA_RESTART;
19 sigaction(sig, &act, NULL);
20 }
21
22 void moxie_signal_ignore(uint32_t sig) {
23 struct sigaction act = { 0 };
24 act.sa_handler = SIG_IGN;
25 sigaction(sig, &act, NULL);
26 }
27
28 void moxie_signal_disable(uint32_t sig) {
29 struct sigaction act = { 0 };
30 act.sa_handler = SIG_DFL;
31 sigaction(sig, &act, NULL);
32 }
33