Skip to content

Commit 8b39774

Browse files
committed
[wasm64] Fix for bad Memory initial size under firefox
Recent versions of firefox started requiring bigint values for initial and max memory. See WebAssembly/memory64#68 Fixes: #22486
1 parent 4036606 commit 8b39774

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

.circleci/config.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,15 @@ jobs:
828828
# browser.test_webgl_offscreen_canvas_in_mainthread_after_pthread
829829
# are crashing Firefox (bugzil.la/1281796). The former case is
830830
# further blocked by issue #6897.
831-
test_targets: "browser skip:browser.test_sdl2_mouse skip:browser.test_html5_webgl_create_context skip:browser.test_webgl_offscreen_canvas_in_pthread skip:browser.test_webgl_offscreen_canvas_in_mainthread_after_pthread skip:browser.test_glut_glutget"
831+
test_targets: "
832+
browser64.test_dylink_many
833+
browser
834+
skip:browser.test_sdl2_mouse
835+
skip:browser.test_html5_webgl_create_context
836+
skip:browser.test_webgl_offscreen_canvas_in_pthread
837+
skip:browser.test_webgl_offscreen_canvas_in_mainthread_after_pthread
838+
skip:browser.test_glut_glutget
839+
"
832840
# TODO(sbc): Re-enable once we figure out why the emrun tests are
833841
# locking up.
834842
#test-browser-chrome-emrun:

src/parseTools.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,13 @@ function ENVIRONMENT_IS_MAIN_THREAD() {
10891089
return '(!(' + envs.join('||') + '))';
10901090
}
10911091

1092+
function memoryBounds(val) {
1093+
if (MEMORY64 == 1) {
1094+
return `toMemoryBounds(${val})`
1095+
}
1096+
return val;
1097+
}
1098+
10921099
addToCompileTimeContext({
10931100
ATEXITS,
10941101
ATINITS,
@@ -1141,6 +1148,7 @@ addToCompileTimeContext({
11411148
makeReturn64,
11421149
makeSetValue,
11431150
makeThrow,
1151+
memoryBounds,
11441152
modifyJSFunction,
11451153
receiveI64ParamAsI53,
11461154
receiveI64ParamAsI53Unchecked,

src/runtime_init_memory.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,31 @@ if (!ENVIRONMENT_IS_PTHREAD) {
2525

2626
#if ASSERTIONS
2727
assert(INITIAL_MEMORY >= {{{STACK_SIZE}}}, 'INITIAL_MEMORY should be larger than STACK_SIZE, was ' + INITIAL_MEMORY + '! (STACK_SIZE=' + {{{STACK_SIZE}}} + ')');
28+
#endif
29+
#if MEMORY64 == 1
30+
// Probe for support of bigint bounds with memory64.
31+
// TODO(sbc): Remove this once all browsers start requiring bigint here.
32+
// See https://github.com/WebAssembly/memory64/issues/68
33+
var bigintMemoryBounds = 1;
34+
try {
35+
new WebAssembly.Memory({'initial': 1n, 'index': 'i64'})
36+
} catch (e) {
37+
console.log(e);
38+
bigintMemoryBounds = 0;
39+
}
40+
var toMemoryBounds = (i) => bigintMemoryBounds ? BigInt(i) : i;
2841
#endif
2942
wasmMemory = new WebAssembly.Memory({
30-
'initial': INITIAL_MEMORY / {{{ WASM_PAGE_SIZE }}},
43+
'initial': {{{ memoryBounds(`INITIAL_MEMORY / ${WASM_PAGE_SIZE}`) }}},
3144
#if ALLOW_MEMORY_GROWTH
3245
// In theory we should not need to emit the maximum if we want "unlimited"
3346
// or 4GB of memory, but VMs error on that atm, see
3447
// https://github.com/emscripten-core/emscripten/issues/14130
3548
// And in the pthreads case we definitely need to emit a maximum. So
3649
// always emit one.
37-
'maximum': {{{ MAXIMUM_MEMORY }}} / {{{ WASM_PAGE_SIZE }}},
50+
'maximum': {{{ memoryBounds(MAXIMUM_MEMORY / WASM_PAGE_SIZE }}},
3851
#else
39-
'maximum': INITIAL_MEMORY / {{{ WASM_PAGE_SIZE }}},
52+
'maximum': {{{ memoryBounds(`INITIAL_MEMORY / ${WASM_PAGE_SIZE}`) }}},
4053
#endif // ALLOW_MEMORY_GROWTH
4154
#if SHARED_MEMORY
4255
'shared': true,

0 commit comments

Comments
 (0)