@ai-ecoverse/slicc-kernel 1.76.0 → 1.77.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.
@@ -195,6 +195,8 @@ function slots(sab) {
195
195
  function useLocalClock(sab) {
196
196
  local = sab && sab.byteLength >= LOCAL + SAB_CLOCK_I64 * 8 ? slots(sab) : void 0;
197
197
  if (!local) return;
198
+ localSab = sab;
199
+ localStart = epochMicros();
198
200
  const wait2 = (typed, index3, value2, timeout) => localWait(() => rawWait(typed, index3, value2, timeout));
199
201
  Atomics.wait = wait2;
200
202
  }
@@ -211,13 +213,26 @@ function localWait(wait2) {
211
213
  Atomics.store(clock, IDLE, idle + (end > start2 ? end - start2 : 0n));
212
214
  }
213
215
  }
214
- var LOCAL, IDLE, local, rawWait;
216
+ function localCpuNanos() {
217
+ if (!local || !localSab) return void 0;
218
+ const now = epochMicros();
219
+ const blocked = Number(Atomics.load(local, BLOCKED)) + localIdle(localSab, now).idle;
220
+ return BigInt(Math.max(0, now - localStart - blocked)) * 1000n;
221
+ }
222
+ function localIdle(sab, now) {
223
+ const state = Number(Atomics.load(slots(sab), IDLE));
224
+ if (state >= 0) return { idle: state, waiting: false };
225
+ return { idle: Math.max(0, now + state), waiting: true };
226
+ }
227
+ var LOCAL, BLOCKED, IDLE, local, localSab, localStart, rawWait;
215
228
  var init_cpu_clock = __esm({
216
229
  "src/kernel/cpu-clock.ts"() {
217
230
  "use strict";
218
231
  init_sync_sab_wire();
219
232
  LOCAL = SAB_CLOCK_OFFSET;
233
+ BLOCKED = 0;
220
234
  IDLE = 1;
235
+ localStart = 0;
221
236
  rawWait = Atomics.wait.bind(Atomics);
222
237
  }
223
238
  });
@@ -3250,7 +3265,10 @@ var init_process_fds = __esm({
3250
3265
  faccessat: "__syscall_faccessat",
3251
3266
  utimensat: "__syscall_utimensat",
3252
3267
  getppid: "slicc_getppid_js",
3253
- resizeHeap: "emscripten_resize_heap"
3268
+ resizeHeap: "emscripten_resize_heap",
3269
+ fdWrite: "fd_write",
3270
+ fdRead: "fd_read",
3271
+ sleepMs: "slicc_sleep_ms"
3254
3272
  };
3255
3273
  UTIME_NOW = 1073741823;
3256
3274
  UTIME_OMIT = 1073741822;
@@ -4109,8 +4127,8 @@ function pidStat(info, boot) {
4109
4127
  0,
4110
4128
  ticks(info.utime ?? 0),
4111
4129
  ticks(info.stime ?? 0),
4112
- 0,
4113
- 0,
4130
+ ticks(info.cutime ?? 0),
4131
+ ticks(info.cstime ?? 0),
4114
4132
  20,
4115
4133
  0,
4116
4134
  1,
@@ -4134,7 +4152,7 @@ function pidStat(info, boot) {
4134
4152
  `;
4135
4153
  }
4136
4154
  function pidStatus(info) {
4137
- const state = info.state === "Z" ? "Z (zombie)" : "S (sleeping)";
4155
+ const state = STATES[info.state];
4138
4156
  const c = info.cred ?? ROOT;
4139
4157
  const ids = (r, e, s) => `${r} ${e} ${s} ${e}`;
4140
4158
  return [
@@ -4410,7 +4428,7 @@ function useProcfs(Fs, sys, pid, memory = memorySource()) {
4410
4428
  readdir: (node) => pidNames(selfReaddir ? selfReaddir(node) : [".", ".."])
4411
4429
  };
4412
4430
  }
4413
- var HZ, DIR_MODE2, FILE_MODE, LINK_MODE2, ENOENT, EINVAL, UID, KIB, FALLBACK_MEMORY, PID_FILES, SYSTEM_FILES, sigMask;
4431
+ var HZ, DIR_MODE2, FILE_MODE, LINK_MODE2, ENOENT, EINVAL, UID, KIB, FALLBACK_MEMORY, PID_FILES, SYSTEM_FILES, sigMask, STATES;
4414
4432
  var init_procfs = __esm({
4415
4433
  "src/process/procfs.ts"() {
4416
4434
  "use strict";
@@ -4428,6 +4446,7 @@ var init_procfs = __esm({
4428
4446
  PID_FILES = ["cmdline", "comm", "stat", "statm", "status"];
4429
4447
  SYSTEM_FILES = ["loadavg", "meminfo", "stat", "uptime"];
4430
4448
  sigMask = (mask = 0) => (mask >>> 1).toString(16).padStart(16, "0");
4449
+ STATES = { S: "S (sleeping)", T: "T (stopped)", Z: "Z (zombie)" };
4431
4450
  }
4432
4451
  });
4433
4452
 
@@ -4673,6 +4692,19 @@ function reportGrowth(imports, publish, glue) {
4673
4692
  return grown;
4674
4693
  });
4675
4694
  }
4695
+ function holdWhileStopped(imports, header, glue) {
4696
+ const hold = () => {
4697
+ while (Atomics.load(header, SAB_I_STOP) === 1) Atomics.wait(header, SAB_I_STOP, 1);
4698
+ };
4699
+ for (const name2 of ["fdWrite", "fdRead", "sleepMs"]) {
4700
+ wrapImport(imports, name2, glue, (original) => (...args) => {
4701
+ hold();
4702
+ const done = original(...args);
4703
+ hold();
4704
+ return done;
4705
+ });
4706
+ }
4707
+ }
4676
4708
  function callerOwner(Fs, init) {
4677
4709
  return init.owners ? {} : { owner: ownByCaller(Fs, init.cred, credAbi(init.program.glue)) };
4678
4710
  }
@@ -4697,6 +4729,7 @@ function kernelWrappers(imports, module, deps) {
4697
4729
  positionalIo(imports, { glue, fs: fsOf, sys, memory });
4698
4730
  const grown = () => publishMemory(init.sab, memory()?.buffer.byteLength ?? 0);
4699
4731
  reportGrowth(imports, grown, kernelGlue);
4732
+ holdWhileStopped(imports, new Int32Array(init.sab, 0, SAB_HEADER_I32), kernelGlue);
4700
4733
  }
4701
4734
  async function runWasmProcess(init, port2, deps = {}) {
4702
4735
  const signals = new SignalGate(
@@ -4988,6 +5021,9 @@ var init_process_runtime = __esm({
4988
5021
  " utimensat: typeof ___syscall_utimensat === 'function' ? ___syscall_utimensat : undefined,",
4989
5022
  " getppid: typeof _slicc_getppid_js === 'function' ? _slicc_getppid_js : undefined,",
4990
5023
  " resizeHeap: typeof _emscripten_resize_heap === 'function' ? _emscripten_resize_heap : undefined,",
5024
+ " fdWrite: typeof _fd_write === 'function' ? _fd_write : undefined,",
5025
+ " fdRead: typeof _fd_read === 'function' ? _fd_read : undefined,",
5026
+ " sleepMs: typeof slicc_sleep_ms === 'function' ? slicc_sleep_ms : undefined,",
4991
5027
  "};",
4992
5028
  "Module.sliccFdImports ??= {",
4993
5029
  " fd_sync: typeof _fd_sync === 'function' ? _fd_sync : undefined,",
@@ -6729,6 +6765,7 @@ var init_wasi_host = __esm({
6729
6765
  "src/process/wasi/wasi-host.ts"() {
6730
6766
  "use strict";
6731
6767
  init_physical_path();
6768
+ init_cpu_clock();
6732
6769
  init_cred();
6733
6770
  init_wasi_abi();
6734
6771
  init_wasi_fds();
@@ -6992,7 +7029,7 @@ var init_wasi_host = __esm({
6992
7029
  if (id === CLOCK.MONOTONIC) {
6993
7030
  return MONOTONIC_BASE + BigInt(Math.round(performance.now() * 1e6));
6994
7031
  }
6995
- return BigInt(Math.round((performance.now() - this.started) * 1e6)) + 1n;
7032
+ return (localCpuNanos() ?? BigInt(Math.round((performance.now() - this.started) * 1e6))) + 1n;
6996
7033
  }
6997
7034
  environ() {
6998
7035
  const listen2 = this.listening.length > 0 ? { SLICC_LISTEN_FDS: this.listening.join(" ") } : {};