@ai-ecoverse/slicc-kernel 1.32.3 → 1.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -1
- package/dist/index.js.map +2 -2
- package/dist/kernel-worker.js +193 -49
- package/dist/kernel-worker.js.map +3 -3
- package/dist/node-process-worker.js +806 -40
- package/dist/node-process-worker.js.map +4 -4
- package/dist/node.js +193 -49
- package/dist/node.js.map +3 -3
- package/dist/process-worker.js +807 -40
- package/dist/process-worker.js.map +4 -4
- package/package.json +2 -1
|
@@ -1319,7 +1319,7 @@ function sabViews(sab) {
|
|
|
1319
1319
|
window: new Uint8Array(sab, SAB_HEADER_BYTES)
|
|
1320
1320
|
};
|
|
1321
1321
|
}
|
|
1322
|
-
var SAB_HEADER_I32, SAB_HEADER_BYTES, SAB_I_STATE, SAB_I_SEQ, SAB_I_STATUS, SAB_I_TOTAL, SAB_I_CHUNK, SAB_I_OFFSET, SAB_I_REQ, SAB_I_PUB, SAB_I_SIGNALS, SAB_I_TIMERS, SAB_I_MEMORY, SAB_I_TOTAL_HI, SAB_I_OFFSET_HI, SAB_I_KILLED, U32, SAB_STATE_IDLE, SAB_STATE_PENDING, SAB_STATE_READY, SAB_STATUS_BYTES, SAB_STATUS_JSON, SAB_STATUS_VOID, SAB_STATUS_ERRNO, SAB_DEFAULT_WINDOW_BYTES, SAB_MIN_BYTES, SYNC_SAB_REQ_MSG, SYNC_SAB_NEXT_MSG, encoder, decoder;
|
|
1322
|
+
var SAB_HEADER_I32, SAB_HEADER_BYTES, SAB_I_STATE, SAB_I_SEQ, SAB_I_STATUS, SAB_I_TOTAL, SAB_I_CHUNK, SAB_I_OFFSET, SAB_I_REQ, SAB_I_PUB, SAB_I_SIGNALS, SAB_I_TIMERS, SAB_I_MEMORY, SAB_I_TOTAL_HI, SAB_I_OFFSET_HI, SAB_I_KILLED, SAB_I_ASYNC, SAB_I_STOP, U32, SAB_STATE_IDLE, SAB_STATE_PENDING, SAB_STATE_READY, SAB_STATUS_BYTES, SAB_STATUS_JSON, SAB_STATUS_VOID, SAB_STATUS_ERRNO, SAB_DEFAULT_WINDOW_BYTES, SAB_MIN_BYTES, SYNC_SAB_REQ_MSG, SYNC_SAB_NEXT_MSG, encoder, decoder;
|
|
1323
1323
|
var init_sync_sab_wire = __esm({
|
|
1324
1324
|
"src/realm/sync-sab-wire.ts"() {
|
|
1325
1325
|
"use strict";
|
|
@@ -1339,6 +1339,8 @@ var init_sync_sab_wire = __esm({
|
|
|
1339
1339
|
SAB_I_TOTAL_HI = 11;
|
|
1340
1340
|
SAB_I_OFFSET_HI = 12;
|
|
1341
1341
|
SAB_I_KILLED = 13;
|
|
1342
|
+
SAB_I_ASYNC = 14;
|
|
1343
|
+
SAB_I_STOP = 15;
|
|
1342
1344
|
U32 = 2 ** 32;
|
|
1343
1345
|
SAB_STATE_IDLE = 0;
|
|
1344
1346
|
SAB_STATE_PENDING = 1;
|
|
@@ -2214,6 +2216,47 @@ function positionalIo(imports, deps) {
|
|
|
2214
2216
|
}
|
|
2215
2217
|
}
|
|
2216
2218
|
}
|
|
2219
|
+
function staging(Fs, length) {
|
|
2220
|
+
try {
|
|
2221
|
+
return new Uint8Array(length);
|
|
2222
|
+
} catch {
|
|
2223
|
+
throw new Fs.ErrnoError(wasiErrno("ENOMEM"));
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
function useFileMmap(Fs, deps) {
|
|
2227
|
+
const fs = Fs;
|
|
2228
|
+
const mmap = fs.mmap;
|
|
2229
|
+
if (typeof mmap !== "function") return;
|
|
2230
|
+
fs.mmap = (stream, length, position, prot, flags) => {
|
|
2231
|
+
const memalign = deps.memalign();
|
|
2232
|
+
const memory = deps.memory();
|
|
2233
|
+
const shared = (flags & MAP_TYPE) !== MAP_PRIVATE && (prot & PROT_WRITE) !== 0;
|
|
2234
|
+
const kfd = stream.sliccKernelFile ? stream.sliccKernelFd : void 0;
|
|
2235
|
+
if (shared && kfd !== void 0) throw new Fs.ErrnoError(wasiErrno("ENODEV"));
|
|
2236
|
+
if (stream.stream_ops.mmap && kfd === void 0 || !memalign || !memory || length <= 0 || shared || (stream.flags & O_ACCMODE) === O_WRONLY || !Fs.isFile(stream.node.mode)) {
|
|
2237
|
+
return mmap.call(fs, stream, length, position, prot, flags);
|
|
2238
|
+
}
|
|
2239
|
+
const data = staging(Fs, length);
|
|
2240
|
+
let done = 0;
|
|
2241
|
+
try {
|
|
2242
|
+
if (kfd !== void 0) done = readInto(deps.sys, kfd, data, position);
|
|
2243
|
+
else {
|
|
2244
|
+
for (let got = 1; done < length && got > 0; done += got) {
|
|
2245
|
+
got = Fs.read(stream, data, done, length - done, position + done);
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
} catch (err) {
|
|
2249
|
+
throw new Fs.ErrnoError(errnoOf(err));
|
|
2250
|
+
}
|
|
2251
|
+
const size = Math.ceil(length / MAP_ALIGN) * MAP_ALIGN;
|
|
2252
|
+
const ptr = memalign(MAP_ALIGN, size);
|
|
2253
|
+
if (!ptr) throw new Fs.ErrnoError(wasiErrno("ENOMEM"));
|
|
2254
|
+
const target = new Uint8Array(memory.buffer, ptr, size);
|
|
2255
|
+
target.fill(0);
|
|
2256
|
+
target.set(data.subarray(0, done));
|
|
2257
|
+
return { ptr, allocated: true };
|
|
2258
|
+
};
|
|
2259
|
+
}
|
|
2217
2260
|
function wasmMemory(instance, imports) {
|
|
2218
2261
|
const isMemory = (v) => v instanceof WebAssembly.Memory;
|
|
2219
2262
|
const exported = Object.values(instance.exports).find(isMemory);
|
|
@@ -2410,7 +2453,7 @@ function useMounts(Fs, env = {}, live = false) {
|
|
|
2410
2453
|
}
|
|
2411
2454
|
};
|
|
2412
2455
|
}
|
|
2413
|
-
var O_CLOEXEC, FD_CLOEXEC, F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_DUPFD_CLOEXEC, tracked, IMPORT_NAMES, EBADF, AT_SYMLINK_NOFOLLOW, EMSCRIPTEN_EPERM, O_PATH, DIR_MODE, LINK_MODE, CHAR_DEVICE, O_ACCMODE, O_CREAT2, field, NAME;
|
|
2456
|
+
var O_CLOEXEC, FD_CLOEXEC, F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_DUPFD_CLOEXEC, tracked, IMPORT_NAMES, EBADF, AT_SYMLINK_NOFOLLOW, EMSCRIPTEN_EPERM, O_PATH, PROT_WRITE, MAP_PRIVATE, MAP_TYPE, O_WRONLY, MAP_ALIGN, DIR_MODE, LINK_MODE, CHAR_DEVICE, O_ACCMODE, O_CREAT2, field, NAME;
|
|
2414
2457
|
var init_process_fds = __esm({
|
|
2415
2458
|
"src/process/process-fds.ts"() {
|
|
2416
2459
|
"use strict";
|
|
@@ -2438,6 +2481,11 @@ var init_process_fds = __esm({
|
|
|
2438
2481
|
AT_SYMLINK_NOFOLLOW = 256;
|
|
2439
2482
|
EMSCRIPTEN_EPERM = 63;
|
|
2440
2483
|
O_PATH = 2097152;
|
|
2484
|
+
PROT_WRITE = 2;
|
|
2485
|
+
MAP_PRIVATE = 2;
|
|
2486
|
+
MAP_TYPE = 15;
|
|
2487
|
+
O_WRONLY = 1;
|
|
2488
|
+
MAP_ALIGN = 65536;
|
|
2441
2489
|
DIR_MODE = 16749;
|
|
2442
2490
|
LINK_MODE = 41408;
|
|
2443
2491
|
CHAR_DEVICE = 8630;
|
|
@@ -2905,8 +2953,8 @@ var init_process_http = __esm({
|
|
|
2905
2953
|
"use strict";
|
|
2906
2954
|
HttpError = class extends Error {
|
|
2907
2955
|
code;
|
|
2908
|
-
constructor(code2,
|
|
2909
|
-
super(
|
|
2956
|
+
constructor(code2, message2) {
|
|
2957
|
+
super(message2);
|
|
2910
2958
|
this.code = code2;
|
|
2911
2959
|
}
|
|
2912
2960
|
};
|
|
@@ -3006,7 +3054,7 @@ function socketNode(Fs, addr) {
|
|
|
3006
3054
|
const fs = Fs;
|
|
3007
3055
|
let stream;
|
|
3008
3056
|
try {
|
|
3009
|
-
stream = Fs.open(addr.path,
|
|
3057
|
+
stream = Fs.open(addr.path, O_WRONLY2 | O_CREAT4 | O_EXCL3, 493);
|
|
3010
3058
|
} catch (e) {
|
|
3011
3059
|
if (e?.errno === wasiErrno("EEXIST")) {
|
|
3012
3060
|
throw new SyscallError("EADDRINUSE");
|
|
@@ -3138,7 +3186,7 @@ function createSocketKernel(deps) {
|
|
|
3138
3186
|
})
|
|
3139
3187
|
};
|
|
3140
3188
|
}
|
|
3141
|
-
var O_RDWR2, KILLED_BY_SIGPIPE2,
|
|
3189
|
+
var O_RDWR2, KILLED_BY_SIGPIPE2, O_WRONLY2, O_CREAT4, O_EXCL3;
|
|
3142
3190
|
var init_process_sockets = __esm({
|
|
3143
3191
|
"src/process/process-sockets.ts"() {
|
|
3144
3192
|
"use strict";
|
|
@@ -3148,7 +3196,7 @@ var init_process_sockets = __esm({
|
|
|
3148
3196
|
init_wasi_errno();
|
|
3149
3197
|
O_RDWR2 = 2;
|
|
3150
3198
|
KILLED_BY_SIGPIPE2 = 128 + 13;
|
|
3151
|
-
|
|
3199
|
+
O_WRONLY2 = 1;
|
|
3152
3200
|
O_CREAT4 = 64;
|
|
3153
3201
|
O_EXCL3 = 128;
|
|
3154
3202
|
}
|
|
@@ -3617,7 +3665,7 @@ function wireKernelFd(Fs, streams, entry) {
|
|
|
3617
3665
|
});
|
|
3618
3666
|
}
|
|
3619
3667
|
function openDevice(Fs, fd, meta) {
|
|
3620
|
-
const flags = meta.access === "read" ? O_RDONLY : meta.access === "write" ?
|
|
3668
|
+
const flags = meta.access === "read" ? O_RDONLY : meta.access === "write" ? O_WRONLY3 : O_RDWR3;
|
|
3621
3669
|
let stream;
|
|
3622
3670
|
try {
|
|
3623
3671
|
stream = Fs.open(`/dev/${meta.device}`, flags);
|
|
@@ -3695,12 +3743,13 @@ async function runWasmProcess(init, port2, deps = {}) {
|
|
|
3695
3743
|
);
|
|
3696
3744
|
const transport = signals.transport();
|
|
3697
3745
|
const sys = kernelSys(transport);
|
|
3698
|
-
const
|
|
3699
|
-
const say = (fd) => (text) => sys.write(fd,
|
|
3746
|
+
const encoder3 = new TextEncoder();
|
|
3747
|
+
const say = (fd) => (text) => sys.write(fd, encoder3.encode(`${text}
|
|
3700
3748
|
`));
|
|
3701
3749
|
let ready;
|
|
3702
3750
|
let failed2;
|
|
3703
3751
|
let memory;
|
|
3752
|
+
let exports;
|
|
3704
3753
|
const initialized = new Promise((resolve, reject) => {
|
|
3705
3754
|
ready = resolve;
|
|
3706
3755
|
failed2 = reject;
|
|
@@ -3748,6 +3797,7 @@ async function runWasmProcess(init, port2, deps = {}) {
|
|
|
3748
3797
|
return WebAssembly.instantiate(init.program.module, imports);
|
|
3749
3798
|
}).then((instance) => {
|
|
3750
3799
|
memory = wasmMemory(instance, imports);
|
|
3800
|
+
exports = instance.exports;
|
|
3751
3801
|
publishMemory(init.sab, memory?.buffer.byteLength ?? 0);
|
|
3752
3802
|
done(instance, init.program.module);
|
|
3753
3803
|
}, failed2);
|
|
@@ -3794,6 +3844,11 @@ async function runWasmProcess(init, port2, deps = {}) {
|
|
|
3794
3844
|
if (pipefs) streams.usePipes(pipefs);
|
|
3795
3845
|
streams.useControllingTerminal();
|
|
3796
3846
|
useDevFd(running.FS);
|
|
3847
|
+
useFileMmap(running.FS, {
|
|
3848
|
+
sys,
|
|
3849
|
+
memory: () => memory,
|
|
3850
|
+
memalign: () => exports?.emscripten_builtin_memalign
|
|
3851
|
+
});
|
|
3797
3852
|
ownByRealmUser(running.FS);
|
|
3798
3853
|
const livePath = (s) => liveNodePath(s.node);
|
|
3799
3854
|
running.sliccKernel = createProcessKernel({
|
|
@@ -3865,7 +3920,7 @@ function runMain(running, init) {
|
|
|
3865
3920
|
return status2;
|
|
3866
3921
|
}
|
|
3867
3922
|
}
|
|
3868
|
-
var O_RDONLY,
|
|
3923
|
+
var O_RDONLY, O_WRONLY3, O_RDWR3, PLACED, GLUE_TRAILER, evaluateGlue, EVAL_BLOCKED;
|
|
3869
3924
|
var init_process_runtime = __esm({
|
|
3870
3925
|
"src/process/process-runtime.ts"() {
|
|
3871
3926
|
"use strict";
|
|
@@ -3886,7 +3941,7 @@ var init_process_runtime = __esm({
|
|
|
3886
3941
|
init_realm_user();
|
|
3887
3942
|
init_kernel_streams();
|
|
3888
3943
|
O_RDONLY = 0;
|
|
3889
|
-
|
|
3944
|
+
O_WRONLY3 = 1;
|
|
3890
3945
|
O_RDWR3 = 2;
|
|
3891
3946
|
PLACED = /* @__PURE__ */ new Set(["stream", "file", "socket"]);
|
|
3892
3947
|
GLUE_TRAILER = [
|
|
@@ -4346,7 +4401,7 @@ function promoteRequest(fd, f, handed) {
|
|
|
4346
4401
|
op: "fd-promote",
|
|
4347
4402
|
fd,
|
|
4348
4403
|
path: f.path,
|
|
4349
|
-
flags: (f.writable ? f.readable ? O_RDWR4 :
|
|
4404
|
+
flags: (f.writable ? f.readable ? O_RDWR4 : O_WRONLY4 : 0) | (f.append ? O_APPEND : 0),
|
|
4350
4405
|
position: f.offset,
|
|
4351
4406
|
...joins ? {} : { contents: f.buffer.contents() },
|
|
4352
4407
|
...orphan ? { orphan: true } : {},
|
|
@@ -4354,7 +4409,7 @@ function promoteRequest(fd, f, handed) {
|
|
|
4354
4409
|
...!joins && f.buffer.isDirty() ? { dirty: true } : {}
|
|
4355
4410
|
};
|
|
4356
4411
|
}
|
|
4357
|
-
var SYNTHETIC_DIRS2, O_NONBLOCK2,
|
|
4412
|
+
var SYNTHETIC_DIRS2, O_NONBLOCK2, O_WRONLY4, O_RDWR4, O_APPEND, DEVICES2, WasiFds, GEN;
|
|
4358
4413
|
var init_wasi_fds = __esm({
|
|
4359
4414
|
"src/process/wasi/wasi-fds.ts"() {
|
|
4360
4415
|
"use strict";
|
|
@@ -4362,7 +4417,7 @@ var init_wasi_fds = __esm({
|
|
|
4362
4417
|
init_wasi_files();
|
|
4363
4418
|
SYNTHETIC_DIRS2 = ["usr", "bin"];
|
|
4364
4419
|
O_NONBLOCK2 = 2048;
|
|
4365
|
-
|
|
4420
|
+
O_WRONLY4 = 1;
|
|
4366
4421
|
O_RDWR4 = 2;
|
|
4367
4422
|
O_APPEND = 1024;
|
|
4368
4423
|
DEVICES2 = {
|
|
@@ -4775,7 +4830,7 @@ var init_wasi_fds = __esm({
|
|
|
4775
4830
|
kernelFile(path, existing, oflags, rights, fdflags) {
|
|
4776
4831
|
const { readable, writable } = openAccess(existing, oflags, rights);
|
|
4777
4832
|
const append = (fdflags & FDFLAGS.APPEND) !== 0;
|
|
4778
|
-
const flags = (writable ? readable ? O_RDWR4 :
|
|
4833
|
+
const flags = (writable ? readable ? O_RDWR4 : O_WRONLY4 : 0) | (append ? O_APPEND : 0);
|
|
4779
4834
|
if (!existing) this.fs.writeFile(path, new Uint8Array(0));
|
|
4780
4835
|
const truncate = !existing || (oflags & OFLAGS.TRUNC) !== 0;
|
|
4781
4836
|
const fd = this.kernel.sys.openVfs(path, flags, 0, truncate ? { truncate } : {});
|
|
@@ -4874,11 +4929,11 @@ var init_wasi_memory = __esm({
|
|
|
4874
4929
|
return at;
|
|
4875
4930
|
}
|
|
4876
4931
|
putStrings(list, ptrs, buf) {
|
|
4877
|
-
const
|
|
4932
|
+
const encoder3 = new TextEncoder();
|
|
4878
4933
|
const v = this.view();
|
|
4879
4934
|
let at = buf;
|
|
4880
4935
|
list.forEach((s, i) => {
|
|
4881
|
-
const b =
|
|
4936
|
+
const b = encoder3.encode(s);
|
|
4882
4937
|
v.setUint32(ptrs + i * 4, at, true);
|
|
4883
4938
|
this.bytes(at, b.length).set(b);
|
|
4884
4939
|
v.setUint8(at + b.length, 0);
|
|
@@ -4886,12 +4941,12 @@ var init_wasi_memory = __esm({
|
|
|
4886
4941
|
});
|
|
4887
4942
|
}
|
|
4888
4943
|
putSizes(list, countPtr, sizePtr) {
|
|
4889
|
-
const
|
|
4944
|
+
const encoder3 = new TextEncoder();
|
|
4890
4945
|
const v = this.view();
|
|
4891
4946
|
v.setUint32(countPtr, list.length, true);
|
|
4892
4947
|
v.setUint32(
|
|
4893
4948
|
sizePtr,
|
|
4894
|
-
list.reduce((n, s) => n +
|
|
4949
|
+
list.reduce((n, s) => n + encoder3.encode(s).length + 1, 0),
|
|
4895
4950
|
true
|
|
4896
4951
|
);
|
|
4897
4952
|
}
|
|
@@ -5572,8 +5627,11 @@ function base64(text) {
|
|
|
5572
5627
|
}
|
|
5573
5628
|
return btoa(binary);
|
|
5574
5629
|
}
|
|
5630
|
+
function importSource(source) {
|
|
5631
|
+
return import(`data:text/javascript;base64,${base64(source)}`);
|
|
5632
|
+
}
|
|
5575
5633
|
async function loadImports(source) {
|
|
5576
|
-
const loaded = await
|
|
5634
|
+
const loaded = await importSource(source);
|
|
5577
5635
|
if (typeof loaded.createImports !== "function") {
|
|
5578
5636
|
throw new Error("the imports module exports no createImports function");
|
|
5579
5637
|
}
|
|
@@ -6401,12 +6459,12 @@ var init_wasix_linker = __esm({
|
|
|
6401
6459
|
slot(fn, handle, name) {
|
|
6402
6460
|
const known = this.slots.get(fn);
|
|
6403
6461
|
if (known !== void 0) return known;
|
|
6404
|
-
const
|
|
6462
|
+
const index2 = this.table.length;
|
|
6405
6463
|
this.table.grow(1);
|
|
6406
|
-
this.table.set(
|
|
6407
|
-
this.slots.set(fn,
|
|
6408
|
-
this.publisher?.({ kind: "slot", index, handle, name });
|
|
6409
|
-
return
|
|
6464
|
+
this.table.set(index2, fn);
|
|
6465
|
+
this.slots.set(fn, index2);
|
|
6466
|
+
this.publisher?.({ kind: "slot", index: index2, handle, name });
|
|
6467
|
+
return index2;
|
|
6410
6468
|
}
|
|
6411
6469
|
allocate(size, alignment) {
|
|
6412
6470
|
if (size === 0) return 0;
|
|
@@ -6422,7 +6480,7 @@ var init_wasix_linker = __esm({
|
|
|
6422
6480
|
function resolveFrom(cwd, path) {
|
|
6423
6481
|
return normalize(path.startsWith("/") ? path : `${cwd}/${path}`);
|
|
6424
6482
|
}
|
|
6425
|
-
var POSIX_TO_WASI_SIGNAL,
|
|
6483
|
+
var POSIX_TO_WASI_SIGNAL, O_WRONLY5, O_RDWR5, O_APPEND2, OFLAG_CREAT, OFLAG_TRUNC, WasixProcess;
|
|
6426
6484
|
var init_wasix_process = __esm({
|
|
6427
6485
|
"src/process/wasi/wasix-process.ts"() {
|
|
6428
6486
|
"use strict";
|
|
@@ -6432,7 +6490,7 @@ var init_wasix_process = __esm({
|
|
|
6432
6490
|
POSIX_TO_WASI_SIGNAL = Object.fromEntries(
|
|
6433
6491
|
Object.entries(WASI_SIGNAL_TO_POSIX).map(([wasi, posix]) => [posix, Number(wasi)])
|
|
6434
6492
|
);
|
|
6435
|
-
|
|
6493
|
+
O_WRONLY5 = 1;
|
|
6436
6494
|
O_RDWR5 = 2;
|
|
6437
6495
|
O_APPEND2 = 1024;
|
|
6438
6496
|
OFLAG_CREAT = 1;
|
|
@@ -6523,7 +6581,7 @@ var init_wasix_process = __esm({
|
|
|
6523
6581
|
throw Object.assign(new Error("ENOENT"), { code: "ENOENT" });
|
|
6524
6582
|
}
|
|
6525
6583
|
const flags = (op.rightsWrite ? O_RDWR5 : 0) | (op.append ? O_APPEND2 : 0);
|
|
6526
|
-
return this.host.o.kernel.sys.openVfs(path, op.rightsWrite ? flags ||
|
|
6584
|
+
return this.host.o.kernel.sys.openVfs(path, op.rightsWrite ? flags || O_WRONLY5 : 0, 0, {
|
|
6527
6585
|
...create ? { create } : {},
|
|
6528
6586
|
...op.oflags & OFLAG_TRUNC ? { truncate: true } : {}
|
|
6529
6587
|
});
|
|
@@ -7113,9 +7171,9 @@ var init_wasix_host = __esm({
|
|
|
7113
7171
|
}
|
|
7114
7172
|
dlImports() {
|
|
7115
7173
|
const { mem, host } = this;
|
|
7116
|
-
const failed2 = (
|
|
7174
|
+
const failed2 = (message2, buf, len) => {
|
|
7117
7175
|
if (len > 0) {
|
|
7118
|
-
const bytes = new TextEncoder().encode(
|
|
7176
|
+
const bytes = new TextEncoder().encode(message2).subarray(0, len - 1);
|
|
7119
7177
|
mem.bytes(buf, bytes.length).set(bytes);
|
|
7120
7178
|
mem.view().setUint8(buf + bytes.length, 0);
|
|
7121
7179
|
}
|
|
@@ -7267,10 +7325,10 @@ function parseFunctionNames(payload) {
|
|
|
7267
7325
|
if (end > payload.length) throw new RangeError("truncated name section");
|
|
7268
7326
|
if (id === 1) {
|
|
7269
7327
|
for (let count = leb(); count > 0; count--) {
|
|
7270
|
-
const
|
|
7328
|
+
const index2 = leb();
|
|
7271
7329
|
const length = leb();
|
|
7272
7330
|
if (at + length > end) throw new RangeError("truncated name section");
|
|
7273
|
-
names.set(
|
|
7331
|
+
names.set(index2, decoder3.decode(payload.subarray(at, at + length)));
|
|
7274
7332
|
at += length;
|
|
7275
7333
|
}
|
|
7276
7334
|
}
|
|
@@ -7294,7 +7352,7 @@ function nameFrame(line, module, name) {
|
|
|
7294
7352
|
}
|
|
7295
7353
|
function sidecarNames(read, path) {
|
|
7296
7354
|
let names;
|
|
7297
|
-
return (
|
|
7355
|
+
return (index2) => {
|
|
7298
7356
|
if (!names) {
|
|
7299
7357
|
try {
|
|
7300
7358
|
names = parseFunctionNames(read(path));
|
|
@@ -7302,7 +7360,7 @@ function sidecarNames(read, path) {
|
|
|
7302
7360
|
names = /* @__PURE__ */ new Map();
|
|
7303
7361
|
}
|
|
7304
7362
|
}
|
|
7305
|
-
return names.get(
|
|
7363
|
+
return names.get(index2);
|
|
7306
7364
|
};
|
|
7307
7365
|
}
|
|
7308
7366
|
var UNNAMED_FRAME, WASM_MODULE;
|
|
@@ -7767,6 +7825,706 @@ var init_wasi_runtime = __esm({
|
|
|
7767
7825
|
}
|
|
7768
7826
|
});
|
|
7769
7827
|
|
|
7828
|
+
// src/process/js/async-sab.ts
|
|
7829
|
+
async function changed(header, index2, seen, waitAsync = defaultWaitAsync) {
|
|
7830
|
+
const waited = waitAsync(header, index2, seen);
|
|
7831
|
+
if (waited.async) await waited.value;
|
|
7832
|
+
}
|
|
7833
|
+
function createAsyncSabTransport(sab, port2, waitAsync = defaultWaitAsync) {
|
|
7834
|
+
const { header, window } = sabViews(sab);
|
|
7835
|
+
let seq = 0;
|
|
7836
|
+
let tail = Promise.resolve();
|
|
7837
|
+
async function ready(id) {
|
|
7838
|
+
for (; ; ) {
|
|
7839
|
+
const published = Atomics.load(header, SAB_I_PUB);
|
|
7840
|
+
if (Atomics.load(header, SAB_I_STATE) === SAB_STATE_READY && Atomics.load(header, SAB_I_SEQ) === id) {
|
|
7841
|
+
return;
|
|
7842
|
+
}
|
|
7843
|
+
await changed(header, SAB_I_PUB, published, waitAsync);
|
|
7844
|
+
}
|
|
7845
|
+
}
|
|
7846
|
+
async function once(req) {
|
|
7847
|
+
const id = ++seq;
|
|
7848
|
+
let out = null;
|
|
7849
|
+
let status2 = 0;
|
|
7850
|
+
let offset = 0;
|
|
7851
|
+
Atomics.store(header, SAB_I_REQ, id);
|
|
7852
|
+
try {
|
|
7853
|
+
for (; ; ) {
|
|
7854
|
+
Atomics.store(header, SAB_I_STATE, SAB_STATE_PENDING);
|
|
7855
|
+
port2.postMessage(
|
|
7856
|
+
offset === 0 ? { type: SYNC_SAB_REQ_MSG, id, req } : { type: SYNC_SAB_NEXT_MSG, id, offset }
|
|
7857
|
+
);
|
|
7858
|
+
await ready(id);
|
|
7859
|
+
const total = loadU53(header, SAB_I_TOTAL, SAB_I_TOTAL_HI);
|
|
7860
|
+
const chunk = Atomics.load(header, SAB_I_CHUNK);
|
|
7861
|
+
const at = loadU53(header, SAB_I_OFFSET, SAB_I_OFFSET_HI);
|
|
7862
|
+
if (at !== offset || chunk < 0 || total < 0 || offset + chunk > total) {
|
|
7863
|
+
return { ok: false, errno: "EIO", message: "sync-sab: torn reply" };
|
|
7864
|
+
}
|
|
7865
|
+
if (out === null) {
|
|
7866
|
+
status2 = Atomics.load(header, SAB_I_STATUS);
|
|
7867
|
+
out = new Uint8Array(total);
|
|
7868
|
+
}
|
|
7869
|
+
out.set(window.subarray(0, chunk), offset);
|
|
7870
|
+
offset += chunk;
|
|
7871
|
+
if (offset >= total) break;
|
|
7872
|
+
if (chunk === 0) return { ok: false, errno: "EIO", message: "sync-sab: empty chunk" };
|
|
7873
|
+
}
|
|
7874
|
+
} finally {
|
|
7875
|
+
Atomics.store(header, SAB_I_REQ, 0);
|
|
7876
|
+
Atomics.store(header, SAB_I_STATE, SAB_STATE_IDLE);
|
|
7877
|
+
}
|
|
7878
|
+
return decodeSabResult(status2, out);
|
|
7879
|
+
}
|
|
7880
|
+
return {
|
|
7881
|
+
call(req) {
|
|
7882
|
+
const run = tail.then(() => once(req));
|
|
7883
|
+
tail = run.catch(() => void 0);
|
|
7884
|
+
return run;
|
|
7885
|
+
}
|
|
7886
|
+
};
|
|
7887
|
+
}
|
|
7888
|
+
var defaultWaitAsync;
|
|
7889
|
+
var init_async_sab = __esm({
|
|
7890
|
+
"src/process/js/async-sab.ts"() {
|
|
7891
|
+
"use strict";
|
|
7892
|
+
init_sync_sab_wire();
|
|
7893
|
+
defaultWaitAsync = (a, i, v) => Atomics.waitAsync(a, i, v);
|
|
7894
|
+
}
|
|
7895
|
+
});
|
|
7896
|
+
|
|
7897
|
+
// src/process/js/js-kernel.ts
|
|
7898
|
+
var JsCallError, JsKernel;
|
|
7899
|
+
var init_js_kernel = __esm({
|
|
7900
|
+
"src/process/js/js-kernel.ts"() {
|
|
7901
|
+
"use strict";
|
|
7902
|
+
init_signals();
|
|
7903
|
+
init_sync_sab_wire();
|
|
7904
|
+
init_async_sab();
|
|
7905
|
+
JsCallError = class extends Error {
|
|
7906
|
+
code;
|
|
7907
|
+
constructor(code2, what) {
|
|
7908
|
+
super(`${what}: ${code2}`);
|
|
7909
|
+
this.name = "JsCallError";
|
|
7910
|
+
this.code = code2;
|
|
7911
|
+
}
|
|
7912
|
+
};
|
|
7913
|
+
JsKernel = class {
|
|
7914
|
+
header;
|
|
7915
|
+
transport;
|
|
7916
|
+
waitAsync;
|
|
7917
|
+
onError;
|
|
7918
|
+
handlers = /* @__PURE__ */ new Map();
|
|
7919
|
+
ignored = 0;
|
|
7920
|
+
changing = Promise.resolve();
|
|
7921
|
+
pid = 0;
|
|
7922
|
+
reported = { caught: 0, ignored: 0 };
|
|
7923
|
+
watching = false;
|
|
7924
|
+
constructor(o) {
|
|
7925
|
+
this.header = new Int32Array(o.sab, 0, SAB_HEADER_I32);
|
|
7926
|
+
this.transport = o.transport;
|
|
7927
|
+
this.waitAsync = o.waitAsync;
|
|
7928
|
+
this.onError = o.onError;
|
|
7929
|
+
}
|
|
7930
|
+
async raw(req) {
|
|
7931
|
+
const result = await this.transport.call(req);
|
|
7932
|
+
this.deliver();
|
|
7933
|
+
return result;
|
|
7934
|
+
}
|
|
7935
|
+
async call(req) {
|
|
7936
|
+
const result = await this.raw(req);
|
|
7937
|
+
if (!result.ok) throw new JsCallError(result.errno, req.op);
|
|
7938
|
+
return result;
|
|
7939
|
+
}
|
|
7940
|
+
async json(req) {
|
|
7941
|
+
const result = await this.call(req);
|
|
7942
|
+
return result.ok && result.kind === "json" ? result.json : void 0;
|
|
7943
|
+
}
|
|
7944
|
+
async bytes(req) {
|
|
7945
|
+
const result = await this.call(req);
|
|
7946
|
+
return result.ok && result.kind === "bytes" ? result.bytes : new Uint8Array(0);
|
|
7947
|
+
}
|
|
7948
|
+
async blocking(req) {
|
|
7949
|
+
for (; ; ) {
|
|
7950
|
+
const id = await this.json({ op: "async-submit", req });
|
|
7951
|
+
const result = await this.settled(id);
|
|
7952
|
+
if (result.ok) return result;
|
|
7953
|
+
if (result.errno !== "EINTR") throw new JsCallError(result.errno, req.op);
|
|
7954
|
+
}
|
|
7955
|
+
}
|
|
7956
|
+
async settled(id) {
|
|
7957
|
+
for (; ; ) {
|
|
7958
|
+
const seen = Atomics.load(this.header, SAB_I_ASYNC);
|
|
7959
|
+
const taken = await this.raw({ op: "async-take", id });
|
|
7960
|
+
if (taken.ok || taken.errno !== "EAGAIN") return taken;
|
|
7961
|
+
await changed(this.header, SAB_I_ASYNC, seen, this.waitAsync);
|
|
7962
|
+
}
|
|
7963
|
+
}
|
|
7964
|
+
deliver() {
|
|
7965
|
+
const pending = Atomics.exchange(this.header, SAB_I_SIGNALS, 0);
|
|
7966
|
+
for (const sig of signalsIn(pending)) {
|
|
7967
|
+
const handler = this.handlers.get(sig);
|
|
7968
|
+
if (!handler) {
|
|
7969
|
+
if (!(this.ignored & sigbit(sig))) this.raise(sig);
|
|
7970
|
+
continue;
|
|
7971
|
+
}
|
|
7972
|
+
try {
|
|
7973
|
+
Promise.resolve(handler(sig)).catch(this.onError);
|
|
7974
|
+
} catch (err) {
|
|
7975
|
+
this.onError(err);
|
|
7976
|
+
}
|
|
7977
|
+
}
|
|
7978
|
+
}
|
|
7979
|
+
async watch() {
|
|
7980
|
+
if (this.watching) return;
|
|
7981
|
+
this.watching = true;
|
|
7982
|
+
for (; ; ) {
|
|
7983
|
+
await changed(this.header, SAB_I_SIGNALS, 0, this.waitAsync);
|
|
7984
|
+
this.deliver();
|
|
7985
|
+
}
|
|
7986
|
+
}
|
|
7987
|
+
async watchStops() {
|
|
7988
|
+
for (; ; ) {
|
|
7989
|
+
await changed(this.header, SAB_I_STOP, 0, this.waitAsync);
|
|
7990
|
+
this.freeze();
|
|
7991
|
+
}
|
|
7992
|
+
}
|
|
7993
|
+
freeze() {
|
|
7994
|
+
while (Atomics.load(this.header, SAB_I_STOP) === 1) Atomics.wait(this.header, SAB_I_STOP, 1);
|
|
7995
|
+
}
|
|
7996
|
+
setHandler(sig, handler) {
|
|
7997
|
+
if (sig === SIG.KILL || sig === SIG.STOP) {
|
|
7998
|
+
return Promise.reject(new JsCallError("EINVAL", "signal"));
|
|
7999
|
+
}
|
|
8000
|
+
const run = this.changing.then(() => this.change(sig, handler));
|
|
8001
|
+
this.changing = run.catch(() => void 0);
|
|
8002
|
+
return run;
|
|
8003
|
+
}
|
|
8004
|
+
async change(sig, handler) {
|
|
8005
|
+
const handlers = new Map(this.handlers);
|
|
8006
|
+
handlers.delete(sig);
|
|
8007
|
+
let ignored = this.ignored & ~sigbit(sig);
|
|
8008
|
+
if (handler === "ignore") ignored |= sigbit(sig);
|
|
8009
|
+
else if (handler !== "default") handlers.set(sig, handler);
|
|
8010
|
+
await this.report(handlers, ignored, handler === "default" ? sigbit(sig) : 0);
|
|
8011
|
+
this.handlers = handlers;
|
|
8012
|
+
this.ignored = ignored;
|
|
8013
|
+
if (handlers.size > 0) void this.watch();
|
|
8014
|
+
}
|
|
8015
|
+
raise(sig) {
|
|
8016
|
+
this.call({ op: "proc-kill", pid: this.pid, sig }).catch(this.onError);
|
|
8017
|
+
}
|
|
8018
|
+
async report(handlers, ignored, defaults) {
|
|
8019
|
+
let caught = 0;
|
|
8020
|
+
for (const sig of handlers.keys()) caught |= sigbit(sig);
|
|
8021
|
+
const same = caught === this.reported.caught && ignored === this.reported.ignored;
|
|
8022
|
+
if (same && defaults === 0) return;
|
|
8023
|
+
this.reported = { caught, ignored };
|
|
8024
|
+
await this.call({ op: "sig-mask", caught, ignored, ...defaults ? { defaults } : {} });
|
|
8025
|
+
}
|
|
8026
|
+
};
|
|
8027
|
+
}
|
|
8028
|
+
});
|
|
8029
|
+
|
|
8030
|
+
// src/process/js/js-context.ts
|
|
8031
|
+
function identityOf(answer2, fallback) {
|
|
8032
|
+
const id = answer2;
|
|
8033
|
+
return {
|
|
8034
|
+
pid: typeof id?.pid === "number" ? id.pid : fallback.pid,
|
|
8035
|
+
ppid: typeof id?.ppid === "number" ? id.ppid : fallback.ppid ?? 1
|
|
8036
|
+
};
|
|
8037
|
+
}
|
|
8038
|
+
function signalNumber(signal) {
|
|
8039
|
+
if (typeof signal === "number") {
|
|
8040
|
+
if (Number.isInteger(signal) && signal >= 1 && signal <= 31) return signal;
|
|
8041
|
+
throw new JsCallError("EINVAL", `signal ${signal}`);
|
|
8042
|
+
}
|
|
8043
|
+
const n = SIG[signal.slice(3)];
|
|
8044
|
+
if (n === void 0) throw new JsCallError("EINVAL", `signal ${signal}`);
|
|
8045
|
+
return n;
|
|
8046
|
+
}
|
|
8047
|
+
function resolvePath(cwd, path) {
|
|
8048
|
+
const parts = [];
|
|
8049
|
+
for (const part of (path.startsWith("/") ? path : `${cwd}/${path}`).split("/")) {
|
|
8050
|
+
if (part === "" || part === ".") continue;
|
|
8051
|
+
if (part === "..") parts.pop();
|
|
8052
|
+
else parts.push(part);
|
|
8053
|
+
}
|
|
8054
|
+
return `/${parts.join("/")}`;
|
|
8055
|
+
}
|
|
8056
|
+
function typeOf(info) {
|
|
8057
|
+
if (info.meta && "dir" in info.meta) return "directory";
|
|
8058
|
+
if (info.meta && "device" in info.meta) return "device";
|
|
8059
|
+
if (info.tty || info.kind === "tty") return "tty";
|
|
8060
|
+
if (info.kind === "socket") return "socket";
|
|
8061
|
+
return info.kind === "file" ? "file" : "pipe";
|
|
8062
|
+
}
|
|
8063
|
+
function flagsOf(o) {
|
|
8064
|
+
const write = o.write || o.append || o.truncate;
|
|
8065
|
+
const access = write ? o.read ? O_RDWR6 : O_WRONLY6 : 0;
|
|
8066
|
+
return access | (o.append ? O_APPEND3 : 0);
|
|
8067
|
+
}
|
|
8068
|
+
function createContext(o) {
|
|
8069
|
+
const { kernel } = o;
|
|
8070
|
+
const infos = /* @__PURE__ */ new Map();
|
|
8071
|
+
const handles = /* @__PURE__ */ new Map();
|
|
8072
|
+
const pending = /* @__PURE__ */ new Set();
|
|
8073
|
+
const random = o.random ?? ((bytes) => void crypto.getRandomValues(bytes));
|
|
8074
|
+
const resolve = (path) => resolvePath(o.cwd, path);
|
|
8075
|
+
const exit = (code2 = 0) => {
|
|
8076
|
+
o.exit(code2);
|
|
8077
|
+
throw new JsExit(code2);
|
|
8078
|
+
};
|
|
8079
|
+
const info = async (fd) => {
|
|
8080
|
+
const known = infos.get(fd);
|
|
8081
|
+
if (known) return known;
|
|
8082
|
+
const got = await kernel.json({ op: "fd-info", fd });
|
|
8083
|
+
infos.set(fd, got);
|
|
8084
|
+
return got;
|
|
8085
|
+
};
|
|
8086
|
+
const device = (i) => i.meta && "device" in i.meta ? i.meta : void 0;
|
|
8087
|
+
const read = async (fd, max = CHUNK) => {
|
|
8088
|
+
index(max, "read");
|
|
8089
|
+
const i = await info(fd);
|
|
8090
|
+
if (typeOf(i) === "directory") throw new JsCallError("EISDIR", "read");
|
|
8091
|
+
const dev = device(i);
|
|
8092
|
+
if (dev) {
|
|
8093
|
+
if (dev.access === "write") throw new JsCallError("EBADF", "read");
|
|
8094
|
+
if (dev.device === "null") return new Uint8Array(0);
|
|
8095
|
+
const out = new Uint8Array(Math.min(max, CHUNK));
|
|
8096
|
+
if (dev.device === "urandom") random(out);
|
|
8097
|
+
return out;
|
|
8098
|
+
}
|
|
8099
|
+
const r = await kernel.blocking({ op: "fd-read", fd, max: Math.min(max, MAX_IO) });
|
|
8100
|
+
return r.ok && r.kind === "bytes" ? r.bytes : new Uint8Array(0);
|
|
8101
|
+
};
|
|
8102
|
+
const writeAll = async (fd, data) => {
|
|
8103
|
+
const i = await info(fd);
|
|
8104
|
+
if (typeOf(i) === "directory") throw new JsCallError("EISDIR", "write");
|
|
8105
|
+
const dev = device(i);
|
|
8106
|
+
if (dev) {
|
|
8107
|
+
if (dev.access === "read") throw new JsCallError("EBADF", "write");
|
|
8108
|
+
if (dev.device === "full") throw new JsCallError("ENOSPC", "write");
|
|
8109
|
+
return;
|
|
8110
|
+
}
|
|
8111
|
+
let at = 0;
|
|
8112
|
+
while (at < data.length) {
|
|
8113
|
+
const body = data.subarray(at, at + MAX_IO);
|
|
8114
|
+
try {
|
|
8115
|
+
const r = await kernel.blocking({ op: "fd-write", fd, body });
|
|
8116
|
+
at += r.ok && r.kind === "json" && typeof r.json === "number" ? r.json : body.length;
|
|
8117
|
+
} catch (err) {
|
|
8118
|
+
const broken = err instanceof JsCallError && err.code === "EPIPE";
|
|
8119
|
+
if (broken && typeOf(i) !== "socket") {
|
|
8120
|
+
await kernel.call({ op: "proc-kill", pid: o.pid, sig: SIG.PIPE });
|
|
8121
|
+
}
|
|
8122
|
+
throw err;
|
|
8123
|
+
}
|
|
8124
|
+
}
|
|
8125
|
+
};
|
|
8126
|
+
const write = (fd, data) => {
|
|
8127
|
+
const bytes = typeof data === "string" ? encoder2.encode(data) : data;
|
|
8128
|
+
let settle;
|
|
8129
|
+
const settled = new Promise((resolve2) => settle = resolve2);
|
|
8130
|
+
pending.add(settled);
|
|
8131
|
+
return (async () => {
|
|
8132
|
+
try {
|
|
8133
|
+
await writeAll(fd, bytes);
|
|
8134
|
+
} finally {
|
|
8135
|
+
pending.delete(settled);
|
|
8136
|
+
settle();
|
|
8137
|
+
}
|
|
8138
|
+
})();
|
|
8139
|
+
};
|
|
8140
|
+
const writable = (fd) => new WritableStream({ write: (chunk) => write(fd, chunk) });
|
|
8141
|
+
const statOf = async (op, path) => {
|
|
8142
|
+
const abs = resolve(path);
|
|
8143
|
+
await kernel.call({ op: "fd-path-flush", path: abs });
|
|
8144
|
+
const s = parseSyncFsStat(await kernel.json({ op, path: abs }));
|
|
8145
|
+
if (!s) throw new JsCallError("EIO", op);
|
|
8146
|
+
return s;
|
|
8147
|
+
};
|
|
8148
|
+
const open = async (path, options = {}) => {
|
|
8149
|
+
const abs = resolve(path);
|
|
8150
|
+
const exclusive = options.create === true && options.exclusive === true;
|
|
8151
|
+
const existing = await statOf(exclusive ? "lstat" : "stat", abs).catch((err) => {
|
|
8152
|
+
if (err instanceof JsCallError && err.code === "ENOENT") return void 0;
|
|
8153
|
+
throw err;
|
|
8154
|
+
});
|
|
8155
|
+
if (existing && exclusive) throw new JsCallError("EEXIST", abs);
|
|
8156
|
+
if (!existing && !options.create) throw new JsCallError("ENOENT", abs);
|
|
8157
|
+
if (existing?.isDirectory) throw new JsCallError("EISDIR", abs);
|
|
8158
|
+
const fd = await kernel.json({
|
|
8159
|
+
op: "fd-open-vfs",
|
|
8160
|
+
path: abs,
|
|
8161
|
+
flags: flagsOf(options),
|
|
8162
|
+
position: 0,
|
|
8163
|
+
...exclusive ? { exclusive: true } : options.create ? { create: true } : { existing: true },
|
|
8164
|
+
...options.truncate ? { truncate: true } : {}
|
|
8165
|
+
});
|
|
8166
|
+
try {
|
|
8167
|
+
await kernel.call({ op: "fd-vfs-stat", fd });
|
|
8168
|
+
} catch (err) {
|
|
8169
|
+
await kernel.raw({ op: "fd-close", fd });
|
|
8170
|
+
throw err;
|
|
8171
|
+
}
|
|
8172
|
+
infos.set(fd, { kind: "file" });
|
|
8173
|
+
const handle = fileHandle(kernel, fd, abs, options.append === true, () => {
|
|
8174
|
+
infos.delete(fd);
|
|
8175
|
+
handles.delete(fd);
|
|
8176
|
+
});
|
|
8177
|
+
handles.set(fd, handle.invalidate);
|
|
8178
|
+
return handle.file;
|
|
8179
|
+
};
|
|
8180
|
+
const fs = pathOps(kernel, resolve, statOf, open);
|
|
8181
|
+
const ctx = {
|
|
8182
|
+
argv: o.argv,
|
|
8183
|
+
env: o.env,
|
|
8184
|
+
pid: o.pid,
|
|
8185
|
+
async ppid() {
|
|
8186
|
+
return identityOf(await kernel.json({ op: "proc-identity" }), o).ppid;
|
|
8187
|
+
},
|
|
8188
|
+
cwd: o.cwd,
|
|
8189
|
+
stdin: new ReadableStream(
|
|
8190
|
+
{
|
|
8191
|
+
async pull(controller) {
|
|
8192
|
+
const chunk = await read(0);
|
|
8193
|
+
if (chunk.length === 0) controller.close();
|
|
8194
|
+
else controller.enqueue(chunk);
|
|
8195
|
+
}
|
|
8196
|
+
},
|
|
8197
|
+
{ highWaterMark: 0 }
|
|
8198
|
+
),
|
|
8199
|
+
stdout: writable(1),
|
|
8200
|
+
stderr: writable(2),
|
|
8201
|
+
read,
|
|
8202
|
+
write,
|
|
8203
|
+
async close(fd) {
|
|
8204
|
+
handles.get(fd)?.();
|
|
8205
|
+
handles.delete(fd);
|
|
8206
|
+
infos.delete(fd);
|
|
8207
|
+
await kernel.call({ op: "fd-close", fd });
|
|
8208
|
+
},
|
|
8209
|
+
async fdStatus(fd) {
|
|
8210
|
+
const type = typeOf(await info(fd));
|
|
8211
|
+
return { type, tty: type === "tty", seekable: type === "file" };
|
|
8212
|
+
},
|
|
8213
|
+
isatty: async (fd) => typeOf(await info(fd)) === "tty",
|
|
8214
|
+
open,
|
|
8215
|
+
resolve,
|
|
8216
|
+
fs,
|
|
8217
|
+
signals: {
|
|
8218
|
+
on: async (signal, handler) => kernel.setHandler(signalNumber(signal), handler),
|
|
8219
|
+
ignore: async (signal) => kernel.setHandler(signalNumber(signal), "ignore"),
|
|
8220
|
+
reset: async (signal) => kernel.setHandler(signalNumber(signal), "default")
|
|
8221
|
+
},
|
|
8222
|
+
exit
|
|
8223
|
+
};
|
|
8224
|
+
const drain2 = async () => {
|
|
8225
|
+
for (; ; ) {
|
|
8226
|
+
await Promise.all([...pending]);
|
|
8227
|
+
await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
8228
|
+
if (pending.size === 0) return;
|
|
8229
|
+
}
|
|
8230
|
+
};
|
|
8231
|
+
return { ctx, drain: drain2 };
|
|
8232
|
+
}
|
|
8233
|
+
function fileHandle(kernel, fd, path, append, forget) {
|
|
8234
|
+
let open = true;
|
|
8235
|
+
const live = () => {
|
|
8236
|
+
if (!open) throw new JsCallError("EBADF", path);
|
|
8237
|
+
};
|
|
8238
|
+
const file = {
|
|
8239
|
+
fd,
|
|
8240
|
+
path,
|
|
8241
|
+
async size() {
|
|
8242
|
+
live();
|
|
8243
|
+
const s = await kernel.json({ op: "fd-vfs-stat", fd });
|
|
8244
|
+
return s.size;
|
|
8245
|
+
},
|
|
8246
|
+
async read(position, length) {
|
|
8247
|
+
index(position, "read");
|
|
8248
|
+
index(length, "read");
|
|
8249
|
+
const parts = [];
|
|
8250
|
+
let got = 0;
|
|
8251
|
+
do {
|
|
8252
|
+
live();
|
|
8253
|
+
const max = Math.min(length - got, MAX_IO);
|
|
8254
|
+
if (max <= 0) break;
|
|
8255
|
+
const chunk = await kernel.bytes({ op: "fd-pread", fd, offset: position + got, max });
|
|
8256
|
+
if (chunk.length === 0) break;
|
|
8257
|
+
parts.push(chunk);
|
|
8258
|
+
got += chunk.length;
|
|
8259
|
+
} while (got < length);
|
|
8260
|
+
if (parts.length === 1) return parts[0];
|
|
8261
|
+
const out = new Uint8Array(got);
|
|
8262
|
+
let at = 0;
|
|
8263
|
+
for (const part of parts) {
|
|
8264
|
+
out.set(part, at);
|
|
8265
|
+
at += part.length;
|
|
8266
|
+
}
|
|
8267
|
+
return out;
|
|
8268
|
+
},
|
|
8269
|
+
async write(position, data) {
|
|
8270
|
+
index(position, "write");
|
|
8271
|
+
let at = 0;
|
|
8272
|
+
do {
|
|
8273
|
+
live();
|
|
8274
|
+
if (at >= data.length) break;
|
|
8275
|
+
const body = data.subarray(at, at + MAX_IO);
|
|
8276
|
+
const n = await kernel.json(
|
|
8277
|
+
append ? { op: "fd-write", fd, body } : { op: "fd-pwrite", fd, offset: position + at, body }
|
|
8278
|
+
);
|
|
8279
|
+
if (!(n > 0)) throw new JsCallError("EIO", "write");
|
|
8280
|
+
at += n;
|
|
8281
|
+
} while (at < data.length);
|
|
8282
|
+
return at;
|
|
8283
|
+
},
|
|
8284
|
+
async truncate(size) {
|
|
8285
|
+
live();
|
|
8286
|
+
index(size, "truncate");
|
|
8287
|
+
await kernel.call({ op: "fd-resize", fd, size });
|
|
8288
|
+
},
|
|
8289
|
+
async sync() {
|
|
8290
|
+
live();
|
|
8291
|
+
await kernel.call({ op: "fd-flush", fd });
|
|
8292
|
+
},
|
|
8293
|
+
async close() {
|
|
8294
|
+
live();
|
|
8295
|
+
open = false;
|
|
8296
|
+
forget();
|
|
8297
|
+
await kernel.call({ op: "fd-close", fd });
|
|
8298
|
+
}
|
|
8299
|
+
};
|
|
8300
|
+
return {
|
|
8301
|
+
file,
|
|
8302
|
+
invalidate: () => {
|
|
8303
|
+
open = false;
|
|
8304
|
+
}
|
|
8305
|
+
};
|
|
8306
|
+
}
|
|
8307
|
+
function index(n, what) {
|
|
8308
|
+
if (!Number.isSafeInteger(n) || n < 0) throw new JsCallError("EINVAL", what);
|
|
8309
|
+
}
|
|
8310
|
+
function pathOps(kernel, resolve, statOf, open) {
|
|
8311
|
+
return {
|
|
8312
|
+
stat: (path) => statOf("stat", path),
|
|
8313
|
+
lstat: (path) => statOf("lstat", path),
|
|
8314
|
+
exists: async (path) => await kernel.json({ op: "exists", path: resolve(path) }) === true,
|
|
8315
|
+
readdir: async (path) => await kernel.json({ op: "readdir", path: resolve(path) }),
|
|
8316
|
+
mkdir: async (path) => void await kernel.call({ op: "mkdir", path: resolve(path) }),
|
|
8317
|
+
rm: async (path) => void await kernel.call({ op: "rm", path: resolve(path) }),
|
|
8318
|
+
unlink: async (path) => void await kernel.call({ op: "unlink", path: resolve(path) }),
|
|
8319
|
+
rename: async (from, to) => void await kernel.call({ op: "rename", path: resolve(from), arg2: resolve(to) }),
|
|
8320
|
+
symlink: async (target, path) => void await kernel.call({ op: "symlink", path: resolve(path), arg2: target }),
|
|
8321
|
+
readlink: async (path) => String(await kernel.json({ op: "readlink", path: resolve(path) })),
|
|
8322
|
+
async readFile(path) {
|
|
8323
|
+
const abs = resolve(path);
|
|
8324
|
+
await kernel.call({ op: "fd-path-flush", path: abs });
|
|
8325
|
+
return kernel.bytes({ op: "read", path: abs });
|
|
8326
|
+
},
|
|
8327
|
+
async writeFile(path, data) {
|
|
8328
|
+
const file = await open(path, { write: true, create: true, truncate: true });
|
|
8329
|
+
try {
|
|
8330
|
+
await file.write(0, typeof data === "string" ? encoder2.encode(data) : data);
|
|
8331
|
+
} finally {
|
|
8332
|
+
await file.close();
|
|
8333
|
+
}
|
|
8334
|
+
}
|
|
8335
|
+
};
|
|
8336
|
+
}
|
|
8337
|
+
var JsExit, CHUNK, MAX_IO, O_WRONLY6, O_RDWR6, O_APPEND3, encoder2;
|
|
8338
|
+
var init_js_context = __esm({
|
|
8339
|
+
"src/process/js/js-context.ts"() {
|
|
8340
|
+
"use strict";
|
|
8341
|
+
init_signals();
|
|
8342
|
+
init_sync_fs_wire();
|
|
8343
|
+
init_js_kernel();
|
|
8344
|
+
JsExit = class extends Error {
|
|
8345
|
+
status;
|
|
8346
|
+
constructor(status2) {
|
|
8347
|
+
super(`exit ${status2}`);
|
|
8348
|
+
this.name = "JsExit";
|
|
8349
|
+
this.status = status2;
|
|
8350
|
+
}
|
|
8351
|
+
};
|
|
8352
|
+
CHUNK = 64 * 1024;
|
|
8353
|
+
MAX_IO = 1024 * 1024;
|
|
8354
|
+
O_WRONLY6 = 1;
|
|
8355
|
+
O_RDWR6 = 2;
|
|
8356
|
+
O_APPEND3 = 1024;
|
|
8357
|
+
encoder2 = new TextEncoder();
|
|
8358
|
+
}
|
|
8359
|
+
});
|
|
8360
|
+
|
|
8361
|
+
// src/process/js/lockdown.ts
|
|
8362
|
+
function chain(target) {
|
|
8363
|
+
const out = [];
|
|
8364
|
+
for (let at = target; at && at !== Object.prototype; ) {
|
|
8365
|
+
out.push(at);
|
|
8366
|
+
at = Object.getPrototypeOf(at);
|
|
8367
|
+
}
|
|
8368
|
+
return out;
|
|
8369
|
+
}
|
|
8370
|
+
function hide(target, names) {
|
|
8371
|
+
for (const name of names) {
|
|
8372
|
+
const holders = chain(target);
|
|
8373
|
+
for (const holder of holders) {
|
|
8374
|
+
if (Object.getOwnPropertyDescriptor(holder, name)?.configurable) {
|
|
8375
|
+
Reflect.deleteProperty(holder, name);
|
|
8376
|
+
}
|
|
8377
|
+
}
|
|
8378
|
+
const kept = holders.slice(1).some((holder) => Object.hasOwn(holder, name));
|
|
8379
|
+
const defined = Reflect.defineProperty(target, name, {
|
|
8380
|
+
value: void 0,
|
|
8381
|
+
writable: false,
|
|
8382
|
+
enumerable: false,
|
|
8383
|
+
configurable: false
|
|
8384
|
+
});
|
|
8385
|
+
if (kept || !defined && Reflect.get(target, name) !== void 0) {
|
|
8386
|
+
throw new Error(`slicc-kernel: cannot withhold ${name} from a JS program`);
|
|
8387
|
+
}
|
|
8388
|
+
}
|
|
8389
|
+
}
|
|
8390
|
+
function lockdown(scope2 = globalThis) {
|
|
8391
|
+
hide(scope2, BLOCKED_GLOBALS);
|
|
8392
|
+
const navigator = scope2.navigator;
|
|
8393
|
+
if (navigator && typeof navigator === "object") hide(navigator, BLOCKED_NAVIGATOR);
|
|
8394
|
+
}
|
|
8395
|
+
var BLOCKED_GLOBALS, BLOCKED_NAVIGATOR;
|
|
8396
|
+
var init_lockdown = __esm({
|
|
8397
|
+
"src/process/js/lockdown.ts"() {
|
|
8398
|
+
"use strict";
|
|
8399
|
+
BLOCKED_GLOBALS = [
|
|
8400
|
+
"fetch",
|
|
8401
|
+
"XMLHttpRequest",
|
|
8402
|
+
"WebSocket",
|
|
8403
|
+
"WebSocketStream",
|
|
8404
|
+
"WebTransport",
|
|
8405
|
+
"EventSource",
|
|
8406
|
+
"importScripts",
|
|
8407
|
+
"indexedDB",
|
|
8408
|
+
"caches",
|
|
8409
|
+
"cookieStore",
|
|
8410
|
+
"Worker",
|
|
8411
|
+
"SharedWorker",
|
|
8412
|
+
"BroadcastChannel",
|
|
8413
|
+
"postMessage",
|
|
8414
|
+
"close"
|
|
8415
|
+
];
|
|
8416
|
+
BLOCKED_NAVIGATOR = ["storage", "locks", "serviceWorker"];
|
|
8417
|
+
}
|
|
8418
|
+
});
|
|
8419
|
+
|
|
8420
|
+
// src/process/js/js-runtime.ts
|
|
8421
|
+
var js_runtime_exports = {};
|
|
8422
|
+
__export(js_runtime_exports, {
|
|
8423
|
+
mainOf: () => mainOf,
|
|
8424
|
+
runJsProcess: () => runJsProcess,
|
|
8425
|
+
trapStrays: () => trapStrays
|
|
8426
|
+
});
|
|
8427
|
+
function trapStrays(scope2, fail) {
|
|
8428
|
+
if (typeof scope2.process?.on === "function") {
|
|
8429
|
+
scope2.process.on("unhandledRejection", fail);
|
|
8430
|
+
scope2.process.on("uncaughtException", fail);
|
|
8431
|
+
return;
|
|
8432
|
+
}
|
|
8433
|
+
scope2.addEventListener?.("unhandledrejection", (event) => {
|
|
8434
|
+
event.preventDefault();
|
|
8435
|
+
fail(event.reason);
|
|
8436
|
+
});
|
|
8437
|
+
scope2.addEventListener?.("error", (event) => {
|
|
8438
|
+
event.preventDefault();
|
|
8439
|
+
fail(event.error);
|
|
8440
|
+
});
|
|
8441
|
+
}
|
|
8442
|
+
async function settledStrays() {
|
|
8443
|
+
for (let turn = 0; turn < 2; turn++) await new Promise((resolve) => setTimeout(resolve, 0));
|
|
8444
|
+
}
|
|
8445
|
+
function message(err) {
|
|
8446
|
+
return err instanceof Error ? err.message : String(err);
|
|
8447
|
+
}
|
|
8448
|
+
function statusOf(value2) {
|
|
8449
|
+
return typeof value2 === "number" && Number.isInteger(value2) ? value2 & 255 : 0;
|
|
8450
|
+
}
|
|
8451
|
+
function mainOf(module) {
|
|
8452
|
+
const main = typeof module.default === "function" ? module.default : module.main;
|
|
8453
|
+
return typeof main === "function" ? main : void 0;
|
|
8454
|
+
}
|
|
8455
|
+
async function runJsProcess(init, port2, deps = {}) {
|
|
8456
|
+
const transport = createAsyncSabTransport(init.sab, port2, deps.waitAsync);
|
|
8457
|
+
let resolveExit;
|
|
8458
|
+
const exit = new Promise((resolve) => resolveExit = resolve);
|
|
8459
|
+
let exitedWith;
|
|
8460
|
+
const exited = (status3) => {
|
|
8461
|
+
exitedWith ??= status3;
|
|
8462
|
+
resolveExit(status3);
|
|
8463
|
+
};
|
|
8464
|
+
let failing;
|
|
8465
|
+
const fail = (err) => {
|
|
8466
|
+
if (err instanceof JsExit) return;
|
|
8467
|
+
failing ??= say(message(err)).then(() => exited(1));
|
|
8468
|
+
};
|
|
8469
|
+
const kernel = new JsKernel({
|
|
8470
|
+
sab: init.sab,
|
|
8471
|
+
transport,
|
|
8472
|
+
onError: fail,
|
|
8473
|
+
waitAsync: deps.waitAsync
|
|
8474
|
+
});
|
|
8475
|
+
void kernel.watchStops();
|
|
8476
|
+
const id = identityOf(await kernel.json({ op: "proc-identity" }), init);
|
|
8477
|
+
kernel.pid = id.pid;
|
|
8478
|
+
const { ctx, drain: drain2 } = createContext({
|
|
8479
|
+
kernel,
|
|
8480
|
+
argv: [init.argv0, ...init.args],
|
|
8481
|
+
env: init.env,
|
|
8482
|
+
pid: id.pid,
|
|
8483
|
+
ppid: id.ppid,
|
|
8484
|
+
cwd: init.cwd,
|
|
8485
|
+
exit: (status3) => exited(statusOf(status3))
|
|
8486
|
+
});
|
|
8487
|
+
const say = (text) => ctx.write(2, `${init.argv0}: ${text}
|
|
8488
|
+
`).catch(() => void 0);
|
|
8489
|
+
let main;
|
|
8490
|
+
trapStrays(deps.scope ?? globalThis, fail);
|
|
8491
|
+
try {
|
|
8492
|
+
(deps.lockdown ?? lockdown)();
|
|
8493
|
+
main = mainOf(await (deps.load ?? importSource)(init.program.glue));
|
|
8494
|
+
} catch (err) {
|
|
8495
|
+
await say(message(err));
|
|
8496
|
+
return NOT_RUNNABLE;
|
|
8497
|
+
}
|
|
8498
|
+
if (!main) {
|
|
8499
|
+
await say(`${init.program.path} exports no main function`);
|
|
8500
|
+
return NOT_RUNNABLE;
|
|
8501
|
+
}
|
|
8502
|
+
const program = main;
|
|
8503
|
+
const ran = Promise.resolve().then(() => program(ctx)).then(statusOf, async (err) => {
|
|
8504
|
+
if (err instanceof JsExit) return err.status;
|
|
8505
|
+
await say(message(err));
|
|
8506
|
+
return 1;
|
|
8507
|
+
});
|
|
8508
|
+
const status2 = await Promise.race([ran, exit]);
|
|
8509
|
+
await drain2();
|
|
8510
|
+
await settledStrays();
|
|
8511
|
+
await failing;
|
|
8512
|
+
if (exitedWith !== void 0) return exitedWith;
|
|
8513
|
+
return status2;
|
|
8514
|
+
}
|
|
8515
|
+
var NOT_RUNNABLE;
|
|
8516
|
+
var init_js_runtime = __esm({
|
|
8517
|
+
"src/process/js/js-runtime.ts"() {
|
|
8518
|
+
"use strict";
|
|
8519
|
+
init_wasi_imports();
|
|
8520
|
+
init_async_sab();
|
|
8521
|
+
init_js_context();
|
|
8522
|
+
init_js_kernel();
|
|
8523
|
+
init_lockdown();
|
|
8524
|
+
NOT_RUNNABLE = 126;
|
|
8525
|
+
}
|
|
8526
|
+
});
|
|
8527
|
+
|
|
7770
8528
|
// src/node-process-worker.ts
|
|
7771
8529
|
import { createRequire } from "node:module";
|
|
7772
8530
|
import { parentPort } from "node:worker_threads";
|
|
@@ -7775,7 +8533,17 @@ import { parentPort } from "node:worker_threads";
|
|
|
7775
8533
|
init_protocol();
|
|
7776
8534
|
init_process_runtime();
|
|
7777
8535
|
var loadWasi = () => Promise.resolve().then(() => (init_wasi_runtime(), wasi_runtime_exports));
|
|
7778
|
-
|
|
8536
|
+
var loadJs = () => Promise.resolve().then(() => (init_js_runtime(), js_runtime_exports));
|
|
8537
|
+
function started(init, port2, run, wasi, js) {
|
|
8538
|
+
if (init.program?.abi === "js") {
|
|
8539
|
+
const jsInit = init;
|
|
8540
|
+
return js().then((m) => m.runJsProcess(jsInit, port2));
|
|
8541
|
+
}
|
|
8542
|
+
const wasmInit = init;
|
|
8543
|
+
if (wasmInit.program?.abi === "wasi") return wasi().then((m) => m.runWasiProcess(wasmInit, port2));
|
|
8544
|
+
return run(wasmInit, port2);
|
|
8545
|
+
}
|
|
8546
|
+
function processEntry(port2, run = runWasmProcess, wasi = loadWasi, js = loadJs) {
|
|
7779
8547
|
const failed2 = (err) => port2.postMessage({
|
|
7780
8548
|
type: WASM_PROCESS_ERROR,
|
|
7781
8549
|
message: err instanceof Error ? err.stack ?? err.message : String(err)
|
|
@@ -7787,9 +8555,7 @@ function processEntry(port2, run = runWasmProcess, wasi = loadWasi) {
|
|
|
7787
8555
|
return;
|
|
7788
8556
|
}
|
|
7789
8557
|
if (type !== WASM_PROCESS_INIT) return;
|
|
7790
|
-
|
|
7791
|
-
const started = init.program?.abi === "wasi" ? wasi().then((m) => m.runWasiProcess(init, port2)) : run(init, port2);
|
|
7792
|
-
started.then(
|
|
8558
|
+
started(data, port2, run, wasi, js).then(
|
|
7793
8559
|
(code2) => port2.postMessage({ type: WASM_PROCESS_EXIT, code: code2 }),
|
|
7794
8560
|
failed2
|
|
7795
8561
|
);
|
|
@@ -7802,6 +8568,6 @@ scope.require ??= createRequire(import.meta.url);
|
|
|
7802
8568
|
scope.__filename ??= new URL(import.meta.url).pathname;
|
|
7803
8569
|
scope.__dirname ??= new URL(".", import.meta.url).pathname;
|
|
7804
8570
|
var port = parentPort;
|
|
7805
|
-
var onMessage = processEntry({ postMessage: (
|
|
8571
|
+
var onMessage = processEntry({ postMessage: (message2) => port.postMessage(message2) });
|
|
7806
8572
|
port.on("message", onMessage);
|
|
7807
8573
|
//# sourceMappingURL=node-process-worker.js.map
|