@ai-ecoverse/slicc-kernel 1.29.0 → 1.29.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.
package/dist/node.js CHANGED
@@ -93,6 +93,11 @@ function rangedOps(fs) {
93
93
  if (!pread || !pwrite || !truncate) return void 0;
94
94
  return { pread: pread.bind(fs), pwrite: pwrite.bind(fs), truncate: truncate.bind(fs) };
95
95
  }
96
+ async function lutimesOf(fs, path, atime, mtime) {
97
+ if (fs.lutimes) return fs.lutimes(path, atime, mtime);
98
+ if ((await fs.lstat(path)).isSymbolicLink) throw fsError("EOPNOTSUPP", path);
99
+ return fs.utimes(path, atime, mtime);
100
+ }
96
101
  function fsError(code, path) {
97
102
  return Object.assign(new Error(`${code}: ${path}`), { code });
98
103
  }
@@ -1964,7 +1969,7 @@ var OpfsFs = class {
1964
1969
  size: new TextEncoder().encode(entry.link).length,
1965
1970
  mode: S_IFLNK | 511,
1966
1971
  mtime: time2,
1967
- atime: time2,
1972
+ atime: entry.atimeMs === void 0 ? time2 : new Date(entry.atimeMs),
1968
1973
  ctime: new Date(entry.ctimeMs ?? 0),
1969
1974
  ino: entry.ino ?? inodeOf(entry.path)
1970
1975
  };
@@ -2260,7 +2265,24 @@ var OpfsFs = class {
2260
2265
  }));
2261
2266
  }
2262
2267
  async utimes(path, atime, mtime) {
2263
- const found = await this.locate(path, true);
2268
+ await this.setTimes(await this.locate(path, true), atime, mtime);
2269
+ }
2270
+ async lutimes(path, atime, mtime) {
2271
+ await this.setTimes(await this.locate(path, false), atime, mtime);
2272
+ }
2273
+ async setTimes(found, atime, mtime) {
2274
+ const { link: link2 } = found;
2275
+ if (link2) {
2276
+ const ctimeMs2 = Date.now();
2277
+ await this.meta.update(found.path, (entry) => ({
2278
+ ...link2,
2279
+ ...entry,
2280
+ atimeMs: atime.getTime(),
2281
+ mtimeMs: mtime.getTime(),
2282
+ ctimeMs: ctimeMs2
2283
+ }));
2284
+ return;
2285
+ }
2264
2286
  const handle = found.handle;
2265
2287
  const file = handle.kind === "file" ? await handle.getFile() : void 0;
2266
2288
  const ctimeMs = Date.now();
@@ -3272,6 +3294,7 @@ function withCommandDirs(fs, names) {
3272
3294
  readlink: (path) => fs.readlink(path),
3273
3295
  chmod: (path, mode) => fs.chmod(path, mode),
3274
3296
  utimes: (path, atime, mtime) => fs.utimes(path, atime, mtime),
3297
+ lutimes: (path, atime, mtime) => lutimesOf(fs, path, atime, mtime),
3275
3298
  ...rangedOps(fs) ?? {}
3276
3299
  };
3277
3300
  }
@@ -3347,7 +3370,11 @@ var FsWatchers = class {
3347
3370
  rename: after(fs.rename.bind(fs), (from, to) => [from, to]),
3348
3371
  symlink: after(fs.symlink.bind(fs), (_target, path) => [path]),
3349
3372
  chmod: after(fs.chmod.bind(fs), (path) => [path]),
3350
- utimes: after(fs.utimes.bind(fs), (path) => [path])
3373
+ utimes: after(fs.utimes.bind(fs), (path) => [path]),
3374
+ lutimes: after(
3375
+ (path, atime, mtime) => lutimesOf(fs, path, atime, mtime),
3376
+ (path) => [path]
3377
+ )
3351
3378
  };
3352
3379
  const ranged2 = rangedOps(fs);
3353
3380
  if (ranged2) {
@@ -4275,10 +4302,23 @@ var MountFs = class {
4275
4302
  await found.mount.conn.call({ op: "setattr", path: found.rel, mode });
4276
4303
  }
4277
4304
  async utimes(path, atime, mtime) {
4305
+ const real = await this.follow(path);
4306
+ const found = this.at(real);
4307
+ if (!found) return this.base.utimes(real, atime, mtime);
4308
+ await this.setMtime(found, real, mtime);
4309
+ }
4310
+ async lutimes(path, atime, mtime) {
4278
4311
  const found = this.at(path);
4279
- if (!found) return this.base.utimes(path, atime, mtime);
4280
- this.writable(found.mount, normalizePath(path));
4281
- this.table.forget(found.mount, normalizePath(path));
4312
+ if (!found) return lutimesOf(this.base, path, atime, mtime);
4313
+ const real = normalizePath(path);
4314
+ if (!found.mount.caps.linkTimes && (await this.lstat(real)).isSymbolicLink) {
4315
+ throw errnoError("EOPNOTSUPP", path);
4316
+ }
4317
+ await this.setMtime(found, real, mtime);
4318
+ }
4319
+ async setMtime(found, real, mtime) {
4320
+ this.writable(found.mount, real);
4321
+ this.table.forget(found.mount, real);
4282
4322
  await found.mount.conn.call({ op: "setattr", path: found.rel, mtime: mtime.getTime() });
4283
4323
  }
4284
4324
  };
@@ -4392,6 +4432,9 @@ async function run(entry, path, req) {
4392
4432
  case "utimes":
4393
4433
  await fs.utimes(path, new Date(req.atimeMs ?? 0), new Date(req.mtimeMs ?? 0));
4394
4434
  return done;
4435
+ case "lutimes":
4436
+ await lutimesOf(fs, path, new Date(req.atimeMs ?? 0), new Date(req.mtimeMs ?? 0));
4437
+ return done;
4395
4438
  case "pread":
4396
4439
  case "pwrite":
4397
4440
  case "truncate":
@@ -7450,6 +7493,7 @@ var SYSCALL_OPS = /* @__PURE__ */ new Set([
7450
7493
  "mount",
7451
7494
  "umount",
7452
7495
  "proc-exec",
7496
+ "proc-identity",
7453
7497
  "proc-setpgid",
7454
7498
  "proc-getpgid",
7455
7499
  "proc-getsid",
@@ -7549,6 +7593,7 @@ var WasmProcess = class {
7549
7593
  for (const listener of this.stateListeners) listener("continued", SIG.CONT);
7550
7594
  }
7551
7595
  async syscall(req) {
7596
+ this.options.onSyscall?.();
7552
7597
  for (; ; ) {
7553
7598
  await this.resumed;
7554
7599
  const stops = this.stops;
@@ -7894,6 +7939,8 @@ var WasmProcess = class {
7894
7939
  const waited = await this.children.wait(req.pid, req.nohang, signal, flags);
7895
7940
  return { ok: true, kind: "json", json: waited };
7896
7941
  }
7942
+ case "proc-identity":
7943
+ return { ok: true, kind: "json", json: await this.options.identity?.() ?? null };
7897
7944
  case "proc-exec": {
7898
7945
  this.execChild = req.pid;
7899
7946
  this.options.jobs?.exec(this.pid, req.pid);
@@ -8044,6 +8091,8 @@ function spawnWasmProcess(opts) {
8044
8091
  const header3 = new Int32Array(sab, 0, SAB_HEADER_I32);
8045
8092
  const process = new WasmProcess(opts.pid, opts.fds, {
8046
8093
  ...opts.ignored ? { ignored: opts.ignored } : {},
8094
+ ...opts.identity ? { identity: opts.identity } : {},
8095
+ ...opts.onSyscall ? { onSyscall: opts.onSyscall } : {},
8047
8096
  spawner: opts.spawner,
8048
8097
  forker: opts.forker,
8049
8098
  fs: opts.fs,
@@ -9525,6 +9574,7 @@ var ENV_REFERENCE = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
9525
9574
  var WASM_MAGIC = [0, 97, 115, 109];
9526
9575
  var SHEBANG_MAX = 256;
9527
9576
  var NOT_FOUND = 127;
9577
+ var DECIDE_MS = 100;
9528
9578
  var INIT_PID = 1;
9529
9579
  var SHARED_DIRS = ["/tmp", "/home"];
9530
9580
  var encoder3 = new TextEncoder();
@@ -9623,6 +9673,8 @@ var Launcher = class {
9623
9673
  fstabRetries;
9624
9674
  inserted = /* @__PURE__ */ new Map();
9625
9675
  openFiles = /* @__PURE__ */ new Set();
9676
+ deciding = /* @__PURE__ */ new Map();
9677
+ identities = { asked: 0, timedOut: 0 };
9626
9678
  nodes;
9627
9679
  held = /* @__PURE__ */ new Set();
9628
9680
  processMounts;
@@ -9829,8 +9881,19 @@ var Launcher = class {
9829
9881
  }
9830
9882
  const pid = this.nextPid++;
9831
9883
  const terminal = req.fds.stdioTerminal();
9884
+ const decided = req.decided ?? Promise.resolve(true);
9885
+ const count = (byParent) => {
9886
+ this.identities.asked++;
9887
+ if (!byParent) this.identities.timedOut++;
9888
+ };
9889
+ let asked;
9832
9890
  const handle = spawnWasmProcess({
9833
9891
  pid,
9892
+ identity: async () => {
9893
+ await (asked ??= decided.then(count));
9894
+ return this.identityOf(pid);
9895
+ },
9896
+ onSyscall: () => this.decide(pid),
9834
9897
  ...req.ignored ? { ignored: req.ignored } : {},
9835
9898
  program: req.program,
9836
9899
  argv0: req.argv0,
@@ -9903,7 +9966,8 @@ var Launcher = class {
9903
9966
  };
9904
9967
  const shown = (pid) => {
9905
9968
  const member = pid === void 0 ? void 0 : members.get(pid);
9906
- return member ? rootOf(member).pid : INIT_PID;
9969
+ const root = member && rootOf(member).pid;
9970
+ return root !== void 0 && this.running(root) ? root : INIT_PID;
9907
9971
  };
9908
9972
  const listed = [];
9909
9973
  for (const member of members.values()) {
@@ -9932,7 +9996,9 @@ var Launcher = class {
9932
9996
  throw new SpawnError(await this.unrunnable(req.file, req.cwd));
9933
9997
  }
9934
9998
  const exec = req.exec ? { exec: true } : {};
9999
+ const deciding = req.exec ? void 0 : this.undecided(ppid);
9935
10000
  const handle = await this.launch(planned, {
10001
+ ...deciding ? { decided: deciding.promise } : {},
9936
10002
  env: req.env,
9937
10003
  cwd: req.cwd,
9938
10004
  fds,
@@ -9941,9 +10007,39 @@ var Launcher = class {
9941
10007
  ignored: this.ignoredBy(ppid),
9942
10008
  ...exec
9943
10009
  });
10010
+ deciding?.attach();
9944
10011
  return childHandle(handle);
9945
10012
  };
9946
10013
  }
10014
+ undecided(ppid) {
10015
+ const decided = Promise.withResolvers();
10016
+ return {
10017
+ promise: decided.promise,
10018
+ attach: () => {
10019
+ const timer = setTimeout(() => decided.resolve(false), DECIDE_MS);
10020
+ void decided.promise.then(() => clearTimeout(timer));
10021
+ const waiting = this.deciding.get(ppid) ?? /* @__PURE__ */ new Set();
10022
+ waiting.add(decided.resolve);
10023
+ this.deciding.set(ppid, waiting);
10024
+ }
10025
+ };
10026
+ }
10027
+ identityOf(pid) {
10028
+ const parent = this.jobs.shownParent(pid);
10029
+ const alive = parent !== void 0 && this.running(parent);
10030
+ return { pid: this.jobs.shown(pid), ppid: alive ? parent : INIT_PID };
10031
+ }
10032
+ running(shown) {
10033
+ return this.jobs.list().some((member) => !this.zombies.has(member.pid) && this.jobs.shown(member.pid) === shown);
10034
+ }
10035
+ decide(ppid) {
10036
+ const waiting = this.deciding.get(ppid);
10037
+ if (!waiting) return;
10038
+ this.deciding.delete(ppid);
10039
+ setTimeout(() => {
10040
+ for (const resolve of waiting) resolve(true);
10041
+ }, 0);
10042
+ }
9947
10043
  forker(ppid, parent) {
9948
10044
  const { exec: _exec, ...image } = parent;
9949
10045
  return async (state, fds) => childHandle(
@@ -9985,7 +10081,7 @@ var Launcher = class {
9985
10081
  serveFilesystem(
9986
10082
  port2,
9987
10083
  tmpfs(),
9988
- { symlinks: true, chmod: true, ranges: true, attrTtl: 0 },
10084
+ { symlinks: true, chmod: true, linkTimes: true, ranges: true, attrTtl: 0 },
9989
10085
  { owned: true }
9990
10086
  );
9991
10087
  return {