@ai-ecoverse/slicc-kernel 1.30.0 → 1.31.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/README.md +12 -2
- package/dist/index.js +13 -0
- package/dist/index.js.map +2 -2
- package/dist/kernel-worker.js +109 -13
- package/dist/kernel-worker.js.map +4 -4
- package/dist/node-process-worker.js +45 -19
- package/dist/node-process-worker.js.map +3 -3
- package/dist/node.js +110 -14
- package/dist/node.js.map +4 -4
- package/dist/process-worker.js +45 -19
- package/dist/process-worker.js.map +3 -3
- package/dist/testing.js.map +1 -1
- package/package.json +3 -3
package/dist/node.js
CHANGED
|
@@ -4797,6 +4797,21 @@ function toHostLoopback(href) {
|
|
|
4797
4797
|
url.hostname = "127.0.0.1";
|
|
4798
4798
|
return url.href;
|
|
4799
4799
|
}
|
|
4800
|
+
var DEFAULT_HOSTNAME = "slicc";
|
|
4801
|
+
var HOSTNAME_ADDRESS = "127.0.1.1";
|
|
4802
|
+
var LIBC_HOSTNAMES = ["emscripten", "wasmer.sh"];
|
|
4803
|
+
var LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
|
|
4804
|
+
function reserved(name2) {
|
|
4805
|
+
const lower = name2.toLowerCase();
|
|
4806
|
+
return lower === "localhost" || lower.endsWith(".localhost") || lower === HOST_LOOPBACK || lower === "wasmer.sh" || /^\d+(\.\d+){3}$/.test(lower);
|
|
4807
|
+
}
|
|
4808
|
+
function isHostname(name2) {
|
|
4809
|
+
if (typeof name2 !== "string" || name2.length > 253 || reserved(name2)) return false;
|
|
4810
|
+
return name2.split(".").every((l) => LABEL.test(l));
|
|
4811
|
+
}
|
|
4812
|
+
function ownNames(hostname) {
|
|
4813
|
+
return [.../* @__PURE__ */ new Set([hostname.toLowerCase(), ...LIBC_HOSTNAMES])];
|
|
4814
|
+
}
|
|
4800
4815
|
|
|
4801
4816
|
// src/kernel/net/proxy-service.ts
|
|
4802
4817
|
var REALM_PROXY_PORT = 3128;
|
|
@@ -5760,14 +5775,15 @@ var CA_PATH = "/etc/ssl/certs/slicc-kernel-ca.pem";
|
|
|
5760
5775
|
var PROXY_URL = `http://127.0.0.1:${REALM_PROXY_PORT}`;
|
|
5761
5776
|
var NO_PROXY = "localhost,.localhost,127.0.0.1,127.0.0.0/8";
|
|
5762
5777
|
var CA_OWNER = "slicc-kernel";
|
|
5763
|
-
function networkEnv() {
|
|
5778
|
+
function networkEnv(hostname = DEFAULT_HOSTNAME) {
|
|
5779
|
+
const bypass = [NO_PROXY, ...ownNames(hostname).filter((n) => n !== "wasmer.sh")].join(",");
|
|
5764
5780
|
return {
|
|
5765
5781
|
http_proxy: PROXY_URL,
|
|
5766
5782
|
https_proxy: PROXY_URL,
|
|
5767
5783
|
HTTP_PROXY: PROXY_URL,
|
|
5768
5784
|
HTTPS_PROXY: PROXY_URL,
|
|
5769
|
-
no_proxy:
|
|
5770
|
-
NO_PROXY,
|
|
5785
|
+
no_proxy: bypass,
|
|
5786
|
+
NO_PROXY: bypass,
|
|
5771
5787
|
SSL_CERT_FILE: CA_PATH,
|
|
5772
5788
|
CURL_CA_BUNDLE: CA_PATH,
|
|
5773
5789
|
GIT_SSL_CAINFO: CA_PATH,
|
|
@@ -6090,7 +6106,11 @@ var RESOLVE_TTL_MAX = 60;
|
|
|
6090
6106
|
var RESOLVE_TIMEOUT_MS = 1e4;
|
|
6091
6107
|
var RESOLVE_CACHE_MAX = 256;
|
|
6092
6108
|
var LOOPBACK_NAMES2 = /* @__PURE__ */ new Set(["localhost", "localhost.localdomain", "ip6-localhost", "::1"]);
|
|
6093
|
-
function
|
|
6109
|
+
function loopbackName(name2, own) {
|
|
6110
|
+
return LOOPBACK_NAMES2.has(name2) || name2.endsWith(".localhost") || own.includes(name2);
|
|
6111
|
+
}
|
|
6112
|
+
function hostsEntry(name2, own = ownNames(DEFAULT_HOSTNAME)) {
|
|
6113
|
+
if (own.includes(name2)) return HOSTNAME_ADDRESS;
|
|
6094
6114
|
if (LOOPBACK_NAMES2.has(name2) || name2.endsWith(".localhost")) return "127.0.0.1";
|
|
6095
6115
|
if (name2 === HOST_LOOPBACK) return HOST_LOOPBACK_ADDRESS.join(".");
|
|
6096
6116
|
return ipv4Bytes(name2) ? name2 : void 0;
|
|
@@ -6101,6 +6121,7 @@ var Resolver = class {
|
|
|
6101
6121
|
now;
|
|
6102
6122
|
timeoutMs;
|
|
6103
6123
|
log;
|
|
6124
|
+
own;
|
|
6104
6125
|
cache = /* @__PURE__ */ new Map();
|
|
6105
6126
|
pending = /* @__PURE__ */ new Map();
|
|
6106
6127
|
constructor(options) {
|
|
@@ -6109,16 +6130,17 @@ var Resolver = class {
|
|
|
6109
6130
|
this.now = options.now ?? Date.now;
|
|
6110
6131
|
this.timeoutMs = options.timeoutMs ?? RESOLVE_TIMEOUT_MS;
|
|
6111
6132
|
this.log = options.log ?? ((message2) => console.warn(message2));
|
|
6133
|
+
this.own = ownNames(options.hostname ?? DEFAULT_HOSTNAME);
|
|
6112
6134
|
}
|
|
6113
6135
|
async resolve(name2, family, blocking) {
|
|
6114
6136
|
const key = name2.toLowerCase().replace(/\.$/, "");
|
|
6115
|
-
const local = hostsEntry(key);
|
|
6137
|
+
const local = hostsEntry(key, this.own);
|
|
6116
6138
|
if (ipv6Groups(key)) {
|
|
6117
6139
|
const v4 = family !== 6 && local ? [local] : [];
|
|
6118
6140
|
return family === 4 ? v4 : [...v4, key];
|
|
6119
6141
|
}
|
|
6120
6142
|
if (local) {
|
|
6121
|
-
const six =
|
|
6143
|
+
const six = loopbackName(key, this.own) ? ["::1"] : [];
|
|
6122
6144
|
return family === 6 ? six : family === 4 ? [local] : [local, ...six];
|
|
6123
6145
|
}
|
|
6124
6146
|
if (!this.uplink || key === "") return [];
|
|
@@ -7594,7 +7616,7 @@ var WasmProcess = class {
|
|
|
7594
7616
|
for (const listener of this.stateListeners) listener("continued", SIG.CONT);
|
|
7595
7617
|
}
|
|
7596
7618
|
async syscall(req) {
|
|
7597
|
-
this.options.onSyscall?.();
|
|
7619
|
+
this.options.onSyscall?.(req);
|
|
7598
7620
|
for (; ; ) {
|
|
7599
7621
|
await this.resumed;
|
|
7600
7622
|
const stops = this.stops;
|
|
@@ -8388,6 +8410,57 @@ var JobTable = class {
|
|
|
8388
8410
|
}
|
|
8389
8411
|
};
|
|
8390
8412
|
|
|
8413
|
+
// src/kernel/settling.ts
|
|
8414
|
+
var SETUP_OPS = /* @__PURE__ */ new Set([
|
|
8415
|
+
"proc-list",
|
|
8416
|
+
"proc-identity",
|
|
8417
|
+
"fd-info",
|
|
8418
|
+
"sig-mask",
|
|
8419
|
+
"proc-setpgid",
|
|
8420
|
+
"tty-pgrp-set"
|
|
8421
|
+
]);
|
|
8422
|
+
var SETTLE_MS = 250;
|
|
8423
|
+
var KEY_SIGNALS = /* @__PURE__ */ new Set([2, 3, 20]);
|
|
8424
|
+
var SettlingChildren = class {
|
|
8425
|
+
children = /* @__PURE__ */ new Map();
|
|
8426
|
+
held = [];
|
|
8427
|
+
pgidOf;
|
|
8428
|
+
settleMs;
|
|
8429
|
+
constructor(pgidOf, settleMs = SETTLE_MS) {
|
|
8430
|
+
this.pgidOf = pgidOf;
|
|
8431
|
+
this.settleMs = settleMs;
|
|
8432
|
+
}
|
|
8433
|
+
started(pid, ppid) {
|
|
8434
|
+
this.children.set(pid, { ppid });
|
|
8435
|
+
}
|
|
8436
|
+
syscall(pid, op) {
|
|
8437
|
+
const child = this.children.get(pid);
|
|
8438
|
+
if (!child) return;
|
|
8439
|
+
if (!SETUP_OPS.has(op)) {
|
|
8440
|
+
this.settled(pid);
|
|
8441
|
+
return;
|
|
8442
|
+
}
|
|
8443
|
+
child.timer ??= setTimeout(() => this.settled(pid), this.settleMs);
|
|
8444
|
+
}
|
|
8445
|
+
settled(pid) {
|
|
8446
|
+
const child = this.children.get(pid);
|
|
8447
|
+
if (!child) return;
|
|
8448
|
+
clearTimeout(child.timer);
|
|
8449
|
+
this.children.delete(pid);
|
|
8450
|
+
const ready2 = this.held.filter((h) => !this.blocking(h.pgid));
|
|
8451
|
+
this.held = this.held.filter((h) => this.blocking(h.pgid));
|
|
8452
|
+
for (const h of ready2) h.send();
|
|
8453
|
+
}
|
|
8454
|
+
deliver(sig, pgid, send) {
|
|
8455
|
+
if (KEY_SIGNALS.has(sig) && this.blocking(pgid)) this.held.push({ pgid, send });
|
|
8456
|
+
else send();
|
|
8457
|
+
}
|
|
8458
|
+
blocking(pgid) {
|
|
8459
|
+
for (const { ppid } of this.children.values()) if (this.pgidOf(ppid) === pgid) return true;
|
|
8460
|
+
return false;
|
|
8461
|
+
}
|
|
8462
|
+
};
|
|
8463
|
+
|
|
8391
8464
|
// src/mount/driver.ts
|
|
8392
8465
|
function fsError2(code, message2 = code) {
|
|
8393
8466
|
return Object.assign(new Error(message2), { code });
|
|
@@ -9657,7 +9730,14 @@ var Launcher = class {
|
|
|
9657
9730
|
described = /* @__PURE__ */ new Map();
|
|
9658
9731
|
jobs = new JobTable();
|
|
9659
9732
|
locks = new LockTable();
|
|
9660
|
-
|
|
9733
|
+
settling = new SettlingChildren((pid) => this.jobs.pgidOf(pid));
|
|
9734
|
+
ptys = new PtyTable(
|
|
9735
|
+
(tty, sig) => this.settling.deliver(
|
|
9736
|
+
sig,
|
|
9737
|
+
this.jobs.tcgetpgrp(tty, 0),
|
|
9738
|
+
() => this.jobs.signalOwnedForeground(tty, sig)
|
|
9739
|
+
)
|
|
9740
|
+
);
|
|
9661
9741
|
net = new LoopbackNet();
|
|
9662
9742
|
cdp;
|
|
9663
9743
|
ca;
|
|
@@ -9665,6 +9745,7 @@ var Launcher = class {
|
|
|
9665
9745
|
uplink;
|
|
9666
9746
|
routes;
|
|
9667
9747
|
resolver;
|
|
9748
|
+
hostname;
|
|
9668
9749
|
watchers = new FsWatchers();
|
|
9669
9750
|
pnpmHome;
|
|
9670
9751
|
mounts;
|
|
@@ -9703,13 +9784,16 @@ var Launcher = class {
|
|
|
9703
9784
|
this.pnpmHome = options.env?.PNPM_HOME ?? PNPM_HOME;
|
|
9704
9785
|
this.modulesDir = options.modules ?? "/node_modules";
|
|
9705
9786
|
this.cdp = new CdpHosts(options.cdp);
|
|
9706
|
-
|
|
9787
|
+
const hostname = options.hostname ?? DEFAULT_HOSTNAME;
|
|
9788
|
+
if (!isHostname(hostname)) throw new Error(`not a host name: ${String(hostname)}`);
|
|
9789
|
+
this.hostname = hostname;
|
|
9790
|
+
this.env = { ...networkEnv(hostname), SLICC_CDP_URL: this.cdp.url, ...options.env };
|
|
9707
9791
|
this.ca = kernelCa(options.caStore ?? memoryCaStore());
|
|
9708
9792
|
this.transport = options.transport ?? missingTransport();
|
|
9709
9793
|
this.uplink = options.uplink;
|
|
9710
9794
|
this.routes = new Routes(options.uplink?.traits.ipv6 === true);
|
|
9711
9795
|
if (options.uplink?.routes) this.routes.set(options.uplink.routes);
|
|
9712
|
-
this.resolver = new Resolver({ uplink: options.uplink, routes: this.routes });
|
|
9796
|
+
this.resolver = new Resolver({ uplink: options.uplink, routes: this.routes, hostname });
|
|
9713
9797
|
if (options.uplink) this.net.useUplink({ uplink: options.uplink, routes: this.routes });
|
|
9714
9798
|
enableNetwork(this.net, {
|
|
9715
9799
|
transport: this.transport,
|
|
@@ -9865,8 +9949,10 @@ var Launcher = class {
|
|
|
9865
9949
|
}
|
|
9866
9950
|
async launch(planned, req) {
|
|
9867
9951
|
const { target, args } = planned;
|
|
9868
|
-
const
|
|
9952
|
+
const seen = { ...req.env, HOSTNAME: this.hostname, cwd: req.cwd };
|
|
9953
|
+
const env = { ...expandDefaults(target.env, seen), ...req.env };
|
|
9869
9954
|
for (const key of target.unset ?? []) delete env[key];
|
|
9955
|
+
env.HOSTNAME = this.hostname;
|
|
9870
9956
|
let program;
|
|
9871
9957
|
try {
|
|
9872
9958
|
program = await this.program(target, env);
|
|
@@ -9897,7 +9983,10 @@ var Launcher = class {
|
|
|
9897
9983
|
await (asked ??= decided.then(count));
|
|
9898
9984
|
return this.identityOf(pid);
|
|
9899
9985
|
},
|
|
9900
|
-
onSyscall: () =>
|
|
9986
|
+
onSyscall: (call) => {
|
|
9987
|
+
this.decide(pid);
|
|
9988
|
+
this.settling.syscall(pid, call.op);
|
|
9989
|
+
},
|
|
9901
9990
|
...req.ignored ? { ignored: req.ignored } : {},
|
|
9902
9991
|
program: req.program,
|
|
9903
9992
|
argv0: req.argv0,
|
|
@@ -9930,6 +10019,7 @@ var Launcher = class {
|
|
|
9930
10019
|
...this.shownIds(req)
|
|
9931
10020
|
});
|
|
9932
10021
|
this.processes.set(pid, handle);
|
|
10022
|
+
if (req.ppid !== void 0) this.settling.started(pid, req.ppid);
|
|
9933
10023
|
this.jobs.add(pid, req.ppid, (sig) => handle.signal(sig), terminal);
|
|
9934
10024
|
if (req.exec && req.ppid !== void 0) this.jobs.exec(req.ppid, pid, true);
|
|
9935
10025
|
if (req.pgid !== void 0) this.jobs.join(pid, req.pgid);
|
|
@@ -9940,6 +10030,7 @@ var Launcher = class {
|
|
|
9940
10030
|
});
|
|
9941
10031
|
void handle.exited.then(() => {
|
|
9942
10032
|
this.processes.delete(pid);
|
|
10033
|
+
this.settling.settled(pid);
|
|
9943
10034
|
if (req.ppid === void 0 || this.orphans.delete(pid)) this.forget(pid);
|
|
9944
10035
|
else this.zombies.add(pid);
|
|
9945
10036
|
});
|
|
@@ -10252,7 +10343,11 @@ var Launcher = class {
|
|
|
10252
10343
|
let leader = 0;
|
|
10253
10344
|
const tty = new KernelTty(
|
|
10254
10345
|
{ write: (bytes) => options.onData(bytes.slice()) },
|
|
10255
|
-
(sig) => this.
|
|
10346
|
+
(sig) => this.settling.deliver(
|
|
10347
|
+
sig,
|
|
10348
|
+
this.jobs.tcgetpgrp(tty, leader),
|
|
10349
|
+
() => this.jobs.signalForeground(tty, leader, sig)
|
|
10350
|
+
)
|
|
10256
10351
|
);
|
|
10257
10352
|
tty.name = `/dev/tty${++this.terminals}`;
|
|
10258
10353
|
tty.setSize(options.cols ?? 80, options.rows ?? 24);
|
|
@@ -11311,7 +11406,8 @@ async function createNodeKernel(options = {}) {
|
|
|
11311
11406
|
...options.processMounts !== void 0 ? { processMounts: options.processMounts } : {},
|
|
11312
11407
|
...options.fstabRetries ? { fstabRetries: options.fstabRetries } : {},
|
|
11313
11408
|
...options.hostfs ? { hostfs: options.hostfs } : {},
|
|
11314
|
-
...options.cdp ? { cdp: options.cdp } : {}
|
|
11409
|
+
...options.cdp ? { cdp: options.cdp } : {},
|
|
11410
|
+
...options.hostname !== void 0 ? { hostname: options.hostname } : {}
|
|
11315
11411
|
});
|
|
11316
11412
|
await launcher.prepare();
|
|
11317
11413
|
const guard = (work) => new Promise((resolve, reject) => {
|