-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
调整代码,同时解决rust analyzer未能提示warning的问题
- Loading branch information
Showing
11 changed files
with
99 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod jump_label; | ||
pub mod klog; | ||
pub mod kprobe; | ||
pub mod panic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use unwinding::abi::{UnwindContext, UnwindReasonCode, _Unwind_GetIP}; | ||
use unwinding::panic::UserUnwindTrace; | ||
|
||
extern "C" { | ||
fn lookup_kallsyms(addr: u64, level: i32) -> i32; | ||
} | ||
|
||
/// User hook for unwinding | ||
/// | ||
/// During stack backtrace, the user can print the function location of the current stack frame. | ||
pub struct Tracer; | ||
pub struct CallbackData { | ||
pub counter: usize, | ||
} | ||
impl UserUnwindTrace for Tracer { | ||
type Arg = CallbackData; | ||
|
||
fn trace(ctx: &UnwindContext<'_>, arg: *mut Self::Arg) -> UnwindReasonCode { | ||
let data = unsafe { &mut *(arg) }; | ||
data.counter += 1; | ||
let pc = _Unwind_GetIP(ctx); | ||
unsafe { | ||
lookup_kallsyms(pc as u64, data.counter as i32); | ||
} | ||
UnwindReasonCode::NO_REASON | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#[cfg(feature = "backtrace")] | ||
mod hook; | ||
use core::panic::PanicInfo; | ||
|
||
/// 全局的panic处理函数 | ||
/// | ||
#[cfg(target_os = "none")] | ||
#[panic_handler] | ||
#[no_mangle] | ||
pub fn panic(info: &PanicInfo) -> ! { | ||
use log::error; | ||
|
||
use crate::process; | ||
|
||
error!("Kernel Panic Occurred."); | ||
|
||
match info.location() { | ||
Some(loc) => { | ||
println!( | ||
"Location:\n\tFile: {}\n\tLine: {}, Column: {}", | ||
loc.file(), | ||
loc.line(), | ||
loc.column() | ||
); | ||
} | ||
None => { | ||
println!("No location info"); | ||
} | ||
} | ||
println!("Message:\n\t{}", info.message()); | ||
#[cfg(feature = "backtrace")] | ||
{ | ||
let mut data = hook::CallbackData { counter: 0 }; | ||
println!("Rust Panic Backtrace:"); | ||
let _res = unwinding::panic::begin_panic_with_hook::<hook::Tracer>( | ||
alloc::boxed::Box::new(()), | ||
&mut data, | ||
); | ||
// log::error!("panic unreachable: {:?}", res.0); | ||
} | ||
println!( | ||
"Current PCB:\n\t{:?}", | ||
process::ProcessManager::current_pcb() | ||
); | ||
process::ProcessManager::exit(usize::MAX); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters