@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.
@@ -747,6 +747,17 @@ function index(map, key, path) {
747
747
  paths.add(path);
748
748
  map.set(key, paths);
749
749
  }
750
+ function goneAbove(maps, live, path) {
751
+ for (let at = path.lastIndexOf("/"); at > 0; at = path.lastIndexOf("/", at - 1)) {
752
+ const up = path.slice(0, at);
753
+ for (const map of maps) {
754
+ const hit = map.get(up);
755
+ const code2 = hit && "until" in hit ? hit.error.code : void 0;
756
+ if (hit && "until" in hit && code2 === "ENOENT" && live(hit, up)) return hit;
757
+ }
758
+ }
759
+ return void 0;
760
+ }
750
761
  function cachingBridge(bridge, now = () => performance.now(), shared) {
751
762
  const blind = shared !== void 0 && shared.length * 4 < SHARED_IDS_BYTES;
752
763
  const cache = new StatCache(blind ? void 0 : shared);
@@ -754,17 +765,8 @@ function cachingBridge(bridge, now = () => performance.now(), shared) {
754
765
  const view = bridge.changes;
755
766
  const live = (miss, path) => miss.until > now() && (view === void 0 || miss.gen === void 0 || !view.changedSince(miss.gen, path).changed);
756
767
  const seen = new SeenAt(view, lstats);
757
- const gone = (path) => {
758
- for (let at = path.lastIndexOf("/"); at > 0; at = path.lastIndexOf("/", at - 1)) {
759
- const up = path.slice(0, at);
760
- for (const map of [lstats, stats]) {
761
- const hit = map.get(up);
762
- const code2 = hit && "until" in hit ? hit.error.code : void 0;
763
- if (hit && "until" in hit && code2 === "ENOENT" && live(hit, up)) return hit;
764
- }
765
- }
766
- return void 0;
767
- };
768
+ const kept = remember(cache, seen, blind);
769
+ const gone = (path) => goneAbove([lstats, stats], live, path);
768
770
  const cached = (map, path, get) => {
769
771
  if (blind || view?.foreign()) return get();
770
772
  cache.fresh();
@@ -890,7 +892,10 @@ function cachingBridge(bridge, now = () => performance.now(), shared) {
890
892
  ...bridge.keptStat ? { keptStat: bridge.keptStat.bind(bridge) } : {},
891
893
  ...bridge.pinned ? { pinned: (handle) => pinnedIo(bridge, handle, rewriting) } : {},
892
894
  ...bridge.create ? {
893
- create: (p, mode, opening2) => mutating(() => bridge.create?.(p, mode, opening2), ...entry(p))
895
+ create: (p, mode, opening2) => kept(
896
+ p,
897
+ mutating(() => bridge.create?.(p, mode, opening2), ...entry(p))
898
+ )
894
899
  } : {},
895
900
  ...bridge.mkfifo ? {
896
901
  mkfifo: (p, mode) => mutating(() => bridge.mkfifo?.(p, mode), ...entry(p))
@@ -927,7 +932,7 @@ function pinnedIo(bridge, handle, rewriting) {
927
932
  } : {}
928
933
  };
929
934
  }
930
- var WasiError, FileBuffer, LocalFile, MAX_LINKS, MISS_TTL_MS, CACHE_CAP, FS_GEN, CRED_GEN, RING, RING_SIZE, SLOT, FD_RING, FD_RING_SIZE, SHARED_IDS_BYTES, StatCache, SEEN_CAP, SeenAt;
935
+ var WasiError, FileBuffer, LocalFile, MAX_LINKS, MISS_TTL_MS, CACHE_CAP, FS_GEN, CRED_GEN, RING, RING_SIZE, SLOT, FD_RING, FD_RING_SIZE, SHARED_IDS_BYTES, StatCache, SEEN_CAP, SeenAt, remember;
931
936
  var init_wasi_files = __esm({
932
937
  "src/process/wasi/wasi-files.ts"() {
933
938
  "use strict";
@@ -1317,6 +1322,13 @@ var init_wasi_files = __esm({
1317
1322
  return since.changed;
1318
1323
  }
1319
1324
  };
1325
+ remember = (cache, seen, blind) => (path, made) => {
1326
+ if (!made || blind) return made;
1327
+ const { seen: at, ...st } = made;
1328
+ cache.put(cache.stats, path, st);
1329
+ if (at !== void 0) seen.saw(cache.stats, path, at);
1330
+ return made;
1331
+ };
1320
1332
  }
1321
1333
  });
1322
1334
 
@@ -1369,7 +1381,8 @@ function decodeSabResult(status2, payload) {
1369
1381
  try {
1370
1382
  const parsed = JSON.parse(decoder.decode(payload));
1371
1383
  const errno2 = typeof parsed.errno === "string" && /^E[A-Z]+$|^EAI_[A-Z]+$/.test(parsed.errno) ? parsed.errno : "EIO";
1372
- return { ok: false, errno: errno2, message: String(parsed.message ?? errno2) };
1384
+ const message2 = String(parsed.message ?? errno2);
1385
+ return parsed.direct === true ? { ok: false, errno: errno2, message: message2, direct: true } : { ok: false, errno: errno2, message: message2 };
1373
1386
  } catch {
1374
1387
  return { ok: false, errno: "EIO", message: "sync-sab: malformed errno payload" };
1375
1388
  }
@@ -3431,6 +3444,8 @@ var init_wasi_fds = __esm({
3431
3444
  return openDevice2.call(this.kernel.sys, flags);
3432
3445
  }
3433
3446
  open(path, oflags, rights, fdflags, mode) {
3447
+ this.made = void 0;
3448
+ this.created = false;
3434
3449
  const device2 = deviceOf(path);
3435
3450
  if (device2) return this.install({ type: "device", device: device2 });
3436
3451
  const kernelDevice = this.openKernelDevice(path, oflags, fdflags, rights);
@@ -3438,8 +3453,8 @@ var init_wasi_fds = __esm({
3438
3453
  const alias = stdioAlias(path);
3439
3454
  if (alias !== void 0) return this.reopen(alias);
3440
3455
  const exclusive = (oflags & OFLAGS.CREAT) !== 0 && (oflags & OFLAGS.EXCL) !== 0;
3441
- if (exclusive && this.shared && !(oflags & OFLAGS.DIRECTORY) && this.madeAtOnce(path, mode)) {
3442
- return this.kernelFile(path, void 0, oflags, rights, fdflags, mode, true);
3456
+ if (exclusive && !(oflags & OFLAGS.DIRECTORY) && this.madeAtOnce(path, mode)) {
3457
+ return this.regular(path, void 0, oflags, rights, fdflags, mode, true);
3443
3458
  }
3444
3459
  if (exclusive && this.isLink(path)) throw new WasiError("EEXIST");
3445
3460
  const s = this.statOrMissing(path);
@@ -3456,15 +3471,15 @@ var init_wasi_fds = __esm({
3456
3471
  refuseWrite(s, oflags, rights);
3457
3472
  return this.regular(path, s, oflags, rights, fdflags, mode);
3458
3473
  }
3459
- regular(path, s, oflags, rights, fdflags, mode) {
3474
+ regular(path, s, oflags, rights, fdflags, mode, created = false) {
3460
3475
  if (s?.isFifo) return this.kernelFifo(path, s, oflags, rights, fdflags);
3461
3476
  if (s?.isSocket) throw new WasiError("ENXIO");
3462
3477
  if (this.shared || this.kernelHolds(path, s)) {
3463
- return this.kernelFile(path, s, oflags, rights, fdflags, mode);
3478
+ return this.kernelFile(path, s, oflags, rights, fdflags, mode, created);
3464
3479
  }
3465
3480
  return this.install({
3466
3481
  type: "file",
3467
- file: this.file(path, s, oflags, rights, fdflags, mode)
3482
+ file: this.file(path, s, oflags, rights, fdflags, mode, created)
3468
3483
  });
3469
3484
  }
3470
3485
  kernelHolds(path, st) {
@@ -3487,9 +3502,9 @@ var init_wasi_fds = __esm({
3487
3502
  } catch {
3488
3503
  }
3489
3504
  }
3490
- file(path, existing, oflags, rights, fdflags, mode) {
3505
+ file(path, existing, oflags, rights, fdflags, mode, created = false) {
3491
3506
  const { readable: readable3, writable: writable2 } = openAccess(existing, oflags, rights);
3492
- let buffer = this.buffers.get(path);
3507
+ let buffer = created ? void 0 : this.buffers.get(path);
3493
3508
  if (buffer?.handle !== void 0 && this.fs.kept?.(buffer.handle)) {
3494
3509
  this.buffers.delete(path);
3495
3510
  buffer = void 0;
@@ -3500,19 +3515,21 @@ var init_wasi_fds = __esm({
3500
3515
  if (this.fs.owners) this.fs.access?.(path, want, "open");
3501
3516
  if (oflags & OFLAGS.TRUNC) buffer.truncate(0);
3502
3517
  } else {
3503
- buffer = this.freshBuffer(path, existing, oflags, want, mode);
3518
+ buffer = this.freshBuffer(path, existing, oflags, want, mode, created);
3504
3519
  }
3505
3520
  buffer.opens++;
3506
3521
  const file = new LocalFile(buffer, readable3, writable2, (fdflags & FDFLAGS.APPEND) !== 0);
3507
3522
  file.ino = existing?.ino;
3508
3523
  return file;
3509
3524
  }
3510
- freshBuffer(path, existing, oflags, want, mode) {
3511
- const made = !existing && this.createNew(path, oflags, mode);
3525
+ freshBuffer(path, existing, oflags, want, mode, created = false) {
3526
+ const made = created || !existing && this.createNew(path, oflags, mode);
3527
+ const reply = made ? this.made : void 0;
3528
+ this.made = void 0;
3512
3529
  const empty = made || (oflags & OFLAGS.TRUNC) !== 0;
3513
3530
  if (existing?.ranged) this.fs.invalidate?.();
3514
- const seen = this.fs.changes?.now();
3515
- const st = existing?.ranged || !existing ? this.fs.stat(path) : existing;
3531
+ const seen = reply ? reply.seen : this.fs.changes?.now();
3532
+ const st = reply?.st ?? (existing?.ranged || !existing ? this.fs.stat(path) : existing);
3516
3533
  const ranged = st.ranged ? st.size : void 0;
3517
3534
  const asked = (want & 4 ? HOLD_READ : 0) | (want & 2 ? HOLD_WRITE : 0) | (made ? HOLD_CREATED : 0);
3518
3535
  const handle = this.fs.hold?.(path, true, true, void 0, this.fs.owners ? asked : 0, {
@@ -3579,10 +3596,17 @@ var init_wasi_fds = __esm({
3579
3596
  }
3580
3597
  }
3581
3598
  }
3599
+ created = false;
3600
+ made;
3601
+ creating(path, mode) {
3602
+ const st = this.fs.create?.(path, mode, true);
3603
+ this.made = st ? { st, seen: st.seen } : void 0;
3604
+ this.created = true;
3605
+ }
3582
3606
  madeAtOnce(path, mode) {
3583
3607
  if (!this.fs.create) return false;
3584
3608
  try {
3585
- this.fs.create(path, mode, true);
3609
+ this.creating(path, mode);
3586
3610
  return true;
3587
3611
  } catch (err) {
3588
3612
  if (err.code === "EEXIST") throw err;
@@ -3592,10 +3616,11 @@ var init_wasi_fds = __esm({
3592
3616
  createNew(path, oflags, mode) {
3593
3617
  if (!this.fs.create) {
3594
3618
  this.fs.writeFile(path, new Uint8Array(0));
3619
+ this.created = true;
3595
3620
  return true;
3596
3621
  }
3597
3622
  try {
3598
- this.fs.create(path, mode, true);
3623
+ this.creating(path, mode);
3599
3624
  return true;
3600
3625
  } catch (err) {
3601
3626
  if (oflags & OFLAGS.EXCL || err.code !== "EEXIST") throw err;
@@ -5207,9 +5232,8 @@ var init_wasi_host = __esm({
5207
5232
  if (alias && !alias.stdio) this.openFd(alias.fd);
5208
5233
  const path = alias && !alias.stdio ? `/dev/fd/${alias.fd}` : asked;
5209
5234
  if (deviceOf(path)) this.interrupted?.();
5210
- const fresh = (oflags & OFLAGS.CREAT) !== 0 && !this.synthetic(path) && !o.fs.exists(path);
5211
5235
  mem.view().setUint32(out, fds.open(path, oflags, rights, fdflags), true);
5212
- if (fresh) this.created(path, 438);
5236
+ if (fds.created) this.created(path, 438);
5213
5237
  } catch (err) {
5214
5238
  if (err.code !== "ENOENT") throw err;
5215
5239
  const raw = mem.string(p, l);
@@ -6271,7 +6295,7 @@ var KERNEL_VERSION, OS_RELEASE;
6271
6295
  var init_version = __esm({
6272
6296
  "src/version.ts"() {
6273
6297
  "use strict";
6274
- KERNEL_VERSION = true ? "1.125.1" : "0.0.0-dev";
6298
+ KERNEL_VERSION = true ? "1.125.2" : "0.0.0-dev";
6275
6299
  OS_RELEASE = "6.0.0-slicc";
6276
6300
  }
6277
6301
  });
@@ -7115,7 +7139,8 @@ function controlsOf(r) {
7115
7139
  clientCertificate: r.clientCertificate === true,
7116
7140
  sni: r.sni !== false,
7117
7141
  hostnameChecked: r.hostnameChecked === true,
7118
- ...r.hostnameMatches === void 0 ? {} : { hostnameMatches: r.hostnameMatches }
7142
+ ...r.hostnameMatches === void 0 ? {} : { hostnameMatches: r.hostnameMatches },
7143
+ ...r.chainError ? { chainError: r.chainError } : {}
7119
7144
  };
7120
7145
  }
7121
7146
  function sessionOf(r) {
@@ -7141,13 +7166,17 @@ function sessionOf(r) {
7141
7166
  ...controlsOf(r)
7142
7167
  });
7143
7168
  }
7169
+ function withAlert(err) {
7170
+ const alert = ALERT.exec(err.detail ?? "")?.[1];
7171
+ return alert === void 0 ? err : Object.assign(err, { alert: Number(alert) });
7172
+ }
7144
7173
  async function secureCall(call2, what = "connect") {
7145
7174
  try {
7146
7175
  return await call2();
7147
7176
  } catch (err) {
7148
7177
  const e = err;
7149
7178
  const code2 = e.code === "EPROTO" && e.detail ? TLS_CODE.exec(e.detail)?.[1] : void 0;
7150
- if (code2) throw new JsCallError(code2, what, e.detail);
7179
+ if (code2) throw withAlert(new JsCallError(code2, what, e.detail));
7151
7180
  throw err;
7152
7181
  }
7153
7182
  }
@@ -7315,7 +7344,7 @@ function netOps(kernel, io) {
7315
7344
  }
7316
7345
  };
7317
7346
  }
7318
- var PEM, TLS_CODE, SHUT_RD, SHUT_WR, IPV4, NEVER, SOL_SOCKET2, SO_ERROR2;
7347
+ var PEM, TLS_CODE, ALERT, SHUT_RD, SHUT_WR, IPV4, NEVER, SOL_SOCKET2, SO_ERROR2;
7319
7348
  var init_js_net = __esm({
7320
7349
  "src/process/js/js-net.ts"() {
7321
7350
  "use strict";
@@ -7323,6 +7352,7 @@ var init_js_net = __esm({
7323
7352
  init_js_kernel();
7324
7353
  PEM = /-----BEGIN CERTIFICATE-----([\s\S]*?)-----END CERTIFICATE-----/g;
7325
7354
  TLS_CODE = /^([A-Z][A-Z0-9_]+): /;
7355
+ ALERT = / \(alert (\d+)\)$/;
7326
7356
  SHUT_RD = 0;
7327
7357
  SHUT_WR = 1;
7328
7358
  IPV4 = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
@@ -7541,10 +7571,12 @@ function createSyncSabTransport(sab, port3, deps = {}) {
7541
7571
  }
7542
7572
  };
7543
7573
  }
7544
- function errnoError(code2, path) {
7545
- return syncError(code2, `sync-sab bridge, '${path}'`);
7574
+ function errnoError(code2, path, direct) {
7575
+ const err = syncError(code2, `sync-sab bridge, '${path}'`);
7576
+ return direct ? Object.assign(err, { direct }) : err;
7546
7577
  }
7547
7578
  function createSyncFsSabBridge(transport, opts = {}) {
7579
+ const direct = opts.direct ? { direct: true } : {};
7548
7580
  const timeoutMs2 = opts.timeoutMs ?? SYNC_FS_REQUEST_TIMEOUT_MS;
7549
7581
  let identity = {};
7550
7582
  let once = false;
@@ -7553,7 +7585,7 @@ function createSyncFsSabBridge(transport, opts = {}) {
7553
7585
  last = null;
7554
7586
  const silence = SYNC_FS_READ_ONLY.has(req.op) ? timeoutMs2 : Number.POSITIVE_INFINITY;
7555
7587
  const result = transport.call(req, silence, `sync-sab bridge, '${path}'`, transfer);
7556
- if (!result.ok) throw errnoError(result.errno, path);
7588
+ if (!result.ok) throw errnoError(result.errno, path, result.direct);
7557
7589
  return result;
7558
7590
  }
7559
7591
  function bytes(req, path) {
@@ -7599,12 +7631,12 @@ function createSyncFsSabBridge(transport, opts = {}) {
7599
7631
  return s;
7600
7632
  },
7601
7633
  stat: (path) => {
7602
- const s = parseSyncFsStat(json2({ op: "stat", path }, path));
7634
+ const s = parseSyncFsStat(json2({ op: "stat", path, ...direct }, path));
7603
7635
  if (!s) throw errnoError("EIO", path);
7604
7636
  return s;
7605
7637
  },
7606
7638
  lstat: (path) => {
7607
- const s = parseSyncFsStat(json2({ op: "lstat", path }, path));
7639
+ const s = parseSyncFsStat(json2({ op: "lstat", path, ...direct }, path));
7608
7640
  if (!s) throw errnoError("EIO", path);
7609
7641
  return s;
7610
7642
  },
@@ -7682,7 +7714,12 @@ function createSyncFsSabBridge(transport, opts = {}) {
7682
7714
  },
7683
7715
  create: (path, mode, opening2) => {
7684
7716
  const flags = { ...mode !== void 0 ? { mode } : {}, ...opening2 ? { opening: opening2 } : {} };
7685
- run({ op: "create", path, ...flags }, path);
7717
+ const r = run({ op: "create", path, ...flags, identity: true }, path);
7718
+ if (!r.ok || r.kind !== "json") return void 0;
7719
+ const st = parseSyncFsStat(r.json);
7720
+ if (!st) return void 0;
7721
+ const { seen } = r.json;
7722
+ return typeof seen === "number" ? { ...st, seen } : st;
7686
7723
  },
7687
7724
  chown: (path, uid, gid, follow3, handle) => {
7688
7725
  const ids = { ...uid !== void 0 ? { uid } : {}, ...gid !== void 0 ? { gid } : {} };
@@ -10299,15 +10336,15 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
10299
10336
  };
10300
10337
  const track = (stream, names) => {
10301
10338
  let current = names;
10302
- const remember = (list) => scans.set(stream, new Set(list.filter((n) => /^[1-9]\d*$/.test(n)).map(Number)));
10303
- remember(current ?? []);
10339
+ const remember2 = (list) => scans.set(stream, new Set(list.filter((n) => /^[1-9]\d*$/.test(n)).map(Number)));
10340
+ remember2(current ?? []);
10304
10341
  Object.defineProperty(stream, "getdents", {
10305
10342
  configurable: true,
10306
10343
  enumerable: true,
10307
10344
  get: () => current,
10308
10345
  set: (next2) => {
10309
10346
  current = next2;
10310
- if (next2) remember(next2);
10347
+ if (next2) remember2(next2);
10311
10348
  }
10312
10349
  });
10313
10350
  };
@@ -10492,6 +10529,10 @@ function physicalProc(fs) {
10492
10529
  return physical2;
10493
10530
  };
10494
10531
  }
10532
+ function directMiss(err, path) {
10533
+ if (err?.direct !== true) return false;
10534
+ return !path.split("/").some((part) => part === "." || part === "..");
10535
+ }
10495
10536
  function procfsBridge(fs, tree) {
10496
10537
  const toProc = (path, follow3) => procPath(fs, path, follow3);
10497
10538
  const shadowing = physicalProc(fs);
@@ -10504,6 +10545,7 @@ function procfsBridge(fs, tree) {
10504
10545
  try {
10505
10546
  return own();
10506
10547
  } catch (err) {
10548
+ if (directMiss(err, p)) throw err;
10507
10549
  const real = toProc(p, follow3);
10508
10550
  if (real === void 0) throw err;
10509
10551
  return proc(real);
@@ -10564,7 +10606,12 @@ function procfsBridge(fs, tree) {
10564
10606
  const real = shadowing() ? probe() : void 0;
10565
10607
  if (real === null) return false;
10566
10608
  if (real !== void 0) return tree.exists(real);
10567
- if (fs.exists(p)) return true;
10609
+ try {
10610
+ fs.stat(p);
10611
+ return true;
10612
+ } catch (err) {
10613
+ if (directMiss(err, p)) return false;
10614
+ }
10568
10615
  const late2 = probe();
10569
10616
  return typeof late2 === "string" && tree.exists(late2);
10570
10617
  },
@@ -16923,7 +16970,7 @@ async function runWasiProcess(init, port3) {
16923
16970
  kernel: { sys: traced(stats, "kernel", sys), call: call2 },
16924
16971
  fs: procfsBridge(
16925
16972
  cachingBridge(
16926
- traced(stats, "fs", createSyncFsSabBridge(transport, ownersOf(init))),
16973
+ traced(stats, "fs", createSyncFsSabBridge(transport, { ...ownersOf(init), direct: true })),
16927
16974
  void 0,
16928
16975
  threads?.ids
16929
16976
  ),
@@ -17028,7 +17075,11 @@ async function runWasiThread(init, port3) {
17028
17075
  parent: () => identify(transport, init).ppid,
17029
17076
  kernel: { sys, call: call2 },
17030
17077
  fs: procfsBridge(
17031
- cachingBridge(createSyncFsSabBridge(transport, ownersOf(init)), void 0, threads.ids),
17078
+ cachingBridge(
17079
+ createSyncFsSabBridge(transport, { ...ownersOf(init), direct: true }),
17080
+ void 0,
17081
+ threads.ids
17082
+ ),
17032
17083
  procTree(call2, id.pid)
17033
17084
  ),
17034
17085
  shared: threads.ids