@ai-ecoverse/slicc-kernel 1.29.2 → 1.30.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/dist/node.js CHANGED
@@ -3082,6 +3082,7 @@ function commandOf(pkg, name2, raw, packageAbi, shared) {
3082
3082
  wasm,
3083
3083
  argv0,
3084
3084
  ...raw.argv0Path === true ? { argv0Path: true } : {},
3085
+ ...abi === "wasi" && raw.preopenRoot === true ? { preopenRoot: true } : {},
3085
3086
  ...args ? { args } : {},
3086
3087
  ...withEnv,
3087
3088
  ...imports ? { imports } : {}
@@ -7593,7 +7594,7 @@ var WasmProcess = class {
7593
7594
  for (const listener of this.stateListeners) listener("continued", SIG.CONT);
7594
7595
  }
7595
7596
  async syscall(req) {
7596
- this.options.onSyscall?.();
7597
+ this.options.onSyscall?.(req);
7597
7598
  for (; ; ) {
7598
7599
  await this.resumed;
7599
7600
  const stops = this.stops;
@@ -7717,9 +7718,10 @@ var WasmProcess = class {
7717
7718
  json: this.fds.numbers().map((fd) => ({ fd, ...this.fdInfo(fd) }))
7718
7719
  };
7719
7720
  case "fd-meta": {
7720
- const file = this.fds.get(req.fd).file;
7721
- if (!file.held) throw new KernelError("EBADF");
7722
- file.heldMeta = req.meta;
7721
+ if (!this.fds.get(req.fd).file.held) throw new KernelError("EBADF");
7722
+ const cloexec = this.fds.closesOnExec(req.fd);
7723
+ this.fds.installAt(req.fd, heldFile(req.meta));
7724
+ if (cloexec) this.fds.setCloseOnExec(req.fd);
7723
7725
  return { ok: true, kind: "void" };
7724
7726
  }
7725
7727
  case "fd-setfl":
@@ -8386,6 +8388,57 @@ var JobTable = class {
8386
8388
  }
8387
8389
  };
8388
8390
 
8391
+ // src/kernel/settling.ts
8392
+ var SETUP_OPS = /* @__PURE__ */ new Set([
8393
+ "proc-list",
8394
+ "proc-identity",
8395
+ "fd-info",
8396
+ "sig-mask",
8397
+ "proc-setpgid",
8398
+ "tty-pgrp-set"
8399
+ ]);
8400
+ var SETTLE_MS = 250;
8401
+ var KEY_SIGNALS = /* @__PURE__ */ new Set([2, 3, 20]);
8402
+ var SettlingChildren = class {
8403
+ children = /* @__PURE__ */ new Map();
8404
+ held = [];
8405
+ pgidOf;
8406
+ settleMs;
8407
+ constructor(pgidOf, settleMs = SETTLE_MS) {
8408
+ this.pgidOf = pgidOf;
8409
+ this.settleMs = settleMs;
8410
+ }
8411
+ started(pid, ppid) {
8412
+ this.children.set(pid, { ppid });
8413
+ }
8414
+ syscall(pid, op) {
8415
+ const child = this.children.get(pid);
8416
+ if (!child) return;
8417
+ if (!SETUP_OPS.has(op)) {
8418
+ this.settled(pid);
8419
+ return;
8420
+ }
8421
+ child.timer ??= setTimeout(() => this.settled(pid), this.settleMs);
8422
+ }
8423
+ settled(pid) {
8424
+ const child = this.children.get(pid);
8425
+ if (!child) return;
8426
+ clearTimeout(child.timer);
8427
+ this.children.delete(pid);
8428
+ const ready2 = this.held.filter((h) => !this.blocking(h.pgid));
8429
+ this.held = this.held.filter((h) => this.blocking(h.pgid));
8430
+ for (const h of ready2) h.send();
8431
+ }
8432
+ deliver(sig, pgid, send) {
8433
+ if (KEY_SIGNALS.has(sig) && this.blocking(pgid)) this.held.push({ pgid, send });
8434
+ else send();
8435
+ }
8436
+ blocking(pgid) {
8437
+ for (const { ppid } of this.children.values()) if (this.pgidOf(ppid) === pgid) return true;
8438
+ return false;
8439
+ }
8440
+ };
8441
+
8389
8442
  // src/mount/driver.ts
8390
8443
  function fsError2(code, message2 = code) {
8391
8444
  return Object.assign(new Error(message2), { code });
@@ -9620,7 +9673,8 @@ function targetOf(command) {
9620
9673
  ...command.args ? { prefix: command.args } : {},
9621
9674
  ...command.env ? { env: command.env } : {},
9622
9675
  ...command.unset ? { unset: command.unset } : {},
9623
- ...command.imports ? { imports: command.imports } : {}
9676
+ ...command.imports ? { imports: command.imports } : {},
9677
+ ...command.preopenRoot ? { preopenRoot: true } : {}
9624
9678
  };
9625
9679
  }
9626
9680
  function childHandle(handle) {
@@ -9654,7 +9708,14 @@ var Launcher = class {
9654
9708
  described = /* @__PURE__ */ new Map();
9655
9709
  jobs = new JobTable();
9656
9710
  locks = new LockTable();
9657
- ptys = new PtyTable((tty, sig) => this.jobs.signalOwnedForeground(tty, sig));
9711
+ settling = new SettlingChildren((pid) => this.jobs.pgidOf(pid));
9712
+ ptys = new PtyTable(
9713
+ (tty, sig) => this.settling.deliver(
9714
+ sig,
9715
+ this.jobs.tcgetpgrp(tty, 0),
9716
+ () => this.jobs.signalOwnedForeground(tty, sig)
9717
+ )
9718
+ );
9658
9719
  net = new LoopbackNet();
9659
9720
  cdp;
9660
9721
  ca;
@@ -9856,7 +9917,8 @@ var Launcher = class {
9856
9917
  ...memory ? { memory } : {},
9857
9918
  foreign,
9858
9919
  ...names ? { names } : {},
9859
- ...imports !== void 0 ? { imports } : {}
9920
+ ...imports !== void 0 ? { imports } : {},
9921
+ ...target.preopenRoot ? { preopenRoot: true } : {}
9860
9922
  };
9861
9923
  }
9862
9924
  async launch(planned, req) {
@@ -9893,7 +9955,10 @@ var Launcher = class {
9893
9955
  await (asked ??= decided.then(count));
9894
9956
  return this.identityOf(pid);
9895
9957
  },
9896
- onSyscall: () => this.decide(pid),
9958
+ onSyscall: (call) => {
9959
+ this.decide(pid);
9960
+ this.settling.syscall(pid, call.op);
9961
+ },
9897
9962
  ...req.ignored ? { ignored: req.ignored } : {},
9898
9963
  program: req.program,
9899
9964
  argv0: req.argv0,
@@ -9926,6 +9991,7 @@ var Launcher = class {
9926
9991
  ...this.shownIds(req)
9927
9992
  });
9928
9993
  this.processes.set(pid, handle);
9994
+ if (req.ppid !== void 0) this.settling.started(pid, req.ppid);
9929
9995
  this.jobs.add(pid, req.ppid, (sig) => handle.signal(sig), terminal);
9930
9996
  if (req.exec && req.ppid !== void 0) this.jobs.exec(req.ppid, pid, true);
9931
9997
  if (req.pgid !== void 0) this.jobs.join(pid, req.pgid);
@@ -9936,6 +10002,7 @@ var Launcher = class {
9936
10002
  });
9937
10003
  void handle.exited.then(() => {
9938
10004
  this.processes.delete(pid);
10005
+ this.settling.settled(pid);
9939
10006
  if (req.ppid === void 0 || this.orphans.delete(pid)) this.forget(pid);
9940
10007
  else this.zombies.add(pid);
9941
10008
  });
@@ -10248,7 +10315,11 @@ var Launcher = class {
10248
10315
  let leader = 0;
10249
10316
  const tty = new KernelTty(
10250
10317
  { write: (bytes) => options.onData(bytes.slice()) },
10251
- (sig) => this.jobs.signalForeground(tty, leader, sig)
10318
+ (sig) => this.settling.deliver(
10319
+ sig,
10320
+ this.jobs.tcgetpgrp(tty, leader),
10321
+ () => this.jobs.signalForeground(tty, leader, sig)
10322
+ )
10252
10323
  );
10253
10324
  tty.name = `/dev/tty${++this.terminals}`;
10254
10325
  tty.setSize(options.cols ?? 80, options.rows ?? 24);