Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std/os/uefi: additional improvements/fixes #10604

Merged
merged 14 commits into from Feb 18, 2022
Merged

Conversation

fifty-six
Copy link
Contributor

No description provided.

`uefi/protocols.zig` and `uefi/tables.zig` just re-exported all the
public symbols, which is basically the purpose of `usingnamespace`
import-wise.
Writes the panic message to stderr as well as passing it to
boot_services.exit when boot_services is available.
Uses comptime loops over the types instead of writing out a large
switch.
Beyond adding default zero-initialization, this commit changes undefined
initialization to zero, as some cases reserved the padding and on other
cases, I've found some systems act strange when giving uninit instead of
zero even when it shouldn't be an issue, one example being
FileProtocol.Open's attributes, which *should* be ignored when not
creating a file, but ended up giving an unrelated error.
This makes the struct align(4), which allows it to be passed as flags
more easily.
Allows handling uefi function errors in a more zig-style way with try
and catch, using `try f().err()` when a `Status` is returned.
Copy link
Member

@Vexu Vexu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked that the changes you made to padding don't affect the structs? Packed structs are still a bit buggy at the moment.

@fifty-six
Copy link
Contributor Author

fifty-six commented Feb 13, 2022

Yeah, I used zig test with this:

fn test_types(comptime TPrev: type, comptime TPost: type) void {
    var a = std.mem.zeroes(TPrev);
    var b = std.mem.zeroes(TPost);

    inline for (@typeInfo(TPost).Struct.fields) |field| {
        assert(@bitOffsetOf(TPrev, field.name) == @bitOffsetOf(TPost, field.name));
        assert(@offsetOf(TPrev, field.name) == @offsetOf(TPost, field.name));
    }

    assert(@sizeOf(TPrev) == @sizeOf(TPost));
    assert(@alignOf(@TypeOf(&a)) == @alignOf(@TypeOf(&b)));
}

test "align" {
    test_types(Time, Time2);
    test_types(AbsolutePointerMode, AbsolutePointerMode2);
    test_types(AbsolutePointerState, AbsolutePointerState2);
    test_types(EdidOverrideProtocolAttributes, EdidOverrideProtocolAttributes2);
    test_types(SimpleNetworkReceiveFilter, SimpleNetworkReceiveFilter2);
    test_types(SimpleNetworkInterruptStatus, SimpleNetworkInterruptStatus2);
    test_types(OpenProtocolAttributes, OpenProtocolAttributes2);

    var a = std.mem.zeroes(AbsolutePointerMode);
    var a2 = std.mem.zeroes(AbsolutePointerMode2);

    var b = std.mem.zeroes(AbsolutePointerState);
    var b2 = std.mem.zeroes(AbsolutePointerState2);

    test_types(@TypeOf(a.attributes), @TypeOf(a2.attributes));
    test_types(@TypeOf(b.active_buttons), @TypeOf(b2.active_buttons));
}

For the tests I changed _pad on the simplified versions to _pad1 so that it would check the offset against the old start of the padding.

@andrewrk andrewrk merged commit 2c24bf2 into ziglang:master Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants