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

Method define_data

cranelift/jit/src/backend.rs:574–656  ·  view source on GitHub ↗
(&mut self, id: DataId, data: &DataDescription)

Source from the content-addressed store, hash-verified

572 }
573
574 fn define_data(&mut self, id: DataId, data: &DataDescription) -> ModuleResult<()> {
575 let decl = self.declarations.get_data_decl(id);
576 if !decl.linkage.is_definable() {
577 return Err(ModuleError::InvalidImportDefinition(
578 decl.linkage_name(id).into_owned(),
579 ));
580 }
581
582 if !self.compiled_data_objects[id].is_none() {
583 return Err(ModuleError::DuplicateDefinition(
584 decl.linkage_name(id).into_owned(),
585 ));
586 }
587
588 assert!(!decl.tls, "JIT doesn't yet support TLS");
589
590 let &DataDescription {
591 ref init,
592 function_decls: _,
593 data_decls: _,
594 function_relocs: _,
595 data_relocs: _,
596 custom_segment_section: _,
597 align,
598 used: _,
599 } = data;
600
601 let (align, kind) = if decl.writable {
602 (
603 align.unwrap_or(WRITABLE_DATA_ALIGNMENT),
604 JITMemoryKind::Writable,
605 )
606 } else {
607 (
608 align.unwrap_or(READONLY_DATA_ALIGNMENT),
609 JITMemoryKind::ReadOnly,
610 )
611 };
612
613 let pointer_reloc = match self.isa.triple().pointer_width().unwrap() {
614 PointerWidth::U16 => panic!(),
615 PointerWidth::U32 => Reloc::Abs4,
616 PointerWidth::U64 => Reloc::Abs8,
617 };
618 let relocs = data.all_relocs(pointer_reloc).collect::<Vec<_>>();
619
620 self.compiled_data_objects[id] = Some(match *init {
621 Init::Uninitialized => {
622 panic!("data is not initialized yet");
623 }
624 Init::Zeros { size } => CompiledBlob::new_zeroed(
625 &mut *self.memory,
626 size.max(1),
627 align,
628 relocs,
629 #[cfg(feature = "wasmtime-unwinder")]
630 None,
631 kind,

Callers 1

empty_data_objectFunction · 0.45

Calls 14

OkFunction · 0.85
get_data_declMethod · 0.80
is_definableMethod · 0.80
into_ownedMethod · 0.80
linkage_nameMethod · 0.80
all_relocsMethod · 0.80
newFunction · 0.50
is_noneMethod · 0.45
unwrapMethod · 0.45
pointer_widthMethod · 0.45
tripleMethod · 0.45
maxMethod · 0.45

Tested by 1

empty_data_objectFunction · 0.36