@ai-ecoverse/slicc-kernel 1.62.0 → 1.62.1

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.
@@ -575,7 +575,26 @@ function cachingBridge(bridge, now = () => performance.now(), shared) {
575
575
  cache.mutated(paths);
576
576
  }
577
577
  };
578
+ let exact = false;
579
+ const threaded = () => {
580
+ if (blind || shared === void 0 || !bridge.identify) return;
581
+ exact = true;
582
+ bridge.identify();
583
+ };
584
+ const identified = (p, op, also) => {
585
+ const before = cache.generation();
586
+ try {
587
+ return op();
588
+ } finally {
589
+ const st = bridge.identified?.() ?? null;
590
+ if (!st) cache.mutated([]);
591
+ else if (cache.mutated([p, ...also], st.ino) === before + 1 + also.length && !st.isSymbolicLink) {
592
+ cache.put(stats, p, st);
593
+ }
594
+ }
595
+ };
578
596
  const rewriting = (p, op, ...also) => {
597
+ if (exact) return identified(p, op, also);
579
598
  const ino = cache.inoOf(p, () => bridge.stat(p));
580
599
  try {
581
600
  return op();
@@ -634,7 +653,8 @@ function cachingBridge(bridge, now = () => performance.now(), shared) {
634
653
  } : {},
635
654
  ...bridge.owners ? { owners: true } : {},
636
655
  invalidate,
637
- touched
656
+ touched,
657
+ threaded
638
658
  };
639
659
  }
640
660
  function pinnedIo(bridge, handle, rewriting) {
@@ -883,11 +903,15 @@ var init_wasi_files = __esm({
883
903
  }
884
904
  mutated(paths, ino = 0) {
885
905
  this.clear();
886
- if (!this.shared) return;
906
+ if (!this.shared) return 0;
887
907
  const key = ino % 4294967296 | 0;
888
908
  for (const [i, hash] of (paths.length > 0 ? paths.map(pathHash) : [0]).entries()) {
889
909
  this.seen = this.publish(this.shared, hash, i === 0 ? key : 0);
890
910
  }
911
+ return this.seen;
912
+ }
913
+ generation() {
914
+ return this.shared ? Atomics.load(this.shared, FS_GEN) : 0;
891
915
  }
892
916
  inoOf(path, look) {
893
917
  if (!this.shared) return 0;
@@ -1307,6 +1331,7 @@ var init_wasi_fds = __esm({
1307
1331
  this.cloexec.clear();
1308
1332
  }
1309
1333
  this.shared = ids;
1334
+ this.fs.threaded?.();
1310
1335
  this.seen = Atomics.load(ids, GEN);
1311
1336
  }
1312
1337
  sync() {
@@ -1631,6 +1656,14 @@ var init_wasi_fds = __esm({
1631
1656
  this.detach(buffer, linked);
1632
1657
  this.buffers.delete(path);
1633
1658
  }
1659
+ openedIno(fd) {
1660
+ try {
1661
+ return this.kernel.call({ op: "fd-vfs-stat", fd, identity: true }).ino;
1662
+ } catch (err) {
1663
+ this.kernel.sys.close(fd);
1664
+ throw err;
1665
+ }
1666
+ }
1634
1667
  inoOf(path) {
1635
1668
  try {
1636
1669
  return this.fs.stat(path).ino;
@@ -1724,10 +1757,10 @@ var init_wasi_fds = __esm({
1724
1757
  if (e.path !== void 0 || this.learned.has(e)) return;
1725
1758
  this.learned.add(e);
1726
1759
  try {
1727
- const vfs = this.kernel.call({ op: "fd-vfs-stat", fd });
1760
+ const vfs = this.kernel.call({ op: "fd-vfs-stat", fd, identity: true });
1728
1761
  if (vfs.orphan || vfs.path === void 0) return;
1729
1762
  e.path = vfs.path;
1730
- e.ino = this.inoOf(vfs.path);
1763
+ e.ino = vfs.ino ?? this.inoOf(vfs.path);
1731
1764
  } catch {
1732
1765
  }
1733
1766
  }
@@ -1765,9 +1798,8 @@ var init_wasi_fds = __esm({
1765
1798
  const made = !existing && this.createNew(path, oflags);
1766
1799
  const truncate = made || (oflags & OFLAGS.TRUNC) !== 0;
1767
1800
  const fd = this.kernel.sys.openVfs(path, flags, 0, truncate ? { truncate } : {});
1768
- const was = existing && this.inoOf(path);
1769
- if (truncate) this.fs.touched?.(path, was);
1770
- const ino = existing ? was : this.inoOf(path);
1801
+ const ino = writable2 ? this.openedIno(fd) ?? this.inoOf(path) : void 0;
1802
+ if (truncate) this.fs.touched?.(path, ino);
1771
1803
  this.table.set(fd, { type: "kernel", kind: "file", nonblock: false, append, path, ino });
1772
1804
  if (append) this.publishFlags(fd, { nonblock: false, append });
1773
1805
  this.bump();
@@ -2660,9 +2692,9 @@ var init_wasi_host = __esm({
2660
2692
  this.unnamed.add(e);
2661
2693
  let path;
2662
2694
  try {
2663
- const st = this.kernelStat(fd);
2695
+ const st = this.o.kernel.call({ op: "fd-vfs-stat", fd, identity: true });
2664
2696
  path = st.orphan ? void 0 : st.path;
2665
- if (path !== void 0) e.ino = this.o.fs.stat(path).ino;
2697
+ if (path !== void 0) e.ino = st.ino ?? this.o.fs.stat(path).ino;
2666
2698
  } catch {
2667
2699
  return;
2668
2700
  }
@@ -4527,7 +4559,10 @@ function errnoError(code2, path) {
4527
4559
  }
4528
4560
  function createSyncFsSabBridge(transport, opts = {}) {
4529
4561
  const timeoutMs = opts.timeoutMs ?? SYNC_FS_REQUEST_TIMEOUT_MS;
4562
+ let identity = {};
4563
+ let last = null;
4530
4564
  function run(req, path, transfer) {
4565
+ last = null;
4531
4566
  const result = transport.call(req, timeoutMs, `sync-sab bridge, '${path}'`, transfer);
4532
4567
  if (!result.ok) throw errnoError(result.errno, path);
4533
4568
  return result;
@@ -4542,20 +4577,24 @@ function createSyncFsSabBridge(transport, opts = {}) {
4542
4577
  if (r.ok && r.kind === "json") return r.json;
4543
4578
  throw errnoError("EIO", path);
4544
4579
  }
4580
+ const changing = (req, path, transfer) => {
4581
+ const r = run({ ...req, ...identity }, path, transfer);
4582
+ if (r.ok && r.kind === "json") last = parseSyncFsStat(r.json);
4583
+ };
4545
4584
  const io = (id) => ({
4546
4585
  readFile: (path) => bytes({ op: "read", path, ...id }, path),
4547
4586
  writeFile: (path, data, open) => {
4548
- run({ op: "write", path, body: data, ...open ? { mode: 1 } : {}, ...id }, path);
4587
+ changing({ op: "write", path, body: data, ...open ? { mode: 1 } : {}, ...id }, path);
4549
4588
  },
4550
4589
  pread: (path, offset, length, version) => bytes({ op: "pread", path, offset, length, ...version ? { version } : {}, ...id }, path),
4551
4590
  pwrite: (path, offset, body, transfer) => {
4552
4591
  const whole = body.byteOffset === 0 && body.byteLength === body.buffer.byteLength;
4553
4592
  const owned = transfer && whole && body.buffer instanceof ArrayBuffer;
4554
4593
  const transferred = owned ? [body.buffer] : [];
4555
- run({ op: "pwrite", path, offset, body, ...id }, path, transferred);
4594
+ changing({ op: "pwrite", path, offset, body, ...id }, path, transferred);
4556
4595
  },
4557
4596
  truncate: (path, length) => {
4558
- run({ op: "truncate", path, length, ...id }, path);
4597
+ changing({ op: "truncate", path, length, ...id }, path);
4559
4598
  }
4560
4599
  });
4561
4600
  return {
@@ -4627,11 +4666,15 @@ function createSyncFsSabBridge(transport, opts = {}) {
4627
4666
  return target;
4628
4667
  },
4629
4668
  chmod: (path, mode) => {
4630
- run({ op: "chmod", path, mode }, path);
4669
+ changing({ op: "chmod", path, mode }, path);
4631
4670
  },
4632
4671
  utimes: (path, atimeMs, mtimeMs) => {
4633
- run({ op: "utimes", path, atimeMs, mtimeMs }, path);
4672
+ changing({ op: "utimes", path, atimeMs, mtimeMs }, path);
4673
+ },
4674
+ identify: () => {
4675
+ identity = { identity: true };
4634
4676
  },
4677
+ identified: () => last,
4635
4678
  lutimes: (path, atimeMs, mtimeMs) => {
4636
4679
  run({ op: "lutimes", path, atimeMs, mtimeMs }, path);
4637
4680
  },
@@ -4640,7 +4683,7 @@ function createSyncFsSabBridge(transport, opts = {}) {
4640
4683
  },
4641
4684
  chown: (path, uid, gid, follow2) => {
4642
4685
  const ids = { ...uid !== void 0 ? { uid } : {}, ...gid !== void 0 ? { gid } : {} };
4643
- run({ op: follow2 ? "chown" : "lchown", path, ...ids }, path);
4686
+ changing({ op: follow2 ? "chown" : "lchown", path, ...ids }, path);
4644
4687
  },
4645
4688
  ...opts.owners ? { owners: true } : {},
4646
4689
  hold: (path, held, open, handle) => {