MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / define_function_bytes

Method define_function_bytes

cranelift/jit/src/backend.rs:532–572  ·  view source on GitHub ↗
(
        &mut self,
        id: FuncId,
        alignment: u64,
        bytes: &[u8],
        relocs: &[ModuleReloc],
    )

Source from the content-addressed store, hash-verified

530 }
531
532 fn define_function_bytes(
533 &mut self,
534 id: FuncId,
535 alignment: u64,
536 bytes: &[u8],
537 relocs: &[ModuleReloc],
538 ) -> ModuleResult<()> {
539 info!("defining function {id} with bytes");
540 let decl = self.declarations.get_function_decl(id);
541 if !decl.linkage.is_definable() {
542 return Err(ModuleError::InvalidImportDefinition(
543 decl.linkage_name(id).into_owned(),
544 ));
545 }
546
547 if !self.compiled_functions[id].is_none() {
548 return Err(ModuleError::DuplicateDefinition(
549 decl.linkage_name(id).into_owned(),
550 ));
551 }
552
553 let align = alignment
554 .max(self.isa.function_alignment().minimum as u64)
555 .max(self.isa.symbol_alignment());
556
557 let blob = self.compiled_functions[id].insert(CompiledBlob::new(
558 &mut *self.memory,
559 bytes,
560 align,
561 relocs.to_owned(),
562 #[cfg(feature = "wasmtime-unwinder")]
563 None,
564 JITMemoryKind::Executable,
565 )?);
566 let (ptr, size) = (blob.ptr(), blob.size());
567 self.record_function_for_perf(ptr, size, &decl.linkage_name(id));
568
569 self.functions_to_finalize.push(id);
570
571 Ok(())
572 }
573
574 fn define_data(&mut self, id: DataId, data: &DataDescription) -> ModuleResult<()> {
575 let decl = self.declarations.get_data_decl(id);

Callers

nothing calls this directly

Calls 15

OkFunction · 0.85
get_function_declMethod · 0.80
is_definableMethod · 0.80
into_ownedMethod · 0.80
linkage_nameMethod · 0.80
symbol_alignmentMethod · 0.80
newFunction · 0.50
is_noneMethod · 0.45
maxMethod · 0.45
function_alignmentMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected