Catch panics in threads as oops

This commit is contained in:
Zhang Junyang
2024-10-04 21:55:05 +08:00
committed by Tate, Hongliang Tian
parent 709e99d75a
commit 4823b82e41
4 changed files with 116 additions and 7 deletions

View File

@ -45,8 +45,8 @@ impl KernelThreadExt for Thread {
pub fn create_new_kernel_task(mut thread_options: ThreadOptions) -> Arc<Task> {
let task_fn = thread_options.take_func();
let thread_fn = move || {
task_fn();
// Ensures the thread is exit
let _ = crate::oops::catch_panics_as_oops(task_fn);
// Ensure that the thread exits.
current_thread!().exit();
};

View File

@ -89,9 +89,13 @@ pub fn create_new_user_task(user_space: Arc<UserSpace>, thread_ref: Arc<Thread>)
debug!("exit user loop");
}
TaskOptions::new(user_task_entry)
.data(thread_ref)
.user_space(Some(user_space))
.build()
.expect("spawn task failed")
TaskOptions::new(|| {
// TODO: If a kernel "oops" is caught, we should kill the entire
// process rather than just ending the thread.
let _ = crate::oops::catch_panics_as_oops(user_task_entry);
})
.data(thread_ref)
.user_space(Some(user_space))
.build()
.expect("spawn task failed")
}