@ai-ecoverse/slicc-kernel 1.124.7 → 1.124.9

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.
@@ -600,6 +600,7 @@ function parseSyncFsStat(json2) {
600
600
  ...s.ranged === true ? { ranged: true } : {},
601
601
  ...s.linkable === true ? { linkable: true } : {},
602
602
  ...typeof s.version === "string" ? { version: s.version } : {},
603
+ ...typeof s.gen === "number" ? { gen: s.gen } : {},
603
604
  ...typeof s.uid === "number" ? { uid: s.uid } : {},
604
605
  ...typeof s.gid === "number" ? { gid: s.gid } : {}
605
606
  };
@@ -1984,7 +1985,8 @@ function promoteRequest(fd, f, handed) {
1984
1985
  ...orphan ? { orphan: true } : {},
1985
1986
  ...!orphan && f.buffer.pin !== void 0 ? { pin: { version: f.buffer.pin, size: f.buffer.size() } } : {},
1986
1987
  ...!joins && f.buffer.isDirty() ? { dirty: true } : {},
1987
- ...f.buffer.handle !== void 0 ? { handle: f.buffer.handle } : {}
1988
+ ...f.buffer.handle !== void 0 ? { handle: f.buffer.handle } : {},
1989
+ ...f.buffer.handle !== void 0 && f.ino !== void 0 ? { ino: f.ino } : {}
1988
1990
  };
1989
1991
  }
1990
1992
  var SYNTHETIC_DIRS, O_NONBLOCK, O_WRONLY, O_RDWR, O_APPEND, SEALED_PATH, CLIPBOARD_PATH, WasiFds, GEN;
@@ -2586,6 +2588,9 @@ var init_wasi_fds = __esm({
2586
2588
  const alias = stdioAlias(path);
2587
2589
  if (alias !== void 0) return this.reopen(alias);
2588
2590
  const exclusive = (oflags & OFLAGS.CREAT) !== 0 && (oflags & OFLAGS.EXCL) !== 0;
2591
+ if (exclusive && this.shared && !(oflags & OFLAGS.DIRECTORY) && this.madeAtOnce(path, mode)) {
2592
+ return this.kernelFile(path, void 0, oflags, rights, fdflags, mode, true);
2593
+ }
2589
2594
  if (exclusive && this.isLink(path)) throw new WasiError("EEXIST");
2590
2595
  const s = this.statOrMissing(path);
2591
2596
  if (exclusive && s) throw new WasiError("EEXIST");
@@ -2660,7 +2665,9 @@ var init_wasi_fds = __esm({
2660
2665
  const st = existing?.ranged || !existing ? this.fs.stat(path) : existing;
2661
2666
  const ranged = st.ranged ? st.size : void 0;
2662
2667
  const asked = (want & 4 ? HOLD_READ : 0) | (want & 2 ? HOLD_WRITE : 0) | (made ? HOLD_CREATED : 0);
2663
- const handle = this.fs.hold?.(path, true, true, void 0, this.fs.owners ? asked : 0);
2668
+ const handle = this.fs.hold?.(path, true, true, void 0, this.fs.owners ? asked : 0, {
2669
+ gen: st.gen
2670
+ });
2664
2671
  const io = handle !== void 0 && this.fs.pinned ? this.fs.pinned(handle) : this.fs;
2665
2672
  const view = this.fs.changes;
2666
2673
  const watch = view && linkedWatch(
@@ -2683,11 +2690,11 @@ var init_wasi_fds = __esm({
2683
2690
  if (id !== void 0) this.know(buffer, id);
2684
2691
  return buffer;
2685
2692
  }
2686
- kernelFile(path, existing, oflags, rights, fdflags, mode) {
2693
+ kernelFile(path, existing, oflags, rights, fdflags, mode, created = false) {
2687
2694
  const { readable: readable3, writable: writable2 } = openAccess(existing, oflags, rights);
2688
2695
  const append = (fdflags & FDFLAGS.APPEND) !== 0;
2689
2696
  const flags = (writable2 ? readable3 ? O_RDWR : O_WRONLY : 0) | (append ? O_APPEND : 0);
2690
- const made = !existing && this.createNew(path, oflags, mode);
2697
+ const made = created || !existing && this.createNew(path, oflags, mode);
2691
2698
  const truncate = made || (oflags & OFLAGS.TRUNC) !== 0;
2692
2699
  const fd = this.kernel.sys.openVfs(path, flags, 0, {
2693
2700
  ...truncate ? { truncate } : {},
@@ -2722,6 +2729,16 @@ var init_wasi_fds = __esm({
2722
2729
  }
2723
2730
  }
2724
2731
  }
2732
+ madeAtOnce(path, mode) {
2733
+ if (!this.fs.create) return false;
2734
+ try {
2735
+ this.fs.create(path, mode, true);
2736
+ return true;
2737
+ } catch (err) {
2738
+ if (err.code === "EEXIST") throw err;
2739
+ return false;
2740
+ }
2741
+ }
2725
2742
  createNew(path, oflags, mode) {
2726
2743
  if (!this.fs.create) {
2727
2744
  this.fs.writeFile(path, new Uint8Array(0));
@@ -5434,7 +5451,7 @@ var KERNEL_VERSION, OS_RELEASE;
5434
5451
  var init_version = __esm({
5435
5452
  "src/version.ts"() {
5436
5453
  "use strict";
5437
- KERNEL_VERSION = true ? "1.124.7" : "0.0.0-dev";
5454
+ KERNEL_VERSION = true ? "1.124.9" : "0.0.0-dev";
5438
5455
  OS_RELEASE = "6.0.0-slicc";
5439
5456
  }
5440
5457
  });
@@ -7538,9 +7555,12 @@ function createSyncFsSabBridge(transport, opts = {}) {
7538
7555
  access: (path, mode, kind = "access", nofollow) => {
7539
7556
  run({ op: "access", path, mode, arg2: kind, ...nofollow ? { nofollow } : {} }, path);
7540
7557
  },
7541
- hold: (path, held2, open, handle, want = 0) => {
7558
+ hold: (path, held2, open, handle, want = 0, seen = {}) => {
7542
7559
  const mode = (held2 ? 1 : 0) | (open ? 2 : 0);
7543
- if (mode === 3) return json2({ op: "hold", path, mode: mode | want }, path);
7560
+ if (mode === 3) {
7561
+ const at = seen.gen !== void 0 ? { gen: seen.gen } : {};
7562
+ return json2({ op: "hold", path, mode: mode | want, ...at }, path);
7563
+ }
7544
7564
  run({ op: "hold", path, mode, ...handle !== void 0 ? { handle } : {} }, path);
7545
7565
  return void 0;
7546
7566
  },
@@ -8103,6 +8123,16 @@ function appendThrough(h, stream, bytes) {
8103
8123
  stream.position = after - body.length;
8104
8124
  return true;
8105
8125
  }
8126
+ function holdLive(bridge, node, on, want) {
8127
+ const s = node.live;
8128
+ const seen = on && s.stat ? { gen: s.stat.gen } : void 0;
8129
+ return bridge.hold?.(liveNodePath(node), on, true, s.handle, want, seen);
8130
+ }
8131
+ function dropOpen(s) {
8132
+ if (s.openCount === 0) return false;
8133
+ s.openCount -= 1;
8134
+ return true;
8135
+ }
8106
8136
  function createStreamOps(h) {
8107
8137
  const { Fs, statOf, ensureLoaded, ensureCapacity, flushNode, bridgeOf, rangedOf } = h;
8108
8138
  const held2 = (stream, change) => {
@@ -8120,7 +8150,7 @@ function createStreamOps(h) {
8120
8150
  const opened2 = (node, on, want = 0) => {
8121
8151
  const s = node.live;
8122
8152
  try {
8123
- const handle = bridgeOf(node).hold?.(liveNodePath(node), on, true, s.handle, want);
8153
+ const handle = holdLive(bridgeOf(node), node, on, want);
8124
8154
  s.handle = on ? handle : void 0;
8125
8155
  h.linked.opening(node, on);
8126
8156
  if (s.handle === void 0) h.handled.delete(node);
@@ -8212,7 +8242,7 @@ function createStreamOps(h) {
8212
8242
  const node = stream.node;
8213
8243
  if (!Fs.isFile(node.mode)) return;
8214
8244
  const s = node.live;
8215
- s.openCount = Math.max(0, s.openCount - 1);
8245
+ if (!dropOpen(s)) return;
8216
8246
  if (s.openCount > 0) {
8217
8247
  held2(stream, -1);
8218
8248
  return;
@@ -8226,7 +8256,7 @@ function createStreamOps(h) {
8226
8256
  s.len = 0;
8227
8257
  s.loaded = false;
8228
8258
  held2(stream, -1);
8229
- opened2(node, false);
8259
+ if (s.handle !== void 0) opened2(node, false);
8230
8260
  }
8231
8261
  },
8232
8262
  read(stream, buffer, offset, length, position) {
@@ -10276,15 +10306,37 @@ function frozen(bytes) {
10276
10306
  truncate: refuse2
10277
10307
  };
10278
10308
  }
10279
- function procfsBridge(fs, tree) {
10280
- const toProc = (path, follow2) => procPath(fs, path, follow2);
10281
- const shadowing = () => {
10309
+ function physicalProc(fs) {
10310
+ const view = fs.changes;
10311
+ let seen;
10312
+ return () => {
10313
+ if (seen && view && !view.foreign()) {
10314
+ const proc = view.changedSince(seen.gen, "/proc");
10315
+ if (!proc.changed && !view.changedSince(seen.gen, "/").changed) {
10316
+ seen.gen = proc.now;
10317
+ return seen.physical;
10318
+ }
10319
+ }
10320
+ const gen = view?.now();
10321
+ let physical2;
10282
10322
  try {
10283
- return fs.exists("/proc");
10284
- } catch {
10285
- return false;
10323
+ fs.stat("/proc");
10324
+ physical2 = true;
10325
+ } catch (err) {
10326
+ const code2 = err.code;
10327
+ if (code2 !== "ENOENT" && code2 !== "ENOTDIR") {
10328
+ seen = void 0;
10329
+ return false;
10330
+ }
10331
+ physical2 = false;
10286
10332
  }
10333
+ seen = gen === void 0 ? void 0 : { gen, physical: physical2 };
10334
+ return physical2;
10287
10335
  };
10336
+ }
10337
+ function procfsBridge(fs, tree) {
10338
+ const toProc = (path, follow2) => procPath(fs, path, follow2);
10339
+ const shadowing = physicalProc(fs);
10288
10340
  const via = (p, proc, own, follow2 = true) => {
10289
10341
  if (inProc(p)) return proc(p);
10290
10342
  if (shadowing()) {
@@ -10394,10 +10446,10 @@ function procfsBridge(fs, tree) {
10394
10446
  ],
10395
10447
  () => fs.link(from, to, follow2)
10396
10448
  ),
10397
- hold: (p, held2, open, handle, want) => {
10449
+ hold: (p, held2, open, handle, want, seen) => {
10398
10450
  if (handle !== void 0 && snapshots.delete(handle)) return void 0;
10399
10451
  if (!held2) return fs.hold?.(p, held2, open, handle);
10400
- return via(p, snapshot, () => fs.hold?.(p, held2, open, void 0, want) ?? late(p));
10452
+ return via(p, snapshot, () => fs.hold?.(p, held2, open, void 0, want, seen) ?? late(p));
10401
10453
  },
10402
10454
  kept: (handle) => snapshots.has(handle) || fs.kept?.(handle) === true,
10403
10455
  pinned: (handle) => {
@@ -12875,18 +12927,28 @@ function orphanContents(stream) {
12875
12927
  if (live.ranged) return live.ranged.read(0, live.ranged.size());
12876
12928
  return live.data?.slice(0, live.len ?? live.data.length) ?? new Uint8Array(0);
12877
12929
  }
12930
+ function heldOf(live) {
12931
+ const ranged = live?.ranged;
12932
+ const version = ranged?.pinnedVersion;
12933
+ const pin = ranged && version !== void 0 ? { version, size: ranged.size() } : void 0;
12934
+ const handle = live?.handle;
12935
+ const ino = live?.stat?.ino;
12936
+ return {
12937
+ ...pin ? { pin } : {},
12938
+ ...handle !== void 0 ? { handle } : {},
12939
+ ...handle !== void 0 && ino !== void 0 ? { ino } : {}
12940
+ };
12941
+ }
12878
12942
  function vfsPromoter(Fs, sys, streams2, livePath) {
12879
12943
  const promoted = /* @__PURE__ */ new Map();
12880
12944
  return (stream) => {
12881
12945
  if (stream.sliccKernelFd !== void 0 || !isVfsFile(Fs, stream)) return;
12946
+ const live = stream.stream_ops;
12882
12947
  let kfd = promoted.get(stream.shared);
12883
12948
  if (kfd === void 0) {
12949
+ live.fsync?.(stream);
12884
12950
  const contents = orphanContents(stream);
12885
- const ranged = stream.node.live?.ranged;
12886
- const version = ranged?.pinnedVersion;
12887
- const pin = ranged && version !== void 0 ? { version, size: ranged.size() } : void 0;
12888
- const handle = stream.node.live?.handle;
12889
- const held2 = { ...pin ? { pin } : {}, ...handle !== void 0 ? { handle } : {} };
12951
+ const held2 = heldOf(stream.node.live);
12890
12952
  kfd = sys.openVfs(
12891
12953
  livePath(stream),
12892
12954
  stream.flags,
@@ -13727,6 +13789,7 @@ function kernelSys(transport) {
13727
13789
  ...opts?.created ? { created: true } : {},
13728
13790
  ...opts?.pin ? { pin: opts.pin } : {},
13729
13791
  ...opts?.handle !== void 0 ? { handle: opts.handle } : {},
13792
+ ...opts?.ino !== void 0 ? { ino: opts.ino } : {},
13730
13793
  ...opts?.fifo ? { fifo: true } : {}
13731
13794
  },
13732
13795
  `fd-open-vfs ${path}`