@ai-ecoverse/slicc-kernel 1.61.1 → 1.62.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.
@@ -1703,9 +1703,34 @@ var init_wasi_fds = __esm({
1703
1703
  }
1704
1704
  if (!s && !(oflags & OFLAGS.CREAT)) throw new WasiError("ENOENT");
1705
1705
  refuseWrite(s, oflags, rights);
1706
- if (this.shared) return this.kernelFile(path, s, oflags, rights, fdflags);
1706
+ return this.regular(path, s, oflags, rights, fdflags);
1707
+ }
1708
+ regular(path, s, oflags, rights, fdflags) {
1709
+ if (this.shared || this.kernelHolds(path, s)) {
1710
+ return this.kernelFile(path, s, oflags, rights, fdflags);
1711
+ }
1707
1712
  return this.install({ type: "file", file: this.file(path, s, oflags, rights, fdflags) });
1708
1713
  }
1714
+ kernelHolds(path, st) {
1715
+ for (const [fd, e] of this.table) {
1716
+ if (e.type !== "kernel" || this.kind(fd, e) !== "file") continue;
1717
+ this.named(fd, e);
1718
+ if (e.path === path || st?.ino !== void 0 && e.ino === st.ino) return true;
1719
+ }
1720
+ return false;
1721
+ }
1722
+ learned = /* @__PURE__ */ new WeakSet();
1723
+ named(fd, e) {
1724
+ if (e.path !== void 0 || this.learned.has(e)) return;
1725
+ this.learned.add(e);
1726
+ try {
1727
+ const vfs = this.kernel.call({ op: "fd-vfs-stat", fd });
1728
+ if (vfs.orphan || vfs.path === void 0) return;
1729
+ e.path = vfs.path;
1730
+ e.ino = this.inoOf(vfs.path);
1731
+ } catch {
1732
+ }
1733
+ }
1709
1734
  file(path, existing, oflags, rights, fdflags) {
1710
1735
  const { readable: readable2, writable: writable2 } = openAccess(existing, oflags, rights);
1711
1736
  let buffer = this.buffers.get(path);
@@ -3126,6 +3151,12 @@ function importsContext({
3126
3151
  if (path === void 0) throw new WasiError("EBADF");
3127
3152
  return path;
3128
3153
  };
3154
+ const owners = fs.owners === true;
3155
+ const live = () => {
3156
+ if (!owners) return { uid: UID, gid: UID };
3157
+ const cred = call2({ op: "proc-cred" });
3158
+ return { uid: cred.euid, gid: cred.egid };
3159
+ };
3129
3160
  const fds = {
3130
3161
  open(path, o = {}) {
3131
3162
  const abs = host.fds.resolve(3, path);
@@ -3146,7 +3177,7 @@ function importsContext({
3146
3177
  const path = pathOf(fd);
3147
3178
  if (path === void 0) {
3148
3179
  const kind = e.type === "device" ? "device" : "stream";
3149
- return { kind, mode: kind === "device" ? 8630 : 4480, uid: UID, gid: UID, size: 0 };
3180
+ return { kind, mode: kind === "device" ? 8630 : 4480, ...live(), size: 0 };
3150
3181
  }
3151
3182
  host.fds.flushPath(path);
3152
3183
  const s = fs.stat(path);
@@ -3154,8 +3185,7 @@ function importsContext({
3154
3185
  kind: s.isDirectory ? "dir" : "file",
3155
3186
  path,
3156
3187
  mode: s.mode ?? (s.isDirectory ? 16877 : 33188),
3157
- uid: UID,
3158
- gid: UID,
3188
+ ...s.uid !== void 0 && s.gid !== void 0 ? { uid: s.uid, gid: s.gid } : live(),
3159
3189
  size: s.size,
3160
3190
  ...s.ino !== void 0 ? { ino: s.ino } : {},
3161
3191
  ...s.mtimeMs !== void 0 ? { mtimeMs: s.mtimeMs } : {}
@@ -3178,7 +3208,7 @@ function importsContext({
3178
3208
  call2({ op: "unlock", path: requirePath(fd) });
3179
3209
  }
3180
3210
  };
3181
- return {
3211
+ const ctx = {
3182
3212
  memory,
3183
3213
  instance,
3184
3214
  tid,
@@ -3217,6 +3247,11 @@ function importsContext({
3217
3247
  },
3218
3248
  errno: (err) => wasiErrnoOf(code(err))
3219
3249
  };
3250
+ if (!owners) return ctx;
3251
+ return Object.defineProperties(ctx, {
3252
+ uid: { get: () => live().uid, enumerable: true },
3253
+ gid: { get: () => live().gid, enumerable: true }
3254
+ });
3220
3255
  }
3221
3256
  function processes(host, call2, inThread) {
3222
3257
  const close = (fd) => void call2({ op: "fd-close", fd });