@ai-ecoverse/slicc-kernel 1.17.0 → 1.17.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
@@ -6051,8 +6051,9 @@ var WasmProcess = class {
6051
6051
  case "proc-fork":
6052
6052
  return { ok: true, kind: "json", json: await this.children.fork(req.state) };
6053
6053
  case "proc-spawn": {
6054
- const { file, argv, env, cwd, stdio, inherit } = req;
6055
- const pid = await this.children.spawn({ file, argv, env, cwd }, stdio, inherit);
6054
+ const { file, argv, env, cwd, stdio, inherit, exec } = req;
6055
+ const spawned = { file, argv, env, cwd, ...exec ? { exec } : {} };
6056
+ const pid = await this.children.spawn(spawned, stdio, inherit);
6056
6057
  return { ok: true, kind: "json", json: pid };
6057
6058
  }
6058
6059
  case "proc-wait": {
@@ -6319,7 +6320,7 @@ function spawnWasmProcess(opts) {
6319
6320
  });
6320
6321
  const tinit = {
6321
6322
  type: WASM_THREAD_INIT,
6322
- pid: opts.pid,
6323
+ pid: opts.shownPid ?? opts.pid,
6323
6324
  program: opts.program,
6324
6325
  argv0: opts.argv0,
6325
6326
  args: opts.args,
@@ -6333,7 +6334,7 @@ function spawnWasmProcess(opts) {
6333
6334
  };
6334
6335
  const init = {
6335
6336
  type: WASM_PROCESS_INIT,
6336
- pid: opts.pid,
6337
+ pid: opts.shownPid ?? opts.pid,
6337
6338
  program: opts.program,
6338
6339
  argv0: opts.argv0,
6339
6340
  args: opts.args,
@@ -6383,12 +6384,22 @@ var JobTable = class {
6383
6384
  remove(pid) {
6384
6385
  this.members.delete(pid);
6385
6386
  }
6386
- exec(pid, child) {
6387
+ exec(pid, child, adopt = false) {
6387
6388
  const member = this.members.get(child);
6389
+ if (member && adopt) member.shownAs = this.shown(pid);
6388
6390
  if (member) member.execParent = pid;
6389
6391
  const execer = this.members.get(pid);
6390
6392
  if (execer) execer.execed = true;
6391
6393
  }
6394
+ shown(pid) {
6395
+ let member = this.members.get(pid);
6396
+ for (let up = member; up; up = this.members.get(up.execParent ?? -1)) member = up;
6397
+ return member?.pid ?? pid;
6398
+ }
6399
+ shownParent(pid) {
6400
+ const parent = this.members.get(this.shown(pid))?.ppid;
6401
+ return parent === void 0 ? void 0 : this.shown(parent);
6402
+ }
6392
6403
  pgidOf(pid) {
6393
6404
  return this.members.get(pid)?.pgid;
6394
6405
  }
@@ -6397,34 +6408,46 @@ var JobTable = class {
6397
6408
  if (!member) throw new KernelError("ESRCH");
6398
6409
  return member;
6399
6410
  }
6411
+ idOf(pid) {
6412
+ return this.members.get(pid)?.shownAs ?? pid;
6413
+ }
6414
+ byId(id) {
6415
+ for (const member of this.members.values()) if (member.shownAs === id) return member;
6416
+ return this.member(id);
6417
+ }
6400
6418
  setpgid(caller, pid, pgid) {
6401
- const target = this.member(pid || caller);
6402
- const group = pgid || target.pid;
6419
+ const me = this.idOf(caller);
6420
+ const target = this.byId(pid || me);
6421
+ const id = this.idOf(target.pid);
6422
+ const group = pgid || id;
6403
6423
  if (group < 0) throw new KernelError("EINVAL");
6404
6424
  const self = this.member(caller);
6405
- if (target.pid !== caller) {
6406
- if (target.ppid !== caller) throw new KernelError("ESRCH");
6425
+ if (id !== me) {
6426
+ if (target.ppid === void 0 || this.idOf(target.ppid) !== me) {
6427
+ throw new KernelError("ESRCH");
6428
+ }
6407
6429
  if (target.execed) throw new KernelError("EACCES");
6408
6430
  }
6409
6431
  if (target.sid !== self.sid) throw new KernelError("EPERM");
6410
- if (target.pid === target.sid) throw new KernelError("EPERM");
6432
+ if (id === target.sid) throw new KernelError("EPERM");
6411
6433
  const exists = [...this.members.values()].some((m) => m.pgid === group && m.sid === target.sid);
6412
- if (group !== target.pid && !exists) throw new KernelError("EPERM");
6434
+ if (group !== id && !exists) throw new KernelError("EPERM");
6413
6435
  target.pgid = group;
6414
6436
  }
6415
6437
  getpgid(caller, pid) {
6416
- return this.member(pid || caller).pgid;
6438
+ return this.byId(pid || this.idOf(caller)).pgid;
6417
6439
  }
6418
6440
  getsid(caller, pid) {
6419
- return this.member(pid || caller).sid;
6441
+ return this.byId(pid || this.idOf(caller)).sid;
6420
6442
  }
6421
6443
  setsid(pid) {
6422
6444
  const member = this.member(pid);
6423
- if (member.pgid === pid) throw new KernelError("EPERM");
6424
- member.sid = pid;
6425
- member.pgid = pid;
6426
- this.terminals.delete(pid);
6427
- return pid;
6445
+ const id = this.idOf(pid);
6446
+ if (member.pgid === id) throw new KernelError("EPERM");
6447
+ member.sid = id;
6448
+ member.pgid = id;
6449
+ this.terminals.delete(id);
6450
+ return id;
6428
6451
  }
6429
6452
  terminalNamed(name2) {
6430
6453
  const known = /* @__PURE__ */ new Set([...this.terminals.values(), ...this.foreground.keys()]);
@@ -6436,9 +6459,10 @@ var JobTable = class {
6436
6459
  }
6437
6460
  acquireTerminal(pid, tty) {
6438
6461
  const member = this.members.get(pid);
6439
- if (!member || member.sid !== pid || this.terminals.has(pid)) return false;
6462
+ const id = this.idOf(pid);
6463
+ if (!member || member.sid !== id || this.terminals.has(id)) return false;
6440
6464
  if ([...this.terminals.values()].includes(tty)) return false;
6441
- this.terminals.set(pid, tty);
6465
+ this.terminals.set(id, tty);
6442
6466
  this.foreground.set(tty, member.pgid);
6443
6467
  return true;
6444
6468
  }
@@ -7783,10 +7807,11 @@ var Launcher = class {
7783
7807
  locks: this.locks,
7784
7808
  onReap: (child) => this.reaped(child),
7785
7809
  ...req.fork ? { fork: req.fork } : {},
7786
- ...req.ppid !== void 0 ? { ppid: req.ppid } : {}
7810
+ ...this.shownIds(req)
7787
7811
  });
7788
7812
  this.processes.set(pid, handle);
7789
7813
  this.jobs.add(pid, req.ppid, (sig) => handle.signal(sig), terminal);
7814
+ if (req.exec && req.ppid !== void 0) this.jobs.exec(req.ppid, pid, true);
7790
7815
  this.described.set(pid, {
7791
7816
  argv: [req.argv0, ...req.args],
7792
7817
  tty: terminal?.name ?? null,
@@ -7799,6 +7824,12 @@ var Launcher = class {
7799
7824
  });
7800
7825
  return handle;
7801
7826
  }
7827
+ shownIds(req) {
7828
+ if (req.ppid === void 0) return {};
7829
+ if (!req.exec) return { ppid: this.jobs.shown(req.ppid) };
7830
+ const ppid = this.jobs.shownParent(req.ppid);
7831
+ return { shownPid: this.jobs.shown(req.ppid), ...ppid !== void 0 ? { ppid } : {} };
7832
+ }
7802
7833
  forget(pid) {
7803
7834
  this.jobs.remove(pid);
7804
7835
  this.described.delete(pid);
@@ -7846,12 +7877,21 @@ var Launcher = class {
7846
7877
  await fds.closeAll();
7847
7878
  throw new SpawnError(await this.unrunnable(req.file, req.cwd));
7848
7879
  }
7849
- const handle = await this.launch(planned, { env: req.env, cwd: req.cwd, fds, report, ppid });
7880
+ const exec = req.exec ? { exec: true } : {};
7881
+ const handle = await this.launch(planned, {
7882
+ env: req.env,
7883
+ cwd: req.cwd,
7884
+ fds,
7885
+ report,
7886
+ ppid,
7887
+ ...exec
7888
+ });
7850
7889
  return childHandle(handle);
7851
7890
  };
7852
7891
  }
7853
7892
  forker(ppid, parent) {
7854
- return async (state, fds) => childHandle(this.start({ ...parent, cwd: state.cwd ?? parent.cwd, fds, ppid, fork: state }));
7893
+ const { exec: _exec, ...image } = parent;
7894
+ return async (state, fds) => childHandle(this.start({ ...image, cwd: state.cwd ?? parent.cwd, fds, ppid, fork: state }));
7855
7895
  }
7856
7896
  kill(pid, sig) {
7857
7897
  if (pid < 0) return this.jobs.killGroup(-pid, sig);