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

Add uefi::system module #1237

Merged
merged 4 commits into from
Jul 15, 2024

Conversation

nicholasbishop
Copy link
Member

@nicholasbishop nicholasbishop commented Jul 9, 2024

This is similar to existing methods of SystemTable, but as freestanding functions that use the global system table pointer.

Splitting this out from #905, the system module provides a good starting point to get a sense of what uefi::{system,boot,runtime} will look like.

#893

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

@phip1611
Copy link
Contributor

Could you please add a usage in the test-runner as well?

@nicholasbishop
Copy link
Member Author

Added tests (one of which required PartialEq on ConfigTableEntry, so I went ahead and added all the usual derives there).

/// # Panics
///
/// Panics if the global system table pointer is null.
pub(crate) fn system_table_raw() -> NonNull<uefi_raw::table::system::SystemTable> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sorry for postponing this further, but I'm unsure regarding the API. Here, we panic and return a NonNull. system_table_boot() and system_table_runtime() below return Options. Is this consistent? Or is it fine to have this difference between internal and public API?

Copy link
Member Author

Choose a reason for hiding this comment

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

No worries, happy to discuss API decisions. I think having both panicking and non-panicking variants is useful, depending on the circumstances. The function that gets the raw system table should essentially never fail -- the panic can only be reached if the table pointer is null, which means the user isn't using the entry macro, or has an unsafe call to set_system_table(null).

In the high-level API, we could (for example) change system::firmware_vendor to return a Result, with an error if the system table is null. But in practice, I think it's likely that users would simply unwrap the result anyway.

If we accept the above argument, that means will have a decent number of places where we want to panic internally if the system table isn't set. And for each of those places we want to use expect with a clear error message rather than unwrap, so if that panic is ever hit it's clear why. And since we don't want to write out .expect("global system table pointer is not set") in multiple places, we end up with this shared function.

I'll also note that I see the system_table_boot and system_table_runtime functions as transitional APIs. Once the system, boot, and runtime modules are in place, I want to mark SystemTable, BootServices, and RuntimeServices as deprecated, and then after a release or two we can remove those deprecated APIs entirely.

Now, with all that said, we might want a non-panicking variant in the future as well (e.g. for functions that already return a Result), so I've pushed a change to rename it to system_table_raw_panicking.

Copy link
Contributor

Choose a reason for hiding this comment

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

But in practice, I think it's likely that users would simply unwrap the result anyway.

Agree

I'll also note that I see the system_table_boot and system_table_runtime functions as transitional API

got it

I want to mark SystemTable, BootServices, and RuntimeServices as deprecated, and then after a release or two we can remove those deprecated APIs entirely.

Is there already a todo anywhere for that?


Generally, I think panicking at a core function is perfectly fine. Especially, as this will never fail, if people properly use the #[entry] macro.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there already a todo anywhere for that?

Added a new summary comment here: #893 (comment)

This is `pub(crate)`, not part of the public API currently.
This is similar to existing methods of `SystemTable`, but as freestanding
functions that use the global system table pointer.
@@ -1,5 +1,10 @@
# uefi - [Unreleased]

## Added
- `uefi::system` is a new module that provides freestanding functions for
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: In a follow-up: We might should add a [new api] "tag" for that in the changelog - this might ease consumers to understand what's going on

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, I was thinking maybe just add a short paragraph between # uefi and ## Added .

@phip1611 phip1611 added this pull request to the merge queue Jul 15, 2024
Merged via the queue into rust-osdev:main with commit 7a0a8ee Jul 15, 2024
12 checks passed
@nicholasbishop nicholasbishop deleted the bishop-system-freestanding branch July 15, 2024 15:37
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.

2 participants