Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

ScratchpadStack

Struct ScratchpadStack 

Source
pub struct ScratchpadStack<const START: usize, const END: usize>;
Expand description

A call stack in scratchpad bytes START..END.

The stack grows down from END - 16; the bottom word at START is the canary. See the module docs for the rules.

A layout the stack cannot use is a compile error where it is run:

ⓘ
use psx_rt::scratchpad::ScratchpadStack;
// END is not 8-byte aligned.
const _: usize = ScratchpadStack::<0, 1020>::BUDGET;

Implementations§

Source§

impl<const START: usize, const END: usize> ScratchpadStack<START, END>

Source

pub const REGION: Region

The bytes this stack owns while a call runs on it. Evaluating it checks the layout: in bounds, START word aligned, END 8-byte aligned (the o32 stack alignment) and room for more than the overhead.

Source

pub const BUDGET: usize

Bytes of frames the call tree may use; stack-guard fails the build when the linked tree needs more.

Source

pub unsafe fn run<R, F: FnOnce() -> R>(f: F) -> R

Run f with $sp in this region and return its result.

The switch is a 16-instruction trampoline after a 4-instruction $sp test. Already on a scratchpad stack, it calls f in place. On the host there is no scratchpad and it only calls f.

§Safety
  • No scratchpad data another piece of code relies on may live in Self::REGION while f runs, and f must not put any there. Record the regions that are live around the call with assert_disjoint.
  • The linked call tree of f must fit in Self::BUDGET. Run stack-guard on every linked image that calls this.
  • Any exception handler installed while interrupts are enabled must leave $sp and the memory below it alone (psx-rt’s does; declare another with declare_stack_safe_handler).

Auto Trait Implementations§

§

impl<const START: usize, const END: usize> Freeze for ScratchpadStack<START, END>

§

impl<const START: usize, const END: usize> RefUnwindSafe for ScratchpadStack<START, END>

§

impl<const START: usize, const END: usize> Send for ScratchpadStack<START, END>

§

impl<const START: usize, const END: usize> Sync for ScratchpadStack<START, END>

§

impl<const START: usize, const END: usize> Unpin for ScratchpadStack<START, END>

§

impl<const START: usize, const END: usize> UnsafeUnpin for ScratchpadStack<START, END>

§

impl<const START: usize, const END: usize> UnwindSafe for ScratchpadStack<START, END>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.