Uh oh!
There was an error while loading. Please reload this page.
std.os.uefi.tables: ziggify boot and runtime services - #23441
Conversation
commented
Apr 2, 2025
commented
Apr 2, 2025
It is appreciated! :^) |
ee41a75 to
e4487d5CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| /// Returns the current memory map. | ||
| getMemoryMap: *const fn (mmap_size: *usize, mmap: ?[*]MemoryDescriptor, map_key: *usize, descriptor_size: *usize, descriptor_version: *u32) callconv(cc) Status, | ||
| _getMemoryMap: *const fn (mmap_size: *usize, mmap: [*]MemoryDescriptor, map_key: *MemoryMapKey, descriptor_size: *usize, descriptor_version: *u32) callconv(cc) Status, |
There was a problem hiding this comment.
i figured it's safer to obscure map_key values since as far as i can tell it's meant to be assigned by the system (only retrievable via getMemoryMap)
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| interfaces: anytype, | ||
| ) InstallProtocolInterfacesError!Handle { | ||
| var hdl: ?Handle = handle; | ||
| const args_tuple = protocolInterfaces(&hdl, interfaces); |
There was a problem hiding this comment.
i couldn't find an easier way to manage dynamically constructing a tuple than this helper :/
| }; | ||
| }; | ||
| fn protocolInterfaces( |
There was a problem hiding this comment.
this function is kinda gross :/ suggestions are welcome
Uh oh!
There was an error while loading. Please reload this page.
left a comment
There was a problem hiding this comment.
A few minor nitpicks, but since we're overhauling boot services it's time we remove [*]MemoryDescriptor and []MemoryDescriptor from std.os.uefi, they are never valid because the size of the zig struct is almost never the size of the descriptor the firmware returns.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
e4487d5 to
5ad806eCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| raiseTpl: *const fn (new_tpl: usize) callconv(cc) usize, | ||
| raiseTpl: *const fn (new_tpl: TaskPriorityLevel) callconv(cc) TaskPriorityLevel, | ||
| /// Restores a task's priority level to its previous value. | ||
| restoreTpl: *const fn (old_tpl: usize) callconv(cc) void, | ||
| restoreTpl: *const fn (old_tpl: TaskPriorityLevel) callconv(cc) void, |
There was a problem hiding this comment.
doesn't make sense to define wrappers for these functions imo
Uh oh!
There was an error while loading. Please reload this page.
| _createEventEx: *const fn (type: u32, notify_tpl: usize, notify_func: EventNotify, notify_ctx: *const anyopaque, event_group: *align(8) const Guid, event: *Event) callconv(cc) Status, | ||
| /// Opens a protocol with a structure as the loaded image for a UEFI application | ||
| pub fn openProtocolSt(self: *BootServices, comptime protocol: type, handle: Handle) !*protocol { |
There was a problem hiding this comment.
this function is now basically the handleProtocol function
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
50823da to
0733531CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| // ExitData buffer must be allocated using boot_services.allocatePool (spec: page 220) | ||
| const exit_data: []u16 = uefi.raw_pool_allocator.alloc(u16, exit_msg.len + 1) catch @trap(); | ||
| @memcpy(exit_data, exit_msg[0..exit_data.len]); // Includes null terminator. | ||
| _ = bs.exit(uefi.handle, .aborted, exit_data.len, exit_data.ptr); |
There was a problem hiding this comment.
afaict this was a bug 😬 exit_data.len for number of u16s but the spec says it's the number of bytes
commented
Apr 4, 2025 •
i feel like this is ready for a final review :) i haven't tried it with my own project yet though, i'll tackle that later |
| _setWatchdogTimer: *const fn (timeout: usize, watchdog_code: u64, data_size: usize, watchdog_data: ?[*]const u16) callconv(cc) Status, | ||
| /// Connects one or more drives to a controller. | ||
| _connectController: *const fn (controller_handle: Handle, driver_image_handle: ?[*:null]Handle, remaining_device_path: ?*const DevicePathProtocol, recursive: bool) callconv(cc) Status, |
There was a problem hiding this comment.
really feels like [*:null]*anyopaque should work :(
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
commented
Apr 10, 2025
haven't forgotten or abandoned this, I'm dealing with immigration stuffs :) I'll pick it up again soon |
| /// A handle to an event structure. | ||
| pub const Event = *opaque {}; | ||
| pub const EventRegistration = opaque {}; |
There was a problem hiding this comment.
I decided to not keep this as *const opaque{} since it might be nice to have the namespace eventually? idk
There was a problem hiding this comment.
I actually feel like it'd be handy to do that for Event eventually 🙃
There was a problem hiding this comment.
The standard describes an event registration as a VOID*, and the standard provides absolutely no methods to operate on the registration value other than passing around the VOID*, so I say it makes no sense to change this from a *opaque{}.
If for some reason someone finds a good reason to make this a namespace that would be a better time to make this change.
Uh oh!
There was an error while loading. Please reload this page.
46d8e68 to
d37be42Compare
commented
Apr 14, 2025 •
ah sorry i think i rebased and didn't mean to push the rebase 😅 here's the changes link for commits from last night: https://github.com/ziglang/zig/pull/23441/files/13858228112d8ee6798dd51032728f68c512bc5f..d37be4284b844684cd1f39b2fd543d8003dcb348 |
| /// A handle to an event structure. | ||
| pub const Event = *opaque {}; | ||
| pub const EventRegistration = opaque {}; |
There was a problem hiding this comment.
The standard describes an event registration as a VOID*, and the standard provides absolutely no methods to operate on the registration value other than passing around the VOID*, so I say it makes no sense to change this from a *opaque{}.
If for some reason someone finds a good reason to make this a namespace that would be a better time to make this change.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| pub const InvalidValue = math.IntFittingRange( | ||
| @intFromEnum(MemoryType.invalid_start), | ||
| @intFromEnum(MemoryType.invalid_end), | ||
| ); | ||
| pub const OemValue = math.IntFittingRange( | ||
| @intFromEnum(MemoryType.oem_start), | ||
| @intFromEnum(MemoryType.oem_end), | ||
| ); | ||
| pub const VendorValue = math.IntFittingRange( | ||
| @intFromEnum(MemoryType.vendor_start), | ||
| @intFromEnum(MemoryType.vendor_end), | ||
| ); |
There was a problem hiding this comment.
- define
IntFittingRangefor the relevant value range
There was a problem hiding this comment.
oh wait the start should be 0 😅 and the end should be _start - _end 😅
| pub fn invalid(value: InvalidValue) MemoryType { | ||
| const invalid_start = @intFromEnum(MemoryType.invalid_start); | ||
| return @enumFromInt(invalid_start + value); | ||
| } |
There was a problem hiding this comment.
- function for constructing such values ie
pub const my_invalid: MemoryType = .invalid(0x2);
There was a problem hiding this comment.
Why are we constructing invalid memory types?
| pub fn getInvalid(memtype: MemoryType) ?InvalidValue { | ||
| const as_int = @intFromEnum(memtype); | ||
| const invalid_start = @intFromEnum(MemoryType.invalid_start); | ||
| if (as_int < invalid_start) return null; | ||
| if (as_int > @intFromEnum(MemoryType.invalid_end)) return null; | ||
| return @truncate(as_int - invalid_start); | ||
| } |
There was a problem hiding this comment.
- function for retrieving the value relative to the range's start
commented
Apr 18, 2025 •
IMO, it is also a good idea to use |
commented
Apr 18, 2025
Not that that's a bad idea for the special case of exactly 4K alignment, I definitely would need a source to back up that |
commented
Apr 18, 2025
I don't have an exact source to back this up, but testing on some hardware I have available I found that allocatePage is significantly slower than allocatePool. |
This backs out commit cdd9bd6.
51ed5dc to
819a6c6Compare
commented
Jul 2, 2025
rebased to latest master :) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
3065959 to
819a6c6Compare
commented
Jul 11, 2025
^ tried to rebase on latest master but the diff got nasty, i'll merge. reverted the rebase-push |
commented
Jul 12, 2025
CI is failing |
commented
Jul 12, 2025
yup, just saw that lol, looking into it now |
commented
Jul 12, 2025
Thanks for your patience with this! Let's merge 🎉 |
commented
Jul 12, 2025
LFG, glad to see this. I hope we can get #22226 next. I'll rebase it tonight after work, feel free to review. |

this PR updates
BootServicesandRuntimeServicesto an idiomatic interface similar to the pattern used instd.os.uefi.protocol. Part of my crusade towards makingstd.os.uefimore idiomatic