mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
change uefi packed structs to new integer backed syntax (#13173)
* std.os.uefi: integer backed structs, add tests to catch regressions device_path_protocol now uses extern structs with align(1) fields because the transition to integer backed packed struct broke alignment added comptime asserts that device_path_protocol structs do not violate alignment and size specifications
This commit is contained in:
parent
1696434063
commit
40e84a27d6
@ -50,7 +50,9 @@ comptime {
|
||||
test {
|
||||
_ = darwin;
|
||||
_ = linux;
|
||||
if (builtin.os.tag == .uefi) {
|
||||
_ = uefi;
|
||||
}
|
||||
_ = wasi;
|
||||
_ = windows;
|
||||
_ = posix_spawn;
|
||||
|
||||
@ -35,7 +35,7 @@ pub const Ipv6Address = extern struct {
|
||||
address: [16]u8,
|
||||
};
|
||||
|
||||
/// GUIDs must be align(8)
|
||||
/// GUIDs are align(8) unless otherwise specified.
|
||||
pub const Guid = extern struct {
|
||||
time_low: u32,
|
||||
time_mid: u16,
|
||||
@ -150,3 +150,8 @@ test "GUID formatting" {
|
||||
|
||||
try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287"));
|
||||
}
|
||||
|
||||
test {
|
||||
_ = tables;
|
||||
_ = protocols;
|
||||
}
|
||||
|
||||
@ -43,3 +43,8 @@ pub usingnamespace @import("protocols/udp6_protocol.zig");
|
||||
pub const hii = @import("protocols/hii.zig");
|
||||
pub usingnamespace @import("protocols/hii_database_protocol.zig");
|
||||
pub usingnamespace @import("protocols/hii_popup_protocol.zig");
|
||||
|
||||
test {
|
||||
@setEvalBranchQuota(2000);
|
||||
@import("std").testing.refAllDeclsRecursive(@This());
|
||||
}
|
||||
|
||||
@ -31,6 +31,12 @@ pub const AbsolutePointerProtocol = extern struct {
|
||||
};
|
||||
};
|
||||
|
||||
pub const AbsolutePointerModeAttributes = packed struct(u32) {
|
||||
supports_alt_active: bool,
|
||||
supports_pressure_as_z: bool,
|
||||
_pad: u30 = 0,
|
||||
};
|
||||
|
||||
pub const AbsolutePointerMode = extern struct {
|
||||
absolute_min_x: u64,
|
||||
absolute_min_y: u64,
|
||||
@ -38,20 +44,18 @@ pub const AbsolutePointerMode = extern struct {
|
||||
absolute_max_x: u64,
|
||||
absolute_max_y: u64,
|
||||
absolute_max_z: u64,
|
||||
attributes: packed struct {
|
||||
supports_alt_active: bool,
|
||||
supports_pressure_as_z: bool,
|
||||
attributes: AbsolutePointerModeAttributes,
|
||||
};
|
||||
|
||||
pub const AbsolutePointerStateActiveButtons = packed struct(u32) {
|
||||
touch_active: bool,
|
||||
alt_active: bool,
|
||||
_pad: u30 = 0,
|
||||
},
|
||||
};
|
||||
|
||||
pub const AbsolutePointerState = extern struct {
|
||||
current_x: u64,
|
||||
current_y: u64,
|
||||
current_z: u64,
|
||||
active_buttons: packed struct {
|
||||
touch_active: bool,
|
||||
alt_active: bool,
|
||||
_pad: u30 = 0,
|
||||
},
|
||||
active_buttons: AbsolutePointerStateActiveButtons,
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -6,19 +6,17 @@ const Status = uefi.Status;
|
||||
|
||||
/// Override EDID information
|
||||
pub const EdidOverrideProtocol = extern struct {
|
||||
_get_edid: std.meta.FnPtr(fn (*const EdidOverrideProtocol, Handle, *u32, *usize, *?[*]u8) callconv(.C) Status),
|
||||
_get_edid: std.meta.FnPtr(fn (*const EdidOverrideProtocol, Handle, *EdidOverrideProtocolAttributes, *usize, *?[*]u8) callconv(.C) Status),
|
||||
|
||||
/// Returns policy information and potentially a replacement EDID for the specified video output device.
|
||||
pub fn getEdid(
|
||||
self: *const EdidOverrideProtocol,
|
||||
handle: Handle,
|
||||
/// The align(4) here should really be part of the EdidOverrideProtocolAttributes type.
|
||||
/// TODO remove this workaround when packed(u32) structs are implemented.
|
||||
attributes: *align(4) EdidOverrideProtocolAttributes,
|
||||
attributes: *EdidOverrideProtocolAttributes,
|
||||
edid_size: *usize,
|
||||
edid: *?[*]u8,
|
||||
) Status {
|
||||
return self._get_edid(self, handle, @ptrCast(*u32, attributes), edid_size, edid);
|
||||
return self._get_edid(self, handle, attributes, edid_size, edid);
|
||||
}
|
||||
|
||||
pub const guid align(8) = Guid{
|
||||
@ -31,7 +29,7 @@ pub const EdidOverrideProtocol = extern struct {
|
||||
};
|
||||
};
|
||||
|
||||
pub const EdidOverrideProtocolAttributes = packed struct {
|
||||
pub const EdidOverrideProtocolAttributes = packed struct(u32) {
|
||||
dont_override: bool,
|
||||
enable_hot_plug: bool,
|
||||
_pad: u30 = 0,
|
||||
|
||||
@ -4,7 +4,7 @@ const Guid = uefi.Guid;
|
||||
pub const HIIHandle = *opaque {};
|
||||
|
||||
/// The header found at the start of each package.
|
||||
pub const HIIPackageHeader = packed struct {
|
||||
pub const HIIPackageHeader = packed struct(u32) {
|
||||
length: u24,
|
||||
type: u8,
|
||||
|
||||
@ -43,23 +43,27 @@ pub const HIISimplifiedFontPackage = extern struct {
|
||||
}
|
||||
};
|
||||
|
||||
pub const NarrowGlyph = extern struct {
|
||||
unicode_weight: u16,
|
||||
attributes: packed struct {
|
||||
pub const NarrowGlyphAttributes = packed struct(u8) {
|
||||
non_spacing: bool,
|
||||
wide: bool,
|
||||
_pad: u6 = 0,
|
||||
},
|
||||
};
|
||||
|
||||
pub const NarrowGlyph = extern struct {
|
||||
unicode_weight: u16,
|
||||
attributes: NarrowGlyphAttributes,
|
||||
glyph_col_1: [19]u8,
|
||||
};
|
||||
|
||||
pub const WideGlyphAttributes = packed struct(u8) {
|
||||
non_spacing: bool,
|
||||
wide: bool,
|
||||
_pad: u6 = 0,
|
||||
};
|
||||
|
||||
pub const WideGlyph = extern struct {
|
||||
unicode_weight: u16,
|
||||
attributes: packed struct {
|
||||
non_spacing: bool,
|
||||
wide: bool,
|
||||
_pad: u6,
|
||||
},
|
||||
attributes: WideGlyphAttributes,
|
||||
glyph_col_1: [19]u8,
|
||||
glyph_col_2: [19]u8,
|
||||
_pad: [3]u8 = [_]u8{0} ** 3,
|
||||
|
||||
@ -121,7 +121,7 @@ pub const SimpleNetworkMode = extern struct {
|
||||
media_present: bool,
|
||||
};
|
||||
|
||||
pub const SimpleNetworkReceiveFilter = packed struct {
|
||||
pub const SimpleNetworkReceiveFilter = packed struct(u32) {
|
||||
receive_unicast: bool,
|
||||
receive_multicast: bool,
|
||||
receive_broadcast: bool,
|
||||
@ -165,7 +165,7 @@ pub const NetworkStatistics = extern struct {
|
||||
tx_retry_frames: u64,
|
||||
};
|
||||
|
||||
pub const SimpleNetworkInterruptStatus = packed struct {
|
||||
pub const SimpleNetworkInterruptStatus = packed struct(u32) {
|
||||
receive_interrupt: bool,
|
||||
transmit_interrupt: bool,
|
||||
command_interrupt: bool,
|
||||
|
||||
@ -53,8 +53,7 @@ pub const KeyData = extern struct {
|
||||
key_state: KeyState = undefined,
|
||||
};
|
||||
|
||||
pub const KeyState = extern struct {
|
||||
key_shift_state: packed struct {
|
||||
pub const KeyShiftState = packed struct(u32) {
|
||||
right_shift_pressed: bool,
|
||||
left_shift_pressed: bool,
|
||||
right_control_pressed: bool,
|
||||
@ -67,15 +66,20 @@ pub const KeyState = extern struct {
|
||||
sys_req_pressed: bool,
|
||||
_pad: u21 = 0,
|
||||
shift_state_valid: bool,
|
||||
},
|
||||
key_toggle_state: packed struct {
|
||||
};
|
||||
|
||||
pub const KeyToggleState = packed struct(u8) {
|
||||
scroll_lock_active: bool,
|
||||
num_lock_active: bool,
|
||||
caps_lock_active: bool,
|
||||
_pad: u3 = 0,
|
||||
key_state_exposed: bool,
|
||||
toggle_state_valid: bool,
|
||||
},
|
||||
};
|
||||
|
||||
pub const KeyState = extern struct {
|
||||
key_shift_state: KeyShiftState,
|
||||
key_toggle_state: KeyToggleState,
|
||||
};
|
||||
|
||||
pub const InputKey = extern struct {
|
||||
|
||||
@ -3,3 +3,7 @@ pub usingnamespace @import("tables/runtime_services.zig");
|
||||
pub usingnamespace @import("tables/configuration_table.zig");
|
||||
pub usingnamespace @import("tables/system_table.zig");
|
||||
pub usingnamespace @import("tables/table_header.zig");
|
||||
|
||||
test {
|
||||
@import("std").testing.refAllDeclsRecursive(@This());
|
||||
}
|
||||
|
||||
@ -219,20 +219,13 @@ pub const MemoryType = enum(u32) {
|
||||
_,
|
||||
};
|
||||
|
||||
pub const MemoryDescriptor = extern struct {
|
||||
type: MemoryType,
|
||||
padding: u32,
|
||||
physical_start: u64,
|
||||
virtual_start: u64,
|
||||
number_of_pages: usize,
|
||||
attribute: packed struct {
|
||||
pub const MemoryDescriptorAttribute = packed struct(u64) {
|
||||
uc: bool,
|
||||
wc: bool,
|
||||
wt: bool,
|
||||
wb: bool,
|
||||
uce: bool,
|
||||
_pad1: u3,
|
||||
_pad2: u4,
|
||||
_pad1: u7 = 0,
|
||||
wp: bool,
|
||||
rp: bool,
|
||||
xp: bool,
|
||||
@ -241,11 +234,17 @@ pub const MemoryDescriptor = extern struct {
|
||||
ro: bool,
|
||||
sp: bool,
|
||||
cpu_crypto: bool,
|
||||
_pad3: u4,
|
||||
_pad4: u32,
|
||||
_pad5: u7,
|
||||
_pad2: u43 = 0,
|
||||
memory_runtime: bool,
|
||||
},
|
||||
};
|
||||
|
||||
pub const MemoryDescriptor = extern struct {
|
||||
type: MemoryType,
|
||||
padding: u32,
|
||||
physical_start: u64,
|
||||
virtual_start: u64,
|
||||
number_of_pages: usize,
|
||||
attribute: MemoryDescriptorAttribute,
|
||||
};
|
||||
|
||||
pub const LocateSearchType = enum(u32) {
|
||||
@ -254,14 +253,14 @@ pub const LocateSearchType = enum(u32) {
|
||||
ByProtocol,
|
||||
};
|
||||
|
||||
pub const OpenProtocolAttributes = packed struct {
|
||||
pub const OpenProtocolAttributes = packed struct(u32) {
|
||||
by_handle_protocol: bool = false,
|
||||
get_protocol: bool = false,
|
||||
test_protocol: bool = false,
|
||||
by_child_controller: bool = false,
|
||||
by_driver: bool = false,
|
||||
exclusive: bool = false,
|
||||
_pad: u26 = 0,
|
||||
reserved: u26 = 0,
|
||||
};
|
||||
|
||||
pub const ProtocolInformationEntry = extern struct {
|
||||
|
||||
@ -78,7 +78,7 @@ pub const CapsuleHeader = extern struct {
|
||||
|
||||
pub const UefiCapsuleBlockDescriptor = extern struct {
|
||||
length: u64,
|
||||
address: union {
|
||||
address: extern union {
|
||||
dataBlock: EfiPhysicalAddress,
|
||||
continuationPointer: EfiPhysicalAddress,
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user