@ai-ecoverse/slicc-kernel 1.29.2 → 1.30.1

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.
@@ -4156,18 +4156,20 @@ function kernelEntry2() {
4156
4156
  function deviceEntry(meta) {
4157
4157
  return { type: "device", device: meta.device, ...meta.access ? { access: meta.access } : {} };
4158
4158
  }
4159
+ function preopenOf(e) {
4160
+ return {
4161
+ ...e.preopen ? { preopen: e.preopen } : {},
4162
+ ...e.twin !== void 0 ? { twin: e.twin } : {}
4163
+ };
4164
+ }
4159
4165
  function metaOf(e) {
4160
- if (e.type === "dir") return { dir: e.path, ...e.preopen ? { preopen: e.preopen } : {} };
4166
+ if (e.type === "dir") return { dir: e.path, ...preopenOf(e) };
4161
4167
  if (e.type === "device") return { device: e.device, ...e.access ? { access: e.access } : {} };
4162
4168
  return void 0;
4163
4169
  }
4164
4170
  function entryOf(info) {
4165
4171
  if (info.meta && "dir" in info.meta) {
4166
- return {
4167
- type: "dir",
4168
- path: info.meta.dir,
4169
- ...info.meta.preopen ? { preopen: info.meta.preopen } : {}
4170
- };
4172
+ return { type: "dir", path: info.meta.dir, ...preopenOf(info.meta) };
4171
4173
  }
4172
4174
  if (info.meta && "device" in info.meta) return deviceEntry(info.meta);
4173
4175
  if (info.kind === "held") return void 0;
@@ -4227,9 +4229,9 @@ var init_wasi_fds = __esm({
4227
4229
  this.kernel = kernel;
4228
4230
  this.fs = fs;
4229
4231
  }
4230
- setup(cwd, inherited) {
4232
+ setup(cwd, inherited, root = false) {
4231
4233
  for (const fd of [0, 1, 2]) this.table.set(fd, kernelEntry2());
4232
- const preopens = this.preopens(cwd);
4234
+ const preopens = this.preopens(cwd, root);
4233
4235
  const top = 3 + preopens.length;
4234
4236
  for (const { fd, kind, flags, device } of inherited) {
4235
4237
  let at = fd;
@@ -4249,8 +4251,10 @@ var init_wasi_fds = __esm({
4249
4251
  this.table.set(3 + i, entry);
4250
4252
  });
4251
4253
  }
4252
- preopens(cwd) {
4253
- const out = [{ type: "dir", path: normalize(cwd), preopen: "." }];
4254
+ preopens(cwd, root) {
4255
+ const here = normalize(cwd);
4256
+ const dot = { type: "dir", path: here, preopen: "." };
4257
+ const out = [dot];
4254
4258
  let names = [];
4255
4259
  try {
4256
4260
  names = this.fs.readdir("/");
@@ -4268,6 +4272,13 @@ var init_wasi_fds = __esm({
4268
4272
  } catch {
4269
4273
  }
4270
4274
  }
4275
+ if (root) {
4276
+ out.push(
4277
+ { type: "dir", path: "/", preopen: "/" },
4278
+ { type: "dir", path: here, preopen: "./" }
4279
+ );
4280
+ dot.twin = 3 + out.length - 1;
4281
+ }
4271
4282
  return out;
4272
4283
  }
4273
4284
  find(fd) {
@@ -4419,8 +4430,13 @@ var init_wasi_fds = __esm({
4419
4430
  chdir(path) {
4420
4431
  const dot = this.find(3);
4421
4432
  if (dot?.type !== "dir" || dot.preopen !== ".") return;
4422
- dot.path = path;
4423
- this.kernel.call({ op: "fd-meta", fd: 3, meta: { dir: path, preopen: "." } });
4433
+ const moved = [[3, dot]];
4434
+ const twin = dot.twin === void 0 ? void 0 : this.find(dot.twin);
4435
+ if (twin?.type === "dir" && twin.preopen === "./") moved.push([dot.twin, twin]);
4436
+ for (const [fd, e] of moved) {
4437
+ e.path = path;
4438
+ this.kernel.call({ op: "fd-meta", fd, meta: metaOf(e) });
4439
+ }
4424
4440
  this.bump();
4425
4441
  }
4426
4442
  promoteFiles() {
@@ -4448,8 +4464,7 @@ var init_wasi_fds = __esm({
4448
4464
  for (const [fd, e] of this.table) {
4449
4465
  if (e.type === "kernel")
4450
4466
  out.push({ fd, type: "kernel", nonblock: e.nonblock, append: e.append });
4451
- else if (e.type === "dir")
4452
- out.push({ fd, type: "dir", path: e.path, ...e.preopen ? { preopen: e.preopen } : {} });
4467
+ else if (e.type === "dir") out.push({ fd, type: "dir", path: e.path, ...preopenOf(e) });
4453
4468
  else if (e.type === "device") out.push({ fd, ...deviceEntry(e) });
4454
4469
  }
4455
4470
  return out;
@@ -4460,11 +4475,7 @@ var init_wasi_fds = __esm({
4460
4475
  if (f.type === "kernel")
4461
4476
  this.table.set(f.fd, { type: "kernel", nonblock: f.nonblock, append: f.append });
4462
4477
  else if (f.type === "dir")
4463
- this.table.set(f.fd, {
4464
- type: "dir",
4465
- path: f.path,
4466
- ...f.preopen ? { preopen: f.preopen } : {}
4467
- });
4478
+ this.table.set(f.fd, { type: "dir", path: f.path, ...preopenOf(f) });
4468
4479
  else this.table.set(f.fd, deviceEntry(f));
4469
4480
  }
4470
4481
  for (const fd of cloexec) this.cloexec.add(fd);
@@ -4926,7 +4937,7 @@ var init_wasi_host = __esm({
4926
4937
  this.fds = new WasiFds(o.kernel, o.fs);
4927
4938
  if (o.shared) this.fds.share(o.shared, true);
4928
4939
  else if (o.forked) this.fds.restore(o.forked.fds, o.forked.cloexec);
4929
- else this.fds.setup(o.cwd, o.inherited ?? []);
4940
+ else this.fds.setup(o.cwd, o.inherited ?? [], o.preopenRoot === true);
4930
4941
  this.listening = o.shared ? [] : this.fds.sockets();
4931
4942
  }
4932
4943
  get cwd() {
@@ -7343,6 +7354,11 @@ function merge(base, extra) {
7343
7354
  for (const [ns, values] of Object.entries(extra)) out[ns] = { ...base[ns], ...values };
7344
7355
  return out;
7345
7356
  }
7357
+ function descriptors(init, fork, threads) {
7358
+ if (fork?.shared && threads) return { shared: threads.ids };
7359
+ if (fork) return { forked: { fds: fork.fds, cloexec: fork.cloexec } };
7360
+ return { inherited: init.fds ?? [], ...init.program.preopenRoot ? { preopenRoot: true } : {} };
7361
+ }
7346
7362
  async function runWasiProcess(init, port2) {
7347
7363
  captureBacktraces(init.env);
7348
7364
  const signals = new WasiSignals((sig) => {
@@ -7377,7 +7393,7 @@ async function runWasiProcess(init, port2) {
7377
7393
  parent: () => identify(transport, init).ppid,
7378
7394
  kernel: { sys: traced(stats, "kernel", sys), call: call2 },
7379
7395
  fs: cachingBridge(traced(stats, "fs", createSyncFsSabBridge(transport))),
7380
- ...fork?.shared && threads ? { shared: threads.ids } : fork ? { forked: { fds: fork.fds, cloexec: fork.cloexec } } : { inherited: init.fds }
7396
+ ...descriptors(init, fork, threads)
7381
7397
  });
7382
7398
  if (threads) {
7383
7399
  threads.beforeSpawn = () => {