@ai-ecoverse/slicc-kernel 1.99.1 → 1.100.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.
package/dist/node.js CHANGED
@@ -8284,12 +8284,18 @@ var DriverConnection = class _DriverConnection {
8284
8284
  timeoutMs;
8285
8285
  nextId = 0;
8286
8286
  onFail;
8287
- constructor(port, capabilities, waiting, timeoutMs, onFail) {
8287
+ idle;
8288
+ constructor(port, capabilities, waiting, timeoutMs, options) {
8288
8289
  this.port = port;
8289
8290
  this.capabilities = capabilities;
8290
8291
  this.waiting = waiting;
8291
8292
  this.timeoutMs = timeoutMs;
8292
- this.onFail = onFail;
8293
+ this.onFail = options.onFail;
8294
+ this.idle = options.idle === true;
8295
+ if (this.idle) port.unref?.();
8296
+ }
8297
+ settled() {
8298
+ if (this.idle && this.waiting.size === 0) this.port.unref?.();
8293
8299
  }
8294
8300
  static async open(port, mount, options = {}) {
8295
8301
  const timeoutMs = options.timeoutMs ?? DRIVER_TIMEOUT_MS;
@@ -8305,6 +8311,7 @@ var DriverConnection = class _DriverConnection {
8305
8311
  clearTimeout(call.timer);
8306
8312
  if (data.errno) call.reject(errnoError(data.errno, data.message ?? data.errno));
8307
8313
  else call.resolve(data.result);
8314
+ if (options.idle && waiting.size === 0) port.unref?.();
8308
8315
  });
8309
8316
  port.start?.();
8310
8317
  port.postMessage({ hello: { protocol: DRIVER_PROTOCOL, mount } });
@@ -8323,7 +8330,7 @@ var DriverConnection = class _DriverConnection {
8323
8330
  const refused2 = driverVersionError(hello.protocol);
8324
8331
  if (refused2) throw errnoError("EPROTO", refused2);
8325
8332
  if (hello.error) throw errnoError(hello.errno ?? "EIO", hello.error);
8326
- return new _DriverConnection(port, hello.capabilities ?? {}, waiting, timeoutMs, options.onFail);
8333
+ return new _DriverConnection(port, hello.capabilities ?? {}, waiting, timeoutMs, options);
8327
8334
  }
8328
8335
  call(call, transfer = []) {
8329
8336
  if (this.failure) return Promise.reject(this.failure);
@@ -8332,6 +8339,7 @@ var DriverConnection = class _DriverConnection {
8332
8339
  const timer = unref(
8333
8340
  setTimeout(() => {
8334
8341
  this.waiting.delete(id2);
8342
+ this.settled();
8335
8343
  const error = errnoError(
8336
8344
  "EIO",
8337
8345
  `the driver did not answer ${call.op} within ${this.timeoutMs} ms`
@@ -8341,6 +8349,7 @@ var DriverConnection = class _DriverConnection {
8341
8349
  this.onFail?.(error);
8342
8350
  }, this.timeoutMs)
8343
8351
  );
8352
+ if (this.idle && this.waiting.size === 0) this.port.ref?.();
8344
8353
  this.waiting.set(id2, { resolve: resolve2, reject, timer });
8345
8354
  this.port.postMessage({ ...call, id: id2 }, transfer);
8346
8355
  });
@@ -8353,6 +8362,7 @@ var DriverConnection = class _DriverConnection {
8353
8362
  call.reject(error);
8354
8363
  }
8355
8364
  this.waiting.clear();
8365
+ this.settled();
8356
8366
  }
8357
8367
  close() {
8358
8368
  this.fail(errnoError("EIO", "the file system is unmounted"));
@@ -8707,6 +8717,7 @@ var MountTable = class {
8707
8717
  { source: spec.source, options },
8708
8718
  {
8709
8719
  ...this.deps.timeoutMs ? { timeoutMs: this.deps.timeoutMs } : {},
8720
+ ...opened2.idle ? { idle: true } : {},
8710
8721
  onInvalidate: (paths) => this.invalidated(target, paths),
8711
8722
  onFail: (error) => {
8712
8723
  if (mounted) this.crashed(mounted, error);
@@ -11089,7 +11100,7 @@ var PATH_OPS = new Set(SYNC_FS_OPS);
11089
11100
  var EARLY_WHOLE_FILE = 64 * 1024;
11090
11101
 
11091
11102
  // src/version.ts
11092
- var KERNEL_VERSION = true ? "1.99.1" : "0.0.0-dev";
11103
+ var KERNEL_VERSION = true ? "1.100.0" : "0.0.0-dev";
11093
11104
  var OS_RELEASE = "6.0.0-slicc";
11094
11105
  function procVersion() {
11095
11106
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -12129,7 +12140,7 @@ async function recordLock2(req, ctx) {
12129
12140
  return done2;
12130
12141
  }
12131
12142
  const range = lockRange(req.start, req.len);
12132
- const key = await fileKey(target, req.kind);
12143
+ const key = await fileKey(target, req.kind, req.op === "lk-set" && req.fd !== void 0);
12133
12144
  if (req.op === "lk-get") {
12134
12145
  const held = locks.holder(key, owner, { key, kind: req.kind, ...range });
12135
12146
  if (!held) return json3(null);
@@ -15613,7 +15624,7 @@ var WasmProcess = class {
15613
15624
  return await hostSyscall(req, {
15614
15625
  pid: this.pid,
15615
15626
  owner: () => this.lockOwner(),
15616
- fileKey: (target, kind) => this.lockKey(target, kind),
15627
+ fileKey: (target, kind, setting) => this.lockKey(target, kind, setting),
15617
15628
  locks: this.options.locks,
15618
15629
  ops: this.asyncOps,
15619
15630
  blocking: () => this.blockingSignal(cancelled),
@@ -15665,8 +15676,11 @@ var WasmProcess = class {
15665
15676
  }
15666
15677
  return path;
15667
15678
  }
15668
- async lockKey(target, kind) {
15679
+ async lockKey(target, kind, setting = false) {
15669
15680
  const file = target.fd === void 0 ? void 0 : this.fds.get(target.fd);
15681
+ const access2 = file?.file;
15682
+ if (setting && (kind === "read" && !access2?.read || kind === "write" && !access2?.write))
15683
+ throw new KernelError("EBADF");
15670
15684
  const known = file ? fileKeys.get(file) : this.pathKeys.get(target.path ?? "");
15671
15685
  if (kind === "close" && !file && target.path !== void 0) this.pathKeys.delete(target.path);
15672
15686
  const want = kind === "read" ? R_OK : kind === "write" ? W_OK : 0;
@@ -20318,9 +20332,6 @@ var NOT_EXECUTABLE = 126;
20318
20332
  var DECIDE_MS = 100;
20319
20333
  var INIT_PID = 1;
20320
20334
  var SHARED_DIRS = ["/tmp", "/home"];
20321
- function unref2(port) {
20322
- port.unref?.();
20323
- }
20324
20335
  var LAYOUT = [
20325
20336
  ["/", 493],
20326
20337
  ["/root", 448],
@@ -20531,7 +20542,6 @@ var Launcher = class {
20531
20542
  pnpmMade;
20532
20543
  pnpmEpoch = 0;
20533
20544
  mounts;
20534
- shmPorts = [];
20535
20545
  createDriverWorker;
20536
20546
  media;
20537
20547
  onMountPending;
@@ -21796,9 +21806,10 @@ var Launcher = class {
21796
21806
  },
21797
21807
  { owned: true }
21798
21808
  );
21799
- if (spec.target === SHM) this.shmPorts = [port1, port2];
21809
+ if (spec.target === SHM) port2.unref?.();
21800
21810
  return {
21801
21811
  port: port1,
21812
+ ...spec.target === SHM ? { idle: true } : {},
21802
21813
  dispose: () => {
21803
21814
  port1.close();
21804
21815
  port2.close();
@@ -21902,7 +21913,6 @@ var Launcher = class {
21902
21913
  async mountShm() {
21903
21914
  await this.base.mkdir(SHM, { recursive: true });
21904
21915
  await this.mounts.mountSystem({ type: "tmpfs", source: "shm", target: SHM }, this.fs);
21905
- for (const port of this.shmPorts) unref2(port);
21906
21916
  await this.fs.chmod(SHM, 1023);
21907
21917
  }
21908
21918
  async ownTmp() {