| ... | @@ -24,6 +24,19 @@ pub const MAP_NOCACHE = 0x0400; /// don't cache pages for this mapping | ... | @@ -24,6 +24,19 @@ pub const MAP_NOCACHE = 0x0400; /// don't cache pages for this mapping |
| 24 | pub const MAP_NORESERVE = 0x0040; /// don't reserve needed swap area | 24 | pub const MAP_NORESERVE = 0x0040; /// don't reserve needed swap area |
| 25 | pub const MAP_FAILED = @maxValue(usize); | 25 | pub const MAP_FAILED = @maxValue(usize); |
| 26 | | 26 | |
| | 27 | pub const WNOHANG = 0x00000001; /// [XSI] no hang in wait/no child to reap |
| | 28 | pub const WUNTRACED = 0x00000002; /// [XSI] notify on stop, untraced child |
| | 29 | |
| | 30 | pub const SA_ONSTACK = 0x0001; /// take signal on signal stack |
| | 31 | pub const SA_RESTART = 0x0002; /// restart system on signal return |
| | 32 | pub const SA_RESETHAND = 0x0004; /// reset to SIG_DFL when taking signal |
| | 33 | pub const SA_NOCLDSTOP = 0x0008; /// do not generate SIGCHLD on child stop |
| | 34 | pub const SA_NODEFER = 0x0010; /// don't mask the signal we're delivering |
| | 35 | pub const SA_NOCLDWAIT = 0x0020; /// don't keep zombies around |
| | 36 | pub const SA_SIGINFO = 0x0040; /// signal handler with SA_SIGINFO args |
| | 37 | pub const SA_USERTRAMP = 0x0100; /// do not bounce off kernel's sigtramp |
| | 38 | pub const SA_64REGSET = 0x0200; /// signal handler with SA_SIGINFO args with 64bit regs information |
| | 39 | |
| 27 | pub const O_LARGEFILE = 0x0000; | 40 | pub const O_LARGEFILE = 0x0000; |
| 28 | pub const O_PATH = 0x0000; | 41 | pub const O_PATH = 0x0000; |
| 29 | | 42 | |
| ... | @@ -46,40 +59,43 @@ pub const SEEK_SET = 0x0; | ... | @@ -46,40 +59,43 @@ pub const SEEK_SET = 0x0; |
| 46 | pub const SEEK_CUR = 0x1; | 59 | pub const SEEK_CUR = 0x1; |
| 47 | pub const SEEK_END = 0x2; | 60 | pub const SEEK_END = 0x2; |
| 48 | | 61 | |
| 49 | pub const SIGHUP = 1; | 62 | pub const SIG_BLOCK = 1; /// block specified signal set |
| 50 | pub const SIGINT = 2; | 63 | pub const SIG_UNBLOCK = 2; /// unblock specified signal set |
| 51 | pub const SIGQUIT = 3; | 64 | pub const SIG_SETMASK = 3; /// set specified signal set |
| 52 | pub const SIGILL = 4; | 65 | |
| 53 | pub const SIGTRAP = 5; | 66 | pub const SIGHUP = 1; /// hangup |
| 54 | pub const SIGABRT = 6; | 67 | pub const SIGINT = 2; /// interrupt |
| 55 | pub const SIGIOT = SIGABRT; | 68 | pub const SIGQUIT = 3; /// quit |
| 56 | pub const SIGBUS = 7; | 69 | pub const SIGILL = 4; /// illegal instruction (not reset when caught) |
| 57 | pub const SIGFPE = 8; | 70 | pub const SIGTRAP = 5; /// trace trap (not reset when caught) |
| 58 | pub const SIGKILL = 9; | 71 | pub const SIGABRT = 6; /// abort() |
| 59 | pub const SIGUSR1 = 10; | 72 | pub const SIGPOLL = 7; /// pollable event ([XSR] generated, not supported) |
| 60 | pub const SIGSEGV = 11; | 73 | pub const SIGIOT = SIGABRT; /// compatibility |
| 61 | pub const SIGUSR2 = 12; | 74 | pub const SIGEMT = 7; /// EMT instruction |
| 62 | pub const SIGPIPE = 13; | 75 | pub const SIGFPE = 8; /// floating point exception |
| 63 | pub const SIGALRM = 14; | 76 | pub const SIGKILL = 9; /// kill (cannot be caught or ignored) |
| 64 | pub const SIGTERM = 15; | 77 | pub const SIGBUS = 10; /// bus error |
| 65 | pub const SIGSTKFLT = 16; | 78 | pub const SIGSEGV = 11; /// segmentation violation |
| 66 | pub const SIGCHLD = 17; | 79 | pub const SIGSYS = 12; /// bad argument to system call |
| 67 | pub const SIGCONT = 18; | 80 | pub const SIGPIPE = 13; /// write on a pipe with no one to read it |
| 68 | pub const SIGSTOP = 19; | 81 | pub const SIGALRM = 14; /// alarm clock |
| 69 | pub const SIGTSTP = 20; | 82 | pub const SIGTERM = 15; /// software termination signal from kill |
| 70 | pub const SIGTTIN = 21; | 83 | pub const SIGURG = 16; /// urgent condition on IO channel |
| 71 | pub const SIGTTOU = 22; | 84 | pub const SIGSTOP = 17; /// sendable stop signal not from tty |
| 72 | pub const SIGURG = 23; | 85 | pub const SIGTSTP = 18; /// stop signal from tty |
| 73 | pub const SIGXCPU = 24; | 86 | pub const SIGCONT = 19; /// continue a stopped process |
| 74 | pub const SIGXFSZ = 25; | 87 | pub const SIGCHLD = 20; /// to parent on child stop or exit |
| 75 | pub const SIGVTALRM = 26; | 88 | pub const SIGTTIN = 21; /// to readers pgrp upon background tty read |
| 76 | pub const SIGPROF = 27; | 89 | pub const SIGTTOU = 22; /// like TTIN for output if (tp->t_local&LTOSTOP) |
| 77 | pub const SIGWINCH = 28; | 90 | pub const SIGIO = 23; /// input/output possible signal |
| 78 | pub const SIGIO = 29; | 91 | pub const SIGXCPU = 24; /// exceeded CPU time limit |
| 79 | pub const SIGPOLL = 29; | 92 | pub const SIGXFSZ = 25; /// exceeded file size limit |
| 80 | pub const SIGPWR = 30; | 93 | pub const SIGVTALRM = 26; /// virtual time alarm |
| 81 | pub const SIGSYS = 31; | 94 | pub const SIGPROF = 27; /// profiling time alarm |
| 82 | pub const SIGUNUSED = SIGSYS; | 95 | pub const SIGWINCH = 28; /// window size changes |
| | 96 | pub const SIGINFO = 29; /// information request |
| | 97 | pub const SIGUSR1 = 30; /// user defined signal 1 |
| | 98 | pub const SIGUSR2 = 31; /// user defined signal 2 |
| 83 | | 99 | |
| 84 | fn wstatus(x: i32) -> i32 { x & 0o177 } | 100 | fn wstatus(x: i32) -> i32 { x & 0o177 } |
| 85 | const wstopped = 0o177; | 101 | const wstopped = 0o177; |
| ... | @@ -209,6 +225,47 @@ pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) -> usiz | ... | @@ -209,6 +225,47 @@ pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) -> usiz |
| 209 | if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(*c._errno())) else 0 | 225 | if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(*c._errno())) else 0 |
| 210 | } | 226 | } |
| 211 | | 227 | |
| | 228 | pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize { |
| | 229 | errnoWrap(c.sigprocmask(@bitCast(c_int, flags), set, oldset)) |
| | 230 | } |
| | 231 | |
| | 232 | pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize { |
| | 233 | assert(sig != SIGKILL); |
| | 234 | assert(sig != SIGSTOP); |
| | 235 | var cact = c.Sigaction { |
| | 236 | .handler = @ptrCast(extern fn(c_int), act.handler), |
| | 237 | .sa_flags = @bitCast(c_int, act.flags), |
| | 238 | .sa_mask = act.mask, |
| | 239 | }; |
| | 240 | var coact: c.Sigaction = undefined; |
| | 241 | const result = errnoWrap(c.sigaction(sig, &cact, &coact)); |
| | 242 | if (result != 0) { |
| | 243 | return result; |
| | 244 | } |
| | 245 | if (oact) |old| { |
| | 246 | *old = Sigaction { |
| | 247 | .handler = @ptrCast(extern fn(i32), coact.handler), |
| | 248 | .flags = @bitCast(u32, coact.sa_flags), |
| | 249 | .mask = coact.sa_mask, |
| | 250 | }; |
| | 251 | } |
| | 252 | return result; |
| | 253 | } |
| | 254 | |
| | 255 | pub const sigset_t = c.sigset_t; |
| | 256 | pub const empty_sigset = sigset_t(0); |
| | 257 | |
| | 258 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| | 259 | pub const Sigaction = struct { |
| | 260 | handler: extern fn(i32), |
| | 261 | mask: sigset_t, |
| | 262 | flags: u32, |
| | 263 | }; |
| | 264 | |
| | 265 | pub fn sigaddset(set: &sigset_t, signo: u5) { |
| | 266 | *set |= u32(1) << (signo - 1); |
| | 267 | } |
| | 268 | |
| 212 | /// Takes the return value from a syscall and formats it back in the way | 269 | /// Takes the return value from a syscall and formats it back in the way |
| 213 | /// that the kernel represents it to libc. Errno was a mistake, let's make | 270 | /// that the kernel represents it to libc. Errno was a mistake, let's make |
| 214 | /// it go away forever. | 271 | /// it go away forever. |