@ai-ecoverse/slicc-kernel 1.85.1 → 1.86.0

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.
@@ -2591,7 +2591,7 @@ var init_wasi_host = __esm({
2591
2591
  }
2592
2592
  return path;
2593
2593
  };
2594
- const modeOf = (st) => (st.mode ?? 0) & 4095;
2594
+ const modeOf2 = (st) => (st.mode ?? 0) & 4095;
2595
2595
  const chown = (path, uid, gid, follow2) => {
2596
2596
  const { chown: own } = this.o.fs;
2597
2597
  if (!own) throw new WasiError("ENOSYS");
@@ -2670,7 +2670,7 @@ var init_wasi_host = __esm({
2670
2670
  fd_mode: (fd, out) => {
2671
2671
  const e = fds.get(fd);
2672
2672
  const kind = e.type === "kernel" ? fds.kind(fd, e) : void 0;
2673
- const mode = kind === "stream" ? S_IFIFO | 384 : kind === "sealed" || kind === "clipboard" ? SEALED_MODE : modeOf(this.o.fs.stat(pathOf(fd)));
2673
+ const mode = kind === "stream" ? S_IFIFO | 384 : kind === "sealed" || kind === "clipboard" ? SEALED_MODE : modeOf2(this.o.fs.stat(pathOf(fd)));
2674
2674
  mem.view().setUint32(out, mode, true);
2675
2675
  },
2676
2676
  path_mode: (dirfd, p, l, flags, out) => {
@@ -2678,7 +2678,7 @@ var init_wasi_host = __esm({
2678
2678
  if (this.synthetic(path) && deviceOf(path) === void 0)
2679
2679
  return void mem.view().setUint32(out, SEALED_MODE, true);
2680
2680
  const st = flags & AT_SYMLINK_NOFOLLOW ? this.o.fs.lstat(path) : this.o.fs.stat(path);
2681
- mem.view().setUint32(out, modeOf(st), true);
2681
+ mem.view().setUint32(out, modeOf2(st), true);
2682
2682
  }
2683
2683
  });
2684
2684
  }
@@ -3822,6 +3822,12 @@ var init_signals = __esm({
3822
3822
  });
3823
3823
 
3824
3824
  // src/process/js/js-kernel.ts
3825
+ function modeOf(mode) {
3826
+ if (!Number.isInteger(mode) || mode < 0 || mode > 4095) {
3827
+ throw new JsCallError("EINVAL", "chmod");
3828
+ }
3829
+ return mode;
3830
+ }
3825
3831
  function callError(result, op) {
3826
3832
  const { errno: errno2, message: message2 } = result;
3827
3833
  const detailed = typeof message2 === "string" && message2 !== errno2 && DETAILED.has(op);
@@ -5655,10 +5661,15 @@ function syncPathOps(kernel, resolve, statOf, open) {
5655
5661
  if (inDev(abs)) return devSync(kernel, devReaddir(abs));
5656
5662
  return kernel.json({ op: "readdir", path: abs });
5657
5663
  },
5658
- mkdir: (path) => void kernel.call({ op: "mkdir", path: resolve(path) }),
5664
+ mkdir: (path, options) => void kernel.call({
5665
+ op: "mkdir",
5666
+ path: resolve(path),
5667
+ ...options?.recursive === false ? { exclusive: true } : {}
5668
+ }),
5659
5669
  rm: (path) => void kernel.call({ op: "rm", path: resolve(path) }),
5660
5670
  unlink: (path) => void kernel.call({ op: "unlink", path: resolve(path) }),
5661
5671
  rename: (from, to) => void kernel.call({ op: "rename", path: resolve(from), arg2: resolve(to) }),
5672
+ chmod: (path, mode) => void kernel.call({ op: "chmod", path: resolve(path), mode: modeOf(mode) }),
5662
5673
  link: (from, to) => void kernel.call({ op: "link", path: resolve(from), arg2: resolve(to) }),
5663
5674
  symlink: (target, path) => void kernel.call({ op: "symlink", path: resolve(path), arg2: target }),
5664
5675
  readlink(path) {
@@ -6161,7 +6172,9 @@ function createContext(o) {
6161
6172
  kill: killer({ self: o.pid, kernel, syncKernel, lane, writes, modes: terminal.modes }),
6162
6173
  cred: () => syncKernel.json({ op: "proc-cred" }),
6163
6174
  setcred(change) {
6164
- if (typeof change !== "object" || change === null) throw new JsCallError("EINVAL", "setcred");
6175
+ if (typeof change !== "object" || change === null || Array.isArray(change)) {
6176
+ throw new JsCallError("EINVAL", "setcred");
6177
+ }
6165
6178
  return syncKernel.json({ op: "proc-setcred", change: { ...change } });
6166
6179
  }
6167
6180
  };
@@ -6357,10 +6370,15 @@ function pathOps(kernel, resolve, statOf, open) {
6357
6370
  if (inDev(abs)) return devAsync(kernel, devReaddir(abs));
6358
6371
  return await kernel.json({ op: "readdir", path: abs });
6359
6372
  },
6360
- mkdir: async (path) => void await kernel.call({ op: "mkdir", path: resolve(path) }),
6373
+ mkdir: async (path, options) => void await kernel.call({
6374
+ op: "mkdir",
6375
+ path: resolve(path),
6376
+ ...options?.recursive === false ? { exclusive: true } : {}
6377
+ }),
6361
6378
  rm: async (path) => void await kernel.call({ op: "rm", path: resolve(path) }),
6362
6379
  unlink: async (path) => void await kernel.call({ op: "unlink", path: resolve(path) }),
6363
6380
  rename: async (from, to) => void await kernel.call({ op: "rename", path: resolve(from), arg2: resolve(to) }),
6381
+ chmod: async (path, mode) => void await kernel.call({ op: "chmod", path: resolve(path), mode: modeOf(mode) }),
6364
6382
  link: async (from, to) => void await kernel.call({ op: "link", path: resolve(from), arg2: resolve(to) }),
6365
6383
  symlink: async (target, path) => void await kernel.call({ op: "symlink", path: resolve(path), arg2: target }),
6366
6384
  async readlink(path) {
@@ -6617,10 +6635,14 @@ function liveNodePath(node) {
6617
6635
  const root = node.mount.opts.root.replace(/\/+$/, "");
6618
6636
  return parts.length === 0 ? root || "/" : `${root}/${parts.reverse().join("/")}`;
6619
6637
  }
6620
- function modeFromStat(st) {
6638
+ function exactIn(node) {
6639
+ return node?.mount.opts.bridge.owners === true;
6640
+ }
6641
+ function modeFromStat(st, exact = false) {
6621
6642
  const type = st.isSymbolicLink ? S_IFLNK : st.isDirectory ? S_IFDIR : S_IFREG;
6622
6643
  const fallback = st.isDirectory || st.isSymbolicLink ? 511 : 438;
6623
- return type | ((st.mode ?? fallback) & PERM_MASK || fallback);
6644
+ const perm = (st.mode ?? fallback) & PERM_MASK;
6645
+ return type | (exact ? perm : perm || fallback);
6624
6646
  }
6625
6647
  function toMs(v) {
6626
6648
  if (v === void 0 || v === null) return void 0;
@@ -6728,7 +6750,7 @@ function createHelpers(Fs, ops) {
6728
6750
  return { ...stat ? { stat, statAt } : {}, len: 0, loaded: false, dirty: false, openCount: 0 };
6729
6751
  }
6730
6752
  function makeNode(parent, name2, st) {
6731
- const node = Fs.createNode(parent, name2, modeFromStat(st), 0);
6753
+ const node = Fs.createNode(parent, name2, modeFromStat(st, exactIn(parent)), 0);
6732
6754
  node.node_ops = ops.node;
6733
6755
  node.stream_ops = ops.stream;
6734
6756
  node.live = freshState(st);
@@ -6742,7 +6764,7 @@ function createHelpers(Fs, ops) {
6742
6764
  if (!cachedStat(node.live, Fs.isDir(node.mode))) {
6743
6765
  const st = call2(() => bridgeOf(node).lstat(liveNodePath(linked.holder(node))));
6744
6766
  Object.assign(node.live, { stat: st, statAt: syncCallCount() });
6745
- node.mode = modeFromStat(st);
6767
+ node.mode = modeFromStat(st, exactIn(node));
6746
6768
  }
6747
6769
  return node.live.stat;
6748
6770
  }
@@ -7080,9 +7102,21 @@ function createStreamOps(h) {
7080
7102
  }
7081
7103
  return want;
7082
7104
  };
7105
+ const directory = (stream) => {
7106
+ const bridge = bridgeOf(stream.node);
7107
+ if (!bridge.owners || !Fs.isDir(stream.node.mode) || stream.flags & O_PATH) return;
7108
+ try {
7109
+ h.call(
7110
+ () => bridge.access?.(liveNodePath(stream.node), accessOf(wantOf2(stream.flags)), "open")
7111
+ );
7112
+ } catch (err) {
7113
+ if (stream.fd !== void 0) Fs.closeStream?.(stream.fd);
7114
+ throw err;
7115
+ }
7116
+ };
7083
7117
  return {
7084
7118
  open(stream) {
7085
- if (!Fs.isFile(stream.node.mode)) return;
7119
+ if (!Fs.isFile(stream.node.mode)) return directory(stream);
7086
7120
  const s = stream.node.live;
7087
7121
  const created = s.created === true;
7088
7122
  s.created = void 0;
@@ -7214,6 +7248,7 @@ function createLiveVfsPlugin(Fs) {
7214
7248
  const st = h.call(() => mount.opts.bridge.stat(mount.opts.root));
7215
7249
  if (!st.isDirectory) throw new Fs.ErrnoError(wasiErrno("ENOTDIR"));
7216
7250
  const root = h.makeNode(null, "/", st);
7251
+ root.mode = modeFromStat(st, mount.opts.bridge.owners === true);
7217
7252
  mounts.add(mount);
7218
7253
  return root;
7219
7254
  }
@@ -7423,7 +7458,7 @@ function useLiveChown(Fs) {
7423
7458
  Fs.chown(target, uid, gid);
7424
7459
  };
7425
7460
  }
7426
- var S_IFDIR, S_IFREG, S_IFLNK, PERM_MASK, DEFAULT_DIR_PERM, UMASK, SEEK_CUR, SEEK_END, EARLY_WHOLE_FILE, O_ACCMODE, O_TRUNC, stale;
7461
+ var S_IFDIR, S_IFREG, S_IFLNK, PERM_MASK, DEFAULT_DIR_PERM, UMASK, SEEK_CUR, SEEK_END, EARLY_WHOLE_FILE, O_ACCMODE, O_TRUNC, O_PATH, stale;
7427
7462
  var init_live_vfs_fs = __esm({
7428
7463
  "src/realm/live-vfs-fs.ts"() {
7429
7464
  "use strict";
@@ -7443,6 +7478,7 @@ var init_live_vfs_fs = __esm({
7443
7478
  EARLY_WHOLE_FILE = 64 * 1024;
7444
7479
  O_ACCMODE = 3;
7445
7480
  O_TRUNC = 512;
7481
+ O_PATH = 2097152;
7446
7482
  stale = (s) => !!s.orphan && !s.kept;
7447
7483
  }
7448
7484
  });
@@ -8262,7 +8298,7 @@ function pathOpensLinks(Fs) {
8262
8298
  const fs = Fs;
8263
8299
  const { mayOpen, isLink } = fs;
8264
8300
  if (!mayOpen || !isLink) return;
8265
- fs.mayOpen = (node, flags) => flags & O_PATH && isLink.call(fs, node.mode) ? 0 : mayOpen.call(fs, node, flags);
8301
+ fs.mayOpen = (node, flags) => flags & O_PATH2 && isLink.call(fs, node.mode) ? 0 : mayOpen.call(fs, node, flags);
8266
8302
  }
8267
8303
  function importKey(namespace, name2, glue) {
8268
8304
  const own = glue?.[name2];
@@ -8739,7 +8775,24 @@ function kernelAccess(imports, fs, memory, glue) {
8739
8775
  }
8740
8776
  });
8741
8777
  }
8778
+ function kernelChdir(Fs) {
8779
+ const { chdir, lookupPath, ErrnoError } = Fs;
8780
+ if (!chdir || !lookupPath || !ErrnoError) return;
8781
+ Fs.chdir = (path) => {
8782
+ const { node } = lookupPath.call(Fs, path, { follow: true });
8783
+ const directory = Fs.isDir?.(node.mode) === true;
8784
+ const bridge = node.live && directory ? node.mount.opts.bridge : void 0;
8785
+ try {
8786
+ bridge?.access?.(liveNodePath(node), X_ACCESS, "eaccess", false);
8787
+ } catch (err) {
8788
+ throw new ErrnoError(errnoOf(err));
8789
+ }
8790
+ chdir.call(Fs, path);
8791
+ };
8792
+ }
8742
8793
  function linuxDevices(Fs) {
8794
+ Fs.ignorePermissions = true;
8795
+ kernelChdir(Fs);
8743
8796
  const { chmod } = Fs;
8744
8797
  if (!chmod) return;
8745
8798
  for (const [path, mode] of DEVICE_MODES) {
@@ -8749,7 +8802,7 @@ function linuxDevices(Fs) {
8749
8802
  }
8750
8803
  }
8751
8804
  }
8752
- 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, LITERALS, 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, W_ACCESS, DEVICE_MODES;
8805
+ 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_PATH2, LITERALS, 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, W_ACCESS, X_ACCESS, DEVICE_MODES;
8753
8806
  var init_process_fds = __esm({
8754
8807
  "src/process/process-fds.ts"() {
8755
8808
  "use strict";
@@ -8777,7 +8830,7 @@ var init_process_fds = __esm({
8777
8830
  EBADF = 8;
8778
8831
  AT_SYMLINK_NOFOLLOW2 = 256;
8779
8832
  EMSCRIPTEN_EPERM = 63;
8780
- O_PATH = 2097152;
8833
+ O_PATH2 = 2097152;
8781
8834
  LITERALS = {
8782
8835
  openat: "__syscall_openat",
8783
8836
  mkdirat: "__syscall_mkdirat",
@@ -8809,6 +8862,7 @@ var init_process_fds = __esm({
8809
8862
  AT_FDCWD = -100;
8810
8863
  AT_EACCESS2 = 512;
8811
8864
  W_ACCESS = 2;
8865
+ X_ACCESS = 1;
8812
8866
  DEVICE_MODES = [
8813
8867
  ["/", 493],
8814
8868
  ["/dev", 493],