Skip to content

[Wasm64] Fix creation of 64-bit memories from JS #20111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions test/core/test_module_wasm_memory64.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright 2019 The Emscripten Authors. All rights reserved.
* Emscripten is available under two separate licenses, the MIT license and the
* University of Illinois/NCSA Open Source License. Both these licenses can be
* found in the LICENSE file.
*/

Module['wasmMemory'] = new WebAssembly.Memory({ 'initial': 256, 'maximum': 256, 'index': 'u64' });
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
6 changes: 4 additions & 2 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2440,7 +2440,10 @@ def test_aborting_new(self, args):
@no_4gb('depends on memory size')
@no_2gb('depends on memory size')
def test_module_wasm_memory(self):
self.emcc_args += ['--pre-js', test_file('core/test_module_wasm_memory.js')]
if self.get_setting('MEMORY64') == 1:
self.emcc_args += ['--pre-js', test_file('core/test_module_wasm_memory64.js')]
else:
self.emcc_args += ['--pre-js', test_file('core/test_module_wasm_memory.js')]
self.set_setting('IMPORTED_MEMORY')
self.do_runf(test_file('core/test_module_wasm_memory.c'), 'success')

Expand Down Expand Up @@ -8489,7 +8492,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