@ai-ecoverse/slicc-kernel 1.8.2 → 1.8.4
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/process-worker.js
CHANGED
|
@@ -1681,6 +1681,12 @@ function wrapCloexecSyscalls(imports, glue, deps) {
|
|
|
1681
1681
|
}
|
|
1682
1682
|
}
|
|
1683
1683
|
}
|
|
1684
|
+
function errnoOf(err) {
|
|
1685
|
+
const { errno: errno2, code: code2 } = err ?? {};
|
|
1686
|
+
if (typeof errno2 === "number") return errno2;
|
|
1687
|
+
if (typeof code2 === "string") return wasiErrno(code2);
|
|
1688
|
+
throw err;
|
|
1689
|
+
}
|
|
1684
1690
|
function persistsItself(stream) {
|
|
1685
1691
|
const type = stream.node.mount?.type;
|
|
1686
1692
|
return typeof type?.syncfs === "function";
|
|
@@ -1697,12 +1703,66 @@ function syncFsync(imports, fs) {
|
|
|
1697
1703
|
const result = stream.stream_ops.fsync?.(stream);
|
|
1698
1704
|
return typeof result === "number" ? result : 0;
|
|
1699
1705
|
} catch (err) {
|
|
1700
|
-
|
|
1701
|
-
return typeof errno2 === "number" ? errno2 : wasiErrno(String(code2));
|
|
1706
|
+
return errnoOf(err);
|
|
1702
1707
|
}
|
|
1703
1708
|
};
|
|
1704
1709
|
}
|
|
1705
1710
|
}
|
|
1711
|
+
function offsetOf(rest) {
|
|
1712
|
+
const at = rest.length >= 3 ? Number(rest[1]) * 2 ** 32 + (Number(rest[0]) >>> 0) : Number(BigInt.asIntN(64, BigInt(rest[0])));
|
|
1713
|
+
return at >= 0 && Number.isSafeInteger(at) ? at : void 0;
|
|
1714
|
+
}
|
|
1715
|
+
function readInto(sys, kfd, target, at) {
|
|
1716
|
+
let done = 0;
|
|
1717
|
+
while (done < target.length) {
|
|
1718
|
+
const got = sys.pread?.(kfd, target.length - done, at + done) ?? new Uint8Array(0);
|
|
1719
|
+
if (got.length === 0) break;
|
|
1720
|
+
target.set(got, done);
|
|
1721
|
+
done += got.length;
|
|
1722
|
+
}
|
|
1723
|
+
return done;
|
|
1724
|
+
}
|
|
1725
|
+
function positioned(original, write, deps) {
|
|
1726
|
+
return (fd, iov, iovcnt, ...rest) => {
|
|
1727
|
+
const stream = deps.fs()?.getStream(Number(fd));
|
|
1728
|
+
const memory = deps.memory();
|
|
1729
|
+
const kfd = stream?.sliccKernelFile ? stream.sliccKernelFd : void 0;
|
|
1730
|
+
if (kfd === void 0 || !memory || !(write ? deps.sys.pwrite : deps.sys.pread)) {
|
|
1731
|
+
return original(fd, iov, iovcnt, ...rest);
|
|
1732
|
+
}
|
|
1733
|
+
const at = offsetOf(rest);
|
|
1734
|
+
if (at === void 0) return wasiErrno("EINVAL");
|
|
1735
|
+
const view = new DataView(memory.buffer);
|
|
1736
|
+
let done = 0;
|
|
1737
|
+
try {
|
|
1738
|
+
for (let i = 0; i < Number(iovcnt); i++) {
|
|
1739
|
+
const ptr = view.getUint32(Number(iov) + i * 8, true);
|
|
1740
|
+
const len = view.getUint32(Number(iov) + i * 8 + 4, true);
|
|
1741
|
+
const part = new Uint8Array(memory.buffer, ptr, len);
|
|
1742
|
+
const moved = write ? deps.sys.pwrite?.(kfd, part.slice(), at + done) ?? 0 : readInto(deps.sys, kfd, part, at + done);
|
|
1743
|
+
done += moved;
|
|
1744
|
+
if (moved < len) break;
|
|
1745
|
+
}
|
|
1746
|
+
} catch (err) {
|
|
1747
|
+
return errnoOf(err);
|
|
1748
|
+
}
|
|
1749
|
+
view.setUint32(Number(rest[rest.length - 1]), done, true);
|
|
1750
|
+
return 0;
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
function positionalIo(imports, deps) {
|
|
1754
|
+
for (const namespace of Object.values(imports)) {
|
|
1755
|
+
for (const [name, write] of [
|
|
1756
|
+
["fd_pread", false],
|
|
1757
|
+
["fd_pwrite", true]
|
|
1758
|
+
]) {
|
|
1759
|
+
const original = namespace?.[name];
|
|
1760
|
+
if (typeof original === "function") {
|
|
1761
|
+
namespace[name] = positioned(original, write, deps);
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1706
1766
|
function wasmMemory(instance, imports) {
|
|
1707
1767
|
const isMemory = (v) => v instanceof WebAssembly.Memory;
|
|
1708
1768
|
const exported = Object.values(instance.exports).find(isMemory);
|
|
@@ -2344,6 +2404,11 @@ function kernelSys(transport) {
|
|
|
2344
2404
|
const r = call2({ op: "fd-pread", fd, max, offset: at }, `fd-pread ${fd}`);
|
|
2345
2405
|
return r.ok && r.kind === "bytes" ? r.bytes : new Uint8Array(0);
|
|
2346
2406
|
},
|
|
2407
|
+
pwrite(fd, bytes, at) {
|
|
2408
|
+
return json(
|
|
2409
|
+
call2({ op: "fd-pwrite", fd, offset: at, body: bytes }, `fd-pwrite ${fd}`)
|
|
2410
|
+
);
|
|
2411
|
+
},
|
|
2347
2412
|
isatty(fd) {
|
|
2348
2413
|
return json(call2({ op: "fd-info", fd }, `fd-info ${fd}`))?.tty === true;
|
|
2349
2414
|
},
|
|
@@ -2482,6 +2547,11 @@ async function runWasmProcess(init, port, deps = {}) {
|
|
|
2482
2547
|
}
|
|
2483
2548
|
});
|
|
2484
2549
|
syncFsync(imports, () => ownValue(module, "FS"));
|
|
2550
|
+
positionalIo(imports, {
|
|
2551
|
+
fs: () => ownValue(module, "FS"),
|
|
2552
|
+
sys,
|
|
2553
|
+
memory: () => memory
|
|
2554
|
+
});
|
|
2485
2555
|
return WebAssembly.instantiate(init.program.module, imports);
|
|
2486
2556
|
}).then((instance) => {
|
|
2487
2557
|
memory = wasmMemory(instance, imports);
|