Skip to content
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
7 changes: 7 additions & 0 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -3157,8 +3157,15 @@ mergeInto(LibraryManager.library, {
assert(('dynCall_' + sig) in Module, `bad function pointer type - dynCall function not found for sig '${sig}'`);
#endif
if (args && args.length) {
#if WASM_BIGINT
// j (64-bit integer) is fine, and is implemented as a BigInt. Without
// legalization, the number of parameters should match (j is not expanded
// into two i's).
assert(args.length === sig.length - 1);
#else
// j (64-bit integer) must be passed in as two numbers [low 32, high 32].
assert(args.length === sig.substring(1).replace(/j/g, '--').length);
#endif
} else {
assert(sig.length == 1);
}
Expand Down
52 changes: 45 additions & 7 deletions test/core/dyncall_specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,60 @@
* found in the LICENSE file.
*/

#include <assert.h>
#include <emscripten.h>
#include <stdint.h>
#include <stdio.h>

int waka(int w, long long xy, int z) {
#ifdef WASM_BIGINT
// With WASM_BIGINT things are straightforward: the 64-bit value just arrives
// with the expected value of 4.
assert(w == 1);
assert(xy == 4);
assert(z == 9);
#else
// xy should be 0xffff_ffff_0000_0004
int x = (int) xy; // should be 4
int y = xy >> 32; // should be -1
EM_ASM({
out('received ' + [$0, $1, $2, $3] + '.');
}, w, x, y, z);
int x = (int) xy;
int y = xy >> 32;
assert(w == 1);
assert(x == 4);
assert(y == -1);
assert(z == 9);
#endif
return 42;
}

EM_JS_DEPS(main, "$dynCall");

int main() {
EM_ASM({
// Note that these would need to use BigInts if the file were built with
// -sWASM_BIGINT

#ifdef WASM_BIGINT

#if DIRECT
console.log('Received ' + dynCall_iiji($0, 1, BigInt(4), 9));
return;
#endif
#if DYNAMIC_SIG
console.log('Received ' + dynCall('iiji', $0, [1, BigInt(4), 9]));
return;
#endif
#if EXPORTED
console.log('Received ' + Module['dynCall_iiji']($0, 1, BigInt(4), 9));
return;
#endif
#if EXPORTED_DYNAMIC_SIG
console.log('Received ' + Module['dynCall']('iiji', $0, [1, BigInt(4), 9]));
return;
#endif
#if FROM_OUTSIDE
eval("console.log('Received ' + Module['dynCall_iiji'](" + $0 + ", 1, BigInt(4), 9))");
return;
#endif

#else // WASM_BIGINT

#if DIRECT
console.log('Received ' + dynCall_iiji($0, 1, 4, 0xffffffff, 9));
return;
Expand All @@ -45,6 +79,10 @@ int main() {
eval("console.log('Received ' + Module['dynCall_iiji'](" + $0 + ", 1, 4, 0xffffffff, 9))");
return;
#endif

#endif

// We should have run the test and returned before we get here.
throw "no test mode";
}, &waka);
}
Expand Down
3 changes: 1 addition & 2 deletions test/core/dyncall_specific.out
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
received 1,4,-1,9.
Received 42
Received 42
13 changes: 9 additions & 4 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7209,18 +7209,23 @@ def test_EXPORTED_RUNTIME_METHODS(self):
'minimal_runtime': ['-sMINIMAL_RUNTIME=1']
})
def test_dyncall_specific(self, *args):
if self.get_setting('WASM_BIGINT') or self.get_setting('MEMORY64'):
self.skipTest('not compatible with WASM_BIGINT')
if self.get_setting('MEMORY64'):
self.skipTest('not compatible with MEMORY64')
if self.get_setting('WASM_BIGINT'):
# define DYNCALLS because this test does test calling them directly, and
# in WASM_BIGINT mode we do not enable them by default (since we can do
# more without them - we don't need to legalize)
args = list(args) + ['-sDYNCALLS', '-DWASM_BIGINT']
cases = [
('DIRECT', []),
('DYNAMIC_SIG', ['-sDYNCALLS=1']),
('DYNAMIC_SIG', ['-sDYNCALLS']),
]
if '-sMINIMAL_RUNTIME=1' in args:
self.emcc_args += ['--pre-js', test_file('minimal_runtime_exit_handling.js')]
else:
cases += [
('EXPORTED', []),
('EXPORTED_DYNAMIC_SIG', ['-sDYNCALLS=1', '-sEXPORTED_RUNTIME_METHODS=dynCall']),
('EXPORTED_DYNAMIC_SIG', ['-sDYNCALLS', '-sEXPORTED_RUNTIME_METHODS=dynCall']),
('FROM_OUTSIDE', ['-sEXPORTED_RUNTIME_METHODS=dynCall_iiji'])
]

Expand Down