@ai-ecoverse/slicc-kernel 1.26.3 → 1.26.5

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
@@ -6709,8 +6709,10 @@ var VfsNodes = class {
6709
6709
  for (const [p, node] of this.byPath) if (within3(p, path)) await node.serial(() => node.flush());
6710
6710
  }
6711
6711
  async unlinking(path) {
6712
- const node = this.byPath.get(path);
6713
- if (node) await node.serial(async () => void await Promise.all([node.keep(), node.limit()]));
6712
+ for (const [held, node] of [...this.byPath]) {
6713
+ if (!within3(held, path)) continue;
6714
+ await node.serial(async () => void await Promise.all([node.keep(), node.limit()]));
6715
+ }
6714
6716
  }
6715
6717
  revoke(prefix) {
6716
6718
  for (const [path, node] of this.byPath) {
@@ -6720,10 +6722,11 @@ var VfsNodes = class {
6720
6722
  }
6721
6723
  }
6722
6724
  unlinked(path) {
6723
- const node = this.byPath.get(path);
6724
- if (!node) return;
6725
- node.orphaned = true;
6726
- this.byPath.delete(path);
6725
+ for (const [held, node] of [...this.byPath]) {
6726
+ if (!within3(held, path)) continue;
6727
+ node.orphaned = true;
6728
+ this.byPath.delete(held);
6729
+ }
6727
6730
  }
6728
6731
  renamed(from, to) {
6729
6732
  if (from === to) return;
@@ -6797,6 +6800,23 @@ async function refuseReadonly(fs, path, flags, opts = {}) {
6797
6800
  const st = own ?? await stat(await targetDir(fs, path));
6798
6801
  if (st?.readonly) throw new KernelError("EROFS");
6799
6802
  }
6803
+ function keepingOpen(fs, nodes) {
6804
+ return {
6805
+ ...fs,
6806
+ async rm(path, options) {
6807
+ const at = fs.resolvePath("/", path);
6808
+ await nodes.unlinking(at);
6809
+ await fs.rm(path, options);
6810
+ nodes.unlinked(at);
6811
+ },
6812
+ async rename(from, to) {
6813
+ const [a, b] = [fs.resolvePath("/", from), fs.resolvePath("/", to)];
6814
+ await nodes.unlinking(b);
6815
+ await fs.rename(from, to);
6816
+ nodes.renamed(a, b);
6817
+ }
6818
+ };
6819
+ }
6800
6820
  function vfsFile(fs, opts, nodes) {
6801
6821
  const access = opts.flags & O_ACCMODE;
6802
6822
  const readable = access !== O_WRONLY;
@@ -6972,6 +6992,7 @@ var WasmProcess = class {
6972
6992
  children;
6973
6993
  caught = 0;
6974
6994
  ignored = 0;
6995
+ inherited = 0;
6975
6996
  interrupt = new AbortController();
6976
6997
  execChild;
6977
6998
  execTermsig;
@@ -6989,12 +7010,19 @@ var WasmProcess = class {
6989
7010
  this.pid = pid;
6990
7011
  this.fds = fds;
6991
7012
  this.options = options;
7013
+ this.inherited = options.ignored ?? 0;
6992
7014
  this.children = new ChildTable(fds, options.spawner, options.forker);
6993
- this.nodes = new VfsNodes(options.fs);
6994
- options.openFiles?.add(this.nodes);
7015
+ this.nodes = options.nodes ?? new VfsNodes(options.fs);
7016
+ if (!options.nodes) options.openFiles?.add(this.nodes);
6995
7017
  this.children.onChildState = () => this.signal(SIG.CHLD);
6996
7018
  this.children.onReap = options.onReap;
6997
7019
  }
7020
+ ignores(bit) {
7021
+ return ((this.ignored | this.inherited & ~this.caught) & bit) !== 0;
7022
+ }
7023
+ inheritable(fork = false) {
7024
+ return ((fork ? 0 : this.ignored) | this.inherited) & ~this.caught;
7025
+ }
6998
7026
  signal(sig) {
6999
7027
  if (this.execChild !== void 0) {
7000
7028
  void Promise.resolve(this.options.kill?.(this.execChild, sig)).catch(() => void 0);
@@ -7004,7 +7032,7 @@ var WasmProcess = class {
7004
7032
  if (sig === SIG.CONT) this.cont();
7005
7033
  if (sig === SIG.STOP) return this.stop(sig);
7006
7034
  const bit = sigbit(sig);
7007
- if (this.ignored & bit) return "ignore";
7035
+ if (this.ignores(bit)) return "ignore";
7008
7036
  if (!(this.caught & bit)) {
7009
7037
  const action = defaultAction(sig);
7010
7038
  return action === "stop" ? this.stop(sig) : action;
@@ -7303,7 +7331,7 @@ var WasmProcess = class {
7303
7331
  if (session !== void 0 && session !== tty) return;
7304
7332
  const pgid = this.pgid();
7305
7333
  if (jobs.tcgetpgrp(tty, this.sid()) === pgid) return;
7306
- if (this.ignored & sigbit(SIG.TTIN)) throw new KernelError("EIO");
7334
+ if (this.ignores(sigbit(SIG.TTIN))) throw new KernelError("EIO");
7307
7335
  jobs.killGroup(pgid, SIG.TTIN);
7308
7336
  throw new KernelError("EINTR");
7309
7337
  }
@@ -7488,7 +7516,7 @@ var WasmProcess = class {
7488
7516
  this.asyncOps.close();
7489
7517
  for (const pid of this.children.pids()) this.options.onReap?.(pid);
7490
7518
  await this.fds.closeAll();
7491
- this.options.openFiles?.delete(this.nodes);
7519
+ if (!this.options.nodes) this.options.openFiles?.delete(this.nodes);
7492
7520
  await this.options.http?.closeAll();
7493
7521
  }
7494
7522
  };
@@ -7531,12 +7559,14 @@ function spawnWasmProcess(opts) {
7531
7559
  const sab = new SharedArrayBuffer(SAB_HEADER_BYTES + SAB_DEFAULT_WINDOW_BYTES);
7532
7560
  const header3 = new Int32Array(sab, 0, SAB_HEADER_I32);
7533
7561
  const process = new WasmProcess(opts.pid, opts.fds, {
7562
+ ...opts.ignored ? { ignored: opts.ignored } : {},
7534
7563
  spawner: opts.spawner,
7535
7564
  forker: opts.forker,
7536
7565
  fs: opts.fs,
7537
7566
  kill: opts.kill,
7538
7567
  processes: opts.processes,
7539
7568
  openFiles: opts.openFiles,
7569
+ ...opts.nodes ? { nodes: opts.nodes } : {},
7540
7570
  mounts: opts.mounts,
7541
7571
  ...opts.mount ? { mount: opts.mount } : {},
7542
7572
  ...opts.umount ? { umount: opts.umount } : {},
@@ -7673,7 +7703,8 @@ function spawnWasmProcess(opts) {
7673
7703
  signal,
7674
7704
  termsig: () => endedBy,
7675
7705
  onState: (listener) => process.onState(listener),
7676
- memory: () => Atomics.load(header3, SAB_I_MEMORY) * 65536
7706
+ memory: () => Atomics.load(header3, SAB_I_MEMORY) * 65536,
7707
+ ignoredSignals: (fork) => process.inheritable(fork)
7677
7708
  };
7678
7709
  }
7679
7710
 
@@ -9103,6 +9134,7 @@ var Launcher = class {
9103
9134
  fstabRetries;
9104
9135
  inserted = /* @__PURE__ */ new Map();
9105
9136
  openFiles = /* @__PURE__ */ new Set();
9137
+ nodes;
9106
9138
  held = /* @__PURE__ */ new Set();
9107
9139
  processMounts;
9108
9140
  booting = new AbortController();
@@ -9136,7 +9168,10 @@ var Launcher = class {
9136
9168
  ca: this.ca
9137
9169
  });
9138
9170
  enableCdp(this.net, this.cdp);
9139
- this.fs = withCommandDirs(this.base, async () => new Set((await this.commands()).keys()));
9171
+ const fs = withCommandDirs(this.base, async () => new Set((await this.commands()).keys()));
9172
+ this.nodes = new VfsNodes(fs);
9173
+ this.openFiles.add(this.nodes);
9174
+ this.fs = keepingOpen(fs, this.nodes);
9140
9175
  this.watchers.watch([this.modulesDir, this.pnpmHome], { recursive: true }, () => {
9141
9176
  this.catalog = void 0;
9142
9177
  });
@@ -9294,6 +9329,7 @@ var Launcher = class {
9294
9329
  const terminal = req.fds.stdioTerminal();
9295
9330
  const handle = spawnWasmProcess({
9296
9331
  pid,
9332
+ ...req.ignored ? { ignored: req.ignored } : {},
9297
9333
  program: req.program,
9298
9334
  argv0: req.argv0,
9299
9335
  args: req.args,
@@ -9308,6 +9344,7 @@ var Launcher = class {
9308
9344
  kill: (target, sig) => this.kill(target, sig),
9309
9345
  processes: () => ({ boot: this.boot, processes: this.list() }),
9310
9346
  openFiles: this.openFiles,
9347
+ nodes: this.nodes,
9311
9348
  held: this.held,
9312
9349
  statfs: (path) => this.mounts.statfs(path),
9313
9350
  mounts: () => this.mounts.list(),
@@ -9398,6 +9435,7 @@ var Launcher = class {
9398
9435
  fds,
9399
9436
  report,
9400
9437
  ppid,
9438
+ ignored: this.ignoredBy(ppid),
9401
9439
  ...exec
9402
9440
  });
9403
9441
  return childHandle(handle);
@@ -9405,7 +9443,19 @@ var Launcher = class {
9405
9443
  }
9406
9444
  forker(ppid, parent) {
9407
9445
  const { exec: _exec, ...image } = parent;
9408
- return async (state, fds) => childHandle(this.start({ ...image, cwd: state.cwd ?? parent.cwd, fds, ppid, fork: state }));
9446
+ return async (state, fds) => childHandle(
9447
+ this.start({
9448
+ ...image,
9449
+ cwd: state.cwd ?? parent.cwd,
9450
+ fds,
9451
+ ppid,
9452
+ fork: state,
9453
+ ignored: this.ignoredBy(ppid, true)
9454
+ })
9455
+ );
9456
+ }
9457
+ ignoredBy(pid, fork = false) {
9458
+ return this.processes.get(pid)?.ignoredSignals(fork) ?? 0;
9409
9459
  }
9410
9460
  kill(pid, sig) {
9411
9461
  if (pid < 0) return this.jobs.killGroup(-pid, sig);