Skip to content

[Memory64] wasi JS changes for 64-bit #15224

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
Oct 7, 2021
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
19 changes: 11 additions & 8 deletions src/library_wasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ var WasiLibrary = {
args_sizes_get__nothrow: true,
args_sizes_get__sig: 'iii',
args_sizes_get: function(pargc, pargv_buf_size) {
{{{ from64(['pargc', 'pargv_buf_size']) }}};
#if MAIN_READS_PARAMS
{{{ makeSetValue('pargc', 0, 'mainArgs.length', 'i32') }}};
{{{ makeSetValue('pargc', 0, 'mainArgs.length', SIZE_TYPE) }}};
var bufSize = 0;
mainArgs.forEach(function(arg) {
bufSize += arg.length + 1;
});
{{{ makeSetValue('pargv_buf_size', 0, 'bufSize', 'i32') }}};
{{{ makeSetValue('pargv_buf_size', 0, 'bufSize', SIZE_TYPE) }}};
#else
{{{ makeSetValue('pargc', 0, '0', 'i32') }}};
{{{ makeSetValue('pargc', 0, '0', SIZE_TYPE) }}};
#endif
return 0;
},
Expand All @@ -109,11 +110,12 @@ var WasiLibrary = {
args_get__deps: ['$writeAsciiToMemory'],
#endif
args_get: function(argv, argv_buf) {
{{{ from64(['argv', 'argv_buf']) }}};
#if MAIN_READS_PARAMS
var bufSize = 0;
mainArgs.forEach(function(arg, i) {
var ptr = argv_buf + bufSize;
{{{ makeSetValue('argv', 'i * 4', 'ptr', 'i32') }}};
{{{ makeSetValue('argv', `i*${Runtime.POINTER_SIZE}`, 'ptr', `${POINTER_TYPE}`) }}};
writeAsciiToMemory(arg, ptr);
bufSize += arg.length + 1;
});
Expand Down Expand Up @@ -181,7 +183,7 @@ var WasiLibrary = {
#if SYSCALLS_REQUIRE_FILESYSTEM == 0 && (!MINIMAL_RUNTIME || EXIT_RUNTIME)
$flush_NO_FILESYSTEM: function() {
// flush anything remaining in the buffers during shutdown
if (typeof _fflush !== 'undefined') _fflush(0);
if (typeof _fflush !== 'undefined') _fflush({{{ pointerT(0) }}});
var buffers = SYSCALLS.buffers;
if (buffers[1].length) SYSCALLS.printChar(1, {{{ charCode("\n") }}});
if (buffers[2].length) SYSCALLS.printChar(2, {{{ charCode("\n") }}});
Expand All @@ -193,22 +195,23 @@ var WasiLibrary = {
#endif
fd_write__sig: 'iiiii',
fd_write: function(fd, iov, iovcnt, pnum) {
{{{ from64(['iov', 'iovcnt', 'pnum']) }}};
#if SYSCALLS_REQUIRE_FILESYSTEM
var stream = SYSCALLS.getStreamFromFD(fd);
var num = SYSCALLS.doWritev(stream, iov, iovcnt);
#else
// hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0
var num = 0;
for (var i = 0; i < iovcnt; i++) {
var ptr = {{{ makeGetValue('iov', 'i*8', 'i32') }}};
var len = {{{ makeGetValue('iov', 'i*8 + 4', 'i32') }}};
var ptr = {{{ makeGetValue('iov', `i*${Runtime.POINTER_SIZE}*2`, `${POINTER_TYPE}`) }}};
var len = {{{ makeGetValue('iov', `i*${Runtime.POINTER_SIZE}*2 + ${Runtime.POINTER_SIZE}`, `${POINTER_TYPE}`) }}};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably be using C_STRUCTS stuff here.. I can look into that as a followup.

for (var j = 0; j < len; j++) {
SYSCALLS.printChar(fd, HEAPU8[ptr+j]);
}
num += len;
}
#endif // SYSCALLS_REQUIRE_FILESYSTEM
{{{ makeSetValue('pnum', 0, 'num', 'i32') }}}
{{{ makeSetValue('pnum', 0, 'num', `${SIZE_TYPE}`) }}}
return 0;
},

Expand Down
2 changes: 1 addition & 1 deletion src/parseTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function isPointerType(type) {
return type[type.length - 1] == '*';
}

function sizeT(x) {
function pointerT(x) {
return MEMORY64 ? `BigInt(${x})` : x;
}

Expand Down