@ai-ecoverse/slicc-kernel 1.26.2 → 1.26.4

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/README.md CHANGED
@@ -300,7 +300,7 @@ Programs mount and unmount with `mount(2)` and `umount2(2)`, so a `mount`/`umoun
300
300
 
301
301
  ### Exec
302
302
 
303
- An exec'd program takes over the pid of the process it replaces, as on Linux: `getpid()` and `$$` in the new image, `/proc`, `ps`, `kill` and the parent's `waitpid` all agree on that pid, and the image's parent pid is the replaced process's. Its own children see that pid as their parent.
303
+ An exec'd program takes over the pid of the process it replaces, as on Linux: `getpid()` and `$$` in the new image, `/proc`, `ps`, `kill` and the parent's `waitpid` all agree on that pid, and the image's parent pid is the replaced process's. Its own children see that pid as their parent. Signals a program ignores stay ignored in the image it execs and in the children it spawns or forks, as POSIX has it, so `nohup cmd` and `trap '' TERM; exec cmd` keep `cmd` safe from them; caught signals go back to their default. The kernel holds what was handed down, so a new image that sets one of those signals back to the default with `signal(SIG_DFL)` still ignores it, until it installs a handler.
304
304
 
305
305
  - **Emscripten:** `Module.sliccKernel.execve(file, argv, env, cwd)` runs `file` as this process's new image on its fds 0, 1 and 2, waits for it, and returns its wait status, or a negative errno when it cannot start. `env` and `cwd` may be `null` for this process's own. An exec shim detects it with `typeof Module.sliccKernel.execve === 'function'` and exits with the status it returns, as `execve` never returns on success. Older shims spawn the program and then call `Module.sliccKernel.execWait(pid)`; that still works, but the image then reports a pid of its own from `getpid()`.
306
306
  - **WASIX:** `proc_exec` does this by itself.
@@ -7182,6 +7182,7 @@ var WasmProcess = class {
7182
7182
  children;
7183
7183
  caught = 0;
7184
7184
  ignored = 0;
7185
+ inherited = 0;
7185
7186
  interrupt = new AbortController();
7186
7187
  execChild;
7187
7188
  execTermsig;
@@ -7199,12 +7200,19 @@ var WasmProcess = class {
7199
7200
  this.pid = pid;
7200
7201
  this.fds = fds;
7201
7202
  this.options = options;
7203
+ this.inherited = options.ignored ?? 0;
7202
7204
  this.children = new ChildTable(fds, options.spawner, options.forker);
7203
7205
  this.nodes = new VfsNodes(options.fs);
7204
7206
  options.openFiles?.add(this.nodes);
7205
7207
  this.children.onChildState = () => this.signal(SIG.CHLD);
7206
7208
  this.children.onReap = options.onReap;
7207
7209
  }
7210
+ ignores(bit) {
7211
+ return ((this.ignored | this.inherited & ~this.caught) & bit) !== 0;
7212
+ }
7213
+ inheritable(fork = false) {
7214
+ return ((fork ? 0 : this.ignored) | this.inherited) & ~this.caught;
7215
+ }
7208
7216
  signal(sig) {
7209
7217
  if (this.execChild !== void 0) {
7210
7218
  void Promise.resolve(this.options.kill?.(this.execChild, sig)).catch(() => void 0);
@@ -7214,7 +7222,7 @@ var WasmProcess = class {
7214
7222
  if (sig === SIG.CONT) this.cont();
7215
7223
  if (sig === SIG.STOP) return this.stop(sig);
7216
7224
  const bit = sigbit(sig);
7217
- if (this.ignored & bit) return "ignore";
7225
+ if (this.ignores(bit)) return "ignore";
7218
7226
  if (!(this.caught & bit)) {
7219
7227
  const action = defaultAction(sig);
7220
7228
  return action === "stop" ? this.stop(sig) : action;
@@ -7513,7 +7521,7 @@ var WasmProcess = class {
7513
7521
  if (session !== void 0 && session !== tty) return;
7514
7522
  const pgid = this.pgid();
7515
7523
  if (jobs.tcgetpgrp(tty, this.sid()) === pgid) return;
7516
- if (this.ignored & sigbit(SIG.TTIN)) throw new KernelError("EIO");
7524
+ if (this.ignores(sigbit(SIG.TTIN))) throw new KernelError("EIO");
7517
7525
  jobs.killGroup(pgid, SIG.TTIN);
7518
7526
  throw new KernelError("EINTR");
7519
7527
  }
@@ -7741,6 +7749,7 @@ function spawnWasmProcess(opts) {
7741
7749
  const sab = new SharedArrayBuffer(SAB_HEADER_BYTES + SAB_DEFAULT_WINDOW_BYTES);
7742
7750
  const header2 = new Int32Array(sab, 0, SAB_HEADER_I32);
7743
7751
  const process = new WasmProcess(opts.pid, opts.fds, {
7752
+ ...opts.ignored ? { ignored: opts.ignored } : {},
7744
7753
  spawner: opts.spawner,
7745
7754
  forker: opts.forker,
7746
7755
  fs: opts.fs,
@@ -7883,7 +7892,8 @@ function spawnWasmProcess(opts) {
7883
7892
  signal,
7884
7893
  termsig: () => endedBy,
7885
7894
  onState: (listener) => process.onState(listener),
7886
- memory: () => Atomics.load(header2, SAB_I_MEMORY) * 65536
7895
+ memory: () => Atomics.load(header2, SAB_I_MEMORY) * 65536,
7896
+ ignoredSignals: (fork) => process.inheritable(fork)
7887
7897
  };
7888
7898
  }
7889
7899
 
@@ -9495,6 +9505,7 @@ var Launcher = class {
9495
9505
  const terminal = req.fds.stdioTerminal();
9496
9506
  const handle = spawnWasmProcess({
9497
9507
  pid,
9508
+ ...req.ignored ? { ignored: req.ignored } : {},
9498
9509
  program: req.program,
9499
9510
  argv0: req.argv0,
9500
9511
  args: req.args,
@@ -9599,6 +9610,7 @@ var Launcher = class {
9599
9610
  fds,
9600
9611
  report,
9601
9612
  ppid,
9613
+ ignored: this.ignoredBy(ppid),
9602
9614
  ...exec
9603
9615
  });
9604
9616
  return childHandle(handle);
@@ -9606,7 +9618,19 @@ var Launcher = class {
9606
9618
  }
9607
9619
  forker(ppid, parent) {
9608
9620
  const { exec: _exec, ...image } = parent;
9609
- return async (state, fds) => childHandle(this.start({ ...image, cwd: state.cwd ?? parent.cwd, fds, ppid, fork: state }));
9621
+ return async (state, fds) => childHandle(
9622
+ this.start({
9623
+ ...image,
9624
+ cwd: state.cwd ?? parent.cwd,
9625
+ fds,
9626
+ ppid,
9627
+ fork: state,
9628
+ ignored: this.ignoredBy(ppid, true)
9629
+ })
9630
+ );
9631
+ }
9632
+ ignoredBy(pid, fork = false) {
9633
+ return this.processes.get(pid)?.ignoredSignals(fork) ?? 0;
9610
9634
  }
9611
9635
  kill(pid, sig) {
9612
9636
  if (pid < 0) return this.jobs.killGroup(-pid, sig);