@ai-ecoverse/slicc-kernel 1.99.2 → 1.100.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.
@@ -2475,7 +2475,7 @@ var KERNEL_VERSION, OS_RELEASE;
2475
2475
  var init_version = __esm({
2476
2476
  "src/version.ts"() {
2477
2477
  "use strict";
2478
- KERNEL_VERSION = true ? "1.99.2" : "0.0.0-dev";
2478
+ KERNEL_VERSION = true ? "1.100.1" : "0.0.0-dev";
2479
2479
  OS_RELEASE = "6.0.0-slicc";
2480
2480
  }
2481
2481
  });
@@ -4958,11 +4958,11 @@ function pages(bytes) {
4958
4958
  function ticks(ms) {
4959
4959
  return Math.max(0, Math.floor(ms * HZ / 1e3));
4960
4960
  }
4961
- function pidStat(info, boot) {
4961
+ function pidStat(info, boot, state = info.state) {
4962
4962
  const fields = [
4963
4963
  info.pid,
4964
4964
  `(${commOf(info)})`,
4965
- info.state,
4965
+ state,
4966
4966
  info.ppid,
4967
4967
  info.pgid,
4968
4968
  info.sid,
@@ -4999,6 +4999,13 @@ function pidStat(info, boot) {
4999
4999
  return `${fields.join(" ")}
5000
5000
  `;
5001
5001
  }
5002
+ function taskStat(info, tid, boot) {
5003
+ const thread = (info.threads ?? [{ tid: 1, state: info.state }]).find((t) => t.tid === tid);
5004
+ return thread && pidStat({ ...info, pid: tid }, boot, thread.state);
5005
+ }
5006
+ function taskIds(info) {
5007
+ return (info.threads ?? [{ tid: 1 }]).map((t) => t.tid);
5008
+ }
5002
5009
  function pidStatus(info) {
5003
5010
  const state = STATES[info.state];
5004
5011
  const c = info.cred ?? ROOT;
@@ -5312,7 +5319,11 @@ var init_procfs = __esm({
5312
5319
  `, ostype: "Linux\n" }
5313
5320
  };
5314
5321
  sigMask = (mask = 0) => (mask >>> 1).toString(16).padStart(16, "0");
5315
- STATES = { S: "S (sleeping)", T: "T (stopped)", Z: "Z (zombie)" };
5322
+ STATES = {
5323
+ S: "S (sleeping)",
5324
+ T: "T (stopped)",
5325
+ Z: "Z (zombie)"
5326
+ };
5316
5327
  tagLine = (tag) => `Tag: ${tag.replaceAll("\n", "\\n").replaceAll(" ", "\\t").replaceAll("\r", "\\r")}`;
5317
5328
  }
5318
5329
  });
@@ -6665,6 +6676,69 @@ var init_wasi_files = __esm({
6665
6676
  }
6666
6677
  });
6667
6678
 
6679
+ // src/process/wasi/slicc-lock.ts
6680
+ function kindOf2(type) {
6681
+ if (type === F_RDLCK2) return "read";
6682
+ if (type === F_WRLCK2) return "write";
6683
+ if (type === F_UNLCK2) return "unlock";
6684
+ throw new WasiError("EINVAL");
6685
+ }
6686
+ function baseOf3(file, whence) {
6687
+ if (whence === SEEK_SET) return 0;
6688
+ if (whence === SEEK_CUR3) return file.offset();
6689
+ if (whence === SEEK_END3) return file.size();
6690
+ throw new WasiError("EINVAL");
6691
+ }
6692
+ function writeHolder2(view, at, found) {
6693
+ if (!found) {
6694
+ view.setInt16(at, F_UNLCK2, true);
6695
+ return;
6696
+ }
6697
+ view.setInt16(at, found.kind === "read" ? F_RDLCK2 : F_WRLCK2, true);
6698
+ view.setInt16(at + 2, SEEK_SET, true);
6699
+ view.setBigInt64(at + 8, BigInt(found.start), true);
6700
+ view.setBigInt64(at + 16, BigInt(found.len), true);
6701
+ view.setInt32(at + 24, found.pid, true);
6702
+ }
6703
+ function lockImports(host) {
6704
+ return {
6705
+ fcntl_lock: (fd, cmd, at) => {
6706
+ if (cmd !== F_GETLK2 && cmd !== F_SETLK2 && cmd !== F_SETLKW2) throw new WasiError("EINVAL");
6707
+ const file = host.file(fd);
6708
+ const view = host.mem.view();
6709
+ const kind = kindOf2(view.getInt16(at, true));
6710
+ const start2 = baseOf3(file, view.getInt16(at + 2, true)) + Number(view.getBigInt64(at + 8, true));
6711
+ const len = Number(view.getBigInt64(at + 16, true));
6712
+ if (cmd === F_GETLK2) {
6713
+ if (kind === "unlock") throw new WasiError("EINVAL");
6714
+ writeHolder2(view, at, host.calls.get(file.target, kind, start2, len));
6715
+ return;
6716
+ }
6717
+ if (kind === "read" && file.readable === false || kind === "write" && file.writable === false)
6718
+ throw new WasiError("EBADF");
6719
+ if (kind !== "write") host.flush(file);
6720
+ host.calls.set(file.target, kind, start2, len, cmd === F_SETLKW2);
6721
+ if (kind !== "unlock") host.locked();
6722
+ }
6723
+ };
6724
+ }
6725
+ var F_GETLK2, F_SETLK2, F_SETLKW2, F_RDLCK2, F_WRLCK2, F_UNLCK2, SEEK_SET, SEEK_CUR3, SEEK_END3;
6726
+ var init_slicc_lock = __esm({
6727
+ "src/process/wasi/slicc-lock.ts"() {
6728
+ "use strict";
6729
+ init_wasi_files();
6730
+ F_GETLK2 = 12;
6731
+ F_SETLK2 = 13;
6732
+ F_SETLKW2 = 14;
6733
+ F_RDLCK2 = 0;
6734
+ F_WRLCK2 = 1;
6735
+ F_UNLCK2 = 2;
6736
+ SEEK_SET = 0;
6737
+ SEEK_CUR3 = 1;
6738
+ SEEK_END3 = 2;
6739
+ }
6740
+ });
6741
+
6668
6742
  // src/process/wasi/slicc-sem.ts
6669
6743
  function remainingMs(deadline, now) {
6670
6744
  if (deadline <= now) return 0;
@@ -7133,6 +7207,17 @@ var init_wasi_fds = __esm({
7133
7207
  }
7134
7208
  return out;
7135
7209
  }
7210
+ locking = false;
7211
+ holdLocks() {
7212
+ this.locking = true;
7213
+ }
7214
+ dropLocks(e) {
7215
+ if (!this.locking || e?.type !== "file") return;
7216
+ try {
7217
+ this.kernel.call({ op: "lk-close", path: e.file.path });
7218
+ } catch {
7219
+ }
7220
+ }
7136
7221
  close(fd) {
7137
7222
  const e = this.get(fd);
7138
7223
  this.table.delete(fd);
@@ -7141,6 +7226,7 @@ var init_wasi_fds = __esm({
7141
7226
  this.kernel.sys.close(fd);
7142
7227
  } finally {
7143
7228
  this.release(e);
7229
+ this.dropLocks(e);
7144
7230
  this.bump();
7145
7231
  }
7146
7232
  }
@@ -7159,6 +7245,7 @@ var init_wasi_fds = __esm({
7159
7245
  if (this.cloexec.delete(from)) this.cloexec.add(to);
7160
7246
  }
7161
7247
  if (old) this.release(old);
7248
+ this.dropLocks(old);
7162
7249
  this.bump();
7163
7250
  }
7164
7251
  release(e) {
@@ -8229,6 +8316,7 @@ var init_wasi_host = __esm({
8229
8316
  init_physical_path();
8230
8317
  init_cpu_clock();
8231
8318
  init_cred();
8319
+ init_slicc_lock();
8232
8320
  init_slicc_sem();
8233
8321
  init_wasi_abi();
8234
8322
  init_wasi_fds();
@@ -8451,6 +8539,26 @@ var init_wasi_host = __esm({
8451
8539
  void this.o.kernel.call({ op: "proc-setcred", change });
8452
8540
  },
8453
8541
  ...semImports(this),
8542
+ ...lockImports({
8543
+ mem,
8544
+ file: (fd) => this.lockedFile(fd),
8545
+ flush: (file) => {
8546
+ if (file.path !== void 0) this.fds.flushPath(file.path);
8547
+ else if (file.target.fd !== void 0) this.o.kernel.sys.flush(file.target.fd);
8548
+ },
8549
+ locked: () => this.fds.holdLocks(),
8550
+ calls: {
8551
+ set: (target, kind, start2, len, wait2) => void this.o.kernel.call({
8552
+ op: "lk-set",
8553
+ ...target,
8554
+ kind,
8555
+ start: start2,
8556
+ len,
8557
+ ...wait2 ? { wait: wait2 } : {}
8558
+ }),
8559
+ get: (target, kind, start2, len) => this.o.kernel.call({ op: "lk-get", ...target, kind, start: start2, len })
8560
+ }
8561
+ }),
8454
8562
  groups_get: (buf, cap, count) => {
8455
8563
  const { groups } = this.o.kernel.call({ op: "proc-cred" });
8456
8564
  if (cap !== 0 && cap < groups.length) throw new WasiError("EINVAL");
@@ -8843,6 +8951,26 @@ var init_wasi_host = __esm({
8843
8951
  }
8844
8952
  e.path = path;
8845
8953
  }
8954
+ lockedFile(fd) {
8955
+ const e = this.fds.get(fd);
8956
+ if (e.type === "file") {
8957
+ const { file } = e;
8958
+ return {
8959
+ target: { path: file.path },
8960
+ path: file.path,
8961
+ readable: file.readable,
8962
+ writable: file.writable,
8963
+ offset: () => file.offset,
8964
+ size: () => file.size()
8965
+ };
8966
+ }
8967
+ if (e.type !== "kernel" || this.fds.kind(fd, e) !== "file") throw new WasiError("EBADF");
8968
+ return {
8969
+ target: { fd },
8970
+ offset: () => this.o.kernel.sys.seek(fd, 0, WHENCE.CUR),
8971
+ size: () => this.kernelStat(fd).size
8972
+ };
8973
+ }
8846
8974
  kernelStat(fd) {
8847
8975
  return this.o.kernel.call({ op: "fd-vfs-stat", fd });
8848
8976
  }
@@ -9950,8 +10078,10 @@ var init_wasi_procfs = __esm({
9950
10078
  content: () => systemFile(top, this.listing(), Date.now(), this.memory)
9951
10079
  };
9952
10080
  }
9953
- if (!/^[1-9]\d*$/.test(top) || rest2.length > 0 || !this.alive(Number(top))) return void 0;
9954
- if (leaf === void 0) return { kind: "dir", names: () => [...PID_NAMES] };
10081
+ if (!/^[1-9]\d*$/.test(top) || !this.alive(Number(top))) return void 0;
10082
+ if (leaf === "task") return this.task(Number(top), rest2);
10083
+ if (rest2.length > 0) return void 0;
10084
+ if (leaf === void 0) return { kind: "dir", names: () => [...PID_NAMES, "task"] };
9955
10085
  if (!PID_NAMES.includes(leaf)) return void 0;
9956
10086
  return {
9957
10087
  kind: "file",
@@ -9963,6 +10093,28 @@ var init_wasi_procfs = __esm({
9963
10093
  }
9964
10094
  };
9965
10095
  }
10096
+ info(pid) {
10097
+ return this.listing().processes.find((p) => p.pid === pid);
10098
+ }
10099
+ task(pid, rest2) {
10100
+ const [tid, leaf, ...more] = rest2;
10101
+ const tids = () => taskIds(this.info(pid));
10102
+ if (tid === void 0) return { kind: "dir", names: () => tids().map(String) };
10103
+ if (!/^[1-9]\d*$/.test(tid) || more.length > 0 || !tids().includes(Number(tid)))
10104
+ return void 0;
10105
+ if (leaf === void 0) return { kind: "dir", names: () => ["stat"] };
10106
+ if (leaf !== "stat") return void 0;
10107
+ return {
10108
+ kind: "file",
10109
+ content: () => {
10110
+ const listing = this.listing();
10111
+ const info = listing.processes.find((p) => p.pid === pid);
10112
+ const line = info && taskStat(info, Number(tid), listing.boot);
10113
+ if (line === void 0) throw syncError("ENOENT", `/proc/${pid}/task/${tid}/stat`);
10114
+ return line;
10115
+ }
10116
+ };
10117
+ }
9966
10118
  parts(path, follow2) {
9967
10119
  const parts = path.split("/").filter((p) => p !== "").slice(1);
9968
10120
  if (parts[0] === "self" && (follow2 || parts.length > 1)) parts[0] = String(this.pid);
@@ -10298,6 +10450,18 @@ function mutableGlobals(exports) {
10298
10450
  }
10299
10451
  return out;
10300
10452
  }
10453
+ function reseatTls(exports, bytes) {
10454
+ const init = exports.__wasm_init_tls;
10455
+ const base = exports.__tls_base;
10456
+ const size = exports.__tls_size;
10457
+ if (typeof init !== "function" || !(base instanceof WebAssembly.Global) || !(size instanceof WebAssembly.Global)) {
10458
+ return;
10459
+ }
10460
+ const at = base.value;
10461
+ const block = bytes(at, size.value).slice();
10462
+ init(at);
10463
+ bytes(at, block.length).set(block);
10464
+ }
10301
10465
  var STACK_POINTER, UNWINDING, REWINDING, AsyncifyDriver;
10302
10466
  var init_wasix_fork = __esm({
10303
10467
  "src/process/wasi/wasix-fork.ts"() {
@@ -10348,6 +10512,7 @@ var init_wasix_fork = __esm({
10348
10512
  for (const [id, snap] of state.setjmps?.snapshots ?? []) this.snapshots.set(id, snap);
10349
10513
  this.nextSnapshot = Math.max(this.nextSnapshot, state.setjmps?.next ?? 1);
10350
10514
  this.restoreGlobals(state.globals);
10515
+ reseatTls(this.exports, (at, length) => this.mem.bytes(at, length));
10351
10516
  this.answer = 0;
10352
10517
  this.exports.asyncify_start_rewind?.(state.asyncifyData);
10353
10518
  }
@@ -10996,6 +11161,7 @@ var init_wasix_linker = __esm({
10996
11161
  "use strict";
10997
11162
  init_dylink();
10998
11163
  init_wasi_files();
11164
+ init_wasix_fork();
10999
11165
  init_wasix_trampoline();
11000
11166
  init_wasm_functypes();
11001
11167
  TABLE_BASE2 = 1;
@@ -11177,6 +11343,10 @@ var init_wasix_linker = __esm({
11177
11343
  const global = linked.instance.exports.__tls_base;
11178
11344
  if (base === void 0 || !(global instanceof WebAssembly.Global)) return false;
11179
11345
  global.value = base;
11346
+ reseatTls(
11347
+ linked.instance.exports,
11348
+ (at, length) => new Uint8Array(this.memory.buffer, at, length)
11349
+ );
11180
11350
  return true;
11181
11351
  }
11182
11352
  replay(record) {