Skip to content

Commit ae6df9e

Browse files
squeek502e4m2
authored andcommitted
start.zig: Replace kernel32 usage with ntdll
Co-authored-by: e4m2 <[email protected]>
1 parent 94cee4f commit ae6df9e

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/std/os/windows/ntdll.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,7 @@ pub extern "ntdll" fn NtProtectVirtualMemory(
330330
NewAccessProtection: ULONG,
331331
OldAccessProtection: *ULONG,
332332
) callconv(WINAPI) NTSTATUS;
333+
334+
pub extern "ntdll" fn RtlExitUserProcess(
335+
ExitStatus: u32,
336+
) callconv(WINAPI) noreturn;

lib/std/start.zig

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

178-
extern "kernel32" fn ExitProcess(exit_code: u32) callconv(.C) noreturn;
179-
180178
////////////////////////////////////////////////////////////////////////////////
181179

182180
fn _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

351349
fn 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

363361
fn posixCallMainAndExit() callconv(.C) noreturn {
@@ -605,8 +603,8 @@ pub fn callMain() u8 {
605603
pub 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

0 commit comments

Comments
 (0)