@ai-ecoverse/slicc-kernel 1.37.1 → 1.39.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 +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 +370 -99
- 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 +370 -99
- package/dist/process-worker.js.map +4 -4
- package/package.json +1 -1
package/dist/process-worker.js
CHANGED
|
@@ -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, port, 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
|
}
|
|
@@ -8271,6 +8271,320 @@ var init_js_kernel = __esm({
|
|
|
8271
8271
|
}
|
|
8272
8272
|
});
|
|
8273
8273
|
|
|
8274
|
+
// src/process/js/js-io.ts
|
|
8275
|
+
function typeOf(info) {
|
|
8276
|
+
if (info.meta && "dir" in info.meta) return "directory";
|
|
8277
|
+
if (info.meta && "device" in info.meta) return "device";
|
|
8278
|
+
if (info.tty || info.kind === "tty") return "tty";
|
|
8279
|
+
if (info.kind === "socket") return "socket";
|
|
8280
|
+
return info.kind === "file" ? "file" : "pipe";
|
|
8281
|
+
}
|
|
8282
|
+
function device(info) {
|
|
8283
|
+
return info.meta && "device" in info.meta ? info.meta : void 0;
|
|
8284
|
+
}
|
|
8285
|
+
function readDevice(info, max, random) {
|
|
8286
|
+
if (typeOf(info) === "directory") throw new JsCallError("EISDIR", "read");
|
|
8287
|
+
const dev = device(info);
|
|
8288
|
+
if (!dev) return void 0;
|
|
8289
|
+
if (dev.access === "write") throw new JsCallError("EBADF", "read");
|
|
8290
|
+
if (dev.device === "null") return new Uint8Array(0);
|
|
8291
|
+
const out = new Uint8Array(Math.min(max, CHUNK));
|
|
8292
|
+
if (dev.device === "urandom") random(out);
|
|
8293
|
+
return out;
|
|
8294
|
+
}
|
|
8295
|
+
function writeDevice(info) {
|
|
8296
|
+
if (typeOf(info) === "directory") throw new JsCallError("EISDIR", "write");
|
|
8297
|
+
const dev = device(info);
|
|
8298
|
+
if (!dev) return false;
|
|
8299
|
+
if (dev.access === "read") throw new JsCallError("EBADF", "write");
|
|
8300
|
+
if (dev.device === "full") throw new JsCallError("ENOSPC", "write");
|
|
8301
|
+
return true;
|
|
8302
|
+
}
|
|
8303
|
+
function brokenPipe(err, info) {
|
|
8304
|
+
return err instanceof JsCallError && err.code === "EPIPE" && typeOf(info) !== "socket";
|
|
8305
|
+
}
|
|
8306
|
+
function written(r, fallback) {
|
|
8307
|
+
return r.ok && r.kind === "json" && typeof r.json === "number" ? r.json : fallback;
|
|
8308
|
+
}
|
|
8309
|
+
function joined(parts, length) {
|
|
8310
|
+
if (parts.length === 1) return parts[0];
|
|
8311
|
+
const out = new Uint8Array(length);
|
|
8312
|
+
let at = 0;
|
|
8313
|
+
for (const part of parts) {
|
|
8314
|
+
out.set(part, at);
|
|
8315
|
+
at += part.length;
|
|
8316
|
+
}
|
|
8317
|
+
return out;
|
|
8318
|
+
}
|
|
8319
|
+
function fileWrite(fd, append, offset, body) {
|
|
8320
|
+
return append ? { op: "fd-write", fd, body } : { op: "fd-pwrite", fd, offset, body };
|
|
8321
|
+
}
|
|
8322
|
+
function isExclusive(o) {
|
|
8323
|
+
return o.create === true && o.exclusive === true;
|
|
8324
|
+
}
|
|
8325
|
+
function absent(err) {
|
|
8326
|
+
if (err instanceof JsCallError && err.code === "ENOENT") return void 0;
|
|
8327
|
+
throw err;
|
|
8328
|
+
}
|
|
8329
|
+
function checkOpen(abs, o, existing) {
|
|
8330
|
+
if (existing && isExclusive(o)) throw new JsCallError("EEXIST", abs);
|
|
8331
|
+
if (!existing && !o.create) throw new JsCallError("ENOENT", abs);
|
|
8332
|
+
if (existing?.isDirectory) throw new JsCallError("EISDIR", abs);
|
|
8333
|
+
}
|
|
8334
|
+
function flagsOf(o) {
|
|
8335
|
+
const write = o.write || o.append || o.truncate;
|
|
8336
|
+
const access = write ? o.read ? O_RDWR6 : O_WRONLY6 : 0;
|
|
8337
|
+
return access | (o.append ? O_APPEND3 : 0);
|
|
8338
|
+
}
|
|
8339
|
+
function openRequest(abs, o) {
|
|
8340
|
+
return {
|
|
8341
|
+
op: "fd-open-vfs",
|
|
8342
|
+
path: abs,
|
|
8343
|
+
flags: flagsOf(o),
|
|
8344
|
+
position: 0,
|
|
8345
|
+
...isExclusive(o) ? { exclusive: true } : o.create ? { create: true } : { existing: true },
|
|
8346
|
+
...o.truncate ? { truncate: true } : {}
|
|
8347
|
+
};
|
|
8348
|
+
}
|
|
8349
|
+
function index(n, what) {
|
|
8350
|
+
if (!Number.isSafeInteger(n) || n < 0) throw new JsCallError("EINVAL", what);
|
|
8351
|
+
}
|
|
8352
|
+
var CHUNK, MAX_IO, O_WRONLY6, O_RDWR6, O_APPEND3;
|
|
8353
|
+
var init_js_io = __esm({
|
|
8354
|
+
"src/process/js/js-io.ts"() {
|
|
8355
|
+
"use strict";
|
|
8356
|
+
init_js_kernel();
|
|
8357
|
+
CHUNK = 64 * 1024;
|
|
8358
|
+
MAX_IO = 1024 * 1024;
|
|
8359
|
+
O_WRONLY6 = 1;
|
|
8360
|
+
O_RDWR6 = 2;
|
|
8361
|
+
O_APPEND3 = 1024;
|
|
8362
|
+
}
|
|
8363
|
+
});
|
|
8364
|
+
|
|
8365
|
+
// src/process/js/js-sync.ts
|
|
8366
|
+
function laneOf(lane) {
|
|
8367
|
+
if (!lane) return () => ({ ok: false, errno: "ENOSYS", message: "no sync lane" });
|
|
8368
|
+
const transport = createSyncSabTransport(lane.sab, lane.port);
|
|
8369
|
+
return (req) => transport.call(req, Number.POSITIVE_INFINITY, req.op);
|
|
8370
|
+
}
|
|
8371
|
+
function syncOps(kernel, shared) {
|
|
8372
|
+
const { infos, handles, resolve } = shared;
|
|
8373
|
+
const info = (fd) => {
|
|
8374
|
+
const known = infos.get(fd);
|
|
8375
|
+
if (known) return known;
|
|
8376
|
+
const got = kernel.json({ op: "fd-info", fd });
|
|
8377
|
+
infos.set(fd, got);
|
|
8378
|
+
return got;
|
|
8379
|
+
};
|
|
8380
|
+
const read = (fd, max = CHUNK) => {
|
|
8381
|
+
index(max, "read");
|
|
8382
|
+
const emulated = readDevice(info(fd), max, shared.random);
|
|
8383
|
+
if (emulated) return emulated;
|
|
8384
|
+
const r = kernel.blocking({ op: "fd-read", fd, max: Math.min(max, MAX_IO) });
|
|
8385
|
+
return r.ok && r.kind === "bytes" ? r.bytes : new Uint8Array(0);
|
|
8386
|
+
};
|
|
8387
|
+
const write = (fd, data) => {
|
|
8388
|
+
const bytes = typeof data === "string" ? encoder2.encode(data) : data;
|
|
8389
|
+
const i = info(fd);
|
|
8390
|
+
if (writeDevice(i)) return;
|
|
8391
|
+
let at = 0;
|
|
8392
|
+
while (at < bytes.length) {
|
|
8393
|
+
const body = bytes.subarray(at, at + MAX_IO);
|
|
8394
|
+
try {
|
|
8395
|
+
at += written(kernel.blocking({ op: "fd-write", fd, body }), body.length);
|
|
8396
|
+
} catch (err) {
|
|
8397
|
+
if (brokenPipe(err, i)) kernel.call({ op: "proc-kill", pid: shared.pid, sig: SIG.PIPE });
|
|
8398
|
+
throw err;
|
|
8399
|
+
}
|
|
8400
|
+
}
|
|
8401
|
+
};
|
|
8402
|
+
const statOf = (op, path) => {
|
|
8403
|
+
const abs = resolve(path);
|
|
8404
|
+
kernel.call({ op: "fd-path-flush", path: abs });
|
|
8405
|
+
const s = parseSyncFsStat(kernel.json({ op, path: abs }));
|
|
8406
|
+
if (!s) throw new JsCallError("EIO", op);
|
|
8407
|
+
return s;
|
|
8408
|
+
};
|
|
8409
|
+
const open = (path, options = {}) => {
|
|
8410
|
+
const abs = resolve(path);
|
|
8411
|
+
let existing;
|
|
8412
|
+
try {
|
|
8413
|
+
existing = statOf(isExclusive(options) ? "lstat" : "stat", abs);
|
|
8414
|
+
} catch (err) {
|
|
8415
|
+
existing = absent(err);
|
|
8416
|
+
}
|
|
8417
|
+
checkOpen(abs, options, existing);
|
|
8418
|
+
const fd = kernel.json(openRequest(abs, options));
|
|
8419
|
+
try {
|
|
8420
|
+
kernel.call({ op: "fd-vfs-stat", fd });
|
|
8421
|
+
} catch (err) {
|
|
8422
|
+
kernel.raw({ op: "fd-close", fd });
|
|
8423
|
+
throw err;
|
|
8424
|
+
}
|
|
8425
|
+
infos.set(fd, { kind: "file" });
|
|
8426
|
+
const handle = syncFile(kernel, fd, abs, options.append === true, () => {
|
|
8427
|
+
infos.delete(fd);
|
|
8428
|
+
handles.delete(fd);
|
|
8429
|
+
});
|
|
8430
|
+
handles.set(fd, handle.invalidate);
|
|
8431
|
+
return handle.file;
|
|
8432
|
+
};
|
|
8433
|
+
return {
|
|
8434
|
+
read,
|
|
8435
|
+
write,
|
|
8436
|
+
close(fd) {
|
|
8437
|
+
handles.get(fd)?.();
|
|
8438
|
+
handles.delete(fd);
|
|
8439
|
+
infos.delete(fd);
|
|
8440
|
+
kernel.call({ op: "fd-close", fd });
|
|
8441
|
+
},
|
|
8442
|
+
open,
|
|
8443
|
+
fs: syncPathOps(kernel, resolve, statOf, open)
|
|
8444
|
+
};
|
|
8445
|
+
}
|
|
8446
|
+
function syncFile(kernel, fd, path, append, forget) {
|
|
8447
|
+
let open = true;
|
|
8448
|
+
const live = () => {
|
|
8449
|
+
if (!open) throw new JsCallError("EBADF", path);
|
|
8450
|
+
};
|
|
8451
|
+
const file = {
|
|
8452
|
+
fd,
|
|
8453
|
+
path,
|
|
8454
|
+
size() {
|
|
8455
|
+
live();
|
|
8456
|
+
return kernel.json({ op: "fd-vfs-stat", fd }).size;
|
|
8457
|
+
},
|
|
8458
|
+
read(position, length) {
|
|
8459
|
+
index(position, "read");
|
|
8460
|
+
index(length, "read");
|
|
8461
|
+
const parts = [];
|
|
8462
|
+
let got = 0;
|
|
8463
|
+
do {
|
|
8464
|
+
live();
|
|
8465
|
+
const max = Math.min(length - got, MAX_IO);
|
|
8466
|
+
if (max <= 0) break;
|
|
8467
|
+
const chunk = kernel.bytes({ op: "fd-pread", fd, offset: position + got, max });
|
|
8468
|
+
if (chunk.length === 0) break;
|
|
8469
|
+
parts.push(chunk);
|
|
8470
|
+
got += chunk.length;
|
|
8471
|
+
} while (got < length);
|
|
8472
|
+
return joined(parts, got);
|
|
8473
|
+
},
|
|
8474
|
+
write(position, data) {
|
|
8475
|
+
index(position, "write");
|
|
8476
|
+
let at = 0;
|
|
8477
|
+
do {
|
|
8478
|
+
live();
|
|
8479
|
+
if (at >= data.length) break;
|
|
8480
|
+
const body = data.subarray(at, at + MAX_IO);
|
|
8481
|
+
const n = kernel.json(fileWrite(fd, append, position + at, body));
|
|
8482
|
+
if (!(n > 0)) throw new JsCallError("EIO", "write");
|
|
8483
|
+
at += n;
|
|
8484
|
+
} while (at < data.length);
|
|
8485
|
+
return at;
|
|
8486
|
+
},
|
|
8487
|
+
truncate(size) {
|
|
8488
|
+
live();
|
|
8489
|
+
index(size, "truncate");
|
|
8490
|
+
kernel.call({ op: "fd-resize", fd, size });
|
|
8491
|
+
},
|
|
8492
|
+
sync() {
|
|
8493
|
+
live();
|
|
8494
|
+
kernel.call({ op: "fd-flush", fd });
|
|
8495
|
+
},
|
|
8496
|
+
close() {
|
|
8497
|
+
live();
|
|
8498
|
+
open = false;
|
|
8499
|
+
forget();
|
|
8500
|
+
kernel.call({ op: "fd-close", fd });
|
|
8501
|
+
}
|
|
8502
|
+
};
|
|
8503
|
+
return {
|
|
8504
|
+
file,
|
|
8505
|
+
invalidate: () => {
|
|
8506
|
+
open = false;
|
|
8507
|
+
}
|
|
8508
|
+
};
|
|
8509
|
+
}
|
|
8510
|
+
function syncPathOps(kernel, resolve, statOf, open) {
|
|
8511
|
+
return {
|
|
8512
|
+
stat: (path) => statOf("stat", path),
|
|
8513
|
+
lstat: (path) => statOf("lstat", path),
|
|
8514
|
+
exists: (path) => kernel.json({ op: "exists", path: resolve(path) }) === true,
|
|
8515
|
+
readdir: (path) => kernel.json({ op: "readdir", path: resolve(path) }),
|
|
8516
|
+
mkdir: (path) => void kernel.call({ op: "mkdir", path: resolve(path) }),
|
|
8517
|
+
rm: (path) => void kernel.call({ op: "rm", path: resolve(path) }),
|
|
8518
|
+
unlink: (path) => void kernel.call({ op: "unlink", path: resolve(path) }),
|
|
8519
|
+
rename: (from, to) => void kernel.call({ op: "rename", path: resolve(from), arg2: resolve(to) }),
|
|
8520
|
+
symlink: (target, path) => void kernel.call({ op: "symlink", path: resolve(path), arg2: target }),
|
|
8521
|
+
readlink: (path) => String(kernel.json({ op: "readlink", path: resolve(path) })),
|
|
8522
|
+
readFile(path) {
|
|
8523
|
+
const abs = resolve(path);
|
|
8524
|
+
kernel.call({ op: "fd-path-flush", path: abs });
|
|
8525
|
+
return kernel.bytes({ op: "read", path: abs });
|
|
8526
|
+
},
|
|
8527
|
+
writeFile(path, data) {
|
|
8528
|
+
const file = open(path, { write: true, create: true, truncate: true });
|
|
8529
|
+
try {
|
|
8530
|
+
file.write(0, typeof data === "string" ? encoder2.encode(data) : data);
|
|
8531
|
+
} finally {
|
|
8532
|
+
file.close();
|
|
8533
|
+
}
|
|
8534
|
+
}
|
|
8535
|
+
};
|
|
8536
|
+
}
|
|
8537
|
+
var encoder2, JsSyncKernel;
|
|
8538
|
+
var init_js_sync = __esm({
|
|
8539
|
+
"src/process/js/js-sync.ts"() {
|
|
8540
|
+
"use strict";
|
|
8541
|
+
init_signals();
|
|
8542
|
+
init_sync_fs_wire();
|
|
8543
|
+
init_sync_sab_bridge();
|
|
8544
|
+
init_js_io();
|
|
8545
|
+
init_js_kernel();
|
|
8546
|
+
encoder2 = new TextEncoder();
|
|
8547
|
+
JsSyncKernel = class {
|
|
8548
|
+
lane;
|
|
8549
|
+
kernel;
|
|
8550
|
+
unwind;
|
|
8551
|
+
constructor(lane, kernel, unwind = () => {
|
|
8552
|
+
}) {
|
|
8553
|
+
this.lane = lane;
|
|
8554
|
+
this.kernel = kernel;
|
|
8555
|
+
this.unwind = unwind;
|
|
8556
|
+
}
|
|
8557
|
+
raw(req) {
|
|
8558
|
+
this.unwind();
|
|
8559
|
+
const result = this.lane(req);
|
|
8560
|
+
this.kernel.deliver();
|
|
8561
|
+
this.unwind();
|
|
8562
|
+
return result;
|
|
8563
|
+
}
|
|
8564
|
+
call(req) {
|
|
8565
|
+
const result = this.raw(req);
|
|
8566
|
+
if (!result.ok) throw new JsCallError(result.errno, req.op);
|
|
8567
|
+
return result;
|
|
8568
|
+
}
|
|
8569
|
+
json(req) {
|
|
8570
|
+
const result = this.call(req);
|
|
8571
|
+
return result.ok && result.kind === "json" ? result.json : void 0;
|
|
8572
|
+
}
|
|
8573
|
+
bytes(req) {
|
|
8574
|
+
const result = this.call(req);
|
|
8575
|
+
return result.ok && result.kind === "bytes" ? result.bytes : new Uint8Array(0);
|
|
8576
|
+
}
|
|
8577
|
+
blocking(req) {
|
|
8578
|
+
for (; ; ) {
|
|
8579
|
+
const result = this.raw(req);
|
|
8580
|
+
if (result.ok) return result;
|
|
8581
|
+
if (result.errno !== "EINTR") throw new JsCallError(result.errno, req.op);
|
|
8582
|
+
}
|
|
8583
|
+
}
|
|
8584
|
+
};
|
|
8585
|
+
}
|
|
8586
|
+
});
|
|
8587
|
+
|
|
8274
8588
|
// src/process/js/js-context.ts
|
|
8275
8589
|
function identityOf(answer2, fallback) {
|
|
8276
8590
|
const id = answer2;
|
|
@@ -8297,18 +8611,6 @@ function resolvePath(cwd, path) {
|
|
|
8297
8611
|
}
|
|
8298
8612
|
return `/${parts.join("/")}`;
|
|
8299
8613
|
}
|
|
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
8614
|
function createContext(o) {
|
|
8313
8615
|
const { kernel } = o;
|
|
8314
8616
|
const infos = /* @__PURE__ */ new Map();
|
|
@@ -8316,10 +8618,15 @@ function createContext(o) {
|
|
|
8316
8618
|
const pending = /* @__PURE__ */ new Set();
|
|
8317
8619
|
const random = o.random ?? ((bytes) => void crypto.getRandomValues(bytes));
|
|
8318
8620
|
const resolve = (path) => resolvePath(o.cwd, path);
|
|
8621
|
+
let exiting;
|
|
8319
8622
|
const exit = (code2 = 0) => {
|
|
8623
|
+
exiting ??= code2;
|
|
8320
8624
|
o.exit(code2);
|
|
8321
8625
|
throw new JsExit(code2);
|
|
8322
8626
|
};
|
|
8627
|
+
const unwind = () => {
|
|
8628
|
+
if (exiting !== void 0) throw new JsExit(exiting);
|
|
8629
|
+
};
|
|
8323
8630
|
const info = async (fd) => {
|
|
8324
8631
|
const known = infos.get(fd);
|
|
8325
8632
|
if (known) return known;
|
|
@@ -8327,48 +8634,30 @@ function createContext(o) {
|
|
|
8327
8634
|
infos.set(fd, got);
|
|
8328
8635
|
return got;
|
|
8329
8636
|
};
|
|
8330
|
-
const device = (i) => i.meta && "device" in i.meta ? i.meta : void 0;
|
|
8331
8637
|
const read = async (fd, max = CHUNK) => {
|
|
8332
8638
|
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
|
-
}
|
|
8639
|
+
const emulated = readDevice(await info(fd), max, random);
|
|
8640
|
+
if (emulated) return emulated;
|
|
8343
8641
|
const r = await kernel.blocking({ op: "fd-read", fd, max: Math.min(max, MAX_IO) });
|
|
8344
8642
|
return r.ok && r.kind === "bytes" ? r.bytes : new Uint8Array(0);
|
|
8345
8643
|
};
|
|
8346
8644
|
const writeAll = async (fd, data) => {
|
|
8347
8645
|
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
|
-
}
|
|
8646
|
+
if (writeDevice(i)) return;
|
|
8355
8647
|
let at = 0;
|
|
8356
8648
|
while (at < data.length) {
|
|
8357
8649
|
const body = data.subarray(at, at + MAX_IO);
|
|
8358
8650
|
try {
|
|
8359
8651
|
const r = await kernel.blocking({ op: "fd-write", fd, body });
|
|
8360
|
-
at += r
|
|
8652
|
+
at += written(r, body.length);
|
|
8361
8653
|
} catch (err) {
|
|
8362
|
-
|
|
8363
|
-
if (broken && typeOf(i) !== "socket") {
|
|
8364
|
-
await kernel.call({ op: "proc-kill", pid: o.pid, sig: SIG.PIPE });
|
|
8365
|
-
}
|
|
8654
|
+
if (brokenPipe(err, i)) await kernel.call({ op: "proc-kill", pid: o.pid, sig: SIG.PIPE });
|
|
8366
8655
|
throw err;
|
|
8367
8656
|
}
|
|
8368
8657
|
}
|
|
8369
8658
|
};
|
|
8370
8659
|
const write = (fd, data) => {
|
|
8371
|
-
const bytes = typeof data === "string" ?
|
|
8660
|
+
const bytes = typeof data === "string" ? encoder3.encode(data) : data;
|
|
8372
8661
|
let settle;
|
|
8373
8662
|
const settled = new Promise((resolve2) => settle = resolve2);
|
|
8374
8663
|
pending.add(settled);
|
|
@@ -8391,22 +8680,9 @@ function createContext(o) {
|
|
|
8391
8680
|
};
|
|
8392
8681
|
const open = async (path, options = {}) => {
|
|
8393
8682
|
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
|
-
});
|
|
8683
|
+
const existing = await statOf(isExclusive(options) ? "lstat" : "stat", abs).catch(absent);
|
|
8684
|
+
checkOpen(abs, options, existing);
|
|
8685
|
+
const fd = await kernel.json(openRequest(abs, options));
|
|
8410
8686
|
try {
|
|
8411
8687
|
await kernel.call({ op: "fd-vfs-stat", fd });
|
|
8412
8688
|
} catch (err) {
|
|
@@ -8422,6 +8698,13 @@ function createContext(o) {
|
|
|
8422
8698
|
return handle.file;
|
|
8423
8699
|
};
|
|
8424
8700
|
const fs = pathOps(kernel, resolve, statOf, open);
|
|
8701
|
+
const sync = syncOps(new JsSyncKernel(o.lane ?? laneOf(void 0), kernel, unwind), {
|
|
8702
|
+
pid: o.pid,
|
|
8703
|
+
resolve,
|
|
8704
|
+
random,
|
|
8705
|
+
infos,
|
|
8706
|
+
handles
|
|
8707
|
+
});
|
|
8425
8708
|
const ctx = {
|
|
8426
8709
|
argv: o.argv,
|
|
8427
8710
|
env: o.env,
|
|
@@ -8463,6 +8746,7 @@ function createContext(o) {
|
|
|
8463
8746
|
ignore: async (signal) => kernel.setHandler(signalNumber(signal), "ignore"),
|
|
8464
8747
|
reset: async (signal) => kernel.setHandler(signalNumber(signal), "default")
|
|
8465
8748
|
},
|
|
8749
|
+
sync,
|
|
8466
8750
|
exit
|
|
8467
8751
|
};
|
|
8468
8752
|
const drain2 = async () => {
|
|
@@ -8501,14 +8785,7 @@ function fileHandle(kernel, fd, path, append, forget) {
|
|
|
8501
8785
|
parts.push(chunk);
|
|
8502
8786
|
got += chunk.length;
|
|
8503
8787
|
} 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;
|
|
8788
|
+
return joined(parts, got);
|
|
8512
8789
|
},
|
|
8513
8790
|
async write(position, data) {
|
|
8514
8791
|
index(position, "write");
|
|
@@ -8517,9 +8794,7 @@ function fileHandle(kernel, fd, path, append, forget) {
|
|
|
8517
8794
|
live();
|
|
8518
8795
|
if (at >= data.length) break;
|
|
8519
8796
|
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
|
-
);
|
|
8797
|
+
const n = await kernel.json(fileWrite(fd, append, position + at, body));
|
|
8523
8798
|
if (!(n > 0)) throw new JsCallError("EIO", "write");
|
|
8524
8799
|
at += n;
|
|
8525
8800
|
} while (at < data.length);
|
|
@@ -8548,9 +8823,6 @@ function fileHandle(kernel, fd, path, append, forget) {
|
|
|
8548
8823
|
}
|
|
8549
8824
|
};
|
|
8550
8825
|
}
|
|
8551
|
-
function index(n, what) {
|
|
8552
|
-
if (!Number.isSafeInteger(n) || n < 0) throw new JsCallError("EINVAL", what);
|
|
8553
|
-
}
|
|
8554
8826
|
function pathOps(kernel, resolve, statOf, open) {
|
|
8555
8827
|
return {
|
|
8556
8828
|
stat: (path) => statOf("stat", path),
|
|
@@ -8571,20 +8843,22 @@ function pathOps(kernel, resolve, statOf, open) {
|
|
|
8571
8843
|
async writeFile(path, data) {
|
|
8572
8844
|
const file = await open(path, { write: true, create: true, truncate: true });
|
|
8573
8845
|
try {
|
|
8574
|
-
await file.write(0, typeof data === "string" ?
|
|
8846
|
+
await file.write(0, typeof data === "string" ? encoder3.encode(data) : data);
|
|
8575
8847
|
} finally {
|
|
8576
8848
|
await file.close();
|
|
8577
8849
|
}
|
|
8578
8850
|
}
|
|
8579
8851
|
};
|
|
8580
8852
|
}
|
|
8581
|
-
var JsExit,
|
|
8853
|
+
var JsExit, encoder3;
|
|
8582
8854
|
var init_js_context = __esm({
|
|
8583
8855
|
"src/process/js/js-context.ts"() {
|
|
8584
8856
|
"use strict";
|
|
8585
8857
|
init_signals();
|
|
8586
8858
|
init_sync_fs_wire();
|
|
8859
|
+
init_js_io();
|
|
8587
8860
|
init_js_kernel();
|
|
8861
|
+
init_js_sync();
|
|
8588
8862
|
JsExit = class extends Error {
|
|
8589
8863
|
status;
|
|
8590
8864
|
constructor(status2) {
|
|
@@ -8593,12 +8867,7 @@ var init_js_context = __esm({
|
|
|
8593
8867
|
this.status = status2;
|
|
8594
8868
|
}
|
|
8595
8869
|
};
|
|
8596
|
-
|
|
8597
|
-
MAX_IO = 1024 * 1024;
|
|
8598
|
-
O_WRONLY6 = 1;
|
|
8599
|
-
O_RDWR6 = 2;
|
|
8600
|
-
O_APPEND3 = 1024;
|
|
8601
|
-
encoder2 = new TextEncoder();
|
|
8870
|
+
encoder3 = new TextEncoder();
|
|
8602
8871
|
}
|
|
8603
8872
|
});
|
|
8604
8873
|
|
|
@@ -8726,7 +8995,8 @@ async function runJsProcess(init, port, deps = {}) {
|
|
|
8726
8995
|
pid: id.pid,
|
|
8727
8996
|
ppid: id.ppid,
|
|
8728
8997
|
cwd: init.cwd,
|
|
8729
|
-
exit: (status3) => exited(statusOf(status3))
|
|
8998
|
+
exit: (status3) => exited(statusOf(status3)),
|
|
8999
|
+
lane: laneOf(init.lane)
|
|
8730
9000
|
});
|
|
8731
9001
|
const say = (text) => ctx.write(2, `${init.argv0}: ${text}
|
|
8732
9002
|
`).catch(() => void 0);
|
|
@@ -8764,6 +9034,7 @@ var init_js_runtime = __esm({
|
|
|
8764
9034
|
init_async_sab();
|
|
8765
9035
|
init_js_context();
|
|
8766
9036
|
init_js_kernel();
|
|
9037
|
+
init_js_sync();
|
|
8767
9038
|
init_lockdown();
|
|
8768
9039
|
NOT_RUNNABLE = 126;
|
|
8769
9040
|
}
|