@ai-ecoverse/slicc-kernel 1.77.0 → 1.77.2

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.
@@ -3194,6 +3194,22 @@ function cString(memory, at) {
3194
3194
  function baseOf(Fs, dirfd) {
3195
3195
  return dirfd === AT_FDCWD ? Fs.cwd?.() ?? "/" : Fs.getStream?.(dirfd)?.path ?? "/";
3196
3196
  }
3197
+ function readonlyRefusal(Fs, memory, call2) {
3198
+ if (!(call2.amode & W_ACCESS)) return 0;
3199
+ try {
3200
+ const name2 = cString(memory, call2.path);
3201
+ const abs = name2.startsWith("/") ? name2 : `${baseOf(Fs, call2.dirfd)}/${name2}`;
3202
+ const follow2 = (call2.flags & AT_SYMLINK_NOFOLLOW) === 0;
3203
+ const { node } = Fs.lookupPath.call(Fs, abs, {
3204
+ follow: follow2
3205
+ });
3206
+ const bridge = node.live ? node.mount.opts.bridge : void 0;
3207
+ const stat = bridge?.stat;
3208
+ return stat?.(liveNodePath(node)).readonly ? -wasiErrno("EROFS") : 0;
3209
+ } catch {
3210
+ return 0;
3211
+ }
3212
+ }
3197
3213
  function kernelChecks(Fs, memory, call2) {
3198
3214
  const name2 = cString(memory, call2.path);
3199
3215
  const abs = name2.startsWith("/") ? name2 : `${baseOf(Fs, call2.dirfd)}/${name2}`;
@@ -3207,9 +3223,12 @@ function kernelChecks(Fs, memory, call2) {
3207
3223
  }
3208
3224
  function kernelAccess(imports, fs, memory, glue) {
3209
3225
  wrapImport(imports, "faccessat", glue, (own) => (dirfd, path, amode, flags) => {
3210
- const rc = own(dirfd, path, amode, flags);
3211
3226
  const Fs = fs();
3212
3227
  const heap = memory();
3228
+ const call2 = { dirfd, path, amode: amode & 7, flags };
3229
+ const refused = Fs?.lookupPath && heap ? readonlyRefusal(Fs, heap, call2) : 0;
3230
+ if (refused !== 0) return refused;
3231
+ const rc = own(dirfd, path, amode, flags);
3213
3232
  if (rc !== 0 || !Fs?.lookupPath || !heap) return rc;
3214
3233
  try {
3215
3234
  return kernelChecks(Fs, heap, { dirfd, path, amode: amode & 7, flags });
@@ -3228,7 +3247,7 @@ function linuxDevices(Fs) {
3228
3247
  }
3229
3248
  }
3230
3249
  }
3231
- var O_CLOEXEC, FD_CLOEXEC, F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_DUPFD_CLOEXEC, tracked, IMPORT_NAMES, EBADF, AT_SYMLINK_NOFOLLOW, EMSCRIPTEN_EPERM, O_PATH, LITERALS, UTIME_NOW, UTIME_OMIT, PROT_WRITE, MAP_PRIVATE, MAP_TYPE, O_WRONLY, MAP_ALIGN, DIR_MODE, LINK_MODE, CHAR_DEVICE, O_ACCMODE2, O_CREAT2, field, pinnedRoot, rootKind, NAME, AT_FDCWD, AT_EACCESS, DEVICE_MODES;
3250
+ var O_CLOEXEC, FD_CLOEXEC, F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_DUPFD_CLOEXEC, tracked, IMPORT_NAMES, EBADF, AT_SYMLINK_NOFOLLOW, EMSCRIPTEN_EPERM, O_PATH, LITERALS, UTIME_NOW, UTIME_OMIT, PROT_WRITE, MAP_PRIVATE, MAP_TYPE, O_WRONLY, MAP_ALIGN, DIR_MODE, LINK_MODE, CHAR_DEVICE, O_ACCMODE2, O_CREAT2, field, pinnedRoot, rootKind, NAME, AT_FDCWD, AT_EACCESS, W_ACCESS, DEVICE_MODES;
3232
3251
  var init_process_fds = __esm({
3233
3252
  "src/process/process-fds.ts"() {
3234
3253
  "use strict";
@@ -3287,6 +3306,7 @@ var init_process_fds = __esm({
3287
3306
  NAME = /^[a-z_][a-z0-9_-]*$/i;
3288
3307
  AT_FDCWD = -100;
3289
3308
  AT_EACCESS = 512;
3309
+ W_ACCESS = 2;
3290
3310
  DEVICE_MODES = [
3291
3311
  ["/", 493],
3292
3312
  ["/dev", 493],
@@ -5779,6 +5799,7 @@ var init_wasi_fds = __esm({
5779
5799
  WasiFds = class {
5780
5800
  table = /* @__PURE__ */ new Map();
5781
5801
  buffers = /* @__PURE__ */ new Map();
5802
+ reported = /* @__PURE__ */ new WeakSet();
5782
5803
  byId = /* @__PURE__ */ new Map();
5783
5804
  ids = /* @__PURE__ */ new Map();
5784
5805
  kernel;
@@ -6103,7 +6124,16 @@ var init_wasi_fds = __esm({
6103
6124
  release(e) {
6104
6125
  if (e.type !== "file" || --e.file.refs > 0) return;
6105
6126
  const { buffer } = e.file;
6106
- buffer.flush();
6127
+ try {
6128
+ buffer.flush();
6129
+ } catch (err) {
6130
+ this.reported.add(buffer);
6131
+ this.drop(buffer);
6132
+ throw err;
6133
+ }
6134
+ this.drop(buffer);
6135
+ }
6136
+ drop(buffer) {
6107
6137
  if (--buffer.opens > 0) return;
6108
6138
  this.forget(buffer);
6109
6139
  this.letGo(buffer);
@@ -6158,7 +6188,13 @@ var init_wasi_fds = __esm({
6158
6188
  return e.kind;
6159
6189
  }
6160
6190
  flushAll() {
6161
- for (const buffer of this.buffers.values()) buffer.flush();
6191
+ for (const buffer of this.buffers.values()) {
6192
+ try {
6193
+ buffer.flush();
6194
+ } catch (err) {
6195
+ if (!this.reported.has(buffer)) throw err;
6196
+ }
6197
+ }
6162
6198
  }
6163
6199
  flushEarly() {
6164
6200
  for (const buffer of this.buffers.values()) {
@@ -6921,7 +6957,8 @@ var init_wasi_host = __esm({
6921
6957
  if (this.o.fs.owners && amode & 1) throw new WasiError("EACCES");
6922
6958
  return;
6923
6959
  }
6924
- pathOwned(path, !nofollow);
6960
+ const st = pathOwned(path, !nofollow);
6961
+ if (amode & 2 && st.readonly) throw new WasiError("EROFS");
6925
6962
  if (!this.o.fs.owners) return;
6926
6963
  const kind = flags & AT_EACCESS2 ? "eaccess" : "access";
6927
6964
  this.o.fs.access?.(path, amode & 7, kind, nofollow);