@ai-ecoverse/slicc-kernel 1.110.3 → 1.110.4

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/README.md CHANGED
@@ -324,7 +324,7 @@ A WASI command can name an ES module of its package that provides imports of its
324
324
 
325
325
  - `memory()`, `instance()` (after instantiation), `tid` (1 for the main thread), `argv`, `env`, `cwd()`;
326
326
  - `fs`: the synchronous filesystem the WASI calls use (absolute paths);
327
- - `fds`: `open(path, { read, write, append, create, exclusive, truncate, directory, nofollow, mode })` returns a WASI descriptor of the program; `mode` is a new file's mode. With `create` and `exclusive` under users `report` or `enforce`, the file is created with it, less the umask, as `open(2)` does, and the name is only checked by the create itself (a symlink there is `EEXIST`). Otherwise the mode is set exactly once the file is open; `close`, `fstat` (`{ kind, path, mode, uid, gid, size, ino, mtimeMs }`), `fchmod`, and `tryLock(fd, exclusive)` / `unlock(fd)`: advisory locks held by the kernel across processes and threads, keyed by path, released on unlock, on closing the descriptor and at exit (`tryLock` returns 0, or 6 when another process holds the lock);
327
+ - `fds`: `open(path, { read, write, append, create, exclusive, truncate, directory, nofollow, mode })` returns a WASI descriptor of the program; `mode` is a new file's mode. With `create` and `exclusive` under users `report` or `enforce`, the file is created with it, less the umask, as `open(2)` does, and the name is only checked by the create itself (a symlink there is `EEXIST`). Otherwise the mode is set exactly once the file is open; `close`, `fstat` (`{ kind, path, mode, uid, gid, size, ino, mtimeMs }`; an open file's size is the descriptor's own, so writes not yet flushed count, while the other fields come from a stat of its path, as WASI's `fd_filestat_get` gives them), `fchmod`, and `tryLock(fd, exclusive)` / `unlock(fd)`: advisory locks held by the kernel across processes and threads, keyed by path, released on unlock, on closing the descriptor and at exit (`tryLock` returns 0, or 6 when another process holds the lock);
328
328
  - `syscall(req)`: a kernel syscall, synchronously;
329
329
  - `net.connect({ host, port, nonblock })` connects a TCP socket to the kernel's loopback and returns its kernel descriptor. `host` is `localhost` or `127.x.y.z`; anything else, or a port outside 1–65535, is `EINVAL`. A refused connection throws `ECONNREFUSED`. The connection carries the program's own identity, as any connect from its process does, so a [page facade](#page-facades) such as `SLICC_LINK_URL` sees the program's stamp. With `nonblock` it returns at once, and `net.ready(fd)` answers 0 once a connect is complete, `EINPROGRESS` (26) while it isn't, or the connect's WASI errno (`SO_ERROR`). On the loopback a connect completes at once, so `ready` is 0 straight away. `ready` is meant for a descriptor from `net.connect`. The descriptor is read and written with `fd-read` and `fd-write` and closed with `fd-close`, as below, and `fd-select` (`{ op: 'fd-select', read: [fds], write: [fds], timeoutMs }`, answering `{ read, write }` with the ready ones; `timeoutMs: -1` waits without a limit) waits until it's readable or writable;
330
330
  - `spawn({ argv, env, cwd, stdin, stdout, stderr })` starts a command (resolved like `kernel.run`) as a child and returns `{ pid, stdin, stdout, stderr }`. `env` is the child's whole environment (the program's own by default), `cwd` the program's by default. Each stdio is `'inherit'` (the default: the program's own), `'null'`, or `'pipe'`: a kernel pipe whose end the result holds as a descriptor, read and written with `fd-read` (`{ op: 'fd-read', fd, max }`, an empty read at the end), `fd-write` (`{ op: 'fd-write', fd, body }`) and `fd-close`, through `syscall` or `async.submit`; the child's ends are closed in the program. A command that does not exist throws `ENOENT`;
@@ -6176,7 +6176,7 @@ function satisfies(version, range2) {
6176
6176
  }
6177
6177
 
6178
6178
  // src/version.ts
6179
- var KERNEL_VERSION = true ? "1.110.3" : "0.0.0-dev";
6179
+ var KERNEL_VERSION = true ? "1.110.4" : "0.0.0-dev";
6180
6180
  var OS_RELEASE = "6.0.0-slicc";
6181
6181
  function procVersion() {
6182
6182
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -4918,6 +4918,14 @@ function importsContext({
4918
4918
  }
4919
4919
  return void 0;
4920
4920
  };
4921
+ const sizedOf = (fd) => {
4922
+ const e = host.fds.get(fd);
4923
+ if (e.type === "file") return { path: e.file.path, size: e.file.size() };
4924
+ if (e.type === "kernel" && host.fds.kind(fd, e) === "file") {
4925
+ return call2({ op: "fd-vfs-stat", fd });
4926
+ }
4927
+ return { path: pathOf(fd) };
4928
+ };
4921
4929
  const requirePath = (fd) => {
4922
4930
  const path = pathOf(fd);
4923
4931
  if (path === void 0) throw new WasiError("EBADF");
@@ -4948,19 +4956,19 @@ function importsContext({
4948
4956
  },
4949
4957
  fstat(fd) {
4950
4958
  const e = host.fds.get(fd);
4951
- const path = pathOf(fd);
4959
+ const { path, size } = sizedOf(fd);
4952
4960
  if (path === void 0) {
4953
4961
  const kind = e.type === "device" ? "device" : "stream";
4954
4962
  return { kind, mode: kind === "device" ? 8630 : 4480, ...live(), size: 0 };
4955
4963
  }
4956
- host.fds.flushPath(path);
4964
+ if (size === void 0) host.fds.flushPath(path);
4957
4965
  const s = fs.stat(path);
4958
4966
  return {
4959
4967
  kind: s.isDirectory ? "dir" : "file",
4960
4968
  path,
4961
4969
  mode: s.mode ?? (s.isDirectory ? 16877 : 33188),
4962
4970
  ...s.uid !== void 0 && s.gid !== void 0 ? { uid: s.uid, gid: s.gid } : live(),
4963
- size: s.size,
4971
+ size: size ?? s.size,
4964
4972
  ...s.ino !== void 0 ? { ino: s.ino } : {},
4965
4973
  ...s.mtimeMs !== void 0 ? { mtimeMs: s.mtimeMs } : {}
4966
4974
  };
@@ -5204,7 +5212,7 @@ var KERNEL_VERSION, OS_RELEASE;
5204
5212
  var init_version = __esm({
5205
5213
  "src/version.ts"() {
5206
5214
  "use strict";
5207
- KERNEL_VERSION = true ? "1.110.3" : "0.0.0-dev";
5215
+ KERNEL_VERSION = true ? "1.110.4" : "0.0.0-dev";
5208
5216
  OS_RELEASE = "6.0.0-slicc";
5209
5217
  }
5210
5218
  });