@ai-ecoverse/slicc-kernel 1.16.1 → 1.17.1
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/README.md +25 -2
- package/dist/index.js +14 -1
- package/dist/index.js.map +2 -2
- package/dist/kernel-worker.js +3697 -3442
- package/dist/kernel-worker.js.map +4 -4
- package/dist/node-process-worker.js +114 -59
- package/dist/node-process-worker.js.map +2 -2
- package/dist/node.js +4825 -4584
- package/dist/node.js.map +4 -4
- package/dist/process-worker.js +114 -59
- package/dist/process-worker.js.map +2 -2
- package/package.json +1 -1
|
@@ -1020,15 +1020,18 @@ var init_wasi_errno = __esm({
|
|
|
1020
1020
|
EPROTONOSUPPORT: 66,
|
|
1021
1021
|
EOPNOTSUPP: 138,
|
|
1022
1022
|
EBADF: 8,
|
|
1023
|
+
EBUSY: 10,
|
|
1023
1024
|
ECHILD: 12,
|
|
1024
1025
|
EFAULT: 21,
|
|
1025
1026
|
EINTR: 27,
|
|
1026
1027
|
EINVAL: 28,
|
|
1027
1028
|
EIO: 29,
|
|
1028
1029
|
EMFILE: 33,
|
|
1030
|
+
ENODEV: 43,
|
|
1029
1031
|
ENOENT: 44,
|
|
1030
1032
|
ENOEXEC: 45,
|
|
1031
1033
|
ENOSYS: 52,
|
|
1034
|
+
ENOTDIR: 54,
|
|
1032
1035
|
ENOTTY: 59,
|
|
1033
1036
|
ENXIO: 60,
|
|
1034
1037
|
EPERM: 63,
|
|
@@ -1443,10 +1446,30 @@ function ownReady(Fs, read, write) {
|
|
|
1443
1446
|
write: write.filter((fd) => flags(fd) & (POLLOUT2 | POLLERR2 | POLLNVAL))
|
|
1444
1447
|
};
|
|
1445
1448
|
}
|
|
1449
|
+
function anySelect(Fs, transport, read, write, timeoutMs) {
|
|
1450
|
+
const kernel = (fd) => Fs.getStream(fd)?.sliccKernelFd;
|
|
1451
|
+
const own = (fd) => kernel(fd) === void 0;
|
|
1452
|
+
if (![...read, ...write].some(own)) return kernelSelect(Fs, transport, read, write, timeoutMs);
|
|
1453
|
+
const deadline = timeoutMs < 0 ? Number.POSITIVE_INFINITY : Date.now() + timeoutMs;
|
|
1454
|
+
const kernelRead = read.filter((fd) => !own(fd));
|
|
1455
|
+
const kernelWrite = write.filter((fd) => !own(fd));
|
|
1456
|
+
for (; ; ) {
|
|
1457
|
+
const local = ownReady(Fs, read.filter(own), write.filter(own));
|
|
1458
|
+
const pending = local.read.length > 0 || local.write.length > 0;
|
|
1459
|
+
const slice = pending ? 0 : Math.min(SELECT_SLICE_MS, Math.max(0, deadline - Date.now()));
|
|
1460
|
+
const got = kernelSelect(Fs, transport, kernelRead, kernelWrite, slice);
|
|
1461
|
+
if (typeof got === "number") return got;
|
|
1462
|
+
const ready = { read: [...local.read, ...got.read], write: [...local.write, ...got.write] };
|
|
1463
|
+
if (ready.read.length > 0 || ready.write.length > 0 || Date.now() >= deadline) {
|
|
1464
|
+
return ready;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1446
1468
|
function createProcessKernel(deps) {
|
|
1447
1469
|
const { transport, Fs } = deps;
|
|
1448
1470
|
const reaped = /* @__PURE__ */ new Map();
|
|
1449
1471
|
const call2 = (req, label) => transport.call(req, Infinity, label);
|
|
1472
|
+
const at = (path) => path === "" || path.startsWith("/") ? path : `${Fs.cwd()}/${path}`;
|
|
1450
1473
|
const slot = (fd, n, promote) => {
|
|
1451
1474
|
const stream = fd >= 0 ? Fs.getStream(fd) : null;
|
|
1452
1475
|
if (!stream) return { none: true };
|
|
@@ -1483,35 +1506,52 @@ function createProcessKernel(deps) {
|
|
|
1483
1506
|
Fs.write(stream, r.bytes, 0, r.bytes.length);
|
|
1484
1507
|
}
|
|
1485
1508
|
};
|
|
1509
|
+
const execCaptures = /* @__PURE__ */ new Map();
|
|
1510
|
+
const execWait = (pid) => {
|
|
1511
|
+
const r = transport.call({ op: "proc-exec", pid }, Infinity, `exec ${pid}`);
|
|
1512
|
+
if (!r.ok) return -wasiErrno(r.errno);
|
|
1513
|
+
deps.afterChild();
|
|
1514
|
+
return r.kind === "json" ? r.json[1] : 0;
|
|
1515
|
+
};
|
|
1516
|
+
const spawnChild = (file, argv, env, cwd, fds, actions, exec) => {
|
|
1517
|
+
const unflushed = flushed(deps.beforeSpawn);
|
|
1518
|
+
if (unflushed < 0) return unflushed;
|
|
1519
|
+
const promote = deps.stdioPromoter?.();
|
|
1520
|
+
const stdio = [0, 1, 2].map((n) => slot(fds[n] ?? -1, n, promote));
|
|
1521
|
+
const inherit = deps.inherit?.(actions) ?? [];
|
|
1522
|
+
const r = transport.call(
|
|
1523
|
+
{
|
|
1524
|
+
op: "proc-spawn",
|
|
1525
|
+
file,
|
|
1526
|
+
argv,
|
|
1527
|
+
env: env ?? deps.env,
|
|
1528
|
+
cwd: cwd ?? Fs.cwd(),
|
|
1529
|
+
stdio,
|
|
1530
|
+
...inherit.length > 0 ? { inherit } : {},
|
|
1531
|
+
...exec ? { exec } : {}
|
|
1532
|
+
},
|
|
1533
|
+
Infinity,
|
|
1534
|
+
`proc-spawn ${file}`
|
|
1535
|
+
);
|
|
1536
|
+
if (!r.ok) return -wasiErrno(r.errno);
|
|
1537
|
+
const pid = r.kind === "json" ? r.json : 0;
|
|
1538
|
+
const captures = [1, 2].filter((n) => "capture" in stdio[n]);
|
|
1539
|
+
if (captures.length === 0) return pid;
|
|
1540
|
+
if (exec) {
|
|
1541
|
+
execCaptures.set(pid, () => {
|
|
1542
|
+
for (const n of captures) deliver(pid, n, fds[n]);
|
|
1543
|
+
});
|
|
1544
|
+
return pid;
|
|
1545
|
+
}
|
|
1546
|
+
const waited = kernelWait(pid, false);
|
|
1547
|
+
if (typeof waited === "number") return waited;
|
|
1548
|
+
for (const n of captures) deliver(pid, n, fds[n]);
|
|
1549
|
+
reaped.set(pid, waited[1]);
|
|
1550
|
+
return pid;
|
|
1551
|
+
};
|
|
1486
1552
|
return {
|
|
1487
1553
|
spawn(file, argv, env, cwd, fds, actions) {
|
|
1488
|
-
|
|
1489
|
-
if (unflushed < 0) return unflushed;
|
|
1490
|
-
const promote = deps.stdioPromoter?.();
|
|
1491
|
-
const stdio = [0, 1, 2].map((n) => slot(fds[n] ?? -1, n, promote));
|
|
1492
|
-
const inherit = deps.inherit?.(actions) ?? [];
|
|
1493
|
-
const r = transport.call(
|
|
1494
|
-
{
|
|
1495
|
-
op: "proc-spawn",
|
|
1496
|
-
file,
|
|
1497
|
-
argv,
|
|
1498
|
-
env: env ?? deps.env,
|
|
1499
|
-
cwd: cwd ?? Fs.cwd(),
|
|
1500
|
-
stdio,
|
|
1501
|
-
...inherit.length > 0 ? { inherit } : {}
|
|
1502
|
-
},
|
|
1503
|
-
Infinity,
|
|
1504
|
-
`proc-spawn ${file}`
|
|
1505
|
-
);
|
|
1506
|
-
if (!r.ok) return -wasiErrno(r.errno);
|
|
1507
|
-
const pid = r.kind === "json" ? r.json : 0;
|
|
1508
|
-
const captures = [1, 2].filter((n) => "capture" in stdio[n]);
|
|
1509
|
-
if (captures.length === 0) return pid;
|
|
1510
|
-
const waited = kernelWait(pid, false);
|
|
1511
|
-
if (typeof waited === "number") return waited;
|
|
1512
|
-
for (const n of captures) deliver(pid, n, fds[n]);
|
|
1513
|
-
reaped.set(pid, waited[1]);
|
|
1514
|
-
return pid;
|
|
1554
|
+
return spawnChild(file, argv, env, cwd, fds, actions, false);
|
|
1515
1555
|
},
|
|
1516
1556
|
fork(state) {
|
|
1517
1557
|
const unflushed = flushed(deps.beforeSpawn);
|
|
@@ -1525,35 +1565,26 @@ function createProcessKernel(deps) {
|
|
|
1525
1565
|
if (!r.ok) return -wasiErrno(r.errno);
|
|
1526
1566
|
return r.kind === "json" ? r.json : -wasiErrno("EIO");
|
|
1527
1567
|
},
|
|
1528
|
-
select(read, write, timeoutMs)
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
const
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
const local = ownReady(Fs, read.filter(own), write.filter(own));
|
|
1538
|
-
const pending = local.read.length > 0 || local.write.length > 0;
|
|
1539
|
-
const slice = pending ? 0 : Math.min(SELECT_SLICE_MS, Math.max(0, deadline - Date.now()));
|
|
1540
|
-
const got = kernelSelect(Fs, transport, kernelRead, kernelWrite, slice);
|
|
1541
|
-
if (typeof got === "number") return got;
|
|
1542
|
-
const ready = { read: [...local.read, ...got.read], write: [...local.write, ...got.write] };
|
|
1543
|
-
if (ready.read.length > 0 || ready.write.length > 0 || Date.now() >= deadline) {
|
|
1544
|
-
return ready;
|
|
1545
|
-
}
|
|
1546
|
-
}
|
|
1547
|
-
},
|
|
1548
|
-
execWait(pid) {
|
|
1549
|
-
const r = transport.call({ op: "proc-exec", pid }, Infinity, `exec ${pid}`);
|
|
1550
|
-
if (!r.ok) return -wasiErrno(r.errno);
|
|
1551
|
-
deps.afterChild();
|
|
1552
|
-
return r.kind === "json" ? r.json[1] : 0;
|
|
1568
|
+
select: (read, write, timeoutMs) => anySelect(Fs, transport, read, write, timeoutMs),
|
|
1569
|
+
execWait,
|
|
1570
|
+
execve(file, argv, env, cwd) {
|
|
1571
|
+
const pid = spawnChild(file, argv, env, cwd, [0, 1, 2], void 0, true);
|
|
1572
|
+
if (pid < 0) return pid;
|
|
1573
|
+
const status2 = execWait(pid);
|
|
1574
|
+
execCaptures.get(pid)?.();
|
|
1575
|
+
execCaptures.delete(pid);
|
|
1576
|
+
return status2;
|
|
1553
1577
|
},
|
|
1554
1578
|
pause() {
|
|
1555
1579
|
return status(call2({ op: "sig-pause" }, "pause"));
|
|
1556
1580
|
},
|
|
1581
|
+
mount(source, target, type, flags, data) {
|
|
1582
|
+
const req = { op: "mount", source, target: at(target), type, flags, data };
|
|
1583
|
+
return status(call2(req, `mount ${target}`));
|
|
1584
|
+
},
|
|
1585
|
+
umount2(target, flags) {
|
|
1586
|
+
return status(call2({ op: "umount", target: at(target), flags }, `umount ${target}`));
|
|
1587
|
+
},
|
|
1557
1588
|
kill(pid, sig) {
|
|
1558
1589
|
if (pid === deps.pid) {
|
|
1559
1590
|
if (sig !== 0) deps.raise?.(sig);
|
|
@@ -1973,6 +2004,7 @@ function mountTable(mounts = []) {
|
|
|
1973
2004
|
const lines = [`${root} / ${root} rw 0 0`, "devfs /dev devfs rw 0 0", "proc /proc proc rw 0 0"];
|
|
1974
2005
|
for (const m of mounts) {
|
|
1975
2006
|
const options = Object.entries(m.options).map(([k, v]) => v === "" ? k : `${k}=${v}`);
|
|
2007
|
+
if (m.state !== "ok") options.push(m.state);
|
|
1976
2008
|
const access = options.includes("ro") ? [] : ["rw"];
|
|
1977
2009
|
lines.push(
|
|
1978
2010
|
`${field(m.source)} ${field(m.target)} ${m.type} ${[...access, ...options].join(",")} 0 0`
|
|
@@ -4414,6 +4446,24 @@ var init_wasi_host = __esm({
|
|
|
4414
4446
|
get cwd() {
|
|
4415
4447
|
return this.fds.cwd() ?? this.startCwd;
|
|
4416
4448
|
}
|
|
4449
|
+
sliccImports() {
|
|
4450
|
+
const { mem } = this;
|
|
4451
|
+
const path = (p, l) => {
|
|
4452
|
+
const text = mem.string(p, l);
|
|
4453
|
+
return text === "" || text.startsWith("/") ? text : normalize(`${this.cwd}/${text}`);
|
|
4454
|
+
};
|
|
4455
|
+
return wrap({
|
|
4456
|
+
mount: (sp, sl, tp, tl, fp, fl, flags, dp, dl) => void this.o.kernel.call({
|
|
4457
|
+
op: "mount",
|
|
4458
|
+
source: mem.string(sp, sl),
|
|
4459
|
+
target: path(tp, tl),
|
|
4460
|
+
type: mem.string(fp, fl),
|
|
4461
|
+
flags,
|
|
4462
|
+
data: mem.string(dp, dl)
|
|
4463
|
+
}),
|
|
4464
|
+
umount2: (tp, tl, flags) => void this.o.kernel.call({ op: "umount", target: path(tp, tl), flags })
|
|
4465
|
+
});
|
|
4466
|
+
}
|
|
4417
4467
|
imports() {
|
|
4418
4468
|
this.cache ??= wrap({
|
|
4419
4469
|
...this.processImports(),
|
|
@@ -5788,7 +5838,7 @@ var init_wasix_process = __esm({
|
|
|
5788
5838
|
...op.oflags & OFLAG_TRUNC ? { truncate: true } : {}
|
|
5789
5839
|
});
|
|
5790
5840
|
}
|
|
5791
|
-
spawn(req) {
|
|
5841
|
+
spawn(req, exec = false) {
|
|
5792
5842
|
const { stdio, inherit, cwd, opened } = this.childFds(req.ops ?? []);
|
|
5793
5843
|
try {
|
|
5794
5844
|
return this.call({
|
|
@@ -5798,7 +5848,8 @@ var init_wasix_process = __esm({
|
|
|
5798
5848
|
env: req.env ?? this.environment(),
|
|
5799
5849
|
cwd,
|
|
5800
5850
|
stdio,
|
|
5801
|
-
inherit
|
|
5851
|
+
inherit,
|
|
5852
|
+
...exec ? { exec } : {}
|
|
5802
5853
|
});
|
|
5803
5854
|
} finally {
|
|
5804
5855
|
for (const kfd of opened) this.host.o.kernel.sys.close(kfd);
|
|
@@ -5806,7 +5857,7 @@ var init_wasix_process = __esm({
|
|
|
5806
5857
|
}
|
|
5807
5858
|
}
|
|
5808
5859
|
exec(req) {
|
|
5809
|
-
const pid = this.spawn(req);
|
|
5860
|
+
const pid = this.spawn(req, true);
|
|
5810
5861
|
const [, status2] = this.call({ op: "proc-exec", pid });
|
|
5811
5862
|
const sig = status2 & 127;
|
|
5812
5863
|
throw new WasiExit(sig ? 128 + sig : status2 >> 8 & 255);
|
|
@@ -6549,12 +6600,14 @@ function unsupportedImport(module, memory, extended = false, foreign = {}) {
|
|
|
6549
6600
|
}
|
|
6550
6601
|
return void 0;
|
|
6551
6602
|
}
|
|
6552
|
-
function linkImports(module, preview1, wasix, memory, threads, program = {}, foreign) {
|
|
6603
|
+
function linkImports(module, preview1, wasix, memory, threads, program = {}, foreign, slicc = {}) {
|
|
6553
6604
|
for (const ns of Object.keys(program)) {
|
|
6554
|
-
if (RESERVED.has(ns)
|
|
6605
|
+
if (RESERVED.has(ns) || ns === SLICC)
|
|
6606
|
+
throw new Error(`the imports module may not define ${ns}`);
|
|
6555
6607
|
}
|
|
6556
6608
|
const imports = {
|
|
6557
6609
|
...program,
|
|
6610
|
+
[SLICC]: { ...slicc },
|
|
6558
6611
|
[PREVIEW1]: preview1,
|
|
6559
6612
|
...wasix ? { [WASIX]: { ...wasix } } : {},
|
|
6560
6613
|
...threads ? { wasi: { "thread-spawn": (arg) => threads.spawn(arg) } } : {}
|
|
@@ -6680,7 +6733,8 @@ async function instantiate(host, module, memory, threads, {
|
|
|
6680
6733
|
() => memory ?? instance?.exports.memory,
|
|
6681
6734
|
() => instance
|
|
6682
6735
|
);
|
|
6683
|
-
const
|
|
6736
|
+
const slicc = traced(stats, "slicc", host.sliccImports());
|
|
6737
|
+
const hostImports = linkImports(module, preview1, wasix, memory, threads, extra, foreign, slicc);
|
|
6684
6738
|
const imports = sync ? merge(hostImports, sync.linker.mainImports(module)) : hostImports;
|
|
6685
6739
|
instance = await WebAssembly.instantiate(module, imports);
|
|
6686
6740
|
stats?.phase("instantiate");
|
|
@@ -6856,7 +6910,7 @@ async function runWasiThread(init, port2) {
|
|
|
6856
6910
|
throw e;
|
|
6857
6911
|
}
|
|
6858
6912
|
}
|
|
6859
|
-
var TRAPPED, PREVIEW1, WASIX, RESERVED, noErrno, FALLBACK_MAXIMUM_PAGES, LinkSync, DL_GEN, BACKTRACE_FRAMES;
|
|
6913
|
+
var TRAPPED, PREVIEW1, WASIX, SLICC, RESERVED, noErrno, FALLBACK_MAXIMUM_PAGES, LinkSync, DL_GEN, BACKTRACE_FRAMES;
|
|
6860
6914
|
var init_wasi_runtime = __esm({
|
|
6861
6915
|
"src/process/wasi/wasi-runtime.ts"() {
|
|
6862
6916
|
"use strict";
|
|
@@ -6881,6 +6935,7 @@ var init_wasi_runtime = __esm({
|
|
|
6881
6935
|
TRAPPED = 134;
|
|
6882
6936
|
PREVIEW1 = "wasi_snapshot_preview1";
|
|
6883
6937
|
WASIX = "wasix_32v1";
|
|
6938
|
+
SLICC = "slicc";
|
|
6884
6939
|
RESERVED = RESERVED_NAMESPACES;
|
|
6885
6940
|
noErrno = (key) => `imports ${key}: its result cannot carry ENOSYS, and this host does not provide it`;
|
|
6886
6941
|
FALLBACK_MAXIMUM_PAGES = 32768;
|