Skip to content

Commit 8b5bc8a

Browse files
authored
Merge pull request #565 from msft-jlange/task-safety
task: fix safety
2 parents 33d3cd8 + f428b01 commit 8b5bc8a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

kernel/src/task/tasks.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,10 @@ pub fn is_task_fault(vaddr: VirtAddr) -> bool {
691691
/// Runs the first time a new task is scheduled, in the context of the new
692692
/// task. Any first-time initialization and setup work for a new task that
693693
/// 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.
694696
#[no_mangle]
695-
fn setup_new_task(xsa_addr: u64) {
697+
unsafe fn setup_new_task(xsa_addr: u64) {
696698
// Re-enable IRQs here, as they are still disabled from the
697699
// schedule()/sched_init() functions. After the context switch the IrqGuard
698700
// from the previous task is not dropped, which causes IRQs to stay
@@ -701,16 +703,21 @@ fn setup_new_task(xsa_addr: u64) {
701703
// subsequent task switches will go through schedule() and there the guard
702704
// is dropped, re-enabling IRQs.
703705

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.
706710
unsafe {
707-
irqs_enable();
708711
sse_restore_context(xsa_addr);
709712
}
710713
}
711714

712715
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+
}
714721
entry();
715722
}
716723

0 commit comments

Comments
 (0)