@ai-ecoverse/slicc-kernel 1.100.3 → 1.101.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.
@@ -3289,6 +3289,7 @@ var init_wasi_host = __esm({
3289
3289
  signals;
3290
3290
  sigmask;
3291
3291
  linkedTls;
3292
+ threadEntry;
3292
3293
  linkedModules;
3293
3294
  interrupted;
3294
3295
  quietly = (fn) => fn();
@@ -4365,6 +4366,7 @@ var init_wasix_process = __esm({
4365
4366
  ...this.host.linkedTls ? { tls: this.host.linkedTls() } : {},
4366
4367
  ...this.host.linkedModules ? { modules: this.host.linkedModules() } : {}
4367
4368
  };
4369
+ if (this.host.threadEntry) wasi.entry = this.host.threadEntry;
4368
4370
  return this.call({
4369
4371
  op: "proc-fork",
4370
4372
  state: { memory, currData: 0, forkSp, callStackNames: [], ppid: this.host.o.pid, wasi },
@@ -4767,7 +4769,7 @@ var KERNEL_VERSION, OS_RELEASE;
4767
4769
  var init_version = __esm({
4768
4770
  "src/version.ts"() {
4769
4771
  "use strict";
4770
- KERNEL_VERSION = true ? "1.100.3" : "0.0.0-dev";
4772
+ KERNEL_VERSION = true ? "1.101.0" : "0.0.0-dev";
4771
4773
  OS_RELEASE = "6.0.0-slicc";
4772
4774
  }
4773
4775
  });
@@ -13538,6 +13540,11 @@ var init_wasix_fork = __esm({
13538
13540
  useStack(pointer, low) {
13539
13541
  this.linked = { pointer, low };
13540
13542
  }
13543
+ threadStack = false;
13544
+ useThreadStack(pointer, low) {
13545
+ this.useStack(pointer, low);
13546
+ this.threadStack = true;
13547
+ }
13541
13548
  bind(exports) {
13542
13549
  this.exports = exports;
13543
13550
  this.stackUpper = this.stackPointer();
@@ -13620,9 +13627,8 @@ var init_wasix_fork = __esm({
13620
13627
  return out;
13621
13628
  }
13622
13629
  dataPointer() {
13623
- if (this.linked && !(this.exports[STACK_POINTER] instanceof WebAssembly.Global)) {
13624
- return this.linked.low + 15 & ~15;
13625
- }
13630
+ const own = this.exports[STACK_POINTER] instanceof WebAssembly.Global;
13631
+ if (this.linked && (this.threadStack || !own)) return this.linked.low + 15 & ~15;
13626
13632
  const g = this.exports.__data_end;
13627
13633
  const dataEnd = g instanceof WebAssembly.Global ? g.value : 0;
13628
13634
  return dataEnd < this.stackUpper ? dataEnd + 15 & ~15 : 16;
@@ -15136,6 +15142,7 @@ __export(wasi_runtime_exports, {
15136
15142
  runWasiThread: () => runWasiThread,
15137
15143
  sigmaskOf: () => sigmaskOf,
15138
15144
  takeThreadDefault: () => takeThreadDefault,
15145
+ threadStackLow: () => threadStackLow,
15139
15146
  trapMessage: () => trapMessage,
15140
15147
  unsupportedImport: () => unsupportedImport,
15141
15148
  wireSignals: () => wireSignals
@@ -15315,6 +15322,34 @@ function report(stats, sys) {
15315
15322
  } catch {
15316
15323
  }
15317
15324
  }
15325
+ function isWasix(module) {
15326
+ return WebAssembly.Module.imports(module).some((i) => i.module === WASIX);
15327
+ }
15328
+ function threadStackLow(memory, start2) {
15329
+ if (start2 < 0 || start2 + START_ARGS_SLACK > memory.byteLength) return void 0;
15330
+ const stack = memory.getUint32(start2 + START_STACK, true);
15331
+ const size = memory.getUint32(start2 + START_STACK_SIZE, true);
15332
+ if (size < MIN_THREAD_STACK || size > memory.byteLength || size > stack) return void 0;
15333
+ if (stack % 16 !== 0 || stack > start2 + START_ARGS_SLACK || stack + START_ARGS_SLACK < start2) {
15334
+ return void 0;
15335
+ }
15336
+ return stack - size;
15337
+ }
15338
+ function ownStack(driver, instance, linked, low) {
15339
+ const own = instance.exports.__stack_pointer;
15340
+ const pointer = own instanceof WebAssembly.Global ? own : linked;
15341
+ if (!pointer) return false;
15342
+ driver.useThreadStack(pointer, low);
15343
+ return true;
15344
+ }
15345
+ function untilDone(run, driver) {
15346
+ do
15347
+ run();
15348
+ while (driver.resume());
15349
+ }
15350
+ function threadStart(instance) {
15351
+ return instance.exports.wasi_thread_start;
15352
+ }
15318
15353
  function spawnsThreads(module) {
15319
15354
  return WebAssembly.Module.imports(module).some(
15320
15355
  (i) => i.module === "wasi" && i.name === "thread-spawn" || i.module === WASIX && i.name === "thread_spawn_v2"
@@ -15398,7 +15433,7 @@ async function instantiate(host, module, memory, threads, {
15398
15433
  }
15399
15434
  if (sync) bindLinker(host, sync, instance, { thread, forked, path });
15400
15435
  if (sync && !thread) driver.useStack(sync.linker.stackPointer, sync.linker.stackLow);
15401
- return { instance, driver };
15436
+ return { instance, driver, linkedStack: sync?.linker.stackPointer };
15402
15437
  }
15403
15438
  function bindLinker(host, sync, instance, at) {
15404
15439
  sync.linker.bindMain(instance, !at.thread);
@@ -15516,7 +15551,7 @@ async function runWasiProcess(init, port3) {
15516
15551
  };
15517
15552
  }
15518
15553
  const program = await programImports(init.program, host, transport, MAIN_TID);
15519
- const { instance, driver } = await instantiate(host, module, memory, threads, {
15554
+ const { instance, driver, linkedStack } = await instantiate(host, module, memory, threads, {
15520
15555
  ...fork ? { forked: fork } : {},
15521
15556
  stats,
15522
15557
  signals,
@@ -15536,11 +15571,15 @@ async function runWasiProcess(init, port3) {
15536
15571
  host.muted = (fd, data) => signals.muted(fd, data);
15537
15572
  const exports = instance.exports;
15538
15573
  driver.bind(instance.exports);
15574
+ const entry = fork?.entry;
15575
+ if (entry) {
15576
+ ownStack(driver, instance, linkedStack, entry.low);
15577
+ host.threadEntry = entry;
15578
+ }
15579
+ const run = entry ? () => threadStart(instance)(entry.tid, entry.arg) : () => exports._start();
15539
15580
  try {
15540
15581
  if (fork) driver.startChild(fork);
15541
- do
15542
- exports._start();
15543
- while (driver.resume());
15582
+ untilDone(run, driver);
15544
15583
  return 0;
15545
15584
  } catch (e) {
15546
15585
  if (e instanceof WasiExit) return e.code;
@@ -15607,7 +15646,9 @@ async function runWasiThread(init, port3) {
15607
15646
  });
15608
15647
  host.sigmask = sigmaskOf(init.program.module, init.sab, gate, threads, init.signals);
15609
15648
  const program = await programImports(init.program, host, transport, thread.tid);
15610
- const { instance } = await instantiate(host, init.program.module, thread.memory, threads, {
15649
+ const { module } = init.program;
15650
+ const { memory } = thread;
15651
+ const { instance, driver, linkedStack } = await instantiate(host, module, memory, threads, {
15611
15652
  thread: true,
15612
15653
  foreign: init.program.foreign,
15613
15654
  path: init.program.path,
@@ -15617,9 +15658,14 @@ async function runWasiThread(init, port3) {
15617
15658
  signals.register(SIGNAL_CALLBACK);
15618
15659
  wireSignals(host, gate);
15619
15660
  host.onRaise = (sig) => signals.raised(sig);
15620
- const start2 = instance.exports.wasi_thread_start;
15661
+ const low = isWasix(module) ? threadStackLow(host.mem.view(), thread.arg) : void 0;
15662
+ if (low !== void 0 && ownStack(driver, instance, linkedStack, low)) {
15663
+ driver.bind(instance.exports);
15664
+ host.threadEntry = { tid: thread.tid, arg: thread.arg, low };
15665
+ }
15666
+ const start2 = threadStart(instance);
15621
15667
  try {
15622
- start2(thread.tid, thread.arg);
15668
+ untilDone(() => start2(thread.tid, thread.arg), driver);
15623
15669
  threads.exited();
15624
15670
  } catch (e) {
15625
15671
  if (e instanceof ThreadExit) {
@@ -15641,7 +15687,7 @@ async function runWasiThread(init, port3) {
15641
15687
  throw e;
15642
15688
  }
15643
15689
  }
15644
- var TRAPPED, PREVIEW1, WASIX, SLICC, SIGNAL_CALLBACK, takeDefault, takeThreadDefault, SLICC_FS, SLICC_TTY, RESERVED2, UNDELIVERED, DELIVERED, importsSlicc, importsSigactionHook, noErrno, FALLBACK_MAXIMUM_PAGES, LinkSync, DL_GEN, BACKTRACE_FRAMES;
15690
+ var TRAPPED, PREVIEW1, WASIX, SLICC, SIGNAL_CALLBACK, takeDefault, takeThreadDefault, SLICC_FS, SLICC_TTY, RESERVED2, UNDELIVERED, DELIVERED, importsSlicc, importsSigactionHook, noErrno, FALLBACK_MAXIMUM_PAGES, START_STACK, START_STACK_SIZE, MIN_THREAD_STACK, START_ARGS_SLACK, LinkSync, DL_GEN, BACKTRACE_FRAMES;
15645
15691
  var init_wasi_runtime = __esm({
15646
15692
  "src/process/wasi/wasi-runtime.ts"() {
15647
15693
  "use strict";
@@ -15701,6 +15747,10 @@ var init_wasi_runtime = __esm({
15701
15747
  importsSigactionHook = (module) => importsSlicc(module, "sigaction_set");
15702
15748
  noErrno = (key) => `imports ${key}: its result cannot carry ENOSYS, and this host does not provide it`;
15703
15749
  FALLBACK_MAXIMUM_PAGES = 32768;
15750
+ START_STACK = 0;
15751
+ START_STACK_SIZE = 56;
15752
+ MIN_THREAD_STACK = 4096;
15753
+ START_ARGS_SLACK = 64;
15704
15754
  LinkSync = class {
15705
15755
  count = 0;
15706
15756
  gen = 0;