/// Create a new `ModuleMemFds` for the given module. This can be
/// passed in as part of a `InstanceAllocationRequest` to speed up
/// instantiation and execution by using memfd-backed memories.
Create a new `ModuleMemFds` for the given module. This can be
passed in as part of a `InstanceAllocationRequest` to speed up
instantiation and execution by using memfd-backed memories.
Create a new ` ModuleMemFds ` for the given module . This can be passed in as part of a ` InstanceAllocationRequest ` to speed up instantiation and execution by using memfd - backed memories .
pub fn new(
        module: &Module,
        wasm_data: &[u8],
        mmap: Option<&MmapVec>,
    ) -> Result<Option<ModuleMemFds>> {
        let map = match &module.memory_initialization {
            MemoryInitialization::Static { map } => map,
            _ => return Ok(None),
        };
        let mut memories = PrimaryMap::with_capacity(map.len());
        let page_size = region::page::size() as u32;
        for (memory_index, init) in map {
            // mmap-based-initialization only works for defined memories with a
            // known starting point of all zeros, so bail out if the mmeory is
            // imported.
            let defined_memory = match module.defined_memory_index(memory_index) {
                Some(idx) => idx,
                None => return Ok(None),
            };
            // If there's no initialization for this memory known then we don't
            // need an image for the memory so push `None` and move on.
            let init = match init {
                Some(init) => init,
                None => {
                    memories.push(None);
                    continue;
                }
            };
            // Get the image for this wasm module  as a subslice of `wasm_data`,
            // and then use that to try to create the `MemoryMemFd`. If this
            // creation files then we fail creating `ModuleMemFds` since this
            // memory couldn't be represented.
            let data = &wasm_data[init.data.start as usize..init.data.end as usize];
            let memfd = match MemoryMemFd::new(page_size, init.offset, data, mmap)? {
                Some(memfd) => memfd,
                None => return Ok(None),
            };
            let idx = memories.push(Some(Arc::new(memfd)));
            assert_eq!(idx, defined_memory);
        }
        Ok(Some(ModuleMemFds { memories }))
    }
pub fn new ( module : & Module , wasm_data : & [ u8 ] , mmap : Option < & MmapVec > , ) -> Result < Option < ModuleMemFds > > { let map = match & module . memory_initialization { MemoryInitialization :: Static { map } => map , _ => return Ok ( None ) , } ; let mut memories = PrimaryMap :: with_capacity ( map . len ( ) ) ; let page_size = region :: page :: size ( ) as u32 ; for ( memory_index , init ) in map { // mmap-based-initialization only works for defined memories with a // known starting point of all zeros, so bail out if the mmeory is // imported. let defined_memory = match module . defined_memory_index ( memory_index ) { Some ( idx ) => idx , None => return Ok ( None ) , } ; // If there's no initialization for this memory known then we don't // need an image for the memory so push `None` and move on. let init = match init { Some ( init ) => init , None => { memories . push ( None ) ; continue ; } } ; // Get the image for this wasm module  as a subslice of `wasm_data`, // and then use that to try to create the `MemoryMemFd`. If this // creation files then we fail creating `ModuleMemFds` since this // memory couldn't be represented. let data = & wasm_data [ init . data . start as usize .. init . data . end as usize ] ; let memfd = match MemoryMemFd :: new ( page_size , init . offset , data , mmap ) ? { Some ( memfd ) => memfd , None => return Ok ( None ) , } ; let idx = memories . push ( Some ( Arc :: new ( memfd ) ) ) ; assert_eq ! ( idx defined_memory ) ; } Ok ( Some ( ModuleMemFds { memories } ) ) }
Create a new `ModuleMemFds` for the given module.
Create a new ` ModuleMemFds ` for the given module .
module
&Module
wasm_data
&[u8]
mmap
Option<&MmapVec>