@ai-ecoverse/slicc-kernel 1.99.2 → 1.100.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
@@ -3030,7 +3030,7 @@ async function runTagged(l, self, requested, tag) {
3030
3030
  }
3031
3031
  function processes(l, self) {
3032
3032
  const viewer = credOf(self);
3033
- return l.list(viewer).map(({ tid: _, cred = viewer, umask: _umask, ...entry }) => ({
3033
+ return l.list(viewer).map(({ tid: _, cred = viewer, umask: _umask, threads: _threads, ...entry }) => ({
3034
3034
  ...entry,
3035
3035
  rss: entry.memory,
3036
3036
  uid: cred.euid,
@@ -10572,6 +10572,13 @@ var ProcessClocks = class {
10572
10572
  running() {
10573
10573
  return this.enabled ? this.all().filter((c) => c.running()).length : 0;
10574
10574
  }
10575
+ states() {
10576
+ const state = (c) => c.running() ? "R" : "S";
10577
+ return [
10578
+ { tid: 1, state: state(this.main) },
10579
+ ...[...this.threads].map(([tid, c]) => ({ tid, state: state(c) }))
10580
+ ];
10581
+ }
10575
10582
  timed(clock, dispatch2) {
10576
10583
  const c = clock ?? this.main;
10577
10584
  const block = () => c.block();
@@ -11100,7 +11107,7 @@ var PATH_OPS = new Set(SYNC_FS_OPS);
11100
11107
  var EARLY_WHOLE_FILE = 64 * 1024;
11101
11108
 
11102
11109
  // src/version.ts
11103
- var KERNEL_VERSION = true ? "1.99.2" : "0.0.0-dev";
11110
+ var KERNEL_VERSION = true ? "1.100.1" : "0.0.0-dev";
11104
11111
  var OS_RELEASE = "6.0.0-slicc";
11105
11112
  function procVersion() {
11106
11113
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -11160,11 +11167,11 @@ function pages(bytes) {
11160
11167
  function ticks(ms) {
11161
11168
  return Math.max(0, Math.floor(ms * HZ / 1e3));
11162
11169
  }
11163
- function pidStat(info, boot) {
11170
+ function pidStat(info, boot, state = info.state) {
11164
11171
  const fields = [
11165
11172
  info.pid,
11166
11173
  `(${commOf(info)})`,
11167
- info.state,
11174
+ state,
11168
11175
  info.ppid,
11169
11176
  info.pgid,
11170
11177
  info.sid,
@@ -11202,8 +11209,19 @@ function pidStat(info, boot) {
11202
11209
  `;
11203
11210
  }
11204
11211
  var sigMask = (mask = 0) => (mask >>> 1).toString(16).padStart(16, "0");
11205
- var STATES = { S: "S (sleeping)", T: "T (stopped)", Z: "Z (zombie)" };
11212
+ var STATES = {
11213
+ S: "S (sleeping)",
11214
+ T: "T (stopped)",
11215
+ Z: "Z (zombie)"
11216
+ };
11206
11217
  var tagLine = (tag) => `Tag: ${tag.replaceAll("\n", "\\n").replaceAll(" ", "\\t").replaceAll("\r", "\\r")}`;
11218
+ function taskStat(info, tid, boot) {
11219
+ const thread = (info.threads ?? [{ tid: 1, state: info.state }]).find((t) => t.tid === tid);
11220
+ return thread && pidStat({ ...info, pid: tid }, boot, thread.state);
11221
+ }
11222
+ function taskIds(info) {
11223
+ return (info.threads ?? [{ tid: 1 }]).map((t) => t.tid);
11224
+ }
11207
11225
  function pidStatus(info) {
11208
11226
  const state = STATES[info.state];
11209
11227
  const c = info.cred ?? ROOT;
@@ -11381,8 +11399,10 @@ var ProcTree = class {
11381
11399
  content: () => systemFile(top, this.listing(), Date.now(), this.memory)
11382
11400
  };
11383
11401
  }
11384
- if (!/^[1-9]\d*$/.test(top) || rest2.length > 0 || !this.alive(Number(top))) return void 0;
11385
- if (leaf === void 0) return { kind: "dir", names: () => [...PID_NAMES] };
11402
+ if (!/^[1-9]\d*$/.test(top) || !this.alive(Number(top))) return void 0;
11403
+ if (leaf === "task") return this.task(Number(top), rest2);
11404
+ if (rest2.length > 0) return void 0;
11405
+ if (leaf === void 0) return { kind: "dir", names: () => [...PID_NAMES, "task"] };
11386
11406
  if (!PID_NAMES.includes(leaf)) return void 0;
11387
11407
  return {
11388
11408
  kind: "file",
@@ -11394,6 +11414,28 @@ var ProcTree = class {
11394
11414
  }
11395
11415
  };
11396
11416
  }
11417
+ info(pid) {
11418
+ return this.listing().processes.find((p) => p.pid === pid);
11419
+ }
11420
+ task(pid, rest2) {
11421
+ const [tid, leaf, ...more] = rest2;
11422
+ const tids = () => taskIds(this.info(pid));
11423
+ if (tid === void 0) return { kind: "dir", names: () => tids().map(String) };
11424
+ if (!/^[1-9]\d*$/.test(tid) || more.length > 0 || !tids().includes(Number(tid)))
11425
+ return void 0;
11426
+ if (leaf === void 0) return { kind: "dir", names: () => ["stat"] };
11427
+ if (leaf !== "stat") return void 0;
11428
+ return {
11429
+ kind: "file",
11430
+ content: () => {
11431
+ const listing = this.listing();
11432
+ const info = listing.processes.find((p) => p.pid === pid);
11433
+ const line = info && taskStat(info, Number(tid), listing.boot);
11434
+ if (line === void 0) throw syncError("ENOENT", `/proc/${pid}/task/${tid}/stat`);
11435
+ return line;
11436
+ }
11437
+ };
11438
+ }
11397
11439
  parts(path, follow2) {
11398
11440
  const parts2 = path.split("/").filter((p) => p !== "").slice(1);
11399
11441
  if (parts2[0] === "self" && (follow2 || parts2.length > 1)) parts2[0] = String(this.pid);
@@ -12140,7 +12182,7 @@ async function recordLock2(req, ctx) {
12140
12182
  return done2;
12141
12183
  }
12142
12184
  const range = lockRange(req.start, req.len);
12143
- const key = await fileKey(target, req.kind);
12185
+ const key = await fileKey(target, req.kind, req.op === "lk-set" && req.fd !== void 0);
12144
12186
  if (req.op === "lk-get") {
12145
12187
  const held = locks.holder(key, owner, { key, kind: req.kind, ...range });
12146
12188
  if (!held) return json3(null);
@@ -15624,7 +15666,7 @@ var WasmProcess = class {
15624
15666
  return await hostSyscall(req, {
15625
15667
  pid: this.pid,
15626
15668
  owner: () => this.lockOwner(),
15627
- fileKey: (target, kind) => this.lockKey(target, kind),
15669
+ fileKey: (target, kind, setting) => this.lockKey(target, kind, setting),
15628
15670
  locks: this.options.locks,
15629
15671
  ops: this.asyncOps,
15630
15672
  blocking: () => this.blockingSignal(cancelled),
@@ -15676,8 +15718,11 @@ var WasmProcess = class {
15676
15718
  }
15677
15719
  return path;
15678
15720
  }
15679
- async lockKey(target, kind) {
15721
+ async lockKey(target, kind, setting = false) {
15680
15722
  const file = target.fd === void 0 ? void 0 : this.fds.get(target.fd);
15723
+ const access2 = file?.file;
15724
+ if (setting && (kind === "read" && !access2?.read || kind === "write" && !access2?.write))
15725
+ throw new KernelError("EBADF");
15681
15726
  const known = file ? fileKeys.get(file) : this.pathKeys.get(target.path ?? "");
15682
15727
  if (kind === "close" && !file && target.path !== void 0) this.pathKeys.delete(target.path);
15683
15728
  const want = kind === "read" ? R_OK : kind === "write" ? W_OK : 0;
@@ -17042,8 +17087,14 @@ function spawnWasmProcess(opts) {
17042
17087
  umask: () => process2.umask,
17043
17088
  cred: () => copyCred(process2.cred),
17044
17089
  writesBack: () => opts.program.abi === "wasi" && !done4,
17090
+ ...clockViews(clocks)
17091
+ };
17092
+ }
17093
+ function clockViews(clocks) {
17094
+ return {
17045
17095
  times: () => clocks.times(),
17046
- running: () => clocks.running()
17096
+ running: () => clocks.running(),
17097
+ threads: () => clocks.states()
17047
17098
  };
17048
17099
  }
17049
17100
 
@@ -21565,6 +21616,7 @@ var Launcher = class {
21565
21616
  ...described2,
21566
21617
  started: (this.described.get(root.pid) ?? described2).started,
21567
21618
  state: this.stateOf(member.pid),
21619
+ ...this.threadsOf(member.pid),
21568
21620
  memory: this.processes.get(member.pid)?.memory() ?? 0,
21569
21621
  ...this.timesOf(member, members),
21570
21622
  ...this.childrenOf(root.pid),
@@ -21576,6 +21628,10 @@ var Launcher = class {
21576
21628
  }
21577
21629
  return listed;
21578
21630
  }
21631
+ threadsOf(pid) {
21632
+ const threads = this.stateOf(pid) === "S" ? this.processes.get(pid)?.threads?.() : void 0;
21633
+ return threads ? { threads } : {};
21634
+ }
21579
21635
  sudo(pid, call, signal) {
21580
21636
  const caller = {
21581
21637
  cred: this.credOf(pid),