| author | |
| committer | |
| log | fe3063e58cf81287a26219903f2720439dfeb7e6 |
| tree | d07f638d136f35c276c58ac8259cdb84d383ddfb |
| parent | b1ace32f2373914d92459934b9f0697baca9fe83 |
closes #2643 files changed, 15 insertions(+), 6 deletions(-)
std/bootstrap.zig+8-5| ... | @@ -2,8 +2,6 @@ | ... | @@ -2,8 +2,6 @@ |
| 2 | 2 | ||
| 3 | const root = @import("@root"); | 3 | const root = @import("@root"); |
| 4 | const std = @import("std"); | 4 | const std = @import("std"); |
| 5 | const linux = std.linux; | ||
| 6 | const cstr = std.cstr; | ||
| 7 | 5 | ||
| 8 | const want_start_symbol = switch(@compileVar("os")) { | 6 | const want_start_symbol = switch(@compileVar("os")) { |
| 9 | Os.linux => true, | 7 | Os.linux => true, |
| ... | @@ -11,6 +9,11 @@ const want_start_symbol = switch(@compileVar("os")) { | ... | @@ -11,6 +9,11 @@ const want_start_symbol = switch(@compileVar("os")) { |
| 11 | }; | 9 | }; |
| 12 | const want_main_symbol = !want_start_symbol; | 10 | const want_main_symbol = !want_start_symbol; |
| 13 | 11 | ||
| 12 | const exit = switch(@compileVar("os")) { | ||
| 13 | Os.linux => std.linux.exit, | ||
| 14 | Os.darwin => std.darwin.exit, | ||
| 15 | }; | ||
| 16 | |||
| 14 | var argc: usize = undefined; | 17 | var argc: usize = undefined; |
| 15 | var argv: &&u8 = undefined; | 18 | var argv: &&u8 = undefined; |
| 16 | 19 | ||
| ... | @@ -35,14 +38,14 @@ fn callMain() -> %void { | ... | @@ -35,14 +38,14 @@ fn callMain() -> %void { |
| 35 | const args = @alloca([]u8, argc); | 38 | const args = @alloca([]u8, argc); |
| 36 | for (args) |_, i| { | 39 | for (args) |_, i| { |
| 37 | const ptr = argv[i]; | 40 | const ptr = argv[i]; |
| 38 | args[i] = ptr[0...cstr.len(ptr)]; | 41 | args[i] = ptr[0...std.cstr.len(ptr)]; |
| 39 | } | 42 | } |
| 40 | return root.main(args); | 43 | return root.main(args); |
| 41 | } | 44 | } |
| 42 | 45 | ||
| 43 | fn callMainAndExit() -> unreachable { | 46 | fn callMainAndExit() -> unreachable { |
| 44 | callMain() %% linux.exit(1); | 47 | callMain() %% exit(1); |
| 45 | linux.exit(0); | 48 | exit(0); |
| 46 | } | 49 | } |
| 47 | 50 | ||
| 48 | export fn main(c_argc: i32, c_argv: &&u8) -> i32 { | 51 | export fn main(c_argc: i32, c_argv: &&u8) -> i32 { |
std/darwin.zig+6-1| ... | @@ -48,6 +48,11 @@ pub const SIGPWR = 30; | ... | @@ -48,6 +48,11 @@ pub const SIGPWR = 30; |
| 48 | pub const SIGSYS = 31; | 48 | pub const SIGSYS = 31; |
| 49 | pub const SIGUNUSED = SIGSYS; | 49 | pub const SIGUNUSED = SIGSYS; |
| 50 | 50 | ||
| 51 | pub fn exit(status: usize) -> unreachable { | ||
| 52 | arch.syscall1(arch.SYS_exit, status); | ||
| 53 | @unreachable() | ||
| 54 | } | ||
| 55 | |||
| 51 | /// Get the errno from a syscall return value, or 0 for no error. | 56 | /// Get the errno from a syscall return value, or 0 for no error. |
| 52 | pub fn getErrno(r: usize) -> usize { | 57 | pub fn getErrno(r: usize) -> usize { |
| 53 | const signed_r = *(&isize)(&r); | 58 | const signed_r = *(&isize)(&r); |
| ... | @@ -67,7 +72,7 @@ pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize { | ... | @@ -67,7 +72,7 @@ pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize { |
| 67 | } | 72 | } |
| 68 | 73 | ||
| 69 | pub fn open(path: []const u8, flags: usize, perm: usize) -> usize { | 74 | pub fn open(path: []const u8, flags: usize, perm: usize) -> usize { |
| 70 | var buf: [path.len + 1]u8 = undefined; | 75 | const buf = @alloca(u8, path.len + 1); |
| 71 | @memcpy(&buf[0], &path[0], path.len); | 76 | @memcpy(&buf[0], &path[0], path.len); |
| 72 | buf[path.len] = 0; | 77 | buf[path.len] = 0; |
| 73 | return open_c(buf.ptr, flags, perm); | 78 | return open_c(buf.ptr, flags, perm); |
std/darwin_x86_64.zig+1| ... | @@ -11,6 +11,7 @@ pub const SYSCALL_CLASS_DIAG = 4; // Diagnostics | ... | @@ -11,6 +11,7 @@ pub const SYSCALL_CLASS_DIAG = 4; // Diagnostics |
| 11 | 11 | ||
| 12 | // TODO: use the above constants to create the below values | 12 | // TODO: use the above constants to create the below values |
| 13 | 13 | ||
| 14 | pub const SYS_exit = 0x2000001; | ||
| 14 | pub const SYS_read = 0x2000003; | 15 | pub const SYS_read = 0x2000003; |
| 15 | pub const SYS_write = 0x2000004; | 16 | pub const SYS_write = 0x2000004; |
| 16 | pub const SYS_open = 0x2000005; | 17 | pub const SYS_open = 0x2000005; |