@@ -34,45 +34,36 @@ pub unsafe fn set_system_table(ptr: *const uefi_raw::table::system::SystemTable)
3434}
3535
3636/// 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 > > {
4638 let st = SYSTEM_TABLE . load ( Ordering :: Acquire ) ;
47- assert ! ( !st. is_null( ) ) ;
39+ if st. is_null ( ) {
40+ return None ;
41+ }
4842
4943 // SAFETY: the system table is valid per the requirements of `set_system_table`.
5044 unsafe {
5145 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 ( ) )
5349 }
54-
55- SystemTable :: < Boot > :: from_ptr ( st. cast ( ) ) . unwrap ( )
5650 }
5751}
5852
5953/// 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 > > {
6655 let st = SYSTEM_TABLE . load ( Ordering :: Acquire ) ;
67- assert ! ( !st. is_null( ) ) ;
56+ if st. is_null ( ) {
57+ return None ;
58+ }
6859
6960 // SAFETY: the system table is valid per the requirements of `set_system_table`.
7061 unsafe {
7162 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 ( ) )
7366 }
74-
75- SystemTable :: < Runtime > :: from_ptr ( st. cast ( ) ) . unwrap ( )
7667 }
7768}
7869
0 commit comments