mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
sys/posix: impl rest of linux, impl some of Windows
This commit is contained in:
+2
-109
@@ -1,9 +1,9 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "base:intrinsics"
|
||||
|
||||
import "core:c"
|
||||
import "core:c/libc"
|
||||
|
||||
when ODIN_OS == .Darwin {
|
||||
foreign import lib "system:System.framework"
|
||||
@@ -14,31 +14,6 @@ when ODIN_OS == .Darwin {
|
||||
// signal.h - signals
|
||||
|
||||
foreign lib {
|
||||
// LIBC:
|
||||
|
||||
/*
|
||||
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 ---
|
||||
|
||||
// POSIX:
|
||||
|
||||
/*
|
||||
Raise a signal to the process/group specified by pid.
|
||||
|
||||
@@ -227,72 +202,6 @@ sigval :: struct #raw_union {
|
||||
sigval_ptr: rawptr, /* [PSX] pointer signal value */
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
ILL_Code :: enum c.int {
|
||||
// Illegal opcode.
|
||||
ILLOPC = ILL_ILLOPC,
|
||||
@@ -434,20 +343,6 @@ Sig :: enum c.int {
|
||||
SETMASK = SIG_SETMASK,
|
||||
}
|
||||
|
||||
// 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 == .NetBSD {
|
||||
@(private) LSIGPROCMASK :: "__sigprocmask14"
|
||||
@(private) LSIGACTION :: "__sigaction_siginfo"
|
||||
@@ -1118,7 +1013,7 @@ when ODIN_OS == .Darwin {
|
||||
|
||||
uid_t :: distinct c.uint32_t
|
||||
sigset_t :: struct {
|
||||
[1024/(8 * size_of(c.ulong))]val,
|
||||
__val: [1024/(8 * size_of(c.ulong))]c.ulong,
|
||||
}
|
||||
|
||||
SIGHUP :: 1
|
||||
@@ -1285,6 +1180,4 @@ when ODIN_OS == .Darwin {
|
||||
SI_TIMER :: -2
|
||||
SI_MESGQ :: -3
|
||||
SI_ASYNCIO :: -4
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user