Skip to main content

CodeBufferFinalized

Struct CodeBufferFinalized 

Source
pub struct CodeBufferFinalized { /* private fields */ }
Expand description

A CodeBuffer once emission is completed: holds generated code and records, without fixups. This allows the type to be independent of the backend.

Implementations§

Source§

impl CodeBufferFinalized

Source

pub fn total_size(&self) -> usize

Source

pub fn data(&self) -> &[u8] ⓘ

Source

pub fn symbol_name(&self, sym: Sym) -> Option<&ExternalName>

Source

pub fn symbol_distance(&self, sym: Sym) -> Option<RelocDistance>

Source

pub fn defined_symbol_offset(&self, name: &ExternalName) -> Option<CodeOffset>

Offset of a symbol exported with CodeBuffer::bind_symbol, if present.

After loading, the runtime address of the symbol is rx + offset.

Source

pub fn defined_symbol_str(&self, name: &str) -> Option<CodeOffset>

Source

pub fn arch(&self) -> Arch

Source

pub fn label_offset(&self, label: Label) -> u32

Returns the offset of label in this image, or u32::MAX when it was never bound.

Source

pub fn relocs(&self) -> &[AsmReloc]

Source

pub fn alignment(&self) -> u32

Source

pub fn allocate( &self, jit_allocator: &mut JitAllocator, ) -> Result<Span, AsmError>

Allocate this code buffer in executable memory and return a Span referring to it. This will also write the code into the allocated memory. To execute code you can simply use span.rx() to get a pointer to read+exec memory and transmute that to a function pointer of the appropriate type.

Source

pub fn loaded_size(&self) -> usize

Size in bytes of the loaded image: the code followed by one pointer-sized GOT slot per distinct target of a GOT-relative relocation.

Source

pub fn relocate_to_base( &self, dst: &mut [u8], base: usize, resolve: impl Fn(&ExternalName) -> *const u8, ) -> Result<(), AsmError>

Copies the image into dst and applies relocations as if dst were mapped at base, the counterpart of AsmJit’s CodeHolder::relocateToBase.

dst must hold at least Self::loaded_size bytes; the GOT is placed right after the code. Labels and symbols defined in the image are resolved internally. Every other symbol (declared with CodeBuffer::extern_sym or CodeBuffer::extern_user, or left undefined by a Linker link) is passed to resolve, which returns its address; a null address is an error.

base is only an address, so the bytes may be copied there later. The GOT holds host-sized pointers.

Source

pub fn load( &self, jit_allocator: &mut JitAllocator, resolve: impl Fn(&ExternalName) -> *const u8, ) -> Result<LoadedCode, AsmError>

Allocates executable memory, copies the image into it, and applies relocations through Self::relocate_to_base.

The returned LoadedCode carries the image’s exported symbols, so the finalized buffer does not need to outlive the load. The memory is not freed on drop; release it with JitAllocator::release(code.rx()) or let the allocator free it.

Source§

impl CodeBufferFinalized

Source

pub fn location_of<M: PatchMark>(&self, mark: M) -> M::Location

Returns where mark is in this image.

mark must come from the buffer this image was finished from. For an image made by Linker::link, use Self::location_in.

Source

pub fn location_in<M: PatchMark>( &self, section: usize, mark: M, ) -> Option<M::Location>

Returns where mark, from the buffer added as section to a Linker, is in this image. Returns None when there is no such section.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.