@waffle-os/runtime 0.0.156 → 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 +71 -0
- package/core/index.ts +4 -0
- package/core/open-file.ts +212 -18
- package/core/wasi.ts +397 -46
- 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 +13 -0
- package/dist/core/open-file.js +166 -13
- package/dist/core/wasi.js +353 -27
- package/dist/fs/backend.js +29 -2
- package/dist/fs/client.js +199 -6
- 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 +109 -1
- package/dist/fs/multitab-backend.js +315 -195
- package/dist/fs/multitab-protocol.js +1 -0
- package/dist/fs/persistent.js +13 -6
- package/dist/fs/protocol.js +9 -3
- package/dist/fs/service.js +386 -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 +33 -1
- package/fs/client.ts +225 -6
- package/fs/index.ts +22 -1
- package/fs/indexeddb.ts +36 -2
- package/fs/locks.ts +1406 -0
- package/fs/memory.ts +114 -1
- package/fs/multitab-backend.ts +561 -303
- package/fs/multitab-protocol.ts +1 -0
- package/fs/persistent.ts +14 -3
- package/fs/protocol.ts +17 -5
- package/fs/service.ts +468 -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
package/dist/fs/client.js
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
isFileTime,
|
|
35
35
|
permissionsFor
|
|
36
36
|
} from "../core/filesystem.js";
|
|
37
|
+
import { ExecutionUnwind } from "../core/unwind.js";
|
|
37
38
|
import {
|
|
38
39
|
ArrayBufferConstructor,
|
|
39
40
|
Int32ArrayConstructor,
|
|
@@ -314,13 +315,43 @@ export class FilesystemCompletion {
|
|
|
314
315
|
wait() {
|
|
315
316
|
return this.#wait();
|
|
316
317
|
}
|
|
317
|
-
|
|
318
|
+
waitInterruptible(control) {
|
|
319
|
+
return this.#wait(undefined, control);
|
|
320
|
+
}
|
|
321
|
+
checkWaitControl(control) {
|
|
322
|
+
if (!control)
|
|
323
|
+
return;
|
|
324
|
+
try {
|
|
325
|
+
control.checkActive?.();
|
|
326
|
+
} catch (error) {
|
|
327
|
+
this.cancel();
|
|
328
|
+
throw error;
|
|
329
|
+
}
|
|
330
|
+
if (!control.interruptPending?.())
|
|
331
|
+
return;
|
|
332
|
+
this.cancel();
|
|
333
|
+
throw new FilesystemError(27);
|
|
334
|
+
}
|
|
335
|
+
parkWait(signal, observed, control) {
|
|
336
|
+
if (control?.wait) {
|
|
337
|
+
try {
|
|
338
|
+
control.wait(signal, observed, 10);
|
|
339
|
+
} catch (error) {
|
|
340
|
+
this.cancel();
|
|
341
|
+
throw error;
|
|
342
|
+
}
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
atomicsWait(signal, 0, observed, control?.interruptPending ? 10 : undefined);
|
|
346
|
+
}
|
|
347
|
+
#wait(cancellation, control) {
|
|
318
348
|
const signal = this.client.signal;
|
|
319
349
|
while (!this.ready) {
|
|
320
350
|
const observed = atomicsLoad(signal, 0);
|
|
321
351
|
this.check(cancellation);
|
|
352
|
+
this.checkWaitControl(control);
|
|
322
353
|
if (!this.ready)
|
|
323
|
-
|
|
354
|
+
this.parkWait(signal, observed, control);
|
|
324
355
|
}
|
|
325
356
|
this.check(cancellation);
|
|
326
357
|
if (this.consumed)
|
|
@@ -452,6 +483,51 @@ function clientWatches(cells, revoked, remote, canDrain, call) {
|
|
|
452
483
|
}
|
|
453
484
|
};
|
|
454
485
|
}
|
|
486
|
+
function isTerminalLockReleaseErrno(code) {
|
|
487
|
+
return code === 2 || code === 8 || code === 11 || code === 15 || code === 28 || code === 44 || code === 58;
|
|
488
|
+
}
|
|
489
|
+
function clientLocks(owner, call, release, hasActivePosixLocks) {
|
|
490
|
+
return {
|
|
491
|
+
owner,
|
|
492
|
+
flock: (handle, ofdId, operation, control) => {
|
|
493
|
+
try {
|
|
494
|
+
return call("lockFlock", [handle, ofdId, operation], control);
|
|
495
|
+
} catch (error) {
|
|
496
|
+
if (isInstance(error, ExecutionUnwind))
|
|
497
|
+
throw error;
|
|
498
|
+
return errno(error);
|
|
499
|
+
}
|
|
500
|
+
},
|
|
501
|
+
setRangeLock: (handle, ofdId, pid, range, blocking, control) => {
|
|
502
|
+
try {
|
|
503
|
+
return call("lockRange", [handle, ofdId ?? null, pid, range.type, range.start, range.len, blocking], blocking ? control : undefined);
|
|
504
|
+
} catch (error) {
|
|
505
|
+
if (isInstance(error, ExecutionUnwind))
|
|
506
|
+
throw error;
|
|
507
|
+
return errno(error);
|
|
508
|
+
}
|
|
509
|
+
},
|
|
510
|
+
getRangeLock: (handle, ofdId, range) => {
|
|
511
|
+
try {
|
|
512
|
+
return call("lockGetRange", [handle, ofdId ?? null, range.type, range.start, range.len]);
|
|
513
|
+
} catch (error) {
|
|
514
|
+
return errno(error);
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
releaseOfd: (handle, ofdId, inFlight = false) => {
|
|
518
|
+
release("lockReleaseOfd", [handle, ofdId, inFlight]);
|
|
519
|
+
},
|
|
520
|
+
releasePosix: (handle) => {
|
|
521
|
+
release("lockReleasePosix", [handle]);
|
|
522
|
+
},
|
|
523
|
+
handoffPosix: (successorOwner) => {
|
|
524
|
+
try {
|
|
525
|
+
call("lockHandoffPosix", [successorOwner]);
|
|
526
|
+
} catch {}
|
|
527
|
+
},
|
|
528
|
+
hasActivePosixLocks
|
|
529
|
+
};
|
|
530
|
+
}
|
|
455
531
|
function observeResolveWait(completion, writer) {
|
|
456
532
|
const cancellation = {};
|
|
457
533
|
writer.begin(completion.id);
|
|
@@ -500,6 +576,13 @@ export class FilesystemClient {
|
|
|
500
576
|
section;
|
|
501
577
|
shared;
|
|
502
578
|
watches;
|
|
579
|
+
locks;
|
|
580
|
+
get machineId() {
|
|
581
|
+
return this.shared.getMachineId();
|
|
582
|
+
}
|
|
583
|
+
pendingLockReleases = [];
|
|
584
|
+
lockReleaseTimer;
|
|
585
|
+
flushingLockReleases = false;
|
|
503
586
|
watchingRevocation = false;
|
|
504
587
|
resident;
|
|
505
588
|
workspaceStop;
|
|
@@ -521,6 +604,16 @@ export class FilesystemClient {
|
|
|
521
604
|
this.section = new FilesystemTransportSection(connection, this.requests.memory, this.revoked);
|
|
522
605
|
this.shared = new SharedFilesystemState(connection.shared, connection.maxBytes, connection.owner, connection.segments, this.section, connection.publication?.buffers);
|
|
523
606
|
this.watches = clientWatches(() => this.shared.watch.cells, this.revoked, () => this.shared.isDirectDisabled(), () => !this.shared.isWatchDrainDisabled(), (operation, args) => this.call(operation, args));
|
|
607
|
+
this.locks = clientLocks(connection.owner, (operation, args, control) => {
|
|
608
|
+
if (this.pendingLockReleases.length > 0)
|
|
609
|
+
this.flushPendingLockReleases();
|
|
610
|
+
const completion = this.submit(operation, args);
|
|
611
|
+
try {
|
|
612
|
+
return control ? completion.waitInterruptible(control) : completion.wait();
|
|
613
|
+
} finally {
|
|
614
|
+
completion.release();
|
|
615
|
+
}
|
|
616
|
+
}, (operation, args) => this.enqueueLockRelease(operation, args), () => this.shared.posixLockCount() > 0);
|
|
524
617
|
connection.port.onmessage = ({ data }) => {
|
|
525
618
|
if (data.segment)
|
|
526
619
|
this.attachSegment(data.segment, data.buffer);
|
|
@@ -784,10 +877,10 @@ export class FilesystemClient {
|
|
|
784
877
|
mapSet(this.capabilityEntries, reservation.handle, reservation.targetKey);
|
|
785
878
|
}
|
|
786
879
|
releaseReservation(reservation) {
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
if (
|
|
880
|
+
this.finishReleasedReservation(reservation, releaseFilesystemReservation(reservation));
|
|
881
|
+
}
|
|
882
|
+
finishReleasedReservation(reservation, released) {
|
|
883
|
+
if (released) {
|
|
791
884
|
const count = mapGet(this.openHandles, reservation.handle) ?? 0;
|
|
792
885
|
if (count > 1)
|
|
793
886
|
mapSet(this.openHandles, reservation.handle, count - 1);
|
|
@@ -908,7 +1001,105 @@ export class FilesystemClient {
|
|
|
908
1001
|
const completion = mapGet(this.completions, id);
|
|
909
1002
|
return completion && { kind: 3, id, ready: completion.ready };
|
|
910
1003
|
}
|
|
1004
|
+
retainLockReleaseHandle(handle) {
|
|
1005
|
+
if (!Number.isInteger(handle) || handle < 0)
|
|
1006
|
+
return;
|
|
1007
|
+
try {
|
|
1008
|
+
this.retain(handle);
|
|
1009
|
+
return handle;
|
|
1010
|
+
} catch {
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
releaseLockReleaseHandle(retainedHandle) {
|
|
1015
|
+
if (retainedHandle === undefined)
|
|
1016
|
+
return;
|
|
1017
|
+
try {
|
|
1018
|
+
this.release(retainedHandle);
|
|
1019
|
+
} catch {}
|
|
1020
|
+
}
|
|
1021
|
+
finishNextLockRelease() {
|
|
1022
|
+
const removed = this.pendingLockReleases.splice(0, 1);
|
|
1023
|
+
if (removed.length > 0)
|
|
1024
|
+
this.releaseLockReleaseHandle(removed[0].retainedHandle);
|
|
1025
|
+
}
|
|
1026
|
+
enqueueLockRelease(operation, args) {
|
|
1027
|
+
if (this.disposed || this.revoked())
|
|
1028
|
+
return;
|
|
1029
|
+
const handle = typeof args[0] === "number" ? args[0] : -1;
|
|
1030
|
+
const retainedHandle = this.retainLockReleaseHandle(handle);
|
|
1031
|
+
arrayAppend(this.pendingLockReleases, { operation, args, retainedHandle });
|
|
1032
|
+
this.flushPendingLockReleases();
|
|
1033
|
+
}
|
|
1034
|
+
scheduleLockReleaseRetry() {
|
|
1035
|
+
if (this.lockReleaseTimer !== undefined || this.disposed || this.revoked())
|
|
1036
|
+
return;
|
|
1037
|
+
this.lockReleaseTimer = scheduleTimeout(() => {
|
|
1038
|
+
this.lockReleaseTimer = undefined;
|
|
1039
|
+
this.flushPendingLockReleases();
|
|
1040
|
+
}, 1);
|
|
1041
|
+
}
|
|
1042
|
+
clearLockReleaseQueue() {
|
|
1043
|
+
const pending = this.pendingLockReleases.splice(0);
|
|
1044
|
+
for (let i = 0;i < pending.length; i++)
|
|
1045
|
+
this.releaseLockReleaseHandle(pending[i].retainedHandle);
|
|
1046
|
+
if (this.lockReleaseTimer !== undefined) {
|
|
1047
|
+
cancelTimeout(this.lockReleaseTimer);
|
|
1048
|
+
this.lockReleaseTimer = undefined;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
deliverNextLockRelease() {
|
|
1052
|
+
const next = this.pendingLockReleases[0];
|
|
1053
|
+
let completion;
|
|
1054
|
+
try {
|
|
1055
|
+
completion = this.submit(next.operation, next.args);
|
|
1056
|
+
} catch (error) {
|
|
1057
|
+
if (this.revoked() || isTerminalLockReleaseErrno(errno(error))) {
|
|
1058
|
+
this.finishNextLockRelease();
|
|
1059
|
+
return true;
|
|
1060
|
+
}
|
|
1061
|
+
this.scheduleLockReleaseRetry();
|
|
1062
|
+
return false;
|
|
1063
|
+
}
|
|
1064
|
+
try {
|
|
1065
|
+
completion.wait();
|
|
1066
|
+
this.finishNextLockRelease();
|
|
1067
|
+
return true;
|
|
1068
|
+
} catch (error) {
|
|
1069
|
+
if (this.revoked() || isTerminalLockReleaseErrno(errno(error))) {
|
|
1070
|
+
this.finishNextLockRelease();
|
|
1071
|
+
return true;
|
|
1072
|
+
}
|
|
1073
|
+
this.scheduleLockReleaseRetry();
|
|
1074
|
+
return false;
|
|
1075
|
+
} finally {
|
|
1076
|
+
completion.release();
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
flushPendingLockReleases() {
|
|
1080
|
+
if (this.flushingLockReleases || this.pendingLockReleases.length === 0)
|
|
1081
|
+
return;
|
|
1082
|
+
if (this.disposed || this.revoked()) {
|
|
1083
|
+
this.clearLockReleaseQueue();
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
this.flushingLockReleases = true;
|
|
1087
|
+
try {
|
|
1088
|
+
while (this.pendingLockReleases.length > 0) {
|
|
1089
|
+
if (this.disposed || this.revoked()) {
|
|
1090
|
+
this.clearLockReleaseQueue();
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
if (!this.deliverNextLockRelease())
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
} finally {
|
|
1097
|
+
this.flushingLockReleases = false;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
911
1100
|
call(operation, args = [], data) {
|
|
1101
|
+
if (this.pendingLockReleases.length > 0)
|
|
1102
|
+
this.flushPendingLockReleases();
|
|
912
1103
|
const completion = this.submit(operation, args, data);
|
|
913
1104
|
try {
|
|
914
1105
|
return completion.wait();
|
|
@@ -966,6 +1157,8 @@ export class FilesystemClient {
|
|
|
966
1157
|
dispose() {
|
|
967
1158
|
if (this.finishedDispose)
|
|
968
1159
|
return;
|
|
1160
|
+
this.flushPendingLockReleases();
|
|
1161
|
+
this.clearLockReleaseQueue();
|
|
969
1162
|
this.disposed = true;
|
|
970
1163
|
this.resident?.invalidate();
|
|
971
1164
|
this.beginWorkspaceStop();
|
package/dist/fs/index.js
CHANGED
|
@@ -28,7 +28,11 @@ export {
|
|
|
28
28
|
sharedRevoked
|
|
29
29
|
} from "./shared.js";
|
|
30
30
|
export { PersistentBackend } from "./persistent.js";
|
|
31
|
-
export {
|
|
31
|
+
export {
|
|
32
|
+
IndexedDBStorage,
|
|
33
|
+
IndexedDBStorageBusyError,
|
|
34
|
+
IndexedDBStorageMissingError
|
|
35
|
+
} from "./indexeddb.js";
|
|
32
36
|
export { OpfsStorage } from "./opfs.js";
|
|
33
37
|
export { getVfsDescriptor, VfsError } from "./vfs.js";
|
|
34
38
|
export * from "./workspace.js";
|
|
@@ -43,6 +47,22 @@ export {
|
|
|
43
47
|
} from "./workspace-export.js";
|
|
44
48
|
export { WorkspaceArchiveError } from "./workspace-archive.js";
|
|
45
49
|
export { FilesystemWatch } from "./watch.js";
|
|
50
|
+
export {
|
|
51
|
+
LOCK_SH,
|
|
52
|
+
LOCK_EX,
|
|
53
|
+
LOCK_NB,
|
|
54
|
+
LOCK_UN,
|
|
55
|
+
F_GETLK,
|
|
56
|
+
F_SETLK,
|
|
57
|
+
F_SETLKW,
|
|
58
|
+
F_OFD_GETLK,
|
|
59
|
+
F_OFD_SETLK,
|
|
60
|
+
F_OFD_SETLKW,
|
|
61
|
+
F_RDLCK,
|
|
62
|
+
F_WRLCK,
|
|
63
|
+
F_UNLCK
|
|
64
|
+
} from "../core/filesystem.js";
|
|
65
|
+
export { LockTable, LockContentionError } from "./locks.js";
|
|
46
66
|
export {
|
|
47
67
|
openWorkspaceRead,
|
|
48
68
|
WorkspaceReadContractError
|
package/dist/fs/indexeddb.js
CHANGED
|
@@ -71,6 +71,13 @@ export class IndexedDBStorageBusyError extends Error {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
export class IndexedDBStorageMissingError extends Error {
|
|
75
|
+
name = "IndexedDBStorageMissingError";
|
|
76
|
+
constructor(message = "IndexedDB storage database does not exist") {
|
|
77
|
+
super(message);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
74
81
|
class NativeDatabaseOpening {
|
|
75
82
|
signal;
|
|
76
83
|
versionChangeAbort;
|
|
@@ -80,6 +87,7 @@ class NativeDatabaseOpening {
|
|
|
80
87
|
database;
|
|
81
88
|
closing;
|
|
82
89
|
blocked = false;
|
|
90
|
+
missing = false;
|
|
83
91
|
abort = () => this.outcome.reject(this.signal?.reason);
|
|
84
92
|
constructor(factory, name, signal, versionChangeAbort, options) {
|
|
85
93
|
this.signal = signal;
|
|
@@ -92,10 +100,18 @@ class NativeDatabaseOpening {
|
|
|
92
100
|
this.completion.resolve();
|
|
93
101
|
return;
|
|
94
102
|
}
|
|
103
|
+
const createIfMissing = options.createIfMissing ?? true;
|
|
95
104
|
try {
|
|
96
105
|
const request = factory.open(name, 1);
|
|
97
106
|
signal?.addEventListener("abort", this.abort, { once: true });
|
|
98
|
-
request.onupgradeneeded = () =>
|
|
107
|
+
request.onupgradeneeded = () => {
|
|
108
|
+
if (createIfMissing) {
|
|
109
|
+
createStores(request.result);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.missing = true;
|
|
113
|
+
request.transaction?.abort();
|
|
114
|
+
};
|
|
99
115
|
request.onsuccess = () => this.delivered(request.result);
|
|
100
116
|
request.onerror = () => this.failed(request.error);
|
|
101
117
|
request.onblocked = () => this.blockedRequest();
|
|
@@ -113,6 +129,11 @@ class NativeDatabaseOpening {
|
|
|
113
129
|
delivered(database) {
|
|
114
130
|
this.stopObserving();
|
|
115
131
|
this.database = database;
|
|
132
|
+
if (this.missing) {
|
|
133
|
+
this.outcome.reject(new IndexedDBStorageMissingError);
|
|
134
|
+
this.retire().catch(() => {});
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
116
137
|
if (this.signal?.aborted || this.blocked) {
|
|
117
138
|
this.retire().catch(() => {});
|
|
118
139
|
return;
|
|
@@ -125,6 +146,11 @@ class NativeDatabaseOpening {
|
|
|
125
146
|
}
|
|
126
147
|
failed(error) {
|
|
127
148
|
this.stopObserving();
|
|
149
|
+
if (this.missing) {
|
|
150
|
+
this.outcome.reject(new IndexedDBStorageMissingError);
|
|
151
|
+
this.completion.resolve();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
128
154
|
this.outcome.reject(error?.name === "VersionError" ? new VfsError("INVALID_VFS_FORMAT", "indexeddb", "Incompatible IndexedDB database version") : error ?? new Error("Cannot open filesystem storage"));
|
|
129
155
|
this.completion.resolve();
|
|
130
156
|
}
|
|
@@ -970,7 +996,9 @@ export class IndexedDBStorage {
|
|
|
970
996
|
}
|
|
971
997
|
}, committedMode, () => maintenance.release());
|
|
972
998
|
} catch (error) {
|
|
973
|
-
Promise.all(debts).then(() => maintenance.release()).catch(() => {});
|
|
999
|
+
const cleanup = Promise.all(debts).then(() => maintenance.release()).catch(() => {});
|
|
1000
|
+
if (error instanceof IndexedDBStorageMissingError)
|
|
1001
|
+
await cleanup;
|
|
974
1002
|
throw error;
|
|
975
1003
|
}
|
|
976
1004
|
}
|