8000 Clean up duplicate global system table pointer in `uefi::helpers` by nicholasbishop · Pull Request #1188 · rust-osdev/uefi-rs · GitHub
[go: up one dir, main page]

Skip to content

Clean up duplicate global system table pointer in uefi::helpers #1188

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

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
uefi: Remove panics from system_table_boot/system_table_runtime
These functions now return an `Option`.
  • Loading branch information
nicholasbishop committed Jun 11, 2024
commit c649727402f669f0b3b5bb6f1ec800df364ea34c
37 changes: 14 additions & 23 deletions uefi/src/table/mod.rs
< 8000 td id="diff-e7586ebbd461417b3df4ab910e1cb0fcb258fa8294aa57493f22f2d4301e2fcbR35" data-line-number="35" class="blob-num blob-num-context js-linkable-line-number js-blob-rnum">
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,36 @@ pub unsafe fn set_system_table(ptr: *const uefi_raw::table::system::SystemTable)
}

/// Get the system table while boot services are active.
///
/// # Panics
///
/// Panics if the system table has not been set with `set_system_table`, or if
/// boot services are not available (e.g. if [`exit_boot_services`] has been
/// called).
///
/// [`exit_boot_services`]: SystemTable::exit_boot_services
pub fn system_table_boot() -> SystemTable<Boot> {
pub fn system_table_boot() -> Option<SystemTable<Boot>> {
let st = SYSTEM_TABLE.load(Ordering::Acquire);
assert!(!st.is_null());
if st.is_null() {
return None;
}

// SAFETY: the system table is valid per the requirements of `set_system_table`.
unsafe {
if (*st).boot_services.is_null() {
panic!("boot services are not active");
None
} else {
Some(SystemTable::<Boot>::from_ptr(st.cast()).unwrap())
}

SystemTable::<Boot>::from_ptr(st.cast()).unwrap()
}
}

/// Get the system table while runtime services are active.
///
/// # Panics
///
/// Panics if the system table has not been set with `set_system_table`, or if
/// runtime services are not available.
pub fn system_table_runtime() -> SystemTable<Runtime> {
pub fn system_table_runtime() -> Option<SystemTable<Runtime>> {
let st = SYSTEM_TABLE.load(Ordering::Acquire);
assert!(!st.is_null());
if st.is_null() {
return None;
}

// SAFETY: the system table is valid per the requirements of `set_system_table`.
unsafe {
if (*st).runtime_services.is_null() {
panic!("runtime services are not active");
None
} else {
Some(SystemTable::<Runtime>::from_ptr(st.cast()).unwrap())
}

SystemTable::<Runtime>::from_ptr(st.cast()).unwrap()
}
}

Expand Down
0