Skip to content

Commit e5b7c6c

Browse files
authored
[wasm64] update makeDynCall for MEMORY64 (#16933)
Split out from #16922
1 parent cb55df4 commit e5b7c6c

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ jobs:
381381
executor: bionic
382382
steps:
383383
- run-tests-linux:
384-
test_targets: "wasm64.test_hello_world wasm64.test_ccall wasm64l.test_hello_world wasm64l.test_mmap wasm64l.test_unistd_* skip:wasm64l.test_unistd_sysconf wasm64l.test_mmap_file wasm64l.test_ccall"
384+
test_targets: "wasm64.test_hello_world wasm64.test_ccall wasm64l.test_hello_world wasm64l.test_mmap wasm64l.test_unistd_* skip:wasm64l.test_unistd_sysconf wasm64l.test_mmap_file wasm64l.test_ccall wasm64l.test_signals"
385385
test-other:
386386
executor: bionic
387387
steps:

src/library.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,7 @@ LibraryManager.library = {
22392239

22402240
// Helper for raise() to avoid signature mismatch failures:
22412241
// https://github.com/emscripten-core/posixtestsuite/issues/6
2242+
__call_sighandler__sig: 'vpi',
22422243
__call_sighandler: function(fp, sig) {
22432244
{{{ makeDynCall('vi', 'fp') }}}(sig);
22442245
},

src/parseTools.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,33 @@ function makeDynCall(sig, funcPtr) {
822822
}
823823
args = args.join(', ');
824824

825+
const needArgConversion = MEMORY64 && sig.includes('p');
826+
let callArgs = args;
827+
if (needArgConversion) {
828+
callArgs = [];
829+
for (let i = 1; i < sig.length; ++i) {
830+
if (sig[i] == 'p') {
831+
callArgs.push(`BigInt(a${i})`);
832+
} else {
833+
callArgs.push(`a${i}`);
834+
}
835+
}
836+
callArgs = callArgs.join(', ');
837+
}
838+
839+
// Normalize any 'p' characters to either 'j' (wasm64) or 'i' (wasm32)
840+
if (sig.includes('p')) {
841+
let normalizedSig = '';
842+
for (let sigChr of sig) {
843+
if (sigChr == 'p') {
844+
sigChr = MEMORY64 ? 'j' : 'i';
845+
}
846+
normalizedSig += sigChr;
847+
}
848+
sig = normalizedSig;
849+
}
850+
851+
825852
if (funcPtr === undefined) {
826853
printErr(`warning: ${currentlyParsedFilename}: \
827854
Legacy use of {{{ makeDynCall("${sig}") }}}(funcPtr, arg1, arg2, ...). \
@@ -837,9 +864,9 @@ Please update to new syntax.`);
837864
return `(function(${args}) { /* a dynamic function call to signature ${sig}, but there are no exported function pointers with that signature, so this path should never be taken. Build with ASSERTIONS enabled to validate. */ })`;
838865
}
839866
}
840-
return `(function(cb, ${args}) { ${returnExpr} getDynCaller("${sig}", cb)(${args}) })`;
867+
return `(function(cb, ${args}) { ${returnExpr} getDynCaller("${sig}", cb)(${callArgs}) })`;
841868
} else {
842-
return `(function(cb, ${args}) { ${returnExpr} getWasmTableEntry(cb)(${args}) })`;
869+
return `(function(cb, ${args}) { ${returnExpr} getWasmTableEntry(cb)(${callArgs}) })`;
843870
}
844871
}
845872

@@ -854,13 +881,15 @@ Please update to new syntax.`);
854881

855882
const dyncall = exportedAsmFunc(`dynCall_${sig}`);
856883
if (sig.length > 1) {
857-
return `(function(${args}) { ${returnExpr} ${dyncall}.apply(null, [${funcPtr}, ${args}]); })`;
858-
} else {
859-
return `(function() { ${returnExpr} ${dyncall}.call(null, ${funcPtr}); })`;
884+
return `(function(${args}) { ${returnExpr} ${dyncall}.apply(null, [${funcPtr}, ${callArgs}]); })`;
860885
}
861-
} else {
862-
return `getWasmTableEntry(${funcPtr})`;
886+
return `(function() { ${returnExpr} ${dyncall}.call(null, ${funcPtr}); })`;
887+
}
888+
889+
if (needArgConversion) {
890+
return `(function(${args}) { ${returnExpr} getWasmTableEntry(${funcPtr}).call(null, ${callArgs}) })`;
863891
}
892+
return `getWasmTableEntry(${funcPtr})`;
864893
}
865894

866895
function heapAndOffset(heap, ptr) { // given HEAP8, ptr , we return splitChunk, relptr

0 commit comments

Comments
 (0)