@ai-ecoverse/slicc-kernel 1.136.7 → 1.137.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.
@@ -6699,7 +6699,7 @@ var KERNEL_VERSION, OS_RELEASE;
6699
6699
  var init_version = __esm({
6700
6700
  "src/version.ts"() {
6701
6701
  "use strict";
6702
- KERNEL_VERSION = true ? "1.136.7" : "0.0.0-dev";
6702
+ KERNEL_VERSION = true ? "1.137.0" : "0.0.0-dev";
6703
6703
  OS_RELEASE = "6.0.0-slicc";
6704
6704
  }
6705
6705
  });
@@ -7784,6 +7784,20 @@ var init_js_net = __esm({
7784
7784
  }
7785
7785
  });
7786
7786
 
7787
+ // src/kernel/proc-info.ts
7788
+ function mayTrace(viewer, target) {
7789
+ const by = viewer?.cred;
7790
+ const of = target.cred;
7791
+ if (!by || !of || by.euid === 0) return true;
7792
+ const uid = of.ruid === by.euid && of.euid === by.euid && of.suid === by.euid;
7793
+ return uid && of.rgid === by.egid && of.egid === by.egid && of.sgid === by.egid;
7794
+ }
7795
+ var init_proc_info = __esm({
7796
+ "src/kernel/proc-info.ts"() {
7797
+ "use strict";
7798
+ }
7799
+ });
7800
+
7787
7801
  // src/fs/owners.ts
7788
7802
  function inGroup(cred, gid) {
7789
7803
  return cred.egid === gid || cred.groups.includes(gid);
@@ -10619,6 +10633,25 @@ function attr(node) {
10619
10633
  blocks: 0
10620
10634
  };
10621
10635
  }
10636
+ function withPidFiles(names, extra) {
10637
+ return [.../* @__PURE__ */ new Set([...names, ...PID_FILES, ...extra])];
10638
+ }
10639
+ function exeNodes(fresh, info, error, self) {
10640
+ return {
10641
+ exeLink: (parent, target, own = false) => {
10642
+ const of = info(target, own);
10643
+ const exe = of?.exe;
10644
+ if (!of || exe === void 0) throw error();
10645
+ const link = fresh(parent, "exe", LINK_MODE2);
10646
+ link.node_ops.readlink = () => {
10647
+ if (!mayTrace(info(self, true), of)) throw error(EACCES);
10648
+ return exe;
10649
+ };
10650
+ return link;
10651
+ },
10652
+ hasExe: (target, own = false) => info(target, own)?.exe === void 0 ? [] : ["exe"]
10653
+ };
10654
+ }
10622
10655
  function useProcfs(Fs, sys, pid, memory = memorySource()) {
10623
10656
  const { lookupPath, createNode, hashRemoveNode } = Fs;
10624
10657
  const procList = sys.procList?.bind(sys);
@@ -10685,14 +10718,16 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
10685
10718
  dir.node_ops.readdir = () => [".", "..", ...Object.keys(tree)];
10686
10719
  return dir;
10687
10720
  };
10688
- const pidNames = (names) => [.../* @__PURE__ */ new Set([...names, ...PID_FILES])];
10721
+ const exe = exeNodes(fresh, (at, own) => find(procList().processes, at, own), error, pid);
10722
+ const pidNames = (names) => withPidFiles(names, exe.hasExe(pid, true));
10689
10723
  const pidDir = (name2, target) => {
10690
10724
  const dir = fresh(proc, name2, DIR_MODE2);
10691
10725
  dir.node_ops.lookup = (parent, child) => {
10726
+ if (child === "exe") return exe.exeLink(parent, target);
10692
10727
  if (!PID_FILES.includes(child)) throw error();
10693
10728
  return file(parent, child, pidContent(target, child));
10694
10729
  };
10695
- dir.node_ops.readdir = () => [".", "..", ...PID_FILES];
10730
+ dir.node_ops.readdir = () => [".", "..", ...PID_FILES, ...exe.hasExe(target)];
10696
10731
  return dir;
10697
10732
  };
10698
10733
  const scans = /* @__PURE__ */ new Map();
@@ -10776,6 +10811,7 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
10776
10811
  self.node_ops = {
10777
10812
  ...selfOps,
10778
10813
  lookup: (parent, name2) => {
10814
+ if (name2 === "exe") return exe.exeLink(parent, pid, true);
10779
10815
  if (PID_FILES.includes(name2)) {
10780
10816
  return file(parent, name2, pidContent(pid, name2, true));
10781
10817
  }
@@ -10785,11 +10821,12 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
10785
10821
  readdir: (node) => pidNames(selfReaddir ? selfReaddir(node) : [".", ".."])
10786
10822
  };
10787
10823
  }
10788
- var HZ, DIR_MODE2, FILE_MODE, LINK_MODE2, ENOENT, EINVAL, UID2, KIB, FALLBACK_MEMORY, PID_FILES, SYSTEM_FILES, SYS_TREE, sigMask, STATES, tagLine;
10824
+ var HZ, DIR_MODE2, FILE_MODE, LINK_MODE2, ENOENT, EINVAL, EACCES, UID2, KIB, FALLBACK_MEMORY, PID_FILES, SYSTEM_FILES, SYS_TREE, sigMask, STATES, tagLine;
10789
10825
  var init_procfs = __esm({
10790
10826
  "src/process/procfs.ts"() {
10791
10827
  "use strict";
10792
10828
  init_cred();
10829
+ init_proc_info();
10793
10830
  init_version();
10794
10831
  init_process_fds();
10795
10832
  HZ = 100;
@@ -10798,6 +10835,7 @@ var init_procfs = __esm({
10798
10835
  LINK_MODE2 = 41471;
10799
10836
  ENOENT = 44;
10800
10837
  EINVAL = 28;
10838
+ EACCES = 2;
10801
10839
  UID2 = 1e3;
10802
10840
  KIB = 1024;
10803
10841
  FALLBACK_MEMORY = 4 * KIB * KIB * KIB;
@@ -11096,6 +11134,7 @@ var DIR_MODE3, FILE_MODE2, LINK_MODE3, PID_NAMES, SYSTEM_NAMES, ProcTree, FOLLOW
11096
11134
  var init_wasi_procfs = __esm({
11097
11135
  "src/process/wasi/wasi-procfs.ts"() {
11098
11136
  "use strict";
11137
+ init_proc_info();
11099
11138
  init_sync_fs_wire();
11100
11139
  init_process_fds();
11101
11140
  init_procfs();
@@ -11156,7 +11195,16 @@ var init_wasi_procfs = __esm({
11156
11195
  if (!/^[1-9]\d*$/.test(top) || !this.alive(Number(top))) return void 0;
11157
11196
  if (leaf === "task") return this.task(Number(top), rest2);
11158
11197
  if (rest2.length > 0) return void 0;
11159
- if (leaf === void 0) return { kind: "dir", names: () => [...PID_NAMES, "task"] };
11198
+ if (leaf === void 0) {
11199
+ const exe = () => this.info(Number(top))?.exe === void 0 ? [] : ["exe"];
11200
+ return { kind: "dir", names: () => [...PID_NAMES, ...exe(), "task"] };
11201
+ }
11202
+ if (leaf === "exe") {
11203
+ const info = this.info(Number(top));
11204
+ if (info?.exe === void 0) return void 0;
11205
+ const denied = !mayTrace(this.ownInfo(), info);
11206
+ return { kind: "link", target: info.exe, ...denied ? { denied } : {} };
11207
+ }
11160
11208
  if (!PID_NAMES.includes(leaf)) return void 0;
11161
11209
  return {
11162
11210
  kind: "file",
@@ -11168,6 +11216,10 @@ var init_wasi_procfs = __esm({
11168
11216
  }
11169
11217
  };
11170
11218
  }
11219
+ ownInfo() {
11220
+ const processes2 = this.listing().processes;
11221
+ return processes2.find((p) => p.tid === this.pid) ?? processes2.find((p) => p.pid === this.pid);
11222
+ }
11171
11223
  info(pid) {
11172
11224
  return this.listing().processes.find((p) => p.pid === pid);
11173
11225
  }
@@ -11231,6 +11283,7 @@ var init_wasi_procfs = __esm({
11231
11283
  readlink(path) {
11232
11284
  const node = this.find(path, false);
11233
11285
  if (node.kind !== "link") throw syncError("EINVAL", path);
11286
+ if (node.denied) throw syncError("EACCES", path);
11234
11287
  return node.target;
11235
11288
  }
11236
11289
  exists(path) {
@@ -13843,11 +13896,19 @@ function identify(transport, init) {
13843
13896
  function liveParent(imports, parent, glue) {
13844
13897
  wrapImport(imports, "getppid", glue, () => parent);
13845
13898
  }
13846
- function signalMasks(m) {
13899
+ function seedInherited(transport, seeded) {
13900
+ const bits = inheritedSignals(transport);
13901
+ seeded.bits |= bits;
13902
+ return bits;
13903
+ }
13904
+ function signalMasks(m, seeded = { bits: 0 }) {
13847
13905
  const mask = m.sliccSigMask;
13848
13906
  const caught = mask?.(0) ?? -1;
13849
13907
  if (!mask || caught === -1) return null;
13850
- return { caught, ignored: mask(1), restart: mask(2) };
13908
+ const ignored = mask(1);
13909
+ const defaults = seeded.bits & ~ignored & ~caught;
13910
+ seeded.bits &= ~defaults;
13911
+ return { caught, ignored, restart: mask(2), ...defaults ? { defaults } : {} };
13851
13912
  }
13852
13913
  function reportGrowth(imports, publish, glue) {
13853
13914
  wrapImport(imports, "resizeHeap", glue, (resize) => (...args) => {
@@ -13951,13 +14012,12 @@ function sigpipeSpared(transport) {
13951
14012
  return r.ok && !(r.kind === "json" && r.json === "terminate");
13952
14013
  }
13953
14014
  async function runWasmProcess(init, port3, deps = {}) {
14015
+ const seeded = { bits: 0 };
13954
14016
  const signals = new SignalGate(
13955
- createSyncSabTransport(init.sab, port3, {
13956
- memory: () => memory?.buffer.byteLength ?? 0
13957
- }),
14017
+ createSyncSabTransport(init.sab, port3, { memory: () => memory?.buffer.byteLength ?? 0 }),
13958
14018
  new Int32Array(init.sab, 0, SAB_HEADER_I32),
13959
14019
  {
13960
- masks: () => signalMasks(module),
14020
+ masks: () => signalMasks(module, seeded),
13961
14021
  raise: (sig) => module.sliccRaise?.(sig),
13962
14022
  timer: (which) => {
13963
14023
  const running2 = module;
@@ -13990,7 +14050,7 @@ async function runWasmProcess(init, port3, deps = {}) {
13990
14050
  sliccPid: id.pid,
13991
14051
  sliccPpid: id.ppid,
13992
14052
  sliccEnv: init.env,
13993
- sliccKernel: { sigInherited: () => inheritedSignals(transport) },
14053
+ sliccKernel: { sigInherited: () => seedInherited(transport, seeded) },
13994
14054
  print: say(1),
13995
14055
  printErr: say(2),
13996
14056
  instantiateWasm(imports, done) {