@ai-ecoverse/slicc-kernel 1.34.0 → 1.34.1

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.
@@ -594,6 +594,26 @@ function toMs(v) {
594
594
  }
595
595
  function createHelpers(Fs, ops) {
596
596
  const bridgeOf = (node) => node.mount.opts.bridge;
597
+ const dirty = /* @__PURE__ */ new Set();
598
+ function markDirty(node) {
599
+ node.live.dirty = true;
600
+ dirty.add(node);
601
+ }
602
+ function flushDirty() {
603
+ for (const node of [...dirty]) {
604
+ const s = node.live;
605
+ if (!s.dirty || s.orphan) {
606
+ dirty.delete(node);
607
+ continue;
608
+ }
609
+ if (!s.ranged && s.len > EARLY_WHOLE_FILE) continue;
610
+ try {
611
+ flushNode(node);
612
+ dirty.delete(node);
613
+ } catch {
614
+ }
615
+ }
616
+ }
597
617
  function call2(fn) {
598
618
  try {
599
619
  return fn();
@@ -688,7 +708,7 @@ function createHelpers(Fs, ops) {
688
708
  const ranged = s.openCount > 0 ? rangedOf(node) : void 0;
689
709
  if (ranged) {
690
710
  ranged.truncate(size);
691
- s.dirty = true;
711
+ markDirty(node);
692
712
  return;
693
713
  }
694
714
  if (s.openCount > 0) {
@@ -697,7 +717,7 @@ function createHelpers(Fs, ops) {
697
717
  const buf = ensureCapacity(node, size);
698
718
  if (size > s.len) buf.fill(0, s.len, size);
699
719
  s.len = size;
700
- s.dirty = true;
720
+ markDirty(node);
701
721
  return;
702
722
  }
703
723
  const path = liveNodePath(node);
@@ -727,6 +747,8 @@ function createHelpers(Fs, ops) {
727
747
  ensureCapacity,
728
748
  rangedOf,
729
749
  flushNode,
750
+ markDirty,
751
+ flushDirty,
730
752
  truncate
731
753
  };
732
754
  }
@@ -971,7 +993,7 @@ function createStreamOps(h) {
971
993
  if (ranged) {
972
994
  const bytes = new Uint8Array(buffer.buffer, buffer.byteOffset + offset, length);
973
995
  h.call(() => ranged.write(position, bytes));
974
- s.dirty = true;
996
+ h.markDirty(node);
975
997
  return length;
976
998
  }
977
999
  ensureLoaded(node);
@@ -979,7 +1001,7 @@ function createStreamOps(h) {
979
1001
  if (position > s.len) buf.fill(0, s.len, position);
980
1002
  buf.set(new Uint8Array(buffer.buffer, buffer.byteOffset + offset, length), position);
981
1003
  s.len = Math.max(s.len, end);
982
- s.dirty = true;
1004
+ h.markDirty(node);
983
1005
  return length;
984
1006
  },
985
1007
  llseek(stream, offset, whence) {
@@ -1009,6 +1031,7 @@ function createLiveVfsPlugin(Fs) {
1009
1031
  mounts,
1010
1032
  node_ops: nodeOps,
1011
1033
  stream_ops: streamOps,
1034
+ flushDirty: () => h.flushDirty(),
1012
1035
  mount(mount) {
1013
1036
  const st = h.call(() => mount.opts.bridge.stat(mount.opts.root));
1014
1037
  if (!st.isDirectory) throw new Fs.ErrnoError(wasiErrno("ENOTDIR"));
@@ -1173,7 +1196,7 @@ function guardRenames(Fs) {
1173
1196
  rename(from, to);
1174
1197
  };
1175
1198
  }
1176
- var S_IFDIR, S_IFREG, S_IFLNK, PERM_MASK, DEFAULT_DIR_PERM, UMASK, SEEK_CUR, SEEK_END;
1199
+ var S_IFDIR, S_IFREG, S_IFLNK, PERM_MASK, DEFAULT_DIR_PERM, UMASK, SEEK_CUR, SEEK_END, EARLY_WHOLE_FILE;
1177
1200
  var init_live_vfs_fs = __esm({
1178
1201
  "src/realm/live-vfs-fs.ts"() {
1179
1202
  "use strict";
@@ -1188,6 +1211,7 @@ var init_live_vfs_fs = __esm({
1188
1211
  UMASK = 18;
1189
1212
  SEEK_CUR = 1;
1190
1213
  SEEK_END = 2;
1214
+ EARLY_WHOLE_FILE = 64 * 1024;
1191
1215
  }
1192
1216
  });
1193
1217
 
@@ -1224,6 +1248,7 @@ function mountVfsIntoEmscripten(Fs, deps) {
1224
1248
  return {
1225
1249
  mounted,
1226
1250
  flush: () => flushLiveVfs(Fs, plugin),
1251
+ flushDirty: () => plugin.flushDirty(),
1227
1252
  invalidate: () => invalidateLiveVfs(Fs, plugin)
1228
1253
  };
1229
1254
  }
@@ -1268,10 +1293,34 @@ function parseSyncFsStat(json) {
1268
1293
  ...typeof s.version === "string" ? { version: s.version } : {}
1269
1294
  };
1270
1295
  }
1271
- var SYNC_FS_REQUEST_TIMEOUT_MS;
1296
+ var SYNC_FS_OPS, SYNC_FS_REQUEST_TIMEOUT_MS;
1272
1297
  var init_sync_fs_wire = __esm({
1273
1298
  "src/realm/sync-fs-wire.ts"() {
1274
1299
  "use strict";
1300
+ SYNC_FS_OPS = [
1301
+ "read",
1302
+ "write",
1303
+ "exists",
1304
+ "stat",
1305
+ "lstat",
1306
+ "readdir",
1307
+ "readdir-stat",
1308
+ "mkdir",
1309
+ "rm",
1310
+ "rename",
1311
+ "unlink",
1312
+ "rmdir",
1313
+ "symlink",
1314
+ "readlink",
1315
+ "chmod",
1316
+ "utimes",
1317
+ "lutimes",
1318
+ "statfs",
1319
+ "hold",
1320
+ "pread",
1321
+ "pwrite",
1322
+ "truncate"
1323
+ ];
1275
1324
  SYNC_FS_REQUEST_TIMEOUT_MS = 25e3;
1276
1325
  }
1277
1326
  });
@@ -2760,7 +2809,6 @@ function createProcessKernel(deps) {
2760
2809
  if (!stream) return { none: true };
2761
2810
  promote?.(stream);
2762
2811
  if (stream.sliccKernelFd !== void 0) return { fd: stream.sliccKernelFd };
2763
- if (stream.path === "/dev/null") return { none: true };
2764
2812
  const device = deviceOfStream(stream);
2765
2813
  if (device) return device;
2766
2814
  return n === 0 ? { input: drain(Fs, stream) } : { capture: true };
@@ -2975,6 +3023,7 @@ var init_process_signals = __esm({
2975
3023
  depth = 0;
2976
3024
  reporting = false;
2977
3025
  unwinding = false;
3026
+ quieted = 0;
2978
3027
  raw;
2979
3028
  header;
2980
3029
  hooks;
@@ -3019,7 +3068,16 @@ var init_process_signals = __esm({
3019
3068
  this.reported = { caught, ignored };
3020
3069
  this.raw.call({ op: "sig-mask", caught, ignored }, Number.POSITIVE_INFINITY, "sig-mask");
3021
3070
  }
3071
+ quiet(fn) {
3072
+ this.quieted++;
3073
+ try {
3074
+ return fn();
3075
+ } finally {
3076
+ this.quieted--;
3077
+ }
3078
+ }
3022
3079
  deliver() {
3080
+ if (this.quieted > 0) return;
3023
3081
  const killed = Atomics.load(this.header, SAB_I_KILLED);
3024
3082
  if (killed !== 0 && !this.unwinding && this.hooks.killed) {
3025
3083
  this.unwinding = true;
@@ -3608,6 +3666,9 @@ function kernelSys(transport) {
3608
3666
  kind(fd) {
3609
3667
  return json(call2({ op: "fd-info", fd }, `fd-info ${fd}`))?.kind;
3610
3668
  },
3669
+ device(fd) {
3670
+ return json(call2({ op: "fd-info", fd }, `fd-info ${fd}`)).meta;
3671
+ },
3611
3672
  size(fd) {
3612
3673
  return json(call2({ op: "fd-vfs-stat", fd }, `fd-vfs-stat ${fd}`)).size;
3613
3674
  },
@@ -3683,6 +3744,8 @@ function wireKernelStdio(Fs, streams, sys) {
3683
3744
  const stream = Fs.getStream(fd);
3684
3745
  if (!stream) continue;
3685
3746
  const kind = sys?.kind?.(fd);
3747
+ const device = kind === "device" ? sys?.device?.(fd) : void 0;
3748
+ if (device && openDevice(Fs, fd, device)) continue;
3686
3749
  if (kind && PLACED.has(kind)) {
3687
3750
  const { flags } = stream;
3688
3751
  Fs.closeStream(fd);
@@ -3741,7 +3804,15 @@ async function runWasmProcess(init, port2, deps = {}) {
3741
3804
  }
3742
3805
  }
3743
3806
  );
3744
- const transport = signals.transport();
3807
+ const gated = signals.transport();
3808
+ let early = () => {
3809
+ };
3810
+ const transport = {
3811
+ call: (req, timeoutMs, label) => {
3812
+ if (!FS_OPS.has(req.op)) early();
3813
+ return gated.call(req, timeoutMs, label);
3814
+ }
3815
+ };
3745
3816
  const sys = kernelSys(transport);
3746
3817
  const encoder3 = new TextEncoder();
3747
3818
  const say = (fd) => (text) => sys.write(fd, encoder3.encode(`${text}
@@ -3827,6 +3898,7 @@ async function runWasmProcess(init, port2, deps = {}) {
3827
3898
  cwd: init.cwd,
3828
3899
  warn: deps.warn ?? say(2)
3829
3900
  });
3901
+ early = () => signals.quiet(() => vfs.flushDirty());
3830
3902
  const sigpipe = () => running.sliccSigpipe?.() === 1;
3831
3903
  const restartable = () => signals.restartable();
3832
3904
  const streams = new KernelStreams(running.FS, sys, { sigpipe, restartable });
@@ -3920,7 +3992,7 @@ function runMain(running, init) {
3920
3992
  return status2;
3921
3993
  }
3922
3994
  }
3923
- var O_RDONLY, O_WRONLY3, O_RDWR3, PLACED, GLUE_TRAILER, evaluateGlue, EVAL_BLOCKED;
3995
+ var FS_OPS, O_RDONLY, O_WRONLY3, O_RDWR3, PLACED, GLUE_TRAILER, evaluateGlue, EVAL_BLOCKED;
3924
3996
  var init_process_runtime = __esm({
3925
3997
  "src/process/process-runtime.ts"() {
3926
3998
  "use strict";
@@ -3928,6 +4000,7 @@ var init_process_runtime = __esm({
3928
4000
  init_signals();
3929
4001
  init_emscripten_vfs_hook();
3930
4002
  init_live_vfs_fs();
4003
+ init_sync_fs_wire();
3931
4004
  init_sync_sab_bridge();
3932
4005
  init_sync_sab_wire();
3933
4006
  init_kernel_streams();
@@ -3940,6 +4013,7 @@ var init_process_runtime = __esm({
3940
4013
  init_procfs();
3941
4014
  init_realm_user();
3942
4015
  init_kernel_streams();
4016
+ FS_OPS = new Set(SYNC_FS_OPS);
3943
4017
  O_RDONLY = 0;
3944
4018
  O_WRONLY3 = 1;
3945
4019
  O_RDWR3 = 2;
@@ -5077,8 +5151,9 @@ function filestatOf(path, s) {
5077
5151
  function kernelFiletype(kind) {
5078
5152
  switch (kind) {
5079
5153
  case "tty":
5080
- case "device":
5081
5154
  return { filetype: FILETYPE.CHARACTER_DEVICE, seeks: false };
5155
+ case "device":
5156
+ return { filetype: FILETYPE.CHARACTER_DEVICE, seeks: true };
5082
5157
  case "socket":
5083
5158
  return { filetype: FILETYPE.SOCKET_STREAM, seeks: false };
5084
5159
  case "file":
@@ -5482,7 +5557,9 @@ var init_wasi_host = __esm({
5482
5557
  seek(fd, offset, whence) {
5483
5558
  const e = this.fds.get(fd);
5484
5559
  if (e.type === "kernel") {
5485
- if (this.fds.kind(fd, e) !== "file") throw new WasiError("ESPIPE");
5560
+ const kind = this.fds.kind(fd, e);
5561
+ if (kind === "device") return 0;
5562
+ if (kind !== "file") throw new WasiError("ESPIPE");
5486
5563
  return this.o.kernel.sys.seek(fd, offset, whence);
5487
5564
  }
5488
5565
  if (e.type === "device") return 0;