@ai-ecoverse/slicc-kernel 1.110.7 → 1.111.0

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.
@@ -3188,6 +3188,7 @@ function decodeReceived(raw) {
3188
3188
  const length = view.getUint8(3);
3189
3189
  return {
3190
3190
  truncated: (view.getUint8(0) & 1) !== 0,
3191
+ unix: (view.getUint8(0) & 2) !== 0,
3191
3192
  port: view.getUint16(1),
3192
3193
  host: new TextDecoder().decode(raw.subarray(4, 4 + length)),
3193
3194
  bytes: raw.subarray(4 + length)
@@ -3370,7 +3371,7 @@ function ipv4(host) {
3370
3371
  }
3371
3372
  function openRequest(af, type) {
3372
3373
  if (af !== INET4 && af !== INET6 && af !== UNIX) throw new WasiError("EAFNOSUPPORT");
3373
- if (type !== STREAM && (type !== DGRAM || af === UNIX)) throw new WasiError("EPROTONOSUPPORT");
3374
+ if (type !== STREAM && type !== DGRAM) throw new WasiError("EPROTONOSUPPORT");
3374
3375
  const domain = af === UNIX ? "unix" : "inet";
3375
3376
  return {
3376
3377
  op: "sock-open",
@@ -3378,6 +3379,16 @@ function openRequest(af, type) {
3378
3379
  ...type === DGRAM ? { type: "dgram" } : {}
3379
3380
  };
3380
3381
  }
3382
+ function pairRequest(af, type) {
3383
+ if (af !== UNIX)
3384
+ throw new WasiError(af === INET4 || af === INET6 ? "EOPNOTSUPP" : "EAFNOSUPPORT");
3385
+ if (type !== STREAM && type !== DGRAM) throw new WasiError("EPROTONOSUPPORT");
3386
+ return {
3387
+ op: "sock-pair",
3388
+ domain: "unix",
3389
+ ...type === DGRAM ? { type: "dgram" } : {}
3390
+ };
3391
+ }
3381
3392
  function absolute(cwd, addr) {
3382
3393
  if (addr.family !== "unix" || addr.path === "" || addr.path.startsWith("\0")) return addr;
3383
3394
  return addr.path.startsWith("/") ? addr : { family: "unix", path: `${cwd}/${addr.path}` };
@@ -3398,12 +3409,13 @@ function datagramCalls(host) {
3398
3409
  const view = mem.view();
3399
3410
  view.setUint32(outLen, mem.scatter(iovs, n, got.bytes), true);
3400
3411
  view.setUint16(outFlags, got.truncated ? RECV_DATA_TRUNCATED : 0, true);
3401
- if (outAddr)
3402
- writeAddr(mem.view(), outAddr, { family: "inet", host: got.host, port: got.port });
3412
+ const from = got.unix ? { family: "unix", path: got.host } : { family: "inet", host: got.host, port: got.port };
3413
+ if (outAddr) writeAddr(mem.view(), outAddr, from);
3403
3414
  return E.SUCCESS;
3404
3415
  },
3405
3416
  sendTo(fd, nonblock, iovs, n, addr, out) {
3406
- const to = optionalAddr(mem.view(), addr);
3417
+ const named = optionalAddr(mem.view(), addr);
3418
+ const to = named && absolute(host.cwd, named);
3407
3419
  const body = mem.gather(iovs, n);
3408
3420
  const sent = call2({ op: "sock-sendto", fd, body, ...to ? { addr: to } : {}, nonblock });
3409
3421
  mem.view().setUint32(out, sent, true);
@@ -3437,14 +3449,12 @@ function wasixSocketImports(host, preview1) {
3437
3449
  mem.view().setUint32(out, fd, true);
3438
3450
  },
3439
3451
  sock_pair: (af, type, _proto, out1, out2) => {
3440
- if (af !== UNIX)
3441
- throw new WasiError(af === INET4 || af === INET6 ? "EOPNOTSUPP" : "EAFNOSUPPORT");
3442
- if (type !== STREAM) throw new WasiError("EPROTONOSUPPORT");
3452
+ const req = pairRequest(af, type);
3443
3453
  mem.view().setUint32(out1, 0, true);
3444
3454
  mem.view().setUint32(out2, 0, true);
3445
- const [a, b] = call2({ op: "sock-pair", domain: "unix" });
3446
- fds.adopt(a, "socket", false);
3447
- fds.adopt(b, "socket", false);
3455
+ const [a, b] = call2(req);
3456
+ fds.adopt(a, "socket", false, "type" in req);
3457
+ fds.adopt(b, "socket", false, "type" in req);
3448
3458
  mem.view().setUint32(out1, a, true);
3449
3459
  mem.view().setUint32(out2, b, true);
3450
3460
  },
@@ -3664,7 +3674,7 @@ function wrap(table) {
3664
3674
  }
3665
3675
  return out;
3666
3676
  }
3667
- var WasiExit, IDS, NS_PER_MS4, AT_SYMLINK_NOFOLLOW, AT_EACCESS, ROOT_IDS, GONE, S_IFIFO, DEFAULT_UMASK, MONOTONIC_BASE, MAX_READ, SIGPIPE_EXIT, SIG_IGN, SEALED_MODE, WasiHost;
3677
+ var WasiExit, IDS, NS_PER_MS4, AT_SYMLINK_NOFOLLOW, AT_EACCESS, ROOT_IDS, GONE, S_IFIFO, S_IFLNK, DEFAULT_UMASK, MONOTONIC_BASE, MAX_READ, FD_ALIAS, STDIO_FDS, SIGPIPE_EXIT, SIG_IGN, SEALED_MODE, WasiHost;
3668
3678
  var init_wasi_host = __esm({
3669
3679
  "src/process/wasi/wasi-host.ts"() {
3670
3680
  "use strict";
@@ -3699,9 +3709,12 @@ var init_wasi_host = __esm({
3699
3709
  ROOT_IDS = Object.freeze({ uid: 0, gid: 0 });
3700
3710
  GONE = /* @__PURE__ */ new Set(["ENOENT", "ENOTDIR"]);
3701
3711
  S_IFIFO = 4096;
3712
+ S_IFLNK = 40960;
3702
3713
  DEFAULT_UMASK = 18;
3703
3714
  MONOTONIC_BASE = BigInt(Math.round(performance.timeOrigin)) * NS_PER_MS4;
3704
3715
  MAX_READ = 1024 * 1024;
3716
+ FD_ALIAS = /^\/(?:dev\/(stdin|stdout|stderr)|dev\/fd\/(\d+)|proc\/(self|[1-9]\d*)\/fd\/(\d+))$/;
3717
+ STDIO_FDS = { stdin: 0, stdout: 1, stderr: 2 };
3705
3718
  SIGPIPE_EXIT = 128 + SIG.PIPE;
3706
3719
  SIG_IGN = 1;
3707
3720
  SEALED_MODE = 8630;
@@ -3814,7 +3827,20 @@ var init_wasi_host = __esm({
3814
3827
  return void 0;
3815
3828
  }
3816
3829
  };
3830
+ const fdMode = (fd) => {
3831
+ const e = fds.get(fd);
3832
+ const kind = e.type === "kernel" ? fds.kind(fd, e) : void 0;
3833
+ if (kind === "stream") return S_IFIFO | 384;
3834
+ if (kind === "sealed" || kind === "clipboard") return SEALED_MODE;
3835
+ return modeOf2(this.o.fs.stat(pathOf(fd)));
3836
+ };
3817
3837
  const pathOwned = (path, follow2) => {
3838
+ const alias = this.fdAlias(path);
3839
+ if (alias && !follow2) return alias.stdio ? ROOT_IDS : void 0;
3840
+ if (alias) {
3841
+ this.openFd(alias.fd);
3842
+ return fdOwned(alias.fd);
3843
+ }
3818
3844
  if (this.synthetic(path)) return ROOT_IDS;
3819
3845
  return follow2 ? this.o.fs.stat(path) : this.o.fs.lstat(path);
3820
3846
  };
@@ -3864,14 +3890,18 @@ var init_wasi_host = __esm({
3864
3890
  const old = this.o.kernel.call({ op: "proc-umask", mask });
3865
3891
  mem.view().setUint32(out, old, true);
3866
3892
  },
3867
- fd_mode: (fd, out) => {
3868
- const e = fds.get(fd);
3869
- const kind = e.type === "kernel" ? fds.kind(fd, e) : void 0;
3870
- const mode = kind === "stream" ? S_IFIFO | 384 : kind === "sealed" || kind === "clipboard" ? SEALED_MODE : modeOf2(this.o.fs.stat(pathOf(fd)));
3871
- mem.view().setUint32(out, mode, true);
3872
- },
3893
+ fd_mode: (fd, out) => void mem.view().setUint32(out, fdMode(fd), true),
3873
3894
  path_mode: (dirfd, p, l, flags, out) => {
3874
3895
  const path = at(dirfd, p, l);
3896
+ const alias = this.fdAlias(path);
3897
+ if (alias && flags & AT_SYMLINK_NOFOLLOW) {
3898
+ this.fdTarget(alias);
3899
+ return void mem.view().setUint32(out, S_IFLNK | 511, true);
3900
+ }
3901
+ if (alias) {
3902
+ this.openFd(alias.fd);
3903
+ return void mem.view().setUint32(out, fdMode(alias.fd), true);
3904
+ }
3875
3905
  if (this.synthetic(path) && deviceOf(path) === void 0)
3876
3906
  return void mem.view().setUint32(out, SEALED_MODE, true);
3877
3907
  const st = flags & AT_SYMLINK_NOFOLLOW ? this.o.fs.lstat(path) : this.o.fs.stat(path);
@@ -4166,7 +4196,10 @@ var init_wasi_host = __esm({
4166
4196
  path_open: (dirfd, lookup2, p, l, oflags, rights, _inheriting, fdflags, out) => {
4167
4197
  const follow2 = (lookup2 & LOOKUP_SYMLINK_FOLLOW) !== 0;
4168
4198
  try {
4169
- const path = at(dirfd, p, l);
4199
+ const asked = at(dirfd, p, l);
4200
+ const alias = this.fdAlias(asked);
4201
+ if (alias && !alias.stdio) this.openFd(alias.fd);
4202
+ const path = alias && !alias.stdio ? `/dev/fd/${alias.fd}` : asked;
4170
4203
  if (deviceOf(path)) this.interrupted?.();
4171
4204
  const fresh = (oflags & OFLAGS.CREAT) !== 0 && !this.synthetic(path) && !o.fs.exists(path);
4172
4205
  mem.view().setUint32(out, fds.open(path, oflags, rights, fdflags), true);
@@ -4228,7 +4261,9 @@ var init_wasi_host = __esm({
4228
4261
  o.fs.symlink(mem.string(tp, tl), path);
4229
4262
  },
4230
4263
  path_readlink: (dirfd, p, l, buf, len, used) => {
4231
- const target = new TextEncoder().encode(o.fs.readlink(at(dirfd, p, l)));
4264
+ const path = at(dirfd, p, l);
4265
+ const alias = this.fdAlias(path);
4266
+ const target = new TextEncoder().encode(alias ? this.fdTarget(alias) : o.fs.readlink(path));
4232
4267
  const n = Math.min(len, target.length);
4233
4268
  mem.bytes(buf, n).set(target.subarray(0, n));
4234
4269
  mem.view().setUint32(used, n, true);
@@ -4567,7 +4602,55 @@ var init_wasi_host = __esm({
4567
4602
  return void 0;
4568
4603
  }
4569
4604
  }
4605
+ fdAlias(path) {
4606
+ const m = FD_ALIAS.exec(path);
4607
+ if (!m) return void 0;
4608
+ if (m[1]) return { fd: STDIO_FDS[m[1]], stdio: true };
4609
+ if (m[3] !== void 0 && m[3] !== "self" && Number(m[3]) !== this.o.pid) return void 0;
4610
+ return { fd: Number(m[2] ?? m[4]), stdio: false };
4611
+ }
4612
+ openFd(fd) {
4613
+ try {
4614
+ this.fds.get(fd);
4615
+ } catch {
4616
+ throw new WasiError("ENOENT");
4617
+ }
4618
+ }
4619
+ fdTarget(alias) {
4620
+ if (alias.stdio) return `/proc/self/fd/${alias.fd}`;
4621
+ this.openFd(alias.fd);
4622
+ const e = this.fds.get(alias.fd);
4623
+ if (e.type === "file") return e.file.path;
4624
+ if (e.type === "dir") return e.path;
4625
+ if (e.type === "device") return `/dev/${e.device}`;
4626
+ const kind = e.type === "kernel" ? this.fds.kind(alias.fd, e) : void 0;
4627
+ if (kind === "file") {
4628
+ const vfs = this.kernelStat(alias.fd);
4629
+ if (vfs.path) return vfs.path;
4630
+ }
4631
+ if (kind === "tty") return "/dev/tty";
4632
+ if (kind === "device") return "/dev/null";
4633
+ const ino = this.fdFilestat(alias.fd).ino;
4634
+ if (kind === "stream") return `pipe:[${ino}]`;
4635
+ if (kind === "socket") return `socket:[${ino}]`;
4636
+ return `anon_inode:[${kind ?? "fd"}]`;
4637
+ }
4638
+ aliasFilestat(path, alias, lookup2) {
4639
+ if ((lookup2 & LOOKUP_SYMLINK_FOLLOW) === 0) {
4640
+ const target = this.fdTarget(alias);
4641
+ return this.local({
4642
+ filetype: FILETYPE.SYMBOLIC_LINK,
4643
+ size: BigInt(new TextEncoder().encode(target).length),
4644
+ ino: pathInode(path),
4645
+ mtimeNs: 0n
4646
+ });
4647
+ }
4648
+ this.openFd(alias.fd);
4649
+ return this.fdFilestat(alias.fd);
4650
+ }
4570
4651
  pathFilestat(path, lookup2) {
4652
+ const alias = this.fdAlias(path);
4653
+ if (alias) return this.aliasFilestat(path, alias, lookup2);
4571
4654
  if (this.synthetic(path)) {
4572
4655
  return this.local({
4573
4656
  filetype: FILETYPE.CHARACTER_DEVICE,
@@ -5212,7 +5295,7 @@ var KERNEL_VERSION, OS_RELEASE;
5212
5295
  var init_version = __esm({
5213
5296
  "src/version.ts"() {
5214
5297
  "use strict";
5215
- KERNEL_VERSION = true ? "1.110.7" : "0.0.0-dev";
5298
+ KERNEL_VERSION = true ? "1.111.0" : "0.0.0-dev";
5216
5299
  OS_RELEASE = "6.0.0-slicc";
5217
5300
  }
5218
5301
  });
@@ -7250,7 +7333,7 @@ function exactIn(node) {
7250
7333
  return node?.mount.opts.bridge.owners === true;
7251
7334
  }
7252
7335
  function modeFromStat(st, exact = false) {
7253
- const type = st.isSymbolicLink ? S_IFLNK : st.isDirectory ? S_IFDIR : st.isSocket ? S_IFSOCK : S_IFREG;
7336
+ const type = st.isSymbolicLink ? S_IFLNK2 : st.isDirectory ? S_IFDIR : st.isSocket ? S_IFSOCK : S_IFREG;
7254
7337
  const fallback = st.isDirectory || st.isSymbolicLink ? 511 : 438;
7255
7338
  const perm = (st.mode ?? fallback) & PERM_MASK;
7256
7339
  return type | (exact ? perm : perm || fallback);
@@ -8277,7 +8360,7 @@ function readingLinks(Fs) {
8277
8360
  }
8278
8361
  };
8279
8362
  }
8280
- var S_IFDIR, S_IFREG, S_IFLNK, S_IFSOCK, S_IFMT2, PERM_MASK, DEFAULT_DIR_PERM, UMASK, SEEK_CUR2, SEEK_END2, EARLY_WHOLE_FILE, O_APPEND4, O_ACCMODE, O_TRUNC, O_PATH, stale, opening;
8363
+ var S_IFDIR, S_IFREG, S_IFLNK2, S_IFSOCK, S_IFMT2, PERM_MASK, DEFAULT_DIR_PERM, UMASK, SEEK_CUR2, SEEK_END2, EARLY_WHOLE_FILE, O_APPEND4, O_ACCMODE, O_TRUNC, O_PATH, stale, opening;
8281
8364
  var init_live_vfs_fs = __esm({
8282
8365
  "src/realm/live-vfs-fs.ts"() {
8283
8366
  "use strict";
@@ -8289,7 +8372,7 @@ var init_live_vfs_fs = __esm({
8289
8372
  init_sync_sab_bridge();
8290
8373
  S_IFDIR = 16384;
8291
8374
  S_IFREG = 32768;
8292
- S_IFLNK = 40960;
8375
+ S_IFLNK2 = 40960;
8293
8376
  S_IFSOCK = 49152;
8294
8377
  S_IFMT2 = 61440;
8295
8378
  PERM_MASK = 4095;