From 9720bade7a0165d4e6dc7bf4fafb895f2e458a3b Mon Sep 17 00:00:00 2001 From: Carmen Date: Tue, 1 Apr 2025 10:10:10 -0700 Subject: [PATCH] std.start: allow return uefi error union in main (#23425) --- lib/std/os/uefi.zig | 1 + lib/std/start.zig | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/std/os/uefi.zig b/lib/std/os/uefi.zig index 1402766669..c362f707c6 100644 --- a/lib/std/os/uefi.zig +++ b/lib/std/os/uefi.zig @@ -7,6 +7,7 @@ pub const hii = @import("uefi/hii.zig"); /// Status codes returned by EFI interfaces pub const Status = @import("uefi/status.zig").Status; +pub const Error = UnexpectedError || Status.Error; pub const tables = @import("uefi/tables.zig"); /// The memory type to allocate when using the pool. diff --git a/lib/std/start.zig b/lib/std/start.zig index a91df35700..3757462be1 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -211,13 +211,24 @@ fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv root.main(); return 0; }, - usize => { - return root.main(); - }, uefi.Status => { return @intFromEnum(root.main()); }, - else => @compileError("expected return type of main to be 'void', 'noreturn', 'usize', or 'std.os.uefi.Status'"), + uefi.Error!void => { + root.main() catch |err| switch (err) { + error.Unexpected => @panic("EfiMain: unexpected error"), + else => { + const status = uefi.Status.fromError(@errorCast(err)); + return @intFromEnum(status); + }, + }; + + return 0; + }, + else => @compileError( + "expected return type of main to be 'void', 'noreturn', " ++ + "'uefi.Status', or 'uefi.Error!void'", + ), } }