@ai-ecoverse/slicc-kernel 1.37.1 → 1.39.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 +3 -1
- package/dist/driver-worker.js +123 -0
- package/dist/driver-worker.js.map +3 -3
- package/dist/index.js +309 -6
- package/dist/index.js.map +4 -4
- package/dist/kernel-worker.js +647 -214
- package/dist/kernel-worker.js.map +4 -4
- package/dist/node-driver-worker.js +123 -0
- package/dist/node-driver-worker.js.map +3 -3
- package/dist/node-process-worker.js +378 -101
- package/dist/node-process-worker.js.map +4 -4
- package/dist/node.js +578 -66
- package/dist/node.js.map +4 -4
- package/dist/process-worker.js +378 -101
- package/dist/process-worker.js.map +4 -4
- package/package.json +1 -1
|
@@ -259,11 +259,11 @@ var init_pages = __esm({
|
|
|
259
259
|
runs.push({ offset: start, bytes });
|
|
260
260
|
i = j;
|
|
261
261
|
}
|
|
262
|
-
const
|
|
262
|
+
const written2 = Math.max(this.stored, ...runs.map((r) => r.offset + r.bytes.length));
|
|
263
263
|
return {
|
|
264
264
|
...this.shrink !== void 0 ? { shrink: this.shrink } : {},
|
|
265
265
|
runs,
|
|
266
|
-
...this.length >
|
|
266
|
+
...this.length > written2 ? { extend: this.length } : {}
|
|
267
267
|
};
|
|
268
268
|
}
|
|
269
269
|
flushed() {
|
|
@@ -1799,8 +1799,8 @@ var init_kernel_streams = __esm({
|
|
|
1799
1799
|
this.useTerminalNodes();
|
|
1800
1800
|
const open = this.Fs.open.bind(this.Fs);
|
|
1801
1801
|
this.Fs.open = (path, flags, mode) => {
|
|
1802
|
-
const
|
|
1803
|
-
if (
|
|
1802
|
+
const device2 = typeof path === "string" ? this.devicePath(path) : void 0;
|
|
1803
|
+
if (device2 !== void 0 && TTY_PATH.test(device2) && !this.terminalExists(device2)) {
|
|
1804
1804
|
throw new this.Fs.ErrnoError(wasiErrno("ENOENT"));
|
|
1805
1805
|
}
|
|
1806
1806
|
const pty = this.openPty(open, path, flags, mode);
|
|
@@ -2718,15 +2718,15 @@ function describeInherited(Fs, sys, streams, livePath, actions = []) {
|
|
|
2718
2718
|
return out;
|
|
2719
2719
|
}
|
|
2720
2720
|
function deviceOfStream(stream) {
|
|
2721
|
-
const
|
|
2722
|
-
if (!
|
|
2721
|
+
const device2 = stream.path === void 0 ? void 0 : DEVICES[stream.path];
|
|
2722
|
+
if (!device2 || stream.sliccKernelFd !== void 0) return void 0;
|
|
2723
2723
|
const access = ACCESS[stream.flags & O_ACCMODE2];
|
|
2724
|
-
return { device, ...access ? { access } : {} };
|
|
2724
|
+
return { device: device2, ...access ? { access } : {} };
|
|
2725
2725
|
}
|
|
2726
2726
|
function inheritedSlot(fd, stream) {
|
|
2727
2727
|
if (stream.sliccKernelFd === void 0) {
|
|
2728
|
-
const
|
|
2729
|
-
return
|
|
2728
|
+
const device2 = deviceOfStream(stream);
|
|
2729
|
+
return device2 ? { fd, ...device2 } : void 0;
|
|
2730
2730
|
}
|
|
2731
2731
|
const flags = stream.sliccKernelSocket ? { flags: stream.flags } : {};
|
|
2732
2732
|
return { fd, kernel: stream.sliccKernelFd, ...flags };
|
|
@@ -2902,8 +2902,8 @@ function createProcessKernel(deps) {
|
|
|
2902
2902
|
if (!stream) return { none: true };
|
|
2903
2903
|
promote?.(stream);
|
|
2904
2904
|
if (stream.sliccKernelFd !== void 0) return { fd: stream.sliccKernelFd };
|
|
2905
|
-
const
|
|
2906
|
-
if (
|
|
2905
|
+
const device2 = deviceOfStream(stream);
|
|
2906
|
+
if (device2) return device2;
|
|
2907
2907
|
return n === 0 ? { input: drain(Fs, stream) } : { capture: true };
|
|
2908
2908
|
};
|
|
2909
2909
|
const kernelWait = (pid, nohang, options = 0) => {
|
|
@@ -3840,8 +3840,8 @@ function wireKernelStdio(Fs, streams, sys) {
|
|
|
3840
3840
|
const stream = Fs.getStream(fd);
|
|
3841
3841
|
if (!stream) continue;
|
|
3842
3842
|
const kind = sys?.kind?.(fd);
|
|
3843
|
-
const
|
|
3844
|
-
if (
|
|
3843
|
+
const device2 = kind === "device" ? sys?.device?.(fd) : void 0;
|
|
3844
|
+
if (device2 && openDevice(Fs, fd, device2)) continue;
|
|
3845
3845
|
if (kind && PLACED.has(kind)) {
|
|
3846
3846
|
const { flags } = stream;
|
|
3847
3847
|
Fs.closeStream(fd);
|
|
@@ -3910,8 +3910,8 @@ async function runWasmProcess(init, port2, deps = {}) {
|
|
|
3910
3910
|
}
|
|
3911
3911
|
};
|
|
3912
3912
|
const sys = kernelSys(transport);
|
|
3913
|
-
const
|
|
3914
|
-
const say = (fd) => (text) => sys.write(fd,
|
|
3913
|
+
const encoder4 = new TextEncoder();
|
|
3914
|
+
const say = (fd) => (text) => sys.write(fd, encoder4.encode(`${text}
|
|
3915
3915
|
`));
|
|
3916
3916
|
let ready;
|
|
3917
3917
|
let failed2;
|
|
@@ -4616,14 +4616,14 @@ var init_wasi_fds = __esm({
|
|
|
4616
4616
|
for (const fd of [0, 1, 2]) this.table.set(fd, kernelEntry2());
|
|
4617
4617
|
const preopens = this.preopens(cwd, root);
|
|
4618
4618
|
const top = 3 + preopens.length;
|
|
4619
|
-
for (const { fd, kind, flags, device } of inherited) {
|
|
4619
|
+
for (const { fd, kind, flags, device: device2 } of inherited) {
|
|
4620
4620
|
let at = fd;
|
|
4621
4621
|
if (fd < top) {
|
|
4622
4622
|
at = this.kernel.call({ op: "fd-dup", fd, min: top });
|
|
4623
4623
|
this.kernel.sys.close(fd);
|
|
4624
4624
|
}
|
|
4625
|
-
if (
|
|
4626
|
-
this.table.set(at, deviceEntry(
|
|
4625
|
+
if (device2) {
|
|
4626
|
+
this.table.set(at, deviceEntry(device2));
|
|
4627
4627
|
continue;
|
|
4628
4628
|
}
|
|
4629
4629
|
const nonblock = ((flags ?? 0) & O_NONBLOCK2) !== 0;
|
|
@@ -4971,8 +4971,8 @@ var init_wasi_fds = __esm({
|
|
|
4971
4971
|
return resolveUnder(this.dir(dirfd).path, path);
|
|
4972
4972
|
}
|
|
4973
4973
|
open(path, oflags, rights, fdflags) {
|
|
4974
|
-
const
|
|
4975
|
-
if (
|
|
4974
|
+
const device2 = deviceOf(path);
|
|
4975
|
+
if (device2) return this.install({ type: "device", device: device2 });
|
|
4976
4976
|
if (path === "/dev/tty" || /^\/dev\/tty\d+$/.test(path)) {
|
|
4977
4977
|
const fd = this.kernel.sys.openTty?.(path === "/dev/tty" ? void 0 : path);
|
|
4978
4978
|
if (fd === void 0) throw new WasiError("ENXIO");
|
|
@@ -5112,11 +5112,11 @@ var init_wasi_memory = __esm({
|
|
|
5112
5112
|
return at;
|
|
5113
5113
|
}
|
|
5114
5114
|
putStrings(list, ptrs, buf) {
|
|
5115
|
-
const
|
|
5115
|
+
const encoder4 = new TextEncoder();
|
|
5116
5116
|
const v = this.view();
|
|
5117
5117
|
let at = buf;
|
|
5118
5118
|
list.forEach((s, i) => {
|
|
5119
|
-
const b =
|
|
5119
|
+
const b = encoder4.encode(s);
|
|
5120
5120
|
v.setUint32(ptrs + i * 4, at, true);
|
|
5121
5121
|
this.bytes(at, b.length).set(b);
|
|
5122
5122
|
v.setUint8(at + b.length, 0);
|
|
@@ -5124,12 +5124,12 @@ var init_wasi_memory = __esm({
|
|
|
5124
5124
|
});
|
|
5125
5125
|
}
|
|
5126
5126
|
putSizes(list, countPtr, sizePtr) {
|
|
5127
|
-
const
|
|
5127
|
+
const encoder4 = new TextEncoder();
|
|
5128
5128
|
const v = this.view();
|
|
5129
5129
|
v.setUint32(countPtr, list.length, true);
|
|
5130
5130
|
v.setUint32(
|
|
5131
5131
|
sizePtr,
|
|
5132
|
-
list.reduce((n, s) => n +
|
|
5132
|
+
list.reduce((n, s) => n + encoder4.encode(s).length + 1, 0),
|
|
5133
5133
|
true
|
|
5134
5134
|
);
|
|
5135
5135
|
}
|
|
@@ -8165,6 +8165,7 @@ var init_js_kernel = __esm({
|
|
|
8165
8165
|
pid = 0;
|
|
8166
8166
|
reported = { caught: 0, ignored: 0 };
|
|
8167
8167
|
watching = false;
|
|
8168
|
+
faulted = false;
|
|
8168
8169
|
constructor(o) {
|
|
8169
8170
|
this.header = new Int32Array(o.sab, 0, SAB_HEADER_I32);
|
|
8170
8171
|
this.transport = o.transport;
|
|
@@ -8214,12 +8215,16 @@ var init_js_kernel = __esm({
|
|
|
8214
8215
|
continue;
|
|
8215
8216
|
}
|
|
8216
8217
|
try {
|
|
8217
|
-
Promise.resolve(handler(sig)).catch(this.
|
|
8218
|
+
Promise.resolve(handler(sig)).catch((err) => this.fault(err));
|
|
8218
8219
|
} catch (err) {
|
|
8219
|
-
this.
|
|
8220
|
+
this.fault(err);
|
|
8220
8221
|
}
|
|
8221
8222
|
}
|
|
8222
8223
|
}
|
|
8224
|
+
fault(err) {
|
|
8225
|
+
this.faulted = true;
|
|
8226
|
+
this.onError(err);
|
|
8227
|
+
}
|
|
8223
8228
|
async watch() {
|
|
8224
8229
|
if (this.watching) return;
|
|
8225
8230
|
this.watching = true;
|
|
@@ -8271,6 +8276,320 @@ var init_js_kernel = __esm({
|
|
|
8271
8276
|
}
|
|
8272
8277
|
});
|
|
8273
8278
|
|
|
8279
|
+
// src/process/js/js-io.ts
|
|
8280
|
+
function typeOf(info) {
|
|
8281
|
+
if (info.meta && "dir" in info.meta) return "directory";
|
|
8282
|
+
if (info.meta && "device" in info.meta) return "device";
|
|
8283
|
+
if (info.tty || info.kind === "tty") return "tty";
|
|
8284
|
+
if (info.kind === "socket") return "socket";
|
|
8285
|
+
return info.kind === "file" ? "file" : "pipe";
|
|
8286
|
+
}
|
|
8287
|
+
function device(info) {
|
|
8288
|
+
return info.meta && "device" in info.meta ? info.meta : void 0;
|
|
8289
|
+
}
|
|
8290
|
+
function readDevice(info, max, random) {
|
|
8291
|
+
if (typeOf(info) === "directory") throw new JsCallError("EISDIR", "read");
|
|
8292
|
+
const dev = device(info);
|
|
8293
|
+
if (!dev) return void 0;
|
|
8294
|
+
if (dev.access === "write") throw new JsCallError("EBADF", "read");
|
|
8295
|
+
if (dev.device === "null") return new Uint8Array(0);
|
|
8296
|
+
const out = new Uint8Array(Math.min(max, CHUNK));
|
|
8297
|
+
if (dev.device === "urandom") random(out);
|
|
8298
|
+
return out;
|
|
8299
|
+
}
|
|
8300
|
+
function writeDevice(info) {
|
|
8301
|
+
if (typeOf(info) === "directory") throw new JsCallError("EISDIR", "write");
|
|
8302
|
+
const dev = device(info);
|
|
8303
|
+
if (!dev) return false;
|
|
8304
|
+
if (dev.access === "read") throw new JsCallError("EBADF", "write");
|
|
8305
|
+
if (dev.device === "full") throw new JsCallError("ENOSPC", "write");
|
|
8306
|
+
return true;
|
|
8307
|
+
}
|
|
8308
|
+
function brokenPipe(err, info) {
|
|
8309
|
+
return err instanceof JsCallError && err.code === "EPIPE" && typeOf(info) !== "socket";
|
|
8310
|
+
}
|
|
8311
|
+
function written(r, fallback) {
|
|
8312
|
+
return r.ok && r.kind === "json" && typeof r.json === "number" ? r.json : fallback;
|
|
8313
|
+
}
|
|
8314
|
+
function joined(parts, length) {
|
|
8315
|
+
if (parts.length === 1) return parts[0];
|
|
8316
|
+
const out = new Uint8Array(length);
|
|
8317
|
+
let at = 0;
|
|
8318
|
+
for (const part of parts) {
|
|
8319
|
+
out.set(part, at);
|
|
8320
|
+
at += part.length;
|
|
8321
|
+
}
|
|
8322
|
+
return out;
|
|
8323
|
+
}
|
|
8324
|
+
function fileWrite(fd, append, offset, body) {
|
|
8325
|
+
return append ? { op: "fd-write", fd, body } : { op: "fd-pwrite", fd, offset, body };
|
|
8326
|
+
}
|
|
8327
|
+
function isExclusive(o) {
|
|
8328
|
+
return o.create === true && o.exclusive === true;
|
|
8329
|
+
}
|
|
8330
|
+
function absent(err) {
|
|
8331
|
+
if (err instanceof JsCallError && err.code === "ENOENT") return void 0;
|
|
8332
|
+
throw err;
|
|
8333
|
+
}
|
|
8334
|
+
function checkOpen(abs, o, existing) {
|
|
8335
|
+
if (existing && isExclusive(o)) throw new JsCallError("EEXIST", abs);
|
|
8336
|
+
if (!existing && !o.create) throw new JsCallError("ENOENT", abs);
|
|
8337
|
+
if (existing?.isDirectory) throw new JsCallError("EISDIR", abs);
|
|
8338
|
+
}
|
|
8339
|
+
function flagsOf(o) {
|
|
8340
|
+
const write = o.write || o.append || o.truncate;
|
|
8341
|
+
const access = write ? o.read ? O_RDWR6 : O_WRONLY6 : 0;
|
|
8342
|
+
return access | (o.append ? O_APPEND3 : 0);
|
|
8343
|
+
}
|
|
8344
|
+
function openRequest(abs, o) {
|
|
8345
|
+
return {
|
|
8346
|
+
op: "fd-open-vfs",
|
|
8347
|
+
path: abs,
|
|
8348
|
+
flags: flagsOf(o),
|
|
8349
|
+
position: 0,
|
|
8350
|
+
...isExclusive(o) ? { exclusive: true } : o.create ? { create: true } : { existing: true },
|
|
8351
|
+
...o.truncate ? { truncate: true } : {}
|
|
8352
|
+
};
|
|
8353
|
+
}
|
|
8354
|
+
function index(n, what) {
|
|
8355
|
+
if (!Number.isSafeInteger(n) || n < 0) throw new JsCallError("EINVAL", what);
|
|
8356
|
+
}
|
|
8357
|
+
var CHUNK, MAX_IO, O_WRONLY6, O_RDWR6, O_APPEND3;
|
|
8358
|
+
var init_js_io = __esm({
|
|
8359
|
+
"src/process/js/js-io.ts"() {
|
|
8360
|
+
"use strict";
|
|
8361
|
+
init_js_kernel();
|
|
8362
|
+
CHUNK = 64 * 1024;
|
|
8363
|
+
MAX_IO = 1024 * 1024;
|
|
8364
|
+
O_WRONLY6 = 1;
|
|
8365
|
+
O_RDWR6 = 2;
|
|
8366
|
+
O_APPEND3 = 1024;
|
|
8367
|
+
}
|
|
8368
|
+
});
|
|
8369
|
+
|
|
8370
|
+
// src/process/js/js-sync.ts
|
|
8371
|
+
function laneOf(lane) {
|
|
8372
|
+
if (!lane) return () => ({ ok: false, errno: "ENOSYS", message: "no sync lane" });
|
|
8373
|
+
const transport = createSyncSabTransport(lane.sab, lane.port);
|
|
8374
|
+
return (req) => transport.call(req, Number.POSITIVE_INFINITY, req.op);
|
|
8375
|
+
}
|
|
8376
|
+
function syncOps(kernel, shared) {
|
|
8377
|
+
const { infos, handles, resolve } = shared;
|
|
8378
|
+
const info = (fd) => {
|
|
8379
|
+
const known = infos.get(fd);
|
|
8380
|
+
if (known) return known;
|
|
8381
|
+
const got = kernel.json({ op: "fd-info", fd });
|
|
8382
|
+
infos.set(fd, got);
|
|
8383
|
+
return got;
|
|
8384
|
+
};
|
|
8385
|
+
const read = (fd, max = CHUNK) => {
|
|
8386
|
+
index(max, "read");
|
|
8387
|
+
const emulated = readDevice(info(fd), max, shared.random);
|
|
8388
|
+
if (emulated) return emulated;
|
|
8389
|
+
const r = kernel.blocking({ op: "fd-read", fd, max: Math.min(max, MAX_IO) });
|
|
8390
|
+
return r.ok && r.kind === "bytes" ? r.bytes : new Uint8Array(0);
|
|
8391
|
+
};
|
|
8392
|
+
const write = (fd, data) => {
|
|
8393
|
+
const bytes = typeof data === "string" ? encoder2.encode(data) : data;
|
|
8394
|
+
const i = info(fd);
|
|
8395
|
+
if (writeDevice(i)) return;
|
|
8396
|
+
let at = 0;
|
|
8397
|
+
while (at < bytes.length) {
|
|
8398
|
+
const body = bytes.subarray(at, at + MAX_IO);
|
|
8399
|
+
try {
|
|
8400
|
+
at += written(kernel.blocking({ op: "fd-write", fd, body }), body.length);
|
|
8401
|
+
} catch (err) {
|
|
8402
|
+
if (brokenPipe(err, i)) kernel.call({ op: "proc-kill", pid: shared.pid, sig: SIG.PIPE });
|
|
8403
|
+
throw err;
|
|
8404
|
+
}
|
|
8405
|
+
}
|
|
8406
|
+
};
|
|
8407
|
+
const statOf = (op, path) => {
|
|
8408
|
+
const abs = resolve(path);
|
|
8409
|
+
kernel.call({ op: "fd-path-flush", path: abs });
|
|
8410
|
+
const s = parseSyncFsStat(kernel.json({ op, path: abs }));
|
|
8411
|
+
if (!s) throw new JsCallError("EIO", op);
|
|
8412
|
+
return s;
|
|
8413
|
+
};
|
|
8414
|
+
const open = (path, options = {}) => {
|
|
8415
|
+
const abs = resolve(path);
|
|
8416
|
+
let existing;
|
|
8417
|
+
try {
|
|
8418
|
+
existing = statOf(isExclusive(options) ? "lstat" : "stat", abs);
|
|
8419
|
+
} catch (err) {
|
|
8420
|
+
existing = absent(err);
|
|
8421
|
+
}
|
|
8422
|
+
checkOpen(abs, options, existing);
|
|
8423
|
+
const fd = kernel.json(openRequest(abs, options));
|
|
8424
|
+
try {
|
|
8425
|
+
kernel.call({ op: "fd-vfs-stat", fd });
|
|
8426
|
+
} catch (err) {
|
|
8427
|
+
kernel.raw({ op: "fd-close", fd });
|
|
8428
|
+
throw err;
|
|
8429
|
+
}
|
|
8430
|
+
infos.set(fd, { kind: "file" });
|
|
8431
|
+
const handle = syncFile(kernel, fd, abs, options.append === true, () => {
|
|
8432
|
+
infos.delete(fd);
|
|
8433
|
+
handles.delete(fd);
|
|
8434
|
+
});
|
|
8435
|
+
handles.set(fd, handle.invalidate);
|
|
8436
|
+
return handle.file;
|
|
8437
|
+
};
|
|
8438
|
+
return {
|
|
8439
|
+
read,
|
|
8440
|
+
write,
|
|
8441
|
+
close(fd) {
|
|
8442
|
+
handles.get(fd)?.();
|
|
8443
|
+
handles.delete(fd);
|
|
8444
|
+
infos.delete(fd);
|
|
8445
|
+
kernel.call({ op: "fd-close", fd });
|
|
8446
|
+
},
|
|
8447
|
+
open,
|
|
8448
|
+
fs: syncPathOps(kernel, resolve, statOf, open)
|
|
8449
|
+
};
|
|
8450
|
+
}
|
|
8451
|
+
function syncFile(kernel, fd, path, append, forget) {
|
|
8452
|
+
let open = true;
|
|
8453
|
+
const live = () => {
|
|
8454
|
+
if (!open) throw new JsCallError("EBADF", path);
|
|
8455
|
+
};
|
|
8456
|
+
const file = {
|
|
8457
|
+
fd,
|
|
8458
|
+
path,
|
|
8459
|
+
size() {
|
|
8460
|
+
live();
|
|
8461
|
+
return kernel.json({ op: "fd-vfs-stat", fd }).size;
|
|
8462
|
+
},
|
|
8463
|
+
read(position, length) {
|
|
8464
|
+
index(position, "read");
|
|
8465
|
+
index(length, "read");
|
|
8466
|
+
const parts = [];
|
|
8467
|
+
let got = 0;
|
|
8468
|
+
do {
|
|
8469
|
+
live();
|
|
8470
|
+
const max = Math.min(length - got, MAX_IO);
|
|
8471
|
+
if (max <= 0) break;
|
|
8472
|
+
const chunk = kernel.bytes({ op: "fd-pread", fd, offset: position + got, max });
|
|
8473
|
+
if (chunk.length === 0) break;
|
|
8474
|
+
parts.push(chunk);
|
|
8475
|
+
got += chunk.length;
|
|
8476
|
+
} while (got < length);
|
|
8477
|
+
return joined(parts, got);
|
|
8478
|
+
},
|
|
8479
|
+
write(position, data) {
|
|
8480
|
+
index(position, "write");
|
|
8481
|
+
let at = 0;
|
|
8482
|
+
do {
|
|
8483
|
+
live();
|
|
8484
|
+
if (at >= data.length) break;
|
|
8485
|
+
const body = data.subarray(at, at + MAX_IO);
|
|
8486
|
+
const n = kernel.json(fileWrite(fd, append, position + at, body));
|
|
8487
|
+
if (!(n > 0)) throw new JsCallError("EIO", "write");
|
|
8488
|
+
at += n;
|
|
8489
|
+
} while (at < data.length);
|
|
8490
|
+
return at;
|
|
8491
|
+
},
|
|
8492
|
+
truncate(size) {
|
|
8493
|
+
live();
|
|
8494
|
+
index(size, "truncate");
|
|
8495
|
+
kernel.call({ op: "fd-resize", fd, size });
|
|
8496
|
+
},
|
|
8497
|
+
sync() {
|
|
8498
|
+
live();
|
|
8499
|
+
kernel.call({ op: "fd-flush", fd });
|
|
8500
|
+
},
|
|
8501
|
+
close() {
|
|
8502
|
+
live();
|
|
8503
|
+
open = false;
|
|
8504
|
+
forget();
|
|
8505
|
+
kernel.call({ op: "fd-close", fd });
|
|
8506
|
+
}
|
|
8507
|
+
};
|
|
8508
|
+
return {
|
|
8509
|
+
file,
|
|
8510
|
+
invalidate: () => {
|
|
8511
|
+
open = false;
|
|
8512
|
+
}
|
|
8513
|
+
};
|
|
8514
|
+
}
|
|
8515
|
+
function syncPathOps(kernel, resolve, statOf, open) {
|
|
8516
|
+
return {
|
|
8517
|
+
stat: (path) => statOf("stat", path),
|
|
8518
|
+
lstat: (path) => statOf("lstat", path),
|
|
8519
|
+
exists: (path) => kernel.json({ op: "exists", path: resolve(path) }) === true,
|
|
8520
|
+
readdir: (path) => kernel.json({ op: "readdir", path: resolve(path) }),
|
|
8521
|
+
mkdir: (path) => void kernel.call({ op: "mkdir", path: resolve(path) }),
|
|
8522
|
+
rm: (path) => void kernel.call({ op: "rm", path: resolve(path) }),
|
|
8523
|
+
unlink: (path) => void kernel.call({ op: "unlink", path: resolve(path) }),
|
|
8524
|
+
rename: (from, to) => void kernel.call({ op: "rename", path: resolve(from), arg2: resolve(to) }),
|
|
8525
|
+
symlink: (target, path) => void kernel.call({ op: "symlink", path: resolve(path), arg2: target }),
|
|
8526
|
+
readlink: (path) => String(kernel.json({ op: "readlink", path: resolve(path) })),
|
|
8527
|
+
readFile(path) {
|
|
8528
|
+
const abs = resolve(path);
|
|
8529
|
+
kernel.call({ op: "fd-path-flush", path: abs });
|
|
8530
|
+
return kernel.bytes({ op: "read", path: abs });
|
|
8531
|
+
},
|
|
8532
|
+
writeFile(path, data) {
|
|
8533
|
+
const file = open(path, { write: true, create: true, truncate: true });
|
|
8534
|
+
try {
|
|
8535
|
+
file.write(0, typeof data === "string" ? encoder2.encode(data) : data);
|
|
8536
|
+
} finally {
|
|
8537
|
+
file.close();
|
|
8538
|
+
}
|
|
8539
|
+
}
|
|
8540
|
+
};
|
|
8541
|
+
}
|
|
8542
|
+
var encoder2, JsSyncKernel;
|
|
8543
|
+
var init_js_sync = __esm({
|
|
8544
|
+
"src/process/js/js-sync.ts"() {
|
|
8545
|
+
"use strict";
|
|
8546
|
+
init_signals();
|
|
8547
|
+
init_sync_fs_wire();
|
|
8548
|
+
init_sync_sab_bridge();
|
|
8549
|
+
init_js_io();
|
|
8550
|
+
init_js_kernel();
|
|
8551
|
+
encoder2 = new TextEncoder();
|
|
8552
|
+
JsSyncKernel = class {
|
|
8553
|
+
lane;
|
|
8554
|
+
kernel;
|
|
8555
|
+
unwind;
|
|
8556
|
+
constructor(lane, kernel, unwind = () => {
|
|
8557
|
+
}) {
|
|
8558
|
+
this.lane = lane;
|
|
8559
|
+
this.kernel = kernel;
|
|
8560
|
+
this.unwind = unwind;
|
|
8561
|
+
}
|
|
8562
|
+
raw(req) {
|
|
8563
|
+
this.unwind();
|
|
8564
|
+
const result = this.lane(req);
|
|
8565
|
+
this.kernel.deliver();
|
|
8566
|
+
this.unwind();
|
|
8567
|
+
return result;
|
|
8568
|
+
}
|
|
8569
|
+
call(req) {
|
|
8570
|
+
const result = this.raw(req);
|
|
8571
|
+
if (!result.ok) throw new JsCallError(result.errno, req.op);
|
|
8572
|
+
return result;
|
|
8573
|
+
}
|
|
8574
|
+
json(req) {
|
|
8575
|
+
const result = this.call(req);
|
|
8576
|
+
return result.ok && result.kind === "json" ? result.json : void 0;
|
|
8577
|
+
}
|
|
8578
|
+
bytes(req) {
|
|
8579
|
+
const result = this.call(req);
|
|
8580
|
+
return result.ok && result.kind === "bytes" ? result.bytes : new Uint8Array(0);
|
|
8581
|
+
}
|
|
8582
|
+
blocking(req) {
|
|
8583
|
+
for (; ; ) {
|
|
8584
|
+
const result = this.raw(req);
|
|
8585
|
+
if (result.ok) return result;
|
|
8586
|
+
if (result.errno !== "EINTR") throw new JsCallError(result.errno, req.op);
|
|
8587
|
+
}
|
|
8588
|
+
}
|
|
8589
|
+
};
|
|
8590
|
+
}
|
|
8591
|
+
});
|
|
8592
|
+
|
|
8274
8593
|
// src/process/js/js-context.ts
|
|
8275
8594
|
function identityOf(answer2, fallback) {
|
|
8276
8595
|
const id = answer2;
|
|
@@ -8297,18 +8616,6 @@ function resolvePath(cwd, path) {
|
|
|
8297
8616
|
}
|
|
8298
8617
|
return `/${parts.join("/")}`;
|
|
8299
8618
|
}
|
|
8300
|
-
function typeOf(info) {
|
|
8301
|
-
if (info.meta && "dir" in info.meta) return "directory";
|
|
8302
|
-
if (info.meta && "device" in info.meta) return "device";
|
|
8303
|
-
if (info.tty || info.kind === "tty") return "tty";
|
|
8304
|
-
if (info.kind === "socket") return "socket";
|
|
8305
|
-
return info.kind === "file" ? "file" : "pipe";
|
|
8306
|
-
}
|
|
8307
|
-
function flagsOf(o) {
|
|
8308
|
-
const write = o.write || o.append || o.truncate;
|
|
8309
|
-
const access = write ? o.read ? O_RDWR6 : O_WRONLY6 : 0;
|
|
8310
|
-
return access | (o.append ? O_APPEND3 : 0);
|
|
8311
|
-
}
|
|
8312
8619
|
function createContext(o) {
|
|
8313
8620
|
const { kernel } = o;
|
|
8314
8621
|
const infos = /* @__PURE__ */ new Map();
|
|
@@ -8316,10 +8623,16 @@ function createContext(o) {
|
|
|
8316
8623
|
const pending = /* @__PURE__ */ new Set();
|
|
8317
8624
|
const random = o.random ?? ((bytes) => void crypto.getRandomValues(bytes));
|
|
8318
8625
|
const resolve = (path) => resolvePath(o.cwd, path);
|
|
8626
|
+
let exiting;
|
|
8319
8627
|
const exit = (code2 = 0) => {
|
|
8628
|
+
exiting ??= code2;
|
|
8320
8629
|
o.exit(code2);
|
|
8321
8630
|
throw new JsExit(code2);
|
|
8322
8631
|
};
|
|
8632
|
+
const unwind = () => {
|
|
8633
|
+
if (exiting !== void 0) throw new JsExit(exiting);
|
|
8634
|
+
if (kernel.faulted) throw new JsExit(1);
|
|
8635
|
+
};
|
|
8323
8636
|
const info = async (fd) => {
|
|
8324
8637
|
const known = infos.get(fd);
|
|
8325
8638
|
if (known) return known;
|
|
@@ -8327,48 +8640,30 @@ function createContext(o) {
|
|
|
8327
8640
|
infos.set(fd, got);
|
|
8328
8641
|
return got;
|
|
8329
8642
|
};
|
|
8330
|
-
const device = (i) => i.meta && "device" in i.meta ? i.meta : void 0;
|
|
8331
8643
|
const read = async (fd, max = CHUNK) => {
|
|
8332
8644
|
index(max, "read");
|
|
8333
|
-
const
|
|
8334
|
-
if (
|
|
8335
|
-
const dev = device(i);
|
|
8336
|
-
if (dev) {
|
|
8337
|
-
if (dev.access === "write") throw new JsCallError("EBADF", "read");
|
|
8338
|
-
if (dev.device === "null") return new Uint8Array(0);
|
|
8339
|
-
const out = new Uint8Array(Math.min(max, CHUNK));
|
|
8340
|
-
if (dev.device === "urandom") random(out);
|
|
8341
|
-
return out;
|
|
8342
|
-
}
|
|
8645
|
+
const emulated = readDevice(await info(fd), max, random);
|
|
8646
|
+
if (emulated) return emulated;
|
|
8343
8647
|
const r = await kernel.blocking({ op: "fd-read", fd, max: Math.min(max, MAX_IO) });
|
|
8344
8648
|
return r.ok && r.kind === "bytes" ? r.bytes : new Uint8Array(0);
|
|
8345
8649
|
};
|
|
8346
8650
|
const writeAll = async (fd, data) => {
|
|
8347
8651
|
const i = await info(fd);
|
|
8348
|
-
if (
|
|
8349
|
-
const dev = device(i);
|
|
8350
|
-
if (dev) {
|
|
8351
|
-
if (dev.access === "read") throw new JsCallError("EBADF", "write");
|
|
8352
|
-
if (dev.device === "full") throw new JsCallError("ENOSPC", "write");
|
|
8353
|
-
return;
|
|
8354
|
-
}
|
|
8652
|
+
if (writeDevice(i)) return;
|
|
8355
8653
|
let at = 0;
|
|
8356
8654
|
while (at < data.length) {
|
|
8357
8655
|
const body = data.subarray(at, at + MAX_IO);
|
|
8358
8656
|
try {
|
|
8359
8657
|
const r = await kernel.blocking({ op: "fd-write", fd, body });
|
|
8360
|
-
at += r
|
|
8658
|
+
at += written(r, body.length);
|
|
8361
8659
|
} catch (err) {
|
|
8362
|
-
|
|
8363
|
-
if (broken && typeOf(i) !== "socket") {
|
|
8364
|
-
await kernel.call({ op: "proc-kill", pid: o.pid, sig: SIG.PIPE });
|
|
8365
|
-
}
|
|
8660
|
+
if (brokenPipe(err, i)) await kernel.call({ op: "proc-kill", pid: o.pid, sig: SIG.PIPE });
|
|
8366
8661
|
throw err;
|
|
8367
8662
|
}
|
|
8368
8663
|
}
|
|
8369
8664
|
};
|
|
8370
8665
|
const write = (fd, data) => {
|
|
8371
|
-
const bytes = typeof data === "string" ?
|
|
8666
|
+
const bytes = typeof data === "string" ? encoder3.encode(data) : data;
|
|
8372
8667
|
let settle;
|
|
8373
8668
|
const settled = new Promise((resolve2) => settle = resolve2);
|
|
8374
8669
|
pending.add(settled);
|
|
@@ -8391,22 +8686,9 @@ function createContext(o) {
|
|
|
8391
8686
|
};
|
|
8392
8687
|
const open = async (path, options = {}) => {
|
|
8393
8688
|
const abs = resolve(path);
|
|
8394
|
-
const
|
|
8395
|
-
|
|
8396
|
-
|
|
8397
|
-
throw err;
|
|
8398
|
-
});
|
|
8399
|
-
if (existing && exclusive) throw new JsCallError("EEXIST", abs);
|
|
8400
|
-
if (!existing && !options.create) throw new JsCallError("ENOENT", abs);
|
|
8401
|
-
if (existing?.isDirectory) throw new JsCallError("EISDIR", abs);
|
|
8402
|
-
const fd = await kernel.json({
|
|
8403
|
-
op: "fd-open-vfs",
|
|
8404
|
-
path: abs,
|
|
8405
|
-
flags: flagsOf(options),
|
|
8406
|
-
position: 0,
|
|
8407
|
-
...exclusive ? { exclusive: true } : options.create ? { create: true } : { existing: true },
|
|
8408
|
-
...options.truncate ? { truncate: true } : {}
|
|
8409
|
-
});
|
|
8689
|
+
const existing = await statOf(isExclusive(options) ? "lstat" : "stat", abs).catch(absent);
|
|
8690
|
+
checkOpen(abs, options, existing);
|
|
8691
|
+
const fd = await kernel.json(openRequest(abs, options));
|
|
8410
8692
|
try {
|
|
8411
8693
|
await kernel.call({ op: "fd-vfs-stat", fd });
|
|
8412
8694
|
} catch (err) {
|
|
@@ -8422,6 +8704,13 @@ function createContext(o) {
|
|
|
8422
8704
|
return handle.file;
|
|
8423
8705
|
};
|
|
8424
8706
|
const fs = pathOps(kernel, resolve, statOf, open);
|
|
8707
|
+
const sync = syncOps(new JsSyncKernel(o.lane ?? laneOf(void 0), kernel, unwind), {
|
|
8708
|
+
pid: o.pid,
|
|
8709
|
+
resolve,
|
|
8710
|
+
random,
|
|
8711
|
+
infos,
|
|
8712
|
+
handles
|
|
8713
|
+
});
|
|
8425
8714
|
const ctx = {
|
|
8426
8715
|
argv: o.argv,
|
|
8427
8716
|
env: o.env,
|
|
@@ -8463,6 +8752,7 @@ function createContext(o) {
|
|
|
8463
8752
|
ignore: async (signal) => kernel.setHandler(signalNumber(signal), "ignore"),
|
|
8464
8753
|
reset: async (signal) => kernel.setHandler(signalNumber(signal), "default")
|
|
8465
8754
|
},
|
|
8755
|
+
sync,
|
|
8466
8756
|
exit
|
|
8467
8757
|
};
|
|
8468
8758
|
const drain2 = async () => {
|
|
@@ -8501,14 +8791,7 @@ function fileHandle(kernel, fd, path, append, forget) {
|
|
|
8501
8791
|
parts.push(chunk);
|
|
8502
8792
|
got += chunk.length;
|
|
8503
8793
|
} while (got < length);
|
|
8504
|
-
|
|
8505
|
-
const out = new Uint8Array(got);
|
|
8506
|
-
let at = 0;
|
|
8507
|
-
for (const part of parts) {
|
|
8508
|
-
out.set(part, at);
|
|
8509
|
-
at += part.length;
|
|
8510
|
-
}
|
|
8511
|
-
return out;
|
|
8794
|
+
return joined(parts, got);
|
|
8512
8795
|
},
|
|
8513
8796
|
async write(position, data) {
|
|
8514
8797
|
index(position, "write");
|
|
@@ -8517,9 +8800,7 @@ function fileHandle(kernel, fd, path, append, forget) {
|
|
|
8517
8800
|
live();
|
|
8518
8801
|
if (at >= data.length) break;
|
|
8519
8802
|
const body = data.subarray(at, at + MAX_IO);
|
|
8520
|
-
const n = await kernel.json(
|
|
8521
|
-
append ? { op: "fd-write", fd, body } : { op: "fd-pwrite", fd, offset: position + at, body }
|
|
8522
|
-
);
|
|
8803
|
+
const n = await kernel.json(fileWrite(fd, append, position + at, body));
|
|
8523
8804
|
if (!(n > 0)) throw new JsCallError("EIO", "write");
|
|
8524
8805
|
at += n;
|
|
8525
8806
|
} while (at < data.length);
|
|
@@ -8548,9 +8829,6 @@ function fileHandle(kernel, fd, path, append, forget) {
|
|
|
8548
8829
|
}
|
|
8549
8830
|
};
|
|
8550
8831
|
}
|
|
8551
|
-
function index(n, what) {
|
|
8552
|
-
if (!Number.isSafeInteger(n) || n < 0) throw new JsCallError("EINVAL", what);
|
|
8553
|
-
}
|
|
8554
8832
|
function pathOps(kernel, resolve, statOf, open) {
|
|
8555
8833
|
return {
|
|
8556
8834
|
stat: (path) => statOf("stat", path),
|
|
@@ -8571,20 +8849,22 @@ function pathOps(kernel, resolve, statOf, open) {
|
|
|
8571
8849
|
async writeFile(path, data) {
|
|
8572
8850
|
const file = await open(path, { write: true, create: true, truncate: true });
|
|
8573
8851
|
try {
|
|
8574
|
-
await file.write(0, typeof data === "string" ?
|
|
8852
|
+
await file.write(0, typeof data === "string" ? encoder3.encode(data) : data);
|
|
8575
8853
|
} finally {
|
|
8576
8854
|
await file.close();
|
|
8577
8855
|
}
|
|
8578
8856
|
}
|
|
8579
8857
|
};
|
|
8580
8858
|
}
|
|
8581
|
-
var JsExit,
|
|
8859
|
+
var JsExit, encoder3;
|
|
8582
8860
|
var init_js_context = __esm({
|
|
8583
8861
|
"src/process/js/js-context.ts"() {
|
|
8584
8862
|
"use strict";
|
|
8585
8863
|
init_signals();
|
|
8586
8864
|
init_sync_fs_wire();
|
|
8865
|
+
init_js_io();
|
|
8587
8866
|
init_js_kernel();
|
|
8867
|
+
init_js_sync();
|
|
8588
8868
|
JsExit = class extends Error {
|
|
8589
8869
|
status;
|
|
8590
8870
|
constructor(status2) {
|
|
@@ -8593,12 +8873,7 @@ var init_js_context = __esm({
|
|
|
8593
8873
|
this.status = status2;
|
|
8594
8874
|
}
|
|
8595
8875
|
};
|
|
8596
|
-
|
|
8597
|
-
MAX_IO = 1024 * 1024;
|
|
8598
|
-
O_WRONLY6 = 1;
|
|
8599
|
-
O_RDWR6 = 2;
|
|
8600
|
-
O_APPEND3 = 1024;
|
|
8601
|
-
encoder2 = new TextEncoder();
|
|
8876
|
+
encoder3 = new TextEncoder();
|
|
8602
8877
|
}
|
|
8603
8878
|
});
|
|
8604
8879
|
|
|
@@ -8726,7 +9001,8 @@ async function runJsProcess(init, port2, deps = {}) {
|
|
|
8726
9001
|
pid: id.pid,
|
|
8727
9002
|
ppid: id.ppid,
|
|
8728
9003
|
cwd: init.cwd,
|
|
8729
|
-
exit: (status3) => exited(statusOf(status3))
|
|
9004
|
+
exit: (status3) => exited(statusOf(status3)),
|
|
9005
|
+
lane: laneOf(init.lane)
|
|
8730
9006
|
});
|
|
8731
9007
|
const say = (text) => ctx.write(2, `${init.argv0}: ${text}
|
|
8732
9008
|
`).catch(() => void 0);
|
|
@@ -8764,6 +9040,7 @@ var init_js_runtime = __esm({
|
|
|
8764
9040
|
init_async_sab();
|
|
8765
9041
|
init_js_context();
|
|
8766
9042
|
init_js_kernel();
|
|
9043
|
+
init_js_sync();
|
|
8767
9044
|
init_lockdown();
|
|
8768
9045
|
NOT_RUNNABLE = 126;
|
|
8769
9046
|
}
|