@ai-ecoverse/slicc-kernel 1.76.0 → 1.77.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.
@@ -9575,6 +9575,7 @@ var IDLE_OPS = /* @__PURE__ */ new Set([
9575
9575
  ]);
9576
9576
  var SYS_CAP_US = 2e4;
9577
9577
  var LOCAL = SAB_CLOCK_OFFSET;
9578
+ var BLOCKED = 0;
9578
9579
  var IDLE = 1;
9579
9580
  function epochMicros() {
9580
9581
  return Math.floor((performance.timeOrigin + performance.now()) * 1e3);
@@ -9649,6 +9650,7 @@ var CpuClock = class {
9649
9650
  const busy = this.kind === "sys" ? Math.min(spent, SYS_CAP_US) : 0;
9650
9651
  this.sys += busy;
9651
9652
  this.idle += spent - busy;
9653
+ Atomics.store(slots(this.sab), BLOCKED, BigInt(this.idle));
9652
9654
  }
9653
9655
  };
9654
9656
  var ProcessClocks = class {
@@ -9993,8 +9995,8 @@ function pidStat(info, boot) {
9993
9995
  0,
9994
9996
  ticks(info.utime ?? 0),
9995
9997
  ticks(info.stime ?? 0),
9996
- 0,
9997
- 0,
9998
+ ticks(info.cutime ?? 0),
9999
+ ticks(info.cstime ?? 0),
9998
10000
  20,
9999
10001
  0,
10000
10002
  1,
@@ -10018,8 +10020,9 @@ function pidStat(info, boot) {
10018
10020
  `;
10019
10021
  }
10020
10022
  var sigMask = (mask = 0) => (mask >>> 1).toString(16).padStart(16, "0");
10023
+ var STATES = { S: "S (sleeping)", T: "T (stopped)", Z: "Z (zombie)" };
10021
10024
  function pidStatus(info) {
10022
- const state = info.state === "Z" ? "Z (zombie)" : "S (sleeping)";
10025
+ const state = STATES[info.state];
10023
10026
  const c = info.cred ?? ROOT;
10024
10027
  const ids = (r, e, s) => `${r} ${e} ${s} ${e}`;
10025
10028
  return [
@@ -12308,6 +12311,16 @@ function words(value) {
12308
12311
  }
12309
12312
  return [...value];
12310
12313
  }
12314
+ var ESCAPES = { " ": "\\t", "\n": "\\n", "\r": "\\r" };
12315
+ function clipboardLine(text) {
12316
+ let out = "";
12317
+ for (const c of text) {
12318
+ const code = c.charCodeAt(0);
12319
+ const control = code < 32 || code === 127;
12320
+ out += control ? ESCAPES[c] ?? `\\x${code.toString(16).padStart(2, "0")}` : c;
12321
+ }
12322
+ return out.length > 200 ? `${out.slice(0, 200)}\u2026` : out;
12323
+ }
12311
12324
  var DYING = { ok: false, errno: "EINTR", message: "the process is being killed" };
12312
12325
  var HOSTS_ONLY = new Resolver({ routes: new Routes() });
12313
12326
  var WasmProcess = class {
@@ -12560,7 +12573,22 @@ var WasmProcess = class {
12560
12573
  if (req.max <= 0) return new Uint8Array(0);
12561
12574
  if (channel.unread) channel.stamp = await this.clipboardStamp();
12562
12575
  const signal = channel.settled ? this.interrupt.signal : this.blockingSignal(cancelled);
12563
- return channel.read(Math.min(req.max, MAX_READ), signal);
12576
+ try {
12577
+ return await channel.read(Math.min(req.max, MAX_READ), signal);
12578
+ } catch (err) {
12579
+ await this.clipboardComplaint(err);
12580
+ throw err;
12581
+ }
12582
+ }
12583
+ async clipboardComplaint(err) {
12584
+ const name2 = this.options.clipboardName;
12585
+ if (name2 === void 0 || !(err instanceof KernelError) || err.detail === void 0) return;
12586
+ if (err.code !== "EACCES" && err.code !== "EIO") return;
12587
+ const stderr = this.fds.has(2) ? this.fds.get(2).file : void 0;
12588
+ if (!stderr?.write || stderr.clipboard) return;
12589
+ const line = `${name2}: /dev/clipboard: ${clipboardLine(err.detail)}
12590
+ `;
12591
+ await stderr.write(new TextEncoder().encode(line), AbortSignal.timeout(1e3)).catch(() => 0);
12564
12592
  }
12565
12593
  async write(fd, body, nonblock = false, cancelled) {
12566
12594
  const file = this.fds.get(fd).file;
@@ -12773,7 +12801,10 @@ var WasmProcess = class {
12773
12801
  this.options.locks?.closed(this.pid, req.fd);
12774
12802
  const channel = this.fds.get(req.fd).file.clipboard;
12775
12803
  if (channel) channel.stamp = await this.clipboardStamp();
12776
- await Promise.resolve(this.fds.close(req.fd));
12804
+ await Promise.resolve(this.fds.close(req.fd)).catch(async (err) => {
12805
+ if (channel) await this.clipboardComplaint(err);
12806
+ throw err;
12807
+ });
12777
12808
  return { ok: true, kind: "void" };
12778
12809
  }
12779
12810
  case "fd-pipe": {
@@ -13464,12 +13495,15 @@ function holdingToken(opts, holds, caller) {
13464
13495
  renamed: (from, to) => holds.renamed(from, to)
13465
13496
  });
13466
13497
  }
13498
+ function clipboardName(opts) {
13499
+ return opts.program.abi === "js" ? {} : { clipboardName: opts.argv0 };
13500
+ }
13467
13501
  function processOptions(opts, header3, hooks, created3) {
13468
13502
  return {
13469
13503
  ...inherited(opts),
13470
13504
  ...opts.owners ? { owners: true } : {},
13471
13505
  ...opts.sealed ? { sealed: opts.sealed } : {},
13472
- ...opts.clipboard ? { clipboard: opts.clipboard } : {},
13506
+ ...opts.clipboard ? { clipboard: opts.clipboard, ...clipboardName(opts) } : {},
13473
13507
  ...opts.readonlyAt ? { readonlyAt: opts.readonlyAt } : {},
13474
13508
  ...opts.dac ? { guard: { dac: opts.dac, fs: opts.fs, created: created3 } } : {},
13475
13509
  ...opts.identity ? { identity: opts.identity } : {},
@@ -16258,6 +16292,10 @@ function concat5(chunks) {
16258
16292
  }
16259
16293
  return out;
16260
16294
  }
16295
+ function addTimes(into, pid, t) {
16296
+ const at = into.get(pid) ?? { utime: 0, stime: 0 };
16297
+ into.set(pid, { utime: at.utime + t.utime, stime: at.stime + t.stime });
16298
+ }
16261
16299
  var Launcher = class {
16262
16300
  fs;
16263
16301
  processFs;
@@ -16795,7 +16833,7 @@ var Launcher = class {
16795
16833
  http: new HttpHandles(this.transport, pid),
16796
16834
  locks: this.locks,
16797
16835
  resolver: this.resolver,
16798
- onReap: (child) => this.reaped(child),
16836
+ onReap: (child) => this.reaped(child, pid),
16799
16837
  ...req.fork ? { fork: req.fork } : {},
16800
16838
  ...this.shownIds(req)
16801
16839
  });
@@ -16814,9 +16852,14 @@ var Launcher = class {
16814
16852
  tty: terminal?.name ?? null,
16815
16853
  started: Date.now()
16816
16854
  });
16855
+ handle.onState(
16856
+ (state) => state === "stopped" ? this.stopped.add(pid) : this.stopped.delete(pid)
16857
+ );
16817
16858
  void handle.exited.then(() => {
16818
16859
  const spent = handle.times?.();
16819
16860
  if (spent) this.spent.set(pid, spent);
16861
+ if (spent) addTimes(this.imageTimes, this.jobs.shown(pid), spent);
16862
+ this.stopped.delete(pid);
16820
16863
  this.processes.delete(pid);
16821
16864
  if (this.processes.size === 0) {
16822
16865
  clearInterval(this.sampler);
@@ -16844,11 +16887,20 @@ var Launcher = class {
16844
16887
  this.reapedTimes.stime += spent.stime;
16845
16888
  }
16846
16889
  this.spent.delete(pid);
16890
+ this.imageTimes.delete(pid);
16891
+ this.childTimes.delete(pid);
16847
16892
  this.creds.delete(pid);
16848
16893
  this.tags.delete(pid);
16849
16894
  this.granted.delete(pid);
16850
16895
  }
16851
- reaped(pid) {
16896
+ reaped(pid, parent) {
16897
+ const own = this.imageTimes.get(pid);
16898
+ const theirs = this.childTimes.get(pid);
16899
+ const into = this.jobs.shown(parent);
16900
+ if (own) addTimes(this.childTimes, into, own);
16901
+ if (theirs) addTimes(this.childTimes, into, theirs);
16902
+ this.imageTimes.delete(pid);
16903
+ this.childTimes.delete(pid);
16852
16904
  if (this.zombies.delete(pid)) this.forget(pid);
16853
16905
  else this.orphans.add(pid);
16854
16906
  }
@@ -16900,6 +16952,17 @@ var Launcher = class {
16900
16952
  this.sampler.unref?.();
16901
16953
  }
16902
16954
  spent = /* @__PURE__ */ new Map();
16955
+ imageTimes = /* @__PURE__ */ new Map();
16956
+ childTimes = /* @__PURE__ */ new Map();
16957
+ stopped = /* @__PURE__ */ new Set();
16958
+ stateOf(pid) {
16959
+ if (!this.processes.has(pid)) return "Z";
16960
+ return this.stopped.has(pid) ? "T" : "S";
16961
+ }
16962
+ childrenOf(pid) {
16963
+ const t = this.childTimes.get(pid);
16964
+ return t ? { cutime: t.utime, cstime: t.stime } : {};
16965
+ }
16903
16966
  timesAt(pid) {
16904
16967
  return this.processes.get(pid)?.times?.() ?? this.spent.get(pid);
16905
16968
  }
@@ -16945,9 +17008,10 @@ var Launcher = class {
16945
17008
  sid: member.sid,
16946
17009
  ...described2,
16947
17010
  started: (this.described.get(root.pid) ?? described2).started,
16948
- state: this.processes.has(member.pid) ? "S" : "Z",
17011
+ state: this.stateOf(member.pid),
16949
17012
  memory: this.processes.get(member.pid)?.memory() ?? 0,
16950
17013
  ...this.timesOf(member, members),
17014
+ ...this.childrenOf(root.pid),
16951
17015
  umask: this.umaskOf(member.pid),
16952
17016
  cred,
16953
17017
  ...this.signalMasksOf(member.pid)