@ai-ecoverse/slicc-kernel 1.54.7 → 1.54.9

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.
@@ -4078,12 +4078,12 @@ async function runWasmProcess(init, port2, deps = {}) {
4078
4078
  const say = (fd) => (text) => sys.write(fd, encoder4.encode(`${text}
4079
4079
  `));
4080
4080
  let ready;
4081
- let failed4;
4081
+ let failed5;
4082
4082
  let memory;
4083
4083
  let exports;
4084
4084
  const initialized = new Promise((resolve, reject) => {
4085
4085
  ready = resolve;
4086
- failed4 = reject;
4086
+ failed5 = reject;
4087
4087
  });
4088
4088
  const id = identify(transport, init);
4089
4089
  const module = {
@@ -4136,7 +4136,7 @@ async function runWasmProcess(init, port2, deps = {}) {
4136
4136
  exports = instance.exports;
4137
4137
  publishMemory(init.sab, memory?.buffer.byteLength ?? 0);
4138
4138
  done(instance, init.program.module);
4139
- }, failed4);
4139
+ }, failed5);
4140
4140
  return {};
4141
4141
  },
4142
4142
  preRun: [
@@ -6802,6 +6802,7 @@ function* procWalk(path, follow2) {
6802
6802
  let done = [];
6803
6803
  let todo = path.split("/").filter((part) => part !== "");
6804
6804
  let hops = 0;
6805
+ let broken;
6805
6806
  while (todo.length > 0) {
6806
6807
  const part = todo.shift();
6807
6808
  if (part === ".") continue;
@@ -6811,32 +6812,48 @@ function* procWalk(path, follow2) {
6811
6812
  }
6812
6813
  const at = `/${[...done, part].join("/")}`;
6813
6814
  const whole = normalize(`/${[...done, part, ...todo].join("/")}`);
6814
- if (inProc(at) && inProc(whole)) return whole;
6815
+ if (inProc(at) && inProc(whole)) return broken ?? whole;
6815
6816
  if (!follow2 && todo.length === 0) return void 0;
6816
- const target = yield at;
6817
- if (target === null) return void 0;
6818
- if (target === void 0) done.push(part);
6819
- else {
6817
+ const target = yield { at, check: todo.find((next2) => next2 !== ".") === ".." };
6818
+ if (typeof target === "string") {
6820
6819
  if (++hops > MAX_HOPS2) return void 0;
6821
- if (target.startsWith("/")) done = [];
6822
- todo = [...target.split("/").filter((part2) => part2 !== ""), ...todo];
6820
+ [done, todo] = throughLink(target, done, todo);
6821
+ } else {
6822
+ broken ??= refusalOf(target);
6823
+ done.push(part);
6823
6824
  }
6824
6825
  }
6825
6826
  return void 0;
6826
6827
  }
6828
+ function failed2(err) {
6829
+ const code2 = err?.code;
6830
+ return { refused: typeof code2 === "string" ? code2 : "ENOENT" };
6831
+ }
6832
+ function refusalOf(found) {
6833
+ if (found === true) return void 0;
6834
+ return found === false ? { refused: "ENOTDIR" } : found;
6835
+ }
6836
+ function throughLink(target, done, todo) {
6837
+ const parts = target.split("/").filter((part) => part !== "");
6838
+ return [target.startsWith("/") ? [] : done, [...parts, ...todo]];
6839
+ }
6827
6840
  function procPath(fs, path, follow2) {
6828
6841
  const walk = procWalk(path, follow2);
6829
6842
  let step = walk.next();
6830
6843
  while (!step.done) {
6844
+ const { at, check } = step.value;
6831
6845
  let target;
6832
6846
  try {
6833
- target = fs.lstat(step.value).isSymbolicLink ? fs.readlink(step.value) : void 0;
6834
- } catch {
6835
- target = null;
6847
+ const st = fs.lstat(at);
6848
+ target = st.isSymbolicLink ? fs.readlink(at) : !check || st.isDirectory;
6849
+ } catch (err) {
6850
+ target = failed2(err);
6836
6851
  }
6837
6852
  step = walk.next(target);
6838
6853
  }
6839
- return step.value;
6854
+ const result = step.value;
6855
+ if (typeof result === "object") throw syncError(result.refused, path);
6856
+ return result;
6840
6857
  }
6841
6858
  function frozen(bytes) {
6842
6859
  const refuse = () => {
@@ -6918,11 +6935,19 @@ function procfsBridge(fs, tree) {
6918
6935
  ),
6919
6936
  exists: (p) => {
6920
6937
  if (inProc(p)) return tree.exists(p);
6921
- const real = shadowing() ? toProc(p, true) : void 0;
6938
+ const probe = () => {
6939
+ try {
6940
+ return toProc(p, true);
6941
+ } catch {
6942
+ return null;
6943
+ }
6944
+ };
6945
+ const real = shadowing() ? probe() : void 0;
6946
+ if (real === null) return false;
6922
6947
  if (real !== void 0) return tree.exists(real);
6923
6948
  if (fs.exists(p)) return true;
6924
- const late2 = toProc(p, true);
6925
- return late2 !== void 0 && tree.exists(late2);
6949
+ const late2 = probe();
6950
+ return typeof late2 === "string" && tree.exists(late2);
6926
6951
  },
6927
6952
  readlink: (p) => via(
6928
6953
  p,
@@ -8856,7 +8881,7 @@ var init_wasix_host = __esm({
8856
8881
  }
8857
8882
  dlImports() {
8858
8883
  const { mem, host } = this;
8859
- const failed4 = (message2, buf, len) => {
8884
+ const failed5 = (message2, buf, len) => {
8860
8885
  if (len > 0) {
8861
8886
  const bytes = new TextEncoder().encode(message2).subarray(0, len - 1);
8862
8887
  mem.bytes(buf, bytes.length).set(bytes);
@@ -8865,19 +8890,19 @@ var init_wasix_host = __esm({
8865
8890
  return E.NOEXEC;
8866
8891
  };
8867
8892
  const linked = (buf, len, op, out) => {
8868
- if (!this.linker) return failed4("not a dynamically-linked program", buf, len);
8893
+ if (!this.linker) return failed5("not a dynamically-linked program", buf, len);
8869
8894
  try {
8870
8895
  out(op(this.linker));
8871
8896
  return E.SUCCESS;
8872
8897
  } catch (e) {
8873
- if (e instanceof DlError) return failed4(e.message, buf, len);
8898
+ if (e instanceof DlError) return failed5(e.message, buf, len);
8874
8899
  throw e;
8875
8900
  }
8876
8901
  };
8877
8902
  return {
8878
8903
  dlopen: (p, pl, _flags, buf, len, lp, ll, out) => {
8879
8904
  if (p === 0) {
8880
- if (!this.linker) return failed4("not a dynamically-linked program", buf, len);
8905
+ if (!this.linker) return failed5("not a dynamically-linked program", buf, len);
8881
8906
  mem.view().setUint32(out, MAIN_HANDLE, true);
8882
8907
  return E.SUCCESS;
8883
8908
  }
@@ -9966,7 +9991,7 @@ function withoutFragment(url) {
9966
9991
  url.hash = "";
9967
9992
  return url.href;
9968
9993
  }
9969
- function failed2(err) {
9994
+ function failed3(err) {
9970
9995
  return new TypeError("fetch failed", { cause: err });
9971
9996
  }
9972
9997
  function plain(status2, text) {
@@ -9978,7 +10003,7 @@ function plain(status2, text) {
9978
10003
  function rewrite(hop, status2, location) {
9979
10004
  const next2 = new URL(location, hop.url);
9980
10005
  if (next2.protocol !== "http:" && next2.protocol !== "https:") {
9981
- throw failed2(new JsCallError("EPROTONOSUPPORT", next2.protocol));
10006
+ throw failed3(new JsCallError("EPROTONOSUPPORT", next2.protocol));
9982
10007
  }
9983
10008
  const toGet = (status2 === 301 || status2 === 302) && hop.method === "POST" || status2 === 303 && hop.method !== "GET" && hop.method !== "HEAD";
9984
10009
  const crossOrigin = next2.origin !== new URL(hop.url).origin;
@@ -10072,7 +10097,7 @@ function dataResponse(request) {
10072
10097
  const url = withoutFragment(new URL(request.url));
10073
10098
  const rest2 = url.slice("data:".length);
10074
10099
  const comma = rest2.indexOf(",");
10075
- if (comma < 0) throw failed2(new JsCallError("EINVAL", "a data: URL without a comma"));
10100
+ if (comma < 0) throw failed3(new JsCallError("EINVAL", "a data: URL without a comma"));
10076
10101
  let type = rest2.slice(0, comma).replace(/^[\t\n\f\r ]+|[\t\n\f\r ]+$/g, "");
10077
10102
  let body = percentDecode(rest2.slice(comma + 1));
10078
10103
  const base642 = BASE64.exec(type);
@@ -10082,7 +10107,7 @@ function dataResponse(request) {
10082
10107
  try {
10083
10108
  binary = atob(latin1(body));
10084
10109
  } catch {
10085
- throw failed2(new JsCallError("EINVAL", "a data: URL whose base64 does not decode"));
10110
+ throw failed3(new JsCallError("EINVAL", "a data: URL whose base64 does not decode"));
10086
10111
  }
10087
10112
  body = Uint8Array.from(binary, (c) => c.charCodeAt(0));
10088
10113
  }
@@ -10110,7 +10135,7 @@ function bytesOf(chunk) {
10110
10135
  if (ArrayBuffer.isView(chunk)) {
10111
10136
  return new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
10112
10137
  }
10113
- throw failed2(new TypeError("a request body chunk must be bytes or a string"));
10138
+ throw failed3(new TypeError("a request body chunk must be bytes or a string"));
10114
10139
  }
10115
10140
  async function bodyOf(request, cap, signal) {
10116
10141
  signal.throwIfAborted();
@@ -10123,7 +10148,7 @@ async function bodyOf(request, cap, signal) {
10123
10148
  try {
10124
10149
  for (; ; ) {
10125
10150
  const next2 = await reader.read().catch((err) => {
10126
- throw signal.aborted ? signal.reason : failed2(err);
10151
+ throw signal.aborted ? signal.reason : failed3(err);
10127
10152
  });
10128
10153
  signal.throwIfAborted();
10129
10154
  if (next2.done) break;
@@ -10172,7 +10197,7 @@ function fetchOp(kernel) {
10172
10197
  return r.ok && r.kind === "json" ? r.json : void 0;
10173
10198
  } catch (err) {
10174
10199
  await close(handle);
10175
- throw signal.aborted ? signal.reason : failed2(err);
10200
+ throw signal.aborted ? signal.reason : failed3(err);
10176
10201
  }
10177
10202
  };
10178
10203
  const body = (handle, signal) => {
@@ -10197,7 +10222,7 @@ function fetchOp(kernel) {
10197
10222
  } catch (err) {
10198
10223
  settle();
10199
10224
  await close(handle);
10200
- throw signal.aborted ? signal.reason : failed2(err);
10225
+ throw signal.aborted ? signal.reason : failed3(err);
10201
10226
  }
10202
10227
  const bytes = r.ok && r.kind === "bytes" ? r.bytes : new Uint8Array(0);
10203
10228
  if (bytes.length > 0) {
@@ -10219,7 +10244,7 @@ function fetchOp(kernel) {
10219
10244
  const respond = (head, method, redirected, encoded, signal) => {
10220
10245
  if (head.status < 200 || head.status > 599) {
10221
10246
  void close(head.handle);
10222
- throw failed2(new JsCallError("EPROTO", `status ${head.status}`));
10247
+ throw failed3(new JsCallError("EPROTO", `status ${head.status}`));
10223
10248
  }
10224
10249
  const empty = method === "HEAD" || NULL_BODY.has(head.status);
10225
10250
  if (empty) void close(head.handle);
@@ -10248,13 +10273,13 @@ function fetchOp(kernel) {
10248
10273
  const { protocol } = new URL(request.url);
10249
10274
  if (protocol === "data:") return dataResponse(request);
10250
10275
  if (protocol !== "http:" && protocol !== "https:") {
10251
- throw failed2(new JsCallError("EPROTONOSUPPORT", protocol));
10276
+ throw failed3(new JsCallError("EPROTONOSUPPORT", protocol));
10252
10277
  }
10253
10278
  const known = await traitsOf().catch((err) => {
10254
- throw failed2(err);
10279
+ throw failed3(err);
10255
10280
  });
10256
10281
  if (!known.manualRedirects && request.redirect !== "follow") {
10257
- throw failed2(new JsCallError("ENOTSUP", `redirect: ${request.redirect}`));
10282
+ throw failed3(new JsCallError("ENOTSUP", `redirect: ${request.redirect}`));
10258
10283
  }
10259
10284
  const url = withoutFragment(new URL(request.url));
10260
10285
  const bytes = await bodyOf(request, known.maxRequestBody, signal);
@@ -10276,8 +10301,8 @@ function fetchOp(kernel) {
10276
10301
  return respond(head, hop.method, redirected, known.encodedBodies, signal);
10277
10302
  }
10278
10303
  await close(head.handle);
10279
- if (request.redirect === "error") throw failed2(new JsCallError("EREDIRECT", hop.url));
10280
- if (hops >= MAX_REDIRECTS) throw failed2(new JsCallError("ELOOP", hop.url));
10304
+ if (request.redirect === "error") throw failed3(new JsCallError("EREDIRECT", hop.url));
10305
+ if (hops >= MAX_REDIRECTS) throw failed3(new JsCallError("ELOOP", hop.url));
10281
10306
  hop = rewrite(hop, head.status, location);
10282
10307
  }
10283
10308
  };
@@ -10514,13 +10539,13 @@ function netOps(kernel, io) {
10514
10539
  const r = await kernel.raw({ op: "sock-connect", fd, addr, nonblock: true });
10515
10540
  if (!r.ok && r.errno !== "EINPROGRESS") throw new JsCallError(r.errno, "connect");
10516
10541
  await kernel.blocking({ op: "fd-select", read: [], write: [fd], timeoutMs: -1 }, signal);
10517
- const failed4 = await kernel.json({
10542
+ const failed5 = await kernel.json({
10518
10543
  op: "sock-getopt",
10519
10544
  fd,
10520
10545
  level: SOL_SOCKET,
10521
10546
  name: SO_ERROR
10522
10547
  });
10523
- if (failed4 !== 0) throw new JsCallError(errnoName(failed4), "connect");
10548
+ if (failed5 !== 0) throw new JsCallError(errnoName(failed5), "connect");
10524
10549
  return connection(fd);
10525
10550
  });
10526
10551
  }
@@ -10853,7 +10878,7 @@ var init_js_tty = __esm({
10853
10878
  });
10854
10879
 
10855
10880
  // src/process/js/js-websocket.ts
10856
- function failed3(err) {
10881
+ function failed4(err) {
10857
10882
  return new TypeError("websocket failed", { cause: err });
10858
10883
  }
10859
10884
  function socketUrl(input) {
@@ -10897,7 +10922,7 @@ function websocketOp(kernel) {
10897
10922
  protocol = (r.ok && r.kind === "json" ? r.json : {}).protocol;
10898
10923
  } catch (err) {
10899
10924
  await free();
10900
- throw signal.aborted ? signal.reason : failed3(err);
10925
+ throw signal.aborted ? signal.reason : failed4(err);
10901
10926
  }
10902
10927
  let settle;
10903
10928
  let lose;
@@ -10947,7 +10972,7 @@ function websocketOp(kernel) {
10947
10972
  try {
10948
10973
  r = await kernel.blocking({ op: "net-ws-recv", handle }, stop.signal);
10949
10974
  } catch (err) {
10950
- hardStop(stop.signal.aborted ? stop.signal.reason : failed3(err));
10975
+ hardStop(stop.signal.aborted ? stop.signal.reason : failed4(err));
10951
10976
  throw stop.signal.reason;
10952
10977
  }
10953
10978
  stop.signal.throwIfAborted();
@@ -11548,20 +11573,20 @@ function started(init, port2, run, wasi, js) {
11548
11573
  return run(wasmInit, port2);
11549
11574
  }
11550
11575
  function processEntry(port2, run = runWasmProcess, wasi = loadWasi, js = loadJs) {
11551
- const failed4 = (err) => port2.postMessage({
11576
+ const failed5 = (err) => port2.postMessage({
11552
11577
  type: WASM_PROCESS_ERROR,
11553
11578
  message: err instanceof Error ? err.stack ?? err.message : String(err)
11554
11579
  });
11555
11580
  return (data) => {
11556
11581
  const type = data?.type;
11557
11582
  if (type === WASM_THREAD_INIT) {
11558
- wasi().then((m) => m.runWasiThread(data, port2)).catch(failed4);
11583
+ wasi().then((m) => m.runWasiThread(data, port2)).catch(failed5);
11559
11584
  return;
11560
11585
  }
11561
11586
  if (type !== WASM_PROCESS_INIT) return;
11562
11587
  started(data, port2, run, wasi, js).then(
11563
11588
  (code2) => port2.postMessage({ type: WASM_PROCESS_EXIT, code: code2 }),
11564
- failed4
11589
+ failed5
11565
11590
  );
11566
11591
  };
11567
11592
  }