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
impl CodeBufferFinalized
pub fn total_size(&self) -> usize
pub fn data(&self) -> &[u8] ⓘ
pub fn symbol_name(&self, sym: Sym) -> Option<&ExternalName>
pub fn symbol_distance(&self, sym: Sym) -> Option<RelocDistance>
Sourcepub fn defined_symbol_offset(&self, name: &ExternalName) -> Option<CodeOffset>
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.
Sourcepub fn defined_symbol_str(&self, name: &str) -> Option<CodeOffset>
pub fn defined_symbol_str(&self, name: &str) -> Option<CodeOffset>
Like Self::defined_symbol_offset, for string ExternalName::Symbol exports.
pub fn arch(&self) -> Arch
Sourcepub fn label_offset(&self, label: Label) -> u32
pub fn label_offset(&self, label: Label) -> u32
Returns the offset of label in this image, or u32::MAX when it was
never bound.
pub fn relocs(&self) -> &[AsmReloc]
pub fn alignment(&self) -> u32
Sourcepub fn allocate(
&self,
jit_allocator: &mut JitAllocator,
) -> Result<Span, AsmError>
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.
Sourcepub fn loaded_size(&self) -> usize
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, starting at Self::got_offset.
Sourcepub fn got_offset(&self) -> usize
pub fn got_offset(&self) -> usize
Offset of the GOT in the loaded image: the end of the code, rounded up to pointer alignment
Sourcepub fn relocate_to_base(
&self,
dst: &mut [u8],
base: usize,
resolve: impl Fn(&ExternalName) -> *const u8,
) -> Result<(), AsmError>
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
at Self::got_offset, right after the code, so base must be
pointer-aligned. 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.
Sourcepub fn load(
&self,
jit_allocator: &mut JitAllocator,
resolve: impl Fn(&ExternalName) -> *const u8,
) -> Result<LoadedCode, AsmError>
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
impl CodeBufferFinalized
Sourcepub fn location_of<M: PatchMark>(&self, mark: M) -> M::Location
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.