Skip to content

Commit

Permalink
[wasm64] Cast BigInt argument to i64 Number (#17613)
Browse files Browse the repository at this point in the history
Fix argument type and struct access of various functions on WASM64:

    system
    gethostaddr
    gethostbyname
    gethostbyname_r
    getaddrinfo
    getnameinfo
    connect
    bind
    sendto
    doStat (internal helper for stat calls)
    pwrite
    pread
    read return value

Closes: #17595
Closes: #17620
  • Loading branch information
tiran authored Aug 15, 2022
1 parent c881fde commit 7ad06f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ mergeInto(LibraryManager.library, {
},

system__deps: ['$setErrNo'],
system__sig: 'ip',
system: function(command) {
#if ENVIRONMENT_MAY_BE_NODE
if (ENVIRONMENT_IS_NODE) {
Expand Down Expand Up @@ -1849,7 +1850,7 @@ mergeInto(LibraryManager.library, {
// note: lots of leaking here!
gethostbyaddr__deps: ['$DNS', '$getHostByName', '$inetNtop4', '$setErrNo'],
gethostbyaddr__proxy: 'sync',
gethostbyaddr__sig: 'iiii',
gethostbyaddr__sig: 'ipii',
gethostbyaddr: function (addr, addrlen, type) {
if (type !== {{{ cDefine('AF_INET') }}}) {
setErrNo({{{ cDefine('EAFNOSUPPORT') }}});
Expand All @@ -1867,7 +1868,7 @@ mergeInto(LibraryManager.library, {

gethostbyname__deps: ['$getHostByName'],
gethostbyname__proxy: 'sync',
gethostbyname__sig: 'ii',
gethostbyname__sig: 'pp',
gethostbyname: function(name) {
return getHostByName(UTF8ToString(name));
},
Expand Down Expand Up @@ -1895,7 +1896,7 @@ mergeInto(LibraryManager.library, {

gethostbyname_r__deps: ['gethostbyname', 'memcpy', 'free'],
gethostbyname_r__proxy: 'sync',
gethostbyname_r__sig: 'iiiiiii',
gethostbyname_r__sig: 'ipppipp',
gethostbyname_r: function(name, ret, buf, buflen, out, err) {
var data = _gethostbyname(name);
_memcpy(ret, data, {{{ C_STRUCTS.hostent.__size__ }}});
Expand All @@ -1907,7 +1908,7 @@ mergeInto(LibraryManager.library, {

getaddrinfo__deps: ['$Sockets', '$DNS', '$inetPton4', '$inetNtop4', '$inetPton6', '$inetNtop6', '$writeSockaddr'],
getaddrinfo__proxy: 'sync',
getaddrinfo__sig: 'iiiii',
getaddrinfo__sig: 'ipppp',
getaddrinfo: function(node, service, hint, out) {
// Note getaddrinfo currently only returns a single addrinfo with ai_next defaulting to NULL. When NULL
// hints are specified or ai_family set to AF_UNSPEC or ai_socktype or ai_protocol set to 0 then we
Expand Down Expand Up @@ -2078,6 +2079,7 @@ mergeInto(LibraryManager.library, {
},

getnameinfo__deps: ['$Sockets', '$DNS', '$readSockaddr'],
getnameinfo__sig: 'ipipipii',
getnameinfo: function (sa, salen, node, nodelen, serv, servlen, flags) {
var info = readSockaddr(sa, salen);
if (info.errno) {
Expand Down
11 changes: 7 additions & 4 deletions src/library_syscall.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ var SyscallsLibrary = {
{{{ makeSetValue('buf', C_STRUCTS.stat.st_dev, 'stat.dev', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.__st_ino_truncated, 'stat.ino', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_mode, 'stat.mode', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_nlink, 'stat.nlink', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_nlink, 'stat.nlink', SIZE_TYPE) }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_uid, 'stat.uid', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_gid, 'stat.gid', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_rdev, 'stat.rdev', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_size, 'stat.size', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_blksize, '4096', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_blocks, 'stat.blocks', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_atim.tv_sec, 'Math.floor(stat.atime.getTime() / 1000)', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_atim.tv_nsec, '0', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_atim.tv_nsec, '0', SIZE_TYPE) }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_mtim.tv_sec, 'Math.floor(stat.mtime.getTime() / 1000)', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_mtim.tv_nsec, '0', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_mtim.tv_nsec, '0', SIZE_TYPE) }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_ctim.tv_sec, 'Math.floor(stat.ctime.getTime() / 1000)', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_ctim.tv_nsec, '0', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_ctim.tv_nsec, '0', SIZE_TYPE) }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_ino, 'stat.ino', 'i64') }}};
return 0;
},
Expand Down Expand Up @@ -326,6 +326,7 @@ var SyscallsLibrary = {
return 0;
},
__syscall_connect__deps: ['$getSocketFromFD', '$getSocketAddress'],
__syscall_connect__sig: 'iipi',
__syscall_connect: function(fd, addr, addrlen) {
var sock = getSocketFromFD(fd);
var info = getSocketAddress(addr, addrlen);
Expand All @@ -350,6 +351,7 @@ var SyscallsLibrary = {
return newsock.stream.fd;
},
__syscall_bind__deps: ['$getSocketFromFD', '$getSocketAddress'],
__syscall_bind__sig: 'iipi',
__syscall_bind: function(fd, addr, addrlen) {
var sock = getSocketFromFD(fd);
var info = getSocketAddress(addr, addrlen);
Expand Down Expand Up @@ -377,6 +379,7 @@ var SyscallsLibrary = {
return msg.buffer.byteLength;
},
__syscall_sendto__deps: ['$getSocketFromFD', '$getSocketAddress'],
__syscall_sendto__sig: 'iipiipi',
__syscall_sendto: function(fd, message, length, flags, addr, addr_len) {
var sock = getSocketFromFD(fd);
var dest = getSocketAddress(addr, addr_len, true);
Expand Down
1 change: 1 addition & 0 deletions src/library_wasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ var WasiLibrary = {
'$doWritev',
#endif
].concat(i53ConversionDeps),
fd_pwrite__sig: 'iippjp',
fd_pwrite: function(fd, iov, iovcnt, {{{ defineI64Param('offset') }}}, pnum) {
#if SYSCALLS_REQUIRE_FILESYSTEM
{{{ receiveI64ParamAsI53('offset', cDefine('EOVERFLOW')) }}}
Expand Down

0 comments on commit 7ad06f6

Please sign in to comment.