@@ -34,45 +34,36 @@ pub unsafe fn set_system_table(ptr: *const uefi_raw::table::system::SystemTable)
34
34
}
35
35
36
36
/// Get the system table while boot services are active.
37
- ///
38
- /// # Panics
39
- ///
40
- /// Panics if the system table has not been set with `set_system_table`, or if
41
- /// boot services are not available (e.g. if [`exit_boot_services`] has been
42
- /// called).
43
- ///
44
- /// [`exit_boot_services`]: SystemTable::exit_boot_services
45
- pub fn system_table_boot ( ) -> SystemTable < Boot > {
37
+ pub fn system_table_boot ( ) -> Option < SystemTable < Boot > > {
46
38
let st = SYSTEM_TABLE . load ( Ordering :: Acquire ) ;
47
- assert ! ( !st. is_null( ) ) ;
39
+ if st. is_null ( ) {
40
+ return None ;
41
+ }
48
42
49
43
// SAFETY: the system table is valid per the requirements of `set_system_table`.
50
44
unsafe {
51
45
if ( * st) . boot_services . is_null ( ) {
52
- panic ! ( "boot services are not active" ) ;
46
+ None
47
+ } else {
48
+ Some ( SystemTable :: < Boot > :: from_ptr ( st. cast ( ) ) . unwrap ( ) )
53
49
}
54
-
55
- SystemTable :: < Boot > :: from_ptr ( st. cast ( ) ) . unwrap ( )
56
50
}
57
51
}
58
52
59
53
/// Get the system table while runtime services are active.
60
- ///
61
- /// # Panics
62
- ///
63
- /// Panics if the system table has not been set with `set_system_table`, or if
64
- /// runtime services are not available.
65
- pub fn system_table_runtime ( ) -> SystemTable < Runtime > {
54
+ pub fn system_table_runtime ( ) -> Option < SystemTable < Runtime > > {
66
55
let st = SYSTEM_TABLE . load ( Ordering :: Acquire ) ;
67
- assert ! ( !st. is_null( ) ) ;
56
+ if st. is_null ( ) {
57
+ return None ;
58
+ }
68
59
69
60
// SAFETY: the system table is valid per the requirements of `set_system_table`.
70
61
unsafe {
71
62
if ( * st) . runtime_services . is_null ( ) {
72
- panic ! ( "runtime services are not active" ) ;
63
+ None
64
+ } else {
65
+ Some ( SystemTable :: < Runtime > :: from_ptr ( st. cast ( ) ) . unwrap ( ) )
73
66
}
74
-
75
- SystemTable :: < Runtime > :: from_ptr ( st. cast ( ) ) . unwrap ( )
76
67
}
77
68
}
78
69
0 commit comments