@ai-ecoverse/slicc-kernel 1.50.0 → 1.51.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.
@@ -9,8 +9,8 @@ var __esm = (fn, res, err) => function __init() {
9
9
  }
10
10
  };
11
11
  var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
12
+ for (var name2 in all)
13
+ __defProp(target, name2, { get: all[name2], enumerable: true });
14
14
  };
15
15
 
16
16
  // src/process/js/lockdown.ts
@@ -23,22 +23,22 @@ function chain(target) {
23
23
  return out;
24
24
  }
25
25
  function hide(target, names) {
26
- for (const name of names) {
26
+ for (const name2 of names) {
27
27
  const holders = chain(target);
28
28
  for (const holder of holders) {
29
- if (Object.getOwnPropertyDescriptor(holder, name)?.configurable) {
30
- Reflect.deleteProperty(holder, name);
29
+ if (Object.getOwnPropertyDescriptor(holder, name2)?.configurable) {
30
+ Reflect.deleteProperty(holder, name2);
31
31
  }
32
32
  }
33
- const kept = holders.slice(1).some((holder) => Object.hasOwn(holder, name));
34
- const defined = Reflect.defineProperty(target, name, {
33
+ const kept = holders.slice(1).some((holder) => Object.hasOwn(holder, name2));
34
+ const defined = Reflect.defineProperty(target, name2, {
35
35
  value: void 0,
36
36
  writable: false,
37
37
  enumerable: false,
38
38
  configurable: false
39
39
  });
40
- if (kept || !defined && Reflect.get(target, name) !== void 0) {
41
- throw new Error(`slicc-kernel: cannot withhold ${name} from a JS program`);
40
+ if (kept || !defined && Reflect.get(target, name2) !== void 0) {
41
+ throw new Error(`slicc-kernel: cannot withhold ${name2} from a JS program`);
42
42
  }
43
43
  }
44
44
  }
@@ -75,11 +75,11 @@ var init_lockdown = __esm({
75
75
  // src/process/wasi/wasi-abi.ts
76
76
  function wasiErrnoOf(code2) {
77
77
  if (!code2) return E.IO;
78
- const name = code2.startsWith("E") ? code2.slice(1) : code2;
79
- if (name === "OPNOTSUPP") return E.NOTSUP;
80
- if (name === "WOULDBLOCK") return E.AGAIN;
81
- if (name === "NOMEDIUM") return E.NODEV;
82
- return E[name] ?? E.IO;
78
+ const name2 = code2.startsWith("E") ? code2.slice(1) : code2;
79
+ if (name2 === "OPNOTSUPP") return E.NOTSUP;
80
+ if (name2 === "WOULDBLOCK") return E.AGAIN;
81
+ if (name2 === "NOMEDIUM") return E.NODEV;
82
+ return E[name2] ?? E.IO;
83
83
  }
84
84
  function wasixSignal(sig) {
85
85
  return Number.isInteger(sig) && sig >= 1 && sig <= 31 ? sig : void 0;
@@ -520,10 +520,10 @@ function cachingBridge(bridge, now = () => performance.now()) {
520
520
  readdirStat: (p) => {
521
521
  const list = bridge.readdirStat(p);
522
522
  const base = p === "/" ? "" : p;
523
- for (const [name, st] of list) {
523
+ for (const [name2, st] of list) {
524
524
  if (!st) continue;
525
- lstats.set(`${base}/${name}`, st);
526
- if (!st.isSymbolicLink) stats.set(`${base}/${name}`, st);
525
+ lstats.set(`${base}/${name2}`, st);
526
+ if (!st.isSymbolicLink) stats.set(`${base}/${name2}`, st);
527
527
  }
528
528
  return list;
529
529
  },
@@ -1076,8 +1076,8 @@ var init_wasi_fds = __esm({
1076
1076
  } catch {
1077
1077
  return out;
1078
1078
  }
1079
- for (const name of [.../* @__PURE__ */ new Set([...names, "dev", ...SYNTHETIC_DIRS])].sort()) {
1080
- const path = `/${name}`;
1079
+ for (const name2 of [.../* @__PURE__ */ new Set([...names, "dev", ...SYNTHETIC_DIRS])].sort()) {
1080
+ const path = `/${name2}`;
1081
1081
  if (path === "/dev") {
1082
1082
  out.push({ type: "dir", path, preopen: path });
1083
1083
  continue;
@@ -1813,8 +1813,8 @@ function kernelFiletype(kind) {
1813
1813
  return { filetype: FILETYPE.UNKNOWN, seeks: false };
1814
1814
  }
1815
1815
  }
1816
- function direntRecord(next2, ino, name, filetype) {
1817
- const nameBytes = new TextEncoder().encode(name);
1816
+ function direntRecord(next2, ino, name2, filetype) {
1817
+ const nameBytes = new TextEncoder().encode(name2);
1818
1818
  const record = new Uint8Array(SIZE.DIRENT + nameBytes.length);
1819
1819
  const v = new DataView(record.buffer);
1820
1820
  v.setBigUint64(0, BigInt(next2), true);
@@ -1826,8 +1826,8 @@ function direntRecord(next2, ino, name, filetype) {
1826
1826
  }
1827
1827
  function wrap(table) {
1828
1828
  const out = {};
1829
- for (const [name, fn] of Object.entries(table)) {
1830
- out[name] = (...args) => {
1829
+ for (const [name2, fn] of Object.entries(table)) {
1830
+ out[name2] = (...args) => {
1831
1831
  try {
1832
1832
  return fn(...args) ?? E.SUCCESS;
1833
1833
  } catch (e) {
@@ -1888,8 +1888,8 @@ var init_wasi_host = __esm({
1888
1888
  return kernel.call(req);
1889
1889
  };
1890
1890
  const sys = new Proxy(kernel.sys, {
1891
- get: (target, name) => {
1892
- const member = Reflect.get(target, name);
1891
+ get: (target, name2) => {
1892
+ const member = Reflect.get(target, name2);
1893
1893
  if (typeof member !== "function") return member;
1894
1894
  return (...args) => {
1895
1895
  this.fds.flushEarly();
@@ -2117,13 +2117,13 @@ var init_wasi_host = __esm({
2117
2117
  } else if (e.type === "dir") this.setTimes(e.path, atim, mtim, flags);
2118
2118
  },
2119
2119
  fd_prestat_get: (fd, out) => {
2120
- const name = new TextEncoder().encode(fds.preopen(fd).preopen);
2120
+ const name2 = new TextEncoder().encode(fds.preopen(fd).preopen);
2121
2121
  mem.view().setUint8(out, PREOPENTYPE_DIR);
2122
- mem.view().setUint32(out + 4, name.length, true);
2122
+ mem.view().setUint32(out + 4, name2.length, true);
2123
2123
  },
2124
2124
  fd_prestat_dir_name: (fd, buf, len) => {
2125
- const name = new TextEncoder().encode(fds.preopen(fd).preopen);
2126
- mem.bytes(buf, Math.min(len, name.length)).set(name.subarray(0, len));
2125
+ const name2 = new TextEncoder().encode(fds.preopen(fd).preopen);
2126
+ mem.bytes(buf, Math.min(len, name2.length)).set(name2.subarray(0, len));
2127
2127
  },
2128
2128
  fd_readdir: (fd, buf, len, cookie, used) => void this.readdir(fd, buf, len, Number(cookie), used)
2129
2129
  };
@@ -2402,14 +2402,14 @@ var init_wasi_host = __esm({
2402
2402
  const { names, stats } = dir.listing;
2403
2403
  let at = 0;
2404
2404
  for (let i = cookie; i < names.length && at < len; i++) {
2405
- const name = names[i];
2406
- const full = name === "." ? dir.path : name === ".." ? normalize(`${dir.path}/..`) : resolveUnder(dir.path, name);
2407
- if (!stats.has(name)) stats.set(name, this.lstatOrNull(full));
2408
- const st = stats.get(name) ?? null;
2405
+ const name2 = names[i];
2406
+ const full = name2 === "." ? dir.path : name2 === ".." ? normalize(`${dir.path}/..`) : resolveUnder(dir.path, name2);
2407
+ if (!stats.has(name2)) stats.set(name2, this.lstatOrNull(full));
2408
+ const st = stats.get(name2) ?? null;
2409
2409
  const record = direntRecord(
2410
2410
  i + 1,
2411
2411
  st?.ino !== void 0 ? BigInt(st.ino) : pathInode(full),
2412
- name,
2412
+ name2,
2413
2413
  filetypeOf(st)
2414
2414
  );
2415
2415
  const n = Math.min(record.length, len - at);
@@ -2421,7 +2421,7 @@ var init_wasi_host = __esm({
2421
2421
  list(path) {
2422
2422
  const { fs } = this.o;
2423
2423
  const listed = fs.readdirStat(path);
2424
- return { names: [".", "..", ...listed.map(([name]) => name)], stats: new Map(listed) };
2424
+ return { names: [".", "..", ...listed.map(([name2]) => name2)], stats: new Map(listed) };
2425
2425
  }
2426
2426
  lstatOrNull(path) {
2427
2427
  try {
@@ -2483,18 +2483,18 @@ var init_wasix_process = __esm({
2483
2483
  environment() {
2484
2484
  return { ...this.host.o.env, PWD: this.host.cwd };
2485
2485
  }
2486
- locate(name, search, path) {
2487
- if (name.includes("/"))
2488
- return name.startsWith("/") ? name : normalize(`${this.host.cwd}/${name}`);
2489
- if (!search) return name;
2486
+ locate(name2, search, path) {
2487
+ if (name2.includes("/"))
2488
+ return name2.startsWith("/") ? name2 : normalize(`${this.host.cwd}/${name2}`);
2489
+ if (!search) return name2;
2490
2490
  for (const dir of path.split(":")) {
2491
2491
  if (!dir) continue;
2492
2492
  const candidate = normalize(
2493
- `${dir.startsWith("/") ? "" : `${this.host.cwd}/`}${dir}/${name}`
2493
+ `${dir.startsWith("/") ? "" : `${this.host.cwd}/`}${dir}/${name2}`
2494
2494
  );
2495
2495
  if (this.host.o.fs.exists(candidate)) return candidate;
2496
2496
  }
2497
- return name;
2497
+ return name2;
2498
2498
  }
2499
2499
  childFds(ops) {
2500
2500
  const { fds } = this.host;
@@ -2809,7 +2809,7 @@ function processes(host, call2, inThread) {
2809
2809
  const theirs = [];
2810
2810
  host.fds.promoteFiles();
2811
2811
  try {
2812
- const stdio = STDIO.map((name, n) => slot(n, o[name] ?? "inherit", mine, theirs));
2812
+ const stdio = STDIO.map((name2, n) => slot(n, o[name2] ?? "inherit", mine, theirs));
2813
2813
  const req = {
2814
2814
  op: "proc-spawn",
2815
2815
  file: o.argv[0],
@@ -2821,8 +2821,8 @@ function processes(host, call2, inThread) {
2821
2821
  };
2822
2822
  const pid = restarted(() => call2(req));
2823
2823
  const out = { pid };
2824
- STDIO.forEach((name, n) => {
2825
- if (mine[n] !== void 0) out[name] = mine[n];
2824
+ STDIO.forEach((name2, n) => {
2825
+ if (mine[n] !== void 0) out[name2] = mine[n];
2826
2826
  });
2827
2827
  return out;
2828
2828
  } catch (err) {
@@ -3388,7 +3388,7 @@ async function preflight(kernel, hows) {
3388
3388
  }
3389
3389
  }
3390
3390
  async function slots(kernel, o, mine, theirs) {
3391
- const hows = STDIO2.map((name) => o[name] ?? "inherit");
3391
+ const hows = STDIO2.map((name2) => o[name2] ?? "inherit");
3392
3392
  await preflight(kernel, hows);
3393
3393
  const stdio = [];
3394
3394
  for (const [n, how] of hows.entries()) {
@@ -3436,7 +3436,7 @@ function rewrite(hop, status2, location) {
3436
3436
  const toGet = (status2 === 301 || status2 === 302) && hop.method === "POST" || status2 === 303 && hop.method !== "GET" && hop.method !== "HEAD";
3437
3437
  const crossOrigin = next2.origin !== new URL(hop.url).origin;
3438
3438
  const headers = hop.headers.filter(
3439
- ([name]) => !(toGet && BODY_HEADERS.has(name.toLowerCase())) && !(crossOrigin && CREDENTIALS.has(name.toLowerCase()))
3439
+ ([name2]) => !(toGet && BODY_HEADERS.has(name2.toLowerCase())) && !(crossOrigin && CREDENTIALS.has(name2.toLowerCase()))
3440
3440
  );
3441
3441
  return {
3442
3442
  url: withoutFragment(next2),
@@ -3488,7 +3488,7 @@ function parameter(text, from, params) {
3488
3488
  while (SPACE.test(text[at] ?? "")) at++;
3489
3489
  let end = at;
3490
3490
  while (end < text.length && text[end] !== ";" && text[end] !== "=") end++;
3491
- const name = text.slice(at, end).toLowerCase();
3491
+ const name2 = text.slice(at, end).toLowerCase();
3492
3492
  if (text[end] !== "=") return end;
3493
3493
  const start2 = end + 1;
3494
3494
  let value2;
@@ -3501,8 +3501,8 @@ function parameter(text, from, params) {
3501
3501
  if (!value2) return end < 0 ? text.length : end;
3502
3502
  }
3503
3503
  if (end < 0) end = text.length;
3504
- if (TOKEN.test(name) && QUOTABLE.test(value2) && !params.has(name)) {
3505
- params.set(name, value2);
3504
+ if (TOKEN.test(name2) && QUOTABLE.test(value2) && !params.has(name2)) {
3505
+ params.set(name2, value2);
3506
3506
  }
3507
3507
  return end;
3508
3508
  }
@@ -3516,8 +3516,8 @@ function mimeType(input) {
3516
3516
  const params = /* @__PURE__ */ new Map();
3517
3517
  for (let at = semi < 0 ? text.length : semi; at < text.length; ) at = parameter(text, at, params);
3518
3518
  let out = `${type}/${subtype}`.toLowerCase();
3519
- for (const [name, value2] of params) {
3520
- out += `;${name}=${TOKEN.test(value2) ? value2 : `"${value2.replace(/["\\]/g, "\\$&")}"`}`;
3519
+ for (const [name2, value2] of params) {
3520
+ out += `;${name2}=${TOKEN.test(value2) ? value2 : `"${value2.replace(/["\\]/g, "\\$&")}"`}`;
3521
3521
  }
3522
3522
  return out;
3523
3523
  }
@@ -3718,7 +3718,7 @@ function fetchOp(kernel) {
3718
3718
  };
3719
3719
  for (let hops = 0; ; hops++) {
3720
3720
  const head = await send(hop, signal);
3721
- const location = head.headers.find(([name]) => name.toLowerCase() === "location")?.[1];
3721
+ const location = head.headers.find(([name2]) => name2.toLowerCase() === "location")?.[1];
3722
3722
  const follow2 = known.manualRedirects && REDIRECTS.has(head.status) && location !== void 0 && request.redirect !== "manual";
3723
3723
  if (!follow2) {
3724
3724
  const redirected = hops > 0 || head.redirected === true;
@@ -3863,9 +3863,9 @@ function port(n) {
3863
3863
  return n;
3864
3864
  }
3865
3865
  function netOps(kernel, io) {
3866
- const name = async (fd, peer) => addressOf(await kernel.json({ op: "sock-name", fd, peer }));
3866
+ const name2 = async (fd, peer) => addressOf(await kernel.json({ op: "sock-name", fd, peer }));
3867
3867
  const connection = async (fd) => {
3868
- const [local, remote] = [await name(fd, false), await name(fd, true)];
3868
+ const [local, remote] = [await name2(fd, false), await name2(fd, true)];
3869
3869
  const stop = new AbortController();
3870
3870
  let closed;
3871
3871
  const close = () => {
@@ -3947,7 +3947,7 @@ function netOps(kernel, io) {
3947
3947
  };
3948
3948
  await kernel.call({ op: "sock-bind", fd, addr });
3949
3949
  await kernel.call({ op: "sock-listen", fd, backlog: options.backlog ?? 128 });
3950
- return listener(fd, await name(fd, false));
3950
+ return listener(fd, await name2(fd, false));
3951
3951
  }),
3952
3952
  connect: async (options) => {
3953
3953
  const signal = options.signal ?? NEVER;
@@ -5078,13 +5078,13 @@ var init_js_runtime = __esm({
5078
5078
  });
5079
5079
 
5080
5080
  // src/kernel/net/loopback-names.ts
5081
- function reserved(name) {
5082
- const lower = name.toLowerCase();
5081
+ function reserved(name2) {
5082
+ const lower = name2.toLowerCase();
5083
5083
  return lower === "localhost" || lower.endsWith(".localhost") || lower === HOST_LOOPBACK || lower === "wasmer.sh" || /^\d+(\.\d+){3}$/.test(lower);
5084
5084
  }
5085
- function isHostname(name) {
5086
- if (typeof name !== "string" || name.length > 253 || reserved(name)) return false;
5087
- return name.split(".").every((l) => LABEL.test(l));
5085
+ function isHostname(name2) {
5086
+ if (typeof name2 !== "string" || name2.length > 253 || reserved(name2)) return false;
5087
+ return name2.split(".").every((l) => LABEL.test(l));
5088
5088
  }
5089
5089
  function hostnameOf(env) {
5090
5090
  return isHostname(env.HOSTNAME) ? env.HOSTNAME : DEFAULT_HOSTNAME;
@@ -5126,7 +5126,7 @@ var init_wasi_errno = __esm({
5126
5126
  "use strict";
5127
5127
  init_wasi_abi();
5128
5128
  WASI_ERRNO = {
5129
- ...Object.fromEntries(Object.entries(E).map(([name, errno2]) => [`E${name}`, errno2])),
5129
+ ...Object.fromEntries(Object.entries(E).map(([name2, errno2]) => [`E${name2}`, errno2])),
5130
5130
  EWOULDBLOCK: E.AGAIN,
5131
5131
  ENOTSUP: 138,
5132
5132
  EOPNOTSUPP: 138,
@@ -5204,8 +5204,8 @@ function createHelpers(Fs, ops) {
5204
5204
  function freshState(stat) {
5205
5205
  return { ...stat ? { stat } : {}, len: 0, loaded: false, dirty: false, openCount: 0 };
5206
5206
  }
5207
- function makeNode(parent, name, st) {
5208
- const node = Fs.createNode(parent, name, modeFromStat(st), 0);
5207
+ function makeNode(parent, name2, st) {
5208
+ const node = Fs.createNode(parent, name2, modeFromStat(st), 0);
5209
5209
  node.node_ops = ops.node;
5210
5210
  node.stream_ops = ops.stream;
5211
5211
  node.live = freshState(st);
@@ -5223,9 +5223,9 @@ function createHelpers(Fs, ops) {
5223
5223
  }
5224
5224
  return node.live.stat;
5225
5225
  }
5226
- function childPath(parent, name) {
5226
+ function childPath(parent, name2) {
5227
5227
  const base = liveNodePath(parent);
5228
- return base === "/" ? `/${name}` : `${base}/${name}`;
5228
+ return base === "/" ? `/${name2}` : `${base}/${name2}`;
5229
5229
  }
5230
5230
  function ensureLoaded(node) {
5231
5231
  const s = node.live;
@@ -5392,15 +5392,15 @@ function createNodeOps(h) {
5392
5392
  if (times) setTimes(node, path, ...times);
5393
5393
  node.live.stat = void 0;
5394
5394
  },
5395
- lookup(parent, name) {
5396
- const listed = parent.live.listed?.get(name);
5397
- parent.live.listed?.delete(name);
5398
- const st = listed ?? call2(() => bridgeOf(parent).lstat(childPath(parent, name)));
5399
- return makeNode(parent, name, st);
5395
+ lookup(parent, name2) {
5396
+ const listed = parent.live.listed?.get(name2);
5397
+ parent.live.listed?.delete(name2);
5398
+ const st = listed ?? call2(() => bridgeOf(parent).lstat(childPath(parent, name2)));
5399
+ return makeNode(parent, name2, st);
5400
5400
  },
5401
- mknod(parent, name, mode) {
5401
+ mknod(parent, name2, mode) {
5402
5402
  parent.live.listed = void 0;
5403
- const path = childPath(parent, name);
5403
+ const path = childPath(parent, name2);
5404
5404
  if (Fs.isDir(mode)) {
5405
5405
  call2(() => bridgeOf(parent).mkdir(path));
5406
5406
  const perm = mode & PERM_MASK & ~UMASK;
@@ -5413,7 +5413,7 @@ function createNodeOps(h) {
5413
5413
  } else {
5414
5414
  throw new Fs.ErrnoError(wasiErrno("EPERM"));
5415
5415
  }
5416
- const node = makeNode(parent, name, {
5416
+ const node = makeNode(parent, name2, {
5417
5417
  isFile: Fs.isFile(mode),
5418
5418
  isDirectory: Fs.isDir(mode),
5419
5419
  isSymbolicLink: false,
@@ -5440,11 +5440,11 @@ function createNodeOps(h) {
5440
5440
  oldNode.parent = newDir;
5441
5441
  oldNode.live.stat = void 0;
5442
5442
  },
5443
- unlink(parent, name) {
5443
+ unlink(parent, name2) {
5444
5444
  parent.live.listed = void 0;
5445
5445
  let open;
5446
5446
  try {
5447
- const node = Fs.lookupNode?.(parent, name);
5447
+ const node = Fs.lookupNode?.(parent, name2);
5448
5448
  if (node && node.live?.openCount > 0 && Fs.isFile(node.mode)) open = node;
5449
5449
  } catch {
5450
5450
  }
@@ -5454,18 +5454,18 @@ function createNodeOps(h) {
5454
5454
  if (ranged) ranged.pin();
5455
5455
  else ensureLoaded(open);
5456
5456
  }
5457
- call2(() => bridgeOf(parent).unlink(childPath(parent, name)));
5457
+ call2(() => bridgeOf(parent).unlink(childPath(parent, name2)));
5458
5458
  if (open) open.live.orphan = true;
5459
5459
  },
5460
- rmdir(parent, name) {
5460
+ rmdir(parent, name2) {
5461
5461
  parent.live.listed = void 0;
5462
- call2(() => bridgeOf(parent).rmdir(childPath(parent, name)));
5462
+ call2(() => bridgeOf(parent).rmdir(childPath(parent, name2)));
5463
5463
  },
5464
5464
  readdir(node) {
5465
5465
  const listed = call2(() => bridgeOf(node).readdirStat(liveNodePath(node)));
5466
5466
  node.live.listed = /* @__PURE__ */ new Map();
5467
- for (const [name, st] of listed) if (st) node.live.listed.set(name, st);
5468
- return [".", "..", ...listed.map(([name]) => name)];
5467
+ for (const [name2, st] of listed) if (st) node.live.listed.set(name2, st);
5468
+ return [".", "..", ...listed.map(([name2]) => name2)];
5469
5469
  },
5470
5470
  symlink(parent, newName, target) {
5471
5471
  parent.live.listed = void 0;
@@ -5728,28 +5728,28 @@ function liveRoot(Fs, bridge) {
5728
5728
  const memfs = root.memfs ?? root.node_ops;
5729
5729
  const live = plugin.node_ops;
5730
5730
  root.memfs = memfs;
5731
- const own = (name) => Object.hasOwn(root.contents ?? {}, name);
5731
+ const own = (name2) => Object.hasOwn(root.contents ?? {}, name2);
5732
5732
  root.node_ops = {
5733
5733
  ...memfs,
5734
- lookup: (parent, name) => live.lookup(parent, name),
5735
- mknod: (parent, name, mode, dev) => live.mknod(parent, name, mode, dev),
5736
- unlink: (parent, name) => live.unlink(parent, name),
5737
- rmdir: (parent, name) => (own(name) ? memfs : live).rmdir(parent, name),
5738
- symlink: (parent, name, target) => live.symlink(parent, name, target),
5739
- rename: (node, dir, name) => (node.live ? live : memfs).rename(node, dir, name),
5734
+ lookup: (parent, name2) => live.lookup(parent, name2),
5735
+ mknod: (parent, name2, mode, dev) => live.mknod(parent, name2, mode, dev),
5736
+ unlink: (parent, name2) => live.unlink(parent, name2),
5737
+ rmdir: (parent, name2) => (own(name2) ? memfs : live).rmdir(parent, name2),
5738
+ symlink: (parent, name2, target) => live.symlink(parent, name2, target),
5739
+ rename: (node, dir, name2) => (node.live ? live : memfs).rename(node, dir, name2),
5740
5740
  readdir(node) {
5741
5741
  const names = new Set(memfs.readdir(node));
5742
- for (const name of live.readdir(node)) names.add(name);
5742
+ for (const name2 of live.readdir(node)) names.add(name2);
5743
5743
  return [...names];
5744
5744
  }
5745
5745
  };
5746
5746
  }
5747
5747
  function crosses(Fs, from, to) {
5748
5748
  const parentOf = (path) => Fs.lookupPath?.(path, { parent: true }).node;
5749
- const name = from.replace(/\/+$/, "").split("/").pop() ?? "";
5749
+ const name2 = from.replace(/\/+$/, "").split("/").pop() ?? "";
5750
5750
  try {
5751
5751
  const fromDir = parentOf(from);
5752
- const node = fromDir && Fs.lookupNode?.(fromDir, name);
5752
+ const node = fromDir && Fs.lookupNode?.(fromDir, name2);
5753
5753
  const dir = parentOf(to);
5754
5754
  return !!node && !!dir && !!node.live !== !!dir.live;
5755
5755
  } catch {
@@ -5790,8 +5790,8 @@ function guardKeptNodes(Fs, handled) {
5790
5790
  Fs.sliccKept = true;
5791
5791
  const lookupPath = Fs.lookupPath.bind(Fs);
5792
5792
  Fs.open = (path, flags, mode) => {
5793
- const name = path.slice(path.lastIndexOf("/") + 1);
5794
- if (![...handled].some((held) => held.name === name)) return open(path, flags, mode);
5793
+ const name2 = path.slice(path.lastIndexOf("/") + 1);
5794
+ if (![...handled].some((held) => held.name === name2)) return open(path, flags, mode);
5795
5795
  let node;
5796
5796
  try {
5797
5797
  node = lookupPath(path, { follow: true }).node;
@@ -5839,7 +5839,7 @@ function topLevelDirs(bridge, warn) {
5839
5839
  warn(`cannot list the VFS root, nothing mounted: ${String(err)}`);
5840
5840
  return void 0;
5841
5841
  }
5842
- const candidates = names.filter((name) => name && !name.includes("/") && !MODULE_OWNED_DIRS.has(name)).map((name) => `/${name}`);
5842
+ const candidates = names.filter((name2) => name2 && !name2.includes("/") && !MODULE_OWNED_DIRS.has(name2)).map((name2) => `/${name2}`);
5843
5843
  for (const dir of SYNTHETIC_DIRS2) if (!candidates.includes(dir)) candidates.push(dir);
5844
5844
  const dirs = [];
5845
5845
  for (const dir of candidates) {
@@ -5984,14 +5984,14 @@ var init_kernel_streams = __esm({
5984
5984
  nameTerminal(stream) {
5985
5985
  const kfd = stream.sliccKernelFd;
5986
5986
  if (!stream.tty || kfd === void 0) return;
5987
- const name = this.sys.ttyName?.(kfd);
5988
- if (name) this.nameStream(stream, name);
5987
+ const name2 = this.sys.ttyName?.(kfd);
5988
+ if (name2) this.nameStream(stream, name2);
5989
5989
  }
5990
- nameStream(stream, name) {
5991
- stream.path = name;
5992
- this.ttyNode(name);
5990
+ nameStream(stream, name2) {
5991
+ stream.path = name2;
5992
+ this.ttyNode(name2);
5993
5993
  if (typeof this.Fs.stat !== "function") return;
5994
- stream.stream_ops = { ...stream.stream_ops, getattr: () => this.Fs.stat?.(name) ?? {} };
5994
+ stream.stream_ops = { ...stream.stream_ops, getattr: () => this.Fs.stat?.(name2) ?? {} };
5995
5995
  }
5996
5996
  creatingTerminal = false;
5997
5997
  useTerminalNodes() {
@@ -5999,12 +5999,12 @@ var init_kernel_streams = __esm({
5999
5999
  const { lookupNode, readdir, getPath, mkdev, makedev } = fs;
6000
6000
  const ttyNames = this.sys.ttyNames?.bind(this.sys);
6001
6001
  if (!lookupNode || !readdir || !getPath || !mkdev || !makedev || !ttyNames) return;
6002
- fs.lookupNode = (parent, name) => {
6002
+ fs.lookupNode = (parent, name2) => {
6003
6003
  try {
6004
- return lookupNode.call(fs, parent, name);
6004
+ return lookupNode.call(fs, parent, name2);
6005
6005
  } catch (e) {
6006
- const path = `/dev/${name}`;
6007
- if (this.creatingTerminal || !TTY_NAME.test(name) || getPath.call(fs, parent) !== "/dev")
6006
+ const path = `/dev/${name2}`;
6007
+ if (this.creatingTerminal || !TTY_NAME.test(name2) || getPath.call(fs, parent) !== "/dev")
6008
6008
  throw e;
6009
6009
  if (!ttyNames().includes(path)) throw e;
6010
6010
  this.creatingTerminal = true;
@@ -6013,21 +6013,21 @@ var init_kernel_streams = __esm({
6013
6013
  } finally {
6014
6014
  this.creatingTerminal = false;
6015
6015
  }
6016
- return lookupNode.call(fs, parent, name);
6016
+ return lookupNode.call(fs, parent, name2);
6017
6017
  }
6018
6018
  };
6019
6019
  fs.readdir = (path) => {
6020
6020
  const names = readdir.call(fs, path);
6021
6021
  if (path.replace(/\/+$/, "") !== "/dev") return names;
6022
- const missing = ttyNames().map((tty) => tty.slice("/dev/".length)).filter((name) => TTY_NAME.test(name) && !names.includes(name));
6022
+ const missing = ttyNames().map((tty) => tty.slice("/dev/".length)).filter((name2) => TTY_NAME.test(name2) && !names.includes(name2));
6023
6023
  return [...names, ...missing];
6024
6024
  };
6025
6025
  }
6026
- ttyNode(name) {
6026
+ ttyNode(name2) {
6027
6027
  const { analyzePath, mkdev, makedev } = this.Fs;
6028
- if (!TTY_PATH.test(name) || !analyzePath || !mkdev || !makedev) return;
6029
- if (!analyzePath.call(this.Fs, name).exists)
6030
- mkdev.call(this.Fs, name, makedev.call(this.Fs, 6, 0));
6028
+ if (!TTY_PATH.test(name2) || !analyzePath || !mkdev || !makedev) return;
6029
+ if (!analyzePath.call(this.Fs, name2).exists)
6030
+ mkdev.call(this.Fs, name2, makedev.call(this.Fs, 6, 0));
6031
6031
  }
6032
6032
  ttyOps(kfd) {
6033
6033
  return {
@@ -6064,18 +6064,18 @@ var init_kernel_streams = __esm({
6064
6064
  size: this.call(() => size.call(this.sys, kfd))
6065
6065
  }));
6066
6066
  }
6067
- describe(stream, name, getattr) {
6067
+ describe(stream, name2, getattr) {
6068
6068
  if (this.descriptions.size === 0) this.useDescriptions();
6069
- this.descriptions.set(name, getattr);
6070
- stream.path = name;
6069
+ this.descriptions.set(name2, getattr);
6070
+ stream.path = name2;
6071
6071
  stream.stream_ops = { ...stream.stream_ops, getattr };
6072
6072
  }
6073
6073
  useDescriptions() {
6074
6074
  const fs = this.Fs;
6075
- for (const name of ["stat", "lstat"]) {
6076
- const original = fs[name];
6075
+ for (const name2 of ["stat", "lstat"]) {
6076
+ const original = fs[name2];
6077
6077
  if (typeof original !== "function") continue;
6078
- fs[name] = (path, ...rest2) => {
6078
+ fs[name2] = (path, ...rest2) => {
6079
6079
  const getattr = this.descriptions.get(path);
6080
6080
  return getattr ? getattr() : original.call(fs, path, ...rest2);
6081
6081
  };
@@ -6162,15 +6162,15 @@ var init_kernel_streams = __esm({
6162
6162
  }
6163
6163
  usePtyPaths() {
6164
6164
  const fs = this.Fs;
6165
- for (const name of ["chown", "lchown", "chmod", "lchmod"]) {
6166
- const original = fs[name];
6165
+ for (const name2 of ["chown", "lchown", "chmod", "lchmod"]) {
6166
+ const original = fs[name2];
6167
6167
  if (typeof original !== "function") continue;
6168
- fs[name] = (path, ...rest2) => isPtyPath(path) ? this.existingPty(path) : original.call(fs, path, ...rest2);
6168
+ fs[name2] = (path, ...rest2) => isPtyPath(path) ? this.existingPty(path) : original.call(fs, path, ...rest2);
6169
6169
  }
6170
- for (const name of ["stat", "lstat"]) {
6171
- const original = fs[name];
6170
+ for (const name2 of ["stat", "lstat"]) {
6171
+ const original = fs[name2];
6172
6172
  if (typeof original !== "function") continue;
6173
- fs[name] = (path, ...rest2) => {
6173
+ fs[name2] = (path, ...rest2) => {
6174
6174
  if (!isPtyPath(path)) return original.call(fs, path, ...rest2);
6175
6175
  this.existingPty(path);
6176
6176
  return ptyStat(path);
@@ -6183,14 +6183,14 @@ var init_kernel_streams = __esm({
6183
6183
  if (!exists) throw new this.Fs.ErrnoError(wasiErrno("ENOENT"));
6184
6184
  }
6185
6185
  devicePath(path) {
6186
- const name = path.slice(path.lastIndexOf("/") + 1);
6187
- if (!TTY_NAME.test(name)) return void 0;
6186
+ const name2 = path.slice(path.lastIndexOf("/") + 1);
6187
+ if (!TTY_NAME.test(name2)) return void 0;
6188
6188
  const { lookupPath, cwd } = this.Fs;
6189
6189
  const absolute = path.startsWith("/") ? path : `${cwd?.call(this.Fs) ?? "/"}/${path}`;
6190
6190
  const dir = absolute.slice(0, absolute.lastIndexOf("/")) || "/";
6191
6191
  try {
6192
6192
  const real = lookupPath?.call(this.Fs, dir, { follow: true }).path ?? dir;
6193
- return `${real === "/" ? "" : real}/${name}`;
6193
+ return `${real === "/" ? "" : real}/${name2}`;
6194
6194
  } catch {
6195
6195
  return absolute;
6196
6196
  }
@@ -6487,11 +6487,11 @@ function kernelTimer(setitimer, timer) {
6487
6487
  return 0;
6488
6488
  };
6489
6489
  }
6490
- function syscallOf(glue, name, value2) {
6490
+ function syscallOf(glue, name2, value2) {
6491
6491
  const names = Object.keys(IMPORT_NAMES);
6492
6492
  const own = names.find((key) => glue[key] !== void 0 && glue[key] === value2);
6493
6493
  if (own) return own;
6494
- return typeof value2 === "function" ? names.find((key) => glue[key] !== void 0 && IMPORT_NAMES[key] === name) : void 0;
6494
+ return typeof value2 === "function" ? names.find((key) => glue[key] !== void 0 && IMPORT_NAMES[key] === name2) : void 0;
6495
6495
  }
6496
6496
  function wrapCloexecSyscalls(imports, glue, deps) {
6497
6497
  if (!glue) return;
@@ -6500,10 +6500,10 @@ function wrapCloexecSyscalls(imports, glue, deps) {
6500
6500
  for (const namespace of Object.values(imports)) {
6501
6501
  if (!namespace || typeof namespace !== "object" || seen.has(namespace)) continue;
6502
6502
  seen.add(namespace);
6503
- for (const [name, value2] of Object.entries(namespace)) {
6504
- const key = syscallOf(glue, name, value2);
6503
+ for (const [name2, value2] of Object.entries(namespace)) {
6504
+ const key = syscallOf(glue, name2, value2);
6505
6505
  const wrap2 = key && factories[key];
6506
- if (wrap2) namespace[name] = wrap2(value2);
6506
+ if (wrap2) namespace[name2] = wrap2(value2);
6507
6507
  }
6508
6508
  }
6509
6509
  }
@@ -6547,7 +6547,7 @@ function kernelUmask(imports, deps) {
6547
6547
  function noFollowUtimes(imports, fs, glue) {
6548
6548
  for (const namespace of namespaces(imports)) {
6549
6549
  const key = Object.keys(namespace).find(
6550
- (name) => glue !== void 0 && namespace[name] === glue || name === "__syscall_utimensat"
6550
+ (name2) => glue !== void 0 && namespace[name2] === glue || name2 === "__syscall_utimensat"
6551
6551
  );
6552
6552
  const utimensat = key === void 0 ? void 0 : namespace[key];
6553
6553
  if (key === void 0 || typeof utimensat !== "function") continue;
@@ -6587,10 +6587,10 @@ function namespaces(imports) {
6587
6587
  }
6588
6588
  return [...seen];
6589
6589
  }
6590
- function keyOf(namespace, name, glue) {
6591
- const own = glue?.[name];
6590
+ function keyOf(namespace, name2, glue) {
6591
+ const own = glue?.[name2];
6592
6592
  const found = typeof own === "function" ? Object.keys(namespace).find((k) => namespace[k] === own) : void 0;
6593
- return found ?? (typeof namespace[name] === "function" ? name : void 0);
6593
+ return found ?? (typeof namespace[name2] === "function" ? name2 : void 0);
6594
6594
  }
6595
6595
  function syncFsync(imports, fs, glue) {
6596
6596
  for (const namespace of namespaces(imports)) {
@@ -6654,11 +6654,11 @@ function positioned(original, write2, deps) {
6654
6654
  }
6655
6655
  function positionalIo(imports, deps) {
6656
6656
  for (const namespace of namespaces(imports)) {
6657
- for (const [name, write2] of [
6657
+ for (const [name2, write2] of [
6658
6658
  ["fd_pread", false],
6659
6659
  ["fd_pwrite", true]
6660
6660
  ]) {
6661
- const key = keyOf(namespace, name, deps.glue);
6661
+ const key = keyOf(namespace, name2, deps.glue);
6662
6662
  if (key !== void 0) {
6663
6663
  namespace[key] = positioned(namespace[key], write2, deps);
6664
6664
  }
@@ -6760,8 +6760,8 @@ function describeFdDir(Fs) {
6760
6760
  dir.node_ops = {
6761
6761
  ...ops,
6762
6762
  getattr: () => syntheticAttr(DIR_MODE, 1),
6763
- lookup: (parent, name) => {
6764
- const entry = lookup(parent, name);
6763
+ lookup: (parent, name2) => {
6764
+ const entry = lookup(parent, name2);
6765
6765
  entry.node_ops = {
6766
6766
  ...entry.node_ops,
6767
6767
  getattr: () => syntheticAttr(LINK_MODE, entry.id ?? 0)
@@ -6798,13 +6798,13 @@ function useZeroDevices(Fs) {
6798
6798
  function linkStdio(Fs) {
6799
6799
  const { unlink, symlink } = Fs;
6800
6800
  if (!unlink || !symlink) return;
6801
- for (const [fd, name] of ["stdin", "stdout", "stderr"].entries()) {
6801
+ for (const [fd, name2] of ["stdin", "stdout", "stderr"].entries()) {
6802
6802
  try {
6803
- unlink.call(Fs, `/dev/${name}`);
6803
+ unlink.call(Fs, `/dev/${name2}`);
6804
6804
  } catch {
6805
6805
  }
6806
6806
  try {
6807
- symlink.call(Fs, `/proc/self/fd/${fd}`, `/dev/${name}`);
6807
+ symlink.call(Fs, `/proc/self/fd/${fd}`, `/dev/${name2}`);
6808
6808
  } catch {
6809
6809
  }
6810
6810
  }
@@ -6856,14 +6856,14 @@ function mountTable(mounts = []) {
6856
6856
  }
6857
6857
  function accounts(env = {}) {
6858
6858
  const user = env.USER ?? "web_user";
6859
- const name = NAME.test(user) && user !== "root" ? user : "user";
6859
+ const name2 = NAME.test(user) && user !== "root" ? user : "user";
6860
6860
  const home = env.HOME || "/home";
6861
6861
  return {
6862
6862
  passwd: `root:x:0:0:root:/root:/bin/sh
6863
- ${name}:x:1000:1000:${name}:${home}:/bin/bash
6863
+ ${name2}:x:1000:1000:${name2}:${home}:/bin/bash
6864
6864
  `,
6865
6865
  group: `root:x:0:
6866
- ${name}:x:1000:
6866
+ ${name2}:x:1000:
6867
6867
  `
6868
6868
  };
6869
6869
  }
@@ -7672,9 +7672,9 @@ function createSocketKernel(deps) {
7672
7672
  }),
7673
7673
  shutdown: (fd, how) => guard(() => done({ op: "sock-shutdown", fd: kfd(fd), how })),
7674
7674
  name: (fd, peer) => guard(() => json({ op: "sock-name", fd: kfd(fd), peer })),
7675
- getopt: (fd, level, name) => guard(() => ({ value: json({ op: "sock-getopt", fd: kfd(fd), level, name }) })),
7676
- setopt: (fd, level, name, value2) => guard(() => done({ op: "sock-setopt", fd: kfd(fd), level, name, value: value2 })),
7677
- resolve: (name, family = 4) => guard(() => json({ op: "sock-resolve", name, family })),
7675
+ getopt: (fd, level, name2) => guard(() => ({ value: json({ op: "sock-getopt", fd: kfd(fd), level, name: name2 }) })),
7676
+ setopt: (fd, level, name2, value2) => guard(() => done({ op: "sock-setopt", fd: kfd(fd), level, name: name2, value: value2 })),
7677
+ resolve: (name2, family = 4) => guard(() => json({ op: "sock-resolve", name: name2, family })),
7678
7678
  send: (fd, bytes, flags) => guard(() => {
7679
7679
  const stream = socketAt(fd);
7680
7680
  const nonblock = flags.dontwait === true || (stream.flags & O_NONBLOCK2) !== 0;
@@ -7712,8 +7712,8 @@ var init_process_sockets = __esm({
7712
7712
 
7713
7713
  // src/process/procfs.ts
7714
7714
  function commOf(info) {
7715
- const name = info.argv[0] ?? "";
7716
- return name.slice(name.lastIndexOf("/") + 1).slice(0, 15);
7715
+ const name2 = info.argv[0] ?? "";
7716
+ return name2.slice(name2.lastIndexOf("/") + 1).slice(0, 15);
7717
7717
  }
7718
7718
  function ttyNumber(tty) {
7719
7719
  const pts = tty && /^\/dev\/pts\/(\d+)$/.exec(tty);
@@ -7800,12 +7800,12 @@ function pidStatus(info) {
7800
7800
  ""
7801
7801
  ].join("\n");
7802
7802
  }
7803
- function pidFile(name, info, boot) {
7804
- if (name === "cmdline") return info.state === "Z" ? "" : `${info.argv.join("\0")}\0`;
7805
- if (name === "comm") return `${commOf(info)}
7803
+ function pidFile(name2, info, boot) {
7804
+ if (name2 === "cmdline") return info.state === "Z" ? "" : `${info.argv.join("\0")}\0`;
7805
+ if (name2 === "comm") return `${commOf(info)}
7806
7806
  `;
7807
- if (name === "stat") return pidStat(info, boot);
7808
- if (name === "statm") {
7807
+ if (name2 === "stat") return pidStat(info, boot);
7808
+ if (name2 === "statm") {
7809
7809
  const p = pages(info.memory);
7810
7810
  return `${p} ${p} 0 0 0 ${p} 0
7811
7811
  `;
@@ -7829,18 +7829,18 @@ function memoryInfo(source, used = 0) {
7829
7829
  ["SwapFree", kb(0)]
7830
7830
  ].map(([key, value2]) => `${`${key}:`.padEnd(16)}${value2.padStart(12)}`).concat("").join("\n");
7831
7831
  }
7832
- function systemFile(name, listing, now, memory) {
7832
+ function systemFile(name2, listing, now, memory) {
7833
7833
  const up = Math.max(0, now - listing.boot) / 1e3;
7834
- if (name === "uptime") return `${up.toFixed(2)} ${up.toFixed(2)}
7834
+ if (name2 === "uptime") return `${up.toFixed(2)} ${up.toFixed(2)}
7835
7835
  `;
7836
- if (name === "meminfo") {
7836
+ if (name2 === "meminfo") {
7837
7837
  return memoryInfo(
7838
7838
  memory,
7839
7839
  listing.processes.reduce((sum, p) => sum + p.memory, 0)
7840
7840
  );
7841
7841
  }
7842
7842
  const live = listing.processes.filter((p) => p.state !== "Z");
7843
- if (name === "loadavg") {
7843
+ if (name2 === "loadavg") {
7844
7844
  const last = Math.max(0, ...listing.processes.map((p) => p.pid));
7845
7845
  return `0.00 0.00 0.00 1/${live.length} ${last}
7846
7846
  `;
@@ -7899,8 +7899,8 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
7899
7899
  return;
7900
7900
  }
7901
7901
  const error = (errno2 = ENOENT) => new Fs.ErrnoError(errno2);
7902
- const fresh = (parent, name, mode) => {
7903
- const node = createNode.call(Fs, parent, name, mode, 0);
7902
+ const fresh = (parent, name2, mode) => {
7903
+ const node = createNode.call(Fs, parent, name2, mode, 0);
7904
7904
  hashRemoveNode.call(Fs, node);
7905
7905
  node.node_ops = { getattr: attr, setattr: () => {
7906
7906
  } };
@@ -7913,8 +7913,8 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
7913
7913
  };
7914
7914
  return node;
7915
7915
  };
7916
- const file = (parent, name, content) => {
7917
- const node = fresh(parent, name, FILE_MODE);
7916
+ const file = (parent, name2, content) => {
7917
+ const node = fresh(parent, name2, FILE_MODE);
7918
7918
  node.stream_ops = {
7919
7919
  open: (stream) => {
7920
7920
  stream.sliccProc = new TextEncoder().encode(content());
@@ -7936,15 +7936,15 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
7936
7936
  };
7937
7937
  const find = (processes2, target, own) => (own ? processes2.find((p) => p.tid === target) : void 0) ?? processes2.find((p) => p.pid === target || p.tid === target);
7938
7938
  const infoOf = (target) => find(procList().processes, target, false);
7939
- const pidContent = (target, name, own = false) => () => {
7939
+ const pidContent = (target, name2, own = false) => () => {
7940
7940
  const listing = procList();
7941
7941
  const info = find(listing.processes, target, own);
7942
7942
  if (!info) throw error(ESRCH);
7943
- return pidFile(name, info, listing.boot);
7943
+ return pidFile(name2, info, listing.boot);
7944
7944
  };
7945
7945
  const pidNames = (names) => [.../* @__PURE__ */ new Set([...names, ...PID_FILES])];
7946
- const pidDir = (name, target) => {
7947
- const dir = fresh(proc, name, DIR_MODE2);
7946
+ const pidDir = (name2, target) => {
7947
+ const dir = fresh(proc, name2, DIR_MODE2);
7948
7948
  dir.node_ops.lookup = (parent, child) => {
7949
7949
  if (!PID_FILES.includes(child)) throw error();
7950
7950
  return file(parent, child, pidContent(target, child));
@@ -7957,25 +7957,25 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
7957
7957
  const readdir = procOps.readdir?.bind(procOps);
7958
7958
  proc.node_ops = {
7959
7959
  ...procOps,
7960
- lookup: (parent, name) => {
7961
- if (/^[1-9]\d*$/.test(name)) {
7962
- if (!infoOf(Number(name))) throw error();
7963
- return pidDir(name, Number(name));
7960
+ lookup: (parent, name2) => {
7961
+ if (/^[1-9]\d*$/.test(name2)) {
7962
+ if (!infoOf(Number(name2))) throw error();
7963
+ return pidDir(name2, Number(name2));
7964
7964
  }
7965
- if (name === "mounts") return file(parent, name, () => mountTable(sys.mountList?.() ?? []));
7966
- if (SYSTEM_FILES.includes(name)) {
7965
+ if (name2 === "mounts") return file(parent, name2, () => mountTable(sys.mountList?.() ?? []));
7966
+ if (SYSTEM_FILES.includes(name2)) {
7967
7967
  return file(
7968
7968
  parent,
7969
- name,
7970
- () => systemFile(name, procList(), Date.now(), memory)
7969
+ name2,
7970
+ () => systemFile(name2, procList(), Date.now(), memory)
7971
7971
  );
7972
7972
  }
7973
7973
  if (!lookup) throw error();
7974
- return lookup(parent, name);
7974
+ return lookup(parent, name2);
7975
7975
  },
7976
7976
  readdir: (node) => {
7977
7977
  const names = new Set(readdir ? readdir(node) : [".", ".."]);
7978
- for (const name of [...SYSTEM_FILES, "mounts"]) names.add(name);
7978
+ for (const name2 of [...SYSTEM_FILES, "mounts"]) names.add(name2);
7979
7979
  for (const p of procList().processes) names.add(String(p.pid));
7980
7980
  return [...names];
7981
7981
  }
@@ -7985,18 +7985,18 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
7985
7985
  const shownPid = () => String(find(procList().processes, pid, true)?.pid ?? pid);
7986
7986
  link.node_ops.readlink = shownPid;
7987
7987
  const procLookup = proc.node_ops.lookup;
7988
- proc.node_ops.lookup = (parent, name) => name === "self" ? link : name === shownPid() ? self : procLookup(parent, name);
7988
+ proc.node_ops.lookup = (parent, name2) => name2 === "self" ? link : name2 === shownPid() ? self : procLookup(parent, name2);
7989
7989
  const selfOps = self.node_ops;
7990
7990
  const selfLookup = selfOps.lookup?.bind(selfOps);
7991
7991
  const selfReaddir = selfOps.readdir?.bind(selfOps);
7992
7992
  self.node_ops = {
7993
7993
  ...selfOps,
7994
- lookup: (parent, name) => {
7995
- if (PID_FILES.includes(name)) {
7996
- return file(parent, name, pidContent(pid, name, true));
7994
+ lookup: (parent, name2) => {
7995
+ if (PID_FILES.includes(name2)) {
7996
+ return file(parent, name2, pidContent(pid, name2, true));
7997
7997
  }
7998
7998
  if (!selfLookup) throw error();
7999
- return selfLookup(parent, name);
7999
+ return selfLookup(parent, name2);
8000
8000
  },
8001
8001
  readdir: (node) => pidNames(selfReaddir ? selfReaddir(node) : [".", ".."])
8002
8002
  };
@@ -8131,9 +8131,9 @@ function kernelSys(transport) {
8131
8131
  ttyNames() {
8132
8132
  return json(call2({ op: "fd-tty-names" }, "fd-tty-names"));
8133
8133
  },
8134
- openTty(name) {
8135
- const req = name === void 0 ? { op: "fd-open-tty" } : { op: "fd-open-tty", name };
8136
- return json(call2(req, `fd-open-tty ${name ?? ""}`));
8134
+ openTty(name2) {
8135
+ const req = name2 === void 0 ? { op: "fd-open-tty" } : { op: "fd-open-tty", name: name2 };
8136
+ return json(call2(req, `fd-open-tty ${name2 ?? ""}`));
8137
8137
  },
8138
8138
  tcgets(fd) {
8139
8139
  return json(call2({ op: "tty-get", fd }, `tty-get ${fd}`));
@@ -8224,8 +8224,8 @@ function wireKernelStdio(Fs, streams, sys) {
8224
8224
  function glueBody(glue) {
8225
8225
  return glue.startsWith("#!") ? glue.slice(glue.indexOf("\n") + 1) : glue;
8226
8226
  }
8227
- function ownValue(module, name) {
8228
- const own = Object.getOwnPropertyDescriptor(module, name);
8227
+ function ownValue(module, name2) {
8228
+ const own = Object.getOwnPropertyDescriptor(module, name2);
8229
8229
  return own && "value" in own ? own.value : void 0;
8230
8230
  }
8231
8231
  function identify(transport, init) {
@@ -8555,9 +8555,9 @@ var init_process_runtime = __esm({
8555
8555
 
8556
8556
  // src/process/wasi/dylink.ts
8557
8557
  function dylinkInfo(module) {
8558
- const [section] = WebAssembly.Module.customSections(module, "dylink.0");
8559
- if (!section) return void 0;
8560
- const bytes = new Uint8Array(section);
8558
+ const [section2] = WebAssembly.Module.customSections(module, "dylink.0");
8559
+ if (!section2) return void 0;
8560
+ const bytes = new Uint8Array(section2);
8561
8561
  let at = 0;
8562
8562
  const uleb = () => {
8563
8563
  let value2 = 0;
@@ -8665,8 +8665,8 @@ var init_wasi_signals = __esm({
8665
8665
  bind(exports) {
8666
8666
  this.exports = exports;
8667
8667
  }
8668
- register(name) {
8669
- if (typeof this.exports?.[name] === "function") this.callback = name;
8668
+ register(name2) {
8669
+ if (typeof this.exports?.[name2] === "function") this.callback = name2;
8670
8670
  }
8671
8671
  useHook() {
8672
8672
  this.hooked = true;
@@ -8763,11 +8763,11 @@ var init_wasi_stats = __esm({
8763
8763
  mark = performance.now();
8764
8764
  wrap(tag, table) {
8765
8765
  return Object.fromEntries(
8766
- Object.entries(table).map(([name, value2]) => {
8767
- if (typeof value2 !== "function") return [name, value2];
8766
+ Object.entries(table).map(([name2, value2]) => {
8767
+ if (typeof value2 !== "function") return [name2, value2];
8768
8768
  const fn = value2;
8769
- const key = `${tag}.${name}`;
8770
- return [name, (...args) => this.time(key, () => fn.apply(table, args))];
8769
+ const key = `${tag}.${name2}`;
8770
+ return [name2, (...args) => this.time(key, () => fn.apply(table, args))];
8771
8771
  })
8772
8772
  );
8773
8773
  }
@@ -8779,9 +8779,9 @@ var init_wasi_stats = __esm({
8779
8779
  this.count(key, performance.now() - t);
8780
8780
  }
8781
8781
  }
8782
- phase(name) {
8782
+ phase(name2) {
8783
8783
  const now = performance.now();
8784
- this.phases.push([name, now - this.mark]);
8784
+ this.phases.push([name2, now - this.mark]);
8785
8785
  this.mark = now;
8786
8786
  }
8787
8787
  count(key, ms) {
@@ -8793,7 +8793,7 @@ var init_wasi_stats = __esm({
8793
8793
  }
8794
8794
  report() {
8795
8795
  const ms = (v) => v.toFixed(1).padStart(9);
8796
- const lines = this.phases.map(([name, t]) => `${ms(t)} ms ${name}`);
8796
+ const lines = this.phases.map(([name2, t]) => `${ms(t)} ms ${name2}`);
8797
8797
  lines.push(`${"total ms".padStart(12)} ${"calls".padStart(7)} ${"max ms".padStart(9)} call`);
8798
8798
  const sorted = [...this.rows].sort((a, b) => b[1].ms - a[1].ms);
8799
8799
  for (const [key, row] of sorted) {
@@ -8809,12 +8809,12 @@ var init_wasi_stats = __esm({
8809
8809
  // src/process/wasi/wasix-fork.ts
8810
8810
  function mutableGlobals(exports) {
8811
8811
  const out = [];
8812
- for (const [name, value2] of Object.entries(exports)) {
8812
+ for (const [name2, value2] of Object.entries(exports)) {
8813
8813
  if (!(value2 instanceof WebAssembly.Global) || typeof value2.value !== "number") continue;
8814
8814
  try {
8815
8815
  const v = value2.value;
8816
8816
  value2.value = v;
8817
- out.push([name, v]);
8817
+ out.push([name2, v]);
8818
8818
  } catch {
8819
8819
  }
8820
8820
  }
@@ -8924,8 +8924,8 @@ var init_wasix_fork = __esm({
8924
8924
  return E.SUCCESS;
8925
8925
  }
8926
8926
  restoreGlobals(globals) {
8927
- for (const [name, value2] of globals) {
8928
- const g = this.exports[name];
8927
+ for (const [name2, value2] of globals) {
8928
+ const g = this.exports[name2];
8929
8929
  if (g instanceof WebAssembly.Global) g.value = value2;
8930
8930
  }
8931
8931
  }
@@ -8995,6 +8995,173 @@ var init_wasix_ffi = __esm({
8995
8995
  }
8996
8996
  });
8997
8997
 
8998
+ // src/process/wasi/wasix-trampoline.ts
8999
+ function valueTypes(codes) {
9000
+ const out = [];
9001
+ for (const code2 of codes) {
9002
+ const type = CODES[code2];
9003
+ if (!type) return void 0;
9004
+ out.push(type);
9005
+ }
9006
+ return out;
9007
+ }
9008
+ function u32(n) {
9009
+ const out = [];
9010
+ let v = n >>> 0;
9011
+ do {
9012
+ let b = v & 127;
9013
+ v >>>= 7;
9014
+ if (v) b |= 128;
9015
+ out.push(b);
9016
+ } while (v);
9017
+ return out;
9018
+ }
9019
+ function s32(n) {
9020
+ const out = [];
9021
+ let v = n | 0;
9022
+ for (; ; ) {
9023
+ const b = v & 127;
9024
+ v >>= 7;
9025
+ if (v === 0 && !(b & 64) || v === -1 && b & 64) {
9026
+ out.push(b);
9027
+ return out;
9028
+ }
9029
+ out.push(b | 128);
9030
+ }
9031
+ }
9032
+ function name(s) {
9033
+ const bytes = [...new TextEncoder().encode(s)];
9034
+ return [...u32(bytes.length), ...bytes];
9035
+ }
9036
+ function section(id, body) {
9037
+ return [id, ...u32(body.length), ...body];
9038
+ }
9039
+ function vec(items) {
9040
+ return [...u32(items.length), ...items.flat()];
9041
+ }
9042
+ function align16(n) {
9043
+ return Math.ceil(n / 16) * 16;
9044
+ }
9045
+ function trampolineBytes(params, results, shared) {
9046
+ const sig = [
9047
+ 96,
9048
+ ...vec(params.map((t) => [VALTYPE[t]])),
9049
+ ...vec(results.map((t) => [VALTYPE[t]]))
9050
+ ];
9051
+ const backing = [96, ...vec([[127], [127], [127]]), ...vec([])];
9052
+ const memory = shared ? [3, 0, ...u32(65536)] : [0, 0];
9053
+ const imports = vec([
9054
+ [...name("env"), ...name("memory"), 2, ...memory],
9055
+ [...name("env"), ...name("__indirect_function_table"), 1, 112, 0, 0],
9056
+ [...name("env"), ...name("__stack_pointer"), 3, 127, 1],
9057
+ [...name("env"), ...name("backing"), 3, 127, 0],
9058
+ [...name("env"), ...name("user_data"), 3, 127, 0]
9059
+ ]);
9060
+ const n = params.length;
9061
+ const [orig, args, res] = [n, n + 1, n + 2];
9062
+ const valuesSize = align16(params.reduce((sum, t) => sum + SIZE3[t], 0));
9063
+ const resultsSize = align16(results.reduce((sum, t) => sum + SIZE3[t], 0));
9064
+ const body = [
9065
+ 35,
9066
+ 0,
9067
+ 34,
9068
+ ...u32(orig),
9069
+ 65,
9070
+ ...s32(resultsSize),
9071
+ 107,
9072
+ 34,
9073
+ ...u32(res)
9074
+ ];
9075
+ body.push(65, ...s32(valuesSize), 107, 34, ...u32(args), 36, 0);
9076
+ let at = 0;
9077
+ params.forEach((t, i) => {
9078
+ body.push(32, ...u32(args), 32, ...u32(i), ...STORE[t], 0, ...u32(at));
9079
+ at += SIZE3[t];
9080
+ });
9081
+ body.push(32, ...u32(args), 32, ...u32(res), 35, 2, 35, 1, 17, 1, 0);
9082
+ at = 0;
9083
+ for (const t of results) {
9084
+ body.push(32, ...u32(res), ...LOAD[t], 0, ...u32(at));
9085
+ at += SIZE3[t];
9086
+ }
9087
+ body.push(32, ...u32(orig), 36, 0, 11);
9088
+ const func = [...vec([[...u32(3), 127]]), ...body];
9089
+ return Uint8Array.from([
9090
+ 0,
9091
+ 97,
9092
+ 115,
9093
+ 109,
9094
+ 1,
9095
+ 0,
9096
+ 0,
9097
+ 0,
9098
+ ...section(1, vec([sig, backing])),
9099
+ ...section(2, imports),
9100
+ ...section(3, vec([[0]])),
9101
+ ...section(7, vec([[...name("t"), 0, 0]])),
9102
+ ...section(10, vec([[...u32(func.length), ...func]]))
9103
+ ]);
9104
+ }
9105
+ var CODES, VALTYPE, SIZE3, STORE, LOAD, Trampolines;
9106
+ var init_wasix_trampoline = __esm({
9107
+ "src/process/wasi/wasix-trampoline.ts"() {
9108
+ "use strict";
9109
+ CODES = ["i32", "i64", "f32", "f64", "v128"];
9110
+ VALTYPE = {
9111
+ i32: 127,
9112
+ i64: 126,
9113
+ f32: 125,
9114
+ f64: 124,
9115
+ v128: 123
9116
+ };
9117
+ SIZE3 = { i32: 4, i64: 8, f32: 4, f64: 8, v128: 16 };
9118
+ STORE = {
9119
+ i32: [54],
9120
+ i64: [55],
9121
+ f32: [56],
9122
+ f64: [57],
9123
+ v128: [253, 11]
9124
+ };
9125
+ LOAD = {
9126
+ i32: [40],
9127
+ i64: [41],
9128
+ f32: [42],
9129
+ f64: [43],
9130
+ v128: [253, 0]
9131
+ };
9132
+ Trampolines = class {
9133
+ modules = /* @__PURE__ */ new Map();
9134
+ get compiled() {
9135
+ return this.modules.size;
9136
+ }
9137
+ make(params, results, env) {
9138
+ const shared = env.memory.buffer instanceof SharedArrayBuffer;
9139
+ const key = `${params.join(",")}>${results.join(",")}${shared ? "s" : ""}`;
9140
+ let module = this.modules.get(key);
9141
+ if (!module) {
9142
+ module = new WebAssembly.Module(trampolineBytes(params, results, shared));
9143
+ this.modules.set(key, module);
9144
+ }
9145
+ const i32 = (v) => new WebAssembly.Global({ value: "i32", mutable: false }, v);
9146
+ const instance = new WebAssembly.Instance(module, {
9147
+ env: {
9148
+ memory: env.memory,
9149
+ __indirect_function_table: env.table,
9150
+ __stack_pointer: env.stackPointer,
9151
+ backing: i32(env.backing),
9152
+ user_data: i32(env.userData)
9153
+ }
9154
+ });
9155
+ const sig = {
9156
+ params: params.map((t) => t === "v128" ? "other" : t),
9157
+ results: results.map((t) => t === "v128" ? "other" : t)
9158
+ };
9159
+ return { fn: instance.exports.t, sig };
9160
+ }
9161
+ };
9162
+ }
9163
+ });
9164
+
8998
9165
  // src/process/wasi/wasm-functypes.ts
8999
9166
  function readTypes(r, s) {
9000
9167
  for (let i = r.u32(); i > 0; i--) {
@@ -9063,10 +9230,10 @@ function readGlobals(r, s) {
9063
9230
  }
9064
9231
  function readExports(r, s) {
9065
9232
  for (let i = r.u32(); i > 0; i--) {
9066
- const name = r.name();
9233
+ const name2 = r.name();
9067
9234
  const kind = r.byte();
9068
9235
  const index2 = r.u32();
9069
- if (kind === 0) s.info.exports[name] = index2;
9236
+ if (kind === 0) s.info.exports[name2] = index2;
9070
9237
  }
9071
9238
  }
9072
9239
  function readElems(r, s) {
@@ -9186,8 +9353,8 @@ var init_wasm_functypes = __esm({
9186
9353
  }
9187
9354
  add(info, instance, table, tableBase) {
9188
9355
  const sig = (func) => info.sigs[info.funcs[func] ?? -1];
9189
- for (const [name, func] of Object.entries(info.exports)) {
9190
- const fn = instance.exports[name];
9356
+ for (const [name2, func] of Object.entries(info.exports)) {
9357
+ const fn = instance.exports[name2];
9191
9358
  const type = sig(func);
9192
9359
  if (typeof fn === "function" && type) this.known.set(fn, type);
9193
9360
  }
@@ -9230,8 +9397,8 @@ function growTo(memory, bytes) {
9230
9397
  function growTable(table, length) {
9231
9398
  if (table.length < length) table.grow(length - table.length);
9232
9399
  }
9233
- function call(instance, name) {
9234
- const fn = instance.exports[name];
9400
+ function call(instance, name2) {
9401
+ const fn = instance.exports[name2];
9235
9402
  if (typeof fn === "function") fn();
9236
9403
  }
9237
9404
  var TABLE_BASE2, PAGE2, STACK_SIZE, LIBRARY_DIRS, DlError, WasixLinker;
@@ -9240,6 +9407,7 @@ var init_wasix_linker = __esm({
9240
9407
  "use strict";
9241
9408
  init_dylink();
9242
9409
  init_wasi_files();
9410
+ init_wasix_trampoline();
9243
9411
  init_wasm_functypes();
9244
9412
  TABLE_BASE2 = 1;
9245
9413
  PAGE2 = 65536;
@@ -9264,6 +9432,7 @@ var init_wasix_linker = __esm({
9264
9432
  publisher;
9265
9433
  indices;
9266
9434
  types = new FuncTypes();
9435
+ trampolines = new Trampolines();
9267
9436
  memory;
9268
9437
  host;
9269
9438
  constructor(memory, mainInfo, host, thread = false) {
@@ -9327,16 +9496,25 @@ var init_wasix_linker = __esm({
9327
9496
  this.main = instance;
9328
9497
  if (relocate) call(instance, "__wasm_apply_data_relocs");
9329
9498
  }
9330
- open(name, cwd, ldPath) {
9331
- return this.load(this.locate(name, cwd, ldPath), cwd, ldPath).handle;
9332
- }
9333
- symbol(handle, name) {
9334
- const found = handle === 0 ? this.find(name) : this.findIn(this.module(handle), name, /* @__PURE__ */ new Set());
9335
- if (!found) throw new DlError(`undefined symbol: ${name}`);
9499
+ mainPath;
9500
+ isMain(path) {
9501
+ if (this.mainPath === void 0) return false;
9502
+ if (path === this.mainPath) return true;
9503
+ const real = this.host.real;
9504
+ return real !== void 0 && real(path) === real(this.mainPath);
9505
+ }
9506
+ open(name2, cwd, ldPath) {
9507
+ const path = this.locate(name2, cwd, ldPath);
9508
+ if (this.isMain(path)) return 0;
9509
+ return this.load(path, cwd, ldPath).handle;
9510
+ }
9511
+ symbol(handle, name2) {
9512
+ const found = handle === 0 ? this.find(name2) : this.findIn(this.module(handle), name2, /* @__PURE__ */ new Set());
9513
+ if (!found) throw new DlError(`undefined symbol: ${name2}`);
9336
9514
  const [owner, value2] = found;
9337
- if (typeof value2 === "function") return this.slot(value2, owner, name);
9515
+ if (typeof value2 === "function") return this.slot(value2, owner, name2);
9338
9516
  if (value2 instanceof WebAssembly.Global) return this.baseOf(owner) + value2.value;
9339
- throw new DlError(`${name} is neither a function nor data`);
9517
+ throw new DlError(`${name2} is neither a function nor data`);
9340
9518
  }
9341
9519
  invalid(handle) {
9342
9520
  return !this.modules.has(handle);
@@ -9356,6 +9534,25 @@ var init_wasix_linker = __esm({
9356
9534
  this.indices?.free(index2);
9357
9535
  this.table.set(index2, null);
9358
9536
  }
9537
+ prepareClosure(record) {
9538
+ if (record.index >= this.table.length)
9539
+ throw new DlError(`closure ${record.index}: no such slot`);
9540
+ const full = { kind: "closure-prepare", ...record };
9541
+ this.install(full);
9542
+ this.publisher?.(full);
9543
+ }
9544
+ install(record) {
9545
+ growTable(this.table, record.index + 1);
9546
+ const { fn, sig } = this.trampolines.make(record.params, record.results, {
9547
+ memory: this.memory,
9548
+ table: this.table,
9549
+ stackPointer: this.stackPointer,
9550
+ backing: record.backing,
9551
+ userData: record.userData
9552
+ });
9553
+ this.table.set(record.index, fn);
9554
+ this.types.set(fn, sig);
9555
+ }
9359
9556
  reserve(size) {
9360
9557
  return this.indices?.reserve(this.table.length, size) ?? this.table.length;
9361
9558
  }
@@ -9368,6 +9565,10 @@ var init_wasix_linker = __esm({
9368
9565
  if (record.index < this.table.length) this.table.set(record.index, null);
9369
9566
  return;
9370
9567
  }
9568
+ if (record.kind === "closure-prepare") {
9569
+ this.install(record);
9570
+ return;
9571
+ }
9371
9572
  if (record.kind === "load") {
9372
9573
  if (this.modules.has(record.handle)) return;
9373
9574
  this.instantiate(record.path, this.moduleAt(record.path), record, false);
@@ -9392,14 +9593,14 @@ var init_wasix_linker = __esm({
9392
9593
  if (!m) throw new DlError(`invalid handle ${handle}`);
9393
9594
  return m;
9394
9595
  }
9395
- locate(name, cwd, ldPath) {
9396
- if (name.includes("/"))
9397
- return name.startsWith("/") ? normalize(name) : normalize(`${cwd}/${name}`);
9596
+ locate(name2, cwd, ldPath) {
9597
+ if (name2.includes("/"))
9598
+ return name2.startsWith("/") ? normalize(name2) : normalize(`${cwd}/${name2}`);
9398
9599
  for (const dir of [...ldPath.filter(Boolean), ...LIBRARY_DIRS]) {
9399
- const path = normalize(`${dir.startsWith("/") ? "" : `${cwd}/`}${dir}/${name}`);
9600
+ const path = normalize(`${dir.startsWith("/") ? "" : `${cwd}/`}${dir}/${name2}`);
9400
9601
  if (this.byPath.has(path) || this.host.read(path)) return path;
9401
9602
  }
9402
- throw new DlError(`${name}: not found`);
9603
+ throw new DlError(`${name2}: not found`);
9403
9604
  }
9404
9605
  load(path, cwd, ldPath) {
9405
9606
  const loaded = this.byPath.get(path);
@@ -9494,46 +9695,46 @@ var init_wasix_linker = __esm({
9494
9695
  }
9495
9696
  return linked;
9496
9697
  }
9497
- functionImport(name) {
9498
- const now = this.find(name);
9698
+ functionImport(name2) {
9699
+ const now = this.find(name2);
9499
9700
  if (now && typeof now[1] === "function") return now[1];
9500
9701
  let resolved2;
9501
9702
  return (...args) => {
9502
9703
  if (!resolved2) {
9503
- const later = this.find(name);
9704
+ const later = this.find(name2);
9504
9705
  if (!later || typeof later[1] !== "function")
9505
- throw new WebAssembly.RuntimeError(`unresolved symbol ${name}`);
9706
+ throw new WebAssembly.RuntimeError(`unresolved symbol ${name2}`);
9506
9707
  resolved2 = later[1];
9507
9708
  }
9508
9709
  return resolved2(...args);
9509
9710
  };
9510
9711
  }
9511
- addressOrNull(name) {
9512
- const found = this.find(name);
9712
+ addressOrNull(name2) {
9713
+ const found = this.find(name2);
9513
9714
  if (!found || !(found[1] instanceof WebAssembly.Global)) return 0;
9514
9715
  return this.baseOf(found[0]) + found[1].value;
9515
9716
  }
9516
- slotOrNull(name) {
9517
- const found = this.find(name);
9717
+ slotOrNull(name2) {
9718
+ const found = this.find(name2);
9518
9719
  if (!found || typeof found[1] !== "function") return 0;
9519
- return this.slot(found[1], found[0], name);
9720
+ return this.slot(found[1], found[0], name2);
9520
9721
  }
9521
- find(name) {
9522
- const inMain = this.main?.exports[name];
9722
+ find(name2) {
9723
+ const inMain = this.main?.exports[name2];
9523
9724
  if (inMain !== void 0) return [0, inMain];
9524
9725
  for (const m of this.modules.values()) {
9525
- const v = m.instance?.exports[name];
9726
+ const v = m.instance?.exports[name2];
9526
9727
  if (v !== void 0) return [m.handle, v];
9527
9728
  }
9528
9729
  return void 0;
9529
9730
  }
9530
- findIn(m, name, seen) {
9731
+ findIn(m, name2, seen) {
9531
9732
  if (seen.has(m.handle)) return void 0;
9532
9733
  seen.add(m.handle);
9533
- const v = m.instance.exports[name];
9734
+ const v = m.instance.exports[name2];
9534
9735
  if (v !== void 0) return [m.handle, v];
9535
9736
  for (const h of m.needed) {
9536
- const found = this.findIn(this.module(h), name, seen);
9737
+ const found = this.findIn(this.module(h), name2, seen);
9537
9738
  if (found) return found;
9538
9739
  }
9539
9740
  return void 0;
@@ -9541,14 +9742,23 @@ var init_wasix_linker = __esm({
9541
9742
  baseOf(handle) {
9542
9743
  return handle === 0 ? this.memoryBase : this.module(handle).memoryBase;
9543
9744
  }
9544
- slot(fn, handle, name) {
9745
+ indexed = 0;
9746
+ indexTable() {
9747
+ for (let i = this.indexed; i < this.table.length; i++) {
9748
+ const fn = this.table.get(i);
9749
+ if (fn && !this.slots.has(fn)) this.slots.set(fn, i);
9750
+ }
9751
+ this.indexed = this.table.length;
9752
+ }
9753
+ slot(fn, handle, name2) {
9754
+ this.indexTable();
9545
9755
  const known = this.slots.get(fn);
9546
9756
  if (known !== void 0) return known;
9547
9757
  const index2 = this.reserve(1);
9548
9758
  growTable(this.table, index2 + 1);
9549
9759
  this.table.set(index2, fn);
9550
9760
  this.slots.set(fn, index2);
9551
- this.publisher?.({ kind: "slot", index: index2, handle, name });
9761
+ this.publisher?.({ kind: "slot", index: index2, handle, name: name2 });
9552
9762
  return index2;
9553
9763
  }
9554
9764
  allocate(size, alignment) {
@@ -9786,8 +9996,8 @@ function wasixSocketImports(host, preview1) {
9786
9996
  },
9787
9997
  sock_set_opt_time: (fd) => void socket(fd),
9788
9998
  sock_send_file: () => E.NOSYS,
9789
- resolve: (name, len, _port, addrs, naddrs, out) => {
9790
- const found = call2({ op: "sock-resolve", name: mem.string(name, len), family: 0 });
9999
+ resolve: (name2, len, _port, addrs, naddrs, out) => {
10000
+ const found = call2({ op: "sock-resolve", name: mem.string(name2, len), family: 0 });
9791
10001
  const ips = found.map(ipBytes).filter((ip) => ip !== void 0);
9792
10002
  if (ips.length === 0) throw new WasiError("ENOENT");
9793
10003
  if (naddrs < 1) throw new WasiError("EINVAL");
@@ -9852,7 +10062,7 @@ function posixSignal(sig) {
9852
10062
  function nsToMs(ns) {
9853
10063
  return Math.ceil(Number(ns) / 1e6);
9854
10064
  }
9855
- var FDFLAGSEXT_CLOEXEC, SPAWN_OP_SIZE, SPAWN_OPS, RIGHTS_FD_WRITE, ICANON2, ECHO2, FUTEX_SLICE_MS, WasixHost;
10065
+ var FDFLAGSEXT_CLOEXEC, SPAWN_OP_SIZE, SPAWN_OPS, RIGHTS_FD_WRITE, ICANON2, ECHO2, FUTEX_SLICE_MS, MAIN_HANDLE, WasixHost;
9856
10066
  var init_wasix_host = __esm({
9857
10067
  "src/process/wasi/wasix-host.ts"() {
9858
10068
  "use strict";
@@ -9864,6 +10074,7 @@ var init_wasix_host = __esm({
9864
10074
  init_wasix_linker();
9865
10075
  init_wasix_process();
9866
10076
  init_wasix_sockets();
10077
+ init_wasix_trampoline();
9867
10078
  init_wasm_functypes();
9868
10079
  FDFLAGSEXT_CLOEXEC = 1;
9869
10080
  SPAWN_OP_SIZE = 56;
@@ -9872,6 +10083,7 @@ var init_wasix_host = __esm({
9872
10083
  ICANON2 = 2;
9873
10084
  ECHO2 = 8;
9874
10085
  FUTEX_SLICE_MS = 50;
10086
+ MAIN_HANDLE = 2147483647;
9875
10087
  WasixHost = class _WasixHost {
9876
10088
  process;
9877
10089
  threads;
@@ -9963,6 +10175,18 @@ var init_wasix_host = __esm({
9963
10175
  if (!this.linker) throw new WasiError("ENOTSUP");
9964
10176
  this.mem.view().setUint32(out, this.linker.allocateClosure(), true);
9965
10177
  },
10178
+ closure_prepare: (backing, index2, argTypes, argCount, resultTypes, resultCount, userData) => {
10179
+ if (!this.linker) throw new WasiError("ENOTSUP");
10180
+ const params = valueTypes(this.mem.bytes(argTypes, argCount));
10181
+ const results = valueTypes(this.mem.bytes(resultTypes, resultCount));
10182
+ if (!params || !results) throw new WasiError("EINVAL");
10183
+ try {
10184
+ this.linker.prepareClosure({ index: index2, backing, userData, params, results });
10185
+ } catch (e) {
10186
+ if (e instanceof DlError) throw new WasiError("EINVAL");
10187
+ throw e;
10188
+ }
10189
+ },
9966
10190
  closure_free: (index2) => {
9967
10191
  if (!this.linker) throw new WasiError("ENOTSUP");
9968
10192
  this.linker.freeClosure(index2);
@@ -9992,7 +10216,7 @@ var init_wasix_host = __esm({
9992
10216
  },
9993
10217
  proc_signals_sizes_get: (out) => void mem.view().setUint32(out, 0, true),
9994
10218
  proc_signals_get: () => E.SUCCESS,
9995
- callback_signal: (name, len) => void this.signals?.register(this.str(name, len)),
10219
+ callback_signal: (name2, len) => void this.signals?.register(this.str(name2, len)),
9996
10220
  proc_raise_interval: (sig, interval, repeat) => void host.o.kernel.call({
9997
10221
  op: "proc-alarm",
9998
10222
  sig: posixSignal(sig),
@@ -10139,23 +10363,23 @@ var init_wasix_host = __esm({
10139
10363
  return {
10140
10364
  dlopen: (p, pl, _flags, buf, len, lp, ll, out) => {
10141
10365
  if (p === 0) {
10142
- mem.view().setUint32(out, 0, true);
10366
+ mem.view().setUint32(out, MAIN_HANDLE, true);
10143
10367
  return E.SUCCESS;
10144
10368
  }
10145
10369
  return linked(
10146
10370
  buf,
10147
10371
  len,
10148
10372
  (l) => l.open(this.str(p, pl), host.cwd, lp === 0 ? [] : this.str(lp, ll).split(":")),
10149
- (h) => void mem.view().setUint32(out, h, true)
10373
+ (h) => void mem.view().setUint32(out, h === 0 ? MAIN_HANDLE : h, true)
10150
10374
  );
10151
10375
  },
10152
10376
  dlsym: (handle, s, sl, buf, len, out) => linked(
10153
10377
  buf,
10154
10378
  len,
10155
- (l) => l.symbol(handle, this.str(s, sl)),
10379
+ (l) => l.symbol(handle === MAIN_HANDLE ? 0 : handle, this.str(s, sl)),
10156
10380
  (v) => void mem.view().setUint32(out, v, true)
10157
10381
  ),
10158
- dl_invalid_handle: (handle) => handle !== 0 && this.linker && !this.linker.invalid(handle) ? E.SUCCESS : E.NOEXEC
10382
+ dl_invalid_handle: (handle) => handle === MAIN_HANDLE || handle !== 0 && this.linker && !this.linker.invalid(handle) ? E.SUCCESS : E.NOEXEC
10159
10383
  };
10160
10384
  }
10161
10385
  threadImports() {
@@ -10286,10 +10510,10 @@ function mainModule(lines) {
10286
10510
  }
10287
10511
  return void 0;
10288
10512
  }
10289
- function nameFrame(line, module, name) {
10513
+ function nameFrame(line, module, name2) {
10290
10514
  const m = UNNAMED_FRAME.exec(line);
10291
10515
  if (!m || m[3] !== module) return line;
10292
- const found = name(Number(m[4]));
10516
+ const found = name2(Number(m[4]));
10293
10517
  return found === void 0 ? line : `${m[1]}${found} (${m[2]})`;
10294
10518
  }
10295
10519
  function sidecarNames(read2, path) {
@@ -10325,29 +10549,29 @@ __export(wasi_runtime_exports, {
10325
10549
  trapMessage: () => trapMessage,
10326
10550
  unsupportedImport: () => unsupportedImport
10327
10551
  });
10328
- function enosys(module, name, foreign) {
10329
- const type = foreign?.[module]?.[name];
10330
- if (type === "other") throw new Error(noErrno(`${module}.${name}`));
10552
+ function enosys(module, name2, foreign) {
10553
+ const type = foreign?.[module]?.[name2];
10554
+ if (type === "other") throw new Error(noErrno(`${module}.${name2}`));
10331
10555
  if (type === "none") return () => void 0;
10332
10556
  if (type === "i64") return () => 52n;
10333
10557
  return () => 52;
10334
10558
  }
10335
10559
  function firstOther(foreign) {
10336
10560
  for (const [module, fields] of Object.entries(foreign)) {
10337
- const name = Object.keys(fields).find((field2) => fields[field2] === "other");
10338
- if (name !== void 0) return `${module}.${name}`;
10561
+ const name2 = Object.keys(fields).find((field2) => fields[field2] === "other");
10562
+ if (name2 !== void 0) return `${module}.${name2}`;
10339
10563
  }
10340
10564
  return void 0;
10341
10565
  }
10342
10566
  function accepted(imp, scope2) {
10343
- const { module, name, kind } = imp;
10567
+ const { module, name: name2, kind } = imp;
10344
10568
  if (module === PREVIEW1 || module === WASIX) return true;
10345
10569
  if (!RESERVED2.has(module) && (scope2.extended || scope2.wasi && kind === "function")) return true;
10346
10570
  if (scope2.pie && (module === "GOT.mem" || module === "GOT.func")) return true;
10347
10571
  if (scope2.pie && module === "env" && kind !== "memory") return true;
10348
- if (kind === "memory" && scope2.memory?.module === module && scope2.memory.name === name)
10572
+ if (kind === "memory" && scope2.memory?.module === module && scope2.memory.name === name2)
10349
10573
  return true;
10350
- return module === "wasi" && name === "thread-spawn" && (scope2.wasix || !!scope2.memory?.shared);
10574
+ return module === "wasi" && name2 === "thread-spawn" && (scope2.wasix || !!scope2.memory?.shared);
10351
10575
  }
10352
10576
  function unsupportedImport(module, memory, extended = false, foreign = {}) {
10353
10577
  const imports = WebAssembly.Module.imports(module);
@@ -10538,6 +10762,7 @@ async function instantiate(host, module, memory, threads, {
10538
10762
  }
10539
10763
  if (sync) {
10540
10764
  sync.linker.bindMain(instance, !thread);
10765
+ if (path !== void 0) sync.linker.mainPath = path;
10541
10766
  if (thread) sync.catchUp();
10542
10767
  sync.linker.bindMainGot();
10543
10768
  }
@@ -10559,7 +10784,8 @@ function linkerHost(host, imports) {
10559
10784
  hostImports: () => {
10560
10785
  const { env: _env, "GOT.mem": _mem, "GOT.func": _func, ...rest2 } = imports();
10561
10786
  return rest2;
10562
- }
10787
+ },
10788
+ real: (path) => physicalPath(host.o.fs, path)
10563
10789
  };
10564
10790
  }
10565
10791
  function merge(base, extra) {
@@ -10661,12 +10887,12 @@ async function runWasiProcess(init, port3) {
10661
10887
  if (stats) report(stats, sys);
10662
10888
  }
10663
10889
  }
10664
- function trapMessage(e, env, where = "", name) {
10890
+ function trapMessage(e, env, where = "", name2) {
10665
10891
  const head = `wasm trap${where}: ${e.message}`;
10666
10892
  if (env.SLICC_WASM_BACKTRACE !== "1") return head;
10667
10893
  const lines = (e.stack ?? "").split("\n");
10668
- const main = name && mainModule(lines);
10669
- const frames = lines.filter((line) => /^\s+at .*wasm:\/\/wasm\//.test(line)).slice(0, BACKTRACE_FRAMES).map((line) => name && main ? nameFrame(line, main, name) : line);
10894
+ const main = name2 && mainModule(lines);
10895
+ const frames = lines.filter((line) => /^\s+at .*wasm:\/\/wasm\//.test(line)).slice(0, BACKTRACE_FRAMES).map((line) => name2 && main ? nameFrame(line, main, name2) : line);
10670
10896
  return frames.length ? `${head}
10671
10897
  ${frames.join("\n")}` : head;
10672
10898
  }
@@ -10746,6 +10972,7 @@ var TRAPPED, PREVIEW1, WASIX, SLICC, SIGNAL_CALLBACK, takeDefault, SLICC_FS, SLI
10746
10972
  var init_wasi_runtime = __esm({
10747
10973
  "src/process/wasi/wasi-runtime.ts"() {
10748
10974
  "use strict";
10975
+ init_physical_path();
10749
10976
  init_protocol();
10750
10977
  init_signals();
10751
10978
  init_sync_sab_bridge();
@@ -10817,8 +11044,8 @@ var init_wasi_runtime = __esm({
10817
11044
  const ids = this.ids;
10818
11045
  if (!ids) return { preview1, wasix };
10819
11046
  const wrap2 = (table) => Object.fromEntries(
10820
- Object.entries(table).map(([name, fn]) => [
10821
- name,
11047
+ Object.entries(table).map(([name2, fn]) => [
11048
+ name2,
10822
11049
  ((...args) => {
10823
11050
  if (Atomics.load(ids, DL_GEN) !== this.gen) this.catchUp();
10824
11051
  const result = fn(...args);
@@ -10858,19 +11085,19 @@ var NODE_SLOTS = [
10858
11085
  "clearImmediate"
10859
11086
  ];
10860
11087
  function vacate(target, names) {
10861
- for (const name of names) {
11088
+ for (const name2 of names) {
10862
11089
  for (let at = target; at && at !== Object.prototype; ) {
10863
- if (Object.getOwnPropertyDescriptor(at, name)?.configurable) Reflect.deleteProperty(at, name);
11090
+ if (Object.getOwnPropertyDescriptor(at, name2)?.configurable) Reflect.deleteProperty(at, name2);
10864
11091
  at = Object.getPrototypeOf(at);
10865
11092
  }
10866
- Reflect.defineProperty(target, name, {
11093
+ Reflect.defineProperty(target, name2, {
10867
11094
  value: void 0,
10868
11095
  writable: true,
10869
11096
  enumerable: false,
10870
11097
  configurable: true
10871
11098
  });
10872
- if (Reflect.get(target, name) !== void 0) {
10873
- throw new Error(`slicc-kernel: cannot withhold ${name} from a JS program`);
11099
+ if (Reflect.get(target, name2) !== void 0) {
11100
+ throw new Error(`slicc-kernel: cannot withhold ${name2} from a JS program`);
10874
11101
  }
10875
11102
  }
10876
11103
  }