@ai-ecoverse/slicc-kernel 1.7.2 → 1.8.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.
@@ -5889,22 +5889,27 @@ __export(wasi_runtime_exports, {
5889
5889
  trapMessage: () => trapMessage,
5890
5890
  unsupportedImport: () => unsupportedImport
5891
5891
  });
5892
+ function accepted(imp, scope2) {
5893
+ const { module, name, kind } = imp;
5894
+ if (module === PREVIEW1 || module === WASIX) return true;
5895
+ if (!RESERVED.has(module) && (scope2.extended || scope2.wasi && kind === "function")) return true;
5896
+ if (scope2.pie && (module === "GOT.mem" || module === "GOT.func")) return true;
5897
+ if (scope2.pie && module === "env" && kind !== "memory") return true;
5898
+ if (kind === "memory" && scope2.memory?.module === module && scope2.memory.name === name)
5899
+ return true;
5900
+ return module === "wasi" && name === "thread-spawn" && (scope2.wasix || !!scope2.memory?.shared);
5901
+ }
5892
5902
  function unsupportedImport(module, memory, extended = false) {
5893
5903
  const imports = WebAssembly.Module.imports(module);
5894
5904
  const wasix = imports.some((i) => i.module === WASIX);
5895
- const pie = dylinkInfo(module) !== void 0;
5896
- for (const imp of imports) {
5897
- if (imp.module === PREVIEW1 || imp.module === WASIX) continue;
5898
- if (extended && !RESERVED.has(imp.module)) continue;
5899
- if (pie && (imp.module === "GOT.mem" || imp.module === "GOT.func")) continue;
5900
- if (pie && imp.module === "env" && imp.kind !== "memory") continue;
5901
- if (imp.kind === "memory" && memory?.module === imp.module && memory.name === imp.name)
5902
- continue;
5903
- if (imp.module === "wasi" && imp.name === "thread-spawn" && (wasix || memory?.shared)) continue;
5904
- if (imp.kind === "memory" || imp.module === "wasi") {
5905
- return `imports ${imp.module}.${imp.name}: no WASI program this host runs`;
5905
+ const wasi = wasix || imports.some((i) => i.module === PREVIEW1);
5906
+ const scope2 = { extended, wasi, wasix, pie: dylinkInfo(module) !== void 0, memory };
5907
+ const refused = imports.find((imp) => !accepted(imp, scope2));
5908
+ if (refused) {
5909
+ if (refused.kind === "memory" || refused.module === "wasi") {
5910
+ return `imports ${refused.module}.${refused.name}: no WASI program this host runs`;
5906
5911
  }
5907
- return `imports ${imp.module}.${imp.name}: no WASI preview1 program (an Emscripten one runs with its glue)`;
5912
+ return `imports ${refused.module}.${refused.name}: no WASI preview1 program (an Emscripten one runs with its glue)`;
5908
5913
  }
5909
5914
  if (!WebAssembly.Module.exports(module).some((e) => e.name === "_start")) {
5910
5915
  return "no WASI command (it exports no _start)";
@@ -5925,7 +5930,9 @@ function linkImports(module, preview1, wasix, memory, threads, program = {}) {
5925
5930
  const ns = imports[imp.module] ??= {};
5926
5931
  if (imp.name in ns) continue;
5927
5932
  if (imp.kind === "memory" && memory) ns[imp.name] = memory;
5928
- else if (imp.kind === "function") ns[imp.name] = () => imp.name === "thread-spawn" ? -1 : 52;
5933
+ else if (imp.kind === "function") {
5934
+ ns[imp.name] = () => imp.module === "wasi" && imp.name === "thread-spawn" ? -1 : 52;
5935
+ }
5929
5936
  }
5930
5937
  return imports;
5931
5938
  }