diff options
| author | Ayush Singh <ayushsingh1325@gmail.com> | 2023-03-27 19:53:53 +0530 |
|---|---|---|
| committer | Ayush Singh <ayushdevel1325@gmail.com> | 2023-09-22 17:23:33 +0530 |
| commit | 5df24d18b6cdb8abcede6b658cf066360a219c12 (patch) | |
| tree | 7a7d7e6484d376a26b2fee4625e9daab3a3a6be2 /library/std/src/sys | |
| parent | 032e3766d54fe1b91ed13ff12652f91354d019cb (diff) | |
| download | rust-5df24d18b6cdb8abcede6b658cf066360a219c12.tar.gz rust-5df24d18b6cdb8abcede6b658cf066360a219c12.zip | |
Add support for building `std::os::uefi` docs
Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
Diffstat (limited to 'library/std/src/sys')
| -rw-r--r-- | library/std/src/sys/uefi/alloc.rs | 15 | ||||
| -rw-r--r-- | library/std/src/sys/uefi/helpers.rs | 11 | ||||
| -rw-r--r-- | library/std/src/sys/uefi/mod.rs | 1 |
3 files changed, 13 insertions, 14 deletions
diff --git a/library/std/src/sys/uefi/alloc.rs b/library/std/src/sys/uefi/alloc.rs index d6eb371033c..789e3cbd81a 100644 --- a/library/std/src/sys/uefi/alloc.rs +++ b/library/std/src/sys/uefi/alloc.rs @@ -1,7 +1,7 @@ //! Global Allocator for UEFI. //! Uses [r-efi-alloc](https://crates.io/crates/r-efi-alloc) -use crate::alloc::{handle_alloc_error, GlobalAlloc, Layout, System}; +use crate::alloc::{GlobalAlloc, Layout, System}; const MEMORY_TYPE: u32 = r_efi::efi::LOADER_DATA; @@ -13,11 +13,8 @@ unsafe impl GlobalAlloc for System { return crate::ptr::null_mut(); } - let system_table = match crate::os::uefi::env::try_system_table() { - None => return crate::ptr::null_mut(), - Some(x) => x.as_ptr() as *mut _, - }; - + // If boot services is valid then SystemTable is not null. + let system_table = crate::os::uefi::env::system_table().as_ptr().cast(); // The caller must ensure non-0 layout unsafe { r_efi_alloc::raw::alloc(system_table, layout, MEMORY_TYPE) } } @@ -28,10 +25,8 @@ unsafe impl GlobalAlloc for System { return; } - let system_table = match crate::os::uefi::env::try_system_table() { - None => handle_alloc_error(layout), - Some(x) => x.as_ptr() as *mut _, - }; + // If boot services is valid then SystemTable is not null. + let system_table = crate::os::uefi::env::system_table().as_ptr().cast(); // The caller must ensure non-0 layout unsafe { r_efi_alloc::raw::dealloc(system_table, ptr, layout) } } diff --git a/library/std/src/sys/uefi/helpers.rs b/library/std/src/sys/uefi/helpers.rs index 28a82394226..2108484a40c 100644 --- a/library/std/src/sys/uefi/helpers.rs +++ b/library/std/src/sys/uefi/helpers.rs @@ -46,7 +46,7 @@ pub(crate) fn locate_handles(mut guid: Guid) -> io::Result<Vec<NonNull<crate::ff if r.is_error() { Err(status_to_io_error(r)) } else { Ok(()) } } - let boot_services = boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?; + let boot_services = boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?.cast(); let mut buf_len = 0usize; // This should always fail since the size of buffer is 0. This call should update the buf_len @@ -82,7 +82,8 @@ pub(crate) fn open_protocol<T>( handle: NonNull<crate::ffi::c_void>, mut protocol_guid: Guid, ) -> io::Result<NonNull<T>> { - let boot_services = boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?; + let boot_services: NonNull<efi::BootServices> = + boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?.cast(); let system_handle = uefi::env::image_handle(); let mut protocol: MaybeUninit<*mut T> = MaybeUninit::uninit(); @@ -279,7 +280,8 @@ pub(crate) fn create_event( handler: Option<efi::EventNotify>, context: *mut crate::ffi::c_void, ) -> io::Result<NonNull<crate::ffi::c_void>> { - let boot_services = boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?; + let boot_services: NonNull<efi::BootServices> = + boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?.cast(); let mut exit_boot_service_event: r_efi::efi::Event = crate::ptr::null_mut(); let r = unsafe { let create_event = (*boot_services.as_ptr()).create_event; @@ -294,7 +296,8 @@ pub(crate) fn create_event( } pub(crate) fn close_event(evt: NonNull<crate::ffi::c_void>) -> io::Result<()> { - let boot_services = boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?; + let boot_services: NonNull<efi::BootServices> = + boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?.cast(); let r = unsafe { let close_event = (*boot_services.as_ptr()).close_event; (close_event)(evt.as_ptr()) diff --git a/library/std/src/sys/uefi/mod.rs b/library/std/src/sys/uefi/mod.rs index fa33b681a19..6fd2c5f21cb 100644 --- a/library/std/src/sys/uefi/mod.rs +++ b/library/std/src/sys/uefi/mod.rs @@ -129,6 +129,7 @@ pub fn abort_internal() -> ! { if let (Some(boot_services), Some(handle)) = (uefi::env::boot_services(), uefi::env::try_image_handle()) { + let boot_services: NonNull<r_efi::efi::BootServices> = boot_services.cast(); let _ = unsafe { ((*boot_services.as_ptr()).exit)( handle.as_ptr(), |
