| 30 | |
| 31 | impl CompiledBlob { |
| 32 | pub(crate) fn new( |
| 33 | memory: &mut dyn JITMemoryProvider, |
| 34 | data: &[u8], |
| 35 | align: u64, |
| 36 | relocs: Vec<ModuleReloc>, |
| 37 | #[cfg(feature = "wasmtime-unwinder")] wasmtime_exception_data: Option<Vec<u8>>, |
| 38 | kind: JITMemoryKind, |
| 39 | ) -> ModuleResult<Self> { |
| 40 | // Reserve veneers for all function calls just in case |
| 41 | let mut veneer_count = 0; |
| 42 | for reloc in &relocs { |
| 43 | match reloc.kind { |
| 44 | Reloc::Arm64Call => veneer_count += 1, |
| 45 | _ => {} |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | let ptr = memory |
| 50 | .allocate(data.len() + veneer_count * VENEER_SIZE, align, kind) |
| 51 | .map_err(|e| ModuleError::Allocation { err: e })?; |
| 52 | |
| 53 | unsafe { |
| 54 | ptr::copy_nonoverlapping(data.as_ptr(), ptr, data.len()); |
| 55 | } |
| 56 | |
| 57 | Ok(CompiledBlob { |
| 58 | ptr, |
| 59 | size: data.len(), |
| 60 | relocs, |
| 61 | veneer_count, |
| 62 | #[cfg(feature = "wasmtime-unwinder")] |
| 63 | wasmtime_exception_data, |
| 64 | }) |
| 65 | } |
| 66 | |
| 67 | pub(crate) fn new_zeroed( |
| 68 | memory: &mut dyn JITMemoryProvider, |