Skip to content

Commit 28bd282

Browse files
authored
Always emit a "maximum" clause for WebAssembly.Memory (#14178)
It seems like we don't need it for 4GB, but VMs complain. See #14130 (We also definitely need it for pthreads.) Fixes #14130
1 parent 0e05ab9 commit 28bd282

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/runtime_init_memory.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ if (ENVIRONMENT_IS_PTHREAD) {
2323
#endif
2424
{
2525
wasmMemory = new WebAssembly.Memory({
26-
'initial': INITIAL_MEMORY / {{{ WASM_PAGE_SIZE }}}
26+
'initial': INITIAL_MEMORY / {{{ WASM_PAGE_SIZE }}},
2727
#if ALLOW_MEMORY_GROWTH
28-
#if MAXIMUM_MEMORY != FOUR_GB
29-
,
28+
// In theory we should not need to emit the maximum if we want "unlimited"
29+
// or 4GB of memory, but VMs error on that atm, see
30+
// https://github.com/emscripten-core/emscripten/issues/14130
31+
// And in the pthreads case we definitely need to emit a maximum. So
32+
// always emit one.
3033
'maximum': {{{ MAXIMUM_MEMORY }}} / {{{ WASM_PAGE_SIZE }}}
31-
#endif
3234
#else
33-
,
3435
'maximum': INITIAL_MEMORY / {{{ WASM_PAGE_SIZE }}}
3536
#endif // ALLOW_MEMORY_GROWTH
3637
#if USE_PTHREADS

tests/test_core.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3860,6 +3860,11 @@ def test_missing_signatures(self):
38603860
(int)&emscripten_run_script );
38613861
}''')
38623862
self.set_setting('MAIN_MODULE', 1)
3863+
# also test main module with 4GB of memory. we need to emit a "maximum"
3864+
# clause then, even though 4GB is the maximum; see
3865+
# https://github.com/emscripten-core/emscripten/issues/14130
3866+
self.set_setting('ALLOW_MEMORY_GROWTH', '1')
3867+
self.set_setting('MAXIMUM_MEMORY', '4GB')
38633868
self.do_runf('test_sig.c', '')
38643869

38653870
@needs_dylink

0 commit comments

Comments
 (0)