Struct cranelift_jit::JITModule
source · pub struct JITModule { /* private fields */ }
Expand description
A JITModule
implements Module
and emits code and data into memory where it can be
directly called and accessed.
See the JITBuilder
for a convenient way to construct JITModule
instances.
Implementations§
source§impl JITModule
impl JITModule
sourcepub unsafe fn free_memory(self)
pub unsafe fn free_memory(self)
Free memory allocated for code and data segments of compiled functions.
§Safety
Because this function invalidates any pointers retrived from the
corresponding module, it should only be used when none of the functions
from that module are currently executing and none of the fn
pointers
are called afterwards.
sourcepub fn read_got_entry(&self, func_id: FuncId) -> *const u8
pub fn read_got_entry(&self, func_id: FuncId) -> *const u8
Returns the given function’s entry in the Global Offset Table.
Panics if there’s no entry in the table for the given function.
sourcepub fn get_finalized_function(&self, func_id: FuncId) -> *const u8
pub fn get_finalized_function(&self, func_id: FuncId) -> *const u8
Returns the address of a finalized function.
The pointer remains valid until either JITModule::free_memory
is called or in the future
some way of deallocating this individual function is used.
sourcepub fn get_finalized_data(&self, data_id: DataId) -> (*const u8, usize)
pub fn get_finalized_data(&self, data_id: DataId) -> (*const u8, usize)
Returns the address and size of a finalized data object.
The pointer remains valid until either JITModule::free_memory
is called or in the future
some way of deallocating this individual data object is used.
sourcepub fn finalize_definitions(&mut self) -> ModuleResult<()>
pub fn finalize_definitions(&mut self) -> ModuleResult<()>
Finalize all functions and data objects that are defined but not yet finalized. All symbols referenced in their bodies that are declared as needing a definition must be defined by this point.
Use get_finalized_function
and get_finalized_data
to obtain the final
artifacts.
Returns ModuleError in case of allocation or syscall failure
sourcepub fn new(builder: JITBuilder) -> Self
pub fn new(builder: JITBuilder) -> Self
Create a new JITModule
.
sourcepub fn prepare_for_function_redefine(
&mut self,
func_id: FuncId
) -> ModuleResult<()>
pub fn prepare_for_function_redefine( &mut self, func_id: FuncId ) -> ModuleResult<()>
Allow a single future define_function
on a previously defined function. This allows for
hot code swapping and lazy compilation of functions.
This requires hotswap support to be enabled first using JITBuilder::hotswap
.
Trait Implementations§
source§impl Module for JITModule
impl Module for JITModule
source§fn declarations(&self) -> &ModuleDeclarations
fn declarations(&self) -> &ModuleDeclarations
source§fn declare_function(
&mut self,
name: &str,
linkage: Linkage,
signature: &Signature
) -> ModuleResult<FuncId>
fn declare_function( &mut self, name: &str, linkage: Linkage, signature: &Signature ) -> ModuleResult<FuncId>
source§fn declare_anonymous_function(
&mut self,
signature: &Signature
) -> ModuleResult<FuncId>
fn declare_anonymous_function( &mut self, signature: &Signature ) -> ModuleResult<FuncId>
source§fn declare_data(
&mut self,
name: &str,
linkage: Linkage,
writable: bool,
tls: bool
) -> ModuleResult<DataId>
fn declare_data( &mut self, name: &str, linkage: Linkage, writable: bool, tls: bool ) -> ModuleResult<DataId>
source§fn declare_anonymous_data(
&mut self,
writable: bool,
tls: bool
) -> ModuleResult<DataId>
fn declare_anonymous_data( &mut self, writable: bool, tls: bool ) -> ModuleResult<DataId>
source§fn define_function_with_control_plane(
&mut self,
id: FuncId,
ctx: &mut Context,
ctrl_plane: &mut ControlPlane
) -> ModuleResult<()>
fn define_function_with_control_plane( &mut self, id: FuncId, ctx: &mut Context, ctrl_plane: &mut ControlPlane ) -> ModuleResult<()>
Context
. Read moresource§fn define_function_bytes(
&mut self,
id: FuncId,
func: &Function,
alignment: u64,
bytes: &[u8],
relocs: &[FinalizedMachReloc]
) -> ModuleResult<()>
fn define_function_bytes( &mut self, id: FuncId, func: &Function, alignment: u64, bytes: &[u8], relocs: &[FinalizedMachReloc] ) -> ModuleResult<()>
bytes
. Read moresource§fn define_data(
&mut self,
id: DataId,
data: &DataDescription
) -> ModuleResult<()>
fn define_data( &mut self, id: DataId, data: &DataDescription ) -> ModuleResult<()>
DataContext
.source§fn get_name(&self, name: &str) -> Option<FuncOrDataId>
fn get_name(&self, name: &str) -> Option<FuncOrDataId>
source§fn target_config(&self) -> TargetFrontendConfig
fn target_config(&self) -> TargetFrontendConfig
source§fn make_context(&self) -> Context
fn make_context(&self) -> Context
source§fn clear_context(&self, ctx: &mut Context)
fn clear_context(&self, ctx: &mut Context)
Context
and reset it for use with a new function. Read moresource§fn make_signature(&self) -> Signature
fn make_signature(&self) -> Signature
Signature
with the default calling convention for
the TargetIsa
, to which parameter and return types can be added for
declaring a function to be called by this Module
.source§fn clear_signature(&self, sig: &mut Signature)
fn clear_signature(&self, sig: &mut Signature)
Signature
and reset for use with a new function. Read moresource§fn declare_func_in_func(
&mut self,
func_id: FuncId,
func: &mut Function
) -> FuncRef
fn declare_func_in_func( &mut self, func_id: FuncId, func: &mut Function ) -> FuncRef
source§fn declare_data_in_func(&self, data: DataId, func: &mut Function) -> GlobalValue
fn declare_data_in_func(&self, data: DataId, func: &mut Function) -> GlobalValue
source§fn declare_func_in_data(
&self,
func_id: FuncId,
data: &mut DataDescription
) -> FuncRef
fn declare_func_in_data( &self, func_id: FuncId, data: &mut DataDescription ) -> FuncRef
source§fn declare_data_in_data(
&self,
data_id: DataId,
data: &mut DataDescription
) -> GlobalValue
fn declare_data_in_data( &self, data_id: DataId, data: &mut DataDescription ) -> GlobalValue
source§fn define_function(
&mut self,
func: FuncId,
ctx: &mut Context
) -> Result<(), ModuleError>
fn define_function( &mut self, func: FuncId, ctx: &mut Context ) -> Result<(), ModuleError>
Context
. Read more