@@ -2248,18 +2248,17 @@ void CWriter::WriteDataInitializers() {
22482248 Index memory_idx = module_->num_memory_imports ;
22492249 for (Index i = memory_idx; i < module_->memories .size (); i++) {
22502250 const Memory* memory = module_->memories [i];
2251- uint64_t max;
2252- if (memory->page_limits .has_max ) {
2253- max = memory->page_limits .max ;
2254- } else {
2255- max = memory->page_limits .is_64 ? (static_cast <uint64_t >(1 ) << 48 )
2256- : 65536 ;
2257- }
2251+ const uint64_t max =
2252+ memory->page_limits .has_max
2253+ ? memory->page_limits .max
2254+ : WABT_BYTES_TO_MIN_PAGES (
2255+ (memory->page_limits .is_64 ? UINT64_MAX : UINT32_MAX),
2256+ memory->page_size );
22582257 std::string func = GetMemoryAPIString (*memory, " wasm_rt_allocate_memory" );
2259- Write (func, " ( " ,
2260- ExternalInstancePtr (ModuleFieldType::Memory, memory->name ), " , " ,
2261- memory->page_limits .initial , " , " , max, " , " ,
2262- memory->page_limits .is_64 , " );" , Newline ());
2258+ Write (
2259+ func, " ( " , ExternalInstancePtr (ModuleFieldType::Memory, memory->name ),
2260+ " , " , memory->page_limits .initial , " , " , max, " , " ,
2261+ memory->page_limits .is_64 , " , " , memory-> page_size , " );" , Newline ());
22632262 }
22642263 }
22652264
@@ -2898,6 +2897,8 @@ void CWriter::WriteImportProperties(CWriterPhase kind) {
28982897 write_import_prop (import , " max" , " u64" ,
28992898 limits->has_max ? limits->max : default_max);
29002899 write_import_prop (import , " is64" , " u8" , limits->is_64 );
2900+ write_import_prop (import , " pagesize" , " u32" ,
2901+ cast<MemoryImport>(import )->memory .page_size );
29012902 } else if (import ->kind () == ExternalKind::Table) {
29022903 const Limits* limits = &(cast<TableImport>(import )->table .elem_limits );
29032904 const uint64_t default_max = std::numeric_limits<uint32_t >::max ();
0 commit comments