@tybys/wasm-util 0.8.2 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wasm-util.esm-bundler.js +86 -27
- package/dist/wasm-util.esm.js +86 -27
- package/dist/wasm-util.esm.min.js +1 -1
- package/dist/wasm-util.js +86 -27
- package/dist/wasm-util.min.js +1 -1
- package/lib/cjs/wasi/preview1.js +84 -26
- package/lib/cjs/wasi/rights.js +2 -1
- package/lib/mjs/wasi/preview1.mjs +84 -26
- package/lib/mjs/wasi/rights.mjs +2 -1
- package/package.json +1 -1
|
@@ -591,7 +591,8 @@ const RIGHTS_ALL = WasiRights.FD_DATASYNC |
|
|
|
591
591
|
WasiRights.PATH_UNLINK_FILE |
|
|
592
592
|
WasiRights.PATH_REMOVE_DIRECTORY |
|
|
593
593
|
WasiRights.POLL_FD_READWRITE |
|
|
594
|
-
WasiRights.SOCK_SHUTDOWN
|
|
594
|
+
WasiRights.SOCK_SHUTDOWN |
|
|
595
|
+
WasiRights.SOCK_ACCEPT;
|
|
595
596
|
const BLOCK_DEVICE_BASE = RIGHTS_ALL;
|
|
596
597
|
const BLOCK_DEVICE_INHERITING = RIGHTS_ALL;
|
|
597
598
|
const CHARACTER_DEVICE_BASE = RIGHTS_ALL;
|
|
@@ -1127,6 +1128,7 @@ async function resolvePathAsync(fs, fileDescriptor, path, flags) {
|
|
|
1127
1128
|
const encoder = /*#__PURE__*/ new TextEncoder();
|
|
1128
1129
|
// eslint-disable-next-line spaced-comment
|
|
1129
1130
|
const decoder = /*#__PURE__*/ new TextDecoder();
|
|
1131
|
+
const INT64_MAX = (BigInt(1) << BigInt(63)) - BigInt(1);
|
|
1130
1132
|
function readStdin() {
|
|
1131
1133
|
const value = window.prompt();
|
|
1132
1134
|
if (value === null)
|
|
@@ -1134,6 +1136,14 @@ function readStdin() {
|
|
|
1134
1136
|
const buffer = new TextEncoder().encode(value + '\n');
|
|
1135
1137
|
return buffer;
|
|
1136
1138
|
}
|
|
1139
|
+
function validateFstFlagsOrReturn(flags) {
|
|
1140
|
+
return (Boolean((flags) & ~(1 /* WasiFstFlag.SET_ATIM */ | 2 /* WasiFstFlag.SET_ATIM_NOW */ |
|
|
1141
|
+
4 /* WasiFstFlag.SET_MTIM */ | 8 /* WasiFstFlag.SET_MTIM_NOW */)) ||
|
|
1142
|
+
((flags) & (1 /* WasiFstFlag.SET_ATIM */ | 2 /* WasiFstFlag.SET_ATIM_NOW */)) ===
|
|
1143
|
+
(1 /* WasiFstFlag.SET_ATIM */ | 2 /* WasiFstFlag.SET_ATIM_NOW */) ||
|
|
1144
|
+
((flags) & (4 /* WasiFstFlag.SET_MTIM */ | 8 /* WasiFstFlag.SET_MTIM_NOW */)) ===
|
|
1145
|
+
(4 /* WasiFstFlag.SET_MTIM */ | 8 /* WasiFstFlag.SET_MTIM_NOW */));
|
|
1146
|
+
}
|
|
1137
1147
|
class WASI$1 {
|
|
1138
1148
|
constructor(args, env, fds, asyncFs, fs, asyncify) {
|
|
1139
1149
|
this.args_get = syscallWrap(this, 'args_get', function (argv, argv_buf) {
|
|
@@ -1294,7 +1304,7 @@ class WASI$1 {
|
|
|
1294
1304
|
const { view } = getMemory(this);
|
|
1295
1305
|
// preopen type is dir(0)
|
|
1296
1306
|
view.setUint32(prestat, 0, true);
|
|
1297
|
-
view.setUint32(prestat + 4, encoder.encode(fileDescriptor.path).length
|
|
1307
|
+
view.setUint32(prestat + 4, encoder.encode(fileDescriptor.path).length, true);
|
|
1298
1308
|
return 0 /* WasiErrno.ESUCCESS */;
|
|
1299
1309
|
});
|
|
1300
1310
|
this.fd_prestat_dir_name = syscallWrap(this, 'fd_prestat_dir_name', function (fd, path, path_len) {
|
|
@@ -1307,7 +1317,7 @@ class WASI$1 {
|
|
|
1307
1317
|
const fileDescriptor = wasi.fds.get(fd, BigInt(0), BigInt(0));
|
|
1308
1318
|
if (fileDescriptor.preopen !== 1)
|
|
1309
1319
|
return 8 /* WasiErrno.EBADF */;
|
|
1310
|
-
const buffer = encoder.encode(fileDescriptor.path
|
|
1320
|
+
const buffer = encoder.encode(fileDescriptor.path);
|
|
1311
1321
|
const size = buffer.length;
|
|
1312
1322
|
if (size > path_len)
|
|
1313
1323
|
return 42 /* WasiErrno.ENOBUFS */;
|
|
@@ -1502,6 +1512,9 @@ class WASI$1 {
|
|
|
1502
1512
|
this.sock_shutdown = syscallWrap(this, 'sock_shutdown', function () {
|
|
1503
1513
|
return 58 /* WasiErrno.ENOTSUP */;
|
|
1504
1514
|
});
|
|
1515
|
+
this.sock_accept = syscallWrap(this, 'sock_accept', function () {
|
|
1516
|
+
return 58 /* WasiErrno.ENOTSUP */;
|
|
1517
|
+
});
|
|
1505
1518
|
_wasi.set(this, {
|
|
1506
1519
|
fds,
|
|
1507
1520
|
args,
|
|
@@ -1617,11 +1630,17 @@ class WASI$1 {
|
|
|
1617
1630
|
return { fileDescriptor, atim, mtim };
|
|
1618
1631
|
}
|
|
1619
1632
|
defineImport('fd_filestat_set_times', function fd_filestat_set_times(fd, atim, mtim, flags) {
|
|
1633
|
+
if (validateFstFlagsOrReturn(flags)) {
|
|
1634
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1635
|
+
}
|
|
1620
1636
|
const { fileDescriptor, atim: atimRes, mtim: mtimRes } = fdFilestatGetTimes.call(this, fd, atim, mtim, flags);
|
|
1621
1637
|
const fs = getFs(this);
|
|
1622
1638
|
fs.futimesSync(fileDescriptor.fd, Number(atimRes), Number(mtimRes));
|
|
1623
1639
|
return 0 /* WasiErrno.ESUCCESS */;
|
|
1624
1640
|
}, async function fd_filestat_set_times(fd, atim, mtim, flags) {
|
|
1641
|
+
if (validateFstFlagsOrReturn(flags)) {
|
|
1642
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1643
|
+
}
|
|
1625
1644
|
const { fileDescriptor, atim: atimRes, mtim: mtimRes } = fdFilestatGetTimes.call(this, fd, atim, mtim, flags);
|
|
1626
1645
|
const h = fileDescriptor.fd;
|
|
1627
1646
|
await h.utimes(Number(atimRes), Number(mtimRes));
|
|
@@ -1630,12 +1649,16 @@ class WASI$1 {
|
|
|
1630
1649
|
defineImport('fd_pread', function fd_pread(fd, iovs, iovslen, offset, size) {
|
|
1631
1650
|
iovs = Number(iovs);
|
|
1632
1651
|
size = Number(size);
|
|
1633
|
-
if (iovs === 0 || size === 0) {
|
|
1652
|
+
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1634
1653
|
return 28 /* WasiErrno.EINVAL */;
|
|
1635
1654
|
}
|
|
1636
1655
|
const { HEAPU8, view } = getMemory(this);
|
|
1637
1656
|
const wasi = _wasi.get(this);
|
|
1638
1657
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ | WasiRights.FD_SEEK, BigInt(0));
|
|
1658
|
+
if (!iovslen) {
|
|
1659
|
+
view.setUint32(size, 0, true);
|
|
1660
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1661
|
+
}
|
|
1639
1662
|
let totalSize = 0;
|
|
1640
1663
|
const ioVecs = Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1641
1664
|
const offset = iovs + (i * 8);
|
|
@@ -1645,7 +1668,14 @@ class WASI$1 {
|
|
|
1645
1668
|
return HEAPU8.subarray(buf, buf + bufLen);
|
|
1646
1669
|
});
|
|
1647
1670
|
let nread = 0;
|
|
1648
|
-
const buffer =
|
|
1671
|
+
const buffer = (() => {
|
|
1672
|
+
try {
|
|
1673
|
+
return new Uint8Array(new SharedArrayBuffer(totalSize));
|
|
1674
|
+
}
|
|
1675
|
+
catch (_) {
|
|
1676
|
+
return new Uint8Array(totalSize);
|
|
1677
|
+
}
|
|
1678
|
+
})();
|
|
1649
1679
|
buffer._isBuffer = true;
|
|
1650
1680
|
const fs = getFs(this);
|
|
1651
1681
|
const bytesRead = fs.readSync(fileDescriptor.fd, buffer, 0, buffer.length, Number(offset));
|
|
@@ -1655,12 +1685,16 @@ class WASI$1 {
|
|
|
1655
1685
|
}, async function (fd, iovs, iovslen, offset, size) {
|
|
1656
1686
|
iovs = Number(iovs);
|
|
1657
1687
|
size = Number(size);
|
|
1658
|
-
if (iovs === 0 || size === 0) {
|
|
1688
|
+
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1659
1689
|
return 28 /* WasiErrno.EINVAL */;
|
|
1660
1690
|
}
|
|
1661
1691
|
const { HEAPU8, view } = getMemory(this);
|
|
1662
1692
|
const wasi = _wasi.get(this);
|
|
1663
1693
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ | WasiRights.FD_SEEK, BigInt(0));
|
|
1694
|
+
if (!iovslen) {
|
|
1695
|
+
view.setUint32(size, 0, true);
|
|
1696
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1697
|
+
}
|
|
1664
1698
|
let totalSize = 0;
|
|
1665
1699
|
const ioVecs = Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1666
1700
|
const offset = iovs + (i * 8);
|
|
@@ -1680,12 +1714,16 @@ class WASI$1 {
|
|
|
1680
1714
|
defineImport('fd_pwrite', function fd_pwrite(fd, iovs, iovslen, offset, size) {
|
|
1681
1715
|
iovs = Number(iovs);
|
|
1682
1716
|
size = Number(size);
|
|
1683
|
-
if (iovs === 0 || size === 0) {
|
|
1717
|
+
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1684
1718
|
return 28 /* WasiErrno.EINVAL */;
|
|
1685
1719
|
}
|
|
1686
1720
|
const { HEAPU8, view } = getMemory(this);
|
|
1687
1721
|
const wasi = _wasi.get(this);
|
|
1688
1722
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE | WasiRights.FD_SEEK, BigInt(0));
|
|
1723
|
+
if (!iovslen) {
|
|
1724
|
+
view.setUint32(size, 0, true);
|
|
1725
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1726
|
+
}
|
|
1689
1727
|
const buffer = concatBuffer(Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1690
1728
|
const offset = iovs + (i * 8);
|
|
1691
1729
|
const buf = view.getInt32(offset, true);
|
|
@@ -1699,12 +1737,16 @@ class WASI$1 {
|
|
|
1699
1737
|
}, async function fd_pwrite(fd, iovs, iovslen, offset, size) {
|
|
1700
1738
|
iovs = Number(iovs);
|
|
1701
1739
|
size = Number(size);
|
|
1702
|
-
if (iovs === 0 || size === 0) {
|
|
1740
|
+
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1703
1741
|
return 28 /* WasiErrno.EINVAL */;
|
|
1704
1742
|
}
|
|
1705
1743
|
const { HEAPU8, view } = getMemory(this);
|
|
1706
1744
|
const wasi = _wasi.get(this);
|
|
1707
1745
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE | WasiRights.FD_SEEK, BigInt(0));
|
|
1746
|
+
if (!iovslen) {
|
|
1747
|
+
view.setUint32(size, 0, true);
|
|
1748
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1749
|
+
}
|
|
1708
1750
|
const buffer = concatBuffer(Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1709
1751
|
const offset = iovs + (i * 8);
|
|
1710
1752
|
const buf = view.getInt32(offset, true);
|
|
@@ -1718,12 +1760,16 @@ class WASI$1 {
|
|
|
1718
1760
|
defineImport('fd_read', function fd_read(fd, iovs, iovslen, size) {
|
|
1719
1761
|
iovs = Number(iovs);
|
|
1720
1762
|
size = Number(size);
|
|
1721
|
-
if (iovs === 0 || size === 0) {
|
|
1763
|
+
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1722
1764
|
return 28 /* WasiErrno.EINVAL */;
|
|
1723
1765
|
}
|
|
1724
1766
|
const { HEAPU8, view } = getMemory(this);
|
|
1725
1767
|
const wasi = _wasi.get(this);
|
|
1726
1768
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ, BigInt(0));
|
|
1769
|
+
if (!iovslen) {
|
|
1770
|
+
view.setUint32(size, 0, true);
|
|
1771
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1772
|
+
}
|
|
1727
1773
|
let totalSize = 0;
|
|
1728
1774
|
const ioVecs = Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1729
1775
|
const offset = iovs + (i * 8);
|
|
@@ -1742,7 +1788,14 @@ class WASI$1 {
|
|
|
1742
1788
|
nread = buffer ? copyMemory(ioVecs, buffer) : 0;
|
|
1743
1789
|
}
|
|
1744
1790
|
else {
|
|
1745
|
-
buffer =
|
|
1791
|
+
buffer = (() => {
|
|
1792
|
+
try {
|
|
1793
|
+
return new Uint8Array(new SharedArrayBuffer(totalSize));
|
|
1794
|
+
}
|
|
1795
|
+
catch (_) {
|
|
1796
|
+
return new Uint8Array(totalSize);
|
|
1797
|
+
}
|
|
1798
|
+
})();
|
|
1746
1799
|
buffer._isBuffer = true;
|
|
1747
1800
|
const fs = getFs(this);
|
|
1748
1801
|
const bytesRead = fs.readSync(fileDescriptor.fd, buffer, 0, buffer.length, Number(fileDescriptor.pos));
|
|
@@ -1754,12 +1807,16 @@ class WASI$1 {
|
|
|
1754
1807
|
}, async function fd_read(fd, iovs, iovslen, size) {
|
|
1755
1808
|
iovs = Number(iovs);
|
|
1756
1809
|
size = Number(size);
|
|
1757
|
-
if (iovs === 0 || size === 0) {
|
|
1810
|
+
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1758
1811
|
return 28 /* WasiErrno.EINVAL */;
|
|
1759
1812
|
}
|
|
1760
1813
|
const { HEAPU8, view } = getMemory(this);
|
|
1761
1814
|
const wasi = _wasi.get(this);
|
|
1762
1815
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ, BigInt(0));
|
|
1816
|
+
if (!iovslen) {
|
|
1817
|
+
view.setUint32(size, 0, true);
|
|
1818
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1819
|
+
}
|
|
1763
1820
|
let totalSize = 0;
|
|
1764
1821
|
const ioVecs = Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1765
1822
|
const offset = iovs + (i * 8);
|
|
@@ -1912,12 +1969,16 @@ class WASI$1 {
|
|
|
1912
1969
|
defineImport('fd_write', function fd_write(fd, iovs, iovslen, size) {
|
|
1913
1970
|
iovs = Number(iovs);
|
|
1914
1971
|
size = Number(size);
|
|
1915
|
-
if (iovs === 0 || size === 0) {
|
|
1972
|
+
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1916
1973
|
return 28 /* WasiErrno.EINVAL */;
|
|
1917
1974
|
}
|
|
1918
1975
|
const { HEAPU8, view } = getMemory(this);
|
|
1919
1976
|
const wasi = _wasi.get(this);
|
|
1920
1977
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE, BigInt(0));
|
|
1978
|
+
if (!iovslen) {
|
|
1979
|
+
view.setUint32(size, 0, true);
|
|
1980
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1981
|
+
}
|
|
1921
1982
|
const buffer = concatBuffer(Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1922
1983
|
const offset = iovs + (i * 8);
|
|
1923
1984
|
const buf = view.getInt32(offset, true);
|
|
@@ -1938,12 +1999,16 @@ class WASI$1 {
|
|
|
1938
1999
|
}, async function fd_write(fd, iovs, iovslen, size) {
|
|
1939
2000
|
iovs = Number(iovs);
|
|
1940
2001
|
size = Number(size);
|
|
1941
|
-
if (iovs === 0 || size === 0) {
|
|
2002
|
+
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1942
2003
|
return 28 /* WasiErrno.EINVAL */;
|
|
1943
2004
|
}
|
|
1944
2005
|
const { HEAPU8, view } = getMemory(this);
|
|
1945
2006
|
const wasi = _wasi.get(this);
|
|
1946
2007
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE, BigInt(0));
|
|
2008
|
+
if (!iovslen) {
|
|
2009
|
+
view.setUint32(size, 0, true);
|
|
2010
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2011
|
+
}
|
|
1947
2012
|
const buffer = concatBuffer(Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1948
2013
|
const offset = iovs + (i * 8);
|
|
1949
2014
|
const buf = view.getInt32(offset, true);
|
|
@@ -2040,15 +2105,12 @@ class WASI$1 {
|
|
|
2040
2105
|
path_len = Number(path_len);
|
|
2041
2106
|
if (path === 0)
|
|
2042
2107
|
return 28 /* WasiErrno.EINVAL */;
|
|
2043
|
-
if ((fst_flags) & ~(1 /* WasiFstFlag.SET_ATIM */ |
|
|
2044
|
-
2 /* WasiFstFlag.SET_ATIM_NOW */ |
|
|
2045
|
-
4 /* WasiFstFlag.SET_MTIM */ |
|
|
2046
|
-
8 /* WasiFstFlag.SET_MTIM_NOW */)) {
|
|
2047
|
-
return 28 /* WasiErrno.EINVAL */;
|
|
2048
|
-
}
|
|
2049
2108
|
const { HEAPU8 } = getMemory(this);
|
|
2050
2109
|
const wasi = _wasi.get(this);
|
|
2051
2110
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_SET_TIMES, BigInt(0));
|
|
2111
|
+
if (validateFstFlagsOrReturn(fst_flags)) {
|
|
2112
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2113
|
+
}
|
|
2052
2114
|
const fs = getFs(this);
|
|
2053
2115
|
const resolvedPath = resolvePathSync(fs, fileDescriptor, decoder.decode(unsharedSlice(HEAPU8, path, path + path_len)), flags);
|
|
2054
2116
|
if ((fst_flags & 2 /* WasiFstFlag.SET_ATIM_NOW */) === 2 /* WasiFstFlag.SET_ATIM_NOW */) {
|
|
@@ -2064,15 +2126,12 @@ class WASI$1 {
|
|
|
2064
2126
|
path_len = Number(path_len);
|
|
2065
2127
|
if (path === 0)
|
|
2066
2128
|
return 28 /* WasiErrno.EINVAL */;
|
|
2067
|
-
if ((fst_flags) & ~(1 /* WasiFstFlag.SET_ATIM */ |
|
|
2068
|
-
2 /* WasiFstFlag.SET_ATIM_NOW */ |
|
|
2069
|
-
4 /* WasiFstFlag.SET_MTIM */ |
|
|
2070
|
-
8 /* WasiFstFlag.SET_MTIM_NOW */)) {
|
|
2071
|
-
return 28 /* WasiErrno.EINVAL */;
|
|
2072
|
-
}
|
|
2073
2129
|
const { HEAPU8 } = getMemory(this);
|
|
2074
2130
|
const wasi = _wasi.get(this);
|
|
2075
2131
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_SET_TIMES, BigInt(0));
|
|
2132
|
+
if (validateFstFlagsOrReturn(fst_flags)) {
|
|
2133
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2134
|
+
}
|
|
2076
2135
|
const fs = getFs(this);
|
|
2077
2136
|
const resolvedPath = await resolvePathAsync(fs, fileDescriptor, decoder.decode(unsharedSlice(HEAPU8, path, path + path_len)), flags);
|
|
2078
2137
|
if ((fst_flags & 2 /* WasiFstFlag.SET_ATIM_NOW */) === 2 /* WasiFstFlag.SET_ATIM_NOW */) {
|
|
@@ -2271,7 +2330,7 @@ class WASI$1 {
|
|
|
2271
2330
|
return 42 /* WasiErrno.ENOBUFS */;
|
|
2272
2331
|
HEAPU8.set(linkData.subarray(0, len), buf);
|
|
2273
2332
|
HEAPU8[buf + len] = 0;
|
|
2274
|
-
view.setUint32(bufused, len
|
|
2333
|
+
view.setUint32(bufused, len, true);
|
|
2275
2334
|
return 0 /* WasiErrno.ESUCCESS */;
|
|
2276
2335
|
}, async function path_readlink(fd, path, path_len, buf, buf_len, bufused) {
|
|
2277
2336
|
path = Number(path);
|
|
@@ -2295,7 +2354,7 @@ class WASI$1 {
|
|
|
2295
2354
|
return 42 /* WasiErrno.ENOBUFS */;
|
|
2296
2355
|
HEAPU8.set(linkData.subarray(0, len), buf);
|
|
2297
2356
|
HEAPU8[buf + len] = 0;
|
|
2298
|
-
view.setUint32(bufused, len
|
|
2357
|
+
view.setUint32(bufused, len, true);
|
|
2299
2358
|
return 0 /* WasiErrno.ESUCCESS */;
|
|
2300
2359
|
}, ['i32', 'i32', 'i32', 'i32', 'i32', 'i32'], ['i32']);
|
|
2301
2360
|
defineImport('path_remove_directory', function path_remove_directory(fd, path, path_len) {
|
package/dist/wasm-util.esm.js
CHANGED
|
@@ -591,7 +591,8 @@ const RIGHTS_ALL = WasiRights.FD_DATASYNC |
|
|
|
591
591
|
WasiRights.PATH_UNLINK_FILE |
|
|
592
592
|
WasiRights.PATH_REMOVE_DIRECTORY |
|
|
593
593
|
WasiRights.POLL_FD_READWRITE |
|
|
594
|
-
WasiRights.SOCK_SHUTDOWN
|
|
594
|
+
WasiRights.SOCK_SHUTDOWN |
|
|
595
|
+
WasiRights.SOCK_ACCEPT;
|
|
595
596
|
const BLOCK_DEVICE_BASE = RIGHTS_ALL;
|
|
596
597
|
const BLOCK_DEVICE_INHERITING = RIGHTS_ALL;
|
|
597
598
|
const CHARACTER_DEVICE_BASE = RIGHTS_ALL;
|
|
@@ -1127,6 +1128,7 @@ async function resolvePathAsync(fs, fileDescriptor, path, flags) {
|
|
|
1127
1128
|
const encoder = /*#__PURE__*/ new TextEncoder();
|
|
1128
1129
|
// eslint-disable-next-line spaced-comment
|
|
1129
1130
|
const decoder = /*#__PURE__*/ new TextDecoder();
|
|
1131
|
+
const INT64_MAX = (BigInt(1) << BigInt(63)) - BigInt(1);
|
|
1130
1132
|
function readStdin() {
|
|
1131
1133
|
const value = window.prompt();
|
|
1132
1134
|
if (value === null)
|
|
@@ -1134,6 +1136,14 @@ function readStdin() {
|
|
|
1134
1136
|
const buffer = new TextEncoder().encode(value + '\n');
|
|
1135
1137
|
return buffer;
|
|
1136
1138
|
}
|
|
1139
|
+
function validateFstFlagsOrReturn(flags) {
|
|
1140
|
+
return (Boolean((flags) & ~(1 /* WasiFstFlag.SET_ATIM */ | 2 /* WasiFstFlag.SET_ATIM_NOW */ |
|
|
1141
|
+
4 /* WasiFstFlag.SET_MTIM */ | 8 /* WasiFstFlag.SET_MTIM_NOW */)) ||
|
|
1142
|
+
((flags) & (1 /* WasiFstFlag.SET_ATIM */ | 2 /* WasiFstFlag.SET_ATIM_NOW */)) ===
|
|
1143
|
+
(1 /* WasiFstFlag.SET_ATIM */ | 2 /* WasiFstFlag.SET_ATIM_NOW */) ||
|
|
1144
|
+
((flags) & (4 /* WasiFstFlag.SET_MTIM */ | 8 /* WasiFstFlag.SET_MTIM_NOW */)) ===
|
|
1145
|
+
(4 /* WasiFstFlag.SET_MTIM */ | 8 /* WasiFstFlag.SET_MTIM_NOW */));
|
|
1146
|
+
}
|
|
1137
1147
|
class WASI$1 {
|
|
1138
1148
|
constructor(args, env, fds, asyncFs, fs, asyncify) {
|
|
1139
1149
|
this.args_get = syscallWrap(this, 'args_get', function (argv, argv_buf) {
|
|
@@ -1294,7 +1304,7 @@ class WASI$1 {
|
|
|
1294
1304
|
const { view } = getMemory(this);
|
|
1295
1305
|
// preopen type is dir(0)
|
|
1296
1306
|
view.setUint32(prestat, 0, true);
|
|
1297
|
-
view.setUint32(prestat + 4, encoder.encode(fileDescriptor.path).length
|
|
1307
|
+
view.setUint32(prestat + 4, encoder.encode(fileDescriptor.path).length, true);
|
|
1298
1308
|
return 0 /* WasiErrno.ESUCCESS */;
|
|
1299
1309
|
});
|
|
1300
1310
|
this.fd_prestat_dir_name = syscallWrap(this, 'fd_prestat_dir_name', function (fd, path, path_len) {
|
|
@@ -1307,7 +1317,7 @@ class WASI$1 {
|
|
|
1307
1317
|
const fileDescriptor = wasi.fds.get(fd, BigInt(0), BigInt(0));
|
|
1308
1318
|
if (fileDescriptor.preopen !== 1)
|
|
1309
1319
|
return 8 /* WasiErrno.EBADF */;
|
|
1310
|
-
const buffer = encoder.encode(fileDescriptor.path
|
|
1320
|
+
const buffer = encoder.encode(fileDescriptor.path);
|
|
1311
1321
|
const size = buffer.length;
|
|
1312
1322
|
if (size > path_len)
|
|
1313
1323
|
return 42 /* WasiErrno.ENOBUFS */;
|
|
@@ -1502,6 +1512,9 @@ class WASI$1 {
|
|
|
1502
1512
|
this.sock_shutdown = syscallWrap(this, 'sock_shutdown', function () {
|
|
1503
1513
|
return 58 /* WasiErrno.ENOTSUP */;
|
|
1504
1514
|
});
|
|
1515
|
+
this.sock_accept = syscallWrap(this, 'sock_accept', function () {
|
|
1516
|
+
return 58 /* WasiErrno.ENOTSUP */;
|
|
1517
|
+
});
|
|
1505
1518
|
_wasi.set(this, {
|
|
1506
1519
|
fds,
|
|
1507
1520
|
args,
|
|
@@ -1617,11 +1630,17 @@ class WASI$1 {
|
|
|
1617
1630
|
return { fileDescriptor, atim, mtim };
|
|
1618
1631
|
}
|
|
1619
1632
|
defineImport('fd_filestat_set_times', function fd_filestat_set_times(fd, atim, mtim, flags) {
|
|
1633
|
+
if (validateFstFlagsOrReturn(flags)) {
|
|
1634
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1635
|
+
}
|
|
1620
1636
|
const { fileDescriptor, atim: atimRes, mtim: mtimRes } = fdFilestatGetTimes.call(this, fd, atim, mtim, flags);
|
|
1621
1637
|
const fs = getFs(this);
|
|
1622
1638
|
fs.futimesSync(fileDescriptor.fd, Number(atimRes), Number(mtimRes));
|
|
1623
1639
|
return 0 /* WasiErrno.ESUCCESS */;
|
|
1624
1640
|
}, async function fd_filestat_set_times(fd, atim, mtim, flags) {
|
|
1641
|
+
if (validateFstFlagsOrReturn(flags)) {
|
|
1642
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1643
|
+
}
|
|
1625
1644
|
const { fileDescriptor, atim: atimRes, mtim: mtimRes } = fdFilestatGetTimes.call(this, fd, atim, mtim, flags);
|
|
1626
1645
|
const h = fileDescriptor.fd;
|
|
1627
1646
|
await h.utimes(Number(atimRes), Number(mtimRes));
|
|
@@ -1630,12 +1649,16 @@ class WASI$1 {
|
|
|
1630
1649
|
defineImport('fd_pread', function fd_pread(fd, iovs, iovslen, offset, size) {
|
|
1631
1650
|
iovs = Number(iovs);
|
|
1632
1651
|
size = Number(size);
|
|
1633
|
-
if (iovs === 0 || size === 0) {
|
|
1652
|
+
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1634
1653
|
return 28 /* WasiErrno.EINVAL */;
|
|
1635
1654
|
}
|
|
1636
1655
|
const { HEAPU8, view } = getMemory(this);
|
|
1637
1656
|
const wasi = _wasi.get(this);
|
|
1638
1657
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ | WasiRights.FD_SEEK, BigInt(0));
|
|
1658
|
+
if (!iovslen) {
|
|
1659
|
+
view.setUint32(size, 0, true);
|
|
1660
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1661
|
+
}
|
|
1639
1662
|
let totalSize = 0;
|
|
1640
1663
|
const ioVecs = Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1641
1664
|
const offset = iovs + (i * 8);
|
|
@@ -1645,7 +1668,14 @@ class WASI$1 {
|
|
|
1645
1668
|
return HEAPU8.subarray(buf, buf + bufLen);
|
|
1646
1669
|
});
|
|
1647
1670
|
let nread = 0;
|
|
1648
|
-
const buffer =
|
|
1671
|
+
const buffer = (() => {
|
|
1672
|
+
try {
|
|
1673
|
+
return new Uint8Array(new SharedArrayBuffer(totalSize));
|
|
1674
|
+
}
|
|
1675
|
+
catch (_) {
|
|
1676
|
+
return new Uint8Array(totalSize);
|
|
1677
|
+
}
|
|
1678
|
+
})();
|
|
1649
1679
|
buffer._isBuffer = true;
|
|
1650
1680
|
const fs = getFs(this);
|
|
1651
1681
|
const bytesRead = fs.readSync(fileDescriptor.fd, buffer, 0, buffer.length, Number(offset));
|
|
@@ -1655,12 +1685,16 @@ class WASI$1 {
|
|
|
1655
1685
|
}, async function (fd, iovs, iovslen, offset, size) {
|
|
1656
1686
|
iovs = Number(iovs);
|
|
1657
1687
|
size = Number(size);
|
|
1658
|
-
if (iovs === 0 || size === 0) {
|
|
1688
|
+
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1659
1689
|
return 28 /* WasiErrno.EINVAL */;
|
|
1660
1690
|
}
|
|
1661
1691
|
const { HEAPU8, view } = getMemory(this);
|
|
1662
1692
|
const wasi = _wasi.get(this);
|
|
1663
1693
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ | WasiRights.FD_SEEK, BigInt(0));
|
|
1694
|
+
if (!iovslen) {
|
|
1695
|
+
view.setUint32(size, 0, true);
|
|
1696
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1697
|
+
}
|
|
1664
1698
|
let totalSize = 0;
|
|
1665
1699
|
const ioVecs = Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1666
1700
|
const offset = iovs + (i * 8);
|
|
@@ -1680,12 +1714,16 @@ class WASI$1 {
|
|
|
1680
1714
|
defineImport('fd_pwrite', function fd_pwrite(fd, iovs, iovslen, offset, size) {
|
|
1681
1715
|
iovs = Number(iovs);
|
|
1682
1716
|
size = Number(size);
|
|
1683
|
-
if (iovs === 0 || size === 0) {
|
|
1717
|
+
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1684
1718
|
return 28 /* WasiErrno.EINVAL */;
|
|
1685
1719
|
}
|
|
1686
1720
|
const { HEAPU8, view } = getMemory(this);
|
|
1687
1721
|
const wasi = _wasi.get(this);
|
|
1688
1722
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE | WasiRights.FD_SEEK, BigInt(0));
|
|
1723
|
+
if (!iovslen) {
|
|
1724
|
+
view.setUint32(size, 0, true);
|
|
1725
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1726
|
+
}
|
|
1689
1727
|
const buffer = concatBuffer(Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1690
1728
|
const offset = iovs + (i * 8);
|
|
1691
1729
|
const buf = view.getInt32(offset, true);
|
|
@@ -1699,12 +1737,16 @@ class WASI$1 {
|
|
|
1699
1737
|
}, async function fd_pwrite(fd, iovs, iovslen, offset, size) {
|
|
1700
1738
|
iovs = Number(iovs);
|
|
1701
1739
|
size = Number(size);
|
|
1702
|
-
if (iovs === 0 || size === 0) {
|
|
1740
|
+
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1703
1741
|
return 28 /* WasiErrno.EINVAL */;
|
|
1704
1742
|
}
|
|
1705
1743
|
const { HEAPU8, view } = getMemory(this);
|
|
1706
1744
|
const wasi = _wasi.get(this);
|
|
1707
1745
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE | WasiRights.FD_SEEK, BigInt(0));
|
|
1746
|
+
if (!iovslen) {
|
|
1747
|
+
view.setUint32(size, 0, true);
|
|
1748
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1749
|
+
}
|
|
1708
1750
|
const buffer = concatBuffer(Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1709
1751
|
const offset = iovs + (i * 8);
|
|
1710
1752
|
const buf = view.getInt32(offset, true);
|
|
@@ -1718,12 +1760,16 @@ class WASI$1 {
|
|
|
1718
1760
|
defineImport('fd_read', function fd_read(fd, iovs, iovslen, size) {
|
|
1719
1761
|
iovs = Number(iovs);
|
|
1720
1762
|
size = Number(size);
|
|
1721
|
-
if (iovs === 0 || size === 0) {
|
|
1763
|
+
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1722
1764
|
return 28 /* WasiErrno.EINVAL */;
|
|
1723
1765
|
}
|
|
1724
1766
|
const { HEAPU8, view } = getMemory(this);
|
|
1725
1767
|
const wasi = _wasi.get(this);
|
|
1726
1768
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ, BigInt(0));
|
|
1769
|
+
if (!iovslen) {
|
|
1770
|
+
view.setUint32(size, 0, true);
|
|
1771
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1772
|
+
}
|
|
1727
1773
|
let totalSize = 0;
|
|
1728
1774
|
const ioVecs = Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1729
1775
|
const offset = iovs + (i * 8);
|
|
@@ -1742,7 +1788,14 @@ class WASI$1 {
|
|
|
1742
1788
|
nread = buffer ? copyMemory(ioVecs, buffer) : 0;
|
|
1743
1789
|
}
|
|
1744
1790
|
else {
|
|
1745
|
-
buffer =
|
|
1791
|
+
buffer = (() => {
|
|
1792
|
+
try {
|
|
1793
|
+
return new Uint8Array(new SharedArrayBuffer(totalSize));
|
|
1794
|
+
}
|
|
1795
|
+
catch (_) {
|
|
1796
|
+
return new Uint8Array(totalSize);
|
|
1797
|
+
}
|
|
1798
|
+
})();
|
|
1746
1799
|
buffer._isBuffer = true;
|
|
1747
1800
|
const fs = getFs(this);
|
|
1748
1801
|
const bytesRead = fs.readSync(fileDescriptor.fd, buffer, 0, buffer.length, Number(fileDescriptor.pos));
|
|
@@ -1754,12 +1807,16 @@ class WASI$1 {
|
|
|
1754
1807
|
}, async function fd_read(fd, iovs, iovslen, size) {
|
|
1755
1808
|
iovs = Number(iovs);
|
|
1756
1809
|
size = Number(size);
|
|
1757
|
-
if (iovs === 0 || size === 0) {
|
|
1810
|
+
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1758
1811
|
return 28 /* WasiErrno.EINVAL */;
|
|
1759
1812
|
}
|
|
1760
1813
|
const { HEAPU8, view } = getMemory(this);
|
|
1761
1814
|
const wasi = _wasi.get(this);
|
|
1762
1815
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ, BigInt(0));
|
|
1816
|
+
if (!iovslen) {
|
|
1817
|
+
view.setUint32(size, 0, true);
|
|
1818
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1819
|
+
}
|
|
1763
1820
|
let totalSize = 0;
|
|
1764
1821
|
const ioVecs = Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1765
1822
|
const offset = iovs + (i * 8);
|
|
@@ -1912,12 +1969,16 @@ class WASI$1 {
|
|
|
1912
1969
|
defineImport('fd_write', function fd_write(fd, iovs, iovslen, size) {
|
|
1913
1970
|
iovs = Number(iovs);
|
|
1914
1971
|
size = Number(size);
|
|
1915
|
-
if (iovs === 0 || size === 0) {
|
|
1972
|
+
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1916
1973
|
return 28 /* WasiErrno.EINVAL */;
|
|
1917
1974
|
}
|
|
1918
1975
|
const { HEAPU8, view } = getMemory(this);
|
|
1919
1976
|
const wasi = _wasi.get(this);
|
|
1920
1977
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE, BigInt(0));
|
|
1978
|
+
if (!iovslen) {
|
|
1979
|
+
view.setUint32(size, 0, true);
|
|
1980
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1981
|
+
}
|
|
1921
1982
|
const buffer = concatBuffer(Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1922
1983
|
const offset = iovs + (i * 8);
|
|
1923
1984
|
const buf = view.getInt32(offset, true);
|
|
@@ -1938,12 +1999,16 @@ class WASI$1 {
|
|
|
1938
1999
|
}, async function fd_write(fd, iovs, iovslen, size) {
|
|
1939
2000
|
iovs = Number(iovs);
|
|
1940
2001
|
size = Number(size);
|
|
1941
|
-
if (iovs === 0 || size === 0) {
|
|
2002
|
+
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1942
2003
|
return 28 /* WasiErrno.EINVAL */;
|
|
1943
2004
|
}
|
|
1944
2005
|
const { HEAPU8, view } = getMemory(this);
|
|
1945
2006
|
const wasi = _wasi.get(this);
|
|
1946
2007
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE, BigInt(0));
|
|
2008
|
+
if (!iovslen) {
|
|
2009
|
+
view.setUint32(size, 0, true);
|
|
2010
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2011
|
+
}
|
|
1947
2012
|
const buffer = concatBuffer(Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1948
2013
|
const offset = iovs + (i * 8);
|
|
1949
2014
|
const buf = view.getInt32(offset, true);
|
|
@@ -2040,15 +2105,12 @@ class WASI$1 {
|
|
|
2040
2105
|
path_len = Number(path_len);
|
|
2041
2106
|
if (path === 0)
|
|
2042
2107
|
return 28 /* WasiErrno.EINVAL */;
|
|
2043
|
-
if ((fst_flags) & ~(1 /* WasiFstFlag.SET_ATIM */ |
|
|
2044
|
-
2 /* WasiFstFlag.SET_ATIM_NOW */ |
|
|
2045
|
-
4 /* WasiFstFlag.SET_MTIM */ |
|
|
2046
|
-
8 /* WasiFstFlag.SET_MTIM_NOW */)) {
|
|
2047
|
-
return 28 /* WasiErrno.EINVAL */;
|
|
2048
|
-
}
|
|
2049
2108
|
const { HEAPU8 } = getMemory(this);
|
|
2050
2109
|
const wasi = _wasi.get(this);
|
|
2051
2110
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_SET_TIMES, BigInt(0));
|
|
2111
|
+
if (validateFstFlagsOrReturn(fst_flags)) {
|
|
2112
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2113
|
+
}
|
|
2052
2114
|
const fs = getFs(this);
|
|
2053
2115
|
const resolvedPath = resolvePathSync(fs, fileDescriptor, decoder.decode(unsharedSlice(HEAPU8, path, path + path_len)), flags);
|
|
2054
2116
|
if ((fst_flags & 2 /* WasiFstFlag.SET_ATIM_NOW */) === 2 /* WasiFstFlag.SET_ATIM_NOW */) {
|
|
@@ -2064,15 +2126,12 @@ class WASI$1 {
|
|
|
2064
2126
|
path_len = Number(path_len);
|
|
2065
2127
|
if (path === 0)
|
|
2066
2128
|
return 28 /* WasiErrno.EINVAL */;
|
|
2067
|
-
if ((fst_flags) & ~(1 /* WasiFstFlag.SET_ATIM */ |
|
|
2068
|
-
2 /* WasiFstFlag.SET_ATIM_NOW */ |
|
|
2069
|
-
4 /* WasiFstFlag.SET_MTIM */ |
|
|
2070
|
-
8 /* WasiFstFlag.SET_MTIM_NOW */)) {
|
|
2071
|
-
return 28 /* WasiErrno.EINVAL */;
|
|
2072
|
-
}
|
|
2073
2129
|
const { HEAPU8 } = getMemory(this);
|
|
2074
2130
|
const wasi = _wasi.get(this);
|
|
2075
2131
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_SET_TIMES, BigInt(0));
|
|
2132
|
+
if (validateFstFlagsOrReturn(fst_flags)) {
|
|
2133
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2134
|
+
}
|
|
2076
2135
|
const fs = getFs(this);
|
|
2077
2136
|
const resolvedPath = await resolvePathAsync(fs, fileDescriptor, decoder.decode(unsharedSlice(HEAPU8, path, path + path_len)), flags);
|
|
2078
2137
|
if ((fst_flags & 2 /* WasiFstFlag.SET_ATIM_NOW */) === 2 /* WasiFstFlag.SET_ATIM_NOW */) {
|
|
@@ -2271,7 +2330,7 @@ class WASI$1 {
|
|
|
2271
2330
|
return 42 /* WasiErrno.ENOBUFS */;
|
|
2272
2331
|
HEAPU8.set(linkData.subarray(0, len), buf);
|
|
2273
2332
|
HEAPU8[buf + len] = 0;
|
|
2274
|
-
view.setUint32(bufused, len
|
|
2333
|
+
view.setUint32(bufused, len, true);
|
|
2275
2334
|
return 0 /* WasiErrno.ESUCCESS */;
|
|
2276
2335
|
}, async function path_readlink(fd, path, path_len, buf, buf_len, bufused) {
|
|
2277
2336
|
path = Number(path);
|
|
@@ -2295,7 +2354,7 @@ class WASI$1 {
|
|
|
2295
2354
|
return 42 /* WasiErrno.ENOBUFS */;
|
|
2296
2355
|
HEAPU8.set(linkData.subarray(0, len), buf);
|
|
2297
2356
|
HEAPU8[buf + len] = 0;
|
|
2298
|
-
view.setUint32(bufused, len
|
|
2357
|
+
view.setUint32(bufused, len, true);
|
|
2299
2358
|
return 0 /* WasiErrno.ESUCCESS */;
|
|
2300
2359
|
}, ['i32', 'i32', 'i32', 'i32', 'i32', 'i32'], ['i32']);
|
|
2301
2360
|
defineImport('path_remove_directory', function path_remove_directory(fd, path, path_len) {
|