diff --git a/std/os/zen.zig b/std/os/zen.zig index ffc491e404bd3fe1266496f52cb486ea81036537..37ec68763db27f41f3dbbe475a66e76f22444d93 100644 --- a/std/os/zen.zig +++ b/std/os/zen.zig @@ -9,16 +9,23 @@ pub const MBOX_TERMINAL = 1; //// Syscall numbers //// /////////////////////////// -pub const SYS_createMailbox = 0; -pub const SYS_send = 1; -pub const SYS_receive = 2; -pub const SYS_map = 3; +pub const SYS_exit = 0; +pub const SYS_createMailbox = 1; +pub const SYS_send = 2; +pub const SYS_receive = 3; +pub const SYS_map = 4; +pub const SYS_createThread = 5; //////////////////// //// Syscalls //// //////////////////// +pub fn exit(status: i32) -> noreturn { + _ = syscall1(SYS_exit, @bitCast(usize, isize(status))); + unreachable; +} + pub fn createMailbox(id: u16) { _ = syscall1(SYS_createMailbox, id); } @@ -35,6 +42,10 @@ pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) -> bool { return syscall4(SYS_map, v_addr, p_addr, size, usize(writable)) != 0; } +pub fn createThread(function: fn()) -> u16 { + return u16(syscall1(SYS_createThread, @ptrToInt(function))); +} + ///////////////////////// //// Syscall stubs //// diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig index 28175de725fd78184088e505ff5a8b6a96590e19..55d28a2d0e07ab511a63e3c2876ad8a92d5a04ad 100644 --- a/std/special/bootstrap.zig +++ b/std/special/bootstrap.zig @@ -21,9 +21,8 @@ comptime { } extern fn zenMain() -> noreturn { - // TODO: call exit. - root.main() catch {}; - while (true) {} + root.main() catch std.os.posix.exit(1); + std.os.posix.exit(0); } nakedcc fn _start() -> noreturn {