@ai-ecoverse/slicc-kernel 1.64.0 → 1.64.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.
@@ -82,9 +82,21 @@ var init_lockdown = __esm({
82
82
  "SharedWorker",
83
83
  "BroadcastChannel",
84
84
  "postMessage",
85
- "close"
85
+ "close",
86
+ "webkitRequestFileSystem",
87
+ "webkitRequestFileSystemSync",
88
+ "webkitResolveLocalFileSystemURL",
89
+ "webkitResolveLocalFileSystemSyncURL"
90
+ ];
91
+ BLOCKED_NAVIGATOR = [
92
+ "storage",
93
+ "storageBuckets",
94
+ "locks",
95
+ "serviceWorker",
96
+ "usb",
97
+ "hid",
98
+ "serial"
86
99
  ];
87
- BLOCKED_NAVIGATOR = ["storage", "locks", "serviceWorker"];
88
100
  OPEN_SLOTS = ["fetch", "WebSocket"];
89
101
  }
90
102
  });
@@ -6895,12 +6907,27 @@ var init_kernel_streams = __esm({
6895
6907
  const original = fs[name2];
6896
6908
  if (typeof original !== "function") continue;
6897
6909
  fs[name2] = (path, ...rest2) => {
6898
- if (!isPtyPath(path)) return original.call(fs, path, ...rest2);
6910
+ const owned = this.ownedTty(path);
6911
+ if (owned && isPtyPath(path)) return this.owned(path, ptyStat(path));
6912
+ if (!isPtyPath(path)) {
6913
+ const st = original.call(fs, path, ...rest2);
6914
+ return owned && TTY_PATH.test(path) ? this.owned(path, st) : st;
6915
+ }
6899
6916
  this.existingPty(path);
6900
6917
  return ptyStat(path);
6901
6918
  };
6902
6919
  }
6903
6920
  }
6921
+ ownedTty(path) {
6922
+ return this.options.owners === true && this.sys.ttyOwner !== void 0 && path !== "/dev/ptmx";
6923
+ }
6924
+ owned(path, st) {
6925
+ const ask = this.sys.ttyOwner;
6926
+ const owner = this.call(() => ask.call(this.sys, path));
6927
+ if (!owner) return st;
6928
+ const mode = st.mode & ~4095 | (owner.mode ?? 400);
6929
+ return { ...st, uid: owner.uid, gid: owner.gid, mode };
6930
+ }
6904
6931
  existingPty(path) {
6905
6932
  const n = PTY_PATH.exec(path)?.[1];
6906
6933
  const exists = n === void 0 ? this.sys.openPty !== void 0 : this.sys.ptyNumbers?.().includes(Number(n)) ?? false;
@@ -7582,7 +7609,7 @@ function useDevFd(Fs) {
7582
7609
  };
7583
7610
  }
7584
7611
  function mountTable(mounts = []) {
7585
- const root = globalThis.navigator?.storage ? "opfs" : "memory";
7612
+ const root = pinnedRoot ?? rootKind();
7586
7613
  const lines = [`${root} / ${root} rw 0 0`, "devfs /dev devfs rw 0 0", "proc /proc proc rw 0 0"];
7587
7614
  for (const m of mounts) {
7588
7615
  const options = Object.entries(m.options).map(([k, v]) => v === "" ? k : `${k}=${v}`);
@@ -7688,7 +7715,7 @@ function linuxDevices(Fs) {
7688
7715
  }
7689
7716
  }
7690
7717
  }
7691
- var O_CLOEXEC, FD_CLOEXEC, F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_DUPFD_CLOEXEC, tracked, IMPORT_NAMES, EBADF, AT_SYMLINK_NOFOLLOW2, EMSCRIPTEN_EPERM, O_PATH, UTIME_NOW, UTIME_OMIT, PROT_WRITE, MAP_PRIVATE, MAP_TYPE, O_WRONLY4, MAP_ALIGN, DIR_MODE, LINK_MODE, CHAR_DEVICE, O_ACCMODE2, O_CREAT2, field, NAME, AT_FDCWD, AT_EACCESS2, DEVICE_MODES;
7718
+ var O_CLOEXEC, FD_CLOEXEC, F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_DUPFD_CLOEXEC, tracked, IMPORT_NAMES, EBADF, AT_SYMLINK_NOFOLLOW2, EMSCRIPTEN_EPERM, O_PATH, UTIME_NOW, UTIME_OMIT, PROT_WRITE, MAP_PRIVATE, MAP_TYPE, O_WRONLY4, MAP_ALIGN, DIR_MODE, LINK_MODE, CHAR_DEVICE, O_ACCMODE2, O_CREAT2, field, pinnedRoot, rootKind, NAME, AT_FDCWD, AT_EACCESS2, DEVICE_MODES;
7692
7719
  var init_process_fds = __esm({
7693
7720
  "src/process/process-fds.ts"() {
7694
7721
  "use strict";
@@ -7730,6 +7757,7 @@ var init_process_fds = __esm({
7730
7757
  O_ACCMODE2 = 3;
7731
7758
  O_CREAT2 = 64;
7732
7759
  field = (text) => (text || "none").replace(/[\s\\]/g, (c) => `\\${c.charCodeAt(0).toString(8).padStart(3, "0")}`);
7760
+ rootKind = () => globalThis.navigator?.storage ? "opfs" : "memory";
7733
7761
  NAME = /^[a-z_][a-z0-9_-]*$/i;
7734
7762
  AT_FDCWD = -100;
7735
7763
  AT_EACCESS2 = 512;
@@ -8980,6 +9008,9 @@ function kernelSys(transport) {
8980
9008
  ttyNames() {
8981
9009
  return json(call2({ op: "fd-tty-names" }, "fd-tty-names"));
8982
9010
  },
9011
+ ttyOwner(name2) {
9012
+ return json(call2({ op: "fd-tty-owner", name: name2 }, `fd-tty-owner ${name2}`));
9013
+ },
8983
9014
  openTty(name2) {
8984
9015
  const req = name2 === void 0 ? { op: "fd-open-tty" } : { op: "fd-open-tty", name: name2 };
8985
9016
  return json(call2(req, `fd-open-tty ${name2 ?? ""}`));
@@ -9224,7 +9255,8 @@ async function runWasmProcess(init, port3, deps = {}) {
9224
9255
  early = () => signals.quiet(() => vfs.flushDirty());
9225
9256
  const sigpipe = () => running.sliccSigpipe?.() === 1;
9226
9257
  const restartable = () => signals.restartable();
9227
- const streams = new KernelStreams(running.FS, sys, { sigpipe, restartable });
9258
+ const owners = init.owners ? { owners: true } : {};
9259
+ const streams = new KernelStreams(running.FS, sys, { sigpipe, restartable, ...owners });
9228
9260
  trackCloseOnExec(running.FS);
9229
9261
  quietQuit(running.FS);
9230
9262
  useMounts(running.FS, init.env, true);
@@ -12472,6 +12504,7 @@ init_protocol();
12472
12504
  init_process_runtime();
12473
12505
  var loadWasi = () => Promise.resolve().then(() => (init_wasi_runtime(), wasi_runtime_exports));
12474
12506
  var loadJs = () => Promise.resolve().then(() => (init_js_runtime(), js_runtime_exports));
12507
+ var NOT_RUNNABLE2 = 126;
12475
12508
  function started(init, port3, run, wasi, js) {
12476
12509
  if (init.program?.abi === "js") {
12477
12510
  const jsInit = init;
@@ -12481,18 +12514,35 @@ function started(init, port3, run, wasi, js) {
12481
12514
  if (wasmInit.program?.abi === "wasi") return wasi().then((m) => m.runWasiProcess(wasmInit, port3));
12482
12515
  return run(wasmInit, port3);
12483
12516
  }
12484
- function processEntry(port3, run = runWasmProcess, wasi = loadWasi, js = loadJs) {
12485
- const failed5 = (err) => port3.postMessage({
12517
+ function processEntry(port3, run = runWasmProcess, wasi = loadWasi, js = loadJs, seal = () => {
12518
+ }) {
12519
+ const failed5 = (err, code2) => port3.postMessage({
12486
12520
  type: WASM_PROCESS_ERROR,
12487
- message: err instanceof Error ? err.stack ?? err.message : String(err)
12521
+ message: err instanceof Error ? err.stack ?? err.message : String(err),
12522
+ ...code2 === void 0 ? {} : { code: code2 }
12488
12523
  });
12524
+ let refused2;
12525
+ const sealOnce = () => {
12526
+ if (refused2 === void 0) {
12527
+ try {
12528
+ seal();
12529
+ refused2 = null;
12530
+ } catch (error) {
12531
+ refused2 = { error };
12532
+ }
12533
+ }
12534
+ return refused2;
12535
+ };
12489
12536
  return (data) => {
12490
12537
  const type = data?.type;
12538
+ if (type !== WASM_THREAD_INIT && type !== WASM_PROCESS_INIT) return;
12539
+ const refusal2 = sealOnce();
12491
12540
  if (type === WASM_THREAD_INIT) {
12541
+ if (refusal2) return failed5(refusal2.error);
12492
12542
  wasi().then((m) => m.runWasiThread(data, port3)).catch(failed5);
12493
12543
  return;
12494
12544
  }
12495
- if (type !== WASM_PROCESS_INIT) return;
12545
+ if (refusal2) return failed5(refusal2.error, NOT_RUNNABLE2);
12496
12546
  started(data, port3, run, wasi, js).then(
12497
12547
  (code2) => port3.postMessage({ type: WASM_PROCESS_EXIT, code: code2 }),
12498
12548
  failed5