Skip to content

Commit 4f65107

Browse files
committed
std.os.uefi: ziggify function signatures
1 parent 5ffd8bf commit 4f65107

File tree

6 files changed

+226
-97
lines changed

6 files changed

+226
-97
lines changed

lib/std/os/uefi.zig

+4
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,7 @@ test {
247247
_ = tables;
248248
_ = protocol;
249249
}
250+
251+
pub fn unexpectedError(err: Status.Error) noreturn {
252+
std.debug.panic("unexpected error: {any}", .{err});
253+
}

lib/std/os/uefi/protocol/absolute_pointer.zig

+16-5
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,33 @@ const Event = uefi.Event;
44
const Guid = uefi.Guid;
55
const Status = uefi.Status;
66
const cc = uefi.cc;
7+
const Error = Status.Error;
78

89
/// Protocol for touchscreens.
910
pub const AbsolutePointer = extern struct {
10-
_reset: *const fn (*const AbsolutePointer, bool) callconv(cc) Status,
11+
_reset: *const fn (*AbsolutePointer, bool) callconv(cc) Status,
1112
_get_state: *const fn (*const AbsolutePointer, *State) callconv(cc) Status,
1213
wait_for_input: Event,
1314
mode: *Mode,
1415

1516
/// Resets the pointer device hardware.
16-
pub fn reset(self: *const AbsolutePointer, verify: bool) Status {
17-
return self._reset(self, verify);
17+
pub fn reset(self: *AbsolutePointer, verify: bool) !void {
18+
switch (self._reset(self, verify)) {
19+
.success => {},
20+
.device_error => return Error.DeviceError,
21+
else => |err| uefi.unexpectedError(err.err()),
22+
}
1823
}
1924

2025
/// Retrieves the current state of a pointer device.
21-
pub fn getState(self: *const AbsolutePointer, state: *State) Status {
22-
return self._get_state(self, state);
26+
pub fn getState(self: *const AbsolutePointer) !State {
27+
var state: State = undefined;
28+
switch (self._get_state(self, &state)) {
29+
.success => return state,
30+
.not_ready => return Error.NotReady,
31+
.device_error => return Error.DeviceError,
32+
else => |err| uefi.unexpectedError(err.err()),
33+
}
2334
}
2435

2536
pub const guid align(8) = Guid{

lib/std/os/uefi/protocol/block_io.zig

+34-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const std = @import("std");
22
const uefi = std.os.uefi;
33
const Status = uefi.Status;
44
const cc = uefi.cc;
5+
const Error = Status.Error;
56

67
pub const BlockIo = extern struct {
78
const Self = @This();
@@ -15,23 +16,48 @@ pub const BlockIo = extern struct {
1516
_flush_blocks: *const fn (*BlockIo) callconv(cc) Status,
1617

1718
/// Resets the block device hardware.
18-
pub fn reset(self: *Self, extended_verification: bool) Status {
19-
return self._reset(self, extended_verification);
19+
pub fn reset(self: *Self, extended_verification: bool) !void {
20+
switch (self._reset(self, extended_verification)) {
21+
.success => {},
22+
.device_error => return Error.DeviceError,
23+
else => |err| uefi.unexpectedError(err.err()),
24+
}
2025
}
2126

2227
/// Reads the number of requested blocks from the device.
23-
pub fn readBlocks(self: *Self, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) Status {
24-
return self._read_blocks(self, media_id, lba, buffer_size, buf);
28+
pub fn readBlocks(self: *Self, media_id: u32, lba: u64, buf: []u8) !void {
29+
switch (self._read_blocks(self, media_id, lba, buf.len, buf.ptr)) {
30+
.success => {},
31+
.device_error => Error.DeviceError,
32+
.no_media => Error.NoMedia,
33+
.bad_buffer_size => Error.BadBufferSize,
34+
.invalid_parameter => Error.InvalidParameter,
35+
else => |err| uefi.unexpectedError(err.err()),
36+
}
2537
}
2638

2739
/// Writes a specified number of blocks to the device.
28-
pub fn writeBlocks(self: *Self, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) Status {
29-
return self._write_blocks(self, media_id, lba, buffer_size, buf);
40+
pub fn writeBlocks(self: *Self, media_id: u32, lba: u64, buf: []const u8) !void {
41+
switch (self._write_blocks(self, media_id, lba, buf.len, buf.ptr)) {
42+
.success => {},
43+
.write_protected => Error.WriteProtected,
44+
.no_media => Error.NoMedia,
45+
.media_changed => Error.MediaChanged,
46+
.device_error => Error.DeviceError,
47+
.bad_buffer_size => Error.BadBufferSize,
48+
.invalid_parameter => Error.InvalidParameter,
49+
else => |err| uefi.unexpectedError(err.err()),
50+
}
3051
}
3152

3253
/// Flushes all modified data to a physical block device.
33-
pub fn flushBlocks(self: *Self) Status {
34-
return self._flush_blocks(self);
54+
pub fn flushBlocks(self: *Self) !void {
55+
switch (self._flush_blocks(self)) {
56+
.success => {},
57+
.device_error => Error.DeviceError,
58+
.no_media => Error.NoMedia,
59+
else => |err| uefi.unexpectedError(err.err()),
60+
}
3561
}
3662

3763
pub const guid align(8) = uefi.Guid{

lib/std/os/uefi/protocol/device_path.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ pub const DevicePath = extern struct {
2323
};
2424

2525
/// Returns the next DevicePath node in the sequence, if any.
26-
pub fn next(self: *DevicePath) ?*DevicePath {
26+
pub fn next(self: *const DevicePath) ?*DevicePath {
2727
if (self.type == .end and @as(uefi.DevicePath.End.Subtype, @enumFromInt(self.subtype)) == .end_entire)
2828
return null;
2929

3030
return @as(*DevicePath, @ptrCast(@as([*]u8, @ptrCast(self)) + self.length));
3131
}
3232

3333
/// Calculates the total length of the device path structure in bytes, including the end of device path node.
34-
pub fn size(self: *DevicePath) usize {
34+
pub fn size(self: *const DevicePath) usize {
3535
var node = self;
3636

3737
while (node.next()) |next_node| {
@@ -42,7 +42,7 @@ pub const DevicePath = extern struct {
4242
}
4343

4444
/// Creates a file device path from the existing device path and a file path.
45-
pub fn create_file_device_path(self: *DevicePath, allocator: Allocator, path: [:0]align(1) const u16) !*DevicePath {
45+
pub fn create_file_device_path(self: *const DevicePath, allocator: Allocator, path: []const u16) !*DevicePath {
4646
const path_size = self.size();
4747

4848
// 2 * (path.len + 1) for the path and its null terminator, which are u16s

lib/std/os/uefi/protocol/edid.zig

+14-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const Guid = uefi.Guid;
44
const Handle = uefi.Handle;
55
const Status = uefi.Status;
66
const cc = uefi.cc;
7+
const Error = Status.Error;
78

89
/// EDID information for an active video output device
910
pub const Active = extern struct {
@@ -44,10 +45,19 @@ pub const Override = extern struct {
4445
self: *const Override,
4546
handle: Handle,
4647
attributes: *Attributes,
47-
edid_size: *usize,
48-
edid: *?[*]u8,
49-
) Status {
50-
return self._get_edid(self, handle, attributes, edid_size, edid);
48+
) !?[]u8 {
49+
var size: usize = 0;
50+
var ptr: ?[*]u8 = null;
51+
switch (self._get_edid(self, handle, attributes, &size, &ptr)) {
52+
.success => {},
53+
.unsupported => return Error.Unsupported,
54+
else => |err| uefi.unexpectedError(err.err()),
55+
}
56+
57+
if (size == 0 or ptr == null)
58+
return null;
59+
60+
return ptr[0..size];
5161
}
5262

5363
pub const guid align(8) = Guid{

0 commit comments

Comments
 (0)