pub trait Arch {
type SavedContext: Send + Sync;
// Required methods
unsafe fn context_switch(
prev: *mut Self::SavedContext,
next: *const Self::SavedContext,
);
fn enable_interrupts();
fn disable_interrupts();
fn interrupts_enabled() -> bool;
}
Expand description
Architecture abstraction trait.
This trait must be implemented for each supported CPU architecture to provide context switching, interrupt handling, and FPU management capabilities.
§Safety
Implementations of this trait involve direct hardware manipulation and inline assembly. All methods marked as unsafe have specific preconditions that must be upheld by the caller.
Required Associated Types§
Sourcetype SavedContext: Send + Sync
type SavedContext: Send + Sync
Architecture-specific saved context type.
This type must contain all CPU registers and state needed to fully restore a thread’s execution context.
Required Methods§
Sourceunsafe fn context_switch(
prev: *mut Self::SavedContext,
next: *const Self::SavedContext,
)
unsafe fn context_switch( prev: *mut Self::SavedContext, next: *const Self::SavedContext, )
Switch from one thread context to another.
§Safety
prev
must point to a valid, properly aligned SavedContextnext
must point to a valid, properly aligned SavedContext- The caller must ensure the memory pointed to by both pointers remains valid for the duration of this call
- Must be called with interrupts disabled
- The
next
context must represent a valid execution state
Sourcefn enable_interrupts()
fn enable_interrupts()
Enable interrupts on the current CPU.
This function re-enables interrupt delivery, allowing preemption and timer interrupts to occur.
Sourcefn disable_interrupts()
fn disable_interrupts()
Disable interrupts on the current CPU.
This function prevents interrupt delivery, creating a critical section where the current thread cannot be preempted.
Sourcefn interrupts_enabled() -> bool
fn interrupts_enabled() -> bool
Check if interrupts are currently enabled.
Returns true
if interrupts are enabled, false
otherwise.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.