跳转到内容

std.os.uefi.tables.runtime_services

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

第 1 行

std.os.uefi.tables.runtime_services.CapsuleHeader

别名

第 11 行

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

std.os.uefi.tables.runtime_services.cc

别名

第 13 行

别名目标 std.os.uefi.cc

std.os.uefi.tables.runtime_services.Error

别名

第 14 行

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

std.os.uefi.tables.runtime_services.Guid

别名

第 3 行

别名目标 std.os.uefi.Guid

std.os.uefi.tables.runtime_services.MemoryDescriptor

别名

第 8 行

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

std.os.uefi.tables.runtime_services.MemoryMapSlice

别名

第 9 行

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

std.os.uefi.tables.runtime_services.PhysicalAddress

别名

第 12 行

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

std.os.uefi.tables.runtime_services.ResetType

别名

第 10 行

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

std.os.uefi.tables.runtime_services.RuntimeServices

容器

第 24 行

固件在调用 exitBootServices 之前和之后都提供运行时服务。

runtime_services 表可能随新版 UEFI 扩展,因此务必检查 hdr.header_size。

部分函数可能不受支持。请使用 getVariable 检查 RuntimeServicesSupported 变量。 getVariable 本身也是可能不受支持的函数之一。

某些函数在其他函数执行期间不得调用。

字段

hdr: TableHeader
_getTime: *const fn (time: *Time, capabilities: ?*TimeCapabilities) callconv(cc) Status

返回当前时间和日期信息,以及硬件平台的计时能力。

_setTime: *const fn (time: *const Time) callconv(cc) Status

设置当前本地时间和日期信息

_getWakeupTime: *const fn (enabled: *bool, pending: *bool, time: *Time) callconv(cc) Status

返回当前唤醒闹钟设置

_setWakeupTime: *const fn (enable: bool, time: ?*const Time) callconv(cc) Status

设置系统唤醒闹钟时间

_setVirtualAddressMap: *const fn (mmap_size: usize, descriptor_size: usize, descriptor_version: u32, virtual_map: [*]align(@alignOf(MemoryDescriptor)) u8) callconv(cc) Status

将 EFI 固件的运行期寻址模式从物理地址改为虚拟地址。

_convertPointer: *const fn (debug_disposition: DebugDisposition, address: *?*anyopaque) callconv(cc) Status

确定后续内存访问使用的新虚拟地址。

_getVariable: *const fn (var_name: [*:0]const u16, vendor_guid: *const Guid, attributes: ?*VariableAttributes, data_size: *usize, data: ?*anyopaque) callconv(cc) Status

返回变量的值。

_getNextVariableName: *const fn (var_name_size: *usize, var_name: ?[*:0]const u16, vendor_guid: *Guid) callconv(cc) Status

枚举当前变量名称。

_setVariable: *const fn (var_name: [*:0]const u16, vendor_guid: *const Guid, attributes: VariableAttributes, data_size: usize, data: [*]const u8) callconv(cc) Status

设置变量的值。

_getNextHighMonotonicCount: *const fn (high_count: *u32) callconv(cc) Status

返回平台单调计数器接下来的高 32 位。

_resetSystem: *const fn (reset_type: ResetType, reset_status: Status, data_size: usize, reset_data: ?[*]const u16) callconv(cc) noreturn

重置整个平台。

_updateCapsule: *const fn (capsule_header_array: [*]*const CapsuleHeader, capsule_count: usize, scatter_gather_list: PhysicalAddress) callconv(cc) Status

通过虚拟映射和物理映射向固件传递胶囊。 固件可能根据预期用途立即处理胶囊。 若载荷需要在系统复位后保留,必须将 queryCapsuleCapabilities 返回的复位值传给 resetSystem,这会使固件在复位过程中处理胶囊。

_queryCapsuleCapabilities: *const fn (capsule_header_array: [*]*const CapsuleHeader, capsule_count: usize, maximum_capsule_size: *usize, reset_type: *ResetType) callconv(cc) Status

返回是否可通过 updateCapsule 支持该胶囊

_queryVariableInfo: *const fn (attributes: VariableAttributes, maximum_variable_storage_size: *u64, remaining_variable_storage_size: *u64, maximum_variable_size: *u64) callconv(cc) Status

返回 EFI 变量的信息

std.os.uefi.tables.runtime_services.RuntimeServices.convertPointer

函数

第 231 行

pub fn convertPointer( self: *const RuntimeServices, comptime disposition: DebugDisposition, cvt: @FieldType(PointerConversion, @tagName(disposition)), ) ConvertPointerError!?@FieldType(PointerConversion, @tagName(disposition))

参数

self: *const RuntimeServices
disposition: DebugDisposition
cvt: @FieldType(PointerConversion, @tagName(disposition))

错误

InvalidParameter
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.ConvertPointerError

错误集合

第 100 行

错误

InvalidParameter
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.DebugDisposition

容器

第 419 行

字段

pointer = @bitCast(Bits{})
optional = @bitCast(Bits{ .optional_ptr = true })
_

std.os.uefi.tables.runtime_services.RuntimeServices.DebugDisposition.Bits

容器

第 420 行

字段

optional_ptr: bool = false
_pad: @Int(.unsigned, @bitSizeOf(usize) - 1) = 0

std.os.uefi.tables.runtime_services.RuntimeServices.getNextHighMonotonicCount

函数

第 336 行

pub fn getNextHighMonotonicCount(self: *const RuntimeServices) GetNextHighMonotonicCountError!u32

参数

self: *const RuntimeServices

错误

DeviceError
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.GetNextHighMonotonicCountError

错误集合

第 124 行

错误

DeviceError
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.getTime

函数

第 147 行

返回当前时间及平台的时间能力。

pub fn getTime( self: *const RuntimeServices, ) GetTimeError!struct { Time, TimeCapabilities }

参数

self: *const RuntimeServices

错误

DeviceError
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.GetTimeError

错误集合

第 73 行

错误

DeviceError
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.getVariable

函数

第 273 行

要确定该变量所需的最小缓冲区大小,请先调用 getVariableSize。

pub fn getVariable( self: *const RuntimeServices, name: [*:0]const u16, guid: *const Guid, buffer: []u8, ) GetVariableError!?struct { []u8, VariableAttributes }

参数

self: *const RuntimeServices
name: [*:0]const u16
guid: *const Guid
buffer: []u8

错误

BufferTooSmall
DeviceError GetVariableSizeError
Unexpected UnexpectedError
Unsupported GetVariableSizeError

std.os.uefi.tables.runtime_services.RuntimeServices.GetVariableError

错误集合

第 110 行

错误

BufferTooSmall
DeviceError GetVariableSizeError
Unexpected UnexpectedError
Unsupported GetVariableSizeError

std.os.uefi.tables.runtime_services.RuntimeServices.getVariableSize

函数

第 248 行

返回变量数据的长度及其属性。

pub fn getVariableSize( self: *const RuntimeServices, name: [*:0]const u16, guid: *const Guid, ) GetVariableSizeError!?struct { usize, VariableAttributes }

参数

self: *const RuntimeServices
name: [*:0]const u16
guid: *const Guid

错误

DeviceError
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.GetVariableSizeError

错误集合

第 105 行

错误

DeviceError
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.getWakeupTime

函数

第 176 行

pub fn getWakeupTime( self: *const RuntimeServices, ) GetWakeupTimeError!GetWakeupTime

参数

self: *const RuntimeServices

错误

DeviceError
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.GetWakeupTime

容器

第 170 行

字段

enabled: bool
pending: bool
time: Time

std.os.uefi.tables.runtime_services.RuntimeServices.GetWakeupTimeError

错误集合

第 83 行

错误

DeviceError
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.PointerConversion

容器

第 430 行

字段

pointer: *anyopaque
optional: ?*anyopaque

std.os.uefi.tables.runtime_services.RuntimeServices.queryCapsuleCapabilities

函数

第 379 行

pub fn queryCapsuleCapabilities( self: *const RuntimeServices, capsules: []*const CapsuleHeader, ) QueryCapsuleCapabilitiesError!struct { u64, ResetType }

参数

self: *const RuntimeServices
capsules: []*const CapsuleHeader

错误

OutOfResources
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.QueryCapsuleCapabilitiesError

错误集合

第 136 行

错误

OutOfResources
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.queryVariableInfo

函数

第 399 行

pub fn queryVariableInfo( self: *const RuntimeServices,attributes: VariableAttributes, ) QueryVariableInfoError!VariableInfo

参数

self: *const RuntimeServices
attributes: VariableAttributes

错误

InvalidParameter
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.QueryVariableInfoError

错误集合

第 141 行

错误

InvalidParameter
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.resetSystem

函数

第 346 行

pub fn resetSystem( self: *RuntimeServices, reset_type: ResetType, reset_status: Status, data: ?[]align(2) const u8, ) noreturn

参数

self: *RuntimeServices
reset_type: ResetType
reset_status: Status
data: ?[]align(2) const u8

std.os.uefi.tables.runtime_services.RuntimeServices.setTime

函数

第 161 行

pub fn setTime(self: *RuntimeServices, time: *const Time) SetTimeError!void

参数

self: *RuntimeServices
time: *const Time

错误

DeviceError
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.SetTimeError

错误集合

第 78 行

错误

DeviceError
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.setVariable

函数

第 310 行

pub fn setVariable( self: *RuntimeServices, name: [*:0]const u16, guid: *const Guid, attributes: VariableAttributes, data: []const u8, ) SetVariableError!void

参数

self: *RuntimeServices
name: [*:0]const u16
guid: *const Guid
attributes: VariableAttributes
data: []const u8

错误

DeviceError
InvalidParameter
NotFound
OutOfResources
SecurityViolation
Unexpected UnexpectedError
Unsupported
WriteProtected

std.os.uefi.tables.runtime_services.RuntimeServices.SetVariableError

错误集合

第 114 行

错误

DeviceError
InvalidParameter
NotFound
OutOfResources
SecurityViolation
Unexpected UnexpectedError
Unsupported
WriteProtected

std.os.uefi.tables.runtime_services.RuntimeServices.setVirtualAddressMap

函数

第 213 行

pub fn setVirtualAddressMap( self: *RuntimeServices, map: MemoryMapSlice, ) SetVirtualAddressMapError!void

参数

错误

NoMapping
NotFound
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.SetVirtualAddressMapError

错误集合

第 94 行

错误

NoMapping
NotFound
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.setWakeupTime

函数

第 197 行

pub fn setWakeupTime( self: *RuntimeServices, set: SetWakeupTime, ) SetWakeupTimeError!void

参数

错误

DeviceError
InvalidParameter
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.SetWakeupTime

容器

第 192 行

字段

enabled: *const Time
disabled

std.os.uefi.tables.runtime_services.RuntimeServices.SetWakeupTimeError

错误集合

第 88 行

错误

DeviceError
InvalidParameter
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.signature

常量

第 534 行

u64

std.os.uefi.tables.runtime_services.RuntimeServices.updateCapsule

函数

第 360 行

pub fn updateCapsule( self: *RuntimeServices, capsules: []*const CapsuleHeader, scatter_gather_list: PhysicalAddress, ) UpdateCapsuleError!void

参数

self: *RuntimeServices
capsules: []*const CapsuleHeader
scatter_gather_list: PhysicalAddress

错误

DeviceError
InvalidParameter
OutOfResources
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.UpdateCapsuleError

错误集合

第 129 行

错误

DeviceError
InvalidParameter
OutOfResources
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.VariableAttributes

容器

第 435 行

字段

non_volatile: bool = false
bootservice_access: bool = false
runtime_access: bool = false
hardware_error_record: bool = false
authenticated_write_access: bool = false

注意:已弃用,应视为保留项。

time_based_authenticated_write_access: bool = false
append_write: bool = false
enhanced_authenticated_access: bool = false

表示变量负载以 EFI_VARIABLE_AUTHENTICATION_3 结构体开始, 并可能包含由该结构体字段指示的更多结构体。

_pad: u24 = 0

std.os.uefi.tables.runtime_services.RuntimeServices.VariableAuthentication3

容器

第 451 行

字段

version: u8 = 1
type: Type
metadata_size: u32
flags: Flags

std.os.uefi.tables.runtime_services.RuntimeServices.VariableAuthentication3.Flags

容器

第 466 行

字段

update_cert: bool = false
_pad: u31 = 0

std.os.uefi.tables.runtime_services.RuntimeServices.VariableAuthentication3.payload

函数

第 461 行

pub fn payload(self: *VariableAuthentication3) []u8

参数

std.os.uefi.tables.runtime_services.RuntimeServices.VariableAuthentication3.payloadConst

函数

第 457 行

pub fn payloadConst(self: *const VariableAuthentication3) []const u8

参数

std.os.uefi.tables.runtime_services.RuntimeServices.VariableAuthentication3.Type

容器

第 471 行

字段

timestamp = 1
nonce = 2
_

std.os.uefi.tables.runtime_services.RuntimeServices.VariableInfo

容器

第 478 行

字段

max_variable_storage_size: u64
remaining_variable_storage_size: u64
max_variable_size: u64

std.os.uefi.tables.runtime_services.RuntimeServices.variableNameIterator

函数

第 298 行

pub fn variableNameIterator( self: *const RuntimeServices, buffer: []u16, ) VariableNameIterator

参数

self: *const RuntimeServices
buffer: []u16

std.os.uefi.tables.runtime_services.RuntimeServices.VariableNameIterator

容器

第 484 行

字段

services: *const RuntimeServices
buffer: []u16
guid: Guid

std.os.uefi.tables.runtime_services.RuntimeServices.VariableNameIterator.IterateVariableNameError

错误集合

第 490 行

错误

BufferTooSmall
DeviceError NextSizeError
Unexpected UnexpectedError
Unsupported NextSizeError

std.os.uefi.tables.runtime_services.RuntimeServices.VariableNameIterator.next

函数

第 515 行

调用 nextSize 获取下一个变量名称的长度,并检查 buffer 是否足够容纳该名称。

pub fn next( self: *VariableNameIterator, ) IterateVariableNameError!?[:0]const u16

参数

错误

BufferTooSmall
DeviceError NextSizeError
Unexpected UnexpectedError
Unsupported NextSizeError

std.os.uefi.tables.runtime_services.RuntimeServices.VariableNameIterator.nextSize

函数

第 498 行

pub fn nextSize(self: *VariableNameIterator) NextSizeError!?usize

参数

错误

DeviceError
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.RuntimeServices.VariableNameIterator.NextSizeError

错误集合

第 485 行

错误

DeviceError
Unexpected UnexpectedError
Unsupported

std.os.uefi.tables.runtime_services.Status

别名

第 7 行

别名目标 std.os.uefi.Status

std.os.uefi.tables.runtime_services.std

别名

第 1 行

别名目标 std

std.os.uefi.tables.runtime_services.TableHeader

别名

第 4 行

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

std.os.uefi.tables.runtime_services.Time

别名

第 5 行

别名目标 std.os.uefi.Time

std.os.uefi.tables.runtime_services.TimeCapabilities

别名

第 6 行

别名目标 std.os.uefi.TimeCapabilities

std.os.uefi.tables.runtime_services.uefi

别名

第 2 行

别名目标 std.os.uefi

源码

std/os/uefi/tables/runtime_services.zig

const std = @import("std");
const uefi = std.os.uefi;
const Guid = uefi.Guid;
const TableHeader = uefi.tables.TableHeader;
const Time = uefi.Time;
const TimeCapabilities = uefi.TimeCapabilities;
const Status = uefi.Status;
const MemoryDescriptor = uefi.tables.MemoryDescriptor;
const MemoryMapSlice = uefi.tables.MemoryMapSlice;
const ResetType = uefi.tables.ResetType;
const CapsuleHeader = uefi.tables.CapsuleHeader;
const PhysicalAddress = uefi.tables.PhysicalAddress;
const cc = uefi.cc;
const Error = Status.Error;

/// 固件在调用 exitBootServices 之前和之后都提供运行时服务。
///
/// runtime_services 表可能随新版 UEFI 扩展,因此务必检查 hdr.header_size。
///
/// 部分函数可能不受支持。请使用 getVariable 检查 RuntimeServicesSupported 变量。
/// getVariable 本身也是可能不受支持的函数之一。
///
/// 某些函数在其他函数执行期间不得调用。
pub const RuntimeServices = extern struct {
    hdr: TableHeader,

    /// 返回当前时间和日期信息,以及硬件平台的计时能力。
    _getTime: *const fn (time: *Time, capabilities: ?*TimeCapabilities) callconv(cc) Status,

    /// 设置当前本地时间和日期信息
    _setTime: *const fn (time: *const Time) callconv(cc) Status,

    /// 返回当前唤醒闹钟设置
    _getWakeupTime: *const fn (enabled: *bool, pending: *bool, time: *Time) callconv(cc) Status,

    /// 设置系统唤醒闹钟时间
    _setWakeupTime: *const fn (enable: bool, time: ?*const Time) callconv(cc) Status,

    /// 将 EFI 固件的运行期寻址模式从物理地址改为虚拟地址。
    _setVirtualAddressMap: *const fn (mmap_size: usize, descriptor_size: usize, descriptor_version: u32, virtual_map: [*]align(@alignOf(MemoryDescriptor)) u8) callconv(cc) Status,

    /// 确定后续内存访问使用的新虚拟地址。
    _convertPointer: *const fn (debug_disposition: DebugDisposition, address: *?*anyopaque) callconv(cc) Status,

    /// 返回变量的值。
    _getVariable: *const fn (var_name: [*:0]const u16, vendor_guid: *const Guid, attributes: ?*VariableAttributes, data_size: *usize, data: ?*anyopaque) callconv(cc) Status,

    /// 枚举当前变量名称。
    _getNextVariableName: *const fn (var_name_size: *usize, var_name: ?[*:0]const u16, vendor_guid: *Guid) callconv(cc) Status,

    /// 设置变量的值。
    _setVariable: *const fn (var_name: [*:0]const u16, vendor_guid: *const Guid, attributes: VariableAttributes, data_size: usize, data: [*]const u8) callconv(cc) Status,

    /// 返回平台单调计数器接下来的高 32 位。
    _getNextHighMonotonicCount: *const fn (high_count: *u32) callconv(cc) Status,

    /// 重置整个平台。
    _resetSystem: *const fn (reset_type: ResetType, reset_status: Status, data_size: usize, reset_data: ?[*]const u16) callconv(cc) noreturn,

    /// 通过虚拟映射和物理映射向固件传递胶囊。
    /// 固件可能根据预期用途立即处理胶囊。
    /// 若载荷需要在系统复位后保留,必须将 `queryCapsuleCapabilities` 返回的复位值传给 resetSystem,这会使固件在复位过程中处理胶囊。
    ///
    ///
    _updateCapsule: *const fn (capsule_header_array: [*]*const CapsuleHeader, capsule_count: usize, scatter_gather_list: PhysicalAddress) callconv(cc) Status,

    /// 返回是否可通过 `updateCapsule` 支持该胶囊
    _queryCapsuleCapabilities: *const fn (capsule_header_array: [*]*const CapsuleHeader, capsule_count: usize, maximum_capsule_size: *usize, reset_type: *ResetType) callconv(cc) Status,

    /// 返回 EFI 变量的信息
    _queryVariableInfo: *const fn (attributes: VariableAttributes, maximum_variable_storage_size: *u64, remaining_variable_storage_size: *u64, maximum_variable_size: *u64) callconv(cc) Status,

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

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

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

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

    pub const SetVirtualAddressMapError = uefi.UnexpectedError || error{
        Unsupported,
        NoMapping,
        NotFound,
    };

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

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

    pub const GetVariableError = GetVariableSizeError || error{
        BufferTooSmall,
    };

    pub const SetVariableError = uefi.UnexpectedError || error{
        InvalidParameter,
        OutOfResources,
        DeviceError,
        WriteProtected,
        SecurityViolation,
        NotFound,
        Unsupported,
    };

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

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

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

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

    /// 返回当前时间及平台的时间能力。
    pub fn getTime(
        self: *const RuntimeServices,
    ) GetTimeError!struct { Time, TimeCapabilities } {
        var time: Time = undefined;
        var capabilities: TimeCapabilities = undefined;

        switch (self._getTime(&time, &capabilities)) {
            .success => return .{ time, capabilities },
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn setTime(self: *RuntimeServices, time: *const Time) SetTimeError!void {
        switch (self._setTime(time)) {
            .success => {},
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub const GetWakeupTime = struct {
        enabled: bool,
        pending: bool,
        time: Time,
    };

    pub fn getWakeupTime(
        self: *const RuntimeServices,
    ) GetWakeupTimeError!GetWakeupTime {
        var result: GetWakeupTime = undefined;
        switch (self._getWakeupTime(
            &result.enabled,
            &result.pending,
            &result.time,
        )) {
            .success => return result,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub const SetWakeupTime = union(enum) {
        enabled: *const Time,
        disabled,
    };

    pub fn setWakeupTime(
        self: *RuntimeServices,
        set: SetWakeupTime,
    ) SetWakeupTimeError!void {
        switch (self._setWakeupTime(
            set != .disabled,
            if (set == .enabled) set.enabled else null,
        )) {
            .success => {},
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn setVirtualAddressMap(
        self: *RuntimeServices,
        map: MemoryMapSlice,
    ) SetVirtualAddressMapError!void {
        switch (self._setVirtualAddressMap(
            map.info.len * map.info.descriptor_size,
            map.info.descriptor_size,
            map.info.descriptor_version,
            @ptrCast(map.ptr),
        )) {
            .success => {},
            .unsupported => return error.Unsupported,
            .no_mapping => return error.NoMapping,
            .not_found => return error.NotFound,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn convertPointer(
        self: *const RuntimeServices,
        comptime disposition: DebugDisposition,
        cvt: @FieldType(PointerConversion, @tagName(disposition)),
    ) ConvertPointerError!?@FieldType(PointerConversion, @tagName(disposition)) {
        var pointer = cvt;

        switch (self._convertPointer(disposition, @ptrCast(&pointer))) {
            .success => return pointer,
            .not_found => return null,
            .invalid_parameter => return error.InvalidParameter,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 返回变量数据的长度及其属性。
    pub fn getVariableSize(
        self: *const RuntimeServices,
        name: [*:0]const u16,
        guid: *const Guid,
    ) GetVariableSizeError!?struct { usize, VariableAttributes } {
        var size: usize = 0;
        var attrs: VariableAttributes = undefined;

        switch (self._getVariable(
            name,
            guid,
            &attrs,
            &size,
            null,
        )) {
            .buffer_too_small => return .{ size, attrs },
            .not_found => return null,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    /// 要确定该变量所需的最小缓冲区大小,请先调用
    /// `getVariableSize`。
    pub fn getVariable(
        self: *const RuntimeServices,
        name: [*:0]const u16,
        guid: *const Guid,
        buffer: []u8,
    ) GetVariableError!?struct { []u8, VariableAttributes } {
        var attrs: VariableAttributes = undefined;
        var len = buffer.len;

        switch (self._getVariable(
            name,
            guid,
            &attrs,
            &len,
            buffer.ptr,
        )) {
            .success => return .{ buffer[0..len], attrs },
            .not_found => return null,
            .buffer_too_small => return error.BufferTooSmall,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn variableNameIterator(
        self: *const RuntimeServices,
        buffer: []u16,
    ) VariableNameIterator {
        buffer[0] = 0;
        return .{
            .services = self,
            .buffer = buffer,
            .guid = undefined,
        };
    }

    pub fn setVariable(
        self: *RuntimeServices,
        name: [*:0]const u16,
        guid: *const Guid,
        attributes: VariableAttributes,
        data: []const u8,
    ) SetVariableError!void {
        switch (self._setVariable(
            name,
            guid,
            attributes,
            data.len,
            data.ptr,
        )) {
            .success => {},
            .invalid_parameter => return error.InvalidParameter,
            .out_of_resources => return error.OutOfResources,
            .device_error => return error.DeviceError,
            .write_protected => return error.WriteProtected,
            .security_violation => return error.SecurityViolation,
            .not_found => return error.NotFound,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn getNextHighMonotonicCount(self: *const RuntimeServices) GetNextHighMonotonicCountError!u32 {
        var cnt: u32 = undefined;
        switch (self._getNextHighMonotonicCount(&cnt)) {
            .success => return cnt,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn resetSystem(
        self: *RuntimeServices,
        reset_type: ResetType,
        reset_status: Status,
        data: ?[]align(2) const u8,
    ) noreturn {
        self._resetSystem(
            reset_type,
            reset_status,
            if (data) |d| d.len else 0,
            if (data) |d| @ptrCast(@alignCast(d.ptr)) else null,
        );
    }

    pub fn updateCapsule(
        self: *RuntimeServices,
        capsules: []*const CapsuleHeader,
        scatter_gather_list: PhysicalAddress,
    ) UpdateCapsuleError!void {
        switch (self._updateCapsule(
            capsules.ptr,
            capsules.len,
            scatter_gather_list,
        )) {
            .success => {},
            .invalid_parameter => return error.InvalidParameter,
            .device_error => return error.DeviceError,
            .unsupported => return error.Unsupported,
            .out_of_resources => return error.OutOfResources,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn queryCapsuleCapabilities(
        self: *const RuntimeServices,
        capsules: []*const CapsuleHeader,
    ) QueryCapsuleCapabilitiesError!struct { u64, ResetType } {
        var max_capsule_size: u64 = undefined;
        var reset_type: ResetType = undefined;

        switch (self._queryCapsuleCapabilities(
            capsules.ptr,
            capsules.len,
            &max_capsule_size,
            &reset_type,
        )) {
            .success => return .{ max_capsule_size, reset_type },
            .unsupported => return error.Unsupported,
            .out_of_resources => return error.OutOfResources,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub fn queryVariableInfo(
        self: *const RuntimeServices,
        // 注意:忽略 .append_write
        attributes: VariableAttributes,
    ) QueryVariableInfoError!VariableInfo {
        var res: VariableInfo = undefined;

        switch (self._queryVariableInfo(
            attributes,
            &res.max_variable_storage_size,
            &res.remaining_variable_storage_size,
            &res.max_variable_size,
        )) {
            .success => return res,
            .invalid_parameter => return error.InvalidParameter,
            .unsupported => return error.Unsupported,
            else => |status| return uefi.unexpectedStatus(status),
        }
    }

    pub const DebugDisposition = enum(usize) {
        const Bits = packed struct(usize) {
            optional_ptr: bool = false,
            _pad: @Int(.unsigned, @bitSizeOf(usize) - 1) = 0,
        };

        pointer = @bitCast(Bits{}),
        optional = @bitCast(Bits{ .optional_ptr = true }),
        _,
    };

    pub const PointerConversion = union(DebugDisposition) {
        pointer: *anyopaque,
        optional: ?*anyopaque,
    };

    pub const VariableAttributes = packed struct(u32) {
        non_volatile: bool = false,
        bootservice_access: bool = false,
        runtime_access: bool = false,
        hardware_error_record: bool = false,
        /// 注意:已弃用,应视为保留项。
        authenticated_write_access: bool = false,
        time_based_authenticated_write_access: bool = false,
        append_write: bool = false,
        /// 表示变量负载以 EFI_VARIABLE_AUTHENTICATION_3 结构体开始,
        /// 并可能包含由该结构体字段指示的更多结构体。
        ///
        enhanced_authenticated_access: bool = false,
        _pad: u24 = 0,
    };

    pub const VariableAuthentication3 = extern struct {
        version: u8 = 1,
        type: Type,
        metadata_size: u32,
        flags: Flags,

        pub fn payloadConst(self: *const VariableAuthentication3) []const u8 {
            return @constCast(self).payload();
        }

        pub fn payload(self: *VariableAuthentication3) []u8 {
            var ptr: [*]u8 = @ptrCast(self);
            return ptr[@sizeOf(VariableAuthentication3)..self.metadata_size];
        }

        pub const Flags = packed struct(u32) {
            update_cert: bool = false,
            _pad: u31 = 0,
        };

        pub const Type = enum(u8) {
            timestamp = 1,
            nonce = 2,
            _,
        };
    };

    pub const VariableInfo = struct {
        max_variable_storage_size: u64,
        remaining_variable_storage_size: u64,
        max_variable_size: u64,
    };

    pub const VariableNameIterator = struct {
        pub const NextSizeError = uefi.UnexpectedError || error{
            DeviceError,
            Unsupported,
        };

        pub const IterateVariableNameError = NextSizeError || error{
            BufferTooSmall,
        };

        services: *const RuntimeServices,
        buffer: []u16,
        guid: Guid,

        pub fn nextSize(self: *VariableNameIterator) NextSizeError!?usize {
            var len: usize = 0;
            switch (self.services._getNextVariableName(
                &len,
                null,
                &self.guid,
            )) {
                .buffer_too_small => return len,
                .not_found => return null,
                .device_error => return error.DeviceError,
                .unsupported => return error.Unsupported,
                else => |status| return uefi.unexpectedStatus(status),
            }
        }

        /// 调用 `nextSize` 获取下一个变量名称的长度,并检查 `buffer` 是否足够容纳该名称。
        ///
        pub fn next(
            self: *VariableNameIterator,
        ) IterateVariableNameError!?[:0]const u16 {
            var len = self.buffer.len;
            switch (self.services._getNextVariableName(
                &len,
                @ptrCast(self.buffer.ptr),
                &self.guid,
            )) {
                .success => return self.buffer[0 .. len - 1 :0],
                .not_found => return null,
                .buffer_too_small => return error.BufferTooSmall,
                .device_error => return error.DeviceError,
                .unsupported => return error.Unsupported,
                else => |status| return uefi.unexpectedStatus(status),
            }
        }
    };

    pub const signature: u64 = 0x56524553544e5552;
};