authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-10-31 02:15:16-07:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-11-03 19:25:46+02:00
logae6df9e96749cdd7cd4f84245ce20cfb3d4d6354
treef375ed81001ba2885ab5e6ca5c9a321094b49179
parent94cee4fb27a433824c2540dc37375dc14befdf47

start.zig: Replace kernel32 usage with ntdll

Co-authored-by: e4m2 <git@e4m2.com>

2 files changed, 9 insertions(+), 7 deletions(-)

lib/std/os/windows/ntdll.zig+4
......@@ -330,3 +330,7 @@ pub extern "ntdll" fn NtProtectVirtualMemory(
330330 NewAccessProtection: ULONG,
331331 OldAccessProtection: *ULONG,
332332) callconv(WINAPI) NTSTATUS;
333
334pub extern "ntdll" fn RtlExitUserProcess(
335 ExitStatus: u32,
336) callconv(WINAPI) noreturn;
lib/std/start.zig+5-7
......@@ -168,15 +168,13 @@ fn exit2(code: usize) noreturn {
168168 // exits(0)
169169 .plan9 => std.os.plan9.exits(null),
170170 .windows => {
171 ExitProcess(@as(u32, @truncate(code)));
171 std.os.windows.ntdll.RtlExitUserProcess(@as(u32, @truncate(code)));
172172 },
173173 else => @compileError("TODO"),
174174 }
175175 unreachable;
176176}
177177
178extern "kernel32" fn ExitProcess(exit_code: u32) callconv(.C) noreturn;
179
180178////////////////////////////////////////////////////////////////////////////////
181179
182180fn _DllMainCRTStartup(
......@@ -345,7 +343,7 @@ fn WinStartup() callconv(std.os.windows.WINAPI) noreturn {
345343
346344 std.debug.maybeEnableSegfaultHandler();
347345
348 std.os.windows.kernel32.ExitProcess(initEventLoopAndCallMain());
346 std.os.windows.ntdll.RtlExitUserProcess(initEventLoopAndCallMain());
349347}
350348
351349fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn {
......@@ -357,7 +355,7 @@ fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn {
357355 std.debug.maybeEnableSegfaultHandler();
358356
359357 const result: std.os.windows.INT = initEventLoopAndCallWinMain();
360 std.os.windows.kernel32.ExitProcess(@as(std.os.windows.UINT, @bitCast(result)));
358 std.os.windows.ntdll.RtlExitUserProcess(@as(std.os.windows.UINT, @bitCast(result)));
361359}
362360
363361fn posixCallMainAndExit() callconv(.C) noreturn {
......@@ -605,8 +603,8 @@ pub fn callMain() u8 {
605603pub fn call_wWinMain() std.os.windows.INT {
606604 const peb = std.os.windows.peb();
607605 const MAIN_HINSTANCE = @typeInfo(@TypeOf(root.wWinMain)).Fn.params[0].type.?;
608 const hInstance = @as(MAIN_HINSTANCE, @ptrCast(std.os.windows.kernel32.GetModuleHandleW(null).?));
609 const lpCmdLine = std.os.windows.kernel32.GetCommandLineW();
606 const hInstance = @as(MAIN_HINSTANCE, @ptrCast(peb.ImageBaseAddress));
607 const lpCmdLine: [*:0]u16 = @ptrCast(peb.ProcessParameters.CommandLine.Buffer);
610608
611609 // There are various types used for the 'show window' variable through the Win32 APIs:
612610 // - u16 in STARTUPINFOA.wShowWindow / STARTUPINFOW.wShowWindow