@ai-ecoverse/slicc-kernel 1.138.0 → 1.139.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.
@@ -25,11 +25,7 @@ function chain(target) {
25
25
  function hide(target, names) {
26
26
  for (const name2 of names) {
27
27
  const holders = chain(target);
28
- for (const holder of holders) {
29
- if (Object.getOwnPropertyDescriptor(holder, name2)?.configurable) {
30
- Reflect.deleteProperty(holder, name2);
31
- }
32
- }
28
+ for (const holder of holders) Reflect.deleteProperty(holder, name2);
33
29
  const kept = holders.slice(1).some((holder) => Object.hasOwn(holder, name2));
34
30
  const defined = Reflect.defineProperty(target, name2, {
35
31
  value: void 0,
@@ -45,11 +41,7 @@ function hide(target, names) {
45
41
  function vacate(target, names) {
46
42
  for (const name2 of names) {
47
43
  const holders = chain(target);
48
- for (const holder of holders) {
49
- if (Object.getOwnPropertyDescriptor(holder, name2)?.configurable) {
50
- Reflect.deleteProperty(holder, name2);
51
- }
52
- }
44
+ for (const holder of holders) Reflect.deleteProperty(holder, name2);
53
45
  const kept = holders.slice(1).some((holder) => Object.hasOwn(holder, name2));
54
46
  const opened2 = Reflect.defineProperty(target, name2, {
55
47
  value: void 0,
@@ -4059,12 +4051,16 @@ function readyEvents(subs, ready) {
4059
4051
  ...nbytesOf(s, ready)
4060
4052
  }));
4061
4053
  }
4062
- function selectOnce(deps, read2, write2, timeoutMs2) {
4054
+ function selectOnce(deps, read2, write2, timeoutMs2, mayResume) {
4063
4055
  try {
4064
4056
  const ready = deps.kernel.call({ op: "fd-select", read: read2, write: write2, timeoutMs: timeoutMs2 });
4065
4057
  return { ready, interrupted: false };
4066
4058
  } catch (e) {
4067
- if (!deps.interruptWakes || e.code !== "EINTR") throw e;
4059
+ if (e.code !== "EINTR") throw e;
4060
+ if (!deps.interruptWakes && mayResume && deps.resumes?.()) {
4061
+ return { ready: { read: [], write: [] }, interrupted: false, resumed: true };
4062
+ }
4063
+ if (!deps.interruptWakes) throw e;
4068
4064
  return { ready: { read: [], write: [] }, interrupted: true };
4069
4065
  }
4070
4066
  }
@@ -4074,8 +4070,15 @@ function waitEvents(deps, subs, { events, read: read2, write: write2 }, entered)
4074
4070
  if (events.length > 0 || entered) return 0;
4075
4071
  return earliest === Infinity ? -1 : Math.max(0, Math.ceil(earliest - performance.now()));
4076
4072
  };
4077
- for (; ; ) {
4078
- const { ready, interrupted } = selectOnce(deps, read2, write2, timeout());
4073
+ for (let resumes = 0; ; ) {
4074
+ const { ready, interrupted, resumed } = selectOnce(
4075
+ deps,
4076
+ read2,
4077
+ write2,
4078
+ timeout(),
4079
+ resumes++ < RESUMES
4080
+ );
4081
+ if (resumed) continue;
4079
4082
  events.push(...readyEvents(subs, ready));
4080
4083
  if (interrupted) return true;
4081
4084
  if (events.length > 0 || entered || earliest === Infinity) return false;
@@ -4102,10 +4105,12 @@ function pollOneoff(deps, inPtr, outPtr, nsubs, neventsPtr) {
4102
4105
  mem.view().setUint32(neventsPtr, events.length, true);
4103
4106
  return E.SUCCESS;
4104
4107
  }
4108
+ var RESUMES;
4105
4109
  var init_wasi_poll = __esm({
4106
4110
  "src/process/wasi/wasi-poll.ts"() {
4107
4111
  "use strict";
4108
4112
  init_wasi_abi();
4113
+ RESUMES = 64;
4109
4114
  }
4110
4115
  });
4111
4116
 
@@ -4139,10 +4144,10 @@ var init_wasi_sigmask = __esm({
4139
4144
  deliver;
4140
4145
  process;
4141
4146
  tid;
4142
- constructor(header, deliver, process, tid = 1) {
4147
+ constructor(header, deliver, process2, tid = 1) {
4143
4148
  this.header = header;
4144
4149
  this.deliver = deliver;
4145
- this.process = process;
4150
+ this.process = process2;
4146
4151
  this.tid = tid;
4147
4152
  this.lo = libcBits(Atomics.load(header, SAB_I_BLOCKED));
4148
4153
  this.hi = Atomics.load(header, SAB_I_BLOCKED_HI);
@@ -5348,7 +5353,8 @@ var init_wasi_host = __esm({
5348
5353
  }
5349
5354
  });
5350
5355
  }
5351
- poll(inPtr, outPtr, n, nevents) {
5356
+ poll(inPtr, outPtr, n, nevents, resume = true) {
5357
+ const ran = this.signals?.ran ?? 0;
5352
5358
  try {
5353
5359
  return pollOneoff(
5354
5360
  {
@@ -5357,7 +5363,8 @@ var init_wasi_host = __esm({
5357
5363
  kernel: this.o.kernel,
5358
5364
  now: (id) => this.now(id),
5359
5365
  interruptWakes: this.interruptWakes,
5360
- entered: this.entered
5366
+ entered: this.entered,
5367
+ ...resume ? { resumes: () => this.resumesPoll(ran) } : {}
5361
5368
  },
5362
5369
  inPtr,
5363
5370
  outPtr,
@@ -5368,13 +5375,17 @@ var init_wasi_host = __esm({
5368
5375
  this.o.fs.invalidate?.();
5369
5376
  }
5370
5377
  }
5378
+ resumesPoll(ran) {
5379
+ this.interrupted?.();
5380
+ return (this.signals?.ran ?? 0) === ran;
5381
+ }
5371
5382
  maskedPoll(mask, set, [inPtr, outPtr, n, nevents]) {
5372
5383
  const old = mask.swap(set[0], set[1]);
5373
5384
  try {
5374
5385
  this.mem.view().setUint32(nevents, 0, true);
5375
5386
  if (mask.deliverUnblocked()) return E.INTR;
5376
5387
  this.settleEntry(mask);
5377
- if (n > 0) return this.poll(inPtr, outPtr, n, nevents);
5388
+ if (n > 0) return this.poll(inPtr, outPtr, n, nevents, false);
5378
5389
  return this.entered ? E.INTR : this.suspend();
5379
5390
  } finally {
5380
5391
  mask.deliverUnblocked();
@@ -6699,7 +6710,7 @@ var KERNEL_VERSION, OS_RELEASE;
6699
6710
  var init_version = __esm({
6700
6711
  "src/version.ts"() {
6701
6712
  "use strict";
6702
- KERNEL_VERSION = true ? "1.138.0" : "0.0.0-dev";
6713
+ KERNEL_VERSION = true ? "1.139.0" : "0.0.0-dev";
6703
6714
  OS_RELEASE = "6.0.0-slicc";
6704
6715
  }
6705
6716
  });
@@ -7501,7 +7512,7 @@ var init_js_fetch = __esm({
7501
7512
  });
7502
7513
 
7503
7514
  // src/process/js/js-net.ts
7504
- function fromBase64(text) {
7515
+ function fromBase642(text) {
7505
7516
  const bin = atob(text);
7506
7517
  const out = new Uint8Array(bin.length);
7507
7518
  for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
@@ -7584,7 +7595,7 @@ function sessionOf(r) {
7584
7595
  authorized: r.authorized === true,
7585
7596
  ...r.authorizationError ? { authorizationError: r.authorizationError } : {},
7586
7597
  servername: r.servername,
7587
- peerCertificates: Object.freeze((r.peerCertificates ?? []).map(fromBase64)),
7598
+ peerCertificates: Object.freeze((r.peerCertificates ?? []).map(fromBase642)),
7588
7599
  ...controlsOf(r)
7589
7600
  });
7590
7601
  }
@@ -15157,6 +15168,15 @@ function heldOn(init, lane, syncKernel) {
15157
15168
  const ask = () => syncKernel.json({ op: "cwd-check" });
15158
15169
  return new HeldCwd(init.sab, init.slot, ask, init);
15159
15170
  }
15171
+ function measured(measure) {
15172
+ const got = measure?.() ?? {};
15173
+ const out = {};
15174
+ for (const field2 of MEMORY_FIELDS) {
15175
+ const value2 = got[field2];
15176
+ if (typeof value2 === "number" && Number.isFinite(value2)) out[field2] = value2;
15177
+ }
15178
+ return out;
15179
+ }
15160
15180
  function createContext(o) {
15161
15181
  const { kernel } = o;
15162
15182
  const infos = /* @__PURE__ */ new Map();
@@ -15297,6 +15317,7 @@ function createContext(o) {
15297
15317
  tty: terminal.tty,
15298
15318
  exit,
15299
15319
  thread: o.thread,
15320
+ memory: () => measured(o.memory),
15300
15321
  onUncaught: (listener) => listen(strays.exception, listener),
15301
15322
  onUnhandledRejection: (listener) => listen(strays.rejection, listener)
15302
15323
  };
@@ -15494,7 +15515,7 @@ function pathOps(kernel, resolve, statOf, open, tryDev) {
15494
15515
  }
15495
15516
  };
15496
15517
  }
15497
- var KERNEL_INFO, JsExit, encoder4, cryptoRandom;
15518
+ var KERNEL_INFO, JsExit, encoder4, cryptoRandom, MEMORY_FIELDS;
15498
15519
  var init_js_context = __esm({
15499
15520
  "src/process/js/js-context.ts"() {
15500
15521
  "use strict";
@@ -15529,6 +15550,7 @@ var init_js_context = __esm({
15529
15550
  };
15530
15551
  encoder4 = new TextEncoder();
15531
15552
  cryptoRandom = (bytes) => void crypto.getRandomValues(bytes);
15553
+ MEMORY_FIELDS = ["heapUsed", "heapTotal", "heapLimit", "external", "arrayBuffers"];
15532
15554
  }
15533
15555
  });
15534
15556
 
@@ -15702,6 +15724,7 @@ async function runJs(init, port3, deps, thread) {
15702
15724
  fs: { owners: init.owners === true, links: init.links === true },
15703
15725
  strays,
15704
15726
  thread: threadContext(port3, thread),
15727
+ memory: deps.memory,
15705
15728
  ...thread?.owned ? { owned: thread.owned } : {},
15706
15729
  held: init.held,
15707
15730
  failed: () => failedWith
@@ -16028,7 +16051,9 @@ var init_wasi_signals = __esm({
16028
16051
  this.deferred &= ~bit;
16029
16052
  this.raise(sig);
16030
16053
  }
16054
+ ran = 0;
16031
16055
  run(handler, sig) {
16056
+ this.ran++;
16032
16057
  const outer = { sig: this.delivering, defaulted: this.defaulted, libc: this.libcDefault };
16033
16058
  this.delivering = sig;
16034
16059
  this.defaulted = false;
@@ -17420,9 +17445,9 @@ var init_wasix_host = __esm({
17420
17445
  };
17421
17446
  }
17422
17447
  processImports() {
17423
- const { mem, process } = this;
17448
+ const { mem, process: process2 } = this;
17424
17449
  return {
17425
- proc_fork: (_copy, pidPtr) => process.fork(pidPtr),
17450
+ proc_fork: (_copy, pidPtr) => process2.fork(pidPtr),
17426
17451
  stack_checkpoint: (snapPtr, retPtr) => {
17427
17452
  const back = this.driver.rewound();
17428
17453
  if (back === void 0) return this.driver.checkpoint(snapPtr, retPtr);
@@ -17430,7 +17455,7 @@ var init_wasix_host = __esm({
17430
17455
  return E.SUCCESS;
17431
17456
  },
17432
17457
  stack_restore: (snapPtr, val) => void this.driver.restore(snapPtr, val),
17433
- proc_join: (pidPtr, flags, statusPtr) => void process.join(pidPtr, flags, statusPtr),
17458
+ proc_join: (pidPtr, flags, statusPtr) => void process2.join(pidPtr, flags, statusPtr),
17434
17459
  proc_signal: (pid, sig) => {
17435
17460
  const posix = sig === 0 ? 0 : wasixSignal(sig);
17436
17461
  if (posix === void 0) throw new WasiError("EINVAL");
@@ -17439,14 +17464,14 @@ var init_wasix_host = __esm({
17439
17464
  },
17440
17465
  proc_exec: (n, nl, a, al) => this.execOrExit(n, nl, a, al, 0, 0),
17441
17466
  proc_exec2: (n, nl, a, al, e, el) => this.execOrExit(n, nl, a, al, e, el),
17442
- proc_exec3: (n, nl, a, al, e, el, search, p, pl) => process.exec({
17467
+ proc_exec3: (n, nl, a, al, e, el, search, p, pl) => process2.exec({
17443
17468
  name: this.str(n, nl),
17444
17469
  argv: _WasixHost.lines(this.str(a, al)),
17445
17470
  env: _WasixHost.env(_WasixHost.lines(this.str(e, el))),
17446
17471
  search: search !== 0,
17447
17472
  path: this.str(p, pl)
17448
17473
  }),
17449
- proc_exec4: (n, nl, a, ac, e, ec, search, p, pl) => process.exec({
17474
+ proc_exec4: (n, nl, a, ac, e, ec, search, p, pl) => process2.exec({
17450
17475
  name: this.str(n, nl),
17451
17476
  argv: this.cStrings(a, ac),
17452
17477
  env: _WasixHost.env(e === 0 ? void 0 : this.cStrings(e, ec)),
@@ -17455,7 +17480,7 @@ var init_wasix_host = __esm({
17455
17480
  }),
17456
17481
  proc_spawn2: (...args) => {
17457
17482
  const [n, nl, a, al, e, el, ops, opc, , , search, p, pl, out] = args;
17458
- const pid = process.spawn({
17483
+ const pid = process2.spawn({
17459
17484
  name: this.str(n, nl),
17460
17485
  argv: _WasixHost.lines(this.str(a, al)),
17461
17486
  env: _WasixHost.env(_WasixHost.lines(this.str(e, el))),
@@ -17467,7 +17492,7 @@ var init_wasix_host = __esm({
17467
17492
  },
17468
17493
  proc_spawn3: (...args) => {
17469
17494
  const [n, nl, a, ac, e, ec, ops, opc, , , search, p, pl, out] = args;
17470
- const pid = process.spawn({
17495
+ const pid = process2.spawn({
17471
17496
  name: this.str(n, nl),
17472
17497
  argv: this.cStrings(a, ac),
17473
17498
  env: _WasixHost.env(e === 0 ? void 0 : this.cStrings(e, ec)),
@@ -17734,14 +17759,14 @@ function delivering(ns, table, host, driver, before) {
17734
17759
  }
17735
17760
  return out;
17736
17761
  }
17737
- function sigmaskOf(module, sab, gate, threads, process) {
17762
+ function sigmaskOf(module, sab, gate, threads, process2) {
17738
17763
  const header = new Int32Array(sab, 0, SAB_HEADER_I32);
17739
17764
  if (!importsSlicc(module, "sigmask_set")) {
17740
17765
  WasiSigmask.unsupported(header);
17741
17766
  return void 0;
17742
17767
  }
17743
17768
  if (threads) threads.blocked = () => loadBlocked(header);
17744
- const shared = process && new Int32Array(process, 0, SAB_HEADER_I32);
17769
+ const shared = process2 && new Int32Array(process2, 0, SAB_HEADER_I32);
17745
17770
  return new WasiSigmask(header, () => gate.deliver(), shared, threads?.tid ?? MAIN_TID);
17746
17771
  }
17747
17772
  function enosys(module, name2, foreign) {
@@ -18424,6 +18449,7 @@ import { parentPort } from "node:worker_threads";
18424
18449
  // src/node-lockdown.ts
18425
18450
  init_lockdown();
18426
18451
  import { isBuiltin, registerHooks } from "node:module";
18452
+ import { getHeapStatistics } from "node:v8";
18427
18453
  var NODE_GLOBALS = ["localStorage", "sessionStorage"];
18428
18454
  var NODE_SLOTS = [
18429
18455
  "require",
@@ -18450,6 +18476,10 @@ function refused(specifier) {
18450
18476
  code: "ERR_ACCESS_DENIED"
18451
18477
  });
18452
18478
  }
18479
+ var BASE64_MODULE = "data:text/javascript;base64,";
18480
+ var fromBase64 = Buffer.from.bind(Buffer);
18481
+ var toText = Function.prototype.call.bind(Buffer.prototype.toString);
18482
+ var PLAIN_BASE64 = /^[A-Za-z0-9+/]+={0,2}$/;
18453
18483
  function refuseModules() {
18454
18484
  registerHooks({
18455
18485
  resolve(specifier, context, next2) {
@@ -18457,11 +18487,30 @@ function refuseModules() {
18457
18487
  const resolved2 = next2(specifier, context);
18458
18488
  if (!resolved2.url.startsWith("data:")) throw refused(resolved2.url);
18459
18489
  return resolved2;
18490
+ },
18491
+ load(url, context, next2) {
18492
+ const payload = url.startsWith(BASE64_MODULE) ? url.slice(BASE64_MODULE.length) : "";
18493
+ if (payload.length % 4 !== 0 || !PLAIN_BASE64.test(payload)) return next2(url, context);
18494
+ const source = toText(fromBase64(payload, "base64"), "utf8");
18495
+ return { format: "module", source, shortCircuit: true };
18460
18496
  }
18461
18497
  });
18462
18498
  }
18463
18499
  var locked = /* @__PURE__ */ new WeakSet();
18464
18500
  var nodeProcess = typeof globalThis.process === "object" && globalThis.process !== null ? globalThis.process : void 0;
18501
+ var heapStatistics = getHeapStatistics;
18502
+ var memoryUsage = process.memoryUsage.bind(process);
18503
+ function nodeMemory() {
18504
+ const heap = heapStatistics();
18505
+ const usage = memoryUsage();
18506
+ return {
18507
+ heapUsed: heap.used_heap_size,
18508
+ heapTotal: heap.total_heap_size,
18509
+ heapLimit: heap.heap_size_limit,
18510
+ external: heap.external_memory,
18511
+ arrayBuffers: usage.arrayBuffers
18512
+ };
18513
+ }
18465
18514
  function nodeLockdown(scope2 = globalThis) {
18466
18515
  if (locked.has(scope2)) return;
18467
18516
  locked.add(scope2);
@@ -18579,8 +18628,16 @@ var onMessage = processEntry(
18579
18628
  },
18580
18629
  async () => wasi_runtime_exports,
18581
18630
  async () => ({
18582
- runJsProcess: (init, at) => runJsProcess(init, at, { lockdown: () => nodeLockdown(), scope: strayScope }),
18583
- runJsThread: (init, at) => runJsThread(init, at, { lockdown: () => nodeLockdown(), scope: strayScope })
18631
+ runJsProcess: (init, at) => runJsProcess(init, at, {
18632
+ lockdown: () => nodeLockdown(),
18633
+ scope: strayScope,
18634
+ memory: nodeMemory
18635
+ }),
18636
+ runJsThread: (init, at) => runJsThread(init, at, {
18637
+ lockdown: () => nodeLockdown(),
18638
+ scope: strayScope,
18639
+ memory: nodeMemory
18640
+ })
18584
18641
  }),
18585
18642
  () => nodeLockdown()
18586
18643
  );