syscalls.ha (2665B)
1 fn syscall0(_: u64) u64; 2 fn syscall1(_: u64, _: u64) u64; 3 fn syscall2(_: u64, _: u64, _: u64) u64; 4 fn syscall3(_: u64, _: u64, _: u64, _: u64) u64; 5 fn syscall4(_: u64, _: u64, _: u64, _: u64, _: u64) u64; 6 fn syscall5(_: u64, _: u64, _: u64, _: u64, _: u64, _: u64) u64; 7 fn syscall6(_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64) u64; 8 9 export fn write(fd: int, buf: *const void, count: size) size = 10 syscall3(SYS_write, fd: u64, buf: uintptr: u64, count: u64): size; 11 12 export fn close(fd: int) int = syscall1(SYS_close, fd: u64): int; 13 14 export fn dup2(old: int, new: int) int = 15 syscall2(SYS_dup2, old: u64, new: u64): int; 16 17 export fn getpid() int = syscall0(SYS_getpid): int; 18 19 export def EXIT_SUCCESS: int = 0; 20 export def EXIT_FAILURE: int = 1; 21 22 export @noreturn fn exit(status: int) void = { syscall1(SYS_exit, status: u64); }; 23 24 export fn fork() int = syscall0(SYS_fork): int; 25 26 export fn execve( 27 path: *const char, 28 argv: *[*]nullable *const char, 29 envp: *[*]nullable *const char, 30 ) int = syscall3(SYS_execve, 31 path: uintptr: u64, 32 argv: uintptr: u64, 33 envp: uintptr: u64): int; 34 35 export fn wait4(pid: int, status: *int, options: int, rusage: nullable *void) void = { 36 syscall4(SYS_compat_50_wait4, pid: u64, status: uintptr: u64, 37 options: u64, rusage: uintptr: u64); 38 }; 39 40 export fn wifexited(status: int) bool = wtermsig(status) == 0; 41 export fn wexitstatus(status: int) int = (status & 0xff00) >> 8; 42 43 export fn wtermsig(status: int) int = status & 0x7f; 44 export fn wifsignaled(status: int) bool = 45 wtermsig(status) != 0o177 && wtermsig(status) != 0 && status != 0x13; 46 47 export fn kill(pid: int, signal: int) int = 48 syscall2(SYS_kill, pid: u64, signal: u64): int; 49 50 export fn pipe2(pipefd: *[2]int, flags: int) int = 51 syscall2(SYS_pipe2, pipefd: uintptr: u64, flags: u64): int; 52 53 export def MAP_SHARED: uint = 0x0001; 54 export def MAP_PRIVATE: uint = 0x0002; 55 export def MAP_FIXED: uint = 0x0010; 56 export def __MAP_NOREPLACE: uint = 0x0800; 57 export def MAP_ANON: uint = 0x1000; 58 export def MAP_ANONYMOUS: uint = MAP_ANON; 59 export def __MAP_NOFAULT: uint = 0x2000; 60 export def MAP_STACK: uint = 0x4000; 61 export def MAP_CONCEAL: uint = 0x8000; 62 63 def PROT_NONE: uint = 0x00; 64 def PROT_READ: uint = 0x01; 65 def PROT_WRITE: uint = 0x02; 66 def PROT_EXEC: uint = 0x04; 67 68 export fn mmap( 69 addr: nullable *void, 70 length: size, 71 prot: uint, 72 flags: uint, 73 fd: int, 74 offs: size 75 ) *void = { 76 return syscall6(SYS_mmap, addr: uintptr: u64, length: u64, prot: u64, 77 flags: u64, fd: u64, offs: u64): uintptr: *void; 78 }; 79 80 export fn munmap(addr: *void, length: size) int = 81 syscall2(SYS_munmap, addr: uintptr: u64, length: u64): int; 82 83 export def SIGABRT: int = 6; 84 export def SIGCHLD: int = 20;