@ai-ecoverse/slicc-kernel 1.34.1 → 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
@@ -7575,10 +7575,12 @@ var SYSCALL_OPS = /* @__PURE__ */ new Set([
7575
7575
  "fd-cloexec",
7576
7576
  "fd-list",
7577
7577
  "proc-alarm",
7578
+ "proc-umask",
7578
7579
  "dl-log",
7579
7580
  "fd-renumber",
7580
7581
  "fd-promote",
7581
7582
  "fd-open-tty",
7583
+ "fd-tty-names",
7582
7584
  "tty-get",
7583
7585
  "tty-set",
7584
7586
  "tty-winsz",
@@ -7612,6 +7614,7 @@ function isWasmSyscall(req) {
7612
7614
  return typeof op === "string" && SYSCALL_OPS.has(op);
7613
7615
  }
7614
7616
  var MAX_READ = 1024 * 1024;
7617
+ var DEFAULT_UMASK = 18;
7615
7618
  var DYING = { ok: false, errno: "EINTR", message: "the process is being killed" };
7616
7619
  var HOSTS_ONLY = new Resolver({ routes: new Routes() });
7617
7620
  var WasmProcess = class {
@@ -7622,6 +7625,7 @@ var WasmProcess = class {
7622
7625
  inherited = 0;
7623
7626
  interrupt = new AbortController();
7624
7627
  dying = false;
7628
+ umask = DEFAULT_UMASK;
7625
7629
  execChild;
7626
7630
  execTermsig;
7627
7631
  stopped = 0;
@@ -7639,6 +7643,7 @@ var WasmProcess = class {
7639
7643
  this.fds = fds;
7640
7644
  this.options = options;
7641
7645
  this.inherited = options.ignored ?? 0;
7646
+ this.umask = options.umask ?? DEFAULT_UMASK;
7642
7647
  this.children = new ChildTable(fds, options.spawner, options.forker);
7643
7648
  this.nodes = options.nodes ?? new VfsNodes(options.fs);
7644
7649
  if (!options.nodes) options.openFiles?.add(this.nodes);
@@ -7711,6 +7716,11 @@ var WasmProcess = class {
7711
7716
  return result;
7712
7717
  }
7713
7718
  }
7719
+ setUmask(mask) {
7720
+ const old = this.umask;
7721
+ if (mask !== void 0) this.umask = mask & 511;
7722
+ return old;
7723
+ }
7714
7724
  die() {
7715
7725
  if (this.dying) return;
7716
7726
  this.dying = true;
@@ -7875,6 +7885,8 @@ var WasmProcess = class {
7875
7885
  if (!tty) throw new KernelError("ENXIO");
7876
7886
  return { ok: true, kind: "json", json: this.fds.install(tty.file(), 3) };
7877
7887
  }
7888
+ case "fd-tty-names":
7889
+ return { ok: true, kind: "json", json: this.options.jobs?.terminalNames() ?? [] };
7878
7890
  case "fd-select": {
7879
7891
  const { read, write, timeoutMs } = req;
7880
7892
  const signal = this.blockingSignal();
@@ -8106,6 +8118,8 @@ var WasmProcess = class {
8106
8118
  case "proc-alarm":
8107
8119
  this.setAlarm(req.sig, req.firstMs ?? req.ms, req.repeat ? req.ms : 0, req.timer);
8108
8120
  return { ok: true, kind: "void" };
8121
+ case "proc-umask":
8122
+ return { ok: true, kind: "json", json: this.setUmask(req.mask) };
8109
8123
  case "dl-log":
8110
8124
  if (req.append) this.dlLog.push(req.append);
8111
8125
  return { ok: true, kind: "json", json: this.dlLog.slice(req.from) };
@@ -8255,7 +8269,7 @@ var Dying = class {
8255
8269
  return [typeof reported === "number" ? reported : CRASHED, void 0];
8256
8270
  }
8257
8271
  };
8258
- function processInit(opts, sab) {
8272
+ function processInit(opts, sab, umask) {
8259
8273
  const base = {
8260
8274
  type: WASM_PROCESS_INIT,
8261
8275
  pid: opts.shownPid ?? opts.pid,
@@ -8264,6 +8278,7 @@ function processInit(opts, sab) {
8264
8278
  env: opts.env,
8265
8279
  cwd: opts.cwd,
8266
8280
  sab,
8281
+ umask,
8267
8282
  ...opts.ppid !== void 0 ? { ppid: opts.ppid } : {}
8268
8283
  };
8269
8284
  if (opts.program.abi === "js") {
@@ -8275,11 +8290,17 @@ function processInit(opts, sab) {
8275
8290
  ...opts.fork ? { fork: opts.fork } : { fds: inheritedFds(opts.fds) }
8276
8291
  };
8277
8292
  }
8293
+ function inherited(opts) {
8294
+ return {
8295
+ ...opts.ignored ? { ignored: opts.ignored } : {},
8296
+ ...opts.umask !== void 0 ? { umask: opts.umask } : {}
8297
+ };
8298
+ }
8278
8299
  function spawnWasmProcess(opts) {
8279
8300
  const sab = new SharedArrayBuffer(SAB_HEADER_BYTES + SAB_DEFAULT_WINDOW_BYTES);
8280
8301
  const header3 = new Int32Array(sab, 0, SAB_HEADER_I32);
8281
8302
  const process = new WasmProcess(opts.pid, opts.fds, {
8282
- ...opts.ignored ? { ignored: opts.ignored } : {},
8303
+ ...inherited(opts),
8283
8304
  ...opts.identity ? { identity: opts.identity } : {},
8284
8305
  ...opts.onSyscall ? { onSyscall: opts.onSyscall } : {},
8285
8306
  spawner: opts.spawner,
@@ -8413,7 +8434,7 @@ function spawnWasmProcess(opts) {
8413
8434
  };
8414
8435
  tw.postMessage(tinit);
8415
8436
  };
8416
- const init = processInit(opts, sab);
8437
+ const init = processInit(opts, sab, process.umask);
8417
8438
  worker.postMessage(init, opts.fork ? [opts.fork.memory.buffer] : []);
8418
8439
  const signal = (sig) => {
8419
8440
  if (process.signal(sig) !== "terminate") return;
@@ -8431,6 +8452,7 @@ function spawnWasmProcess(opts) {
8431
8452
  onState: (listener) => process.onState(listener),
8432
8453
  memory: () => Atomics.load(header3, SAB_I_MEMORY) * 65536,
8433
8454
  ignoredSignals: (fork) => process.inheritable(fork),
8455
+ umask: () => process.umask,
8434
8456
  writesBack: () => opts.program.abi === "wasi" && !done4
8435
8457
  };
8436
8458
  }
@@ -8536,8 +8558,13 @@ var JobTable = class {
8536
8558
  return id;
8537
8559
  }
8538
8560
  terminalNamed(name2) {
8539
- const known = /* @__PURE__ */ new Set([...this.terminals.values(), ...this.foreground.keys()]);
8540
- 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()])];
8541
8568
  }
8542
8569
  controllingTerminal(pid) {
8543
8570
  const member = this.members.get(pid);
@@ -10180,6 +10207,7 @@ var Launcher = class {
10180
10207
  this.settling.syscall(pid, call.op);
10181
10208
  },
10182
10209
  ...req.ignored ? { ignored: req.ignored } : {},
10210
+ ...req.umask !== void 0 ? { umask: req.umask } : {},
10183
10211
  program: req.program,
10184
10212
  argv0: req.argv0,
10185
10213
  args: req.args,
@@ -10271,7 +10299,8 @@ var Launcher = class {
10271
10299
  ...described,
10272
10300
  started: (this.described.get(root.pid) ?? described).started,
10273
10301
  state: this.processes.has(member.pid) ? "S" : "Z",
10274
- memory: this.processes.get(member.pid)?.memory() ?? 0
10302
+ memory: this.processes.get(member.pid)?.memory() ?? 0,
10303
+ umask: this.umaskOf(member.pid)
10275
10304
  });
10276
10305
  }
10277
10306
  return listed;
@@ -10293,6 +10322,7 @@ var Launcher = class {
10293
10322
  report,
10294
10323
  ppid,
10295
10324
  ignored: this.ignoredBy(ppid),
10325
+ umask: this.umaskOf(ppid),
10296
10326
  ...exec
10297
10327
  });
10298
10328
  deciding?.attach();
@@ -10337,7 +10367,8 @@ var Launcher = class {
10337
10367
  fds,
10338
10368
  ppid,
10339
10369
  fork: state,
10340
- ignored: this.ignoredBy(ppid, true)
10370
+ ignored: this.ignoredBy(ppid, true),
10371
+ umask: this.umaskOf(ppid)
10341
10372
  })
10342
10373
  );
10343
10374
  }
@@ -10346,6 +10377,9 @@ var Launcher = class {
10346
10377
  const foreground = () => this.jobs.tcgetpgrp(tty, fallback);
10347
10378
  this.settling.deliver(sig, pgid, send, tty.reading ? void 0 : foreground);
10348
10379
  }
10380
+ umaskOf(pid) {
10381
+ return this.processes.get(pid)?.umask?.() ?? DEFAULT_UMASK;
10382
+ }
10349
10383
  ignoredBy(pid, fork = false) {
10350
10384
  return this.processes.get(pid)?.ignoredSignals(fork) ?? 0;
10351
10385
  }