Arch

Trait Arch 

Source
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§

Source

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§

Source

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 SavedContext
  • next 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
Source

fn enable_interrupts()

Enable interrupts on the current CPU.

This function re-enables interrupt delivery, allowing preemption and timer interrupts to occur.

Source

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.

Source

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.

Implementors§