@ai-ecoverse/slicc-kernel 1.99.2 → 1.100.0

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.0" : "0.0.0-dev";
2479
2479
  OS_RELEASE = "6.0.0-slicc";
2480
2480
  }
2481
2481
  });
@@ -6665,6 +6665,69 @@ var init_wasi_files = __esm({
6665
6665
  }
6666
6666
  });
6667
6667
 
6668
+ // src/process/wasi/slicc-lock.ts
6669
+ function kindOf2(type) {
6670
+ if (type === F_RDLCK2) return "read";
6671
+ if (type === F_WRLCK2) return "write";
6672
+ if (type === F_UNLCK2) return "unlock";
6673
+ throw new WasiError("EINVAL");
6674
+ }
6675
+ function baseOf3(file, whence) {
6676
+ if (whence === SEEK_SET) return 0;
6677
+ if (whence === SEEK_CUR3) return file.offset();
6678
+ if (whence === SEEK_END3) return file.size();
6679
+ throw new WasiError("EINVAL");
6680
+ }
6681
+ function writeHolder2(view, at, found) {
6682
+ if (!found) {
6683
+ view.setInt16(at, F_UNLCK2, true);
6684
+ return;
6685
+ }
6686
+ view.setInt16(at, found.kind === "read" ? F_RDLCK2 : F_WRLCK2, true);
6687
+ view.setInt16(at + 2, SEEK_SET, true);
6688
+ view.setBigInt64(at + 8, BigInt(found.start), true);
6689
+ view.setBigInt64(at + 16, BigInt(found.len), true);
6690
+ view.setInt32(at + 24, found.pid, true);
6691
+ }
6692
+ function lockImports(host) {
6693
+ return {
6694
+ fcntl_lock: (fd, cmd, at) => {
6695
+ if (cmd !== F_GETLK2 && cmd !== F_SETLK2 && cmd !== F_SETLKW2) throw new WasiError("EINVAL");
6696
+ const file = host.file(fd);
6697
+ const view = host.mem.view();
6698
+ const kind = kindOf2(view.getInt16(at, true));
6699
+ const start2 = baseOf3(file, view.getInt16(at + 2, true)) + Number(view.getBigInt64(at + 8, true));
6700
+ const len = Number(view.getBigInt64(at + 16, true));
6701
+ if (cmd === F_GETLK2) {
6702
+ if (kind === "unlock") throw new WasiError("EINVAL");
6703
+ writeHolder2(view, at, host.calls.get(file.target, kind, start2, len));
6704
+ return;
6705
+ }
6706
+ if (kind === "read" && file.readable === false || kind === "write" && file.writable === false)
6707
+ throw new WasiError("EBADF");
6708
+ if (kind !== "write") host.flush(file);
6709
+ host.calls.set(file.target, kind, start2, len, cmd === F_SETLKW2);
6710
+ if (kind !== "unlock") host.locked();
6711
+ }
6712
+ };
6713
+ }
6714
+ var F_GETLK2, F_SETLK2, F_SETLKW2, F_RDLCK2, F_WRLCK2, F_UNLCK2, SEEK_SET, SEEK_CUR3, SEEK_END3;
6715
+ var init_slicc_lock = __esm({
6716
+ "src/process/wasi/slicc-lock.ts"() {
6717
+ "use strict";
6718
+ init_wasi_files();
6719
+ F_GETLK2 = 12;
6720
+ F_SETLK2 = 13;
6721
+ F_SETLKW2 = 14;
6722
+ F_RDLCK2 = 0;
6723
+ F_WRLCK2 = 1;
6724
+ F_UNLCK2 = 2;
6725
+ SEEK_SET = 0;
6726
+ SEEK_CUR3 = 1;
6727
+ SEEK_END3 = 2;
6728
+ }
6729
+ });
6730
+
6668
6731
  // src/process/wasi/slicc-sem.ts
6669
6732
  function remainingMs(deadline, now) {
6670
6733
  if (deadline <= now) return 0;
@@ -7133,6 +7196,17 @@ var init_wasi_fds = __esm({
7133
7196
  }
7134
7197
  return out;
7135
7198
  }
7199
+ locking = false;
7200
+ holdLocks() {
7201
+ this.locking = true;
7202
+ }
7203
+ dropLocks(e) {
7204
+ if (!this.locking || e?.type !== "file") return;
7205
+ try {
7206
+ this.kernel.call({ op: "lk-close", path: e.file.path });
7207
+ } catch {
7208
+ }
7209
+ }
7136
7210
  close(fd) {
7137
7211
  const e = this.get(fd);
7138
7212
  this.table.delete(fd);
@@ -7141,6 +7215,7 @@ var init_wasi_fds = __esm({
7141
7215
  this.kernel.sys.close(fd);
7142
7216
  } finally {
7143
7217
  this.release(e);
7218
+ this.dropLocks(e);
7144
7219
  this.bump();
7145
7220
  }
7146
7221
  }
@@ -7159,6 +7234,7 @@ var init_wasi_fds = __esm({
7159
7234
  if (this.cloexec.delete(from)) this.cloexec.add(to);
7160
7235
  }
7161
7236
  if (old) this.release(old);
7237
+ this.dropLocks(old);
7162
7238
  this.bump();
7163
7239
  }
7164
7240
  release(e) {
@@ -8229,6 +8305,7 @@ var init_wasi_host = __esm({
8229
8305
  init_physical_path();
8230
8306
  init_cpu_clock();
8231
8307
  init_cred();
8308
+ init_slicc_lock();
8232
8309
  init_slicc_sem();
8233
8310
  init_wasi_abi();
8234
8311
  init_wasi_fds();
@@ -8451,6 +8528,26 @@ var init_wasi_host = __esm({
8451
8528
  void this.o.kernel.call({ op: "proc-setcred", change });
8452
8529
  },
8453
8530
  ...semImports(this),
8531
+ ...lockImports({
8532
+ mem,
8533
+ file: (fd) => this.lockedFile(fd),
8534
+ flush: (file) => {
8535
+ if (file.path !== void 0) this.fds.flushPath(file.path);
8536
+ else if (file.target.fd !== void 0) this.o.kernel.sys.flush(file.target.fd);
8537
+ },
8538
+ locked: () => this.fds.holdLocks(),
8539
+ calls: {
8540
+ set: (target, kind, start2, len, wait2) => void this.o.kernel.call({
8541
+ op: "lk-set",
8542
+ ...target,
8543
+ kind,
8544
+ start: start2,
8545
+ len,
8546
+ ...wait2 ? { wait: wait2 } : {}
8547
+ }),
8548
+ get: (target, kind, start2, len) => this.o.kernel.call({ op: "lk-get", ...target, kind, start: start2, len })
8549
+ }
8550
+ }),
8454
8551
  groups_get: (buf, cap, count) => {
8455
8552
  const { groups } = this.o.kernel.call({ op: "proc-cred" });
8456
8553
  if (cap !== 0 && cap < groups.length) throw new WasiError("EINVAL");
@@ -8843,6 +8940,26 @@ var init_wasi_host = __esm({
8843
8940
  }
8844
8941
  e.path = path;
8845
8942
  }
8943
+ lockedFile(fd) {
8944
+ const e = this.fds.get(fd);
8945
+ if (e.type === "file") {
8946
+ const { file } = e;
8947
+ return {
8948
+ target: { path: file.path },
8949
+ path: file.path,
8950
+ readable: file.readable,
8951
+ writable: file.writable,
8952
+ offset: () => file.offset,
8953
+ size: () => file.size()
8954
+ };
8955
+ }
8956
+ if (e.type !== "kernel" || this.fds.kind(fd, e) !== "file") throw new WasiError("EBADF");
8957
+ return {
8958
+ target: { fd },
8959
+ offset: () => this.o.kernel.sys.seek(fd, 0, WHENCE.CUR),
8960
+ size: () => this.kernelStat(fd).size
8961
+ };
8962
+ }
8846
8963
  kernelStat(fd) {
8847
8964
  return this.o.kernel.call({ op: "fd-vfs-stat", fd });
8848
8965
  }