@ai-ecoverse/slicc-kernel 1.134.1 → 1.134.4

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.1" : "0.0.0-dev";
6681
+ KERNEL_VERSION = true ? "1.134.4" : "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
  };
@@ -12907,7 +12997,7 @@ function forkRestarted(deps, state, snapshotAt) {
12907
12997
  const live = deps.memory?.();
12908
12998
  if (live) memory = new Uint8Array(live.buffer).slice();
12909
12999
  }
12910
- const forked = { ...state, memory, streams: streams2, cwd: deps.Fs.cwd() };
13000
+ const forked = { ...state, memory, streams: streams2, cwd: heldCwdOf(deps.Fs) };
12911
13001
  return deps.transport.call(
12912
13002
  { op: "proc-fork", state: forked, restart: true },
12913
13003
  Infinity,
@@ -13047,7 +13137,7 @@ function createProcessKernel(deps) {
13047
13137
  file,
13048
13138
  argv,
13049
13139
  env: env ?? deps.env,
13050
- cwd: cwd ?? Fs.cwd(),
13140
+ cwd: cwd ?? heldCwdOf(Fs),
13051
13141
  ...cwd !== null ? { chdir: true } : {},
13052
13142
  stdio,
13053
13143
  ...inherit.length > 0 ? { inherit } : {},
@@ -13143,7 +13233,7 @@ function createProcessKernel(deps) {
13143
13233
  }
13144
13234
  };
13145
13235
  }
13146
- var S_IFMT3, UNSEEDED, S_IFDIR2, POLLIN2, POLLOUT2, POLLERR2, POLLHUP2, POLLNVAL, SELECT_SLICE_MS, WUNTRACED, WCONTINUED;
13236
+ var S_IFMT3, UNSEEDED, S_IFDIR2, POLLIN2, POLLOUT2, POLLERR2, POLLHUP2, POLLNVAL, SELECT_SLICE_MS, WUNTRACED, WCONTINUED, heldCwdOf;
13147
13237
  var init_process_children = __esm({
13148
13238
  "src/process/process-children.ts"() {
13149
13239
  "use strict";
@@ -13162,6 +13252,7 @@ var init_process_children = __esm({
13162
13252
  SELECT_SLICE_MS = 20;
13163
13253
  WUNTRACED = 2;
13164
13254
  WCONTINUED = 8;
13255
+ heldCwdOf = (Fs) => (Fs.sliccHeldCwd ?? Fs.cwd).call(Fs);
13165
13256
  }
13166
13257
  });
13167
13258
 
@@ -13782,6 +13873,7 @@ function kernelWrappers(imports, module, deps) {
13782
13873
  const fsOf = () => ownValue(module, "FS");
13783
13874
  noFollowUtimes(imports, fsOf, kernelGlue?.utimensat ?? utimensatOf(module), memory);
13784
13875
  kernelAccess(imports, fsOf, memory, kernelGlue);
13876
+ goneCwdGetcwd(imports, fsOf, kernelGlue);
13785
13877
  kernelLink(imports, fsOf, memory, kernelGlue);
13786
13878
  devCreations(imports, fsOf, memory, kernelGlue);
13787
13879
  kernelUname(imports, hostnameOf(init.env), memory, kernelGlue);
@@ -13799,6 +13891,19 @@ function kernelWrappers(imports, module, deps) {
13799
13891
  reportGrowth(imports, grown, kernelGlue);
13800
13892
  holdWhileStopped(imports, new Int32Array(init.sab, 0, SAB_HEADER_I32), kernelGlue, deps.poll);
13801
13893
  }
13894
+ function heldIn(fs, init, transport) {
13895
+ if (!init.held) return;
13896
+ const ask = (req) => {
13897
+ const r = transport.call(req, Number.POSITIVE_INFINITY, req.op);
13898
+ return r.ok && r.kind === "json" ? r.json : {};
13899
+ };
13900
+ const check = () => ask({ op: "cwd-check" });
13901
+ holdingCwd(
13902
+ fs,
13903
+ new HeldCwd(init.held.sab, init.held.slot, check, init.held),
13904
+ (path) => ask({ op: "cwd-chdir", path })
13905
+ );
13906
+ }
13802
13907
  function bridgeFlags(init) {
13803
13908
  return {
13804
13909
  ...init.owners ? { owners: true } : {},
@@ -13929,15 +14034,15 @@ async function runWasmProcess(init, port3, deps = {}) {
13929
14034
  warn: deps.warn ?? say(2),
13930
14035
  cred: init.owners ? init.cred : void 0
13931
14036
  });
14037
+ heldIn(running.FS, init, transport);
13932
14038
  early = () => signals.quiet(() => vfs.flushDirty());
13933
14039
  closeDropsLocks(running.FS, sys);
13934
14040
  const sigpipe = () => running.sliccSigpipe?.() === 1 || sigpipeSpared(gated);
13935
14041
  const restartable = () => signals.restartable();
13936
- const owners = init.owners ? { owners: true } : {};
13937
14042
  const streams2 = new KernelStreams(running.FS, sys, {
13938
14043
  sigpipe,
13939
14044
  restartable,
13940
- ...owners,
14045
+ ...init.owners ? { owners: true } : {},
13941
14046
  program: init.argv0
13942
14047
  });
13943
14048
  trackCloseOnExec(running.FS);
@@ -14076,9 +14181,11 @@ var FS_OPS, O_RDONLY2, O_WRONLY6, O_RDWR6, O_ACCMODE5, O_DIRECTORY2, accessMode,
14076
14181
  var init_process_runtime = __esm({
14077
14182
  "src/process/process-runtime.ts"() {
14078
14183
  "use strict";
14184
+ init_held_cwd();
14079
14185
  init_loopback_names();
14080
14186
  init_protocol();
14081
14187
  init_signals();
14188
+ init_emscripten_held_cwd();
14082
14189
  init_emscripten_vfs_hook();
14083
14190
  init_live_vfs_fs();
14084
14191
  init_sync_fs_wire();
@@ -14962,13 +15069,19 @@ function tracked2(pending, writeAll, writeSome, failed5) {
14962
15069
  })();
14963
15070
  };
14964
15071
  }
15072
+ function heldOn(init, lane, syncKernel) {
15073
+ if (!init || lane === noLane) return void 0;
15074
+ const ask = () => syncKernel.json({ op: "cwd-check" });
15075
+ return new HeldCwd(init.sab, init.slot, ask, init);
15076
+ }
14965
15077
  function createContext(o) {
14966
15078
  const { kernel } = o;
14967
15079
  const infos = /* @__PURE__ */ new Map();
14968
15080
  const handles = /* @__PURE__ */ new Map();
14969
15081
  const pending = /* @__PURE__ */ new Set();
14970
15082
  const random = o.random ?? cryptoRandom;
14971
- const resolve = (path) => resolvePath(o.cwd, path);
15083
+ let held2;
15084
+ const resolve = (path) => resolvePath(cwdFor(o.cwd, held2, path), path);
14972
15085
  const tryDev = (abs) => resolveDevAsync(kernel, abs);
14973
15086
  let exiting;
14974
15087
  const exit = (code2 = 0) => {
@@ -15020,6 +15133,7 @@ function createContext(o) {
15020
15133
  const lane = o.lane ?? laneOf(void 0);
15021
15134
  if (o.lane && o.lane !== noLane) kernel.syncLane = o.lane;
15022
15135
  const syncKernel = new JsSyncKernel(lane, kernel, unwind);
15136
+ held2 = heldOn(o.held, lane, syncKernel);
15023
15137
  const terminal = ttyOps(kernel, syncKernel);
15024
15138
  const shared = { pid: o.pid, resolve, random, infos, handles, closing };
15025
15139
  const wasi = wasiFor({ lane, pid: o.pid, cwd: o.cwd, resolve, fs: o.fs, owned: o.owned });
@@ -15302,7 +15416,9 @@ var init_js_context = __esm({
15302
15416
  "src/process/js/js-context.ts"() {
15303
15417
  "use strict";
15304
15418
  init_physical_path();
15419
+ init_held_cwd();
15305
15420
  init_signals();
15421
+ init_emscripten_held_cwd();
15306
15422
  init_sync_fs_wire();
15307
15423
  init_version();
15308
15424
  init_js_children();
@@ -15504,6 +15620,7 @@ async function runJs(init, port3, deps, thread) {
15504
15620
  strays,
15505
15621
  thread: threadContext(port3, thread),
15506
15622
  ...thread?.owned ? { owned: thread.owned } : {},
15623
+ held: init.held,
15507
15624
  failed: () => failedWith
15508
15625
  });
15509
15626
  const say = (text) => ctx.write(2, `${init.argv0}: ${text}
@@ -15561,59 +15678,6 @@ var init_js_runtime = __esm({
15561
15678
  }
15562
15679
  });
15563
15680
 
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
15681
  // src/process/wasi/dylink.ts
15618
15682
  function dylinkInfo(module) {
15619
15683
  const [section2] = WebAssembly.Module.customSections(module, "dylink.0");