Skip to content

Commit d7d8dd5

Browse files
committed
feat(task): deny an interrupt context in Kernel::exit_task
1 parent 43e1bb7 commit d7d8dd5

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/constance/src/kernel/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ define_error! {
200200
///
201201
/// [`Kernel::exit_task`]: super::Kernel::exit_task
202202
pub enum ExitTaskError: BadContextError {
203-
/// CPU Lock is active.
203+
/// CPU Lock is active, or the current context is not a task context.
204204
BadContext,
205205
}
206206
}

src/constance/src/kernel/task.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,9 @@ impl Init for TaskSt {
344344

345345
/// Implements [`Kernel::exit_task`].
346346
pub(super) unsafe fn exit_current_task<System: Kernel>() -> Result<!, ExitTaskError> {
347-
// TODO: Deny interrupt context
347+
if System::is_interrupt_context() {
348+
return Err(ExitTaskError::BadContext);
349+
}
348350

349351
// If CPU Lock is inactive, activate it.
350352
// TODO: If `is_cpu_lock_active() == true`, assert that it was an

src/constance_test_suite/src/kernel_tests/interrupt_disallowed_services.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ fn isr<System: Kernel, D: Driver<App<System>>>(_: usize) {
5959
System::boost_priority(),
6060
Err(kernel::BoostPriorityError::BadContext),
6161
);
62+
assert_eq!(
63+
unsafe { System::exit_task() },
64+
Err(kernel::ExitTaskError::BadContext),
65+
);
66+
67+
// Blocking system services
68+
assert_eq!(System::park(), Err(kernel::ParkError::BadContext));
6269

6370
D::success();
6471
}

0 commit comments

Comments
 (0)