@ai-ecoverse/slicc-kernel 1.125.1 → 1.125.2

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.
@@ -135,7 +135,8 @@ function decodeSabResult(status2, payload) {
135
135
  try {
136
136
  const parsed = JSON.parse(decoder.decode(payload));
137
137
  const errno2 = typeof parsed.errno === "string" && /^E[A-Z]+$|^EAI_[A-Z]+$/.test(parsed.errno) ? parsed.errno : "EIO";
138
- return { ok: false, errno: errno2, message: String(parsed.message ?? errno2) };
138
+ const message2 = String(parsed.message ?? errno2);
139
+ return parsed.direct === true ? { ok: false, errno: errno2, message: message2, direct: true } : { ok: false, errno: errno2, message: message2 };
139
140
  } catch {
140
141
  return { ok: false, errno: "EIO", message: "sync-sab: malformed errno payload" };
141
142
  }
@@ -1180,10 +1181,12 @@ function createSyncSabTransport(sab, port2, deps = {}) {
1180
1181
  }
1181
1182
  };
1182
1183
  }
1183
- function errnoError(code2, path) {
1184
- return syncError(code2, `sync-sab bridge, '${path}'`);
1184
+ function errnoError(code2, path, direct) {
1185
+ const err = syncError(code2, `sync-sab bridge, '${path}'`);
1186
+ return direct ? Object.assign(err, { direct }) : err;
1185
1187
  }
1186
1188
  function createSyncFsSabBridge(transport, opts = {}) {
1189
+ const direct = opts.direct ? { direct: true } : {};
1187
1190
  const timeoutMs2 = opts.timeoutMs ?? SYNC_FS_REQUEST_TIMEOUT_MS;
1188
1191
  let identity = {};
1189
1192
  let once = false;
@@ -1192,7 +1195,7 @@ function createSyncFsSabBridge(transport, opts = {}) {
1192
1195
  last = null;
1193
1196
  const silence = SYNC_FS_READ_ONLY.has(req.op) ? timeoutMs2 : Number.POSITIVE_INFINITY;
1194
1197
  const result = transport.call(req, silence, `sync-sab bridge, '${path}'`, transfer);
1195
- if (!result.ok) throw errnoError(result.errno, path);
1198
+ if (!result.ok) throw errnoError(result.errno, path, result.direct);
1196
1199
  return result;
1197
1200
  }
1198
1201
  function bytes(req, path) {
@@ -1238,12 +1241,12 @@ function createSyncFsSabBridge(transport, opts = {}) {
1238
1241
  return s;
1239
1242
  },
1240
1243
  stat: (path) => {
1241
- const s = parseSyncFsStat(json2({ op: "stat", path }, path));
1244
+ const s = parseSyncFsStat(json2({ op: "stat", path, ...direct }, path));
1242
1245
  if (!s) throw errnoError("EIO", path);
1243
1246
  return s;
1244
1247
  },
1245
1248
  lstat: (path) => {
1246
- const s = parseSyncFsStat(json2({ op: "lstat", path }, path));
1249
+ const s = parseSyncFsStat(json2({ op: "lstat", path, ...direct }, path));
1247
1250
  if (!s) throw errnoError("EIO", path);
1248
1251
  return s;
1249
1252
  },
@@ -1321,7 +1324,12 @@ function createSyncFsSabBridge(transport, opts = {}) {
1321
1324
  },
1322
1325
  create: (path, mode, opening2) => {
1323
1326
  const flags = { ...mode !== void 0 ? { mode } : {}, ...opening2 ? { opening: opening2 } : {} };
1324
- run({ op: "create", path, ...flags }, path);
1327
+ const r = run({ op: "create", path, ...flags, identity: true }, path);
1328
+ if (!r.ok || r.kind !== "json") return void 0;
1329
+ const st = parseSyncFsStat(r.json);
1330
+ if (!st) return void 0;
1331
+ const { seen } = r.json;
1332
+ return typeof seen === "number" ? { ...st, seen } : st;
1325
1333
  },
1326
1334
  chown: (path, uid, gid, follow3, handle) => {
1327
1335
  const ids = { ...uid !== void 0 ? { uid } : {}, ...gid !== void 0 ? { gid } : {} };
@@ -2647,7 +2655,7 @@ var KERNEL_VERSION, OS_RELEASE;
2647
2655
  var init_version = __esm({
2648
2656
  "src/version.ts"() {
2649
2657
  "use strict";
2650
- KERNEL_VERSION = true ? "1.125.1" : "0.0.0-dev";
2658
+ KERNEL_VERSION = true ? "1.125.2" : "0.0.0-dev";
2651
2659
  OS_RELEASE = "6.0.0-slicc";
2652
2660
  }
2653
2661
  });
@@ -5590,15 +5598,15 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
5590
5598
  };
5591
5599
  const track = (stream, names) => {
5592
5600
  let current = names;
5593
- const remember = (list) => scans.set(stream, new Set(list.filter((n) => /^[1-9]\d*$/.test(n)).map(Number)));
5594
- remember(current ?? []);
5601
+ const remember2 = (list) => scans.set(stream, new Set(list.filter((n) => /^[1-9]\d*$/.test(n)).map(Number)));
5602
+ remember2(current ?? []);
5595
5603
  Object.defineProperty(stream, "getdents", {
5596
5604
  configurable: true,
5597
5605
  enumerable: true,
5598
5606
  get: () => current,
5599
5607
  set: (next2) => {
5600
5608
  current = next2;
5601
- if (next2) remember(next2);
5609
+ if (next2) remember2(next2);
5602
5610
  }
5603
5611
  });
5604
5612
  };
@@ -6617,6 +6625,17 @@ function index(map, key, path) {
6617
6625
  paths.add(path);
6618
6626
  map.set(key, paths);
6619
6627
  }
6628
+ function goneAbove(maps, live, path) {
6629
+ for (let at = path.lastIndexOf("/"); at > 0; at = path.lastIndexOf("/", at - 1)) {
6630
+ const up = path.slice(0, at);
6631
+ for (const map of maps) {
6632
+ const hit = map.get(up);
6633
+ const code2 = hit && "until" in hit ? hit.error.code : void 0;
6634
+ if (hit && "until" in hit && code2 === "ENOENT" && live(hit, up)) return hit;
6635
+ }
6636
+ }
6637
+ return void 0;
6638
+ }
6620
6639
  function cachingBridge(bridge, now = () => performance.now(), shared) {
6621
6640
  const blind = shared !== void 0 && shared.length * 4 < SHARED_IDS_BYTES;
6622
6641
  const cache = new StatCache(blind ? void 0 : shared);
@@ -6624,17 +6643,8 @@ function cachingBridge(bridge, now = () => performance.now(), shared) {
6624
6643
  const view = bridge.changes;
6625
6644
  const live = (miss, path) => miss.until > now() && (view === void 0 || miss.gen === void 0 || !view.changedSince(miss.gen, path).changed);
6626
6645
  const seen = new SeenAt(view, lstats);
6627
- const gone = (path) => {
6628
- for (let at = path.lastIndexOf("/"); at > 0; at = path.lastIndexOf("/", at - 1)) {
6629
- const up = path.slice(0, at);
6630
- for (const map of [lstats, stats]) {
6631
- const hit = map.get(up);
6632
- const code2 = hit && "until" in hit ? hit.error.code : void 0;
6633
- if (hit && "until" in hit && code2 === "ENOENT" && live(hit, up)) return hit;
6634
- }
6635
- }
6636
- return void 0;
6637
- };
6646
+ const kept = remember(cache, seen, blind);
6647
+ const gone = (path) => goneAbove([lstats, stats], live, path);
6638
6648
  const cached = (map, path, get) => {
6639
6649
  if (blind || view?.foreign()) return get();
6640
6650
  cache.fresh();
@@ -6760,7 +6770,10 @@ function cachingBridge(bridge, now = () => performance.now(), shared) {
6760
6770
  ...bridge.keptStat ? { keptStat: bridge.keptStat.bind(bridge) } : {},
6761
6771
  ...bridge.pinned ? { pinned: (handle) => pinnedIo2(bridge, handle, rewriting) } : {},
6762
6772
  ...bridge.create ? {
6763
- create: (p, mode, opening2) => mutating(() => bridge.create?.(p, mode, opening2), ...entry(p))
6773
+ create: (p, mode, opening2) => kept(
6774
+ p,
6775
+ mutating(() => bridge.create?.(p, mode, opening2), ...entry(p))
6776
+ )
6764
6777
  } : {},
6765
6778
  ...bridge.mkfifo ? {
6766
6779
  mkfifo: (p, mode) => mutating(() => bridge.mkfifo?.(p, mode), ...entry(p))
@@ -6797,7 +6810,7 @@ function pinnedIo2(bridge, handle, rewriting) {
6797
6810
  } : {}
6798
6811
  };
6799
6812
  }
6800
- var WasiError, FileBuffer, LocalFile, MAX_LINKS, MISS_TTL_MS, CACHE_CAP, FS_GEN, CRED_GEN, RING2, RING_SIZE2, SLOT2, FD_RING, FD_RING_SIZE, SHARED_IDS_BYTES, StatCache, SEEN_CAP, SeenAt;
6813
+ var WasiError, FileBuffer, LocalFile, MAX_LINKS, MISS_TTL_MS, CACHE_CAP, FS_GEN, CRED_GEN, RING2, RING_SIZE2, SLOT2, FD_RING, FD_RING_SIZE, SHARED_IDS_BYTES, StatCache, SEEN_CAP, SeenAt, remember;
6801
6814
  var init_wasi_files = __esm({
6802
6815
  "src/process/wasi/wasi-files.ts"() {
6803
6816
  "use strict";
@@ -7187,6 +7200,13 @@ var init_wasi_files = __esm({
7187
7200
  return since.changed;
7188
7201
  }
7189
7202
  };
7203
+ remember = (cache, seen, blind) => (path, made) => {
7204
+ if (!made || blind) return made;
7205
+ const { seen: at, ...st } = made;
7206
+ cache.put(cache.stats, path, st);
7207
+ if (at !== void 0) seen.saw(cache.stats, path, at);
7208
+ return made;
7209
+ };
7190
7210
  }
7191
7211
  });
7192
7212
 
@@ -8847,6 +8867,8 @@ var init_wasi_fds = __esm({
8847
8867
  return openDevice2.call(this.kernel.sys, flags);
8848
8868
  }
8849
8869
  open(path, oflags, rights, fdflags, mode) {
8870
+ this.made = void 0;
8871
+ this.created = false;
8850
8872
  const device2 = deviceOf(path);
8851
8873
  if (device2) return this.install({ type: "device", device: device2 });
8852
8874
  const kernelDevice = this.openKernelDevice(path, oflags, fdflags, rights);
@@ -8854,8 +8876,8 @@ var init_wasi_fds = __esm({
8854
8876
  const alias = stdioAlias(path);
8855
8877
  if (alias !== void 0) return this.reopen(alias);
8856
8878
  const exclusive = (oflags & OFLAGS.CREAT) !== 0 && (oflags & OFLAGS.EXCL) !== 0;
8857
- if (exclusive && this.shared && !(oflags & OFLAGS.DIRECTORY) && this.madeAtOnce(path, mode)) {
8858
- return this.kernelFile(path, void 0, oflags, rights, fdflags, mode, true);
8879
+ if (exclusive && !(oflags & OFLAGS.DIRECTORY) && this.madeAtOnce(path, mode)) {
8880
+ return this.regular(path, void 0, oflags, rights, fdflags, mode, true);
8859
8881
  }
8860
8882
  if (exclusive && this.isLink(path)) throw new WasiError("EEXIST");
8861
8883
  const s = this.statOrMissing(path);
@@ -8872,15 +8894,15 @@ var init_wasi_fds = __esm({
8872
8894
  refuseWrite(s, oflags, rights);
8873
8895
  return this.regular(path, s, oflags, rights, fdflags, mode);
8874
8896
  }
8875
- regular(path, s, oflags, rights, fdflags, mode) {
8897
+ regular(path, s, oflags, rights, fdflags, mode, created = false) {
8876
8898
  if (s?.isFifo) return this.kernelFifo(path, s, oflags, rights, fdflags);
8877
8899
  if (s?.isSocket) throw new WasiError("ENXIO");
8878
8900
  if (this.shared || this.kernelHolds(path, s)) {
8879
- return this.kernelFile(path, s, oflags, rights, fdflags, mode);
8901
+ return this.kernelFile(path, s, oflags, rights, fdflags, mode, created);
8880
8902
  }
8881
8903
  return this.install({
8882
8904
  type: "file",
8883
- file: this.file(path, s, oflags, rights, fdflags, mode)
8905
+ file: this.file(path, s, oflags, rights, fdflags, mode, created)
8884
8906
  });
8885
8907
  }
8886
8908
  kernelHolds(path, st) {
@@ -8903,9 +8925,9 @@ var init_wasi_fds = __esm({
8903
8925
  } catch {
8904
8926
  }
8905
8927
  }
8906
- file(path, existing, oflags, rights, fdflags, mode) {
8928
+ file(path, existing, oflags, rights, fdflags, mode, created = false) {
8907
8929
  const { readable: readable3, writable: writable2 } = openAccess(existing, oflags, rights);
8908
- let buffer = this.buffers.get(path);
8930
+ let buffer = created ? void 0 : this.buffers.get(path);
8909
8931
  if (buffer?.handle !== void 0 && this.fs.kept?.(buffer.handle)) {
8910
8932
  this.buffers.delete(path);
8911
8933
  buffer = void 0;
@@ -8916,19 +8938,21 @@ var init_wasi_fds = __esm({
8916
8938
  if (this.fs.owners) this.fs.access?.(path, want, "open");
8917
8939
  if (oflags & OFLAGS.TRUNC) buffer.truncate(0);
8918
8940
  } else {
8919
- buffer = this.freshBuffer(path, existing, oflags, want, mode);
8941
+ buffer = this.freshBuffer(path, existing, oflags, want, mode, created);
8920
8942
  }
8921
8943
  buffer.opens++;
8922
8944
  const file = new LocalFile(buffer, readable3, writable2, (fdflags & FDFLAGS.APPEND) !== 0);
8923
8945
  file.ino = existing?.ino;
8924
8946
  return file;
8925
8947
  }
8926
- freshBuffer(path, existing, oflags, want, mode) {
8927
- const made = !existing && this.createNew(path, oflags, mode);
8948
+ freshBuffer(path, existing, oflags, want, mode, created = false) {
8949
+ const made = created || !existing && this.createNew(path, oflags, mode);
8950
+ const reply = made ? this.made : void 0;
8951
+ this.made = void 0;
8928
8952
  const empty = made || (oflags & OFLAGS.TRUNC) !== 0;
8929
8953
  if (existing?.ranged) this.fs.invalidate?.();
8930
- const seen = this.fs.changes?.now();
8931
- const st = existing?.ranged || !existing ? this.fs.stat(path) : existing;
8954
+ const seen = reply ? reply.seen : this.fs.changes?.now();
8955
+ const st = reply?.st ?? (existing?.ranged || !existing ? this.fs.stat(path) : existing);
8932
8956
  const ranged = st.ranged ? st.size : void 0;
8933
8957
  const asked = (want & 4 ? HOLD_READ : 0) | (want & 2 ? HOLD_WRITE : 0) | (made ? HOLD_CREATED : 0);
8934
8958
  const handle = this.fs.hold?.(path, true, true, void 0, this.fs.owners ? asked : 0, {
@@ -8995,10 +9019,17 @@ var init_wasi_fds = __esm({
8995
9019
  }
8996
9020
  }
8997
9021
  }
9022
+ created = false;
9023
+ made;
9024
+ creating(path, mode) {
9025
+ const st = this.fs.create?.(path, mode, true);
9026
+ this.made = st ? { st, seen: st.seen } : void 0;
9027
+ this.created = true;
9028
+ }
8998
9029
  madeAtOnce(path, mode) {
8999
9030
  if (!this.fs.create) return false;
9000
9031
  try {
9001
- this.fs.create(path, mode, true);
9032
+ this.creating(path, mode);
9002
9033
  return true;
9003
9034
  } catch (err) {
9004
9035
  if (err.code === "EEXIST") throw err;
@@ -9008,10 +9039,11 @@ var init_wasi_fds = __esm({
9008
9039
  createNew(path, oflags, mode) {
9009
9040
  if (!this.fs.create) {
9010
9041
  this.fs.writeFile(path, new Uint8Array(0));
9042
+ this.created = true;
9011
9043
  return true;
9012
9044
  }
9013
9045
  try {
9014
- this.fs.create(path, mode, true);
9046
+ this.creating(path, mode);
9015
9047
  return true;
9016
9048
  } catch (err) {
9017
9049
  if (oflags & OFLAGS.EXCL || err.code !== "EEXIST") throw err;
@@ -10577,9 +10609,8 @@ var init_wasi_host = __esm({
10577
10609
  if (alias && !alias.stdio) this.openFd(alias.fd);
10578
10610
  const path = alias && !alias.stdio ? `/dev/fd/${alias.fd}` : asked;
10579
10611
  if (deviceOf(path)) this.interrupted?.();
10580
- const fresh = (oflags & OFLAGS.CREAT) !== 0 && !this.synthetic(path) && !o.fs.exists(path);
10581
10612
  mem.view().setUint32(out, fds.open(path, oflags, rights, fdflags), true);
10582
- if (fresh) this.created(path, 438);
10613
+ if (fds.created) this.created(path, 438);
10583
10614
  } catch (err) {
10584
10615
  if (err.code !== "ENOENT") throw err;
10585
10616
  const raw = mem.string(p, l);
@@ -11830,6 +11861,10 @@ function physicalProc(fs) {
11830
11861
  return physical2;
11831
11862
  };
11832
11863
  }
11864
+ function directMiss(err, path) {
11865
+ if (err?.direct !== true) return false;
11866
+ return !path.split("/").some((part) => part === "." || part === "..");
11867
+ }
11833
11868
  function procfsBridge(fs, tree) {
11834
11869
  const toProc = (path, follow3) => procPath(fs, path, follow3);
11835
11870
  const shadowing = physicalProc(fs);
@@ -11842,6 +11877,7 @@ function procfsBridge(fs, tree) {
11842
11877
  try {
11843
11878
  return own();
11844
11879
  } catch (err) {
11880
+ if (directMiss(err, p)) throw err;
11845
11881
  const real = toProc(p, follow3);
11846
11882
  if (real === void 0) throw err;
11847
11883
  return proc(real);
@@ -11902,7 +11938,12 @@ function procfsBridge(fs, tree) {
11902
11938
  const real = shadowing() ? probe() : void 0;
11903
11939
  if (real === null) return false;
11904
11940
  if (real !== void 0) return tree.exists(real);
11905
- if (fs.exists(p)) return true;
11941
+ try {
11942
+ fs.stat(p);
11943
+ return true;
11944
+ } catch (err) {
11945
+ if (directMiss(err, p)) return false;
11946
+ }
11906
11947
  const late2 = probe();
11907
11948
  return typeof late2 === "string" && tree.exists(late2);
11908
11949
  },
@@ -14311,7 +14352,7 @@ async function runWasiProcess(init, port2) {
14311
14352
  kernel: { sys: traced(stats, "kernel", sys), call: call2 },
14312
14353
  fs: procfsBridge(
14313
14354
  cachingBridge(
14314
- traced(stats, "fs", createSyncFsSabBridge(transport, ownersOf(init))),
14355
+ traced(stats, "fs", createSyncFsSabBridge(transport, { ...ownersOf(init), direct: true })),
14315
14356
  void 0,
14316
14357
  threads?.ids
14317
14358
  ),
@@ -14416,7 +14457,11 @@ async function runWasiThread(init, port2) {
14416
14457
  parent: () => identify(transport, init).ppid,
14417
14458
  kernel: { sys, call: call2 },
14418
14459
  fs: procfsBridge(
14419
- cachingBridge(createSyncFsSabBridge(transport, ownersOf(init)), void 0, threads.ids),
14460
+ cachingBridge(
14461
+ createSyncFsSabBridge(transport, { ...ownersOf(init), direct: true }),
14462
+ void 0,
14463
+ threads.ids
14464
+ ),
14420
14465
  procTree(call2, id.pid)
14421
14466
  ),
14422
14467
  shared: threads.ids
@@ -15453,7 +15498,8 @@ function controlsOf(r) {
15453
15498
  clientCertificate: r.clientCertificate === true,
15454
15499
  sni: r.sni !== false,
15455
15500
  hostnameChecked: r.hostnameChecked === true,
15456
- ...r.hostnameMatches === void 0 ? {} : { hostnameMatches: r.hostnameMatches }
15501
+ ...r.hostnameMatches === void 0 ? {} : { hostnameMatches: r.hostnameMatches },
15502
+ ...r.chainError ? { chainError: r.chainError } : {}
15457
15503
  };
15458
15504
  }
15459
15505
  function sessionOf(r) {
@@ -15479,13 +15525,17 @@ function sessionOf(r) {
15479
15525
  ...controlsOf(r)
15480
15526
  });
15481
15527
  }
15528
+ function withAlert(err) {
15529
+ const alert = ALERT.exec(err.detail ?? "")?.[1];
15530
+ return alert === void 0 ? err : Object.assign(err, { alert: Number(alert) });
15531
+ }
15482
15532
  async function secureCall(call2, what = "connect") {
15483
15533
  try {
15484
15534
  return await call2();
15485
15535
  } catch (err) {
15486
15536
  const e = err;
15487
15537
  const code2 = e.code === "EPROTO" && e.detail ? TLS_CODE.exec(e.detail)?.[1] : void 0;
15488
- if (code2) throw new JsCallError(code2, what, e.detail);
15538
+ if (code2) throw withAlert(new JsCallError(code2, what, e.detail));
15489
15539
  throw err;
15490
15540
  }
15491
15541
  }
@@ -15653,7 +15703,7 @@ function netOps(kernel, io) {
15653
15703
  }
15654
15704
  };
15655
15705
  }
15656
- var PEM, TLS_CODE, SHUT_RD, SHUT_WR, IPV4, NEVER, SOL_SOCKET2, SO_ERROR2;
15706
+ var PEM, TLS_CODE, ALERT, SHUT_RD, SHUT_WR, IPV4, NEVER, SOL_SOCKET2, SO_ERROR2;
15657
15707
  var init_js_net = __esm({
15658
15708
  "src/process/js/js-net.ts"() {
15659
15709
  "use strict";
@@ -15661,6 +15711,7 @@ var init_js_net = __esm({
15661
15711
  init_js_kernel();
15662
15712
  PEM = /-----BEGIN CERTIFICATE-----([\s\S]*?)-----END CERTIFICATE-----/g;
15663
15713
  TLS_CODE = /^([A-Z][A-Z0-9_]+): /;
15714
+ ALERT = / \(alert (\d+)\)$/;
15664
15715
  SHUT_RD = 0;
15665
15716
  SHUT_WR = 1;
15666
15717
  IPV4 = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;