mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 01:24:49 +01:00
std.Threaded: replace more kernel32 functions with ntdll
This commit is contained in:
parent
12cb5b9285
commit
b5bd494606
27 changed files with 1694 additions and 2261 deletions
|
|
@ -4,17 +4,16 @@ const fatal = std.process.fatal;
|
|||
extern fn add(a: u32, b: u32, addr: *usize) u32;
|
||||
|
||||
pub fn main(init: std.process.Init) void {
|
||||
const gpa = init.gpa;
|
||||
const io = init.io;
|
||||
|
||||
var di: std.debug.SelfInfo = .init;
|
||||
defer di.deinit(gpa);
|
||||
defer di.deinit(io);
|
||||
|
||||
var add_addr: usize = undefined;
|
||||
_ = add(1, 2, &add_addr);
|
||||
|
||||
const symbol = di.getSymbol(gpa, io, add_addr) catch |err| fatal("failed to get symbol: {t}", .{err});
|
||||
defer if (symbol.source_location) |sl| gpa.free(sl.file_name);
|
||||
const symbol = di.getSymbol(io, add_addr) catch |err| fatal("failed to get symbol: {t}", .{err});
|
||||
defer if (symbol.source_location) |sl| std.debug.getDebugInfoAllocator().free(sl.file_name);
|
||||
|
||||
if (symbol.name == null) fatal("failed to resolve symbol name", .{});
|
||||
if (symbol.compile_unit_name == null) fatal("failed to resolve compile unit", .{});
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ fn spawnVerify(verify_path: [:0]const u16, cmd_line: [:0]const u16) !windows.DWO
|
|||
.hStdOutput = null,
|
||||
.hStdError = windows.peb().ProcessParameters.hStdError,
|
||||
};
|
||||
var proc_info: windows.PROCESS_INFORMATION = undefined;
|
||||
var proc_info: windows.PROCESS.INFORMATION = undefined;
|
||||
|
||||
if (windows.kernel32.CreateProcessW(
|
||||
@constCast(verify_path.ptr),
|
||||
|
|
@ -141,7 +141,7 @@ fn spawnVerify(verify_path: [:0]const u16, cmd_line: [:0]const u16) !windows.DWO
|
|||
&startup_info,
|
||||
&proc_info,
|
||||
) == 0) {
|
||||
std.process.fatal("kernel32 CreateProcessW failed with {t}", .{windows.kernel32.GetLastError()});
|
||||
std.process.fatal("kernel32 CreateProcessW failed with {t}", .{windows.GetLastError()});
|
||||
}
|
||||
|
||||
windows.CloseHandle(proc_info.hThread);
|
||||
|
|
@ -156,9 +156,15 @@ fn spawnVerify(verify_path: [:0]const u16, cmd_line: [:0]const u16) !windows.DWO
|
|||
else => |status| return windows.unexpectedStatus(status),
|
||||
}
|
||||
|
||||
var exit_code: windows.DWORD = undefined;
|
||||
if (windows.kernel32.GetExitCodeProcess(child_proc, &exit_code) == 0) {
|
||||
return error.UnableToGetExitCode;
|
||||
var info: windows.PROCESS.BASIC_INFORMATION = undefined;
|
||||
switch (windows.ntdll.NtQueryInformationProcess(
|
||||
child_proc,
|
||||
.BasicInformation,
|
||||
&info,
|
||||
@sizeOf(windows.PROCESS.BASIC_INFORMATION),
|
||||
null,
|
||||
)) {
|
||||
.SUCCESS => return @intFromEnum(info.ExitStatus),
|
||||
else => return error.UnableToGetExitCode,
|
||||
}
|
||||
return exit_code;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ fn testArgv(expected_args: []const [*:0]const u16) !void {
|
|||
defer arena_state.deinit();
|
||||
const allocator = arena_state.allocator();
|
||||
|
||||
const cmd_line = std.os.windows.peb().ProcessParameters.CommandLine;
|
||||
const cmd_line_w = cmd_line.Buffer.?[0..@divExact(cmd_line.Length, 2)];
|
||||
const raw_args: std.process.Args = .{ .vector = cmd_line_w };
|
||||
const raw_args: std.process.Args = .{
|
||||
.vector = std.os.windows.peb().ProcessParameters.CommandLine.slice(),
|
||||
};
|
||||
const args = try raw_args.toSlice(allocator);
|
||||
var wtf8_buf = std.array_list.Managed(u8).init(allocator);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue