Skip to content

Commit 38cad97

Browse files
authored
Use toIndexType in minimal runtime (#22724)
This fixes the MINIMAL_RUNTIME + MEMORY64 + IMPORTED_MEMORY. See #22497
1 parent c4b200c commit 38cad97

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ addToLibrary({
20062006
#endif
20072007
// In -Os and -Oz builds, do not implement a JS side wasm table mirror for small
20082008
// code size, but directly access wasmTable, which is a bit slower as uncached.
2009-
return wasmTable.get(funcPtr);
2009+
return wasmTable.get({{{ toIndexType('funcPtr') }}});
20102010
},
20112011
#endif // SHRINK_LEVEL == 0
20122012

src/preamble_minimal.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ var HEAP8, HEAP16, HEAP32, HEAPU8, HEAPU16, HEAPU32, HEAPF32, HEAPF64,
6161
#endif
6262

6363
#if IMPORTED_MEMORY
64+
// This code is largely a duplcate of src/runtime_init_memory.js
65+
// TODO(sbc): merge these two.
6466
#if PTHREADS
6567
if (!ENVIRONMENT_IS_PTHREAD) {
6668
#endif
@@ -69,10 +71,17 @@ if (!ENVIRONMENT_IS_PTHREAD) {
6971
Module['mem'] ||
7072
#endif
7173
new WebAssembly.Memory({
72-
'initial': {{{ INITIAL_MEMORY / WASM_PAGE_SIZE }}},
73-
#if SHARED_MEMORY || !ALLOW_MEMORY_GROWTH || MAXIMUM_MEMORY != FOUR_GB
74-
'maximum': {{{ (ALLOW_MEMORY_GROWTH && MAXIMUM_MEMORY != FOUR_GB ? MAXIMUM_MEMORY : INITIAL_MEMORY) / WASM_PAGE_SIZE }}},
75-
#endif
74+
'initial': {{{ toIndexType(`${INITIAL_MEMORY} / ${WASM_PAGE_SIZE}`) }}},
75+
#if ALLOW_MEMORY_GROWTH
76+
// In theory we should not need to emit the maximum if we want "unlimited"
77+
// or 4GB of memory, but VMs error on that atm, see
78+
// https://github.com/emscripten-core/emscripten/issues/14130
79+
// And in the pthreads case we definitely need to emit a maximum. So
80+
// always emit one.
81+
'maximum': {{{ toIndexType(MAXIMUM_MEMORY / WASM_PAGE_SIZE) }}},
82+
#else
83+
'maximum': {{{ toIndexType(`${INITIAL_MEMORY} / ${WASM_PAGE_SIZE}`) }}},
84+
#endif // ALLOW_MEMORY_GROWTH
7685
#if SHARED_MEMORY
7786
'shared': true,
7887
#endif

0 commit comments

Comments
 (0)