@ai-ecoverse/slicc-kernel 1.30.1 → 1.31.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.
@@ -29,6 +29,45 @@ var init_protocol = __esm({
29
29
  }
30
30
  });
31
31
 
32
+ // src/kernel/net/loopback-names.ts
33
+ function reserved(name) {
34
+ const lower = name.toLowerCase();
35
+ return lower === "localhost" || lower.endsWith(".localhost") || lower === HOST_LOOPBACK || lower === "wasmer.sh" || /^\d+(\.\d+){3}$/.test(lower);
36
+ }
37
+ function isHostname(name) {
38
+ if (typeof name !== "string" || name.length > 253 || reserved(name)) return false;
39
+ return name.split(".").every((l) => LABEL.test(l));
40
+ }
41
+ function hostnameOf(env) {
42
+ return isHostname(env.HOSTNAME) ? env.HOSTNAME : DEFAULT_HOSTNAME;
43
+ }
44
+ function ownNames(hostname) {
45
+ return [.../* @__PURE__ */ new Set([hostname.toLowerCase(), ...LIBC_HOSTNAMES])];
46
+ }
47
+ function hostsFile(hostname = DEFAULT_HOSTNAME) {
48
+ return [
49
+ "127.0.0.1 localhost localhost.localdomain",
50
+ "::1 localhost ip6-localhost",
51
+ `${HOSTNAME_ADDRESS} ${ownNames(hostname).join(" ")}`,
52
+ `${HOST_LOOPBACK_ADDRESS.join(".")} ${HOST_LOOPBACK}`,
53
+ ""
54
+ ].join("\n");
55
+ }
56
+ var HOST_LOOPBACK, HOST_LOOPBACK_ADDRESS, PAGE_LOOPBACK, PAGE_LOOPBACK_URL, DEFAULT_HOSTNAME, HOSTNAME_ADDRESS, LIBC_HOSTNAMES, LABEL;
57
+ var init_loopback_names = __esm({
58
+ "src/kernel/net/loopback-names.ts"() {
59
+ "use strict";
60
+ HOST_LOOPBACK = "host.slicc.internal";
61
+ HOST_LOOPBACK_ADDRESS = [10, 0, 2, 2];
62
+ PAGE_LOOPBACK = "kernel.localhost";
63
+ PAGE_LOOPBACK_URL = `http://{port}.${PAGE_LOOPBACK}`;
64
+ DEFAULT_HOSTNAME = "slicc";
65
+ HOSTNAME_ADDRESS = "127.0.1.1";
66
+ LIBC_HOSTNAMES = ["emscripten", "wasmer.sh"];
67
+ LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
68
+ }
69
+ });
70
+
32
71
  // src/kernel/signals.ts
33
72
  function sigbit(sig) {
34
73
  return 1 << sig;
@@ -2074,24 +2113,6 @@ var init_process_children = __esm({
2074
2113
  }
2075
2114
  });
2076
2115
 
2077
- // src/kernel/net/loopback-names.ts
2078
- function hostsFile() {
2079
- return `127.0.0.1 localhost
2080
- ::1 localhost ip6-localhost
2081
- ${HOST_LOOPBACK_ADDRESS.join(".")} ${HOST_LOOPBACK}
2082
- `;
2083
- }
2084
- var HOST_LOOPBACK, HOST_LOOPBACK_ADDRESS, PAGE_LOOPBACK, PAGE_LOOPBACK_URL;
2085
- var init_loopback_names = __esm({
2086
- "src/kernel/net/loopback-names.ts"() {
2087
- "use strict";
2088
- HOST_LOOPBACK = "host.slicc.internal";
2089
- HOST_LOOPBACK_ADDRESS = [10, 0, 2, 2];
2090
- PAGE_LOOPBACK = "kernel.localhost";
2091
- PAGE_LOOPBACK_URL = `http://{port}.${PAGE_LOOPBACK}`;
2092
- }
2093
- });
2094
-
2095
2116
  // src/process/process-pty.ts
2096
2117
  function failed(e) {
2097
2118
  const code2 = e?.code;
@@ -2538,10 +2559,13 @@ function useMounts(Fs, env = {}, live = false) {
2538
2559
  mkdirTree.call(Fs, "/dev/.etc");
2539
2560
  writeFile.call(Fs, "/dev/.etc/passwd", passwd);
2540
2561
  writeFile.call(Fs, "/dev/.etc/group", group);
2541
- writeFile.call(Fs, "/dev/.etc/hosts", hostsFile());
2562
+ writeFile.call(Fs, "/dev/.etc/hosts", hostsFile(hostnameOf(env)));
2563
+ writeFile.call(Fs, "/dev/.etc/hostname", `${hostnameOf(env)}
2564
+ `);
2542
2565
  backing["/etc/passwd"] = "/dev/.etc/passwd";
2543
2566
  backing["/etc/group"] = "/dev/.etc/group";
2544
2567
  backing["/etc/hosts"] = "/dev/.etc/hosts";
2568
+ backing["/etc/hostname"] = "/dev/.etc/hostname";
2545
2569
  } catch {
2546
2570
  }
2547
2571
  const open = Fs.open.bind(Fs);
@@ -3674,6 +3698,7 @@ async function runWasmProcess(init, port, deps = {}) {
3674
3698
  stdioPromoter: () => vfsPromoter(running.FS, sys, streams, livePath)
3675
3699
  });
3676
3700
  running.sliccKernel.http = createHttpKernel(transport);
3701
+ running.sliccKernel.hostname = hostnameOf(init.env);
3677
3702
  running.sliccKernel.net = createSocketKernel({
3678
3703
  transport,
3679
3704
  Fs: running.FS,
@@ -3732,6 +3757,7 @@ var O_RDONLY, O_WRONLY2, O_RDWR3, GLUE_TRAILER, evaluateGlue, EVAL_BLOCKED;
3732
3757
  var init_process_runtime = __esm({
3733
3758
  "src/process/process-runtime.ts"() {
3734
3759
  "use strict";
3760
+ init_loopback_names();
3735
3761
  init_signals();
3736
3762
  init_emscripten_vfs_hook();
3737
3763
  init_live_vfs_fs();
@@ -3975,6 +4001,9 @@ var init_wasi_files = __esm({
3975
4001
  data;
3976
4002
  length = 0;
3977
4003
  dirty = false;
4004
+ whole = false;
4005
+ from = Infinity;
4006
+ to = 0;
3978
4007
  orphaned = false;
3979
4008
  opens = 0;
3980
4009
  fs;
@@ -3993,6 +4022,7 @@ var init_wasi_files = __esm({
3993
4022
  } else if (empty) {
3994
4023
  this.data = new Uint8Array(0);
3995
4024
  this.dirty = true;
4025
+ this.whole = true;
3996
4026
  }
3997
4027
  }
3998
4028
  get path() {
@@ -4045,6 +4075,8 @@ var init_wasi_files = __esm({
4045
4075
  this.load();
4046
4076
  this.ensure(end);
4047
4077
  const buf = this.data;
4078
+ this.from = Math.min(this.from, at, this.length);
4079
+ this.to = Math.max(this.to, end);
4048
4080
  if (at > this.length) buf.fill(0, this.length, at);
4049
4081
  buf.set(bytes, at);
4050
4082
  this.length = Math.max(this.length, end);
@@ -4059,6 +4091,7 @@ var init_wasi_files = __esm({
4059
4091
  }
4060
4092
  this.load();
4061
4093
  this.ensure(size);
4094
+ this.whole = true;
4062
4095
  if (size > this.length) this.data.fill(0, this.length, size);
4063
4096
  this.length = size;
4064
4097
  }
@@ -4086,9 +4119,14 @@ var init_wasi_files = __esm({
4086
4119
  flush() {
4087
4120
  if (this.orphaned || !this.dirty) return;
4088
4121
  if (this.ranged) this.ranged.flush();
4089
- else if (this.data) this.fs.writeFile(this.path, this.data.slice(0, this.length));
4090
- else return;
4122
+ else if (!this.data) return;
4123
+ else if (this.whole || !this.fs.pwrite)
4124
+ this.fs.writeFile(this.path, this.data.slice(0, this.length));
4125
+ else this.fs.pwrite(this.path, this.from, this.data.slice(this.from, this.to), true);
4091
4126
  this.dirty = false;
4127
+ this.whole = false;
4128
+ this.from = Infinity;
4129
+ this.to = 0;
4092
4130
  }
4093
4131
  };
4094
4132
  LocalFile = class {
@@ -4537,6 +4575,14 @@ var init_wasi_fds = __esm({
4537
4575
  flushAll() {
4538
4576
  for (const buffer of this.buffers.values()) buffer.flush();
4539
4577
  }
4578
+ flushEarly() {
4579
+ for (const buffer of this.buffers.values()) {
4580
+ try {
4581
+ buffer.flush();
4582
+ } catch {
4583
+ }
4584
+ }
4585
+ }
4540
4586
  flushPath(path) {
4541
4587
  for (const [p, buffer] of this.buffers) if (within(p, path)) buffer.flush();
4542
4588
  if (this.shared) this.kernel.call({ op: "fd-path-flush", path });
@@ -4932,9 +4978,24 @@ var init_wasi_host = __esm({
4932
4978
  listening;
4933
4979
  o;
4934
4980
  constructor(o) {
4935
- this.o = o;
4981
+ const { kernel } = o;
4982
+ const call2 = (req) => {
4983
+ if (req.op !== "fd-promote") this.fds.flushEarly();
4984
+ return kernel.call(req);
4985
+ };
4986
+ const sys = new Proxy(kernel.sys, {
4987
+ get: (target, name) => {
4988
+ const member = Reflect.get(target, name);
4989
+ if (typeof member !== "function") return member;
4990
+ return (...args) => {
4991
+ this.fds.flushEarly();
4992
+ return member.apply(target, args);
4993
+ };
4994
+ }
4995
+ });
4996
+ this.o = { ...o, kernel: { sys, call: call2 } };
4936
4997
  this.startCwd = o.cwd;
4937
- this.fds = new WasiFds(o.kernel, o.fs);
4998
+ this.fds = new WasiFds(this.o.kernel, o.fs);
4938
4999
  if (o.shared) this.fds.share(o.shared, true);
4939
5000
  else if (o.forked) this.fds.restore(o.forked.fds, o.forked.cloexec);
4940
5001
  else this.fds.setup(o.cwd, o.inherited ?? [], o.preopenRoot === true);