跳转到内容

std.os.uefi.tables.boot_services

标准库Zig 0.17.1官方原文
源码std/os/uefi/tables/boot_services.zig

第 1 行

std.os.uefi.tables.boot_services.AllocateLocation

别名

第 12 行

别名目标 std.os.uefi.tables.AllocateLocation

std.os.uefi.tables.boot_services.AllocateType

别名

第 13 行

别名目标 std.os.uefi.tables.AllocateType

std.os.uefi.tables.boot_services.BootServices

容器

第 41 行

引导服务是系统固件提供的服务,直到操作系统通过调用 exitBootServices 接管硬件控制权为止。

调用 exitBootServices 后,不得继续使用引导服务。唯一例外为 getMemoryMap:第一次调用 exitBootServices 失败后,仍可使用它。成功调用 exitBootServices 后,应将 system_table.console_in_handle、system_table.con_in、system_table.console_out_handle、system_table.con_out、system_table.standard_error_handle、system_table.std_err 和 system_table.boot_services 设为 null。设置这些属性后,必须重新计算 system_table.hdr.crc32。

boot_services 表可能随新 UEFI 版本扩展,因此必须检查 hdr.header_size。

字段

hdr: TableHeader
raiseTpl: *const fn (new_tpl: TaskPriorityLevel) callconv(cc) TaskPriorityLevel

提高任务的优先级,并返回其先前的优先级。

restoreTpl: *const fn (old_tpl: TaskPriorityLevel) callconv(cc) void

将任务的优先级恢复为先前值。

_allocatePages: *const fn (alloc_type: AllocateType, mem_type: MemoryType, pages: usize, memory: *[*]align(4096) Page) callconv(cc) Status

从系统分配内存页。

_freePages: *const fn (memory: [*]align(4096) Page, pages: usize) callconv(cc) Status

释放内存页。

_getMemoryMap: *const fn (mmap_size: *usize, mmap: ?[*]align(@alignOf(MemoryDescriptor)) u8, map_key: *MemoryMapKey, descriptor_size: *usize, descriptor_version: *u32) callconv(cc) Status

返回当前内存映射。

_allocatePool: *const fn (pool_type: MemoryType, size: usize, buffer: *[*]align(8) u8) callconv(cc) Status

分配池内存。

_freePool: *const fn (buffer: [*]align(8) u8) callconv(cc) Status

将池内存归还系统。

_createEvent: *const fn (type: u32, notify_tpl: TaskPriorityLevel, notify_func: ?*const fn (Event, ?*anyopaque) callconv(cc) void, notify_ctx: ?*anyopaque, event: *Event) callconv(cc) Status

创建事件。

_setTimer: *const fn (event: Event, type: TimerDelay, trigger_time: u64) callconv(cc) Status

设置定时器事件的定时器类型及触发时间。

_waitForEvent: *const fn (event_len: usize, events: [*]const Event, index: *usize) callconv(cc) Status

暂停执行,直到事件收到信号。

_signalEvent: *const fn (event: Event) callconv(cc) Status

发出事件信号。

_closeEvent: *const fn (event: Event) callconv(cc) Status

关闭事件。

_checkEvent: *const fn (event: Event) callconv(cc) Status

检查事件是否处于已通知状态。

_installProtocolInterface: *const fn (handle: Handle, protocol: *const Guid, interface_type: InterfaceType, interface: *anyopaque) callconv(cc) Status

在设备句柄上安装协议接口。如果句柄不存在,则创建该句柄 并加入系统句柄列表。installMultipleProtocolInterfaces() 比 installProtocolInterface() 执行更多错误检查,因此建议优先使用前者。

_reinstallProtocolInterface: *const fn (handle: Handle, protocol: *const Guid, old_interface: *anyopaque, new_interface: *anyopaque) callconv(cc) Status

在设备句柄上重新安装协议接口

_uninstallProtocolInterface: *const fn (handle: Handle, protocol: *const Guid, interface: *anyopaque) callconv(cc) Status

从设备句柄中移除协议接口。 建议改用 uninstallMultipleProtocolInterfaces。

_handleProtocol: *const fn (handle: Handle, protocol: *const Guid, interface: *?*anyopaque) callconv(cc) Status

查询句柄,确定它是否支持指定协议。

_reserved: *anyopaque
_registerProtocolNotify: *const fn (protocol: *const Guid, event: Event, registration: *EventRegistration) callconv(cc) Status

创建一个事件,每当为指定协议安装接口时就触发该事件。

_locateHandle: *const fn (search_type: LocateSearchType, protocol: ?*const Guid, search_key: ?*const anyopaque, buffer_size: *usize, buffer: ?[*]Handle) callconv(cc) Status

返回支持指定协议的句柄数组。

_locateDevicePath: *const fn (protocols: *const Guid, device_path: **const DevicePathProtocol, device: *?Handle) callconv(cc) Status

查找设备路径上支持指定协议的设备句柄

_installConfigurationTable: *const fn (guid: *const Guid, table: ?*anyopaque) callconv(cc) Status

在 EFI 系统表中添加、更新或移除配置表条目。

_loadImage: *const fn (boot_policy: bool, parent_image_handle: Handle, device_path: ?*const DevicePathProtocol, source_buffer: ?[*]const u8, source_size: usize, image_handle: *Handle) callconv(cc) Status

将 EFI 映像加载到内存。

_startImage: *const fn (image_handle: Handle, exit_data_size: ?*usize, exit_data: ?*[*]u16) callconv(cc) Status

将控制权转移到已加载映像的入口点。

_exit: *const fn (image_handle: Handle, exit_status: Status, exit_data_size: usize, exit_data: ?[*]align(2) const u8) callconv(cc) Status

终止已加载的 EFI 映像,并将控制权返回启动服务。

_unloadImage: *const fn (image_handle: Handle) callconv(cc) Status

卸载映像。

_exitBootServices: *const fn (image_handle: Handle, map_key: MemoryMapKey) callconv(cc) Status

终止所有启动服务。

_getNextMonotonicCount: *const fn (count: *u64) callconv(cc) Status

返回平台的单调递增计数。

_stall: *const fn (microseconds: usize) callconv(cc) Status

引入精细粒度的暂停。

_setWatchdogTimer: *const fn (timeout: usize, watchdog_code: u64, data_size: usize, watchdog_data: ?[*]const u16) callconv(cc) Status

设置系统看门狗定时器。

_connectController: *const fn (controller_handle: Handle, driver_image_handle: ?[*:null]?Handle, remaining_device_path: ?*const DevicePathProtocol, recursive: bool) callconv(cc) Status

将一个或多个驱动器连接到控制器。

_disconnectController: *const fn (controller_handle: Handle, driver_image_handle: ?Handle, child_handle: ?Handle) callconv(cc) Status
_openProtocol: *const fn (handle: Handle, protocol: *const Guid, interface: ?*?*anyopaque, agent_handle: ?Handle, controller_handle: ?Handle, attributes: OpenProtocolAttributes) callconv(cc) Status

查询句柄,确定它是否支持指定协议。

_closeProtocol: *const fn (handle: Handle, protocol: *const Guid, agent_handle: Handle, controller_handle: ?Handle) callconv(cc) Status

关闭通过 openProtocol() 打开的句柄上的协议。

_openProtocolInformation: *const fn (handle: Handle, protocol: *const Guid, entry_buffer: *[*]ProtocolInformationEntry, entry_count: *usize) callconv(cc) Status

获取当前已打开某协议接口的代理列表。

_protocolsPerHandle: *const fn (handle: Handle, protocol_buffer: *[*]*const Guid, protocol_buffer_count: *usize) callconv(cc) Status

获取已安装于句柄上的协议接口 GUID 列表,存入从池分配的缓冲区。

_locateHandleBuffer: *const fn (search_type: LocateSearchType, protocol: ?*const Guid, search_key: ?*const anyopaque, num_handles: *usize, buffer: *[*]Handle) callconv(cc) Status

在池中分配的缓冲区中返回支持请求协议的句柄数组。

_locateProtocol: *const fn (protocol: *const Guid, registration: ?EventRegistration, interface: *?*const anyopaque) callconv(cc) Status

返回与给定协议匹配的第一个协议实例。

_installMultipleProtocolInterfaces: *const fn (handle: *?Handle, ...) callconv(cc) Status

将一个或多个协议接口安装到启动服务环境中。

_uninstallMultipleProtocolInterfaces: *const fn (handle: Handle, ...) callconv(cc) Status

从启动服务环境中移除一个或多个协议接口。

_calculateCrc32: *const fn (data: [*]const u8, data_size: usize, *u32) callconv(cc) Status

计算并返回数据缓冲区的 32 位 CRC。

_copyMem: *const fn (dest: [*]u8, src: [*]const u8, len: usize) callconv(cc) void

将一个缓冲区的内容复制到另一个缓冲区

_setMem: *const fn (buffer: [*]u8, size: usize, value: u8) callconv(cc) void

使用指定值填充缓冲区

_createEventEx: *const fn (type: u32, notify_tpl: usize, notify_func: EventNotify, notify_ctx: *const anyopaque, event_group: *const Guid, event: *Event) callconv(cc) Status

在组中创建事件。

std.os.uefi.tables.boot_services.BootServices.allocatePages

函数

第 370 行

分配内存页。

此函数扫描内存映射以查找空闲页。找到足够大的物理连续页块,且该页块满足 alloc_type 的分配要求后,会修改内存映射,将这些页标记为 mem_type 类型。

通常,UEFI 操作系统加载器与 UEFI 应用程序应分配 .loader_data 类型的内存和内存池。UEFI 引导服务驱动必须分配 .boot_services_data 类型的内存和内存池。UEFI 运行时驱动应分配 .runtime_services_data 类型的内存和内存池,不过只能在引导服务阶段执行此类分配。

.allocate_any_pages 分配请求会分配任意满足要求的可用页范围。

.allocate_max_address 分配请求会分配任意可用页范围,且该范围的最高地址小于或等于输入所指向的地址。

.allocate_address 分配请求会在输入所指向的地址分配内存页。

pub fn allocatePages( self: *BootServices, location: AllocateLocation, mem_type: MemoryType, pages: usize, ) AllocatePagesError![]align(4096) Page

参数

self: *BootServices
location: AllocateLocation
mem_type: MemoryType
pages: usize

错误

InvalidParameter
NotFound
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.AllocatePagesError

错误集合

第 178 行

错误

InvalidParameter
NotFound
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.allocatePool

函数

第 450 行

从类型为 pool_type 的内存中分配 size 字节内存区域, 并返回所分配内存。按需从 .conventional_memory 分配页面, 以扩展请求的池类型。

pub fn allocatePool( self: *BootServices, pool_type: MemoryType, size: usize, ) AllocatePoolError![]align(8) u8

参数

self: *BootServices
pool_type: MemoryType
size: usize

错误

InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.AllocatePoolError

错误集合

第 194 行

错误

InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.calculateCrc32

函数

第 1195 行

pub fn calculateCrc32( self: *const BootServices, data: []const u8, ) CalculateCrc32Error!u32

参数

self: *const BootServices
data: []const u8

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.CalculateCrc32Error

错误集合

第 344 行

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.checkEvent

函数

第 571 行

检查事件是否处于已触发状态。

底层函数等同于以下伪代码:

if (event.type.signal)
    return error.InvalidParameter;

if (event.signaled) {
    event.signaled = false;
    return true;
}

const notify = event.notification_function orelse return false;
notify();

if (event.signaled) {
    event.signaled = false;
    return true;
}

return false;
pub fn checkEvent(self: *BootServices, event: Event) CheckEventError!bool

参数

self: *BootServices
event: Event

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.CheckEventError

错误集合

第 217 行

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.closeEvent

函数

第 542 行

pub fn closeEvent(self: *BootServices, event: Event) uefi.UnexpectedError!void

参数

self: *BootServices
event: Event

错误

Unexpected

std.os.uefi.tables.boot_services.BootServices.closeProtocol

函数

第 1031 行

pub fn closeProtocol( self: *BootServices, handle: Handle, Protocol: type, agent: Handle, controller: ?Handle, ) CloseProtocolError!void

参数

self: *BootServices
handle: Handle
Protocol: type
agent: Handle
controller: ?Handle

错误

InvalidParameter
NotFound
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.CloseProtocolError

错误集合

第 311 行

错误

InvalidParameter
NotFound
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.connectController

函数

第 955 行

driver_image 应为以空值结尾的有序句柄列表。

pub fn connectController( self: *BootServices, controller: Handle, driver_image: ?[*:null]?Handle, remaining_device_path: ?*const DevicePathProtocol, recursive: bool, ) ConnectControllerError!void

参数

self: *BootServices
controller: Handle
driver_image: ?[*:null]?Handle
remaining_device_path: ?*const DevicePathProtocol
recursive: bool

错误

InvalidParameter
NotFound
SecurityViolation
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.ConnectControllerError

错误集合

第 292 行

错误

InvalidParameter
NotFound
SecurityViolation
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.createEvent

函数

第 473 行

pub fn createEvent( self: *BootServices, event_type: uefi.EventType, notify_opts: NotifyOpts, ) CreateEventError!Event

参数

self: *BootServices
event_type: uefi.EventType
notify_opts: NotifyOpts

错误

InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.CreateEventError

错误集合

第 203 行

错误

InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.disconnectController

函数

第 976 行

pub fn disconnectController( self: *BootServices, controller: Handle, driver_image: ?Handle, child: ?Handle, ) DisconnectControllerError!void

参数

self: *BootServices
controller: Handle
driver_image: ?Handle
child: ?Handle

错误

DeviceError
InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.DisconnectControllerError

错误集合

第 298 行

错误

DeviceError
InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.exit

函数

第 859 行

message 必须使用 allocatePool 分配。

pub fn exit( self: *BootServices, handle: Handle, status: Status, message: ?[:0]const u16, ) ExitError!void

参数

self: *BootServices
handle: Handle
status: Status
message: ?[:0]const u16

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.exitBootServices

函数

第 903 行

pub fn exitBootServices( self: *BootServices, image: Handle, map_key: MemoryMapKey, ) ExitBootServicesError!void

参数

self: *BootServices
image: Handle
map_key: MemoryMapKey

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.ExitBootServicesError

错误集合

第 277 行

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.ExitError

错误集合

第 273 行

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.exitWithData

函数

第 879 行

message 应为以空字符结尾的 u16 字符串,之后跟随 使用 allocatePool 分配的二进制数据。

pub fn exitWithData( self: *BootServices, handle: Handle, status: Status, data: []align(2) const u8, ) ExitError!void

参数

self: *BootServices
handle: Handle
status: Status
data: []align(2) const u8

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.freePages

函数

第 395 行

pub fn freePages(self: *BootServices, pages: []align(4096) Page) FreePagesError!void

参数

self: *BootServices
pages: []align(4096) Page

错误

InvalidParameter
NotFound
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.FreePagesError

错误集合

第 184 行

错误

InvalidParameter
NotFound
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.freePool

函数

第 465 行

pub fn freePool(self: *BootServices, ptr: [*]align(8) u8) FreePoolError!void

参数

self: *BootServices
ptr: [*]align(8) u8

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.FreePoolError

错误集合

第 199 行

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.getMemoryMap

函数

第 423 行

pub fn getMemoryMap( self: *const BootServices, buffer: []align(@alignOf(MemoryDescriptor)) u8, ) GetMemoryMapError!MemoryMapSlice

参数

self: *const BootServices
buffer: []align(@alignOf(MemoryDescriptor)) u8

错误

BufferTooSmall
InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.GetMemoryMapError

错误集合

第 189 行

错误

BufferTooSmall
InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.getMemoryMapInfo

函数

第 404 行

pub fn getMemoryMapInfo(self: *const BootServices) uefi.UnexpectedError!MemoryMapInfo

参数

self: *const BootServices

错误

Unexpected

std.os.uefi.tables.boot_services.BootServices.getNextMonotonicCount

函数

第 915 行

pub fn getNextMonotonicCount( self: *const BootServices, count: *u64, ) GetNextMonotonicCountError!void

参数

self: *const BootServices
count: *u64

错误

DeviceError
InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.GetNextMonotonicCountError

错误集合

第 281 行

错误

DeviceError
InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.handleProtocol

函数

第 647 行

若句柄支持 Protocol 接口, 则返回指向该接口的指针。

注意,UEFI 实现已不再要求提供此函数, 因此转而使用 openProtocol 实现。

pub fn handleProtocol( self: *BootServices, Protocol: type, handle: Handle, ) HandleProtocolError!?*Protocol

参数

self: *BootServices
Protocol: type
handle: Handle

错误

Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.boot_services.BootServices.HandleProtocolError

错误集合

第 227 行

错误

Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.boot_services.BootServices.ImageExitData

容器

第 1223 行

字段

code: Status
description: ?[:0]const u16
data: ?[]const u16

std.os.uefi.tables.boot_services.BootServices.installConfigurationTable

函数

第 762 行

pub fn installConfigurationTable( self: *BootServices, guid: *const Guid, table: *anyopaque, ) InstallConfigurationTableError!void

参数

self: *BootServices
guid: *const Guid
table: *anyopaque

错误

InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.InstallConfigurationTableError

错误集合

第 248 行

错误

InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.installProtocolInterface

函数

第 584 行

参见 installProtocolInterfaces。

不调用 self._installProtocolInterface,因为 self._installMultipleProtocolInterfaces 执行更多错误检查。

pub fn installProtocolInterface( self: *BootServices, handle: ?Handle, interface: anytype, ) InstallProtocolInterfacesError!Handle

参数

self: *BootServices
handle: ?Handle

错误

AlreadyStarted
InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.installProtocolInterfaces

函数

第 1156 行

向启动服务环境安装一组协议接口。

此函数的最后一个参数应为指向协议 接口的指针元组,例如:

const handle = try boot_services.installProtocolInterfaces(null, .{
    &my_interface_1,
    &my_interface_2,
});

底层函数接受变长参数列表,其中每对参数分别是 Guid 指针 和指向接口的不透明指针。为提供 guid,接口 类型应按以下方式声明 guid 常量:

pub const guid: uefi.Guid = .{ ... };

协议类型定义示例见 std.os.uefi.protocol。

pub fn installProtocolInterfaces( self: *BootServices, handle: ?Handle, interfaces: anytype, ) InstallProtocolInterfacesError!Handle

参数

self: *BootServices
handle: ?Handle

错误

AlreadyStarted
InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.InstallProtocolInterfacesError

错误集合

第 334 行

错误

AlreadyStarted
InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.loadImage

函数

第 799 行

pub fn loadImage( self: *BootServices, boot_policy: bool, parent_image: Handle, source: LoadImageSource, ) LoadImageError!Handle

参数

self: *BootServices
boot_policy: bool
parent_image: Handle
source: LoadImageSource

错误

AccessDenied
DeviceError
InvalidParameter
LoadError
NotFound
OutOfResources
SecurityViolation
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.boot_services.BootServices.LoadImageError

错误集合

第 257 行

错误

AccessDenied
DeviceError
InvalidParameter
LoadError
NotFound
OutOfResources
SecurityViolation
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.boot_services.BootServices.LoadImageSource

容器

第 794 行

字段

buffer: []const u8
device_path: *const DevicePathProtocol

std.os.uefi.tables.boot_services.BootServices.locateDevicePath

函数

第 740 行

定位 device_path 上所有支持 Protocol 的设备。一旦找到与 device_path 最接近的匹配,就返回尚未匹配的设备路径和句柄。

pub fn locateDevicePath( self: *const BootServices, device_path: *const DevicePathProtocol, Protocol: type, ) LocateHandleError!?struct { *const DevicePathProtocol, Handle }

参数

self: *const BootServices
device_path: *const DevicePathProtocol
Protocol: type

错误

BufferTooSmall
InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.LocateDevicePathError

错误集合

第 243 行

错误

InvalidParameter
NotFound
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.locateHandle

函数

第 717 行

要确定 buffer 所需大小,请先调用 locateHandleLen。

pub fn locateHandle( self: *BootServices, search: LocateSearch, buffer: []Handle, ) LocateHandleError![]Handle

参数

self: *BootServices
search: LocateSearch
buffer: []Handle

错误

BufferTooSmall
InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.locateHandleBuffer

函数

第 1094 行

pub fn locateHandleBuffer( self: *const BootServices, search: LocateSearch, ) LocateHandleBufferError!?[]Handle

参数

self: *const BootServices
search: LocateSearch

错误

InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.LocateHandleBufferError

错误集合

第 325 行

错误

InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.LocateHandleError

错误集合

第 238 行

错误

BufferTooSmall
InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.locateHandleLen

函数

第 692 行

返回符合给定搜索条件的句柄数量。

pub fn locateHandleLen(self: *const BootServices, search: LocateSearch) NumHandlesError!usize

参数

self: *const BootServices
search: LocateSearch

错误

Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.locateProtocol

函数

第 1116 行

pub fn locateProtocol( self: *const BootServices, Protocol: type, registration: ?EventRegistration, ) LocateProtocolError!?*Protocol

参数

self: *const BootServices
Protocol: type
registration: ?EventRegistration

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.LocateProtocolError

错误集合

第 330 行

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.NotifyOpts

容器

第 1209 行

字段

tpl: TaskPriorityLevel = .application
function: ?*const fn (Event, ?*anyopaque) callconv(cc) void = null
context: ?*anyopaque = null

std.os.uefi.tables.boot_services.BootServices.NumHandlesError

别名

第 236 行

别名目标 std.os.uefi.UnexpectedError

std.os.uefi.tables.boot_services.BootServices.openProtocol

函数

第 1000 行

为 UEFI 应用程序打开协议,以其结构体作为已加载映像。

若 flag 为 .test_protocol,则唯一有效返回值为 null,并返回 Status.unsupported。 否则,若 _openProtocol 返回 Status.unsupported,则返回 null。

pub fn openProtocol( self: *BootServices, Protocol: type, handle: Handle, attributes: OpenProtocolArgs, ) OpenProtocolError!?*Protocol

参数

self: *BootServices
Protocol: type
handle: Handle
attributes: OpenProtocolArgs

错误

AccessDenied
AlreadyStarted
InvalidParameter
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.boot_services.BootServices.OpenProtocolError

错误集合

第 304 行

错误

AccessDenied
AlreadyStarted
InvalidParameter
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.boot_services.BootServices.openProtocolInformation

函数

第 1054 行

pub fn openProtocolInformation( self: *const BootServices, handle: Handle, Protocol: type, ) OpenProtocolInformationError!?[]ProtocolInformationEntry

参数

self: *const BootServices
handle: Handle
Protocol: type

错误

OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.OpenProtocolInformationError

错误集合

第 316 行

错误

OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.protocolsPerHandle

函数

第 1075 行

pub fn protocolsPerHandle( self: *const BootServices, handle: Handle, ) ProtocolsPerHandleError![]*const Guid

参数

self: *const BootServices
handle: Handle

错误

InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.ProtocolsPerHandleError

错误集合

第 320 行

错误

InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.registerProtocolNotify

函数

第 670 行

pub fn registerProtocolNotify( self: *BootServices, Protocol: type, event: Event, ) RegisterProtocolNotifyError!EventRegistration

参数

self: *BootServices
Protocol: type
event: Event

错误

InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.RegisterProtocolNotifyError

错误集合

第 231 行

错误

InvalidParameter
OutOfResources
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.reinstallProtocolInterface

函数

第 604 行

在设备句柄上重新安装协议接口。

new 可以与 old 相同;此时会对该句柄触发已注册的协议通知, 但不替换句柄上的接口。

所有已注册等待该接口安装的进程 都会收到通知。

若正移除 old,调用方负责确保 不存在对它的引用。

pub fn reinstallProtocolInterface( self: *BootServices, handle: Handle, Protocol: type, old: ?*const Protocol, new: ?*const Protocol, ) ReinstallProtocolInterfaceError!void

参数

self: *BootServices
handle: Handle
Protocol: type
old: ?*const Protocol
new: ?*const Protocol

错误

AccessDenied
InvalidParameter
NotFound
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.ReinstallProtocolInterfaceError

错误集合

第 221 行

错误

AccessDenied
InvalidParameter
NotFound
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.setTimer

函数

第 498 行

取消此事件此前的时间触发设置,并设置新的 事件触发计时器。

若事件不是计时器事件,则返回 error.InvalidParameter。

pub fn setTimer( self: *BootServices, event: Event, @"type": TimerDelay, trigger_time: u64, ) SetTimerError!void

参数

self: *BootServices
event: Event
@"type": TimerDelay
trigger_time: u64

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.SetTimerError

错误集合

第 208 行

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.setWatchdogTimer

函数

第 934 行

pub fn setWatchdogTimer( self: *BootServices, timeout: usize, watchdog_code: u64, data: ?[]const u16, ) SetWatchdogTimerError!void

参数

self: *BootServices
timeout: usize
watchdog_code: u64
data: ?[]const u16

错误

DeviceError
InvalidParameter
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.boot_services.BootServices.SetWatchdogTimerError

错误集合

第 286 行

错误

DeviceError
InvalidParameter
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.boot_services.BootServices.signalEvent

函数

第 535 行

若 event 为 EventType.signal,则调度其通知函数,以该事件的通知任务优先级调用。 可从任意任务优先级调用此函数。

若给定事件属于事件组,则该组所有事件也都会置为已触发状态,并调度其通知函数。

触发事件组时,可以先在组中创建事件,再触发它,最后关闭该事件,将其从组中移除。

pub fn signalEvent(self: *BootServices, event: Event) uefi.UnexpectedError!void

参数

self: *BootServices
event: Event

错误

Unexpected

std.os.uefi.tables.boot_services.BootServices.signature

常量

第 1207 行

u64

std.os.uefi.tables.boot_services.BootServices.stall

函数

第 927 行

pub fn stall(self: *const BootServices, microseconds: usize) uefi.UnexpectedError!void

参数

self: *const BootServices
microseconds: usize

错误

Unexpected

std.os.uefi.tables.boot_services.BootServices.startImage

函数

第 828 行

pub fn startImage(self: *BootServices, image: Handle) StartImageError!ImageExitData

参数

self: *BootServices
image: Handle

错误

InvalidParameter
SecurityViolation
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.StartImageError

错误集合

第 268 行

错误

InvalidParameter
SecurityViolation
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.TaskPriorityLevel

容器

第 1215 行

字段

application = 4
callback = 8
notify = 16
high_level = 31
_

std.os.uefi.tables.boot_services.BootServices.uninstallConfigurationTable

函数

第 778 行

pub fn uninstallConfigurationTable( self: *BootServices, guid: *const Guid, ) UninstallConfigurationTableError!void

参数

self: *BootServices
guid: *const Guid

错误

InvalidParameter InstallConfigurationTableError
NotFound
OutOfResources InstallConfigurationTableError
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.UninstallConfigurationTableError

错误集合

第 253 行

错误

InvalidParameter InstallConfigurationTableError
NotFound
OutOfResources InstallConfigurationTableError
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.uninstallProtocolInterface

函数

第 632 行

参见 uninstallProtocolInterfaces。

不调用 self._uninstallProtocolInterface,因为 self._uninstallMultipleProtocolInterfaces 会执行更多错误检查。

pub fn uninstallProtocolInterface( self: *BootServices, handle: Handle, interface: anytype, ) UninstallProtocolInterfacesError!void

参数

self: *BootServices
handle: Handle

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.uninstallProtocolInterfaces

函数

第 1177 行

pub fn uninstallProtocolInterfaces( self: *BootServices, handle: Handle, interfaces: anytype, ) UninstallProtocolInterfacesError!void

参数

self: *BootServices
handle: Handle

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.UninstallProtocolInterfacesError

错误集合

第 340 行

错误

InvalidParameter
Unexpected UnexpectedError

std.os.uefi.tables.boot_services.BootServices.unloadImage

函数

第 894 行

结果为卸载处理程序的退出码。所有错误码均可通过 try/catch 处理,因此结果仅保留成功码和警告码。

pub fn unloadImage( self: *BootServices, image: Handle, ) Status.Error!Status

参数

self: *BootServices
image: Handle

错误

Aborted
AccessDenied
AlreadyStarted
BadBufferSize
BufferTooSmall
CompromisedData
ConnectionFin
ConnectionRefused
ConnectionReset
CrcError
DeviceError
EndOfFile
EndOfMedia
HostUnreachable
HttpError
IcmpError
IncompatibleVersion
InvalidLanguage
InvalidParameter
IpAddressConflict
LoadError
MediaChanged
NetworkUnreachable
NoMapping
NoMedia
NoResponse
NotFound
NotReady
NotStarted
OutOfResources
PortUnreachable
ProtocolError
ProtocolUnreachable
SecurityViolation
TftpError
Timeout
Unsupported
VolumeCorrupted
VolumeFull
WriteProtected

std.os.uefi.tables.boot_services.BootServices.waitForEvent

函数

第 512 行

返回已被置为有信号状态的事件,以及它在切片中的索引。

pub fn waitForEvent( self: *BootServices, events: []const Event, ) WaitForEventError!struct { *const Event, usize }

参数

self: *BootServices
events: []const Event

错误

InvalidParameter
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.boot_services.BootServices.WaitForEventError

错误集合

第 212 行

错误

InvalidParameter
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.boot_services.cc

别名

第 27 行

别名目标 std.os.uefi.cc

std.os.uefi.tables.boot_services.DevicePathProtocol

别名

第 11 行

别名目标 std.os.uefi.protocol.DevicePath

std.os.uefi.tables.boot_services.Error

别名

第 28 行

别名目标 std.os.uefi.status.Status.Error

std.os.uefi.tables.boot_services.Event

别名

第 3 行

别名目标 std.os.uefi.Event

std.os.uefi.tables.boot_services.EventNotify

别名

第 26 行

别名目标 std.os.uefi.tables.EventNotify

std.os.uefi.tables.boot_services.EventRegistration

别名

第 4 行

别名目标 std.os.uefi.EventRegistration

std.os.uefi.tables.boot_services.Guid

别名

第 5 行

别名目标 std.os.uefi.Guid

std.os.uefi.tables.boot_services.Handle

别名

第 6 行

别名目标 std.os.uefi.Handle

std.os.uefi.tables.boot_services.InterfaceType

别名

第 20 行

别名目标 std.os.uefi.tables.InterfaceType

std.os.uefi.tables.boot_services.LocateSearch

别名

第 21 行

别名目标 std.os.uefi.tables.LocateSearch

std.os.uefi.tables.boot_services.LocateSearchType

别名

第 22 行

别名目标 std.os.uefi.tables.LocateSearchType

std.os.uefi.tables.boot_services.MemoryDescriptor

别名

第 15 行

别名目标 std.os.uefi.tables.MemoryDescriptor

std.os.uefi.tables.boot_services.MemoryMapInfo

别名

第 17 行

别名目标 std.os.uefi.tables.MemoryMapInfo

std.os.uefi.tables.boot_services.MemoryMapKey

别名

第 16 行

别名目标 std.os.uefi.tables.MemoryMapKey

std.os.uefi.tables.boot_services.MemoryMapSlice

别名

第 18 行

别名目标 std.os.uefi.tables.MemoryMapSlice

std.os.uefi.tables.boot_services.MemoryType

别名

第 14 行

别名目标 std.os.uefi.tables.MemoryType

std.os.uefi.tables.boot_services.OpenProtocolArgs

别名

第 23 行

别名目标 std.os.uefi.tables.OpenProtocolArgs

std.os.uefi.tables.boot_services.OpenProtocolAttributes

别名

第 24 行

别名目标 std.os.uefi.tables.OpenProtocolAttributes

std.os.uefi.tables.boot_services.Page

别名

第 7 行

别名目标 std.os.uefi.Page

std.os.uefi.tables.boot_services.Pages

常量

第 8 行

std.os.uefi.tables.boot_services.ProtocolInformationEntry

别名

第 25 行

别名目标 std.os.uefi.tables.ProtocolInformationEntry

std.os.uefi.tables.boot_services.protocolInterfaces

函数

第 1230 行

fn protocolInterfaces( handle_arg: anytype, interfaces: anytype, ) ProtocolInterfaces(@TypeOf(handle_arg), @TypeOf(interfaces))

std.os.uefi.tables.boot_services.ProtocolInterfaces

类型函数

第 1268 行

fn ProtocolInterfaces(HandleType: type, Interfaces: type) type

参数

HandleType: type
Interfaces: type

std.os.uefi.tables.boot_services.Status

别名

第 9 行

别名目标 std.os.uefi.Status

std.os.uefi.tables.boot_services.std

别名

第 1 行

别名目标 std

std.os.uefi.tables.boot_services.TableHeader

别名

第 10 行

别名目标 std.os.uefi.tables.TableHeader

std.os.uefi.tables.boot_services.TimerDelay

别名

第 19 行

别名目标 std.os.uefi.tables.TimerDelay

std.os.uefi.tables.boot_services.uefi

别名

第 2 行

别名目标 std.os.uefi

源码

std/os/uefi/tables/boot_services.zig

const std = @import("std");
const uefi = std.os.uefi;
const Event = uefi.Event;
const EventRegistration = uefi.EventRegistration;
const Guid = uefi.Guid;
const Handle = uefi.Handle;
const Page = uefi.Page;
const Pages = uefi.Pages;
const Status = uefi.Status;
const TableHeader = uefi.tables.TableHeader;
const DevicePathProtocol = uefi.protocol.DevicePath;
const AllocateLocation = uefi.tables.AllocateLocation;
const AllocateType = uefi.tables.AllocateType;
const MemoryType = uefi.tables.MemoryType;
const MemoryDescriptor = uefi.tables.MemoryDescriptor;
const MemoryMapKey = uefi.tables.MemoryMapKey;
const MemoryMapInfo = uefi.tables.MemoryMapInfo;
const MemoryMapSlice = uefi.tables.MemoryMapSlice;
const TimerDelay = uefi.tables.TimerDelay;
const InterfaceType = uefi.tables.InterfaceType;
const LocateSearch = uefi.tables.LocateSearch;
const LocateSearchType = uefi.tables.LocateSearchType;
const OpenProtocolArgs = uefi.tables.OpenProtocolArgs;
const OpenProtocolAttributes = uefi.tables.OpenProtocolAttributes;
const ProtocolInformationEntry = uefi.tables.ProtocolInformationEntry;
const EventNotify = uefi.tables.EventNotify;
const cc = uefi.cc;
const Error = Status.Error;

/// 引导服务是系统固件提供的服务,直到操作系统通过调用 exitBootServices 接管硬件控制权为止。
///
/// 调用 exitBootServices 后,不得继续使用引导服务。唯一例外为 getMemoryMap:第一次调用 exitBootServices 失败后,仍可使用它。成功调用 exitBootServices 后,应将 system_table.console_in_handle、system_table.con_in、system_table.console_out_handle、system_table.con_out、system_table.standard_error_handle、system_table.std_err 和 system_table.boot_services 设为 null。设置这些属性后,必须重新计算 system_table.hdr.crc32。
///
/// boot_services 表可能随新 UEFI 版本扩展,因此必须检查 hdr.header_size。
///
///
///
///
///
///
pub const BootServices = extern struct {
    hdr: TableHeader,

    /// 提高任务的优先级,并返回其先前的优先级。
    raiseTpl: *const fn (new_tpl: TaskPriorityLevel) callconv(cc) TaskPriorityLevel,

    /// 将任务的优先级恢复为先前值。
    restoreTpl: *const fn (old_tpl: TaskPriorityLevel) callconv(cc) void,

    /// 从系统分配内存页。
    _allocatePages: *const fn (alloc_type: AllocateType, mem_type: MemoryType, pages: usize, memory: *[*]align(4096) Page) callconv(cc) Status,

    /// 释放内存页。
    _freePages: *const fn (memory: [*]align(4096) Page, pages: usize) callconv(cc) Status,

    /// 返回当前内存映射。
    _getMemoryMap: *const fn (mmap_size: *usize, mmap: ?[*]align(@alignOf(MemoryDescriptor)) u8, map_key: *MemoryMapKey, descriptor_size: *usize, descriptor_version: *u32) callconv(cc) Status,

    /// 分配池内存。
    _allocatePool: *const fn (pool_type: MemoryType, size: usize, buffer: *[*]align(8) u8) callconv(cc) Status,

    /// 将池内存归还系统。
    _freePool: *const fn (buffer: [*]align(8) u8) callconv(cc) Status,

    /// 创建事件。
    _createEvent: *const fn (type: u32, notify_tpl: TaskPriorityLevel, notify_func: ?*const fn (Event, ?*anyopaque) callconv(cc) void, notify_ctx: ?*anyopaque, event: *Event) callconv(cc) Status,

    /// 设置定时器事件的定时器类型及触发时间。
    _setTimer: *const fn (event: Event, type: TimerDelay, trigger_time: u64) callconv(cc) Status,

    /// 暂停执行,直到事件收到信号。
    _waitForEvent: *const fn (event_len: usize, events: [*]const Event, index: *usize) callconv(cc) Status,

    /// 发出事件信号。
    _signalEvent: *const fn (event: Event) callconv(cc) Status,

    /// 关闭事件。
    _closeEvent: *const fn (event: Event) callconv(cc) Status,

    /// 检查事件是否处于已通知状态。
    _checkEvent: *const fn (event: Event) callconv(cc) Status,

    /// 在设备句柄上安装协议接口。如果句柄不存在,则创建该句柄
    /// 并加入系统句柄列表。installMultipleProtocolInterfaces()
    /// 比 installProtocolInterface() 执行更多错误检查,因此建议优先使用前者。
    _installProtocolInterface: *const fn (handle: Handle, protocol: *const Guid, interface_type: InterfaceType, interface: *anyopaque) callconv(cc) Status,

    /// 在设备句柄上重新安装协议接口
    _reinstallProtocolInterface: *const fn (handle: Handle, protocol: *const Guid, old_interface: *anyopaque, new_interface: *anyopaque) callconv(cc) Status,

    /// 从设备句柄中移除协议接口。
    /// 建议改用 uninstallMultipleProtocolInterfaces。
    _uninstallProtocolInterface: *const fn (handle: Handle, protocol: *const Guid, interface: *anyopaque) callconv(cc) Status,

    /// 查询句柄,确定它是否支持指定协议。
    _handleProtocol: *const fn (handle: Handle, protocol: *const Guid, interface: *?*anyopaque) callconv(cc) Status,

    _reserved: *anyopaque,

    /// 创建一个事件,每当为指定协议安装接口时就触发该事件。
    _registerProtocolNotify: *const fn (protocol: *const Guid, event: Event, registration: *EventRegistration) callconv(cc) Status,

    /// 返回支持指定协议的句柄数组。
    _locateHandle: *const fn (search_type: LocateSearchType, protocol: ?*const Guid, search_key: ?*const anyopaque, buffer_size: *usize, buffer: ?[*]Handle) callconv(cc) Status,

    /// 查找设备路径上支持指定协议的设备句柄
    _locateDevicePath: *const fn (protocols: *const Guid, device_path: **const DevicePathProtocol, device: *?Handle) callconv(cc) Status,

    /// 在 EFI 系统表中添加、更新或移除配置表条目。
    _installConfigurationTable: *const fn (guid: *const Guid, table: ?*anyopaque) callconv(cc) Status,

    /// 将 EFI 映像加载到内存。
    _loadImage: *const fn (boot_policy: bool, parent_image_handle: Handle, device_path: ?*const DevicePathProtocol, source_buffer: ?[*]const u8, source_size: usize, image_handle: *Handle) callconv(cc) Status,

    /// 将控制权转移到已加载映像的入口点。
    _startImage: *const fn (image_handle: Handle, exit_data_size: ?*usize, exit_data: ?*[*]u16) callconv(cc) Status,

    /// 终止已加载的 EFI 映像,并将控制权返回启动服务。
    _exit: *const fn (image_handle: Handle, exit_status: Status, exit_data_size: usize, exit_data: ?[*]align(2) const u8) callconv(cc) Status,

    /// 卸载映像。
    _unloadImage: *const fn (image_handle: Handle) callconv(cc) Status,

    /// 终止所有启动服务。
    _exitBootServices: *const fn (image_handle: Handle, map_key: MemoryMapKey) callconv(cc) Status,

    /// 返回平台的单调递增计数。
    _getNextMonotonicCount: *const fn (count: *u64) callconv(cc) Status,

    /// 引入精细粒度的暂停。
    _stall: *const fn (microseconds: usize) callconv(cc) Status,

    /// 设置系统看门狗定时器。
    _setWatchdogTimer: *const fn (timeout: usize, watchdog_code: u64, data_size: usize, watchdog_data: ?[*]const u16) callconv(cc) Status,

    /// 将一个或多个驱动器连接到控制器。
    _connectController: *const fn (controller_handle: Handle, driver_image_handle: ?[*:null]?Handle, remaining_device_path: ?*const DevicePathProtocol, recursive: bool) callconv(cc) Status,

    // 从控制器断开一个或多个驱动程序
    _disconnectController: *const fn (controller_handle: Handle, driver_image_handle: ?Handle, child_handle: ?Handle) callconv(cc) Status,

    /// 查询句柄,确定它是否支持指定协议。
    _openProtocol: *const fn (handle: Handle, protocol: *const Guid, interface: ?*?*anyopaque, agent_handle: ?Handle, controller_handle: ?Handle, attributes: OpenProtocolAttributes) callconv(cc) Status,

    /// 关闭通过 openProtocol() 打开的句柄上的协议。
    _closeProtocol: *const fn (handle: Handle, protocol: *const Guid, agent_handle: Handle, controller_handle: ?Handle) callconv(cc) Status,

    /// 获取当前已打开某协议接口的代理列表。
    _openProtocolInformation: *const fn (handle: Handle, protocol: *const Guid, entry_buffer: *[*]ProtocolInformationEntry, entry_count: *usize) callconv(cc) Status,

    /// 获取已安装于句柄上的协议接口 GUID 列表,存入从池分配的缓冲区。
    _protocolsPerHandle: *const fn (handle: Handle, protocol_buffer: *[*]*const Guid, protocol_buffer_count: *usize) callconv(cc) Status,

    /// 在池中分配的缓冲区中返回支持请求协议的句柄数组。
    _locateHandleBuffer: *const fn (search_type: LocateSearchType, protocol: ?*const Guid, search_key: ?*const anyopaque, num_handles: *usize, buffer: *[*]Handle) callconv(cc) Status,

    /// 返回与给定协议匹配的第一个协议实例。
    _locateProtocol: *const fn (protocol: *const Guid, registration: ?EventRegistration, interface: *?*const anyopaque) callconv(cc) Status,

    /// 将一个或多个协议接口安装到启动服务环境中。
    _installMultipleProtocolInterfaces: *const fn (handle: *?Handle, ...) callconv(cc) Status,

    /// 从启动服务环境中移除一个或多个协议接口。
    _uninstallMultipleProtocolInterfaces: *const fn (handle: Handle, ...) callconv(cc) Status,

    /// 计算并返回数据缓冲区的 32 位 CRC。
    _calculateCrc32: *const fn (data: [*]const u8, data_size: usize, *u32) callconv(cc) Status,

    /// 将一个缓冲区的内容复制到另一个缓冲区
    _copyMem: *const fn (dest: [*]u8, src: [*]const u8, len: usize) callconv(cc) void,

    /// 使用指定值填充缓冲区
    _setMem: *const fn (buffer: [*]u8, size: usize, value: u8) callconv(cc) void,

    /// 在组中创建事件。
    _createEventEx: *const fn (type: u32, notify_tpl: usize, notify_func: EventNotify, notify_ctx: *const anyopaque, event_group: *const Guid, event: *Event) callconv(cc) Status,

    pub const AllocatePagesError = uefi.UnexpectedError || error{
        OutOfResources,
        InvalidParameter,
        NotFound,
    };

    pub const FreePagesError = uefi.UnexpectedError || error{
        NotFound,
        InvalidParameter,
    };

    pub const GetMemoryMapError = uefi.UnexpectedError || error{
        InvalidParameter,
        BufferTooSmall,
    };

    pub const AllocatePoolError = uefi.UnexpectedError || error{
        OutOfResources,
        InvalidParameter,
    };

    pub const FreePoolError = uefi.UnexpectedError || error{
        InvalidParameter,
    };

    pub const CreateEventError = uefi.UnexpectedError || error{
        InvalidParameter,
        OutOfResources,
    };

    pub const SetTimerError = uefi.UnexpectedError || error{
        InvalidParameter,
    };

    pub const WaitForEventError = uefi.UnexpectedError || error{
        InvalidParameter,
        Unsupported,
    };

    pub const CheckEventError = uefi.UnexpectedError || error{
        InvalidParameter,
    };

    pub const ReinstallProtocolInterfaceError = uefi.UnexpectedError || error{
        NotFound,
        AccessDenied,
        InvalidParameter,
    };

    pub const HandleProtocolError = uefi.UnexpectedError || error{
        Unsupported,
    };

    pub const RegisterProtocolNotifyError = uefi.UnexpectedError || error{
        OutOfResources,
        InvalidParameter,
    };

    pub const NumHandlesError = uefi.UnexpectedError;

    pub const LocateHandleError = uefi.UnexpectedError || error{
        BufferTooSmall,
        InvalidParameter,
    };

    pub const LocateDevicePathError = uefi.UnexpectedError || error{
        NotFound,
        InvalidParameter,
    };

    pub const InstallConfigurationTableError = uefi.UnexpectedError || error{
        InvalidParameter,
        OutOfResources,
    };

    pub const UninstallConfigurationTableError = InstallConfigurationTableError || error{
        NotFound,
    };

    pub const LoadImageError = uefi.UnexpectedError || error{
        NotFound,
        InvalidParameter,
        Unsupported,
        OutOfResources,
        LoadError,
        DeviceError,
        AccessDenied,
        SecurityViolation,
    };

    pub const StartImageError = uefi.UnexpectedError || error{
        InvalidParameter,
        SecurityViolation,
    };

    pub const ExitError = uefi.UnexpectedError || error{
        InvalidParameter,
    };

    pub const ExitBootServicesError = uefi.UnexpectedError || error{
        InvalidParameter,
    };

    pub const GetNextMonotonicCountError = uefi.UnexpectedError || error{
        DeviceError,
        InvalidParameter,
    };

    pub const SetWatchdogTimerError = uefi.UnexpectedError || error{
        InvalidParameter,
        Unsupported,
        DeviceError,
    };

    pub const ConnectControllerError = uefi.UnexpectedError || error{
        InvalidParameter,
        NotFound,
        SecurityViolation,
    };

    pub const DisconnectControllerError = uefi.UnexpectedError || error{
        InvalidParameter,
        OutOfResources,
        DeviceError,
    };

    pub const OpenProtocolError = uefi.UnexpectedError || error{
        InvalidParameter,
        Unsupported,
        AccessDenied,
        AlreadyStarted,
    };

    pub const CloseProtocolError = uefi.UnexpectedError || error{
        InvalidParameter,
        NotFound,
    };

    pub const OpenProtocolInformationError = uefi.UnexpectedError || error{
        OutOfResources,
    };

    pub const ProtocolsPerHandleError = uefi.UnexpectedError || error{
        InvalidParameter,
        OutOfResources,
    };

    pub const LocateHandleBufferError = uefi.UnexpectedError || error{
        InvalidParameter,
        OutOfResources,
    };

    pub const LocateProtocolError = uefi.UnexpectedError || error{
        InvalidParameter,
    };

    pub const InstallProtocolInterfacesError = uefi.UnexpectedError || error{
        AlreadyStarted,
        OutOfResources,
        InvalidParameter,
    };

    pub const UninstallProtocolInterfacesError = uefi.UnexpectedError || error{
        InvalidParameter,
    };

    pub const CalculateCrc32Error = uefi.UnexpectedError || error{
        InvalidParameter,
    };

    /// 分配内存页。
    ///
    /// 此函数扫描内存映射以查找空闲页。找到足够大的物理连续页块,且该页块满足 `alloc_type` 的分配要求后,会修改内存映射,将这些页标记为 `mem_type` 类型。
    ///
    /// 通常,UEFI 操作系统加载器与 UEFI 应用程序应分配 `.loader_data` 类型的内存和内存池。UEFI 引导服务驱动必须分配 `.boot_services_data` 类型的内存和内存池。UEFI 运行时驱动应分配 `.runtime_services_data` 类型的内存和内存池,不过只能在引导服务阶段执行此类分配。
    ///
    /// `.allocate_any_pages` 分配请求会分配任意满足要求的可用页范围。
    ///
    /// `.allocate_max_address` 分配请求会分配任意可用页范围,且该范围的最高地址小于或等于输入所指向的地址。
    ///
    /// `.allocate_address` 分配请求会在输入所指向的地址分配内存页。
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    pub fn allocatePages(
        self: *BootServices,
        location: AllocateLocation,
        mem_type: MemoryType,
        pages: usize,
    ) AllocatePagesError![]align(4096) Page {
        var ptr: [*]align(4096) Page = switch (location) {
            .any => undefined,
            .address, .max_address => |ptr| ptr,
        };

        switch (self._allocatePages(
            std.meta.activeTag(location),
            mem_type,
            pages,
            &ptr,
        )) {
            .success => return ptr[0..pages],
            .out_of_resources => return error.OutOfResources,
            .invalid_parameter => return error.InvalidParameter,
            .not_found => return error.NotFound,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn freePages(self: *BootServices, pages: []align(4096) Page) FreePagesError!void {
        switch (self._freePages(pages.ptr, pages.len)) {
            .success => {},
            .not_found => return error.NotFound,
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn getMemoryMapInfo(self: *const BootServices) uefi.UnexpectedError!MemoryMapInfo {
        var info: MemoryMapInfo = undefined;
        info.len = 0;

        switch (self._getMemoryMap(
            &info.len,
            null,
            &info.key,
            &info.descriptor_size,
            &info.descriptor_version,
        )) {
            .success, .buffer_too_small => {
                info.len = @divExact(info.len, info.descriptor_size);
                return info;
            },
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn getMemoryMap(
        self: *const BootServices,
        buffer: []align(@alignOf(MemoryDescriptor)) u8,
    ) GetMemoryMapError!MemoryMapSlice {
        var info: MemoryMapInfo = undefined;
        info.len = buffer.len;

        switch (self._getMemoryMap(
            &info.len,
            buffer.ptr,
            &info.key,
            &info.descriptor_size,
            &info.descriptor_version,
        )) {
            .success => {
                info.len = @divExact(info.len, info.descriptor_size);
                return .{ .info = info, .ptr = buffer.ptr };
            },
            .buffer_too_small => return error.BufferTooSmall,
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 从类型为 `pool_type` 的内存中分配 `size` 字节内存区域,
    /// 并返回所分配内存。按需从 `.conventional_memory` 分配页面,
    /// 以扩展请求的池类型。
    pub fn allocatePool(
        self: *BootServices,
        pool_type: MemoryType,
        size: usize,
    ) AllocatePoolError![]align(8) u8 {
        var ptr: [*]align(8) u8 = undefined;

        switch (self._allocatePool(pool_type, size, &ptr)) {
            .success => return ptr[0..size],
            .out_of_resources => return error.OutOfResources,
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn freePool(self: *BootServices, ptr: [*]align(8) u8) FreePoolError!void {
        switch (self._freePool(ptr)) {
            .success => {},
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn createEvent(
        self: *BootServices,
        event_type: uefi.EventType,
        notify_opts: NotifyOpts,
    ) CreateEventError!Event {
        var evt: Event = undefined;

        switch (self._createEvent(
            @bitCast(event_type),
            notify_opts.tpl,
            notify_opts.function,
            notify_opts.context,
            &evt,
        )) {
            .success => return evt,
            .invalid_parameter => return error.InvalidParameter,
            .out_of_resources => return error.OutOfResources,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 取消此事件此前的时间触发设置,并设置新的
    /// 事件触发计时器。
    ///
    /// 若事件不是计时器事件,则返回 `error.InvalidParameter`。
    pub fn setTimer(
        self: *BootServices,
        event: Event,
        @"type": TimerDelay,
        trigger_time: u64,
    ) SetTimerError!void {
        switch (self._setTimer(event, @"type", trigger_time)) {
            .success => {},
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 返回已被置为有信号状态的事件,以及它在切片中的索引。
    pub fn waitForEvent(
        self: *BootServices,
        events: []const Event,
    ) WaitForEventError!struct { *const Event, usize } {
        var idx: usize = undefined;
        switch (self._waitForEvent(events.len, events.ptr, &idx)) {
            .success => return .{ &events[idx], idx },
            .invalid_parameter => return error.InvalidParameter,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 若 `event` 为 `EventType.signal`,则调度其通知函数,以该事件的通知任务优先级调用。
    /// 可从任意任务优先级调用此函数。
    ///
    /// 若给定事件属于事件组,则该组所有事件也都会置为已触发状态,并调度其通知函数。
    ///
    /// 触发事件组时,可以先在组中创建事件,再触发它,最后关闭该事件,将其从组中移除。
    ///
    ///
    ///
    ///
    pub fn signalEvent(self: *BootServices, event: Event) uefi.UnexpectedError!void {
        switch (self._signalEvent(event)) {
            .success => {},
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn closeEvent(self: *BootServices, event: Event) uefi.UnexpectedError!void {
        switch (self._closeEvent(event)) {
            .success => {},
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 检查事件是否处于已触发状态。
    ///
    /// 底层函数等同于以下伪代码:
    /// ```
    /// if (event.type.signal)
    ///     return error.InvalidParameter;
    ///
    /// if (event.signaled) {
    ///     event.signaled = false;
    ///     return true;
    /// }
    ///
    /// const notify = event.notification_function orelse return false;
    /// notify();
    ///
    /// if (event.signaled) {
    ///     event.signaled = false;
    ///     return true;
    /// }
    ///
    /// return false;
    /// ```
    pub fn checkEvent(self: *BootServices, event: Event) CheckEventError!bool {
        switch (self._checkEvent(event)) {
            .success => return true,
            .not_ready => return false,
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 参见 `installProtocolInterfaces`。
    ///
    /// 不调用 `self._installProtocolInterface`,因为
    /// `self._installMultipleProtocolInterfaces` 执行更多错误检查。
    pub fn installProtocolInterface(
        self: *BootServices,
        handle: ?Handle,
        interface: anytype,
    ) InstallProtocolInterfacesError!Handle {
        return self.installProtocolInterfaces(handle, .{
            interface,
        });
    }

    /// 在设备句柄上重新安装协议接口。
    ///
    /// `new` 可以与 `old` 相同;此时会对该句柄触发已注册的协议通知,
    /// 但不替换句柄上的接口。
    ///
    /// 所有已注册等待该接口安装的进程
    /// 都会收到通知。
    ///
    /// 若正移除 `old`,调用方负责确保
    /// 不存在对它的引用。
    pub fn reinstallProtocolInterface(
        self: *BootServices,
        handle: Handle,
        Protocol: type,
        old: ?*const Protocol,
        new: ?*const Protocol,
    ) ReinstallProtocolInterfaceError!void {
        if (!@hasDecl(Protocol, "guid"))
            @compileError("protocol is missing guid");

        switch (self._reinstallProtocolInterface(
            handle,
            &Protocol.guid,
            old,
            new,
        )) {
            .success => {},
            .not_found => return error.NotFound,
            .access_denied => return error.AccessDenied,
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 参见 `uninstallProtocolInterfaces`。
    ///
    /// 不调用 `self._uninstallProtocolInterface`,因为
    /// `self._uninstallMultipleProtocolInterfaces` 会执行更多错误检查。
    pub fn uninstallProtocolInterface(
        self: *BootServices,
        handle: Handle,
        interface: anytype,
    ) UninstallProtocolInterfacesError!void {
        return self.uninstallProtocolInterfaces(handle, .{
            interface,
        });
    }

    /// 若句柄支持 `Protocol` 接口,
    /// 则返回指向该接口的指针。
    ///
    /// 注意,UEFI 实现已不再要求提供此函数,
    /// 因此转而使用 `openProtocol` 实现。
    pub fn handleProtocol(
        self: *BootServices,
        Protocol: type,
        handle: Handle,
    ) HandleProtocolError!?*Protocol {
        // 根据 https://uefi.org/specs/UEFI/2.10/07_Services_Boot_Services.html#efi-boot-services-handleprotocol
        // handleProtocol 基本等同于满足以下条件的 `openProtocol`:
        // 1. agent_handle 为 `uefi.handle`,即传给 `EfiMain` 的句柄
        // 2. controller_handle 为 `null`
        // 3. attributes 为 `EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL`

        return self.openProtocol(
            Protocol,
            handle,
            .{ .by_handle_protocol = .{ .agent = uefi.handle } },
        ) catch |err| switch (err) {
            error.AlreadyStarted => return uefi.unexpectedStatus(.already_started),
            error.AccessDenied => return uefi.unexpectedStatus(.access_denied),
            error.InvalidParameter => return uefi.unexpectedStatus(.invalid_parameter),
            else => return @errorCast(err),
        };
    }

    pub fn registerProtocolNotify(
        self: *BootServices,
        Protocol: type,
        event: Event,
    ) RegisterProtocolNotifyError!EventRegistration {
        if (!@hasDecl(Protocol, "guid"))
            @compileError("Protocol is missing guid");

        var registration: EventRegistration = undefined;
        switch (self._registerProtocolNotify(
            &Protocol.guid,
            event,
            &registration,
        )) {
            .success => return registration,
            .out_of_resources => return error.OutOfResources,
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 返回符合给定搜索条件的句柄数量。
    pub fn locateHandleLen(self: *const BootServices, search: LocateSearch) NumHandlesError!usize {
        var len: usize = 0;
        switch (self._locateHandle(
            std.meta.activeTag(search),
            if (search == .by_protocol) search.by_protocol else null,
            if (search == .by_register_notify) search.by_register_notify else null,
            &len,
            null,
        )) {
            // 若 len 为零,应返回 not_found,否则返回 buffer_too_small。
            // 原因是只有传入有效且大小非零的缓冲区时,
            // 才可以且应该返回成功,而此处不符合条件。
            // 因此认为此状态不可达,并返回 error.Unexpected。
            // .success => unreachable,
            .buffer_too_small => return @divExact(len, @sizeOf(uefi.Handle)),
            .not_found => return 0,
            // 此函数已根据最新的 UEFI 2.10A 规范考虑此错误码的
            // 所有可能原因,因此此分支视为不可达,
            // 转而返回 error.Unexpected。
            // .invalid_parameter => unreachable
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 要确定 `buffer` 所需大小,请先调用 `locateHandleLen`。
    pub fn locateHandle(
        self: *BootServices,
        search: LocateSearch,
        buffer: []Handle,
    ) LocateHandleError![]Handle {
        var len: usize = @sizeOf(Handle) * buffer.len;
        switch (self._locateHandle(
            std.meta.activeTag(search),
            if (search == .by_protocol) search.by_protocol else null,
            if (search == .by_register_notify) search.by_register_notify else null,
            &len,
            buffer.ptr,
        )) {
            .success => return buffer[0..@divExact(len, @sizeOf(Handle))],
            .not_found => return buffer[0..0],
            .buffer_too_small => return error.BufferTooSmall,
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 定位 `device_path` 上所有支持 `Protocol` 的设备。一旦找到与
    /// `device_path` 最接近的匹配,就返回尚未匹配的设备路径和句柄。
    pub fn locateDevicePath(
        self: *const BootServices,
        device_path: *const DevicePathProtocol,
        Protocol: type,
    ) LocateHandleError!?struct { *const DevicePathProtocol, Handle } {
        if (!@hasDecl(Protocol, "guid"))
            @compileError("Protocol is missing guid");

        var dev_path = device_path;
        var device: ?Handle = undefined;
        switch (self._locateDevicePath(
            &Protocol.guid,
            &dev_path,
            &device,
        )) {
            .success => return .{ dev_path, device.? },
            .not_found => return null,
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn installConfigurationTable(
        self: *BootServices,
        guid: *const Guid,
        table: *anyopaque,
    ) InstallConfigurationTableError!void {
        switch (self._installConfigurationTable(
            guid,
            table,
        )) {
            .success => {},
            .invalid_parameter => return error.InvalidParameter,
            .out_of_resources => return error.OutOfResources,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn uninstallConfigurationTable(
        self: *BootServices,
        guid: *const Guid,
    ) UninstallConfigurationTableError!void {
        switch (self._installConfigurationTable(
            guid,
            null,
        )) {
            .success => {},
            .not_found => return error.NotFound,
            .invalid_parameter => return error.InvalidParameter,
            .out_of_resources => return error.OutOfResources,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub const LoadImageSource = union(enum) {
        buffer: []const u8,
        device_path: *const DevicePathProtocol,
    };

    pub fn loadImage(
        self: *BootServices,
        boot_policy: bool,
        parent_image: Handle,
        source: LoadImageSource,
    ) LoadImageError!Handle {
        var handle: Handle = undefined;

        switch (self._loadImage(
            boot_policy,
            parent_image,
            if (source == .device_path) source.device_path else null,
            if (source == .buffer) source.buffer.ptr else null,
            if (source == .buffer) source.buffer.len else 0,
            &handle,
        )) {
            .success => return handle,
            .not_found => return error.NotFound,
            .invalid_parameter => return error.InvalidParameter,
            .unsupported => return error.Unsupported,
            .out_of_resources => return error.OutOfResources,
            .load_error => return error.LoadError,
            .device_error => return error.DeviceError,
            .access_denied => return error.AccessDenied,
            .security_violation => return error.SecurityViolation,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn startImage(self: *BootServices, image: Handle) StartImageError!ImageExitData {
        var exit_data_size: usize = undefined;
        var exit_data: [*]u16 = undefined;

        const exit_code = switch (self._startImage(
            image,
            &exit_data_size,
            &exit_data,
        )) {
            .invalid_parameter => return error.InvalidParameter,
            .security_violation => return error.SecurityViolation,
            else => |exit_code| exit_code,
        };

        if (exit_data_size == 0) return .{
            .code = exit_code,
            .description = null,
            .data = null,
        };

        const description_ptr: [*:0]const u16 = @ptrCast(exit_data);
        const description = std.mem.sliceTo(description_ptr, 0);

        return ImageExitData{
            .code = exit_code,
            .description = description,
            .data = exit_data[description.len + 1 .. exit_data_size],
        };
    }

    /// `message` 必须使用 `allocatePool` 分配。
    pub fn exit(
        self: *BootServices,
        handle: Handle,
        status: Status,
        message: ?[:0]const u16,
    ) ExitError!void {
        switch (self._exit(
            handle,
            status,
            if (message) |msg| (2 * msg.len) + 1 else 0,
            if (message) |msg| @ptrCast(msg.ptr) else null,
        )) {
            .success => {},
            .invalid_parameter => return error.InvalidParameter,
            else => |exit_status| return uefi.unexpectedStatus(exit_status),
        }
    }

    /// `message` 应为以空字符结尾的 u16 字符串,之后跟随
    /// 使用 `allocatePool` 分配的二进制数据。
    pub fn exitWithData(
        self: *BootServices,
        handle: Handle,
        status: Status,
        data: []align(2) const u8,
    ) ExitError!void {
        switch (self._exit(handle, status, data.len, data.ptr)) {
            .success => {},
            .invalid_parameter => return error.InvalidParameter,
            else => |exit_status| return uefi.unexpectedStatus(exit_status),
        }
    }

    /// 结果为卸载处理程序的退出码。所有错误码均可通过
    /// `try/catch` 处理,因此结果仅保留成功码和警告码。
    pub fn unloadImage(
        self: *BootServices,
        image: Handle,
    ) Status.Error!Status {
        const status = self._unloadImage(image);
        try status.err();
        return status;
    }

    pub fn exitBootServices(
        self: *BootServices,
        image: Handle,
        map_key: MemoryMapKey,
    ) ExitBootServicesError!void {
        switch (self._exitBootServices(image, map_key)) {
            .success => {},
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn getNextMonotonicCount(
        self: *const BootServices,
        count: *u64,
    ) GetNextMonotonicCountError!void {
        switch (self._getNextMonotonicCount(count)) {
            .success => {},
            .device_error => return error.DeviceError,
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn stall(self: *const BootServices, microseconds: usize) uefi.UnexpectedError!void {
        switch (self._stall(microseconds)) {
            .success => {},
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn setWatchdogTimer(
        self: *BootServices,
        timeout: usize,
        watchdog_code: u64,
        data: ?[]const u16,
    ) SetWatchdogTimerError!void {
        switch (self._setWatchdogTimer(
            timeout,
            watchdog_code,
            if (data) |d| d.len else 0,
            if (data) |d| d.ptr else null,
        )) {
            .success => {},
            .invalid_parameter => return error.InvalidParameter,
            .unsupported => return error.Unsupported,
            .device_error => return error.DeviceError,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// `driver_image` 应为以空值结尾的有序句柄列表。
    pub fn connectController(
        self: *BootServices,
        controller: Handle,
        driver_image: ?[*:null]?Handle,
        remaining_device_path: ?*const DevicePathProtocol,
        recursive: bool,
    ) ConnectControllerError!void {
        switch (self._connectController(
            controller,
            driver_image,
            remaining_device_path,
            recursive,
        )) {
            .success => {},
            .invalid_parameter => return error.InvalidParameter,
            .not_found => return error.NotFound,
            .security_violation => return error.SecurityViolation,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn disconnectController(
        self: *BootServices,
        controller: Handle,
        driver_image: ?Handle,
        child: ?Handle,
    ) DisconnectControllerError!void {
        switch (self._disconnectController(
            controller,
            driver_image,
            child,
        )) {
            .success => {},
            .invalid_parameter => return error.InvalidParameter,
            .out_of_resources => return error.OutOfResources,
            .device_error => return error.DeviceError,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 为 UEFI 应用程序打开协议,以其结构体作为已加载映像。
    ///
    /// 若 `flag` 为 `.test_protocol`,则唯一有效返回值为 `null`,并返回 `Status.unsupported`。
    /// 否则,若 `_openProtocol` 返回 `Status.unsupported`,则返回 `null`。
    ///
    pub fn openProtocol(
        self: *BootServices,
        Protocol: type,
        handle: Handle,
        attributes: OpenProtocolArgs,
    ) OpenProtocolError!?*Protocol {
        if (!@hasDecl(Protocol, "guid"))
            @compileError("Protocol is missing guid: " ++ @typeName(Protocol));

        const agent_handle: ?Handle, const controller_handle: ?Handle = switch (attributes) {
            inline else => |arg| .{ arg.agent, arg.controller },
        };

        var ptr: ?*Protocol = undefined;

        switch (self._openProtocol(
            handle,
            &Protocol.guid,
            @as(*?*anyopaque, @ptrCast(&ptr)),
            agent_handle,
            controller_handle,
            std.meta.activeTag(attributes),
        )) {
            .success => return if (attributes == .test_protocol) null else ptr,
            .unsupported => return if (attributes == .test_protocol) error.Unsupported else null,
            .access_denied => return error.AccessDenied,
            .already_started => return error.AlreadyStarted,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn closeProtocol(
        self: *BootServices,
        handle: Handle,
        Protocol: type,
        agent: Handle,
        controller: ?Handle,
    ) CloseProtocolError!void {
        if (!@hasDecl(Protocol, "guid"))
            @compileError("protocol is missing guid: " ++ @typeName(Protocol));

        switch (self._closeProtocol(
            handle,
            &Protocol.guid,
            agent,
            controller,
        )) {
            .success => {},
            .invalid_parameter => return error.InvalidParameter,
            .not_found => return error.NotFound,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn openProtocolInformation(
        self: *const BootServices,
        handle: Handle,
        Protocol: type,
    ) OpenProtocolInformationError!?[]ProtocolInformationEntry {
        var entries: [*]ProtocolInformationEntry = undefined;
        var len: usize = undefined;

        switch (self._openProtocolInformation(
            handle,
            &Protocol.guid,
            &entries,
            &len,
        )) {
            .success => return entries[0..len],
            .not_found => return null,
            .out_of_resources => return error.OutOfResources,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn protocolsPerHandle(
        self: *const BootServices,
        handle: Handle,
    ) ProtocolsPerHandleError![]*const Guid {
        var guids: [*]*const Guid = undefined;
        var len: usize = undefined;

        switch (self._protocolsPerHandle(
            handle,
            &guids,
            &len,
        )) {
            .success => return guids[0..len],
            .invalid_parameter => return error.InvalidParameter,
            .out_of_resources => return error.OutOfResources,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn locateHandleBuffer(
        self: *const BootServices,
        search: LocateSearch,
    ) LocateHandleBufferError!?[]Handle {
        var handles: [*]Handle = undefined;
        var len: usize = undefined;

        switch (self._locateHandleBuffer(
            std.meta.activeTag(search),
            if (search == .by_protocol) search.by_protocol else null,
            if (search == .by_register_notify) search.by_register_notify else null,
            &len,
            &handles,
        )) {
            .success => return handles[0..len],
            .invalid_parameter => return error.InvalidParameter,
            .not_found => return null,
            .out_of_resources => return error.OutOfResources,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn locateProtocol(
        self: *const BootServices,
        Protocol: type,
        registration: ?EventRegistration,
    ) LocateProtocolError!?*Protocol {
        var interface: *Protocol = undefined;

        switch (self._locateProtocol(
            &Protocol.guid,
            registration,
            @ptrCast(&interface),
        )) {
            .success => return interface,
            .not_found => return null,
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 向启动服务环境安装一组协议接口。
    ///
    /// 此函数的最后一个参数应为指向协议
    /// 接口的指针元组,例如:
    ///
    /// ```
    /// const handle = try boot_services.installProtocolInterfaces(null, .{
    ///     &my_interface_1,
    ///     &my_interface_2,
    /// });
    /// ```
    ///
    /// 底层函数接受变长参数列表,其中每对参数分别是 Guid 指针
    /// 和指向接口的不透明指针。为提供 guid,接口
    /// 类型应按以下方式声明 `guid` 常量:
    ///
    /// ```
    /// pub const guid: uefi.Guid = .{ ... };
    /// ```
    ///
    /// 协议类型定义示例见 `std.os.uefi.protocol`。
    pub fn installProtocolInterfaces(
        self: *BootServices,
        handle: ?Handle,
        interfaces: anytype,
    ) InstallProtocolInterfacesError!Handle {
        var hdl: ?Handle = handle;
        const args_tuple = protocolInterfaces(&hdl, interfaces);

        switch (@call(
            .auto,
            self._installMultipleProtocolInterfaces,
            args_tuple,
        )) {
            .success => return hdl.?,
            .already_started => return error.AlreadyStarted,
            .out_of_resources => return error.OutOfResources,
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn uninstallProtocolInterfaces(
        self: *BootServices,
        handle: Handle,
        interfaces: anytype,
    ) UninstallProtocolInterfacesError!void {
        const args_tuple = protocolInterfaces(handle, interfaces);

        switch (@call(
            .auto,
            self._uninstallMultipleProtocolInterfaces,
            args_tuple,
        )) {
            .success => {},
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn calculateCrc32(
        self: *const BootServices,
        data: []const u8,
    ) CalculateCrc32Error!u32 {
        var value: u32 = undefined;
        switch (self._calculateCrc32(data.ptr, data.len, &value)) {
            .success => return value,
            .invalid_parameter => return error.InvalidParameter,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub const signature: u64 = 0x56524553544f4f42;

    pub const NotifyOpts = struct {
        tpl: TaskPriorityLevel = .application,
        function: ?*const fn (Event, ?*anyopaque) callconv(cc) void = null,
        context: ?*anyopaque = null,
    };

    pub const TaskPriorityLevel = enum(usize) {
        application = 4,
        callback = 8,
        notify = 16,
        high_level = 31,
        _,
    };

    pub const ImageExitData = struct {
        code: Status,
        description: ?[:0]const u16,
        data: ?[]const u16,
    };
};

fn protocolInterfaces(
    handle_arg: anytype,
    interfaces: anytype,
) ProtocolInterfaces(@TypeOf(handle_arg), @TypeOf(interfaces)) {
    var result: ProtocolInterfaces(
        @TypeOf(handle_arg),
        @TypeOf(interfaces),
    ) = undefined;
    result[0] = handle_arg;
    result[result.len - 1] = null;

    comptime var idx: usize = 1;
    inline for (interfaces) |interface| {
        const InterfacePtr = @TypeOf(interface);
        const Interface = switch (@typeInfo(InterfacePtr)) {
            .pointer => |pointer| pointer.child,
            else => @compileError("expected tuple of '*const Protocol', got " ++ @typeName(InterfacePtr)),
        };

        if (!@hasDecl(Interface, "guid"))
            @compileError("protocol interface '" ++ @typeName(Interface) ++
                "' does not declare a 'const guid: uefi.Guid'.");

        switch (@typeInfo(Interface)) {
            .@"struct" => |struct_info| if (struct_info.layout != .@"extern")
                @compileLog("protocol interface '" ++ @typeName(Interface) ++
                    "' is not extern - this is likely a mistake"),
            else => @compileError("protocol interface must be a struct, got " ++ @typeName(Interface)),
        }

        result[idx] = &Interface.guid;
        result[idx + 1] = @ptrCast(interface);
        idx += 2;
    }

    return result;
}

fn ProtocolInterfaces(HandleType: type, Interfaces: type) type {
    const interfaces_type_info = @typeInfo(Interfaces);
    if (interfaces_type_info != .@"struct" or !interfaces_type_info.@"struct".is_tuple)
        @compileError("expected tuple of protocol interfaces, got " ++ @typeName(Interfaces));
    const interfaces_info = interfaces_type_info.@"struct";

    var tuple_types: [interfaces_info.field_names.len * 2 + 2]type = undefined;
    tuple_types[0] = HandleType;
    tuple_types[tuple_types.len - 1] = ?*const Guid;

    var idx = 1;
    while (idx < tuple_types.len - 1) : (idx += 2) {
        tuple_types[idx] = *const Guid;
        tuple_types[idx + 1] = *const anyopaque;
    }

    return @Tuple(tuple_types[0..]);
}