@ai-ecoverse/slicc-kernel 1.40.1 → 1.41.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.
@@ -166,7 +166,7 @@ var init_pages = __esm({
166
166
  }
167
167
  const last = runs[runs.length - 1];
168
168
  if (last) last[1] = Math.max(last[1], Math.min(READAHEAD, this.stored - last[0]));
169
- return runs.map(([start, n]) => [start, Math.min(n, this.stored - start)]);
169
+ return runs.map(([start2, n]) => [start2, Math.min(n, this.stored - start2)]);
170
170
  }
171
171
  partial(at, length) {
172
172
  if (length === 0) return [];
@@ -174,16 +174,16 @@ var init_pages = __esm({
174
174
  const edges = /* @__PURE__ */ new Set([Math.floor(at / PAGE), Math.floor((at + length - 1) / PAGE)]);
175
175
  const runs = [];
176
176
  for (const page of edges) {
177
- const start = page * PAGE;
178
- const covered = at <= start && at + length >= start + PAGE;
179
- if (covered || this.pages.has(page) || start >= this.stored) continue;
180
- runs.push([start, Math.min(PAGE, this.stored - start)]);
177
+ const start2 = page * PAGE;
178
+ const covered = at <= start2 && at + length >= start2 + PAGE;
179
+ if (covered || this.pages.has(page) || start2 >= this.stored) continue;
180
+ runs.push([start2, Math.min(PAGE, this.stored - start2)]);
181
181
  }
182
182
  return runs;
183
183
  }
184
- fill(start, bytes) {
184
+ fill(start2, bytes) {
185
185
  for (let at = 0; at < bytes.length; at += PAGE) {
186
- const page = (start + at) / PAGE;
186
+ const page = (start2 + at) / PAGE;
187
187
  if (this.pages.has(page)) continue;
188
188
  const part = bytes.subarray(at, Math.min(at + PAGE, bytes.length));
189
189
  const fresh = this.take(part.length);
@@ -249,14 +249,14 @@ var init_pages = __esm({
249
249
  while (j < sorted.length && sorted[j] === first + (j - i) && sorted[j] * PAGE % RUN !== 0) {
250
250
  j++;
251
251
  }
252
- const start = first * PAGE;
252
+ const start2 = first * PAGE;
253
253
  const end = Math.min(this.length, (first + (j - i)) * PAGE);
254
- const bytes = new Uint8Array(end - start);
254
+ const bytes = new Uint8Array(end - start2);
255
255
  for (let k = i; k < j; k++) {
256
256
  const page = this.pages.get(sorted[k]);
257
- bytes.set(page.subarray(0, Math.min(PAGE, end - (k - i) * PAGE - start)), (k - i) * PAGE);
257
+ bytes.set(page.subarray(0, Math.min(PAGE, end - (k - i) * PAGE - start2)), (k - i) * PAGE);
258
258
  }
259
- runs.push({ offset: start, bytes });
259
+ runs.push({ offset: start2, bytes });
260
260
  i = j;
261
261
  }
262
262
  const written2 = Math.max(this.stored, ...runs.map((r) => r.offset + r.bytes.length));
@@ -339,8 +339,8 @@ var init_ranged = __esm({
339
339
  return this.pages.length;
340
340
  }
341
341
  fetch(runs) {
342
- for (const [start, n] of runs) {
343
- this.pages.fill(start, this.io.pread(this.path, start, n, this.version));
342
+ for (const [start2, n] of runs) {
343
+ this.pages.fill(start2, this.io.pread(this.path, start2, n, this.version));
344
344
  }
345
345
  }
346
346
  read(at, length) {
@@ -1794,9 +1794,9 @@ var init_kernel_streams = __esm({
1794
1794
  for (const name of ["stat", "lstat"]) {
1795
1795
  const original = fs[name];
1796
1796
  if (typeof original !== "function") continue;
1797
- fs[name] = (path, ...rest) => {
1797
+ fs[name] = (path, ...rest2) => {
1798
1798
  const getattr = this.descriptions.get(path);
1799
- return getattr ? getattr() : original.call(fs, path, ...rest);
1799
+ return getattr ? getattr() : original.call(fs, path, ...rest2);
1800
1800
  };
1801
1801
  }
1802
1802
  }
@@ -1884,13 +1884,13 @@ var init_kernel_streams = __esm({
1884
1884
  for (const name of ["chown", "lchown", "chmod", "lchmod"]) {
1885
1885
  const original = fs[name];
1886
1886
  if (typeof original !== "function") continue;
1887
- fs[name] = (path, ...rest) => isPtyPath(path) ? this.existingPty(path) : original.call(fs, path, ...rest);
1887
+ fs[name] = (path, ...rest2) => isPtyPath(path) ? this.existingPty(path) : original.call(fs, path, ...rest2);
1888
1888
  }
1889
1889
  for (const name of ["stat", "lstat"]) {
1890
1890
  const original = fs[name];
1891
1891
  if (typeof original !== "function") continue;
1892
- fs[name] = (path, ...rest) => {
1893
- if (!isPtyPath(path)) return original.call(fs, path, ...rest);
1892
+ fs[name] = (path, ...rest2) => {
1893
+ if (!isPtyPath(path)) return original.call(fs, path, ...rest2);
1894
1894
  this.existingPty(path);
1895
1895
  return ptyStat(path);
1896
1896
  };
@@ -2165,7 +2165,7 @@ function cloexecPipe2(pipe2, deps) {
2165
2165
  };
2166
2166
  }
2167
2167
  function quietTarget(dup3, deps) {
2168
- return (fd = -1, newfd = -1, flags = 0, ...rest) => {
2168
+ return (fd = -1, newfd = -1, flags = 0, ...rest2) => {
2169
2169
  const Fs = deps.fs();
2170
2170
  const target = fd === newfd || flags !== 0 ? void 0 : Fs?.getStream(newfd);
2171
2171
  if (target && Fs?.getStream(fd)) {
@@ -2174,7 +2174,7 @@ function quietTarget(dup3, deps) {
2174
2174
  } catch {
2175
2175
  }
2176
2176
  }
2177
- return dup3(fd, newfd, flags, ...rest);
2177
+ return dup3(fd, newfd, flags, ...rest2);
2178
2178
  };
2179
2179
  }
2180
2180
  function cloexecByFlag(syscall, flagArg, deps) {
@@ -2329,8 +2329,8 @@ function syncFsync(imports, fs, glue) {
2329
2329
  };
2330
2330
  }
2331
2331
  }
2332
- function offsetOf(rest) {
2333
- const at = rest.length >= 3 ? Number(rest[1]) * 2 ** 32 + (Number(rest[0]) >>> 0) : Number(BigInt.asIntN(64, BigInt(rest[0])));
2332
+ function offsetOf(rest2) {
2333
+ const at = rest2.length >= 3 ? Number(rest2[1]) * 2 ** 32 + (Number(rest2[0]) >>> 0) : Number(BigInt.asIntN(64, BigInt(rest2[0])));
2334
2334
  return at >= 0 && Number.isSafeInteger(at) ? at : void 0;
2335
2335
  }
2336
2336
  function readInto(sys, kfd, target, at) {
@@ -2344,14 +2344,14 @@ function readInto(sys, kfd, target, at) {
2344
2344
  return done;
2345
2345
  }
2346
2346
  function positioned(original, write, deps) {
2347
- return (fd, iov, iovcnt, ...rest) => {
2347
+ return (fd, iov, iovcnt, ...rest2) => {
2348
2348
  const stream = deps.fs()?.getStream(Number(fd));
2349
2349
  const memory = deps.memory();
2350
2350
  const kfd = stream?.sliccKernelFile ? stream.sliccKernelFd : void 0;
2351
2351
  if (kfd === void 0 || !memory || !(write ? deps.sys.pwrite : deps.sys.pread)) {
2352
- return original(fd, iov, iovcnt, ...rest);
2352
+ return original(fd, iov, iovcnt, ...rest2);
2353
2353
  }
2354
- const at = offsetOf(rest);
2354
+ const at = offsetOf(rest2);
2355
2355
  if (at === void 0) return wasiErrno("EINVAL");
2356
2356
  const view = new DataView(memory.buffer);
2357
2357
  let done = 0;
@@ -2367,7 +2367,7 @@ function positioned(original, write, deps) {
2367
2367
  } catch (err) {
2368
2368
  return errnoOf(err);
2369
2369
  }
2370
- view.setUint32(Number(rest[rest.length - 1]), done, true);
2370
+ view.setUint32(Number(rest2[rest2.length - 1]), done, true);
2371
2371
  return 0;
2372
2372
  };
2373
2373
  }
@@ -5343,11 +5343,11 @@ function kernelFiletype(kind) {
5343
5343
  return { filetype: FILETYPE.UNKNOWN, seeks: false };
5344
5344
  }
5345
5345
  }
5346
- function direntRecord(next, ino, name, filetype) {
5346
+ function direntRecord(next2, ino, name, filetype) {
5347
5347
  const nameBytes = new TextEncoder().encode(name);
5348
5348
  const record = new Uint8Array(SIZE.DIRENT + nameBytes.length);
5349
5349
  const v = new DataView(record.buffer);
5350
- v.setBigUint64(0, BigInt(next), true);
5350
+ v.setBigUint64(0, BigInt(next2), true);
5351
5351
  v.setBigUint64(8, ino, true);
5352
5352
  v.setUint32(16, nameBytes.length, true);
5353
5353
  v.setUint8(20, filetype);
@@ -5861,19 +5861,19 @@ var init_wasi_host = __esm({
5861
5861
  return { filetype: FILETYPE.CHARACTER_DEVICE, size: 0n, ino: pathInode(path), mtimeNs: 0n };
5862
5862
  }
5863
5863
  this.fds.flushPath(path);
5864
- const follow = (lookup & LOOKUP_SYMLINK_FOLLOW) !== 0;
5865
- return filestatOf(path, follow ? this.o.fs.stat(path) : this.o.fs.lstat(path));
5864
+ const follow2 = (lookup & LOOKUP_SYMLINK_FOLLOW) !== 0;
5865
+ return filestatOf(path, follow2 ? this.o.fs.stat(path) : this.o.fs.lstat(path));
5866
5866
  }
5867
- setTimes(path, atim, mtim, flags, follow = true) {
5867
+ setTimes(path, atim, mtim, flags, follow2 = true) {
5868
5868
  const now = Date.now();
5869
5869
  let current;
5870
- const statOf = follow ? this.o.fs.stat.bind(this.o.fs) : this.o.fs.lstat.bind(this.o.fs);
5870
+ const statOf = follow2 ? this.o.fs.stat.bind(this.o.fs) : this.o.fs.lstat.bind(this.o.fs);
5871
5871
  const kept = (field2) => {
5872
5872
  current ??= statOf(path);
5873
5873
  return current[field2] ?? current.mtimeMs ?? now;
5874
5874
  };
5875
5875
  const pick = (set, setNow, value2, field2) => flags & setNow ? now : flags & set ? Number(value2 / NS_PER_MS) : kept(field2);
5876
- (follow ? this.o.fs.utimes : this.o.fs.lutimes).call(
5876
+ (follow2 ? this.o.fs.utimes : this.o.fs.lutimes).call(
5877
5877
  this.o.fs,
5878
5878
  path,
5879
5879
  pick(FSTFLAGS.ATIM, FSTFLAGS.ATIM_NOW, atim, "atimeMs"),
@@ -6779,6 +6779,61 @@ var init_wasix_linker = __esm({
6779
6779
  }
6780
6780
  });
6781
6781
 
6782
+ // src/fs/physical-path.ts
6783
+ function start(path) {
6784
+ return { done: [], todo: path.split("/").filter((p) => p !== ""), hops: 0 };
6785
+ }
6786
+ function next(walk) {
6787
+ while (walk.todo.length > 0) {
6788
+ const part = walk.todo.shift();
6789
+ if (part === ".") continue;
6790
+ if (part === "..") {
6791
+ walk.done.pop();
6792
+ continue;
6793
+ }
6794
+ return part;
6795
+ }
6796
+ return void 0;
6797
+ }
6798
+ function lexical(path) {
6799
+ const walk = start(path);
6800
+ for (let part = next(walk); part !== void 0; part = next(walk)) walk.done.push(part);
6801
+ return `/${walk.done.join("/")}`;
6802
+ }
6803
+ function rest(walk, part) {
6804
+ return lexical(`/${[...walk.done, part, ...walk.todo].join("/")}`);
6805
+ }
6806
+ function follow(walk, target) {
6807
+ if (++walk.hops > MAX_HOPS) return false;
6808
+ if (target.startsWith("/")) walk.done.length = 0;
6809
+ walk.todo = [...target.split("/").filter((p) => p !== ""), ...walk.todo];
6810
+ return true;
6811
+ }
6812
+ function physicalPath(fs, path) {
6813
+ const walk = start(path);
6814
+ for (let part = next(walk); part !== void 0; part = next(walk)) {
6815
+ const at = `/${[...walk.done, part].join("/")}`;
6816
+ let target;
6817
+ try {
6818
+ target = fs.lstat(at).isSymbolicLink ? fs.readlink(at) : void 0;
6819
+ } catch {
6820
+ return rest(walk, part);
6821
+ }
6822
+ if (target === void 0) walk.done.push(part);
6823
+ else if (!follow(walk, target)) {
6824
+ throw Object.assign(new Error("too many levels of symbolic links"), { code: "ELOOP" });
6825
+ }
6826
+ }
6827
+ return `/${walk.done.join("/")}`;
6828
+ }
6829
+ var MAX_HOPS;
6830
+ var init_physical_path = __esm({
6831
+ "src/fs/physical-path.ts"() {
6832
+ "use strict";
6833
+ MAX_HOPS = 40;
6834
+ }
6835
+ });
6836
+
6782
6837
  // src/process/wasi/wasix-process.ts
6783
6838
  function resolveFrom(cwd, path) {
6784
6839
  return normalize(path.startsWith("/") ? path : `${cwd}/${path}`);
@@ -6787,6 +6842,7 @@ var POSIX_TO_WASI_SIGNAL, O_WRONLY5, O_RDWR5, O_APPEND2, OFLAG_CREAT, OFLAG_TRUN
6787
6842
  var init_wasix_process = __esm({
6788
6843
  "src/process/wasi/wasix-process.ts"() {
6789
6844
  "use strict";
6845
+ init_physical_path();
6790
6846
  init_wasi_abi();
6791
6847
  init_wasi_files();
6792
6848
  init_wasi_host();
@@ -6873,10 +6929,13 @@ var init_wasix_process = __esm({
6873
6929
  const kfd = this.openFor(op, cwd);
6874
6930
  opened.push(kfd);
6875
6931
  point(op.fd, kfd);
6876
- } else if (op.cmd === "chdir") return resolveFrom(cwd, op.path);
6877
- else return fds.dir(op.fd).path;
6932
+ } else if (op.cmd === "chdir") return this.physicalFrom(cwd, op.path);
6933
+ else return physicalPath(this.host.o.fs, fds.dir(op.fd).path);
6878
6934
  return cwd;
6879
6935
  }
6936
+ physicalFrom(cwd, path) {
6937
+ return physicalPath(this.host.o.fs, path.startsWith("/") ? path : `${cwd}/${path}`);
6938
+ }
6880
6939
  openFor(op, cwd) {
6881
6940
  const path = resolveFrom(cwd, op.path);
6882
6941
  const create = (op.oflags & OFLAG_CREAT) !== 0;
@@ -7100,6 +7159,18 @@ function wasixSocketImports(host, preview1) {
7100
7159
  fds.adopt(fd, "socket", false);
7101
7160
  mem.view().setUint32(out, fd, true);
7102
7161
  },
7162
+ sock_pair: (af, type, _proto, out1, out2) => {
7163
+ if (af !== UNIX)
7164
+ throw new WasiError(af === INET4 || af === INET6 ? "EOPNOTSUPP" : "EAFNOSUPPORT");
7165
+ if (type !== STREAM) throw new WasiError("EPROTONOSUPPORT");
7166
+ mem.view().setUint32(out1, 0, true);
7167
+ mem.view().setUint32(out2, 0, true);
7168
+ const [a, b] = call2({ op: "sock-pair", domain: "unix" });
7169
+ fds.adopt(a, "socket", false);
7170
+ fds.adopt(b, "socket", false);
7171
+ mem.view().setUint32(out1, a, true);
7172
+ mem.view().setUint32(out2, b, true);
7173
+ },
7103
7174
  sock_bind: (fd, addr) => {
7104
7175
  socket(fd);
7105
7176
  call2({ op: "sock-bind", fd, addr: readAddr(mem.view(), addr) });
@@ -7898,8 +7969,8 @@ function linkerHost(host, imports) {
7898
7969
  }
7899
7970
  },
7900
7971
  hostImports: () => {
7901
- const { env: _env, "GOT.mem": _mem, "GOT.func": _func, ...rest } = imports();
7902
- return rest;
7972
+ const { env: _env, "GOT.mem": _mem, "GOT.func": _func, ...rest2 } = imports();
7973
+ return rest2;
7903
7974
  }
7904
7975
  };
7905
7976
  }
@@ -8041,9 +8112,9 @@ async function runWasiThread(init, port) {
8041
8112
  foreign: init.program.foreign,
8042
8113
  ...program ? { program } : {}
8043
8114
  });
8044
- const start = instance.exports.wasi_thread_start;
8115
+ const start2 = instance.exports.wasi_thread_start;
8045
8116
  try {
8046
- start(thread.tid, thread.arg);
8117
+ start2(thread.tid, thread.arg);
8047
8118
  threads.exited();
8048
8119
  } catch (e) {
8049
8120
  if (e instanceof ThreadExit) {