1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#+build linux, windows, darwin, netbsd, openbsd, freebsd, haiku
package posix
import "base:intrinsics"
import "core:c"
import "core:c/libc"
when ODIN_OS == .Windows {
foreign import lib "system:libucrt.lib"
} else when ODIN_OS == .Darwin {
foreign import lib "system:System"
} else {
foreign import lib "system:c"
}
// signal.h - signals
foreign lib {
/*
Set a signal handler.
func can either be:
- `auto_cast posix.SIG_DFL` setting the default handler for that specific signal
- `auto_cast posix.SIG_IGN` causing the specific signal to be ignored
- a custom signal handler
Returns: SIG_ERR (setting errno), the last value of func on success
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/signal.html ]]
*/
signal :: proc(sig: Signal, func: proc "c" (Signal)) -> proc "c" (Signal) ---
/*
Raises a signal, calling its handler and then returning.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/raise.html ]]
*/
raise :: proc(sig: Signal) -> result ---
}
Signal :: enum c.int {
NONE,
// LIBC:
// Process abort signal.
SIGABRT = SIGABRT,
// Erronous arithemtic operation.
SIGFPE = SIGFPE,
// Illegal instruction.
SIGILL = SIGILL,
// Terminal interrupt signal.
SIGINT = SIGINT,
// Invalid memory reference.
SIGSEGV = SIGSEGV,
// Termination signal.
SIGTERM = SIGTERM,
// POSIX:
// Process abort signal.
SIGALRM = SIGALRM,
// Access to an undefined portion of a memory object.
SIGBUS = SIGBUS,
// Child process terminated, stopped, or continued.
SIGCHLD = SIGCHLD,
// Continue execution, if stopped.
SIGCONT = SIGCONT,
// Hangup.
SIGHUP = SIGHUP,
// Kill (cannot be caught or ignored).
SIGKILL = SIGKILL,
// Write on a pipe with no one to read it.
SIGPIPE = SIGPIPE,
// Terminal quit signal.
SIGQUIT = SIGQUIT,
// Stop executing (cannot be caught or ignored).
SIGSTOP = SIGSTOP,
// Terminal stop process.
SIGTSTP = SIGTSTP,
// Background process attempting read.
SIGTTIN = SIGTTIN,
// Background process attempting write.
SIGTTOU = SIGTTOU,
// User-defined signal 1.
SIGUSR1 = SIGUSR1,
// User-defined signal 2.
SIGUSR2 = SIGUSR2,
// Pollable event.
SIGPOLL = SIGPOLL,
// Profiling timer expired.
SIGPROF = SIGPROF,
// Bad system call.
SIGSYS = SIGSYS,
// Trace/breakpoint trap.
SIGTRAP = SIGTRAP,
// High bandwidth data is available at a socket.
SIGURG = SIGURG,
// Virtual timer expired.
SIGVTALRM = SIGVTALRM,
// CPU time limit exceeded.
SIGXCPU = SIGXCPU,
// File size limit exceeded.
SIGXFSZ = SIGXFSZ,
}
// Request for default signal handling.
SIG_DFL :: libc.SIG_DFL
// Return value from signal() in case of error.
SIG_ERR :: libc.SIG_ERR
// Request that signal be ignored.
SIG_IGN :: libc.SIG_IGN
SIGABRT :: libc.SIGABRT
SIGFPE :: libc.SIGFPE
SIGILL :: libc.SIGILL
SIGINT :: libc.SIGINT
SIGSEGV :: libc.SIGSEGV
SIGTERM :: libc.SIGTERM
when ODIN_OS == .Windows {
SIGALRM :: -1
SIGBUS :: -1
SIGCHLD :: -1
SIGCONT :: -1
SIGHUP :: -1
SIGKILL :: -1
SIGPIPE :: -1
SIGQUIT :: -1
SIGSTOP :: -1
SIGTSTP :: -1
SIGTTIN :: -1
SIGTTOU :: -1
SIGUSR1 :: -1
SIGUSR2 :: -1
SIGPOLL :: -1
SIGPROF :: -1
SIGSYS :: -1
SIGTRAP :: -1
SIGURG :: -1
SIGVTALRM :: -1
SIGXCPU :: -1
SIGXFSZ :: -1
}
|