@ai-ecoverse/slicc-kernel 1.71.0 → 1.72.0

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.
@@ -1818,6 +1818,7 @@ var init_wasi_fds = __esm({
1818
1818
  }
1819
1819
  }
1820
1820
  resolve(dirfd, path) {
1821
+ if (path === "") throw new WasiError("ENOENT");
1821
1822
  const joined2 = path.startsWith("/") ? path : `${this.dir(dirfd).path}/${path}`;
1822
1823
  return joined2.split("/").includes("..") ? physical(this.fs, joined2) : normalize(joined2);
1823
1824
  }
@@ -2728,7 +2729,11 @@ var init_wasi_host = __esm({
2728
2729
  o.fs.rename(from, to);
2729
2730
  fds.renamed(from, to, replaced);
2730
2731
  },
2731
- path_symlink: (tp, tl, dirfd, p, l) => void o.fs.symlink(mem.string(tp, tl), at(dirfd, p, l)),
2732
+ path_symlink: (tp, tl, dirfd, p, l) => {
2733
+ const path = at(dirfd, p, l);
2734
+ if (tl === 0) throw new WasiError("ENOENT");
2735
+ o.fs.symlink(mem.string(tp, tl), path);
2736
+ },
2732
2737
  path_readlink: (dirfd, p, l, buf, len, used) => {
2733
2738
  const target = new TextEncoder().encode(o.fs.readlink(at(dirfd, p, l)));
2734
2739
  const n = Math.min(len, target.length);
@@ -3874,6 +3879,11 @@ var init_js_kernel = __esm({
3874
3879
  freeze() {
3875
3880
  while (Atomics.load(this.header, SAB_I_STOP) === 1) Atomics.wait(this.header, SAB_I_STOP, 1);
3876
3881
  }
3882
+ disposition(sig) {
3883
+ if (this.handlers.has(sig)) return "caught";
3884
+ if (this.ignored & sigbit(sig)) return "ignored";
3885
+ return defaultAction(sig);
3886
+ }
3877
3887
  setHandler(sig, handler) {
3878
3888
  if (sig === SIG.KILL || sig === SIG.STOP) {
3879
3889
  return Promise.reject(new JsCallError("EINVAL", "signal"));
@@ -4527,7 +4537,7 @@ function settled(lane, writes) {
4527
4537
  });
4528
4538
  return out;
4529
4539
  }
4530
- function exitAtOnce(lane, writes, modes, status2) {
4540
+ function exitAtOnce(lane, writes, modes, status2, last = { op: "proc-exit", status: status2 & 255 }) {
4531
4541
  const done = settled(lane, writes);
4532
4542
  const broken = /* @__PURE__ */ new Set();
4533
4543
  for (const w of writes) {
@@ -4537,7 +4547,7 @@ function exitAtOnce(lane, writes, modes, status2) {
4537
4547
  if (!writeOut(lane, w.fd, w.data.subarray(w.at + (sent ?? 0)))) broken.add(w.fd);
4538
4548
  }
4539
4549
  for (const mode of modes) restoreMode(lane, mode);
4540
- lane({ op: "proc-exit", status: status2 & 255 });
4550
+ lane(last);
4541
4551
  const parked = new Int32Array(new SharedArrayBuffer(4));
4542
4552
  for (; ; ) Atomics.wait(parked, 0, 0);
4543
4553
  }
@@ -5355,7 +5365,7 @@ var init_sync_sab_bridge = __esm({
5355
5365
 
5356
5366
  // src/process/js/js-sync.ts
5357
5367
  function laneOf(lane) {
5358
- if (!lane) return () => ({ ok: false, errno: "ENOSYS", message: "no sync lane" });
5368
+ if (!lane) return noLane;
5359
5369
  const transport = createSyncSabTransport(lane.sab, lane.port);
5360
5370
  return (req) => transport.call(req, Number.POSITIVE_INFINITY, req.op);
5361
5371
  }
@@ -5556,7 +5566,7 @@ function syncPathOps(kernel, resolve, statOf, open) {
5556
5566
  }
5557
5567
  };
5558
5568
  }
5559
- var encoder3, JsSyncKernel;
5569
+ var encoder3, noLane, JsSyncKernel;
5560
5570
  var init_js_sync = __esm({
5561
5571
  "src/process/js/js-sync.ts"() {
5562
5572
  "use strict";
@@ -5567,6 +5577,7 @@ var init_js_sync = __esm({
5567
5577
  init_js_io();
5568
5578
  init_js_kernel();
5569
5579
  encoder3 = new TextEncoder();
5580
+ noLane = () => ({ ok: false, errno: "ENOSYS", message: "no sync lane" });
5570
5581
  JsSyncKernel = class {
5571
5582
  lane;
5572
5583
  kernel;
@@ -5881,6 +5892,30 @@ function resolvePath(cwd, path) {
5881
5892
  }
5882
5893
  return `/${parts.join("/")}`;
5883
5894
  }
5895
+ function killer(d) {
5896
+ return (pid, signal = "SIGTERM") => {
5897
+ const sig = signal === 0 ? 0 : signalNumber(signal);
5898
+ const self = sig !== 0 && includesSelf(d.syncKernel, d.self, pid);
5899
+ if (!self || d.kernel.disposition(sig) !== "terminate") {
5900
+ d.syncKernel.call({ op: "proc-kill", pid, sig });
5901
+ return;
5902
+ }
5903
+ const target = pid === d.self ? {} : { target: pid };
5904
+ const r = d.lane({ op: "proc-kill-self", sig, ...target, probe: true });
5905
+ if (!r.ok) throw new JsCallError(r.errno, "kill");
5906
+ if (r.kind === "void") return;
5907
+ exitAtOnce(d.lane, [...d.writes], d.modes(), 128 + sig, {
5908
+ op: "proc-kill-self",
5909
+ sig,
5910
+ ...target
5911
+ });
5912
+ };
5913
+ }
5914
+ function includesSelf(kernel, self, pid) {
5915
+ if (pid === self || pid === 0) return true;
5916
+ if (pid > 0 || pid === -1) return false;
5917
+ return kernel.json({ op: "proc-getpgid", pid: 0 }) === -pid;
5918
+ }
5884
5919
  function writer(kernel, info, pid) {
5885
5920
  const writes = /* @__PURE__ */ new Set();
5886
5921
  const sendAll = async (fd, data, i, w, signal) => {
@@ -5992,7 +6027,7 @@ function createContext(o) {
5992
6027
  };
5993
6028
  const fs = pathOps(kernel, resolve, statOf, open);
5994
6029
  const lane = o.lane ?? laneOf(void 0);
5995
- if (o.lane) kernel.syncLane = o.lane;
6030
+ if (o.lane && o.lane !== noLane) kernel.syncLane = o.lane;
5996
6031
  const syncKernel = new JsSyncKernel(lane, kernel, unwind);
5997
6032
  const terminal = ttyOps(kernel);
5998
6033
  const sync = {
@@ -6001,7 +6036,8 @@ function createContext(o) {
6001
6036
  exit: (status2 = 0) => {
6002
6037
  exiting ??= status2 & 255;
6003
6038
  return exitAtOnce(lane, [...writes], terminal.modes(), exiting);
6004
- }
6039
+ },
6040
+ kill: killer({ self: o.pid, kernel, syncKernel, lane, writes, modes: terminal.modes })
6005
6041
  };
6006
6042
  const io = { read: read2, send: writeAll, close: (fd) => ctx.close(fd) };
6007
6043
  const children = childOps(kernel, io, { env: o.env, cwd: o.cwd, signal: signalNumber });