@@ -8,11 +8,6 @@ use crate::os::uefi;
8
8
use crate :: os:: uefi:: ffi:: { OsStrExt , OsStringExt } ;
9
9
use crate :: ptr:: NonNull ;
10
10
11
- pub ( crate ) const BOOT_SERVICES_ERROR : io:: Error =
12
- const_io_error ! ( io:: ErrorKind :: Other , "failed to acquire boot services" , ) ;
13
- pub ( crate ) const RUNTIME_SERVICES_ERROR : io:: Error =
14
- const_io_error ! ( io:: ErrorKind :: Other , "failed to acquire runtime services" , ) ;
15
-
16
11
/// Get the Protocol for current system handle.
17
12
/// Note: Some protocols need to be manually freed. It is the callers responsibility to do so.
18
13
pub ( crate ) fn get_current_handle_protocol < T > ( protocol_guid : Guid ) -> Option < NonNull < T > > {
@@ -42,7 +37,7 @@ impl Event {
42
37
notify_function : Option < EventNotify > ,
43
38
notify_context : Option < NonNull < crate :: ffi:: c_void > > ,
44
39
) -> io:: Result < Self > {
45
- let boot_services = get_boot_services ( ) . ok_or ( BOOT_SERVICES_ERROR ) ? ;
40
+ let boot_services = boot_services ( ) ;
46
41
47
42
let mut event: r_efi:: efi:: Event = crate :: ptr:: null_mut ( ) ;
48
43
let notify_context = match notify_context {
@@ -69,7 +64,7 @@ impl Event {
69
64
}
70
65
71
66
pub ( crate ) fn wait ( & self ) -> io:: Result < ( ) > {
72
- let boot_services = get_boot_services ( ) . ok_or ( BOOT_SERVICES_ERROR ) ? ;
67
+ let boot_services = boot_services ( ) ;
73
68
74
69
let mut index = 0usize ;
75
70
let r = unsafe {
@@ -91,10 +86,9 @@ impl Event {
91
86
92
87
impl Drop for Event {
93
88
fn drop ( & mut self ) {
94
- if let Some ( boot_services) = get_boot_services ( ) {
95
- // Always returns EFI_SUCCESS
96
- let _ = unsafe { ( ( * boot_services. as_ptr ( ) ) . close_event ) ( self . inner . as_ptr ( ) ) } ;
97
- }
89
+ let boot_services = boot_services ( ) ;
90
+ // Always returns EFI_SUCCESS
91
+ let _ = unsafe { ( ( * boot_services. as_ptr ( ) ) . close_event ) ( self . inner . as_ptr ( ) ) } ;
98
92
}
99
93
}
100
94
@@ -203,7 +197,7 @@ pub(crate) fn locate_handles(mut guid: Guid) -> io::Result<Vec<NonNull<crate::ff
203
197
if r. is_error ( ) { Err ( status_to_io_error ( r) ) } else { Ok ( ( ) ) }
204
198
}
205
199
206
- let boot_services = get_boot_services ( ) . ok_or ( BOOT_SERVICES_ERROR ) ? ;
200
+ let boot_services = boot_services ( ) ;
207
201
let mut buf_len = 0usize ;
208
202
209
203
match inner ( & mut guid, boot_services, & mut buf_len, crate :: ptr:: null_mut ( ) ) {
@@ -235,7 +229,7 @@ pub(crate) fn open_protocol<T>(
235
229
handle : NonNull < crate :: ffi:: c_void > ,
236
230
mut protocol_guid : Guid ,
237
231
) -> io:: Result < NonNull < T > > {
238
- let boot_services = get_boot_services ( ) . ok_or ( BOOT_SERVICES_ERROR ) ? ;
232
+ let boot_services = boot_services ( ) ;
239
233
let system_handle = uefi:: env:: image_handle ( ) ;
240
234
let mut protocol: MaybeUninit < * mut T > = MaybeUninit :: uninit ( ) ;
241
235
@@ -376,7 +370,7 @@ pub(crate) fn install_protocol<T>(
376
370
mut guid : r_efi:: efi:: Guid ,
377
371
interface : & mut T ,
378
372
) -> io:: Result < ( ) > {
379
- let boot_services = get_boot_services ( ) . ok_or ( BOOT_SERVICES_ERROR ) ? ;
373
+ let boot_services = boot_services ( ) ;
380
374
let r = unsafe {
381
375
( ( * boot_services. as_ptr ( ) ) . install_protocol_interface ) (
382
376
handle,
@@ -393,7 +387,7 @@ pub(crate) fn uninstall_protocol<T>(
393
387
mut guid : r_efi:: efi:: Guid ,
394
388
interface : & mut T ,
395
389
) -> io:: Result < ( ) > {
396
- let boot_services = get_boot_services ( ) . ok_or ( BOOT_SERVICES_ERROR ) ? ;
390
+ let boot_services = boot_services ( ) ;
397
391
let r = unsafe {
398
392
( ( * boot_services. as_ptr ( ) ) . uninstall_protocol_interface ) (
399
393
handle,
@@ -464,17 +458,24 @@ where
464
458
}
465
459
466
460
/// Get the BootServices Pointer.
467
- pub ( crate ) fn get_boot_services ( ) -> Option < NonNull < r_efi:: efi:: BootServices > > {
461
+ pub ( crate ) fn boot_services ( ) -> NonNull < r_efi:: efi:: BootServices > {
468
462
let system_table: NonNull < r_efi:: efi:: SystemTable > = uefi:: env:: system_table ( ) . cast ( ) ;
469
463
let boot_services = unsafe { ( * system_table. as_ptr ( ) ) . boot_services } ;
464
+ NonNull :: new ( boot_services) . unwrap ( )
465
+ }
466
+ /// Get the BootServices Pointer.
467
+ /// This function is mostly intended for places where panic is not an option
468
+ pub ( crate ) fn try_boot_services ( ) -> Option < NonNull < r_efi:: efi:: BootServices > > {
469
+ let system_table: NonNull < r_efi:: efi:: SystemTable > = uefi:: env:: try_system_table ( ) ?. cast ( ) ;
470
+ let boot_services = unsafe { ( * system_table. as_ptr ( ) ) . boot_services } ;
470
471
NonNull :: new ( boot_services)
471
472
}
472
473
473
474
/// Get the RuntimeServices Pointer.
474
- pub ( crate ) fn get_runtime_services ( ) -> Option < NonNull < r_efi:: efi:: RuntimeServices > > {
475
+ pub ( crate ) fn runtime_services ( ) -> NonNull < r_efi:: efi:: RuntimeServices > {
475
476
let system_table: NonNull < r_efi:: efi:: SystemTable > = uefi:: env:: system_table ( ) . cast ( ) ;
476
477
let runtime_services = unsafe { ( * system_table. as_ptr ( ) ) . runtime_services } ;
477
- NonNull :: new ( runtime_services)
478
+ NonNull :: new ( runtime_services) . unwrap ( )
478
479
}
479
480
480
481
// Create UCS-2 Vector from OsStr
0 commit comments