@ai-ecoverse/slicc-kernel 1.48.0 → 1.48.1

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.
@@ -1673,7 +1673,7 @@ function ptyStat(path) {
1673
1673
  function nonblocking(stream) {
1674
1674
  return (stream.flags & O_NONBLOCK) !== 0 ? { nonblock: true } : void 0;
1675
1675
  }
1676
- var POLLIN, POLLOUT, POLLERR, POLLHUP, POLLRDNORM, POLLWRNORM, O_NONBLOCK, SOCKET_MODE, PTY_PATH, TTY_PATH, TTY_NAME, O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, KILLED_BY_SIGPIPE, ProcessExit, SyscallError, KernelStreams;
1676
+ 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_TRUNC, KILLED_BY_SIGPIPE, ProcessExit, SyscallError, KernelStreams;
1677
1677
  var init_kernel_streams = __esm({
1678
1678
  "src/process/kernel-streams.ts"() {
1679
1679
  "use strict";
@@ -1684,6 +1684,7 @@ var init_kernel_streams = __esm({
1684
1684
  POLLHUP = 16;
1685
1685
  POLLRDNORM = 64;
1686
1686
  POLLWRNORM = 256;
1687
+ TCSETSF = 21508;
1687
1688
  O_NONBLOCK = 2048;
1688
1689
  SOCKET_MODE = 49663;
1689
1690
  PTY_PATH = /^\/dev\/(?:ptmx|pts\/(\d+))$/;
@@ -1802,8 +1803,8 @@ var init_kernel_streams = __esm({
1802
1803
  return {
1803
1804
  ops: {
1804
1805
  ioctl_tcgets: () => this.call(() => this.sys.tcgets?.(kfd)),
1805
- ioctl_tcsets: (_tty, _op, termios) => this.call(() => {
1806
- this.sys.tcsets?.(kfd, termios);
1806
+ ioctl_tcsets: (_tty, op, termios) => this.call(() => {
1807
+ this.sys.tcsets?.(kfd, termios, op === TCSETSF);
1807
1808
  return 0;
1808
1809
  }),
1809
1810
  ioctl_tiocgwinsz: () => this.call(() => this.sys.winsize?.(kfd) ?? [24, 80]),
@@ -3926,8 +3927,8 @@ function kernelSys(transport) {
3926
3927
  tcgets(fd) {
3927
3928
  return json(call2({ op: "tty-get", fd }, `tty-get ${fd}`));
3928
3929
  },
3929
- tcsets(fd, termios) {
3930
- call2({ op: "tty-set", fd, termios }, `tty-set ${fd}`);
3930
+ tcsets(fd, termios, flush) {
3931
+ call2({ op: "tty-set", fd, termios, ...flush ? { flush } : {} }, `tty-set ${fd}`);
3931
3932
  },
3932
3933
  winsize(fd) {
3933
3934
  return json(call2({ op: "tty-winsz", fd }, `tty-winsz ${fd}`));
@@ -5499,7 +5500,7 @@ function sliccTty(mem, fds, kernel) {
5499
5500
  if (actions < 0 || actions > TCSAFLUSH) throw new WasiError("EINVAL");
5500
5501
  const at = terminal(fd);
5501
5502
  needs(sys.tcsets);
5502
- sys.tcsets?.(at, readTermios(mem, ptr));
5503
+ sys.tcsets?.(at, readTermios(mem, ptr), actions === TCSAFLUSH);
5503
5504
  };
5504
5505
  const size = (fd, ptr) => {
5505
5506
  const [rows, cols] = needs(sys.winsize?.(terminal(fd)));
@@ -6315,7 +6316,7 @@ function restarted2(issue) {
6315
6316
  function resolveFrom(cwd, path) {
6316
6317
  return normalize(path.startsWith("/") ? path : `${cwd}/${path}`);
6317
6318
  }
6318
- var O_WRONLY5, O_RDWR5, O_APPEND2, OFLAG_CREAT, OFLAG_TRUNC, WasixProcess;
6319
+ var O_WRONLY5, O_RDWR5, O_APPEND2, OFLAG_CREAT, OFLAG_TRUNC, JOIN_NON_BLOCKING, JOIN_WAKE_STOPPED, JOIN_STOPPED, WasixProcess;
6319
6320
  var init_wasix_process = __esm({
6320
6321
  "src/process/wasi/wasix-process.ts"() {
6321
6322
  "use strict";
@@ -6327,6 +6328,9 @@ var init_wasix_process = __esm({
6327
6328
  O_APPEND2 = 1024;
6328
6329
  OFLAG_CREAT = 1;
6329
6330
  OFLAG_TRUNC = 8;
6331
+ JOIN_NON_BLOCKING = 1;
6332
+ JOIN_WAKE_STOPPED = 2;
6333
+ JOIN_STOPPED = 3;
6330
6334
  WasixProcess = class {
6331
6335
  host;
6332
6336
  driver;
@@ -6456,13 +6460,21 @@ var init_wasix_process = __esm({
6456
6460
  const v = this.host.mem.view();
6457
6461
  const pid = v.getUint8(pidPtr) === 1 ? v.getUint32(pidPtr + 4, true) : -1;
6458
6462
  this.host.mem.bytes(statusPtr, 6).fill(0);
6459
- const [child, status2] = this.call({ op: "proc-wait", pid, nohang: (flags & 1) !== 0 });
6463
+ const [child, status2] = this.call({
6464
+ op: "proc-wait",
6465
+ pid,
6466
+ nohang: (flags & JOIN_NON_BLOCKING) !== 0,
6467
+ ...flags & JOIN_WAKE_STOPPED ? { untraced: true } : {}
6468
+ });
6460
6469
  if (child === 0) return;
6461
6470
  this.host.o.fs.invalidate?.();
6462
6471
  v.setUint8(pidPtr, 1);
6463
6472
  v.setUint32(pidPtr + 4, child, true);
6464
6473
  const sig = status2 & 127;
6465
- if (sig) {
6474
+ if (sig === 127) {
6475
+ v.setUint8(statusPtr, JOIN_STOPPED);
6476
+ v.setUint8(statusPtr + 2, status2 >> 8 & 255);
6477
+ } else if (sig) {
6466
6478
  v.setUint8(statusPtr, 2);
6467
6479
  v.setUint8(statusPtr + 4, sig);
6468
6480
  } else {
@@ -8989,6 +9001,56 @@ function latin1(bytes) {
8989
9001
  }
8990
9002
  return text;
8991
9003
  }
9004
+ function quoted(input, from) {
9005
+ let value2 = "";
9006
+ let at = from + 1;
9007
+ while (at < input.length) {
9008
+ const char = input[at++];
9009
+ if (char === '"') break;
9010
+ if (char !== "\\") value2 += char;
9011
+ else if (at < input.length) value2 += input[at++];
9012
+ else value2 += char;
9013
+ }
9014
+ return [value2, at];
9015
+ }
9016
+ function parameter(text, from, params) {
9017
+ let at = from + 1;
9018
+ while (SPACE.test(text[at] ?? "")) at++;
9019
+ let end = at;
9020
+ while (end < text.length && text[end] !== ";" && text[end] !== "=") end++;
9021
+ const name = text.slice(at, end).toLowerCase();
9022
+ if (text[end] !== "=") return end;
9023
+ const start2 = end + 1;
9024
+ let value2;
9025
+ if (text[start2] === '"') {
9026
+ [value2, at] = quoted(text, start2);
9027
+ end = text.indexOf(";", at);
9028
+ } else {
9029
+ end = text.indexOf(";", start2);
9030
+ value2 = text.slice(start2, end < 0 ? void 0 : end).replace(/[\t\n\r ]+$/, "");
9031
+ if (!value2) return end < 0 ? text.length : end;
9032
+ }
9033
+ if (end < 0) end = text.length;
9034
+ if (TOKEN.test(name) && QUOTABLE.test(value2) && !params.has(name)) {
9035
+ params.set(name, value2);
9036
+ }
9037
+ return end;
9038
+ }
9039
+ function mimeType(input) {
9040
+ const text = input.replace(/^[\t\n\r ]+|[\t\n\r ]+$/g, "");
9041
+ const slash = text.indexOf("/");
9042
+ const semi = text.indexOf(";", slash);
9043
+ const type = text.slice(0, slash);
9044
+ const subtype = text.slice(slash + 1, semi < 0 ? void 0 : semi).replace(/[\t\n\r ]+$/, "");
9045
+ if (slash < 0 || !TOKEN.test(type) || !TOKEN.test(subtype)) return void 0;
9046
+ const params = /* @__PURE__ */ new Map();
9047
+ for (let at = semi < 0 ? text.length : semi; at < text.length; ) at = parameter(text, at, params);
9048
+ let out = `${type}/${subtype}`.toLowerCase();
9049
+ for (const [name, value2] of params) {
9050
+ out += `;${name}=${TOKEN.test(value2) ? value2 : `"${value2.replace(/["\\]/g, "\\$&")}"`}`;
9051
+ }
9052
+ return out;
9053
+ }
8992
9054
  function dataResponse(request) {
8993
9055
  const url = withoutFragment(new URL(request.url));
8994
9056
  const rest2 = url.slice("data:".length);
@@ -8998,7 +9060,7 @@ function dataResponse(request) {
8998
9060
  let body = percentDecode(rest2.slice(comma + 1));
8999
9061
  const base642 = BASE64.exec(type);
9000
9062
  if (base642) {
9001
- type = type.slice(0, base642.index).replace(/[\t\n\f\r ]+$/, "");
9063
+ type = type.slice(0, base642.index);
9002
9064
  let binary;
9003
9065
  try {
9004
9066
  binary = atob(latin1(body));
@@ -9008,11 +9070,10 @@ function dataResponse(request) {
9008
9070
  body = Uint8Array.from(binary, (c) => c.charCodeAt(0));
9009
9071
  }
9010
9072
  if (type.startsWith(";")) type = `text/plain${type}`;
9011
- if (!MIME.test(type)) type = "text/plain;charset=US-ASCII";
9012
- const response = new Response(body, {
9013
- status: 200,
9014
- headers: { "content-type": type }
9015
- });
9073
+ const response = new Response(
9074
+ request.method === "HEAD" ? null : body,
9075
+ { status: 200, headers: { "content-type": mimeType(type) ?? "text/plain;charset=US-ASCII" } }
9076
+ );
9016
9077
  return withMeta(response, url, false);
9017
9078
  }
9018
9079
  function withMeta(response, url, redirected) {
@@ -9200,7 +9261,7 @@ function fetchOp(kernel) {
9200
9261
  }
9201
9262
  };
9202
9263
  }
9203
- var CHUNK, MAX_REDIRECTS, NULL_BODY, REDIRECTS, BODY_HEADERS, DECODED, CREDENTIALS, OVER, MIME, BASE64, SLICE;
9264
+ var CHUNK, MAX_REDIRECTS, NULL_BODY, REDIRECTS, BODY_HEADERS, DECODED, CREDENTIALS, OVER, TOKEN, QUOTABLE, SPACE, BASE64, SLICE;
9204
9265
  var init_js_fetch = __esm({
9205
9266
  "src/process/js/js-fetch.ts"() {
9206
9267
  "use strict";
@@ -9219,7 +9280,9 @@ var init_js_fetch = __esm({
9219
9280
  DECODED = /* @__PURE__ */ new Set(["gzip", "x-gzip", "deflate"]);
9220
9281
  CREDENTIALS = /* @__PURE__ */ new Set(["authorization", "proxy-authorization", "cookie", "cookie2"]);
9221
9282
  OVER = /* @__PURE__ */ Symbol("over");
9222
- MIME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+(?:[\t ]*;.*)?$/s;
9283
+ TOKEN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
9284
+ QUOTABLE = /^[\t\x20-\x7e\x80-\xff]*$/;
9285
+ SPACE = /[\t\n\r ]/;
9223
9286
  BASE64 = /; *base64$/i;
9224
9287
  SLICE = 32768;
9225
9288
  }
@@ -9696,6 +9759,7 @@ function rawOf(termios) {
9696
9759
  }
9697
9760
  function ttyOps(kernel) {
9698
9761
  const saved = /* @__PURE__ */ new Map();
9762
+ const terminalOf = async (fd) => (await kernel.json({ op: "fd-info", fd })).terminal ?? `fd ${fd}`;
9699
9763
  const getAttr = async (fd) => await kernel.json({ op: "tty-get", fd });
9700
9764
  const setAttr = async (fd, termios) => {
9701
9765
  await kernel.call({ op: "tty-set", fd, termios: copy(termios) });
@@ -9704,14 +9768,15 @@ function ttyOps(kernel) {
9704
9768
  getAttr,
9705
9769
  setAttr,
9706
9770
  async setRaw(fd, raw) {
9771
+ const terminal = await terminalOf(fd);
9707
9772
  if (!raw) {
9708
- const original = saved.get(fd);
9709
- saved.delete(fd);
9710
- if (original) await setAttr(fd, original);
9773
+ const original = saved.get(terminal);
9774
+ saved.delete(terminal);
9775
+ if (original) await setAttr(fd, original.termios);
9711
9776
  return;
9712
9777
  }
9713
9778
  const current = await getAttr(fd);
9714
- if (!saved.has(fd)) saved.set(fd, current);
9779
+ if (!saved.has(terminal)) saved.set(terminal, { fd, termios: current });
9715
9780
  await setAttr(fd, rawOf(current));
9716
9781
  },
9717
9782
  async size(fd) {
@@ -9724,9 +9789,9 @@ function ttyOps(kernel) {
9724
9789
  }
9725
9790
  };
9726
9791
  const restore = async () => {
9727
- for (const [fd, original] of [...saved].reverse()) {
9728
- saved.delete(fd);
9729
- await setAttr(fd, original).catch(() => void 0);
9792
+ for (const [terminal, { fd, termios }] of [...saved].reverse()) {
9793
+ saved.delete(terminal);
9794
+ await setAttr(fd, termios).catch(() => void 0);
9730
9795
  }
9731
9796
  };
9732
9797
  return { tty, restore };