authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-02 10:20:05+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-02 12:24:15-05:00
log5eaacf1ce9b2b99f1f29bf51a663291329a1793e
treed64ba2a49b7ce2c283f70d7dd997c20581b18573
parent16dc86a49e1e92d036d196be40a4fc073314bcf7

windows: use array of tmp bufs as backing store for input memory to ntdll


1 files changed, 11 insertions(+), 14 deletions(-)

lib/std/zig/system/windows.zig+11-14
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const assert = std.debug.assert;
34const mem = std.mem;
45const Target = std.Target;
56
......@@ -89,6 +90,8 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
8990 .DefaultLength = 0,
9091 };
9192
93 var tmp_bufs: [fields_info.len][max_value_len]u8 align(@alignOf(std.os.windows.UNICODE_STRING)) = undefined;
94
9295 inline for (fields_info) |field, i| {
9396 const ctx: *anyopaque = blk: {
9497 switch (@field(args, field.name).value_type) {
......@@ -96,26 +99,20 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
9699 REG.EXPAND_SZ,
97100 REG.MULTI_SZ,
98101 => {
99 var buf: [max_value_len / 2]u16 = undefined;
100 var unicode = std.os.windows.UNICODE_STRING{
102 comptime assert(@sizeOf(std.os.windows.UNICODE_STRING) % 2 == 0);
103 const unicode = @ptrCast(*std.os.windows.UNICODE_STRING, &tmp_bufs[i]);
104 unicode.* = .{
101105 .Length = 0,
102 .MaximumLength = max_value_len,
103 .Buffer = &buf,
106 .MaximumLength = max_value_len - @sizeOf(std.os.windows.UNICODE_STRING),
107 .Buffer = @ptrCast([*]u16, tmp_bufs[i][@sizeOf(std.os.windows.UNICODE_STRING)..]),
104108 };
105 break :blk &unicode;
109 break :blk unicode;
106110 },
107111
108112 REG.DWORD,
109113 REG.DWORD_BIG_ENDIAN,
110 => {
111 var buf: [4]u8 = undefined;
112 break :blk &buf;
113 },
114
115 REG.QWORD => {
116 var buf: [8]u8 = undefined;
117 break :blk &buf;
118 },
114 REG.QWORD,
115 => break :blk &tmp_bufs[i],
119116
120117 else => unreachable,
121118 }