Skip to main content

ExecutableMemory

Trait ExecutableMemory 

Source
pub unsafe trait ExecutableMemory: Sync {
    // Required methods
    fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, Error>;
    unsafe fn finish_writes(
        &self,
        allocation: NonNull<u8>,
        layout: Layout,
        regions: &mut dyn Iterator<Item = Region>,
    ) -> Result<(), Error>;
    unsafe fn free(&self, allocation: NonNull<u8>, layout: Layout);

    // Provided method
    fn execution_base(&self, allocation: NonNull<u8>) -> NonNull<u8> { ... }
}
Expand description

Platform-specific executable RAM or PSRAM.

§Safety

Successful allocations supply an exclusive writable allocation of the given layout. On unified-address platforms, the same virtual addresses are used for data access and execution (Self::execution_base returns allocation). On split-bus (Harvard) platforms where instruction fetch uses a separate address alias of the same physical memory, Self::execution_base returns that alias with at least the same alignment and size as allocation, valid until Self::free. Finalization must make written instructions visible to instruction fetch, apply permissions supported by the platform and preserve region contents. Memory must remain mapped until freed, including on finalization failure.

Required Methods§

Source

fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, Error>

Source

unsafe fn finish_writes( &self, allocation: NonNull<u8>, layout: Layout, regions: &mut dyn Iterator<Item = Region>, ) -> Result<(), Error>

Synchronize caches and apply final executable/data permissions. Return an error if the region layout cannot be supported.

§Safety

The allocation must have come from allocate with this layout. All writes by the loader are complete and no references to the bytes remain.

Source

unsafe fn free(&self, allocation: NonNull<u8>, layout: Layout)

Release the allocation, regardless of whether finalization succeeded.

§Safety

The allocation must have come from allocate with this layout. No code may still be executing from or referencing it.

Provided Methods§

Source

fn execution_base(&self, allocation: NonNull<u8>) -> NonNull<u8>

Instruction-fetch base address aliasing allocation.

Unified-address platforms inherit the default, which returns allocation. Split-bus platforms (such as ESP32-S2/S3 internal D/IRAM) override this to return the instruction-bus alias of the same physical bytes.

Implementors§