pub fn read_region(ctx: &Ctx, ptr: u32, max_length: usize) -> VmResult<Vec<u8>> {
    let region = get_region(ctx, ptr)?;

    if region.length > to_u32(max_length)? {
        return Err(
            CommunicationError::region_length_too_big(region.length as usize, max_length).into(),
        );
    }

    let memory = ctx.memory(0);
    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 len = region.length as usize;
            let mut result = vec![0u8; len];
            for i in 0..len {
                result[i] = cells[i].get();
            }
            Ok(result)
        }
        None => Err(CommunicationError::deref_err(region.offset, format!(
            "Tried to access memory of region {:?} in wasm memory of size {} bytes. This typically happens when the given Region pointer does not point to a proper Region struct.",
            region,
            memory.size().bytes().0
        )).into()),
    }
}
/// Expects a (fixed size) Region struct at ptr, which is read. This links to the
/// memory region, which is copied in the second step.
/// Errors if the length of the region exceeds `max_length`.
Expects a (fixed size) Region struct at ptr, which is read. This links to the
memory region, which is copied in the second step.
Errors if the length of the region exceeds `max_length`.
Expects a ( fixed size ) Region struct at ptr which is read . This links to the memory region which is copied in the second step . Errors if the length of the region exceeds ` max_length ` .
pub fn read_region(ctx: &Ctx, ptr: u32, max_length: usize) -> VmResult<Vec<u8>> {
    let region = get_region(ctx, ptr)?;
    if region.length > to_u32(max_length)? {
        return Err(
            CommunicationError::region_length_too_big(region.length as usize, max_length).into(),
        );
    }
    let memory = ctx.memory(0);
    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 len = region.length as usize;
            let mut result = vec![0u8; len];
            for i in 0..len {
                result[i] = cells[i].get();
            }
            Ok(result)
        }
        None => Err(CommunicationError::deref_err(region.offset, format!(
            "Tried to access memory of region {:?} in wasm memory of size {} bytes. This typically happens when the given Region pointer does not point to a proper Region struct.",
            region,
            memory.size().bytes().0
        )).into()),
    }
}
pub fn read_region ( ctx : & Ctx , ptr : u32 , max_length : usize ) -> VmResult < Vec < u8 > > { let region = get_region ( ctx , ptr ) ? ; if region . length > to_u32 ( max_length ) ? { return Err ( CommunicationError :: region_length_too_big ( region . length as usize , max_length ) . into ( ) , ) ; } let memory = ctx . memory ( 0 ) ; 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 len = region . length as usize ; let mut result = vec ! [ 0u8 len ] ; for i in 0 .. len { result [ i ] = cells [ i ] . get ( ) ; } Ok ( result ) } None => Err ( CommunicationError :: deref_err ( region . offset , format ! ( " " region memory size ( ) bytes ( ) 0 ) ) . into ( ) ) , } }
Expects a (fixed size) Region struct at ptr, which is read.
Expects a ( fixed size ) Region struct at ptr which is read .
ctx
&Ctx
ptr
u32
max_length
usize
ctx
&Ctx
ptr
u32
max_length
usize