@ai-ecoverse/slicc-kernel 1.133.4 → 1.133.5

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
@@ -5564,6 +5564,9 @@ var OpfsFs = class {
5564
5564
  }
5565
5565
  }
5566
5566
  await this.meta.remove([found.path]);
5567
+ if (found.handle?.kind === "directory") {
5568
+ await this.meta.update(found.path, (entry) => entry ?? vacatedAt(found.path));
5569
+ }
5567
5570
  this.touch(Date.now(), parentOf4(found.path));
5568
5571
  }
5569
5572
  links() {
@@ -7461,7 +7464,7 @@ function satisfies(version, range2) {
7461
7464
  }
7462
7465
 
7463
7466
  // src/version.ts
7464
- var KERNEL_VERSION = true ? "1.133.4" : "0.0.0-dev";
7467
+ var KERNEL_VERSION = true ? "1.133.5" : "0.0.0-dev";
7465
7468
  var OS_RELEASE = "6.0.0-slicc";
7466
7469
  function procVersion() {
7467
7470
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -10795,6 +10798,88 @@ var FifoTable = class {
10795
10798
  }
10796
10799
  };
10797
10800
 
10801
+ // src/kernel/held-cwd.ts
10802
+ var CWD_SLOTS = 1024;
10803
+ var UNTRACKED = CWD_SLOTS - 1;
10804
+ var under4 = (path, changed) => changed === "/" || path === changed || path.startsWith(`${changed}/`);
10805
+ var CwdTable = class {
10806
+ sab = new SharedArrayBuffer(CWD_SLOTS * 4);
10807
+ view = new Int32Array(this.sab);
10808
+ held = /* @__PURE__ */ new Map();
10809
+ free = [];
10810
+ next = 0;
10811
+ checks = 0;
10812
+ inodeOf;
10813
+ constructor(inodeOf2) {
10814
+ this.inodeOf = inodeOf2;
10815
+ }
10816
+ async hold(path, from) {
10817
+ const shared = from === void 0 ? void 0 : this.held.get(from);
10818
+ if (shared && shared.path === path) return this.share(from);
10819
+ const ino = await this.inodeOf(path).catch(() => void 0);
10820
+ const slot2 = this.free.pop() ?? (this.next < UNTRACKED ? this.next++ : UNTRACKED);
10821
+ if (slot2 === UNTRACKED) return slot2;
10822
+ this.held.set(slot2, {
10823
+ path,
10824
+ ino,
10825
+ refs: 1,
10826
+ dead: false,
10827
+ verified: Atomics.load(this.view, slot2)
10828
+ });
10829
+ return slot2;
10830
+ }
10831
+ share(slot2) {
10832
+ const held = slot2 === void 0 ? void 0 : this.held.get(slot2);
10833
+ if (!held) return UNTRACKED;
10834
+ held.refs++;
10835
+ return slot2;
10836
+ }
10837
+ release(slot2) {
10838
+ const held = slot2 === void 0 ? void 0 : this.held.get(slot2);
10839
+ if (!held || --held.refs > 0) return;
10840
+ this.held.delete(slot2);
10841
+ Atomics.add(this.view, slot2, 1);
10842
+ this.free.push(slot2);
10843
+ }
10844
+ stateOf(slot2) {
10845
+ const held = this.held.get(slot2);
10846
+ return { seen: held?.verified ?? Atomics.load(this.view, slot2), dead: held?.dead === true };
10847
+ }
10848
+ touched(paths, trees = []) {
10849
+ if (this.held.size === 0) return;
10850
+ for (const [slot2, held] of this.held) {
10851
+ if (held.dead) continue;
10852
+ if (paths.some((p) => under4(held.path, p)) || trees.some((t) => under4(held.path, t))) {
10853
+ Atomics.add(this.view, slot2, 1);
10854
+ }
10855
+ }
10856
+ }
10857
+ async check(slot2) {
10858
+ this.checks++;
10859
+ const gen = Atomics.load(this.view, slot2);
10860
+ const held = this.held.get(slot2);
10861
+ if (!held) return { gen, alive: true };
10862
+ if (!held.dead) {
10863
+ const ino = await this.inodeOf(held.path).catch(() => null);
10864
+ held.dead = ino === null || held.ino !== void 0 && ino !== held.ino;
10865
+ held.verified = gen;
10866
+ }
10867
+ return { gen, alive: !held.dead };
10868
+ }
10869
+ };
10870
+ function heldInit(o) {
10871
+ if (!o.cwds || o.cwdSlot === void 0) return {};
10872
+ const state = o.cwdState ?? { seen: 0, dead: false };
10873
+ return { held: { sab: o.cwds, slot: o.cwdSlot, ...state } };
10874
+ }
10875
+ function heldHooks(o) {
10876
+ if (!o.cwdCheck || !o.cwdChdir) return {};
10877
+ return { cwdCheck: o.cwdCheck, cwdChdir: o.cwdChdir };
10878
+ }
10879
+ function inheritedCwd(chdir, parent) {
10880
+ return chdir ? void 0 : parent;
10881
+ }
10882
+
10798
10883
  // src/fs/copy.ts
10799
10884
  async function present2(fs, path) {
10800
10885
  return fs.lstat(path).then(
@@ -20994,6 +21079,8 @@ var SYSCALL_OPS = /* @__PURE__ */ new Set([
20994
21079
  "fd-list",
20995
21080
  "proc-alarm",
20996
21081
  "proc-umask",
21082
+ "cwd-check",
21083
+ "cwd-chdir",
20997
21084
  "proc-cred",
20998
21085
  "proc-setcred",
20999
21086
  "dl-log",
@@ -22319,6 +22406,14 @@ var WasmProcess = class {
22319
22406
  return { ok: true, kind: "void" };
22320
22407
  case "proc-umask":
22321
22408
  return { ok: true, kind: "json", json: this.setUmask(req.mask) };
22409
+ case "cwd-check":
22410
+ return {
22411
+ ok: true,
22412
+ kind: "json",
22413
+ json: await this.options.cwdCheck?.() ?? { gen: 0, alive: true }
22414
+ };
22415
+ case "cwd-chdir":
22416
+ return { ok: true, kind: "json", json: await this.options.cwdChdir?.(req.path) ?? {} };
22322
22417
  case "proc-cred":
22323
22418
  return { ok: true, kind: "json", json: copyCred(this.cred) };
22324
22419
  case "proc-setcred":
@@ -22868,6 +22963,7 @@ function processInit(opts, sab, umask, cred, lane) {
22868
22963
  umask,
22869
22964
  cred,
22870
22965
  ...opts.changes ? { changes: opts.changes } : {},
22966
+ ...heldInit(opts),
22871
22967
  ...opts.owners ? { owners: true } : {},
22872
22968
  ...opts.links !== void 0 ? { links: true } : {},
22873
22969
  ...opts.ppid !== void 0 ? { ppid: opts.ppid } : {}
@@ -22941,6 +23037,7 @@ function processOptions(opts, header4, hooks, created4) {
22941
23037
  ...opts.identity ? { identity: opts.identity } : {},
22942
23038
  ...opts.onSyscall ? { onSyscall: opts.onSyscall } : {},
22943
23039
  ...opts.settling ? { settling: opts.settling } : {},
23040
+ ...heldHooks(opts),
22944
23041
  spawner: opts.spawner,
22945
23042
  forker: opts.forker,
22946
23043
  ...opts.fork?.dl ? { dl: opts.fork.dl } : {},
@@ -22991,6 +23088,7 @@ function threadInit(opts, program, sab, cred, thread, main) {
22991
23088
  owners: opts.owners === true,
22992
23089
  ...opts.links !== void 0 ? { links: true } : {},
22993
23090
  ...opts.changes ? { changes: opts.changes } : {},
23091
+ ...heldInit(opts),
22994
23092
  ...opts.ppid !== void 0 ? { ppid: opts.ppid } : {},
22995
23093
  thread,
22996
23094
  signals: main
@@ -26690,6 +26788,11 @@ var Launcher = class {
26690
26788
  hostname;
26691
26789
  watchers = new FsWatchers();
26692
26790
  changes = new FileChanges();
26791
+ cwds = new CwdTable(async (path) => {
26792
+ const { dev, ino } = await this.base.stat(path);
26793
+ return `${dev ?? 0}:${ino}`;
26794
+ });
26795
+ cwdSlots = /* @__PURE__ */ new Map();
26693
26796
  pnpmHome;
26694
26797
  pnpmChain;
26695
26798
  pnpmMade;
@@ -26746,7 +26849,10 @@ var Launcher = class {
26746
26849
  this.sealed.tickets.normalise = (path) => physicalPathAsync(this.base, path);
26747
26850
  this.sealed.userOf = async (uid) => (await this.users.lookup(uid))?.name;
26748
26851
  if (this.owners) options.fs.trackOwners?.();
26749
- this.watchers.tap((paths) => this.changes.publish(...paths));
26852
+ this.watchers.tap((paths) => {
26853
+ this.changes.publish(...paths);
26854
+ this.cwds.touched(paths);
26855
+ });
26750
26856
  this.watchers.onReshape(() => {
26751
26857
  for (const nodes of this.openFiles) nodes.reshaped();
26752
26858
  });
@@ -26816,6 +26922,7 @@ var Launcher = class {
26816
26922
  options.fs.onPeer?.(() => this.flushOpen());
26817
26923
  options.fs.remoteChanges?.((change) => {
26818
26924
  this.changes.flush();
26925
+ this.cwds.touched(change.paths, change.trees);
26819
26926
  this.rewritten(change.paths, change.trees);
26820
26927
  });
26821
26928
  const holders = [this.held, this.openFiles];
@@ -27598,11 +27705,12 @@ var Launcher = class {
27598
27705
  }
27599
27706
  const done4 = this.heldUrl(program);
27600
27707
  try {
27708
+ const cwdSlot = await this.cwds.hold(cwd, req.cwdFrom);
27601
27709
  const handle = await this.admitted(
27602
27710
  program.abi !== "js",
27603
27711
  req.fds,
27604
- (fds, quietOom) => this.start({ ...req, fds, quietOom, cwd, program, argv0: target.argv0, args, env })
27605
- );
27712
+ (fds, quietOom) => this.start({ ...req, fds, quietOom, cwd, program, argv0: target.argv0, args, env, cwdSlot })
27713
+ ).finally(() => this.cwds.release(cwdSlot));
27606
27714
  void handle.exited.finally(done4);
27607
27715
  return handle;
27608
27716
  } catch (err) {
@@ -27689,6 +27797,8 @@ var Launcher = class {
27689
27797
  throw new SpawnError("ESRCH");
27690
27798
  }
27691
27799
  const pid = req.pid ?? this.nextPid++;
27800
+ const cwdSlot = this.cwds.share(req.cwdSlot);
27801
+ this.cwdSlots.set(pid, cwdSlot);
27692
27802
  const scrubs = this.treeScrubs(req);
27693
27803
  const stack = this.stackFor(req.tag);
27694
27804
  const terminal = req.fds.stdioTerminal();
@@ -27723,6 +27833,7 @@ var Launcher = class {
27723
27833
  ...this.dac ? { dac: this.dac } : {},
27724
27834
  program: req.program,
27725
27835
  changes: this.changes.sab,
27836
+ ...this.heldFor(pid, cwdSlot),
27726
27837
  argv0: req.argv0,
27727
27838
  args: req.args,
27728
27839
  env: req.env,
@@ -27797,6 +27908,8 @@ var Launcher = class {
27797
27908
  (state) => state === "stopped" ? this.stopped.add(pid) : this.stopped.delete(pid)
27798
27909
  );
27799
27910
  void handle.exited.then(() => {
27911
+ this.cwds.release(this.cwdSlots.get(pid));
27912
+ this.cwdSlots.delete(pid);
27800
27913
  this.freshModules.forget(pid);
27801
27914
  const spent = handle.times?.();
27802
27915
  if (spent) this.spent.set(pid, spent);
@@ -28028,6 +28141,7 @@ var Launcher = class {
28028
28141
  const handle = await this.launch(planned, {
28029
28142
  ...deciding ? { decided: deciding.promise } : {},
28030
28143
  cwd: req.cwd,
28144
+ cwdFrom: inheritedCwd(req.chdir, this.cwdSlots.get(ppid)),
28031
28145
  ...redeemed,
28032
28146
  fds,
28033
28147
  report,
@@ -28089,6 +28203,24 @@ var Launcher = class {
28089
28203
  for (const resolve2 of waiting) resolve2(true);
28090
28204
  }, 0);
28091
28205
  }
28206
+ heldFor(pid, slot2) {
28207
+ return {
28208
+ cwds: this.cwds.sab,
28209
+ cwdSlot: slot2,
28210
+ cwdState: this.cwds.stateOf(slot2),
28211
+ cwdCheck: async () => {
28212
+ const current = this.cwdSlots.get(pid);
28213
+ return { ...await this.cwds.check(current), slot: current };
28214
+ },
28215
+ cwdChdir: (path) => this.chdirHeld(pid, path)
28216
+ };
28217
+ }
28218
+ async chdirHeld(pid, path) {
28219
+ this.cwds.release(this.cwdSlots.get(pid));
28220
+ const slot2 = await this.cwds.hold(path);
28221
+ this.cwdSlots.set(pid, slot2);
28222
+ return { slot: slot2, ...this.cwds.stateOf(slot2) };
28223
+ }
28092
28224
  forker(ppid, parent) {
28093
28225
  const { exec: _exec, pgid: _pgid, group: _group, pid: _pid, scrub: _scrub, ...image } = parent;
28094
28226
  return async (state, given) => {
@@ -28096,6 +28228,7 @@ var Launcher = class {
28096
28228
  ...image,
28097
28229
  quietOom,
28098
28230
  cwd: state.cwd ?? parent.cwd,
28231
+ cwdSlot: this.cwdSlots.get(ppid),
28099
28232
  fds,
28100
28233
  ppid,
28101
28234
  fork: state,