@ai-ecoverse/slicc-kernel 1.141.0 → 1.141.2

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.
@@ -978,8 +978,8 @@ function cachingBridge(bridge, now = () => performance.now(), shared) {
978
978
  readlink: (p) => {
979
979
  const known = blind ? void 0 : (cache.fresh(), lstats.get(p));
980
980
  const gen = seen.lstat(p);
981
- const current = view !== void 0 && gen !== void 0 && !view.changedSince(gen, p).changed;
982
- if (known && current && !("until" in known) && young2(known) && !known.isSymbolicLink) {
981
+ const current2 = view !== void 0 && gen !== void 0 && !view.changedSince(gen, p).changed;
982
+ if (known && current2 && !("until" in known) && young2(known) && !known.isSymbolicLink) {
983
983
  throw syncError("EINVAL", `'${p}' is not a symbolic link`);
984
984
  }
985
985
  return bridge.readlink(p);
@@ -2224,8 +2224,8 @@ var init_js_kernel = __esm({
2224
2224
  }
2225
2225
  async report(handlers, ignored, defaults) {
2226
2226
  const caught = caughtOf(handlers);
2227
- const same = caught === this.reported.caught && ignored === this.reported.ignored;
2228
- if (same && defaults === 0) return;
2227
+ const same2 = caught === this.reported.caught && ignored === this.reported.ignored;
2228
+ if (same2 && defaults === 0) return;
2229
2229
  this.reported = { caught, ignored };
2230
2230
  await this.call({ op: "sig-mask", caught, ignored, ...defaults ? { defaults } : {} });
2231
2231
  }
@@ -3699,6 +3699,10 @@ var init_wasi_fds = __esm({
3699
3699
  if (exclusive && this.isLink(path)) throw new WasiError("EEXIST");
3700
3700
  const s = this.statOrMissing(path);
3701
3701
  if (exclusive && s) throw new WasiError("EEXIST");
3702
+ if (s?.escape !== void 0) {
3703
+ refuseWrite({ readonly: true }, oflags, rights);
3704
+ return this.open(s.escape, oflags, rights, fdflags, mode);
3705
+ }
3702
3706
  if (oflags & OFLAGS.DIRECTORY && !s?.isDirectory) {
3703
3707
  throw new WasiError(s ? "ENOTDIR" : "ENOENT");
3704
3708
  }
@@ -6087,11 +6091,11 @@ var init_wasi_host = __esm({
6087
6091
  const asked = FSTFLAGS.ATIM | FSTFLAGS.ATIM_NOW | FSTFLAGS.MTIM | FSTFLAGS.MTIM_NOW;
6088
6092
  if (this.o.fs.owners && (flags & asked) === 0) return;
6089
6093
  const now = Date.now();
6090
- let current;
6094
+ let current2;
6091
6095
  const statOf = follow3 ? this.o.fs.stat.bind(this.o.fs) : this.o.fs.lstat.bind(this.o.fs);
6092
6096
  const kept = (field2) => {
6093
- current ??= statOf(path);
6094
- return current[field2] ?? current.mtimeMs ?? now;
6097
+ current2 ??= statOf(path);
6098
+ return current2[field2] ?? current2.mtimeMs ?? now;
6095
6099
  };
6096
6100
  const pick = (set, setNow, value2, field2) => flags & setNow ? now : flags & set ? Number(value2 / NS_PER_MS4) : kept(field2);
6097
6101
  (follow3 ? this.o.fs.utimes : this.o.fs.lutimes).call(
@@ -6721,7 +6725,7 @@ var KERNEL_VERSION, OS_RELEASE;
6721
6725
  var init_version = __esm({
6722
6726
  "src/version.ts"() {
6723
6727
  "use strict";
6724
- KERNEL_VERSION = true ? "1.141.0" : "0.0.0-dev";
6728
+ KERNEL_VERSION = true ? "1.141.2" : "0.0.0-dev";
6725
6729
  OS_RELEASE = "6.0.0-slicc";
6726
6730
  }
6727
6731
  });
@@ -7814,6 +7818,10 @@ function mayTrace(viewer, target) {
7814
7818
  const uid = of.ruid === by.euid && of.euid === by.euid && of.suid === by.euid;
7815
7819
  return uid && of.rgid === by.egid && of.egid === by.egid && of.sgid === by.egid;
7816
7820
  }
7821
+ function fileIdentity(ino, mtimeMs) {
7822
+ if (ino === void 0 || mtimeMs === void 0 || !Number.isFinite(mtimeMs)) return void 0;
7823
+ return `${ino}:${Math.trunc(mtimeMs)}`;
7824
+ }
7817
7825
  var init_proc_info = __esm({
7818
7826
  "src/kernel/proc-info.ts"() {
7819
7827
  "use strict";
@@ -10792,15 +10800,15 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
10792
10800
  readdir: (node) => listAll(node)
10793
10801
  };
10794
10802
  const track = (stream, names) => {
10795
- let current = names;
10803
+ let current2 = names;
10796
10804
  const remember2 = (list) => scans.set(stream, new Set(list.filter((n) => /^[1-9]\d*$/.test(n)).map(Number)));
10797
- remember2(current ?? []);
10805
+ remember2(current2 ?? []);
10798
10806
  Object.defineProperty(stream, "getdents", {
10799
10807
  configurable: true,
10800
10808
  enumerable: true,
10801
- get: () => current,
10809
+ get: () => current2,
10802
10810
  set: (next2) => {
10803
- current = next2;
10811
+ current2 = next2;
10804
10812
  if (next2) remember2(next2);
10805
10813
  }
10806
10814
  });
@@ -10998,10 +11006,40 @@ function directMiss(err, path) {
10998
11006
  if (err?.direct !== true) return false;
10999
11007
  return !path.split("/").some((part) => part === "." || part === "..");
11000
11008
  }
11001
- function routing(tree, toProc, shadowing) {
11009
+ function same(fs, path, id) {
11010
+ try {
11011
+ const st = fs.stat(path);
11012
+ const now = fileIdentity(st.ino, st.mtimeMs);
11013
+ return now === void 0 || now === id;
11014
+ } catch {
11015
+ return false;
11016
+ }
11017
+ }
11018
+ function current(fs, tree, q) {
11019
+ const to = tree.escapeTo(q);
11020
+ if (!to || to.id === void 0) return to?.target;
11021
+ if (!same(fs, to.target, to.id)) throw syncError("ENOENT", q);
11022
+ return to.target;
11023
+ }
11024
+ function guard(toProc, shadowing) {
11025
+ return (paths, run) => {
11026
+ const physical2 = shadowing();
11027
+ for (const [p, follow3] of paths) {
11028
+ if (inProc(p) || physical2 && toProc(p, follow3) !== void 0) throw syncError("EROFS", p);
11029
+ }
11030
+ return run();
11031
+ };
11032
+ }
11033
+ function shownLink(fs, tree, q) {
11034
+ const target = tree.readlink(q);
11035
+ const to = tree.linkTo(q);
11036
+ if (!to) return target;
11037
+ return same(fs, to.target, to.id) ? target : `${target} (deleted)`;
11038
+ }
11039
+ function routing(fs, tree, toProc, shadowing) {
11002
11040
  return (p, inner, own, follow3 = true, outside) => {
11003
11041
  const proc = (q) => {
11004
- const target = outside ? tree.escape(q) : void 0;
11042
+ const target = outside ? current(fs, tree, q) : void 0;
11005
11043
  return target === void 0 ? inner(q) : outside(target);
11006
11044
  };
11007
11045
  if (inProc(p)) return proc(p);
@@ -11022,14 +11060,8 @@ function routing(tree, toProc, shadowing) {
11022
11060
  function procfsBridge(fs, tree) {
11023
11061
  const toProc = (path, follow3) => procPath(fs, path, follow3);
11024
11062
  const shadowing = physicalProc(fs);
11025
- const via = routing(tree, toProc, shadowing);
11026
- const readOnly2 = (paths, run) => {
11027
- const physical2 = shadowing();
11028
- for (const [p, follow3] of paths) {
11029
- if (inProc(p) || physical2 && toProc(p, follow3) !== void 0) throw syncError("EROFS", p);
11030
- }
11031
- return run();
11032
- };
11063
+ const via = routing(fs, tree, toProc, shadowing);
11064
+ const readOnly2 = guard(toProc, shadowing);
11033
11065
  const snapshots = /* @__PURE__ */ new Map();
11034
11066
  let lastSnapshot = 0;
11035
11067
  const snapshot = (q) => {
@@ -11054,7 +11086,7 @@ function procfsBridge(fs, tree) {
11054
11086
  (q) => tree.stat(q),
11055
11087
  () => fs.stat(p),
11056
11088
  true,
11057
- (t) => fs.stat(t)
11089
+ (t) => ({ ...fs.stat(t), escape: t })
11058
11090
  ),
11059
11091
  lstat: (p) => via(
11060
11092
  p,
@@ -11093,7 +11125,7 @@ function procfsBridge(fs, tree) {
11093
11125
  },
11094
11126
  readlink: (p) => via(
11095
11127
  p,
11096
- (q) => tree.readlink(q),
11128
+ (q) => shownLink(fs, tree, q),
11097
11129
  () => fs.readlink(p),
11098
11130
  false
11099
11131
  ),
@@ -11133,7 +11165,7 @@ function procfsBridge(fs, tree) {
11133
11165
  return via(p, snapshot, () => fs.hold?.(p, held2, open, void 0, want, seen) ?? late(p));
11134
11166
  },
11135
11167
  kept: (handle) => snapshots.has(handle) || fs.kept?.(handle) === true,
11136
- escape: (p) => inProc(p) ? tree.escape(p) : void 0,
11168
+ escape: (p) => inProc(p) ? current(fs, tree, p) : void 0,
11137
11169
  pinned: (handle) => {
11138
11170
  const bytes = snapshots.get(handle);
11139
11171
  return bytes ? frozen(bytes) : fs.pinned?.(handle) ?? fs;
@@ -11233,12 +11265,7 @@ var init_wasi_procfs = __esm({
11233
11265
  const exe = () => this.info(Number(top))?.exe === void 0 ? [] : ["exe"];
11234
11266
  return { kind: "dir", names: () => [...PID_NAMES, ...exe(), "task"] };
11235
11267
  }
11236
- if (leaf === "exe") {
11237
- const info = this.info(Number(top));
11238
- if (info?.exe === void 0) return void 0;
11239
- const denied = !mayTrace(this.ownInfo(), info);
11240
- return { kind: "link", target: info.exe, ...denied ? { denied } : {} };
11241
- }
11268
+ if (leaf === "exe") return this.exe(Number(top));
11242
11269
  if (!PID_NAMES.includes(leaf)) return void 0;
11243
11270
  return {
11244
11271
  kind: "file",
@@ -11250,6 +11277,13 @@ var init_wasi_procfs = __esm({
11250
11277
  }
11251
11278
  };
11252
11279
  }
11280
+ exe(pid) {
11281
+ const info = this.info(pid);
11282
+ if (info?.exe === void 0) return void 0;
11283
+ const denied = !mayTrace(this.ownInfo(), info);
11284
+ const id = info.exeId === void 0 ? {} : { id: info.exeId };
11285
+ return { kind: "link", target: info.exe, ...denied ? { denied } : {}, ...id };
11286
+ }
11253
11287
  ownInfo() {
11254
11288
  const processes2 = this.listing().processes;
11255
11289
  return processes2.find((p) => p.tid === this.pid) ?? processes2.find((p) => p.pid === this.pid);
@@ -11315,10 +11349,18 @@ var init_wasi_procfs = __esm({
11315
11349
  return node.names();
11316
11350
  }
11317
11351
  escape(path) {
11352
+ return this.escapeTo(path)?.target;
11353
+ }
11354
+ escapeTo(path) {
11318
11355
  const node = this.node(this.parts(path, true));
11319
11356
  if (node?.kind !== "link" || !node.target.startsWith("/")) return void 0;
11320
11357
  if (node.denied) throw syncError("EACCES", path);
11321
- return node.target;
11358
+ return node.id === void 0 ? { target: node.target } : { target: node.target, id: node.id };
11359
+ }
11360
+ linkTo(path) {
11361
+ const node = this.node(this.parts(path, false));
11362
+ if (node?.kind !== "link" || node.id === void 0 || node.denied) return void 0;
11363
+ return { target: node.target, id: node.id };
11322
11364
  }
11323
11365
  readlink(path) {
11324
11366
  const node = this.find(path, false);
@@ -11937,9 +11979,9 @@ function ttyOps(kernel, syncKernel) {
11937
11979
  if (original) await setAttr(fd, original.termios);
11938
11980
  return;
11939
11981
  }
11940
- const current = await getAttr(fd);
11941
- if (!saved.has(terminal)) saved.set(terminal, { fd, termios: current });
11942
- await setAttr(fd, rawOf(current));
11982
+ const current2 = await getAttr(fd);
11983
+ if (!saved.has(terminal)) saved.set(terminal, { fd, termios: current2 });
11984
+ await setAttr(fd, rawOf(current2));
11943
11985
  },
11944
11986
  async size(fd) {
11945
11987
  const [rows, columns] = await kernel.json({ op: "tty-winsz", fd });
@@ -11985,9 +12027,9 @@ function ttyOps(kernel, syncKernel) {
11985
12027
  if (original) syncSet(fd, original.termios);
11986
12028
  return;
11987
12029
  }
11988
- const current = syncGet(fd);
11989
- if (!saved.has(terminal)) saved.set(terminal, { fd, termios: current });
11990
- syncSet(fd, rawOf(current));
12030
+ const current2 = syncGet(fd);
12031
+ if (!saved.has(terminal)) saved.set(terminal, { fd, termios: current2 });
12032
+ syncSet(fd, rawOf(current2));
11991
12033
  }
11992
12034
  };
11993
12035
  const modes = () => [...saved].reverse().map(([terminal, { fd, termios }]) => ({ terminal, fd, termios }));
@@ -13475,8 +13517,8 @@ var init_process_signals = __esm({
13475
13517
  const { caught, ignored, defaults = 0 } = masks;
13476
13518
  const nocldwait = masks.nocldwait === true;
13477
13519
  const was = this.reported;
13478
- const same = caught === was.caught && ignored === was.ignored && nocldwait === was.nocldwait;
13479
- if (same && defaults === 0) return;
13520
+ const same2 = caught === was.caught && ignored === was.ignored && nocldwait === was.nocldwait;
13521
+ if (same2 && defaults === 0) return;
13480
13522
  this.reported = { caught, ignored, nocldwait };
13481
13523
  const req = {
13482
13524
  op: "sig-mask",
@@ -13561,7 +13603,7 @@ function createSocketKernel(deps) {
13561
13603
  call2(req);
13562
13604
  return 0;
13563
13605
  };
13564
- const guard = (op) => {
13606
+ const guard2 = (op) => {
13565
13607
  for (; ; ) {
13566
13608
  try {
13567
13609
  return op();
@@ -13593,8 +13635,8 @@ function createSocketKernel(deps) {
13593
13635
  return stream.fd;
13594
13636
  };
13595
13637
  return {
13596
- socket: (domain, nonblock, cloexec) => guard(() => install(json2({ op: "sock-open", domain }), nonblock, cloexec)),
13597
- socketpair: (domain, nonblock, cloexec) => guard(() => {
13638
+ socket: (domain, nonblock, cloexec) => guard2(() => install(json2({ op: "sock-open", domain }), nonblock, cloexec)),
13639
+ socketpair: (domain, nonblock, cloexec) => guard2(() => {
13598
13640
  const [a, b] = json2({ op: "sock-pair", domain });
13599
13641
  let first;
13600
13642
  try {
@@ -13612,9 +13654,9 @@ function createSocketKernel(deps) {
13612
13654
  throw e;
13613
13655
  }
13614
13656
  }),
13615
- bind: (fd, given) => guard(() => done({ op: "sock-bind", fd: kfd(fd), addr: resolved(Fs, given) })),
13616
- listen: (fd, backlog) => guard(() => done({ op: "sock-listen", fd: kfd(fd), backlog })),
13617
- accept: (fd, nonblock, cloexec) => guard(() => {
13657
+ bind: (fd, given) => guard2(() => done({ op: "sock-bind", fd: kfd(fd), addr: resolved(Fs, given) })),
13658
+ listen: (fd, backlog) => guard2(() => done({ op: "sock-listen", fd: kfd(fd), backlog })),
13659
+ accept: (fd, nonblock, cloexec) => guard2(() => {
13618
13660
  const listener = socketAt(fd);
13619
13661
  const req = {
13620
13662
  op: "sock-accept",
@@ -13624,7 +13666,7 @@ function createSocketKernel(deps) {
13624
13666
  const got = json2(req);
13625
13667
  return { fd: install(got.fd, nonblock, cloexec), peer: got.peer };
13626
13668
  }),
13627
- connect: (fd, addr) => guard(() => {
13669
+ connect: (fd, addr) => guard2(() => {
13628
13670
  const stream = socketAt(fd);
13629
13671
  const nonblock = (stream.flags & O_NONBLOCK2) !== 0;
13630
13672
  return done({
@@ -13634,12 +13676,12 @@ function createSocketKernel(deps) {
13634
13676
  nonblock
13635
13677
  });
13636
13678
  }),
13637
- shutdown: (fd, how) => guard(() => done({ op: "sock-shutdown", fd: kfd(fd), how })),
13638
- name: (fd, peer) => guard(() => json2({ op: "sock-name", fd: kfd(fd), peer })),
13639
- getopt: (fd, level, name2) => guard(() => ({ value: json2({ op: "sock-getopt", fd: kfd(fd), level, name: name2 }) })),
13640
- setopt: (fd, level, name2, value2) => guard(() => done({ op: "sock-setopt", fd: kfd(fd), level, name: name2, value: value2 })),
13641
- resolve: (name2, family = 4) => guard(() => json2({ op: "sock-resolve", name: name2, family })),
13642
- send: (fd, bytes, flags) => guard(() => {
13679
+ shutdown: (fd, how) => guard2(() => done({ op: "sock-shutdown", fd: kfd(fd), how })),
13680
+ name: (fd, peer) => guard2(() => json2({ op: "sock-name", fd: kfd(fd), peer })),
13681
+ getopt: (fd, level, name2) => guard2(() => ({ value: json2({ op: "sock-getopt", fd: kfd(fd), level, name: name2 }) })),
13682
+ setopt: (fd, level, name2, value2) => guard2(() => done({ op: "sock-setopt", fd: kfd(fd), level, name: name2, value: value2 })),
13683
+ resolve: (name2, family = 4) => guard2(() => json2({ op: "sock-resolve", name: name2, family })),
13684
+ send: (fd, bytes, flags) => guard2(() => {
13643
13685
  const stream = socketAt(fd);
13644
13686
  const nonblock = flags.dontwait === true || (stream.flags & O_NONBLOCK2) !== 0;
13645
13687
  try {
@@ -13651,7 +13693,7 @@ function createSocketKernel(deps) {
13651
13693
  throw e;
13652
13694
  }
13653
13695
  }),
13654
- recv: (fd, max, flags) => guard(() => {
13696
+ recv: (fd, max, flags) => guard2(() => {
13655
13697
  const stream = socketAt(fd);
13656
13698
  const nonblock = flags.dontwait === true || (stream.flags & O_NONBLOCK2) !== 0;
13657
13699
  return sys.read(stream.sliccKernelFd, max, { nonblock, peek: flags.peek === true });