@ai-ecoverse/slicc-kernel 1.146.1 → 1.146.3

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.
@@ -1197,6 +1197,18 @@ var init_sync_fs_wire = __esm({
1197
1197
  });
1198
1198
 
1199
1199
  // src/realm/sync-sab-bridge.ts
1200
+ function exactBody(req, transfer = []) {
1201
+ const body = req.body;
1202
+ if (!ArrayBuffer.isView(body)) return { req, transfer };
1203
+ if (Object.prototype.toString.call(body.buffer) === "[object SharedArrayBuffer]") {
1204
+ return { req, transfer };
1205
+ }
1206
+ const whole = body.constructor === Uint8Array && body.byteOffset === 0 && body.byteLength === body.buffer.byteLength;
1207
+ if (whole) return { req, transfer };
1208
+ const copy2 = new Uint8Array(body.byteLength);
1209
+ copy2.set(new Uint8Array(body.buffer, body.byteOffset, body.byteLength));
1210
+ return { req: { ...req, body: copy2 }, transfer: [...transfer, copy2.buffer] };
1211
+ }
1200
1212
  function syncCallCount() {
1201
1213
  return calls;
1202
1214
  }
@@ -1242,8 +1254,9 @@ function createSyncSabTransport(sab, port2, deps = {}) {
1242
1254
  }
1243
1255
  }
1244
1256
  return {
1245
- call(req, timeoutMs2, label, transfer = []) {
1257
+ call(asked, timeoutMs2, label, given = []) {
1246
1258
  if (deps.memory) publishMemory(sab, deps.memory());
1259
+ const { req, transfer } = exactBody(asked, given);
1247
1260
  const id = ++seq;
1248
1261
  calls += Number(!UNCOUNTED_OPS.has(req.op));
1249
1262
  let out = null;
@@ -2914,7 +2927,7 @@ var KERNEL_VERSION, OS_RELEASE;
2914
2927
  var init_version = __esm({
2915
2928
  "src/version.ts"() {
2916
2929
  "use strict";
2917
- KERNEL_VERSION = true ? "1.146.1" : "0.0.0-dev";
2930
+ KERNEL_VERSION = true ? "1.146.3" : "0.0.0-dev";
2918
2931
  OS_RELEASE = "6.0.0-slicc";
2919
2932
  }
2920
2933
  });
@@ -6112,9 +6125,12 @@ function ownBytes(bytes) {
6112
6125
  if (bytes.constructor === Uint8Array) return bytes;
6113
6126
  return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength).slice();
6114
6127
  }
6128
+ function ownedBuffer(body, given) {
6129
+ return body === given ? void 0 : [body.buffer];
6130
+ }
6115
6131
  function kernelSys(transport) {
6116
- const call2 = (req, label) => {
6117
- const r = transport.call(req, Number.POSITIVE_INFINITY, label);
6132
+ const call2 = (req, label, transfer) => {
6133
+ const r = transport.call(req, Number.POSITIVE_INFINITY, label, transfer);
6118
6134
  if (!r.ok) throw new SyscallError(r.errno);
6119
6135
  return r;
6120
6136
  };
@@ -6129,13 +6145,14 @@ function kernelSys(transport) {
6129
6145
  return r.ok && r.kind === "bytes" ? r.bytes : new Uint8Array(0);
6130
6146
  },
6131
6147
  write(fd, bytes, opts) {
6148
+ const body = ownBytes(bytes);
6132
6149
  const req = {
6133
6150
  op: "fd-write",
6134
6151
  fd,
6135
- body: ownBytes(bytes),
6152
+ body,
6136
6153
  ...opts?.nonblock ? { nonblock: true } : {}
6137
6154
  };
6138
- const n = json2(call2(req, `fd-write ${fd}`));
6155
+ const n = json2(call2(req, `fd-write ${fd}`, ownedBuffer(body, bytes)));
6139
6156
  return typeof n === "number" ? n : bytes.length;
6140
6157
  },
6141
6158
  close(fd) {
@@ -6180,8 +6197,9 @@ function kernelSys(transport) {
6180
6197
  return r.ok && r.kind === "bytes" ? r.bytes : new Uint8Array(0);
6181
6198
  },
6182
6199
  pwrite(fd, bytes, at) {
6200
+ const body = ownBytes(bytes);
6183
6201
  return json2(
6184
- call2({ op: "fd-pwrite", fd, offset: at, body: ownBytes(bytes) }, `fd-pwrite ${fd}`)
6202
+ call2({ op: "fd-pwrite", fd, offset: at, body }, `fd-pwrite ${fd}`, ownedBuffer(body, bytes))
6185
6203
  );
6186
6204
  },
6187
6205
  isatty(fd) {
@@ -7734,7 +7752,8 @@ function createAsyncSabTransport(sab, port2, waitAsync = defaultWaitAsync) {
7734
7752
  await changed(header, SAB_I_PUB, published, waitAsync);
7735
7753
  }
7736
7754
  }
7737
- async function once(req) {
7755
+ async function once(asked) {
7756
+ const { req, transfer } = exactBody(asked);
7738
7757
  const id = ++seq;
7739
7758
  let out = null;
7740
7759
  let status2 = 0;
@@ -7743,9 +7762,8 @@ function createAsyncSabTransport(sab, port2, waitAsync = defaultWaitAsync) {
7743
7762
  try {
7744
7763
  for (; ; ) {
7745
7764
  Atomics.store(header, SAB_I_STATE, SAB_STATE_PENDING);
7746
- port2.postMessage(
7747
- offset === 0 ? { type: SYNC_SAB_REQ_MSG, id, req } : { type: SYNC_SAB_NEXT_MSG, id, offset }
7748
- );
7765
+ if (offset === 0) port2.postMessage({ type: SYNC_SAB_REQ_MSG, id, req }, transfer);
7766
+ else port2.postMessage({ type: SYNC_SAB_NEXT_MSG, id, offset });
7749
7767
  await ready(id);
7750
7768
  const total = loadU53(header, SAB_I_TOTAL, SAB_I_TOTAL_HI);
7751
7769
  const chunk = Atomics.load(header, SAB_I_CHUNK);
@@ -7780,6 +7798,7 @@ var defaultWaitAsync;
7780
7798
  var init_async_sab = __esm({
7781
7799
  "src/process/js/async-sab.ts"() {
7782
7800
  "use strict";
7801
+ init_sync_sab_bridge();
7783
7802
  init_sync_sab_wire();
7784
7803
  defaultWaitAsync = (a, i, v) => Atomics.waitAsync(a, i, v);
7785
7804
  }
@@ -9506,10 +9525,9 @@ var init_wasi_fds = __esm({
9506
9525
  if (exclusive && !(oflags & OFLAGS.DIRECTORY) && this.madeAtOnce(path, mode)) {
9507
9526
  return this.regular(path, void 0, oflags, rights, fdflags, mode, true);
9508
9527
  }
9509
- if ((exclusive || nofollow) && this.isLink(path)) {
9510
- throw new WasiError(exclusive ? "EEXIST" : "ELOOP");
9511
- }
9512
- const s = this.statOrMissing(path);
9528
+ if (exclusive && !nofollow && this.isLink(path)) throw new WasiError("EEXIST");
9529
+ const s = nofollow ? this.lstatOrMissing(path) : this.statOrMissing(path);
9530
+ if (s?.isSymbolicLink) throw new WasiError(exclusive ? "EEXIST" : "ELOOP");
9513
9531
  if (exclusive && s) throw new WasiError("EEXIST");
9514
9532
  if (s?.escape !== void 0) {
9515
9533
  refuseWrite({ readonly: true }, oflags, rights);
@@ -9528,6 +9546,11 @@ var init_wasi_fds = __esm({
9528
9546
  return this.regular(path, s, oflags, rights, fdflags, mode);
9529
9547
  }
9530
9548
  nofollow = false;
9549
+ inos = /* @__PURE__ */ new WeakMap();
9550
+ otherFile(buffer, st) {
9551
+ const ino = this.inos.get(buffer);
9552
+ return ino !== void 0 && st?.ino !== void 0 && ino !== st.ino;
9553
+ }
9531
9554
  openSpecial(path, oflags, rights, fdflags, exclusive) {
9532
9555
  if (exclusive && namedDevice(path)) throw new WasiError("EEXIST");
9533
9556
  const device2 = deviceOf(path);
@@ -9585,6 +9608,7 @@ var init_wasi_fds = __esm({
9585
9608
  buffer = void 0;
9586
9609
  }
9587
9610
  buffer ??= this.sharing(path, existing);
9611
+ if (buffer && this.nofollow && this.otherFile(buffer, existing)) buffer = void 0;
9588
9612
  const want = wantOf2(oflags, rights);
9589
9613
  if (buffer) {
9590
9614
  if (this.fs.owners) this.fs.access?.(path, want, "open");
@@ -9629,6 +9653,7 @@ var init_wasi_fds = __esm({
9629
9653
  const buffer = new FileBuffer(io, path, empty, st.maxFile, ranged, st.version, watch);
9630
9654
  buffer.moved = (missing2) => this.followRenames(missing2);
9631
9655
  buffer.handle = handle;
9656
+ if (st.ino !== void 0) this.inos.set(buffer, st.ino);
9632
9657
  this.buffers.set(path, buffer);
9633
9658
  const id = this.identity(st);
9634
9659
  if (id !== void 0) this.know(buffer, id);
@@ -9711,6 +9736,14 @@ var init_wasi_fds = __esm({
9711
9736
  return false;
9712
9737
  }
9713
9738
  }
9739
+ lstatOrMissing(path) {
9740
+ try {
9741
+ return this.fs.lstat(path);
9742
+ } catch (e) {
9743
+ if (e.code === "ENOENT") return void 0;
9744
+ throw e;
9745
+ }
9746
+ }
9714
9747
  statOrMissing(path) {
9715
9748
  try {
9716
9749
  return this.fs.stat(path);