From cb26b10672868ffde2dd30417b51c913b6ed2f89 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 10 May 2022 15:22:36 -0700 Subject: [PATCH] [wasm64] Fix ccall for MEMORY64 Split out from #16922 --- .circleci/config.yml | 2 +- src/preamble.js | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c7952d30dbfcc..f5899e2026f16 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -381,7 +381,7 @@ jobs: executor: bionic steps: - run-tests-linux: - test_targets: "wasm64.test_hello_world wasm64l.test_hello_world wasm64l.test_mmap wasm64l.test_unistd_* skip:wasm64l.test_unistd_sysconf wasm64l.test_mmap_file" + 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" test-other: executor: bionic steps: diff --git a/src/preamble.js b/src/preamble.js index 2090af133dbb7..e7064597e1aad 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -103,6 +103,9 @@ function getCFunc(ident) { function ccall(ident, returnType, argTypes, args, opts) { // For fast lookup of conversion functions var toC = { +#if MEMORY64 + 'pointer': (p) => {{{ to64('p') }}}, +#endif 'string': function(str) { var ret = 0; if (str !== null && str !== undefined && str !== 0) { // null string @@ -111,17 +114,23 @@ function ccall(ident, returnType, argTypes, args, opts) { ret = stackAlloc(len); stringToUTF8(str, ret, len); } - return ret; + return {{{ to64('ret') }}}; }, 'array': function(arr) { var ret = stackAlloc(arr.length); writeArrayToMemory(arr, ret); - return ret; + return {{{ to64('ret') }}}; } }; function convertReturnValue(ret) { - if (returnType === 'string') return UTF8ToString(ret); + if (returnType === 'string') { + {{{ from64('ret') }}} + return UTF8ToString(ret); + } +#if MEMORY64 + if (returnType === 'pointer') return Number(ret); +#endif if (returnType === 'boolean') return Boolean(ret); return ret; }