@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.
@@ -887,7 +887,7 @@ function pinnedIo(bridge, handle, rewriting) {
887
887
  } : {}
888
888
  };
889
889
  }
890
- var WasiError, FileBuffer, LocalFile, MAX_LINKS, MISS_TTL_MS, CACHE_CAP, FS_GEN, CRED_GEN, RING, RING_SIZE, SLOT, SHARED_IDS_BYTES, StatCache;
890
+ var WasiError, FileBuffer, LocalFile, MAX_LINKS, MISS_TTL_MS, CACHE_CAP, FS_GEN, CRED_GEN, RING, RING_SIZE, SLOT, FD_RING, FD_RING_SIZE, SHARED_IDS_BYTES, StatCache;
891
891
  var init_wasi_files = __esm({
892
892
  "src/process/wasi/wasi-files.ts"() {
893
893
  "use strict";
@@ -1114,7 +1114,9 @@ var init_wasi_files = __esm({
1114
1114
  RING = 8;
1115
1115
  RING_SIZE = 64;
1116
1116
  SLOT = 3;
1117
- SHARED_IDS_BYTES = (RING + RING_SIZE * SLOT) * 4;
1117
+ FD_RING = RING + RING_SIZE * SLOT;
1118
+ FD_RING_SIZE = 64;
1119
+ SHARED_IDS_BYTES = (FD_RING + FD_RING_SIZE * 2) * 4;
1118
1120
  StatCache = class {
1119
1121
  stats = /* @__PURE__ */ new Map();
1120
1122
  lstats = /* @__PURE__ */ new Map();
@@ -1886,6 +1888,9 @@ function within(path, root) {
1886
1888
  function kernelEntry() {
1887
1889
  return { type: "kernel", nonblock: false, append: false };
1888
1890
  }
1891
+ function ringed(shared) {
1892
+ return shared.length >= FD_RING + FD_RING_SIZE * 2;
1893
+ }
1889
1894
  function deviceEntry(meta) {
1890
1895
  return { type: "device", device: meta.device, ...meta.access ? { access: meta.access } : {} };
1891
1896
  }
@@ -2053,16 +2058,44 @@ var init_wasi_fds = __esm({
2053
2058
  this.seen = Atomics.load(ids, GEN);
2054
2059
  }
2055
2060
  sync() {
2056
- const gen = Atomics.load(this.shared, GEN);
2061
+ const shared = this.shared;
2062
+ const gen = Atomics.load(shared, GEN);
2057
2063
  if (gen === this.seen) return;
2058
- this.table.clear();
2059
- this.cloexec.clear();
2064
+ if (!this.replay(shared, gen)) {
2065
+ this.table.clear();
2066
+ this.cloexec.clear();
2067
+ }
2060
2068
  this.seen = gen;
2061
2069
  }
2062
- bump() {
2070
+ replay(shared, upTo) {
2071
+ if (upTo - this.seen > FD_RING_SIZE || !ringed(shared)) return false;
2072
+ const changed2 = [];
2073
+ for (let g = this.seen + 1; g <= upTo; g++) {
2074
+ const at = FD_RING + g % FD_RING_SIZE * 2;
2075
+ if (Atomics.load(shared, at) !== g) return false;
2076
+ const fd = Atomics.load(shared, at + 1);
2077
+ if (fd < 0 || Atomics.load(shared, at) !== g) return false;
2078
+ changed2.push(fd);
2079
+ }
2080
+ for (const fd of changed2) {
2081
+ this.table.delete(fd);
2082
+ this.cloexec.delete(fd);
2083
+ }
2084
+ return true;
2085
+ }
2086
+ bump(...fds) {
2063
2087
  if (!this.shared) return;
2064
- const gen = Atomics.add(this.shared, GEN, 1) + 1;
2065
- if (gen - 1 === this.seen) this.seen = gen;
2088
+ const shared = this.shared;
2089
+ for (const fd of fds.length > 0 ? fds : [-1]) {
2090
+ const gen = Atomics.add(shared, GEN, 1) + 1;
2091
+ if (ringed(shared)) {
2092
+ const at = FD_RING + gen % FD_RING_SIZE * 2;
2093
+ Atomics.store(shared, at, 0);
2094
+ Atomics.store(shared, at + 1, fd);
2095
+ Atomics.store(shared, at, gen);
2096
+ }
2097
+ if (gen - 1 === this.seen) this.seen = gen;
2098
+ }
2066
2099
  }
2067
2100
  stdioEntry(fd) {
2068
2101
  let info;
@@ -2105,7 +2138,7 @@ var init_wasi_fds = __esm({
2105
2138
  e.append = append;
2106
2139
  if (this.shared) {
2107
2140
  this.publishFlags(fd, e);
2108
- this.bump();
2141
+ this.bump(fd);
2109
2142
  }
2110
2143
  } else if (e.type === "file") e.file.append = append;
2111
2144
  }
@@ -2115,7 +2148,7 @@ var init_wasi_fds = __esm({
2115
2148
  else this.cloexec.delete(fd);
2116
2149
  if (this.shared) {
2117
2150
  this.kernel.call({ op: "fd-cloexec", fd, on });
2118
- this.bump();
2151
+ this.bump(fd);
2119
2152
  }
2120
2153
  }
2121
2154
  cwd() {
@@ -2132,7 +2165,7 @@ var init_wasi_fds = __esm({
2132
2165
  adopt(fd, kind, nonblock, dgram = false) {
2133
2166
  this.table.set(fd, { type: "kernel", kind, dgram, nonblock, append: false });
2134
2167
  if (this.shared && nonblock) this.publishFlags(fd, { nonblock, append: false });
2135
- this.bump();
2168
+ this.bump(fd);
2136
2169
  }
2137
2170
  get(fd) {
2138
2171
  const e = this.find(fd);
@@ -2157,7 +2190,7 @@ var init_wasi_fds = __esm({
2157
2190
  ...meta ? { meta } : {}
2158
2191
  });
2159
2192
  this.table.set(fd, e);
2160
- this.bump();
2193
+ this.bump(fd);
2161
2194
  return fd;
2162
2195
  }
2163
2196
  cloexec = /* @__PURE__ */ new Set();
@@ -2173,14 +2206,14 @@ var init_wasi_fds = __esm({
2173
2206
  at = this.install(e.type === "file" ? e : { ...e }, min);
2174
2207
  }
2175
2208
  if (cloexec) this.setCloexec(at, true);
2176
- this.bump();
2209
+ this.bump(at);
2177
2210
  return at;
2178
2211
  }
2179
2212
  pipe() {
2180
2213
  const [r, w] = this.kernel.sys.pipe();
2181
2214
  this.table.set(r, { type: "kernel", kind: "stream", nonblock: false, append: false });
2182
2215
  this.table.set(w, { type: "kernel", kind: "stream", nonblock: false, append: false });
2183
- this.bump();
2216
+ this.bump(r, w);
2184
2217
  return [r, w];
2185
2218
  }
2186
2219
  chdir(path) {
@@ -2280,7 +2313,7 @@ var init_wasi_fds = __esm({
2280
2313
  } finally {
2281
2314
  this.release(e);
2282
2315
  this.dropLocks(e);
2283
- this.bump();
2316
+ this.bump(fd);
2284
2317
  }
2285
2318
  }
2286
2319
  renumber(from, to, keep = false) {
@@ -2299,7 +2332,7 @@ var init_wasi_fds = __esm({
2299
2332
  }
2300
2333
  if (old) this.release(old);
2301
2334
  this.dropLocks(old);
2302
- this.bump();
2335
+ this.bump(from, to);
2303
2336
  }
2304
2337
  release(e) {
2305
2338
  if (e.type !== "file" || --e.file.refs > 0) return;
@@ -2487,7 +2520,6 @@ var init_wasi_fds = __esm({
2487
2520
  kind = "tty";
2488
2521
  } else return void 0;
2489
2522
  this.adopt(fd, kind, nonblock);
2490
- this.bump();
2491
2523
  return fd;
2492
2524
  }
2493
2525
  openCharDevice(openDevice2, oflags, rights) {
@@ -2612,7 +2644,7 @@ var init_wasi_fds = __esm({
2612
2644
  if (truncate) this.fs.touched?.(path, ino);
2613
2645
  this.table.set(fd, { type: "kernel", kind: "file", nonblock: false, append, path, ino });
2614
2646
  if (append) this.publishFlags(fd, { nonblock: false, append });
2615
- this.bump();
2647
+ this.bump(fd);
2616
2648
  return fd;
2617
2649
  }
2618
2650
  createNew(path, oflags, mode) {
@@ -2648,7 +2680,7 @@ var init_wasi_fds = __esm({
2648
2680
  if (e.type === "kernel") {
2649
2681
  const at = this.kernel.call({ op: "fd-dup", fd });
2650
2682
  this.table.set(at, { ...e });
2651
- this.bump();
2683
+ this.bump(at);
2652
2684
  return at;
2653
2685
  }
2654
2686
  if (e.type === "file") e.file.refs++;
@@ -3689,6 +3721,7 @@ var init_wasi_host = __esm({
3689
3721
  muted;
3690
3722
  signals;
3691
3723
  sigmask;
3724
+ tid = 1;
3692
3725
  linkedTls;
3693
3726
  threadEntry;
3694
3727
  linkedModules;
@@ -4378,14 +4411,13 @@ var init_wasi_host = __esm({
4378
4411
  brokenPipe() {
4379
4412
  let action;
4380
4413
  try {
4381
- action = this.o.kernel.call({ op: "proc-kill-self", sig: SIG.PIPE, probe: true });
4414
+ action = this.o.kernel.call({ op: "proc-kill-self", sig: SIG.PIPE, dry: true });
4382
4415
  } catch {
4383
4416
  action = "terminate";
4384
4417
  }
4385
- if (action !== "terminate") return;
4386
- const mask = this.sigmask;
4387
- if (!mask?.blocks(SIG.PIPE)) throw new WasiExit(SIGPIPE_EXIT);
4388
- this.o.kernel.call({ op: "thread-kill", tid: mask.tid, sig: SIG.PIPE });
4418
+ if (action === "ignore") return;
4419
+ if (action === "terminate" && !this.sigmask?.blocks(SIG.PIPE)) throw new WasiExit(SIGPIPE_EXIT);
4420
+ this.o.kernel.call({ op: "thread-kill", tid: this.tid, sig: SIG.PIPE });
4389
4421
  }
4390
4422
  read(fd, max) {
4391
4423
  const e = this.fds.get(fd);
@@ -5172,7 +5204,7 @@ var KERNEL_VERSION, OS_RELEASE;
5172
5204
  var init_version = __esm({
5173
5205
  "src/version.ts"() {
5174
5206
  "use strict";
5175
- KERNEL_VERSION = true ? "1.108.3" : "0.0.0-dev";
5207
+ KERNEL_VERSION = true ? "1.108.4" : "0.0.0-dev";
5176
5208
  OS_RELEASE = "6.0.0-slicc";
5177
5209
  }
5178
5210
  });
@@ -16033,6 +16065,7 @@ async function runWasiThread(init, port3) {
16033
16065
  ),
16034
16066
  shared: threads.ids
16035
16067
  });
16068
+ host.tid = thread.tid;
16036
16069
  host.sigmask = sigmaskOf(init.program.module, init.sab, gate, threads, init.signals);
16037
16070
  const program = await programImports(init.program, host, transport, thread.tid);
16038
16071
  const { module } = init.program;