@ai-ecoverse/slicc-kernel 1.183.0 → 1.184.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.
- package/README.md +96 -0
- package/dist/async-process.js +14060 -0
- package/dist/async-process.js.map +7 -0
- package/dist/cloudflare-sources.js +2 -0
- package/dist/cloudflare.js +42562 -0
- package/dist/cloudflare.js.map +7 -0
- package/dist/driver-worker.js.map +2 -2
- package/dist/index.js.map +2 -2
- package/dist/kernel-worker.js +134 -39
- package/dist/kernel-worker.js.map +4 -4
- package/dist/node-driver-worker.js.map +2 -2
- package/dist/node-process-worker.cjs +3988 -576
- package/dist/node-process-worker.cjs.map +4 -4
- package/dist/node-process-worker.js +3988 -576
- package/dist/node-process-worker.js.map +4 -4
- package/dist/node.js +1478 -193
- package/dist/node.js.map +4 -4
- package/dist/process-worker.js +3904 -492
- package/dist/process-worker.js.map +4 -4
- package/dist/types/async/header-hook.d.ts +3 -0
- package/dist/types/async/link.d.ts +14 -0
- package/dist/types/async/message-link.d.ts +15 -0
- package/dist/types/async/node-host.d.ts +16 -0
- package/dist/types/async/remote-worker.d.ts +12 -0
- package/dist/types/async/snapshots.d.ts +13 -0
- package/dist/types/async/transport.d.ts +28 -0
- package/dist/types/async/wire.d.ts +113 -0
- package/dist/types/cdp/port.d.ts +2 -1
- package/dist/types/cloudflare/clock-skew.d.ts +2 -0
- package/dist/types/cloudflare/computer-driver.d.ts +65 -0
- package/dist/types/cloudflare/computer.d.ts +105 -0
- package/dist/types/cloudflare/fork-tokens.d.ts +17 -0
- package/dist/types/cloudflare/images.d.ts +20 -0
- package/dist/types/cloudflare/isolates.d.ts +17 -0
- package/dist/types/cloudflare/kernel-end.d.ts +45 -0
- package/dist/types/cloudflare/loader.d.ts +54 -0
- package/dist/types/cloudflare/options.d.ts +81 -0
- package/dist/types/cloudflare/placement.d.ts +61 -0
- package/dist/types/cloudflare/rpc-link.d.ts +49 -0
- package/dist/types/cloudflare/rpc-pack.d.ts +7 -0
- package/dist/types/cloudflare/sqlite-meta.d.ts +4 -0
- package/dist/types/cloudflare/sqlite-root.d.ts +5 -0
- package/dist/types/cloudflare/sqlite-store.d.ts +73 -0
- package/dist/types/cloudflare.d.ts +16 -0
- package/dist/types/facade/port.d.ts +2 -1
- package/dist/types/kernel/host.d.ts +1 -0
- package/dist/types/kernel/process.d.ts +2 -0
- package/dist/types/kernel/protocol.d.ts +1 -0
- package/dist/types/launcher.d.ts +16 -0
- package/dist/types/mount/hostfs.d.ts +2 -1
- package/dist/types/mount/in-process.d.ts +15 -0
- package/dist/types/node.d.ts +14 -0
- package/dist/types/ports.d.ts +7 -0
- package/dist/types/process/wasi/wasi-files.d.ts +1 -0
- package/dist/types/process/wasi/wasi-host.d.ts +3 -2
- package/dist/types/process/wasi/wasi-module.d.ts +2 -0
- package/dist/types/process/wasi/wasi-sigmask.d.ts +2 -1
- package/dist/types/process/wasi/wasm-reentry.d.ts +1 -0
- package/dist/types/realm/sync-sab-bridge.d.ts +1 -0
- package/package.json +10 -4
package/dist/node.js
CHANGED
|
@@ -1,15 +1,911 @@
|
|
|
1
1
|
// src/node.ts
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
2
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
3
3
|
import { lstatSync, mkdirSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import { isAbsolute, join } from "node:path";
|
|
6
|
-
import { MessageChannel as
|
|
6
|
+
import { MessageChannel as MessageChannel4 } from "node:worker_threads";
|
|
7
|
+
|
|
8
|
+
// src/async/node-host.ts
|
|
9
|
+
import { createHash } from "node:crypto";
|
|
10
|
+
import { MessageChannel as MessageChannel2, Worker } from "node:worker_threads";
|
|
11
|
+
|
|
12
|
+
// src/async/message-link.ts
|
|
13
|
+
var LINK_CLOSED = "link closed";
|
|
14
|
+
function isFrame(data) {
|
|
15
|
+
return typeof data === "object" && data !== null && typeof data.link === "string";
|
|
16
|
+
}
|
|
17
|
+
function messageLinks(port) {
|
|
18
|
+
const posts = [];
|
|
19
|
+
const closes = [];
|
|
20
|
+
const early = [];
|
|
21
|
+
const earlyCalls = [];
|
|
22
|
+
const waiting = /* @__PURE__ */ new Map();
|
|
23
|
+
let answer2;
|
|
24
|
+
let next3 = 0;
|
|
25
|
+
let ended;
|
|
26
|
+
const send2 = (frame4, transfer) => {
|
|
27
|
+
if (ended !== void 0) return false;
|
|
28
|
+
try {
|
|
29
|
+
if (transfer && transfer.length > 0) port.postMessage(frame4, transfer);
|
|
30
|
+
else port.postMessage(frame4);
|
|
31
|
+
return true;
|
|
32
|
+
} catch (err) {
|
|
33
|
+
finish(`post failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const finish = (reason) => {
|
|
38
|
+
if (ended !== void 0) return;
|
|
39
|
+
ended = reason;
|
|
40
|
+
for (const pending of waiting.values()) pending.reject(new Error(`${LINK_CLOSED}: ${reason}`));
|
|
41
|
+
waiting.clear();
|
|
42
|
+
try {
|
|
43
|
+
port.close?.();
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
for (const handler of closes.splice(0)) handler(reason);
|
|
47
|
+
};
|
|
48
|
+
const serve = (id2, message3) => {
|
|
49
|
+
const handler = answer2;
|
|
50
|
+
let result;
|
|
51
|
+
try {
|
|
52
|
+
result = Promise.resolve(handler(message3));
|
|
53
|
+
} catch (err) {
|
|
54
|
+
result = Promise.reject(err);
|
|
55
|
+
}
|
|
56
|
+
result.then(
|
|
57
|
+
(value2) => send2({ link: "reply", id: id2, value: value2 }),
|
|
58
|
+
(err) => send2({ link: "reply", id: id2, error: err instanceof Error ? err.message : String(err) })
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
const deliver = (message3) => {
|
|
62
|
+
if (posts.length === 0) {
|
|
63
|
+
early.push(message3);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
for (const handler of [...posts]) handler(message3);
|
|
67
|
+
};
|
|
68
|
+
port.addEventListener("message", (event) => {
|
|
69
|
+
const data = event.data;
|
|
70
|
+
if (ended !== void 0 || !isFrame(data)) return;
|
|
71
|
+
switch (data.link) {
|
|
72
|
+
case "post":
|
|
73
|
+
deliver(data.message);
|
|
74
|
+
return;
|
|
75
|
+
case "call":
|
|
76
|
+
if (answer2) serve(data.id, data.message);
|
|
77
|
+
else earlyCalls.push({ id: data.id, message: data.message });
|
|
78
|
+
return;
|
|
79
|
+
case "reply": {
|
|
80
|
+
const pending = waiting.get(data.id);
|
|
81
|
+
if (!pending) return;
|
|
82
|
+
waiting.delete(data.id);
|
|
83
|
+
if ("error" in data) pending.reject(new Error(data.error));
|
|
84
|
+
else pending.resolve(data.value);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
case "close":
|
|
88
|
+
finish(data.reason);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
port.addEventListener("close", () => finish("port closed"));
|
|
93
|
+
port.start?.();
|
|
94
|
+
const onPosts = (handler) => {
|
|
95
|
+
posts.push(handler);
|
|
96
|
+
for (const message3 of early.splice(0)) for (const each of [...posts]) each(message3);
|
|
97
|
+
};
|
|
98
|
+
const onClose = (handler) => {
|
|
99
|
+
if (ended !== void 0) {
|
|
100
|
+
const reason = ended;
|
|
101
|
+
queueMicrotask(() => handler(reason));
|
|
102
|
+
} else closes.push(handler);
|
|
103
|
+
};
|
|
104
|
+
const post = (message3, transfer) => {
|
|
105
|
+
send2({ link: "post", message: message3 }, transfer);
|
|
106
|
+
};
|
|
107
|
+
const close = (reason = "closed") => {
|
|
108
|
+
send2({ link: "close", reason });
|
|
109
|
+
finish(reason);
|
|
110
|
+
};
|
|
111
|
+
const process2 = {
|
|
112
|
+
post,
|
|
113
|
+
onPost: onPosts,
|
|
114
|
+
onCall(handler) {
|
|
115
|
+
answer2 = handler;
|
|
116
|
+
for (const { id: id2, message: message3 } of earlyCalls.splice(0)) serve(id2, message3);
|
|
117
|
+
},
|
|
118
|
+
onClose,
|
|
119
|
+
close: () => close()
|
|
120
|
+
};
|
|
121
|
+
const kernel = {
|
|
122
|
+
post,
|
|
123
|
+
call(message3, transfer) {
|
|
124
|
+
if (ended !== void 0) return Promise.reject(new Error(`${LINK_CLOSED}: ${ended}`));
|
|
125
|
+
const id2 = ++next3;
|
|
126
|
+
const pending = Promise.withResolvers();
|
|
127
|
+
waiting.set(id2, pending);
|
|
128
|
+
send2({ link: "call", id: id2, message: message3 }, transfer);
|
|
129
|
+
return pending.promise;
|
|
130
|
+
},
|
|
131
|
+
onMessage: onPosts,
|
|
132
|
+
onClose,
|
|
133
|
+
close: () => close()
|
|
134
|
+
};
|
|
135
|
+
return { process: process2, kernel, close };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/kernel/protocol.ts
|
|
139
|
+
var WASM_PROCESS_INIT = "wasm-process-init";
|
|
140
|
+
var WASM_PROCESS_EXIT = "wasm-process-exit";
|
|
141
|
+
var WASM_PROCESS_ERROR = "wasm-process-error";
|
|
142
|
+
var WASM_PROCESS_READY = "wasm-process-ready";
|
|
143
|
+
var WASM_THREAD_SPAWN = "wasm-thread-spawn";
|
|
144
|
+
var WASM_THREAD_INIT = "wasm-thread-init";
|
|
145
|
+
var WASM_THREAD_EXIT = "wasm-thread-exit";
|
|
146
|
+
var WASM_MAX_THREADS = 256;
|
|
147
|
+
var JS_THREAD_SPAWN = "js-thread-spawn";
|
|
148
|
+
var JS_THREAD_INIT = "js-thread-init";
|
|
149
|
+
var JS_THREAD_EXIT = "js-thread-exit";
|
|
150
|
+
var JS_MAX_THREADS = 256;
|
|
151
|
+
var JS_DEFAULT_THREADS = 16;
|
|
152
|
+
var JS_THREAD_NO_MEMORY = 256;
|
|
153
|
+
var JS_THREAD_CRASHED = 257;
|
|
154
|
+
var JS_THREAD_OWNED_FDS = 1024;
|
|
155
|
+
|
|
156
|
+
// src/realm/sync-sab-wire.ts
|
|
157
|
+
var atomicLoad = Atomics.load;
|
|
158
|
+
var atomicStore = Atomics.store;
|
|
159
|
+
var atomicWaitAsync = Atomics.waitAsync;
|
|
160
|
+
var setBytes = Uint8Array.prototype.set;
|
|
161
|
+
var bytesPart = Uint8Array.prototype.subarray;
|
|
162
|
+
var decodeText = TextDecoder.prototype.decode;
|
|
163
|
+
var sabLoad = (a, i) => atomicLoad(a, i);
|
|
164
|
+
var sabStore = (a, i, v) => atomicStore(a, i, v);
|
|
165
|
+
var SAB_HEADER_I32 = 18;
|
|
166
|
+
var SAB_CLOCK_OFFSET = SAB_HEADER_I32 * 4;
|
|
167
|
+
var SAB_CLOCK_I64 = 3;
|
|
168
|
+
var SAB_HEADER_BYTES = SAB_CLOCK_OFFSET + SAB_CLOCK_I64 * 8;
|
|
169
|
+
var SAB_I_STATE = 0;
|
|
170
|
+
var SAB_I_SEQ = 1;
|
|
171
|
+
var SAB_I_STATUS = 2;
|
|
172
|
+
var SAB_I_TOTAL = 3;
|
|
173
|
+
var SAB_I_CHUNK = 4;
|
|
174
|
+
var SAB_I_OFFSET = 5;
|
|
175
|
+
var SAB_I_REQ = 6;
|
|
176
|
+
var SAB_I_PUB = 7;
|
|
177
|
+
var SAB_I_SIGNALS = 8;
|
|
178
|
+
var SAB_I_TIMERS = 9;
|
|
179
|
+
var SAB_I_MEMORY = 10;
|
|
180
|
+
var SAB_I_TOTAL_HI = 11;
|
|
181
|
+
var SAB_I_OFFSET_HI = 12;
|
|
182
|
+
var SAB_I_KILLED = 13;
|
|
183
|
+
var SAB_I_ASYNC = 14;
|
|
184
|
+
var SAB_I_STOP = 15;
|
|
185
|
+
var SAB_I_BLOCKED = 16;
|
|
186
|
+
var SAB_I_BLOCKED_HI = 17;
|
|
187
|
+
function loadBlocked(header5) {
|
|
188
|
+
return [sabLoad(header5, SAB_I_BLOCKED), sabLoad(header5, SAB_I_BLOCKED_HI)];
|
|
189
|
+
}
|
|
190
|
+
function storeBlocked(header5, [low, high]) {
|
|
191
|
+
sabStore(header5, SAB_I_BLOCKED_HI, high);
|
|
192
|
+
sabStore(header5, SAB_I_BLOCKED, low);
|
|
193
|
+
}
|
|
194
|
+
var anyBlocked = (mask) => mask !== void 0 && (mask[0] !== 0 || mask[1] !== 0);
|
|
195
|
+
var U32 = 2 ** 32;
|
|
196
|
+
function storeU53(header5, lo, hi, value2) {
|
|
197
|
+
sabStore(header5, hi, Math.floor(value2 / U32));
|
|
198
|
+
sabStore(header5, lo, value2 % U32 | 0);
|
|
199
|
+
}
|
|
200
|
+
function loadU53(header5, lo, hi) {
|
|
201
|
+
return (sabLoad(header5, lo) >>> 0) + sabLoad(header5, hi) * U32;
|
|
202
|
+
}
|
|
203
|
+
var SAB_STATE_IDLE = 0;
|
|
204
|
+
var SAB_STATE_PENDING = 1;
|
|
205
|
+
var SAB_STATE_READY = 2;
|
|
206
|
+
var SAB_STATUS_BYTES = 1;
|
|
207
|
+
var SAB_STATUS_JSON = 2;
|
|
208
|
+
var SAB_STATUS_VOID = 3;
|
|
209
|
+
var SAB_STATUS_ERRNO = 4;
|
|
210
|
+
var SAB_DEFAULT_WINDOW_BYTES = 1024 * 1024;
|
|
211
|
+
var SAB_MIN_BYTES = SAB_HEADER_BYTES + 4096;
|
|
212
|
+
var SYNC_SAB_REQ_MSG = "sync-sab-req";
|
|
213
|
+
var SYNC_SAB_NEXT_MSG = "sync-sab-next";
|
|
214
|
+
var encoder = new TextEncoder();
|
|
215
|
+
var decoder = new TextDecoder();
|
|
216
|
+
function encodeSabResult(result) {
|
|
217
|
+
if (!result.ok) {
|
|
218
|
+
return {
|
|
219
|
+
status: SAB_STATUS_ERRNO,
|
|
220
|
+
payload: encoder.encode(
|
|
221
|
+
JSON.stringify({
|
|
222
|
+
errno: result.errno,
|
|
223
|
+
message: result.message,
|
|
224
|
+
...result.direct ? { direct: true } : {},
|
|
225
|
+
...result.dev !== void 0 ? { dev: result.dev } : {},
|
|
226
|
+
...result.detail ? { detail: result.detail } : {}
|
|
227
|
+
})
|
|
228
|
+
)
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
switch (result.kind) {
|
|
232
|
+
case "bytes":
|
|
233
|
+
return { status: SAB_STATUS_BYTES, payload: result.bytes };
|
|
234
|
+
case "json":
|
|
235
|
+
return { status: SAB_STATUS_JSON, payload: encoder.encode(JSON.stringify(result.json)) };
|
|
236
|
+
default:
|
|
237
|
+
return { status: SAB_STATUS_VOID, payload: new Uint8Array(0) };
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function decodeSabResult(status, payload) {
|
|
241
|
+
switch (status) {
|
|
242
|
+
case SAB_STATUS_BYTES:
|
|
243
|
+
return { ok: true, kind: "bytes", bytes: payload };
|
|
244
|
+
case SAB_STATUS_VOID:
|
|
245
|
+
return { ok: true, kind: "void" };
|
|
246
|
+
case SAB_STATUS_JSON: {
|
|
247
|
+
try {
|
|
248
|
+
return { ok: true, kind: "json", json: JSON.parse(decodeText.call(decoder, payload)) };
|
|
249
|
+
} catch {
|
|
250
|
+
return { ok: false, errno: "EIO", message: "sync-sab: malformed json payload" };
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
case SAB_STATUS_ERRNO: {
|
|
254
|
+
try {
|
|
255
|
+
const parsed3 = JSON.parse(decodeText.call(decoder, payload));
|
|
256
|
+
const errno3 = typeof parsed3.errno === "string" && /^E[A-Z]+$|^EAI_[A-Z]+$/.test(parsed3.errno) ? parsed3.errno : "EIO";
|
|
257
|
+
const message3 = String(parsed3.message ?? errno3);
|
|
258
|
+
return {
|
|
259
|
+
ok: false,
|
|
260
|
+
errno: errno3,
|
|
261
|
+
message: message3,
|
|
262
|
+
...parsed3.direct === true ? { direct: true } : {},
|
|
263
|
+
...typeof parsed3.dev === "string" ? { dev: parsed3.dev } : {},
|
|
264
|
+
...parsed3.detail === "transport" || parsed3.detail === "placeholder" || parsed3.detail === "forbidden-header" ? { detail: parsed3.detail } : {}
|
|
265
|
+
};
|
|
266
|
+
} catch {
|
|
267
|
+
return { ok: false, errno: "EIO", message: "sync-sab: malformed errno payload" };
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
default:
|
|
271
|
+
return { ok: false, errno: "EIO", message: `sync-sab: unknown status ${status}` };
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function sabViews(sab) {
|
|
275
|
+
if (sab.byteLength < SAB_MIN_BYTES) {
|
|
276
|
+
throw new Error(`sync-sab: buffer too small (${sab.byteLength} < ${SAB_MIN_BYTES})`);
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
header: new Int32Array(sab, 0, SAB_HEADER_I32),
|
|
280
|
+
window: new Uint8Array(sab, SAB_HEADER_BYTES)
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// src/async/header-hook.ts
|
|
285
|
+
var watchers = /* @__PURE__ */ new WeakMap();
|
|
286
|
+
var watching = 0;
|
|
287
|
+
function watchHeader(sab, watcher) {
|
|
288
|
+
if (!watchers.has(sab)) watching++;
|
|
289
|
+
watchers.set(sab, watcher);
|
|
290
|
+
return () => {
|
|
291
|
+
if (watchers.get(sab) !== watcher) return;
|
|
292
|
+
watchers.delete(sab);
|
|
293
|
+
watching--;
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function headerNotified(header5, index, bits2 = 0) {
|
|
297
|
+
if (watching === 0) return;
|
|
298
|
+
watchers.get(header5.buffer)?.(index, bits2);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// src/async/wire.ts
|
|
302
|
+
var ASYNC_SYSCALL = "async-syscall";
|
|
303
|
+
var ASYNC_MORE = "async-more";
|
|
304
|
+
var ASYNC_STAGE = "async-stage";
|
|
305
|
+
var ASYNC_WORDS = "async-words";
|
|
306
|
+
var ASYNC_MIRROR = "async-mirror";
|
|
307
|
+
var ASYNC_SNAPSHOT = "async-snapshot";
|
|
308
|
+
var ASYNC_SNAPSHOT_TAKEN = "async-snapshot-taken";
|
|
309
|
+
function diffRuns(last, now) {
|
|
310
|
+
const out = [];
|
|
311
|
+
const length2 = now.length;
|
|
312
|
+
let i = 0;
|
|
313
|
+
while (i < length2) {
|
|
314
|
+
if (now[i] === last[i]) {
|
|
315
|
+
i++;
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
const start2 = i;
|
|
319
|
+
const at = out.length;
|
|
320
|
+
out.push(start2, 0);
|
|
321
|
+
while (i < length2) {
|
|
322
|
+
const next3 = now[i];
|
|
323
|
+
if (next3 === last[i]) break;
|
|
324
|
+
last[i] = next3;
|
|
325
|
+
out.push(next3);
|
|
326
|
+
i++;
|
|
327
|
+
}
|
|
328
|
+
out[at + 1] = i - start2;
|
|
329
|
+
}
|
|
330
|
+
return out.length === 0 ? void 0 : Int32Array.from(out);
|
|
331
|
+
}
|
|
332
|
+
function applyRuns(view2, runs) {
|
|
333
|
+
if (!runs) return;
|
|
334
|
+
let at = 0;
|
|
335
|
+
while (at + 1 < runs.length) {
|
|
336
|
+
const start2 = runs[at];
|
|
337
|
+
const count2 = runs[at + 1];
|
|
338
|
+
at += 2;
|
|
339
|
+
for (let k = 0; k < count2 && start2 + k < view2.length; k++) {
|
|
340
|
+
Atomics.store(view2, start2 + k, runs[at + k]);
|
|
341
|
+
}
|
|
342
|
+
at += count2;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// src/async/remote-worker.ts
|
|
347
|
+
var PART_TTL_MS = 6e4;
|
|
348
|
+
var SNAPSHOT_PART_BYTES = 16 * 2 ** 20;
|
|
349
|
+
var NOT_RUNNABLE = 126;
|
|
350
|
+
var CLOCK_BLOCKED = 0;
|
|
351
|
+
var CLOCK_IDLE = 1;
|
|
352
|
+
var ASYNC_NO_JS = "the async process host runs no JS programs";
|
|
353
|
+
var ASYNC_NO_THREADS = "the async process host runs no threads";
|
|
354
|
+
function defaultImage(program) {
|
|
355
|
+
const image = program.module?.image;
|
|
356
|
+
return typeof image === "string" ? image : void 0;
|
|
357
|
+
}
|
|
358
|
+
function mirrorOf(sab) {
|
|
359
|
+
if (!sab) return void 0;
|
|
360
|
+
const view2 = new Int32Array(sab);
|
|
361
|
+
return { view: view2, last: new Int32Array(view2.length) };
|
|
362
|
+
}
|
|
363
|
+
function initial(mirror) {
|
|
364
|
+
if (!mirror) return void 0;
|
|
365
|
+
return {
|
|
366
|
+
bytes: mirror.view.byteLength,
|
|
367
|
+
runs: diffRuns(mirror.last, mirror.view) ?? new Int32Array(0)
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
var KernelSide = class {
|
|
371
|
+
header;
|
|
372
|
+
window;
|
|
373
|
+
clock;
|
|
374
|
+
changes;
|
|
375
|
+
cwds;
|
|
376
|
+
unwatch;
|
|
377
|
+
history = [];
|
|
378
|
+
raised = { signals: 0, timers: 0 };
|
|
379
|
+
sent = { killed: 0, async: 0, stop: 0, clock: 0 };
|
|
380
|
+
seq = 0;
|
|
381
|
+
words = 0;
|
|
382
|
+
requests = 0;
|
|
383
|
+
parts = /* @__PURE__ */ new Map();
|
|
384
|
+
stages = /* @__PURE__ */ new Map();
|
|
385
|
+
nextPart = 0;
|
|
386
|
+
current;
|
|
387
|
+
pushing = false;
|
|
388
|
+
pumping = false;
|
|
389
|
+
ended = false;
|
|
390
|
+
max;
|
|
391
|
+
emit;
|
|
392
|
+
push;
|
|
393
|
+
constructor(init, max, emit, push) {
|
|
394
|
+
const { header: header5, window } = sabViews(init.sab);
|
|
395
|
+
this.header = header5;
|
|
396
|
+
this.window = window;
|
|
397
|
+
this.clock = new BigInt64Array(init.sab, SAB_CLOCK_OFFSET, SAB_CLOCK_I64);
|
|
398
|
+
this.changes = mirrorOf(init.changes);
|
|
399
|
+
this.cwds = mirrorOf(init.held?.sab);
|
|
400
|
+
this.max = max;
|
|
401
|
+
this.emit = emit;
|
|
402
|
+
this.push = push;
|
|
403
|
+
this.unwatch = watchHeader(init.sab, (index, bits2) => this.notified(index, bits2));
|
|
404
|
+
this.sent = this.words4();
|
|
405
|
+
}
|
|
406
|
+
wire(init, image) {
|
|
407
|
+
const { sab: _sab, changes: _changes, held, program, fork, ...rest2 } = init;
|
|
408
|
+
const { module: _module, ...shown2 } = program;
|
|
409
|
+
const memory = fork?.memory;
|
|
410
|
+
let forkWire;
|
|
411
|
+
if (fork && memory && memory.byteLength > this.max) {
|
|
412
|
+
forkWire = { ...fork, memory: { part: this.keep(memory.slice()), total: memory.byteLength } };
|
|
413
|
+
} else if (fork) forkWire = fork;
|
|
414
|
+
const changes = initial(this.changes);
|
|
415
|
+
const cwds = initial(this.cwds);
|
|
416
|
+
return {
|
|
417
|
+
...rest2,
|
|
418
|
+
program: { ...shown2, image },
|
|
419
|
+
...held ? { held: { slot: held.slot, seen: held.seen, dead: held.dead } } : {},
|
|
420
|
+
...forkWire ? { fork: forkWire } : {},
|
|
421
|
+
...Number.isFinite(this.max) ? { maxMessageBytes: this.max } : {},
|
|
422
|
+
mirror: {
|
|
423
|
+
seq: 0,
|
|
424
|
+
header: Int32Array.from(this.header),
|
|
425
|
+
clock: [
|
|
426
|
+
Number(Atomics.load(this.clock, CLOCK_BLOCKED)),
|
|
427
|
+
Number(Atomics.load(this.clock, CLOCK_IDLE))
|
|
428
|
+
],
|
|
429
|
+
...changes ? { changes } : {},
|
|
430
|
+
...cwds ? { cwds } : {}
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
words4() {
|
|
435
|
+
return {
|
|
436
|
+
killed: Atomics.load(this.header, SAB_I_KILLED),
|
|
437
|
+
async: Atomics.load(this.header, SAB_I_ASYNC),
|
|
438
|
+
stop: Atomics.load(this.header, SAB_I_STOP),
|
|
439
|
+
clock: Number(Atomics.load(this.clock, CLOCK_BLOCKED))
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
notified(index, bits2) {
|
|
443
|
+
if (this.ended) return;
|
|
444
|
+
if (index === SAB_I_PUB) {
|
|
445
|
+
this.schedulePump();
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
if (index === SAB_I_SIGNALS) this.raised.signals |= bits2;
|
|
449
|
+
else if (index === SAB_I_TIMERS) this.raised.timers |= bits2;
|
|
450
|
+
this.schedulePush();
|
|
451
|
+
}
|
|
452
|
+
schedulePush() {
|
|
453
|
+
if (this.pushing) return;
|
|
454
|
+
this.pushing = true;
|
|
455
|
+
queueMicrotask(() => {
|
|
456
|
+
this.pushing = false;
|
|
457
|
+
if (this.ended) return;
|
|
458
|
+
const mirror = this.mirror(false);
|
|
459
|
+
if (mirror) this.push({ type: ASYNC_MIRROR, mirror });
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
mirror(always) {
|
|
463
|
+
const now = this.words4();
|
|
464
|
+
const { signals, timers } = this.raised;
|
|
465
|
+
const changes = this.changes ? diffRuns(this.changes.last, this.changes.view) : void 0;
|
|
466
|
+
const cwds = this.cwds ? diffRuns(this.cwds.last, this.cwds.view) : void 0;
|
|
467
|
+
const same2 = now.killed === this.sent.killed && now.async === this.sent.async && now.stop === this.sent.stop && now.clock === this.sent.clock;
|
|
468
|
+
if (!always && same2 && signals === 0 && timers === 0 && !changes && !cwds) return void 0;
|
|
469
|
+
const seq2 = ++this.seq;
|
|
470
|
+
this.raised = { signals: 0, timers: 0 };
|
|
471
|
+
this.sent = now;
|
|
472
|
+
if (signals !== 0 || timers !== 0) this.history.push({ seq: seq2, signals, timers });
|
|
473
|
+
return {
|
|
474
|
+
seq: seq2,
|
|
475
|
+
signals,
|
|
476
|
+
timers,
|
|
477
|
+
...now,
|
|
478
|
+
...changes ? { changes } : {},
|
|
479
|
+
...cwds ? { cwds } : {}
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
applyWords(words3) {
|
|
483
|
+
if (!words3 || typeof words3.n !== "number" || words3.n <= this.words) return;
|
|
484
|
+
this.words = words3.n;
|
|
485
|
+
while (this.history.length > 0 && (this.history[0]?.seq ?? 0) <= words3.seen) {
|
|
486
|
+
this.history.shift();
|
|
487
|
+
}
|
|
488
|
+
let signals = words3.signals | this.raised.signals;
|
|
489
|
+
let timers = words3.timers | this.raised.timers;
|
|
490
|
+
for (const entry of this.history) {
|
|
491
|
+
signals |= entry.signals;
|
|
492
|
+
timers |= entry.timers;
|
|
493
|
+
}
|
|
494
|
+
Atomics.store(this.header, SAB_I_SIGNALS, signals);
|
|
495
|
+
Atomics.store(this.header, SAB_I_TIMERS, timers);
|
|
496
|
+
storeBlocked(this.header, words3.blocked);
|
|
497
|
+
Atomics.store(this.header, SAB_I_MEMORY, words3.memory);
|
|
498
|
+
Atomics.store(this.clock, CLOCK_IDLE, BigInt(words3.idle));
|
|
499
|
+
}
|
|
500
|
+
keep(bytes) {
|
|
501
|
+
const id2 = ++this.nextPart;
|
|
502
|
+
const timer = setTimeout(() => this.parts.delete(id2), PART_TTL_MS);
|
|
503
|
+
this.parts.set(id2, { bytes, timer });
|
|
504
|
+
return id2;
|
|
505
|
+
}
|
|
506
|
+
more(msg) {
|
|
507
|
+
const part = this.parts.get(msg.part);
|
|
508
|
+
if (!part || !Number.isInteger(msg.offset) || msg.offset < 0) {
|
|
509
|
+
throw new Error("async: unknown or expired answer part");
|
|
510
|
+
}
|
|
511
|
+
const end = Math.min(part.bytes.length, msg.offset + this.max);
|
|
512
|
+
const bytes = part.bytes.slice(msg.offset, end);
|
|
513
|
+
if (end >= part.bytes.length) {
|
|
514
|
+
clearTimeout(part.timer);
|
|
515
|
+
this.parts.delete(msg.part);
|
|
516
|
+
} else {
|
|
517
|
+
clearTimeout(part.timer);
|
|
518
|
+
part.timer = setTimeout(() => this.parts.delete(msg.part), PART_TTL_MS);
|
|
519
|
+
}
|
|
520
|
+
return { bytes };
|
|
521
|
+
}
|
|
522
|
+
stage(msg) {
|
|
523
|
+
let into = this.stages.get(msg.stage);
|
|
524
|
+
if (!into) {
|
|
525
|
+
into = new Uint8Array(msg.total);
|
|
526
|
+
this.stages.set(msg.stage, into);
|
|
527
|
+
}
|
|
528
|
+
into.set(msg.bytes, msg.offset);
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
syscall(msg) {
|
|
532
|
+
if (this.ended) return Promise.resolve({ failed: "terminated" });
|
|
533
|
+
this.current?.resolve({ failed: "superseded" });
|
|
534
|
+
this.current = void 0;
|
|
535
|
+
this.applyWords(msg.words);
|
|
536
|
+
let req = msg.req;
|
|
537
|
+
if (msg.staged !== void 0) {
|
|
538
|
+
const body = this.stages.get(msg.staged);
|
|
539
|
+
this.stages.delete(msg.staged);
|
|
540
|
+
if (!body) return Promise.resolve({ failed: "unknown staged body" });
|
|
541
|
+
req = { ...req, body };
|
|
542
|
+
}
|
|
543
|
+
const id2 = ++this.requests;
|
|
544
|
+
const { promise, resolve: resolve2 } = Promise.withResolvers();
|
|
545
|
+
this.current = { id: id2, resolve: resolve2, out: null, status: 0, offset: 0 };
|
|
546
|
+
Atomics.store(this.header, SAB_I_REQ, id2);
|
|
547
|
+
Atomics.store(this.header, SAB_I_STATE, SAB_STATE_PENDING);
|
|
548
|
+
this.emit({ type: SYNC_SAB_REQ_MSG, id: id2, req });
|
|
549
|
+
return promise;
|
|
550
|
+
}
|
|
551
|
+
schedulePump() {
|
|
552
|
+
if (this.pumping) return;
|
|
553
|
+
this.pumping = true;
|
|
554
|
+
queueMicrotask(() => {
|
|
555
|
+
this.pumping = false;
|
|
556
|
+
this.pump();
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
pump() {
|
|
560
|
+
const pending = this.current;
|
|
561
|
+
if (this.ended || !pending) return;
|
|
562
|
+
const { header: header5 } = this;
|
|
563
|
+
if (Atomics.load(header5, SAB_I_STATE) !== SAB_STATE_READY) return;
|
|
564
|
+
if (Atomics.load(header5, SAB_I_SEQ) !== pending.id) return;
|
|
565
|
+
const total = loadU53(header5, SAB_I_TOTAL, SAB_I_TOTAL_HI);
|
|
566
|
+
const chunk2 = Atomics.load(header5, SAB_I_CHUNK);
|
|
567
|
+
const at = loadU53(header5, SAB_I_OFFSET, SAB_I_OFFSET_HI);
|
|
568
|
+
if (at !== pending.offset || chunk2 < 0 || total < 0 || at + chunk2 > total) {
|
|
569
|
+
this.answer(pending, encodeSabResult({ ok: false, errno: "EIO", message: "async: torn" }));
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
if (pending.out === null) {
|
|
573
|
+
pending.status = Atomics.load(header5, SAB_I_STATUS);
|
|
574
|
+
pending.out = new Uint8Array(total);
|
|
575
|
+
}
|
|
576
|
+
pending.out.set(this.window.subarray(0, chunk2), at);
|
|
577
|
+
pending.offset += chunk2;
|
|
578
|
+
if (pending.offset >= total) {
|
|
579
|
+
this.answer(pending, { status: pending.status, payload: pending.out });
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
if (chunk2 === 0) {
|
|
583
|
+
this.answer(pending, encodeSabResult({ ok: false, errno: "EIO", message: "async: stall" }));
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
Atomics.store(header5, SAB_I_STATE, SAB_STATE_PENDING);
|
|
587
|
+
this.emit({ type: SYNC_SAB_NEXT_MSG, id: pending.id, offset: pending.offset });
|
|
588
|
+
}
|
|
589
|
+
answer(pending, { status, payload }) {
|
|
590
|
+
if (this.current === pending) this.current = void 0;
|
|
591
|
+
Atomics.store(this.header, SAB_I_REQ, 0);
|
|
592
|
+
Atomics.store(this.header, SAB_I_STATE, SAB_STATE_IDLE);
|
|
593
|
+
const mirror = this.mirror(true);
|
|
594
|
+
const total = payload.byteLength;
|
|
595
|
+
const reply = total > this.max ? {
|
|
596
|
+
status,
|
|
597
|
+
bytes: payload.slice(0, this.max),
|
|
598
|
+
total,
|
|
599
|
+
part: this.keep(payload),
|
|
600
|
+
mirror
|
|
601
|
+
} : { status, bytes: payload, total, mirror };
|
|
602
|
+
pending.resolve(reply);
|
|
603
|
+
}
|
|
604
|
+
end() {
|
|
605
|
+
if (this.ended) return;
|
|
606
|
+
this.ended = true;
|
|
607
|
+
this.unwatch();
|
|
608
|
+
this.current?.resolve({ failed: "terminated" });
|
|
609
|
+
this.current = void 0;
|
|
610
|
+
for (const part of this.parts.values()) clearTimeout(part.timer);
|
|
611
|
+
this.parts.clear();
|
|
612
|
+
this.stages.clear();
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
function refusal(init) {
|
|
616
|
+
const type = init.type;
|
|
617
|
+
if (type === WASM_THREAD_INIT || type === JS_THREAD_INIT) return ASYNC_NO_THREADS;
|
|
618
|
+
if (type !== WASM_PROCESS_INIT) return "the async process host got no process init";
|
|
619
|
+
if (init.program?.abi === "js") return ASYNC_NO_JS;
|
|
620
|
+
return void 0;
|
|
621
|
+
}
|
|
622
|
+
function remoteWorker(open, options = {}) {
|
|
623
|
+
const max = options.maxMessageBytes ?? Number.POSITIVE_INFINITY;
|
|
624
|
+
const imageOf = options.image ?? defaultImage;
|
|
625
|
+
const messages = /* @__PURE__ */ new Set();
|
|
626
|
+
const errors = /* @__PURE__ */ new Set();
|
|
627
|
+
let started = false;
|
|
628
|
+
let ended = false;
|
|
629
|
+
let exited = false;
|
|
630
|
+
let link2;
|
|
631
|
+
let side;
|
|
632
|
+
const emit = (data) => {
|
|
633
|
+
if (ended) return;
|
|
634
|
+
for (const handler of [...messages]) handler({ data });
|
|
635
|
+
};
|
|
636
|
+
const fail3 = (message3) => {
|
|
637
|
+
if (ended || exited) return;
|
|
638
|
+
for (const handler of [...errors]) {
|
|
639
|
+
handler({ message: message3, preventDefault() {
|
|
640
|
+
} });
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
const refuse2 = (message3, code) => {
|
|
644
|
+
queueMicrotask(
|
|
645
|
+
() => emit({ type: WASM_PROCESS_ERROR, message: message3, ...code === void 0 ? {} : { code } })
|
|
646
|
+
);
|
|
647
|
+
};
|
|
648
|
+
const fromProcess = (message3) => {
|
|
649
|
+
if (ended) return;
|
|
650
|
+
const data = message3;
|
|
651
|
+
const type = data?.type;
|
|
652
|
+
if (type === ASYNC_WORDS) {
|
|
653
|
+
if (data?.words) side?.applyWords(data.words);
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
if (type === WASM_THREAD_SPAWN || type === JS_THREAD_SPAWN) {
|
|
657
|
+
emit({ type: WASM_PROCESS_ERROR, message: ASYNC_NO_THREADS });
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
if (type === WASM_PROCESS_EXIT) exited = true;
|
|
661
|
+
emit(message3);
|
|
662
|
+
};
|
|
663
|
+
const snapshotPart = async (msg) => {
|
|
664
|
+
if (!options.snapshot) throw new Error("async: this kernel keeps no fork snapshots");
|
|
665
|
+
const limit = Number.isFinite(max) ? max : SNAPSHOT_PART_BYTES;
|
|
666
|
+
return { bytes: await options.snapshot(msg.token, msg.offset, limit) };
|
|
667
|
+
};
|
|
668
|
+
const answer2 = async (message3) => {
|
|
669
|
+
const data = message3;
|
|
670
|
+
if (!side) return { failed: "terminated" };
|
|
671
|
+
switch (data?.type) {
|
|
672
|
+
case ASYNC_SYSCALL:
|
|
673
|
+
return side.syscall(data);
|
|
674
|
+
case ASYNC_MORE:
|
|
675
|
+
return side.more(data);
|
|
676
|
+
case ASYNC_STAGE:
|
|
677
|
+
return side.stage(data);
|
|
678
|
+
case ASYNC_SNAPSHOT:
|
|
679
|
+
return snapshotPart(data);
|
|
680
|
+
default:
|
|
681
|
+
throw new Error(`async: unknown call ${String(data?.type)}`);
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
const start2 = async (init) => {
|
|
685
|
+
const image = imageOf(init.program);
|
|
686
|
+
if (image === void 0) {
|
|
687
|
+
refuse2("the async process host needs a program image id", NOT_RUNNABLE);
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
const kernel = new KernelSide(init, max, emit, (msg) => link2?.post(msg));
|
|
691
|
+
side = kernel;
|
|
692
|
+
const wire = kernel.wire(init, image);
|
|
693
|
+
let opened2;
|
|
694
|
+
try {
|
|
695
|
+
opened2 = await open(wire);
|
|
696
|
+
} catch (err) {
|
|
697
|
+
kernel.end();
|
|
698
|
+
queueMicrotask(() => fail3(err instanceof Error ? err.message : String(err)));
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
if (ended) {
|
|
702
|
+
opened2.close();
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
link2 = opened2;
|
|
706
|
+
opened2.onClose((reason) => {
|
|
707
|
+
if (ended) return;
|
|
708
|
+
kernel.end();
|
|
709
|
+
fail3(`the async process link closed: ${reason}`);
|
|
710
|
+
});
|
|
711
|
+
opened2.onPost(fromProcess);
|
|
712
|
+
opened2.onCall(answer2);
|
|
713
|
+
opened2.post(wire);
|
|
714
|
+
};
|
|
715
|
+
return {
|
|
716
|
+
postMessage(message3) {
|
|
717
|
+
if (started || ended) return;
|
|
718
|
+
started = true;
|
|
719
|
+
const refused5 = refusal(message3);
|
|
720
|
+
if (refused5) {
|
|
721
|
+
refuse2(refused5, refused5 === ASYNC_NO_JS ? NOT_RUNNABLE : void 0);
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
void start2(message3);
|
|
725
|
+
},
|
|
726
|
+
addEventListener(type, handler) {
|
|
727
|
+
(type === "error" ? errors : messages).add(handler);
|
|
728
|
+
},
|
|
729
|
+
removeEventListener(type, handler) {
|
|
730
|
+
(type === "error" ? errors : messages).delete(handler);
|
|
731
|
+
},
|
|
732
|
+
terminate() {
|
|
733
|
+
if (ended) return;
|
|
734
|
+
ended = true;
|
|
735
|
+
side?.end();
|
|
736
|
+
link2?.close();
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// src/async/node-host.ts
|
|
742
|
+
var TERMINATED = "the kernel is terminated";
|
|
743
|
+
var THREAD_BOOT = `(async () => {
|
|
744
|
+
const { workerData } = require('node:worker_threads');
|
|
745
|
+
const { messageLinks } = await import(workerData.links);
|
|
746
|
+
const loaded = await import(workerData.entry);
|
|
747
|
+
const entry = loaded.asyncProcessEntry ?? loaded.default;
|
|
748
|
+
if (typeof entry !== 'function') throw new Error('async process entry exports no asyncProcessEntry');
|
|
749
|
+
const modules = workerData.modules;
|
|
750
|
+
const waiting = new Map();
|
|
751
|
+
let next = 0;
|
|
752
|
+
modules.on('message', ({ id, module, error }) => {
|
|
753
|
+
const pending = waiting.get(id);
|
|
754
|
+
if (!pending) return;
|
|
755
|
+
waiting.delete(id);
|
|
756
|
+
if (module) pending.resolve(module);
|
|
757
|
+
else pending.reject(new Error(error));
|
|
758
|
+
});
|
|
759
|
+
modules.unref();
|
|
760
|
+
const module = (image) =>
|
|
761
|
+
new Promise((resolve, reject) => {
|
|
762
|
+
const id = ++next;
|
|
763
|
+
waiting.set(id, { resolve, reject });
|
|
764
|
+
modules.ref();
|
|
765
|
+
modules.postMessage({ id, image });
|
|
766
|
+
}).finally(() => {
|
|
767
|
+
if (waiting.size === 0) modules.unref();
|
|
768
|
+
});
|
|
769
|
+
entry(messageLinks(workerData.link).kernel, { module });
|
|
770
|
+
})().catch((err) => {
|
|
771
|
+
setImmediate(() => {
|
|
772
|
+
throw err;
|
|
773
|
+
});
|
|
774
|
+
});`;
|
|
775
|
+
function portOf(port) {
|
|
776
|
+
return port;
|
|
777
|
+
}
|
|
778
|
+
function imageRegistry() {
|
|
779
|
+
const images = /* @__PURE__ */ new Map();
|
|
780
|
+
const ids = /* @__PURE__ */ new WeakMap();
|
|
781
|
+
return {
|
|
782
|
+
async compile(bytes) {
|
|
783
|
+
const module = await WebAssembly.compile(bytes);
|
|
784
|
+
const id2 = `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
|
|
785
|
+
images.set(id2, module);
|
|
786
|
+
ids.set(module, id2);
|
|
787
|
+
return module;
|
|
788
|
+
},
|
|
789
|
+
image: (program) => ids.get(program.module),
|
|
790
|
+
module(image) {
|
|
791
|
+
const module = images.get(image);
|
|
792
|
+
if (!module) throw new Error(`no program image ${image}`);
|
|
793
|
+
return module;
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
function inlineOpen(entry, deps) {
|
|
798
|
+
return () => {
|
|
799
|
+
const { port1, port2 } = new MessageChannel2();
|
|
800
|
+
const kernelEnd = messageLinks(portOf(port1));
|
|
801
|
+
const processEnd = messageLinks(portOf(port2));
|
|
802
|
+
queueMicrotask(() => entry(processEnd.kernel, deps));
|
|
803
|
+
return kernelEnd.process;
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
function threadOpen(entry, modules) {
|
|
807
|
+
const links = new URL("./node.js", import.meta.url).href;
|
|
808
|
+
return () => {
|
|
809
|
+
const link2 = new MessageChannel2();
|
|
810
|
+
const images = new MessageChannel2();
|
|
811
|
+
const worker = new Worker(THREAD_BOOT, {
|
|
812
|
+
eval: true,
|
|
813
|
+
workerData: { entry, links, link: link2.port2, modules: images.port2 },
|
|
814
|
+
transferList: [link2.port2, images.port2]
|
|
815
|
+
});
|
|
816
|
+
const ends = messageLinks(portOf(link2.port1));
|
|
817
|
+
images.port1.on("message", ({ id: id2, image }) => {
|
|
818
|
+
try {
|
|
819
|
+
images.port1.postMessage({ id: id2, module: modules(image) });
|
|
820
|
+
} catch (err) {
|
|
821
|
+
images.port1.postMessage({ id: id2, error: err instanceof Error ? err.message : String(err) });
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
let gone = false;
|
|
825
|
+
const stop = (reason) => {
|
|
826
|
+
if (gone) return;
|
|
827
|
+
gone = true;
|
|
828
|
+
images.port1.close();
|
|
829
|
+
ends.close(reason);
|
|
830
|
+
void worker.terminate();
|
|
831
|
+
};
|
|
832
|
+
worker.on("error", (err) => stop(`the process worker failed: ${String(err)}`));
|
|
833
|
+
worker.on("exit", (code) => stop(`the process worker exited with ${code}`));
|
|
834
|
+
return {
|
|
835
|
+
post: ends.process.post,
|
|
836
|
+
onPost: ends.process.onPost,
|
|
837
|
+
onCall: ends.process.onCall,
|
|
838
|
+
onClose: ends.process.onClose,
|
|
839
|
+
close: () => stop("closed")
|
|
840
|
+
};
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
function entryUrl(entry) {
|
|
844
|
+
if (entry === void 0) return new URL("./async-process.js", import.meta.url).href;
|
|
845
|
+
return entry instanceof URL ? entry.href : new URL(entry, `file://${process.cwd()}/`).href;
|
|
846
|
+
}
|
|
847
|
+
function nodeAsyncHost(options, live2) {
|
|
848
|
+
const registry2 = imageRegistry();
|
|
849
|
+
const deps = { module: (image) => registry2.module(image) };
|
|
850
|
+
const open = options.inline ? inlineOpen(options.inline, deps) : threadOpen(entryUrl(options.entry), (image) => registry2.module(image));
|
|
851
|
+
const settings = {
|
|
852
|
+
image: registry2.image,
|
|
853
|
+
...options.maxMessageBytes !== void 0 ? { maxMessageBytes: options.maxMessageBytes } : {}
|
|
854
|
+
};
|
|
855
|
+
return {
|
|
856
|
+
compile: (bytes) => registry2.compile(bytes),
|
|
857
|
+
createWorker(closed) {
|
|
858
|
+
const errors = /* @__PURE__ */ new Set();
|
|
859
|
+
const fail3 = (message3) => {
|
|
860
|
+
for (const handler of [...errors]) {
|
|
861
|
+
handler({ message: message3, preventDefault() {
|
|
862
|
+
} });
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
if (closed) {
|
|
866
|
+
setTimeout(() => fail3(TERMINATED), 0);
|
|
867
|
+
return {
|
|
868
|
+
postMessage() {
|
|
869
|
+
},
|
|
870
|
+
addEventListener: (type, handler) => void (type === "error" && errors.add(handler)),
|
|
871
|
+
removeEventListener: (_type, handler) => void errors.delete(handler),
|
|
872
|
+
terminate() {
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
const worker = remoteWorker(open, settings);
|
|
877
|
+
const kill = () => {
|
|
878
|
+
worker.terminate();
|
|
879
|
+
fail3(TERMINATED);
|
|
880
|
+
};
|
|
881
|
+
live2.add(kill);
|
|
882
|
+
return {
|
|
883
|
+
postMessage: (message3, transfer) => worker.postMessage(message3, transfer),
|
|
884
|
+
addEventListener(type, handler) {
|
|
885
|
+
if (type === "error") errors.add(handler);
|
|
886
|
+
worker.addEventListener(type, handler);
|
|
887
|
+
},
|
|
888
|
+
removeEventListener(type, handler) {
|
|
889
|
+
errors.delete(handler);
|
|
890
|
+
worker.removeEventListener(type, handler);
|
|
891
|
+
},
|
|
892
|
+
terminate() {
|
|
893
|
+
live2.delete(kill);
|
|
894
|
+
worker.terminate();
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
}
|
|
7
900
|
|
|
8
901
|
// src/bytes.ts
|
|
9
902
|
function fresh(bytes, start2 = 0, end = bytes.length) {
|
|
10
903
|
return new Uint8Array(bytes.subarray(start2, end));
|
|
11
904
|
}
|
|
12
905
|
|
|
906
|
+
// src/ports.ts
|
|
907
|
+
var messageChannel = () => new MessageChannel();
|
|
908
|
+
|
|
13
909
|
// src/cdp/port.ts
|
|
14
910
|
function serveCdpPort(port, hook, request, onDone) {
|
|
15
911
|
let conn;
|
|
@@ -54,9 +950,9 @@ function serveCdpPort(port, hook, request, onDone) {
|
|
|
54
950
|
finish("the CDP host is gone");
|
|
55
951
|
};
|
|
56
952
|
}
|
|
57
|
-
function portCdpHook(ask, gone) {
|
|
953
|
+
function portCdpHook(ask, gone, ports = messageChannel) {
|
|
58
954
|
return (request) => new Promise((resolve2, reject) => {
|
|
59
|
-
const { port1, port2 } =
|
|
955
|
+
const { port1, port2 } = ports();
|
|
60
956
|
let closed = false;
|
|
61
957
|
const conn = {
|
|
62
958
|
send: (m) => {
|
|
@@ -566,9 +1462,9 @@ function serveFacadePort(port, hook, { name: name2, stamp }, onDone) {
|
|
|
566
1462
|
finish();
|
|
567
1463
|
};
|
|
568
1464
|
}
|
|
569
|
-
function portFacadeHook(ask, gone) {
|
|
1465
|
+
function portFacadeHook(ask, gone, ports = messageChannel) {
|
|
570
1466
|
return (stamp, { name: name2 }) => new Promise((resolve2, reject) => {
|
|
571
|
-
const { port1, port2 } =
|
|
1467
|
+
const { port1, port2 } = ports();
|
|
572
1468
|
let closed = false;
|
|
573
1469
|
const shut = () => {
|
|
574
1470
|
closed = true;
|
|
@@ -4021,7 +4917,7 @@ function satisfies(version, range2) {
|
|
|
4021
4917
|
}
|
|
4022
4918
|
|
|
4023
4919
|
// src/version.ts
|
|
4024
|
-
var KERNEL_VERSION = true ? "1.
|
|
4920
|
+
var KERNEL_VERSION = true ? "1.184.1" : "0.0.0-dev";
|
|
4025
4921
|
var OS_RELEASE = "6.0.0-slicc";
|
|
4026
4922
|
function procVersion() {
|
|
4027
4923
|
return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
|
|
@@ -5761,7 +6657,7 @@ var JOBS_PER_USER = 16;
|
|
|
5761
6657
|
var WAKE_MS = 6e4;
|
|
5762
6658
|
var BACK_JUMP_MS = 12e4;
|
|
5763
6659
|
var DEFAULT_SHELL = "/bin/bash";
|
|
5764
|
-
var
|
|
6660
|
+
var encoder2 = new TextEncoder();
|
|
5765
6661
|
var EMPTY_STAMP = JSON.stringify({ jobs: {}, reboot: {}, when: {} });
|
|
5766
6662
|
var messageOf = (err) => err?.message ?? String(err);
|
|
5767
6663
|
var keyOf2 = ({ source, job }) => `${source} ${job.id}`;
|
|
@@ -5983,7 +6879,7 @@ var CronService = class {
|
|
|
5983
6879
|
async error(line) {
|
|
5984
6880
|
if (this.stopping.signal.aborted) return;
|
|
5985
6881
|
const stamp = new Date(this.clock.now()).toISOString();
|
|
5986
|
-
await this.append(ERR_LOG,
|
|
6882
|
+
await this.append(ERR_LOG, encoder2.encode(`${stamp} ${line}
|
|
5987
6883
|
`), 0, 0).catch(() => void 0);
|
|
5988
6884
|
}
|
|
5989
6885
|
async append(path, bytes, uid, gid) {
|
|
@@ -6021,7 +6917,7 @@ var CronService = class {
|
|
|
6021
6917
|
const why = `${JOBS_PER_USER} cron jobs of ${account.name} are running`;
|
|
6022
6918
|
await this.append(
|
|
6023
6919
|
log,
|
|
6024
|
-
|
|
6920
|
+
encoder2.encode(`--- ${iso} skipped: ${why} ---
|
|
6025
6921
|
`),
|
|
6026
6922
|
account.uid,
|
|
6027
6923
|
account.gid
|
|
@@ -6051,7 +6947,7 @@ var CronService = class {
|
|
|
6051
6947
|
...entry.tags ? { tags: entry.tags.tags, tagBase: entry.tags.base } : {}
|
|
6052
6948
|
});
|
|
6053
6949
|
} catch (err) {
|
|
6054
|
-
output.push(
|
|
6950
|
+
output.push(encoder2.encode(`cron: ${messageOf(err)}
|
|
6055
6951
|
`));
|
|
6056
6952
|
ended = { status: 127 };
|
|
6057
6953
|
} finally {
|
|
@@ -6059,10 +6955,10 @@ var CronService = class {
|
|
|
6059
6955
|
}
|
|
6060
6956
|
if (this.stopping.signal.aborted) return;
|
|
6061
6957
|
const exit = ended.signal ? `signal=${ended.signal}` : `exit=${ended.status}`;
|
|
6062
|
-
const header5 =
|
|
6958
|
+
const header5 = encoder2.encode(`--- ${iso} ${exit} missed=${missed} ---
|
|
6063
6959
|
`);
|
|
6064
6960
|
const body = output.bytes();
|
|
6065
|
-
const newline = body.length > 0 && body[body.length - 1] !== 10 ?
|
|
6961
|
+
const newline = body.length > 0 && body[body.length - 1] !== 10 ? encoder2.encode("\n") : new Uint8Array();
|
|
6066
6962
|
await this.append(log, concat2([header5, body, newline]), account.uid, account.gid).catch(
|
|
6067
6963
|
(err) => this.error(messageOf(err))
|
|
6068
6964
|
);
|
|
@@ -8797,12 +9693,12 @@ var ChildTable = class {
|
|
|
8797
9693
|
async nextChange(candidates, flags2, interrupt) {
|
|
8798
9694
|
let wake;
|
|
8799
9695
|
const stateChange = new Promise((resolve2) => wake = resolve2);
|
|
8800
|
-
const
|
|
8801
|
-
if (
|
|
9696
|
+
const watching2 = flags2.untraced || flags2.continued;
|
|
9697
|
+
if (watching2 && wake) this.stateChanged.push(wake);
|
|
8802
9698
|
try {
|
|
8803
9699
|
await Promise.race([
|
|
8804
9700
|
...candidates.map(([, child]) => child.exited),
|
|
8805
|
-
...
|
|
9701
|
+
...watching2 ? [stateChange] : [],
|
|
8806
9702
|
interrupt
|
|
8807
9703
|
]);
|
|
8808
9704
|
} finally {
|
|
@@ -8849,8 +9745,8 @@ var ChildTable = class {
|
|
|
8849
9745
|
// src/kernel/clipboard.ts
|
|
8850
9746
|
var CLIPBOARD_MAX_BYTES = 1024 * 1024;
|
|
8851
9747
|
var CLIPBOARD_TIMEOUT_MS = 1e4;
|
|
8852
|
-
var
|
|
8853
|
-
var
|
|
9748
|
+
var encoder3 = new TextEncoder();
|
|
9749
|
+
var decoder2 = new TextDecoder("utf-8", { fatal: true });
|
|
8854
9750
|
var READY = { readable: true, writable: true, hangup: false };
|
|
8855
9751
|
function lineOf(err) {
|
|
8856
9752
|
const text = err instanceof Error ? err.message : String(err);
|
|
@@ -8917,7 +9813,7 @@ var ClipboardChannel = class {
|
|
|
8917
9813
|
const asked = this.broker.ask(async (hook) => {
|
|
8918
9814
|
const text = await hook.read(stamp);
|
|
8919
9815
|
if (typeof text !== "string") throw new KernelError("EIO", "the clipboard gave no text");
|
|
8920
|
-
return
|
|
9816
|
+
return encoder3.encode(text);
|
|
8921
9817
|
});
|
|
8922
9818
|
this.snapshot = asked;
|
|
8923
9819
|
asked.then(
|
|
@@ -8965,7 +9861,7 @@ var ClipboardChannel = class {
|
|
|
8965
9861
|
this.size = 0;
|
|
8966
9862
|
let text;
|
|
8967
9863
|
try {
|
|
8968
|
-
text =
|
|
9864
|
+
text = decoder2.decode(bytes);
|
|
8969
9865
|
} catch {
|
|
8970
9866
|
throw new KernelError("EILSEQ", "the text is not valid UTF-8");
|
|
8971
9867
|
}
|
|
@@ -9654,7 +10550,7 @@ function defaultTermios() {
|
|
|
9654
10550
|
c_cc: cCc
|
|
9655
10551
|
};
|
|
9656
10552
|
}
|
|
9657
|
-
var
|
|
10553
|
+
var encoder4 = new TextEncoder();
|
|
9658
10554
|
function isContinuation(byte) {
|
|
9659
10555
|
return (byte & 192) === 128;
|
|
9660
10556
|
}
|
|
@@ -9781,7 +10677,7 @@ var KernelTty = class {
|
|
|
9781
10677
|
this.line.push(byte);
|
|
9782
10678
|
this.readable.push(Uint8Array.from(this.line));
|
|
9783
10679
|
this.line = [];
|
|
9784
|
-
if (echo) this.output(
|
|
10680
|
+
if (echo) this.output(encoder4.encode("\n"));
|
|
9785
10681
|
} else {
|
|
9786
10682
|
this.line.push(byte);
|
|
9787
10683
|
if (echo) this.echo(byte);
|
|
@@ -9806,7 +10702,7 @@ var KernelTty = class {
|
|
|
9806
10702
|
const utf83 = (this.termios.c_iflag & IUTF8) !== 0;
|
|
9807
10703
|
const cells = utf83 ? dropped2.filter((b) => !isContinuation(b)).length : dropped2.length;
|
|
9808
10704
|
if (cells > 0 && this.termios.c_lflag & ECHO) {
|
|
9809
|
-
this.output(
|
|
10705
|
+
this.output(encoder4.encode("\b \b".repeat(cells)), false);
|
|
9810
10706
|
}
|
|
9811
10707
|
}
|
|
9812
10708
|
echo(byte) {
|
|
@@ -12896,8 +13792,8 @@ async function guarded(entry, path, req) {
|
|
|
12896
13792
|
const paths = await guard(g, path, req, entry.cwd);
|
|
12897
13793
|
return { paths };
|
|
12898
13794
|
} catch (err) {
|
|
12899
|
-
const
|
|
12900
|
-
const refused5 = req.op === "exists" &&
|
|
13795
|
+
const refusal4 = err.code === "EACCES";
|
|
13796
|
+
const refused5 = req.op === "exists" && refusal4 ? json2(false) : toErrno(err);
|
|
12901
13797
|
return { refused: refused5 };
|
|
12902
13798
|
}
|
|
12903
13799
|
}
|
|
@@ -13216,95 +14112,6 @@ async function dispatchPath(entry, req) {
|
|
|
13216
14112
|
}
|
|
13217
14113
|
}
|
|
13218
14114
|
|
|
13219
|
-
// src/realm/sync-sab-wire.ts
|
|
13220
|
-
var atomicLoad = Atomics.load;
|
|
13221
|
-
var atomicStore = Atomics.store;
|
|
13222
|
-
var atomicWaitAsync = Atomics.waitAsync;
|
|
13223
|
-
var setBytes = Uint8Array.prototype.set;
|
|
13224
|
-
var bytesPart = Uint8Array.prototype.subarray;
|
|
13225
|
-
var decodeText = TextDecoder.prototype.decode;
|
|
13226
|
-
var sabLoad = (a, i) => atomicLoad(a, i);
|
|
13227
|
-
var sabStore = (a, i, v) => atomicStore(a, i, v);
|
|
13228
|
-
var SAB_HEADER_I32 = 18;
|
|
13229
|
-
var SAB_CLOCK_OFFSET = SAB_HEADER_I32 * 4;
|
|
13230
|
-
var SAB_CLOCK_I64 = 3;
|
|
13231
|
-
var SAB_HEADER_BYTES = SAB_CLOCK_OFFSET + SAB_CLOCK_I64 * 8;
|
|
13232
|
-
var SAB_I_STATE = 0;
|
|
13233
|
-
var SAB_I_SEQ = 1;
|
|
13234
|
-
var SAB_I_STATUS = 2;
|
|
13235
|
-
var SAB_I_TOTAL = 3;
|
|
13236
|
-
var SAB_I_CHUNK = 4;
|
|
13237
|
-
var SAB_I_OFFSET = 5;
|
|
13238
|
-
var SAB_I_REQ = 6;
|
|
13239
|
-
var SAB_I_PUB = 7;
|
|
13240
|
-
var SAB_I_SIGNALS = 8;
|
|
13241
|
-
var SAB_I_TIMERS = 9;
|
|
13242
|
-
var SAB_I_MEMORY = 10;
|
|
13243
|
-
var SAB_I_TOTAL_HI = 11;
|
|
13244
|
-
var SAB_I_OFFSET_HI = 12;
|
|
13245
|
-
var SAB_I_KILLED = 13;
|
|
13246
|
-
var SAB_I_ASYNC = 14;
|
|
13247
|
-
var SAB_I_STOP = 15;
|
|
13248
|
-
var SAB_I_BLOCKED = 16;
|
|
13249
|
-
var SAB_I_BLOCKED_HI = 17;
|
|
13250
|
-
function loadBlocked(header5) {
|
|
13251
|
-
return [sabLoad(header5, SAB_I_BLOCKED), sabLoad(header5, SAB_I_BLOCKED_HI)];
|
|
13252
|
-
}
|
|
13253
|
-
function storeBlocked(header5, [low, high]) {
|
|
13254
|
-
sabStore(header5, SAB_I_BLOCKED_HI, high);
|
|
13255
|
-
sabStore(header5, SAB_I_BLOCKED, low);
|
|
13256
|
-
}
|
|
13257
|
-
var anyBlocked = (mask) => mask !== void 0 && (mask[0] !== 0 || mask[1] !== 0);
|
|
13258
|
-
var U32 = 2 ** 32;
|
|
13259
|
-
function storeU53(header5, lo, hi, value2) {
|
|
13260
|
-
sabStore(header5, hi, Math.floor(value2 / U32));
|
|
13261
|
-
sabStore(header5, lo, value2 % U32 | 0);
|
|
13262
|
-
}
|
|
13263
|
-
var SAB_STATE_READY = 2;
|
|
13264
|
-
var SAB_STATUS_BYTES = 1;
|
|
13265
|
-
var SAB_STATUS_JSON = 2;
|
|
13266
|
-
var SAB_STATUS_VOID = 3;
|
|
13267
|
-
var SAB_STATUS_ERRNO = 4;
|
|
13268
|
-
var SAB_DEFAULT_WINDOW_BYTES = 1024 * 1024;
|
|
13269
|
-
var SAB_MIN_BYTES = SAB_HEADER_BYTES + 4096;
|
|
13270
|
-
var SYNC_SAB_REQ_MSG = "sync-sab-req";
|
|
13271
|
-
var SYNC_SAB_NEXT_MSG = "sync-sab-next";
|
|
13272
|
-
var encoder4 = new TextEncoder();
|
|
13273
|
-
var decoder2 = new TextDecoder();
|
|
13274
|
-
function encodeSabResult(result) {
|
|
13275
|
-
if (!result.ok) {
|
|
13276
|
-
return {
|
|
13277
|
-
status: SAB_STATUS_ERRNO,
|
|
13278
|
-
payload: encoder4.encode(
|
|
13279
|
-
JSON.stringify({
|
|
13280
|
-
errno: result.errno,
|
|
13281
|
-
message: result.message,
|
|
13282
|
-
...result.direct ? { direct: true } : {},
|
|
13283
|
-
...result.dev !== void 0 ? { dev: result.dev } : {},
|
|
13284
|
-
...result.detail ? { detail: result.detail } : {}
|
|
13285
|
-
})
|
|
13286
|
-
)
|
|
13287
|
-
};
|
|
13288
|
-
}
|
|
13289
|
-
switch (result.kind) {
|
|
13290
|
-
case "bytes":
|
|
13291
|
-
return { status: SAB_STATUS_BYTES, payload: result.bytes };
|
|
13292
|
-
case "json":
|
|
13293
|
-
return { status: SAB_STATUS_JSON, payload: encoder4.encode(JSON.stringify(result.json)) };
|
|
13294
|
-
default:
|
|
13295
|
-
return { status: SAB_STATUS_VOID, payload: new Uint8Array(0) };
|
|
13296
|
-
}
|
|
13297
|
-
}
|
|
13298
|
-
function sabViews(sab) {
|
|
13299
|
-
if (sab.byteLength < SAB_MIN_BYTES) {
|
|
13300
|
-
throw new Error(`sync-sab: buffer too small (${sab.byteLength} < ${SAB_MIN_BYTES})`);
|
|
13301
|
-
}
|
|
13302
|
-
return {
|
|
13303
|
-
header: new Int32Array(sab, 0, SAB_HEADER_I32),
|
|
13304
|
-
window: new Uint8Array(sab, SAB_HEADER_BYTES)
|
|
13305
|
-
};
|
|
13306
|
-
}
|
|
13307
|
-
|
|
13308
14115
|
// src/realm/sync-sab-responder.ts
|
|
13309
14116
|
var PENDING_TTL_MS = SYNC_FS_REQUEST_TIMEOUT_MS + 5e3;
|
|
13310
14117
|
function attachSyncSabResponder(port, sab, token, opts) {
|
|
@@ -13334,6 +14141,7 @@ function attachSyncSabResponder(port, sab, token, opts) {
|
|
|
13334
14141
|
Atomics.store(header5, SAB_I_STATE, SAB_STATE_READY);
|
|
13335
14142
|
Atomics.add(header5, SAB_I_PUB, 1);
|
|
13336
14143
|
Atomics.notify(header5, SAB_I_PUB);
|
|
14144
|
+
headerNotified(header5, SAB_I_PUB);
|
|
13337
14145
|
if (offset + chunk2 >= entry.payload.byteLength) drop(id2);
|
|
13338
14146
|
else if (entry.timer) {
|
|
13339
14147
|
clearTimeout(entry.timer);
|
|
@@ -18322,8 +19130,8 @@ var EventFd = class _EventFd {
|
|
|
18322
19130
|
count;
|
|
18323
19131
|
semaphore;
|
|
18324
19132
|
changes = new Notifier();
|
|
18325
|
-
constructor(
|
|
18326
|
-
this.count =
|
|
19133
|
+
constructor(initial3, semaphore) {
|
|
19134
|
+
this.count = initial3;
|
|
18327
19135
|
this.semaphore = semaphore;
|
|
18328
19136
|
}
|
|
18329
19137
|
async read(max, signal) {
|
|
@@ -21867,7 +22675,7 @@ async function cleartext(message3, asks) {
|
|
|
21867
22675
|
if (Object.keys(values).length === 0) return { bytes: message3, done: true };
|
|
21868
22676
|
return { bytes: frame3(112, `${replaced(password, values)}\0`), values, done: true };
|
|
21869
22677
|
}
|
|
21870
|
-
function
|
|
22678
|
+
function initial2(message3) {
|
|
21871
22679
|
const body = latin2(message3.subarray(5));
|
|
21872
22680
|
const nul = body.indexOf("\0");
|
|
21873
22681
|
const mechanism = body.slice(0, nul);
|
|
@@ -21906,7 +22714,7 @@ var PgClient = class {
|
|
|
21906
22714
|
return cleartext(message3, this.asks);
|
|
21907
22715
|
}
|
|
21908
22716
|
if (server.sasl && this.clientFirst === void 0) {
|
|
21909
|
-
const first =
|
|
22717
|
+
const first = initial2(message3);
|
|
21910
22718
|
const parsed3 = first && clientFirstOf(first.data);
|
|
21911
22719
|
if (!first || !parsed3) return { bytes: message3, done: true };
|
|
21912
22720
|
this.clientFirst = first.data;
|
|
@@ -23155,7 +23963,7 @@ var RightsMark = class {
|
|
|
23155
23963
|
for (const { file } of this.passed) void Promise.resolve(file.release()).catch(() => void 0);
|
|
23156
23964
|
}
|
|
23157
23965
|
};
|
|
23158
|
-
function
|
|
23966
|
+
function refusal2(file) {
|
|
23159
23967
|
if (file instanceof KernelSocket) {
|
|
23160
23968
|
if (file.domain === "unix") return "EOPNOTSUPP";
|
|
23161
23969
|
return file.secured ? "EPERM" : void 0;
|
|
@@ -23179,7 +23987,7 @@ async function sendRights(fds, req, signal) {
|
|
|
23179
23987
|
if (req.fds.length > RIGHTS_MAX || req.body.length === 0) throw new KernelError("EINVAL");
|
|
23180
23988
|
const passed = req.fds.map((fd) => ({ file: fds.get(fd), status: fds.statusFlags(fd) }));
|
|
23181
23989
|
for (const { file } of passed) {
|
|
23182
|
-
const errno3 =
|
|
23990
|
+
const errno3 = refusal2(file.file);
|
|
23183
23991
|
if (errno3) throw new KernelError(errno3, "this descriptor cannot be passed");
|
|
23184
23992
|
}
|
|
23185
23993
|
for (const { file } of passed) file.retain();
|
|
@@ -25775,6 +26583,7 @@ var WasmProcess = class {
|
|
|
25775
26583
|
case "fd-flush": {
|
|
25776
26584
|
const file = this.fds.get(req.fd).file;
|
|
25777
26585
|
if (file.flush) await file.flush();
|
|
26586
|
+
await this.options.durable?.();
|
|
25778
26587
|
return { ok: true, kind: "void" };
|
|
25779
26588
|
}
|
|
25780
26589
|
}
|
|
@@ -25784,6 +26593,7 @@ var WasmProcess = class {
|
|
|
25784
26593
|
const nodes = this.nodes;
|
|
25785
26594
|
if (req.op === "fd-path-flush") {
|
|
25786
26595
|
await nodes.flush(await nodes.targetKey(req.path).catch(() => req.path));
|
|
26596
|
+
if (req.durable) await this.options.durable?.();
|
|
25787
26597
|
} else if (req.op === "fd-path-unlinking")
|
|
25788
26598
|
await nodes.unlinking(await nodes.entryKey(req.path));
|
|
25789
26599
|
else if (req.op === "fd-path-unlinked") nodes.unlinked(await nodes.entryKey(req.path));
|
|
@@ -26423,24 +27233,6 @@ async function notLink(fs, path) {
|
|
|
26423
27233
|
if (st?.isSymbolicLink) throw new KernelError("ELOOP");
|
|
26424
27234
|
}
|
|
26425
27235
|
|
|
26426
|
-
// src/kernel/protocol.ts
|
|
26427
|
-
var WASM_PROCESS_INIT = "wasm-process-init";
|
|
26428
|
-
var WASM_PROCESS_EXIT = "wasm-process-exit";
|
|
26429
|
-
var WASM_PROCESS_ERROR = "wasm-process-error";
|
|
26430
|
-
var WASM_PROCESS_READY = "wasm-process-ready";
|
|
26431
|
-
var WASM_THREAD_SPAWN = "wasm-thread-spawn";
|
|
26432
|
-
var WASM_THREAD_INIT = "wasm-thread-init";
|
|
26433
|
-
var WASM_THREAD_EXIT = "wasm-thread-exit";
|
|
26434
|
-
var WASM_MAX_THREADS = 256;
|
|
26435
|
-
var JS_THREAD_SPAWN = "js-thread-spawn";
|
|
26436
|
-
var JS_THREAD_INIT = "js-thread-init";
|
|
26437
|
-
var JS_THREAD_EXIT = "js-thread-exit";
|
|
26438
|
-
var JS_MAX_THREADS = 256;
|
|
26439
|
-
var JS_DEFAULT_THREADS = 16;
|
|
26440
|
-
var JS_THREAD_NO_MEMORY = 256;
|
|
26441
|
-
var JS_THREAD_CRASHED = 257;
|
|
26442
|
-
var JS_THREAD_OWNED_FDS = 1024;
|
|
26443
|
-
|
|
26444
27236
|
// src/kernel/js-threads.ts
|
|
26445
27237
|
var JS_OOM = /out of memory|Array buffer allocation failed|Cannot allocate Wasm memory|could not allocate memory|ERR_WORKER_OUT_OF_MEMORY/i;
|
|
26446
27238
|
var ENDING = { ok: false, errno: "EINTR", message: "the thread is ending" };
|
|
@@ -26667,6 +27459,7 @@ var Dying = class {
|
|
|
26667
27459
|
this.hard = setTimeout(finish, KILL_HARD_MS);
|
|
26668
27460
|
this.arm();
|
|
26669
27461
|
Atomics.store(header5, SAB_I_KILLED, code);
|
|
27462
|
+
headerNotified(header5, SAB_I_KILLED);
|
|
26670
27463
|
process2.die();
|
|
26671
27464
|
}
|
|
26672
27465
|
serve(req, work) {
|
|
@@ -26731,11 +27524,13 @@ function notifiers(header5) {
|
|
|
26731
27524
|
onPending(sig) {
|
|
26732
27525
|
Atomics.or(header5, SAB_I_SIGNALS, sigbit(sig));
|
|
26733
27526
|
Atomics.notify(header5, SAB_I_SIGNALS);
|
|
27527
|
+
headerNotified(header5, SAB_I_SIGNALS, sigbit(sig));
|
|
26734
27528
|
},
|
|
26735
27529
|
onAsync() {
|
|
26736
27530
|
for (const at of [header5, ...asyncFanout.get(header5) ?? []]) {
|
|
26737
27531
|
Atomics.add(at, SAB_I_ASYNC, 1);
|
|
26738
27532
|
Atomics.notify(at, SAB_I_ASYNC);
|
|
27533
|
+
headerNotified(at, SAB_I_ASYNC);
|
|
26739
27534
|
}
|
|
26740
27535
|
}
|
|
26741
27536
|
};
|
|
@@ -26744,6 +27539,7 @@ function publishStops(process2, header5) {
|
|
|
26744
27539
|
process2.onState((state) => {
|
|
26745
27540
|
Atomics.store(header5, SAB_I_STOP, state === "stopped" ? 1 : 0);
|
|
26746
27541
|
Atomics.notify(header5, SAB_I_STOP);
|
|
27542
|
+
headerNotified(header5, SAB_I_STOP);
|
|
26747
27543
|
});
|
|
26748
27544
|
}
|
|
26749
27545
|
function transferOf(opts, lane) {
|
|
@@ -26867,6 +27663,7 @@ function processOptions(opts, header5, hooks, created4) {
|
|
|
26867
27663
|
...opts.dac ? { guard: { dac: opts.dac, fs: opts.fs, created: created4, ...linksOf(opts) } } : {},
|
|
26868
27664
|
...opts.identity ? { identity: opts.identity } : {},
|
|
26869
27665
|
...opts.onSyscall ? { onSyscall: opts.onSyscall } : {},
|
|
27666
|
+
...opts.durable ? { durable: opts.durable } : {},
|
|
26870
27667
|
...opts.settling ? { settling: opts.settling } : {},
|
|
26871
27668
|
...heldHooks(opts),
|
|
26872
27669
|
spawner: opts.spawner,
|
|
@@ -26895,7 +27692,10 @@ function processOptions(opts, header5, hooks, created4) {
|
|
|
26895
27692
|
onReap: opts.onReap,
|
|
26896
27693
|
resolver: opts.resolver,
|
|
26897
27694
|
...notifiers(header5),
|
|
26898
|
-
onTimer: (which) =>
|
|
27695
|
+
onTimer: (which) => {
|
|
27696
|
+
Atomics.or(header5, SAB_I_TIMERS, 1 << which);
|
|
27697
|
+
headerNotified(header5, SAB_I_TIMERS, 1 << which);
|
|
27698
|
+
},
|
|
26899
27699
|
hasPending: () => unblocked(header5) !== 0 || Atomics.load(header5, SAB_I_TIMERS) !== 0,
|
|
26900
27700
|
raise: hooks.raise,
|
|
26901
27701
|
threadKill: hooks.threadKill,
|
|
@@ -33025,12 +33825,12 @@ function grantConnect(hook, fetch2, liveness = {}) {
|
|
|
33025
33825
|
return new HostfsClient(first, grant, fetch2);
|
|
33026
33826
|
};
|
|
33027
33827
|
}
|
|
33028
|
-
async function openHostfs(spec, connect2, timing = {}) {
|
|
33828
|
+
async function openHostfs(spec, connect2, timing = {}, ports = messageChannel) {
|
|
33029
33829
|
const readonly2 = spec.options?.ro !== void 0;
|
|
33030
|
-
const { port1, port2 } =
|
|
33830
|
+
const { port1, port2 } = ports();
|
|
33031
33831
|
const slot2 = mediumSlot(
|
|
33032
33832
|
async (err) => unreachable(err),
|
|
33033
|
-
() =>
|
|
33833
|
+
() => watching2.kick()
|
|
33034
33834
|
);
|
|
33035
33835
|
const stop = new AbortController();
|
|
33036
33836
|
let active;
|
|
@@ -33050,7 +33850,7 @@ async function openHostfs(spec, connect2, timing = {}) {
|
|
|
33050
33850
|
...readonly2 ? { readonly: true } : {}
|
|
33051
33851
|
}
|
|
33052
33852
|
);
|
|
33053
|
-
const
|
|
33853
|
+
const watching2 = keepWatching(
|
|
33054
33854
|
{
|
|
33055
33855
|
connect: () => connect2(spec.source, { readonly: readonly2 }),
|
|
33056
33856
|
up(client) {
|
|
@@ -33067,7 +33867,7 @@ async function openHostfs(spec, connect2, timing = {}) {
|
|
|
33067
33867
|
},
|
|
33068
33868
|
stop.signal
|
|
33069
33869
|
);
|
|
33070
|
-
await
|
|
33870
|
+
await watching2.ready;
|
|
33071
33871
|
return {
|
|
33072
33872
|
port: port1,
|
|
33073
33873
|
present: slot2.present,
|
|
@@ -33079,6 +33879,26 @@ async function openHostfs(spec, connect2, timing = {}) {
|
|
|
33079
33879
|
};
|
|
33080
33880
|
}
|
|
33081
33881
|
|
|
33882
|
+
// src/mount/in-process.ts
|
|
33883
|
+
var IN_PROCESS_DRIVER = /* @__PURE__ */ Symbol.for(
|
|
33884
|
+
"slicc-kernel.mount.in-process"
|
|
33885
|
+
);
|
|
33886
|
+
function openInProcess(spec, ports = messageChannel) {
|
|
33887
|
+
const driver = spec[IN_PROCESS_DRIVER];
|
|
33888
|
+
if (!driver) return void 0;
|
|
33889
|
+
const { port1, port2 } = ports();
|
|
33890
|
+
driver.served?.(
|
|
33891
|
+
serveFilesystem(port2, driver.handlers, driver.capabilities ?? {}, { owned: true })
|
|
33892
|
+
);
|
|
33893
|
+
return {
|
|
33894
|
+
port: port1,
|
|
33895
|
+
dispose: () => {
|
|
33896
|
+
port1.close();
|
|
33897
|
+
port2.close();
|
|
33898
|
+
}
|
|
33899
|
+
};
|
|
33900
|
+
}
|
|
33901
|
+
|
|
33082
33902
|
// src/mount/media.ts
|
|
33083
33903
|
function memoryMedia() {
|
|
33084
33904
|
const handles = /* @__PURE__ */ new Map();
|
|
@@ -33368,9 +34188,9 @@ function importedMemory(bytes) {
|
|
|
33368
34188
|
};
|
|
33369
34189
|
const limits = () => {
|
|
33370
34190
|
const flags2 = bytes[at++];
|
|
33371
|
-
const
|
|
34191
|
+
const initial3 = u32();
|
|
33372
34192
|
const maximum = flags2 & 1 ? u32() : void 0;
|
|
33373
|
-
return { initial:
|
|
34193
|
+
return { initial: initial3, maximum, shared: (flags2 & 2) !== 0 };
|
|
33374
34194
|
};
|
|
33375
34195
|
while (at < bytes.length) {
|
|
33376
34196
|
const id2 = bytes[at++];
|
|
@@ -33506,13 +34326,29 @@ function foreignImports(bytes) {
|
|
|
33506
34326
|
return {};
|
|
33507
34327
|
}
|
|
33508
34328
|
var LIBC_MARK = /^wasix-sysroot \d{4}\.\d+\.\d+-(\d+)/;
|
|
33509
|
-
function
|
|
33510
|
-
for (const section of
|
|
34329
|
+
function libcOf(sections) {
|
|
34330
|
+
for (const section of sections) {
|
|
33511
34331
|
const found = LIBC_MARK.exec(new TextDecoder().decode(section));
|
|
33512
34332
|
if (found) return Number(found[1]);
|
|
33513
34333
|
}
|
|
33514
34334
|
return void 0;
|
|
33515
34335
|
}
|
|
34336
|
+
function customSectionsOf(bytes, wanted) {
|
|
34337
|
+
const found = [];
|
|
34338
|
+
const r = new Reader(bytes);
|
|
34339
|
+
r.at = 8;
|
|
34340
|
+
while (r.at < bytes.length) {
|
|
34341
|
+
const id2 = r.byte();
|
|
34342
|
+
const size = r.u32();
|
|
34343
|
+
const end = r.at + size;
|
|
34344
|
+
if (id2 === 0 && r.name() === wanted) found.push(bytes.subarray(r.at, end));
|
|
34345
|
+
r.at = end;
|
|
34346
|
+
}
|
|
34347
|
+
return found;
|
|
34348
|
+
}
|
|
34349
|
+
function libcVersionOf(bytes) {
|
|
34350
|
+
return libcOf(customSectionsOf(bytes, "slicc.libc"));
|
|
34351
|
+
}
|
|
33516
34352
|
|
|
33517
34353
|
// src/refused-command.ts
|
|
33518
34354
|
var REFUSED_PATH = "/usr/lib/slicc/refused";
|
|
@@ -33939,8 +34775,8 @@ function cronPath(path) {
|
|
|
33939
34775
|
);
|
|
33940
34776
|
}
|
|
33941
34777
|
var ETC_HOSTNAME_LIBC = 42;
|
|
33942
|
-
function readsEtcHostname(program) {
|
|
33943
|
-
return program.abi === "wasi" && (
|
|
34778
|
+
function readsEtcHostname(program, libc) {
|
|
34779
|
+
return program.abi === "wasi" && (libc ?? 0) >= ETC_HOSTNAME_LIBC;
|
|
33944
34780
|
}
|
|
33945
34781
|
function setOrDrop(env, key, value2) {
|
|
33946
34782
|
if (value2 === void 0) delete env[key];
|
|
@@ -34098,6 +34934,8 @@ function addTimes(into, pid, t) {
|
|
|
34098
34934
|
into.set(pid, { utime: at.utime + t.utime, stime: at.stime + t.stime });
|
|
34099
34935
|
}
|
|
34100
34936
|
var Launcher = class {
|
|
34937
|
+
emscripten;
|
|
34938
|
+
admit;
|
|
34101
34939
|
fs;
|
|
34102
34940
|
processFs;
|
|
34103
34941
|
noLinksFs;
|
|
@@ -34108,8 +34946,10 @@ var Launcher = class {
|
|
|
34108
34946
|
unguardedRoot;
|
|
34109
34947
|
writers;
|
|
34110
34948
|
unlinkOwnerOption;
|
|
34949
|
+
durable;
|
|
34111
34950
|
base;
|
|
34112
34951
|
createWorker;
|
|
34952
|
+
compile;
|
|
34113
34953
|
moduleUrl;
|
|
34114
34954
|
moduleUrls = /* @__PURE__ */ new Map();
|
|
34115
34955
|
urlsInUse = /* @__PURE__ */ new Map();
|
|
@@ -34124,6 +34964,7 @@ var Launcher = class {
|
|
|
34124
34964
|
unwatchScopes = () => void 0;
|
|
34125
34965
|
warned = /* @__PURE__ */ new Set();
|
|
34126
34966
|
compiled = /* @__PURE__ */ new Map();
|
|
34967
|
+
libcs = /* @__PURE__ */ new WeakMap();
|
|
34127
34968
|
texts = /* @__PURE__ */ new Map();
|
|
34128
34969
|
revocations = 0;
|
|
34129
34970
|
integrity;
|
|
@@ -34192,6 +35033,9 @@ var Launcher = class {
|
|
|
34192
35033
|
onMountPending;
|
|
34193
35034
|
removable = /* @__PURE__ */ new Map();
|
|
34194
35035
|
hostfs;
|
|
35036
|
+
get ports() {
|
|
35037
|
+
return this.hostfs.ports ?? messageChannel;
|
|
35038
|
+
}
|
|
34195
35039
|
fstabRetries;
|
|
34196
35040
|
inserted = /* @__PURE__ */ new Map();
|
|
34197
35041
|
openFiles = /* @__PURE__ */ new Set();
|
|
@@ -34275,8 +35119,8 @@ var Launcher = class {
|
|
|
34275
35119
|
this.mounted = this.mounts.wrap(options.fs);
|
|
34276
35120
|
this.base = this.rooted(this.mounted);
|
|
34277
35121
|
this.createWorker = options.createWorker;
|
|
34278
|
-
this.
|
|
34279
|
-
this.createDriverWorker = options
|
|
35122
|
+
({ compile: this.compile, emscripten: this.emscripten, admit: this.admit } = options);
|
|
35123
|
+
({ moduleUrl: this.moduleUrl, createDriverWorker: this.createDriverWorker } = options);
|
|
34280
35124
|
this.media = options.media ?? memoryMedia();
|
|
34281
35125
|
this.onMountPending = options.onMountPending;
|
|
34282
35126
|
this.hostfs = options;
|
|
@@ -34349,7 +35193,7 @@ var Launcher = class {
|
|
|
34349
35193
|
);
|
|
34350
35194
|
this.fs = this.processChain(fs, this.nodes, this.unlinked);
|
|
34351
35195
|
this.writerTags = writerTags(options.protect);
|
|
34352
|
-
this.unlinkOwnerOption = options
|
|
35196
|
+
({ unlinkOwner: this.unlinkOwnerOption, durable: this.durable } = options);
|
|
34353
35197
|
if (this.writerTags.size > 0 && options.fs.protect && !options.fs.unguarded) {
|
|
34354
35198
|
throw new TypeError("protect.writers needs a root file system with an unguarded view");
|
|
34355
35199
|
}
|
|
@@ -35135,9 +35979,12 @@ var Launcher = class {
|
|
|
35135
35979
|
const bytes = sum === void 0 ? read : await this.pinnedBytes(pin, read);
|
|
35136
35980
|
const memory = importedMemory(bytes);
|
|
35137
35981
|
const foreign = foreignImports(bytes);
|
|
35138
|
-
const
|
|
35982
|
+
const libc = libcVersionOf(bytes);
|
|
35983
|
+
const named = customSectionsOf(bytes, "name").length > 0;
|
|
35984
|
+
const compiled = this.compile ? await this.compile(bytes, key) : await WebAssembly.compile(bytes);
|
|
35985
|
+
if (libc !== void 0) this.libcs.set(compiled, libc);
|
|
35139
35986
|
return {
|
|
35140
|
-
value: { module: compiled, ...memory ? { memory } : {}, foreign },
|
|
35987
|
+
value: { module: compiled, ...memory ? { memory } : {}, foreign, named },
|
|
35141
35988
|
key: sum === void 0 ? readKey : key
|
|
35142
35989
|
};
|
|
35143
35990
|
});
|
|
@@ -35213,8 +36060,7 @@ var Launcher = class {
|
|
|
35213
36060
|
if (this.urlsInUse.get(held.made.url) === held) this.urlsInUse.delete(held.made.url);
|
|
35214
36061
|
held.made.revoke();
|
|
35215
36062
|
}
|
|
35216
|
-
async names(path
|
|
35217
|
-
if (WebAssembly.Module.customSections(module, "name").length > 0) return void 0;
|
|
36063
|
+
async names(path) {
|
|
35218
36064
|
const beside = `${path}.names`;
|
|
35219
36065
|
if (await this.base.exists(beside)) return beside;
|
|
35220
36066
|
const root = PACKAGE_ROOT.exec(path)?.[1];
|
|
@@ -35287,6 +36133,10 @@ var Launcher = class {
|
|
|
35287
36133
|
const { url, source } = this.urlFor(await this.text(target.wasm, caller, asked));
|
|
35288
36134
|
return { abi: "js", glue: "", url, path: target.wasm, ...source ? { source } : {} };
|
|
35289
36135
|
}
|
|
36136
|
+
if (target.abi !== "wasi" && this.emscripten === "kernel") {
|
|
36137
|
+
const { module: module2 } = await this.module(target.wasm, caller, asked && modulePath(asked));
|
|
36138
|
+
return { abi: "emscripten", emscripten: "kernel", glue: "", module: module2, path: target.glue };
|
|
36139
|
+
}
|
|
35290
36140
|
if (target.abi !== "wasi") {
|
|
35291
36141
|
const [glue, { module: module2 }] = await Promise.all([
|
|
35292
36142
|
this.text(target.glue, caller, asked),
|
|
@@ -35294,8 +36144,8 @@ var Launcher = class {
|
|
|
35294
36144
|
]);
|
|
35295
36145
|
return { glue, module: module2, path: target.glue };
|
|
35296
36146
|
}
|
|
35297
|
-
const { module, memory, foreign } = await this.module(target.wasm, caller, asked);
|
|
35298
|
-
const names2 = env.SLICC_WASM_BACKTRACE === "1" ? await this.names(target.wasm
|
|
36147
|
+
const { module, memory, foreign, named } = await this.module(target.wasm, caller, asked);
|
|
36148
|
+
const names2 = env.SLICC_WASM_BACKTRACE === "1" && !named ? await this.names(target.wasm) : void 0;
|
|
35299
36149
|
const imports = target.imports ? await this.text(target.imports, caller) : void 0;
|
|
35300
36150
|
return {
|
|
35301
36151
|
abi: "wasi",
|
|
@@ -35330,7 +36180,7 @@ var Launcher = class {
|
|
|
35330
36180
|
try {
|
|
35331
36181
|
const cwdSlot = await this.cwds.hold(cwd, req.cwdFrom);
|
|
35332
36182
|
const handle = await this.admitted(
|
|
35333
|
-
program
|
|
36183
|
+
program,
|
|
35334
36184
|
req.fds,
|
|
35335
36185
|
(fds, quietOom) => this.start({
|
|
35336
36186
|
...req,
|
|
@@ -35345,7 +36195,8 @@ var Launcher = class {
|
|
|
35345
36195
|
args,
|
|
35346
36196
|
env,
|
|
35347
36197
|
cwdSlot
|
|
35348
|
-
})
|
|
36198
|
+
}),
|
|
36199
|
+
req.ppid
|
|
35349
36200
|
).finally(() => this.cwds.release(cwdSlot));
|
|
35350
36201
|
void handle.exited.finally(done4);
|
|
35351
36202
|
return handle;
|
|
@@ -35369,7 +36220,8 @@ var Launcher = class {
|
|
|
35369
36220
|
};
|
|
35370
36221
|
if (this.integrity) await this.checkedSources(planned, caller);
|
|
35371
36222
|
const [program, exeId] = await this.loaded(planned.target, env, caller);
|
|
35372
|
-
|
|
36223
|
+
const libc = program.abi === "js" ? void 0 : this.libcs.get(program.module);
|
|
36224
|
+
if (readsEtcHostname(program, libc)) setOrDrop(env, "HOSTNAME", own);
|
|
35373
36225
|
return { planned, env, program, exeId };
|
|
35374
36226
|
}
|
|
35375
36227
|
packageRootIs(path) {
|
|
@@ -35466,12 +36318,25 @@ var Launcher = class {
|
|
|
35466
36318
|
if (req.command !== void 0) this.programs.set(pid, req.command);
|
|
35467
36319
|
this.cwdPaths.set(pid, req.cwd);
|
|
35468
36320
|
}
|
|
35469
|
-
async
|
|
36321
|
+
async reserved(program, fds, ppid) {
|
|
36322
|
+
if (!this.admit) return () => {
|
|
36323
|
+
};
|
|
36324
|
+
try {
|
|
36325
|
+
return await this.admit(program, ppid === void 0 ? {} : { ppid });
|
|
36326
|
+
} catch (err) {
|
|
36327
|
+
this.memories.ended();
|
|
36328
|
+
await fds.closeAll();
|
|
36329
|
+
throw err;
|
|
36330
|
+
}
|
|
36331
|
+
}
|
|
36332
|
+
async admitted(program, fds, start2, ppid) {
|
|
36333
|
+
const wasm = program.abi !== "js";
|
|
35470
36334
|
for (; ; ) {
|
|
35471
36335
|
await this.memories.admit().catch(async (err) => {
|
|
35472
36336
|
await fds.closeAll();
|
|
35473
36337
|
throw err;
|
|
35474
36338
|
});
|
|
36339
|
+
const release = await this.reserved(program, fds, ppid);
|
|
35475
36340
|
const counted3 = (handle2) => {
|
|
35476
36341
|
void handle2.exited.finally(() => this.memories.ended());
|
|
35477
36342
|
void Promise.resolve(handle2.ready).then(() => this.memories.started());
|
|
@@ -35483,6 +36348,8 @@ var Launcher = class {
|
|
|
35483
36348
|
} catch (err) {
|
|
35484
36349
|
this.memories.ended();
|
|
35485
36350
|
throw err;
|
|
36351
|
+
} finally {
|
|
36352
|
+
release();
|
|
35486
36353
|
}
|
|
35487
36354
|
}
|
|
35488
36355
|
const forked = fds.fork();
|
|
@@ -35490,7 +36357,7 @@ var Launcher = class {
|
|
|
35490
36357
|
this.memories.ended();
|
|
35491
36358
|
await forked.closeAll();
|
|
35492
36359
|
throw err;
|
|
35493
|
-
});
|
|
36360
|
+
}).finally(release);
|
|
35494
36361
|
const fit = await (handle.ready ?? true);
|
|
35495
36362
|
if (fit) {
|
|
35496
36363
|
this.traceAdmitted(handle.pid, true);
|
|
@@ -35533,6 +36400,7 @@ var Launcher = class {
|
|
|
35533
36400
|
this.settling.syscall(pid, call.op);
|
|
35534
36401
|
},
|
|
35535
36402
|
settling: () => this.settling.isSettling(pid),
|
|
36403
|
+
durable: this.durable,
|
|
35536
36404
|
...req.ignored ? { ignored: req.ignored } : {},
|
|
35537
36405
|
...anyBlocked(req.blocked) ? { blocked: req.blocked } : {},
|
|
35538
36406
|
...req.umask !== void 0 ? { umask: req.umask } : {},
|
|
@@ -36093,7 +36961,7 @@ var Launcher = class {
|
|
|
36093
36961
|
tagBase: this.tagBases.get(ppid),
|
|
36094
36962
|
links: this.links.get(ppid)
|
|
36095
36963
|
});
|
|
36096
|
-
return childHandle(await this.admitted(parent.program
|
|
36964
|
+
return childHandle(await this.admitted(parent.program, given, fresh4, ppid));
|
|
36097
36965
|
};
|
|
36098
36966
|
}
|
|
36099
36967
|
keySignal(tty, fallback, sig, send2) {
|
|
@@ -36223,6 +37091,8 @@ var Launcher = class {
|
|
|
36223
37091
|
return targets.length > 0;
|
|
36224
37092
|
}
|
|
36225
37093
|
async driver(type, spec) {
|
|
37094
|
+
const inProcess = openInProcess(spec, this.ports);
|
|
37095
|
+
if (inProcess) return inProcess;
|
|
36226
37096
|
if (type === "fsa") return this.fsaDriver(spec);
|
|
36227
37097
|
if (type === "hostfs") {
|
|
36228
37098
|
const { hostfs, hostfsFetch, hostfsTiming } = this.hostfs;
|
|
@@ -36231,11 +37101,12 @@ var Launcher = class {
|
|
|
36231
37101
|
return openHostfs(
|
|
36232
37102
|
spec,
|
|
36233
37103
|
grantConnect(hostfs, hostfsFetch ?? ((url, init) => fetch(url, init)), hostfsTiming),
|
|
36234
|
-
hostfsTiming
|
|
37104
|
+
hostfsTiming,
|
|
37105
|
+
this.ports
|
|
36235
37106
|
);
|
|
36236
37107
|
}
|
|
36237
37108
|
if (type === "tmpfs") {
|
|
36238
|
-
const { port1, port2 } =
|
|
37109
|
+
const { port1, port2 } = this.ports();
|
|
36239
37110
|
serveFilesystem(
|
|
36240
37111
|
port2,
|
|
36241
37112
|
tmpfs(),
|
|
@@ -36296,7 +37167,7 @@ var Launcher = class {
|
|
|
36296
37167
|
async fsaDriver(spec) {
|
|
36297
37168
|
const { target, source } = spec;
|
|
36298
37169
|
const ask = (handle) => this.onMountPending?.({ target, source, ...handle ? { handle } : {} });
|
|
36299
|
-
const { port1, port2 } =
|
|
37170
|
+
const { port1, port2 } = this.ports();
|
|
36300
37171
|
const medium = removableMedium((handle) => {
|
|
36301
37172
|
served2.invalidate(true);
|
|
36302
37173
|
ask(handle);
|
|
@@ -37722,7 +38593,7 @@ function signalOf(host) {
|
|
|
37722
38593
|
}
|
|
37723
38594
|
function dialFor(l, req, open) {
|
|
37724
38595
|
const socket = dialSocket(l.net, req.port, req.host);
|
|
37725
|
-
const { port1, port2 } =
|
|
38596
|
+
const { port1, port2 } = l.ports();
|
|
37726
38597
|
open.set(
|
|
37727
38598
|
req.id,
|
|
37728
38599
|
serveSocket(socket, port1, () => open.delete(req.id))
|
|
@@ -37815,7 +38686,8 @@ function cdpRegistry(send2, gone) {
|
|
|
37815
38686
|
(request, cdp) => send2({ cdpOpen: { ...request, registration: req.id }, port: cdp }, [
|
|
37816
38687
|
cdp
|
|
37817
38688
|
]),
|
|
37818
|
-
gone
|
|
38689
|
+
gone,
|
|
38690
|
+
l.ports
|
|
37819
38691
|
);
|
|
37820
38692
|
registered.set(req.id, l.cdp.register(hook, req.runtime));
|
|
37821
38693
|
return req.id;
|
|
@@ -37838,7 +38710,8 @@ function facadeRegistry(send2, gone) {
|
|
|
37838
38710
|
(request, facade) => send2({ facadeOpen: { ...request, registration: req.id }, port: facade }, [
|
|
37839
38711
|
facade
|
|
37840
38712
|
]),
|
|
37841
|
-
gone
|
|
38713
|
+
gone,
|
|
38714
|
+
l.ports
|
|
37842
38715
|
);
|
|
37843
38716
|
registered.set(req.id, l.facades.register(req.name, hook));
|
|
37844
38717
|
return req.id;
|
|
@@ -38272,7 +39145,7 @@ function loopbackName2(host) {
|
|
|
38272
39145
|
const name2 = host.toLowerCase().replace(/\.$/, "");
|
|
38273
39146
|
return name2 === "localhost" || name2.endsWith(".localhost");
|
|
38274
39147
|
}
|
|
38275
|
-
function
|
|
39148
|
+
function portOf2(url) {
|
|
38276
39149
|
if (url.port) return Number(url.port);
|
|
38277
39150
|
return url.protocol === "https:" || url.protocol === "wss:" ? 443 : 80;
|
|
38278
39151
|
}
|
|
@@ -38280,8 +39153,8 @@ function allows(policy, port) {
|
|
|
38280
39153
|
if (Array.isArray(policy)) return policy.includes(port);
|
|
38281
39154
|
return policy === true && !DEVTOOLS_PORTS.includes(port);
|
|
38282
39155
|
}
|
|
38283
|
-
function
|
|
38284
|
-
const where = `${address2}:${
|
|
39156
|
+
function refusal3(url, address2, place) {
|
|
39157
|
+
const where = `${address2}:${portOf2(url)}`;
|
|
38285
39158
|
const why = place === "link-local" ? `nodeTransport refuses link-local ${where}` : `nodeTransport refuses the host's loopback ${where} (see nodeTransport({ hostLoopback }))`;
|
|
38286
39159
|
return Object.assign(new Error(why), { status: 403, code: "EACCES" });
|
|
38287
39160
|
}
|
|
@@ -38301,8 +39174,8 @@ async function checkDestination(target, policy, resolve2 = resolveHost) {
|
|
|
38301
39174
|
for (const address2 of await addressesOf(url.hostname, resolve2)) {
|
|
38302
39175
|
const place = placeOf(address2);
|
|
38303
39176
|
if (!place) continue;
|
|
38304
|
-
if (place === "loopback" && allows(policy,
|
|
38305
|
-
throw
|
|
39177
|
+
if (place === "loopback" && allows(policy, portOf2(url))) continue;
|
|
39178
|
+
throw refusal3(url, address2, place);
|
|
38306
39179
|
}
|
|
38307
39180
|
}
|
|
38308
39181
|
function guarded3(check, signal) {
|
|
@@ -38628,7 +39501,7 @@ function isMemoryRoot(handle) {
|
|
|
38628
39501
|
|
|
38629
39502
|
// src/node/worker-boot.ts
|
|
38630
39503
|
import { readFileSync } from "node:fs";
|
|
38631
|
-
import { MessageChannel as
|
|
39504
|
+
import { MessageChannel as MessageChannel3, Worker as Worker2 } from "node:worker_threads";
|
|
38632
39505
|
var PROCESS_BOOT = `(async () => {
|
|
38633
39506
|
'use strict';
|
|
38634
39507
|
const { workerData } = require('node:worker_threads');
|
|
@@ -38680,10 +39553,10 @@ function cachedBoot(cache, data) {
|
|
|
38680
39553
|
if (data.cachedData) cache.cachedData = data.cachedData;
|
|
38681
39554
|
else if (data.rejected) cache.cachedData = void 0;
|
|
38682
39555
|
}
|
|
38683
|
-
function bootWorker(file, options, bundle, make = (entry, init) => new
|
|
39556
|
+
function bootWorker(file, options, bundle, make = (entry, init) => new Worker2(entry, init), read = readFileSync) {
|
|
38684
39557
|
if (!(file instanceof URL) || file.href !== bundle.href) return make(file, options);
|
|
38685
39558
|
const cache = bootCache(file, read);
|
|
38686
|
-
const { port1, port2 } = new
|
|
39559
|
+
const { port1, port2 } = new MessageChannel3();
|
|
38687
39560
|
port1.once("message", (data) => {
|
|
38688
39561
|
cachedBoot(cache, data);
|
|
38689
39562
|
port1.close();
|
|
@@ -38799,6 +39672,382 @@ function signalNumber(name2) {
|
|
|
38799
39672
|
return SIG[key];
|
|
38800
39673
|
}
|
|
38801
39674
|
|
|
39675
|
+
// src/async/transport.ts
|
|
39676
|
+
function snapshotted(asked, snapshots) {
|
|
39677
|
+
const fork = asked;
|
|
39678
|
+
const memory = fork.state?.memory;
|
|
39679
|
+
if (!snapshots || fork.op !== "proc-fork" || !(memory instanceof Uint8Array)) {
|
|
39680
|
+
return { req: asked };
|
|
39681
|
+
}
|
|
39682
|
+
if (memory.byteLength === 0) return { req: asked };
|
|
39683
|
+
const owned4 = memory.buffer instanceof ArrayBuffer ? memory : memory.slice();
|
|
39684
|
+
const snapshot = snapshots.keep(owned4);
|
|
39685
|
+
const state = { ...fork.state, memory: new Uint8Array(0), snapshot };
|
|
39686
|
+
const req = { ...asked, state };
|
|
39687
|
+
return { req, token: snapshot.token };
|
|
39688
|
+
}
|
|
39689
|
+
var CLOCK_BLOCKED2 = 0;
|
|
39690
|
+
var CLOCK_IDLE2 = 1;
|
|
39691
|
+
function isAnswer(reply) {
|
|
39692
|
+
return typeof reply.status === "number";
|
|
39693
|
+
}
|
|
39694
|
+
function bodyOf2(req) {
|
|
39695
|
+
const body = req.body;
|
|
39696
|
+
return body instanceof Uint8Array ? body : void 0;
|
|
39697
|
+
}
|
|
39698
|
+
function exactCopy(body) {
|
|
39699
|
+
const whole = body.byteOffset === 0 && body.byteLength === body.buffer.byteLength;
|
|
39700
|
+
if (whole && body.buffer instanceof ArrayBuffer) return { body, transfer: [] };
|
|
39701
|
+
const copy = body.slice();
|
|
39702
|
+
return { body: copy, transfer: [copy.buffer] };
|
|
39703
|
+
}
|
|
39704
|
+
function landing(status, total, sink) {
|
|
39705
|
+
if (!sink || status !== SAB_STATUS_BYTES || total > sink.length) return new Uint8Array(total);
|
|
39706
|
+
return new Uint8Array(sink.buffer, sink.byteOffset, total);
|
|
39707
|
+
}
|
|
39708
|
+
function mirrored(spec) {
|
|
39709
|
+
if (!spec) return void 0;
|
|
39710
|
+
const buffer = new ArrayBuffer(spec.bytes);
|
|
39711
|
+
applyRuns(new Int32Array(buffer), spec.runs);
|
|
39712
|
+
return buffer;
|
|
39713
|
+
}
|
|
39714
|
+
function withTimeout(work, ms, label) {
|
|
39715
|
+
if (!Number.isFinite(ms)) return work;
|
|
39716
|
+
return new Promise((resolve2, reject) => {
|
|
39717
|
+
const timer = setTimeout(() => reject(syncError("EIO", label)), Math.max(0, ms));
|
|
39718
|
+
work.then(
|
|
39719
|
+
(value2) => {
|
|
39720
|
+
clearTimeout(timer);
|
|
39721
|
+
resolve2(value2);
|
|
39722
|
+
},
|
|
39723
|
+
(err) => {
|
|
39724
|
+
clearTimeout(timer);
|
|
39725
|
+
reject(err);
|
|
39726
|
+
}
|
|
39727
|
+
);
|
|
39728
|
+
});
|
|
39729
|
+
}
|
|
39730
|
+
var Mirrors = class {
|
|
39731
|
+
buffer = new ArrayBuffer(SAB_HEADER_BYTES);
|
|
39732
|
+
header = new Int32Array(this.buffer, 0, SAB_HEADER_I32);
|
|
39733
|
+
clock = new BigInt64Array(this.buffer, SAB_CLOCK_OFFSET, SAB_CLOCK_I64);
|
|
39734
|
+
changes;
|
|
39735
|
+
cwds;
|
|
39736
|
+
changesView;
|
|
39737
|
+
cwdsView;
|
|
39738
|
+
applied = 0;
|
|
39739
|
+
early = /* @__PURE__ */ new Map();
|
|
39740
|
+
settled = /* @__PURE__ */ new Map();
|
|
39741
|
+
waiters = /* @__PURE__ */ new Set();
|
|
39742
|
+
start(mirror) {
|
|
39743
|
+
this.header.set(mirror.header.subarray(0, SAB_HEADER_I32));
|
|
39744
|
+
Atomics.store(this.clock, CLOCK_BLOCKED2, BigInt(mirror.clock[0]));
|
|
39745
|
+
Atomics.store(this.clock, CLOCK_IDLE2, BigInt(mirror.clock[1]));
|
|
39746
|
+
this.changes = mirrored(mirror.changes);
|
|
39747
|
+
this.cwds = mirrored(mirror.cwds);
|
|
39748
|
+
this.changesView = this.changes ? new Int32Array(this.changes) : void 0;
|
|
39749
|
+
this.cwdsView = this.cwds ? new Int32Array(this.cwds) : void 0;
|
|
39750
|
+
}
|
|
39751
|
+
apply(m) {
|
|
39752
|
+
const { header: header5 } = this;
|
|
39753
|
+
if (m.signals) Atomics.or(header5, SAB_I_SIGNALS, m.signals);
|
|
39754
|
+
if (m.timers) Atomics.or(header5, SAB_I_TIMERS, m.timers);
|
|
39755
|
+
Atomics.store(header5, SAB_I_KILLED, m.killed);
|
|
39756
|
+
Atomics.store(header5, SAB_I_ASYNC, m.async);
|
|
39757
|
+
Atomics.store(header5, SAB_I_STOP, m.stop);
|
|
39758
|
+
Atomics.store(this.clock, CLOCK_BLOCKED2, BigInt(m.clock));
|
|
39759
|
+
if (this.changesView) applyRuns(this.changesView, m.changes);
|
|
39760
|
+
if (this.cwdsView) applyRuns(this.cwdsView, m.cwds);
|
|
39761
|
+
this.applied = m.seq;
|
|
39762
|
+
}
|
|
39763
|
+
accept(m) {
|
|
39764
|
+
if (m.seq <= this.applied) return Promise.resolve();
|
|
39765
|
+
this.early.set(m.seq, m);
|
|
39766
|
+
const done4 = new Promise((resolve2) => {
|
|
39767
|
+
const list = this.settled.get(m.seq) ?? [];
|
|
39768
|
+
list.push(resolve2);
|
|
39769
|
+
this.settled.set(m.seq, list);
|
|
39770
|
+
});
|
|
39771
|
+
let progressed = false;
|
|
39772
|
+
for (let next3 = this.early.get(this.applied + 1); next3; next3 = this.early.get(this.applied + 1)) {
|
|
39773
|
+
this.early.delete(next3.seq);
|
|
39774
|
+
this.apply(next3);
|
|
39775
|
+
progressed = true;
|
|
39776
|
+
for (const resolve2 of this.settled.get(next3.seq) ?? []) resolve2();
|
|
39777
|
+
this.settled.delete(next3.seq);
|
|
39778
|
+
}
|
|
39779
|
+
if (progressed) this.wake();
|
|
39780
|
+
return done4;
|
|
39781
|
+
}
|
|
39782
|
+
wake() {
|
|
39783
|
+
for (const waiter of [...this.waiters]) {
|
|
39784
|
+
if (Atomics.load(waiter.view, waiter.index) === waiter.value) continue;
|
|
39785
|
+
this.waiters.delete(waiter);
|
|
39786
|
+
waiter.settle("ok");
|
|
39787
|
+
}
|
|
39788
|
+
}
|
|
39789
|
+
notify(view2, index) {
|
|
39790
|
+
for (const waiter of [...this.waiters]) {
|
|
39791
|
+
if (waiter.view !== view2 || waiter.index !== index) continue;
|
|
39792
|
+
this.waiters.delete(waiter);
|
|
39793
|
+
waiter.settle("ok");
|
|
39794
|
+
}
|
|
39795
|
+
}
|
|
39796
|
+
failAll(err) {
|
|
39797
|
+
for (const waiter of [...this.waiters]) {
|
|
39798
|
+
this.waiters.delete(waiter);
|
|
39799
|
+
waiter.fail(err);
|
|
39800
|
+
}
|
|
39801
|
+
}
|
|
39802
|
+
words(n, memory) {
|
|
39803
|
+
const { header: header5 } = this;
|
|
39804
|
+
if (memory !== void 0 && memory > 0) {
|
|
39805
|
+
Atomics.store(header5, SAB_I_MEMORY, Math.ceil(memory / 65536));
|
|
39806
|
+
}
|
|
39807
|
+
return {
|
|
39808
|
+
n,
|
|
39809
|
+
seen: this.applied,
|
|
39810
|
+
signals: Atomics.load(header5, SAB_I_SIGNALS),
|
|
39811
|
+
timers: Atomics.load(header5, SAB_I_TIMERS),
|
|
39812
|
+
blocked: [Atomics.load(header5, SAB_I_BLOCKED), Atomics.load(header5, SAB_I_BLOCKED_HI)],
|
|
39813
|
+
memory: Atomics.load(header5, SAB_I_MEMORY),
|
|
39814
|
+
idle: Number(Atomics.load(this.clock, CLOCK_IDLE2))
|
|
39815
|
+
};
|
|
39816
|
+
}
|
|
39817
|
+
wait(view2, index, value2, timeoutMs) {
|
|
39818
|
+
return new Promise((resolve2, reject) => {
|
|
39819
|
+
let timer;
|
|
39820
|
+
const waiter = {
|
|
39821
|
+
view: view2,
|
|
39822
|
+
index,
|
|
39823
|
+
value: value2,
|
|
39824
|
+
settle: (result) => {
|
|
39825
|
+
clearTimeout(timer);
|
|
39826
|
+
resolve2(result);
|
|
39827
|
+
},
|
|
39828
|
+
fail: (err) => {
|
|
39829
|
+
clearTimeout(timer);
|
|
39830
|
+
reject(err);
|
|
39831
|
+
}
|
|
39832
|
+
};
|
|
39833
|
+
this.waiters.add(waiter);
|
|
39834
|
+
if (!Number.isFinite(timeoutMs)) return;
|
|
39835
|
+
timer = setTimeout(
|
|
39836
|
+
() => {
|
|
39837
|
+
this.waiters.delete(waiter);
|
|
39838
|
+
resolve2("timed-out");
|
|
39839
|
+
},
|
|
39840
|
+
Math.max(0, timeoutMs)
|
|
39841
|
+
);
|
|
39842
|
+
});
|
|
39843
|
+
}
|
|
39844
|
+
};
|
|
39845
|
+
var Caller = class {
|
|
39846
|
+
link;
|
|
39847
|
+
max;
|
|
39848
|
+
stages = 0;
|
|
39849
|
+
constructor(link2, max) {
|
|
39850
|
+
this.link = link2;
|
|
39851
|
+
this.max = max;
|
|
39852
|
+
}
|
|
39853
|
+
async pull(part, out, from, label) {
|
|
39854
|
+
for (let offset = from; offset < out.length; ) {
|
|
39855
|
+
const reply = await this.link.call({ type: ASYNC_MORE, part, offset });
|
|
39856
|
+
const bytes = reply?.bytes;
|
|
39857
|
+
if (!(bytes instanceof Uint8Array) || bytes.length === 0) throw syncError("EIO", label);
|
|
39858
|
+
if (offset + bytes.length > out.length) throw syncError("EIO", label);
|
|
39859
|
+
out.set(bytes, offset);
|
|
39860
|
+
offset += bytes.length;
|
|
39861
|
+
}
|
|
39862
|
+
}
|
|
39863
|
+
async snapshot(token, out) {
|
|
39864
|
+
for (let offset = 0; offset < out.length; ) {
|
|
39865
|
+
const reply = await this.link.call({
|
|
39866
|
+
type: ASYNC_SNAPSHOT,
|
|
39867
|
+
token,
|
|
39868
|
+
offset
|
|
39869
|
+
});
|
|
39870
|
+
const bytes = reply?.bytes;
|
|
39871
|
+
if (!(bytes instanceof Uint8Array) || bytes.length === 0)
|
|
39872
|
+
throw syncError("EIO", "fork memory");
|
|
39873
|
+
if (offset + bytes.length > out.length) throw syncError("EIO", "fork memory");
|
|
39874
|
+
out.set(bytes, offset);
|
|
39875
|
+
offset += bytes.length;
|
|
39876
|
+
}
|
|
39877
|
+
}
|
|
39878
|
+
async stage(body) {
|
|
39879
|
+
const id2 = ++this.stages;
|
|
39880
|
+
for (let offset = 0; offset < body.length; offset += this.max) {
|
|
39881
|
+
const bytes = body.slice(offset, Math.min(body.length, offset + this.max));
|
|
39882
|
+
await this.link.call({ type: ASYNC_STAGE, stage: id2, offset, total: body.length, bytes }, [
|
|
39883
|
+
bytes.buffer
|
|
39884
|
+
]);
|
|
39885
|
+
}
|
|
39886
|
+
return id2;
|
|
39887
|
+
}
|
|
39888
|
+
staging(asked) {
|
|
39889
|
+
const body = bodyOf2(asked);
|
|
39890
|
+
return body && body.byteLength > this.max ? body : void 0;
|
|
39891
|
+
}
|
|
39892
|
+
async staged(asked, body, timeoutMs, label) {
|
|
39893
|
+
const staged2 = await withTimeout(this.stage(body), timeoutMs, label).catch(() => {
|
|
39894
|
+
throw syncError("EIO", label);
|
|
39895
|
+
});
|
|
39896
|
+
const { body: _dropped, ...rest2 } = asked;
|
|
39897
|
+
return { req: rest2, transfer: [], staged: staged2 };
|
|
39898
|
+
}
|
|
39899
|
+
exact(asked, given) {
|
|
39900
|
+
const body = bodyOf2(asked);
|
|
39901
|
+
if (!body) return { req: asked, transfer: given };
|
|
39902
|
+
const exact2 = exactCopy(body);
|
|
39903
|
+
if (exact2.body === body) return { req: asked, transfer: given };
|
|
39904
|
+
return {
|
|
39905
|
+
req: { ...asked, body: exact2.body },
|
|
39906
|
+
transfer: [...given, ...exact2.transfer]
|
|
39907
|
+
};
|
|
39908
|
+
}
|
|
39909
|
+
async answer(reply, timeoutMs, label, sink) {
|
|
39910
|
+
const { status, total, bytes } = reply;
|
|
39911
|
+
if (reply.part === void 0) {
|
|
39912
|
+
if (!sink || status !== SAB_STATUS_BYTES || bytes.length > sink.length) {
|
|
39913
|
+
return decodeSabResult(status, bytes);
|
|
39914
|
+
}
|
|
39915
|
+
const out2 = landing(status, bytes.length, sink);
|
|
39916
|
+
out2.set(bytes);
|
|
39917
|
+
return decodeSabResult(status, out2);
|
|
39918
|
+
}
|
|
39919
|
+
const out = landing(status, total, sink);
|
|
39920
|
+
out.set(bytes);
|
|
39921
|
+
await withTimeout(this.pull(reply.part, out, bytes.length, label), timeoutMs, label).catch(
|
|
39922
|
+
(err) => {
|
|
39923
|
+
throw err.code === "EIO" ? err : syncError("EIO", label);
|
|
39924
|
+
}
|
|
39925
|
+
);
|
|
39926
|
+
return decodeSabResult(status, out);
|
|
39927
|
+
}
|
|
39928
|
+
};
|
|
39929
|
+
function createAsyncTransport(link2, options = {}) {
|
|
39930
|
+
const mirrors = new Mirrors();
|
|
39931
|
+
const caller = new Caller(link2, options.maxMessageBytes ?? Number.POSITIVE_INFINITY);
|
|
39932
|
+
const started = Promise.withResolvers();
|
|
39933
|
+
let words3 = 0;
|
|
39934
|
+
let initialised = false;
|
|
39935
|
+
let closedBy;
|
|
39936
|
+
const current = () => mirrors.words(++words3, options.memory?.());
|
|
39937
|
+
const begin = async (init) => {
|
|
39938
|
+
mirrors.start(init.mirror);
|
|
39939
|
+
if (options.maxMessageBytes === void 0 && init.maxMessageBytes !== void 0) {
|
|
39940
|
+
caller.max = init.maxMessageBytes;
|
|
39941
|
+
}
|
|
39942
|
+
const fork = init.fork;
|
|
39943
|
+
const ref = fork?.snapshot;
|
|
39944
|
+
if (fork && ref) {
|
|
39945
|
+
delete fork.snapshot;
|
|
39946
|
+
const local2 = options.snapshots?.take(ref.token);
|
|
39947
|
+
if (local2 && local2.byteLength === ref.total) {
|
|
39948
|
+
fork.memory = local2;
|
|
39949
|
+
link2.post({ type: ASYNC_SNAPSHOT_TAKEN, token: ref.token });
|
|
39950
|
+
} else {
|
|
39951
|
+
const whole = new Uint8Array(ref.total);
|
|
39952
|
+
await caller.snapshot(ref.token, whole);
|
|
39953
|
+
fork.memory = whole;
|
|
39954
|
+
}
|
|
39955
|
+
}
|
|
39956
|
+
const memory = init.fork?.memory;
|
|
39957
|
+
if (memory && !(memory instanceof Uint8Array) && init.fork) {
|
|
39958
|
+
const whole = new Uint8Array(memory.total);
|
|
39959
|
+
await caller.pull(memory.part, whole, 0, "fork memory");
|
|
39960
|
+
init.fork.memory = whole;
|
|
39961
|
+
}
|
|
39962
|
+
started.resolve(init);
|
|
39963
|
+
};
|
|
39964
|
+
link2.onMessage((message3) => {
|
|
39965
|
+
const data = message3;
|
|
39966
|
+
if (!initialised && data?.type === "wasm-process-init") {
|
|
39967
|
+
initialised = true;
|
|
39968
|
+
begin(data).catch((err) => started.reject(err));
|
|
39969
|
+
} else if (initialised && data?.type === ASYNC_MIRROR && data.mirror) {
|
|
39970
|
+
void mirrors.accept(data.mirror);
|
|
39971
|
+
}
|
|
39972
|
+
});
|
|
39973
|
+
link2.onClose((reason) => {
|
|
39974
|
+
closedBy = reason;
|
|
39975
|
+
if (!initialised) started.reject(new Error(`the kernel link closed: ${reason}`));
|
|
39976
|
+
mirrors.failAll(syncError("EIO", `kernel link closed: ${reason}`));
|
|
39977
|
+
});
|
|
39978
|
+
const send2 = (msg, transfer, ms, label) => {
|
|
39979
|
+
const answered2 = link2.call(msg, transfer).then(async (value2) => {
|
|
39980
|
+
const reply = value2;
|
|
39981
|
+
if (!reply || !isAnswer(reply)) throw syncError("EIO", label);
|
|
39982
|
+
await mirrors.accept(reply.mirror);
|
|
39983
|
+
return reply;
|
|
39984
|
+
});
|
|
39985
|
+
answered2.catch(() => void 0);
|
|
39986
|
+
return withTimeout(answered2, ms, label).catch((err) => {
|
|
39987
|
+
throw err.code === "EIO" ? err : syncError("EIO", label);
|
|
39988
|
+
});
|
|
39989
|
+
};
|
|
39990
|
+
const issue = async (asked, given, ms, label) => {
|
|
39991
|
+
const words4 = current();
|
|
39992
|
+
const body = caller.staging(asked);
|
|
39993
|
+
if (!body) {
|
|
39994
|
+
const { req: req2, transfer } = caller.exact(asked, given);
|
|
39995
|
+
return send2({ type: ASYNC_SYSCALL, req: req2, words: words4 }, transfer, ms, label);
|
|
39996
|
+
}
|
|
39997
|
+
const { req, staged: staged2 } = await caller.staged(asked, body, ms, label);
|
|
39998
|
+
return send2({ type: ASYNC_SYSCALL, req, words: words4, staged: staged2 }, [], ms, label);
|
|
39999
|
+
};
|
|
40000
|
+
return {
|
|
40001
|
+
init: started.promise,
|
|
40002
|
+
buffer: mirrors.buffer,
|
|
40003
|
+
header: mirrors.header,
|
|
40004
|
+
clock: mirrors.clock,
|
|
40005
|
+
get changes() {
|
|
40006
|
+
return mirrors.changes;
|
|
40007
|
+
},
|
|
40008
|
+
get cwds() {
|
|
40009
|
+
return mirrors.cwds;
|
|
40010
|
+
},
|
|
40011
|
+
get closed() {
|
|
40012
|
+
return closedBy !== void 0;
|
|
40013
|
+
},
|
|
40014
|
+
async call(asked, askedMs, label, given = [], sink) {
|
|
40015
|
+
const timeoutMs = options.deadlines === false ? Number.POSITIVE_INFINITY : askedMs;
|
|
40016
|
+
if (closedBy !== void 0) throw syncError("EIO", label);
|
|
40017
|
+
const { req, token } = snapshotted(asked, options.snapshots);
|
|
40018
|
+
const forget = () => {
|
|
40019
|
+
if (token !== void 0) options.snapshots?.release(token);
|
|
40020
|
+
};
|
|
40021
|
+
try {
|
|
40022
|
+
const reply = await issue(req, given, timeoutMs, label);
|
|
40023
|
+
const result = await caller.answer(reply, timeoutMs, label, sink);
|
|
40024
|
+
if (!result.ok) forget();
|
|
40025
|
+
return result;
|
|
40026
|
+
} catch (err) {
|
|
40027
|
+
forget();
|
|
40028
|
+
throw err;
|
|
40029
|
+
}
|
|
40030
|
+
},
|
|
40031
|
+
wait(view2, index, value2, timeoutMs = Number.POSITIVE_INFINITY) {
|
|
40032
|
+
if (Atomics.load(view2, index) !== value2) return Promise.resolve("not-equal");
|
|
40033
|
+
if (closedBy !== void 0) {
|
|
40034
|
+
return Promise.reject(syncError("EIO", `kernel link closed: ${closedBy}`));
|
|
40035
|
+
}
|
|
40036
|
+
return mirrors.wait(view2, index, value2, timeoutMs);
|
|
40037
|
+
},
|
|
40038
|
+
notify: (view2, index) => mirrors.notify(view2, index),
|
|
40039
|
+
publish() {
|
|
40040
|
+
if (closedBy === void 0 && initialised) {
|
|
40041
|
+
link2.post({ type: ASYNC_WORDS, words: current() });
|
|
40042
|
+
}
|
|
40043
|
+
},
|
|
40044
|
+
post(message3, transfer) {
|
|
40045
|
+
if (closedBy === void 0) link2.post(message3, transfer);
|
|
40046
|
+
},
|
|
40047
|
+
onClose: (handler) => link2.onClose(handler)
|
|
40048
|
+
};
|
|
40049
|
+
}
|
|
40050
|
+
|
|
38802
40051
|
// src/client/dial-stream.ts
|
|
38803
40052
|
function errorWithCode(message3) {
|
|
38804
40053
|
const code = /^E[A-Z]+/.exec(message3)?.[0];
|
|
@@ -38957,7 +40206,7 @@ async function* counted2(source, length2) {
|
|
|
38957
40206
|
async function* untilClose2(source) {
|
|
38958
40207
|
for (let data = await source.some(65536); data; data = await source.some(65536)) yield data;
|
|
38959
40208
|
}
|
|
38960
|
-
function
|
|
40209
|
+
function bodyOf3(source, head, method) {
|
|
38961
40210
|
if (method === "HEAD" || head.status === 204 || head.status === 304) return void 0;
|
|
38962
40211
|
if (header4(head, "transfer-encoding")?.toLowerCase().includes("chunked")) return chunked2(source);
|
|
38963
40212
|
const length2 = header4(head, "content-length");
|
|
@@ -39025,7 +40274,7 @@ async function loopbackFetch(dial, input, options) {
|
|
|
39025
40274
|
if (!raw2) throw errorWithCode("ECONNRESET: the connection closed before a response");
|
|
39026
40275
|
head = parseHead2(raw2);
|
|
39027
40276
|
} while (head.status >= 100 && head.status < 200);
|
|
39028
|
-
const chunks2 =
|
|
40277
|
+
const chunks2 = bodyOf3(source, head, request.method);
|
|
39029
40278
|
if (!chunks2) socket.close();
|
|
39030
40279
|
return new Response(chunks2 ? stream(chunks2, socket, options.signal) : null, {
|
|
39031
40280
|
status: head.status,
|
|
@@ -39566,6 +40815,12 @@ async function attachKernel(port, options = {}) {
|
|
|
39566
40815
|
}
|
|
39567
40816
|
|
|
39568
40817
|
// src/node.ts
|
|
40818
|
+
function tuningOf(options) {
|
|
40819
|
+
return {
|
|
40820
|
+
...options.wasmMemories ? { wasmMemories: options.wasmMemories } : {},
|
|
40821
|
+
...options.emscripten ? { emscripten: options.emscripten } : {}
|
|
40822
|
+
};
|
|
40823
|
+
}
|
|
39569
40824
|
function hostfsFetchOf(options) {
|
|
39570
40825
|
const { hostfsFetch, hostfsOrigin } = options;
|
|
39571
40826
|
if (hostfsOrigin === void 0) return hostfsFetch ? { hostfsFetch } : {};
|
|
@@ -39588,7 +40843,7 @@ function nodeTransport(options = {}) {
|
|
|
39588
40843
|
const open = { ...transport, traits: { ...transport.traits, crossOrigin: "any" } };
|
|
39589
40844
|
return diagnosing(guardedLoopback(open, options.hostLoopback ?? false));
|
|
39590
40845
|
}
|
|
39591
|
-
var
|
|
40846
|
+
var TERMINATED2 = "the kernel is terminated";
|
|
39592
40847
|
var EXIT_GRACE_MS = 50;
|
|
39593
40848
|
var WARM_IDLE_MS = 3e4;
|
|
39594
40849
|
var MAX_WARM_WORKERS = 64;
|
|
@@ -39692,7 +40947,7 @@ function processWorker(file, workerData, internals = false) {
|
|
|
39692
40947
|
return internals ? internalsWorker(make) : make();
|
|
39693
40948
|
}
|
|
39694
40949
|
function sourceModule(source) {
|
|
39695
|
-
const url = `slicc-module:${
|
|
40950
|
+
const url = `slicc-module:${createHash2("sha256").update(source).digest("hex")}`;
|
|
39696
40951
|
return { url, source, revoke: () => {
|
|
39697
40952
|
} };
|
|
39698
40953
|
}
|
|
@@ -39716,7 +40971,7 @@ function nodeWorker(file, live2, closed, workerData, take, internals = false) {
|
|
|
39716
40971
|
const kill = () => {
|
|
39717
40972
|
ending = true;
|
|
39718
40973
|
void worker.terminate();
|
|
39719
|
-
fail3(
|
|
40974
|
+
fail3(TERMINATED2);
|
|
39720
40975
|
};
|
|
39721
40976
|
live2.add(kill);
|
|
39722
40977
|
worker.once("exit", (code) => {
|
|
@@ -39727,7 +40982,7 @@ function nodeWorker(file, live2, closed, workerData, take, internals = false) {
|
|
|
39727
40982
|
});
|
|
39728
40983
|
worker.on("error", (err) => fail3(String(err)));
|
|
39729
40984
|
} else {
|
|
39730
|
-
setTimeout(() => fail3(
|
|
40985
|
+
setTimeout(() => fail3(TERMINATED2), 0);
|
|
39731
40986
|
}
|
|
39732
40987
|
return {
|
|
39733
40988
|
postMessage: (message3, transfer) => worker?.postMessage(message3, transfer),
|
|
@@ -39850,7 +41105,7 @@ var nodeSessions = 0;
|
|
|
39850
41105
|
var portSessions = /* @__PURE__ */ new WeakMap();
|
|
39851
41106
|
function nodeClient(launcher, clients, { user, tag, requests, devices }) {
|
|
39852
41107
|
tagOption(tag);
|
|
39853
|
-
const { port1, port2 } = new
|
|
41108
|
+
const { port1, port2 } = new MessageChannel4();
|
|
39854
41109
|
const session = ++nodeSessions;
|
|
39855
41110
|
const served2 = serveClient(port1, {
|
|
39856
41111
|
launcher: async () => launcher,
|
|
@@ -39882,6 +41137,32 @@ function checkedRequests(hook) {
|
|
|
39882
41137
|
const kinds = kindsOf(hook);
|
|
39883
41138
|
return { kinds, handle: (request) => hook.handle(request) };
|
|
39884
41139
|
}
|
|
41140
|
+
function rootFs(root, options) {
|
|
41141
|
+
return new OpfsFs(root, options.meta, void 0, {
|
|
41142
|
+
ranged: options.ranged ?? isMemoryRoot(root)
|
|
41143
|
+
});
|
|
41144
|
+
}
|
|
41145
|
+
function blockingOf(options) {
|
|
41146
|
+
const { blocking } = options;
|
|
41147
|
+
if (blocking === void 0 || blocking === "sync" || blocking === "async")
|
|
41148
|
+
return blocking ?? "sync";
|
|
41149
|
+
throw new TypeError("createNodeKernel: blocking must be 'sync' or 'async'");
|
|
41150
|
+
}
|
|
41151
|
+
function processWorkers(options, file, workerData, live2, closed) {
|
|
41152
|
+
if (blockingOf(options) === "async") {
|
|
41153
|
+
const remote = nodeAsyncHost(options.asyncProcess ?? {}, live2);
|
|
41154
|
+
return {
|
|
41155
|
+
warm: void 0,
|
|
41156
|
+
launch: { createWorker: () => remote.createWorker(closed()), compile: remote.compile }
|
|
41157
|
+
};
|
|
41158
|
+
}
|
|
41159
|
+
const warm = warmPoolOf(options, file, workerData, live2);
|
|
41160
|
+
const take = warm ? () => warm.take() : void 0;
|
|
41161
|
+
return {
|
|
41162
|
+
warm,
|
|
41163
|
+
launch: { createWorker: () => nodeWorker(file, live2, closed(), workerData, take, true) }
|
|
41164
|
+
};
|
|
41165
|
+
}
|
|
39885
41166
|
function nodeAccounts(launcher, guard2) {
|
|
39886
41167
|
return {
|
|
39887
41168
|
users: {
|
|
@@ -39926,7 +41207,7 @@ async function createNodeKernel(options = {}) {
|
|
|
39926
41207
|
const hooks = sealedHooks(options.sealed);
|
|
39927
41208
|
const timeZone = systemTimeZone(options.timeZone, clockZone(options.cron?.clock));
|
|
39928
41209
|
const root = options.root ?? memoryRoot();
|
|
39929
|
-
const fs =
|
|
41210
|
+
const fs = rootFs(root, options);
|
|
39930
41211
|
await fs.reconcile();
|
|
39931
41212
|
const live2 = /* @__PURE__ */ new Set();
|
|
39932
41213
|
const pending = /* @__PURE__ */ new Set();
|
|
@@ -39935,13 +41216,14 @@ async function createNodeKernel(options = {}) {
|
|
|
39935
41216
|
const file = options.worker ?? new URL("./node-process-worker.cjs", import.meta.url);
|
|
39936
41217
|
const cache = cacheDirOf(options.compileCache);
|
|
39937
41218
|
const workerData = cacheData(cache);
|
|
39938
|
-
const warm =
|
|
41219
|
+
const { warm, launch } = processWorkers(options, file, workerData, live2, () => terminated);
|
|
39939
41220
|
const transport = options.network?.transport;
|
|
39940
41221
|
const launcher = new Launcher({
|
|
39941
41222
|
fs,
|
|
39942
41223
|
moduleUrl: sourceModule,
|
|
39943
41224
|
unlinkOwner: pidOwner(process),
|
|
39944
|
-
|
|
41225
|
+
...options.durable ? { durable: options.durable } : {},
|
|
41226
|
+
...launch,
|
|
39945
41227
|
createDriverWorker: () => nodeWorker(
|
|
39946
41228
|
options.driverWorker ?? new URL("./node-driver-worker.js", import.meta.url),
|
|
39947
41229
|
live2,
|
|
@@ -39968,12 +41250,12 @@ async function createNodeKernel(options = {}) {
|
|
|
39968
41250
|
...hooks.fetch ? { sealedFetch: hooks.fetch } : {},
|
|
39969
41251
|
...pageHooks(options),
|
|
39970
41252
|
...options.sudo?.clock ? { sudoClock: options.sudo.clock } : {},
|
|
39971
|
-
...options
|
|
41253
|
+
...tuningOf(options),
|
|
39972
41254
|
cron: { lock: cronLock(root), ...options.cron?.clock ? { clock: options.cron.clock } : {} }
|
|
39973
41255
|
});
|
|
39974
41256
|
await launcher.prepare();
|
|
39975
41257
|
const guard2 = (work) => new Promise((resolve2, reject) => {
|
|
39976
|
-
if (terminated) return reject(new Error(
|
|
41258
|
+
if (terminated) return reject(new Error(TERMINATED2));
|
|
39977
41259
|
pending.add(reject);
|
|
39978
41260
|
work().then(resolve2, reject).finally(() => pending.delete(reject));
|
|
39979
41261
|
});
|
|
@@ -40052,7 +41334,7 @@ async function createNodeKernel(options = {}) {
|
|
|
40052
41334
|
sudoRun: (replay, sudoOptions = {}) => nodeSudoRun(launcher, guard2, replay, sudoOptions),
|
|
40053
41335
|
devices: nodeDevices(launcher, guard2),
|
|
40054
41336
|
async connect(connectOptions = {}) {
|
|
40055
|
-
if (terminated) throw new Error(
|
|
41337
|
+
if (terminated) throw new Error(TERMINATED2);
|
|
40056
41338
|
const { user } = connectOptions;
|
|
40057
41339
|
if (user !== void 0 && !await guard2(() => launcher.users.lookup(user))) {
|
|
40058
41340
|
throw fsError("ENOENT", `no user ${String(user)}`);
|
|
@@ -40063,7 +41345,7 @@ async function createNodeKernel(options = {}) {
|
|
|
40063
41345
|
terminated = true;
|
|
40064
41346
|
warm?.close();
|
|
40065
41347
|
for (const client of [...clients]) client.detach();
|
|
40066
|
-
for (const reject of [...pending]) reject(new Error(
|
|
41348
|
+
for (const reject of [...pending]) reject(new Error(TERMINATED2));
|
|
40067
41349
|
for (const kill of [...live2]) kill();
|
|
40068
41350
|
launcher.cdp.close();
|
|
40069
41351
|
launcher.endFills();
|
|
@@ -40079,14 +41361,17 @@ export {
|
|
|
40079
41361
|
SEALED_FETCH_VERSION,
|
|
40080
41362
|
WARM_IDLE_MS,
|
|
40081
41363
|
attachKernel,
|
|
41364
|
+
createAsyncTransport,
|
|
40082
41365
|
createNodeKernel,
|
|
40083
41366
|
fetchTransport,
|
|
40084
41367
|
internalsWorker,
|
|
40085
41368
|
memoryRoot,
|
|
41369
|
+
messageLinks,
|
|
40086
41370
|
narrowArgv,
|
|
40087
41371
|
nodeTransport,
|
|
40088
41372
|
ownCacheDir,
|
|
40089
41373
|
privateCacheDir,
|
|
41374
|
+
remoteWorker,
|
|
40090
41375
|
resetInternalArgv,
|
|
40091
41376
|
serveHostfsPort,
|
|
40092
41377
|
sourceModule,
|