update wasmer to 2.2.1

This commit is contained in:
Anton-4 2022-05-03 18:00:29 +02:00
parent bb5c260d2e
commit cc28de408c
No known key found for this signature in database
GPG key ID: C954D6E0F9C0ABFD
7 changed files with 349 additions and 174 deletions

View file

@ -1,5 +1,6 @@
use roc_gen_wasm::wasm32_sized::Wasm32Sized;
use roc_std::{ReferenceCount, RocDec, RocList, RocOrder, RocStr};
use std::convert::TryInto;
pub trait FromWasmerMemory: Wasm32Sized {
fn decode(memory: &wasmer::Memory, offset: u32) -> Self;
@ -17,9 +18,9 @@ macro_rules! from_wasm_memory_primitive_decode {
let raw_ptr = ptr as *mut u8;
let slice = unsafe { std::slice::from_raw_parts_mut(raw_ptr, width) };
let ptr: wasmer::WasmPtr<u8, wasmer::Array> = wasmer::WasmPtr::new(offset);
let foobar = (ptr.deref(memory, 0, width as u32)).unwrap();
let wasm_slice = unsafe { std::mem::transmute(foobar) };
let memory_bytes: &[u8] = unsafe { memory.data_unchecked() };
let index = offset as usize;
let wasm_slice = &memory_bytes[index..][..width];
slice.copy_from_slice(wasm_slice);
@ -108,12 +109,16 @@ impl<T: FromWasmerMemory> FromWasmerMemory for &'_ T {
impl<T: FromWasmerMemory + Clone, const N: usize> FromWasmerMemory for [T; N] {
fn decode(memory: &wasmer::Memory, offset: u32) -> Self {
let ptr: wasmer::WasmPtr<u8, wasmer::Array> = wasmer::WasmPtr::new(offset);
let width = <T as Wasm32Sized>::SIZE_OF_WASM as u32 * N as u32;
let foobar = (ptr.deref(memory, 0, width)).unwrap();
let wasm_slice: &[T; N] = unsafe { &*(foobar as *const _ as *const [T; N]) };
let memory_bytes: &[u8] = unsafe { memory.data_unchecked() };
let index = offset as usize;
wasm_slice.clone()
debug_assert!(memory_bytes.len() >= index + (N * <T as Wasm32Sized>::SIZE_OF_WASM));
let slice_bytes: &[u8] = &memory_bytes[index..][..N];
let slice: &[T] = unsafe { std::mem::transmute(slice_bytes) };
let array: &[T; N] = slice.try_into().expect("incorrect length");
array.clone()
}
}

View file

@ -414,13 +414,14 @@ fn wasm_roc_panic(address: u32, tag_id: u32) {
MEMORY.with(|f| {
let memory = f.borrow().unwrap();
let ptr: wasmer::WasmPtr<u8, wasmer::Array> = wasmer::WasmPtr::new(address);
let width = 100;
let c_ptr = (ptr.deref(memory, 0, width)).unwrap();
let memory_bytes: &[u8] = unsafe { memory.data_unchecked() };
let index = address as usize;
let slice = &memory_bytes[index..];
let c_ptr: *const u8 = slice.as_ptr();
use std::ffi::CStr;
use std::os::raw::c_char;
let slice = unsafe { CStr::from_ptr(c_ptr as *const _ as *const c_char) };
let slice = unsafe { CStr::from_ptr(c_ptr as *const c_char) };
string = slice.to_str().unwrap();
});

View file

@ -1,4 +1,3 @@
use core::cell::Cell;
use roc_gen_wasm::wasm_module::{Export, ExportType};
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
@ -280,7 +279,7 @@ where
// Read the actual refcount values
let refcount_ptr_array: WasmPtr<WasmPtr<i32>, wasmer::Array> =
WasmPtr::new(4 + refcount_vector_addr as u32);
let refcount_ptrs: &[Cell<WasmPtr<i32>>] = refcount_ptr_array
let refcount_ptrs = refcount_ptr_array
.deref(memory, 0, num_refcounts as u32)
.unwrap();