@waffle-os/runtime 0.0.150 → 0.0.152
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/process-broker.ts +42 -4
- package/browser/service-worker.ts +18 -3
- package/dist/browser/process-broker.js +47 -2
- package/dist/browser/service-worker.js +9 -3
- package/dist/fs/multitab-backend.js +303 -97
- package/dist/fs/multitab-protocol.js +2 -0
- package/dist/fs/service.js +25 -3
- package/dist/interrupt/rewriter-internal.js +2 -1
- package/dist/proc/abi.js +20 -6
- package/dist/proc/directory.js +111 -0
- package/dist/proc/errors.js +1 -0
- package/dist/proc/supervisor.js +130 -24
- package/dist/proc/table.js +9 -1
- package/dist/proc/types.js +5 -0
- package/dist/proc/worker-client.js +34 -5
- package/dist/runtime.js +3 -0
- package/dist/tooling/program/program-transformer.json +1 -1
- package/fs/backend.ts +6 -1
- package/fs/multitab-backend.ts +385 -105
- package/fs/multitab-protocol.ts +11 -0
- package/fs/service.ts +28 -6
- package/interrupt/rewriter-internal.ts +2 -1
- package/package.json +1 -1
- package/proc/abi.ts +25 -4
- package/proc/directory.ts +131 -0
- package/proc/errors.ts +1 -0
- package/proc/supervisor.ts +173 -36
- package/proc/table.ts +11 -0
- package/proc/types.ts +6 -0
- package/proc/worker-client.ts +36 -5
- package/runtime.ts +3 -0
- package/tooling/program/program-transformer.json +1 -1
|
@@ -84,6 +84,8 @@ import {
|
|
|
84
84
|
directoryProcesses,
|
|
85
85
|
directoryAdmissionVersion,
|
|
86
86
|
commitDirectoryAdmission,
|
|
87
|
+
peekDirectoryJob,
|
|
88
|
+
peekDirectoryProcess,
|
|
87
89
|
isCollectedProcess,
|
|
88
90
|
wakeDirectory,
|
|
89
91
|
} from "../proc/directory.js";
|
|
@@ -99,13 +101,14 @@ import { type FilesystemConnection, type FilesystemIdentity, isRevoked } from ".
|
|
|
99
101
|
import type { ProcessSupervisor, RootProcessOptions } from "../proc/supervisor.js";
|
|
100
102
|
import type { CommandPrograms, ExecutableRegistry, ResolvedExecutable } from "../proc/registry.js";
|
|
101
103
|
import type { ProcessIdentityAllocator } from "../proc/identity.js";
|
|
102
|
-
import type { ProcessRecord, ProcessTable } from "../proc/table.js";
|
|
104
|
+
import type { ProcessJob, ProcessRecord, ProcessTable } from "../proc/table.js";
|
|
103
105
|
import {
|
|
104
106
|
type ChildExitEvent,
|
|
105
107
|
type ProcessContext,
|
|
106
108
|
type ProcessExit,
|
|
107
109
|
type CommandProcessContext,
|
|
108
110
|
type ProcessHandle,
|
|
111
|
+
checkedKillSignal,
|
|
109
112
|
checkedSignal,
|
|
110
113
|
checkedProcessCwd,
|
|
111
114
|
snapshotLogicalProcessIdentity,
|
|
@@ -115,6 +118,7 @@ import {
|
|
|
115
118
|
} from "../proc/types.js";
|
|
116
119
|
import { requestSignal, createSignalState, type SignalTransport } from "../proc/signals.js";
|
|
117
120
|
import {
|
|
121
|
+
OutcomeCell,
|
|
118
122
|
claimOutcome,
|
|
119
123
|
outcomeWord,
|
|
120
124
|
readOutcome,
|
|
@@ -3569,8 +3573,38 @@ export class BrowserProcessBroker {
|
|
|
3569
3573
|
Array.from(directoryProcesses(root.directory)),
|
|
3570
3574
|
);
|
|
3571
3575
|
}
|
|
3576
|
+
private isDirectoryBackedJob(entry: ProcessJob): boolean {
|
|
3577
|
+
if (entry.shared) return true;
|
|
3578
|
+
const leader =
|
|
3579
|
+
entry.leaderPid === undefined ? undefined : this.options.table.get(entry.leaderPid);
|
|
3580
|
+
return leader !== undefined && isInstance(leader.outcome, OutcomeCell);
|
|
3581
|
+
}
|
|
3582
|
+
private hasProcess(pid: number): boolean {
|
|
3583
|
+
for (const root of this.roots.values())
|
|
3584
|
+
if (peekDirectoryProcess(root.directory, pid)) return true;
|
|
3585
|
+
const record = this.options.table.get(pid);
|
|
3586
|
+
if (record && !isInstance(record.outcome, OutcomeCell)) return true;
|
|
3587
|
+
const reserved = this.reservedRoots.get(pid);
|
|
3588
|
+
return reserved !== undefined && !isInstance(reserved.outcome, OutcomeCell);
|
|
3589
|
+
}
|
|
3590
|
+
private hasJob(
|
|
3591
|
+
job: number,
|
|
3592
|
+
reserved: readonly { pid: number; signals: SignalTransport }[],
|
|
3593
|
+
): boolean {
|
|
3594
|
+
if (reserved.length > 0) return true;
|
|
3595
|
+
for (const root of this.roots.values()) if (peekDirectoryJob(root.directory, job)) return true;
|
|
3596
|
+
const entry = this.options.table.job(job);
|
|
3597
|
+
if (entry && !this.isDirectoryBackedJob(entry)) return true;
|
|
3598
|
+
for (const root of this.reservedRoots.values())
|
|
3599
|
+
if (root.job === job && !isInstance(root.outcome, OutcomeCell)) return true;
|
|
3600
|
+
return false;
|
|
3601
|
+
}
|
|
3572
3602
|
async kill(pid: number, signal: number): Promise<void> {
|
|
3573
|
-
const sig =
|
|
3603
|
+
const sig = checkedKillSignal(signal);
|
|
3604
|
+
if (sig === 0) {
|
|
3605
|
+
if (this.suspended || this.hasProcess(pid)) return;
|
|
3606
|
+
throw new ProcessError(ProcessErrno.SRCH, `unknown process ${pid}`);
|
|
3607
|
+
}
|
|
3574
3608
|
const found = this.publishProcessSignal(pid, sig);
|
|
3575
3609
|
const supervisor = await this.ready();
|
|
3576
3610
|
if (this.suspended) return;
|
|
@@ -3624,8 +3658,12 @@ export class BrowserProcessBroker {
|
|
|
3624
3658
|
signal: number,
|
|
3625
3659
|
reserved: readonly { pid: number; signals: SignalTransport }[] = [],
|
|
3626
3660
|
): Promise<void> {
|
|
3627
|
-
const sig =
|
|
3628
|
-
|
|
3661
|
+
const sig = checkedKillSignal(signal);
|
|
3662
|
+
if (sig === 0) {
|
|
3663
|
+
if (this.suspended || this.hasJob(job, reserved)) return;
|
|
3664
|
+
throw new ProcessError(ProcessErrno.SRCH, `unknown job ${job}`);
|
|
3665
|
+
}
|
|
3666
|
+
const states = this.states().filter((state) => state.job === job);
|
|
3629
3667
|
const seen = new Set(states.map((state) => state.pid));
|
|
3630
3668
|
const records = Array.from(this.options.table.values()).filter(
|
|
3631
3669
|
(record) => record.job === job && !seen.has(record.pid),
|
|
@@ -219,10 +219,25 @@ export function createPreviewServiceWorker(options: PreviewServiceWorkerOptions)
|
|
|
219
219
|
};
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
/**
|
|
222
|
+
/**
|
|
223
|
+
* Await activation even when the registering page is outside the worker's scope.
|
|
224
|
+
*
|
|
225
|
+
* A worker in the registration's active slot is already activating or activated, and fetches it
|
|
226
|
+
* handles wait for its activation, so it needs no wait. Only an installing or waiting worker is
|
|
227
|
+
* watched. WebKit can resolve `register()` in a second page that registered at the same moment with
|
|
228
|
+
* the active worker's state still reading "installing", and never sends that object another
|
|
229
|
+
* `statechange`; waiting on it would hang forever. A "redundant" state is still a failure: the spec
|
|
230
|
+
* queues that state update before it clears the active slot, so the two can briefly disagree.
|
|
231
|
+
*/
|
|
223
232
|
export function activated(registration: ServiceWorkerRegistration): Promise<void> {
|
|
224
|
-
const worker = registration.installing ?? registration.waiting
|
|
225
|
-
if (!worker)
|
|
233
|
+
const worker = registration.installing ?? registration.waiting;
|
|
234
|
+
if (!worker) {
|
|
235
|
+
const active = registration.active;
|
|
236
|
+
if (!active) return Promise.reject(new Error("service worker registration has no worker"));
|
|
237
|
+
if (active.state === "redundant")
|
|
238
|
+
return Promise.reject(new Error("service worker became redundant before activation"));
|
|
239
|
+
return Promise.resolve();
|
|
240
|
+
}
|
|
226
241
|
return new Promise((resolve, reject) => {
|
|
227
242
|
const check = () => {
|
|
228
243
|
if (worker.state !== "activated" && worker.state !== "redundant") return;
|
|
@@ -60,6 +60,8 @@ import {
|
|
|
60
60
|
directoryProcesses,
|
|
61
61
|
directoryAdmissionVersion,
|
|
62
62
|
commitDirectoryAdmission,
|
|
63
|
+
peekDirectoryJob,
|
|
64
|
+
peekDirectoryProcess,
|
|
63
65
|
isCollectedProcess,
|
|
64
66
|
wakeDirectory
|
|
65
67
|
} from "../proc/directory.js";
|
|
@@ -71,6 +73,7 @@ import {
|
|
|
71
73
|
} from "../proc/control.js";
|
|
72
74
|
import { isRevoked } from "../fs/protocol.js";
|
|
73
75
|
import {
|
|
76
|
+
checkedKillSignal,
|
|
74
77
|
checkedSignal,
|
|
75
78
|
checkedProcessCwd,
|
|
76
79
|
snapshotLogicalProcessIdentity,
|
|
@@ -79,6 +82,7 @@ import {
|
|
|
79
82
|
} from "../proc/types.js";
|
|
80
83
|
import { requestSignal, createSignalState } from "../proc/signals.js";
|
|
81
84
|
import {
|
|
85
|
+
OutcomeCell,
|
|
82
86
|
claimOutcome,
|
|
83
87
|
outcomeWord,
|
|
84
88
|
readOutcome,
|
|
@@ -2789,8 +2793,43 @@ export class BrowserProcessBroker {
|
|
|
2789
2793
|
states() {
|
|
2790
2794
|
return Array.from(this.roots.values()).flatMap((root) => Array.from(directoryProcesses(root.directory)));
|
|
2791
2795
|
}
|
|
2796
|
+
isDirectoryBackedJob(entry) {
|
|
2797
|
+
if (entry.shared)
|
|
2798
|
+
return true;
|
|
2799
|
+
const leader = entry.leaderPid === undefined ? undefined : this.options.table.get(entry.leaderPid);
|
|
2800
|
+
return leader !== undefined && isInstance(leader.outcome, OutcomeCell);
|
|
2801
|
+
}
|
|
2802
|
+
hasProcess(pid) {
|
|
2803
|
+
for (const root of this.roots.values())
|
|
2804
|
+
if (peekDirectoryProcess(root.directory, pid))
|
|
2805
|
+
return true;
|
|
2806
|
+
const record = this.options.table.get(pid);
|
|
2807
|
+
if (record && !isInstance(record.outcome, OutcomeCell))
|
|
2808
|
+
return true;
|
|
2809
|
+
const reserved = this.reservedRoots.get(pid);
|
|
2810
|
+
return reserved !== undefined && !isInstance(reserved.outcome, OutcomeCell);
|
|
2811
|
+
}
|
|
2812
|
+
hasJob(job, reserved) {
|
|
2813
|
+
if (reserved.length > 0)
|
|
2814
|
+
return true;
|
|
2815
|
+
for (const root of this.roots.values())
|
|
2816
|
+
if (peekDirectoryJob(root.directory, job))
|
|
2817
|
+
return true;
|
|
2818
|
+
const entry = this.options.table.job(job);
|
|
2819
|
+
if (entry && !this.isDirectoryBackedJob(entry))
|
|
2820
|
+
return true;
|
|
2821
|
+
for (const root of this.reservedRoots.values())
|
|
2822
|
+
if (root.job === job && !isInstance(root.outcome, OutcomeCell))
|
|
2823
|
+
return true;
|
|
2824
|
+
return false;
|
|
2825
|
+
}
|
|
2792
2826
|
async kill(pid, signal) {
|
|
2793
|
-
const sig =
|
|
2827
|
+
const sig = checkedKillSignal(signal);
|
|
2828
|
+
if (sig === 0) {
|
|
2829
|
+
if (this.suspended || this.hasProcess(pid))
|
|
2830
|
+
return;
|
|
2831
|
+
throw new ProcessError(ProcessErrno.SRCH, `unknown process ${pid}`);
|
|
2832
|
+
}
|
|
2794
2833
|
const found = this.publishProcessSignal(pid, sig);
|
|
2795
2834
|
const supervisor = await this.ready();
|
|
2796
2835
|
if (this.suspended)
|
|
@@ -2833,7 +2872,13 @@ export class BrowserProcessBroker {
|
|
|
2833
2872
|
}
|
|
2834
2873
|
}
|
|
2835
2874
|
async killJob(job, signal, reserved = []) {
|
|
2836
|
-
const sig =
|
|
2875
|
+
const sig = checkedKillSignal(signal);
|
|
2876
|
+
if (sig === 0) {
|
|
2877
|
+
if (this.suspended || this.hasJob(job, reserved))
|
|
2878
|
+
return;
|
|
2879
|
+
throw new ProcessError(ProcessErrno.SRCH, `unknown job ${job}`);
|
|
2880
|
+
}
|
|
2881
|
+
const states = this.states().filter((state) => state.job === job);
|
|
2837
2882
|
const seen = new Set(states.map((state) => state.pid));
|
|
2838
2883
|
const records = Array.from(this.options.table.values()).filter((record) => record.job === job && !seen.has(record.pid));
|
|
2839
2884
|
for (const state of states)
|
|
@@ -177,9 +177,15 @@ export function createPreviewServiceWorker(options) {
|
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
179
|
export function activated(registration) {
|
|
180
|
-
const worker = registration.installing ?? registration.waiting
|
|
181
|
-
if (!worker)
|
|
182
|
-
|
|
180
|
+
const worker = registration.installing ?? registration.waiting;
|
|
181
|
+
if (!worker) {
|
|
182
|
+
const active = registration.active;
|
|
183
|
+
if (!active)
|
|
184
|
+
return Promise.reject(new Error("service worker registration has no worker"));
|
|
185
|
+
if (active.state === "redundant")
|
|
186
|
+
return Promise.reject(new Error("service worker became redundant before activation"));
|
|
187
|
+
return Promise.resolve();
|
|
188
|
+
}
|
|
183
189
|
return new Promise((resolve, reject) => {
|
|
184
190
|
const check = () => {
|
|
185
191
|
if (worker.state !== "activated" && worker.state !== "redundant")
|