@ai-ecoverse/slicc-kernel 1.58.0 → 1.58.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.
@@ -3850,7 +3850,7 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
3850
3850
  const pidContent = (target, name2, own = false) => () => {
3851
3851
  const listing = procList();
3852
3852
  const info = find(listing.processes, target, own);
3853
- if (!info) throw error(ESRCH);
3853
+ if (!info) throw error();
3854
3854
  return pidFile(name2, info, listing.boot);
3855
3855
  };
3856
3856
  const pidNames = (names) => [.../* @__PURE__ */ new Set([...names, ...PID_FILES])];
@@ -3863,14 +3863,29 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
3863
3863
  dir.node_ops.readdir = () => [".", "..", ...PID_FILES];
3864
3864
  return dir;
3865
3865
  };
3866
+ const scans = /* @__PURE__ */ new Map();
3867
+ const listed = (target) => {
3868
+ let found = false;
3869
+ for (const [stream, pids] of scans) {
3870
+ if (Fs.streams && Fs.streams[stream.fd ?? -1] !== stream) scans.delete(stream);
3871
+ else found ||= pids.has(target);
3872
+ }
3873
+ return found;
3874
+ };
3866
3875
  const procOps = proc.node_ops;
3867
3876
  const lookup = procOps.lookup?.bind(procOps);
3868
3877
  const readdir = procOps.readdir?.bind(procOps);
3878
+ const listAll = (node) => {
3879
+ const names = new Set(readdir ? readdir(node) : [".", ".."]);
3880
+ for (const name2 of [...SYSTEM_FILES, "mounts"]) names.add(name2);
3881
+ for (const p of procList().processes) names.add(String(p.pid));
3882
+ return [...names];
3883
+ };
3869
3884
  proc.node_ops = {
3870
3885
  ...procOps,
3871
3886
  lookup: (parent, name2) => {
3872
3887
  if (/^[1-9]\d*$/.test(name2)) {
3873
- if (!infoOf(Number(name2))) throw error();
3888
+ if (!infoOf(Number(name2)) && !listed(Number(name2))) throw error();
3874
3889
  return pidDir(name2, Number(name2));
3875
3890
  }
3876
3891
  if (name2 === "mounts") return file(parent, name2, () => mountTable(sys.mountList?.() ?? []));
@@ -3884,11 +3899,36 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
3884
3899
  if (!lookup) throw error();
3885
3900
  return lookup(parent, name2);
3886
3901
  },
3887
- readdir: (node) => {
3888
- const names = new Set(readdir ? readdir(node) : [".", ".."]);
3889
- for (const name2 of [...SYSTEM_FILES, "mounts"]) names.add(name2);
3890
- for (const p of procList().processes) names.add(String(p.pid));
3891
- return [...names];
3902
+ readdir: (node) => listAll(node)
3903
+ };
3904
+ const track = (stream, names) => {
3905
+ let current = names;
3906
+ const remember = (list) => scans.set(stream, new Set(list.filter((n) => /^[1-9]\d*$/.test(n)).map(Number)));
3907
+ remember(current ?? []);
3908
+ Object.defineProperty(stream, "getdents", {
3909
+ configurable: true,
3910
+ enumerable: true,
3911
+ get: () => current,
3912
+ set: (next2) => {
3913
+ current = next2;
3914
+ if (next2) remember(next2);
3915
+ }
3916
+ });
3917
+ };
3918
+ const dirOps = proc.stream_ops ?? {};
3919
+ proc.stream_ops = {
3920
+ ...dirOps,
3921
+ open: (stream) => {
3922
+ dirOps.open?.(stream);
3923
+ track(stream, listAll(proc));
3924
+ },
3925
+ dup: (stream) => {
3926
+ dirOps.dup?.(stream);
3927
+ track(stream, stream.getdents);
3928
+ },
3929
+ close: (stream) => {
3930
+ scans.delete(stream);
3931
+ dirOps.close?.(stream);
3892
3932
  }
3893
3933
  };
3894
3934
  hashRemoveNode.call(Fs, self);
@@ -3912,7 +3952,7 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
3912
3952
  readdir: (node) => pidNames(selfReaddir ? selfReaddir(node) : [".", ".."])
3913
3953
  };
3914
3954
  }
3915
- var HZ, DIR_MODE2, FILE_MODE, LINK_MODE2, ENOENT, ESRCH, EINVAL, UID, KIB, FALLBACK_MEMORY, PID_FILES, SYSTEM_FILES, sigMask;
3955
+ var HZ, DIR_MODE2, FILE_MODE, LINK_MODE2, ENOENT, EINVAL, UID, KIB, FALLBACK_MEMORY, PID_FILES, SYSTEM_FILES, sigMask;
3916
3956
  var init_procfs = __esm({
3917
3957
  "src/process/procfs.ts"() {
3918
3958
  "use strict";
@@ -3923,7 +3963,6 @@ var init_procfs = __esm({
3923
3963
  FILE_MODE = 33060;
3924
3964
  LINK_MODE2 = 41471;
3925
3965
  ENOENT = 44;
3926
- ESRCH = 71;
3927
3966
  EINVAL = 28;
3928
3967
  UID = 1e3;
3929
3968
  KIB = 1024;