authorgravatar for ybham6@gmail.comfifty-six <ybham6@gmail.com> 2022-01-16 01:44:15-05:00
committergravatar for ybham6@gmail.comfifty-six <ybham6@gmail.com> 2022-01-16 02:04:39-05:00
log4771ac298b0c692750524cb7e94eaf0b4343ce2b
tree42b74453b3af7bc3cac4c0db9e9b4583348ca1ea
parentdab4c63684ca951049fb8e8f6b2415857eb6652b

std/os/uefi: Simplify packed struct padding and default zero-initialize

Beyond adding default zero-initialization, this commit changes undefined initialization to zero, as some cases reserved the padding and on other cases, I've found some systems act strange when giving uninit instead of zero even when it shouldn't be an issue, one example being FileProtocol.Open's attributes, which *should* be ignored when not creating a file, but ended up giving an unrelated error.

7 files changed, 10 insertions(+), 24 deletions(-)

lib/std/os/uefi.zig-2
...@@ -98,7 +98,6 @@ pub const Time = extern struct {...@@ -98,7 +98,6 @@ pub const Time = extern struct {
9898
99 /// 0 - 5999 /// 0 - 59
100 second: u8,100 second: u8,
101 _pad1: u8,
102101
103 /// 0 - 999999999102 /// 0 - 999999999
104 nanosecond: u32,103 nanosecond: u32,
...@@ -115,7 +114,6 @@ pub const Time = extern struct {...@@ -115,7 +114,6 @@ pub const Time = extern struct {
115 /// If true, the time is affected by daylight savings time.114 /// If true, the time is affected by daylight savings time.
116 adjust_daylight: bool,115 adjust_daylight: bool,
117 },116 },
118 _pad2: u8,
119117
120 /// Time is to be interpreted as local time118 /// Time is to be interpreted as local time
121 pub const unspecified_timezone: i16 = 0x7ff;119 pub const unspecified_timezone: i16 = 0x7ff;
lib/std/os/uefi/protocols/absolute_pointer_protocol.zig+2-6
...@@ -40,9 +40,7 @@ pub const AbsolutePointerMode = extern struct {...@@ -40,9 +40,7 @@ pub const AbsolutePointerMode = extern struct {
40 attributes: packed struct {40 attributes: packed struct {
41 supports_alt_active: bool,41 supports_alt_active: bool,
42 supports_pressure_as_z: bool,42 supports_pressure_as_z: bool,
43 _pad1: u6,43 _pad: u30 = 0,
44 _pad2: u8,
45 _pad3: u16,
46 },44 },
47};45};
4846
...@@ -53,8 +51,6 @@ pub const AbsolutePointerState = extern struct {...@@ -53,8 +51,6 @@ pub const AbsolutePointerState = extern struct {
53 active_buttons: packed struct {51 active_buttons: packed struct {
54 touch_active: bool,52 touch_active: bool,
55 alt_active: bool,53 alt_active: bool,
56 _pad1: u6,54 _pad: u30 = 0,
57 _pad2: u8,
58 _pad3: u16,
59 },55 },
60};56};
lib/std/os/uefi/protocols/edid_override_protocol.zig+1-3
...@@ -26,7 +26,5 @@ pub const EdidOverrideProtocol = extern struct {...@@ -26,7 +26,5 @@ pub const EdidOverrideProtocol = extern struct {
26pub const EdidOverrideProtocolAttributes = packed struct {26pub const EdidOverrideProtocolAttributes = packed struct {
27 dont_override: bool,27 dont_override: bool,
28 enable_hot_plug: bool,28 enable_hot_plug: bool,
29 _pad1: u6,29 _pad: u30 = 0,
30 _pad2: u8,
31 _pad3: u16,
32};30};
lib/std/os/uefi/protocols/hii.zig+2-2
...@@ -48,7 +48,7 @@ pub const NarrowGlyph = extern struct {...@@ -48,7 +48,7 @@ pub const NarrowGlyph = extern struct {
48 attributes: packed struct {48 attributes: packed struct {
49 non_spacing: bool,49 non_spacing: bool,
50 wide: bool,50 wide: bool,
51 _pad: u6,51 _pad: u6 = 0,
52 },52 },
53 glyph_col_1: [19]u8,53 glyph_col_1: [19]u8,
54};54};
...@@ -62,7 +62,7 @@ pub const WideGlyph = extern struct {...@@ -62,7 +62,7 @@ pub const WideGlyph = extern struct {
62 },62 },
63 glyph_col_1: [19]u8,63 glyph_col_1: [19]u8,
64 glyph_col_2: [19]u8,64 glyph_col_2: [19]u8,
65 _pad: [3]u8,65 _pad: [3]u8 = [_]u8{0} ** 3,
66};66};
6767
68pub const HIIStringPackage = extern struct {68pub const HIIStringPackage = extern struct {
lib/std/os/uefi/protocols/simple_network_protocol.zig+2-6
...@@ -126,9 +126,7 @@ pub const SimpleNetworkReceiveFilter = packed struct {...@@ -126,9 +126,7 @@ pub const SimpleNetworkReceiveFilter = packed struct {
126 receive_broadcast: bool,126 receive_broadcast: bool,
127 receive_promiscuous: bool,127 receive_promiscuous: bool,
128 receive_promiscuous_multicast: bool,128 receive_promiscuous_multicast: bool,
129 _pad1: u3 = undefined,129 _pad: u27 = 0,
130 _pad2: u8 = undefined,
131 _pad3: u16 = undefined,
132};130};
133131
134pub const SimpleNetworkState = enum(u32) {132pub const SimpleNetworkState = enum(u32) {
...@@ -171,7 +169,5 @@ pub const SimpleNetworkInterruptStatus = packed struct {...@@ -171,7 +169,5 @@ pub const SimpleNetworkInterruptStatus = packed struct {
171 transmit_interrupt: bool,169 transmit_interrupt: bool,
172 command_interrupt: bool,170 command_interrupt: bool,
173 software_interrupt: bool,171 software_interrupt: bool,
174 _pad1: u4,172 _pad: u28 = 0,
175 _pad2: u8,
176 _pad3: u16,
177};173};
lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig+2-2
...@@ -64,14 +64,14 @@ pub const KeyState = extern struct {...@@ -64,14 +64,14 @@ pub const KeyState = extern struct {
64 left_logo_pressed: bool,64 left_logo_pressed: bool,
65 menu_key_pressed: bool,65 menu_key_pressed: bool,
66 sys_req_pressed: bool,66 sys_req_pressed: bool,
67 _pad1: u21,67 _pad: u21 = 0,
68 shift_state_valid: bool,68 shift_state_valid: bool,
69 },69 },
70 key_toggle_state: packed struct {70 key_toggle_state: packed struct {
71 scroll_lock_active: bool,71 scroll_lock_active: bool,
72 num_lock_active: bool,72 num_lock_active: bool,
73 caps_lock_active: bool,73 caps_lock_active: bool,
74 _pad1: u3,74 _pad: u3 = 0,
75 key_state_exposed: bool,75 key_state_exposed: bool,
76 toggle_state_valid: bool,76 toggle_state_valid: bool,
77 },77 },
lib/std/os/uefi/tables/boot_services.zig+1-3
...@@ -239,9 +239,7 @@ pub const OpenProtocolAttributes = packed struct {...@@ -239,9 +239,7 @@ pub const OpenProtocolAttributes = packed struct {
239 by_child_controller: bool = false,239 by_child_controller: bool = false,
240 by_driver: bool = false,240 by_driver: bool = false,
241 exclusive: bool = false,241 exclusive: bool = false,
242 _pad1: u2 = undefined,242 _pad: u26 = 0,
243 _pad2: u8 = undefined,
244 _pad3: u16 = undefined,
245};243};
246244
247pub const ProtocolInformationEntry = extern struct {245pub const ProtocolInformationEntry = extern struct {