@ai-ecoverse/slicc-kernel 1.34.0 → 1.35.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
@@ -339,14 +339,6 @@ function sinkFile(onData) {
339
339
  }
340
340
  });
341
341
  }
342
- function nullFile() {
343
- return new OpenFile({
344
- read: async () => new Uint8Array(0),
345
- write: async (bytes) => bytes.length,
346
- close: () => {
347
- }
348
- });
349
- }
350
342
  function written(device, bytes) {
351
343
  if (device === "full" && bytes.length > 0) throw new KernelError("ENOSPC");
352
344
  return bytes.length;
@@ -3519,7 +3511,7 @@ var ChildTable = class {
3519
3511
  captured.set(n, chunks2);
3520
3512
  return sinkFile((bytes) => chunks2.push(bytes));
3521
3513
  }
3522
- return nullFile();
3514
+ return deviceFile("null");
3523
3515
  }
3524
3516
  async wait(pid, nohang, signal, flags = {}) {
3525
3517
  let interrupt;
@@ -7583,10 +7575,12 @@ var SYSCALL_OPS = /* @__PURE__ */ new Set([
7583
7575
  "fd-cloexec",
7584
7576
  "fd-list",
7585
7577
  "proc-alarm",
7578
+ "proc-umask",
7586
7579
  "dl-log",
7587
7580
  "fd-renumber",
7588
7581
  "fd-promote",
7589
7582
  "fd-open-tty",
7583
+ "fd-tty-names",
7590
7584
  "tty-get",
7591
7585
  "tty-set",
7592
7586
  "tty-winsz",
@@ -7620,6 +7614,7 @@ function isWasmSyscall(req) {
7620
7614
  return typeof op === "string" && SYSCALL_OPS.has(op);
7621
7615
  }
7622
7616
  var MAX_READ = 1024 * 1024;
7617
+ var DEFAULT_UMASK = 18;
7623
7618
  var DYING = { ok: false, errno: "EINTR", message: "the process is being killed" };
7624
7619
  var HOSTS_ONLY = new Resolver({ routes: new Routes() });
7625
7620
  var WasmProcess = class {
@@ -7630,6 +7625,7 @@ var WasmProcess = class {
7630
7625
  inherited = 0;
7631
7626
  interrupt = new AbortController();
7632
7627
  dying = false;
7628
+ umask = DEFAULT_UMASK;
7633
7629
  execChild;
7634
7630
  execTermsig;
7635
7631
  stopped = 0;
@@ -7647,6 +7643,7 @@ var WasmProcess = class {
7647
7643
  this.fds = fds;
7648
7644
  this.options = options;
7649
7645
  this.inherited = options.ignored ?? 0;
7646
+ this.umask = options.umask ?? DEFAULT_UMASK;
7650
7647
  this.children = new ChildTable(fds, options.spawner, options.forker);
7651
7648
  this.nodes = options.nodes ?? new VfsNodes(options.fs);
7652
7649
  if (!options.nodes) options.openFiles?.add(this.nodes);
@@ -7719,6 +7716,11 @@ var WasmProcess = class {
7719
7716
  return result;
7720
7717
  }
7721
7718
  }
7719
+ setUmask(mask) {
7720
+ const old = this.umask;
7721
+ if (mask !== void 0) this.umask = mask & 511;
7722
+ return old;
7723
+ }
7722
7724
  die() {
7723
7725
  if (this.dying) return;
7724
7726
  this.dying = true;
@@ -7883,6 +7885,8 @@ var WasmProcess = class {
7883
7885
  if (!tty) throw new KernelError("ENXIO");
7884
7886
  return { ok: true, kind: "json", json: this.fds.install(tty.file(), 3) };
7885
7887
  }
7888
+ case "fd-tty-names":
7889
+ return { ok: true, kind: "json", json: this.options.jobs?.terminalNames() ?? [] };
7886
7890
  case "fd-select": {
7887
7891
  const { read, write, timeoutMs } = req;
7888
7892
  const signal = this.blockingSignal();
@@ -8114,6 +8118,8 @@ var WasmProcess = class {
8114
8118
  case "proc-alarm":
8115
8119
  this.setAlarm(req.sig, req.firstMs ?? req.ms, req.repeat ? req.ms : 0, req.timer);
8116
8120
  return { ok: true, kind: "void" };
8121
+ case "proc-umask":
8122
+ return { ok: true, kind: "json", json: this.setUmask(req.mask) };
8117
8123
  case "dl-log":
8118
8124
  if (req.append) this.dlLog.push(req.append);
8119
8125
  return { ok: true, kind: "json", json: this.dlLog.slice(req.from) };
@@ -8263,7 +8269,7 @@ var Dying = class {
8263
8269
  return [typeof reported === "number" ? reported : CRASHED, void 0];
8264
8270
  }
8265
8271
  };
8266
- function processInit(opts, sab) {
8272
+ function processInit(opts, sab, umask) {
8267
8273
  const base = {
8268
8274
  type: WASM_PROCESS_INIT,
8269
8275
  pid: opts.shownPid ?? opts.pid,
@@ -8272,6 +8278,7 @@ function processInit(opts, sab) {
8272
8278
  env: opts.env,
8273
8279
  cwd: opts.cwd,
8274
8280
  sab,
8281
+ umask,
8275
8282
  ...opts.ppid !== void 0 ? { ppid: opts.ppid } : {}
8276
8283
  };
8277
8284
  if (opts.program.abi === "js") {
@@ -8283,11 +8290,17 @@ function processInit(opts, sab) {
8283
8290
  ...opts.fork ? { fork: opts.fork } : { fds: inheritedFds(opts.fds) }
8284
8291
  };
8285
8292
  }
8293
+ function inherited(opts) {
8294
+ return {
8295
+ ...opts.ignored ? { ignored: opts.ignored } : {},
8296
+ ...opts.umask !== void 0 ? { umask: opts.umask } : {}
8297
+ };
8298
+ }
8286
8299
  function spawnWasmProcess(opts) {
8287
8300
  const sab = new SharedArrayBuffer(SAB_HEADER_BYTES + SAB_DEFAULT_WINDOW_BYTES);
8288
8301
  const header3 = new Int32Array(sab, 0, SAB_HEADER_I32);
8289
8302
  const process = new WasmProcess(opts.pid, opts.fds, {
8290
- ...opts.ignored ? { ignored: opts.ignored } : {},
8303
+ ...inherited(opts),
8291
8304
  ...opts.identity ? { identity: opts.identity } : {},
8292
8305
  ...opts.onSyscall ? { onSyscall: opts.onSyscall } : {},
8293
8306
  spawner: opts.spawner,
@@ -8421,7 +8434,7 @@ function spawnWasmProcess(opts) {
8421
8434
  };
8422
8435
  tw.postMessage(tinit);
8423
8436
  };
8424
- const init = processInit(opts, sab);
8437
+ const init = processInit(opts, sab, process.umask);
8425
8438
  worker.postMessage(init, opts.fork ? [opts.fork.memory.buffer] : []);
8426
8439
  const signal = (sig) => {
8427
8440
  if (process.signal(sig) !== "terminate") return;
@@ -8439,6 +8452,7 @@ function spawnWasmProcess(opts) {
8439
8452
  onState: (listener) => process.onState(listener),
8440
8453
  memory: () => Atomics.load(header3, SAB_I_MEMORY) * 65536,
8441
8454
  ignoredSignals: (fork) => process.inheritable(fork),
8455
+ umask: () => process.umask,
8442
8456
  writesBack: () => opts.program.abi === "wasi" && !done4
8443
8457
  };
8444
8458
  }
@@ -8544,8 +8558,13 @@ var JobTable = class {
8544
8558
  return id;
8545
8559
  }
8546
8560
  terminalNamed(name2) {
8547
- const known = /* @__PURE__ */ new Set([...this.terminals.values(), ...this.foreground.keys()]);
8548
- return [...known].find((tty) => tty.name === name2);
8561
+ return this.knownTerminals().find((tty) => tty.name === name2);
8562
+ }
8563
+ terminalNames() {
8564
+ return this.knownTerminals().flatMap((tty) => tty.name ? [tty.name] : []);
8565
+ }
8566
+ knownTerminals() {
8567
+ return [.../* @__PURE__ */ new Set([...this.terminals.values(), ...this.foreground.keys()])];
8549
8568
  }
8550
8569
  controllingTerminal(pid) {
8551
8570
  const member = this.members.get(pid);
@@ -10188,6 +10207,7 @@ var Launcher = class {
10188
10207
  this.settling.syscall(pid, call.op);
10189
10208
  },
10190
10209
  ...req.ignored ? { ignored: req.ignored } : {},
10210
+ ...req.umask !== void 0 ? { umask: req.umask } : {},
10191
10211
  program: req.program,
10192
10212
  argv0: req.argv0,
10193
10213
  args: req.args,
@@ -10279,7 +10299,8 @@ var Launcher = class {
10279
10299
  ...described,
10280
10300
  started: (this.described.get(root.pid) ?? described).started,
10281
10301
  state: this.processes.has(member.pid) ? "S" : "Z",
10282
- memory: this.processes.get(member.pid)?.memory() ?? 0
10302
+ memory: this.processes.get(member.pid)?.memory() ?? 0,
10303
+ umask: this.umaskOf(member.pid)
10283
10304
  });
10284
10305
  }
10285
10306
  return listed;
@@ -10301,6 +10322,7 @@ var Launcher = class {
10301
10322
  report,
10302
10323
  ppid,
10303
10324
  ignored: this.ignoredBy(ppid),
10325
+ umask: this.umaskOf(ppid),
10304
10326
  ...exec
10305
10327
  });
10306
10328
  deciding?.attach();
@@ -10345,7 +10367,8 @@ var Launcher = class {
10345
10367
  fds,
10346
10368
  ppid,
10347
10369
  fork: state,
10348
- ignored: this.ignoredBy(ppid, true)
10370
+ ignored: this.ignoredBy(ppid, true),
10371
+ umask: this.umaskOf(ppid)
10349
10372
  })
10350
10373
  );
10351
10374
  }
@@ -10354,6 +10377,9 @@ var Launcher = class {
10354
10377
  const foreground = () => this.jobs.tcgetpgrp(tty, fallback);
10355
10378
  this.settling.deliver(sig, pgid, send, tty.reading ? void 0 : foreground);
10356
10379
  }
10380
+ umaskOf(pid) {
10381
+ return this.processes.get(pid)?.umask?.() ?? DEFAULT_UMASK;
10382
+ }
10357
10383
  ignoredBy(pid, fork = false) {
10358
10384
  return this.processes.get(pid)?.ignoredSignals(fork) ?? 0;
10359
10385
  }
@@ -10600,7 +10626,7 @@ var Launcher = class {
10600
10626
  return { status: NOT_FOUND, stdout: concat5(out), stderr: concat5(err) };
10601
10627
  }
10602
10628
  const fds = new FdTable();
10603
- fds.installAt(0, options.stdin ? bytesSource(options.stdin) : nullFile());
10629
+ fds.installAt(0, options.stdin ? bytesSource(options.stdin) : deviceFile("null"));
10604
10630
  fds.installAt(1, sinkFile(stdout));
10605
10631
  fds.installAt(2, sinkFile(stderr));
10606
10632
  const group = options.pgid !== void 0 ? { pgid: options.pgid } : {};
@@ -11539,10 +11565,11 @@ function hostfsFetchOf(options) {
11539
11565
  if (hostfsOrigin === void 0) return hostfsFetch ? { hostfsFetch } : {};
11540
11566
  const base = hostfsFetch ?? ((url, init) => fetch(url, init));
11541
11567
  return {
11542
- hostfsFetch: (url, init) => base(url, {
11543
- ...init,
11544
- headers: { ...init.headers, Origin: hostfsOrigin }
11545
- })
11568
+ hostfsFetch: (url, init) => {
11569
+ const headers = new Headers(init.headers);
11570
+ headers.set("Origin", hostfsOrigin);
11571
+ return base(url, { ...init, headers });
11572
+ }
11546
11573
  };
11547
11574
  }
11548
11575
  function nodeTransport() {