@ai-ecoverse/slicc-kernel 1.133.4 → 1.134.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.
@@ -3335,6 +3335,7 @@ var init_wasi_fds = __esm({
3335
3335
  e.path = path;
3336
3336
  this.kernel.call({ op: "fd-meta", fd, meta: metaOf(e) });
3337
3337
  }
3338
+ this.held?.moved(this.kernel.call({ op: "cwd-chdir", path }), path);
3338
3339
  this.bump();
3339
3340
  }
3340
3341
  promote(fd, moved = false) {
@@ -3621,9 +3622,21 @@ var init_wasi_fds = __esm({
3621
3622
  this.buffers.set(next2, buffer);
3622
3623
  }
3623
3624
  }
3625
+ held;
3626
+ cwdEntry(dir) {
3627
+ return dir.preopen === "." || dir.preopen === "./";
3628
+ }
3629
+ goneCwd(dir) {
3630
+ return this.held !== void 0 && this.cwdEntry(dir) && !this.held.alive(dir.path);
3631
+ }
3624
3632
  resolve(dirfd, path) {
3625
3633
  if (path === "") throw new WasiError("ENOENT");
3626
- const joined2 = path.startsWith("/") ? path : `${this.dir(dirfd).path}/${path}`;
3634
+ if (path.startsWith("/")) return this.joined(path);
3635
+ const dir = this.dir(dirfd);
3636
+ if (path.split("/")[0] !== ".." && this.goneCwd(dir)) throw new WasiError("ENOENT");
3637
+ return this.joined(`${dir.path}/${path}`);
3638
+ }
3639
+ joined(joined2) {
3627
3640
  return joined2.split("/").includes("..") ? physical(this.fs, joined2) : normalize(joined2);
3628
3641
  }
3629
3642
  openKernelDevice(path, oflags, fdflags, rights) {
@@ -4966,6 +4979,7 @@ var init_wasi_host = __esm({
4966
4979
  this.o = { ...o, kernel: { sys, call: call2 } };
4967
4980
  this.startCwd = o.cwd;
4968
4981
  this.fds = new WasiFds(this.o.kernel, o.fs);
4982
+ if (o.held) this.fds.held = o.held;
4969
4983
  this.creds = new CredCache(
4970
4984
  () => this.o.kernel.call({ op: "proc-cred" }),
4971
4985
  o.credGen ?? o.shared
@@ -6047,7 +6061,9 @@ var init_wasi_host = __esm({
6047
6061
  }
6048
6062
  readdir(fd, buf, len, cookie, usedPtr) {
6049
6063
  const dir = this.fds.dir(fd);
6050
- if (cookie === 0 || !dir.listing) dir.listing = this.list(dir.path);
6064
+ if (cookie === 0 || !dir.listing) {
6065
+ dir.listing = this.fds.goneCwd(dir) ? { names: [], stats: /* @__PURE__ */ new Map() } : this.list(dir.path);
6066
+ }
6051
6067
  const { names, stats } = dir.listing;
6052
6068
  let at = 0;
6053
6069
  for (let i = cookie; i < names.length && at < len; i++) {
@@ -6584,7 +6600,7 @@ var KERNEL_VERSION, OS_RELEASE;
6584
6600
  var init_version = __esm({
6585
6601
  "src/version.ts"() {
6586
6602
  "use strict";
6587
- KERNEL_VERSION = true ? "1.133.4" : "0.0.0-dev";
6603
+ KERNEL_VERSION = true ? "1.134.0" : "0.0.0-dev";
6588
6604
  OS_RELEASE = "6.0.0-slicc";
6589
6605
  }
6590
6606
  });
@@ -15540,6 +15556,59 @@ var init_js_runtime = __esm({
15540
15556
  }
15541
15557
  });
15542
15558
 
15559
+ // src/kernel/held-cwd.ts
15560
+ var CWD_SLOTS, UNTRACKED, HeldCwd;
15561
+ var init_held_cwd = __esm({
15562
+ "src/kernel/held-cwd.ts"() {
15563
+ "use strict";
15564
+ CWD_SLOTS = 1024;
15565
+ UNTRACKED = CWD_SLOTS - 1;
15566
+ HeldCwd = class {
15567
+ view;
15568
+ seen;
15569
+ dead = false;
15570
+ slot;
15571
+ at;
15572
+ ask;
15573
+ constructor(sab, slot2, ask, state) {
15574
+ this.view = new Int32Array(sab);
15575
+ this.slot = slot2;
15576
+ this.ask = ask;
15577
+ this.seen = state.seen;
15578
+ this.dead = state.dead;
15579
+ this.at = state.path;
15580
+ }
15581
+ moved(reply, path) {
15582
+ if (reply.slot === void 0) return false;
15583
+ this.slot = reply.slot;
15584
+ this.seen = reply.seen ?? Atomics.load(this.view, reply.slot);
15585
+ this.dead = reply.dead === true;
15586
+ this.at = path;
15587
+ return true;
15588
+ }
15589
+ follow() {
15590
+ const answer2 = this.ask();
15591
+ if (answer2.slot !== void 0) this.slot = answer2.slot;
15592
+ this.seen = answer2.gen;
15593
+ this.dead = !answer2.alive;
15594
+ return answer2.alive;
15595
+ }
15596
+ alive(path) {
15597
+ if (path !== void 0 && this.at !== void 0 && path !== this.at) {
15598
+ this.at = path;
15599
+ return this.follow();
15600
+ }
15601
+ if (this.dead) return false;
15602
+ if (Atomics.load(this.view, this.slot) === this.seen) return true;
15603
+ return this.follow();
15604
+ }
15605
+ get current() {
15606
+ return this.slot;
15607
+ }
15608
+ };
15609
+ }
15610
+ });
15611
+
15543
15612
  // src/process/wasi/dylink.ts
15544
15613
  function dylinkInfo(module) {
15545
15614
  const [section2] = WebAssembly.Module.customSections(module, "dylink.0");
@@ -17819,6 +17888,12 @@ function ownersOf(init) {
17819
17888
  ...init.changes ? { changes: init.changes } : {}
17820
17889
  };
17821
17890
  }
17891
+ function heldOf2(init, call2) {
17892
+ const { held: held2 } = init;
17893
+ if (!held2) return {};
17894
+ const ask = () => call2({ op: "cwd-check" });
17895
+ return { held: new HeldCwd(held2.sab, held2.slot, ask, { ...held2, path: init.cwd }) };
17896
+ }
17822
17897
  async function runWasiProcess(init, port3) {
17823
17898
  captureBacktraces(init.env);
17824
17899
  const signals = new WasiSignals(
@@ -17876,6 +17951,7 @@ async function runWasiProcess(init, port3) {
17876
17951
  call2
17877
17952
  ),
17878
17953
  ...descriptors(init, fork, threads),
17954
+ ...heldOf2(init, call2),
17879
17955
  ...threads ? { credGen: threads.ids } : {}
17880
17956
  });
17881
17957
  host.sigmask = sigmaskOf(module, init.sab, gate, threads);
@@ -17984,7 +18060,8 @@ async function runWasiThread(init, port3) {
17984
18060
  ),
17985
18061
  call2
17986
18062
  ),
17987
- shared: threads.ids
18063
+ shared: threads.ids,
18064
+ ...heldOf2(init, call2)
17988
18065
  });
17989
18066
  host.tid = thread.tid;
17990
18067
  host.sigmask = sigmaskOf(init.program.module, init.sab, gate, threads, init.signals);
@@ -18035,6 +18112,7 @@ var init_wasi_runtime = __esm({
18035
18112
  "src/process/wasi/wasi-runtime.ts"() {
18036
18113
  "use strict";
18037
18114
  init_physical_path();
18115
+ init_held_cwd();
18038
18116
  init_protocol();
18039
18117
  init_signals();
18040
18118
  init_sync_sab_bridge();