@ai-ecoverse/slicc-kernel 1.134.3 → 1.135.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.
@@ -6591,6 +6591,84 @@ var init_wasi_imports = __esm({
6591
6591
  }
6592
6592
  });
6593
6593
 
6594
+ // src/kernel/held-cwd.ts
6595
+ var CWD_SLOTS, UNTRACKED, HeldCwd;
6596
+ var init_held_cwd = __esm({
6597
+ "src/kernel/held-cwd.ts"() {
6598
+ "use strict";
6599
+ CWD_SLOTS = 1024;
6600
+ UNTRACKED = CWD_SLOTS - 1;
6601
+ HeldCwd = class {
6602
+ view;
6603
+ seen;
6604
+ dead = false;
6605
+ slot;
6606
+ at;
6607
+ ask;
6608
+ constructor(sab, slot2, ask, state) {
6609
+ this.view = new Int32Array(sab);
6610
+ this.slot = slot2;
6611
+ this.ask = ask;
6612
+ this.seen = state.seen;
6613
+ this.dead = state.dead;
6614
+ this.at = state.path;
6615
+ }
6616
+ moved(reply, path) {
6617
+ if (reply.slot === void 0) return false;
6618
+ this.slot = reply.slot;
6619
+ this.seen = reply.seen ?? Atomics.load(this.view, reply.slot);
6620
+ this.dead = reply.dead === true;
6621
+ this.at = path;
6622
+ return true;
6623
+ }
6624
+ follow() {
6625
+ const answer2 = this.ask();
6626
+ if (answer2.slot !== void 0) this.slot = answer2.slot;
6627
+ this.seen = answer2.gen;
6628
+ this.dead = !answer2.alive;
6629
+ return answer2.alive;
6630
+ }
6631
+ alive(path) {
6632
+ if (path !== void 0 && this.at !== void 0 && path !== this.at) {
6633
+ this.at = path;
6634
+ return this.follow();
6635
+ }
6636
+ if (this.dead) return false;
6637
+ if (Atomics.load(this.view, this.slot) === this.seen) return true;
6638
+ return this.follow();
6639
+ }
6640
+ get current() {
6641
+ return this.slot;
6642
+ }
6643
+ };
6644
+ }
6645
+ });
6646
+
6647
+ // src/realm/emscripten-held-cwd.ts
6648
+ function holdingCwd(Fs, held2, chdirred) {
6649
+ const { chdir, cwd } = Fs;
6650
+ if (!chdir || !cwd) return;
6651
+ Fs.sliccHeldCwd = () => cwd.call(Fs);
6652
+ Fs.sliccCwdGone = () => !held2.alive();
6653
+ Fs.cwd = () => {
6654
+ const path = cwd.call(Fs);
6655
+ return held2.alive() ? path : `${path}${DELETED}`;
6656
+ };
6657
+ Fs.chdir = (path) => {
6658
+ chdir.call(Fs, path);
6659
+ held2.moved(chdirred(cwd.call(Fs)));
6660
+ };
6661
+ }
6662
+ var DELETED, relativeHere, cwdFor;
6663
+ var init_emscripten_held_cwd = __esm({
6664
+ "src/realm/emscripten-held-cwd.ts"() {
6665
+ "use strict";
6666
+ DELETED = " (deleted)";
6667
+ relativeHere = (path) => !path.startsWith("/") && path.split("/")[0] !== "..";
6668
+ cwdFor = (cwd, held2, path) => held2 && relativeHere(path) && !held2.alive() ? `${cwd}${DELETED}` : cwd;
6669
+ }
6670
+ });
6671
+
6594
6672
  // src/version.ts
6595
6673
  function procVersion() {
6596
6674
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -6600,7 +6678,7 @@ var KERNEL_VERSION, OS_RELEASE;
6600
6678
  var init_version = __esm({
6601
6679
  "src/version.ts"() {
6602
6680
  "use strict";
6603
- KERNEL_VERSION = true ? "1.134.3" : "0.0.0-dev";
6681
+ KERNEL_VERSION = true ? "1.135.0" : "0.0.0-dev";
6604
6682
  OS_RELEASE = "6.0.0-slicc";
6605
6683
  }
6606
6684
  });
@@ -7791,7 +7869,7 @@ function createSyncSabTransport(sab, port3, deps = {}) {
7791
7869
  call(req, timeoutMs2, label, transfer = []) {
7792
7870
  if (deps.memory) publishMemory(sab, deps.memory());
7793
7871
  const id = ++seq;
7794
- calls += Number(!PATH_OPS.has(req.op));
7872
+ calls += Number(!UNCOUNTED_OPS.has(req.op));
7795
7873
  let out = null;
7796
7874
  let status2 = 0;
7797
7875
  let offset = 0;
@@ -8013,7 +8091,7 @@ function createSyncFsSabBridge(transport, opts = {}) {
8013
8091
  statfs: (path = "/") => parseSyncFsUsage(json2({ op: "statfs", path }, path))
8014
8092
  };
8015
8093
  }
8016
- var PATH_OPS, calls, looks, SPIN_MS, SPIN_STRIDE, SPIN_STRIDES, SPIN_CORES, spinning, SPIN_CAP_MS;
8094
+ var UNCOUNTED_OPS, calls, looks, SPIN_MS, SPIN_STRIDE, SPIN_STRIDES, SPIN_CORES, spinning, SPIN_CAP_MS;
8017
8095
  var init_sync_sab_bridge = __esm({
8018
8096
  "src/realm/sync-sab-bridge.ts"() {
8019
8097
  "use strict";
@@ -8021,7 +8099,7 @@ var init_sync_sab_bridge = __esm({
8021
8099
  init_cpu_clock();
8022
8100
  init_sync_fs_wire();
8023
8101
  init_sync_sab_wire();
8024
- PATH_OPS = new Set(SYNC_FS_OPS);
8102
+ UNCOUNTED_OPS = /* @__PURE__ */ new Set([...SYNC_FS_OPS, "cwd-check", "cwd-chdir"]);
8025
8103
  calls = 0;
8026
8104
  looks = 0;
8027
8105
  SPIN_MS = 0.06;
@@ -10068,6 +10146,15 @@ function kernelChecks(Fs, memory, call2) {
10068
10146
  bridge.access(liveNodePath(node), call2.amode, kind, (call2.flags & AT_SYMLINK_NOFOLLOW2) !== 0);
10069
10147
  return 0;
10070
10148
  }
10149
+ function goneCwdGetcwd(imports, fs, glue) {
10150
+ wrapImport(
10151
+ imports,
10152
+ "getcwd",
10153
+ glue,
10154
+ (own) => (...args) => fs()?.sliccCwdGone?.() === true ? -44 : own(...args),
10155
+ true
10156
+ );
10157
+ }
10071
10158
  function kernelAccess(imports, fs, memory, glue) {
10072
10159
  wrapImport(imports, "faccessat", glue, (own) => (dirfd, path, amode, flags) => {
10073
10160
  const Fs = fs();
@@ -10255,7 +10342,8 @@ var init_process_fds = __esm({
10255
10342
  fdWrite: "fd_write",
10256
10343
  fdRead: "fd_read",
10257
10344
  sleepMs: "slicc_sleep_ms",
10258
- flock: "__syscall_flock"
10345
+ flock: "__syscall_flock",
10346
+ getcwd: "__syscall_getcwd"
10259
10347
  };
10260
10348
  UTIME_NOW = 1073741823;
10261
10349
  UTIME_OMIT = 1073741822;
@@ -10707,6 +10795,8 @@ var init_procfs = __esm({
10707
10795
  slicc_opfs_calls: (listing2) => `${listing2.opfsCalls ?? 0}
10708
10796
  `,
10709
10797
  slicc_opfs_ops: (listing2) => `${listing2.opfsOps ?? 0}
10798
+ `,
10799
+ slicc_cwd_checks: (listing2) => `${listing2.cwdChecks ?? 0}
10710
10800
  `
10711
10801
  }
10712
10802
  };
@@ -10793,11 +10883,11 @@ function frozen(bytes) {
10793
10883
  truncate: refuse2
10794
10884
  };
10795
10885
  }
10796
- function physicalProc(fs) {
10886
+ function physicalProc(fs, now = () => performance.now()) {
10797
10887
  const view = fs.changes;
10798
10888
  let seen;
10799
10889
  return () => {
10800
- if (seen && view && !view.foreign()) {
10890
+ if (seen && view && (!view.foreign() || now() - seen.at < SHARED_TTL_MS)) {
10801
10891
  const proc = view.changedSince(seen.gen, "/proc");
10802
10892
  if (!proc.changed && !view.changedSince(seen.gen, "/").changed) {
10803
10893
  seen.gen = proc.now;
@@ -10805,6 +10895,7 @@ function physicalProc(fs) {
10805
10895
  }
10806
10896
  }
10807
10897
  const gen = view?.now();
10898
+ const at = now();
10808
10899
  let physical2;
10809
10900
  try {
10810
10901
  fs.stat("/proc");
@@ -10817,7 +10908,7 @@ function physicalProc(fs) {
10817
10908
  }
10818
10909
  physical2 = false;
10819
10910
  }
10820
- seen = gen === void 0 ? void 0 : { gen, physical: physical2 };
10911
+ seen = gen === void 0 ? void 0 : { gen, physical: physical2, at };
10821
10912
  return physical2;
10822
10913
  };
10823
10914
  }
@@ -12907,7 +12998,7 @@ function forkRestarted(deps, state, snapshotAt) {
12907
12998
  const live = deps.memory?.();
12908
12999
  if (live) memory = new Uint8Array(live.buffer).slice();
12909
13000
  }
12910
- const forked = { ...state, memory, streams: streams2, cwd: deps.Fs.cwd() };
13001
+ const forked = { ...state, memory, streams: streams2, cwd: heldCwdOf(deps.Fs) };
12911
13002
  return deps.transport.call(
12912
13003
  { op: "proc-fork", state: forked, restart: true },
12913
13004
  Infinity,
@@ -13047,7 +13138,7 @@ function createProcessKernel(deps) {
13047
13138
  file,
13048
13139
  argv,
13049
13140
  env: env ?? deps.env,
13050
- cwd: cwd ?? Fs.cwd(),
13141
+ cwd: cwd ?? heldCwdOf(Fs),
13051
13142
  ...cwd !== null ? { chdir: true } : {},
13052
13143
  stdio,
13053
13144
  ...inherit.length > 0 ? { inherit } : {},
@@ -13143,7 +13234,7 @@ function createProcessKernel(deps) {
13143
13234
  }
13144
13235
  };
13145
13236
  }
13146
- var S_IFMT3, UNSEEDED, S_IFDIR2, POLLIN2, POLLOUT2, POLLERR2, POLLHUP2, POLLNVAL, SELECT_SLICE_MS, WUNTRACED, WCONTINUED;
13237
+ var S_IFMT3, UNSEEDED, S_IFDIR2, POLLIN2, POLLOUT2, POLLERR2, POLLHUP2, POLLNVAL, SELECT_SLICE_MS, WUNTRACED, WCONTINUED, heldCwdOf;
13147
13238
  var init_process_children = __esm({
13148
13239
  "src/process/process-children.ts"() {
13149
13240
  "use strict";
@@ -13162,6 +13253,7 @@ var init_process_children = __esm({
13162
13253
  SELECT_SLICE_MS = 20;
13163
13254
  WUNTRACED = 2;
13164
13255
  WCONTINUED = 8;
13256
+ heldCwdOf = (Fs) => (Fs.sliccHeldCwd ?? Fs.cwd).call(Fs);
13165
13257
  }
13166
13258
  });
13167
13259
 
@@ -13782,6 +13874,7 @@ function kernelWrappers(imports, module, deps) {
13782
13874
  const fsOf = () => ownValue(module, "FS");
13783
13875
  noFollowUtimes(imports, fsOf, kernelGlue?.utimensat ?? utimensatOf(module), memory);
13784
13876
  kernelAccess(imports, fsOf, memory, kernelGlue);
13877
+ goneCwdGetcwd(imports, fsOf, kernelGlue);
13785
13878
  kernelLink(imports, fsOf, memory, kernelGlue);
13786
13879
  devCreations(imports, fsOf, memory, kernelGlue);
13787
13880
  kernelUname(imports, hostnameOf(init.env), memory, kernelGlue);
@@ -13799,6 +13892,19 @@ function kernelWrappers(imports, module, deps) {
13799
13892
  reportGrowth(imports, grown, kernelGlue);
13800
13893
  holdWhileStopped(imports, new Int32Array(init.sab, 0, SAB_HEADER_I32), kernelGlue, deps.poll);
13801
13894
  }
13895
+ function heldIn(fs, init, transport) {
13896
+ if (!init.held) return;
13897
+ const ask = (req) => {
13898
+ const r = transport.call(req, Number.POSITIVE_INFINITY, req.op);
13899
+ return r.ok && r.kind === "json" ? r.json : {};
13900
+ };
13901
+ const check = () => ask({ op: "cwd-check" });
13902
+ holdingCwd(
13903
+ fs,
13904
+ new HeldCwd(init.held.sab, init.held.slot, check, init.held),
13905
+ (path) => ask({ op: "cwd-chdir", path })
13906
+ );
13907
+ }
13802
13908
  function bridgeFlags(init) {
13803
13909
  return {
13804
13910
  ...init.owners ? { owners: true } : {},
@@ -13929,15 +14035,15 @@ async function runWasmProcess(init, port3, deps = {}) {
13929
14035
  warn: deps.warn ?? say(2),
13930
14036
  cred: init.owners ? init.cred : void 0
13931
14037
  });
14038
+ heldIn(running.FS, init, transport);
13932
14039
  early = () => signals.quiet(() => vfs.flushDirty());
13933
14040
  closeDropsLocks(running.FS, sys);
13934
14041
  const sigpipe = () => running.sliccSigpipe?.() === 1 || sigpipeSpared(gated);
13935
14042
  const restartable = () => signals.restartable();
13936
- const owners = init.owners ? { owners: true } : {};
13937
14043
  const streams2 = new KernelStreams(running.FS, sys, {
13938
14044
  sigpipe,
13939
14045
  restartable,
13940
- ...owners,
14046
+ ...init.owners ? { owners: true } : {},
13941
14047
  program: init.argv0
13942
14048
  });
13943
14049
  trackCloseOnExec(running.FS);
@@ -14076,9 +14182,11 @@ var FS_OPS, O_RDONLY2, O_WRONLY6, O_RDWR6, O_ACCMODE5, O_DIRECTORY2, accessMode,
14076
14182
  var init_process_runtime = __esm({
14077
14183
  "src/process/process-runtime.ts"() {
14078
14184
  "use strict";
14185
+ init_held_cwd();
14079
14186
  init_loopback_names();
14080
14187
  init_protocol();
14081
14188
  init_signals();
14189
+ init_emscripten_held_cwd();
14082
14190
  init_emscripten_vfs_hook();
14083
14191
  init_live_vfs_fs();
14084
14192
  init_sync_fs_wire();
@@ -14962,13 +15070,19 @@ function tracked2(pending, writeAll, writeSome, failed5) {
14962
15070
  })();
14963
15071
  };
14964
15072
  }
15073
+ function heldOn(init, lane, syncKernel) {
15074
+ if (!init || lane === noLane) return void 0;
15075
+ const ask = () => syncKernel.json({ op: "cwd-check" });
15076
+ return new HeldCwd(init.sab, init.slot, ask, init);
15077
+ }
14965
15078
  function createContext(o) {
14966
15079
  const { kernel } = o;
14967
15080
  const infos = /* @__PURE__ */ new Map();
14968
15081
  const handles = /* @__PURE__ */ new Map();
14969
15082
  const pending = /* @__PURE__ */ new Set();
14970
15083
  const random = o.random ?? cryptoRandom;
14971
- const resolve = (path) => resolvePath(o.cwd, path);
15084
+ let held2;
15085
+ const resolve = (path) => resolvePath(cwdFor(o.cwd, held2, path), path);
14972
15086
  const tryDev = (abs) => resolveDevAsync(kernel, abs);
14973
15087
  let exiting;
14974
15088
  const exit = (code2 = 0) => {
@@ -15020,6 +15134,7 @@ function createContext(o) {
15020
15134
  const lane = o.lane ?? laneOf(void 0);
15021
15135
  if (o.lane && o.lane !== noLane) kernel.syncLane = o.lane;
15022
15136
  const syncKernel = new JsSyncKernel(lane, kernel, unwind);
15137
+ held2 = heldOn(o.held, lane, syncKernel);
15023
15138
  const terminal = ttyOps(kernel, syncKernel);
15024
15139
  const shared = { pid: o.pid, resolve, random, infos, handles, closing };
15025
15140
  const wasi = wasiFor({ lane, pid: o.pid, cwd: o.cwd, resolve, fs: o.fs, owned: o.owned });
@@ -15302,7 +15417,9 @@ var init_js_context = __esm({
15302
15417
  "src/process/js/js-context.ts"() {
15303
15418
  "use strict";
15304
15419
  init_physical_path();
15420
+ init_held_cwd();
15305
15421
  init_signals();
15422
+ init_emscripten_held_cwd();
15306
15423
  init_sync_fs_wire();
15307
15424
  init_version();
15308
15425
  init_js_children();
@@ -15504,6 +15621,7 @@ async function runJs(init, port3, deps, thread) {
15504
15621
  strays,
15505
15622
  thread: threadContext(port3, thread),
15506
15623
  ...thread?.owned ? { owned: thread.owned } : {},
15624
+ held: init.held,
15507
15625
  failed: () => failedWith
15508
15626
  });
15509
15627
  const say = (text) => ctx.write(2, `${init.argv0}: ${text}
@@ -15561,59 +15679,6 @@ var init_js_runtime = __esm({
15561
15679
  }
15562
15680
  });
15563
15681
 
15564
- // src/kernel/held-cwd.ts
15565
- var CWD_SLOTS, UNTRACKED, HeldCwd;
15566
- var init_held_cwd = __esm({
15567
- "src/kernel/held-cwd.ts"() {
15568
- "use strict";
15569
- CWD_SLOTS = 1024;
15570
- UNTRACKED = CWD_SLOTS - 1;
15571
- HeldCwd = class {
15572
- view;
15573
- seen;
15574
- dead = false;
15575
- slot;
15576
- at;
15577
- ask;
15578
- constructor(sab, slot2, ask, state) {
15579
- this.view = new Int32Array(sab);
15580
- this.slot = slot2;
15581
- this.ask = ask;
15582
- this.seen = state.seen;
15583
- this.dead = state.dead;
15584
- this.at = state.path;
15585
- }
15586
- moved(reply, path) {
15587
- if (reply.slot === void 0) return false;
15588
- this.slot = reply.slot;
15589
- this.seen = reply.seen ?? Atomics.load(this.view, reply.slot);
15590
- this.dead = reply.dead === true;
15591
- this.at = path;
15592
- return true;
15593
- }
15594
- follow() {
15595
- const answer2 = this.ask();
15596
- if (answer2.slot !== void 0) this.slot = answer2.slot;
15597
- this.seen = answer2.gen;
15598
- this.dead = !answer2.alive;
15599
- return answer2.alive;
15600
- }
15601
- alive(path) {
15602
- if (path !== void 0 && this.at !== void 0 && path !== this.at) {
15603
- this.at = path;
15604
- return this.follow();
15605
- }
15606
- if (this.dead) return false;
15607
- if (Atomics.load(this.view, this.slot) === this.seen) return true;
15608
- return this.follow();
15609
- }
15610
- get current() {
15611
- return this.slot;
15612
- }
15613
- };
15614
- }
15615
- });
15616
-
15617
15682
  // src/process/wasi/dylink.ts
15618
15683
  function dylinkInfo(module) {
15619
15684
  const [section2] = WebAssembly.Module.customSections(module, "dylink.0");