@ai-ecoverse/slicc-kernel 1.67.1 → 1.68.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.
@@ -1983,10 +1983,28 @@ function ptyStat(path) {
1983
1983
  ctime: now
1984
1984
  };
1985
1985
  }
1986
+ function sealedStat() {
1987
+ const now = /* @__PURE__ */ new Date();
1988
+ return {
1989
+ dev: 22,
1990
+ ino: 1,
1991
+ mode: 8630,
1992
+ nlink: 1,
1993
+ uid: 0,
1994
+ gid: 0,
1995
+ rdev: 10 << 8 | 250,
1996
+ size: 0,
1997
+ blksize: 4096,
1998
+ blocks: 0,
1999
+ atime: now,
2000
+ mtime: now,
2001
+ ctime: now
2002
+ };
2003
+ }
1986
2004
  function nonblocking(stream) {
1987
2005
  return (stream.flags & O_NONBLOCK) !== 0 ? { nonblock: true } : void 0;
1988
2006
  }
1989
- var POLLIN, POLLOUT, POLLERR, POLLHUP, POLLRDNORM, POLLWRNORM, TCSETSF, O_NONBLOCK, SOCKET_MODE, PTY_PATH, TTY_PATH, TTY_NAME, O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC2, KILLED_BY_SIGPIPE, ProcessExit, SyscallError, KernelStreams;
2007
+ var POLLIN, POLLOUT, POLLERR, POLLHUP, POLLRDNORM, POLLWRNORM, TCSETSF, O_NONBLOCK, SOCKET_MODE, PTY_PATH, TTY_PATH, TTY_NAME, SEALED_PATH, O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC2, KILLED_BY_SIGPIPE, ProcessExit, SyscallError, KernelStreams;
1990
2008
  var init_kernel_streams = __esm({
1991
2009
  "src/process/kernel-streams.ts"() {
1992
2010
  "use strict";
@@ -2003,6 +2021,7 @@ var init_kernel_streams = __esm({
2003
2021
  PTY_PATH = /^\/dev\/(?:ptmx|pts\/(\d+))$/;
2004
2022
  TTY_PATH = /^\/dev\/tty\d+$/;
2005
2023
  TTY_NAME = /^tty\d+$/;
2024
+ SEALED_PATH = "/dev/sealed";
2006
2025
  O_CREAT = 64;
2007
2026
  O_EXCL = 128;
2008
2027
  O_NOCTTY = 256;
@@ -2076,6 +2095,15 @@ var init_kernel_streams = __esm({
2076
2095
  if (typeof this.Fs.stat !== "function") return;
2077
2096
  stream.stream_ops = { ...stream.stream_ops, getattr: () => this.Fs.stat?.(name2) ?? {} };
2078
2097
  }
2098
+ listSealed() {
2099
+ const { analyzePath, mkdev, makedev } = this.Fs;
2100
+ if (!this.sys.openSealed || !analyzePath || !mkdev || !makedev) return;
2101
+ if (analyzePath.call(this.Fs, SEALED_PATH).exists) return;
2102
+ try {
2103
+ mkdev.call(this.Fs, SEALED_PATH, makedev.call(this.Fs, 10, 250));
2104
+ } catch {
2105
+ }
2106
+ }
2079
2107
  creatingTerminal = false;
2080
2108
  useTerminalNodes() {
2081
2109
  const fs = this.Fs;
@@ -2168,13 +2196,14 @@ var init_kernel_streams = __esm({
2168
2196
  if (typeof this.Fs.open !== "function") return;
2169
2197
  this.usePtyPaths();
2170
2198
  this.useTerminalNodes();
2199
+ this.listSealed();
2171
2200
  const open = this.Fs.open.bind(this.Fs);
2172
2201
  this.Fs.open = (path, flags, mode) => {
2173
2202
  const device2 = typeof path === "string" ? this.devicePath(path) : void 0;
2174
2203
  if (device2 !== void 0 && TTY_PATH.test(device2) && !this.terminalExists(device2)) {
2175
2204
  throw new this.Fs.ErrnoError(wasiErrno("ENOENT"));
2176
2205
  }
2177
- const pty = this.openPty(open, path, flags, mode);
2206
+ const pty = this.openPty(open, path, flags, mode) ?? this.openSealed(open, path, flags, mode);
2178
2207
  if (pty) return pty;
2179
2208
  this.refuseExclusiveLink(path, flags);
2180
2209
  const stream = this.openRacing(open, path, flags, mode);
@@ -2232,15 +2261,24 @@ var init_kernel_streams = __esm({
2232
2261
  const kfd = this.call(
2233
2262
  () => pts ? openPts(Number(pts[1]), (flags & O_NOCTTY) !== 0) : openPty()
2234
2263
  );
2264
+ return this.vessel(open, kfd, { path, flags, mode }, true);
2265
+ }
2266
+ openSealed(open, path, flags, mode) {
2267
+ const { openSealed } = this.sys;
2268
+ if (path !== SEALED_PATH || !openSealed) return void 0;
2269
+ const kfd = this.call(() => openSealed.call(this.sys));
2270
+ return this.vessel(open, kfd, { path, flags, mode }, false);
2271
+ }
2272
+ vessel(open, kfd, at, terminal) {
2235
2273
  let stream;
2236
2274
  try {
2237
- stream = open("/dev/null", flags & ~(O_CREAT | O_EXCL | O_TRUNC2), mode);
2275
+ stream = open("/dev/null", at.flags & ~(O_CREAT | O_EXCL | O_TRUNC2), at.mode);
2238
2276
  } catch (e) {
2239
2277
  this.sys.close(kfd);
2240
2278
  throw e;
2241
2279
  }
2242
- this.attach(stream, kfd, true);
2243
- this.nameStream(stream, path);
2280
+ this.attach(stream, kfd, terminal);
2281
+ this.nameStream(stream, at.path);
2244
2282
  return stream;
2245
2283
  }
2246
2284
  usePtyPaths() {
@@ -2254,6 +2292,7 @@ var init_kernel_streams = __esm({
2254
2292
  const original = fs[name2];
2255
2293
  if (typeof original !== "function") continue;
2256
2294
  fs[name2] = (path, ...rest2) => {
2295
+ if (path === SEALED_PATH && this.sys.openSealed) return sealedStat();
2257
2296
  const owned = this.ownedTty(path);
2258
2297
  if (owned && isPtyPath(path)) return this.owned(path, ptyStat(path));
2259
2298
  if (!isPtyPath(path)) {
@@ -4403,6 +4442,9 @@ function kernelSys(transport) {
4403
4442
  openPts(n, noctty) {
4404
4443
  return json2(call2({ op: "pty-slave-open", n, noctty }, `pty-slave-open ${n}`));
4405
4444
  },
4445
+ openSealed() {
4446
+ return json2(call2({ op: "fd-open-sealed" }, "fd-open-sealed"));
4447
+ },
4406
4448
  ptyNumbers() {
4407
4449
  return json2(call2({ op: "pty-list" }, "pty-list"));
4408
4450
  },
@@ -5480,7 +5522,7 @@ function promoteRequest(fd, f, handed) {
5480
5522
  ...f.buffer.handle !== void 0 ? { handle: f.buffer.handle } : {}
5481
5523
  };
5482
5524
  }
5483
- var SYNTHETIC_DIRS2, O_NONBLOCK2, O_WRONLY4, O_RDWR4, O_APPEND, DEVICES2, WasiFds, GEN;
5525
+ var SYNTHETIC_DIRS2, O_NONBLOCK2, O_WRONLY4, O_RDWR4, O_APPEND, DEVICES2, SEALED_PATH2, WasiFds, GEN;
5484
5526
  var init_wasi_fds = __esm({
5485
5527
  "src/process/wasi/wasi-fds.ts"() {
5486
5528
  "use strict";
@@ -5499,6 +5541,7 @@ var init_wasi_fds = __esm({
5499
5541
  "/dev/urandom": "urandom",
5500
5542
  "/dev/random": "urandom"
5501
5543
  };
5544
+ SEALED_PATH2 = "/dev/sealed";
5502
5545
  WasiFds = class {
5503
5546
  table = /* @__PURE__ */ new Map();
5504
5547
  buffers = /* @__PURE__ */ new Map();
@@ -5963,16 +6006,30 @@ var init_wasi_fds = __esm({
5963
6006
  const joined2 = path.startsWith("/") ? path : `${this.dir(dirfd).path}/${path}`;
5964
6007
  return joined2.split("/").includes("..") ? physical(this.fs, joined2) : normalize(joined2);
5965
6008
  }
6009
+ openKernelDevice(path, oflags, fdflags) {
6010
+ const { openSealed, openTty } = this.kernel.sys;
6011
+ const nonblock = (fdflags & FDFLAGS.NONBLOCK) !== 0;
6012
+ let fd;
6013
+ let kind;
6014
+ if (path === SEALED_PATH2 && openSealed) {
6015
+ if (oflags & OFLAGS.DIRECTORY) throw new WasiError("ENOTDIR");
6016
+ if (oflags & OFLAGS.CREAT && oflags & OFLAGS.EXCL) throw new WasiError("EEXIST");
6017
+ fd = openSealed.call(this.kernel.sys);
6018
+ kind = "sealed";
6019
+ } else if (path === "/dev/tty" || /^\/dev\/tty\d+$/.test(path)) {
6020
+ fd = openTty?.call(this.kernel.sys, path === "/dev/tty" ? void 0 : path);
6021
+ if (fd === void 0) throw new WasiError("ENXIO");
6022
+ kind = "tty";
6023
+ } else return void 0;
6024
+ this.adopt(fd, kind, nonblock);
6025
+ this.bump();
6026
+ return fd;
6027
+ }
5966
6028
  open(path, oflags, rights, fdflags) {
5967
6029
  const device2 = deviceOf(path);
5968
6030
  if (device2) return this.install({ type: "device", device: device2 });
5969
- if (path === "/dev/tty" || /^\/dev\/tty\d+$/.test(path)) {
5970
- const fd = this.kernel.sys.openTty?.(path === "/dev/tty" ? void 0 : path);
5971
- if (fd === void 0) throw new WasiError("ENXIO");
5972
- this.table.set(fd, { ...kernelEntry2(), kind: "tty" });
5973
- this.bump();
5974
- return fd;
5975
- }
6031
+ const kernelDevice = this.openKernelDevice(path, oflags, fdflags);
6032
+ if (kernelDevice !== void 0) return kernelDevice;
5976
6033
  const alias = stdioAlias(path);
5977
6034
  if (alias !== void 0) return this.reopen(alias);
5978
6035
  const exclusive = (oflags & OFLAGS.CREAT) !== 0 && (oflags & OFLAGS.EXCL) !== 0;
@@ -6413,6 +6470,7 @@ function filestatOf(path, s) {
6413
6470
  function kernelFiletype(kind) {
6414
6471
  switch (kind) {
6415
6472
  case "tty":
6473
+ case "sealed":
6416
6474
  return { filetype: FILETYPE.CHARACTER_DEVICE, seeks: false };
6417
6475
  case "device":
6418
6476
  return { filetype: FILETYPE.CHARACTER_DEVICE, seeks: true };
@@ -6453,7 +6511,7 @@ function wrap(table) {
6453
6511
  }
6454
6512
  return out;
6455
6513
  }
6456
- var WasiExit, IDS, NS_PER_MS, AT_SYMLINK_NOFOLLOW2, AT_EACCESS2, ROOT_IDS, GONE, S_IFIFO, DEFAULT_UMASK, MONOTONIC_BASE, MAX_READ, SIGPIPE_EXIT, WasiHost;
6514
+ var WasiExit, IDS, NS_PER_MS, AT_SYMLINK_NOFOLLOW2, AT_EACCESS2, ROOT_IDS, GONE, S_IFIFO, DEFAULT_UMASK, MONOTONIC_BASE, MAX_READ, SIGPIPE_EXIT, SEALED_MODE, WasiHost;
6457
6515
  var init_wasi_host = __esm({
6458
6516
  "src/process/wasi/wasi-host.ts"() {
6459
6517
  "use strict";
@@ -6483,6 +6541,7 @@ var init_wasi_host = __esm({
6483
6541
  MONOTONIC_BASE = BigInt(Math.round(performance.timeOrigin)) * NS_PER_MS;
6484
6542
  MAX_READ = 1024 * 1024;
6485
6543
  SIGPIPE_EXIT = 141;
6544
+ SEALED_MODE = 8630;
6486
6545
  WasiHost = class {
6487
6546
  mem = new WasiMemory();
6488
6547
  fds;
@@ -6568,7 +6627,9 @@ var init_wasi_host = __esm({
6568
6627
  const fdOwned = (fd) => {
6569
6628
  const e = fds.get(fd);
6570
6629
  if (e.type === "device") return ROOT_IDS;
6571
- if (e.type === "kernel" && fds.kind(fd, e) !== "file") return void 0;
6630
+ const kind = e.type === "kernel" ? fds.kind(fd, e) : "file";
6631
+ if (kind === "sealed") return ROOT_IDS;
6632
+ if (kind !== "file") return void 0;
6572
6633
  try {
6573
6634
  return this.o.fs.stat(pathOf(fd));
6574
6635
  } catch (err) {
@@ -6577,7 +6638,7 @@ var init_wasi_host = __esm({
6577
6638
  }
6578
6639
  };
6579
6640
  const pathOwned = (path, follow2) => {
6580
- if (deviceOf(path)) return ROOT_IDS;
6641
+ if (this.synthetic(path)) return ROOT_IDS;
6581
6642
  return follow2 ? this.o.fs.stat(path) : this.o.fs.lstat(path);
6582
6643
  };
6583
6644
  return wrap({
@@ -6606,7 +6667,7 @@ var init_wasi_host = __esm({
6606
6667
  path_access: (dirfd, p, l, amode, flags) => {
6607
6668
  const path = at(dirfd, p, l);
6608
6669
  const nofollow = (flags & AT_SYMLINK_NOFOLLOW2) !== 0;
6609
- if (deviceOf(path)) {
6670
+ if (this.synthetic(path)) {
6610
6671
  if (this.o.fs.owners && amode & 1) throw new WasiError("EACCES");
6611
6672
  return;
6612
6673
  }
@@ -6623,12 +6684,14 @@ var init_wasi_host = __esm({
6623
6684
  },
6624
6685
  fd_mode: (fd, out) => {
6625
6686
  const e = fds.get(fd);
6626
- const pipe = e.type === "kernel" && fds.kind(fd, e) === "stream";
6627
- const mode = pipe ? S_IFIFO | 384 : modeOf(this.o.fs.stat(pathOf(fd)));
6687
+ const kind = e.type === "kernel" ? fds.kind(fd, e) : void 0;
6688
+ const mode = kind === "stream" ? S_IFIFO | 384 : kind === "sealed" ? SEALED_MODE : modeOf(this.o.fs.stat(pathOf(fd)));
6628
6689
  mem.view().setUint32(out, mode, true);
6629
6690
  },
6630
6691
  path_mode: (dirfd, p, l, flags, out) => {
6631
6692
  const path = at(dirfd, p, l);
6693
+ if (path === SEALED_PATH2 && this.o.kernel.sys.openSealed)
6694
+ return void mem.view().setUint32(out, SEALED_MODE, true);
6632
6695
  const st = flags & AT_SYMLINK_NOFOLLOW2 ? this.o.fs.lstat(path) : this.o.fs.stat(path);
6633
6696
  mem.view().setUint32(out, modeOf(st), true);
6634
6697
  }
@@ -6816,7 +6879,7 @@ var init_wasi_host = __esm({
6816
6879
  path_open: (dirfd, _lookup, p, l, oflags, rights, _inheriting, fdflags, out) => {
6817
6880
  const path = at(dirfd, p, l);
6818
6881
  if (deviceOf(path)) this.interrupted?.();
6819
- const fresh = (oflags & OFLAGS.CREAT) !== 0 && !o.fs.exists(path);
6882
+ const fresh = (oflags & OFLAGS.CREAT) !== 0 && !this.synthetic(path) && !o.fs.exists(path);
6820
6883
  mem.view().setUint32(out, fds.open(path, oflags, rights, fdflags), true);
6821
6884
  if (fresh) this.created(path, 438);
6822
6885
  },
@@ -7125,8 +7188,11 @@ var init_wasi_host = __esm({
7125
7188
  const out = this.sized(path, s, size);
7126
7189
  return gone ? { ...out, nlink: 0n } : out;
7127
7190
  }
7191
+ synthetic(path) {
7192
+ return deviceOf(path) !== void 0 || path === SEALED_PATH2 && !!this.o.kernel.sys.openSealed;
7193
+ }
7128
7194
  pathFilestat(path, lookup) {
7129
- if (deviceOf(path)) {
7195
+ if (this.synthetic(path)) {
7130
7196
  return this.local({
7131
7197
  filetype: FILETYPE.CHARACTER_DEVICE,
7132
7198
  size: 0n,