authorgravatar for spexguy070@gmail.comMartin Wickham <spexguy070@gmail.com> 2021-09-01 14:32:02-05:00
committergravatar for spexguy070@gmail.comMartin Wickham <spexguy070@gmail.com> 2021-09-22 13:58:49-05:00
logd6e87da47b61ac31fe93a212d4f47eae55fec492
treed57a5ef5d791385d9b55072f338735a79c8f5ba4
parent3b09262c1252de0d9f946630e701be65bc5b2fc7

Make stage2 start.zig work on Windows


1 files changed, 12 insertions(+), 0 deletions(-)

lib/std/start.zig+12
...@@ -28,6 +28,8 @@ comptime {...@@ -28,6 +28,8 @@ comptime {
28 if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {28 if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
29 @export(main2, .{ .name = "main" });29 @export(main2, .{ .name = "main" });
30 }30 }
31 } else if (builtin.stage2_os == .windows) {
32 @export(wWinMainCRTStartup2, .{ .name = "wWinMainCRTStartup" });
31 } else {33 } else {
32 if (!@hasDecl(root, "_start")) {34 if (!@hasDecl(root, "_start")) {
33 @export(_start2, .{ .name = "_start" });35 @export(_start2, .{ .name = "_start" });
...@@ -96,6 +98,11 @@ fn callMain2() noreturn {...@@ -96,6 +98,11 @@ fn callMain2() noreturn {
96 exit2(0);98 exit2(0);
97}99}
98100
101fn wWinMainCRTStartup2() callconv(.C) noreturn {
102 root.main();
103 exit2(0);
104}
105
99fn exit2(code: usize) noreturn {106fn exit2(code: usize) noreturn {
100 switch (native_os) {107 switch (native_os) {
101 .linux => switch (builtin.stage2_arch) {108 .linux => switch (builtin.stage2_arch) {
...@@ -148,11 +155,16 @@ fn exit2(code: usize) noreturn {...@@ -148,11 +155,16 @@ fn exit2(code: usize) noreturn {
148 },155 },
149 else => @compileError("TODO"),156 else => @compileError("TODO"),
150 },157 },
158 .windows => {
159 ExitProcess(@truncate(u32, code));
160 },
151 else => @compileError("TODO"),161 else => @compileError("TODO"),
152 }162 }
153 unreachable;163 unreachable;
154}164}
155165
166extern "kernel32" fn ExitProcess(exit_code: u32) callconv(.C) noreturn;
167
156////////////////////////////////////////////////////////////////////////////////168////////////////////////////////////////////////////////////////////////////////
157169
158fn _DllMainCRTStartup(170fn _DllMainCRTStartup(