diff options
| author | Ayush Singh <ayushsingh1325@gmail.com> | 2023-03-25 14:20:49 +0530 |
|---|---|---|
| committer | Ayush Singh <ayushdevel1325@gmail.com> | 2023-09-22 17:23:33 +0530 |
| commit | 032e3766d54fe1b91ed13ff12652f91354d019cb (patch) | |
| tree | 5c87481f017b31986eaf542d2bd2d4f1bdb14735 /library/std/src/sys/uefi/alloc.rs | |
| parent | 8e56b33d59593a99fdef6f73f0c1a09a012ca907 (diff) | |
| download | rust-032e3766d54fe1b91ed13ff12652f91354d019cb.tar.gz rust-032e3766d54fe1b91ed13ff12652f91354d019cb.zip | |
Handle ExitBootServices
- Make BootServices unavailable if ExitBootServices event is signaled. - Use thread locals for SystemTable and ImageHandle Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
Diffstat (limited to 'library/std/src/sys/uefi/alloc.rs')
| -rw-r--r-- | library/std/src/sys/uefi/alloc.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/library/std/src/sys/uefi/alloc.rs b/library/std/src/sys/uefi/alloc.rs index 54d86d0c8a7..d6eb371033c 100644 --- a/library/std/src/sys/uefi/alloc.rs +++ b/library/std/src/sys/uefi/alloc.rs @@ -8,6 +8,11 @@ const MEMORY_TYPE: u32 = r_efi::efi::LOADER_DATA; #[stable(feature = "alloc_system_type", since = "1.28.0")] unsafe impl GlobalAlloc for System { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + // Return null pointer if boot services are not available + if crate::os::uefi::env::boot_services().is_none() { + 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 _, @@ -18,6 +23,11 @@ unsafe impl GlobalAlloc for System { } unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { + // Do nothing if boot services are not available + if crate::os::uefi::env::boot_services().is_none() { + return; + } + let system_table = match crate::os::uefi::env::try_system_table() { None => handle_alloc_error(layout), Some(x) => x.as_ptr() as *mut _, |
