Skip to content

Commit cb5ca6e

Browse files
authored
[Wasm64] Allow testing of wasm64 + standalone (emscripten-core#18771)
1 parent e2918ae commit cb5ca6e

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

system/lib/standalone/standalone.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ int emscripten_resize_heap(size_t size) {
142142
assert(old_size < size);
143143
ssize_t diff = (size - old_size + WASM_PAGE_SIZE - 1) / WASM_PAGE_SIZE;
144144
size_t result = __builtin_wasm_memory_grow(0, diff);
145-
if (result != (size_t)-1) {
145+
// Its seems v8 has a bug in memory.grow that causes it to return
146+
// (uint32_t)-1 even with memory64:
147+
// https://bugs.chromium.org/p/v8/issues/detail?id=13948
148+
if (result != (uint32_t)-1 && result != (size_t)-1) {
146149
// Success, update JS (see https://github.com/WebAssembly/WASI/issues/82)
147150
emscripten_notify_memory_growth(0);
148151
return 1;

test/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ def require_engine(self, engine):
515515
self.skipTest(f'Skipping test that requires `{engine}` when `{self.required_engine}` was previously required')
516516
self.required_engine = engine
517517
self.js_engines = [engine]
518+
self.wasm_engines = []
518519

519520
def require_wasm64(self):
520521
if config.NODE_JS and config.NODE_JS in self.js_engines:

test/test_core.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,20 @@ def metafunc(self, rawfs):
156156
return metafunc
157157

158158

159-
def can_do_standalone(self):
159+
def can_do_wasm2c(self):
160+
# the npm version of wasm2c does not support MEMORY64
161+
return not self.get_setting('MEMORY64')
162+
163+
164+
def can_do_standalone(self, impure=False):
165+
# Pure standalone engines don't support MEMORY64 yet. Even with MEMORY64=2 (lowered)
166+
# the WASI APIs that take pointer values don't have 64-bit variants yet.
167+
if self.get_setting('MEMORY64') and not impure:
168+
return False
160169
return self.is_wasm() and \
161170
self.get_setting('STACK_OVERFLOW_CHECK', 0) < 2 and \
162171
not self.get_setting('MINIMAL_RUNTIME') and \
163172
not self.get_setting('SAFE_HEAP') and \
164-
not self.get_setting('MEMORY64') and \
165173
not any(a.startswith('-fsanitize=') for a in self.emcc_args)
166174

167175

@@ -202,7 +210,7 @@ def metafunc(self, standalone):
202210
if not standalone:
203211
func(self)
204212
else:
205-
if not can_do_standalone(self):
213+
if not can_do_standalone(self, impure):
206214
self.skipTest('Test configuration is not compatible with STANDALONE_WASM')
207215
self.set_setting('STANDALONE_WASM')
208216
# we will not legalize the JS ffi interface, so we must use BigInt
@@ -213,10 +221,9 @@ def metafunc(self, standalone):
213221
# if we are impure, disallow all wasm engines
214222
if impure:
215223
self.wasm_engines = []
216-
self.js_engines = [config.NODE_JS]
217224
self.node_args += shared.node_bigint_flags()
218225
func(self)
219-
if wasm2c:
226+
if wasm2c and can_do_wasm2c(self):
220227
print('wasm2c')
221228
self.set_setting('WASM2C')
222229
self.wasm_engines = []
@@ -7160,6 +7167,8 @@ def test_wasm2c_sandboxing(self, mode):
71607167
self.node_args += shared.node_bigint_flags()
71617168
if not can_do_standalone(self):
71627169
return self.skipTest('standalone mode not supported')
7170+
if not can_do_wasm2c(self):
7171+
return self.skipTest('wasm2c not supported')
71637172
self.set_setting('STANDALONE_WASM')
71647173
self.set_setting('WASM2C')
71657174
self.set_setting('WASM2C_SANDBOXING', mode)

0 commit comments

Comments
 (0)