@ai-ecoverse/slicc-kernel 1.54.4 → 1.54.5

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.
@@ -7426,6 +7426,12 @@ function read(view, at, type) {
7426
7426
  if (type === "f32") return view.getFloat32(at, true);
7427
7427
  return view.getFloat64(at, true);
7428
7428
  }
7429
+ function readSome(view, at, end, type) {
7430
+ if (at + SIZE2[type] <= end) return read(view, at, type);
7431
+ const some = new DataView(new ArrayBuffer(8));
7432
+ for (let i = 0; at + i < end; i++) some.setUint8(i, view.getUint8(at + i));
7433
+ return read(some, 0, type);
7434
+ }
7429
7435
  function write(view, at, type, value2) {
7430
7436
  if (type === "i32") view.setInt32(at, Number(value2), true);
7431
7437
  else if (type === "i64") view.setBigInt64(at, BigInt(value2), true);
@@ -7436,7 +7442,8 @@ function scalars(types) {
7436
7442
  if (types.includes("other")) throw new WasiError("EINVAL");
7437
7443
  return types;
7438
7444
  }
7439
- function callDynamic(ctx, id, values, valuesLen, results, resultsLen, strict) {
7445
+ function callDynamic(ctx, ...operands) {
7446
+ const [id, values, valuesLen, results, resultsLen, strict] = operands.map((n) => n >>> 0);
7440
7447
  const table = ctx.table();
7441
7448
  if (!table) throw new WasiError("ENOTSUP");
7442
7449
  const fn = id < table.length ? table.get(id) : null;
@@ -7444,33 +7451,31 @@ function callDynamic(ctx, id, values, valuesLen, results, resultsLen, strict) {
7444
7451
  if (!fn || !sig) throw new WasiError("EINVAL");
7445
7452
  const params = scalars(sig.params);
7446
7453
  const outs = scalars(sig.results);
7454
+ const size = (types) => types.reduce((n, type) => n + SIZE2[type], 0);
7455
+ if (strict && (size(params) !== valuesLen || size(outs) !== resultsLen)) {
7456
+ throw new WasiError("EINVAL");
7457
+ }
7447
7458
  const view = ctx.mem.view();
7459
+ if (values + valuesLen > view.byteLength || results + resultsLen > view.byteLength) {
7460
+ throw new WasiError("EFAULT");
7461
+ }
7448
7462
  const end = values + valuesLen;
7449
7463
  let at = values;
7450
7464
  const args = params.map((type) => {
7451
- if (at + SIZE2[type] > end) {
7452
- if (strict) throw new WasiError("EINVAL");
7453
- return type === "i64" ? 0n : 0;
7454
- }
7455
- const v = read(view, at, type);
7465
+ const v = readSome(view, at, end, type);
7456
7466
  at += SIZE2[type];
7457
7467
  return v;
7458
7468
  });
7459
- if (strict && at !== end) throw new WasiError("EINVAL");
7460
7469
  const returned = fn(...args);
7461
7470
  const got = outs.length === 1 ? [returned] : returned ?? [];
7462
7471
  const after = ctx.mem.view();
7463
7472
  const stop = results + resultsLen;
7464
7473
  let out = results;
7465
7474
  outs.forEach((type, i) => {
7466
- if (out + SIZE2[type] > stop) {
7467
- if (strict) throw new WasiError("EINVAL");
7468
- return;
7469
- }
7475
+ if (out + SIZE2[type] > stop) return;
7470
7476
  write(after, out, type, got[i]);
7471
7477
  out += SIZE2[type];
7472
7478
  });
7473
- if (strict && out !== stop) throw new WasiError("EINVAL");
7474
7479
  }
7475
7480
  var SIZE2;
7476
7481
  var init_wasix_ffi = __esm({