Skip to content

Commit

Permalink
Use toIndexType in minimal runtime
Browse files Browse the repository at this point in the history
This fixes the MINIMAL_RUNTIME + MEMORY64 + IMPORTED_MEMORY.

See emscripten-core#22497
  • Loading branch information
sbc100 committed Oct 11, 2024
1 parent c4b200c commit aa048a4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/preamble_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ var HEAP8, HEAP16, HEAP32, HEAPU8, HEAPU16, HEAPU32, HEAPF32, HEAPF64,
#endif

#if IMPORTED_MEMORY
// This code is largely a duplcate of src/runtime_init_memory.js
// TODO(sbc): merge these two.
#if PTHREADS
if (!ENVIRONMENT_IS_PTHREAD) {
#endif
Expand All @@ -69,10 +71,17 @@ if (!ENVIRONMENT_IS_PTHREAD) {
Module['mem'] ||
#endif
new WebAssembly.Memory({
'initial': {{{ INITIAL_MEMORY / WASM_PAGE_SIZE }}},
#if SHARED_MEMORY || !ALLOW_MEMORY_GROWTH || MAXIMUM_MEMORY != FOUR_GB
'maximum': {{{ (ALLOW_MEMORY_GROWTH && MAXIMUM_MEMORY != FOUR_GB ? MAXIMUM_MEMORY : INITIAL_MEMORY) / WASM_PAGE_SIZE }}},
#endif
'initial': {{{ toIndexType(`${INITIAL_MEMORY} / ${WASM_PAGE_SIZE}`) }}},
#if ALLOW_MEMORY_GROWTH
// In theory we should not need to emit the maximum if we want "unlimited"
// or 4GB of memory, but VMs error on that atm, see
// https://github.com/emscripten-core/emscripten/issues/14130
// And in the pthreads case we definitely need to emit a maximum. So
// always emit one.
'maximum': {{{ toIndexType(MAXIMUM_MEMORY / WASM_PAGE_SIZE) }}},
#else
'maximum': {{{ toIndexType(`${INITIAL_MEMORY} / ${WASM_PAGE_SIZE}`) }}},
#endif // ALLOW_MEMORY_GROWTH
#if SHARED_MEMORY
'shared': true,
#endif
Expand Down

0 comments on commit aa048a4

Please sign in to comment.