@@ -12,7 +12,8 @@ use crate::table::boot::{
12
12
AllocateType , BootServices , EventNotifyFn , EventType , LoadImageSource , MemoryMap , MemoryType ,
13
13
OpenProtocolAttributes , OpenProtocolParams , SearchType , TimerTrigger , Tpl , IMAGE_HANDLE ,
14
14
} ;
15
- use crate :: { system, Char16 , Error , Event , Guid , Handle , Result , Status , StatusExt } ;
15
+ use crate :: table:: { Boot , SystemTable } ;
16
+ use crate :: { table, Char16 , Error , Event , Guid , Handle , Result , Status , StatusExt } ;
16
17
use core:: ffi:: c_void;
17
18
use core:: mem:: MaybeUninit ;
18
19
use core:: ops:: { Deref , DerefMut } ;
@@ -21,14 +22,21 @@ use core::slice;
21
22
use core:: sync:: atomic:: Ordering ;
22
23
23
24
// TODO
25
+ fn boot_services ( ) -> NonNull < BootServices > {
26
+ let st = table:: system_table_boot ( ) . expect ( "boot services are not active" ) ;
27
+ let ptr: * const _ = st. boot_services ( ) ;
28
+ NonNull :: new ( ptr. cast_mut ( ) ) . unwrap ( )
29
+ }
30
+
24
31
fn boot_services_raw ( ) -> NonNull < uefi_raw:: table:: boot:: BootServices > {
25
- let st = unsafe { system:: system_table ( ) . as_mut ( ) } ;
26
- NonNull :: new ( st. boot_services ) . expect ( "boot services are not active" )
32
+ // OK to cast: `BootServices` is a `repr(transparent)` wrapper around
33
+ // the raw type.
34
+ boot_services ( ) . cast ( )
27
35
}
28
36
29
- fn boot_services ( ) -> NonNull < BootServices > {
30
- let st = unsafe { system :: system_table ( ) . as_mut ( ) } ;
31
- NonNull :: new ( st . boot_services . cast ( ) ) . expect ( "boot services are not active " )
37
+ # [ track_caller ]
38
+ fn stboot ( ) -> SystemTable < Boot > {
39
+ table :: system_table_boot ( ) . expect ( "boot services are not available " )
32
40
}
33
41
34
42
/// Get the [`Handle`] of the currently-executing image.
@@ -74,7 +82,7 @@ pub fn allocate_pages(
74
82
mem_ty : MemoryType ,
75
83
count : usize ,
76
84
) -> Result < PhysicalAddress > {
77
- unsafe { boot_services ( ) . as_mut ( ) } . allocate_pages ( ty, mem_ty, count)
85
+ stboot ( ) . boot_services ( ) . allocate_pages ( ty, mem_ty, count)
78
86
}
79
87
80
88
/// Frees memory pages allocated by UEFI.
@@ -86,7 +94,7 @@ pub fn allocate_pages(
86
94
/// * [`uefi::Status::NOT_FOUND`]
87
95
/// * [`uefi::Status::INVALID_PARAMETER`]
88
96
pub unsafe fn free_pages ( addr : PhysicalAddress , count : usize ) -> Result {
89
- unsafe { boot_services ( ) . as_mut ( ) } . free_pages ( addr, count)
97
+ stboot ( ) . boot_services ( ) . free_pages ( addr, count)
90
98
}
91
99
92
100
/// Raises a task's priority level and returns its previous level.
@@ -130,7 +138,7 @@ pub unsafe fn raise_tpl(tpl: Tpl) -> TplGuard {
130
138
/// * [`uefi::Status::BUFFER_TOO_SMALL`]
131
139
/// * [`uefi::Status::INVALID_PARAMETER`]
132
140
pub fn memory_map ( mt : MemoryType ) -> Result < MemoryMap > {
133
- unsafe { boot_services ( ) . as_mut ( ) } . memory_map ( mt)
141
+ stboot ( ) . boot_services ( ) . memory_map ( mt)
134
142
}
135
143
136
144
/// Allocates from a memory pool. The pointer will be 8-byte aligned.
@@ -142,7 +150,7 @@ pub fn memory_map(mt: MemoryType) -> Result<MemoryMap> {
142
150
/// * [`uefi::Status::OUT_OF_RESOURCES`]
143
151
/// * [`uefi::Status::INVALID_PARAMETER`]
144
152
pub fn allocate_pool ( mem_ty : MemoryType , size : usize ) -> Result < NonNull < u8 > > {
145
- unsafe { boot_services ( ) . as_mut ( ) } . allocate_pool ( mem_ty, size)
153
+ stboot ( ) . boot_services ( ) . allocate_pool ( mem_ty, size)
146
154
}
147
155
148
156
/// Frees memory allocated from a pool.
@@ -154,7 +162,7 @@ pub fn allocate_pool(mem_ty: MemoryType, size: usize) -> Result<NonNull<u8>> {
154
162
/// * [`uefi::Status::INVALID_PARAMETER`]
155
163
#[ allow( clippy:: not_unsafe_ptr_arg_deref) ]
156
164
pub unsafe fn free_pool ( addr : * mut u8 ) -> Result {
157
- unsafe { boot_services ( ) . as_mut ( ) } . free_pool ( addr)
165
+ stboot ( ) . boot_services ( ) . free_pool ( addr)
158
166
}
159
167
160
168
/// Creates an event
@@ -185,7 +193,9 @@ pub unsafe fn create_event(
185
193
notify_fn : Option < EventNotifyFn > ,
186
194
notify_ctx : Option < NonNull < c_void > > ,
187
195
) -> Result < Event > {
188
- unsafe { boot_services ( ) . as_mut ( ) } . create_event ( event_ty, notify_tpl, notify_fn, notify_ctx)
196
+ stboot ( )
197
+ . boot_services ( )
198
+ . create_event ( event_ty, notify_tpl, notify_fn, notify_ctx)
189
199
}
190
200
191
201
/// Creates a new `Event` of type `event_type`. The event's notification function, context,
@@ -234,7 +244,7 @@ pub unsafe fn create_event_ex(
234
244
notify_ctx : Option < NonNull < c_void > > ,
235
245
event_group : Option < NonNull < Guid > > ,
236
246
) -> Result < Event > {
237
- unsafe { boot_services ( ) . as_mut ( ) } . create_event_ex (
247
+ stboot ( ) . boot_services ( ) . create_event_ex (
238
248
event_type,
239
249
notify_tpl,
240
250
notify_fn,
@@ -251,7 +261,7 @@ pub unsafe fn create_event_ex(
251
261
///
252
262
/// * [`uefi::Status::INVALID_PARAMETER`]
253
263
pub fn set_timer ( event : & Event , trigger_time : TimerTrigger ) -> Result {
254
- unsafe { boot_services ( ) . as_mut ( ) } . set_timer ( event, trigger_time)
264
+ stboot ( ) . boot_services ( ) . set_timer ( event, trigger_time)
255
265
}
256
266
257
267
/// Stops execution until an event is signaled.
@@ -289,7 +299,7 @@ pub fn set_timer(event: &Event, trigger_time: TimerTrigger) -> Result {
289
299
/// * [`uefi::Status::INVALID_PARAMETER`]
290
300
/// * [`uefi::Status::UNSUPPORTED`]
291
301
pub fn wait_for_event ( events : & mut [ Event ] ) -> Result < usize , Option < usize > > {
292
- unsafe { boot_services ( ) . as_mut ( ) } . wait_for_event ( events)
302
+ stboot ( ) . boot_services ( ) . wait_for_event ( events)
293
303
}
294
304
295
305
/// Place 'event' in the signaled stated. If 'event' is already in the signaled state,
@@ -311,7 +321,7 @@ pub fn wait_for_event(events: &mut [Event]) -> Result<usize, Option<usize>> {
311
321
///
312
322
/// Currently, (as of UEFI Spec v2.9) this only returns `EFI_SUCCESS`.
313
323
pub fn signal_event ( event : & Event ) -> Result {
314
- unsafe { boot_services ( ) . as_mut ( ) } . signal_event ( event)
324
+ stboot ( ) . boot_services ( ) . signal_event ( event)
315
325
}
316
326
317
327
/// Removes `event` from any event group to which it belongs and closes it. If `event` was
@@ -328,7 +338,7 @@ pub fn signal_event(event: &Event) -> Result {
328
338
///
329
339
/// * [`uefi::Status::INVALID_PARAMETER`]
330
340
pub fn close_event ( event : Event ) -> Result {
331
- unsafe { boot_services ( ) . as_mut ( ) } . close_event ( event)
341
+ stboot ( ) . boot_services ( ) . close_event ( event)
332
342
}
333
343
334
344
/// Checks to see if an event is signaled, without blocking execution to wait for it.
@@ -345,7 +355,7 @@ pub fn close_event(event: Event) -> Result {
345
355
///
346
356
/// * [`uefi::Status::INVALID_PARAMETER`]
347
357
pub fn check_event ( event : Event ) -> Result < bool > {
348
- unsafe { boot_services ( ) . as_mut ( ) } . check_event ( event)
358
+ stboot ( ) . boot_services ( ) . check_event ( event)
349
359
}
350
360
351
361
/// Installs a protocol interface on a device handle. If the inner `Option` in `handle` is `None`,
@@ -370,7 +380,9 @@ pub unsafe fn install_protocol_interface(
370
380
protocol : & Guid ,
371
381
interface : * mut c_void ,
372
382
) -> Result < Handle > {
373
- unsafe { boot_services ( ) . as_mut ( ) } . install_protocol_interface ( handle, protocol, interface)
383
+ stboot ( )
384
+ . boot_services ( )
385
+ . install_protocol_interface ( handle, protocol, interface)
374
386
}
375
387
376
388
/// Reinstalls a protocol interface on a device handle. `old_interface` is replaced with `new_interface`.
@@ -398,7 +410,7 @@ pub unsafe fn reinstall_protocol_interface(
398
410
old_interface : * mut c_void ,
399
411
new_interface : * mut c_void ,
400
412
) -> Result < ( ) > {
401
- unsafe { boot_services ( ) . as_mut ( ) } . reinstall_protocol_interface (
413
+ stboot ( ) . boot_services ( ) . reinstall_protocol_interface (
402
414
handle,
403
415
protocol,
404
416
old_interface,
@@ -430,7 +442,9 @@ pub unsafe fn uninstall_protocol_interface(
430
442
protocol : & Guid ,
431
443
interface : * mut c_void ,
432
444
) -> Result < ( ) > {
433
- unsafe { boot_services ( ) . as_mut ( ) } . uninstall_protocol_interface ( handle, protocol, interface)
445
+ stboot ( )
446
+ . boot_services ( )
447
+ . uninstall_protocol_interface ( handle, protocol, interface)
434
448
}
435
449
436
450
/// Registers `event` to be signalled whenever a protocol interface is registered for
@@ -450,7 +464,9 @@ pub unsafe fn uninstall_protocol_interface(
450
464
/// * [`uefi::Status::OUT_OF_RESOURCES`]
451
465
/// * [`uefi::Status::INVALID_PARAMETER`]
452
466
pub fn register_protocol_notify ( protocol : & Guid , event : Event ) -> Result < ( Event , SearchType ) > {
453
- unsafe { boot_services ( ) . as_mut ( ) } . register_protocol_notify ( protocol, event)
467
+ stboot ( )
468
+ . boot_services ( )
469
+ . register_protocol_notify ( protocol, event)
454
470
}
455
471
456
472
/// Enumerates all handles installed on the system which match a certain query.
@@ -471,7 +487,7 @@ pub fn locate_handle(
471
487
search_ty : SearchType ,
472
488
output : Option < & mut [ MaybeUninit < Handle > ] > ,
473
489
) -> Result < usize > {
474
- unsafe { boot_services ( ) . as_mut ( ) } . locate_handle ( search_ty, output)
490
+ stboot ( ) . boot_services ( ) . locate_handle ( search_ty, output)
475
491
}
476
492
477
493
/// Locates the handle to a device on the device path that supports the specified protocol.
@@ -494,7 +510,9 @@ pub fn locate_handle(
494
510
pub fn locate_device_path < P : ProtocolPointer + ?Sized > (
495
511
device_path : & mut & DevicePath ,
496
512
) -> Result < Handle > {
497
- unsafe { boot_services ( ) . as_mut ( ) } . locate_device_path :: < P > ( device_path)
513
+ stboot ( )
514
+ . boot_services ( )
515
+ . locate_device_path :: < P > ( device_path)
498
516
}
499
517
500
518
/// Find an arbitrary handle that supports a particular
@@ -533,7 +551,7 @@ pub fn locate_device_path<P: ProtocolPointer + ?Sized>(
533
551
///
534
552
/// Returns [`NOT_FOUND`] if no handles support the requested protocol.
535
553
pub fn get_handle_for_protocol < P : ProtocolPointer + ?Sized > ( ) -> Result < Handle > {
536
- unsafe { boot_services ( ) . as_mut ( ) } . get_handle_for_protocol :: < P > ( )
554
+ stboot ( ) . boot_services ( ) . get_handle_for_protocol :: < P > ( )
537
555
}
538
556
539
557
/// Load an EFI image into memory and return a [`Handle`] to the image.
@@ -569,7 +587,9 @@ pub fn get_handle_for_protocol<P: ProtocolPointer + ?Sized>() -> Result<Handle>
569
587
/// * [`uefi::Status::ACCESS_DENIED`]
570
588
/// * [`uefi::Status::SECURITY_VIOLATION`]
571
589
pub fn load_image ( parent_image_handle : Handle , source : LoadImageSource ) -> uefi:: Result < Handle > {
572
- unsafe { boot_services ( ) . as_mut ( ) } . load_image ( parent_image_handle, source)
590
+ stboot ( )
591
+ . boot_services ( )
592
+ . load_image ( parent_image_handle, source)
573
593
}
574
594
575
595
/// Unload an EFI image.
@@ -586,7 +606,7 @@ pub fn load_image(parent_image_handle: Handle, source: LoadImageSource) -> uefi:
586
606
/// * [`uefi::Status::UNSUPPORTED`]
587
607
/// * [`uefi::Status::INVALID_PARAMETER`]
588
608
pub fn unload_image ( image_handle : Handle ) -> Result {
589
- unsafe { boot_services ( ) . as_mut ( ) } . unload_image ( image_handle)
609
+ stboot ( ) . boot_services ( ) . unload_image ( image_handle)
590
610
}
591
611
592
612
/// Transfer control to a loaded image's entry point.
@@ -602,7 +622,7 @@ pub fn unload_image(image_handle: Handle) -> Result {
602
622
///
603
623
/// * [`uefi::Status::UNSUPPORTED`]
604
624
pub fn start_image ( image_handle : Handle ) -> Result {
605
- unsafe { boot_services ( ) . as_mut ( ) } . start_image ( image_handle)
625
+ stboot ( ) . boot_services ( ) . start_image ( image_handle)
606
626
}
607
627
608
628
/// Exits the UEFI application and returns control to the UEFI component
@@ -620,12 +640,9 @@ pub unsafe fn exit(
620
640
exit_data_size : usize ,
621
641
exit_data : * mut Char16 ,
622
642
) -> ! {
623
- unsafe { boot_services ( ) . as_mut ( ) } . exit (
624
- image_handle,
625
- exit_status,
626
- exit_data_size,
627
- exit_data. cast ( ) ,
628
- )
643
+ stboot ( )
644
+ . boot_services ( )
645
+ . exit ( image_handle, exit_status, exit_data_size, exit_data. cast ( ) )
629
646
}
630
647
631
648
/// Exit the UEFI boot services.
@@ -657,7 +674,8 @@ pub unsafe fn exit(
657
674
/// caller, the system will be reset.
658
675
#[ must_use]
659
676
pub unsafe fn exit_boot_services ( memory_type : MemoryType ) -> MemoryMap {
660
- system:: system_table_boot ( )
677
+ table:: system_table_boot ( )
678
+ . expect ( "boot services are not active" )
661
679
. exit_boot_services ( memory_type)
662
680
. 1
663
681
}
@@ -666,7 +684,7 @@ pub unsafe fn exit_boot_services(memory_type: MemoryType) -> MemoryMap {
666
684
///
667
685
/// The time is in microseconds.
668
686
pub fn stall ( time : usize ) {
669
- unsafe { boot_services ( ) . as_mut ( ) } . stall ( time)
687
+ stboot ( ) . boot_services ( ) . stall ( time)
670
688
}
671
689
672
690
/// Adds, updates, or removes a configuration table entry
@@ -690,7 +708,9 @@ pub fn stall(time: usize) {
690
708
/// * [`uefi::Status::NOT_FOUND`]
691
709
/// * [`uefi::Status::OUT_OF_RESOURCES`]
692
710
pub unsafe fn install_configuration_table ( guid_entry : & Guid , table_ptr : * const c_void ) -> Result {
693
- unsafe { boot_services ( ) . as_mut ( ) } . install_configuration_table ( guid_entry, table_ptr)
711
+ stboot ( )
712
+ . boot_services ( )
713
+ . install_configuration_table ( guid_entry, table_ptr)
694
714
}
695
715
696
716
/// Set the watchdog timer.
@@ -720,7 +740,9 @@ pub unsafe fn install_configuration_table(guid_entry: &Guid, table_ptr: *const c
720
740
/// * [`uefi::Status::UNSUPPORTED`]
721
741
/// * [`uefi::Status::DEVICE_ERROR`]
722
742
pub fn set_watchdog_timer ( timeout : usize , watchdog_code : u64 , data : Option < & mut [ u16 ] > ) -> Result {
723
- unsafe { boot_services ( ) . as_mut ( ) } . set_watchdog_timer ( timeout, watchdog_code, data)
743
+ stboot ( )
744
+ . boot_services ( )
745
+ . set_watchdog_timer ( timeout, watchdog_code, data)
724
746
}
725
747
726
748
/// Connect one or more drivers to a controller.
@@ -742,7 +764,7 @@ pub fn connect_controller(
742
764
remaining_device_path : Option < & DevicePath > ,
743
765
recursive : bool ,
744
766
) -> Result {
745
- unsafe { boot_services ( ) . as_mut ( ) } . connect_controller (
767
+ stboot ( ) . boot_services ( ) . connect_controller (
746
768
controller,
747
769
driver_image,
748
770
remaining_device_path,
@@ -766,7 +788,9 @@ pub fn disconnect_controller(
766
788
driver_image : Option < Handle > ,
767
789
child : Option < Handle > ,
768
790
) -> Result {
769
- unsafe { boot_services ( ) . as_mut ( ) } . disconnect_controller ( controller, driver_image, child)
791
+ stboot ( )
792
+ . boot_services ( )
793
+ . disconnect_controller ( controller, driver_image, child)
770
794
}
771
795
772
796
/// Open a protocol interface for a handle.
@@ -880,7 +904,7 @@ pub fn open_protocol_exclusive<P: ProtocolPointer + ?Sized>(
880
904
/// * [`uefi::Status::ACCESS_DENIED`]
881
905
/// * [`uefi::Status::ALREADY_STARTED`]
882
906
pub fn test_protocol < P : ProtocolPointer + ?Sized > ( params : OpenProtocolParams ) -> Result < ( ) > {
883
- unsafe { boot_services ( ) . as_mut ( ) } . test_protocol :: < P > ( params)
907
+ stboot ( ) . boot_services ( ) . test_protocol :: < P > ( params)
884
908
}
885
909
886
910
/// Get the list of protocol interface [`Guids`][Guid] that are installed
0 commit comments