@ai-ecoverse/slicc-kernel 1.125.10 → 1.125.11

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.
@@ -2655,7 +2655,7 @@ var KERNEL_VERSION, OS_RELEASE;
2655
2655
  var init_version = __esm({
2656
2656
  "src/version.ts"() {
2657
2657
  "use strict";
2658
- KERNEL_VERSION = true ? "1.125.10" : "0.0.0-dev";
2658
+ KERNEL_VERSION = true ? "1.125.11" : "0.0.0-dev";
2659
2659
  OS_RELEASE = "6.0.0-slicc";
2660
2660
  }
2661
2661
  });
@@ -4016,7 +4016,7 @@ var init_kernel_streams = __esm({
4016
4016
  }
4017
4017
  }
4018
4018
  }
4019
- openNode(stream, path, opener) {
4019
+ openNode(stream, path, opener, terminal = false) {
4020
4020
  let kfd;
4021
4021
  try {
4022
4022
  kfd = this.call(() => opener.call(this.sys, stream.flags & 3));
@@ -4024,7 +4024,7 @@ var init_kernel_streams = __esm({
4024
4024
  this.Fs.closeStream(stream.fd);
4025
4025
  throw e;
4026
4026
  }
4027
- this.attach(stream, kfd, false);
4027
+ this.attach(stream, kfd, terminal);
4028
4028
  this.nameStream(stream, path);
4029
4029
  if (path === CLIPBOARD_PATH) this.reportClose(kfd);
4030
4030
  }
@@ -4114,8 +4114,10 @@ var init_kernel_streams = __esm({
4114
4114
  const make = (parent, name2) => {
4115
4115
  const dir = getPath.call(fs, parent);
4116
4116
  if (dir === "/dev" && name2 === "pts") mkdir.call(fs, "/dev/pts", 493);
4117
+ else if (dir === "/dev" && name2 === "ptmx" && this.sys.openPty)
4118
+ this.ptyNode("/dev/ptmx", makedev.call(fs, 5, 2));
4117
4119
  else if (dir === "/dev/pts" && numbers().includes(Number(name2)) && /^\d+$/.test(name2))
4118
- mkdev.call(fs, `/dev/pts/${name2}`, makedev.call(fs, PTS_MAJOR, Number(name2)));
4120
+ this.ptyNode(`/dev/pts/${name2}`, makedev.call(fs, PTS_MAJOR, Number(name2)));
4119
4121
  else return false;
4120
4122
  return true;
4121
4123
  };
@@ -4139,9 +4141,23 @@ var init_kernel_streams = __esm({
4139
4141
  const at = path.replace(/\/+$/, "");
4140
4142
  if (at === "/dev/pts") return [".", "..", ...numbers().map(String)];
4141
4143
  const names = readdir.call(fs, path);
4142
- return at === "/dev" && !names.includes("pts") ? [...names, "pts"] : names;
4144
+ if (at !== "/dev") return names;
4145
+ const extra = ["pts", ...this.sys.openPty ? ["ptmx"] : []];
4146
+ return [...names, ...extra.filter((name2) => !names.includes(name2))];
4143
4147
  };
4144
4148
  }
4149
+ ptyNode(path, dev) {
4150
+ const fs = this.Fs;
4151
+ fs.registerDevice?.call(fs, dev, {
4152
+ open: (stream) => {
4153
+ const n = PTY_PATH.exec(path)?.[1];
4154
+ const { openPty, openPts } = this.sys;
4155
+ const opener = () => n === void 0 ? openPty.call(this.sys) : openPts.call(this.sys, Number(n), (stream.flags & O_NOCTTY) !== 0);
4156
+ this.openNode(stream, path, opener, true);
4157
+ }
4158
+ });
4159
+ fs.mkdev?.call(fs, path, dev);
4160
+ }
4145
4161
  ptsTarget(path, st) {
4146
4162
  if ((st?.rdev ?? 0) < PTS_MAJOR << 8) return void 0;
4147
4163
  const { lookupPath } = this.Fs;
@@ -4342,7 +4358,8 @@ var init_kernel_streams = __esm({
4342
4358
  if (!isPtyPath(path))
4343
4359
  return this.pathStat(path, original.call(fs, path, ...rest2), name2, owned);
4344
4360
  this.existingPty(path);
4345
- return ptyStat(path);
4361
+ const st = ptyStat(path);
4362
+ return this.options.owners === true ? { ...st, uid: 0, gid: 0 } : st;
4346
4363
  };
4347
4364
  }
4348
4365
  }
@@ -14953,6 +14970,7 @@ function childOps(kernel, io, defaults, sync) {
14953
14970
  const group = groupOf(o, "spawn");
14954
14971
  const named = argv0Of(o.argv0, "spawn");
14955
14972
  const death = deathOf(o.parentDeathSignal, defaults);
14973
+ const inherit = fdsOf(o.fds);
14956
14974
  return (stdio) => ({
14957
14975
  op: "proc-spawn",
14958
14976
  file,
@@ -14962,6 +14980,7 @@ function childOps(kernel, io, defaults, sync) {
14962
14980
  cwd: o.cwd ?? defaults.cwd,
14963
14981
  ...o.cwd !== void 0 ? { chdir: true } : {},
14964
14982
  stdio,
14983
+ ...inherit.length > 0 ? { inherit } : {},
14965
14984
  ...group,
14966
14985
  ...death
14967
14986
  });
@@ -14997,6 +15016,20 @@ function childOps(kernel, io, defaults, sync) {
14997
15016
  };
14998
15017
  return { spawn, wait: wait2, kill, spawnSync };
14999
15018
  }
15019
+ function fdsOf(fds) {
15020
+ if (fds === void 0) return [];
15021
+ if (typeof fds !== "object" || fds === null || Array.isArray(fds)) {
15022
+ throw new JsCallError("EINVAL", "spawn");
15023
+ }
15024
+ return Object.entries(fds).map(([key, from]) => {
15025
+ const fd = Number(key);
15026
+ const valid = Number.isInteger(fd) && fd >= 3 && String(fd) === key;
15027
+ if (!valid || !Number.isInteger(from) || from < 0) {
15028
+ throw new JsCallError("EINVAL", "spawn");
15029
+ }
15030
+ return { fd, kernel: from };
15031
+ });
15032
+ }
15000
15033
  function groupOf(o, call2) {
15001
15034
  const { pgid, session } = o;
15002
15035
  const valid = pgid === void 0 || Number.isInteger(pgid) && pgid >= 0;
@@ -16302,8 +16335,11 @@ function syncOps(kernel, shared) {
16302
16335
  handles.get(fd)?.();
16303
16336
  handles.delete(fd);
16304
16337
  infos.delete(fd);
16338
+ shared.closing?.(fd);
16305
16339
  kernel.call({ op: "fd-close", fd });
16306
16340
  },
16341
+ socketpair: () => kernel.json({ op: "sock-pair", domain: "unix", type: "stream" }),
16342
+ pipe: () => kernel.json({ op: "fd-pipe" }),
16307
16343
  open: procOpenSync(open, kernel, { resolve, pid: shared.pid }),
16308
16344
  fs: procFsSync(syncPathOps(kernel, resolve, statOf, open, tryDevSync), kernel, {
16309
16345
  resolve,
@@ -17010,12 +17046,37 @@ function watchingSyncOps(kernel, syncKernel, shared) {
17010
17046
  };
17011
17047
  return { ...ops, fs: { ...ops.fs, watch } };
17012
17048
  }
17049
+ function pendingReads(kernel, info, random) {
17050
+ const reading = /* @__PURE__ */ new Map();
17051
+ const read2 = async (fd, max = CHUNK, signal) => {
17052
+ index2(max, "read");
17053
+ const emulated = readDevice(await info(fd), max, random);
17054
+ if (emulated) return emulated;
17055
+ const stop = new AbortController();
17056
+ const waits = reading.get(fd) ?? /* @__PURE__ */ new Set();
17057
+ reading.set(fd, waits.add(stop));
17058
+ try {
17059
+ const n = Math.min(max, MAX_IO);
17060
+ if (signal) return await readPipe(kernel, fd, n, AbortSignal.any([signal, stop.signal]));
17061
+ const r = await kernel.blocking({ op: "fd-read", fd, max: n }, stop.signal);
17062
+ return r.ok && r.kind === "bytes" ? r.bytes : new Uint8Array(0);
17063
+ } finally {
17064
+ waits.delete(stop);
17065
+ if (waits.size === 0 && reading.get(fd) === waits) reading.delete(fd);
17066
+ }
17067
+ };
17068
+ const closing = (fd) => {
17069
+ for (const stop of reading.get(fd) ?? []) stop.abort(new JsCallError("EBADF", "read"));
17070
+ reading.delete(fd);
17071
+ };
17072
+ return { read: read2, closing };
17073
+ }
17013
17074
  function createContext(o) {
17014
17075
  const { kernel } = o;
17015
17076
  const infos = /* @__PURE__ */ new Map();
17016
17077
  const handles = /* @__PURE__ */ new Map();
17017
17078
  const pending = /* @__PURE__ */ new Set();
17018
- const random = o.random ?? ((bytes) => void crypto.getRandomValues(bytes));
17079
+ const random = o.random ?? cryptoRandom;
17019
17080
  const resolve = (path) => resolvePath(o.cwd, path);
17020
17081
  const tryDev = (abs) => resolveDevAsync(kernel, abs);
17021
17082
  let exiting;
@@ -17035,12 +17096,7 @@ function createContext(o) {
17035
17096
  infos.set(fd, got);
17036
17097
  return got;
17037
17098
  };
17038
- const read2 = async (fd, max = CHUNK, signal) => {
17039
- index2(max, "read");
17040
- const emulated = readDevice(await info(fd), max, random);
17041
- if (emulated) return emulated;
17042
- return readPipe(kernel, fd, Math.min(max, MAX_IO), signal);
17043
- };
17099
+ const { read: read2, closing } = pendingReads(kernel, info, random);
17044
17100
  const { writes, writeAll } = writer(kernel, info, o.pid);
17045
17101
  const write2 = (fd, data) => {
17046
17102
  const bytes = typeof data === "string" ? encoder4.encode(data) : data;
@@ -17083,9 +17139,10 @@ function createContext(o) {
17083
17139
  if (o.lane && o.lane !== noLane) kernel.syncLane = o.lane;
17084
17140
  const syncKernel = new JsSyncKernel(lane, kernel, unwind);
17085
17141
  const terminal = ttyOps(kernel);
17142
+ const shared = { pid: o.pid, resolve, random, infos, handles, closing };
17086
17143
  const sync = {
17087
17144
  kernel: KERNEL_INFO,
17088
- ...watchingSyncOps(kernel, syncKernel, { pid: o.pid, resolve, random, infos, handles }),
17145
+ ...watchingSyncOps(kernel, syncKernel, shared),
17089
17146
  run: (options) => runSync(syncKernel, { env: o.env, cwd: o.cwd, resolve, signal: signalNumber }, options),
17090
17147
  spawn: (options) => spawnSync(options),
17091
17148
  exit: (status2 = 0) => {
@@ -17124,8 +17181,11 @@ function createContext(o) {
17124
17181
  handles.get(fd)?.();
17125
17182
  handles.delete(fd);
17126
17183
  infos.delete(fd);
17184
+ closing(fd);
17127
17185
  await kernel.call({ op: "fd-close", fd });
17128
17186
  },
17187
+ socketpair: async () => await kernel.json({ op: "sock-pair", domain: "unix", type: "stream" }),
17188
+ pipe: async () => await kernel.json({ op: "fd-pipe" }),
17129
17189
  async fdStatus(fd) {
17130
17190
  const type = typeOf(await info(fd));
17131
17191
  return { type, tty: type === "tty", seekable: type === "file" };
@@ -17350,7 +17410,7 @@ function pathOps(kernel, resolve, statOf, open, tryDev) {
17350
17410
  }
17351
17411
  };
17352
17412
  }
17353
- var KERNEL_INFO, JsExit, encoder4;
17413
+ var KERNEL_INFO, JsExit, encoder4, cryptoRandom;
17354
17414
  var init_js_context = __esm({
17355
17415
  "src/process/js/js-context.ts"() {
17356
17416
  "use strict";
@@ -17381,6 +17441,7 @@ var init_js_context = __esm({
17381
17441
  }
17382
17442
  };
17383
17443
  encoder4 = new TextEncoder();
17444
+ cryptoRandom = (bytes) => void crypto.getRandomValues(bytes);
17384
17445
  }
17385
17446
  });
17386
17447