| ... | ... | @@ -24,6 +24,19 @@ pub const MAP_NOCACHE = 0x0400; /// don't cache pages for this mapping |
| 24 | 24 | pub const MAP_NORESERVE = 0x0040; /// don't reserve needed swap area |
| 25 | 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 | 40 | pub const O_LARGEFILE = 0x0000; |
| 28 | 41 | pub const O_PATH = 0x0000; |
| 29 | 42 | |
| ... | ... | @@ -46,40 +59,43 @@ pub const SEEK_SET = 0x0; |
| 46 | 59 | pub const SEEK_CUR = 0x1; |
| 47 | 60 | pub const SEEK_END = 0x2; |
| 48 | 61 | |
| 49 | | pub const SIGHUP = 1; |
| 50 | | pub const SIGINT = 2; |
| 51 | | pub const SIGQUIT = 3; |
| 52 | | pub const SIGILL = 4; |
| 53 | | pub const SIGTRAP = 5; |
| 54 | | pub const SIGABRT = 6; |
| 55 | | pub const SIGIOT = SIGABRT; |
| 56 | | pub const SIGBUS = 7; |
| 57 | | pub const SIGFPE = 8; |
| 58 | | pub const SIGKILL = 9; |
| 59 | | pub const SIGUSR1 = 10; |
| 60 | | pub const SIGSEGV = 11; |
| 61 | | pub const SIGUSR2 = 12; |
| 62 | | pub const SIGPIPE = 13; |
| 63 | | pub const SIGALRM = 14; |
| 64 | | pub const SIGTERM = 15; |
| 65 | | pub const SIGSTKFLT = 16; |
| 66 | | pub const SIGCHLD = 17; |
| 67 | | pub const SIGCONT = 18; |
| 68 | | pub const SIGSTOP = 19; |
| 69 | | pub const SIGTSTP = 20; |
| 70 | | pub const SIGTTIN = 21; |
| 71 | | pub const SIGTTOU = 22; |
| 72 | | pub const SIGURG = 23; |
| 73 | | pub const SIGXCPU = 24; |
| 74 | | pub const SIGXFSZ = 25; |
| 75 | | pub const SIGVTALRM = 26; |
| 76 | | pub const SIGPROF = 27; |
| 77 | | pub const SIGWINCH = 28; |
| 78 | | pub const SIGIO = 29; |
| 79 | | pub const SIGPOLL = 29; |
| 80 | | pub const SIGPWR = 30; |
| 81 | | pub const SIGSYS = 31; |
| 82 | | pub const SIGUNUSED = SIGSYS; |
| 62 | pub const SIG_BLOCK = 1; /// block specified signal set |
| 63 | pub const SIG_UNBLOCK = 2; /// unblock specified signal set |
| 64 | pub const SIG_SETMASK = 3; /// set specified signal set |
| 65 | |
| 66 | pub const SIGHUP = 1; /// hangup |
| 67 | pub const SIGINT = 2; /// interrupt |
| 68 | pub const SIGQUIT = 3; /// quit |
| 69 | pub const SIGILL = 4; /// illegal instruction (not reset when caught) |
| 70 | pub const SIGTRAP = 5; /// trace trap (not reset when caught) |
| 71 | pub const SIGABRT = 6; /// abort() |
| 72 | pub const SIGPOLL = 7; /// pollable event ([XSR] generated, not supported) |
| 73 | pub const SIGIOT = SIGABRT; /// compatibility |
| 74 | pub const SIGEMT = 7; /// EMT instruction |
| 75 | pub const SIGFPE = 8; /// floating point exception |
| 76 | pub const SIGKILL = 9; /// kill (cannot be caught or ignored) |
| 77 | pub const SIGBUS = 10; /// bus error |
| 78 | pub const SIGSEGV = 11; /// segmentation violation |
| 79 | pub const SIGSYS = 12; /// bad argument to system call |
| 80 | pub const SIGPIPE = 13; /// write on a pipe with no one to read it |
| 81 | pub const SIGALRM = 14; /// alarm clock |
| 82 | pub const SIGTERM = 15; /// software termination signal from kill |
| 83 | pub const SIGURG = 16; /// urgent condition on IO channel |
| 84 | pub const SIGSTOP = 17; /// sendable stop signal not from tty |
| 85 | pub const SIGTSTP = 18; /// stop signal from tty |
| 86 | pub const SIGCONT = 19; /// continue a stopped process |
| 87 | pub const SIGCHLD = 20; /// to parent on child stop or exit |
| 88 | pub const SIGTTIN = 21; /// to readers pgrp upon background tty read |
| 89 | pub const SIGTTOU = 22; /// like TTIN for output if (tp->t_local&LTOSTOP) |
| 90 | pub const SIGIO = 23; /// input/output possible signal |
| 91 | pub const SIGXCPU = 24; /// exceeded CPU time limit |
| 92 | pub const SIGXFSZ = 25; /// exceeded file size limit |
| 93 | pub const SIGVTALRM = 26; /// virtual time alarm |
| 94 | pub const SIGPROF = 27; /// profiling time alarm |
| 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 | 100 | fn wstatus(x: i32) -> i32 { x & 0o177 } |
| 85 | 101 | const wstopped = 0o177; |
| ... | ... | @@ -209,6 +225,47 @@ pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) -> usiz |
| 209 | 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 | 269 | /// Takes the return value from a syscall and formats it back in the way |
| 213 | 270 | /// that the kernel represents it to libc. Errno was a mistake, let's make |
| 214 | 271 | /// it go away forever. |