@@ -19,13 +19,8 @@ use core::fmt::Debug;
1919use core:: mem:: { self , MaybeUninit } ;
2020use core:: ops:: { Deref , DerefMut } ;
2121use core:: ptr:: NonNull ;
22- use core:: sync:: atomic:: { AtomicPtr , Ordering } ;
2322use core:: { ptr, slice} ;
2423
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-
2924/// Size in bytes of a UEFI page.
3025///
3126/// Note that this is not necessarily the processor's page size. The UEFI page
@@ -85,31 +80,19 @@ pub struct BootServices(uefi_raw::table::boot::BootServices);
8580impl BootServices {
8681 /// Get the [`Handle`] of the currently-executing image.
8782 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" )
83+ uefi:: boot:: image_handle ( )
9284 }
9385
9486 /// Update the global image [`Handle`].
9587 ///
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.
88+ /// This is the same as calling [`uefi::boot::set_image_handle`]. See that
89+ /// function for details.
10190 ///
10291 /// # Safety
10392 ///
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.
93+ /// See [`uefi::boot::set_image_handle`] for safety requirements.
10894 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 ) ;
95+ uefi:: boot:: set_image_handle ( image_handle)
11396 }
11497
11598 /// Raises a task's priority level and returns its previous level.
0 commit comments