Skip to content

Commit

Permalink
Change to copy function in read_region (#730)
Browse files Browse the repository at this point in the history
On behalf of @slave5vw
  • Loading branch information
maurolacy committed Jan 21, 2021
1 parent 9400c62 commit c87181e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/vm/src/memory.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::ptr;
use wasmer::{Array, ValueType, WasmPtr};

use crate::conversion::to_u32;
Expand Down Expand Up @@ -39,12 +40,11 @@ pub fn read_region(memory: &wasmer::Memory, ptr: u32, max_length: usize) -> VmRe

match WasmPtr::<u8, Array>::new(region.offset).deref(memory, 0, region.length) {
Some(cells) => {
// In case you want to do some premature optimization, this shows how to cast a `&'mut [Cell<u8>]` to `&mut [u8]`:
// https://github.com/wasmerio/wasmer/blob/0.13.1/lib/wasi/src/syscalls/mod.rs#L79-L81
let raw_cells = cells as *const [_] as *const u8;
let len = region.length as usize;
let mut result = vec![0u8; len];
for i in 0..len {
result[i] = cells[i].get();
unsafe{
ptr::copy(raw_cells, result.as_mut_ptr(), len);
}
Ok(result)
}
Expand Down

0 comments on commit c87181e

Please sign in to comment.