@@ -19,8 +19,8 @@ use std::convert::TryFrom;
19
19
use std:: mem;
20
20
use std:: sync:: Mutex ;
21
21
use wasmtime_environ:: {
22
- DefinedMemoryIndex , DefinedTableIndex , HostPtr , Module , PrimaryMap , Tunables , VMOffsets ,
23
- WASM_PAGE_SIZE ,
22
+ DefinedMemoryIndex , DefinedTableIndex , HostPtr , MemoryStyle , Module , PrimaryMap , Tunables ,
23
+ VMOffsets , WASM_PAGE_SIZE ,
24
24
} ;
25
25
26
26
mod index_allocator;
@@ -386,6 +386,20 @@ impl InstancePool {
386
386
. defined_memory_index ( memory_index)
387
387
. expect ( "should be a defined memory since we skipped imported ones" ) ;
388
388
389
+ match plan. style {
390
+ MemoryStyle :: Static { bound } => {
391
+ let bound = bound * u64:: from ( WASM_PAGE_SIZE ) ;
392
+ if bound < self . memories . static_memory_bound {
393
+ return Err ( InstantiationError :: Resource ( anyhow ! (
394
+ "static bound of {bound:x} bytes incompatible with \
395
+ reservation of {:x} bytes",
396
+ self . memories. static_memory_bound,
397
+ ) ) ) ;
398
+ }
399
+ }
400
+ MemoryStyle :: Dynamic { .. } => { }
401
+ }
402
+
389
403
let memory = unsafe {
390
404
std:: slice:: from_raw_parts_mut (
391
405
self . memories . get_base ( instance_index, defined_index) ,
@@ -658,6 +672,7 @@ struct MemoryPool {
658
672
initial_memory_offset : usize ,
659
673
max_memories : usize ,
660
674
max_instances : usize ,
675
+ static_memory_bound : u64 ,
661
676
}
662
677
663
678
impl MemoryPool {
@@ -679,15 +694,11 @@ impl MemoryPool {
679
694
) ;
680
695
}
681
696
682
- let memory_size = if instance_limits. memory_pages > 0 {
683
- usize:: try_from (
684
- u64:: from ( tunables. static_memory_bound ) * u64:: from ( WASM_PAGE_SIZE )
685
- + tunables. static_memory_offset_guard_size ,
686
- )
687
- . map_err ( |_| anyhow ! ( "memory reservation size exceeds addressable memory" ) ) ?
688
- } else {
689
- 0
690
- } ;
697
+ let static_memory_bound =
698
+ u64:: from ( tunables. static_memory_bound ) * u64:: from ( WASM_PAGE_SIZE ) ;
699
+ let memory_size =
700
+ usize:: try_from ( static_memory_bound + tunables. static_memory_offset_guard_size )
701
+ . map_err ( |_| anyhow ! ( "memory reservation size exceeds addressable memory" ) ) ?;
691
702
692
703
assert ! (
693
704
memory_size % crate :: page_size( ) == 0 ,
@@ -745,6 +756,7 @@ impl MemoryPool {
745
756
max_memories,
746
757
max_instances,
747
758
max_memory_size : ( instance_limits. memory_pages as usize ) * ( WASM_PAGE_SIZE as usize ) ,
759
+ static_memory_bound,
748
760
} ;
749
761
750
762
Ok ( pool)
0 commit comments