1 #[cfg(feature = "backtrace")] 2 mod hook; 3 use core::panic::PanicInfo; 4 5 /// 全局的panic处理函数 6 /// 7 #[cfg(target_os = "none")] 8 #[panic_handler] 9 #[no_mangle] panic(info: &PanicInfo) -> !10pub fn panic(info: &PanicInfo) -> ! { 11 use log::error; 12 13 use crate::process; 14 15 error!("Kernel Panic Occurred."); 16 17 match info.location() { 18 Some(loc) => { 19 println!( 20 "Location:\n\tFile: {}\n\tLine: {}, Column: {}", 21 loc.file(), 22 loc.line(), 23 loc.column() 24 ); 25 } 26 None => { 27 println!("No location info"); 28 } 29 } 30 println!("Message:\n\t{}", info.message()); 31 #[cfg(feature = "backtrace")] 32 { 33 let mut data = hook::CallbackData { counter: 0 }; 34 println!("Rust Panic Backtrace:"); 35 let _res = unwinding::panic::begin_panic_with_hook::<hook::Tracer>( 36 alloc::boxed::Box::new(()), 37 &mut data, 38 ); 39 // log::error!("panic unreachable: {:?}", res.0); 40 } 41 println!( 42 "Current PCB:\n\t{:?}", 43 process::ProcessManager::current_pcb() 44 ); 45 process::ProcessManager::exit(usize::MAX); 46 } 47