@ai-ecoverse/slicc-kernel 1.17.2 → 1.17.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.
@@ -211,7 +211,13 @@ function createHelpers(Fs, ops) {
211
211
  }
212
212
  function truncate(node, size) {
213
213
  const s = node.live;
214
- if (!s.orphan && statOf(node).readonly) throw new Fs.ErrnoError(ERRNO_BY_CODE.EROFS);
214
+ if (!s.orphan) {
215
+ const st = statOf(node);
216
+ if (st.readonly) throw new Fs.ErrnoError(ERRNO_BY_CODE.EROFS);
217
+ if (st.maxFile !== void 0 && size > st.maxFile) {
218
+ throw new Fs.ErrnoError(ERRNO_BY_CODE.EFBIG);
219
+ }
220
+ }
215
221
  if (s.openCount > 0) {
216
222
  if (size > 0) ensureLoaded(node);
217
223
  else s.loaded = true;
@@ -402,7 +408,9 @@ function createStreamOps(h) {
402
408
  if (!Fs.isFile(stream.node.mode)) return;
403
409
  if ((stream.flags & 3) !== 0) {
404
410
  try {
405
- if (statOf(stream.node).readonly) throw new Fs.ErrnoError(ERRNO_BY_CODE.EROFS);
411
+ const st = statOf(stream.node);
412
+ if (st.readonly) throw new Fs.ErrnoError(ERRNO_BY_CODE.EROFS);
413
+ stream.node.live.maxFile = st.maxFile;
406
414
  } catch (err) {
407
415
  if (stream.fd !== void 0) Fs.closeStream?.(stream.fd);
408
416
  throw err;
@@ -449,9 +457,10 @@ function createStreamOps(h) {
449
457
  const node = stream.node;
450
458
  if (Fs.isDir(node.mode)) throw new Fs.ErrnoError(ERRNO_BY_CODE.EISDIR);
451
459
  if (length <= 0) return 0;
452
- ensureLoaded(node);
453
460
  const s = node.live;
454
461
  const end = position + length;
462
+ if (s.maxFile !== void 0 && end > s.maxFile) throw new Fs.ErrnoError(ERRNO_BY_CODE.EFBIG);
463
+ ensureLoaded(node);
455
464
  const buf = ensureCapacity(node, end);
456
465
  if (position > s.len) buf.fill(0, s.len, position);
457
466
  buf.set(new Uint8Array(buffer.buffer, buffer.byteOffset + offset, length), position);
@@ -751,7 +760,8 @@ function parseSyncFsStat(json) {
751
760
  ...typeof s.ctimeMs === "number" ? { ctimeMs: s.ctimeMs } : {},
752
761
  ...typeof s.ino === "number" ? { ino: s.ino } : {},
753
762
  ...typeof s.dev === "number" ? { dev: s.dev } : {},
754
- ...s.readonly === true ? { readonly: true } : {}
763
+ ...s.readonly === true ? { readonly: true } : {},
764
+ ...typeof s.maxFile === "number" ? { maxFile: s.maxFile } : {}
755
765
  };
756
766
  }
757
767
  var SYNC_FS_REQUEST_TIMEOUT_MS;
@@ -1761,6 +1771,19 @@ function cloexecPipe2(pipe2, deps) {
1761
1771
  return r;
1762
1772
  };
1763
1773
  }
1774
+ function quietTarget(dup3, deps) {
1775
+ return (fd = -1, newfd = -1, flags = 0, ...rest) => {
1776
+ const Fs = deps.fs();
1777
+ const target = fd === newfd || flags !== 0 ? void 0 : Fs?.getStream(newfd);
1778
+ if (target && Fs?.getStream(fd)) {
1779
+ try {
1780
+ Fs.close?.(target);
1781
+ } catch {
1782
+ }
1783
+ }
1784
+ return dup3(fd, newfd, flags, ...rest);
1785
+ };
1786
+ }
1764
1787
  function cloexecByFlag(syscall, flagArg, deps) {
1765
1788
  const mark = marker(deps);
1766
1789
  return (...args) => {
@@ -1777,7 +1800,7 @@ function wrapperFactories(deps) {
1777
1800
  ...timer ? { setitimer: (f) => kernelTimer(f, timer) } : {},
1778
1801
  fcntl: (f) => cloexecFcntl(f, deps),
1779
1802
  pipe2: (f) => cloexecPipe2(f, deps),
1780
- dup3: (f) => cloexecByFlag(f, 2, deps),
1803
+ dup3: (f) => cloexecByFlag(quietTarget(f, deps), 2, deps),
1781
1804
  socket: (f) => cloexecByFlag(f, 1, deps),
1782
1805
  accept4: (f) => cloexecByFlag(f, 3, deps),
1783
1806
  ...pty ? { ioctl: (f) => ptyIoctl(f, { fs: deps.fs, heap: deps.heap, kernel: pty }) } : {}
@@ -2749,7 +2772,7 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
2749
2772
  };
2750
2773
  return node;
2751
2774
  };
2752
- const find = (processes2, target, own) => processes2.find((p) => own ? p.tid === target : p.pid === target || p.tid === target);
2775
+ const find = (processes2, target, own) => (own ? processes2.find((p) => p.tid === target) : void 0) ?? processes2.find((p) => p.pid === target || p.tid === target);
2753
2776
  const infoOf = (target) => find(procList().processes, target, false);
2754
2777
  const pidContent = (target, name, own = false) => () => {
2755
2778
  const listing = procList();
@@ -3440,9 +3463,11 @@ var init_wasi_files = __esm({
3440
3463
  opens = 0;
3441
3464
  fs;
3442
3465
  path;
3443
- constructor(fs, path, empty) {
3466
+ maxFile;
3467
+ constructor(fs, path, empty, maxFile) {
3444
3468
  this.fs = fs;
3445
3469
  this.path = path;
3470
+ this.maxFile = maxFile;
3446
3471
  if (empty) {
3447
3472
  this.data = new Uint8Array(0);
3448
3473
  this.dirty = true;
@@ -3464,9 +3489,14 @@ var init_wasi_files = __esm({
3464
3489
  const n = Math.max(0, Math.min(max, this.length - at));
3465
3490
  return bytes.subarray(at, at + n);
3466
3491
  }
3492
+ fits(end) {
3493
+ if (this.maxFile !== void 0 && end > this.maxFile) throw new WasiError("EFBIG");
3494
+ }
3467
3495
  pwrite(bytes, at) {
3468
- this.load();
3496
+ if (bytes.length === 0) return 0;
3469
3497
  const end = at + bytes.length;
3498
+ this.fits(end);
3499
+ this.load();
3470
3500
  this.ensure(end);
3471
3501
  const buf = this.data;
3472
3502
  if (at > this.length) buf.fill(0, this.length, at);
@@ -3476,6 +3506,7 @@ var init_wasi_files = __esm({
3476
3506
  return bytes.length;
3477
3507
  }
3478
3508
  truncate(size) {
3509
+ this.fits(size);
3479
3510
  this.load();
3480
3511
  this.ensure(size);
3481
3512
  if (size > this.length) this.data.fill(0, this.length, size);
@@ -4115,7 +4146,8 @@ var init_wasi_fds = __esm({
4115
4146
  if (oflags & OFLAGS.TRUNC) buffer.truncate(0);
4116
4147
  } else {
4117
4148
  if (!existing) this.fs.writeFile(path, new Uint8Array(0));
4118
- buffer = new FileBuffer(this.fs, path, !existing || (oflags & OFLAGS.TRUNC) !== 0);
4149
+ const empty = !existing || (oflags & OFLAGS.TRUNC) !== 0;
4150
+ buffer = new FileBuffer(this.fs, path, empty, (existing ?? this.fs.stat(path)).maxFile);
4119
4151
  this.buffers.set(path, buffer);
4120
4152
  }
4121
4153
  buffer.opens++;