@waffle-os/runtime 0.0.155 → 0.0.157
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/browser/filesystem-backend.ts +11 -1
- package/browser/preview-protocol.ts +2 -0
- package/browser/preview.ts +128 -18
- package/browser/runtime-terminals.ts +65 -24
- package/browser/shared-fs.ts +141 -14
- package/browser/worker.ts +73 -6
- package/core/descriptors.ts +19 -2
- package/core/devices.ts +237 -2
- package/core/fd-reopen.ts +105 -20
- package/core/filesystem.ts +79 -0
- package/core/index.ts +4 -0
- package/core/open-file.ts +212 -18
- package/core/wasi.ts +449 -47
- package/dist/browser/filesystem-backend.js +4 -2
- package/dist/browser/preview.js +120 -17
- package/dist/browser/runtime-terminals.js +53 -10
- package/dist/browser/shared-fs.js +124 -11
- package/dist/browser/worker.js +59 -6
- package/dist/core/descriptors.js +9 -1
- package/dist/core/devices.js +211 -1
- package/dist/core/fd-reopen.js +79 -18
- package/dist/core/filesystem.js +14 -0
- package/dist/core/open-file.js +166 -13
- package/dist/core/wasi.js +402 -29
- package/dist/fs/backend.js +51 -3
- package/dist/fs/client.js +204 -7
- package/dist/fs/cold-read-cache.js +23 -0
- package/dist/fs/index.js +21 -1
- package/dist/fs/indexeddb.js +30 -2
- package/dist/fs/locks.js +1112 -0
- package/dist/fs/memory.js +126 -2
- package/dist/fs/multitab-backend.js +317 -196
- package/dist/fs/multitab-protocol.js +2 -0
- package/dist/fs/persistent.js +32 -7
- package/dist/fs/protocol.js +9 -3
- package/dist/fs/service.js +387 -22
- package/dist/fs/shared.js +54 -1
- package/dist/fs/storage-geometry.js +2 -0
- package/dist/interrupt/rewriter-internal.js +4 -1
- package/dist/proc/abi.js +80 -6
- package/dist/proc/errors.js +1 -0
- package/dist/proc/filesystem-codec.js +40 -9
- package/dist/proc/index.js +10 -1
- package/dist/proc/pty.js +193 -0
- package/dist/proc/worker-client.js +11 -2
- package/dist/proc/worker-pipes.js +51 -0
- package/dist/runtime.js +11 -2
- package/dist/search/engine.js +53 -0
- package/dist/tooling/program/program-transformer.json +1 -1
- package/fs/backend.ts +54 -2
- package/fs/client.ts +230 -6
- package/fs/cold-read-cache.ts +38 -0
- package/fs/index.ts +22 -1
- package/fs/indexeddb.ts +36 -2
- package/fs/locks.ts +1406 -0
- package/fs/memory.ts +132 -1
- package/fs/multitab-backend.ts +563 -304
- package/fs/multitab-protocol.ts +2 -0
- package/fs/persistent.ts +46 -4
- package/fs/protocol.ts +17 -5
- package/fs/service.ts +469 -23
- package/fs/shared.ts +60 -2
- package/fs/storage-geometry.ts +3 -0
- package/index.ts +2 -0
- package/interrupt/rewriter-internal.ts +4 -1
- package/package.json +2 -2
- package/proc/abi.ts +79 -6
- package/proc/errors.ts +1 -0
- package/proc/filesystem-codec.ts +39 -9
- package/proc/index.ts +11 -0
- package/proc/pty.ts +227 -0
- package/proc/worker-client.ts +28 -6
- package/proc/worker-pipes.ts +57 -0
- package/runtime.ts +12 -2
- package/search/engine.ts +49 -0
- package/testing/indexeddb-storage-browser.ts +173 -2
- package/tooling/program/program-transformer.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const INTERRUPT_REWRITER_REVISION =
|
|
1
|
+
export const INTERRUPT_REWRITER_REVISION = 9;
|
|
2
2
|
const encoder = new TextEncoder;
|
|
3
3
|
const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
4
4
|
const HEADER = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0]);
|
|
@@ -17,6 +17,9 @@ const runtimeProcSignatures = new Map([
|
|
|
17
17
|
["spawn_error", { params: [127, 127, 127], results: [127] }],
|
|
18
18
|
["job_of", { params: [127], results: [127] }],
|
|
19
19
|
["pipe", { params: [127], results: [127] }],
|
|
20
|
+
["pty_open", { params: [127, 127, 127], results: [127] }],
|
|
21
|
+
["pty_resize", { params: [127, 127, 127], results: [127] }],
|
|
22
|
+
["pty_size", { params: [127, 127], results: [127] }],
|
|
20
23
|
["dup", { params: [127], results: [127] }],
|
|
21
24
|
["fd_kind", { params: [127], results: [127] }],
|
|
22
25
|
["inherited_fd", { params: [127], results: [127] }],
|
package/dist/proc/abi.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
arrayAppend,
|
|
5
5
|
atomicsAdd,
|
|
6
6
|
atomicsNotify,
|
|
7
|
+
isInstance,
|
|
7
8
|
isSharedArrayBuffer,
|
|
8
9
|
DataViewConstructor,
|
|
9
10
|
Uint8ArrayConstructor,
|
|
@@ -34,6 +35,7 @@ import {
|
|
|
34
35
|
withFileOffset
|
|
35
36
|
} from "../core/open-file.js";
|
|
36
37
|
import { PipeController } from "./pipes.js";
|
|
38
|
+
import { PtyEndpoint, allocatePtyGeometry, validatePtyDimensions } from "./pty.js";
|
|
37
39
|
import { readOutcome } from "./outcome.js";
|
|
38
40
|
import { WasiExit } from "../core/wasi.js";
|
|
39
41
|
import { waitStatus } from "./wait-status.js";
|
|
@@ -69,7 +71,8 @@ export class ProcessSignalExit extends ExecutionUnwind {
|
|
|
69
71
|
this.status = 128 + signal;
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
|
-
const READ = 1n << 1n, WRITE = 1n << 6n, FILESTAT_GET = 1n << 21n, POLL = 1n << 27n;
|
|
74
|
+
const READ = 1n << 1n, FDSTAT_SET_FLAGS = 1n << 3n, WRITE = 1n << 6n, FILESTAT_GET = 1n << 21n, POLL = 1n << 27n;
|
|
75
|
+
const PTY_RIGHTS = READ | WRITE | FILESTAT_GET | POLL | FDSTAT_SET_FLAGS;
|
|
73
76
|
const FAULT = 21, ISDIR = 31, NOSYS = 52, NOTCAPABLE = 76;
|
|
74
77
|
const decode = new TextDecoder("utf-8", { fatal: true });
|
|
75
78
|
const pathDecode = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
@@ -136,6 +139,9 @@ export class ProcessABI {
|
|
|
136
139
|
exec: (ptr, length) => this.result(() => this.exec(ptr, length)),
|
|
137
140
|
job_of: (pid) => this.result(() => options.service.jobOf(pid === 0 ? options.pid : pid)),
|
|
138
141
|
pipe: (ptr) => this.result(() => this.pipe(ptr)),
|
|
142
|
+
pty_open: (cols, rows, ptr) => this.result(() => this.ptyOpen(cols, rows, ptr)),
|
|
143
|
+
pty_resize: (fd, cols, rows) => this.result(() => this.ptyResize(fd, cols, rows)),
|
|
144
|
+
pty_size: (fd, ptr) => this.result(() => this.ptySize(fd, ptr)),
|
|
139
145
|
dup: (fd) => options.descriptors.dup(fd >>> 0),
|
|
140
146
|
fd_kind: (fd) => options.descriptors.kind(fd >>> 0),
|
|
141
147
|
fd_reopen: (fd, oflags, fdflags, base, out) => {
|
|
@@ -341,7 +347,7 @@ export class ProcessABI {
|
|
|
341
347
|
}
|
|
342
348
|
pipe(ptr) {
|
|
343
349
|
this.span(ptr, 8);
|
|
344
|
-
const endpoints = this.options.createPipe?.() ?? this.
|
|
350
|
+
const endpoints = this.options.createPipe?.() ?? this.localPipeEndpoints();
|
|
345
351
|
let read, write;
|
|
346
352
|
try {
|
|
347
353
|
read = this.options.descriptors.open(endpoints[0], READ | FILESTAT_GET | POLL, 0n);
|
|
@@ -362,7 +368,76 @@ export class ProcessABI {
|
|
|
362
368
|
throw error;
|
|
363
369
|
}
|
|
364
370
|
}
|
|
365
|
-
|
|
371
|
+
ptyOpen(cols, rows, ptr) {
|
|
372
|
+
validatePtyDimensions(cols, rows);
|
|
373
|
+
this.span(ptr, 8);
|
|
374
|
+
const endpoints = this.options.createPty?.(cols, rows) ?? this.localPty(cols, rows);
|
|
375
|
+
let master, slave;
|
|
376
|
+
try {
|
|
377
|
+
master = this.options.descriptors.open(endpoints[0], PTY_RIGHTS, 0n);
|
|
378
|
+
slave = this.options.descriptors.open(endpoints[1], PTY_RIGHTS, 0n);
|
|
379
|
+
const output = this.view(ptr, 8);
|
|
380
|
+
dataViewSetUint32(output, 0, master, true);
|
|
381
|
+
dataViewSetUint32(output, 4, slave, true);
|
|
382
|
+
return 0;
|
|
383
|
+
} catch (error) {
|
|
384
|
+
if (master !== undefined)
|
|
385
|
+
this.options.descriptors.close(master);
|
|
386
|
+
else
|
|
387
|
+
endpoints[0].close?.();
|
|
388
|
+
if (slave !== undefined)
|
|
389
|
+
this.options.descriptors.close(slave);
|
|
390
|
+
else
|
|
391
|
+
endpoints[1].close?.();
|
|
392
|
+
throw error;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
ptyEndpoint(fd) {
|
|
396
|
+
const entry = this.options.descriptors.get(fd >>> 0);
|
|
397
|
+
if (!entry)
|
|
398
|
+
throw new ProcessError(ProcessErrno.BADF, `missing descriptor ${fd}`);
|
|
399
|
+
if (!isInstance(entry.resource, PtyEndpoint))
|
|
400
|
+
throw new ProcessError(ProcessErrno.NOTTY, `descriptor ${fd} is not a pty`);
|
|
401
|
+
return entry.resource;
|
|
402
|
+
}
|
|
403
|
+
ptyResize(fd, cols, rows) {
|
|
404
|
+
validatePtyDimensions(cols, rows);
|
|
405
|
+
this.ptyEndpoint(fd).resize(cols, rows);
|
|
406
|
+
return 0;
|
|
407
|
+
}
|
|
408
|
+
ptySize(fd, ptr) {
|
|
409
|
+
this.span(ptr, 12);
|
|
410
|
+
const size = this.ptyEndpoint(fd).size();
|
|
411
|
+
const output = this.view(ptr, 12);
|
|
412
|
+
dataViewSetUint32(output, 0, size.cols, true);
|
|
413
|
+
dataViewSetUint32(output, 4, size.rows, true);
|
|
414
|
+
dataViewSetUint32(output, 8, size.seq, true);
|
|
415
|
+
return 0;
|
|
416
|
+
}
|
|
417
|
+
localPty(cols, rows) {
|
|
418
|
+
const geometry = allocatePtyGeometry(cols, rows);
|
|
419
|
+
const input = this.localPipeEndpoints();
|
|
420
|
+
const slaveIn = input[0];
|
|
421
|
+
const masterOut = input[1];
|
|
422
|
+
let masterIn;
|
|
423
|
+
let slaveOut;
|
|
424
|
+
try {
|
|
425
|
+
const output = this.localPipeEndpoints();
|
|
426
|
+
masterIn = output[0];
|
|
427
|
+
slaveOut = output[1];
|
|
428
|
+
return [
|
|
429
|
+
new PtyEndpoint("master", masterIn, masterOut, geometry),
|
|
430
|
+
new PtyEndpoint("slave", slaveIn, slaveOut, geometry)
|
|
431
|
+
];
|
|
432
|
+
} catch (error) {
|
|
433
|
+
slaveIn.close();
|
|
434
|
+
masterOut.close();
|
|
435
|
+
masterIn?.close();
|
|
436
|
+
slaveOut?.close();
|
|
437
|
+
throw error;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
localPipeEndpoints() {
|
|
366
441
|
const controller = new PipeController({
|
|
367
442
|
capacity: this.options.pipeCapacity,
|
|
368
443
|
wake: this.options.wake
|
|
@@ -372,7 +447,7 @@ export class ProcessABI {
|
|
|
372
447
|
try {
|
|
373
448
|
write = controller.retain(this.options.pid, "write");
|
|
374
449
|
} catch (error) {
|
|
375
|
-
read.close
|
|
450
|
+
read.close();
|
|
376
451
|
throw error;
|
|
377
452
|
}
|
|
378
453
|
const unregister = this.options.service.registerRevocation?.(this.options.pid, () => controller.revoke(this.options.pid));
|
|
@@ -388,8 +463,7 @@ export class ProcessABI {
|
|
|
388
463
|
return;
|
|
389
464
|
closed = true;
|
|
390
465
|
try {
|
|
391
|
-
|
|
392
|
-
reflectApply(close, endpoint, []);
|
|
466
|
+
reflectApply(close, endpoint, []);
|
|
393
467
|
} finally {
|
|
394
468
|
if (--remaining === 0)
|
|
395
469
|
unregister();
|
package/dist/proc/errors.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { isInstance, isSharedArrayBuffer } from "./intrinsics.js";
|
|
2
2
|
import { OpenDescription } from "../core/descriptors.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
readSharedOfdBuffer,
|
|
5
|
+
retainSharedOfdTransfer,
|
|
6
|
+
shareDirectoryOfd,
|
|
7
|
+
shareFileResource
|
|
8
|
+
} from "../core/open-file.js";
|
|
4
9
|
import { FilesystemClient } from "../fs/client.js";
|
|
5
10
|
import {
|
|
6
11
|
releaseFilesystemReservation
|
|
@@ -8,18 +13,33 @@ import {
|
|
|
8
13
|
export function isFilesystemDescriptorToken(token) {
|
|
9
14
|
return typeof token === "object" && token !== null && "kind" in token && token.kind === "filesystem";
|
|
10
15
|
}
|
|
16
|
+
function tokenOfdBuffer(token) {
|
|
17
|
+
const candidate = token.resource === "file" ? token.offset : token.ofd;
|
|
18
|
+
return isSharedArrayBuffer(candidate) ? candidate : undefined;
|
|
19
|
+
}
|
|
20
|
+
function releaseTokenOfd(client, token) {
|
|
21
|
+
const buffer = tokenOfdBuffer(token);
|
|
22
|
+
if (!buffer)
|
|
23
|
+
return;
|
|
24
|
+
const ofd = readSharedOfdBuffer(buffer);
|
|
25
|
+
if (!ofd?.locked)
|
|
26
|
+
return;
|
|
27
|
+
client.locks.releaseOfd(token.reservation.handle, ofd.id, ofd.pendingTransfers > 0);
|
|
28
|
+
}
|
|
11
29
|
export function createFilesystemDescriptorCodec(filesystem, target, sweep) {
|
|
12
30
|
const client = isInstance(filesystem, FilesystemClient) ? filesystem : undefined;
|
|
13
31
|
const identity = client?.connection ?? filesystem;
|
|
14
32
|
const discard = (token) => {
|
|
15
33
|
if (!isFilesystemDescriptorToken(token))
|
|
16
34
|
throw new TypeError("not a filesystem descriptor token");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
35
|
+
const won = releaseFilesystemReservation(token.reservation);
|
|
36
|
+
const localOwner = client && token.reservation.targetOwner === client.connection.owner;
|
|
37
|
+
if (won && localOwner)
|
|
38
|
+
releaseTokenOfd(client, token);
|
|
39
|
+
if (localOwner)
|
|
40
|
+
client.finishReleasedReservation(token.reservation, won);
|
|
41
|
+
else if (won)
|
|
21
42
|
(sweep ?? (() => client?.sweep()))();
|
|
22
|
-
}
|
|
23
43
|
};
|
|
24
44
|
return {
|
|
25
45
|
export(descriptor) {
|
|
@@ -29,11 +49,19 @@ export function createFilesystemDescriptorCodec(filesystem, target, sweep) {
|
|
|
29
49
|
if (!client || !target)
|
|
30
50
|
throw new TypeError("filesystem export requires a client and child identity");
|
|
31
51
|
const offset = resource.kind === "file" ? shareFileResource(resource, client.connection) : undefined;
|
|
52
|
+
const dirOfd = resource.kind === "directory" ? shareDirectoryOfd(resource, client.connection) : undefined;
|
|
53
|
+
const reservation = client.reserve(resource.handle, target);
|
|
54
|
+
const ofd = offset ?? dirOfd;
|
|
55
|
+
if (ofd) {
|
|
56
|
+
reservation.ofd = ofd;
|
|
57
|
+
retainSharedOfdTransfer(ofd);
|
|
58
|
+
}
|
|
32
59
|
return {
|
|
33
60
|
kind: "filesystem",
|
|
34
61
|
resource: resource.kind,
|
|
35
|
-
reservation
|
|
36
|
-
offset
|
|
62
|
+
reservation,
|
|
63
|
+
offset,
|
|
64
|
+
...dirOfd ? { ofd: dirOfd } : {}
|
|
37
65
|
};
|
|
38
66
|
},
|
|
39
67
|
import(token) {
|
|
@@ -50,8 +78,11 @@ export function createFilesystemDescriptorCodec(filesystem, target, sweep) {
|
|
|
50
78
|
throw new TypeError("file offset is missing");
|
|
51
79
|
resource = { kind: "file", handle, offset: 0, append: false };
|
|
52
80
|
shareFileResource(resource, identity, token.offset);
|
|
53
|
-
} else
|
|
81
|
+
} else {
|
|
54
82
|
resource = { kind: "directory", handle };
|
|
83
|
+
if (isSharedArrayBuffer(token.ofd))
|
|
84
|
+
shareDirectoryOfd(resource, identity, token.ofd);
|
|
85
|
+
}
|
|
55
86
|
client?.adopt(token.reservation);
|
|
56
87
|
return new OpenDescription(resource, () => discard(token));
|
|
57
88
|
},
|
package/dist/proc/index.js
CHANGED
|
@@ -54,6 +54,15 @@ export {
|
|
|
54
54
|
WorkerPipeHost,
|
|
55
55
|
WorkerPipeBroker,
|
|
56
56
|
createWorkerPipeCodec,
|
|
57
|
-
isWorkerPipeDescriptorToken
|
|
57
|
+
isWorkerPipeDescriptorToken,
|
|
58
|
+
isWorkerPtyDescriptorToken
|
|
58
59
|
} from "./worker-pipes.js";
|
|
60
|
+
export {
|
|
61
|
+
PtyEndpoint,
|
|
62
|
+
PTY_GEOMETRY_BYTES,
|
|
63
|
+
MAX_PTY_DIMENSION,
|
|
64
|
+
isValidPtyDimension,
|
|
65
|
+
allocatePtyGeometry,
|
|
66
|
+
attachPtyEndpoint
|
|
67
|
+
} from "./pty.js";
|
|
59
68
|
export { ProcessABI, ProcessSignalExit } from "./abi.js";
|
package/dist/proc/pty.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { allocateSharedControl } from "../memory/control.js";
|
|
2
|
+
import { ProcessErrno, ProcessError } from "./errors.js";
|
|
3
|
+
import {
|
|
4
|
+
BigInt64ArrayConstructor,
|
|
5
|
+
Int32ArrayConstructor,
|
|
6
|
+
atomicsAdd,
|
|
7
|
+
atomicsCompareExchange,
|
|
8
|
+
atomicsLoad,
|
|
9
|
+
atomicsNotify,
|
|
10
|
+
atomicsStore,
|
|
11
|
+
isSharedArrayBuffer,
|
|
12
|
+
typedArrayLength
|
|
13
|
+
} from "./intrinsics.js";
|
|
14
|
+
const bigintConstructor = BigInt;
|
|
15
|
+
const bigIntAsIntN = BigInt.asIntN;
|
|
16
|
+
const numberConstructor = Number;
|
|
17
|
+
import {
|
|
18
|
+
PipeEndpoint,
|
|
19
|
+
attachPipeEndpoint
|
|
20
|
+
} from "./pipes.js";
|
|
21
|
+
export const PTY_GEOMETRY_BYTES = 16;
|
|
22
|
+
export const MAX_PTY_DIMENSION = 65535;
|
|
23
|
+
export function isValidPtyDimension(value) {
|
|
24
|
+
return Number.isInteger(value) && value >= 1 && value <= MAX_PTY_DIMENSION;
|
|
25
|
+
}
|
|
26
|
+
export function validatePtyDimensions(cols, rows) {
|
|
27
|
+
if (!isValidPtyDimension(cols) || !isValidPtyDimension(rows))
|
|
28
|
+
throw new ProcessError(ProcessErrno.INVAL, "invalid pty dimensions");
|
|
29
|
+
}
|
|
30
|
+
function isValidPtyGeometryBuffer(buffer) {
|
|
31
|
+
if (!isSharedArrayBuffer(buffer))
|
|
32
|
+
return false;
|
|
33
|
+
return typedArrayLength(new Int32ArrayConstructor(buffer)) >= 4;
|
|
34
|
+
}
|
|
35
|
+
function packPtySize(cols, rows) {
|
|
36
|
+
return ((rows & 65535) << 16 | cols & 65535) >>> 0;
|
|
37
|
+
}
|
|
38
|
+
function packGeometryWord(cols, rows, seq) {
|
|
39
|
+
return bigIntAsIntN(64, bigintConstructor(seq >>> 0) << 32n | bigintConstructor(packPtySize(cols, rows)));
|
|
40
|
+
}
|
|
41
|
+
export function allocatePtyGeometry(cols, rows, allocateShared) {
|
|
42
|
+
validatePtyDimensions(cols, rows);
|
|
43
|
+
const buffer = allocateShared ? allocateShared(PTY_GEOMETRY_BYTES) : allocateSharedControl(PTY_GEOMETRY_BYTES);
|
|
44
|
+
const words = new BigInt64ArrayConstructor(buffer, 0, 2);
|
|
45
|
+
atomicsStore(words, 0, packGeometryWord(cols, rows, 0));
|
|
46
|
+
atomicsStore(words, 1, 0n);
|
|
47
|
+
return buffer;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class PtyEndpoint {
|
|
51
|
+
role;
|
|
52
|
+
readEnd;
|
|
53
|
+
writeEnd;
|
|
54
|
+
geometryBuffer;
|
|
55
|
+
kind;
|
|
56
|
+
notification;
|
|
57
|
+
geometry;
|
|
58
|
+
closed = false;
|
|
59
|
+
constructor(role, readEnd, writeEnd, geometryBuffer) {
|
|
60
|
+
this.role = role;
|
|
61
|
+
this.readEnd = readEnd;
|
|
62
|
+
this.writeEnd = writeEnd;
|
|
63
|
+
this.geometryBuffer = geometryBuffer;
|
|
64
|
+
if (!isValidPtyGeometryBuffer(geometryBuffer))
|
|
65
|
+
throw new TypeError("invalid pty geometry buffer");
|
|
66
|
+
this.kind = role === "slave" ? "terminal" : "pipe";
|
|
67
|
+
this.notification = readEnd.notification;
|
|
68
|
+
this.geometry = new BigInt64ArrayConstructor(geometryBuffer, 0, 2);
|
|
69
|
+
}
|
|
70
|
+
get pid() {
|
|
71
|
+
return this.readEnd.pid;
|
|
72
|
+
}
|
|
73
|
+
get live() {
|
|
74
|
+
return !this.closed && this.readEnd.live && this.writeEnd.live;
|
|
75
|
+
}
|
|
76
|
+
get fdflags() {
|
|
77
|
+
return this.readEnd.fdflags;
|
|
78
|
+
}
|
|
79
|
+
set fdflags(value) {
|
|
80
|
+
this.readEnd.fdflags = value;
|
|
81
|
+
this.writeEnd.fdflags = value;
|
|
82
|
+
}
|
|
83
|
+
read(chunks) {
|
|
84
|
+
return this.readEnd.read(chunks);
|
|
85
|
+
}
|
|
86
|
+
tryRead(chunks) {
|
|
87
|
+
return this.readEnd.tryRead(chunks);
|
|
88
|
+
}
|
|
89
|
+
write(chunks) {
|
|
90
|
+
return this.writeEnd.write(chunks);
|
|
91
|
+
}
|
|
92
|
+
tryWrite(chunks) {
|
|
93
|
+
return this.writeEnd.tryWrite(chunks);
|
|
94
|
+
}
|
|
95
|
+
readiness() {
|
|
96
|
+
const readState = this.readEnd.readiness();
|
|
97
|
+
const writeState = this.writeEnd.readiness();
|
|
98
|
+
return {
|
|
99
|
+
readable: readState.readable,
|
|
100
|
+
writable: writeState.writable,
|
|
101
|
+
hangup: readState.hangup || writeState.hangup,
|
|
102
|
+
nbytes: readState.nbytes
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
size() {
|
|
106
|
+
const word = atomicsLoad(this.geometry, 0);
|
|
107
|
+
const packed = numberConstructor(word & 0xffffffffn);
|
|
108
|
+
const seq = numberConstructor(word >> 32n & 0xffffffffn);
|
|
109
|
+
return {
|
|
110
|
+
cols: packed & 65535,
|
|
111
|
+
rows: packed >>> 16 & 65535,
|
|
112
|
+
seq
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
resize(cols, rows) {
|
|
116
|
+
validatePtyDimensions(cols, rows);
|
|
117
|
+
const dims = bigintConstructor(packPtySize(cols, rows));
|
|
118
|
+
for (;; ) {
|
|
119
|
+
const prev = atomicsLoad(this.geometry, 0);
|
|
120
|
+
const nextSeq = (prev >> 32n & 0xffffffffn) + 1n & 0xffffffffn;
|
|
121
|
+
const next = bigIntAsIntN(64, nextSeq << 32n | dims);
|
|
122
|
+
if (atomicsCompareExchange(this.geometry, 0, prev, next) === prev)
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
atomicsAdd(this.notification, 0, 1);
|
|
126
|
+
atomicsNotify(this.notification, 0);
|
|
127
|
+
}
|
|
128
|
+
handle() {
|
|
129
|
+
return {
|
|
130
|
+
role: this.role,
|
|
131
|
+
read: this.readEnd.handle(),
|
|
132
|
+
write: this.writeEnd.handle(),
|
|
133
|
+
geometry: this.geometryBuffer
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
forProcess(pid) {
|
|
137
|
+
if (!this.live)
|
|
138
|
+
throw new Error("pty endpoint is closed");
|
|
139
|
+
if (pid === this.pid)
|
|
140
|
+
return this;
|
|
141
|
+
const nextRead = this.readEnd.forProcess(pid);
|
|
142
|
+
try {
|
|
143
|
+
const nextWrite = this.writeEnd.forProcess(pid);
|
|
144
|
+
return new PtyEndpoint(this.role, nextRead, nextWrite, this.geometryBuffer);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
nextRead.close();
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
retainSuccessor() {
|
|
151
|
+
if (!this.live)
|
|
152
|
+
throw new Error("pty endpoint is closed");
|
|
153
|
+
const nextRead = this.readEnd.retainSuccessor();
|
|
154
|
+
try {
|
|
155
|
+
const nextWrite = this.writeEnd.retainSuccessor();
|
|
156
|
+
return new PtyEndpoint(this.role, nextRead, nextWrite, this.geometryBuffer);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
nextRead.close();
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
revoke() {
|
|
163
|
+
try {
|
|
164
|
+
this.readEnd.revoke();
|
|
165
|
+
} finally {
|
|
166
|
+
this.writeEnd.revoke();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
close() {
|
|
170
|
+
if (this.closed)
|
|
171
|
+
return;
|
|
172
|
+
this.closed = true;
|
|
173
|
+
try {
|
|
174
|
+
this.readEnd.close();
|
|
175
|
+
} finally {
|
|
176
|
+
this.writeEnd.close();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
export function attachPtyEndpoint(handle, options) {
|
|
181
|
+
if (handle.role !== "master" && handle.role !== "slave")
|
|
182
|
+
throw new TypeError("invalid pty endpoint role");
|
|
183
|
+
if (!isValidPtyGeometryBuffer(handle.geometry))
|
|
184
|
+
throw new TypeError("invalid pty geometry buffer");
|
|
185
|
+
const readEnd = attachPipeEndpoint(handle.read, options);
|
|
186
|
+
try {
|
|
187
|
+
const writeEnd = attachPipeEndpoint(handle.write, options);
|
|
188
|
+
return new PtyEndpoint(handle.role, readEnd, writeEnd, handle.geometry);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
readEnd.close();
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -223,8 +223,12 @@ export class WorkerProcessClient {
|
|
|
223
223
|
};
|
|
224
224
|
const handoff = commandExecTransfer(staged);
|
|
225
225
|
let published = false;
|
|
226
|
+
const keptFds = [];
|
|
227
|
+
for (let index = 0;index < snapshot.fds.length; index++) {
|
|
228
|
+
arrayAppend(keptFds, snapshot.fds[index].parent);
|
|
229
|
+
}
|
|
226
230
|
try {
|
|
227
|
-
transfer = this.options.prepareExec(pid, (error) => recordCommandTransferFailure(this.options.transport, "exec", staged.generation, error));
|
|
231
|
+
transfer = this.options.prepareExec(pid, (error) => recordCommandTransferFailure(this.options.transport, "exec", staged.generation, error), keptFds);
|
|
228
232
|
codec = transfer.codec ?? codec;
|
|
229
233
|
staged.data = transfer.data;
|
|
230
234
|
this.exportBindings(staged, snapshot, sources, references, codec);
|
|
@@ -442,7 +446,7 @@ export class WorkerProcessClient {
|
|
|
442
446
|
let codec = this.options.codec;
|
|
443
447
|
let publishing = false;
|
|
444
448
|
try {
|
|
445
|
-
transfer = this.options.prepareSpawn?.(pid, (error) => recordCommandTransferFailure(this.options.transport, "spawn", pid, error));
|
|
449
|
+
transfer = this.options.prepareSpawn?.(pid, (error) => recordCommandTransferFailure(this.options.transport, "spawn", pid, error), processKind);
|
|
446
450
|
codec = transfer?.codec ?? codec;
|
|
447
451
|
child = reserveRecord(this.options.transport, pid, this.pid, job, existingJob?.ownerPid ?? this.pid, existingJob?.slot, selector === 0, jobLifetime, cwd, processKind);
|
|
448
452
|
child.data = transfer?.data;
|
|
@@ -818,6 +822,11 @@ export class WorkerProcessClient {
|
|
|
818
822
|
throw new ProcessError(58, "worker pipe factory is unavailable");
|
|
819
823
|
return this.options.createPipe();
|
|
820
824
|
}
|
|
825
|
+
createPty(cols, rows) {
|
|
826
|
+
if (!this.options.createPty)
|
|
827
|
+
throw new ProcessError(58, "worker pty factory is unavailable");
|
|
828
|
+
return this.options.createPty(cols, rows);
|
|
829
|
+
}
|
|
821
830
|
report(error) {
|
|
822
831
|
try {
|
|
823
832
|
this.options.onError?.(error);
|
|
@@ -8,15 +8,27 @@ import {
|
|
|
8
8
|
attachPipeEndpoint,
|
|
9
9
|
attachPipePublicationRegistry
|
|
10
10
|
} from "./pipes.js";
|
|
11
|
+
import {
|
|
12
|
+
PtyEndpoint,
|
|
13
|
+
allocatePtyGeometry,
|
|
14
|
+
attachPtyEndpoint
|
|
15
|
+
} from "./pty.js";
|
|
11
16
|
import {
|
|
12
17
|
workerProcessState
|
|
13
18
|
} from "./worker-client.js";
|
|
14
19
|
export function isWorkerPipeDescriptorToken(token) {
|
|
15
20
|
return typeof token === "object" && token !== null && "kind" in token && token.kind === "pipe";
|
|
16
21
|
}
|
|
22
|
+
export function isWorkerPtyDescriptorToken(token) {
|
|
23
|
+
return typeof token === "object" && token !== null && "kind" in token && token.kind === "pty";
|
|
24
|
+
}
|
|
17
25
|
export function createWorkerPipeCodec(options = {}) {
|
|
18
26
|
return {
|
|
19
27
|
export(descriptor, pid) {
|
|
28
|
+
if (isInstance(descriptor.resource, PtyEndpoint)) {
|
|
29
|
+
const endpoint = options.successor ? descriptor.resource.retainSuccessor() : descriptor.resource.forProcess(pid);
|
|
30
|
+
return { kind: "pty", ...endpoint.handle() };
|
|
31
|
+
}
|
|
20
32
|
if (!isInstance(descriptor.resource, PipeEndpoint)) {
|
|
21
33
|
if (options.fallback)
|
|
22
34
|
return options.fallback.export(descriptor, pid);
|
|
@@ -26,6 +38,14 @@ export function createWorkerPipeCodec(options = {}) {
|
|
|
26
38
|
return { kind: "pipe", endpoint: endpoint.handle() };
|
|
27
39
|
},
|
|
28
40
|
import(token, pid) {
|
|
41
|
+
if (isWorkerPtyDescriptorToken(token)) {
|
|
42
|
+
if (token.read.pid !== pid || token.write.pid !== pid)
|
|
43
|
+
throw new TypeError("pty descriptor belongs to another process");
|
|
44
|
+
options.onPipe?.(token.read);
|
|
45
|
+
options.onPipe?.(token.write);
|
|
46
|
+
const endpoint = attachPtyEndpoint(token, options);
|
|
47
|
+
return new OpenDescription(endpoint, () => endpoint.close());
|
|
48
|
+
}
|
|
29
49
|
if (!isWorkerPipeDescriptorToken(token)) {
|
|
30
50
|
if (options.fallback)
|
|
31
51
|
return options.fallback.import(token, pid);
|
|
@@ -38,6 +58,14 @@ export function createWorkerPipeCodec(options = {}) {
|
|
|
38
58
|
return new OpenDescription(endpoint, () => endpoint.close());
|
|
39
59
|
},
|
|
40
60
|
discard(token) {
|
|
61
|
+
if (isWorkerPtyDescriptorToken(token)) {
|
|
62
|
+
try {
|
|
63
|
+
attachPipeEndpoint(token.read, options).close();
|
|
64
|
+
} finally {
|
|
65
|
+
attachPipeEndpoint(token.write, options).close();
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
41
69
|
if (isWorkerPipeDescriptorToken(token))
|
|
42
70
|
attachPipeEndpoint(token.endpoint, options).close();
|
|
43
71
|
else if (options.fallback)
|
|
@@ -96,6 +124,29 @@ export class WorkerPipeHost {
|
|
|
96
124
|
throw error;
|
|
97
125
|
}
|
|
98
126
|
}
|
|
127
|
+
createPty(cols, rows) {
|
|
128
|
+
const geometry = allocatePtyGeometry(cols, rows, this.options.allocateShared);
|
|
129
|
+
const input = this.createPipe();
|
|
130
|
+
const slaveIn = input[0];
|
|
131
|
+
const masterOut = input[1];
|
|
132
|
+
let masterIn;
|
|
133
|
+
let slaveOut;
|
|
134
|
+
try {
|
|
135
|
+
const output = this.createPipe();
|
|
136
|
+
masterIn = output[0];
|
|
137
|
+
slaveOut = output[1];
|
|
138
|
+
return [
|
|
139
|
+
new PtyEndpoint("master", masterIn, masterOut, geometry),
|
|
140
|
+
new PtyEndpoint("slave", slaveIn, slaveOut, geometry)
|
|
141
|
+
];
|
|
142
|
+
} catch (error) {
|
|
143
|
+
slaveIn.close();
|
|
144
|
+
masterOut.close();
|
|
145
|
+
masterIn?.close();
|
|
146
|
+
slaveOut?.close();
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
99
150
|
revokeProcess(pid) {
|
|
100
151
|
this.registry.revoke(pid);
|
|
101
152
|
}
|
package/dist/runtime.js
CHANGED
|
@@ -31,6 +31,7 @@ const filesystemCapabilities = {
|
|
|
31
31
|
drain: "async",
|
|
32
32
|
flush: "async",
|
|
33
33
|
resolvePath: "async",
|
|
34
|
+
stat: "async",
|
|
34
35
|
lookup: "async",
|
|
35
36
|
readFile: "async",
|
|
36
37
|
listFiles: "async",
|
|
@@ -40,6 +41,7 @@ const filesystemCapabilities = {
|
|
|
40
41
|
move: "async",
|
|
41
42
|
workspace: "readonly",
|
|
42
43
|
state: "readonly",
|
|
44
|
+
machineId: "readonly",
|
|
43
45
|
vfs: "readonly",
|
|
44
46
|
ownershipLost: "readonly",
|
|
45
47
|
onOwnershipLost: "callback",
|
|
@@ -649,9 +651,16 @@ export function createRuntime(options = {}) {
|
|
|
649
651
|
}
|
|
650
652
|
while (launching.size)
|
|
651
653
|
await Promise.allSettled(Array.from(launching));
|
|
652
|
-
if (!pendingStartup) {
|
|
654
|
+
if (!pendingStartup && !filesystem.ownershipLost) {
|
|
653
655
|
filesystem.beginRuntimeDispose();
|
|
654
|
-
await attempt(() =>
|
|
656
|
+
await attempt(async () => {
|
|
657
|
+
try {
|
|
658
|
+
await filesystem.drain();
|
|
659
|
+
} catch (error) {
|
|
660
|
+
if (!filesystem.ownershipLost)
|
|
661
|
+
throw error;
|
|
662
|
+
}
|
|
663
|
+
});
|
|
655
664
|
}
|
|
656
665
|
const failuresBeforeFences = failures.length;
|
|
657
666
|
await Promise.all([
|
package/dist/search/engine.js
CHANGED
|
@@ -19,6 +19,44 @@ function displayPath(root, relative, tool) {
|
|
|
19
19
|
const prefix = tool === "grep" ? root.replace(/\/+$/, "/") : root;
|
|
20
20
|
return prefix.endsWith("/") ? `${prefix}${relative}` : `${prefix}/${relative}`;
|
|
21
21
|
}
|
|
22
|
+
function matchStarGlob(glob, text) {
|
|
23
|
+
let g = 0;
|
|
24
|
+
let t = 0;
|
|
25
|
+
let star = -1;
|
|
26
|
+
let match = 0;
|
|
27
|
+
while (t < text.length) {
|
|
28
|
+
if (g < glob.length && glob[g] === "*") {
|
|
29
|
+
star = g++;
|
|
30
|
+
match = t;
|
|
31
|
+
} else if (g < glob.length && glob[g] === text[t]) {
|
|
32
|
+
g++;
|
|
33
|
+
t++;
|
|
34
|
+
} else if (star !== -1) {
|
|
35
|
+
g = star + 1;
|
|
36
|
+
t = ++match;
|
|
37
|
+
} else {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
while (g < glob.length && glob[g] === "*")
|
|
42
|
+
g++;
|
|
43
|
+
return g === glob.length;
|
|
44
|
+
}
|
|
45
|
+
function matchPathSuffix(glob, path) {
|
|
46
|
+
let offset = 0;
|
|
47
|
+
for (;; ) {
|
|
48
|
+
if (matchStarGlob(glob, path.slice(offset)))
|
|
49
|
+
return true;
|
|
50
|
+
let slash = path.indexOf("/", offset);
|
|
51
|
+
if (slash === -1)
|
|
52
|
+
return false;
|
|
53
|
+
while (slash < path.length && path[slash] === "/")
|
|
54
|
+
slash++;
|
|
55
|
+
if (slash >= path.length)
|
|
56
|
+
return false;
|
|
57
|
+
offset = slash;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
22
60
|
|
|
23
61
|
export class WalkSource {
|
|
24
62
|
context;
|
|
@@ -84,6 +122,10 @@ export class WalkSource {
|
|
|
84
122
|
return;
|
|
85
123
|
}
|
|
86
124
|
if (opened.kind === "file") {
|
|
125
|
+
if (!this.matchesExplicitFile(path)) {
|
|
126
|
+
this.context.fs.release(opened.handle);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
87
129
|
this.add(entries, { kind: "file", path, handle: opened.handle, size: opened.size }, { kind: "open", handle: opened.handle });
|
|
88
130
|
return;
|
|
89
131
|
}
|
|
@@ -93,6 +135,17 @@ export class WalkSource {
|
|
|
93
135
|
this.add(entries, { kind: "error", path, errno: errnoOf(error) });
|
|
94
136
|
}
|
|
95
137
|
}
|
|
138
|
+
matchesExplicitFile(path) {
|
|
139
|
+
if (this.context.request.plan.tool !== "grep")
|
|
140
|
+
return true;
|
|
141
|
+
const { include, exclude } = this.context.request.plan.walk;
|
|
142
|
+
if (include.length === 0 && exclude.length === 0)
|
|
143
|
+
return true;
|
|
144
|
+
const matches = (pattern) => matchPathSuffix(pattern.glob, path);
|
|
145
|
+
if (include.length > 0 && !include.some(matches))
|
|
146
|
+
return false;
|
|
147
|
+
return !exclude.some(matches);
|
|
148
|
+
}
|
|
96
149
|
openWalk(path, handle) {
|
|
97
150
|
try {
|
|
98
151
|
const original = this.context.fs.walkOpen(handle, this.context.request.plan.walk);
|