Module atomic_mode

Source
Expand description

Atomic Mode

Multitasking, while powerful, can sometimes lead to undesirable or catastrophic consequences if being misused. For instance, a user of OSTD might accidentally write an IRQ handler that relies on mutexes, which could attempt to sleep within an interrupt context—something that must be avoided. Another common mistake is acquiring a spinlock in a task context and then attempting to yield or sleep, which can easily lead to deadlocks.

To mitigate the risks associated with improper multitasking, we introduce the concept of atomic mode. Kernel code is considered to be running in atomic mode if one of the following conditions is met:

  1. Task preemption is disabled, such as when a spinlock is held.
  2. Local IRQs are disabled, such as during interrupt context.

While in atomic mode, any attempt to perform “sleep-like” actions will trigger a panic:

  1. Switching to another task.
  2. Switching to user space.

This module provides API to detect such “sleep-like” actions.

Traits§

AsAtomicModeGuard
Abstracts any type from which one can obtain a reference to an atomic-mode guard.
InAtomicMode
A marker trait for guard types that enforce the atomic mode.

Functions§

might_sleep
Marks a function as one that might sleep.