@ai-ecoverse/slicc-kernel 1.48.1 → 1.48.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.
package/dist/node.js CHANGED
@@ -9203,6 +9203,7 @@ function isWasmSyscall(req) {
9203
9203
  return typeof op === "string" && SYSCALL_OPS.has(op);
9204
9204
  }
9205
9205
  var MAX_READ = 1024 * 1024;
9206
+ var KEYBOARD = /* @__PURE__ */ new Set([SIG.INT, SIG.QUIT, SIG.TSTP]);
9206
9207
  var DEFAULT_UMASK = 18;
9207
9208
  var DYING = { ok: false, errno: "EINTR", message: "the process is being killed" };
9208
9209
  var HOSTS_ONLY = new Resolver({ routes: new Routes() });
@@ -9221,6 +9222,8 @@ var WasmProcess = class {
9221
9222
  execTermsig;
9222
9223
  stopped = 0;
9223
9224
  stops = 0;
9225
+ owed = false;
9226
+ waits = 0;
9224
9227
  resumed = Promise.resolve();
9225
9228
  wake;
9226
9229
  stateListeners = [];
@@ -9276,6 +9279,7 @@ var WasmProcess = class {
9276
9279
  return "terminate";
9277
9280
  }
9278
9281
  this.options.onPending?.(sig);
9282
+ if (this.options.jobs?.keyboard && KEYBOARD.has(sig)) this.owed = true;
9279
9283
  const blocked = this.interrupt;
9280
9284
  this.interrupt = new AbortController();
9281
9285
  blocked.abort();
@@ -9320,8 +9324,10 @@ var WasmProcess = class {
9320
9324
  await this.resumed;
9321
9325
  if (this.dying) return DYING;
9322
9326
  const stops = this.stops;
9327
+ const waits = this.waits;
9323
9328
  const result = await this.dispatch(req, cancelled);
9324
9329
  if (this.dying) return DYING;
9330
+ if (!result.ok && result.errno === "EINTR" && this.waits !== waits) this.owed = false;
9325
9331
  const restart = !result.ok && result.errno === "EINTR" && this.stops !== stops;
9326
9332
  if (restart && !this.options.hasPending?.()) continue;
9327
9333
  await this.resumed;
@@ -9374,8 +9380,11 @@ var WasmProcess = class {
9374
9380
  refuseIfPending(restart) {
9375
9381
  if (restart && this.options.hasPending?.()) throw new KernelError("EINTR");
9376
9382
  }
9377
- blockingSignal(cancelled) {
9378
- if (this.options.hasPending?.() || cancelled?.aborted) throw new KernelError("EINTR");
9383
+ blockingSignal(cancelled, owing = true) {
9384
+ if (owing) this.waits++;
9385
+ if (this.options.hasPending?.() || cancelled?.aborted || owing && this.owed) {
9386
+ throw new KernelError("EINTR");
9387
+ }
9379
9388
  return cancelled ? AbortSignal.any([this.interrupt.signal, cancelled]) : this.interrupt.signal;
9380
9389
  }
9381
9390
  async read(req, cancelled) {
@@ -9521,7 +9530,7 @@ var WasmProcess = class {
9521
9530
  return { ok: true, kind: "json", json: this.options.jobs?.terminalNames() ?? [] };
9522
9531
  case "fd-select": {
9523
9532
  const { read, write, timeoutMs } = req;
9524
- const signal = this.blockingSignal(cancelled);
9533
+ const signal = this.blockingSignal(cancelled, timeoutMs !== 0);
9525
9534
  const selected = await selectFds(this.fds, read, write, timeoutMs, signal);
9526
9535
  return { ok: true, kind: "json", json: selected };
9527
9536
  }
@@ -10197,6 +10206,7 @@ var JobTable = class {
10197
10206
  handoffs = /* @__PURE__ */ new Map();
10198
10207
  foreground = /* @__PURE__ */ new Map();
10199
10208
  terminals = /* @__PURE__ */ new Map();
10209
+ keyboard = false;
10200
10210
  add(pid, parentPid, signal, terminal) {
10201
10211
  const parent = parentPid === void 0 ? void 0 : this.members.get(parentPid);
10202
10212
  if (!parent && terminal) this.terminals.set(pid, terminal);
@@ -10366,6 +10376,14 @@ var JobTable = class {
10366
10376
  signalForeground(tty, fallback, sig) {
10367
10377
  this.killGroup(this.tcgetpgrp(tty, fallback), sig);
10368
10378
  }
10379
+ fromKeyboard(send) {
10380
+ this.keyboard = true;
10381
+ try {
10382
+ send();
10383
+ } finally {
10384
+ this.keyboard = false;
10385
+ }
10386
+ }
10369
10387
  };
10370
10388
 
10371
10389
  // src/kernel/settling.ts
@@ -12201,7 +12219,8 @@ var Launcher = class {
12201
12219
  keySignal(tty, fallback, sig, send) {
12202
12220
  const pgid = this.jobs.tcgetpgrp(tty, fallback);
12203
12221
  const foreground = () => this.jobs.tcgetpgrp(tty, fallback);
12204
- this.settling.deliver(sig, pgid, send, tty.reading ? void 0 : foreground);
12222
+ const keyed = () => this.jobs.fromKeyboard(send);
12223
+ this.settling.deliver(sig, pgid, keyed, tty.reading ? void 0 : foreground);
12205
12224
  }
12206
12225
  umaskOf(pid) {
12207
12226
  return this.processes.get(pid)?.umask?.() ?? DEFAULT_UMASK;
@@ -13533,13 +13552,18 @@ function nodeWorker(file, live, closed) {
13533
13552
  }
13534
13553
  };
13535
13554
  const worker = closed ? void 0 : new Worker(file);
13555
+ let ending = false;
13536
13556
  if (worker) {
13537
13557
  const kill = () => {
13558
+ ending = true;
13538
13559
  void worker.terminate();
13539
13560
  fail3(TERMINATED);
13540
13561
  };
13541
13562
  live.add(kill);
13542
- worker.once("exit", () => live.delete(kill));
13563
+ worker.once("exit", (code) => {
13564
+ live.delete(kill);
13565
+ if (!ending) fail3(`the process worker exited with ${code}`);
13566
+ });
13543
13567
  worker.on("error", (err) => fail3(String(err)));
13544
13568
  } else {
13545
13569
  setTimeout(() => fail3(TERMINATED), 0);
@@ -13560,7 +13584,10 @@ function nodeWorker(file, live, closed) {
13560
13584
  const listener = messages.get(handler);
13561
13585
  if (listener) worker?.off("message", listener);
13562
13586
  },
13563
- terminate: () => void worker?.terminate()
13587
+ terminate: () => {
13588
+ ending = true;
13589
+ void worker?.terminate();
13590
+ }
13564
13591
  };
13565
13592
  }
13566
13593
  function textOf(on) {