@ai-ecoverse/slicc-kernel 1.108.3 → 1.108.4

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.
@@ -2491,7 +2491,7 @@ var KERNEL_VERSION, OS_RELEASE;
2491
2491
  var init_version = __esm({
2492
2492
  "src/version.ts"() {
2493
2493
  "use strict";
2494
- KERNEL_VERSION = true ? "1.108.3" : "0.0.0-dev";
2494
+ KERNEL_VERSION = true ? "1.108.4" : "0.0.0-dev";
2495
2495
  OS_RELEASE = "6.0.0-slicc";
2496
2496
  }
2497
2497
  });
@@ -6444,7 +6444,7 @@ function pinnedIo2(bridge, handle, rewriting) {
6444
6444
  } : {}
6445
6445
  };
6446
6446
  }
6447
- var WasiError, FileBuffer, LocalFile, MAX_LINKS, MISS_TTL_MS, CACHE_CAP, FS_GEN, CRED_GEN, RING2, RING_SIZE2, SLOT2, SHARED_IDS_BYTES, StatCache;
6447
+ var WasiError, FileBuffer, LocalFile, MAX_LINKS, MISS_TTL_MS, CACHE_CAP, FS_GEN, CRED_GEN, RING2, RING_SIZE2, SLOT2, FD_RING, FD_RING_SIZE, SHARED_IDS_BYTES, StatCache;
6448
6448
  var init_wasi_files = __esm({
6449
6449
  "src/process/wasi/wasi-files.ts"() {
6450
6450
  "use strict";
@@ -6671,7 +6671,9 @@ var init_wasi_files = __esm({
6671
6671
  RING2 = 8;
6672
6672
  RING_SIZE2 = 64;
6673
6673
  SLOT2 = 3;
6674
- SHARED_IDS_BYTES = (RING2 + RING_SIZE2 * SLOT2) * 4;
6674
+ FD_RING = RING2 + RING_SIZE2 * SLOT2;
6675
+ FD_RING_SIZE = 64;
6676
+ SHARED_IDS_BYTES = (FD_RING + FD_RING_SIZE * 2) * 4;
6675
6677
  StatCache = class {
6676
6678
  stats = /* @__PURE__ */ new Map();
6677
6679
  lstats = /* @__PURE__ */ new Map();
@@ -6997,6 +6999,9 @@ function within(path, root) {
6997
6999
  function kernelEntry2() {
6998
7000
  return { type: "kernel", nonblock: false, append: false };
6999
7001
  }
7002
+ function ringed(shared) {
7003
+ return shared.length >= FD_RING + FD_RING_SIZE * 2;
7004
+ }
7000
7005
  function deviceEntry(meta) {
7001
7006
  return { type: "device", device: meta.device, ...meta.access ? { access: meta.access } : {} };
7002
7007
  }
@@ -7164,16 +7169,44 @@ var init_wasi_fds = __esm({
7164
7169
  this.seen = Atomics.load(ids, GEN2);
7165
7170
  }
7166
7171
  sync() {
7167
- const gen = Atomics.load(this.shared, GEN2);
7172
+ const shared = this.shared;
7173
+ const gen = Atomics.load(shared, GEN2);
7168
7174
  if (gen === this.seen) return;
7169
- this.table.clear();
7170
- this.cloexec.clear();
7175
+ if (!this.replay(shared, gen)) {
7176
+ this.table.clear();
7177
+ this.cloexec.clear();
7178
+ }
7171
7179
  this.seen = gen;
7172
7180
  }
7173
- bump() {
7181
+ replay(shared, upTo) {
7182
+ if (upTo - this.seen > FD_RING_SIZE || !ringed(shared)) return false;
7183
+ const changed2 = [];
7184
+ for (let g = this.seen + 1; g <= upTo; g++) {
7185
+ const at = FD_RING + g % FD_RING_SIZE * 2;
7186
+ if (Atomics.load(shared, at) !== g) return false;
7187
+ const fd = Atomics.load(shared, at + 1);
7188
+ if (fd < 0 || Atomics.load(shared, at) !== g) return false;
7189
+ changed2.push(fd);
7190
+ }
7191
+ for (const fd of changed2) {
7192
+ this.table.delete(fd);
7193
+ this.cloexec.delete(fd);
7194
+ }
7195
+ return true;
7196
+ }
7197
+ bump(...fds) {
7174
7198
  if (!this.shared) return;
7175
- const gen = Atomics.add(this.shared, GEN2, 1) + 1;
7176
- if (gen - 1 === this.seen) this.seen = gen;
7199
+ const shared = this.shared;
7200
+ for (const fd of fds.length > 0 ? fds : [-1]) {
7201
+ const gen = Atomics.add(shared, GEN2, 1) + 1;
7202
+ if (ringed(shared)) {
7203
+ const at = FD_RING + gen % FD_RING_SIZE * 2;
7204
+ Atomics.store(shared, at, 0);
7205
+ Atomics.store(shared, at + 1, fd);
7206
+ Atomics.store(shared, at, gen);
7207
+ }
7208
+ if (gen - 1 === this.seen) this.seen = gen;
7209
+ }
7177
7210
  }
7178
7211
  stdioEntry(fd) {
7179
7212
  let info;
@@ -7216,7 +7249,7 @@ var init_wasi_fds = __esm({
7216
7249
  e.append = append;
7217
7250
  if (this.shared) {
7218
7251
  this.publishFlags(fd, e);
7219
- this.bump();
7252
+ this.bump(fd);
7220
7253
  }
7221
7254
  } else if (e.type === "file") e.file.append = append;
7222
7255
  }
@@ -7226,7 +7259,7 @@ var init_wasi_fds = __esm({
7226
7259
  else this.cloexec.delete(fd);
7227
7260
  if (this.shared) {
7228
7261
  this.kernel.call({ op: "fd-cloexec", fd, on });
7229
- this.bump();
7262
+ this.bump(fd);
7230
7263
  }
7231
7264
  }
7232
7265
  cwd() {
@@ -7243,7 +7276,7 @@ var init_wasi_fds = __esm({
7243
7276
  adopt(fd, kind, nonblock, dgram = false) {
7244
7277
  this.table.set(fd, { type: "kernel", kind, dgram, nonblock, append: false });
7245
7278
  if (this.shared && nonblock) this.publishFlags(fd, { nonblock, append: false });
7246
- this.bump();
7279
+ this.bump(fd);
7247
7280
  }
7248
7281
  get(fd) {
7249
7282
  const e = this.find(fd);
@@ -7268,7 +7301,7 @@ var init_wasi_fds = __esm({
7268
7301
  ...meta ? { meta } : {}
7269
7302
  });
7270
7303
  this.table.set(fd, e);
7271
- this.bump();
7304
+ this.bump(fd);
7272
7305
  return fd;
7273
7306
  }
7274
7307
  cloexec = /* @__PURE__ */ new Set();
@@ -7284,14 +7317,14 @@ var init_wasi_fds = __esm({
7284
7317
  at = this.install(e.type === "file" ? e : { ...e }, min);
7285
7318
  }
7286
7319
  if (cloexec) this.setCloexec(at, true);
7287
- this.bump();
7320
+ this.bump(at);
7288
7321
  return at;
7289
7322
  }
7290
7323
  pipe() {
7291
7324
  const [r, w] = this.kernel.sys.pipe();
7292
7325
  this.table.set(r, { type: "kernel", kind: "stream", nonblock: false, append: false });
7293
7326
  this.table.set(w, { type: "kernel", kind: "stream", nonblock: false, append: false });
7294
- this.bump();
7327
+ this.bump(r, w);
7295
7328
  return [r, w];
7296
7329
  }
7297
7330
  chdir(path) {
@@ -7391,7 +7424,7 @@ var init_wasi_fds = __esm({
7391
7424
  } finally {
7392
7425
  this.release(e);
7393
7426
  this.dropLocks(e);
7394
- this.bump();
7427
+ this.bump(fd);
7395
7428
  }
7396
7429
  }
7397
7430
  renumber(from, to, keep = false) {
@@ -7410,7 +7443,7 @@ var init_wasi_fds = __esm({
7410
7443
  }
7411
7444
  if (old) this.release(old);
7412
7445
  this.dropLocks(old);
7413
- this.bump();
7446
+ this.bump(from, to);
7414
7447
  }
7415
7448
  release(e) {
7416
7449
  if (e.type !== "file" || --e.file.refs > 0) return;
@@ -7598,7 +7631,6 @@ var init_wasi_fds = __esm({
7598
7631
  kind = "tty";
7599
7632
  } else return void 0;
7600
7633
  this.adopt(fd, kind, nonblock);
7601
- this.bump();
7602
7634
  return fd;
7603
7635
  }
7604
7636
  openCharDevice(openDevice2, oflags, rights) {
@@ -7723,7 +7755,7 @@ var init_wasi_fds = __esm({
7723
7755
  if (truncate) this.fs.touched?.(path, ino);
7724
7756
  this.table.set(fd, { type: "kernel", kind: "file", nonblock: false, append, path, ino });
7725
7757
  if (append) this.publishFlags(fd, { nonblock: false, append });
7726
- this.bump();
7758
+ this.bump(fd);
7727
7759
  return fd;
7728
7760
  }
7729
7761
  createNew(path, oflags, mode) {
@@ -7759,7 +7791,7 @@ var init_wasi_fds = __esm({
7759
7791
  if (e.type === "kernel") {
7760
7792
  const at = this.kernel.call({ op: "fd-dup", fd });
7761
7793
  this.table.set(at, { ...e });
7762
- this.bump();
7794
+ this.bump(at);
7763
7795
  return at;
7764
7796
  }
7765
7797
  if (e.type === "file") e.file.refs++;
@@ -8754,6 +8786,7 @@ var init_wasi_host = __esm({
8754
8786
  muted;
8755
8787
  signals;
8756
8788
  sigmask;
8789
+ tid = 1;
8757
8790
  linkedTls;
8758
8791
  threadEntry;
8759
8792
  linkedModules;
@@ -9443,14 +9476,13 @@ var init_wasi_host = __esm({
9443
9476
  brokenPipe() {
9444
9477
  let action;
9445
9478
  try {
9446
- action = this.o.kernel.call({ op: "proc-kill-self", sig: SIG.PIPE, probe: true });
9479
+ action = this.o.kernel.call({ op: "proc-kill-self", sig: SIG.PIPE, dry: true });
9447
9480
  } catch {
9448
9481
  action = "terminate";
9449
9482
  }
9450
- if (action !== "terminate") return;
9451
- const mask = this.sigmask;
9452
- if (!mask?.blocks(SIG.PIPE)) throw new WasiExit(SIGPIPE_EXIT);
9453
- this.o.kernel.call({ op: "thread-kill", tid: mask.tid, sig: SIG.PIPE });
9483
+ if (action === "ignore") return;
9484
+ if (action === "terminate" && !this.sigmask?.blocks(SIG.PIPE)) throw new WasiExit(SIGPIPE_EXIT);
9485
+ this.o.kernel.call({ op: "thread-kill", tid: this.tid, sig: SIG.PIPE });
9454
9486
  }
9455
9487
  read(fd, max) {
9456
9488
  const e = this.fds.get(fd);
@@ -12901,6 +12933,7 @@ async function runWasiThread(init, port2) {
12901
12933
  ),
12902
12934
  shared: threads.ids
12903
12935
  });
12936
+ host.tid = thread.tid;
12904
12937
  host.sigmask = sigmaskOf(init.program.module, init.sab, gate, threads, init.signals);
12905
12938
  const program = await programImports(init.program, host, transport, thread.tid);
12906
12939
  const { module } = init.program;