Skip to content

Commit 0c35c4a

Browse files
authored
[Wasm64] Fix creation of 64-bit memories from JS (#20111)
This enables quite a few tests that were previously disabled. The extra check for `navigator.userAgent` is because node added support for the navigator object: nodejs/node#47769. This change is also part of #19959, which could land instead.
1 parent 597d849 commit 0c35c4a

9 files changed

+23
-16
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ commands:
109109
description: "install canary version of node"
110110
steps:
111111
- install-node-version:
112-
node_version: "20.0.0-v8-canary2023041819be670741"
112+
node_version: "21.0.0-v8-canary20230822f5e30d0702"
113113
canary: true
114114
install-v8:
115115
description: "install v8 using jsvu"

src/library_pthread.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,8 @@ var LibraryPThread = {
10421042
$establishStackSpace__internal: true,
10431043
$establishStackSpace: () => {
10441044
var pthread_ptr = _pthread_self();
1045-
var stackHigh = {{{ makeGetValue('pthread_ptr', C_STRUCTS.pthread.stack, 'i32') }}};
1046-
var stackSize = {{{ makeGetValue('pthread_ptr', C_STRUCTS.pthread.stack_size, 'i32') }}};
1045+
var stackHigh = {{{ makeGetValue('pthread_ptr', C_STRUCTS.pthread.stack, '*') }}};
1046+
var stackSize = {{{ makeGetValue('pthread_ptr', C_STRUCTS.pthread.stack_size, '*') }}};
10471047
var stackLow = stackHigh - stackSize;
10481048
#if PTHREADS_DEBUG
10491049
dbg(`establishStackSpace: ${ptrToString(stackHigh)} -> ${ptrToString(stackLow)}`);

src/library_wasm_worker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ if (ENVIRONMENT_IS_WASM_WORKER) {
244244
// https://github.com/tc39/proposal-atomics-wait-async/blob/master/PROPOSAL.md
245245
// This polyfill performs polling with setTimeout() to observe a change in the
246246
// target memory location.
247-
emscripten_atomic_wait_async__postset: `if (!Atomics.waitAsync || (typeof navigator !== 'undefined' && jstoi_q((navigator.userAgent.match(/Chrom(e|ium)\\/([0-9]+)\\./)||[])[2]) < 91)) {
247+
emscripten_atomic_wait_async__postset: `if (!Atomics.waitAsync || (typeof navigator !== 'undefined' && navigator.userAgent && jstoi_q((navigator.userAgent.match(/Chrom(e|ium)\\/([0-9]+)\\./)||[])[2]) < 91)) {
248248
let __Atomics_waitAsyncAddresses = [/*[i32a, index, value, maxWaitMilliseconds, promiseResolve]*/];
249249
function __Atomics_pollWaitAsyncAddresses() {
250250
let now = performance.now();

src/runtime_init_memory.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ if (ENVIRONMENT_IS_PTHREAD) {
3535
// https://github.com/emscripten-core/emscripten/issues/14130
3636
// And in the pthreads case we definitely need to emit a maximum. So
3737
// always emit one.
38-
'maximum': {{{ MAXIMUM_MEMORY }}} / {{{ WASM_PAGE_SIZE }}}
38+
'maximum': {{{ MAXIMUM_MEMORY }}} / {{{ WASM_PAGE_SIZE }}},
3939
#else
40-
'maximum': INITIAL_MEMORY / {{{ WASM_PAGE_SIZE }}}
40+
'maximum': INITIAL_MEMORY / {{{ WASM_PAGE_SIZE }}},
4141
#endif // ALLOW_MEMORY_GROWTH
4242
#if SHARED_MEMORY
43-
,
44-
'shared': true
43+
'shared': true,
44+
#endif
45+
#if MEMORY64 == 1
46+
'index': 'u64',
4547
#endif
4648
});
4749
#if SHARED_MEMORY

test/common.py

-4
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,6 @@ def setup_node_pthreads(self):
713713
self.emcc_args += ['-Wno-pthreads-mem-growth', '-pthread']
714714
if self.get_setting('MINIMAL_RUNTIME'):
715715
self.skipTest('node pthreads not yet supported with MINIMAL_RUNTIME')
716-
# Pthread support requires IMPORTED_MEMORY which depends on the JS API
717-
# for creating 64-bit memories.
718-
if self.get_setting('GLOBAL_BASE') == '4gb':
719-
self.skipTest('no support for IMPORTED_MEMORY over 4gb yet')
720716
self.js_engines = [config.NODE_JS]
721717
self.node_args += shared.node_pthread_flags()
722718

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright 2019 The Emscripten Authors. All rights reserved.
3+
* Emscripten is available under two separate licenses, the MIT license and the
4+
* University of Illinois/NCSA Open Source License. Both these licenses can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
Module['wasmMemory'] = new WebAssembly.Memory({ 'initial': 256, 'maximum': 256, 'index': 'u64' });

test/pthread/test_pthread_attr_getstack.c

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ void TestStack() {
1818
void *stbase;
1919
size_t stsize;
2020
char dummy;
21-
intptr_t result;
2221

2322
rc = pthread_attr_init(&attr);
2423
assert(rc == 0);

test/pthread/test_pthread_proxying_canceled_work.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void set_flag(void* flag) {
3939
// because this code needs to run after the thread runtime has exited.
4040

4141
// clang-format off
42-
EM_ASM({setTimeout(() => Atomics.store(HEAP32, $0 >>> 2, 1))}, flag);
42+
EM_ASM({setTimeout(() => Atomics.store(HEAP32, $0 / 4, 1))}, flag);
4343
// clang-format on
4444
}
4545

test/test_core.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,10 @@ def test_aborting_new(self, args):
24402440
@no_4gb('depends on memory size')
24412441
@no_2gb('depends on memory size')
24422442
def test_module_wasm_memory(self):
2443-
self.emcc_args += ['--pre-js', test_file('core/test_module_wasm_memory.js')]
2443+
if self.get_setting('MEMORY64') == 1:
2444+
self.emcc_args += ['--pre-js', test_file('core/test_module_wasm_memory64.js')]
2445+
else:
2446+
self.emcc_args += ['--pre-js', test_file('core/test_module_wasm_memory.js')]
24442447
self.set_setting('IMPORTED_MEMORY')
24452448
self.do_runf(test_file('core/test_module_wasm_memory.c'), 'success')
24462449

@@ -8490,7 +8493,6 @@ def test_pthread_join_and_asyncify(self):
84908493
'conditional': (True,),
84918494
'unconditional': (False,),
84928495
})
8493-
@no_4gb('uses imported memory')
84948496
def test_emscripten_lazy_load_code(self, conditional):
84958497
if self.get_setting('STACK_OVERFLOW_CHECK'):
84968498
self.skipTest('https://github.com/emscripten-core/emscripten/issues/16828')

0 commit comments

Comments
 (0)