Skip to content

Commit

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

See #22497
  • Loading branch information
sbc100 authored Oct 11, 2024
1 parent c4b200c commit 38cad97
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ addToLibrary({
#endif
// In -Os and -Oz builds, do not implement a JS side wasm table mirror for small
// code size, but directly access wasmTable, which is a bit slower as uncached.
return wasmTable.get(funcPtr);
return wasmTable.get({{{ toIndexType('funcPtr') }}});
},
#endif // SHRINK_LEVEL == 0

Expand Down
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 38cad97

Please sign in to comment.