@@ -19,13 +19,8 @@ use core::fmt::Debug;
19
19
use core:: mem:: { self , MaybeUninit } ;
20
20
use core:: ops:: { Deref , DerefMut } ;
21
21
use core:: ptr:: NonNull ;
22
- use core:: sync:: atomic:: { AtomicPtr , Ordering } ;
23
22
use core:: { ptr, slice} ;
24
23
25
- /// Global image handle. This is only set by `BootServices::set_image_handle`,
26
- /// and it is only read by `BootServices::image_handle`.
27
- static IMAGE_HANDLE : AtomicPtr < c_void > = AtomicPtr :: new ( ptr:: null_mut ( ) ) ;
28
-
29
24
/// Size in bytes of a UEFI page.
30
25
///
31
26
/// Note that this is not necessarily the processor's page size. The UEFI page
@@ -84,32 +79,21 @@ pub struct BootServices(uefi_raw::table::boot::BootServices);
84
79
85
80
impl BootServices {
86
81
/// Get the [`Handle`] of the currently-executing image.
82
+ #[ must_use]
87
83
pub fn image_handle ( & self ) -> Handle {
88
- let ptr = IMAGE_HANDLE . load ( Ordering :: Acquire ) ;
89
- // Safety: the image handle must be valid. We know it is, because it was
90
- // set by `set_image_handle`, which has that same safety requirement.
91
- unsafe { Handle :: from_ptr ( ptr) } . expect ( "set_image_handle has not been called" )
84
+ uefi:: boot:: image_handle ( )
92
85
}
93
86
94
87
/// Update the global image [`Handle`].
95
88
///
96
- /// This is called automatically in the `main` entry point as part
97
- /// of [`uefi::entry`]. It should not be called at any other
98
- /// point in time, unless the executable does not use
99
- /// [`uefi::entry`], in which case it should be called once
100
- /// before calling other `BootServices` functions.
89
+ /// This is the same as calling [`uefi::boot::set_image_handle`]. See that
90
+ /// function for details.
101
91
///
102
92
/// # Safety
103
93
///
104
- /// This function should only be called as described above,
105
- /// and the `image_handle` must be a valid image [`Handle`]. Then
106
- /// safety guarantees of [`BootServices::open_protocol_exclusive`]
107
- /// rely on the global image handle being correct.
94
+ /// See [`uefi::boot::set_image_handle`] for safety requirements.
108
95
pub unsafe fn set_image_handle ( & self , image_handle : Handle ) {
109
- // As with `image_handle`, `&self` isn't actually used, but it
110
- // enforces that this function is only called while boot
111
- // services are active.
112
- IMAGE_HANDLE . store ( image_handle. as_ptr ( ) , Ordering :: Release ) ;
96
+ uefi:: boot:: set_image_handle ( image_handle)
113
97
}
114
98
115
99
/// Raises a task's priority level and returns its previous level.
0 commit comments