@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.
@@ -275,6 +275,59 @@ var init_protocol = __esm({
275
275
  }
276
276
  });
277
277
 
278
+ // src/kernel/held-cwd.ts
279
+ var CWD_SLOTS, UNTRACKED, HeldCwd;
280
+ var init_held_cwd = __esm({
281
+ "src/kernel/held-cwd.ts"() {
282
+ "use strict";
283
+ CWD_SLOTS = 1024;
284
+ UNTRACKED = CWD_SLOTS - 1;
285
+ HeldCwd = class {
286
+ view;
287
+ seen;
288
+ dead = false;
289
+ slot;
290
+ at;
291
+ ask;
292
+ constructor(sab, slot2, ask, state) {
293
+ this.view = new Int32Array(sab);
294
+ this.slot = slot2;
295
+ this.ask = ask;
296
+ this.seen = state.seen;
297
+ this.dead = state.dead;
298
+ this.at = state.path;
299
+ }
300
+ moved(reply, path) {
301
+ if (reply.slot === void 0) return false;
302
+ this.slot = reply.slot;
303
+ this.seen = reply.seen ?? Atomics.load(this.view, reply.slot);
304
+ this.dead = reply.dead === true;
305
+ this.at = path;
306
+ return true;
307
+ }
308
+ follow() {
309
+ const answer2 = this.ask();
310
+ if (answer2.slot !== void 0) this.slot = answer2.slot;
311
+ this.seen = answer2.gen;
312
+ this.dead = !answer2.alive;
313
+ return answer2.alive;
314
+ }
315
+ alive(path) {
316
+ if (path !== void 0 && this.at !== void 0 && path !== this.at) {
317
+ this.at = path;
318
+ return this.follow();
319
+ }
320
+ if (this.dead) return false;
321
+ if (Atomics.load(this.view, this.slot) === this.seen) return true;
322
+ return this.follow();
323
+ }
324
+ get current() {
325
+ return this.slot;
326
+ }
327
+ };
328
+ }
329
+ });
330
+
278
331
  // src/kernel/net/loopback-names.ts
279
332
  function isKernelLoopbackHost(hostname) {
280
333
  const host = hostname.replace(/^\[(.*)\]$/, "$1").replace(/\.$/, "").toLowerCase();
@@ -391,6 +444,31 @@ var init_signals = __esm({
391
444
  }
392
445
  });
393
446
 
447
+ // src/realm/emscripten-held-cwd.ts
448
+ function holdingCwd(Fs, held2, chdirred) {
449
+ const { chdir, cwd } = Fs;
450
+ if (!chdir || !cwd) return;
451
+ Fs.sliccHeldCwd = () => cwd.call(Fs);
452
+ Fs.sliccCwdGone = () => !held2.alive();
453
+ Fs.cwd = () => {
454
+ const path = cwd.call(Fs);
455
+ return held2.alive() ? path : `${path}${DELETED}`;
456
+ };
457
+ Fs.chdir = (path) => {
458
+ chdir.call(Fs, path);
459
+ held2.moved(chdirred(cwd.call(Fs)));
460
+ };
461
+ }
462
+ var DELETED, relativeHere, cwdFor;
463
+ var init_emscripten_held_cwd = __esm({
464
+ "src/realm/emscripten-held-cwd.ts"() {
465
+ "use strict";
466
+ DELETED = " (deleted)";
467
+ relativeHere = (path) => !path.startsWith("/") && path.split("/")[0] !== "..";
468
+ cwdFor = (cwd, held2, path) => held2 && relativeHere(path) && !held2.alive() ? `${cwd}${DELETED}` : cwd;
469
+ }
470
+ });
471
+
394
472
  // src/fs/types.ts
395
473
  function normalizePath(path) {
396
474
  const parts = [];
@@ -1149,7 +1227,7 @@ function createSyncSabTransport(sab, port2, deps = {}) {
1149
1227
  call(req, timeoutMs2, label, transfer = []) {
1150
1228
  if (deps.memory) publishMemory(sab, deps.memory());
1151
1229
  const id = ++seq;
1152
- calls += Number(!PATH_OPS.has(req.op));
1230
+ calls += Number(!UNCOUNTED_OPS.has(req.op));
1153
1231
  let out = null;
1154
1232
  let status2 = 0;
1155
1233
  let offset = 0;
@@ -1371,7 +1449,7 @@ function createSyncFsSabBridge(transport, opts = {}) {
1371
1449
  statfs: (path = "/") => parseSyncFsUsage(json2({ op: "statfs", path }, path))
1372
1450
  };
1373
1451
  }
1374
- var PATH_OPS, calls, looks, SPIN_MS, SPIN_STRIDE, SPIN_STRIDES, SPIN_CORES, spinning, SPIN_CAP_MS;
1452
+ var UNCOUNTED_OPS, calls, looks, SPIN_MS, SPIN_STRIDE, SPIN_STRIDES, SPIN_CORES, spinning, SPIN_CAP_MS;
1375
1453
  var init_sync_sab_bridge = __esm({
1376
1454
  "src/realm/sync-sab-bridge.ts"() {
1377
1455
  "use strict";
@@ -1379,7 +1457,7 @@ var init_sync_sab_bridge = __esm({
1379
1457
  init_cpu_clock();
1380
1458
  init_sync_fs_wire();
1381
1459
  init_sync_sab_wire();
1382
- PATH_OPS = new Set(SYNC_FS_OPS);
1460
+ UNCOUNTED_OPS = /* @__PURE__ */ new Set([...SYNC_FS_OPS, "cwd-check", "cwd-chdir"]);
1383
1461
  calls = 0;
1384
1462
  looks = 0;
1385
1463
  SPIN_MS = 0.06;
@@ -2693,7 +2771,7 @@ var KERNEL_VERSION, OS_RELEASE;
2693
2771
  var init_version = __esm({
2694
2772
  "src/version.ts"() {
2695
2773
  "use strict";
2696
- KERNEL_VERSION = true ? "1.134.1" : "0.0.0-dev";
2774
+ KERNEL_VERSION = true ? "1.134.4" : "0.0.0-dev";
2697
2775
  OS_RELEASE = "6.0.0-slicc";
2698
2776
  }
2699
2777
  });
@@ -3551,6 +3629,15 @@ function kernelChecks(Fs, memory, call2) {
3551
3629
  bridge.access(liveNodePath(node), call2.amode, kind, (call2.flags & AT_SYMLINK_NOFOLLOW) !== 0);
3552
3630
  return 0;
3553
3631
  }
3632
+ function goneCwdGetcwd(imports, fs, glue) {
3633
+ wrapImport(
3634
+ imports,
3635
+ "getcwd",
3636
+ glue,
3637
+ (own) => (...args) => fs()?.sliccCwdGone?.() === true ? -44 : own(...args),
3638
+ true
3639
+ );
3640
+ }
3554
3641
  function kernelAccess(imports, fs, memory, glue) {
3555
3642
  wrapImport(imports, "faccessat", glue, (own) => (dirfd, path, amode, flags) => {
3556
3643
  const Fs = fs();
@@ -3738,7 +3825,8 @@ var init_process_fds = __esm({
3738
3825
  fdWrite: "fd_write",
3739
3826
  fdRead: "fd_read",
3740
3827
  sleepMs: "slicc_sleep_ms",
3741
- flock: "__syscall_flock"
3828
+ flock: "__syscall_flock",
3829
+ getcwd: "__syscall_getcwd"
3742
3830
  };
3743
3831
  UTIME_NOW = 1073741823;
3744
3832
  UTIME_OMIT = 1073741822;
@@ -4807,7 +4895,7 @@ function forkRestarted(deps, state, snapshotAt) {
4807
4895
  const live = deps.memory?.();
4808
4896
  if (live) memory = new Uint8Array(live.buffer).slice();
4809
4897
  }
4810
- const forked = { ...state, memory, streams: streams2, cwd: deps.Fs.cwd() };
4898
+ const forked = { ...state, memory, streams: streams2, cwd: heldCwdOf(deps.Fs) };
4811
4899
  return deps.transport.call(
4812
4900
  { op: "proc-fork", state: forked, restart: true },
4813
4901
  Infinity,
@@ -4947,7 +5035,7 @@ function createProcessKernel(deps) {
4947
5035
  file,
4948
5036
  argv,
4949
5037
  env: env ?? deps.env,
4950
- cwd: cwd ?? Fs.cwd(),
5038
+ cwd: cwd ?? heldCwdOf(Fs),
4951
5039
  ...cwd !== null ? { chdir: true } : {},
4952
5040
  stdio,
4953
5041
  ...inherit.length > 0 ? { inherit } : {},
@@ -5043,7 +5131,7 @@ function createProcessKernel(deps) {
5043
5131
  }
5044
5132
  };
5045
5133
  }
5046
- var S_IFMT2, UNSEEDED, S_IFDIR2, POLLIN2, POLLOUT2, POLLERR2, POLLHUP2, POLLNVAL, SELECT_SLICE_MS, WUNTRACED, WCONTINUED;
5134
+ var S_IFMT2, UNSEEDED, S_IFDIR2, POLLIN2, POLLOUT2, POLLERR2, POLLHUP2, POLLNVAL, SELECT_SLICE_MS, WUNTRACED, WCONTINUED, heldCwdOf;
5047
5135
  var init_process_children = __esm({
5048
5136
  "src/process/process-children.ts"() {
5049
5137
  "use strict";
@@ -5062,6 +5150,7 @@ var init_process_children = __esm({
5062
5150
  SELECT_SLICE_MS = 20;
5063
5151
  WUNTRACED = 2;
5064
5152
  WCONTINUED = 8;
5153
+ heldCwdOf = (Fs) => (Fs.sliccHeldCwd ?? Fs.cwd).call(Fs);
5065
5154
  }
5066
5155
  });
5067
5156
 
@@ -5784,6 +5873,8 @@ var init_procfs = __esm({
5784
5873
  slicc_opfs_calls: (listing2) => `${listing2.opfsCalls ?? 0}
5785
5874
  `,
5786
5875
  slicc_opfs_ops: (listing2) => `${listing2.opfsOps ?? 0}
5876
+ `,
5877
+ slicc_cwd_checks: (listing2) => `${listing2.cwdChecks ?? 0}
5787
5878
  `
5788
5879
  }
5789
5880
  };
@@ -6115,6 +6206,7 @@ function kernelWrappers(imports, module, deps) {
6115
6206
  const fsOf = () => ownValue(module, "FS");
6116
6207
  noFollowUtimes(imports, fsOf, kernelGlue?.utimensat ?? utimensatOf(module), memory);
6117
6208
  kernelAccess(imports, fsOf, memory, kernelGlue);
6209
+ goneCwdGetcwd(imports, fsOf, kernelGlue);
6118
6210
  kernelLink(imports, fsOf, memory, kernelGlue);
6119
6211
  devCreations(imports, fsOf, memory, kernelGlue);
6120
6212
  kernelUname(imports, hostnameOf(init.env), memory, kernelGlue);
@@ -6132,6 +6224,19 @@ function kernelWrappers(imports, module, deps) {
6132
6224
  reportGrowth(imports, grown, kernelGlue);
6133
6225
  holdWhileStopped(imports, new Int32Array(init.sab, 0, SAB_HEADER_I32), kernelGlue, deps.poll);
6134
6226
  }
6227
+ function heldIn(fs, init, transport) {
6228
+ if (!init.held) return;
6229
+ const ask = (req) => {
6230
+ const r = transport.call(req, Number.POSITIVE_INFINITY, req.op);
6231
+ return r.ok && r.kind === "json" ? r.json : {};
6232
+ };
6233
+ const check = () => ask({ op: "cwd-check" });
6234
+ holdingCwd(
6235
+ fs,
6236
+ new HeldCwd(init.held.sab, init.held.slot, check, init.held),
6237
+ (path) => ask({ op: "cwd-chdir", path })
6238
+ );
6239
+ }
6135
6240
  function bridgeFlags(init) {
6136
6241
  return {
6137
6242
  ...init.owners ? { owners: true } : {},
@@ -6262,15 +6367,15 @@ async function runWasmProcess(init, port2, deps = {}) {
6262
6367
  warn: deps.warn ?? say(2),
6263
6368
  cred: init.owners ? init.cred : void 0
6264
6369
  });
6370
+ heldIn(running.FS, init, transport);
6265
6371
  early = () => signals.quiet(() => vfs.flushDirty());
6266
6372
  closeDropsLocks(running.FS, sys);
6267
6373
  const sigpipe = () => running.sliccSigpipe?.() === 1 || sigpipeSpared(gated);
6268
6374
  const restartable = () => signals.restartable();
6269
- const owners = init.owners ? { owners: true } : {};
6270
6375
  const streams2 = new KernelStreams(running.FS, sys, {
6271
6376
  sigpipe,
6272
6377
  restartable,
6273
- ...owners,
6378
+ ...init.owners ? { owners: true } : {},
6274
6379
  program: init.argv0
6275
6380
  });
6276
6381
  trackCloseOnExec(running.FS);
@@ -6409,9 +6514,11 @@ var FS_OPS, O_RDONLY2, O_WRONLY3, O_RDWR3, O_ACCMODE5, O_DIRECTORY2, accessMode,
6409
6514
  var init_process_runtime = __esm({
6410
6515
  "src/process/process-runtime.ts"() {
6411
6516
  "use strict";
6517
+ init_held_cwd();
6412
6518
  init_loopback_names();
6413
6519
  init_protocol();
6414
6520
  init_signals();
6521
+ init_emscripten_held_cwd();
6415
6522
  init_emscripten_vfs_hook();
6416
6523
  init_live_vfs_fs();
6417
6524
  init_sync_fs_wire();
@@ -6608,59 +6715,6 @@ var init_physical_path = __esm({
6608
6715
  }
6609
6716
  });
6610
6717
 
6611
- // src/kernel/held-cwd.ts
6612
- var CWD_SLOTS, UNTRACKED, HeldCwd;
6613
- var init_held_cwd = __esm({
6614
- "src/kernel/held-cwd.ts"() {
6615
- "use strict";
6616
- CWD_SLOTS = 1024;
6617
- UNTRACKED = CWD_SLOTS - 1;
6618
- HeldCwd = class {
6619
- view;
6620
- seen;
6621
- dead = false;
6622
- slot;
6623
- at;
6624
- ask;
6625
- constructor(sab, slot2, ask, state) {
6626
- this.view = new Int32Array(sab);
6627
- this.slot = slot2;
6628
- this.ask = ask;
6629
- this.seen = state.seen;
6630
- this.dead = state.dead;
6631
- this.at = state.path;
6632
- }
6633
- moved(reply, path) {
6634
- if (reply.slot === void 0) return false;
6635
- this.slot = reply.slot;
6636
- this.seen = reply.seen ?? Atomics.load(this.view, reply.slot);
6637
- this.dead = reply.dead === true;
6638
- this.at = path;
6639
- return true;
6640
- }
6641
- follow() {
6642
- const answer2 = this.ask();
6643
- if (answer2.slot !== void 0) this.slot = answer2.slot;
6644
- this.seen = answer2.gen;
6645
- this.dead = !answer2.alive;
6646
- return answer2.alive;
6647
- }
6648
- alive(path) {
6649
- if (path !== void 0 && this.at !== void 0 && path !== this.at) {
6650
- this.at = path;
6651
- return this.follow();
6652
- }
6653
- if (this.dead) return false;
6654
- if (Atomics.load(this.view, this.slot) === this.seen) return true;
6655
- return this.follow();
6656
- }
6657
- get current() {
6658
- return this.slot;
6659
- }
6660
- };
6661
- }
6662
- });
6663
-
6664
6718
  // src/process/wasi/dylink.ts
6665
6719
  function dylinkInfo(module) {
6666
6720
  const [section2] = WebAssembly.Module.customSections(module, "dylink.0");
@@ -17667,13 +17721,19 @@ function tracked2(pending, writeAll, writeSome, failed5) {
17667
17721
  })();
17668
17722
  };
17669
17723
  }
17724
+ function heldOn(init, lane, syncKernel) {
17725
+ if (!init || lane === noLane) return void 0;
17726
+ const ask = () => syncKernel.json({ op: "cwd-check" });
17727
+ return new HeldCwd(init.sab, init.slot, ask, init);
17728
+ }
17670
17729
  function createContext(o) {
17671
17730
  const { kernel } = o;
17672
17731
  const infos = /* @__PURE__ */ new Map();
17673
17732
  const handles = /* @__PURE__ */ new Map();
17674
17733
  const pending = /* @__PURE__ */ new Set();
17675
17734
  const random = o.random ?? cryptoRandom;
17676
- const resolve = (path) => resolvePath(o.cwd, path);
17735
+ let held2;
17736
+ const resolve = (path) => resolvePath(cwdFor(o.cwd, held2, path), path);
17677
17737
  const tryDev = (abs) => resolveDevAsync(kernel, abs);
17678
17738
  let exiting;
17679
17739
  const exit = (code2 = 0) => {
@@ -17725,6 +17785,7 @@ function createContext(o) {
17725
17785
  const lane = o.lane ?? laneOf(void 0);
17726
17786
  if (o.lane && o.lane !== noLane) kernel.syncLane = o.lane;
17727
17787
  const syncKernel = new JsSyncKernel(lane, kernel, unwind);
17788
+ held2 = heldOn(o.held, lane, syncKernel);
17728
17789
  const terminal = ttyOps(kernel, syncKernel);
17729
17790
  const shared = { pid: o.pid, resolve, random, infos, handles, closing };
17730
17791
  const wasi = wasiFor({ lane, pid: o.pid, cwd: o.cwd, resolve, fs: o.fs, owned: o.owned });
@@ -18007,7 +18068,9 @@ var init_js_context = __esm({
18007
18068
  "src/process/js/js-context.ts"() {
18008
18069
  "use strict";
18009
18070
  init_physical_path();
18071
+ init_held_cwd();
18010
18072
  init_signals();
18073
+ init_emscripten_held_cwd();
18011
18074
  init_sync_fs_wire();
18012
18075
  init_version();
18013
18076
  init_js_children();
@@ -18209,6 +18272,7 @@ async function runJs(init, port2, deps, thread) {
18209
18272
  strays,
18210
18273
  thread: threadContext(port2, thread),
18211
18274
  ...thread?.owned ? { owned: thread.owned } : {},
18275
+ held: init.held,
18212
18276
  failed: () => failedWith
18213
18277
  });
18214
18278
  const say = (text) => ctx.write(2, `${init.argv0}: ${text}