@ai-ecoverse/slicc-kernel 1.32.3 → 1.33.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/README.md +22 -0
- package/dist/index.js.map +2 -2
- package/dist/kernel-worker.js +134 -30
- package/dist/kernel-worker.js.map +3 -3
- package/dist/node-process-worker.js +739 -26
- package/dist/node-process-worker.js.map +4 -4
- package/dist/node.js +134 -30
- package/dist/node.js.map +3 -3
- package/dist/process-worker.js +740 -26
- package/dist/process-worker.js.map +4 -4
- package/package.json +1 -1
package/dist/kernel-worker.js
CHANGED
|
@@ -4548,7 +4548,7 @@ function argsOf(pkg, raw) {
|
|
|
4548
4548
|
}
|
|
4549
4549
|
function abiOf(raw, fallback) {
|
|
4550
4550
|
const abi = raw ?? fallback;
|
|
4551
|
-
return abi === "emscripten" || abi === "wasi" ? abi : void 0;
|
|
4551
|
+
return abi === "emscripten" || abi === "wasi" || abi === "js" ? abi : void 0;
|
|
4552
4552
|
}
|
|
4553
4553
|
function commandOf(pkg, name2, raw, packageAbi, shared) {
|
|
4554
4554
|
const withEnv = envFields({ ...shared, ...envOf(pkg, raw.env) });
|
|
@@ -4557,11 +4557,25 @@ function commandOf(pkg, name2, raw, packageAbi, shared) {
|
|
|
4557
4557
|
return { name: name2, abi: packageAbi, glue: script, wasm: script, argv0: name2, script, ...withEnv };
|
|
4558
4558
|
}
|
|
4559
4559
|
const abi = abiOf(raw.abi, packageAbi);
|
|
4560
|
+
const argv0 = typeof raw.argv0 === "string" && raw.argv0 ? raw.argv0 : name2;
|
|
4561
|
+
const args = argsOf(pkg, raw.args);
|
|
4562
|
+
if (abi === "js") {
|
|
4563
|
+
const module = inside(pkg, raw.module);
|
|
4564
|
+
if (!module) return void 0;
|
|
4565
|
+
return {
|
|
4566
|
+
name: name2,
|
|
4567
|
+
abi,
|
|
4568
|
+
glue: module,
|
|
4569
|
+
wasm: module,
|
|
4570
|
+
argv0,
|
|
4571
|
+
...raw.argv0Path === true ? { argv0Path: true } : {},
|
|
4572
|
+
...args ? { args } : {},
|
|
4573
|
+
...withEnv
|
|
4574
|
+
};
|
|
4575
|
+
}
|
|
4560
4576
|
const wasm = inside(pkg, raw.wasm);
|
|
4561
4577
|
const glue = abi === "wasi" ? wasm : inside(pkg, raw.glue);
|
|
4562
4578
|
if (!abi || !glue || !wasm) return void 0;
|
|
4563
|
-
const argv0 = typeof raw.argv0 === "string" && raw.argv0 ? raw.argv0 : name2;
|
|
4564
|
-
const args = argsOf(pkg, raw.args);
|
|
4565
4579
|
const imports = abi === "wasi" ? inside(pkg, raw.imports) : void 0;
|
|
4566
4580
|
return {
|
|
4567
4581
|
name: name2,
|
|
@@ -5268,12 +5282,12 @@ var MountTable = class {
|
|
|
5268
5282
|
}
|
|
5269
5283
|
list() {
|
|
5270
5284
|
const mounted = [...this.mounts.values()].map(
|
|
5271
|
-
({ type, source, target, options, state, error, present }) => ({
|
|
5285
|
+
({ type, source, target, options, state, error, present: present2 }) => ({
|
|
5272
5286
|
type,
|
|
5273
5287
|
source,
|
|
5274
5288
|
target,
|
|
5275
5289
|
options: { ...options },
|
|
5276
|
-
state: state === "ok" &&
|
|
5290
|
+
state: state === "ok" && present2?.() === false ? "nomedium" : state,
|
|
5277
5291
|
...error ? { error } : {}
|
|
5278
5292
|
})
|
|
5279
5293
|
);
|
|
@@ -5982,6 +5996,8 @@ var SAB_I_MEMORY = 10;
|
|
|
5982
5996
|
var SAB_I_TOTAL_HI = 11;
|
|
5983
5997
|
var SAB_I_OFFSET_HI = 12;
|
|
5984
5998
|
var SAB_I_KILLED = 13;
|
|
5999
|
+
var SAB_I_ASYNC = 14;
|
|
6000
|
+
var SAB_I_STOP = 15;
|
|
5985
6001
|
var U32 = 2 ** 32;
|
|
5986
6002
|
function storeU53(header2, lo, hi, value) {
|
|
5987
6003
|
Atomics.store(header2, hi, Math.floor(value / U32));
|
|
@@ -6163,8 +6179,10 @@ var AsyncOps = class {
|
|
|
6163
6179
|
waiters = /* @__PURE__ */ new Set();
|
|
6164
6180
|
closed = false;
|
|
6165
6181
|
run;
|
|
6166
|
-
|
|
6182
|
+
onReady;
|
|
6183
|
+
constructor(run2, onReady) {
|
|
6167
6184
|
this.run = run2;
|
|
6185
|
+
this.onReady = onReady;
|
|
6168
6186
|
}
|
|
6169
6187
|
submit(req) {
|
|
6170
6188
|
const id = this.hold();
|
|
@@ -6241,6 +6259,7 @@ var AsyncOps = class {
|
|
|
6241
6259
|
this.results.set(id, result);
|
|
6242
6260
|
this.ready.push(id);
|
|
6243
6261
|
this.wake();
|
|
6262
|
+
this.onReady?.();
|
|
6244
6263
|
}
|
|
6245
6264
|
wake() {
|
|
6246
6265
|
for (const wake of [...this.waiters]) wake();
|
|
@@ -7399,6 +7418,9 @@ var VfsNode = class {
|
|
|
7399
7418
|
}
|
|
7400
7419
|
return this.data;
|
|
7401
7420
|
}
|
|
7421
|
+
holds() {
|
|
7422
|
+
return this.dirty;
|
|
7423
|
+
}
|
|
7402
7424
|
replace(contents2) {
|
|
7403
7425
|
this.ranged = void 0;
|
|
7404
7426
|
this.data = new Uint8Array(contents2);
|
|
@@ -7509,9 +7531,34 @@ var VfsNode = class {
|
|
|
7509
7531
|
var VfsNodes = class {
|
|
7510
7532
|
byPath = /* @__PURE__ */ new Map();
|
|
7511
7533
|
fs;
|
|
7534
|
+
entries = /* @__PURE__ */ new Map();
|
|
7512
7535
|
constructor(fs) {
|
|
7513
7536
|
this.fs = fs;
|
|
7514
7537
|
}
|
|
7538
|
+
async onEntry(path, op) {
|
|
7539
|
+
const key = await this.entryKey(path);
|
|
7540
|
+
const run2 = (this.entries.get(key) ?? Promise.resolve()).then(op);
|
|
7541
|
+
const tail = run2.catch(() => void 0);
|
|
7542
|
+
this.entries.set(key, tail);
|
|
7543
|
+
void tail.then(() => {
|
|
7544
|
+
if (this.entries.get(key) === tail) this.entries.delete(key);
|
|
7545
|
+
});
|
|
7546
|
+
return run2;
|
|
7547
|
+
}
|
|
7548
|
+
async entryKey(path) {
|
|
7549
|
+
const parent = parentOf5(path);
|
|
7550
|
+
const dir = await realDir(this.fs, parent).catch(() => parent);
|
|
7551
|
+
const name2 = path.slice(path.lastIndexOf("/") + 1);
|
|
7552
|
+
return dir === "/" ? `/${name2}` : `${dir}/${name2}`;
|
|
7553
|
+
}
|
|
7554
|
+
createExclusive(path) {
|
|
7555
|
+
return this.onEntry(path, async () => {
|
|
7556
|
+
const node = this.byPath.get(path);
|
|
7557
|
+
const held = node ? await node.serial(async () => node.holds()) : false;
|
|
7558
|
+
if (held || await present(this.fs, path)) throw fsError("EEXIST", path);
|
|
7559
|
+
await this.fs.writeFile(path, new Uint8Array(0));
|
|
7560
|
+
});
|
|
7561
|
+
}
|
|
7515
7562
|
open(path, pin) {
|
|
7516
7563
|
let node = this.byPath.get(path);
|
|
7517
7564
|
if (!node) {
|
|
@@ -7580,6 +7627,16 @@ var VfsNodes = class {
|
|
|
7580
7627
|
}
|
|
7581
7628
|
}
|
|
7582
7629
|
};
|
|
7630
|
+
async function present(fs, path, follow = false) {
|
|
7631
|
+
const look = (follow ? void 0 : fs.lstat) ?? fs.stat;
|
|
7632
|
+
try {
|
|
7633
|
+
await (look ? look.call(fs, path) : fs.readFileBuffer(path));
|
|
7634
|
+
return true;
|
|
7635
|
+
} catch (err) {
|
|
7636
|
+
if (err?.code === "ENOENT") return false;
|
|
7637
|
+
throw err;
|
|
7638
|
+
}
|
|
7639
|
+
}
|
|
7583
7640
|
var MAX_LINKS5 = 40;
|
|
7584
7641
|
function parentOf5(path) {
|
|
7585
7642
|
return path.slice(0, path.lastIndexOf("/")) || "/";
|
|
@@ -7644,12 +7701,17 @@ function keepingOpen(fs, nodes) {
|
|
|
7644
7701
|
await fs.rm(path, options);
|
|
7645
7702
|
nodes.unlinked(at);
|
|
7646
7703
|
},
|
|
7647
|
-
|
|
7704
|
+
rename(from, to) {
|
|
7648
7705
|
const [a, b] = [fs.resolvePath("/", from), fs.resolvePath("/", to)];
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
7652
|
-
|
|
7706
|
+
return nodes.onEntry(b, async () => {
|
|
7707
|
+
await nodes.unlinking(b);
|
|
7708
|
+
await fs.rename(from, to);
|
|
7709
|
+
nodes.renamed(a, b);
|
|
7710
|
+
});
|
|
7711
|
+
},
|
|
7712
|
+
writeFile: (path, content) => nodes.onEntry(fs.resolvePath("/", path), () => fs.writeFile(path, content)),
|
|
7713
|
+
symlink: (target, path) => nodes.onEntry(fs.resolvePath("/", path), () => fs.symlink(target, path)),
|
|
7714
|
+
mkdir: (path, options) => nodes.onEntry(fs.resolvePath("/", path), () => fs.mkdir(path, options))
|
|
7653
7715
|
};
|
|
7654
7716
|
}
|
|
7655
7717
|
function vfsFile(fs, opts, nodes) {
|
|
@@ -7988,6 +8050,21 @@ var WasmProcess = class {
|
|
|
7988
8050
|
this.options.hasPending?.() ? AbortSignal.abort() : this.interrupt.signal
|
|
7989
8051
|
);
|
|
7990
8052
|
}
|
|
8053
|
+
async openVfs(req) {
|
|
8054
|
+
await refuseReadonly(this.options.fs, req.path, req.flags, req);
|
|
8055
|
+
const fd = this.fds.install(heldFile(), 3);
|
|
8056
|
+
try {
|
|
8057
|
+
if (req.exclusive) await this.nodes.createExclusive(req.path);
|
|
8058
|
+
this.fds.installAt(fd, this.openVfsFile(req));
|
|
8059
|
+
if (req.existing && !await present(this.options.fs, req.path, true)) {
|
|
8060
|
+
throw new KernelError("ENOENT");
|
|
8061
|
+
}
|
|
8062
|
+
} catch (err) {
|
|
8063
|
+
await Promise.resolve(this.fds.close(fd));
|
|
8064
|
+
throw err;
|
|
8065
|
+
}
|
|
8066
|
+
return fd;
|
|
8067
|
+
}
|
|
7991
8068
|
openVfsFile(req) {
|
|
7992
8069
|
return vfsFile(
|
|
7993
8070
|
this.options.fs,
|
|
@@ -8030,8 +8107,7 @@ var WasmProcess = class {
|
|
|
8030
8107
|
case "fd-poll":
|
|
8031
8108
|
return { ok: true, kind: "json", json: pollFile(this.fds.get(req.fd).file) };
|
|
8032
8109
|
case "fd-open-vfs":
|
|
8033
|
-
|
|
8034
|
-
return { ok: true, kind: "json", json: this.fds.install(this.openVfsFile(req), 3) };
|
|
8110
|
+
return { ok: true, kind: "json", json: await this.openVfs(req) };
|
|
8035
8111
|
case "fd-info":
|
|
8036
8112
|
return { ok: true, kind: "json", json: this.fdInfo(req.fd) };
|
|
8037
8113
|
case "fd-list":
|
|
@@ -8309,6 +8385,7 @@ var WasmProcess = class {
|
|
|
8309
8385
|
case "sig-mask":
|
|
8310
8386
|
this.caught = req.caught;
|
|
8311
8387
|
this.ignored = req.ignored;
|
|
8388
|
+
this.inherited &= ~(req.defaults ?? 0);
|
|
8312
8389
|
return { ok: true, kind: "void" };
|
|
8313
8390
|
case "sig-pause":
|
|
8314
8391
|
return this.pause();
|
|
@@ -8338,7 +8415,10 @@ var WasmProcess = class {
|
|
|
8338
8415
|
}
|
|
8339
8416
|
alarm;
|
|
8340
8417
|
dlLog = [];
|
|
8341
|
-
asyncOps = new AsyncOps(
|
|
8418
|
+
asyncOps = new AsyncOps(
|
|
8419
|
+
(req) => this.syscall(req),
|
|
8420
|
+
() => this.options.onAsync?.()
|
|
8421
|
+
);
|
|
8342
8422
|
alarmEvery;
|
|
8343
8423
|
setAlarm(sig, first, every, timer) {
|
|
8344
8424
|
if (!isSignal(sig)) throw new KernelError("EINVAL");
|
|
@@ -8447,6 +8527,26 @@ var Dying = class {
|
|
|
8447
8527
|
return [typeof reported === "number" ? reported : CRASHED, void 0];
|
|
8448
8528
|
}
|
|
8449
8529
|
};
|
|
8530
|
+
function processInit(opts, sab) {
|
|
8531
|
+
const base = {
|
|
8532
|
+
type: WASM_PROCESS_INIT,
|
|
8533
|
+
pid: opts.shownPid ?? opts.pid,
|
|
8534
|
+
argv0: opts.argv0,
|
|
8535
|
+
args: opts.args,
|
|
8536
|
+
env: opts.env,
|
|
8537
|
+
cwd: opts.cwd,
|
|
8538
|
+
sab,
|
|
8539
|
+
...opts.ppid !== void 0 ? { ppid: opts.ppid } : {}
|
|
8540
|
+
};
|
|
8541
|
+
if (opts.program.abi === "js") {
|
|
8542
|
+
return { ...base, program: opts.program, fds: inheritedFds(opts.fds) };
|
|
8543
|
+
}
|
|
8544
|
+
return {
|
|
8545
|
+
...base,
|
|
8546
|
+
program: opts.program,
|
|
8547
|
+
...opts.fork ? { fork: opts.fork } : { fds: inheritedFds(opts.fds) }
|
|
8548
|
+
};
|
|
8549
|
+
}
|
|
8450
8550
|
function spawnWasmProcess(opts) {
|
|
8451
8551
|
const sab = new SharedArrayBuffer(SAB_HEADER_BYTES + SAB_DEFAULT_WINDOW_BYTES);
|
|
8452
8552
|
const header2 = new Int32Array(sab, 0, SAB_HEADER_I32);
|
|
@@ -8472,11 +8572,22 @@ function spawnWasmProcess(opts) {
|
|
|
8472
8572
|
locks: opts.locks,
|
|
8473
8573
|
onReap: opts.onReap,
|
|
8474
8574
|
resolver: opts.resolver,
|
|
8475
|
-
onPending: (sig) =>
|
|
8575
|
+
onPending: (sig) => {
|
|
8576
|
+
Atomics.or(header2, SAB_I_SIGNALS, sigbit(sig));
|
|
8577
|
+
Atomics.notify(header2, SAB_I_SIGNALS);
|
|
8578
|
+
},
|
|
8579
|
+
onAsync: () => {
|
|
8580
|
+
Atomics.add(header2, SAB_I_ASYNC, 1);
|
|
8581
|
+
Atomics.notify(header2, SAB_I_ASYNC);
|
|
8582
|
+
},
|
|
8476
8583
|
onTimer: (which) => void Atomics.or(header2, SAB_I_TIMERS, 1 << which),
|
|
8477
8584
|
hasPending: () => Atomics.load(header2, SAB_I_SIGNALS) !== 0 || Atomics.load(header2, SAB_I_TIMERS) !== 0,
|
|
8478
8585
|
raise: (sig) => signal(sig),
|
|
8479
|
-
...opts.program.abi === "wasi" ? { pendingBits: () => Atomics.load(header2, SAB_I_SIGNALS) } : {}
|
|
8586
|
+
...opts.program.abi === "wasi" || opts.program.abi === "js" ? { pendingBits: () => Atomics.load(header2, SAB_I_SIGNALS) } : {}
|
|
8587
|
+
});
|
|
8588
|
+
process.onState((state) => {
|
|
8589
|
+
Atomics.store(header2, SAB_I_STOP, state === "stopped" ? 1 : 0);
|
|
8590
|
+
Atomics.notify(header2, SAB_I_STOP);
|
|
8480
8591
|
});
|
|
8481
8592
|
const holds = new HeldPaths();
|
|
8482
8593
|
opts.held?.add(holds);
|
|
@@ -8537,7 +8648,8 @@ function spawnWasmProcess(opts) {
|
|
|
8537
8648
|
end?.();
|
|
8538
8649
|
};
|
|
8539
8650
|
const spawnThread = (thread) => {
|
|
8540
|
-
|
|
8651
|
+
const { program } = opts;
|
|
8652
|
+
if (done4 || program.abi === "js") return;
|
|
8541
8653
|
if (threads.size >= WASM_MAX_THREADS - 1) {
|
|
8542
8654
|
opts.onError?.(`more than ${WASM_MAX_THREADS} threads`);
|
|
8543
8655
|
finish(CRASHED);
|
|
@@ -8562,7 +8674,7 @@ function spawnWasmProcess(opts) {
|
|
|
8562
8674
|
const tinit = {
|
|
8563
8675
|
type: WASM_THREAD_INIT,
|
|
8564
8676
|
pid: opts.shownPid ?? opts.pid,
|
|
8565
|
-
program
|
|
8677
|
+
program,
|
|
8566
8678
|
argv0: opts.argv0,
|
|
8567
8679
|
args: opts.args,
|
|
8568
8680
|
env: opts.env,
|
|
@@ -8573,18 +8685,7 @@ function spawnWasmProcess(opts) {
|
|
|
8573
8685
|
};
|
|
8574
8686
|
tw.postMessage(tinit);
|
|
8575
8687
|
};
|
|
8576
|
-
const init =
|
|
8577
|
-
type: WASM_PROCESS_INIT,
|
|
8578
|
-
pid: opts.shownPid ?? opts.pid,
|
|
8579
|
-
program: opts.program,
|
|
8580
|
-
argv0: opts.argv0,
|
|
8581
|
-
args: opts.args,
|
|
8582
|
-
env: opts.env,
|
|
8583
|
-
cwd: opts.cwd,
|
|
8584
|
-
sab,
|
|
8585
|
-
...opts.ppid !== void 0 ? { ppid: opts.ppid } : {},
|
|
8586
|
-
...opts.fork ? { fork: opts.fork } : { fds: inheritedFds(opts.fds) }
|
|
8587
|
-
};
|
|
8688
|
+
const init = processInit(opts, sab);
|
|
8588
8689
|
worker.postMessage(init, opts.fork ? [opts.fork.memory.buffer] : []);
|
|
8589
8690
|
const signal = (sig) => {
|
|
8590
8691
|
if (process.signal(sig) !== "terminate") return;
|
|
@@ -10257,6 +10358,9 @@ var Launcher = class {
|
|
|
10257
10358
|
return await this.base.exists(optional) ? optional : void 0;
|
|
10258
10359
|
}
|
|
10259
10360
|
async program(target, env) {
|
|
10361
|
+
if (target.abi === "js") {
|
|
10362
|
+
return { abi: "js", glue: await this.base.readFile(target.wasm), path: target.wasm };
|
|
10363
|
+
}
|
|
10260
10364
|
if (target.abi !== "wasi") {
|
|
10261
10365
|
const [glue, { module: module2 }] = await Promise.all([
|
|
10262
10366
|
this.base.readFile(target.glue),
|