@ai-ecoverse/slicc-kernel 1.66.0 → 1.66.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.
@@ -1339,6 +1339,11 @@ function versionError(theirs) {
1339
1339
  return `slicc-kernel client protocol ${named} is not supported: this side speaks ${PROTOCOL.join(".")}`;
1340
1340
  }
1341
1341
 
1342
+ // src/bytes.ts
1343
+ function fresh(bytes, start2 = 0, end = bytes.length) {
1344
+ return new Uint8Array(bytes.subarray(start2, end));
1345
+ }
1346
+
1342
1347
  // src/fs/walk.ts
1343
1348
  var MAX_LINKS2 = 40;
1344
1349
  function parentOf4(path) {
@@ -3002,7 +3007,7 @@ function serveTransport(peer, transport, { closeWaitMs = CLOSE_WAIT_MS } = {}) {
3002
3007
  }
3003
3008
  if (typeof data === "string") peer.postMessage({ net: "ws-message", nid, data });
3004
3009
  else {
3005
- const bytes = data.slice();
3010
+ const bytes = fresh(data);
3006
3011
  peer.postMessage({ net: "ws-message", nid, data: bytes }, [bytes.buffer]);
3007
3012
  }
3008
3013
  flow.inflight += payloadSize(data);
@@ -3040,7 +3045,7 @@ function serveTransport(peer, transport, { closeWaitMs = CLOSE_WAIT_MS } = {}) {
3040
3045
  open.delete(nid);
3041
3046
  peer.postMessage({ net: "end", nid });
3042
3047
  } else {
3043
- const bytes = next2.value.slice();
3048
+ const bytes = fresh(next2.value);
3044
3049
  peer.postMessage({ net: "chunk", nid, bytes }, [bytes.buffer]);
3045
3050
  }
3046
3051
  } catch (e) {
@@ -3334,7 +3339,7 @@ var UserDb = class {
3334
3339
  joined(name2, extra);
3335
3340
  group.push({ name: name2, gid: uid, members: [] });
3336
3341
  passwd.push(row);
3337
- const fresh = !await this.fs.exists(home);
3342
+ const fresh2 = !await this.fs.exists(home);
3338
3343
  await this.fs.mkdir(home, { recursive: true });
3339
3344
  try {
3340
3345
  await this.provision(row);
@@ -3342,7 +3347,7 @@ var UserDb = class {
3342
3347
  await this.fs.mkdir("/etc", { recursive: true });
3343
3348
  await this.commit(formatPasswd(passwd), formatGroup(group));
3344
3349
  } catch (err) {
3345
- if (fresh) await this.fs.rm(home, { recursive: true, force: true });
3350
+ if (fresh2) await this.fs.rm(home, { recursive: true, force: true });
3346
3351
  throw err;
3347
3352
  }
3348
3353
  remember();
@@ -3460,7 +3465,7 @@ async function fsCall(fs, method, args, owner, g) {
3460
3465
  }
3461
3466
  switch (method) {
3462
3467
  case "readFile": {
3463
- const bytes = (await fs.readFileBuffer(path(0))).slice();
3468
+ const bytes = fresh(await fs.readFileBuffer(path(0)));
3464
3469
  return { result: bytes, transfer: [bytes.buffer] };
3465
3470
  }
3466
3471
  case "writeFile":
@@ -7294,9 +7299,9 @@ var HeldPaths = class extends Map {
7294
7299
  return this.keptHandles.get(handle);
7295
7300
  }
7296
7301
  keep(path, file) {
7297
- const fresh = this.handlesAt(path).filter((id2) => !this.keptHandles.has(id2));
7298
- for (const id2 of fresh) this.keptHandles.set(id2, file);
7299
- this.uses.set(file, Math.max(fresh.length, 1));
7302
+ const fresh2 = this.handlesAt(path).filter((id2) => !this.keptHandles.has(id2));
7303
+ for (const id2 of fresh2) this.keptHandles.set(id2, file);
7304
+ this.uses.set(file, Math.max(fresh2.length, 1));
7300
7305
  this.unlinked.set(path, file);
7301
7306
  }
7302
7307
  unkeep(path, file) {
@@ -7852,7 +7857,7 @@ var MountFs = class {
7852
7857
  const chunk2 = mount.caps.maxIo ?? DEFAULT_IO;
7853
7858
  try {
7854
7859
  for (let offset = 0; offset < bytes.length; offset += chunk2) {
7855
- const part = bytes.slice(offset, offset + chunk2);
7860
+ const part = fresh(bytes, offset, offset + chunk2);
7856
7861
  await mount.conn.call({ op: "write", fh, offset, bytes: part }, [part.buffer]);
7857
7862
  }
7858
7863
  } finally {
@@ -7949,7 +7954,7 @@ var MountFs = class {
7949
7954
  async writeRuns(mount, fh, offset, bytes, transfer) {
7950
7955
  const chunk2 = mount.caps.maxIo ?? DEFAULT_IO;
7951
7956
  for (let at = 0; at < bytes.length; at += chunk2) {
7952
- const part = handed(bytes, transfer, chunk2) ? bytes : bytes.slice(at, at + chunk2);
7957
+ const part = handed(bytes, transfer, chunk2) ? bytes : fresh(bytes, at, at + chunk2);
7953
7958
  await mount.conn.call({ op: "write", fh, offset: offset + at, bytes: part }, [part.buffer]);
7954
7959
  }
7955
7960
  }
@@ -8181,8 +8186,8 @@ var MountFs = class {
8181
8186
  }
8182
8187
  this.writable(mount, real);
8183
8188
  const { uid, gid, mode } = change;
8184
- const fresh = change.kind === "new" && { uid, gid, mode };
8185
- const set2 = fresh ? await this.driverOwner(found, real, fresh, false) : change;
8189
+ const fresh2 = change.kind === "new" && { uid, gid, mode };
8190
+ const set2 = fresh2 ? await this.driverOwner(found, real, fresh2, false) : change;
8186
8191
  this.table.forget(mount, real);
8187
8192
  const attrs = Object.entries({ uid: set2.uid, gid: set2.gid, mode: set2.mode });
8188
8193
  await mount.conn.call({
@@ -8785,9 +8790,9 @@ var Pages = class {
8785
8790
  const page = (start2 + at) / PAGE;
8786
8791
  if (this.pages.has(page)) continue;
8787
8792
  const part = bytes.subarray(at, Math.min(at + PAGE, bytes.length));
8788
- const fresh = this.take(part.length);
8789
- fresh.set(part);
8790
- this.pages.set(page, fresh);
8793
+ const fresh2 = this.take(part.length);
8794
+ fresh2.set(part);
8795
+ this.pages.set(page, fresh2);
8791
8796
  }
8792
8797
  }
8793
8798
  read(at, length2) {
@@ -11565,10 +11570,10 @@ var WasmProcess = class {
11565
11570
  this.fds.installAt(fd, this.openVfsFile(open));
11566
11571
  } else if (req.create) {
11567
11572
  await nodes.onEntry(path, async () => {
11568
- const fresh = this.options.owners && !await present2(this.options.fs, path, true);
11573
+ const fresh2 = this.options.owners && !await present2(this.options.fs, path, true);
11569
11574
  this.fds.installAt(fd, this.openVfsFile(open, await nodes.identify(path)));
11570
11575
  await this.fds.get(fd).file.stat?.();
11571
- if (fresh) await this.options.fs.chown?.(path, { ...this.newOwner(), kind: "new" });
11576
+ if (fresh2) await this.options.fs.chown?.(path, { ...this.newOwner(), kind: "new" });
11572
11577
  });
11573
11578
  } else {
11574
11579
  this.fds.installAt(fd, this.openVfsFile(open, await nodes.identify(path)));
@@ -13012,7 +13017,7 @@ function serveFilesystem(port, handlers, capabilities = {}, options = {}) {
13012
13017
  (result) => {
13013
13018
  if (result instanceof Uint8Array) {
13014
13019
  const whole = result.byteOffset === 0 && result.byteLength === result.buffer.byteLength;
13015
- const bytes = options.owned && whole ? result : result.slice();
13020
+ const bytes = options.owned && whole ? result : fresh(result);
13016
13021
  reply({ id: data.id, result: bytes }, [bytes.buffer]);
13017
13022
  } else reply({ id: data.id, result: result ?? null });
13018
13023
  },
@@ -13500,14 +13505,14 @@ var RESTORE_AGAIN_MS = 3e4;
13500
13505
  function hostfsHandlers(current, againMs = RESTORE_AGAIN_MS) {
13501
13506
  const handles = /* @__PURE__ */ new Map();
13502
13507
  let nextFh = 0;
13503
- const fresh = (remote) => {
13508
+ const fresh2 = (remote) => {
13504
13509
  if (remote.client.token === remote.token && !remote.client.gone) return remote;
13505
13510
  throw fsError2("ESTALE", "the folder was granted again, so this open file is gone");
13506
13511
  };
13507
13512
  const live = (fh) => {
13508
13513
  const remote = handles.get(fh);
13509
13514
  if (!remote) throw fsError2("EBADF", `handle ${fh}`);
13510
- return fresh(remote);
13515
+ return fresh2(remote);
13511
13516
  };
13512
13517
  const call = (op, body = {}) => current().call(op, body);
13513
13518
  const same = (was, mode, seen) => seen?.mode === (mode | 128) && (was.ino !== void 0 && seen.ino !== void 0 ? seen.ino === was.ino : seen.size === was.size && seen.mtime === was.mtime);
@@ -13589,7 +13594,7 @@ function hostfsHandlers(current, againMs = RESTORE_AGAIN_MS) {
13589
13594
  if (!remote) throw fsError2("EBADF", `handle ${fh}`);
13590
13595
  handles.delete(fh);
13591
13596
  try {
13592
- await fresh(remote).client.call("release", { fh: remote.fh }, true);
13597
+ await fresh2(remote).client.call("release", { fh: remote.fh }, true);
13593
13598
  } finally {
13594
13599
  if (remote.restore) await settle3(current(), remote.restore);
13595
13600
  }
@@ -15771,8 +15776,8 @@ var Launcher = class {
15771
15776
  ];
15772
15777
  for (const [path, mode] of layout) {
15773
15778
  const real = await this.realLayoutPath(path);
15774
- const fresh = real !== void 0 && !await this.base.hasOwner?.(real);
15775
- if (fresh) await this.base.chown?.(real, { uid: 0, gid: 0, mode, follow: false });
15779
+ const fresh2 = real !== void 0 && !await this.base.hasOwner?.(real);
15780
+ if (fresh2) await this.base.chown?.(real, { uid: 0, gid: 0, mode, follow: false });
15776
15781
  }
15777
15782
  }
15778
15783
  async realLayoutPath(given) {