diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-06-14 00:04:34 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-06-14 00:04:34 -0400 |
| commit | 6a93dda3e1c0ff5f400da25a5d14c907fc9a6fdf (patch) | |
| tree | 08260222b967ccf73f237ae97824c054c023c9b8 /std/special/bootstrap.zig | |
| parent | 199bbb6292896330ced71dec2e5c58a49af5907e (diff) | |
| download | zig-6a93dda3e1c0ff5f400da25a5d14c907fc9a6fdf.tar.gz zig-6a93dda3e1c0ff5f400da25a5d14c907fc9a6fdf.zip | |
progress toward windows hello world working
Diffstat (limited to 'std/special/bootstrap.zig')
| -rw-r--r-- | std/special/bootstrap.zig | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig index 3c1fe86ceb..d2554fd8df 100644 --- a/std/special/bootstrap.zig +++ b/std/special/bootstrap.zig @@ -5,19 +5,23 @@ const root = @import("@root"); const std = @import("std"); const builtin = @import("builtin"); -const want_main_symbol = std.target.linking_libc; +const want_main_symbol = builtin.link_libc; const want_start_symbol = !want_main_symbol; -const posix_exit = std.os.posix.exit; - var argc_ptr: &usize = undefined; +const is_windows = builtin.os == builtin.Os.windows; + export nakedcc fn _start() -> noreturn { if (!want_start_symbol) { @setGlobalLinkage(_start, builtin.GlobalLinkage.Internal); unreachable; } + if (is_windows) { + windowsCallMainAndExit() + } + switch (builtin.arch) { builtin.Arch.x86_64 => { argc_ptr = asm("lea (%%rsp), %[argc]": [argc] "=r" (-> &usize)); @@ -27,23 +31,21 @@ export nakedcc fn _start() -> noreturn { }, else => @compileError("unsupported arch"), } - callMainAndExit() + posixCallMainAndExit() +} + +fn windowsCallMainAndExit() -> noreturn { + std.debug.user_main_fn = root.main; + root.main() %% std.os.windows.ExitProcess(1); + std.os.windows.ExitProcess(0); } -fn callMainAndExit() -> noreturn { +fn posixCallMainAndExit() -> noreturn { const argc = *argc_ptr; const argv = @ptrCast(&&u8, &argc_ptr[1]); const envp = @ptrCast(&?&u8, &argv[argc + 1]); - callMain(argc, argv, envp) %% exit(true); - exit(false); -} - -fn exit(failure: bool) -> noreturn { - if (builtin.os == builtin.Os.windows) { - std.os.windows.ExitProcess(c_uint(failure)); - } else { - posix_exit(i32(failure)); - } + callMain(argc, argv, envp) %% std.os.posix.exit(1); + std.os.posix.exit(0); } fn callMain(argc: usize, argv: &&u8, envp: &?&u8) -> %void { |
