syscalls.ha (2820B)
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_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_HASSEMAPHORE: uint = 0x0200; 57 export def MAP_STACK: uint = 0x0400; 58 export def MAP_NOSYNC: uint = 0x0800; 59 export def MAP_FILE: uint = 0x0000; 60 export def MAP_ANON: uint = 0x1000; 61 export def MAP_GUARD: uint = 0x00002000; 62 export def MAP_EXCL: uint = 0x00004000; 63 export def MAP_NOCORE: uint = 0x00020000; 64 export def MAP_PREFAULT_READ: uint = 0x00040000; 65 export def MAP_32BIT: uint = 0x00080000; 66 67 def PROT_NONE: uint = 0x00; 68 def PROT_READ: uint = 0x01; 69 def PROT_WRITE: uint = 0x02; 70 def PROT_EXEC: uint = 0x04; 71 72 export fn mmap( 73 addr: nullable *void, 74 length: size, 75 prot: uint, 76 flags: uint, 77 fd: int, 78 offs: size 79 ) *void = { 80 return syscall6(SYS_mmap, addr: uintptr: u64, length: u64, prot: u64, 81 flags: u64, fd: u64, offs: u64): uintptr: *void; 82 }; 83 84 export fn munmap(addr: *void, length: size) int = 85 syscall2(SYS_munmap, addr: uintptr: u64, length: u64): int; 86 87 export def SIGABRT: int = 6; 88 export def SIGCHLD: int = 20;