Commit fe3063e58c
Changed files (3)
std/bootstrap.zig
@@ -2,8 +2,6 @@
const root = @import("@root");
const std = @import("std");
-const linux = std.linux;
-const cstr = std.cstr;
const want_start_symbol = switch(@compileVar("os")) {
Os.linux => true,
@@ -11,6 +9,11 @@ const want_start_symbol = switch(@compileVar("os")) {
};
const want_main_symbol = !want_start_symbol;
+const exit = switch(@compileVar("os")) {
+ Os.linux => std.linux.exit,
+ Os.darwin => std.darwin.exit,
+};
+
var argc: usize = undefined;
var argv: &&u8 = undefined;
@@ -35,14 +38,14 @@ fn callMain() -> %void {
const args = @alloca([]u8, argc);
for (args) |_, i| {
const ptr = argv[i];
- args[i] = ptr[0...cstr.len(ptr)];
+ args[i] = ptr[0...std.cstr.len(ptr)];
}
return root.main(args);
}
fn callMainAndExit() -> unreachable {
- callMain() %% linux.exit(1);
- linux.exit(0);
+ callMain() %% exit(1);
+ exit(0);
}
export fn main(c_argc: i32, c_argv: &&u8) -> i32 {
std/darwin.zig
@@ -48,6 +48,11 @@ pub const SIGPWR = 30;
pub const SIGSYS = 31;
pub const SIGUNUSED = SIGSYS;
+pub fn exit(status: usize) -> unreachable {
+ arch.syscall1(arch.SYS_exit, status);
+ @unreachable()
+}
+
/// Get the errno from a syscall return value, or 0 for no error.
pub fn getErrno(r: usize) -> usize {
const signed_r = *(&isize)(&r);
@@ -67,7 +72,7 @@ pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize {
}
pub fn open(path: []const u8, flags: usize, perm: usize) -> usize {
- var buf: [path.len + 1]u8 = undefined;
+ const buf = @alloca(u8, path.len + 1);
@memcpy(&buf[0], &path[0], path.len);
buf[path.len] = 0;
return open_c(buf.ptr, flags, perm);
std/darwin_x86_64.zig
@@ -11,6 +11,7 @@ pub const SYSCALL_CLASS_DIAG = 4; // Diagnostics
// TODO: use the above constants to create the below values
+pub const SYS_exit = 0x2000001;
pub const SYS_read = 0x2000003;
pub const SYS_write = 0x2000004;
pub const SYS_open = 0x2000005;