@ai-ecoverse/slicc-kernel 1.31.0 → 1.31.2

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.
@@ -1318,7 +1318,7 @@ function sabViews(sab) {
1318
1318
  window: new Uint8Array(sab, SAB_HEADER_BYTES)
1319
1319
  };
1320
1320
  }
1321
- var SAB_HEADER_I32, SAB_HEADER_BYTES, SAB_I_STATE, SAB_I_SEQ, SAB_I_STATUS, SAB_I_TOTAL, SAB_I_CHUNK, SAB_I_OFFSET, SAB_I_REQ, SAB_I_PUB, SAB_I_SIGNALS, SAB_I_TIMERS, SAB_I_MEMORY, SAB_I_TOTAL_HI, SAB_I_OFFSET_HI, U32, SAB_STATE_IDLE, SAB_STATE_PENDING, SAB_STATE_READY, SAB_STATUS_BYTES, SAB_STATUS_JSON, SAB_STATUS_VOID, SAB_STATUS_ERRNO, SAB_DEFAULT_WINDOW_BYTES, SAB_MIN_BYTES, SYNC_SAB_REQ_MSG, SYNC_SAB_NEXT_MSG, encoder, decoder;
1321
+ var SAB_HEADER_I32, SAB_HEADER_BYTES, SAB_I_STATE, SAB_I_SEQ, SAB_I_STATUS, SAB_I_TOTAL, SAB_I_CHUNK, SAB_I_OFFSET, SAB_I_REQ, SAB_I_PUB, SAB_I_SIGNALS, SAB_I_TIMERS, SAB_I_MEMORY, SAB_I_TOTAL_HI, SAB_I_OFFSET_HI, SAB_I_KILLED, U32, SAB_STATE_IDLE, SAB_STATE_PENDING, SAB_STATE_READY, SAB_STATUS_BYTES, SAB_STATUS_JSON, SAB_STATUS_VOID, SAB_STATUS_ERRNO, SAB_DEFAULT_WINDOW_BYTES, SAB_MIN_BYTES, SYNC_SAB_REQ_MSG, SYNC_SAB_NEXT_MSG, encoder, decoder;
1322
1322
  var init_sync_sab_wire = __esm({
1323
1323
  "src/realm/sync-sab-wire.ts"() {
1324
1324
  "use strict";
@@ -1337,6 +1337,7 @@ var init_sync_sab_wire = __esm({
1337
1337
  SAB_I_MEMORY = 10;
1338
1338
  SAB_I_TOTAL_HI = 11;
1339
1339
  SAB_I_OFFSET_HI = 12;
1340
+ SAB_I_KILLED = 13;
1340
1341
  U32 = 2 ** 32;
1341
1342
  SAB_STATE_IDLE = 0;
1342
1343
  SAB_STATE_PENDING = 1;
@@ -2836,6 +2837,7 @@ var init_process_signals = __esm({
2836
2837
  lastDelivered = 0;
2837
2838
  depth = 0;
2838
2839
  reporting = false;
2840
+ unwinding = false;
2839
2841
  raw;
2840
2842
  header;
2841
2843
  hooks;
@@ -2881,6 +2883,11 @@ var init_process_signals = __esm({
2881
2883
  this.raw.call({ op: "sig-mask", caught, ignored }, Number.POSITIVE_INFINITY, "sig-mask");
2882
2884
  }
2883
2885
  deliver() {
2886
+ const killed = Atomics.load(this.header, SAB_I_KILLED);
2887
+ if (killed !== 0 && !this.unwinding && this.hooks.killed) {
2888
+ this.unwinding = true;
2889
+ this.hooks.killed(killed);
2890
+ }
2884
2891
  const timers = Atomics.exchange(this.header, SAB_I_TIMERS, 0);
2885
2892
  const pending = Atomics.exchange(this.header, SAB_I_SIGNALS, 0);
2886
2893
  if (this.depth <= 1) this.lastDelivered = pending | (timers & 1 ? sigbit(SIG.ALRM) : 0);
@@ -4001,6 +4008,9 @@ var init_wasi_files = __esm({
4001
4008
  data;
4002
4009
  length = 0;
4003
4010
  dirty = false;
4011
+ whole = false;
4012
+ from = Infinity;
4013
+ to = 0;
4004
4014
  orphaned = false;
4005
4015
  opens = 0;
4006
4016
  fs;
@@ -4019,6 +4029,7 @@ var init_wasi_files = __esm({
4019
4029
  } else if (empty) {
4020
4030
  this.data = new Uint8Array(0);
4021
4031
  this.dirty = true;
4032
+ this.whole = true;
4022
4033
  }
4023
4034
  }
4024
4035
  get path() {
@@ -4071,6 +4082,8 @@ var init_wasi_files = __esm({
4071
4082
  this.load();
4072
4083
  this.ensure(end);
4073
4084
  const buf = this.data;
4085
+ this.from = Math.min(this.from, at, this.length);
4086
+ this.to = Math.max(this.to, end);
4074
4087
  if (at > this.length) buf.fill(0, this.length, at);
4075
4088
  buf.set(bytes, at);
4076
4089
  this.length = Math.max(this.length, end);
@@ -4085,6 +4098,7 @@ var init_wasi_files = __esm({
4085
4098
  }
4086
4099
  this.load();
4087
4100
  this.ensure(size);
4101
+ this.whole = true;
4088
4102
  if (size > this.length) this.data.fill(0, this.length, size);
4089
4103
  this.length = size;
4090
4104
  }
@@ -4112,9 +4126,14 @@ var init_wasi_files = __esm({
4112
4126
  flush() {
4113
4127
  if (this.orphaned || !this.dirty) return;
4114
4128
  if (this.ranged) this.ranged.flush();
4115
- else if (this.data) this.fs.writeFile(this.path, this.data.slice(0, this.length));
4116
- else return;
4129
+ else if (!this.data) return;
4130
+ else if (this.whole || !this.fs.pwrite)
4131
+ this.fs.writeFile(this.path, this.data.slice(0, this.length));
4132
+ else this.fs.pwrite(this.path, this.from, this.data.slice(this.from, this.to), true);
4117
4133
  this.dirty = false;
4134
+ this.whole = false;
4135
+ this.from = Infinity;
4136
+ this.to = 0;
4118
4137
  }
4119
4138
  };
4120
4139
  LocalFile = class {
@@ -4563,6 +4582,14 @@ var init_wasi_fds = __esm({
4563
4582
  flushAll() {
4564
4583
  for (const buffer of this.buffers.values()) buffer.flush();
4565
4584
  }
4585
+ flushEarly() {
4586
+ for (const buffer of this.buffers.values()) {
4587
+ try {
4588
+ buffer.flush();
4589
+ } catch {
4590
+ }
4591
+ }
4592
+ }
4566
4593
  flushPath(path) {
4567
4594
  for (const [p, buffer] of this.buffers) if (within(p, path)) buffer.flush();
4568
4595
  if (this.shared) this.kernel.call({ op: "fd-path-flush", path });
@@ -4958,9 +4985,24 @@ var init_wasi_host = __esm({
4958
4985
  listening;
4959
4986
  o;
4960
4987
  constructor(o) {
4961
- this.o = o;
4988
+ const { kernel } = o;
4989
+ const call2 = (req) => {
4990
+ if (req.op !== "fd-promote") this.fds.flushEarly();
4991
+ return kernel.call(req);
4992
+ };
4993
+ const sys = new Proxy(kernel.sys, {
4994
+ get: (target, name) => {
4995
+ const member = Reflect.get(target, name);
4996
+ if (typeof member !== "function") return member;
4997
+ return (...args) => {
4998
+ this.fds.flushEarly();
4999
+ return member.apply(target, args);
5000
+ };
5001
+ }
5002
+ });
5003
+ this.o = { ...o, kernel: { sys, call: call2 } };
4962
5004
  this.startCwd = o.cwd;
4963
- this.fds = new WasiFds(o.kernel, o.fs);
5005
+ this.fds = new WasiFds(this.o.kernel, o.fs);
4964
5006
  if (o.shared) this.fds.share(o.shared, true);
4965
5007
  else if (o.forked) this.fds.restore(o.forked.fds, o.forked.cloexec);
4966
5008
  else this.fds.setup(o.cwd, o.inherited ?? [], o.preopenRoot === true);
@@ -5647,8 +5689,13 @@ var init_wasi_signals = __esm({
5647
5689
  uncaught = 0;
5648
5690
  delivering;
5649
5691
  fallBack;
5650
- constructor(fallBack) {
5692
+ onKilled;
5693
+ constructor(fallBack, onKilled) {
5651
5694
  this.fallBack = fallBack;
5695
+ this.onKilled = onKilled;
5696
+ }
5697
+ killed(code2) {
5698
+ this.onKilled?.(code2);
5652
5699
  }
5653
5700
  bind(exports) {
5654
5701
  this.exports = exports;
@@ -7387,10 +7434,15 @@ function descriptors(init, fork, threads) {
7387
7434
  }
7388
7435
  async function runWasiProcess(init, port) {
7389
7436
  captureBacktraces(init.env);
7390
- const signals = new WasiSignals((sig) => {
7391
- call2({ op: "proc-kill", pid: init.pid, sig });
7392
- throw new WasiExit(128 + sig);
7393
- });
7437
+ const signals = new WasiSignals(
7438
+ (sig) => {
7439
+ call2({ op: "proc-kill", pid: init.pid, sig });
7440
+ throw new WasiExit(128 + sig);
7441
+ },
7442
+ (code2) => {
7443
+ throw new WasiExit(code2);
7444
+ }
7445
+ );
7394
7446
  const main = {};
7395
7447
  const { transport, sys, call: kernelCall, say } = kernelOf(init, port, signals, sizeOf(main));
7396
7448
  const id = identify(transport, init);