@ai-ecoverse/slicc-kernel 1.30.0 → 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
@@ -7594,7 +7594,7 @@ var WasmProcess = class {
7594
7594
  for (const listener of this.stateListeners) listener("continued", SIG.CONT);
7595
7595
  }
7596
7596
  async syscall(req) {
7597
- this.options.onSyscall?.();
7597
+ this.options.onSyscall?.(req);
7598
7598
  for (; ; ) {
7599
7599
  await this.resumed;
7600
7600
  const stops = this.stops;
@@ -8388,6 +8388,57 @@ var JobTable = class {
8388
8388
  }
8389
8389
  };
8390
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
+
8391
8442
  // src/mount/driver.ts
8392
8443
  function fsError2(code, message2 = code) {
8393
8444
  return Object.assign(new Error(message2), { code });
@@ -9657,7 +9708,14 @@ var Launcher = class {
9657
9708
  described = /* @__PURE__ */ new Map();
9658
9709
  jobs = new JobTable();
9659
9710
  locks = new LockTable();
9660
- 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
+ );
9661
9719
  net = new LoopbackNet();
9662
9720
  cdp;
9663
9721
  ca;
@@ -9897,7 +9955,10 @@ var Launcher = class {
9897
9955
  await (asked ??= decided.then(count));
9898
9956
  return this.identityOf(pid);
9899
9957
  },
9900
- onSyscall: () => this.decide(pid),
9958
+ onSyscall: (call) => {
9959
+ this.decide(pid);
9960
+ this.settling.syscall(pid, call.op);
9961
+ },
9901
9962
  ...req.ignored ? { ignored: req.ignored } : {},
9902
9963
  program: req.program,
9903
9964
  argv0: req.argv0,
@@ -9930,6 +9991,7 @@ var Launcher = class {
9930
9991
  ...this.shownIds(req)
9931
9992
  });
9932
9993
  this.processes.set(pid, handle);
9994
+ if (req.ppid !== void 0) this.settling.started(pid, req.ppid);
9933
9995
  this.jobs.add(pid, req.ppid, (sig) => handle.signal(sig), terminal);
9934
9996
  if (req.exec && req.ppid !== void 0) this.jobs.exec(req.ppid, pid, true);
9935
9997
  if (req.pgid !== void 0) this.jobs.join(pid, req.pgid);
@@ -9940,6 +10002,7 @@ var Launcher = class {
9940
10002
  });
9941
10003
  void handle.exited.then(() => {
9942
10004
  this.processes.delete(pid);
10005
+ this.settling.settled(pid);
9943
10006
  if (req.ppid === void 0 || this.orphans.delete(pid)) this.forget(pid);
9944
10007
  else this.zombies.add(pid);
9945
10008
  });
@@ -10252,7 +10315,11 @@ var Launcher = class {
10252
10315
  let leader = 0;
10253
10316
  const tty = new KernelTty(
10254
10317
  { write: (bytes) => options.onData(bytes.slice()) },
10255
- (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
+ )
10256
10323
  );
10257
10324
  tty.name = `/dev/tty${++this.terminals}`;
10258
10325
  tty.setSize(options.cols ?? 80, options.rows ?? 24);