Skip to content

Commit

Permalink
[Wasm64] Fix creation of 64-bit memories from JS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sbc100 committed Aug 23, 2023
1 parent fd743d1 commit 020b0f4
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ commands:
description: "install canary version of node"
steps:
- install-node-version:
node_version: "20.0.0-v8-canary2023041819be670741"
node_version: "21.0.0-v8-canary20230822f5e30d0702"
canary: true
install-v8:
description: "install v8 using jsvu"
Expand Down
4 changes: 2 additions & 2 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,8 @@ var LibraryPThread = {
$establishStackSpace__internal: true,
$establishStackSpace: () => {
var pthread_ptr = _pthread_self();
var stackHigh = {{{ makeGetValue('pthread_ptr', C_STRUCTS.pthread.stack, 'i32') }}};
var stackSize = {{{ makeGetValue('pthread_ptr', C_STRUCTS.pthread.stack_size, 'i32') }}};
var stackHigh = {{{ makeGetValue('pthread_ptr', C_STRUCTS.pthread.stack, '*') }}};
var stackSize = {{{ makeGetValue('pthread_ptr', C_STRUCTS.pthread.stack_size, '*') }}};
var stackLow = stackHigh - stackSize;
#if PTHREADS_DEBUG
dbg(`establishStackSpace: ${ptrToString(stackHigh)} -> ${ptrToString(stackLow)}`);
Expand Down
2 changes: 1 addition & 1 deletion src/library_wasm_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ if (ENVIRONMENT_IS_WASM_WORKER) {
// https://github.com/tc39/proposal-atomics-wait-async/blob/master/PROPOSAL.md
// This polyfill performs polling with setTimeout() to observe a change in the
// target memory location.
emscripten_atomic_wait_async__postset: `if (!Atomics.waitAsync || (typeof navigator !== 'undefined' && jstoi_q((navigator.userAgent.match(/Chrom(e|ium)\\/([0-9]+)\\./)||[])[2]) < 91)) {
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)) {
let __Atomics_waitAsyncAddresses = [/*[i32a, index, value, maxWaitMilliseconds, promiseResolve]*/];
function __Atomics_pollWaitAsyncAddresses() {
let now = performance.now();
Expand Down
10 changes: 6 additions & 4 deletions src/runtime_init_memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ if (ENVIRONMENT_IS_PTHREAD) {
// 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': {{{ MAXIMUM_MEMORY }}} / {{{ WASM_PAGE_SIZE }}}
'maximum': {{{ MAXIMUM_MEMORY }}} / {{{ WASM_PAGE_SIZE }}},
#else
'maximum': INITIAL_MEMORY / {{{ WASM_PAGE_SIZE }}}
'maximum': INITIAL_MEMORY / {{{ WASM_PAGE_SIZE }}},
#endif // ALLOW_MEMORY_GROWTH
#if SHARED_MEMORY
,
'shared': true
'shared': true,
#endif
#if MEMORY64 == 1
'index': 'u64',
#endif
});
#if SHARED_MEMORY
Expand Down
4 changes: 0 additions & 4 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,6 @@ def setup_node_pthreads(self):
self.emcc_args += ['-Wno-pthreads-mem-growth', '-pthread']
if self.get_setting('MINIMAL_RUNTIME'):
self.skipTest('node pthreads not yet supported with MINIMAL_RUNTIME')
# Pthread support requires IMPORTED_MEMORY which depends on the JS API
# for creating 64-bit memories.
if self.get_setting('GLOBAL_BASE') == '4gb':
self.skipTest('no support for IMPORTED_MEMORY over 4gb yet')
self.js_engines = [config.NODE_JS]
self.node_args += shared.node_pthread_flags()

Expand Down
1 change: 0 additions & 1 deletion test/pthread/test_pthread_attr_getstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ void TestStack() {
void *stbase;
size_t stsize;
char dummy;
intptr_t result;

rc = pthread_attr_init(&attr);
assert(rc == 0);
Expand Down
2 changes: 1 addition & 1 deletion test/pthread/test_pthread_proxying_canceled_work.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void set_flag(void* flag) {
// because this code needs to run after the thread runtime has exited.

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

Expand Down
1 change: 0 additions & 1 deletion test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8489,7 +8489,6 @@ def test_pthread_join_and_asyncify(self):
'conditional': (True,),
'unconditional': (False,),
})
@no_4gb('uses imported memory')
def test_emscripten_lazy_load_code(self, conditional):
if self.get_setting('STACK_OVERFLOW_CHECK'):
self.skipTest('https://github.com/emscripten-core/emscripten/issues/16828')
Expand Down

0 comments on commit 020b0f4

Please sign in to comment.