@ai-ecoverse/slicc-kernel 1.33.0 → 1.34.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.
@@ -2216,6 +2216,47 @@ function positionalIo(imports, deps) {
2216
2216
  }
2217
2217
  }
2218
2218
  }
2219
+ function staging(Fs, length) {
2220
+ try {
2221
+ return new Uint8Array(length);
2222
+ } catch {
2223
+ throw new Fs.ErrnoError(wasiErrno("ENOMEM"));
2224
+ }
2225
+ }
2226
+ function useFileMmap(Fs, deps) {
2227
+ const fs = Fs;
2228
+ const mmap = fs.mmap;
2229
+ if (typeof mmap !== "function") return;
2230
+ fs.mmap = (stream, length, position, prot, flags) => {
2231
+ const memalign = deps.memalign();
2232
+ const memory = deps.memory();
2233
+ const shared = (flags & MAP_TYPE) !== MAP_PRIVATE && (prot & PROT_WRITE) !== 0;
2234
+ const kfd = stream.sliccKernelFile ? stream.sliccKernelFd : void 0;
2235
+ if (shared && kfd !== void 0) throw new Fs.ErrnoError(wasiErrno("ENODEV"));
2236
+ if (stream.stream_ops.mmap && kfd === void 0 || !memalign || !memory || length <= 0 || shared || (stream.flags & O_ACCMODE) === O_WRONLY || !Fs.isFile(stream.node.mode)) {
2237
+ return mmap.call(fs, stream, length, position, prot, flags);
2238
+ }
2239
+ const data = staging(Fs, length);
2240
+ let done = 0;
2241
+ try {
2242
+ if (kfd !== void 0) done = readInto(deps.sys, kfd, data, position);
2243
+ else {
2244
+ for (let got = 1; done < length && got > 0; done += got) {
2245
+ got = Fs.read(stream, data, done, length - done, position + done);
2246
+ }
2247
+ }
2248
+ } catch (err) {
2249
+ throw new Fs.ErrnoError(errnoOf(err));
2250
+ }
2251
+ const size = Math.ceil(length / MAP_ALIGN) * MAP_ALIGN;
2252
+ const ptr = memalign(MAP_ALIGN, size);
2253
+ if (!ptr) throw new Fs.ErrnoError(wasiErrno("ENOMEM"));
2254
+ const target = new Uint8Array(memory.buffer, ptr, size);
2255
+ target.fill(0);
2256
+ target.set(data.subarray(0, done));
2257
+ return { ptr, allocated: true };
2258
+ };
2259
+ }
2219
2260
  function wasmMemory(instance, imports) {
2220
2261
  const isMemory = (v) => v instanceof WebAssembly.Memory;
2221
2262
  const exported = Object.values(instance.exports).find(isMemory);
@@ -2412,7 +2453,7 @@ function useMounts(Fs, env = {}, live = false) {
2412
2453
  }
2413
2454
  };
2414
2455
  }
2415
- 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, DIR_MODE, LINK_MODE, CHAR_DEVICE, O_ACCMODE, O_CREAT2, field, NAME;
2456
+ 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, PROT_WRITE, MAP_PRIVATE, MAP_TYPE, O_WRONLY, MAP_ALIGN, DIR_MODE, LINK_MODE, CHAR_DEVICE, O_ACCMODE, O_CREAT2, field, NAME;
2416
2457
  var init_process_fds = __esm({
2417
2458
  "src/process/process-fds.ts"() {
2418
2459
  "use strict";
@@ -2440,6 +2481,11 @@ var init_process_fds = __esm({
2440
2481
  AT_SYMLINK_NOFOLLOW = 256;
2441
2482
  EMSCRIPTEN_EPERM = 63;
2442
2483
  O_PATH = 2097152;
2484
+ PROT_WRITE = 2;
2485
+ MAP_PRIVATE = 2;
2486
+ MAP_TYPE = 15;
2487
+ O_WRONLY = 1;
2488
+ MAP_ALIGN = 65536;
2443
2489
  DIR_MODE = 16749;
2444
2490
  LINK_MODE = 41408;
2445
2491
  CHAR_DEVICE = 8630;
@@ -3008,7 +3054,7 @@ function socketNode(Fs, addr) {
3008
3054
  const fs = Fs;
3009
3055
  let stream;
3010
3056
  try {
3011
- stream = Fs.open(addr.path, O_WRONLY | O_CREAT4 | O_EXCL3, 493);
3057
+ stream = Fs.open(addr.path, O_WRONLY2 | O_CREAT4 | O_EXCL3, 493);
3012
3058
  } catch (e) {
3013
3059
  if (e?.errno === wasiErrno("EEXIST")) {
3014
3060
  throw new SyscallError("EADDRINUSE");
@@ -3140,7 +3186,7 @@ function createSocketKernel(deps) {
3140
3186
  })
3141
3187
  };
3142
3188
  }
3143
- var O_RDWR2, KILLED_BY_SIGPIPE2, O_WRONLY, O_CREAT4, O_EXCL3;
3189
+ var O_RDWR2, KILLED_BY_SIGPIPE2, O_WRONLY2, O_CREAT4, O_EXCL3;
3144
3190
  var init_process_sockets = __esm({
3145
3191
  "src/process/process-sockets.ts"() {
3146
3192
  "use strict";
@@ -3150,7 +3196,7 @@ var init_process_sockets = __esm({
3150
3196
  init_wasi_errno();
3151
3197
  O_RDWR2 = 2;
3152
3198
  KILLED_BY_SIGPIPE2 = 128 + 13;
3153
- O_WRONLY = 1;
3199
+ O_WRONLY2 = 1;
3154
3200
  O_CREAT4 = 64;
3155
3201
  O_EXCL3 = 128;
3156
3202
  }
@@ -3619,7 +3665,7 @@ function wireKernelFd(Fs, streams, entry) {
3619
3665
  });
3620
3666
  }
3621
3667
  function openDevice(Fs, fd, meta) {
3622
- const flags = meta.access === "read" ? O_RDONLY : meta.access === "write" ? O_WRONLY2 : O_RDWR3;
3668
+ const flags = meta.access === "read" ? O_RDONLY : meta.access === "write" ? O_WRONLY3 : O_RDWR3;
3623
3669
  let stream;
3624
3670
  try {
3625
3671
  stream = Fs.open(`/dev/${meta.device}`, flags);
@@ -3703,6 +3749,7 @@ async function runWasmProcess(init, port2, deps = {}) {
3703
3749
  let ready;
3704
3750
  let failed2;
3705
3751
  let memory;
3752
+ let exports;
3706
3753
  const initialized = new Promise((resolve, reject) => {
3707
3754
  ready = resolve;
3708
3755
  failed2 = reject;
@@ -3750,6 +3797,7 @@ async function runWasmProcess(init, port2, deps = {}) {
3750
3797
  return WebAssembly.instantiate(init.program.module, imports);
3751
3798
  }).then((instance) => {
3752
3799
  memory = wasmMemory(instance, imports);
3800
+ exports = instance.exports;
3753
3801
  publishMemory(init.sab, memory?.buffer.byteLength ?? 0);
3754
3802
  done(instance, init.program.module);
3755
3803
  }, failed2);
@@ -3796,6 +3844,11 @@ async function runWasmProcess(init, port2, deps = {}) {
3796
3844
  if (pipefs) streams.usePipes(pipefs);
3797
3845
  streams.useControllingTerminal();
3798
3846
  useDevFd(running.FS);
3847
+ useFileMmap(running.FS, {
3848
+ sys,
3849
+ memory: () => memory,
3850
+ memalign: () => exports?.emscripten_builtin_memalign
3851
+ });
3799
3852
  ownByRealmUser(running.FS);
3800
3853
  const livePath = (s) => liveNodePath(s.node);
3801
3854
  running.sliccKernel = createProcessKernel({
@@ -3867,7 +3920,7 @@ function runMain(running, init) {
3867
3920
  return status2;
3868
3921
  }
3869
3922
  }
3870
- var O_RDONLY, O_WRONLY2, O_RDWR3, PLACED, GLUE_TRAILER, evaluateGlue, EVAL_BLOCKED;
3923
+ var O_RDONLY, O_WRONLY3, O_RDWR3, PLACED, GLUE_TRAILER, evaluateGlue, EVAL_BLOCKED;
3871
3924
  var init_process_runtime = __esm({
3872
3925
  "src/process/process-runtime.ts"() {
3873
3926
  "use strict";
@@ -3888,7 +3941,7 @@ var init_process_runtime = __esm({
3888
3941
  init_realm_user();
3889
3942
  init_kernel_streams();
3890
3943
  O_RDONLY = 0;
3891
- O_WRONLY2 = 1;
3944
+ O_WRONLY3 = 1;
3892
3945
  O_RDWR3 = 2;
3893
3946
  PLACED = /* @__PURE__ */ new Set(["stream", "file", "socket"]);
3894
3947
  GLUE_TRAILER = [
@@ -4348,7 +4401,7 @@ function promoteRequest(fd, f, handed) {
4348
4401
  op: "fd-promote",
4349
4402
  fd,
4350
4403
  path: f.path,
4351
- flags: (f.writable ? f.readable ? O_RDWR4 : O_WRONLY3 : 0) | (f.append ? O_APPEND : 0),
4404
+ flags: (f.writable ? f.readable ? O_RDWR4 : O_WRONLY4 : 0) | (f.append ? O_APPEND : 0),
4352
4405
  position: f.offset,
4353
4406
  ...joins ? {} : { contents: f.buffer.contents() },
4354
4407
  ...orphan ? { orphan: true } : {},
@@ -4356,7 +4409,7 @@ function promoteRequest(fd, f, handed) {
4356
4409
  ...!joins && f.buffer.isDirty() ? { dirty: true } : {}
4357
4410
  };
4358
4411
  }
4359
- var SYNTHETIC_DIRS2, O_NONBLOCK2, O_WRONLY3, O_RDWR4, O_APPEND, DEVICES2, WasiFds, GEN;
4412
+ var SYNTHETIC_DIRS2, O_NONBLOCK2, O_WRONLY4, O_RDWR4, O_APPEND, DEVICES2, WasiFds, GEN;
4360
4413
  var init_wasi_fds = __esm({
4361
4414
  "src/process/wasi/wasi-fds.ts"() {
4362
4415
  "use strict";
@@ -4364,7 +4417,7 @@ var init_wasi_fds = __esm({
4364
4417
  init_wasi_files();
4365
4418
  SYNTHETIC_DIRS2 = ["usr", "bin"];
4366
4419
  O_NONBLOCK2 = 2048;
4367
- O_WRONLY3 = 1;
4420
+ O_WRONLY4 = 1;
4368
4421
  O_RDWR4 = 2;
4369
4422
  O_APPEND = 1024;
4370
4423
  DEVICES2 = {
@@ -4777,7 +4830,7 @@ var init_wasi_fds = __esm({
4777
4830
  kernelFile(path, existing, oflags, rights, fdflags) {
4778
4831
  const { readable, writable } = openAccess(existing, oflags, rights);
4779
4832
  const append = (fdflags & FDFLAGS.APPEND) !== 0;
4780
- const flags = (writable ? readable ? O_RDWR4 : O_WRONLY3 : 0) | (append ? O_APPEND : 0);
4833
+ const flags = (writable ? readable ? O_RDWR4 : O_WRONLY4 : 0) | (append ? O_APPEND : 0);
4781
4834
  if (!existing) this.fs.writeFile(path, new Uint8Array(0));
4782
4835
  const truncate = !existing || (oflags & OFLAGS.TRUNC) !== 0;
4783
4836
  const fd = this.kernel.sys.openVfs(path, flags, 0, truncate ? { truncate } : {});
@@ -6427,7 +6480,7 @@ var init_wasix_linker = __esm({
6427
6480
  function resolveFrom(cwd, path) {
6428
6481
  return normalize(path.startsWith("/") ? path : `${cwd}/${path}`);
6429
6482
  }
6430
- var POSIX_TO_WASI_SIGNAL, O_WRONLY4, O_RDWR5, O_APPEND2, OFLAG_CREAT, OFLAG_TRUNC, WasixProcess;
6483
+ var POSIX_TO_WASI_SIGNAL, O_WRONLY5, O_RDWR5, O_APPEND2, OFLAG_CREAT, OFLAG_TRUNC, WasixProcess;
6431
6484
  var init_wasix_process = __esm({
6432
6485
  "src/process/wasi/wasix-process.ts"() {
6433
6486
  "use strict";
@@ -6437,7 +6490,7 @@ var init_wasix_process = __esm({
6437
6490
  POSIX_TO_WASI_SIGNAL = Object.fromEntries(
6438
6491
  Object.entries(WASI_SIGNAL_TO_POSIX).map(([wasi, posix]) => [posix, Number(wasi)])
6439
6492
  );
6440
- O_WRONLY4 = 1;
6493
+ O_WRONLY5 = 1;
6441
6494
  O_RDWR5 = 2;
6442
6495
  O_APPEND2 = 1024;
6443
6496
  OFLAG_CREAT = 1;
@@ -6528,7 +6581,7 @@ var init_wasix_process = __esm({
6528
6581
  throw Object.assign(new Error("ENOENT"), { code: "ENOENT" });
6529
6582
  }
6530
6583
  const flags = (op.rightsWrite ? O_RDWR5 : 0) | (op.append ? O_APPEND2 : 0);
6531
- return this.host.o.kernel.sys.openVfs(path, op.rightsWrite ? flags || O_WRONLY4 : 0, 0, {
6584
+ return this.host.o.kernel.sys.openVfs(path, op.rightsWrite ? flags || O_WRONLY5 : 0, 0, {
6532
6585
  ...create ? { create } : {},
6533
6586
  ...op.oflags & OFLAG_TRUNC ? { truncate: true } : {}
6534
6587
  });
@@ -8009,7 +8062,7 @@ function typeOf(info) {
8009
8062
  }
8010
8063
  function flagsOf(o) {
8011
8064
  const write = o.write || o.append || o.truncate;
8012
- const access = write ? o.read ? O_RDWR6 : O_WRONLY5 : 0;
8065
+ const access = write ? o.read ? O_RDWR6 : O_WRONLY6 : 0;
8013
8066
  return access | (o.append ? O_APPEND3 : 0);
8014
8067
  }
8015
8068
  function createContext(o) {
@@ -8281,7 +8334,7 @@ function pathOps(kernel, resolve, statOf, open) {
8281
8334
  }
8282
8335
  };
8283
8336
  }
8284
- var JsExit, CHUNK, MAX_IO, O_WRONLY5, O_RDWR6, O_APPEND3, encoder2;
8337
+ var JsExit, CHUNK, MAX_IO, O_WRONLY6, O_RDWR6, O_APPEND3, encoder2;
8285
8338
  var init_js_context = __esm({
8286
8339
  "src/process/js/js-context.ts"() {
8287
8340
  "use strict";
@@ -8298,7 +8351,7 @@ var init_js_context = __esm({
8298
8351
  };
8299
8352
  CHUNK = 64 * 1024;
8300
8353
  MAX_IO = 1024 * 1024;
8301
- O_WRONLY5 = 1;
8354
+ O_WRONLY6 = 1;
8302
8355
  O_RDWR6 = 2;
8303
8356
  O_APPEND3 = 1024;
8304
8357
  encoder2 = new TextEncoder();