mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-26 11:03:22 +00:00
fix the panic error for riscv64 (#1123)
* fix the panic error for riscv64
This commit is contained in:
3
kernel/Cargo.lock
generated
3
kernel/Cargo.lock
generated
@ -1816,7 +1816,8 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "unwinding"
|
name = "unwinding"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
source = "git+https://git.mirrors.dragonos.org.cn/DragonOS-Community/unwinding?rev=4eb845da62#4eb845da624f4c9899639ca116beb6d2f87e18bc"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "637d511437df708cee34bdec7ba2f1548d256b7acf3ff20e0a1c559f9bf3a987"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gimli 0.31.1",
|
"gimli 0.31.1",
|
||||||
]
|
]
|
||||||
|
@ -10,14 +10,11 @@ edition = "2021"
|
|||||||
crate-type = ["staticlib"]
|
crate-type = ["staticlib"]
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = ["crates/*"]
|
||||||
"crates/*",
|
|
||||||
]
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["backtrace", "kvm", "fatfs", "fatfs-secure", "static_keys_test"]
|
default = ["fatfs", "kvm", "fatfs-secure", "static_keys_test"]
|
||||||
# 内核栈回溯
|
# 内核栈回溯
|
||||||
backtrace = ["dep:unwinding"]
|
|
||||||
# kvm
|
# kvm
|
||||||
kvm = []
|
kvm = []
|
||||||
|
|
||||||
@ -52,7 +49,18 @@ linkme = "=0.3.27"
|
|||||||
num = { version = "=0.4.0", default-features = false }
|
num = { version = "=0.4.0", default-features = false }
|
||||||
num-derive = "=0.3"
|
num-derive = "=0.3"
|
||||||
num-traits = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/num-traits.git", rev = "1597c1c", default-features = false }
|
num-traits = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/num-traits.git", rev = "1597c1c", default-features = false }
|
||||||
smoltcp = { version = "=0.11.0", default-features = false, features = ["log", "alloc", "socket-raw", "socket-udp", "socket-tcp", "socket-icmp", "socket-dhcpv4", "socket-dns", "proto-ipv4", "proto-ipv6"]}
|
smoltcp = { version = "=0.11.0", default-features = false, features = [
|
||||||
|
"log",
|
||||||
|
"alloc",
|
||||||
|
"socket-raw",
|
||||||
|
"socket-udp",
|
||||||
|
"socket-tcp",
|
||||||
|
"socket-icmp",
|
||||||
|
"socket-dhcpv4",
|
||||||
|
"socket-dns",
|
||||||
|
"proto-ipv4",
|
||||||
|
"proto-ipv6",
|
||||||
|
] }
|
||||||
system_error = { path = "crates/system_error" }
|
system_error = { path = "crates/system_error" }
|
||||||
uefi = { version = "=0.26.0", features = ["alloc"] }
|
uefi = { version = "=0.26.0", features = ["alloc"] }
|
||||||
uefi-raw = "=0.5.0"
|
uefi-raw = "=0.5.0"
|
||||||
@ -69,11 +77,11 @@ rbpf = { path = "crates/rbpf" }
|
|||||||
printf-compat = { version = "0.1.1", default-features = false }
|
printf-compat = { version = "0.1.1", default-features = false }
|
||||||
|
|
||||||
static-keys = "=0.6.1"
|
static-keys = "=0.6.1"
|
||||||
unwinding = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/unwinding", rev = "4eb845da62", default-features = false, optional = true, features = [
|
unwinding = { version = "=0.2.3", default-features = false, features = [
|
||||||
"unwinder",
|
"unwinder",
|
||||||
"fde-gnu-eh-frame-hdr",
|
"fde-gnu-eh-frame-hdr",
|
||||||
"panic",
|
"panic",
|
||||||
"personality"
|
"personality",
|
||||||
] }
|
] }
|
||||||
defer = "0.2.1"
|
defer = "0.2.1"
|
||||||
cfg-if = { version = "1.0.0" }
|
cfg-if = { version = "1.0.0" }
|
||||||
@ -87,7 +95,9 @@ x86_64 = "=0.14.10"
|
|||||||
|
|
||||||
# target为riscv64时,使用下面的依赖
|
# target为riscv64时,使用下面的依赖
|
||||||
[target.'cfg(target_arch = "riscv64")'.dependencies]
|
[target.'cfg(target_arch = "riscv64")'.dependencies]
|
||||||
riscv = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/riscv.git", rev = "4241a97", features = [ "s-mode" ] }
|
riscv = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/riscv.git", rev = "4241a97", features = [
|
||||||
|
"s-mode",
|
||||||
|
] }
|
||||||
sbi-rt = { version = "=0.0.3", features = ["legacy"] }
|
sbi-rt = { version = "=0.0.3", features = ["legacy"] }
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ clean:
|
|||||||
fmt:
|
fmt:
|
||||||
RUSTFLAGS="$(RUSTFLAGS)" cargo fmt --all $(FMT_CHECK)
|
RUSTFLAGS="$(RUSTFLAGS)" cargo fmt --all $(FMT_CHECK)
|
||||||
ifeq ($(ARCH), x86_64)
|
ifeq ($(ARCH), x86_64)
|
||||||
RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2024-11-05 clippy --all-features
|
RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2024-11-05 clippy --all-features --target x86_64-unknown-none
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,11 +124,11 @@ static mut CASTER_MAP: Option<HashMap<(TypeId, TypeId), BoxedCaster, BuildFastHa
|
|||||||
#[cfg(target_os = "none")]
|
#[cfg(target_os = "none")]
|
||||||
#[allow(static_mut_refs)]
|
#[allow(static_mut_refs)]
|
||||||
pub fn caster_map() -> &'static HashMap<(TypeId, TypeId), BoxedCaster, BuildFastHasher> {
|
pub fn caster_map() -> &'static HashMap<(TypeId, TypeId), BoxedCaster, BuildFastHasher> {
|
||||||
return unsafe {
|
unsafe {
|
||||||
CASTER_MAP.as_ref().unwrap_or_else(|| {
|
CASTER_MAP.as_ref().unwrap_or_else(|| {
|
||||||
panic!("intertrait_caster_map() must be called after CASTER_MAP is initialized")
|
panic!("intertrait_caster_map() must be called after CASTER_MAP is initialized")
|
||||||
})
|
})
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initializes the global [`CASTER_MAP`] with [`CASTERS`].
|
/// Initializes the global [`CASTER_MAP`] with [`CASTERS`].
|
||||||
|
@ -32,3 +32,10 @@ pub use self::ipc::signal::RiscV64SignalArch as CurrentSignalArch;
|
|||||||
pub use crate::arch::smp::RiscV64SMPArch as CurrentSMPArch;
|
pub use crate::arch::smp::RiscV64SMPArch as CurrentSMPArch;
|
||||||
|
|
||||||
pub use crate::arch::sched::RiscV64SchedArch as CurrentSchedArch;
|
pub use crate::arch::sched::RiscV64SchedArch as CurrentSchedArch;
|
||||||
|
|
||||||
|
pub fn panic_pre_work() {
|
||||||
|
unsafe { riscv::register::sstatus::set_fs(riscv::register::sstatus::FS::Initial) };
|
||||||
|
}
|
||||||
|
pub fn panic_post_work() {
|
||||||
|
unsafe { riscv::register::sstatus::set_fs(riscv::register::sstatus::FS::Off) };
|
||||||
|
}
|
||||||
|
@ -36,16 +36,8 @@ pub(super) fn syscall_handler(syscall_num: usize, frame: &mut TrapFrame) -> () {
|
|||||||
|
|
||||||
let args = [frame.a0, frame.a1, frame.a2, frame.a3, frame.a4, frame.a5];
|
let args = [frame.a0, frame.a1, frame.a2, frame.a3, frame.a4, frame.a5];
|
||||||
let mut syscall_handle = || -> usize {
|
let mut syscall_handle = || -> usize {
|
||||||
#[cfg(feature = "backtrace")]
|
|
||||||
{
|
|
||||||
Syscall::catch_handle(syscall_num, &args, frame)
|
Syscall::catch_handle(syscall_num, &args, frame)
|
||||||
.unwrap_or_else(|e| e.to_posix_errno() as usize)
|
.unwrap_or_else(|e| e.to_posix_errno() as usize)
|
||||||
}
|
|
||||||
#[cfg(not(feature = "backtrace"))]
|
|
||||||
{
|
|
||||||
Syscall::handle(syscall_num, &args, frame)
|
|
||||||
.unwrap_or_else(|e| e.to_posix_errno() as usize)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
syscall_return!(syscall_handle(), frame, false);
|
syscall_return!(syscall_handle(), frame, false);
|
||||||
}
|
}
|
||||||
|
@ -48,3 +48,6 @@ pub use crate::arch::vm::x86_kvm_ops as kvm_arch_ops;
|
|||||||
|
|
||||||
pub use crate::arch::vm::kvm_host::vcpu::X86VcpuArch as VirtCpuArch;
|
pub use crate::arch::vm::kvm_host::vcpu::X86VcpuArch as VirtCpuArch;
|
||||||
pub use crate::arch::vm::kvm_host::KvmVcpuStat as VirtCpuStat;
|
pub use crate::arch::vm::kvm_host::KvmVcpuStat as VirtCpuStat;
|
||||||
|
|
||||||
|
pub fn panic_pre_work() {}
|
||||||
|
pub fn panic_post_work() {}
|
||||||
|
@ -120,16 +120,8 @@ pub extern "sysv64" fn syscall_handler(frame: &mut TrapFrame) {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
let mut syscall_handle = || -> u64 {
|
let mut syscall_handle = || -> u64 {
|
||||||
#[cfg(feature = "backtrace")]
|
|
||||||
{
|
|
||||||
Syscall::catch_handle(syscall_num, &args, frame)
|
Syscall::catch_handle(syscall_num, &args, frame)
|
||||||
.unwrap_or_else(|e| e.to_posix_errno() as usize) as u64
|
.unwrap_or_else(|e| e.to_posix_errno() as usize) as u64
|
||||||
}
|
|
||||||
#[cfg(not(feature = "backtrace"))]
|
|
||||||
{
|
|
||||||
Syscall::handle(syscall_num, &args, frame)
|
|
||||||
.unwrap_or_else(|e| e.to_posix_errno() as usize) as u64
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
syscall_return!(syscall_handle(), frame, show);
|
syscall_return!(syscall_handle(), frame, show);
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ int read_symbol(FILE *filp, struct kernel_symbol_entry_t *entry)
|
|||||||
int retval = sscanf(str, "%llx %c %512c", &entry->vaddr, &entry->type, symbol_name);
|
int retval = sscanf(str, "%llx %c %512c", &entry->vaddr, &entry->type, symbol_name);
|
||||||
|
|
||||||
// 如果当前行不符合要求
|
// 如果当前行不符合要求
|
||||||
if (retval != 3)
|
if (retval != 3 || entry->type != 'T')
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,34 @@
|
|||||||
use crate::debug::traceback::lookup_kallsyms;
|
use crate::debug::traceback::lookup_kallsyms;
|
||||||
use unwinding::abi::{UnwindContext, UnwindReasonCode, _Unwind_GetIP};
|
use crate::libs::spinlock::SpinLock;
|
||||||
use unwinding::panic::UserUnwindTrace;
|
use core::ffi::c_void;
|
||||||
|
use unwinding::abi::{UnwindContext, UnwindReasonCode, _Unwind_Backtrace, _Unwind_GetIP};
|
||||||
|
|
||||||
/// User hook for unwinding
|
pub fn print_stack_trace() {
|
||||||
///
|
static GLOBAL_LOCK: SpinLock<()> = SpinLock::new(());
|
||||||
/// During stack backtrace, the user can print the function location of the current stack frame.
|
let _lock = GLOBAL_LOCK.lock();
|
||||||
pub struct Tracer;
|
println!("Rust Panic Backtrace:");
|
||||||
pub struct CallbackData {
|
struct CallbackData {
|
||||||
pub counter: usize,
|
counter: usize,
|
||||||
|
kernel_main: bool,
|
||||||
|
}
|
||||||
|
extern "C" fn callback(unwind_ctx: &UnwindContext<'_>, arg: *mut c_void) -> UnwindReasonCode {
|
||||||
|
let data = unsafe { &mut *(arg as *mut CallbackData) };
|
||||||
|
if data.kernel_main {
|
||||||
|
// If we are in kernel_main, we don't need to print the backtrace.
|
||||||
|
return UnwindReasonCode::NORMAL_STOP;
|
||||||
}
|
}
|
||||||
impl UserUnwindTrace for Tracer {
|
|
||||||
type Arg = CallbackData;
|
|
||||||
|
|
||||||
fn trace(ctx: &UnwindContext<'_>, arg: *mut Self::Arg) -> UnwindReasonCode {
|
|
||||||
let data = unsafe { &mut *(arg) };
|
|
||||||
data.counter += 1;
|
data.counter += 1;
|
||||||
let pc = _Unwind_GetIP(ctx);
|
let pc = _Unwind_GetIP(unwind_ctx);
|
||||||
unsafe {
|
if pc > 0 {
|
||||||
lookup_kallsyms(pc as u64, data.counter as i32);
|
let is_kernel_main = unsafe { lookup_kallsyms(pc as u64, data.counter as i32) };
|
||||||
|
data.kernel_main = is_kernel_main;
|
||||||
}
|
}
|
||||||
UnwindReasonCode::NO_REASON
|
UnwindReasonCode::NO_REASON
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut data = CallbackData {
|
||||||
|
counter: 0,
|
||||||
|
kernel_main: false,
|
||||||
|
};
|
||||||
|
_Unwind_Backtrace(callback, &mut data as *mut _ as _);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
#[cfg(feature = "backtrace")]
|
|
||||||
mod hook;
|
mod hook;
|
||||||
|
use alloc::boxed::Box;
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
|
use log::error;
|
||||||
|
|
||||||
|
use crate::process;
|
||||||
|
use system_error::SystemError;
|
||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(target_os = "none")] {
|
if #[cfg(target_os = "none")] {
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
@ -10,15 +15,29 @@ cfg_if! {
|
|||||||
static PANIC_COUNTER: AtomicU8 = AtomicU8::new(0);
|
static PANIC_COUNTER: AtomicU8 = AtomicU8::new(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct PanicGuard;
|
||||||
|
|
||||||
|
impl PanicGuard {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
crate::arch::panic_pre_work();
|
||||||
|
Self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for PanicGuard {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
crate::arch::panic_post_work();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// 全局的panic处理函数
|
/// 全局的panic处理函数
|
||||||
///
|
///
|
||||||
#[cfg(target_os = "none")]
|
#[cfg(target_os = "none")]
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn panic(info: &PanicInfo) -> ! {
|
pub fn panic(info: &PanicInfo) -> ! {
|
||||||
use log::error;
|
|
||||||
|
|
||||||
use crate::process;
|
|
||||||
PANIC_COUNTER.fetch_add(1, core::sync::atomic::Ordering::Relaxed);
|
PANIC_COUNTER.fetch_add(1, core::sync::atomic::Ordering::Relaxed);
|
||||||
error!("Kernel Panic Occurred.");
|
error!("Kernel Panic Occurred.");
|
||||||
|
|
||||||
@ -43,15 +62,12 @@ pub fn panic(info: &PanicInfo) -> ! {
|
|||||||
);
|
);
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "backtrace")]
|
|
||||||
{
|
if info.can_unwind() {
|
||||||
let mut data = hook::CallbackData { counter: 0 };
|
let guard = Box::new(PanicGuard::new());
|
||||||
println!("Rust Panic Backtrace:");
|
hook::print_stack_trace();
|
||||||
let _res = unwinding::panic::begin_panic_with_hook::<hook::Tracer>(
|
let _res = unwinding::panic::begin_panic(guard);
|
||||||
alloc::boxed::Box::new(()),
|
// log::error!("panic unreachable: {:?}", _res.0);
|
||||||
&mut data,
|
|
||||||
);
|
|
||||||
// log::error!("panic unreachable: {:?}", res.0);
|
|
||||||
}
|
}
|
||||||
println!(
|
println!(
|
||||||
"Current PCB:\n\t{:?}",
|
"Current PCB:\n\t{:?}",
|
||||||
@ -59,3 +75,40 @@ pub fn panic(info: &PanicInfo) -> ! {
|
|||||||
);
|
);
|
||||||
process::ProcessManager::exit(usize::MAX);
|
process::ProcessManager::exit(usize::MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The wrapper of `unwinding::panic::begin_panic`. If the panic is
|
||||||
|
/// caught, it will return the result of the function.
|
||||||
|
/// If the panic is not caught, it will return an error.
|
||||||
|
pub fn kernel_catch_unwind<R, F: FnOnce() -> R>(f: F) -> Result<R, SystemError> {
|
||||||
|
let res = unwinding::panic::catch_unwind(f);
|
||||||
|
match res {
|
||||||
|
Ok(r) => Ok(r),
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Catch Unwind Error: {:?}", e);
|
||||||
|
Err(SystemError::MAXERRNO)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn test_unwind() {
|
||||||
|
struct UnwindTest;
|
||||||
|
impl Drop for UnwindTest {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
log::info!("Drop UnwindTest");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log::error!("Test unwind");
|
||||||
|
let res1 = unwinding::panic::catch_unwind(|| {
|
||||||
|
let _unwind_test = UnwindTest;
|
||||||
|
log::error!("Test panic...");
|
||||||
|
panic!("Test panic");
|
||||||
|
});
|
||||||
|
assert!(res1.is_err());
|
||||||
|
let res2 = unwinding::panic::catch_unwind(|| {
|
||||||
|
let _unwind_test = UnwindTest;
|
||||||
|
log::error!("Test no panic...");
|
||||||
|
0
|
||||||
|
});
|
||||||
|
assert!(res2.is_ok());
|
||||||
|
}
|
||||||
|
@ -13,7 +13,9 @@ fn kallsyms_names_index() {}
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
fn kallsyms_names() {}
|
fn kallsyms_names() {}
|
||||||
|
|
||||||
pub unsafe fn lookup_kallsyms(addr: u64, level: i32) -> Option<()> {
|
/// print the func name according to the pc address and
|
||||||
|
/// return true if the func is kernel_main
|
||||||
|
pub unsafe fn lookup_kallsyms(addr: u64, level: i32) -> bool {
|
||||||
let sym_names = kallsyms_names as *const u8;
|
let sym_names = kallsyms_names as *const u8;
|
||||||
// 由于符号表使用nm -n生成,因此是按照地址升序排列的,因此可以二分
|
// 由于符号表使用nm -n生成,因此是按照地址升序排列的,因此可以二分
|
||||||
let sym_num = kallsyms_num as usize;
|
let sym_num = kallsyms_num as usize;
|
||||||
@ -28,10 +30,14 @@ pub unsafe fn lookup_kallsyms(addr: u64, level: i32) -> Option<()> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return if index < sym_num {
|
let mut is_kernel_main = false;
|
||||||
|
if index < sym_num {
|
||||||
let sym_name = CStr::from_ptr(sym_names.add(sym_names_index[index] as usize) as _)
|
let sym_name = CStr::from_ptr(sym_names.add(sym_names_index[index] as usize) as _)
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
if sym_name.starts_with("kernel_main") {
|
||||||
|
is_kernel_main = true;
|
||||||
|
}
|
||||||
println!(
|
println!(
|
||||||
"[{}] function:{}() \t(+) {:04} address:{:#018x}",
|
"[{}] function:{}() \t(+) {:04} address:{:#018x}",
|
||||||
level,
|
level,
|
||||||
@ -39,11 +45,18 @@ pub unsafe fn lookup_kallsyms(addr: u64, level: i32) -> Option<()> {
|
|||||||
addr - kallsyms_address_list[index],
|
addr - kallsyms_address_list[index],
|
||||||
addr
|
addr
|
||||||
);
|
);
|
||||||
Some(())
|
|
||||||
} else {
|
} else {
|
||||||
None
|
println!(
|
||||||
|
"[{}] function:unknown \t(+) {:04} address:{:#018x}",
|
||||||
|
level,
|
||||||
|
addr - kallsyms_address_list[sym_num - 1],
|
||||||
|
addr
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
return is_kernel_main;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the address of the symbol
|
||||||
pub unsafe fn addr_from_symbol(symbol: &str) -> Option<u64> {
|
pub unsafe fn addr_from_symbol(symbol: &str) -> Option<u64> {
|
||||||
let sym_num = kallsyms_num as usize;
|
let sym_num = kallsyms_num as usize;
|
||||||
let sym_names = kallsyms_names as *const u8;
|
let sym_names = kallsyms_names as *const u8;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#![no_main] // <1>
|
#![no_main] // <1>
|
||||||
|
#![no_std]
|
||||||
#![feature(alloc_error_handler)]
|
#![feature(alloc_error_handler)]
|
||||||
#![feature(new_zeroed_alloc)]
|
#![feature(new_zeroed_alloc)]
|
||||||
#![feature(allocator_api)]
|
#![feature(allocator_api)]
|
||||||
@ -20,7 +21,7 @@
|
|||||||
#![feature(c_variadic)]
|
#![feature(c_variadic)]
|
||||||
#![feature(asm_goto)]
|
#![feature(asm_goto)]
|
||||||
#![feature(linkage)]
|
#![feature(linkage)]
|
||||||
#![cfg_attr(target_os = "none", no_std)]
|
#![feature(panic_can_unwind)]
|
||||||
#![allow(static_mut_refs, non_local_definitions, internal_features)]
|
#![allow(static_mut_refs, non_local_definitions, internal_features)]
|
||||||
// clippy的配置
|
// clippy的配置
|
||||||
#![deny(clippy::all)]
|
#![deny(clippy::all)]
|
||||||
|
@ -154,7 +154,7 @@ fn dealloc_debug_log(source: LogSource, layout: Layout, ptr: *mut u8) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 为内核slab分配器实现Allocator特性
|
// 为内核slab分配器实现Allocator特性
|
||||||
// unsafe impl Allocator for KernelAllocator {
|
// unsafe impl Allocator for KernelAllocator {
|
||||||
// fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
|
// fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
|
||||||
// let memory = unsafe {self.local_alloc(layout)};
|
// let memory = unsafe {self.local_alloc(layout)};
|
||||||
|
@ -5,6 +5,7 @@ use core::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
arch::{ipc::signal::SigSet, syscall::nr::*},
|
arch::{ipc::signal::SigSet, syscall::nr::*},
|
||||||
|
debug::panic::kernel_catch_unwind,
|
||||||
filesystem::vfs::syscall::{PosixStatfs, PosixStatx},
|
filesystem::vfs::syscall::{PosixStatfs, PosixStatx},
|
||||||
ipc::shm::{ShmCtlCmd, ShmFlags, ShmId, ShmKey},
|
ipc::shm::{ShmCtlCmd, ShmFlags, ShmId, ShmKey},
|
||||||
libs::{futex::constant::FutexFlag, rand::GRandFlags},
|
libs::{futex::constant::FutexFlag, rand::GRandFlags},
|
||||||
@ -77,16 +78,13 @@ impl Syscall {
|
|||||||
/// 系统调用分发器,用于分发系统调用。
|
/// 系统调用分发器,用于分发系统调用。
|
||||||
///
|
///
|
||||||
/// 与[handle]不同,这个函数会捕获系统调用处理函数的panic,返回错误码。
|
/// 与[handle]不同,这个函数会捕获系统调用处理函数的panic,返回错误码。
|
||||||
#[cfg(feature = "backtrace")]
|
|
||||||
pub fn catch_handle(
|
pub fn catch_handle(
|
||||||
syscall_num: usize,
|
syscall_num: usize,
|
||||||
args: &[usize],
|
args: &[usize],
|
||||||
frame: &mut TrapFrame,
|
frame: &mut TrapFrame,
|
||||||
) -> Result<usize, SystemError> {
|
) -> Result<usize, SystemError> {
|
||||||
let res = unwinding::panic::catch_unwind(|| Self::handle(syscall_num, args, frame));
|
let res = kernel_catch_unwind(|| Self::handle(syscall_num, args, frame))?;
|
||||||
res.unwrap_or_else(|_| loop {
|
res
|
||||||
core::hint::spin_loop();
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
/// @brief 系统调用分发器,用于分发系统调用。
|
/// @brief 系统调用分发器,用于分发系统调用。
|
||||||
///
|
///
|
||||||
|
Reference in New Issue
Block a user