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(...@@ -330,3 +330,7 @@ pub extern "ntdll" fn NtProtectVirtualMemory(
330 NewAccessProtection: ULONG,330 NewAccessProtection: ULONG,
331 OldAccessProtection: *ULONG,331 OldAccessProtection: *ULONG,
332) callconv(WINAPI) NTSTATUS;332) 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 {...@@ -168,15 +168,13 @@ fn exit2(code: usize) noreturn {
168 // exits(0)168 // exits(0)
169 .plan9 => std.os.plan9.exits(null),169 .plan9 => std.os.plan9.exits(null),
170 .windows => {170 .windows => {
171 ExitProcess(@as(u32, @truncate(code)));171 std.os.windows.ntdll.RtlExitUserProcess(@as(u32, @truncate(code)));
172 },172 },
173 else => @compileError("TODO"),173 else => @compileError("TODO"),
174 }174 }
175 unreachable;175 unreachable;
176}176}
177177
178extern "kernel32" fn ExitProcess(exit_code: u32) callconv(.C) noreturn;
179
180////////////////////////////////////////////////////////////////////////////////178////////////////////////////////////////////////////////////////////////////////
181179
182fn _DllMainCRTStartup(180fn _DllMainCRTStartup(
...@@ -345,7 +343,7 @@ fn WinStartup() callconv(std.os.windows.WINAPI) noreturn {...@@ -345,7 +343,7 @@ fn WinStartup() callconv(std.os.windows.WINAPI) noreturn {
345343
346 std.debug.maybeEnableSegfaultHandler();344 std.debug.maybeEnableSegfaultHandler();
347345
348 std.os.windows.kernel32.ExitProcess(initEventLoopAndCallMain());346 std.os.windows.ntdll.RtlExitUserProcess(initEventLoopAndCallMain());
349}347}
350348
351fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn {349fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn {
...@@ -357,7 +355,7 @@ fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn {...@@ -357,7 +355,7 @@ fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn {
357 std.debug.maybeEnableSegfaultHandler();355 std.debug.maybeEnableSegfaultHandler();
358356
359 const result: std.os.windows.INT = initEventLoopAndCallWinMain();357 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)));
361}359}
362360
363fn posixCallMainAndExit() callconv(.C) noreturn {361fn posixCallMainAndExit() callconv(.C) noreturn {
...@@ -605,8 +603,8 @@ pub fn callMain() u8 {...@@ -605,8 +603,8 @@ pub fn callMain() u8 {
605pub fn call_wWinMain() std.os.windows.INT {603pub fn call_wWinMain() std.os.windows.INT {
606 const peb = std.os.windows.peb();604 const peb = std.os.windows.peb();
607 const MAIN_HINSTANCE = @typeInfo(@TypeOf(root.wWinMain)).Fn.params[0].type.?;605 const MAIN_HINSTANCE = @typeInfo(@TypeOf(root.wWinMain)).Fn.params[0].type.?;
608 const hInstance = @as(MAIN_HINSTANCE, @ptrCast(std.os.windows.kernel32.GetModuleHandleW(null).?));606 const hInstance = @as(MAIN_HINSTANCE, @ptrCast(peb.ImageBaseAddress));
609 const lpCmdLine = std.os.windows.kernel32.GetCommandLineW();607 const lpCmdLine: [*:0]u16 = @ptrCast(peb.ProcessParameters.CommandLine.Buffer);
610608
611 // There are various types used for the 'show window' variable through the Win32 APIs:609 // There are various types used for the 'show window' variable through the Win32 APIs:
612 // - u16 in STARTUPINFOA.wShowWindow / STARTUPINFOW.wShowWindow610 // - u16 in STARTUPINFOA.wShowWindow / STARTUPINFOW.wShowWindow