@@ -691,8 +691,10 @@ pub fn is_task_fault(vaddr: VirtAddr) -> bool {
691
691
/// Runs the first time a new task is scheduled, in the context of the new
692
692
/// task. Any first-time initialization and setup work for a new task that
693
693
/// needs to happen in its context must be done here.
694
+ /// # Safety
695
+ /// The caller is required to verify the correctness of the save area address.
694
696
#[ no_mangle]
695
- fn setup_new_task ( xsa_addr : u64 ) {
697
+ unsafe fn setup_new_task ( xsa_addr : u64 ) {
696
698
// Re-enable IRQs here, as they are still disabled from the
697
699
// schedule()/sched_init() functions. After the context switch the IrqGuard
698
700
// from the previous task is not dropped, which causes IRQs to stay
@@ -701,16 +703,21 @@ fn setup_new_task(xsa_addr: u64) {
701
703
// subsequent task switches will go through schedule() and there the guard
702
704
// is dropped, re-enabling IRQs.
703
705
704
- // SAFETY: Safe because this matches the IrqGuard drop in
705
- // schedule()/schedule_init(). See description above.
706
+ irqs_enable ( ) ;
707
+
708
+ // SAFETY: The caller takes responsibility for the correctness of the save
709
+ // area address.
706
710
unsafe {
707
- irqs_enable ( ) ;
708
711
sse_restore_context ( xsa_addr) ;
709
712
}
710
713
}
711
714
712
715
extern "C" fn run_kernel_task ( entry : extern "C" fn ( ) , xsa_addr : u64 ) {
713
- setup_new_task ( xsa_addr) ;
716
+ // SAFETY: the save area address is provided by the context switch assembly
717
+ // code.
718
+ unsafe {
719
+ setup_new_task ( xsa_addr) ;
720
+ }
714
721
entry ( ) ;
715
722
}
716
723
0 commit comments