@waffle-os/runtime 0.0.0-stage → 0.0.146
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/Cargo.lock +250 -0
- package/Cargo.toml +16 -0
- package/LICENSE +21 -0
- package/LICENSES/Apache-2.0.txt +191 -0
- package/README.md +31 -2
- package/browser/command-input.ts +86 -0
- package/browser/command-owner.ts +5 -0
- package/browser/diagnostic.ts +58 -0
- package/browser/display/generated/graphics-layout.ts +18 -0
- package/browser/display/guest.ts +71 -0
- package/browser/display/launch-retention.ts +59 -0
- package/browser/display/open.ts +45 -0
- package/browser/display/owner.ts +563 -0
- package/browser/display/protocol.ts +24 -0
- package/browser/display/service-protocol.ts +28 -0
- package/browser/display/service-readers.ts +96 -0
- package/browser/display/surface-info.ts +19 -0
- package/browser/filesystem-backend.ts +57 -0
- package/browser/filesystem-worker-backend.ts +27 -0
- package/browser/fs-worker.ts +13 -0
- package/browser/gpu/access.ts +62 -0
- package/browser/gpu/buffers.ts +273 -0
- package/browser/gpu/codec.ts +426 -0
- package/browser/gpu/command-reader.ts +90 -0
- package/browser/gpu/completions.ts +437 -0
- package/browser/gpu/generated/tables.ts +7513 -0
- package/browser/gpu/guest.ts +267 -0
- package/browser/gpu/handles.ts +143 -0
- package/browser/gpu/lowering.ts +238 -0
- package/browser/gpu/metadata.ts +364 -0
- package/browser/gpu/method-coverage.json +1933 -0
- package/browser/gpu/payload.ts +117 -0
- package/browser/gpu/protocol.ts +61 -0
- package/browser/gpu/replay.ts +1067 -0
- package/browser/gpu/ring.ts +336 -0
- package/browser/gpu/scheduler.ts +151 -0
- package/browser/gpu/service-worker.ts +20 -0
- package/browser/gpu/service.ts +490 -0
- package/browser/gpu/stream.json +4175 -0
- package/browser/gpu/surfaces.ts +433 -0
- package/browser/gpu/transport.ts +317 -0
- package/browser/gpu/upstream/LICENSE +29 -0
- package/browser/gpu/upstream/webgpu.h +6774 -0
- package/browser/gpu/upstream/webgpu.yml +5532 -0
- package/browser/guarded-stream.ts +63 -0
- package/browser/net/address.ts +132 -0
- package/browser/net/buffer-module.ts +64 -0
- package/browser/net/helper.ts +1237 -0
- package/browser/net/host.ts +982 -0
- package/browser/net/http1.ts +372 -0
- package/browser/net/module.ts +45 -0
- package/browser/net/namespace.ts +416 -0
- package/browser/net/network.buffer.d.ts +10 -0
- package/browser/net/network.buffer.js +11960 -0
- package/browser/net/network.buffer.sha256 +1 -0
- package/browser/net/network.growth.json +1 -0
- package/browser/net/network.input-hash +1 -0
- package/browser/net/network.sha256 +1 -0
- package/browser/net/network.wasm +0 -0
- package/browser/net/outbound-socket.ts +253 -0
- package/browser/net/outbound.ts +42 -0
- package/browser/net/owner.ts +55 -0
- package/browser/net/protocol.ts +136 -0
- package/browser/net/ring.ts +198 -0
- package/browser/net/runtime.ts +235 -0
- package/browser/net/tcp-status.ts +7 -0
- package/browser/net/transport.ts +26 -0
- package/browser/net/unix-paths.ts +260 -0
- package/browser/net/unix-status.ts +39 -0
- package/browser/notification-blocking-wait.ts +54 -0
- package/browser/notification-relay.ts +76 -0
- package/browser/notification-wait.ts +241 -0
- package/browser/notification-worker.ts +105 -0
- package/browser/operations/cells.ts +90 -0
- package/browser/operations/guest.ts +94 -0
- package/browser/operations/owner.ts +201 -0
- package/browser/operations/protocol.ts +16 -0
- package/browser/operations/types.ts +41 -0
- package/browser/operations/writer.ts +106 -0
- package/browser/persistent-resident-owner.ts +368 -0
- package/browser/preview-host.ts +595 -0
- package/browser/preview-protocol.ts +20 -0
- package/browser/preview.ts +179 -0
- package/browser/preview1-network-types.ts +20 -0
- package/browser/preview1-network.ts +77 -0
- package/browser/preview1-socket.ts +278 -0
- package/browser/preview1-worker.ts +25 -0
- package/browser/process-broker.ts +4209 -0
- package/browser/process-context.ts +56 -0
- package/browser/process-start.ts +133 -0
- package/browser/publication-authority.ts +437 -0
- package/browser/run-command.ts +388 -0
- package/browser/runtime-terminals.ts +183 -0
- package/browser/service-worker.ts +237 -0
- package/browser/shared-fs.ts +742 -0
- package/browser/terminal-input.ts +574 -0
- package/browser/terminal-lifetime.ts +42 -0
- package/browser/terminal-output.ts +491 -0
- package/browser/terminal-session.ts +2225 -0
- package/browser/worker-memory.ts +137 -0
- package/browser/worker-pool.ts +17 -0
- package/browser/worker.ts +1683 -0
- package/build.ts +375 -0
- package/core/descriptors.ts +284 -0
- package/core/devices.ts +20 -0
- package/core/fd-reopen.ts +210 -0
- package/core/filesystem.ts +154 -0
- package/core/index.ts +21 -0
- package/core/memory-views.ts +74 -0
- package/core/open-file.ts +173 -0
- package/core/path.ts +26 -0
- package/core/rights.ts +33 -0
- package/core/unwind.ts +2 -0
- package/core/wasi.ts +1459 -0
- package/dist/browser/command-input.js +82 -0
- package/dist/browser/command-owner.js +2 -0
- package/dist/browser/diagnostic.js +42 -0
- package/dist/browser/display/generated/graphics-layout.js +17 -0
- package/dist/browser/display/guest.js +62 -0
- package/dist/browser/display/launch-retention.js +35 -0
- package/dist/browser/display/open.js +18 -0
- package/dist/browser/display/owner.js +506 -0
- package/dist/browser/display/protocol.js +0 -0
- package/dist/browser/display/service-protocol.js +0 -0
- package/dist/browser/display/service-readers.js +88 -0
- package/dist/browser/display/surface-info.js +18 -0
- package/dist/browser/filesystem-backend.js +29 -0
- package/dist/browser/filesystem-worker-backend.js +20 -0
- package/dist/browser/fs-worker.js +10 -0
- package/dist/browser/gpu/access.js +65 -0
- package/dist/browser/gpu/buffers.js +212 -0
- package/dist/browser/gpu/codec.js +426 -0
- package/dist/browser/gpu/command-reader.js +82 -0
- package/dist/browser/gpu/completions.js +372 -0
- package/dist/browser/gpu/generated/tables.js +7492 -0
- package/dist/browser/gpu/guest.js +239 -0
- package/dist/browser/gpu/handles.js +147 -0
- package/dist/browser/gpu/lowering.js +234 -0
- package/dist/browser/gpu/metadata.js +311 -0
- package/dist/browser/gpu/payload.js +91 -0
- package/dist/browser/gpu/protocol.js +55 -0
- package/dist/browser/gpu/replay.js +871 -0
- package/dist/browser/gpu/ring.js +244 -0
- package/dist/browser/gpu/scheduler.js +124 -0
- package/dist/browser/gpu/service-worker.js +16 -0
- package/dist/browser/gpu/service.js +460 -0
- package/dist/browser/gpu/surfaces.js +394 -0
- package/dist/browser/gpu/transport.js +293 -0
- package/dist/browser/guarded-stream.js +44 -0
- package/dist/browser/net/address.js +98 -0
- package/dist/browser/net/buffer-module.js +60 -0
- package/dist/browser/net/helper.js +1065 -0
- package/dist/browser/net/host.js +896 -0
- package/dist/browser/net/http1.js +305 -0
- package/dist/browser/net/module.js +36 -0
- package/dist/browser/net/namespace.js +396 -0
- package/dist/browser/net/network.buffer.js +11960 -0
- package/dist/browser/net/network.buffer.sha256 +1 -0
- package/dist/browser/net/network.growth.json +1 -0
- package/dist/browser/net/network.input-hash +1 -0
- package/dist/browser/net/network.sha256 +1 -0
- package/dist/browser/net/network.wasm +0 -0
- package/dist/browser/net/outbound-socket.js +226 -0
- package/dist/browser/net/outbound.js +8 -0
- package/dist/browser/net/owner.js +51 -0
- package/dist/browser/net/protocol.js +23 -0
- package/dist/browser/net/ring.js +143 -0
- package/dist/browser/net/runtime.js +177 -0
- package/dist/browser/net/tcp-status.js +5 -0
- package/dist/browser/net/transport.js +12 -0
- package/dist/browser/net/unix-paths.js +178 -0
- package/dist/browser/net/unix-status.js +33 -0
- package/dist/browser/notification-blocking-wait.js +38 -0
- package/dist/browser/notification-relay.js +50 -0
- package/dist/browser/notification-wait.js +179 -0
- package/dist/browser/notification-worker.js +83 -0
- package/dist/browser/operations/cells.js +80 -0
- package/dist/browser/operations/guest.js +67 -0
- package/dist/browser/operations/owner.js +175 -0
- package/dist/browser/operations/protocol.js +0 -0
- package/dist/browser/operations/types.js +0 -0
- package/dist/browser/operations/writer.js +98 -0
- package/dist/browser/persistent-resident-owner.js +264 -0
- package/dist/browser/preview-host.js +435 -0
- package/dist/browser/preview-protocol.js +0 -0
- package/dist/browser/preview.js +161 -0
- package/dist/browser/preview1-network-types.js +0 -0
- package/dist/browser/preview1-network.js +58 -0
- package/dist/browser/preview1-socket.js +273 -0
- package/dist/browser/preview1-worker.js +17 -0
- package/dist/browser/process-broker.js +3361 -0
- package/dist/browser/process-context.js +22 -0
- package/dist/browser/process-start.js +74 -0
- package/dist/browser/publication-authority.js +404 -0
- package/dist/browser/run-command.js +377 -0
- package/dist/browser/runtime-terminals.js +97 -0
- package/dist/browser/service-worker.js +196 -0
- package/dist/browser/shared-fs.js +568 -0
- package/dist/browser/terminal-input.js +562 -0
- package/dist/browser/terminal-lifetime.js +30 -0
- package/dist/browser/terminal-output.js +415 -0
- package/dist/browser/terminal-session.js +1854 -0
- package/dist/browser/worker-memory.js +116 -0
- package/dist/browser/worker-pool.js +14 -0
- package/dist/browser/worker.js +1263 -0
- package/dist/core/descriptors.js +216 -0
- package/dist/core/devices.js +16 -0
- package/dist/core/fd-reopen.js +185 -0
- package/dist/core/filesystem.js +38 -0
- package/dist/core/index.js +8 -0
- package/dist/core/memory-views.js +48 -0
- package/dist/core/open-file.js +141 -0
- package/dist/core/path.js +25 -0
- package/dist/core/rights.js +31 -0
- package/dist/core/unwind.js +2 -0
- package/dist/core/wasi.js +1136 -0
- package/dist/fs/backend.js +885 -0
- package/dist/fs/checkpoint-pressure.js +81 -0
- package/dist/fs/cleanup.js +13 -0
- package/dist/fs/client.js +1808 -0
- package/dist/fs/directory-pages.js +166 -0
- package/dist/fs/dirty-admission.js +196 -0
- package/dist/fs/file-identity.js +149 -0
- package/dist/fs/glob.js +154 -0
- package/dist/fs/guest-watch.js +173 -0
- package/dist/fs/identity-allocation.js +24 -0
- package/dist/fs/idle-database.js +113 -0
- package/dist/fs/idle-owner.js +290 -0
- package/dist/fs/idle-walk.js +112 -0
- package/dist/fs/idle-workspace.js +41 -0
- package/dist/fs/index.js +49 -0
- package/dist/fs/indexeddb-chunks.js +109 -0
- package/dist/fs/indexeddb.js +1421 -0
- package/dist/fs/memory-admission.js +18 -0
- package/dist/fs/memory-budget.js +665 -0
- package/dist/fs/memory.js +1103 -0
- package/dist/fs/namespace-cursor.js +241 -0
- package/dist/fs/namespace-projection-memory-budget.js +59 -0
- package/dist/fs/namespace-projection-owner.js +116 -0
- package/dist/fs/namespace-projection-table.js +660 -0
- package/dist/fs/opfs.js +751 -0
- package/dist/fs/persisted-tree.js +44 -0
- package/dist/fs/persistent.js +819 -0
- package/dist/fs/protocol.js +406 -0
- package/dist/fs/publication-attachment.js +1102 -0
- package/dist/fs/publication-grant.js +463 -0
- package/dist/fs/publication-internal.js +16 -0
- package/dist/fs/publication-memory-budget.js +71 -0
- package/dist/fs/publication-workspace.js +231 -0
- package/dist/fs/publication.js +1294 -0
- package/dist/fs/request-memory.js +728 -0
- package/dist/fs/resolve-observation.js +11 -0
- package/dist/fs/root-construction.js +94 -0
- package/dist/fs/root-memory-budget.js +66 -0
- package/dist/fs/safe-staging.js +547 -0
- package/dist/fs/section.js +37 -0
- package/dist/fs/service.js +1779 -0
- package/dist/fs/shared-capacity.js +5 -0
- package/dist/fs/shared-version-pages.js +46 -0
- package/dist/fs/shared.js +1943 -0
- package/dist/fs/startup.js +26 -0
- package/dist/fs/storage-geometry.js +29 -0
- package/dist/fs/storage-maintenance.js +45 -0
- package/dist/fs/storage.js +306 -0
- package/dist/fs/utf8-size.js +22 -0
- package/dist/fs/vfs-format.js +2 -0
- package/dist/fs/vfs-internal.js +4 -0
- package/dist/fs/vfs.js +121 -0
- package/dist/fs/walk.js +296 -0
- package/dist/fs/watch-account.js +293 -0
- package/dist/fs/watch-arena.js +60 -0
- package/dist/fs/watch-capture.js +77 -0
- package/dist/fs/watch-id-index.js +150 -0
- package/dist/fs/watch-index.js +288 -0
- package/dist/fs/watch-names.js +140 -0
- package/dist/fs/watch-ring.js +172 -0
- package/dist/fs/watch-routing.js +54 -0
- package/dist/fs/watch-service.js +282 -0
- package/dist/fs/watch-subscriptions.js +381 -0
- package/dist/fs/watch.js +78 -0
- package/dist/fs/workspace-archive.js +631 -0
- package/dist/fs/workspace-export.js +309 -0
- package/dist/fs/workspace-import-admission.js +111 -0
- package/dist/fs/workspace-index.js +15 -0
- package/dist/fs/workspace-namespace.js +89 -0
- package/dist/fs/workspace-protocol.js +303 -0
- package/dist/fs/workspace-read.js +576 -0
- package/dist/fs/workspace-search.js +618 -0
- package/dist/fs/workspace-stream.js +210 -0
- package/dist/fs/workspace-types.js +21 -0
- package/dist/fs/workspace.js +557 -0
- package/dist/group/member.js +360 -0
- package/dist/group/protocol.js +35 -0
- package/dist/group/ranges.js +50 -0
- package/dist/group/state.js +846 -0
- package/dist/index.js +27 -0
- package/dist/interrupt/admitted-store.js +180 -0
- package/dist/interrupt/check.js +8 -0
- package/dist/interrupt/index.js +3 -0
- package/dist/interrupt/loader-internal.js +243 -0
- package/dist/interrupt/loader.js +10 -0
- package/dist/interrupt/rewriter-internal.js +942 -0
- package/dist/interrupt/rewriter.js +4 -0
- package/dist/interrupt/wait.js +75 -0
- package/dist/link/code.js +195 -0
- package/dist/link/group.js +258 -0
- package/dist/link/image.js +100 -0
- package/dist/link/index.js +7 -0
- package/dist/link/issuance.js +9 -0
- package/dist/link/metadata.js +455 -0
- package/dist/link/plan.js +264 -0
- package/dist/link/relay.js +46 -0
- package/dist/link/worker.js +44 -0
- package/dist/memory/allocator.js +15 -0
- package/dist/memory/control.js +70 -0
- package/dist/memory/declarations.js +242 -0
- package/dist/memory/graphics-retention.js +10 -0
- package/dist/memory/index.js +8 -0
- package/dist/memory/platform.js +57 -0
- package/dist/memory/reservations.js +970 -0
- package/dist/proc/abi.js +794 -0
- package/dist/proc/access.js +7 -0
- package/dist/proc/admission.js +17 -0
- package/dist/proc/command-runner.js +108 -0
- package/dist/proc/command-stdio.js +176 -0
- package/dist/proc/command-transfer.js +72 -0
- package/dist/proc/command.js +8 -0
- package/dist/proc/control.js +145 -0
- package/dist/proc/directory.js +798 -0
- package/dist/proc/errors.js +20 -0
- package/dist/proc/exec.js +37 -0
- package/dist/proc/filesystem-codec.js +60 -0
- package/dist/proc/identity.js +54 -0
- package/dist/proc/index.js +59 -0
- package/dist/proc/intrinsics/core.js +65 -0
- package/dist/proc/intrinsics/host.js +254 -0
- package/dist/proc/intrinsics.js +99 -0
- package/dist/proc/node-wasi.js +312 -0
- package/dist/proc/observation.js +233 -0
- package/dist/proc/outcome.js +237 -0
- package/dist/proc/pipes.js +1334 -0
- package/dist/proc/registry.js +304 -0
- package/dist/proc/signals.js +179 -0
- package/dist/proc/start-command.js +101 -0
- package/dist/proc/start-diagnostic.js +100 -0
- package/dist/proc/start-errno.js +24 -0
- package/dist/proc/start-failure.js +25 -0
- package/dist/proc/stub.js +17 -0
- package/dist/proc/supervisor.js +1565 -0
- package/dist/proc/table.js +195 -0
- package/dist/proc/terminal-lifetime.js +117 -0
- package/dist/proc/terminal-turn.js +50 -0
- package/dist/proc/types.js +77 -0
- package/dist/proc/wait-status.js +3 -0
- package/dist/proc/worker-access.js +117 -0
- package/dist/proc/worker-broker.js +908 -0
- package/dist/proc/worker-client.js +892 -0
- package/dist/proc/worker-pipes.js +165 -0
- package/dist/programs/catalog.js +27 -0
- package/dist/programs/collection.js +278 -0
- package/dist/programs/download.js +70 -0
- package/dist/programs/index.js +358 -0
- package/dist/runtime.js +774 -0
- package/dist/search/engine.js +299 -0
- package/dist/search/format.js +83 -0
- package/dist/search/index.js +3 -0
- package/dist/search/matcher.js +102 -0
- package/dist/search/paths.js +7 -0
- package/dist/search/search-worker.js +4 -0
- package/dist/search/shard-worker.js +74 -0
- package/dist/search/shards.js +529 -0
- package/dist/search/types.js +7 -0
- package/dist/tests/error-serialization.js +36 -0
- package/dist/tests/page-runner/bootstrap-diagnostics.js +29 -0
- package/dist/tests/page-runner/bootstrap-navigation.js +11 -0
- package/dist/tests/page-runner/browser-observation.js +421 -0
- package/dist/tests/page-runner/collector-fetch.js +70 -0
- package/dist/tests/page-runner/collector.js +635 -0
- package/dist/tests/page-runner/console-observation.js +24 -0
- package/dist/tests/page-runner/continuity-lock-diagnostic.js +301 -0
- package/dist/tests/page-runner/driver.js +41 -0
- package/dist/tests/page-runner/framework-bootstrap.js +9 -0
- package/dist/tests/page-runner/framework-collector.js +219 -0
- package/dist/tests/page-runner/framework-host.js +680 -0
- package/dist/tests/page-runner/framework-http-body.js +47 -0
- package/dist/tests/page-runner/framework-middleware.js +60 -0
- package/dist/tests/page-runner/framework-page.js +12 -0
- package/dist/tests/page-runner/framework-queue.js +344 -0
- package/dist/tests/page-runner/framework-trace.js +458 -0
- package/dist/tests/page-runner/framework-validation.js +44 -0
- package/dist/tests/page-runner/framework.js +7 -0
- package/dist/tests/page-runner/inspector-endpoint-receipt.js +308 -0
- package/dist/tests/page-runner/inspector-endpoint.js +34 -0
- package/dist/tests/page-runner/inspector-plist.js +300 -0
- package/dist/tests/page-runner/inspector-stream.js +99 -0
- package/dist/tests/page-runner/owned-consumers.js +34 -0
- package/dist/tests/page-runner/protocol.js +183 -0
- package/dist/tests/page-runner/report-chunks.js +124 -0
- package/dist/tests/page-runner/report-control.js +7 -0
- package/dist/tests/page-runner/report-stream.js +9 -0
- package/dist/tests/page-runner/result-file.js +15 -0
- package/dist/tests/page-runner/safari-console.js +32 -0
- package/dist/tests/page-runner/safari-driver.js +614 -0
- package/dist/tests/page-runner/safari-observer.js +552 -0
- package/dist/tests/page-runner/service-worker-page.js +93 -0
- package/dist/tests/page-runner/stall-diagnostics.js +506 -0
- package/dist/thread/entry.js +108 -0
- package/dist/thread/guest-bootstrap.js +8 -0
- package/dist/thread/guest-imports.js +272 -0
- package/dist/thread/guest-module.js +4 -0
- package/dist/thread/guest-worker.js +120 -0
- package/dist/thread/lane.js +419 -0
- package/dist/thread/protocol.js +0 -0
- package/dist/thread/runtime-owner.js +561 -0
- package/dist/thread/runtime-protocol.js +0 -0
- package/dist/thread/service-worker.js +81 -0
- package/dist/thread/service.js +396 -0
- package/dist/tooling/program/program-build-tools.js +341 -0
- package/dist/tooling/program/program-build-tools.ts +440 -0
- package/dist/tooling/program/program-derivation.js +102 -0
- package/dist/tooling/program/program-derivation.ts +175 -0
- package/dist/tooling/program/program-optimize.js +246 -0
- package/dist/tooling/program/program-optimize.ts +330 -0
- package/dist/tooling/program/program-transformer.json +1 -0
- package/fs/backend.ts +1111 -0
- package/fs/checkpoint-pressure.ts +102 -0
- package/fs/cleanup.ts +13 -0
- package/fs/client.ts +2283 -0
- package/fs/directory-pages.ts +177 -0
- package/fs/dirty-admission.ts +216 -0
- package/fs/file-identity.ts +175 -0
- package/fs/glob.ts +142 -0
- package/fs/guest-watch.ts +217 -0
- package/fs/identity-allocation.ts +41 -0
- package/fs/idle-database.ts +130 -0
- package/fs/idle-owner.ts +353 -0
- package/fs/idle-walk.ts +126 -0
- package/fs/idle-workspace.ts +88 -0
- package/fs/index.ts +79 -0
- package/fs/indexeddb-chunks.ts +180 -0
- package/fs/indexeddb.ts +1709 -0
- package/fs/memory-admission.ts +19 -0
- package/fs/memory-budget.ts +753 -0
- package/fs/memory.ts +1262 -0
- package/fs/namespace-cursor.ts +260 -0
- package/fs/namespace-projection-memory-budget.ts +58 -0
- package/fs/namespace-projection-owner.ts +149 -0
- package/fs/namespace-projection-table.ts +723 -0
- package/fs/opfs.ts +914 -0
- package/fs/persisted-tree.ts +43 -0
- package/fs/persistent.ts +934 -0
- package/fs/protocol.ts +573 -0
- package/fs/publication-attachment.ts +1269 -0
- package/fs/publication-grant.ts +651 -0
- package/fs/publication-internal.ts +96 -0
- package/fs/publication-memory-budget.ts +77 -0
- package/fs/publication-workspace.ts +242 -0
- package/fs/publication.ts +1820 -0
- package/fs/request-memory.ts +883 -0
- package/fs/resolve-observation.ts +25 -0
- package/fs/root-construction.ts +101 -0
- package/fs/root-memory-budget.ts +64 -0
- package/fs/safe-staging.ts +757 -0
- package/fs/section.ts +42 -0
- package/fs/service.ts +2222 -0
- package/fs/shared-capacity.ts +7 -0
- package/fs/shared-version-pages.ts +59 -0
- package/fs/shared.ts +2454 -0
- package/fs/startup.ts +64 -0
- package/fs/storage-geometry.ts +37 -0
- package/fs/storage-maintenance.ts +95 -0
- package/fs/storage.ts +435 -0
- package/fs/utf8-size.ts +23 -0
- package/fs/vfs-format.ts +3 -0
- package/fs/vfs-internal.ts +10 -0
- package/fs/vfs.ts +203 -0
- package/fs/walk.ts +416 -0
- package/fs/watch-account.ts +312 -0
- package/fs/watch-arena.ts +58 -0
- package/fs/watch-capture.ts +79 -0
- package/fs/watch-id-index.ts +145 -0
- package/fs/watch-index.ts +313 -0
- package/fs/watch-names.ts +139 -0
- package/fs/watch-ring.ts +187 -0
- package/fs/watch-routing.ts +51 -0
- package/fs/watch-service.ts +269 -0
- package/fs/watch-subscriptions.ts +393 -0
- package/fs/watch.ts +81 -0
- package/fs/workspace-archive.ts +721 -0
- package/fs/workspace-export.ts +389 -0
- package/fs/workspace-import-admission.ts +157 -0
- package/fs/workspace-index.ts +16 -0
- package/fs/workspace-namespace.ts +96 -0
- package/fs/workspace-protocol.ts +371 -0
- package/fs/workspace-read.ts +652 -0
- package/fs/workspace-search.ts +788 -0
- package/fs/workspace-stream.ts +274 -0
- package/fs/workspace-types.ts +195 -0
- package/fs/workspace.ts +639 -0
- package/group/member.ts +424 -0
- package/group/protocol.ts +83 -0
- package/group/ranges.ts +51 -0
- package/group/state.ts +1128 -0
- package/index.ts +156 -0
- package/interrupt/admitted-store.ts +245 -0
- package/interrupt/check.ts +15 -0
- package/interrupt/index.ts +3 -0
- package/interrupt/loader-internal.ts +333 -0
- package/interrupt/loader.ts +17 -0
- package/interrupt/rewriter-internal.ts +971 -0
- package/interrupt/rewriter.ts +13 -0
- package/interrupt/wait.ts +111 -0
- package/link/code.ts +145 -0
- package/link/group.ts +396 -0
- package/link/image.ts +124 -0
- package/link/index.ts +12 -0
- package/link/issuance.ts +20 -0
- package/link/metadata.ts +586 -0
- package/link/plan.ts +369 -0
- package/link/relay.ts +80 -0
- package/link/worker.ts +53 -0
- package/memory/allocator.ts +20 -0
- package/memory/control.ts +87 -0
- package/memory/declarations.ts +296 -0
- package/memory/graphics-retention.ts +14 -0
- package/memory/index.ts +21 -0
- package/memory/platform.ts +94 -0
- package/memory/reservations.ts +1421 -0
- package/network/Cargo.toml +26 -0
- package/network/src/abi.rs +100 -0
- package/network/src/lib.rs +440 -0
- package/network/src/module.rs +329 -0
- package/network/src/native.rs +395 -0
- package/network/src/queue.rs +29 -0
- package/network/src/virtual_net.rs +467 -0
- package/network/tests/host_abi.rs +66 -0
- package/network/tests/module.rs +627 -0
- package/network/tests/state.rs +258 -0
- package/network/tests/support/mod.rs +56 -0
- package/network/tests/transport.rs +220 -0
- package/network/tests/virtual.rs +174 -0
- package/package.json +703 -4
- package/patches/wasi-libc/preopen-scan.patch +24 -0
- package/prepare.ts +26 -0
- package/proc/abi.ts +1013 -0
- package/proc/access.ts +21 -0
- package/proc/admission.ts +70 -0
- package/proc/command-runner.ts +131 -0
- package/proc/command-stdio.ts +199 -0
- package/proc/command-transfer.ts +96 -0
- package/proc/command.ts +53 -0
- package/proc/control.ts +198 -0
- package/proc/directory.ts +937 -0
- package/proc/errors.ts +20 -0
- package/proc/exec.ts +46 -0
- package/proc/filesystem-codec.ts +79 -0
- package/proc/identity.ts +55 -0
- package/proc/index.ts +116 -0
- package/proc/intrinsics/core.ts +81 -0
- package/proc/intrinsics/host.ts +346 -0
- package/proc/intrinsics.ts +99 -0
- package/proc/node-wasi.ts +397 -0
- package/proc/observation.ts +293 -0
- package/proc/outcome.ts +276 -0
- package/proc/pipes.ts +1579 -0
- package/proc/registry.ts +556 -0
- package/proc/signals.ts +247 -0
- package/proc/start-command.ts +157 -0
- package/proc/start-diagnostic.ts +109 -0
- package/proc/start-errno.ts +25 -0
- package/proc/start-failure.ts +49 -0
- package/proc/stub.ts +28 -0
- package/proc/supervisor.ts +1877 -0
- package/proc/table.ts +343 -0
- package/proc/terminal-lifetime.ts +125 -0
- package/proc/terminal-turn.ts +62 -0
- package/proc/types.ts +200 -0
- package/proc/wait-status.ts +5 -0
- package/proc/worker-access.ts +143 -0
- package/proc/worker-broker.ts +1086 -0
- package/proc/worker-client.ts +1186 -0
- package/proc/worker-pipes.ts +212 -0
- package/programs/catalog.ts +44 -0
- package/programs/collection.ts +353 -0
- package/programs/download.ts +92 -0
- package/programs/index.ts +584 -0
- package/runtime.ts +1103 -0
- package/rust-toolchain.toml +5 -0
- package/scripts/browser-command.ts +34 -0
- package/scripts/browser-supervisor.ts +158 -0
- package/scripts/build-c-thread-fixture.ts +430 -0
- package/scripts/build-gpu-fixture.ts +279 -0
- package/scripts/build-memory-group-fixture.ts +147 -0
- package/scripts/build-thread-fixture.ts +205 -0
- package/scripts/build-wasi-libc.sh +87 -0
- package/scripts/c-threads-fixture-producer.test.ts +86 -0
- package/scripts/owned-command.ts +89 -0
- package/scripts/test-browser.ts +129 -0
- package/scripts/test-wasi-libc.ts +108 -0
- package/scripts/threads-fixture-producer.test.ts +177 -0
- package/search/engine.ts +363 -0
- package/search/format.ts +102 -0
- package/search/index.ts +11 -0
- package/search/matcher.ts +134 -0
- package/search/paths.ts +11 -0
- package/search/search-worker.ts +6 -0
- package/search/shard-worker.ts +115 -0
- package/search/shards.ts +683 -0
- package/search/types.ts +46 -0
- package/tests/aggregate-memory-contract.test.ts +620 -0
- package/tests/asset-load-recovery-browser-runner.ts +179 -0
- package/tests/asset-load-recovery.test.ts +117 -0
- package/tests/blocking-read-lock-contention.test.ts +305 -0
- package/tests/bootstrap-arrival-browser-runner.ts +19 -0
- package/tests/bootstrap-arrival-runner.test.ts +89 -0
- package/tests/browser-command-real.test.ts +124 -0
- package/tests/browser-command.test.ts +342 -0
- package/tests/browser-controls-discovery.test.ts +56 -0
- package/tests/browser-filesystem-cancel.test.ts +248 -0
- package/tests/browser-filesystem-disposal.test.ts +469 -0
- package/tests/browser-filesystem-failure.test.ts +74 -0
- package/tests/browser-filesystem-options.test.ts +190 -0
- package/tests/browser-filesystem-service-port.test.ts +239 -0
- package/tests/browser-matrix.test.ts +605 -0
- package/tests/browser-navigation-browser-runner.ts +121 -0
- package/tests/browser-navigation.test.ts +106 -0
- package/tests/browser-navigation.ts +49 -0
- package/tests/browser-net-services.test.ts +472 -0
- package/tests/browser-net.test.ts +310 -0
- package/tests/browser-process-broker.test.ts +4172 -0
- package/tests/browser-runner-lifecycle.test.ts +200 -0
- package/tests/browser-runner-lifecycle.ts +328 -0
- package/tests/browser-worker.test.ts +2736 -0
- package/tests/buffer-boundaries.test.ts +52 -0
- package/tests/c-threads-embedding-runner.ts +84 -0
- package/tests/c-threads-fixture-inspect.ts +23 -0
- package/tests/c-threads-fixture.test.ts +142 -0
- package/tests/c-threads-packet-runner.ts +6 -0
- package/tests/c-threads-packet.ts +132 -0
- package/tests/c-threads-paths.test.ts +83 -0
- package/tests/c-threads-positive-worker.ts +5 -0
- package/tests/c-threads-runtime-browser-runner.ts +122 -0
- package/tests/c-threads-runtime-browser.ts +334 -0
- package/tests/c-threads-runtime-guest.ts +14 -0
- package/tests/c-threads-runtime.test.ts +68 -0
- package/tests/c-threads-safari-runner.ts +178 -0
- package/tests/checkpoint-failure-browser.ts +97 -0
- package/tests/checkpoint-pressure.test.ts +602 -0
- package/tests/child-diagnostic-browser.ts +166 -0
- package/tests/child-diagnostic-worker.ts +25 -0
- package/tests/child-diagnostics.test.ts +114 -0
- package/tests/ci-browser-install.test.ts +244 -0
- package/tests/cold-descriptor-lifecycle.test.ts +170 -0
- package/tests/cold-descriptor-read.test.ts +245 -0
- package/tests/command-input.test.ts +40 -0
- package/tests/command-scope.test.ts +422 -0
- package/tests/core-import-boundaries.test.ts +92 -0
- package/tests/core-size-contract.test.ts +327 -0
- package/tests/default-allocation-parity.test.ts +184 -0
- package/tests/descendant-preparation.test.ts +726 -0
- package/tests/descendant-real-worker.test.ts +505 -0
- package/tests/descriptors.test.ts +71 -0
- package/tests/dev-null.test.ts +157 -0
- package/tests/diagnostic-drain.test.ts +62 -0
- package/tests/dirty-admission.test.ts +572 -0
- package/tests/durable-file-identity.test.ts +586 -0
- package/tests/durable-identity-storage.test.ts +112 -0
- package/tests/error-serialization.test.ts +94 -0
- package/tests/error-serialization.ts +34 -0
- package/tests/exec-integration.test.ts +94 -0
- package/tests/fd-reopen.test.ts +4 -0
- package/tests/file-offset-contention.test.ts +186 -0
- package/tests/file-times.test.ts +353 -0
- package/tests/filesystem-allocation-context.test.ts +198 -0
- package/tests/filesystem-atomic.test.ts +564 -0
- package/tests/filesystem-capacity.test.ts +34 -0
- package/tests/filesystem-client-intrinsics.test.ts +288 -0
- package/tests/filesystem-codec.test.ts +227 -0
- package/tests/filesystem-conditional-remove.test.ts +200 -0
- package/tests/filesystem-endpoint-observer.test.ts +371 -0
- package/tests/filesystem-glob.test.ts +38 -0
- package/tests/filesystem-io-fastpath.test.ts +339 -0
- package/tests/filesystem-large-file.test.ts +61 -0
- package/tests/filesystem-lazy-backing.test.ts +440 -0
- package/tests/filesystem-nonblocking.test.ts +339 -0
- package/tests/filesystem-permissions.test.ts +348 -0
- package/tests/filesystem-persistence-shared.test.ts +375 -0
- package/tests/filesystem-port-transport.test.ts +275 -0
- package/tests/filesystem-private-input.test.ts +1155 -0
- package/tests/filesystem-publication-grant.test.ts +674 -0
- package/tests/filesystem-publication-workspace.test.ts +2105 -0
- package/tests/filesystem-publication.test.ts +1774 -0
- package/tests/filesystem-quiescence-rearm.test.ts +76 -0
- package/tests/filesystem-quiescence.test.ts +522 -0
- package/tests/filesystem-readlink-shared.test.ts +311 -0
- package/tests/filesystem-ready-disposal-browser-runner.ts +243 -0
- package/tests/filesystem-refcount.test.ts +552 -0
- package/tests/filesystem-request-memory.test.ts +202 -0
- package/tests/filesystem-request-pool.test.ts +408 -0
- package/tests/filesystem-resolve-observation.test.ts +185 -0
- package/tests/filesystem-retired-release.test.ts +37 -0
- package/tests/filesystem-review.test.ts +284 -0
- package/tests/filesystem-segment.test.ts +339 -0
- package/tests/filesystem-shared.test.ts +304 -0
- package/tests/filesystem-shutdown-browser-debt.ts +267 -0
- package/tests/filesystem-shutdown-browser-runner.ts +524 -0
- package/tests/filesystem-shutdown-browser.ts +290 -0
- package/tests/filesystem-shutdown-close-observation.test.ts +437 -0
- package/tests/filesystem-shutdown-close-observation.ts +206 -0
- package/tests/filesystem-shutdown-observer.test.ts +93 -0
- package/tests/filesystem-shutdown.test.ts +893 -0
- package/tests/filesystem-staged-write.test.ts +909 -0
- package/tests/filesystem-stop-observer.ts +50 -0
- package/tests/filesystem-storage-geometry.test.ts +404 -0
- package/tests/filesystem-transfer.test.ts +135 -0
- package/tests/filesystem-transport-browser-driver.ts +28 -0
- package/tests/filesystem-transport-browser-runner.ts +134 -0
- package/tests/filesystem-transport-browser.ts +179 -0
- package/tests/filesystem-transport-codec.test.ts +96 -0
- package/tests/filesystem-walk.test.ts +524 -0
- package/tests/filesystem-worker.test.ts +676 -0
- package/tests/first-worker-import.ts +118 -0
- package/tests/fixtures/asset-load-recovery-page.ts +95 -0
- package/tests/fixtures/bigint-hooks.ts +28 -0
- package/tests/fixtures/browser-cell-clone.ts +100 -0
- package/tests/fixtures/browser-process-child.ts +25 -0
- package/tests/fixtures/buffer-boundaries.ts +65 -0
- package/tests/fixtures/cold-descriptor-guest.ts +58 -0
- package/tests/fixtures/cold-descriptor.ts +162 -0
- package/tests/fixtures/cold-range-proof-lifecycle.ts +136 -0
- package/tests/fixtures/command-bounded-admission.ts +31 -0
- package/tests/fixtures/command-disposal.ts +47 -0
- package/tests/fixtures/command-guests.ts +123 -0
- package/tests/fixtures/default-allocation-capture.ts +239 -0
- package/tests/fixtures/descendant-real-worker.ts +121 -0
- package/tests/fixtures/diagnostic-public.ts +14 -0
- package/tests/fixtures/documented-startup-control.ts +33 -0
- package/tests/fixtures/durable-identity-opfs.ts +123 -0
- package/tests/fixtures/exec-browser-worker.ts +5 -0
- package/tests/fixtures/exec-guest.ts +279 -0
- package/tests/fixtures/exec-integration.ts +305 -0
- package/tests/fixtures/exec-node-control.ts +22 -0
- package/tests/fixtures/exec-node-host.ts +31 -0
- package/tests/fixtures/exec-node-worker.ts +11 -0
- package/tests/fixtures/exec-worker.ts +33 -0
- package/tests/fixtures/fd-kind-cases.ts +81 -0
- package/tests/fixtures/fd-reopen-cases.ts +489 -0
- package/tests/fixtures/file-offset-contention.ts +110 -0
- package/tests/fixtures/file-only-abi.ts +48 -0
- package/tests/fixtures/file-times-guest.ts +151 -0
- package/tests/fixtures/file-times-storage.ts +76 -0
- package/tests/fixtures/file-times-worker.ts +16 -0
- package/tests/fixtures/file-times.ts +16 -0
- package/tests/fixtures/filesystem-atomic-guest.ts +94 -0
- package/tests/fixtures/filesystem-default-service.ts +3 -0
- package/tests/fixtures/filesystem-diagnostic-transfer-failure.ts +15 -0
- package/tests/fixtures/filesystem-endpoint-observer.ts +159 -0
- package/tests/fixtures/filesystem-endpoint-service.ts +53 -0
- package/tests/fixtures/filesystem-file.ts +23 -0
- package/tests/fixtures/filesystem-guest.ts +119 -0
- package/tests/fixtures/filesystem-host.ts +47 -0
- package/tests/fixtures/filesystem-offset-guest.ts +48 -0
- package/tests/fixtures/filesystem-permissions-worker.ts +44 -0
- package/tests/fixtures/filesystem-port-service.ts +32 -0
- package/tests/fixtures/filesystem-port-worker.ts +71 -0
- package/tests/fixtures/filesystem-proc-guest.ts +59 -0
- package/tests/fixtures/filesystem-quiescence-guest.ts +23 -0
- package/tests/fixtures/filesystem-refcount-guest.ts +75 -0
- package/tests/fixtures/filesystem-request-release-worker.ts +32 -0
- package/tests/fixtures/filesystem-segment-guest.ts +46 -0
- package/tests/fixtures/filesystem-service.ts +17 -0
- package/tests/fixtures/filesystem-shutdown-debt-page.ts +178 -0
- package/tests/fixtures/filesystem-shutdown-debt-worker.ts +116 -0
- package/tests/fixtures/filesystem-shutdown-page.ts +288 -0
- package/tests/fixtures/filesystem-shutdown-worker.ts +168 -0
- package/tests/fixtures/filesystem-startup-failure.ts +24 -0
- package/tests/fixtures/filesystem-transport-observation-worker.ts +5 -0
- package/tests/fixtures/filesystem-walk-worker.ts +45 -0
- package/tests/fixtures/generic-memory-node-worker.ts +16 -0
- package/tests/fixtures/global-lock-holder.ts +55 -0
- package/tests/fixtures/gpu/async-expected.json +506 -0
- package/tests/fixtures/gpu/async-host.ts +263 -0
- package/tests/fixtures/gpu/async-native.ts +507 -0
- package/tests/fixtures/gpu/async-page.ts +193 -0
- package/tests/fixtures/gpu/async.c +463 -0
- package/tests/fixtures/gpu/async_encode.h +170 -0
- package/tests/fixtures/gpu/bootstrap-cleanup-worker.ts +135 -0
- package/tests/fixtures/gpu/bundle-query-expected.json +400 -0
- package/tests/fixtures/gpu/bundle-query-fixture.ts +121 -0
- package/tests/fixtures/gpu/bundle-query-native.ts +674 -0
- package/tests/fixtures/gpu/compute-expected.json +187 -0
- package/tests/fixtures/gpu/compute-native.ts +418 -0
- package/tests/fixtures/gpu/copy-draw-expected.json +372 -0
- package/tests/fixtures/gpu/copy-draw-fixture.ts +82 -0
- package/tests/fixtures/gpu/copy-draw-native.ts +690 -0
- package/tests/fixtures/gpu/core-fixture.ts +202 -0
- package/tests/fixtures/gpu/core-transport-worker.ts +76 -0
- package/tests/fixtures/gpu/desktop-arm-contract.ts +180 -0
- package/tests/fixtures/gpu/desktop-fairness-contract.ts +99 -0
- package/tests/fixtures/gpu/desktop-fairness-observation.ts +79 -0
- package/tests/fixtures/gpu/disposal-retirement.ts +21 -0
- package/tests/fixtures/gpu/enums.json +46 -0
- package/tests/fixtures/gpu/expected.json +251 -0
- package/tests/fixtures/gpu/fairness-observer.ts +504 -0
- package/tests/fixtures/gpu/fairness-test-data.ts +164 -0
- package/tests/fixtures/gpu/fairness-validation.ts +325 -0
- package/tests/fixtures/gpu/fixture-runtime.ts +48 -0
- package/tests/fixtures/gpu/gpu_encode.h +236 -0
- package/tests/fixtures/gpu/gpu_fixture.h +237 -0
- package/tests/fixtures/gpu/import-unwind.ts +12 -0
- package/tests/fixtures/gpu/integration-guest.ts +244 -0
- package/tests/fixtures/gpu/integration-page.ts +805 -0
- package/tests/fixtures/gpu/integration-service-worker.ts +113 -0
- package/tests/fixtures/gpu/label-expected.json +219 -0
- package/tests/fixtures/gpu/label-native.ts +280 -0
- package/tests/fixtures/gpu/lazy-page.ts +39 -0
- package/tests/fixtures/gpu/measurement-contract.ts +148 -0
- package/tests/fixtures/gpu/measurement-desktop.ts +121 -0
- package/tests/fixtures/gpu/measurement-page.ts +347 -0
- package/tests/fixtures/gpu/measurement-runtime.ts +82 -0
- package/tests/fixtures/gpu/measurement-worker.ts +310 -0
- package/tests/fixtures/gpu/ownership-reader-terminal-worker.ts +42 -0
- package/tests/fixtures/gpu/ownership-service-worker.ts +920 -0
- package/tests/fixtures/gpu/peer-input.ts +6 -0
- package/tests/fixtures/gpu/qualification-contract.ts +42 -0
- package/tests/fixtures/gpu/qualification-page.ts +67 -0
- package/tests/fixtures/gpu/qualification-webgpu.ts +199 -0
- package/tests/fixtures/gpu/qualification-worker.ts +97 -0
- package/tests/fixtures/gpu/ring-snapshot.ts +25 -0
- package/tests/fixtures/gpu/ring-worker.ts +227 -0
- package/tests/fixtures/gpu/runtime-display-fence-launcher.ts +16 -0
- package/tests/fixtures/gpu/runtime-display-fence.ts +193 -0
- package/tests/fixtures/gpu/runtime-disposal-signal-order.ts +195 -0
- package/tests/fixtures/gpu/runtime-disposal-signal-worker.ts +79 -0
- package/tests/fixtures/gpu/scene-expected.json +360 -0
- package/tests/fixtures/gpu/scene-fixture.ts +73 -0
- package/tests/fixtures/gpu/scene-native.ts +473 -0
- package/tests/fixtures/gpu/scene.c +73 -0
- package/tests/fixtures/gpu/scene_encode.h +302 -0
- package/tests/fixtures/gpu/service-access.ts +39 -0
- package/tests/fixtures/gpu/service-bootstrap-worker.ts +10 -0
- package/tests/fixtures/gpu/service-reader-worker.ts +29 -0
- package/tests/fixtures/gpu/thrown-observation.ts +120 -0
- package/tests/fixtures/gpu/triangle.c +480 -0
- package/tests/fixtures/gpu/waffle_gpu_stream.h +2046 -0
- package/tests/fixtures/group-futex-worker.ts +102 -0
- package/tests/fixtures/group-link-program.ts +18 -0
- package/tests/fixtures/guarded-nonblock-worker.ts +37 -0
- package/tests/fixtures/guest-watch-runtime-worker.ts +115 -0
- package/tests/fixtures/guest-watch-worker.ts +41 -0
- package/tests/fixtures/guest-watch-writer-worker.ts +46 -0
- package/tests/fixtures/host-failure-worker.ts +17 -0
- package/tests/fixtures/indexeddb-background-confirmation.ts +33 -0
- package/tests/fixtures/indexeddb-caller-delivery.ts +100 -0
- package/tests/fixtures/installer-symlinks-support.ts +25 -0
- package/tests/fixtures/interrupt-browser-loops.ts +78 -0
- package/tests/fixtures/interrupt-browser-worker.ts +104 -0
- package/tests/fixtures/interrupt-browser-workload.ts +17 -0
- package/tests/fixtures/interrupt-dom-consumer.ts +9 -0
- package/tests/fixtures/interrupt-wait-wasm.ts +108 -0
- package/tests/fixtures/interrupt-wait-worker.ts +61 -0
- package/tests/fixtures/intrinsics.ts +114 -0
- package/tests/fixtures/isolated-process.ts +98 -0
- package/tests/fixtures/lazy-backing-constructions.ts +117 -0
- package/tests/fixtures/lazy-backing-guest.ts +219 -0
- package/tests/fixtures/lazy-backing.ts +226 -0
- package/tests/fixtures/link-initialization-worker.ts +112 -0
- package/tests/fixtures/link-initialization.ts +169 -0
- package/tests/fixtures/link-member-workers.ts +73 -0
- package/tests/fixtures/link-relay-program.ts +76 -0
- package/tests/fixtures/link-relay-worker.ts +77 -0
- package/tests/fixtures/linked-nested-node-worker.ts +50 -0
- package/tests/fixtures/logical-process-context-guest.ts +37 -0
- package/tests/fixtures/memory-group-abi-worker.ts +108 -0
- package/tests/fixtures/memory-group-member.c +215 -0
- package/tests/fixtures/memory-group-pie.ts +46 -0
- package/tests/fixtures/memory-group-wake-worker.ts +14 -0
- package/tests/fixtures/memory-group-worker.ts +18 -0
- package/tests/fixtures/memory-observation-guest.ts +90 -0
- package/tests/fixtures/metadata-completion-observer-worker.ts +13 -0
- package/tests/fixtures/metadata-enumeration-r173-service.ts +71 -0
- package/tests/fixtures/metadata-enumeration-r173-store.ts +51 -0
- package/tests/fixtures/metadata-enumeration-r173-wasi.ts +168 -0
- package/tests/fixtures/metadata-enumeration-r173-worker.ts +68 -0
- package/tests/fixtures/navigation-wire-child.ts +134 -0
- package/tests/fixtures/nested-wasi.ts +260 -0
- package/tests/fixtures/network-fence-script.ts +46 -0
- package/tests/fixtures/network-hook-positions.json +16 -0
- package/tests/fixtures/network-original-nodes.json +149 -0
- package/tests/fixtures/node-wasi-descriptors.ts +203 -0
- package/tests/fixtures/node-worker-transfers.ts +11 -0
- package/tests/fixtures/notification-collecting-worker.ts +7 -0
- package/tests/fixtures/notification-controlled-relay.ts +57 -0
- package/tests/fixtures/notification-deadline-worker.ts +128 -0
- package/tests/fixtures/notification-mixed-worker.ts +215 -0
- package/tests/fixtures/notification-probed-worker.ts +53 -0
- package/tests/fixtures/notification-reject-worker.ts +7 -0
- package/tests/fixtures/notification-runtime-worker.ts +55 -0
- package/tests/fixtures/notification-send-failure-worker.ts +60 -0
- package/tests/fixtures/notification-stalled-worker.ts +5 -0
- package/tests/fixtures/notification-traffic-worker.ts +71 -0
- package/tests/fixtures/operation-fs-worker.ts +114 -0
- package/tests/fixtures/operation-observer-worker.ts +41 -0
- package/tests/fixtures/operation-page.ts +522 -0
- package/tests/fixtures/opfs-close-page.ts +94 -0
- package/tests/fixtures/opfs-close-worker.ts +565 -0
- package/tests/fixtures/opfs-range-storage.ts +285 -0
- package/tests/fixtures/owned-job-root-worker.ts +84 -0
- package/tests/fixtures/owned-job-wait-worker.ts +56 -0
- package/tests/fixtures/owner-freeze-guest.ts +81 -0
- package/tests/fixtures/owner-freeze-owner.ts +77 -0
- package/tests/fixtures/page-root-client.ts +33 -0
- package/tests/fixtures/permissions-guest.ts +55 -0
- package/tests/fixtures/permissions-storage.ts +97 -0
- package/tests/fixtures/persistent-authority-observer.ts +27 -0
- package/tests/fixtures/persistent-lifecycle-r2-owner.ts +149 -0
- package/tests/fixtures/persistent-ready.ts +34 -0
- package/tests/fixtures/pipe-filestat-guest.ts +101 -0
- package/tests/fixtures/pipe-filestat-worker.ts +36 -0
- package/tests/fixtures/pipe-reuse-worker.ts +41 -0
- package/tests/fixtures/pipes-intrinsics.ts +63 -0
- package/tests/fixtures/preopen-guest.c +44 -0
- package/tests/fixtures/preopen-node-host.ts +13 -0
- package/tests/fixtures/prepared-program-loading-control.ts +42 -0
- package/tests/fixtures/prepared-runtime-control.ts +80 -0
- package/tests/fixtures/preview-wire-headers-page.ts +84 -0
- package/tests/fixtures/preview1-entry.ts +1 -0
- package/tests/fixtures/preview1-listener.wat +44 -0
- package/tests/fixtures/preview1-relay.wat +24 -0
- package/tests/fixtures/preview1-socket-imports.wat +36 -0
- package/tests/fixtures/preview1-socket-unknown.wat +4 -0
- package/tests/fixtures/preview1-socket-worker.ts +72 -0
- package/tests/fixtures/preview1-socket.c +58 -0
- package/tests/fixtures/preview1-socket.wat +19 -0
- package/tests/fixtures/private-authority-cases.ts +260 -0
- package/tests/fixtures/process-abi-guest.ts +67 -0
- package/tests/fixtures/process-abi-poll-guest.ts +84 -0
- package/tests/fixtures/process-cell-clone.ts +520 -0
- package/tests/fixtures/process-context-guest.ts +22 -0
- package/tests/fixtures/process-filesystem.ts +34 -0
- package/tests/fixtures/process-intrinsics.ts +360 -0
- package/tests/fixtures/process-lookup.ts +6 -0
- package/tests/fixtures/process-observation-acquisition-worker.ts +68 -0
- package/tests/fixtures/process-observation-controls.ts +15 -0
- package/tests/fixtures/process-observation-worker.ts +72 -0
- package/tests/fixtures/process-poll-start-failure.ts +68 -0
- package/tests/fixtures/process-root-navigation-original-bun-lock.txt +333 -0
- package/tests/fixtures/process-root-navigation-original-runner.txt +378 -0
- package/tests/fixtures/process-start-worker.ts +32 -0
- package/tests/fixtures/program-shell.ts +86 -0
- package/tests/fixtures/publication-channel-observer.ts +144 -0
- package/tests/fixtures/publication-cleanup-failure.ts +16 -0
- package/tests/fixtures/publication-guest.ts +296 -0
- package/tests/fixtures/publication-launch-close.ts +61 -0
- package/tests/fixtures/publication-resident-authority.ts +464 -0
- package/tests/fixtures/publication-resident-guest.ts +331 -0
- package/tests/fixtures/publication-storage.ts +30 -0
- package/tests/fixtures/publication-wasm.ts +103 -0
- package/tests/fixtures/readlink-service.ts +19 -0
- package/tests/fixtures/recovery-r42-owner.ts +49 -0
- package/tests/fixtures/recovery-r42-page.ts +67 -0
- package/tests/fixtures/reservation-waste-worker.ts +16 -0
- package/tests/fixtures/resident-memory.ts +11 -0
- package/tests/fixtures/retained-client.ts +26 -0
- package/tests/fixtures/root-return-gc.ts +121 -0
- package/tests/fixtures/running-member-wasm.ts +55 -0
- package/tests/fixtures/running-member-worker.ts +50 -0
- package/tests/fixtures/runtime-filesystem-close-debt.ts +142 -0
- package/tests/fixtures/runtime-stop-control.ts +229 -0
- package/tests/fixtures/search-count-worker.ts +265 -0
- package/tests/fixtures/search-fault-shard.ts +21 -0
- package/tests/fixtures/search-program-fs-worker.ts +34 -0
- package/tests/fixtures/shared-caller-debt-control.ts +13 -0
- package/tests/fixtures/shared-caller-exec-worker.ts +119 -0
- package/tests/fixtures/shared-caller-exec.ts +597 -0
- package/tests/fixtures/shared-caller-host-failure-control.ts +92 -0
- package/tests/fixtures/shared-memory-platform.ts +6 -0
- package/tests/fixtures/socket-admission-relay.ts +114 -0
- package/tests/fixtures/spawn-diagnostic-guest.ts +44 -0
- package/tests/fixtures/spawn-request.ts +14 -0
- package/tests/fixtures/stable-memory-grow-worker.ts +10 -0
- package/tests/fixtures/stable-memory-reader.ts +253 -0
- package/tests/fixtures/standalone-runtime-process.ts +19 -0
- package/tests/fixtures/start-failure-public.ts +8 -0
- package/tests/fixtures/start-failure-quiet-worker.ts +54 -0
- package/tests/fixtures/startup-diagnostic-request.ts +8 -0
- package/tests/fixtures/startup-diagnostic-worker.ts +62 -0
- package/tests/fixtures/startup-pool-worker.ts +19 -0
- package/tests/fixtures/stop-order-wasm.ts +60 -0
- package/tests/fixtures/stop-order-worker.ts +11 -0
- package/tests/fixtures/storage-lifecycle-fs-prelude.ts +15 -0
- package/tests/fixtures/storage-lifecycle-fs-worker.ts +2 -0
- package/tests/fixtures/storage-lock-startup.ts +70 -0
- package/tests/fixtures/storage-maintenance.ts +16 -0
- package/tests/fixtures/symlink-sizing-probe.ts +59 -0
- package/tests/fixtures/terminal-control-worker.ts +150 -0
- package/tests/fixtures/terminal-input-pause.ts +30 -0
- package/tests/fixtures/terminal-input-producer.ts +18 -0
- package/tests/fixtures/terminal-mode-worker.ts +58 -0
- package/tests/fixtures/terminal-resolver-worker.ts +92 -0
- package/tests/fixtures/thread-admission-control.ts +294 -0
- package/tests/fixtures/threads-c.c +117 -0
- package/tests/fixtures/threads.rs +140 -0
- package/tests/fixtures/truncate-page-work.ts +32 -0
- package/tests/fixtures/wasi-atomic-host.ts +92 -0
- package/tests/fixtures/wasi-cat.ts +177 -0
- package/tests/fixtures/wasi-nonblock-inherited-worker.ts +34 -0
- package/tests/fixtures/wasi-nonblock-worker.ts +33 -0
- package/tests/fixtures/wasi-nonblock.ts +48 -0
- package/tests/fixtures/wasi-poll-guest.ts +45 -0
- package/tests/fixtures/wasi-write.ts +72 -0
- package/tests/fixtures/wasm-start-section.ts +88 -0
- package/tests/fixtures/watch-delivery-error-worker.ts +4 -0
- package/tests/fixtures/watch-guest.ts +141 -0
- package/tests/fixtures/watch-lifecycle-worker.ts +2 -0
- package/tests/fixtures/watch-startup-error-worker.ts +1 -0
- package/tests/fixtures/worker-pipe-transfer-guest.ts +58 -0
- package/tests/fixtures/workspace-endurance.ts +113 -0
- package/tests/fixtures/workspace-read-claim.ts +41 -0
- package/tests/fixtures/workspace-read.ts +104 -0
- package/tests/fixtures/workspace-recovery.ts +133 -0
- package/tests/fs-socket-attachment-browser.ts +184 -0
- package/tests/fs-socket-browser-runner.ts +35 -0
- package/tests/fs-socket-node.test.ts +123 -0
- package/tests/fs-socket-owner.test.ts +106 -0
- package/tests/fs-socket-scope.test.ts +285 -0
- package/tests/gated-indexeddb.test.ts +16 -0
- package/tests/gated-indexeddb.ts +72 -0
- package/tests/git-install.test.ts +25 -0
- package/tests/gpu-admission-browser.ts +763 -0
- package/tests/gpu-admission-controls.test.ts +592 -0
- package/tests/gpu-asset-paths.test.ts +107 -0
- package/tests/gpu-async-assets.ts +29 -0
- package/tests/gpu-async-browser-runner.ts +20 -0
- package/tests/gpu-async-command.test.ts +249 -0
- package/tests/gpu-async-command.ts +272 -0
- package/tests/gpu-async-desktop.ts +78 -0
- package/tests/gpu-async-fixture.test.ts +252 -0
- package/tests/gpu-async-native.test.ts +38 -0
- package/tests/gpu-async-native.ts +70 -0
- package/tests/gpu-async-output.test.ts +49 -0
- package/tests/gpu-async-payload.test.ts +537 -0
- package/tests/gpu-async-replay.test.ts +656 -0
- package/tests/gpu-async-stream.test.ts +166 -0
- package/tests/gpu-bootstrap-cleanup.test.ts +185 -0
- package/tests/gpu-browser-controls.test.ts +64 -0
- package/tests/gpu-browser-qualification.test.ts +102 -0
- package/tests/gpu-browser-qualification.ts +432 -0
- package/tests/gpu-browser-runner.ts +554 -0
- package/tests/gpu-browser-shared.ts +59 -0
- package/tests/gpu-bundle-query-native.test.ts +8 -0
- package/tests/gpu-bundle-query-native.ts +55 -0
- package/tests/gpu-bundle-query-replay.test.ts +406 -0
- package/tests/gpu-bundle-query-stream.test.ts +97 -0
- package/tests/gpu-ci.test.ts +244 -0
- package/tests/gpu-completions.test.ts +404 -0
- package/tests/gpu-compute-native.test.ts +9 -0
- package/tests/gpu-compute-native.ts +47 -0
- package/tests/gpu-compute-replay.test.ts +363 -0
- package/tests/gpu-compute-stream.test.ts +53 -0
- package/tests/gpu-control-retention.test.ts +202 -0
- package/tests/gpu-copy-draw-native.test.ts +9 -0
- package/tests/gpu-copy-draw-native.ts +71 -0
- package/tests/gpu-copy-draw-replay.test.ts +350 -0
- package/tests/gpu-copy-draw-stream.test.ts +78 -0
- package/tests/gpu-coverage.test.ts +250 -0
- package/tests/gpu-desktop-measure.test.ts +344 -0
- package/tests/gpu-display-retirement.test.ts +213 -0
- package/tests/gpu-display-shutdown.test.ts +180 -0
- package/tests/gpu-disposal-browser.ts +685 -0
- package/tests/gpu-disposal-controls.test.ts +738 -0
- package/tests/gpu-disposal-retirement.test.ts +108 -0
- package/tests/gpu-fairness-browser.ts +273 -0
- package/tests/gpu-fairness-fixture.test.ts +202 -0
- package/tests/gpu-fairness.test.ts +203 -0
- package/tests/gpu-fixture-closed.test.ts +232 -0
- package/tests/gpu-fixture-host.ts +253 -0
- package/tests/gpu-fixture.test.ts +569 -0
- package/tests/gpu-grant-quota-browser.ts +767 -0
- package/tests/gpu-grant-quota-controls.test.ts +525 -0
- package/tests/gpu-grant-retirement.test.ts +413 -0
- package/tests/gpu-import-observation.test.ts +472 -0
- package/tests/gpu-integration.test.ts +479 -0
- package/tests/gpu-label-native.test.ts +8 -0
- package/tests/gpu-label-native.ts +37 -0
- package/tests/gpu-label-replay.test.ts +313 -0
- package/tests/gpu-label-stream.test.ts +135 -0
- package/tests/gpu-launch-retention.test.ts +134 -0
- package/tests/gpu-loading-browser.ts +54 -0
- package/tests/gpu-loading.test.ts +97 -0
- package/tests/gpu-malformed-browser.ts +522 -0
- package/tests/gpu-malformed-controls.test.ts +720 -0
- package/tests/gpu-measure.test.ts +281 -0
- package/tests/gpu-native-browser-runner.ts +48 -0
- package/tests/gpu-native-controls.test.ts +181 -0
- package/tests/gpu-native-controls.ts +117 -0
- package/tests/gpu-ownership-browser.ts +642 -0
- package/tests/gpu-ownership-controls.test.ts +373 -0
- package/tests/gpu-payload-pressure-browser.ts +1142 -0
- package/tests/gpu-payload-pressure-controls.test.ts +974 -0
- package/tests/gpu-payload-settlement.test.ts +323 -0
- package/tests/gpu-peer-input.test.ts +98 -0
- package/tests/gpu-reader-terminal.test.ts +194 -0
- package/tests/gpu-regrant-browser.ts +861 -0
- package/tests/gpu-regrant-controls.test.ts +680 -0
- package/tests/gpu-replay.test.ts +511 -0
- package/tests/gpu-ring-snapshot.test.ts +53 -0
- package/tests/gpu-ring.test.ts +497 -0
- package/tests/gpu-scene-fixture.test.ts +272 -0
- package/tests/gpu-scene-native.test.ts +14 -0
- package/tests/gpu-scene-native.ts +36 -0
- package/tests/gpu-scene-replay.test.ts +678 -0
- package/tests/gpu-scene-stream.test.ts +112 -0
- package/tests/gpu-service-bootstrap.test.ts +61 -0
- package/tests/gpu-service-failure-browser.ts +792 -0
- package/tests/gpu-service-failure-controls.test.ts +1035 -0
- package/tests/gpu-service-failure-ordering.test.ts +105 -0
- package/tests/gpu-service-readers.test.ts +247 -0
- package/tests/gpu-stream.test.ts +338 -0
- package/tests/gpu-surface-transfer.test.ts +855 -0
- package/tests/gpu-transport.test.ts +311 -0
- package/tests/gpu-worker-bundle.test.ts +31 -0
- package/tests/group-futex-browser-runner.ts +150 -0
- package/tests/group-futex-browser.ts +141 -0
- package/tests/group-futex.test.ts +798 -0
- package/tests/guarded-stream-nonblock.test.ts +130 -0
- package/tests/guest-watch-browser-cases.test.ts +24 -0
- package/tests/guest-watch-browser-cases.ts +271 -0
- package/tests/guest-watch-browser-runner.ts +66 -0
- package/tests/host-interface.test.ts +115 -0
- package/tests/host.test.ts +349 -0
- package/tests/http1-buffer-boundaries.test.ts +102 -0
- package/tests/http1-framing-limits.test.ts +419 -0
- package/tests/idle-workspace-browser.ts +350 -0
- package/tests/idle-workspace-cancellation-browser.ts +129 -0
- package/tests/idle-workspace-fixtures.ts +25 -0
- package/tests/idle-workspace-maintenance-browser.ts +271 -0
- package/tests/idle-workspace-metadata-browser.ts +287 -0
- package/tests/imports.test.ts +92 -0
- package/tests/indexeddb-checkpoint-decode-browser.ts +232 -0
- package/tests/indexeddb-checkpoint-decode.test.ts +32 -0
- package/tests/indexeddb-chunks-browser-runner.ts +39 -0
- package/tests/indexeddb-chunks-browser.ts +841 -0
- package/tests/indexeddb-chunks.test.ts +57 -0
- package/tests/indexeddb-publication-browser.ts +458 -0
- package/tests/indexeddb-publication.test.ts +89 -0
- package/tests/indexeddb-storage-browser.ts +1357 -0
- package/tests/inherited-fd-review.test.ts +362 -0
- package/tests/inherited-fd.test.ts +82 -0
- package/tests/installer-symlinks-alias.test.ts +266 -0
- package/tests/installer-symlinks-borrow.test.ts +451 -0
- package/tests/installer-symlinks-codec.test.ts +117 -0
- package/tests/installer-symlinks-creation.test.ts +369 -0
- package/tests/installer-symlinks-final-components.test.ts +392 -0
- package/tests/installer-symlinks-history.test.ts +155 -0
- package/tests/installer-symlinks-metadata-types.ts +32 -0
- package/tests/installer-symlinks-metadata.test.ts +140 -0
- package/tests/installer-symlinks-persistence.test.ts +120 -0
- package/tests/installer-symlinks-readlink.test.ts +444 -0
- package/tests/installer-symlinks-service.test.ts +125 -0
- package/tests/installer-symlinks-tree.test.ts +88 -0
- package/tests/installer-symlinks.test.ts +251 -0
- package/tests/interrupt-admitted-browser-runner.ts +290 -0
- package/tests/interrupt-admitted-browser.ts +167 -0
- package/tests/interrupt-admitted-fixture.ts +44 -0
- package/tests/interrupt-admitted-loader.test.ts +324 -0
- package/tests/interrupt-admitted-store.test.ts +195 -0
- package/tests/interrupt-browser-benchmark.ts +208 -0
- package/tests/interrupt-browser-control.ts +55 -0
- package/tests/interrupt-browser-fixtures.test.ts +40 -0
- package/tests/interrupt-browser-runner-control.ts +52 -0
- package/tests/interrupt-browser-runner.test.ts +125 -0
- package/tests/interrupt-browser.ts +251 -0
- package/tests/interrupt-cache-storage-fixture.ts +58 -0
- package/tests/interrupt-check.test.ts +47 -0
- package/tests/interrupt-loader-cache.test.ts +383 -0
- package/tests/interrupt-loader.test.ts +111 -0
- package/tests/interrupt-rewriter-exports.test.ts +11 -0
- package/tests/interrupt-rewriter.test.ts +740 -0
- package/tests/interrupt-standard-eh.test.ts +293 -0
- package/tests/interrupt-transform-pin.test.ts +16 -0
- package/tests/interrupt-wait-profile.test.ts +126 -0
- package/tests/interrupt-wait.test.ts +328 -0
- package/tests/intrinsics-boundary.test.ts +377 -0
- package/tests/isolated-page-runner.ts +186 -0
- package/tests/libc-tooling.test.ts +313 -0
- package/tests/link-browser-runner.ts +167 -0
- package/tests/link-browser.ts +61 -0
- package/tests/link-initialization.test.ts +344 -0
- package/tests/link-member-workers.test.ts +83 -0
- package/tests/link-program.test.ts +1642 -0
- package/tests/link-quickjs-worker.ts +140 -0
- package/tests/link-quickjs.test.ts +83 -0
- package/tests/link-relay-browser.ts +94 -0
- package/tests/link-shared-basic512-fixture.ts +48 -0
- package/tests/link-shared-basic512.test.ts +129 -0
- package/tests/loopback-fetch-bun-consumer.test.ts +121 -0
- package/tests/loopback-fetch-compression.test.ts +204 -0
- package/tests/loopback-fetch-fixture.ts +128 -0
- package/tests/loopback-fetch-redirect.test.ts +321 -0
- package/tests/loopback-fetch-worker.ts +115 -0
- package/tests/memory-budget.test.ts +952 -0
- package/tests/memory-group-browser-runner.ts +123 -0
- package/tests/memory-group-browser.ts +649 -0
- package/tests/memory-group-cap.test.ts +200 -0
- package/tests/memory-group-exit-lock.test.ts +325 -0
- package/tests/memory-group-grow.test.ts +151 -0
- package/tests/memory-group-link.test.ts +485 -0
- package/tests/memory-group-pin-port.test.ts +170 -0
- package/tests/memory-group-pin.test.ts +275 -0
- package/tests/memory-group-review.test.ts +286 -0
- package/tests/memory-group-stack-worker.ts +94 -0
- package/tests/memory-group-state.test.ts +537 -0
- package/tests/memory-reservations.test.ts +804 -0
- package/tests/memory-views.test.ts +168 -0
- package/tests/metadata-directory-contract-r173.test.ts +307 -0
- package/tests/metadata-nlink-r173.test.ts +201 -0
- package/tests/metadata-readdir-r173.test.ts +126 -0
- package/tests/metadata-worker-completion.test.ts +29 -0
- package/tests/namespace-cursor.test.ts +470 -0
- package/tests/namespace-projection-memory-budget.test.ts +250 -0
- package/tests/namespace-projection-owner.test.ts +880 -0
- package/tests/namespace-projection-table.test.ts +1598 -0
- package/tests/nested-wasi.test.ts +7 -0
- package/tests/net-host-watch.test.ts +236 -0
- package/tests/net-transport-metadata.test.ts +81 -0
- package/tests/network-activation-browser.ts +71 -0
- package/tests/network-address.test.ts +412 -0
- package/tests/network-browser-runner.ts +21 -0
- package/tests/network-browser-service-worker.ts +19 -0
- package/tests/network-browser-worker.ts +147 -0
- package/tests/network-browser.test.ts +22 -0
- package/tests/network-browser.ts +679 -0
- package/tests/network-budget.test.ts +103 -0
- package/tests/network-command-controls.ts +87 -0
- package/tests/network-command.test.ts +253 -0
- package/tests/network-command.ts +274 -0
- package/tests/network-control-page.ts +32 -0
- package/tests/network-desktop-driver.ts +66 -0
- package/tests/network-failure-control.ts +332 -0
- package/tests/network-failure.test.ts +14 -0
- package/tests/network-finalizer.test.ts +61 -0
- package/tests/network-finalizer.ts +17 -0
- package/tests/network-flow-cases.ts +146 -0
- package/tests/network-flow-control.test.ts +43 -0
- package/tests/network-growth-control.ts +18 -0
- package/tests/network-growth.test.ts +27 -0
- package/tests/network-lazy.test.ts +260 -0
- package/tests/network-lookup-consumer.test.ts +193 -0
- package/tests/network-lookup-handles.test.ts +527 -0
- package/tests/network-lookup-node.test.ts +32 -0
- package/tests/network-lookup-worker.ts +83 -0
- package/tests/network-lookup.test.ts +134 -0
- package/tests/network-module-host.test.ts +263 -0
- package/tests/network-module.test.ts +76 -0
- package/tests/network-namespace.test.ts +562 -0
- package/tests/network-outbound.test.ts +786 -0
- package/tests/network-page-contract.ts +24 -0
- package/tests/network-page-inputs.ts +79 -0
- package/tests/network-page-suite.ts +183 -0
- package/tests/network-page.ts +14 -0
- package/tests/network-path-scope.test.ts +93 -0
- package/tests/network-relay-browser-runner.ts +10 -0
- package/tests/network-relay-browser.ts +384 -0
- package/tests/network-relay-contract.ts +35 -0
- package/tests/network-relay-fixture.ts +249 -0
- package/tests/network-relay-modules.ts +21 -0
- package/tests/network-relay-page.ts +10 -0
- package/tests/network-relay-runner.test.ts +171 -0
- package/tests/network-relay-worker.ts +137 -0
- package/tests/network-resource-control.ts +73 -0
- package/tests/network-ring-wake.test.ts +186 -0
- package/tests/network-safari-websocket.test.ts +272 -0
- package/tests/network-sentinel-assets.ts +6 -0
- package/tests/network-signal-control.test.ts +8 -0
- package/tests/network-signal-control.ts +101 -0
- package/tests/network-signal-controls.ts +52 -0
- package/tests/network-size.test.ts +22 -0
- package/tests/network-source-parity.test.ts +95 -0
- package/tests/network-source-parity.ts +240 -0
- package/tests/network-unix-fs.test.ts +297 -0
- package/tests/network-unix-guest.ts +41 -0
- package/tests/network-unix-races.test.ts +370 -0
- package/tests/network-unix-support.ts +93 -0
- package/tests/network-unix.test.ts +600 -0
- package/tests/network-wire.test.ts +198 -0
- package/tests/network-worker-peer.ts +88 -0
- package/tests/node-exports.test.ts +258 -0
- package/tests/node-wasi-descriptors.test.ts +32 -0
- package/tests/notification-admission.test.ts +51 -0
- package/tests/notification-browser-runner.ts +92 -0
- package/tests/notification-command.test.ts +130 -0
- package/tests/notification-command.ts +230 -0
- package/tests/notification-fairness-browser-runner.ts +66 -0
- package/tests/notification-fairness-cases.ts +327 -0
- package/tests/notification-lifetime-cases.ts +457 -0
- package/tests/notification-mixed-cases.ts +220 -0
- package/tests/notification-race-browser-runner.ts +26 -0
- package/tests/notification-race-cases.ts +54 -0
- package/tests/notification-relay-retention.test.ts +133 -0
- package/tests/notification-wait.test.ts +100 -0
- package/tests/operation-diagnostics-browser.ts +192 -0
- package/tests/operation-diagnostics.test.ts +291 -0
- package/tests/opfs-close-browser-observer.test.ts +319 -0
- package/tests/opfs-close-browser-runner.ts +434 -0
- package/tests/opfs-close-browser.ts +113 -0
- package/tests/opfs-close.test.ts +504 -0
- package/tests/opfs-qualification-browser.ts +297 -0
- package/tests/opfs-range-browser-runner.ts +86 -0
- package/tests/opfs-range-browser.ts +202 -0
- package/tests/opfs-range.test.ts +331 -0
- package/tests/opfs-snapshot.test.ts +224 -0
- package/tests/opfs-storage-browser.ts +1109 -0
- package/tests/owned-job-cleanup.test.ts +1167 -0
- package/tests/owner-freeze-browser-runner.ts +571 -0
- package/tests/owner-freeze-browser.ts +226 -0
- package/tests/packaging.test.ts +278 -0
- package/tests/page-runner/aggregate-error-fixture.ts +18 -0
- package/tests/page-runner/asset-hold-control-page.ts +7 -0
- package/tests/page-runner/asset-hold-controls.ts +132 -0
- package/tests/page-runner/asset-owner.test.ts +635 -0
- package/tests/page-runner/asset-owner.ts +251 -0
- package/tests/page-runner/bootstrap-arrival-browser.test.ts +139 -0
- package/tests/page-runner/bootstrap-arrival.test.ts +344 -0
- package/tests/page-runner/bootstrap-control.ts +19 -0
- package/tests/page-runner/bootstrap-diagnostics.test.ts +133 -0
- package/tests/page-runner/bootstrap-diagnostics.ts +35 -0
- package/tests/page-runner/bootstrap-navigation.ts +19 -0
- package/tests/page-runner/browser-controls-process-fixture.ts +112 -0
- package/tests/page-runner/browser-controls-runner.test.ts +380 -0
- package/tests/page-runner/browser-controls-runner.ts +130 -0
- package/tests/page-runner/browser-controls-suite.ts +443 -0
- package/tests/page-runner/browser-observation.test.ts +448 -0
- package/tests/page-runner/browser-observation.ts +469 -0
- package/tests/page-runner/collector-fetch.ts +93 -0
- package/tests/page-runner/collector-policy.test.ts +216 -0
- package/tests/page-runner/collector.test.ts +429 -0
- package/tests/page-runner/collector.ts +993 -0
- package/tests/page-runner/command-controls.ts +334 -0
- package/tests/page-runner/command-fixtures.ts +46 -0
- package/tests/page-runner/command-host.test.ts +167 -0
- package/tests/page-runner/command-observation.test.ts +358 -0
- package/tests/page-runner/command-page.ts +21 -0
- package/tests/page-runner/command-suites.ts +142 -0
- package/tests/page-runner/console-control-page.ts +33 -0
- package/tests/page-runner/console-control-worker.ts +14 -0
- package/tests/page-runner/console-controls.ts +174 -0
- package/tests/page-runner/console-first-line-worker.ts +2 -0
- package/tests/page-runner/console-late-control-page.ts +25 -0
- package/tests/page-runner/console-late-control.test.ts +214 -0
- package/tests/page-runner/console-late-control.ts +398 -0
- package/tests/page-runner/console-lifecycle.test.ts +139 -0
- package/tests/page-runner/console-observation.test.ts +73 -0
- package/tests/page-runner/console-observation.ts +49 -0
- package/tests/page-runner/consumer-control-chunk.ts +1 -0
- package/tests/page-runner/consumer-control-page.ts +147 -0
- package/tests/page-runner/consumer-control-worker.ts +4 -0
- package/tests/page-runner/consumer-controls.ts +345 -0
- package/tests/page-runner/consumer-entry.test.ts +856 -0
- package/tests/page-runner/consumer-page.ts +8 -0
- package/tests/page-runner/consumer.ts +39 -0
- package/tests/page-runner/continuity-lock-browser.test.ts +29 -0
- package/tests/page-runner/continuity-lock-control-page.ts +430 -0
- package/tests/page-runner/continuity-lock-diagnostic.test.ts +122 -0
- package/tests/page-runner/continuity-lock-diagnostic.ts +380 -0
- package/tests/page-runner/control-run.test.ts +112 -0
- package/tests/page-runner/control-run.ts +44 -0
- package/tests/page-runner/cross-tab-evaluator.ts +162 -0
- package/tests/page-runner/cross-tab-value.ts +59 -0
- package/tests/page-runner/document-retirement.test.ts +288 -0
- package/tests/page-runner/driver-observation-cleanup.test.ts +63 -0
- package/tests/page-runner/driver-observation-diagnostics.test.ts +93 -0
- package/tests/page-runner/driver.ts +118 -0
- package/tests/page-runner/error-context.test.ts +95 -0
- package/tests/page-runner/fake-driver.ts +192 -0
- package/tests/page-runner/filesystem-transport-browser.test.ts +75 -0
- package/tests/page-runner/filesystem-transport-native.ts +13 -0
- package/tests/page-runner/filesystem-transport-observation.ts +65 -0
- package/tests/page-runner/filesystem-transport-page.ts +48 -0
- package/tests/page-runner/filesystem-transport-suite.test.ts +310 -0
- package/tests/page-runner/filesystem-transport-suite.ts +127 -0
- package/tests/page-runner/fixture-admission.test.ts +167 -0
- package/tests/page-runner/fixture-capability-control-page.ts +24 -0
- package/tests/page-runner/fixture-capability-controls.ts +189 -0
- package/tests/page-runner/fixture-host.test.ts +524 -0
- package/tests/page-runner/fixture-owner.test.ts +176 -0
- package/tests/page-runner/fixture-owner.ts +189 -0
- package/tests/page-runner/fixtures/large-assertion.ts +21 -0
- package/tests/page-runner/framework-bootstrap-main.ts +22 -0
- package/tests/page-runner/framework-bootstrap.ts +311 -0
- package/tests/page-runner/framework-collector.test.ts +277 -0
- package/tests/page-runner/framework-collector.ts +287 -0
- package/tests/page-runner/framework-controls/installed.ts +433 -0
- package/tests/page-runner/framework-dom-controls.ts +685 -0
- package/tests/page-runner/framework-dom-page.ts +136 -0
- package/tests/page-runner/framework-final-ack.test.ts +79 -0
- package/tests/page-runner/framework-host.test.ts +443 -0
- package/tests/page-runner/framework-host.ts +899 -0
- package/tests/page-runner/framework-http-body.ts +44 -0
- package/tests/page-runner/framework-middleware.test.ts +85 -0
- package/tests/page-runner/framework-middleware.ts +73 -0
- package/tests/page-runner/framework-page.ts +37 -0
- package/tests/page-runner/framework-queue.test.ts +405 -0
- package/tests/page-runner/framework-queue.ts +417 -0
- package/tests/page-runner/framework-reporting.test.ts +451 -0
- package/tests/page-runner/framework-trace-host.test.ts +106 -0
- package/tests/page-runner/framework-trace-page.ts +483 -0
- package/tests/page-runner/framework-trace-regression.test.ts +300 -0
- package/tests/page-runner/framework-trace.test.ts +793 -0
- package/tests/page-runner/framework-trace.ts +509 -0
- package/tests/page-runner/framework-types.ts +255 -0
- package/tests/page-runner/framework-validation.test.ts +52 -0
- package/tests/page-runner/framework-validation.ts +65 -0
- package/tests/page-runner/framework-verdict.test.ts +259 -0
- package/tests/page-runner/framework.ts +37 -0
- package/tests/page-runner/gpu-async-controls-runner.ts +108 -0
- package/tests/page-runner/gpu-async-failure-controls.ts +93 -0
- package/tests/page-runner/gpu-async-native.ts +6 -0
- package/tests/page-runner/gpu-async-operations.ts +49 -0
- package/tests/page-runner/gpu-async-page.ts +14 -0
- package/tests/page-runner/gpu-async-request.ts +3 -0
- package/tests/page-runner/gpu-async-suite.test.ts +189 -0
- package/tests/page-runner/gpu-async-suite.ts +120 -0
- package/tests/page-runner/guest-watch-command.ts +11 -0
- package/tests/page-runner/guest-watch-control-phases.ts +20 -0
- package/tests/page-runner/guest-watch-controls-runner.ts +134 -0
- package/tests/page-runner/guest-watch-stalled-helper.ts +5 -0
- package/tests/page-runner/host-drive-control-page.ts +90 -0
- package/tests/page-runner/host-drive-controls.test.ts +91 -0
- package/tests/page-runner/host-drive-controls.ts +318 -0
- package/tests/page-runner/host-drive.test.ts +2222 -0
- package/tests/page-runner/host-drive.ts +1311 -0
- package/tests/page-runner/host-page.test.ts +58 -0
- package/tests/page-runner/host-page.ts +207 -0
- package/tests/page-runner/host-storage-control-page.ts +182 -0
- package/tests/page-runner/host-storage-control-worker.ts +11 -0
- package/tests/page-runner/host-storage-controls.ts +313 -0
- package/tests/page-runner/host.test.ts +133 -0
- package/tests/page-runner/inspector-endpoint-receipt.ts +425 -0
- package/tests/page-runner/inspector-endpoint.test.ts +236 -0
- package/tests/page-runner/inspector-endpoint.ts +69 -0
- package/tests/page-runner/inspector-plist.ts +395 -0
- package/tests/page-runner/inspector-stream.test.ts +149 -0
- package/tests/page-runner/inspector-stream.ts +105 -0
- package/tests/page-runner/json-snapshot.ts +8 -0
- package/tests/page-runner/key-press-control-page.ts +17 -0
- package/tests/page-runner/key-press-controls-native.ts +7 -0
- package/tests/page-runner/key-press-controls.ts +78 -0
- package/tests/page-runner/key-press-fixture.ts +109 -0
- package/tests/page-runner/key-press-observation.ts +129 -0
- package/tests/page-runner/key-press-suite.ts +138 -0
- package/tests/page-runner/large-reporting.test.ts +351 -0
- package/tests/page-runner/lifecycle-queue.test.ts +186 -0
- package/tests/page-runner/memory-group-command.test.ts +227 -0
- package/tests/page-runner/memory-group-command.ts +80 -0
- package/tests/page-runner/memory-group-control-page.ts +7 -0
- package/tests/page-runner/memory-group-controls-runner.ts +126 -0
- package/tests/page-runner/native-cli.test.ts +86 -0
- package/tests/page-runner/native-failure.test.ts +396 -0
- package/tests/page-runner/native.ts +62 -0
- package/tests/page-runner/notification-host.test.ts +264 -0
- package/tests/page-runner/notification-native.ts +6 -0
- package/tests/page-runner/ordered-reporter.ts +305 -0
- package/tests/page-runner/owned-consumers.ts +36 -0
- package/tests/page-runner/page-main.ts +137 -0
- package/tests/page-runner/peer-collector.test.ts +356 -0
- package/tests/page-runner/peer-control-page.ts +33 -0
- package/tests/page-runner/peer-controls.ts +249 -0
- package/tests/page-runner/peer-driver-fixture.test.ts +219 -0
- package/tests/page-runner/peer-driver-fixture.ts +257 -0
- package/tests/page-runner/peer-host.test.ts +248 -0
- package/tests/page-runner/peer-probe.test.ts +131 -0
- package/tests/page-runner/peer-storage-control-page.ts +51 -0
- package/tests/page-runner/peer-storage-controls.ts +116 -0
- package/tests/page-runner/playwright-driver.test.ts +270 -0
- package/tests/page-runner/playwright-driver.ts +229 -0
- package/tests/page-runner/playwright-observer.ts +137 -0
- package/tests/page-runner/prepared-assets.test.ts +91 -0
- package/tests/page-runner/process-recycling-assets.ts +34 -0
- package/tests/page-runner/process-recycling-controls-page.ts +27 -0
- package/tests/page-runner/process-recycling-controls.test.ts +70 -0
- package/tests/page-runner/process-recycling-controls.ts +134 -0
- package/tests/page-runner/process-recycling-error-control-worker.ts +2 -0
- package/tests/page-runner/process-recycling-fs-control-worker.ts +3 -0
- package/tests/page-runner/process-recycling-native.ts +46 -0
- package/tests/page-runner/process-recycling-page.ts +24 -0
- package/tests/page-runner/process-recycling-storage-control.ts +11 -0
- package/tests/page-runner/process-recycling-suite.test.ts +202 -0
- package/tests/page-runner/process-recycling-suite.ts +38 -0
- package/tests/page-runner/protocol.ts +286 -0
- package/tests/page-runner/publication-bootstrap.ts +65 -0
- package/tests/page-runner/publication-cross-tab-browser.test.ts +68 -0
- package/tests/page-runner/publication-cross-tab-host.ts +211 -0
- package/tests/page-runner/publication-cross-tab-native.ts +6 -0
- package/tests/page-runner/publication-cross-tab-page.ts +24 -0
- package/tests/page-runner/publication-cross-tab-suite.test.ts +181 -0
- package/tests/page-runner/publication-cross-tab-suite.ts +87 -0
- package/tests/page-runner/publication-native.ts +11 -0
- package/tests/page-runner/publication-page.ts +46 -0
- package/tests/page-runner/publication-suite.test.ts +100 -0
- package/tests/page-runner/publication-suite.ts +99 -0
- package/tests/page-runner/report-chunks.test.ts +295 -0
- package/tests/page-runner/report-chunks.ts +195 -0
- package/tests/page-runner/report-control.ts +12 -0
- package/tests/page-runner/report-stream.ts +12 -0
- package/tests/page-runner/reporter-control-failure.test.ts +119 -0
- package/tests/page-runner/reporter-control-page.ts +101 -0
- package/tests/page-runner/reporter.test.ts +237 -0
- package/tests/page-runner/reporter.ts +28 -0
- package/tests/page-runner/reporting-cleanup.test.ts +118 -0
- package/tests/page-runner/reporting-contract.test.ts +242 -0
- package/tests/page-runner/reporting-fixture.ts +130 -0
- package/tests/page-runner/reporting-host.test.ts +149 -0
- package/tests/page-runner/reporting-realm.ts +4 -0
- package/tests/page-runner/reporting-types.ts +22 -0
- package/tests/page-runner/result-file.ts +18 -0
- package/tests/page-runner/retained-worker-control-page.ts +23 -0
- package/tests/page-runner/retained-worker-controls.ts +107 -0
- package/tests/page-runner/root-continuity-allocation.ts +21 -0
- package/tests/page-runner/root-continuity-control-fixture.ts +11 -0
- package/tests/page-runner/root-continuity-controls.ts +237 -0
- package/tests/page-runner/root-continuity-gate-page.ts +94 -0
- package/tests/page-runner/root-continuity-page.ts +48 -0
- package/tests/page-runner/root-continuity-suite.test.ts +290 -0
- package/tests/page-runner/root-continuity-suite.ts +102 -0
- package/tests/page-runner/safari-console.ts +40 -0
- package/tests/page-runner/safari-driver-log.test.ts +202 -0
- package/tests/page-runner/safari-driver.test.ts +474 -0
- package/tests/page-runner/safari-driver.ts +763 -0
- package/tests/page-runner/safari-error.test.ts +61 -0
- package/tests/page-runner/safari-navigation.test.ts +220 -0
- package/tests/page-runner/safari-observer.test.ts +868 -0
- package/tests/page-runner/safari-observer.ts +665 -0
- package/tests/page-runner/safari-session-startup.test.ts +139 -0
- package/tests/page-runner/safe-staging-allocation.ts +19 -0
- package/tests/page-runner/safe-staging-control-page.ts +58 -0
- package/tests/page-runner/safe-staging-controls-runner.ts +53 -0
- package/tests/page-runner/safe-staging-page.ts +27 -0
- package/tests/page-runner/safe-staging-suite.ts +70 -0
- package/tests/page-runner/safe-staging.test.ts +145 -0
- package/tests/page-runner/service-worker-page.ts +132 -0
- package/tests/page-runner/stall-diagnostics.test.ts +380 -0
- package/tests/page-runner/stall-diagnostics.ts +627 -0
- package/tests/page-runner/storage-cleanup.ts +83 -0
- package/tests/page-runner/storage-control-page.ts +124 -0
- package/tests/page-runner/storage-control-worker.ts +36 -0
- package/tests/page-runner/storage-host.ts +51 -0
- package/tests/page-runner/storage-page-control-worker.ts +15 -0
- package/tests/page-runner/storage-page.ts +14 -0
- package/tests/page-runner/storage-policy.ts +74 -0
- package/tests/page-runner/storage-worker.test.ts +30 -0
- package/tests/page-runner/storage-worker.ts +154 -0
- package/tests/page-runner/suite-host.ts +1259 -0
- package/tests/page-runner/suite-query.test.ts +164 -0
- package/tests/page-runner/suite-startup.test.ts +102 -0
- package/tests/page-runner/threads-runtime-browser.test.ts +68 -0
- package/tests/page-runner/threads-runtime-native.ts +31 -0
- package/tests/page-runner/threads-runtime-page.ts +19 -0
- package/tests/page-runner/threads-runtime-suite.test.ts +245 -0
- package/tests/page-runner/threads-runtime-suite.ts +162 -0
- package/tests/page-runner/worker-allocation.test.ts +161 -0
- package/tests/page-runner/worker-capability-control-page.ts +91 -0
- package/tests/page-runner/worker-capability-controls.ts +394 -0
- package/tests/page-runner/worker-close-query.test.ts +229 -0
- package/tests/page-runner/worker-lifecycle-browser.test.ts +104 -0
- package/tests/page-runner/worker-lifecycle-control-page.ts +18 -0
- package/tests/persistence-close.test.ts +359 -0
- package/tests/persistence-durability.test.ts +588 -0
- package/tests/persistence-queue.test.ts +324 -0
- package/tests/persistence.test.ts +788 -0
- package/tests/persistent-authority-browser-runner.ts +518 -0
- package/tests/persistent-authority-browser.ts +25 -0
- package/tests/persistent-authority-report.test.ts +216 -0
- package/tests/persistent-authority-report.ts +81 -0
- package/tests/persistent-lifecycle-r2-browser-runner.ts +503 -0
- package/tests/persistent-lifecycle-r2-page.ts +248 -0
- package/tests/persistent-lifecycle-r2.test.ts +114 -0
- package/tests/persistent-native-inspection.test.ts +254 -0
- package/tests/persistent-native-inspection.ts +179 -0
- package/tests/persistent-ready.test.ts +54 -0
- package/tests/persistent-resident-owner.test.ts +612 -0
- package/tests/pinned-truncate.test.ts +137 -0
- package/tests/pipe-description-flags.test.ts +29 -0
- package/tests/pipe-filestat-browser.ts +182 -0
- package/tests/pipe-filestat.test.ts +157 -0
- package/tests/pipe-persistent-lifetime.test.ts +134 -0
- package/tests/pipe-reader-lifetime.test.ts +46 -0
- package/tests/pipe-reader-reuse-races.test.ts +228 -0
- package/tests/pipe-registry-allocator.test.ts +35 -0
- package/tests/pipe-reuse-worker.test.ts +112 -0
- package/tests/pipe-shared-allocator.test.ts +170 -0
- package/tests/pipe-slot-reuse.test.ts +500 -0
- package/tests/pipes.test.ts +1669 -0
- package/tests/preopen-placement.test.ts +236 -0
- package/tests/prepared-platform-boundary.test.ts +26 -0
- package/tests/preview-host-reference.test.ts +51 -0
- package/tests/preview-host-reference.ts +155 -0
- package/tests/preview-host.test.ts +875 -0
- package/tests/preview-network-fixture.ts +150 -0
- package/tests/preview-upgrade-lifetime.test.ts +123 -0
- package/tests/preview-upgrade.test.ts +277 -0
- package/tests/preview-vite.test.ts +296 -0
- package/tests/preview.test.ts +406 -0
- package/tests/preview1-listener-browser.ts +136 -0
- package/tests/preview1-listener-lifecycle.test.ts +55 -0
- package/tests/preview1-listener-module.ts +12 -0
- package/tests/preview1-listener.test.ts +430 -0
- package/tests/preview1-network-launch.test.ts +251 -0
- package/tests/preview1-network-lifetime.test.ts +71 -0
- package/tests/preview1-socket-libc.test.ts +65 -0
- package/tests/preview1-socket-support.ts +213 -0
- package/tests/preview1-socket.test.ts +506 -0
- package/tests/preview1-worker-entry.test.ts +42 -0
- package/tests/preview1-worker-startup.test.ts +74 -0
- package/tests/process-abi.test.ts +1568 -0
- package/tests/process-access.test.ts +653 -0
- package/tests/process-admission.test.ts +413 -0
- package/tests/process-cell-clone-browser.test.ts +24 -0
- package/tests/process-cell-clone-browser.ts +239 -0
- package/tests/process-cell-clone.test.ts +39 -0
- package/tests/process-control.test.ts +166 -0
- package/tests/process-core.test.ts +1528 -0
- package/tests/process-cwd.test.ts +237 -0
- package/tests/process-directory-rejection.test.ts +149 -0
- package/tests/process-entry.test.ts +12 -0
- package/tests/process-execve.test.ts +677 -0
- package/tests/process-host-failure.test.ts +149 -0
- package/tests/process-identity.test.ts +482 -0
- package/tests/process-job.test.ts +504 -0
- package/tests/process-linux-signals.test.ts +535 -0
- package/tests/process-loader-retry.test.ts +137 -0
- package/tests/process-lookup.test.ts +408 -0
- package/tests/process-memory-admission-rollback.test.ts +218 -0
- package/tests/process-navigation-observer.test.ts +362 -0
- package/tests/process-navigation-observer.ts +707 -0
- package/tests/process-observation-boundary.test.ts +103 -0
- package/tests/process-observation-lifecycle.test.ts +279 -0
- package/tests/process-observation-root.test.ts +498 -0
- package/tests/process-observation-standalone.test.ts +236 -0
- package/tests/process-observation.test.ts +243 -0
- package/tests/process-outcome.test.ts +222 -0
- package/tests/process-pipe-recycling.test.ts +336 -0
- package/tests/process-poll-idle.test.ts +345 -0
- package/tests/process-quiescence.test.ts +317 -0
- package/tests/process-recycling-browser-runner-control.ts +103 -0
- package/tests/process-recycling-browser-runner.test.ts +385 -0
- package/tests/process-recycling-browser-runner.ts +410 -0
- package/tests/process-recycling-browser.ts +1720 -0
- package/tests/process-replacement.test.ts +1950 -0
- package/tests/process-root-navigation-diagnostic.test.ts +1146 -0
- package/tests/process-root-navigation-diagnostic.ts +1291 -0
- package/tests/process-signal-poll.test.ts +168 -0
- package/tests/process-spawn-diagnostic.test.ts +388 -0
- package/tests/process-spawn-errno.test.ts +265 -0
- package/tests/process-start-browser-runner.ts +90 -0
- package/tests/process-start-browser.ts +181 -0
- package/tests/process-start-diagnostics.test.ts +301 -0
- package/tests/process-start-failed.test.ts +336 -0
- package/tests/process-start-status.test.ts +512 -0
- package/tests/process-startup-review.test.ts +507 -0
- package/tests/process-worker-lifetime.test.ts +125 -0
- package/tests/process-worker-ownership.test.ts +3153 -0
- package/tests/program-admission-metadata.test.ts +131 -0
- package/tests/program-build-tools.test.ts +271 -0
- package/tests/program-host-command-debt.ts +48 -0
- package/tests/program-host-command-fixture.ts +108 -0
- package/tests/program-host-command-signals.test.ts +271 -0
- package/tests/program-host-command-types.test.ts +46 -0
- package/tests/program-host-command.test.ts +688 -0
- package/tests/program-loading-api.test.ts +475 -0
- package/tests/program-manifest-lookup.test.ts +129 -0
- package/tests/program-script-loading.test.ts +174 -0
- package/tests/program-session-example.test.ts +313 -0
- package/tests/program-url-download.test.ts +380 -0
- package/tests/programs-install-termination-debt.ts +146 -0
- package/tests/programs-install-termination.test.ts +51 -0
- package/tests/programs-install.test.ts +388 -0
- package/tests/public-workspace-endurance.test.ts +244 -0
- package/tests/publication-browser-runner.test.ts +27 -0
- package/tests/publication-browser-runner.ts +96 -0
- package/tests/publication-browser.ts +913 -0
- package/tests/publication-channel-observer.test.ts +92 -0
- package/tests/publication-checkpoint-contract.test.ts +306 -0
- package/tests/publication-command.ts +35 -0
- package/tests/publication-cross-tab-assets.ts +38 -0
- package/tests/publication-cross-tab-browser-runner.ts +37 -0
- package/tests/publication-cross-tab-browser.ts +966 -0
- package/tests/publication-cross-tab-command.ts +1003 -0
- package/tests/publication-cross-tab-host.ts +89 -0
- package/tests/publication-cross-tab-inventory.ts +53 -0
- package/tests/publication-durable-metadata.test.ts +507 -0
- package/tests/publication-limits-contract.test.ts +106 -0
- package/tests/publication-memory-accounting.test.ts +575 -0
- package/tests/readiness-stream.test.ts +405 -0
- package/tests/readiness.test.ts +90 -0
- package/tests/recovery-r42-browser-runner.ts +330 -0
- package/tests/recovery-r42.test.ts +23 -0
- package/tests/reservation-waste.test.ts +243 -0
- package/tests/resident-construction.test.ts +663 -0
- package/tests/root-continuity-browser-runner.ts +62 -0
- package/tests/root-continuity-browser.ts +269 -0
- package/tests/root-continuity-command.ts +23 -0
- package/tests/root-continuity-source-parity.test.ts +77 -0
- package/tests/root-continuity.test.ts +196 -0
- package/tests/root-return-gc.test.ts +36 -0
- package/tests/running-member-reuse-browser-runner.ts +123 -0
- package/tests/running-member-reuse-browser.ts +383 -0
- package/tests/runtime-budget-ownership.test.ts +38 -0
- package/tests/runtime-display-fence.test.ts +20 -0
- package/tests/runtime-disposal-signal-order.test.ts +25 -0
- package/tests/runtime-facade.test.ts +2004 -0
- package/tests/runtime-filesystem-close-debt.test.ts +38 -0
- package/tests/runtime-network-fence.test.ts +8 -0
- package/tests/runtime-network.test.ts +456 -0
- package/tests/runtime-process-context.test.ts +349 -0
- package/tests/runtime-request-pool.test.ts +83 -0
- package/tests/runtime-size.test.ts +102 -0
- package/tests/runtime-startup-proof.test.ts +86 -0
- package/tests/runtime-startup-proof.ts +25 -0
- package/tests/runtime-startup.test.ts +299 -0
- package/tests/runtime-terminals.test.ts +496 -0
- package/tests/safe-staging-browser-runner.ts +22 -0
- package/tests/safe-staging-browser.ts +1224 -0
- package/tests/safe-staging-fixture-hooks.test.ts +63 -0
- package/tests/safe-staging-native.test.ts +29 -0
- package/tests/safe-staging-native.ts +32 -0
- package/tests/safe-staging-runner-contract.test.ts +30 -0
- package/tests/safe-staging.test.ts +96 -0
- package/tests/search-executor-browser-runner.ts +34 -0
- package/tests/search-executor-browser.ts +614 -0
- package/tests/search-file-reader.test.ts +58 -0
- package/tests/search-grep-plan.test.ts +364 -0
- package/tests/search-matcher-differential.test.ts +187 -0
- package/tests/search-matcher.test.ts +173 -0
- package/tests/search-operand-plan.test.ts +30 -0
- package/tests/search-program-browser-runner.ts +146 -0
- package/tests/search-program-browser.ts +388 -0
- package/tests/search-rg-plan.test.ts +407 -0
- package/tests/search-run.test.ts +366 -0
- package/tests/search-source.test.ts +129 -0
- package/tests/sender-admission.test.ts +251 -0
- package/tests/shared-caller-admission.test.ts +121 -0
- package/tests/shared-caller-host-exec.test.ts +119 -0
- package/tests/shared-control-pipes.test.ts +37 -0
- package/tests/shared-guest-backing.test.ts +746 -0
- package/tests/shared-memory-admission.test.ts +203 -0
- package/tests/shared-memory-browser-bundle.test.ts +62 -0
- package/tests/shared-memory-input.test.ts +79 -0
- package/tests/shared-reservation-coverage.test.ts +15 -0
- package/tests/spawn-error-context.test.ts +38 -0
- package/tests/stable-memory-reader.test.ts +26 -0
- package/tests/start-command.test.ts +109 -0
- package/tests/start-failure-quiet-browser.ts +333 -0
- package/tests/start-failure-quiet.test.ts +24 -0
- package/tests/startup-diagnostic-browser.ts +192 -0
- package/tests/startup-diagnostic.test.ts +43 -0
- package/tests/startup-pool-browser.ts +173 -0
- package/tests/stop-order-browser-runner.ts +135 -0
- package/tests/stop-order-browser.ts +166 -0
- package/tests/storage-allocation.ts +41 -0
- package/tests/storage-browser-helpers.ts +46 -0
- package/tests/storage-browser-runner.ts +205 -0
- package/tests/storage-browser.ts +2 -0
- package/tests/storage-caller-release.test.ts +82 -0
- package/tests/storage-crash-r2-browser.ts +7 -0
- package/tests/storage-crash-r2-indexeddb.ts +307 -0
- package/tests/storage-crash-r2-opfs.ts +224 -0
- package/tests/storage-crash-r2-scheduler.ts +88 -0
- package/tests/storage-crash-r2-state.ts +132 -0
- package/tests/storage-crash-r2.test.ts +109 -0
- package/tests/storage-lifecycle-marker.ts +5 -0
- package/tests/storage-lifecycle-observer.ts +131 -0
- package/tests/storage-lock-adapter.test.ts +82 -0
- package/tests/storage-lock-browser-runner.ts +1033 -0
- package/tests/storage-lock-browser.ts +321 -0
- package/tests/storage-lock-cases.ts +157 -0
- package/tests/storage-lock-host.ts +103 -0
- package/tests/storage-lock-observation.ts +60 -0
- package/tests/storage-lock-page.ts +18 -0
- package/tests/storage-lock-peer.ts +132 -0
- package/tests/storage-lock-recovery-worker.ts +60 -0
- package/tests/storage-lock-schedules.ts +375 -0
- package/tests/storage-lock-startup.test.ts +73 -0
- package/tests/storage-navigation-diagnostics.test.ts +548 -0
- package/tests/storage-navigation-diagnostics.ts +231 -0
- package/tests/storage-open-worker.ts +18 -0
- package/tests/storage-quota-control.ts +12 -0
- package/tests/storage-quota-r2-browser.ts +548 -0
- package/tests/storage-quota-r2-probes.ts +393 -0
- package/tests/storage-quota-r2.test.ts +17 -0
- package/tests/storage-release-browser.ts +129 -0
- package/tests/storage-release.test.ts +442 -0
- package/tests/storage-suite-contract.test.ts +15 -0
- package/tests/storage.test.ts +520 -0
- package/tests/symlink-sizing.test.ts +226 -0
- package/tests/terminal-control.test.ts +639 -0
- package/tests/terminal-deadholder.test.ts +631 -0
- package/tests/terminal-gate-wake.test.ts +360 -0
- package/tests/terminal-handoff.test.ts +86 -0
- package/tests/terminal-input.test.ts +332 -0
- package/tests/terminal-interrupt-flush.test.ts +554 -0
- package/tests/terminal-output.test.ts +711 -0
- package/tests/terminal-read-fds.test.ts +153 -0
- package/tests/terminal-resolver-worker.test.ts +125 -0
- package/tests/terminal-session.test.ts +1794 -0
- package/tests/thread-admission.test.ts +151 -0
- package/tests/threads-browser-contract.ts +32 -0
- package/tests/threads-browser-guest-worker.ts +12 -0
- package/tests/threads-browser-page.ts +552 -0
- package/tests/threads-browser-runner.test.ts +83 -0
- package/tests/threads-browser-runner.ts +120 -0
- package/tests/threads-browser-service-worker.ts +116 -0
- package/tests/threads-fdstat-admission.test.ts +64 -0
- package/tests/threads-fdstat-authority-worker.ts +65 -0
- package/tests/threads-fdstat-authority.test.ts +81 -0
- package/tests/threads-fdstat.test.ts +304 -0
- package/tests/threads-fixture-inspect.ts +179 -0
- package/tests/threads-fixture-producer.test.ts +97 -0
- package/tests/threads-guest-fixture.ts +204 -0
- package/tests/threads-guest-lane.test.ts +64 -0
- package/tests/threads-guest-memory.test.ts +283 -0
- package/tests/threads-guest-module.ts +95 -0
- package/tests/threads-guest-rust-runner.test.ts +52 -0
- package/tests/threads-guest-rust-runner.ts +142 -0
- package/tests/threads-guest-worker.ts +50 -0
- package/tests/threads-guest.test.ts +305 -0
- package/tests/threads-lifecycle-module.ts +41 -0
- package/tests/threads-lifecycle-waiter.ts +38 -0
- package/tests/threads-lifecycle.test.ts +416 -0
- package/tests/threads-memory-growth.test.ts +188 -0
- package/tests/threads-random-control.ts +170 -0
- package/tests/threads-random.test.ts +23 -0
- package/tests/threads-runtime-authority-worker.ts +63 -0
- package/tests/threads-runtime-browser-runner.ts +119 -0
- package/tests/threads-runtime-browser.ts +622 -0
- package/tests/threads-runtime-cases.ts +38 -0
- package/tests/threads-runtime-cleanup.test.ts +58 -0
- package/tests/threads-runtime-cleanup.ts +46 -0
- package/tests/threads-runtime-control.ts +13 -0
- package/tests/threads-runtime-failure-control.ts +338 -0
- package/tests/threads-runtime-failures.test.ts +116 -0
- package/tests/threads-runtime-fault-bootstrap.ts +1 -0
- package/tests/threads-runtime-fault-conditions.test.ts +35 -0
- package/tests/threads-runtime-fault-control.ts +394 -0
- package/tests/threads-runtime-fault-service.ts +56 -0
- package/tests/threads-runtime-fd-browser.ts +247 -0
- package/tests/threads-runtime-fd-control.ts +6 -0
- package/tests/threads-runtime-fd-descriptors.test.ts +45 -0
- package/tests/threads-runtime-fd-filesystem.ts +41 -0
- package/tests/threads-runtime-fd-module.ts +102 -0
- package/tests/threads-runtime-fd-service.ts +75 -0
- package/tests/threads-runtime-growth-worker.ts +61 -0
- package/tests/threads-runtime-host.ts +32 -0
- package/tests/threads-runtime-late-read-service.ts +46 -0
- package/tests/threads-runtime-modules.ts +132 -0
- package/tests/threads-runtime-regression-controls.ts +386 -0
- package/tests/threads-runtime-regression-modules.ts +242 -0
- package/tests/threads-runtime-safari-packet.ts +285 -0
- package/tests/threads-runtime-safari-runner.test.ts +173 -0
- package/tests/threads-runtime-safari-runner.ts +270 -0
- package/tests/threads-runtime-service-barrier.ts +56 -0
- package/tests/threads-runtime.test.ts +143 -0
- package/tests/threads-safari-runner.ts +159 -0
- package/tests/threads-service-edge.test.ts +93 -0
- package/tests/threads-service-fixture.ts +117 -0
- package/tests/threads-service-host.ts +103 -0
- package/tests/threads-service.test.ts +305 -0
- package/tests/threads-wait-owner.test.ts +169 -0
- package/tests/vfs-continuation.test.ts +337 -0
- package/tests/vfs-guest-buffer.test.ts +31 -0
- package/tests/vfs-harness.test.ts +414 -0
- package/tests/vfs.test.ts +167 -0
- package/tests/wasi-clocks.test.ts +152 -0
- package/tests/wasi-exit.test.ts +74 -0
- package/tests/wasi-libc.test.ts +272 -0
- package/tests/wasi-nonblock-inheritance.test.ts +109 -0
- package/tests/wasi-nonblock.test.ts +181 -0
- package/tests/wasi-path-memory.test.ts +225 -0
- package/tests/wasi-size-admission.test.ts +227 -0
- package/tests/wasm-start-section.test.ts +39 -0
- package/tests/watch-account.test.ts +603 -0
- package/tests/watch-admission.test.ts +211 -0
- package/tests/watch-committed.test.ts +1068 -0
- package/tests/watch-direct-worker.ts +35 -0
- package/tests/watch-registration-reap.test.ts +129 -0
- package/tests/watch-root-runtime.test.ts +313 -0
- package/tests/webkit-diagnostics.ts +125 -0
- package/tests/webkit-error-output.test.ts +118 -0
- package/tests/worker-access.test.ts +331 -0
- package/tests/worker-final-completion.test.ts +434 -0
- package/tests/worker-memory-bootstrap.test.ts +237 -0
- package/tests/worker-memory-broker.test.ts +666 -0
- package/tests/worker-memory.test.ts +210 -0
- package/tests/worker-pipes.test.ts +993 -0
- package/tests/worker-pool.test.ts +88 -0
- package/tests/worker-selected-signal.test.ts +429 -0
- package/tests/workspace-archive-pulls.test.ts +501 -0
- package/tests/workspace-archive.test.ts +1281 -0
- package/tests/workspace-browser.ts +444 -0
- package/tests/workspace-capacity.test.ts +627 -0
- package/tests/workspace-continuity-browser-runner.ts +664 -0
- package/tests/workspace-continuity-checkpoint.test.ts +101 -0
- package/tests/workspace-continuity.test.ts +196 -0
- package/tests/workspace-export-public.test.ts +154 -0
- package/tests/workspace-export.test.ts +1709 -0
- package/tests/workspace-import-admission.test.ts +409 -0
- package/tests/workspace-root-release.test.ts +112 -0
- package/tests/workspace-safari-browser.ts +239 -0
- package/tests/workspace-safari-guest.ts +38 -0
- package/tests/workspace-safari-local.ts +33 -0
- package/tests/workspace-safari-runner.test.ts +298 -0
- package/tests/workspace-search.test.ts +892 -0
- package/tests/workspace-vfs-read-browser.ts +388 -0
- package/tests/workspace-vfs-read-cold-lifecycle.test.ts +236 -0
- package/tests/workspace-vfs-read-cold-readiness.test.ts +97 -0
- package/tests/workspace-vfs-read-dirty.test.ts +119 -0
- package/tests/workspace-vfs-read-races.test.ts +863 -0
- package/tests/workspace-vfs-read-serials.test.ts +124 -0
- package/tests/workspace-vfs-read-shutdown.test.ts +217 -0
- package/tests/workspace-vfs-read-stream.test.ts +878 -0
- package/tests/workspace-vfs-read.test.ts +758 -0
- package/tests/workspace-vfs.test.ts +785 -0
- package/thread/entry.ts +140 -0
- package/thread/guest-bootstrap.ts +12 -0
- package/thread/guest-imports.ts +329 -0
- package/thread/guest-module.ts +6 -0
- package/thread/guest-worker.ts +179 -0
- package/thread/lane.ts +461 -0
- package/thread/protocol.ts +18 -0
- package/thread/runtime-owner.ts +619 -0
- package/thread/runtime-protocol.ts +33 -0
- package/thread/service-worker.ts +95 -0
- package/thread/service.ts +482 -0
- package/tooling/build-network.ts +157 -0
- package/tooling/check-network-rust.ts +59 -0
- package/tooling/check-package-metadata.ts +8 -0
- package/tooling/ci-paths.test.ts +1904 -0
- package/tooling/fixtures/page-runner-error-consumer.ts +124 -0
- package/tooling/gpu-coverage.ts +177 -0
- package/tooling/gpu-desktop-measure.ts +100 -0
- package/tooling/gpu-measure-host.ts +59 -0
- package/tooling/gpu-measure.ts +512 -0
- package/tooling/gpu-size.ts +38 -0
- package/tooling/gpu-stream-layout.ts +268 -0
- package/tooling/gpu-stream-model.ts +106 -0
- package/tooling/gpu-stream.ts +951 -0
- package/tooling/host-interface.ts +107 -0
- package/tooling/network-growth.ts +120 -0
- package/tooling/network-size.ts +73 -0
- package/tooling/network-source-smoke.ts +86 -0
- package/tooling/network-translator/bun.lock +15 -0
- package/tooling/network-translator/package.json +7 -0
- package/tooling/network-translator.test.ts +117 -0
- package/tooling/network-translator.ts +147 -0
- package/tooling/package-inputs.ts +25 -0
- package/tooling/prepare-allocation-reference.ts +32 -0
- package/tooling/private-authority.ts +1445 -0
- package/tooling/program/program-build-tools.ts +440 -0
- package/tooling/program/program-derivation.ts +175 -0
- package/tooling/program/program-optimize.ts +330 -0
- package/tooling/program/program-transformer.json +1 -0
- package/tooling/program-tools-package.ts +77 -0
- package/tooling/quality-probes.ts +101 -0
- package/tooling/runtime-size.ts +42 -0
- package/tooling/shared-reservations.ts +57 -0
- package/tooling/storage-crash-r2-mutations.ts +59 -0
- package/tooling/storage-crash-r2.ts +89 -0
- package/tooling/storage-quota-r2.ts +141 -0
- package/tooling/tarball-smoke.ts +556 -0
- package/tooling/typescript-source.test.ts +38 -0
- package/tooling/typescript-source.ts +47 -0
- package/tooling/vfs-benchmark.ts +903 -0
- package/tooling/vfs-browser.ts +320 -0
- package/tooling/vfs-continuation.ts +313 -0
- package/tooling/vfs-guest.ts +235 -0
- package/tooling/vfs-score-config.ts +64 -0
- package/tooling/vfs-score.ts +406 -0
- package/tooling/vfs-startup.ts +21 -0
- package/tooling/vfs-workloads.ts +382 -0
- package/tooling/workspace-safari-runner.ts +313 -0
|
@@ -0,0 +1,4209 @@
|
|
|
1
|
+
import {
|
|
2
|
+
commandExecTransfer,
|
|
3
|
+
commandTransferFailed,
|
|
4
|
+
initializeCommandExec,
|
|
5
|
+
readCommandTransferFailure,
|
|
6
|
+
} from "../proc/command-transfer.js";
|
|
7
|
+
import { WorkerStartError } from "../proc/start-diagnostic.ts";
|
|
8
|
+
import { requireGroupPlan } from "../link/issuance.js";
|
|
9
|
+
import type { SharedLinkPlan } from "../link/image.js";
|
|
10
|
+
import {
|
|
11
|
+
admitProcessObservation,
|
|
12
|
+
captureNativeReturn,
|
|
13
|
+
type ProcessObservationTransfer,
|
|
14
|
+
} from "../proc/observation.js";
|
|
15
|
+
import {
|
|
16
|
+
bindGraphicsLaunch,
|
|
17
|
+
graphicsLaunchRetention,
|
|
18
|
+
retainAllocationReceipts,
|
|
19
|
+
} from "./display/launch-retention.js";
|
|
20
|
+
import type { GraphicsGrant } from "./display/protocol.js";
|
|
21
|
+
import { allocateSharedControl, type SharedControlGrant } from "../memory/control.js";
|
|
22
|
+
import {
|
|
23
|
+
bytes,
|
|
24
|
+
type Headroom,
|
|
25
|
+
type RuntimeReservations,
|
|
26
|
+
type Ticket,
|
|
27
|
+
type LaunchedTicket,
|
|
28
|
+
type ProcessGuestPlan,
|
|
29
|
+
type ProcessPlan,
|
|
30
|
+
} from "../memory/reservations.js";
|
|
31
|
+
import type { ThreadAggregate, ThreadLaunchOptions } from "../thread/runtime-protocol.js";
|
|
32
|
+
import {
|
|
33
|
+
threadModuleDeclaration,
|
|
34
|
+
moduleMemoryDeclarations,
|
|
35
|
+
type MemoryDeclaration,
|
|
36
|
+
} from "../memory/declarations.js";
|
|
37
|
+
import type { Preview1Network } from "./preview1-network-types.js";
|
|
38
|
+
import {
|
|
39
|
+
prepareTerminalDescendant,
|
|
40
|
+
terminalPreparationReceipt,
|
|
41
|
+
type TerminalAuthority,
|
|
42
|
+
type TerminalControlTurn,
|
|
43
|
+
type TerminalControlReceipt,
|
|
44
|
+
type TerminalResult,
|
|
45
|
+
type TerminalFailure,
|
|
46
|
+
} from "./terminal-session.js";
|
|
47
|
+
import {
|
|
48
|
+
atomicsWaitAsync,
|
|
49
|
+
atomicsLoad,
|
|
50
|
+
BigInt64ArrayConstructor,
|
|
51
|
+
reflectApply,
|
|
52
|
+
observeRejectedPromise,
|
|
53
|
+
isInstance,
|
|
54
|
+
PromiseConstructor,
|
|
55
|
+
} from "../proc/intrinsics.js";
|
|
56
|
+
import { ReadyWorkerPool } from "./worker-pool.js";
|
|
57
|
+
import {
|
|
58
|
+
markStart,
|
|
59
|
+
observeStart,
|
|
60
|
+
processStartRecord,
|
|
61
|
+
startMessage,
|
|
62
|
+
startSnapshot,
|
|
63
|
+
type ProcessStartRecord,
|
|
64
|
+
type ProcessStartState,
|
|
65
|
+
} from "./process-start.js";
|
|
66
|
+
import { createNotificationBridge, type NotificationBridge } from "./notification-relay.js";
|
|
67
|
+
import { snapshotHostIdentity, type RuntimeHostIdentity } from "./process-context.js";
|
|
68
|
+
import { drainDiagnostic } from "./diagnostic.js";
|
|
69
|
+
import {
|
|
70
|
+
MemoryGroups,
|
|
71
|
+
type MemberLease,
|
|
72
|
+
type MemoryGroupHandle,
|
|
73
|
+
type MemoryGroupPolicyOptions,
|
|
74
|
+
type MemoryGroupSnapshot,
|
|
75
|
+
} from "../group/state.js";
|
|
76
|
+
import type { MemoryGroupMemberRequest } from "../group/protocol.js";
|
|
77
|
+
import { WorkerExecutableAccess, rejectWorkerAccess } from "../proc/worker-access.js";
|
|
78
|
+
import {
|
|
79
|
+
directoryGroups,
|
|
80
|
+
directoryCapacity,
|
|
81
|
+
collectDirectoryJob,
|
|
82
|
+
idleDirectoryAdmission,
|
|
83
|
+
directoryProcesses,
|
|
84
|
+
directoryAdmissionVersion,
|
|
85
|
+
commitDirectoryAdmission,
|
|
86
|
+
isCollectedProcess,
|
|
87
|
+
wakeDirectory,
|
|
88
|
+
} from "../proc/directory.js";
|
|
89
|
+
import {
|
|
90
|
+
type ControlCells,
|
|
91
|
+
TaggedCells,
|
|
92
|
+
controlLoad,
|
|
93
|
+
controlStore,
|
|
94
|
+
controlCas,
|
|
95
|
+
} from "../proc/control.js";
|
|
96
|
+
import { type FilesystemConnection, type FilesystemIdentity, isRevoked } from "../fs/protocol.js";
|
|
97
|
+
|
|
98
|
+
import type { ProcessSupervisor, RootProcessOptions } from "../proc/supervisor.js";
|
|
99
|
+
import type { ExecutableRegistry, ResolvedExecutable } from "../proc/registry.js";
|
|
100
|
+
import type { ProcessIdentityAllocator } from "../proc/identity.js";
|
|
101
|
+
import type { ProcessRecord, ProcessTable } from "../proc/table.js";
|
|
102
|
+
import {
|
|
103
|
+
type ChildExitEvent,
|
|
104
|
+
type ProcessContext,
|
|
105
|
+
type ProcessExit,
|
|
106
|
+
type CommandProcessContext,
|
|
107
|
+
type ProcessHandle,
|
|
108
|
+
checkedSignal,
|
|
109
|
+
checkedProcessCwd,
|
|
110
|
+
snapshotLogicalProcessIdentity,
|
|
111
|
+
type LogicalProcessIdentity,
|
|
112
|
+
ProcessErrno,
|
|
113
|
+
ProcessError,
|
|
114
|
+
} from "../proc/types.js";
|
|
115
|
+
import { requestSignal, createSignalState, type SignalTransport } from "../proc/signals.js";
|
|
116
|
+
import {
|
|
117
|
+
claimOutcome,
|
|
118
|
+
outcomeWord,
|
|
119
|
+
readOutcome,
|
|
120
|
+
startStatus,
|
|
121
|
+
serializeOutcome,
|
|
122
|
+
} from "../proc/outcome.js";
|
|
123
|
+
import { WorkerProcessBroker } from "../proc/worker-broker.js";
|
|
124
|
+
import {
|
|
125
|
+
captureTerminalLifetime,
|
|
126
|
+
type TerminalProcessLifetime,
|
|
127
|
+
} from "../proc/terminal-lifetime.js";
|
|
128
|
+
import {
|
|
129
|
+
reportProcessAdmission,
|
|
130
|
+
type ProcessAdmissionEvent,
|
|
131
|
+
type ProcessAdmissionObserver,
|
|
132
|
+
} from "../proc/admission.js";
|
|
133
|
+
import {
|
|
134
|
+
confirmWorkerProcessJob,
|
|
135
|
+
installWorkerBindings,
|
|
136
|
+
wakeWorkerProcess,
|
|
137
|
+
workerProcessDirectoryId,
|
|
138
|
+
workerProcessState,
|
|
139
|
+
type WorkerDescriptorCodec,
|
|
140
|
+
type WorkerProcessMessage,
|
|
141
|
+
type WorkerProcessTransport,
|
|
142
|
+
} from "../proc/worker-client.js";
|
|
143
|
+
import { createFilesystemDescriptorCodec } from "../proc/filesystem-codec.js";
|
|
144
|
+
import { WorkerPipeBroker, WorkerPipeHost } from "../proc/worker-pipes.js";
|
|
145
|
+
import {
|
|
146
|
+
attachPipePublicationRegistry,
|
|
147
|
+
PipeEndpoint,
|
|
148
|
+
PipePublicationRegistry,
|
|
149
|
+
} from "../proc/pipes.js";
|
|
150
|
+
import { createRuntimeTerminalCodec } from "./runtime-terminals.js";
|
|
151
|
+
import {
|
|
152
|
+
createTerminalOutput,
|
|
153
|
+
deliveredTerminalOutput,
|
|
154
|
+
TerminalOutputBudget,
|
|
155
|
+
type TerminalOutputDelivery,
|
|
156
|
+
type TerminalOutputReader,
|
|
157
|
+
} from "./terminal-output.js";
|
|
158
|
+
import type { RuntimeWorkerRequest, RuntimeWorkerMessage } from "./worker.js";
|
|
159
|
+
import type { RuntimeNetworkPathScope } from "./net/runtime.js";
|
|
160
|
+
import type { SignalDelegation } from "../programs/index.js";
|
|
161
|
+
import { packageIdentity } from "../programs/catalog.js";
|
|
162
|
+
import { preview1Launch } from "../programs/collection.js";
|
|
163
|
+
import {
|
|
164
|
+
CommandStdioError,
|
|
165
|
+
type ProcessQuery,
|
|
166
|
+
type CommandProcessRow,
|
|
167
|
+
type DelegatedSignals,
|
|
168
|
+
} from "../proc/command.js";
|
|
169
|
+
import type { CommandCapabilities } from "../proc/command-runner.js";
|
|
170
|
+
import type { FileHandle } from "../core/filesystem.js";
|
|
171
|
+
import type { OperationOwner } from "./operations/owner.js";
|
|
172
|
+
import type {
|
|
173
|
+
GuestOperationBinding,
|
|
174
|
+
ObservedPreview1Bootstrap,
|
|
175
|
+
OperationBinding,
|
|
176
|
+
} from "./operations/protocol.js";
|
|
177
|
+
import type { OperationDiagnostics } from "./operations/types.js";
|
|
178
|
+
|
|
179
|
+
export interface ProcessFilesystem {
|
|
180
|
+
fork?(): FilesystemConnection;
|
|
181
|
+
connect(
|
|
182
|
+
identity: FilesystemIdentity,
|
|
183
|
+
headroom?: Headroom | null,
|
|
184
|
+
operations?: OperationBinding,
|
|
185
|
+
): FilesystemConnection;
|
|
186
|
+
revoke(identity: FilesystemIdentity): void;
|
|
187
|
+
reap(identity: FilesystemIdentity): void;
|
|
188
|
+
quiesce(identity: FilesystemIdentity): Promise<void>;
|
|
189
|
+
sweep?(): void;
|
|
190
|
+
}
|
|
191
|
+
export interface ProcessController {
|
|
192
|
+
readonly signalDelegation?: SignalDelegation;
|
|
193
|
+
filesystem?: FilesystemIdentity;
|
|
194
|
+
acknowledged?(): boolean;
|
|
195
|
+
launch?(context: ProcessContext): ProcessHandle | Promise<ProcessHandle>;
|
|
196
|
+
startFailed?(error: unknown, active: () => boolean): void | Promise<void>;
|
|
197
|
+
canConfirmExit?(): boolean;
|
|
198
|
+
quiesce?(): void | Promise<void>;
|
|
199
|
+
exited?(event: ChildExitEvent): void;
|
|
200
|
+
revoke?(): void;
|
|
201
|
+
/** Physical consumer cleanup, after its filesystem admission fence. */
|
|
202
|
+
stop?(): void | Promise<void>;
|
|
203
|
+
wake?(): void;
|
|
204
|
+
/** Release adapter ancestry after this root and its descendants no longer need it. */
|
|
205
|
+
retired?(): void;
|
|
206
|
+
}
|
|
207
|
+
export interface BrowserProcessBrokerOptions {
|
|
208
|
+
readonly reservations: RuntimeReservations;
|
|
209
|
+
hostIdentity?: RuntimeHostIdentity | null;
|
|
210
|
+
filesystem: ProcessFilesystem;
|
|
211
|
+
/** Injectable lazy supervisor module loader; pipe-only roots never invoke it. */
|
|
212
|
+
activate?: () => Promise<typeof import("../proc/index.js")>;
|
|
213
|
+
identities: ProcessIdentityAllocator;
|
|
214
|
+
registry: ExecutableRegistry;
|
|
215
|
+
table: ProcessTable;
|
|
216
|
+
launch(context: ProcessContext): ProcessHandle | Promise<ProcessHandle>;
|
|
217
|
+
launchCommand?(
|
|
218
|
+
context: CommandProcessContext,
|
|
219
|
+
capabilities: CommandCapabilities,
|
|
220
|
+
): ProcessHandle | Promise<ProcessHandle>;
|
|
221
|
+
onError?(error: unknown): void;
|
|
222
|
+
/** Opt-in metadata only; observers must not reenter process control. Exceptions are ignored. */
|
|
223
|
+
onProcessAdmission?: ProcessAdmissionObserver;
|
|
224
|
+
observeOperations?: boolean;
|
|
225
|
+
/** Memory group policy (W1-W3). Groups are created only by a launch that asks for one. */
|
|
226
|
+
memoryGroups?: MemoryGroupPolicyOptions;
|
|
227
|
+
}
|
|
228
|
+
/** "new" leads a fresh group; "inherit" joins the parent's group; a handle joins that group. */
|
|
229
|
+
export type MemoryGroupLaunch = "new" | "inherit" | MemoryGroupHandle;
|
|
230
|
+
/** An external root's group membership. Settle it only after the root's agent physically stopped. */
|
|
231
|
+
export interface RootMemoryGroupMember {
|
|
232
|
+
readonly group: MemoryGroupHandle;
|
|
233
|
+
/** Broker-owned request field for the root worker; transfer `transfer` with it. */
|
|
234
|
+
readonly request: MemoryGroupMemberRequest;
|
|
235
|
+
readonly transfer: readonly Transferable[];
|
|
236
|
+
/** Call in finally after this root's native terminate attempt, before awaiting its end. */
|
|
237
|
+
terminating(): void;
|
|
238
|
+
/** The embedder proved its root worker physically stopped. Idempotent. */
|
|
239
|
+
stopped(): void;
|
|
240
|
+
}
|
|
241
|
+
/** A reserved, admitted descendant of a runtime root whose adapter has not launched. */
|
|
242
|
+
export interface RuntimeDescendant {
|
|
243
|
+
readonly pid: number;
|
|
244
|
+
readonly parentPid: number;
|
|
245
|
+
readonly job: number;
|
|
246
|
+
/** A frozen structured clone of the spawn's metadata without the runtime-owned `filesystem`
|
|
247
|
+
* and `pipeRegistry` fields. Inherited fields are the parent's claims, not membership. */
|
|
248
|
+
readonly data: Readonly<Record<string, unknown>>;
|
|
249
|
+
}
|
|
250
|
+
export type RootPreparationCompletion =
|
|
251
|
+
| { readonly kind: "rolled-back"; readonly receipt: TerminalControlReceipt }
|
|
252
|
+
| {
|
|
253
|
+
readonly kind: "committed";
|
|
254
|
+
readonly entry: "not-entered" | "adapter-invoked";
|
|
255
|
+
readonly receipt: TerminalControlReceipt;
|
|
256
|
+
};
|
|
257
|
+
export interface RootDescendantPreparation {
|
|
258
|
+
readonly terminal: TerminalAuthority;
|
|
259
|
+
/** Synchronous, once under a granted root turn; publish local maps with turn.publish. */
|
|
260
|
+
run(descendant: RuntimeDescendant, turn: TerminalControlTurn): TerminalResult<void>;
|
|
261
|
+
/** Once before onChildExit/retirement can run. Committed means exit cleanup owns membership. */
|
|
262
|
+
settled?(descendant: RuntimeDescendant, completion: RootPreparationCompletion): undefined;
|
|
263
|
+
}
|
|
264
|
+
export interface RuntimeRootOptions {
|
|
265
|
+
readonly memory: readonly MemoryDeclaration[] | "group";
|
|
266
|
+
readonly signalDelegation?: SignalDelegation;
|
|
267
|
+
filesystem?: FilesystemIdentity;
|
|
268
|
+
acknowledged?(): boolean;
|
|
269
|
+
/** Takes every terminal byte of this root's processes, in order. Exclusive with tryOutput. */
|
|
270
|
+
output?(fd: 1 | 2, data: Uint8Array): void;
|
|
271
|
+
/**
|
|
272
|
+
* Bounded terminal destination. Return the exact accepted prefix length, 0 to data.length.
|
|
273
|
+
* The rest stays in its writer's bounded buffer and that writer waits, like a full TTY.
|
|
274
|
+
* Call ProcessService.outputDrained(rootPid) when room returns. Exclusive with output.
|
|
275
|
+
*/
|
|
276
|
+
tryOutput?(fd: 1 | 2, data: Uint8Array): number;
|
|
277
|
+
quiesce?(): void | Promise<void>;
|
|
278
|
+
stop?(): void | Promise<void>;
|
|
279
|
+
wake?(): void;
|
|
280
|
+
retired?(): void;
|
|
281
|
+
/** The kernel waits for this exact root authority before invoking run once, then enters
|
|
282
|
+
* the adapter in the same continuation. Promises from run are invalid. */
|
|
283
|
+
prepareDescendant?: RootDescendantPreparation;
|
|
284
|
+
}
|
|
285
|
+
export interface WorkerLaunchOptions<T extends RuntimeWorkerRequest = RuntimeWorkerRequest> {
|
|
286
|
+
/** Module entry stays inert until its first request. A fresh worker is created on demand. */
|
|
287
|
+
workerUrl: string;
|
|
288
|
+
readonly [preview1Launch]?: true;
|
|
289
|
+
notificationWorkerUrl?: string;
|
|
290
|
+
/** Explicit internal proof profile. Source admission is still mandatory. */
|
|
291
|
+
threaded?: ThreadLaunchOptions;
|
|
292
|
+
/** Ownership moves to the broker, including all failed launch and termination paths. */
|
|
293
|
+
network?: Preview1Network;
|
|
294
|
+
graphics?: GraphicsGrant;
|
|
295
|
+
request: Omit<
|
|
296
|
+
T,
|
|
297
|
+
| "filesystem"
|
|
298
|
+
| "runtimeProcess"
|
|
299
|
+
| "startupStderr"
|
|
300
|
+
| "hostIdentity"
|
|
301
|
+
| "notifications"
|
|
302
|
+
| "memoryObservation"
|
|
303
|
+
| "observation"
|
|
304
|
+
| "terminalOutput"
|
|
305
|
+
| "memoryGroup"
|
|
306
|
+
| "controlGrant"
|
|
307
|
+
| "network"
|
|
308
|
+
| "graphics"
|
|
309
|
+
>;
|
|
310
|
+
/** Join a memory group. Admission is reserved before the Worker is constructed. */
|
|
311
|
+
memoryGroup?: MemoryGroupLaunch;
|
|
312
|
+
/** Trusted adapter-created memories in addition to the module declarations. */
|
|
313
|
+
memories?: readonly MemoryDeclaration[];
|
|
314
|
+
cleanup?(): void;
|
|
315
|
+
onMessage?(message: unknown, context: ProcessContext): void;
|
|
316
|
+
wake?(): void;
|
|
317
|
+
executableName?(name: string): string;
|
|
318
|
+
}
|
|
319
|
+
interface DescendantHook {
|
|
320
|
+
readonly prepare: NonNullable<RuntimeRootOptions["prepareDescendant"]>;
|
|
321
|
+
readonly directory: string;
|
|
322
|
+
}
|
|
323
|
+
interface PendingPreparation {
|
|
324
|
+
readonly pid: number;
|
|
325
|
+
readonly rootPid: number;
|
|
326
|
+
readonly observation: ProcessObservationTransfer;
|
|
327
|
+
readonly controller: AbortController;
|
|
328
|
+
readonly settled: Promise<void>;
|
|
329
|
+
phase: "preparing" | "handed-off" | "settling" | "settled";
|
|
330
|
+
receipt: TerminalControlReceipt;
|
|
331
|
+
entry: "not-entered" | "adapter-invoked";
|
|
332
|
+
finish(): void;
|
|
333
|
+
}
|
|
334
|
+
const reservedDescendantData = ["filesystem", "pipeRegistry"];
|
|
335
|
+
/** Latest sampled linear-memory bytes, retained until successful physical cleanup. */
|
|
336
|
+
export interface WorkerMemoryObservation {
|
|
337
|
+
readonly pid: number;
|
|
338
|
+
readonly parentPid: number;
|
|
339
|
+
readonly rootPid: number;
|
|
340
|
+
readonly job: number;
|
|
341
|
+
readonly directory: string;
|
|
342
|
+
/** null until actual memory becomes visible; may be stale between host boundaries. */
|
|
343
|
+
readonly bytes: number | null;
|
|
344
|
+
}
|
|
345
|
+
interface PendingLaunch {
|
|
346
|
+
readonly observation: ProcessObservationTransfer;
|
|
347
|
+
readonly start: ProcessStartRecord;
|
|
348
|
+
acquiring: boolean;
|
|
349
|
+
readonly acquired: Promise<void>;
|
|
350
|
+
readonly settled: Promise<void>;
|
|
351
|
+
}
|
|
352
|
+
interface RuntimeLaunch {
|
|
353
|
+
active: boolean;
|
|
354
|
+
pending?: PendingLaunch;
|
|
355
|
+
}
|
|
356
|
+
interface RuntimeChild {
|
|
357
|
+
readonly generation: number;
|
|
358
|
+
operationCapture?: number;
|
|
359
|
+
readonly transport: WorkerProcessTransport;
|
|
360
|
+
readonly launch: RuntimeLaunch;
|
|
361
|
+
/** Shared with the pending launch that created this child. */
|
|
362
|
+
readonly start: ProcessStartRecord;
|
|
363
|
+
accesses?: WorkerExecutableAccess;
|
|
364
|
+
controllerStopping?: { pending: Promise<void>; controllerStop: boolean };
|
|
365
|
+
controller?: ProcessController;
|
|
366
|
+
controllerQuiet?: boolean;
|
|
367
|
+
capturedControllerStop?: () => void | Promise<void>;
|
|
368
|
+
controllerNativeReturn?: NativeReturnFollowers;
|
|
369
|
+
controllerNativeStop?: NativeStopHandle;
|
|
370
|
+
fence?: Promise<void>;
|
|
371
|
+
finalFence?: Promise<void>;
|
|
372
|
+
finalQuiet?: boolean;
|
|
373
|
+
revokeController?: () => void;
|
|
374
|
+
nativeReturned?: () => void;
|
|
375
|
+
threads?: Promise<ThreadAggregate | undefined>;
|
|
376
|
+
memory: BigInt64Array;
|
|
377
|
+
identity: Omit<WorkerMemoryObservation, "bytes">;
|
|
378
|
+
notifications?: NotificationBridge;
|
|
379
|
+
filesystem: FilesystemIdentity;
|
|
380
|
+
context: ProcessContext;
|
|
381
|
+
worker?: Worker;
|
|
382
|
+
acknowledged: boolean;
|
|
383
|
+
/** The worker reported that its guest finished (exit, error or a worker error). */
|
|
384
|
+
guestEnded?: boolean;
|
|
385
|
+
/** Resolves a stop waiting for guestEnded (see terminateWorker). */
|
|
386
|
+
endGuest?: () => void;
|
|
387
|
+
replacementAcknowledged?: boolean;
|
|
388
|
+
failed: boolean;
|
|
389
|
+
stopped: boolean;
|
|
390
|
+
quiescence?: Promise<void>;
|
|
391
|
+
stopping?: Promise<void>;
|
|
392
|
+
/** Borrowed Worker stop excludes adapter-owned work and member/process retirement. */
|
|
393
|
+
nativeStopping?: Promise<void>;
|
|
394
|
+
/** Exact accepted entry handle, captured before acquisition is published. */
|
|
395
|
+
adapter?: ProcessHandle;
|
|
396
|
+
replacing?: boolean;
|
|
397
|
+
startupStderr?: PipeEndpoint;
|
|
398
|
+
network?: Preview1Network;
|
|
399
|
+
graphics?: GraphicsGrant;
|
|
400
|
+
cleanup?(): void;
|
|
401
|
+
wake?(): void;
|
|
402
|
+
output?: TerminalOutputReader;
|
|
403
|
+
group?: MemberLease;
|
|
404
|
+
ticket?: Ticket;
|
|
405
|
+
launched?: LaunchedTicket;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** Page-owned process admission and descriptor transport. Guest adapter policy is injected. */
|
|
409
|
+
const originalGraphicsGrants = new WeakMap<GraphicsGrant, GraphicsGrant>();
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* How long a stop waits for a signalled guest to unwind before terminate(). A guest polling
|
|
413
|
+
* runtime_proc.signal(0, 4) takes about a millisecond; this only caps one that never polls.
|
|
414
|
+
*/
|
|
415
|
+
const STOP_UNWIND_MS = 1000;
|
|
416
|
+
|
|
417
|
+
/** Messages a worker posts last, once its guest can no longer run (browser/worker.ts finish). */
|
|
418
|
+
function guestFinished(type: RuntimeWorkerMessage["type"] | undefined): boolean {
|
|
419
|
+
return (
|
|
420
|
+
type === "exit" || type === "error" || type === "cleanup-error" || type === "observation-error"
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function guestEnded(child: RuntimeChild): void {
|
|
425
|
+
child.guestEnded = true;
|
|
426
|
+
child.endGuest?.();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** True once executable entry committed: guest code may be running on this worker. */
|
|
430
|
+
function guestEntered(child: RuntimeChild): boolean {
|
|
431
|
+
try {
|
|
432
|
+
return startStatus(child.context.outcome) === 0;
|
|
433
|
+
} catch {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Waits until the worker reports that its guest finished, or STOP_UNWIND_MS. No wait when no
|
|
440
|
+
* guest code can be running: it never entered, already finished, or is parked in a group
|
|
441
|
+
* futex wait, which SIGKILL does not wake. closeParked() closes that wait record first, so a
|
|
442
|
+
* timed or sibling wake before terminate() throws instead of resuming guest code.
|
|
443
|
+
*/
|
|
444
|
+
function guestUnwound(child: RuntimeChild): Promise<void> | undefined {
|
|
445
|
+
if (child.guestEnded || !guestEntered(child)) return;
|
|
446
|
+
if (child.group?.closeParked()) return;
|
|
447
|
+
const unwound = Promise.withResolvers<void>();
|
|
448
|
+
const cap = setTimeout(unwound.resolve, STOP_UNWIND_MS);
|
|
449
|
+
child.endGuest = unwound.resolve;
|
|
450
|
+
return unwound.promise.finally(() => {
|
|
451
|
+
clearTimeout(cap);
|
|
452
|
+
child.endGuest = undefined;
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function senderRevoked(
|
|
457
|
+
result: ReturnType<typeof readOutcome>,
|
|
458
|
+
filesystemRevoked: boolean,
|
|
459
|
+
): boolean {
|
|
460
|
+
return result?.kind === "signaled" || (!result && filesystemRevoked);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
interface CommandRootState {
|
|
464
|
+
readonly root: WorkerProcessTransport;
|
|
465
|
+
readonly pending: Set<Promise<void>>;
|
|
466
|
+
readonly failures: Map<WorkerProcessTransport, unknown>;
|
|
467
|
+
stopped: boolean;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
export class BrowserProcessBroker {
|
|
471
|
+
private readonly hostIdentity: RuntimeHostIdentity | null;
|
|
472
|
+
private suspended = false;
|
|
473
|
+
private readonly pendingPreparations = new Set<PendingPreparation>();
|
|
474
|
+
private readonly retirementGate = Promise.withResolvers<void>();
|
|
475
|
+
private disposing?: Promise<void>;
|
|
476
|
+
private activation?: Promise<ProcessSupervisor>;
|
|
477
|
+
private supervisor?: ProcessSupervisor;
|
|
478
|
+
private readonly pipes: WorkerPipeBroker;
|
|
479
|
+
private readonly workers = new ReadyWorkerPool();
|
|
480
|
+
private readonly roots = new Map<number, WorkerProcessTransport>();
|
|
481
|
+
private readonly reservedRoots = new Map<
|
|
482
|
+
number,
|
|
483
|
+
RootProcessOptions &
|
|
484
|
+
SignalTransport & {
|
|
485
|
+
pid: number;
|
|
486
|
+
job: number;
|
|
487
|
+
observation: ProcessObservationTransfer;
|
|
488
|
+
processIdentity: LogicalProcessIdentity;
|
|
489
|
+
}
|
|
490
|
+
>();
|
|
491
|
+
private readonly completedRoots = new Set<number>();
|
|
492
|
+
private commandRoots?: Map<number, CommandRootState>;
|
|
493
|
+
private readonly rootLeases = new Map<number, number>();
|
|
494
|
+
private readonly controllers = new Map<number, ProcessController>();
|
|
495
|
+
private readonly signalPolicies = new Map<
|
|
496
|
+
number,
|
|
497
|
+
{ controller: ProcessController; packages: ReadonlySet<object> }
|
|
498
|
+
>();
|
|
499
|
+
private revokedControllers = new Set<number>();
|
|
500
|
+
private quiescedControllers = new Set<number>();
|
|
501
|
+
private controllerStops?: Map<number, { pending: Promise<void>; controllerStop: boolean }>;
|
|
502
|
+
private launches?: Set<number>;
|
|
503
|
+
private pendingLaunches?: Map<number, PendingLaunch>;
|
|
504
|
+
private readonly settledGroupAcquisitions = new Set<string>();
|
|
505
|
+
private readonly groupAdmissionWatches = new Map<SharedArrayBuffer, Int32Array>();
|
|
506
|
+
private readonly descendantHooks = new Map<number, DescendantHook>();
|
|
507
|
+
private readonly outputs = new Map<number, TerminalOutputDelivery | undefined>();
|
|
508
|
+
/** Each root's terminal output: live writers and stopped writers' accepted bytes. */
|
|
509
|
+
private readonly terminalOutputs = new Map<number, TerminalOutputBudget>();
|
|
510
|
+
private readonly registries = new Map<number, PipePublicationRegistry>();
|
|
511
|
+
private readonly children = new Map<number, RuntimeChild>();
|
|
512
|
+
#operations?: OperationOwner;
|
|
513
|
+
#operationsUnavailable = false;
|
|
514
|
+
private readonly launchStates = new WeakMap<object, RuntimeLaunch>();
|
|
515
|
+
private readonly fences = new Map<number, Promise<void>>();
|
|
516
|
+
private readonly startupDiagnostics = new Set<Promise<void>>();
|
|
517
|
+
private readonly rejectedTransfers = new Map<string, Promise<void>>();
|
|
518
|
+
private cleanupCodec?: WorkerDescriptorCodec;
|
|
519
|
+
private readonly acquiredProcesses = new Map<number, string>();
|
|
520
|
+
private readonly retainedRootStops = new Map<number, ProcessController>();
|
|
521
|
+
private readonly capturedControllerRevocations = new Map<number, () => void>();
|
|
522
|
+
private readonly capturedControllerStops = new Map<number, () => void | Promise<void>>();
|
|
523
|
+
private readonly controllerNativeReturns = new Map<number, NativeReturnFollowers>();
|
|
524
|
+
private readonly controllerNativeStops = new Map<number, NativeStopHandle>();
|
|
525
|
+
private readonly observationOwners = new Map<number, NativeObservationOwner>();
|
|
526
|
+
private readonly neverConstructed = new WeakMap<object, number>();
|
|
527
|
+
private readonly nativeLaunchReturns = new Map<number, () => void>();
|
|
528
|
+
private readonly imageStops = new Map<number, Promise<void>>();
|
|
529
|
+
private readonly replacementDiagnostics = new WeakSet<object>();
|
|
530
|
+
private readonly terminalLifetimes = new Map<number, TerminalProcessLifetime>();
|
|
531
|
+
private groups?: MemoryGroups;
|
|
532
|
+
private rootGroups?: Map<number, MemberLease>;
|
|
533
|
+
private readonly rootAdmissions = new Map<number, Ticket>();
|
|
534
|
+
private readonly rootTickets = new Map<number, LaunchedTicket>();
|
|
535
|
+
private readonly rootGrants = new Map<number, SharedControlGrant>();
|
|
536
|
+
private readonly stopTrackingConsumers: () => void;
|
|
537
|
+
private readonly accesses = new WorkerExecutableAccess({
|
|
538
|
+
active: (sender) => !this.suspended && !isRevoked(this.filesystem(sender)),
|
|
539
|
+
check: async (_sender, path, cwd, active) => {
|
|
540
|
+
await this.options.registry.check(path, cwd, active);
|
|
541
|
+
return 0;
|
|
542
|
+
},
|
|
543
|
+
});
|
|
544
|
+
private timer: ReturnType<typeof setTimeout> | null = null;
|
|
545
|
+
private readonly transport: WorkerProcessBroker;
|
|
546
|
+
constructor(private readonly options: BrowserProcessBrokerOptions) {
|
|
547
|
+
this.pipes = new WorkerPipeBroker({
|
|
548
|
+
allocateShared: (length) =>
|
|
549
|
+
options.reservations.buffer("control", { kind: "fixed-buffer", length: bytes(length) }),
|
|
550
|
+
});
|
|
551
|
+
void this.retirementGate.promise.catch(() => {});
|
|
552
|
+
this.hostIdentity = snapshotHostIdentity(options.hostIdentity);
|
|
553
|
+
this.transport = new WorkerProcessBroker({
|
|
554
|
+
supervisor: () => this.ready(),
|
|
555
|
+
codec: (transport) => this.descriptorCodec(transport),
|
|
556
|
+
discard: (token) => this.discardCodec().discard(token),
|
|
557
|
+
onPipe: (handle) =>
|
|
558
|
+
this.pipes.attach(handle as import("../proc/pipes.js").PipeEndpointHandle),
|
|
559
|
+
pumpPipes: () => this.pipes.pump(),
|
|
560
|
+
onError: (error) => this.report(error),
|
|
561
|
+
onAdmission: options.onProcessAdmission,
|
|
562
|
+
nativeReturn: (transport) => this.processNativeReturn(transport),
|
|
563
|
+
onAdmitted: (transport) => this.acquireProcess(transport),
|
|
564
|
+
quiesce: (_pid, transport) => this.quiesceUnstarted(transport),
|
|
565
|
+
beforeAdmit: (transport) => this.checkCommandAdmission(transport),
|
|
566
|
+
transferCleanup: (transport, cleanup) => this.trackCommandTransfer(transport, cleanup),
|
|
567
|
+
retireRejected: (transport) => this.retireRejectedCommand(transport),
|
|
568
|
+
canExec: (transport) => this.canExec(transport),
|
|
569
|
+
discardExec: (transport) => {
|
|
570
|
+
const filesystem = this.filesystem(transport);
|
|
571
|
+
this.options.filesystem.revoke(filesystem);
|
|
572
|
+
if (this.commandScope(transport)) return this.options.filesystem.quiesce(filesystem);
|
|
573
|
+
this.options.filesystem.reap(filesystem);
|
|
574
|
+
},
|
|
575
|
+
});
|
|
576
|
+
this.stopTrackingConsumers = options.table.onRemove((record) => {
|
|
577
|
+
this.releaseAcquiredProcess(record.pid);
|
|
578
|
+
this.settledGroupAcquisitions.delete(observationKey(record.observation));
|
|
579
|
+
this.groups?.settleStopping();
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
ready(): Promise<ProcessSupervisor> {
|
|
583
|
+
return (this.activation ??= (this.options.activate?.() ?? import("../proc/index.js")).then(
|
|
584
|
+
(proc) => {
|
|
585
|
+
const supervisor = (this.supervisor = new proc.ProcessSupervisor({
|
|
586
|
+
registry: this.options.registry,
|
|
587
|
+
byteBackedGuestOnly: (rootPid) =>
|
|
588
|
+
rootPid !== undefined && !!this.commandRoots?.has(rootPid),
|
|
589
|
+
table: this.options.table,
|
|
590
|
+
launch: (context) => this.launchPrepared(context),
|
|
591
|
+
launchCommand: (context) => this.launchPrepared(context),
|
|
592
|
+
canConfirmExit: (pid) => {
|
|
593
|
+
const child = this.children.get(pid);
|
|
594
|
+
return (
|
|
595
|
+
this.suspended ||
|
|
596
|
+
(child
|
|
597
|
+
? child.threads !== undefined || child.acknowledged || child.failed
|
|
598
|
+
: (this.controllerFor(pid)?.canConfirmExit?.() ?? true))
|
|
599
|
+
);
|
|
600
|
+
},
|
|
601
|
+
quiesce: (pid) => this.quiesceProcess(pid),
|
|
602
|
+
retire: (pid) => this.retireProcess(pid),
|
|
603
|
+
stopImage: (pid, generation, active) => this.stopImage(pid, generation, active),
|
|
604
|
+
commitReplacement: (pid, generation, resolved) =>
|
|
605
|
+
this.commitReplacement(pid, generation, resolved),
|
|
606
|
+
replacementFailed: (pid, error) => this.reportReplacementFailure(pid, error),
|
|
607
|
+
staleImage: (pid) => {
|
|
608
|
+
const record = this.options.table.get(pid);
|
|
609
|
+
if (record) this.traceProcess(record, "dropped", "stale-image");
|
|
610
|
+
},
|
|
611
|
+
startFailed: (pid, error, active) => this.writeStartupDiagnostic(pid, error, active),
|
|
612
|
+
onError: (error) => this.report(error),
|
|
613
|
+
}));
|
|
614
|
+
supervisor.onChildExit((event) => {
|
|
615
|
+
this.revokeRuntimeProcess(event.pid);
|
|
616
|
+
const transport = this.transport.get(event.pid);
|
|
617
|
+
if (transport && !this.children.get(event.pid)?.acknowledged)
|
|
618
|
+
this.options.filesystem.revoke(this.filesystem(transport));
|
|
619
|
+
void (async () => {
|
|
620
|
+
try {
|
|
621
|
+
this.controllerFor(event.pid)?.exited?.(event);
|
|
622
|
+
} finally {
|
|
623
|
+
// Notification failures cannot skip failed-start cleanup. Report them only
|
|
624
|
+
// after the same fenced physical stop used by successful notifications.
|
|
625
|
+
const child = this.children.get(event.pid);
|
|
626
|
+
if (child) await this.stop(child);
|
|
627
|
+
else {
|
|
628
|
+
await this.pendingLaunches?.get(event.pid)?.settled;
|
|
629
|
+
if (!this.launches?.has(event.pid)) await this.stopController(event.pid);
|
|
630
|
+
}
|
|
631
|
+
this.observationOwners.get(event.pid)?.close();
|
|
632
|
+
this.retireRoots();
|
|
633
|
+
}
|
|
634
|
+
})().catch((error) => this.report(error));
|
|
635
|
+
});
|
|
636
|
+
supervisor.onProcessQuiescent((event) => {
|
|
637
|
+
this.fences.delete(event.pid);
|
|
638
|
+
this.releaseAcquiredProcess(event.pid);
|
|
639
|
+
this.groups?.settleStopping();
|
|
640
|
+
});
|
|
641
|
+
supervisor.onJobReap(() => this.retireRoots());
|
|
642
|
+
for (const root of this.reservedRoots.values())
|
|
643
|
+
if (!supervisor.get(root.pid)) {
|
|
644
|
+
supervisor.createRoot(root);
|
|
645
|
+
supervisor.registerRevocation(root.pid, () => this.revokeController(root.pid));
|
|
646
|
+
}
|
|
647
|
+
for (const transport of this.roots.values())
|
|
648
|
+
this.activateRuntimeRoot(supervisor, transport);
|
|
649
|
+
if (this.suspended) supervisor.dispose();
|
|
650
|
+
return supervisor;
|
|
651
|
+
},
|
|
652
|
+
));
|
|
653
|
+
}
|
|
654
|
+
private async launchPrepared(
|
|
655
|
+
context: ProcessContext | CommandProcessContext,
|
|
656
|
+
): Promise<ProcessHandle> {
|
|
657
|
+
const descendant = this.descendant(context.pid);
|
|
658
|
+
if (!descendant) return this.launchAdapter(context);
|
|
659
|
+
return this.prepareDescendant(context, descendant.hook, descendant.transport);
|
|
660
|
+
}
|
|
661
|
+
/** Required preparation is captured before any asynchronous acquisition. */
|
|
662
|
+
private descendant(pid: number) {
|
|
663
|
+
const transport = this.transport.get(pid);
|
|
664
|
+
if (!transport) return undefined;
|
|
665
|
+
const { rootPid } = workerProcessState(transport);
|
|
666
|
+
const hook = rootPid === pid ? undefined : this.descendantHooks.get(rootPid);
|
|
667
|
+
if (!hook || hook.directory !== workerProcessDirectoryId(transport)) return undefined;
|
|
668
|
+
return { hook, transport };
|
|
669
|
+
}
|
|
670
|
+
private preparationFailure(
|
|
671
|
+
context: ProcessContext | CommandProcessContext,
|
|
672
|
+
hook: DescendantHook,
|
|
673
|
+
rootPid: number,
|
|
674
|
+
): TerminalFailure | undefined {
|
|
675
|
+
if (this.suspended || this.descendantHooks.get(rootPid) !== hook) return "CANCELED";
|
|
676
|
+
if (
|
|
677
|
+
this.options.table.get(context.pid)?.image.generation !== context.generation ||
|
|
678
|
+
readOutcome(context.outcome)
|
|
679
|
+
)
|
|
680
|
+
return "CANCELED";
|
|
681
|
+
const root = this.roots.get(rootPid);
|
|
682
|
+
if (!root || readOutcome(workerProcessState(root).signals.outcome)) return "PROCESS_GONE";
|
|
683
|
+
return undefined;
|
|
684
|
+
}
|
|
685
|
+
private beginPreparation(
|
|
686
|
+
context: ProcessContext | CommandProcessContext,
|
|
687
|
+
rootPid: number,
|
|
688
|
+
initial: TerminalControlReceipt,
|
|
689
|
+
hook: DescendantHook,
|
|
690
|
+
descendant: RuntimeDescendant,
|
|
691
|
+
): PendingPreparation {
|
|
692
|
+
const controller = new AbortController();
|
|
693
|
+
const release = this.retainRoot(rootPid);
|
|
694
|
+
let settle!: () => void;
|
|
695
|
+
const settled = new Promise<void>((resolve) => {
|
|
696
|
+
settle = resolve;
|
|
697
|
+
});
|
|
698
|
+
const record: PendingPreparation = {
|
|
699
|
+
pid: context.pid,
|
|
700
|
+
rootPid,
|
|
701
|
+
observation: context.observation,
|
|
702
|
+
controller,
|
|
703
|
+
settled,
|
|
704
|
+
phase: "preparing",
|
|
705
|
+
receipt: initial,
|
|
706
|
+
entry: "not-entered",
|
|
707
|
+
finish: () => {
|
|
708
|
+
if (record.phase === "settled" || record.phase === "settling") return;
|
|
709
|
+
record.phase = "settling";
|
|
710
|
+
const completion: RootPreparationCompletion =
|
|
711
|
+
record.receipt.phase === "committed"
|
|
712
|
+
? { kind: "committed", entry: record.entry, receipt: record.receipt }
|
|
713
|
+
: { kind: "rolled-back", receipt: record.receipt };
|
|
714
|
+
try {
|
|
715
|
+
const notification: unknown = hook.prepare.settled?.(descendant, completion);
|
|
716
|
+
if (notification !== undefined) {
|
|
717
|
+
if (isInstance(notification, PromiseConstructor)) observeRejectedPromise(notification);
|
|
718
|
+
throw new TypeError("preparation settlement must return undefined synchronously");
|
|
719
|
+
}
|
|
720
|
+
} catch (error) {
|
|
721
|
+
this.report(error);
|
|
722
|
+
} finally {
|
|
723
|
+
this.pendingPreparations.delete(record);
|
|
724
|
+
record.phase = "settled";
|
|
725
|
+
settle();
|
|
726
|
+
release();
|
|
727
|
+
this.groups?.settleStopping();
|
|
728
|
+
}
|
|
729
|
+
},
|
|
730
|
+
};
|
|
731
|
+
this.pendingPreparations.add(record);
|
|
732
|
+
context.registerRevocation(() => {
|
|
733
|
+
if (record.phase === "preparing") controller.abort();
|
|
734
|
+
});
|
|
735
|
+
return record;
|
|
736
|
+
}
|
|
737
|
+
private async watchPreparation(
|
|
738
|
+
context: ProcessContext | CommandProcessContext,
|
|
739
|
+
hook: DescendantHook,
|
|
740
|
+
transport: WorkerProcessTransport,
|
|
741
|
+
record: PendingPreparation,
|
|
742
|
+
): Promise<void> {
|
|
743
|
+
const wake = new Int32Array(transport.directory, 4, 1);
|
|
744
|
+
while (this.pendingPreparations.has(record) && record.phase === "preparing") {
|
|
745
|
+
const seen = Atomics.load(wake, 0);
|
|
746
|
+
if (this.preparationFailure(context, hook, record.rootPid)) {
|
|
747
|
+
record.controller.abort();
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
const waiting = atomicsWaitAsync(wake, 0, seen);
|
|
751
|
+
if (waiting.async) await waiting.value;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
private async prepareDescendant(
|
|
755
|
+
context: ProcessContext | CommandProcessContext,
|
|
756
|
+
hook: DescendantHook,
|
|
757
|
+
transport: WorkerProcessTransport,
|
|
758
|
+
): Promise<ProcessHandle> {
|
|
759
|
+
const state = workerProcessState(transport);
|
|
760
|
+
const root = this.roots.get(state.rootPid);
|
|
761
|
+
if (!root) throw new ProcessError(ProcessErrno.CANCELED, "preparation root is gone");
|
|
762
|
+
const claims = { ...(transport.data as Record<string, unknown>) };
|
|
763
|
+
for (const key of reservedDescendantData) delete claims[key];
|
|
764
|
+
const descendant = Object.freeze({
|
|
765
|
+
pid: state.pid,
|
|
766
|
+
parentPid: state.parentPid,
|
|
767
|
+
job: state.job,
|
|
768
|
+
data: Object.freeze(structuredClone(claims)),
|
|
769
|
+
});
|
|
770
|
+
const initial = terminalPreparationReceipt(hook.prepare.terminal, root);
|
|
771
|
+
const record = this.beginPreparation(context, state.rootPid, initial, hook, descendant);
|
|
772
|
+
void this.watchPreparation(context, hook, transport, record).catch((error) => {
|
|
773
|
+
record.controller.abort();
|
|
774
|
+
this.report(error);
|
|
775
|
+
});
|
|
776
|
+
try {
|
|
777
|
+
const result = await prepareTerminalDescendant({
|
|
778
|
+
terminal: hook.prepare.terminal,
|
|
779
|
+
root,
|
|
780
|
+
signal: record.controller.signal,
|
|
781
|
+
check: () => this.preparationFailure(context, hook, state.rootPid),
|
|
782
|
+
settled: (receipt) => {
|
|
783
|
+
record.receipt = receipt;
|
|
784
|
+
},
|
|
785
|
+
work: (turn) => hook.prepare.run(descendant, turn),
|
|
786
|
+
finish: (result, receipt) => {
|
|
787
|
+
record.receipt = receipt;
|
|
788
|
+
try {
|
|
789
|
+
if (result.kind === "error") throw terminalPreparationError(result.code);
|
|
790
|
+
const failure = this.preparationFailure(context, hook, state.rootPid);
|
|
791
|
+
if (failure) throw terminalPreparationError(failure);
|
|
792
|
+
record.phase = "handed-off";
|
|
793
|
+
record.entry = "adapter-invoked";
|
|
794
|
+
wakeDirectory(transport.directory);
|
|
795
|
+
return this.launchAdapter(context);
|
|
796
|
+
} finally {
|
|
797
|
+
record.finish();
|
|
798
|
+
wakeDirectory(transport.directory);
|
|
799
|
+
}
|
|
800
|
+
},
|
|
801
|
+
});
|
|
802
|
+
if (result.kind === "error") throw terminalPreparationError(result.code);
|
|
803
|
+
return result.value;
|
|
804
|
+
} finally {
|
|
805
|
+
record.finish();
|
|
806
|
+
wakeDirectory(transport.directory);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
private cancelPreparations(pid?: number): void {
|
|
810
|
+
for (const record of this.pendingPreparations)
|
|
811
|
+
if (
|
|
812
|
+
record.phase === "preparing" &&
|
|
813
|
+
(pid === undefined || record.pid === pid || record.rootPid === pid)
|
|
814
|
+
)
|
|
815
|
+
record.controller.abort();
|
|
816
|
+
}
|
|
817
|
+
private launchAdapter(
|
|
818
|
+
context: ProcessContext | CommandProcessContext,
|
|
819
|
+
): ProcessHandle | Promise<ProcessHandle> {
|
|
820
|
+
if (this.suspended) throw new Error("Process broker is disposed");
|
|
821
|
+
const transport = this.transport.get(context.pid);
|
|
822
|
+
const command = transport && this.commandScope(transport);
|
|
823
|
+
if (command) {
|
|
824
|
+
this.traceProcess(context, "launching");
|
|
825
|
+
this.checkCommandAdmission(transport);
|
|
826
|
+
}
|
|
827
|
+
this.acquireObservation(context.observation, true);
|
|
828
|
+
const observation = this.observationOwners.get(context.pid);
|
|
829
|
+
const nativeReturned = this.nativeLaunchReturns.get(context.pid) ?? observation?.acquire();
|
|
830
|
+
let controllerReturn: NativeReturnFollowers | undefined;
|
|
831
|
+
const failedLaunch = (error: unknown) => {
|
|
832
|
+
const child = this.children.get(context.pid);
|
|
833
|
+
if (child?.generation === context.generation) return;
|
|
834
|
+
if (
|
|
835
|
+
typeof error === "object" &&
|
|
836
|
+
error !== null &&
|
|
837
|
+
this.neverConstructed.get(error) === context.pid
|
|
838
|
+
) {
|
|
839
|
+
if (context.generation === 1) nativeReturned?.();
|
|
840
|
+
} else if (controllerReturn && nativeReturned) controllerReturn.follow(nativeReturned);
|
|
841
|
+
else {
|
|
842
|
+
this.imageStops.delete(context.pid);
|
|
843
|
+
observation?.fail(error);
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
const invokeLauncher = (): ProcessHandle | Promise<ProcessHandle> => {
|
|
847
|
+
if ("command" in context) return this.launchCommand(context);
|
|
848
|
+
if (command || context.execution?.kind === "host") return this.options.launch(context);
|
|
849
|
+
const controller = this.controllerFor(context.pid);
|
|
850
|
+
if (!controller?.launch) return this.options.launch(context);
|
|
851
|
+
controllerReturn = this.controllerNativeReturnFor(context.pid);
|
|
852
|
+
const candidate = controller.launch(context);
|
|
853
|
+
if (candidate !== undefined && candidate !== null) return candidate;
|
|
854
|
+
controllerReturn = undefined;
|
|
855
|
+
return this.options.launch(context);
|
|
856
|
+
};
|
|
857
|
+
if (nativeReturned) this.nativeLaunchReturns.set(context.pid, nativeReturned);
|
|
858
|
+
if (!command) this.traceProcess(context, "launching");
|
|
859
|
+
const launch = this.launchState(context);
|
|
860
|
+
launch.active = true;
|
|
861
|
+
(this.launches ??= new Set()).add(context.pid);
|
|
862
|
+
let acquireLaunch!: () => void, settleLaunch!: () => void;
|
|
863
|
+
// A launcher may select an outcome synchronously before returning its handle.
|
|
864
|
+
// Retain its cleanup authority before invoking any adapter code.
|
|
865
|
+
const pendingLaunch = {
|
|
866
|
+
observation: context.observation,
|
|
867
|
+
start: processStartRecord(context),
|
|
868
|
+
acquiring: true,
|
|
869
|
+
acquired: new Promise<void>((resolve) => {
|
|
870
|
+
acquireLaunch = resolve;
|
|
871
|
+
}),
|
|
872
|
+
settled: new Promise<void>((resolve) => {
|
|
873
|
+
settleLaunch = resolve;
|
|
874
|
+
}),
|
|
875
|
+
};
|
|
876
|
+
launch.pending = pendingLaunch;
|
|
877
|
+
this.settledGroupAcquisitions.delete(observationKey(context.observation));
|
|
878
|
+
(this.pendingLaunches ??= new Map()).set(context.pid, pendingLaunch);
|
|
879
|
+
const settled = () => {
|
|
880
|
+
pendingLaunch.acquiring = false;
|
|
881
|
+
this.settledGroupAcquisitions.add(observationKey(context.observation));
|
|
882
|
+
launch.pending = undefined;
|
|
883
|
+
if (this.pendingLaunches?.get(context.pid) === pendingLaunch)
|
|
884
|
+
this.pendingLaunches.delete(context.pid);
|
|
885
|
+
this.releaseAcquiredProcess(context.pid);
|
|
886
|
+
acquireLaunch();
|
|
887
|
+
settleLaunch();
|
|
888
|
+
this.groups?.settleStopping();
|
|
889
|
+
};
|
|
890
|
+
let launched: ProcessHandle | Promise<ProcessHandle>;
|
|
891
|
+
try {
|
|
892
|
+
launched = invokeLauncher();
|
|
893
|
+
} catch (error) {
|
|
894
|
+
failedLaunch(error);
|
|
895
|
+
launch.active = false;
|
|
896
|
+
this.launches.delete(context.pid);
|
|
897
|
+
settled();
|
|
898
|
+
throw error;
|
|
899
|
+
}
|
|
900
|
+
const track = (handle: ProcessHandle): ProcessHandle => {
|
|
901
|
+
pendingLaunch.acquiring = false;
|
|
902
|
+
this.settledGroupAcquisitions.add(observationKey(context.observation));
|
|
903
|
+
// Worker acquisition already clears the previous image's stop. A late handle
|
|
904
|
+
// must retain the stop started while its adapter acquisition was pending.
|
|
905
|
+
this.traceProcess(context, "launched");
|
|
906
|
+
const terminal = this.terminalLifetimes.get(context.pid);
|
|
907
|
+
if (this.children.has(context.pid) || !this.controllerFor(context.pid)) {
|
|
908
|
+
const child = this.children.get(context.pid);
|
|
909
|
+
const adapter =
|
|
910
|
+
child?.generation === context.generation
|
|
911
|
+
? (child.adapter = ownedAdapterHandle(handle))
|
|
912
|
+
: undefined;
|
|
913
|
+
launch.active = false;
|
|
914
|
+
this.launches?.delete(context.pid);
|
|
915
|
+
settled();
|
|
916
|
+
return this.children.has(context.pid)
|
|
917
|
+
? (adapter ?? handle)
|
|
918
|
+
: this.bindRootGroup(
|
|
919
|
+
context.pid,
|
|
920
|
+
nativeStopHandle(
|
|
921
|
+
handle,
|
|
922
|
+
terminal,
|
|
923
|
+
nativeReturned,
|
|
924
|
+
() => observation?.close(),
|
|
925
|
+
(error) => observation?.fail(error),
|
|
926
|
+
),
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
acquireLaunch();
|
|
930
|
+
const ownedHandle = this.bindRootGroup(
|
|
931
|
+
context.pid,
|
|
932
|
+
nativeStopHandle(
|
|
933
|
+
handle,
|
|
934
|
+
terminal,
|
|
935
|
+
nativeReturned,
|
|
936
|
+
() => observation?.close(),
|
|
937
|
+
(error) => observation?.fail(error),
|
|
938
|
+
),
|
|
939
|
+
);
|
|
940
|
+
this.groups?.settleStopping();
|
|
941
|
+
// External launchers own their physical handle. Keep controller authority until
|
|
942
|
+
// that handle's asynchronous cleanup settles, not merely its child-exit event.
|
|
943
|
+
return {
|
|
944
|
+
terminate: () => {
|
|
945
|
+
let pending: void | Promise<void>;
|
|
946
|
+
try {
|
|
947
|
+
const stopped = ownedHandle.terminate();
|
|
948
|
+
const stopController = this.controllerNativeStopFor(context.pid);
|
|
949
|
+
const stopCapturedController = () => stopController?.terminate();
|
|
950
|
+
pending = stopped ? stopped.then(stopCapturedController) : stopCapturedController();
|
|
951
|
+
} catch (error) {
|
|
952
|
+
settled();
|
|
953
|
+
throw error;
|
|
954
|
+
}
|
|
955
|
+
if (pending) {
|
|
956
|
+
const stopping = pending
|
|
957
|
+
.then(() => {
|
|
958
|
+
this.controllerStops?.delete(context.pid);
|
|
959
|
+
launch.active = false;
|
|
960
|
+
this.launches?.delete(context.pid);
|
|
961
|
+
this.retireChildController(context.pid);
|
|
962
|
+
})
|
|
963
|
+
.finally(settled);
|
|
964
|
+
(this.controllerStops ??= new Map()).set(context.pid, {
|
|
965
|
+
pending: stopping,
|
|
966
|
+
controllerStop: false,
|
|
967
|
+
});
|
|
968
|
+
return stopping;
|
|
969
|
+
}
|
|
970
|
+
launch.active = false;
|
|
971
|
+
this.launches?.delete(context.pid);
|
|
972
|
+
this.retireChildController(context.pid);
|
|
973
|
+
settled();
|
|
974
|
+
},
|
|
975
|
+
};
|
|
976
|
+
};
|
|
977
|
+
if (!("then" in launched)) return track(launched);
|
|
978
|
+
// Disposal owns late external handles too. Settlement follows physical cleanup,
|
|
979
|
+
// not just promise resolution, so retirement cannot outrun a pending launcher.
|
|
980
|
+
return Promise.resolve(launched).then(track, (error) => {
|
|
981
|
+
failedLaunch(error);
|
|
982
|
+
launch.active = false;
|
|
983
|
+
this.launches?.delete(context.pid);
|
|
984
|
+
settled();
|
|
985
|
+
// A terminal outcome can win while this external launcher is still pending.
|
|
986
|
+
if (readOutcome(context.outcome))
|
|
987
|
+
void this.stopController(context.pid)?.catch((error) => this.report(error));
|
|
988
|
+
throw error;
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
private launchCommand(context: CommandProcessContext): ProcessHandle | Promise<ProcessHandle> {
|
|
992
|
+
const launch = this.options.launchCommand;
|
|
993
|
+
if (!launch) throw new ProcessError(45, "Host commands are unavailable");
|
|
994
|
+
const record = this.options.table.require(context.pid);
|
|
995
|
+
const rootPid = record.rootPid;
|
|
996
|
+
if (rootPid === undefined) throw new ProcessError(ProcessErrno.SRCH, "Command root is missing");
|
|
997
|
+
const root = this.options.table.require(rootPid);
|
|
998
|
+
const processes: ProcessQuery = Object.freeze({
|
|
999
|
+
snapshot: () => {
|
|
1000
|
+
if (
|
|
1001
|
+
this.suspended ||
|
|
1002
|
+
record.revoked ||
|
|
1003
|
+
root.revoked ||
|
|
1004
|
+
this.options.table.get(rootPid) !== root ||
|
|
1005
|
+
readOutcome(root.outcome) ||
|
|
1006
|
+
readOutcome(record.outcome) ||
|
|
1007
|
+
context.command.definition.admission?.aborted ||
|
|
1008
|
+
this.options.table.get(record.pid) !== record
|
|
1009
|
+
)
|
|
1010
|
+
throw new CommandStdioError("CANCELED");
|
|
1011
|
+
const rows: CommandProcessRow[] = [];
|
|
1012
|
+
for (const row of this.options.table.values()) {
|
|
1013
|
+
if (
|
|
1014
|
+
row.rootPid !== rootPid ||
|
|
1015
|
+
!row.image.request ||
|
|
1016
|
+
row.revoked ||
|
|
1017
|
+
row.state === "exited" ||
|
|
1018
|
+
readOutcome(row.outcome)
|
|
1019
|
+
)
|
|
1020
|
+
continue;
|
|
1021
|
+
rows.push({
|
|
1022
|
+
pid: row.pid,
|
|
1023
|
+
parentPid: row.parentPid,
|
|
1024
|
+
executable: row.image.request.executable,
|
|
1025
|
+
argv: row.image.request.argv.slice(),
|
|
1026
|
+
state: row.state,
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
return rows.sort((left, right) => left.pid - right.pid);
|
|
1030
|
+
},
|
|
1031
|
+
});
|
|
1032
|
+
const transport = this.transport.get(context.pid);
|
|
1033
|
+
const identity = transport
|
|
1034
|
+
? this.filesystem(transport)
|
|
1035
|
+
: this.controllerFor(context.pid)?.filesystem;
|
|
1036
|
+
if (identity) context.registerRevocation(() => this.options.filesystem.revoke(identity));
|
|
1037
|
+
const connectFilesystem = identity
|
|
1038
|
+
? () => {
|
|
1039
|
+
if (this.suspended || record.revoked || readOutcome(record.outcome))
|
|
1040
|
+
throw new CommandStdioError("CANCELED");
|
|
1041
|
+
return this.options.filesystem.connect(identity);
|
|
1042
|
+
}
|
|
1043
|
+
: undefined;
|
|
1044
|
+
return launch(context, {
|
|
1045
|
+
processes,
|
|
1046
|
+
signals: this.commandSignals(context, record, rootPid),
|
|
1047
|
+
connectFilesystem,
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
private commandSignals(
|
|
1052
|
+
context: CommandProcessContext,
|
|
1053
|
+
holder: ProcessRecord,
|
|
1054
|
+
rootPid: number,
|
|
1055
|
+
): DelegatedSignals | null {
|
|
1056
|
+
const definition = context.command.definition;
|
|
1057
|
+
const policy = this.signalPolicies.get(rootPid);
|
|
1058
|
+
const anchor = this.options.table.get(rootPid);
|
|
1059
|
+
if (
|
|
1060
|
+
definition.signals !== "delegated" ||
|
|
1061
|
+
!definition.owner ||
|
|
1062
|
+
!policy ||
|
|
1063
|
+
!anchor ||
|
|
1064
|
+
!policy.packages.has(definition.owner)
|
|
1065
|
+
)
|
|
1066
|
+
return null;
|
|
1067
|
+
const live = () =>
|
|
1068
|
+
!this.suspended &&
|
|
1069
|
+
!holder.revoked &&
|
|
1070
|
+
!anchor.revoked &&
|
|
1071
|
+
!definition.admission?.aborted &&
|
|
1072
|
+
this.options.table.get(holder.pid) === holder &&
|
|
1073
|
+
this.options.table.get(anchor.pid) === anchor &&
|
|
1074
|
+
this.signalPolicies.get(anchor.pid) === policy &&
|
|
1075
|
+
this.controllerFor(anchor.pid) === policy.controller &&
|
|
1076
|
+
!readOutcome(holder.outcome) &&
|
|
1077
|
+
!readOutcome(anchor.outcome);
|
|
1078
|
+
return Object.freeze({
|
|
1079
|
+
send: (pid: number, signal: number) => {
|
|
1080
|
+
const sig = checkedSignal(signal);
|
|
1081
|
+
if (!live()) return "revoked";
|
|
1082
|
+
const target = this.options.table.get(pid);
|
|
1083
|
+
if (!target || target.revoked || readOutcome(target.outcome)) return "missing";
|
|
1084
|
+
if (target.rootPid !== anchor.pid || target === anchor) return "denied";
|
|
1085
|
+
this.publishProcessSignal(pid, sig, target);
|
|
1086
|
+
return "sent";
|
|
1087
|
+
},
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
/** Register an explicit adapter controller (including legacy transports), not a default adapter. */
|
|
1092
|
+
registerController(pid: number, controller: ProcessController): void {
|
|
1093
|
+
if (this.suspended) throw new Error("Process broker is disposed");
|
|
1094
|
+
if (this.controllerFor(pid)) throw new Error(`Process ${pid} already has a controller`);
|
|
1095
|
+
const observation =
|
|
1096
|
+
this.reservedRoots.get(pid)?.observation ?? this.options.table.get(pid)?.observation;
|
|
1097
|
+
if (observation) this.acquireObservation(observation);
|
|
1098
|
+
const stop = controller.stop;
|
|
1099
|
+
const capturedStop = stop
|
|
1100
|
+
? () => reflectApply(stop, controller, []) as void | Promise<void>
|
|
1101
|
+
: undefined;
|
|
1102
|
+
const child = this.children.get(pid);
|
|
1103
|
+
const revoke = this.controllerRevocation(controller);
|
|
1104
|
+
if (child) {
|
|
1105
|
+
child.revokeController = revoke;
|
|
1106
|
+
child.controller = controller;
|
|
1107
|
+
child.capturedControllerStop = capturedStop;
|
|
1108
|
+
} else if (capturedStop) this.capturedControllerStops.set(pid, capturedStop);
|
|
1109
|
+
if (child) child.controller = controller;
|
|
1110
|
+
else {
|
|
1111
|
+
this.controllers.set(pid, controller);
|
|
1112
|
+
this.capturedControllerRevocations.set(pid, revoke);
|
|
1113
|
+
}
|
|
1114
|
+
this.captureControllerStop(pid);
|
|
1115
|
+
this.acquireController(pid);
|
|
1116
|
+
if (this.supervisor?.get(pid)) this.supervisor.registerCurrentImageRevocation(pid, revoke);
|
|
1117
|
+
}
|
|
1118
|
+
/** Reserve an externally executed root without activating the optional supervisor. */
|
|
1119
|
+
reserveRoot(root: RootProcessOptions, controller: ProcessController = {}): number {
|
|
1120
|
+
if (this.suspended) throw new Error("Process broker is disposed");
|
|
1121
|
+
const initialCwd = root.cwd;
|
|
1122
|
+
const cwd = checkedProcessCwd(initialCwd === undefined ? "/" : initialCwd);
|
|
1123
|
+
const pid = root.pid ?? this.options.identities.pid(),
|
|
1124
|
+
job = root.job ?? this.options.identities.job();
|
|
1125
|
+
this.options.identities.observePid(pid);
|
|
1126
|
+
this.options.identities.observeJob(job);
|
|
1127
|
+
const word = (value?: ControlCells | SharedArrayBuffer) =>
|
|
1128
|
+
value instanceof TaggedCells
|
|
1129
|
+
? value
|
|
1130
|
+
: value instanceof Int32Array
|
|
1131
|
+
? value
|
|
1132
|
+
: new Int32Array(value ?? allocateSharedControl(4));
|
|
1133
|
+
const reserved = {
|
|
1134
|
+
...root,
|
|
1135
|
+
pid,
|
|
1136
|
+
job,
|
|
1137
|
+
cwd,
|
|
1138
|
+
signalState: createSignalState(root.signalState),
|
|
1139
|
+
outcome: outcomeWord(root.outcome),
|
|
1140
|
+
interrupt: word(root.interrupt),
|
|
1141
|
+
requestedSignal: word(root.requestedSignal),
|
|
1142
|
+
processIdentity: snapshotLogicalProcessIdentity({ pid, parentPid: 0 }),
|
|
1143
|
+
};
|
|
1144
|
+
const observation = admitProcessObservation(pid, reserved.outcome, root.observation);
|
|
1145
|
+
const admitted = { ...reserved, observation };
|
|
1146
|
+
this.acquireObservation(observation);
|
|
1147
|
+
const packages = controller.signalDelegation?.packages;
|
|
1148
|
+
const policy = packages
|
|
1149
|
+
? { controller, packages: new Set(packages.map((pkg) => packageIdentity(pkg))) }
|
|
1150
|
+
: undefined;
|
|
1151
|
+
if (this.controllerFor(pid)) throw new Error(`Process ${pid} already has a controller`);
|
|
1152
|
+
this.supervisor?.createRoot(admitted);
|
|
1153
|
+
this.registerController(pid, controller);
|
|
1154
|
+
this.reservedRoots.set(pid, admitted);
|
|
1155
|
+
if (policy) this.signalPolicies.set(pid, policy);
|
|
1156
|
+
return pid;
|
|
1157
|
+
}
|
|
1158
|
+
/** Keep an accepted external spawn's ancestry until its asynchronous admission finishes. */
|
|
1159
|
+
retainRoot(pid: number): () => void {
|
|
1160
|
+
if (this.suspended) throw new Error("Process broker is disposed");
|
|
1161
|
+
if (!this.reservedRoots.has(pid)) throw new Error(`Unknown root process ${pid}`);
|
|
1162
|
+
const releaseObservation = this.observationOwners.get(pid)?.acquire();
|
|
1163
|
+
this.rootLeases.set(pid, (this.rootLeases.get(pid) ?? 0) + 1);
|
|
1164
|
+
let released = false;
|
|
1165
|
+
return () => {
|
|
1166
|
+
if (released) return;
|
|
1167
|
+
released = true;
|
|
1168
|
+
releaseObservation?.();
|
|
1169
|
+
const remaining = (this.rootLeases.get(pid) ?? 1) - 1;
|
|
1170
|
+
if (remaining) this.rootLeases.set(pid, remaining);
|
|
1171
|
+
else this.rootLeases.delete(pid);
|
|
1172
|
+
this.retireRoots();
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
private retainsRoot(
|
|
1176
|
+
transport: WorkerProcessTransport,
|
|
1177
|
+
pid: number,
|
|
1178
|
+
job: number | undefined,
|
|
1179
|
+
): boolean {
|
|
1180
|
+
if (Array.from(directoryGroups(transport.directory)).some((group) => group.id !== job))
|
|
1181
|
+
return true;
|
|
1182
|
+
return Array.from(directoryProcesses(transport.directory)).some((state) => {
|
|
1183
|
+
try {
|
|
1184
|
+
return (
|
|
1185
|
+
state.pid !== pid &&
|
|
1186
|
+
(controlLoad(state.confirmed, 0) === 0 ||
|
|
1187
|
+
(state.job !== job && controlLoad(state.jobPending, 0) >= 0))
|
|
1188
|
+
);
|
|
1189
|
+
} catch (error) {
|
|
1190
|
+
if (!isCollectedProcess(error)) throw error;
|
|
1191
|
+
return false;
|
|
1192
|
+
}
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
private retireRoots(): void {
|
|
1196
|
+
if (this.suspended) return;
|
|
1197
|
+
for (const pid of this.completedRoots) {
|
|
1198
|
+
if (this.rootLeases.has(pid)) continue;
|
|
1199
|
+
// Control ancestry is compressed past exited parents. Immutable rootPid, not that
|
|
1200
|
+
// mutable chain, owns controller/output lifetime until the last descendant is safe.
|
|
1201
|
+
if (
|
|
1202
|
+
Array.from(this.options.table.values()).some(
|
|
1203
|
+
(record) => record.pid !== pid && record.rootPid === pid && !record.result,
|
|
1204
|
+
)
|
|
1205
|
+
)
|
|
1206
|
+
continue;
|
|
1207
|
+
const transport = this.roots.get(pid),
|
|
1208
|
+
root = this.reservedRoots.get(pid);
|
|
1209
|
+
if (transport && this.retainsRoot(transport, pid, root?.job)) continue;
|
|
1210
|
+
const controller = this.controllerFor(pid);
|
|
1211
|
+
this.observationOwners.get(pid)?.close();
|
|
1212
|
+
this.transport.releaseRoot(pid);
|
|
1213
|
+
this.options.table.remove(pid);
|
|
1214
|
+
if (root && !this.options.table.job(root.job)?.members.size)
|
|
1215
|
+
this.options.table.removeJob(root.job);
|
|
1216
|
+
this.completedRoots.delete(pid);
|
|
1217
|
+
this.commandRoots?.delete(pid);
|
|
1218
|
+
this.reservedRoots.delete(pid);
|
|
1219
|
+
this.descendantHooks.delete(pid);
|
|
1220
|
+
this.signalPolicies.delete(pid);
|
|
1221
|
+
if (controller && this.capturedControllerStops.has(pid))
|
|
1222
|
+
this.retainedRootStops.set(pid, controller);
|
|
1223
|
+
this.controllers.delete(pid);
|
|
1224
|
+
this.capturedControllerRevocations.delete(pid);
|
|
1225
|
+
this.quiescedControllers.delete(pid);
|
|
1226
|
+
this.revokedControllers.delete(pid);
|
|
1227
|
+
this.roots.delete(pid);
|
|
1228
|
+
this.outputs.delete(pid);
|
|
1229
|
+
this.retireTerminalOutput(pid);
|
|
1230
|
+
this.registries.delete(pid);
|
|
1231
|
+
this.fences.delete(pid);
|
|
1232
|
+
this.releaseAcquiredProcess(pid);
|
|
1233
|
+
try {
|
|
1234
|
+
controller?.retired?.();
|
|
1235
|
+
} catch (error) {
|
|
1236
|
+
this.report(error);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
async adoptRoot(
|
|
1241
|
+
root: RootProcessOptions & { readonly memory: readonly MemoryDeclaration[] },
|
|
1242
|
+
controller: ProcessController = {},
|
|
1243
|
+
): Promise<number> {
|
|
1244
|
+
const ticket = this.options.reservations.admit({
|
|
1245
|
+
pid: root.pid ?? 0,
|
|
1246
|
+
executable: "external root",
|
|
1247
|
+
guest: { kind: "declared", memories: root.memory },
|
|
1248
|
+
group: "none",
|
|
1249
|
+
connection: false,
|
|
1250
|
+
controls: true,
|
|
1251
|
+
});
|
|
1252
|
+
let pid: number;
|
|
1253
|
+
try {
|
|
1254
|
+
pid = this.reserveRoot(root, controller);
|
|
1255
|
+
} catch (error) {
|
|
1256
|
+
ticket.abort();
|
|
1257
|
+
throw error;
|
|
1258
|
+
}
|
|
1259
|
+
this.rootAdmissions.set(pid, ticket);
|
|
1260
|
+
this.rootTickets.set(pid, ticket.launched());
|
|
1261
|
+
this.rootGrants.set(pid, ticket.control);
|
|
1262
|
+
// Reservation transfers an external consumer's teardown capabilities to this owner.
|
|
1263
|
+
// Activation may fail after creating its table record; keep those capabilities until
|
|
1264
|
+
// disposal even when the caller observes a rejected admission promise.
|
|
1265
|
+
await this.ready();
|
|
1266
|
+
if (this.suspended) throw new Error("Process broker is disposed");
|
|
1267
|
+
return pid;
|
|
1268
|
+
}
|
|
1269
|
+
async adoptRuntimeRoot(
|
|
1270
|
+
transport: WorkerProcessTransport,
|
|
1271
|
+
options: RuntimeRootOptions,
|
|
1272
|
+
): Promise<void> {
|
|
1273
|
+
if (this.suspended) throw new Error("Process broker is disposed");
|
|
1274
|
+
const cwd = checkedProcessCwd(transport.cwd);
|
|
1275
|
+
const state = workerProcessState(transport);
|
|
1276
|
+
if (this.controllerFor(state.pid))
|
|
1277
|
+
throw new Error(`Process ${state.pid} already has a controller`);
|
|
1278
|
+
if (state.parentPid !== 0) throw new TypeError("root process has a parent");
|
|
1279
|
+
if (
|
|
1280
|
+
state.processKind !== "process" ||
|
|
1281
|
+
state.processIdentity.pid !== state.pid ||
|
|
1282
|
+
state.processIdentity.parentPid !== 0
|
|
1283
|
+
)
|
|
1284
|
+
throw new ProcessError(
|
|
1285
|
+
ProcessErrno.INVAL,
|
|
1286
|
+
"root process identity conflicts with reservation",
|
|
1287
|
+
);
|
|
1288
|
+
const existing = this.transport.get(state.pid);
|
|
1289
|
+
if (existing && workerProcessDirectoryId(existing) !== workerProcessDirectoryId(transport))
|
|
1290
|
+
throw new TypeError("process identity is already registered");
|
|
1291
|
+
if (transport.identity !== this.options.identities.buffer)
|
|
1292
|
+
throw new TypeError("root must borrow the runtime identity allocator");
|
|
1293
|
+
this.filesystem(transport);
|
|
1294
|
+
const data = transport.data as {
|
|
1295
|
+
filesystem: FilesystemIdentity;
|
|
1296
|
+
pipeRegistry?: import("../proc/pipes.js").PipePublicationRegistryHandle;
|
|
1297
|
+
};
|
|
1298
|
+
if (
|
|
1299
|
+
data.pipeRegistry &&
|
|
1300
|
+
!this.options.reservations.ownsBuffer("pipe-registry", data.pipeRegistry.buffer)
|
|
1301
|
+
)
|
|
1302
|
+
throw new TypeError("Root bootstrap requires a ledger-charged registry");
|
|
1303
|
+
const guestControls = this.commandRoots?.get(state.pid)?.root !== transport;
|
|
1304
|
+
const ticket = this.options.reservations.admit({
|
|
1305
|
+
pid: workerProcessState(transport).pid,
|
|
1306
|
+
executable: "adopted root",
|
|
1307
|
+
guest:
|
|
1308
|
+
options.memory === "group"
|
|
1309
|
+
? { kind: "group" }
|
|
1310
|
+
: { kind: "declared", memories: options.memory },
|
|
1311
|
+
group: "none",
|
|
1312
|
+
connection: false,
|
|
1313
|
+
controls: guestControls,
|
|
1314
|
+
});
|
|
1315
|
+
const previousData = transport.data;
|
|
1316
|
+
let changedData = false;
|
|
1317
|
+
let registeredRegistry: PipePublicationRegistry | undefined;
|
|
1318
|
+
try {
|
|
1319
|
+
const output = rootOutput(options);
|
|
1320
|
+
// Capture fallible embedding getters before publishing this root.
|
|
1321
|
+
const prepare = options.prepareDescendant;
|
|
1322
|
+
const descendant = prepare
|
|
1323
|
+
? {
|
|
1324
|
+
prepare: Object.freeze({
|
|
1325
|
+
terminal: prepare.terminal,
|
|
1326
|
+
run: prepare.run,
|
|
1327
|
+
settled: prepare.settled,
|
|
1328
|
+
}),
|
|
1329
|
+
directory: workerProcessDirectoryId(transport),
|
|
1330
|
+
}
|
|
1331
|
+
: undefined;
|
|
1332
|
+
const registry = data.pipeRegistry
|
|
1333
|
+
? attachPipePublicationRegistry(data.pipeRegistry)
|
|
1334
|
+
: new PipePublicationRegistry({
|
|
1335
|
+
wake: state.wake,
|
|
1336
|
+
allocate: (length, maximum) =>
|
|
1337
|
+
this.options.reservations.buffer("pipe-registry", {
|
|
1338
|
+
kind: "growable-buffer",
|
|
1339
|
+
initial: length,
|
|
1340
|
+
maximum: bytes(maximum),
|
|
1341
|
+
}),
|
|
1342
|
+
});
|
|
1343
|
+
const bootstrap = { ...data, pipeRegistry: registry.handle() };
|
|
1344
|
+
const registered = !registry.isRevoked(state.pid);
|
|
1345
|
+
registry.registerProcess(state.pid);
|
|
1346
|
+
if (!registered) registeredRegistry = registry;
|
|
1347
|
+
transport.data = bootstrap;
|
|
1348
|
+
changedData = true;
|
|
1349
|
+
this.acquireProcess(transport);
|
|
1350
|
+
this.reserveRoot(
|
|
1351
|
+
{ pid: state.pid, job: state.job, cwd, observation: transport, ...state.signals },
|
|
1352
|
+
options,
|
|
1353
|
+
);
|
|
1354
|
+
this.transport.adoptRoot(transport);
|
|
1355
|
+
this.roots.set(state.pid, transport);
|
|
1356
|
+
this.acquireController(state.pid);
|
|
1357
|
+
this.outputs.set(state.pid, output);
|
|
1358
|
+
this.registries.set(state.pid, registry);
|
|
1359
|
+
if (descendant) this.descendantHooks.set(state.pid, descendant);
|
|
1360
|
+
this.rootAdmissions.set(state.pid, ticket);
|
|
1361
|
+
this.rootTickets.set(state.pid, ticket.launched());
|
|
1362
|
+
if (guestControls) this.rootGrants.set(state.pid, ticket.control);
|
|
1363
|
+
} catch (error) {
|
|
1364
|
+
if (changedData) transport.data = previousData;
|
|
1365
|
+
registeredRegistry?.collectProcess(state.pid);
|
|
1366
|
+
ticket.abort();
|
|
1367
|
+
throw error;
|
|
1368
|
+
}
|
|
1369
|
+
if (this.activation) {
|
|
1370
|
+
const supervisor = await this.activation;
|
|
1371
|
+
if (this.suspended) throw new Error("Process broker is disposed");
|
|
1372
|
+
this.activateRuntimeRoot(supervisor, transport);
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
async adoptCommandRoot(
|
|
1376
|
+
transport: WorkerProcessTransport,
|
|
1377
|
+
options: RuntimeRootOptions,
|
|
1378
|
+
): Promise<void> {
|
|
1379
|
+
if (this.suspended || !this.supervisor) throw new Error("Process broker is unavailable");
|
|
1380
|
+
const processCapacity = directoryCapacity(transport.directory);
|
|
1381
|
+
const registry = new PipePublicationRegistry({
|
|
1382
|
+
processCapacity,
|
|
1383
|
+
cellsPerProcess: 16,
|
|
1384
|
+
maxCells: processCapacity * 128,
|
|
1385
|
+
wake: workerProcessState(transport).wake,
|
|
1386
|
+
allocate: (length, maximum) =>
|
|
1387
|
+
this.options.reservations.buffer("pipe-registry", {
|
|
1388
|
+
kind: "growable-buffer",
|
|
1389
|
+
initial: length,
|
|
1390
|
+
maximum: bytes(maximum),
|
|
1391
|
+
}),
|
|
1392
|
+
});
|
|
1393
|
+
initializeCommandExec(transport);
|
|
1394
|
+
transport.data = { filesystem: options.filesystem, pipeRegistry: registry.handle() };
|
|
1395
|
+
(this.commandRoots ??= new Map()).set(transport.pid, {
|
|
1396
|
+
root: transport,
|
|
1397
|
+
pending: new Set(),
|
|
1398
|
+
failures: new Map(),
|
|
1399
|
+
stopped: false,
|
|
1400
|
+
});
|
|
1401
|
+
try {
|
|
1402
|
+
await this.adoptRuntimeRoot(transport, options);
|
|
1403
|
+
} catch (error) {
|
|
1404
|
+
if (!this.roots.has(transport.pid)) this.commandRoots?.delete(transport.pid);
|
|
1405
|
+
throw error;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
private commandScope(transport: WorkerProcessTransport): CommandRootState | undefined {
|
|
1409
|
+
if (!this.commandRoots?.size) return;
|
|
1410
|
+
let rootPid: number;
|
|
1411
|
+
try {
|
|
1412
|
+
rootPid = workerProcessState(transport).rootPid;
|
|
1413
|
+
} catch (error) {
|
|
1414
|
+
if (!isCollectedProcess(error)) throw error;
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
const scope = this.commandRoots.get(rootPid);
|
|
1418
|
+
if (scope && workerProcessDirectoryId(scope.root) === workerProcessDirectoryId(transport))
|
|
1419
|
+
return scope;
|
|
1420
|
+
}
|
|
1421
|
+
private checkCommandAdmission(transport: WorkerProcessTransport): void {
|
|
1422
|
+
const scope = this.commandScope(transport);
|
|
1423
|
+
if (scope && this.commandAdmissionClosed(scope))
|
|
1424
|
+
throw new ProcessError(ProcessErrno.SRCH, "Command is stopping");
|
|
1425
|
+
}
|
|
1426
|
+
private commandAdmissionClosed(scope: CommandRootState): boolean {
|
|
1427
|
+
return (
|
|
1428
|
+
scope.stopped ||
|
|
1429
|
+
scope.failures.size !== 0 ||
|
|
1430
|
+
commandTransferFailed(scope.root.commandTransfer)
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1433
|
+
private trackCommandTransfer(
|
|
1434
|
+
transport: WorkerProcessTransport,
|
|
1435
|
+
cleanup: () => Promise<void>,
|
|
1436
|
+
): Promise<void> {
|
|
1437
|
+
const scope = this.commandScope(transport);
|
|
1438
|
+
if (!scope) return cleanup();
|
|
1439
|
+
const pending = Promise.resolve().then(cleanup);
|
|
1440
|
+
scope.pending.add(pending);
|
|
1441
|
+
const settle = () => {
|
|
1442
|
+
scope.pending.delete(pending);
|
|
1443
|
+
wakeWorkerProcess(scope.root);
|
|
1444
|
+
};
|
|
1445
|
+
void pending.then(settle, (error) => {
|
|
1446
|
+
scope.failures.set(transport, error);
|
|
1447
|
+
settle();
|
|
1448
|
+
});
|
|
1449
|
+
return pending;
|
|
1450
|
+
}
|
|
1451
|
+
private async retireRejectedCommand(transport: WorkerProcessTransport): Promise<void> {
|
|
1452
|
+
const returned = this.processNativeReturn(transport);
|
|
1453
|
+
if (this.acquiredProcesses.get(transport.pid) === this.processLifetime(transport)) {
|
|
1454
|
+
await this.retireProcess(transport.pid, true);
|
|
1455
|
+
this.retireChildController(transport.pid);
|
|
1456
|
+
}
|
|
1457
|
+
returned();
|
|
1458
|
+
}
|
|
1459
|
+
private commandCleanupFailure(scope: CommandRootState): Error | undefined {
|
|
1460
|
+
if (scope.failures.size) {
|
|
1461
|
+
const [cause] = scope.failures.values();
|
|
1462
|
+
return new Error("Command transfer cleanup failed", { cause });
|
|
1463
|
+
}
|
|
1464
|
+
const buffer = scope.root.commandTransfer;
|
|
1465
|
+
return buffer ? readCommandTransferFailure(buffer)?.error : undefined;
|
|
1466
|
+
}
|
|
1467
|
+
private async joinCommandExec(transport: WorkerProcessTransport): Promise<void> {
|
|
1468
|
+
const scope = this.commandScope(transport);
|
|
1469
|
+
const handoff = commandExecTransfer(transport);
|
|
1470
|
+
if (!scope || !handoff) return;
|
|
1471
|
+
const state = workerProcessState(transport);
|
|
1472
|
+
for (;;) {
|
|
1473
|
+
const expected = Atomics.load(state.wake, 0);
|
|
1474
|
+
const buffer = scope.root.commandTransfer;
|
|
1475
|
+
const local = buffer && readCommandTransferFailure(buffer);
|
|
1476
|
+
if (
|
|
1477
|
+
local?.kind === "exec" &&
|
|
1478
|
+
local.pid === transport.pid &&
|
|
1479
|
+
local.generation === transport.generation
|
|
1480
|
+
)
|
|
1481
|
+
throw local.error;
|
|
1482
|
+
const staged = controlLoad(handoff);
|
|
1483
|
+
if (staged === 0) return;
|
|
1484
|
+
for (const [transfer, cause] of scope.failures) {
|
|
1485
|
+
if (transfer.pid === transport.pid && transfer.generation === staged)
|
|
1486
|
+
throw new Error("Exec transfer cleanup failed", { cause });
|
|
1487
|
+
}
|
|
1488
|
+
await atomicsWaitAsync(state.wake, 0, expected).value;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
commandPipeHost(
|
|
1493
|
+
transport: WorkerProcessTransport,
|
|
1494
|
+
postMessage: (message: WorkerProcessMessage) => void,
|
|
1495
|
+
): WorkerPipeHost {
|
|
1496
|
+
const registry = this.registries.get(transport.pid);
|
|
1497
|
+
if (!registry || !this.commandRoots?.has(transport.pid))
|
|
1498
|
+
throw new Error("Command root is not admitted");
|
|
1499
|
+
return new WorkerPipeHost({
|
|
1500
|
+
transport,
|
|
1501
|
+
registry,
|
|
1502
|
+
postMessage,
|
|
1503
|
+
allocateShared: (length) =>
|
|
1504
|
+
this.options.reservations.buffer("control", {
|
|
1505
|
+
kind: "fixed-buffer",
|
|
1506
|
+
length: bytes(length),
|
|
1507
|
+
}),
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
stopCommandRoot(root: WorkerProcessTransport): void {
|
|
1511
|
+
const scope = this.commandRoots?.get(root.pid);
|
|
1512
|
+
if (!scope || scope.stopped) return;
|
|
1513
|
+
scope.stopped = true;
|
|
1514
|
+
this.stopCommandMembers(root);
|
|
1515
|
+
wakeWorkerProcess(root);
|
|
1516
|
+
}
|
|
1517
|
+
private stopCommandMembers(root: WorkerProcessTransport): void {
|
|
1518
|
+
const members = Array.from(directoryProcesses(root.directory)).filter((state) => {
|
|
1519
|
+
try {
|
|
1520
|
+
return state.pid !== root.pid && !readOutcome(state.signals.outcome);
|
|
1521
|
+
} catch (error) {
|
|
1522
|
+
if (!isCollectedProcess(error)) throw error;
|
|
1523
|
+
return false;
|
|
1524
|
+
}
|
|
1525
|
+
});
|
|
1526
|
+
for (const state of members) this.requestSignalIfPresent(state.signals, 9);
|
|
1527
|
+
for (const state of members) {
|
|
1528
|
+
try {
|
|
1529
|
+
this.revokeRuntimeProcess(state.pid, workerProcessDirectoryId(root));
|
|
1530
|
+
} catch (error) {
|
|
1531
|
+
if (!isCollectedProcess(error)) throw error;
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
checkCommandCleanup(root: WorkerProcessTransport, mayCollect: boolean): boolean {
|
|
1536
|
+
const scope = this.commandRoots?.get(root.pid);
|
|
1537
|
+
const supervisor = this.supervisor;
|
|
1538
|
+
if (!scope || !supervisor) throw new Error("Command root is not admitted");
|
|
1539
|
+
const version = idleDirectoryAdmission(root.directory);
|
|
1540
|
+
if (scope.stopped) this.stopCommandMembers(root);
|
|
1541
|
+
this.transport.pump();
|
|
1542
|
+
this.serviceTerminalOutput(root.pid);
|
|
1543
|
+
const failure = this.commandCleanupFailure(scope);
|
|
1544
|
+
if (failure) throw failure;
|
|
1545
|
+
const retired = supervisor.rootConsumersRetired(root.pid);
|
|
1546
|
+
if (!mayCollect) return false;
|
|
1547
|
+
const ownJob = workerProcessState(root).job;
|
|
1548
|
+
for (const group of directoryGroups(root.directory)) {
|
|
1549
|
+
if (group.id === ownJob) continue;
|
|
1550
|
+
try {
|
|
1551
|
+
if (supervisor.job(group.id)) {
|
|
1552
|
+
if (supervisor.jobCleanupReady(root.pid, group.id))
|
|
1553
|
+
supervisor.reapJob(root.pid, group.id);
|
|
1554
|
+
} else if (controlLoad(group.pending) === 0) {
|
|
1555
|
+
collectDirectoryJob(root.directory, group.slot, group.id);
|
|
1556
|
+
}
|
|
1557
|
+
} catch (error) {
|
|
1558
|
+
if (!isCollectedProcess(error)) throw error;
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
return (
|
|
1562
|
+
retired &&
|
|
1563
|
+
scope.pending.size === 0 &&
|
|
1564
|
+
!Array.from(directoryGroups(root.directory)).some((group) => group.id !== ownJob) &&
|
|
1565
|
+
!this.terminalOutputs.get(root.pid)?.pending() &&
|
|
1566
|
+
version !== undefined &&
|
|
1567
|
+
idleDirectoryAdmission(root.directory) === version
|
|
1568
|
+
);
|
|
1569
|
+
}
|
|
1570
|
+
async retireCommandRoot(root: WorkerProcessTransport): Promise<void> {
|
|
1571
|
+
const owner = this.observationOwners.get(root.pid);
|
|
1572
|
+
await this.quiesceProcess(root.pid);
|
|
1573
|
+
await this.rootExit(root.pid, 0);
|
|
1574
|
+
this.rootStopped(root.pid);
|
|
1575
|
+
await owner?.join();
|
|
1576
|
+
this.pipes.pump();
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
private bindPipeRegistry(transport: WorkerProcessTransport): void {
|
|
1580
|
+
const state = workerProcessState(transport);
|
|
1581
|
+
const registry = this.registries.get(state.rootPid);
|
|
1582
|
+
if (!registry)
|
|
1583
|
+
throw new ProcessError(ProcessErrno.SRCH, "Process has no admitted pipe registry");
|
|
1584
|
+
registry.registerProcess(state.pid);
|
|
1585
|
+
const data = transport.data;
|
|
1586
|
+
if (!data || typeof data !== "object") throw new TypeError("Process has no bootstrap data");
|
|
1587
|
+
transport.data = { ...data, pipeRegistry: registry.handle() };
|
|
1588
|
+
}
|
|
1589
|
+
private activateRuntimeRoot(
|
|
1590
|
+
supervisor: ProcessSupervisor,
|
|
1591
|
+
transport: WorkerProcessTransport,
|
|
1592
|
+
): void {
|
|
1593
|
+
const state = workerProcessState(transport);
|
|
1594
|
+
if (!supervisor.get(state.pid))
|
|
1595
|
+
supervisor.createRoot({
|
|
1596
|
+
observation: transport,
|
|
1597
|
+
pid: state.pid,
|
|
1598
|
+
job: state.job,
|
|
1599
|
+
cwd: transport.cwd,
|
|
1600
|
+
...state.signals,
|
|
1601
|
+
});
|
|
1602
|
+
supervisor.registerRevocation(state.pid, () => this.revokeRuntimeProcess(state.pid));
|
|
1603
|
+
installWorkerBindings(
|
|
1604
|
+
transport,
|
|
1605
|
+
supervisor.get(state.pid)!.image.descriptors,
|
|
1606
|
+
this.descriptorCodec(transport),
|
|
1607
|
+
);
|
|
1608
|
+
const result = readOutcome(state.signals.outcome);
|
|
1609
|
+
if (result?.kind === "signaled") supervisor.defaultSignal(state.pid, result.code);
|
|
1610
|
+
else if (result) supervisor.exit(state.pid, result.code);
|
|
1611
|
+
}
|
|
1612
|
+
private filesystem(transport: WorkerProcessTransport): FilesystemIdentity {
|
|
1613
|
+
const identity = (transport.data as { filesystem?: FilesystemIdentity } | undefined)
|
|
1614
|
+
?.filesystem;
|
|
1615
|
+
if (
|
|
1616
|
+
!identity ||
|
|
1617
|
+
typeof identity !== "object" ||
|
|
1618
|
+
!Number.isSafeInteger(identity.owner) ||
|
|
1619
|
+
identity.owner <= 0 ||
|
|
1620
|
+
![
|
|
1621
|
+
identity.epoch,
|
|
1622
|
+
identity.signal,
|
|
1623
|
+
identity.shared,
|
|
1624
|
+
identity.capabilities,
|
|
1625
|
+
identity.sections,
|
|
1626
|
+
identity.ownerStates,
|
|
1627
|
+
identity.requestBudget,
|
|
1628
|
+
].every((buffer) => buffer instanceof SharedArrayBuffer && buffer.byteLength >= 4) ||
|
|
1629
|
+
identity.ownerStates.byteLength < (identity.owner + 1) * 4 ||
|
|
1630
|
+
!Array.isArray(identity.revocations) ||
|
|
1631
|
+
!identity.revocations.length ||
|
|
1632
|
+
!identity.revocations.every(
|
|
1633
|
+
(buffer) => buffer instanceof SharedArrayBuffer && buffer.byteLength >= 4,
|
|
1634
|
+
) ||
|
|
1635
|
+
!Array.isArray(identity.segments) ||
|
|
1636
|
+
!identity.segments.every((buffer) => buffer instanceof SharedArrayBuffer) ||
|
|
1637
|
+
!Array.isArray(identity.reservations) ||
|
|
1638
|
+
!Number.isFinite(identity.maxBytes)
|
|
1639
|
+
)
|
|
1640
|
+
throw new TypeError("runtime process has no valid filesystem identity");
|
|
1641
|
+
return identity;
|
|
1642
|
+
}
|
|
1643
|
+
private descriptorCodec(transport: WorkerProcessTransport) {
|
|
1644
|
+
return this.pipes.codec(
|
|
1645
|
+
createRuntimeTerminalCodec({
|
|
1646
|
+
fallback: createFilesystemDescriptorCodec(this.filesystem(transport), undefined, () =>
|
|
1647
|
+
this.options.filesystem.sweep?.(),
|
|
1648
|
+
),
|
|
1649
|
+
output: deliveredTerminalOutput((target, data) => {
|
|
1650
|
+
const destination = this.outputFor(workerProcessState(transport).pid);
|
|
1651
|
+
return destination ? destination(target, data) : data.length;
|
|
1652
|
+
}),
|
|
1653
|
+
}),
|
|
1654
|
+
);
|
|
1655
|
+
}
|
|
1656
|
+
private discardCodec() {
|
|
1657
|
+
return (this.cleanupCodec ??= this.pipes.codec(
|
|
1658
|
+
createRuntimeTerminalCodec({
|
|
1659
|
+
fallback: createFilesystemDescriptorCodec(undefined, undefined, () =>
|
|
1660
|
+
this.options.filesystem.sweep?.(),
|
|
1661
|
+
),
|
|
1662
|
+
}),
|
|
1663
|
+
));
|
|
1664
|
+
}
|
|
1665
|
+
private processLifetime(transport: WorkerProcessTransport): string {
|
|
1666
|
+
return `${workerProcessDirectoryId(transport)}:${transport.slot}:${transport.pid}`;
|
|
1667
|
+
}
|
|
1668
|
+
private runtimeProcessLifetime(
|
|
1669
|
+
pid: number,
|
|
1670
|
+
): { key: string; terminal: TerminalProcessLifetime } | undefined {
|
|
1671
|
+
// Only adopted directories can resolve a controller registered before publication.
|
|
1672
|
+
for (const root of this.roots.values()) {
|
|
1673
|
+
const state = Array.from(directoryProcesses(root.directory)).find(
|
|
1674
|
+
(state) => state.pid === pid,
|
|
1675
|
+
);
|
|
1676
|
+
if (state)
|
|
1677
|
+
return {
|
|
1678
|
+
key: `${workerProcessDirectoryId(root)}:${state.slot}:${pid}`,
|
|
1679
|
+
terminal: captureTerminalLifetime({ directory: root.directory, slot: state.slot, pid }),
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1682
|
+
return undefined;
|
|
1683
|
+
}
|
|
1684
|
+
private processNativeReturn(transport: WorkerProcessTransport): () => void {
|
|
1685
|
+
this.acquireController(transport.pid);
|
|
1686
|
+
const acquired = this.acquiredProcesses.get(transport.pid);
|
|
1687
|
+
const existing = this.observationOwners.get(transport.pid);
|
|
1688
|
+
if (
|
|
1689
|
+
(acquired && acquired !== this.processLifetime(transport)) ||
|
|
1690
|
+
(existing && !existing.matches(transport))
|
|
1691
|
+
)
|
|
1692
|
+
return () => {};
|
|
1693
|
+
this.acquireObservation(transport, true);
|
|
1694
|
+
const owner = this.observationOwners.get(transport.pid)!;
|
|
1695
|
+
return () => owner.close();
|
|
1696
|
+
}
|
|
1697
|
+
private captureControllerStop(pid: number): void {
|
|
1698
|
+
const stop = this.capturedControllerStopFor(pid);
|
|
1699
|
+
if (
|
|
1700
|
+
(this.options.table.get(pid)?.image.generation ?? 1) > 1 &&
|
|
1701
|
+
this.nativeLaunchReturns.has(pid)
|
|
1702
|
+
)
|
|
1703
|
+
return;
|
|
1704
|
+
if (!stop || !this.observationOwners.has(pid) || this.controllerNativeStopFor(pid)) return;
|
|
1705
|
+
const child = this.children.get(pid);
|
|
1706
|
+
const returned = new NativeReturnFollowers();
|
|
1707
|
+
const captured = this.captureConsumerStop(pid, stop, () => {
|
|
1708
|
+
if (!child) {
|
|
1709
|
+
this.controllerNativeStops.delete(pid);
|
|
1710
|
+
this.capturedControllerStops.delete(pid);
|
|
1711
|
+
this.controllerNativeReturns.delete(pid);
|
|
1712
|
+
}
|
|
1713
|
+
this.retainedRootStops.delete(pid);
|
|
1714
|
+
returned.returned();
|
|
1715
|
+
this.rootStopped(pid);
|
|
1716
|
+
});
|
|
1717
|
+
if (child) {
|
|
1718
|
+
child.controllerNativeReturn = returned;
|
|
1719
|
+
child.controllerNativeStop = captured;
|
|
1720
|
+
} else {
|
|
1721
|
+
this.controllerNativeReturns.set(pid, returned);
|
|
1722
|
+
this.controllerNativeStops.set(pid, captured);
|
|
1723
|
+
this.bindRootGroup(pid, captured);
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
private acquireObservation(transfer: ProcessObservationTransfer, execution = false): void {
|
|
1727
|
+
const existing = this.observationOwners.get(transfer.pid);
|
|
1728
|
+
if (existing) {
|
|
1729
|
+
if (!existing.matches(transfer))
|
|
1730
|
+
throw new ProcessError(
|
|
1731
|
+
ProcessErrno.INVAL,
|
|
1732
|
+
"Process observation owner differs from admission",
|
|
1733
|
+
);
|
|
1734
|
+
if (execution) existing.acceptExecution();
|
|
1735
|
+
return;
|
|
1736
|
+
}
|
|
1737
|
+
this.observationOwners.set(
|
|
1738
|
+
transfer.pid,
|
|
1739
|
+
new NativeObservationOwner(
|
|
1740
|
+
transfer,
|
|
1741
|
+
() => this.releaseObservationOwner(transfer.pid),
|
|
1742
|
+
execution,
|
|
1743
|
+
),
|
|
1744
|
+
);
|
|
1745
|
+
const controller = this.controllerFor(transfer.pid);
|
|
1746
|
+
if (controller) this.captureControllerStop(transfer.pid);
|
|
1747
|
+
}
|
|
1748
|
+
/** Capture this admitted association before handing it to an external worker. */
|
|
1749
|
+
rootObservation(pid: number): ProcessObservationTransfer {
|
|
1750
|
+
const observation =
|
|
1751
|
+
this.reservedRoots.get(pid)?.observation ?? this.options.table.get(pid)?.observation;
|
|
1752
|
+
if (!observation) throw new ProcessError(ProcessErrno.SRCH, "Process is not admitted");
|
|
1753
|
+
return observation;
|
|
1754
|
+
}
|
|
1755
|
+
private acquireProcess(transport: WorkerProcessTransport): void {
|
|
1756
|
+
const lifetime = this.processLifetime(transport);
|
|
1757
|
+
const acquired = this.acquiredProcesses.get(transport.pid);
|
|
1758
|
+
if (acquired && acquired !== lifetime)
|
|
1759
|
+
throw new Error("process consumer belongs to another lifetime");
|
|
1760
|
+
this.acquiredProcesses.set(transport.pid, lifetime);
|
|
1761
|
+
if (!acquired && this.supervisor?.get(transport.pid))
|
|
1762
|
+
this.supervisor.registerRevocation(transport.pid, () =>
|
|
1763
|
+
this.revokeRuntimeProcess(transport.pid),
|
|
1764
|
+
);
|
|
1765
|
+
this.acquireObservation(transport, workerProcessState(transport).parentPid !== 0);
|
|
1766
|
+
if (!this.terminalLifetimes.has(transport.pid))
|
|
1767
|
+
this.terminalLifetimes.set(transport.pid, captureTerminalLifetime(transport));
|
|
1768
|
+
}
|
|
1769
|
+
private acquireController(pid: number): void {
|
|
1770
|
+
if (this.acquiredProcesses.has(pid) || !this.controllerFor(pid)) return;
|
|
1771
|
+
const lifetime = this.runtimeProcessLifetime(pid);
|
|
1772
|
+
if (!lifetime) return;
|
|
1773
|
+
this.acquiredProcesses.set(pid, lifetime.key);
|
|
1774
|
+
this.terminalLifetimes.set(pid, lifetime.terminal);
|
|
1775
|
+
}
|
|
1776
|
+
private releaseObservationOwner(pid: number): void {
|
|
1777
|
+
this.observationOwners.delete(pid);
|
|
1778
|
+
this.nativeLaunchReturns.delete(pid);
|
|
1779
|
+
this.controllerNativeStops.delete(pid);
|
|
1780
|
+
this.capturedControllerStops.delete(pid);
|
|
1781
|
+
this.controllerNativeReturns.delete(pid);
|
|
1782
|
+
this.retainedRootStops.delete(pid);
|
|
1783
|
+
}
|
|
1784
|
+
private releaseAcquiredProcess(pid: number): void {
|
|
1785
|
+
if (
|
|
1786
|
+
this.options.table.get(pid) ||
|
|
1787
|
+
this.nativeLaunchReturns.has(pid) ||
|
|
1788
|
+
this.imageStops.has(pid) ||
|
|
1789
|
+
!!this.controllerFor(pid) ||
|
|
1790
|
+
this.children.has(pid) ||
|
|
1791
|
+
this.launches?.has(pid) ||
|
|
1792
|
+
this.pendingLaunches?.has(pid) ||
|
|
1793
|
+
this.fences.has(pid)
|
|
1794
|
+
)
|
|
1795
|
+
return;
|
|
1796
|
+
this.acquiredProcesses.delete(pid);
|
|
1797
|
+
this.terminalLifetimes.delete(pid);
|
|
1798
|
+
if (this.observationOwners.get(pid)?.completed) this.observationOwners.delete(pid);
|
|
1799
|
+
this.nativeLaunchReturns.delete(pid);
|
|
1800
|
+
}
|
|
1801
|
+
private async quiesceUnstarted(transport: WorkerProcessTransport): Promise<void> {
|
|
1802
|
+
// prepareSpawn may register before publication; resolve against our adopted roots.
|
|
1803
|
+
this.acquireController(transport.pid);
|
|
1804
|
+
const acquired = this.acquiredProcesses.get(transport.pid) === this.processLifetime(transport);
|
|
1805
|
+
let filesystem: FilesystemIdentity | undefined;
|
|
1806
|
+
try {
|
|
1807
|
+
filesystem = this.filesystem(transport);
|
|
1808
|
+
} catch (error) {
|
|
1809
|
+
// Invalid metadata proves nothing about an acquired consumer, but foreign PID
|
|
1810
|
+
// aliases never inherit a local lifetime's physical cleanup obligations.
|
|
1811
|
+
if (acquired) throw error;
|
|
1812
|
+
}
|
|
1813
|
+
const pending: Promise<void>[] = [];
|
|
1814
|
+
if (filesystem) {
|
|
1815
|
+
this.options.filesystem.revoke(filesystem);
|
|
1816
|
+
pending.push(this.options.filesystem.quiesce(filesystem));
|
|
1817
|
+
}
|
|
1818
|
+
// The payload's identity cannot replace a controller's distinct identity or adapter fence.
|
|
1819
|
+
if (acquired) pending.push(Promise.resolve(this.quiesceProcess(transport.pid)));
|
|
1820
|
+
await Promise.all(pending);
|
|
1821
|
+
this.collectRuntimeProcess(transport.pid, workerProcessDirectoryId(transport));
|
|
1822
|
+
}
|
|
1823
|
+
/** A bounded root destination reports room for its writers' buffered terminal output. */
|
|
1824
|
+
outputDrained(rootPid: number): void {
|
|
1825
|
+
this.serviceTerminalOutput(rootPid);
|
|
1826
|
+
}
|
|
1827
|
+
private serviceTerminalOutput(rootPid: number): void {
|
|
1828
|
+
const budget = this.terminalOutputs.get(rootPid);
|
|
1829
|
+
if (!budget || this.suspended) return;
|
|
1830
|
+
const destination = this.outputFor(rootPid);
|
|
1831
|
+
try {
|
|
1832
|
+
budget.service(destination ?? ((_target, data) => data.length));
|
|
1833
|
+
} catch (error) {
|
|
1834
|
+
this.report(error);
|
|
1835
|
+
}
|
|
1836
|
+
if (!budget.readers.size) this.terminalOutputs.delete(rootPid);
|
|
1837
|
+
}
|
|
1838
|
+
private retireTerminalOutput(rootPid: number): void {
|
|
1839
|
+
const budget = this.terminalOutputs.get(rootPid);
|
|
1840
|
+
this.terminalOutputs.delete(rootPid);
|
|
1841
|
+
const pending = budget?.pending();
|
|
1842
|
+
// The destination is gone. Say so instead of dropping accepted bytes silently.
|
|
1843
|
+
if (pending)
|
|
1844
|
+
this.report(
|
|
1845
|
+
new Error(`root ${rootPid} retired with ${pending} terminal output bytes undelivered`),
|
|
1846
|
+
);
|
|
1847
|
+
}
|
|
1848
|
+
private outputFor(pid: number): TerminalOutputDelivery | undefined {
|
|
1849
|
+
const rootPid = this.options.table.get(pid)?.rootPid;
|
|
1850
|
+
if (rootPid !== undefined && this.outputs.has(rootPid)) return this.outputs.get(rootPid);
|
|
1851
|
+
for (;;) {
|
|
1852
|
+
if (this.outputs.has(pid)) return this.outputs.get(pid);
|
|
1853
|
+
const parent = this.options.table.parentOf(pid);
|
|
1854
|
+
if (!parent) return undefined;
|
|
1855
|
+
pid = parent;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
revokeRuntimeProcess(pid: number, directoryId?: string): void {
|
|
1859
|
+
this.accesses.revoke(pid, directoryId);
|
|
1860
|
+
this.children.get(pid)?.accesses?.dispose();
|
|
1861
|
+
if (directoryId === undefined) this.disposeNotifications(this.children.get(pid));
|
|
1862
|
+
// A root directory owns its publication registry. Rejected foreign identities cannot
|
|
1863
|
+
// revoke an admitted or still-pending process that happens to use the same numeric PID.
|
|
1864
|
+
for (const [rootPid, transport] of this.roots) {
|
|
1865
|
+
if (directoryId !== undefined && workerProcessDirectoryId(transport) !== directoryId)
|
|
1866
|
+
continue;
|
|
1867
|
+
for (const state of directoryProcesses(transport.directory))
|
|
1868
|
+
if (state.pid === pid) {
|
|
1869
|
+
this.disposeNotifications(this.children.get(pid));
|
|
1870
|
+
this.registries.get(rootPid)?.revoke(pid);
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
async runtimeMessage(message: WorkerProcessMessage, senderPid: number): Promise<void> {
|
|
1876
|
+
this.traceSpawn(message, "received");
|
|
1877
|
+
const sender = this.transport.getIdentity(senderPid);
|
|
1878
|
+
const consumingReceipt =
|
|
1879
|
+
message.operation === "reap-job" || message.operation === "reap-process";
|
|
1880
|
+
let filesystemRevoked = false;
|
|
1881
|
+
if (sender && !consumingReceipt) {
|
|
1882
|
+
try {
|
|
1883
|
+
// Ordinary exit claims its outcome before reap revokes the filesystem.
|
|
1884
|
+
// Sample revocation first so a new reap cannot pair with an old running outcome.
|
|
1885
|
+
filesystemRevoked = isRevoked(this.filesystem(sender));
|
|
1886
|
+
} catch (error) {
|
|
1887
|
+
// Sender validation owns rejection cleanup for incoming transferred resources.
|
|
1888
|
+
this.rejectMessage(message, senderPid, "sender-revoked");
|
|
1889
|
+
throw error;
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
let result: ReturnType<typeof readOutcome> = null;
|
|
1893
|
+
try {
|
|
1894
|
+
if (sender) result = readOutcome(workerProcessState(sender).signals.outcome);
|
|
1895
|
+
} catch (error) {
|
|
1896
|
+
if (
|
|
1897
|
+
!(error instanceof ProcessError) ||
|
|
1898
|
+
(error.errno !== ProcessErrno.SRCH && error.errno !== ProcessErrno.CHILD)
|
|
1899
|
+
)
|
|
1900
|
+
throw error;
|
|
1901
|
+
}
|
|
1902
|
+
// A published spawn or consuming receipt can arrive after its original sender's
|
|
1903
|
+
// process row was collected. The still-live directory and captured PID authenticate
|
|
1904
|
+
// the notice, never the process now occupying its old slot.
|
|
1905
|
+
let retainedNotice = false;
|
|
1906
|
+
if (
|
|
1907
|
+
!sender &&
|
|
1908
|
+
(message.operation === "spawn" ||
|
|
1909
|
+
message.operation === "reap-job" ||
|
|
1910
|
+
message.operation === "reap-process")
|
|
1911
|
+
) {
|
|
1912
|
+
const directory = workerProcessDirectoryId(message.transport);
|
|
1913
|
+
const root = Array.from(this.roots.values()).find(
|
|
1914
|
+
(root) => workerProcessDirectoryId(root) === directory,
|
|
1915
|
+
);
|
|
1916
|
+
if (root) {
|
|
1917
|
+
if (message.operation === "reap-job" || message.operation === "reap-process")
|
|
1918
|
+
retainedNotice = message.transport.pid === senderPid;
|
|
1919
|
+
else {
|
|
1920
|
+
try {
|
|
1921
|
+
retainedNotice = workerProcessState(message.transport).parentPid === senderPid;
|
|
1922
|
+
} catch (error) {
|
|
1923
|
+
if (
|
|
1924
|
+
!(error instanceof ProcessError) ||
|
|
1925
|
+
(error.errno !== ProcessErrno.SRCH && error.errno !== ProcessErrno.CHILD)
|
|
1926
|
+
)
|
|
1927
|
+
throw error;
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
const revoked = !consumingReceipt && senderRevoked(result, filesystemRevoked);
|
|
1933
|
+
const stopping = this.commandMessageStopped(message);
|
|
1934
|
+
if ((!sender && !retainedNotice) || this.suspended || revoked || stopping) {
|
|
1935
|
+
this.rejectMessage(
|
|
1936
|
+
message,
|
|
1937
|
+
senderPid,
|
|
1938
|
+
this.suspended
|
|
1939
|
+
? "broker-disposed"
|
|
1940
|
+
: !sender
|
|
1941
|
+
? "unknown-sender"
|
|
1942
|
+
: result?.kind === "signaled"
|
|
1943
|
+
? "sender-signaled"
|
|
1944
|
+
: stopping
|
|
1945
|
+
? "external-rejection"
|
|
1946
|
+
: "sender-revoked",
|
|
1947
|
+
);
|
|
1948
|
+
return;
|
|
1949
|
+
}
|
|
1950
|
+
if (message.operation === "access" || message.operation === "access-cancel") {
|
|
1951
|
+
await this.accessMessage(message, senderPid, sender, result);
|
|
1952
|
+
return;
|
|
1953
|
+
}
|
|
1954
|
+
await this.transport.handle(message, senderPid);
|
|
1955
|
+
this.retireRoots();
|
|
1956
|
+
if (message.operation !== "pipe") this.watch();
|
|
1957
|
+
}
|
|
1958
|
+
private commandMessageStopped(message: WorkerProcessMessage): boolean {
|
|
1959
|
+
if (message.operation !== "spawn" && message.operation !== "exec") return false;
|
|
1960
|
+
try {
|
|
1961
|
+
const scope = this.commandScope(message.transport);
|
|
1962
|
+
return scope !== undefined && this.commandAdmissionClosed(scope);
|
|
1963
|
+
} catch (error) {
|
|
1964
|
+
if (!isCollectedProcess(error)) throw error;
|
|
1965
|
+
return false;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
private async accessMessage(
|
|
1969
|
+
message: Extract<WorkerProcessMessage, { operation: "access" | "access-cancel" }>,
|
|
1970
|
+
senderPid: number,
|
|
1971
|
+
sender: WorkerProcessTransport | undefined,
|
|
1972
|
+
result: ProcessExit | null,
|
|
1973
|
+
): Promise<void> {
|
|
1974
|
+
if (
|
|
1975
|
+
!sender ||
|
|
1976
|
+
result ||
|
|
1977
|
+
workerProcessState(message.transport).pid !== senderPid ||
|
|
1978
|
+
workerProcessDirectoryId(sender) !== workerProcessDirectoryId(message.transport)
|
|
1979
|
+
) {
|
|
1980
|
+
this.rejectMessage(message, senderPid, "wrong-sender");
|
|
1981
|
+
return;
|
|
1982
|
+
}
|
|
1983
|
+
await (this.children.get(senderPid)?.accesses ?? this.accesses).handle(message, sender);
|
|
1984
|
+
}
|
|
1985
|
+
rejectRuntimeMessage(
|
|
1986
|
+
message: WorkerProcessMessage,
|
|
1987
|
+
senderPid?: number,
|
|
1988
|
+
reason: ProcessAdmissionEvent["reason"] = "external-rejection",
|
|
1989
|
+
): void {
|
|
1990
|
+
this.traceSpawn(message, "received");
|
|
1991
|
+
this.rejectMessage(message, senderPid, reason);
|
|
1992
|
+
}
|
|
1993
|
+
private traceProcess(
|
|
1994
|
+
identity: Pick<ProcessAdmissionEvent, "pid" | "parentPid" | "job">,
|
|
1995
|
+
stage: ProcessAdmissionEvent["stage"],
|
|
1996
|
+
reason?: ProcessAdmissionEvent["reason"],
|
|
1997
|
+
): void {
|
|
1998
|
+
if (!this.options.onProcessAdmission) return;
|
|
1999
|
+
const transport = this.transport.getIdentity(identity.pid);
|
|
2000
|
+
reportProcessAdmission(
|
|
2001
|
+
this.options.onProcessAdmission,
|
|
2002
|
+
identity,
|
|
2003
|
+
stage,
|
|
2004
|
+
reason,
|
|
2005
|
+
transport ? workerProcessDirectoryId(transport) : undefined,
|
|
2006
|
+
);
|
|
2007
|
+
}
|
|
2008
|
+
private traceSpawn(
|
|
2009
|
+
message: WorkerProcessMessage,
|
|
2010
|
+
stage: ProcessAdmissionEvent["stage"],
|
|
2011
|
+
reason?: ProcessAdmissionEvent["reason"],
|
|
2012
|
+
): void {
|
|
2013
|
+
if (message.operation !== "spawn" || !this.options.onProcessAdmission) return;
|
|
2014
|
+
try {
|
|
2015
|
+
reportProcessAdmission(
|
|
2016
|
+
this.options.onProcessAdmission,
|
|
2017
|
+
workerProcessState(message.transport),
|
|
2018
|
+
stage,
|
|
2019
|
+
reason,
|
|
2020
|
+
workerProcessDirectoryId(message.transport),
|
|
2021
|
+
);
|
|
2022
|
+
} catch (error) {
|
|
2023
|
+
if (
|
|
2024
|
+
!(error instanceof ProcessError) ||
|
|
2025
|
+
(error.errno !== ProcessErrno.SRCH && error.errno !== ProcessErrno.CHILD)
|
|
2026
|
+
)
|
|
2027
|
+
throw error;
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
private rejectMessage(
|
|
2031
|
+
message: WorkerProcessMessage,
|
|
2032
|
+
senderPid: number | undefined,
|
|
2033
|
+
reason: ProcessAdmissionEvent["reason"],
|
|
2034
|
+
): void {
|
|
2035
|
+
if (message.operation === "exec") {
|
|
2036
|
+
void this.transport
|
|
2037
|
+
.rejectExec(message, new ProcessError(ProcessErrno.SRCH, "exec sender is unavailable"))
|
|
2038
|
+
.catch((error) => this.report(error));
|
|
2039
|
+
return;
|
|
2040
|
+
}
|
|
2041
|
+
if (message.operation === "access" || message.operation === "access-cancel") {
|
|
2042
|
+
rejectWorkerAccess(message);
|
|
2043
|
+
return;
|
|
2044
|
+
}
|
|
2045
|
+
if (message.operation === "reap-job") {
|
|
2046
|
+
if (!this.suspended && senderPid !== undefined)
|
|
2047
|
+
void this.transport.handle(message, senderPid).catch((error) => this.report(error));
|
|
2048
|
+
return;
|
|
2049
|
+
}
|
|
2050
|
+
if (message.operation !== "spawn") return;
|
|
2051
|
+
const transport = message.transport;
|
|
2052
|
+
let state: ReturnType<typeof workerProcessState>;
|
|
2053
|
+
try {
|
|
2054
|
+
state = workerProcessState(transport);
|
|
2055
|
+
} catch (error) {
|
|
2056
|
+
if (
|
|
2057
|
+
error instanceof ProcessError &&
|
|
2058
|
+
(error.errno === ProcessErrno.SRCH || error.errno === ProcessErrno.CHILD)
|
|
2059
|
+
)
|
|
2060
|
+
return;
|
|
2061
|
+
throw error;
|
|
2062
|
+
}
|
|
2063
|
+
const directory = workerProcessDirectoryId(transport);
|
|
2064
|
+
const key = `${directory}:${state.pid}`;
|
|
2065
|
+
if (this.transport.getIdentity(state.pid, directory) || this.rejectedTransfers.has(key)) {
|
|
2066
|
+
this.traceSpawn(message, "dropped", "already-registered");
|
|
2067
|
+
return;
|
|
2068
|
+
}
|
|
2069
|
+
this.traceSpawn(message, "rejected", reason);
|
|
2070
|
+
requestSignal(state.signals, 9);
|
|
2071
|
+
this.revokeRuntimeProcess(state.pid, workerProcessDirectoryId(transport));
|
|
2072
|
+
let resolve!: () => void, reject!: (error: unknown) => void;
|
|
2073
|
+
const pending = new Promise<void>((accept, fail) => {
|
|
2074
|
+
resolve = accept;
|
|
2075
|
+
reject = fail;
|
|
2076
|
+
});
|
|
2077
|
+
this.rejectedTransfers.set(key, pending);
|
|
2078
|
+
void this.trackCommandTransfer(transport, () => this.releaseRejectedTransfer(transport)).then(
|
|
2079
|
+
resolve,
|
|
2080
|
+
reject,
|
|
2081
|
+
);
|
|
2082
|
+
void pending.then(
|
|
2083
|
+
() => this.rejectedTransfers.delete(key),
|
|
2084
|
+
(error) => this.report(error),
|
|
2085
|
+
);
|
|
2086
|
+
}
|
|
2087
|
+
private async releaseRejectedTransfer(transport: WorkerProcessTransport): Promise<void> {
|
|
2088
|
+
const errors: unknown[] = [];
|
|
2089
|
+
const codec = this.discardCodec();
|
|
2090
|
+
for (const token of transport.resources) {
|
|
2091
|
+
try {
|
|
2092
|
+
codec.discard(token);
|
|
2093
|
+
} catch (error) {
|
|
2094
|
+
errors.push(error);
|
|
2095
|
+
this.report(error);
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
wakeWorkerProcess(transport);
|
|
2099
|
+
await this.quiesceUnstarted(transport);
|
|
2100
|
+
const scope = this.commandScope(transport);
|
|
2101
|
+
if (errors.length) {
|
|
2102
|
+
if (scope) throw new AggregateError(errors, "Rejected spawn descriptor cleanup failed");
|
|
2103
|
+
return;
|
|
2104
|
+
}
|
|
2105
|
+
if (scope) await this.retireRejectedCommand(transport);
|
|
2106
|
+
controlStore(workerProcessState(transport).confirmed, 0, 1);
|
|
2107
|
+
confirmWorkerProcessJob(transport);
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
transportFor(pid: number): WorkerProcessTransport | undefined {
|
|
2111
|
+
return this.transport.get(pid);
|
|
2112
|
+
}
|
|
2113
|
+
/** Legacy handle ABIs have no job waiter; release their empty, unshared completion metadata. */
|
|
2114
|
+
releaseLegacyJob(job: number): void {
|
|
2115
|
+
this.retireRoots();
|
|
2116
|
+
const record = this.options.table.job(job);
|
|
2117
|
+
if (
|
|
2118
|
+
!record ||
|
|
2119
|
+
record.members.size ||
|
|
2120
|
+
record.pendingMembers ||
|
|
2121
|
+
this.states().some((state) => state.job === job)
|
|
2122
|
+
)
|
|
2123
|
+
return;
|
|
2124
|
+
this.supervisor?.reapJob(record.ownerPid, job);
|
|
2125
|
+
}
|
|
2126
|
+
/**
|
|
2127
|
+
* A fresh single-use module worker for a root the consumer launches itself.
|
|
2128
|
+
* It stays inert until the consumer posts its request; the consumer owns its termination.
|
|
2129
|
+
*/
|
|
2130
|
+
takeWorker(workerUrl: string): Worker {
|
|
2131
|
+
if (this.suspended) throw new Error("Process broker is disposed");
|
|
2132
|
+
return this.workers.take(workerUrl);
|
|
2133
|
+
}
|
|
2134
|
+
/** Trusted external-root bootstrap field, never guest environment configuration. */
|
|
2135
|
+
rootControlGrant(pid: number): SharedControlGrant {
|
|
2136
|
+
const grant = this.rootGrants.get(pid);
|
|
2137
|
+
if (!grant) throw new ProcessError(ProcessErrno.SRCH, "Root is not admitted");
|
|
2138
|
+
return grant;
|
|
2139
|
+
}
|
|
2140
|
+
/** Trusted root launcher must enroll before its bootstrap post or graphics port transfer. */
|
|
2141
|
+
retainRootGraphics(pid: number, graphics: GraphicsGrant, worker: Worker): void {
|
|
2142
|
+
const ticket = this.rootAdmissions.get(pid);
|
|
2143
|
+
const launched = this.rootTickets.get(pid);
|
|
2144
|
+
if (!ticket || !launched) throw new ProcessError(ProcessErrno.SRCH, "Root is not admitted");
|
|
2145
|
+
const retention = ticket.retainControlsForGraphics();
|
|
2146
|
+
bindGraphicsLaunch(graphics, retention);
|
|
2147
|
+
retainAllocationReceipts(worker, launched, retention, (error) => this.report(error));
|
|
2148
|
+
}
|
|
2149
|
+
/** Capture before handing process controls to an externally owned native consumer. */
|
|
2150
|
+
captureRootStop(pid: number, stop: () => void | Promise<void>): () => void | Promise<void> {
|
|
2151
|
+
const captured = this.captureConsumerStop(pid, stop);
|
|
2152
|
+
return () => captured.terminate();
|
|
2153
|
+
}
|
|
2154
|
+
/** Only the native root consumer is bound. Independent captureRootStop helpers are excluded. */
|
|
2155
|
+
private bindRootGroup(pid: number, handle: NativeStopHandle): NativeStopHandle {
|
|
2156
|
+
const group = this.rootGroups?.get(pid);
|
|
2157
|
+
if (group) handle.bindGroup(group);
|
|
2158
|
+
return handle;
|
|
2159
|
+
}
|
|
2160
|
+
private captureConsumerStop(
|
|
2161
|
+
pid: number,
|
|
2162
|
+
stop: () => void | Promise<void>,
|
|
2163
|
+
onReturned?: () => void,
|
|
2164
|
+
): NativeStopHandle {
|
|
2165
|
+
const owner = this.observationOwners.get(pid);
|
|
2166
|
+
if (!owner) throw new ProcessError(ProcessErrno.SRCH, "Root is not admitted");
|
|
2167
|
+
const returned = owner.acquire();
|
|
2168
|
+
const handle = nativeStopHandle(
|
|
2169
|
+
{ terminate: stop },
|
|
2170
|
+
undefined,
|
|
2171
|
+
() => {
|
|
2172
|
+
owner.removeStop(handle);
|
|
2173
|
+
onReturned?.();
|
|
2174
|
+
returned();
|
|
2175
|
+
},
|
|
2176
|
+
() => owner.close(),
|
|
2177
|
+
(error) => owner.fail(error),
|
|
2178
|
+
);
|
|
2179
|
+
owner.addStop(handle);
|
|
2180
|
+
return handle;
|
|
2181
|
+
}
|
|
2182
|
+
/** A successful external native return acknowledges only this root's controller consumer. */
|
|
2183
|
+
rootStopped(pid: number): void {
|
|
2184
|
+
const stop = this.controllerNativeStopFor(pid);
|
|
2185
|
+
if (stop) {
|
|
2186
|
+
stop.acknowledgeReturn();
|
|
2187
|
+
return;
|
|
2188
|
+
}
|
|
2189
|
+
this.rootTickets.get(pid)?.stopped();
|
|
2190
|
+
this.rootTickets.delete(pid);
|
|
2191
|
+
this.rootAdmissions.delete(pid);
|
|
2192
|
+
this.rootGrants.delete(pid);
|
|
2193
|
+
}
|
|
2194
|
+
rootControlAllocated(pid: number, buffer: SharedArrayBuffer): void {
|
|
2195
|
+
const ticket = this.rootTickets.get(pid);
|
|
2196
|
+
if (!ticket) throw new ProcessError(ProcessErrno.SRCH, "Root is not admitted");
|
|
2197
|
+
ticket.controlAllocated(buffer);
|
|
2198
|
+
}
|
|
2199
|
+
/** Always false: workers transfer to their caller immediately, with no idle residency. */
|
|
2200
|
+
isIdleWorker(worker: Worker): boolean {
|
|
2201
|
+
return this.workers.isIdle(worker);
|
|
2202
|
+
}
|
|
2203
|
+
/** Includes pending/failed physical cleanup. Each result is a fresh, authority-free snapshot. */
|
|
2204
|
+
workerMemory(): readonly WorkerMemoryObservation[] {
|
|
2205
|
+
return Array.from(this.children.values(), (child) => {
|
|
2206
|
+
const bytes = Atomics.load(child.memory, 0);
|
|
2207
|
+
return { ...child.identity, bytes: bytes < 0n ? null : Number(bytes) };
|
|
2208
|
+
});
|
|
2209
|
+
}
|
|
2210
|
+
async prepareOperationDiagnostics(): Promise<void> {
|
|
2211
|
+
try {
|
|
2212
|
+
const { OperationOwner } = await import("./operations/owner.js");
|
|
2213
|
+
this.#operations = new OperationOwner(
|
|
2214
|
+
(length) =>
|
|
2215
|
+
this.options.reservations.buffer("control", {
|
|
2216
|
+
kind: "fixed-buffer",
|
|
2217
|
+
length: bytes(length),
|
|
2218
|
+
}),
|
|
2219
|
+
({ pid, generation, captureId }) => {
|
|
2220
|
+
const child = this.children.get(pid);
|
|
2221
|
+
return child?.generation === generation && child.operationCapture === captureId;
|
|
2222
|
+
},
|
|
2223
|
+
);
|
|
2224
|
+
} catch {
|
|
2225
|
+
this.#operationsUnavailable = true;
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
operationDiagnostics(): OperationDiagnostics {
|
|
2229
|
+
if (!this.options.observeOperations) return { status: "disabled" };
|
|
2230
|
+
try {
|
|
2231
|
+
return (
|
|
2232
|
+
this.#operations?.snapshot() ?? {
|
|
2233
|
+
status: this.#operationsUnavailable ? "unavailable" : "empty",
|
|
2234
|
+
}
|
|
2235
|
+
);
|
|
2236
|
+
} catch {
|
|
2237
|
+
return { status: "unavailable" };
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
private captureOperations(
|
|
2241
|
+
child: RuntimeChild,
|
|
2242
|
+
options: WorkerLaunchOptions,
|
|
2243
|
+
enabled: boolean,
|
|
2244
|
+
): GuestOperationBinding | undefined {
|
|
2245
|
+
if (!enabled || !this.#operations || options.memoryGroup || options.memories?.length) return;
|
|
2246
|
+
const memories = moduleMemoryDeclarations(options.request.module);
|
|
2247
|
+
if (memories?.length !== 1 || memories[0]?.kind !== "private") return;
|
|
2248
|
+
try {
|
|
2249
|
+
const binding = this.#operations.enroll(child.identity.pid, child.generation);
|
|
2250
|
+
if (binding) child.operationCapture = binding.captureId;
|
|
2251
|
+
return binding;
|
|
2252
|
+
} catch {
|
|
2253
|
+
return;
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
private connectWorkerFilesystem(
|
|
2257
|
+
filesystem: FilesystemIdentity,
|
|
2258
|
+
arena: Headroom | null,
|
|
2259
|
+
binding: GuestOperationBinding | undefined,
|
|
2260
|
+
): FilesystemConnection {
|
|
2261
|
+
if (!binding) return this.options.filesystem.connect(filesystem, arena);
|
|
2262
|
+
const { buffer, slot, captureId } = binding;
|
|
2263
|
+
return this.options.filesystem.connect(filesystem, arena, { buffer, slot, captureId });
|
|
2264
|
+
}
|
|
2265
|
+
/**
|
|
2266
|
+
* The start step each live launch reached, with page timestamps: a hung start names its
|
|
2267
|
+
* stuck step. Fresh authority-free snapshots; see docs/process-observation.md, "Start states".
|
|
2268
|
+
*/
|
|
2269
|
+
startStates(): readonly ProcessStartState[] {
|
|
2270
|
+
const states: ProcessStartState[] = [];
|
|
2271
|
+
for (const child of this.children.values()) {
|
|
2272
|
+
if (child.guestEnded || child.failed || child.stopped) continue;
|
|
2273
|
+
observeStart(child.start, child.memory, child.context.outcome);
|
|
2274
|
+
states.push(startSnapshot(child.start));
|
|
2275
|
+
}
|
|
2276
|
+
for (const launch of this.pendingLaunches?.values() ?? []) {
|
|
2277
|
+
// A launch that already constructed its worker is listed (or retired) as that child.
|
|
2278
|
+
if (this.children.get(launch.start.pid)?.start === launch.start) continue;
|
|
2279
|
+
states.push(startSnapshot(launch.start));
|
|
2280
|
+
}
|
|
2281
|
+
return states;
|
|
2282
|
+
}
|
|
2283
|
+
/**
|
|
2284
|
+
* Trusted launcher pairing for RuntimeNetwork.createHelper: the live admitted process's own
|
|
2285
|
+
* filesystem identity with `directory`. Nothing is attached here; the network authenticates the
|
|
2286
|
+
* pair (same filesystem, live identity, a directory the guest's table holds) on the guest's first
|
|
2287
|
+
* path request. The caller keeps owning `directory` and releases it after the helper is disposed.
|
|
2288
|
+
*/
|
|
2289
|
+
networkPathScope(context: ProcessContext, directory: FileHandle): RuntimeNetworkPathScope {
|
|
2290
|
+
if (this.suspended) throw new Error("Process broker is disposed");
|
|
2291
|
+
if (!Number.isSafeInteger(directory) || directory < 0)
|
|
2292
|
+
throw new TypeError("Network path scope requires a directory handle");
|
|
2293
|
+
const transport = this.transport.get(context.pid);
|
|
2294
|
+
if (!transport) throw new Error("process has no admitted worker transport");
|
|
2295
|
+
const state = workerProcessState(transport);
|
|
2296
|
+
if (state.parentPid !== context.parentPid || state.job !== context.job)
|
|
2297
|
+
throw new Error("process context does not match its admitted transport");
|
|
2298
|
+
if (readOutcome(context.outcome)) throw new Error("process has already exited");
|
|
2299
|
+
const filesystem = this.filesystem(transport);
|
|
2300
|
+
if (isRevoked(filesystem)) throw new Error("process filesystem is revoked");
|
|
2301
|
+
return Object.freeze({ filesystem, directory });
|
|
2302
|
+
}
|
|
2303
|
+
private workerPlan(context: ProcessContext, options: WorkerLaunchOptions): ProcessPlan {
|
|
2304
|
+
const memories = moduleMemoryDeclarations(options.request.module);
|
|
2305
|
+
const guest: ProcessGuestPlan = options.memoryGroup
|
|
2306
|
+
? { kind: "declared", memories: options.memories ?? [] }
|
|
2307
|
+
: memories
|
|
2308
|
+
? { kind: "declared", memories: memories.concat(options.memories ?? []) }
|
|
2309
|
+
: { kind: "undeclared" };
|
|
2310
|
+
const group =
|
|
2311
|
+
options.memoryGroup === "new"
|
|
2312
|
+
? {
|
|
2313
|
+
create: this.options.reservations.sizing.groupShape(
|
|
2314
|
+
this.options.memoryGroups?.maximumPages,
|
|
2315
|
+
),
|
|
2316
|
+
}
|
|
2317
|
+
: options.memoryGroup
|
|
2318
|
+
? "join"
|
|
2319
|
+
: "none";
|
|
2320
|
+
return {
|
|
2321
|
+
pid: context.pid,
|
|
2322
|
+
executable: context.request.executable,
|
|
2323
|
+
guest,
|
|
2324
|
+
group,
|
|
2325
|
+
connection: true,
|
|
2326
|
+
controls: true,
|
|
2327
|
+
};
|
|
2328
|
+
}
|
|
2329
|
+
launchWorker<T extends RuntimeWorkerRequest>(
|
|
2330
|
+
context: ProcessContext,
|
|
2331
|
+
options: WorkerLaunchOptions<T>,
|
|
2332
|
+
): ProcessHandle {
|
|
2333
|
+
const graphicsOwner = options.graphics;
|
|
2334
|
+
let graphicsReleased = false;
|
|
2335
|
+
const graphics: GraphicsGrant | undefined = graphicsOwner && {
|
|
2336
|
+
connection: graphicsOwner.connection,
|
|
2337
|
+
dispose() {
|
|
2338
|
+
if (graphicsReleased) return;
|
|
2339
|
+
graphicsReleased = true;
|
|
2340
|
+
graphicsOwner.dispose();
|
|
2341
|
+
},
|
|
2342
|
+
retired: () => graphicsOwner.retired(),
|
|
2343
|
+
};
|
|
2344
|
+
if (graphics && graphicsOwner) originalGraphicsGrants.set(graphics, graphicsOwner);
|
|
2345
|
+
const owner = options.network;
|
|
2346
|
+
let released = false;
|
|
2347
|
+
const network = owner && {
|
|
2348
|
+
connection: owner.connection,
|
|
2349
|
+
dispose() {
|
|
2350
|
+
if (released) return;
|
|
2351
|
+
released = true;
|
|
2352
|
+
owner.dispose();
|
|
2353
|
+
},
|
|
2354
|
+
};
|
|
2355
|
+
try {
|
|
2356
|
+
this.checkGuestImage(context.pid, context.generation);
|
|
2357
|
+
if (options.memoryGroup)
|
|
2358
|
+
requireGroupPlan(
|
|
2359
|
+
options.request.module,
|
|
2360
|
+
"linkPlan" in options.request ? options.request.linkPlan : undefined,
|
|
2361
|
+
);
|
|
2362
|
+
if (readOutcome(context.outcome))
|
|
2363
|
+
throw new ProcessError(ProcessErrno.SRCH, "process exited before worker admission");
|
|
2364
|
+
const threaded = threadModuleDeclaration(options.request.module);
|
|
2365
|
+
if (threaded && graphics) throw new Error("Threaded guests do not accept graphics grants");
|
|
2366
|
+
if (threaded) return this.launchThreadWorker(context, options, threaded);
|
|
2367
|
+
if (
|
|
2368
|
+
WebAssembly.Module.imports(options.request.module).some(
|
|
2369
|
+
(entry) => entry.module === "wasi" && entry.name === "thread-spawn",
|
|
2370
|
+
)
|
|
2371
|
+
)
|
|
2372
|
+
throw new Error("Threaded Preview 1 requires validated source bytes");
|
|
2373
|
+
return this.launchOwnedWorker(
|
|
2374
|
+
context,
|
|
2375
|
+
{ ...options, network, graphics },
|
|
2376
|
+
!!this.#operations && options[preview1Launch] === true,
|
|
2377
|
+
);
|
|
2378
|
+
} catch (error) {
|
|
2379
|
+
if (
|
|
2380
|
+
!this.children.has(context.pid) &&
|
|
2381
|
+
context.execution?.kind !== "host" &&
|
|
2382
|
+
this.options.table.get(context.pid)?.image.execution?.kind !== "host" &&
|
|
2383
|
+
typeof error === "object" &&
|
|
2384
|
+
error !== null
|
|
2385
|
+
)
|
|
2386
|
+
this.neverConstructed.set(error, context.pid);
|
|
2387
|
+
try {
|
|
2388
|
+
graphics?.dispose();
|
|
2389
|
+
} catch (cleanup) {
|
|
2390
|
+
this.report(cleanup);
|
|
2391
|
+
}
|
|
2392
|
+
try {
|
|
2393
|
+
network?.dispose();
|
|
2394
|
+
} catch (cleanup) {
|
|
2395
|
+
this.report(cleanup);
|
|
2396
|
+
}
|
|
2397
|
+
throw error;
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
private launchThreadWorker(
|
|
2401
|
+
context: ProcessContext,
|
|
2402
|
+
options: WorkerLaunchOptions,
|
|
2403
|
+
declaration: NonNullable<ReturnType<typeof threadModuleDeclaration>>,
|
|
2404
|
+
): ProcessHandle {
|
|
2405
|
+
const { threaded: urls, cleanup } = options;
|
|
2406
|
+
if (
|
|
2407
|
+
!urls ||
|
|
2408
|
+
options.memoryGroup ||
|
|
2409
|
+
options.network ||
|
|
2410
|
+
options.memories?.length ||
|
|
2411
|
+
!options.request.interruptible
|
|
2412
|
+
)
|
|
2413
|
+
throw new Error("Threaded Preview 1 requires the explicit source-admitted thread launcher");
|
|
2414
|
+
if (this.suspended) throw new Error("Process broker is disposed");
|
|
2415
|
+
const transport = this.transport.get(context.pid);
|
|
2416
|
+
if (!transport || transport.generation !== context.generation || this.children.has(context.pid))
|
|
2417
|
+
throw new Error("process has no available worker transport");
|
|
2418
|
+
const state = workerProcessState(transport);
|
|
2419
|
+
const filesystem = this.filesystem(transport);
|
|
2420
|
+
this.bindPipeRegistry(transport);
|
|
2421
|
+
const memory = new BigInt64Array(allocateSharedControl(8));
|
|
2422
|
+
Atomics.store(memory, 0, -1n);
|
|
2423
|
+
const launch = this.launchState(context);
|
|
2424
|
+
const child: RuntimeChild = {
|
|
2425
|
+
generation: context.generation,
|
|
2426
|
+
transport,
|
|
2427
|
+
launch,
|
|
2428
|
+
start: launch.pending?.start ?? processStartRecord(context),
|
|
2429
|
+
nativeReturned: this.nativeLaunchReturns.get(context.pid),
|
|
2430
|
+
memory,
|
|
2431
|
+
filesystem,
|
|
2432
|
+
context,
|
|
2433
|
+
cleanup,
|
|
2434
|
+
identity: {
|
|
2435
|
+
pid: state.pid,
|
|
2436
|
+
parentPid: state.parentPid,
|
|
2437
|
+
rootPid: state.rootPid,
|
|
2438
|
+
job: state.job,
|
|
2439
|
+
directory: workerProcessDirectoryId(transport),
|
|
2440
|
+
},
|
|
2441
|
+
acknowledged: false,
|
|
2442
|
+
failed: false,
|
|
2443
|
+
stopped: false,
|
|
2444
|
+
};
|
|
2445
|
+
this.captureImageState(child);
|
|
2446
|
+
this.children.set(context.pid, child);
|
|
2447
|
+
context.registerRevocation(() => {
|
|
2448
|
+
this.options.filesystem.revoke(filesystem);
|
|
2449
|
+
void child.threads?.then((owner) => owner?.terminal()).catch((error) => this.report(error));
|
|
2450
|
+
});
|
|
2451
|
+
child.threads = import("../thread/runtime-owner.js").then(({ RuntimeThreadOwner }) =>
|
|
2452
|
+
RuntimeThreadOwner.create({
|
|
2453
|
+
context,
|
|
2454
|
+
transport,
|
|
2455
|
+
declaration,
|
|
2456
|
+
urls,
|
|
2457
|
+
reservations: this.options.reservations,
|
|
2458
|
+
connect: (headroom) => this.options.filesystem.connect(filesystem, headroom),
|
|
2459
|
+
filesystemFence: () => this.options.filesystem.quiesce(filesystem),
|
|
2460
|
+
nativeReturned: () => child.nativeReturned?.(),
|
|
2461
|
+
cleanup: () => {
|
|
2462
|
+
const dispose = child.cleanup;
|
|
2463
|
+
child.cleanup = undefined;
|
|
2464
|
+
dispose?.();
|
|
2465
|
+
},
|
|
2466
|
+
failed: (error) => {
|
|
2467
|
+
this.report(error);
|
|
2468
|
+
if (startStatus(context.outcome) === 0) context.fail(error);
|
|
2469
|
+
else context.startFailed(error);
|
|
2470
|
+
},
|
|
2471
|
+
}),
|
|
2472
|
+
);
|
|
2473
|
+
void child.threads.catch((error) => {
|
|
2474
|
+
child.failed = true;
|
|
2475
|
+
context.startFailed(error);
|
|
2476
|
+
});
|
|
2477
|
+
this.watch();
|
|
2478
|
+
return { terminate: () => this.stop(child) };
|
|
2479
|
+
}
|
|
2480
|
+
private launchOwnedWorker<T extends RuntimeWorkerRequest>(
|
|
2481
|
+
context: ProcessContext,
|
|
2482
|
+
options: WorkerLaunchOptions<T>,
|
|
2483
|
+
observeOperations: boolean,
|
|
2484
|
+
): ProcessHandle {
|
|
2485
|
+
if (this.suspended) {
|
|
2486
|
+
options.network?.dispose();
|
|
2487
|
+
throw new Error("Process broker is disposed");
|
|
2488
|
+
}
|
|
2489
|
+
const transport = this.transport.get(context.pid);
|
|
2490
|
+
if (
|
|
2491
|
+
!transport ||
|
|
2492
|
+
transport.generation !== context.generation ||
|
|
2493
|
+
this.children.has(context.pid)
|
|
2494
|
+
) {
|
|
2495
|
+
options.network?.dispose();
|
|
2496
|
+
throw new Error(
|
|
2497
|
+
!transport ? "process has no admitted worker transport" : "process already has a worker",
|
|
2498
|
+
);
|
|
2499
|
+
}
|
|
2500
|
+
const state = workerProcessState(transport);
|
|
2501
|
+
const ticket = this.options.reservations.admit(this.workerPlan(context, options));
|
|
2502
|
+
if (options.graphics) {
|
|
2503
|
+
try {
|
|
2504
|
+
const retention = ticket.retainControlsForGraphics();
|
|
2505
|
+
bindGraphicsLaunch(options.graphics, retention);
|
|
2506
|
+
const original = originalGraphicsGrants.get(options.graphics);
|
|
2507
|
+
if (original) bindGraphicsLaunch(original, retention);
|
|
2508
|
+
} catch (error) {
|
|
2509
|
+
ticket.abort();
|
|
2510
|
+
throw error;
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
let memory: BigInt64Array<SharedArrayBuffer>;
|
|
2514
|
+
try {
|
|
2515
|
+
memory = new BigInt64Array(allocateSharedControl(8));
|
|
2516
|
+
Atomics.store(memory, 0, -1n);
|
|
2517
|
+
} catch (error) {
|
|
2518
|
+
ticket.abort();
|
|
2519
|
+
throw error;
|
|
2520
|
+
}
|
|
2521
|
+
const filesystem = this.filesystem(transport);
|
|
2522
|
+
// Record cleanup ownership before either connection or Worker construction can throw.
|
|
2523
|
+
const launch = this.launchState(context);
|
|
2524
|
+
const child: RuntimeChild = {
|
|
2525
|
+
generation: context.generation,
|
|
2526
|
+
transport,
|
|
2527
|
+
launch,
|
|
2528
|
+
start: launch.pending?.start ?? processStartRecord(context),
|
|
2529
|
+
nativeReturned: this.nativeLaunchReturns.get(context.pid),
|
|
2530
|
+
ticket,
|
|
2531
|
+
memory,
|
|
2532
|
+
identity: {
|
|
2533
|
+
pid: state.pid,
|
|
2534
|
+
parentPid: state.parentPid,
|
|
2535
|
+
rootPid: state.rootPid,
|
|
2536
|
+
job: state.job,
|
|
2537
|
+
directory: workerProcessDirectoryId(transport),
|
|
2538
|
+
},
|
|
2539
|
+
filesystem,
|
|
2540
|
+
context,
|
|
2541
|
+
acknowledged: false,
|
|
2542
|
+
failed: false,
|
|
2543
|
+
stopped: false,
|
|
2544
|
+
cleanup: options.cleanup,
|
|
2545
|
+
network: options.network,
|
|
2546
|
+
graphics: options.graphics,
|
|
2547
|
+
wake: options.wake,
|
|
2548
|
+
};
|
|
2549
|
+
this.captureImageState(child);
|
|
2550
|
+
this.children.set(context.pid, child);
|
|
2551
|
+
const operations = this.captureOperations(child, options, observeOperations);
|
|
2552
|
+
context.registerRevocation(() => this.disposeNetwork(child));
|
|
2553
|
+
let connection: FilesystemConnection | undefined;
|
|
2554
|
+
let worker: Worker;
|
|
2555
|
+
let output: TerminalOutputReader;
|
|
2556
|
+
try {
|
|
2557
|
+
this.bindPipeRegistry(transport);
|
|
2558
|
+
output = child.output = createTerminalOutput();
|
|
2559
|
+
let budget = this.terminalOutputs.get(state.rootPid);
|
|
2560
|
+
if (!budget) this.terminalOutputs.set(state.rootPid, (budget = new TerminalOutputBudget()));
|
|
2561
|
+
budget.readers.add(output);
|
|
2562
|
+
context.registerRevocation(() => output.close());
|
|
2563
|
+
const stderr = context.descriptors.get(2)?.resource;
|
|
2564
|
+
if (stderr instanceof PipeEndpoint) {
|
|
2565
|
+
// Imported page/worker descriptions share one close-once lifetime. Keep an independent
|
|
2566
|
+
// diagnostic capability through worker cleanup; bootstrap closes it at executable entry
|
|
2567
|
+
// so it cannot postpone ordinary guest fd2 closure or EOF.
|
|
2568
|
+
child.startupStderr = this.pipes.attach(stderr.handle()).duplicate(stderr);
|
|
2569
|
+
context.registerRevocation(() => child.startupStderr!.close());
|
|
2570
|
+
}
|
|
2571
|
+
if (options.notificationWorkerUrl)
|
|
2572
|
+
child.notifications = createNotificationBridge(options.notificationWorkerUrl);
|
|
2573
|
+
context.registerRevocation(() => {
|
|
2574
|
+
this.options.filesystem.revoke(filesystem);
|
|
2575
|
+
});
|
|
2576
|
+
if (options.memoryGroup)
|
|
2577
|
+
child.group = this.admitGroupMember(
|
|
2578
|
+
context.pid,
|
|
2579
|
+
transport,
|
|
2580
|
+
options.memoryGroup,
|
|
2581
|
+
ticket.group,
|
|
2582
|
+
);
|
|
2583
|
+
connection = this.connectWorkerFilesystem(filesystem, ticket.arena, operations);
|
|
2584
|
+
if (readOutcome(context.outcome))
|
|
2585
|
+
throw new ProcessError(ProcessErrno.SRCH, "process exited before worker construction");
|
|
2586
|
+
worker = child.worker = this.workers.take(options.workerUrl);
|
|
2587
|
+
markStart(child.start, "worker-constructed");
|
|
2588
|
+
this.imageStops.delete(context.pid);
|
|
2589
|
+
child.launched = ticket.launched();
|
|
2590
|
+
if (options.graphics)
|
|
2591
|
+
retainAllocationReceipts(
|
|
2592
|
+
worker,
|
|
2593
|
+
child.launched,
|
|
2594
|
+
graphicsLaunchRetention(options.graphics),
|
|
2595
|
+
(error) => this.report(error),
|
|
2596
|
+
);
|
|
2597
|
+
} catch (error) {
|
|
2598
|
+
// No Worker exists yet: the group reservation returns exactly once.
|
|
2599
|
+
child.group?.abort();
|
|
2600
|
+
ticket.abort();
|
|
2601
|
+
child.failed = true;
|
|
2602
|
+
this.disposeNotifications(child);
|
|
2603
|
+
this.disposeNetwork(child);
|
|
2604
|
+
connection?.port.close();
|
|
2605
|
+
throw error;
|
|
2606
|
+
}
|
|
2607
|
+
const request = {
|
|
2608
|
+
...options.request,
|
|
2609
|
+
hostIdentity: this.hostIdentity,
|
|
2610
|
+
memoryObservation: memory.buffer,
|
|
2611
|
+
controlGrant: ticket.control,
|
|
2612
|
+
filesystem: connection,
|
|
2613
|
+
runtimeProcess: transport,
|
|
2614
|
+
outcome: serializeOutcome(context.outcome),
|
|
2615
|
+
observation: context.observation,
|
|
2616
|
+
startupStderr: child.startupStderr?.handle(),
|
|
2617
|
+
notifications: child.notifications?.connection,
|
|
2618
|
+
terminalOutput: output.buffer,
|
|
2619
|
+
network: options.network?.connection,
|
|
2620
|
+
graphics: options.graphics?.connection,
|
|
2621
|
+
};
|
|
2622
|
+
const group = child.group?.launch();
|
|
2623
|
+
if (group) Object.assign(request, { memoryGroup: group.request });
|
|
2624
|
+
this.watch();
|
|
2625
|
+
worker.onmessage = ({ data }: MessageEvent<RuntimeWorkerMessage>) => {
|
|
2626
|
+
startMessage(child.start, data, memory, context.outcome);
|
|
2627
|
+
if (guestFinished(data?.type)) guestEnded(child);
|
|
2628
|
+
this.childMessage(child, options, data);
|
|
2629
|
+
};
|
|
2630
|
+
worker.onerror = (event) => {
|
|
2631
|
+
guestEnded(child);
|
|
2632
|
+
this.childError(child, event);
|
|
2633
|
+
};
|
|
2634
|
+
try {
|
|
2635
|
+
if (readOutcome(context.outcome))
|
|
2636
|
+
throw new ProcessError(ProcessErrno.SRCH, "process exited before worker publication");
|
|
2637
|
+
const ports: Transferable[] = [request.filesystem.port];
|
|
2638
|
+
if (request.notifications) ports.push(request.notifications.port);
|
|
2639
|
+
if (request.network) ports.push(request.network.port);
|
|
2640
|
+
if (request.graphics) ports.push(request.graphics.port);
|
|
2641
|
+
const bootstrap: RuntimeWorkerRequest | ObservedPreview1Bootstrap = operations
|
|
2642
|
+
? [request, operations]
|
|
2643
|
+
: request;
|
|
2644
|
+
worker.postMessage(bootstrap, group ? ports.concat(group.transfer) : ports);
|
|
2645
|
+
markStart(child.start, "start-posted");
|
|
2646
|
+
} catch (error) {
|
|
2647
|
+
child.failed = true;
|
|
2648
|
+
this.disposeNotifications(child);
|
|
2649
|
+
request.filesystem.port.close();
|
|
2650
|
+
this.disposeNetwork(child);
|
|
2651
|
+
throw error;
|
|
2652
|
+
}
|
|
2653
|
+
return { terminate: () => this.stopWorker(child) };
|
|
2654
|
+
}
|
|
2655
|
+
/** The group whose launched member runs as `pid`. Trusted embedder use only. */
|
|
2656
|
+
memoryGroupOf(pid: number): MemoryGroupHandle | undefined {
|
|
2657
|
+
return this.groups?.groupOf(pid);
|
|
2658
|
+
}
|
|
2659
|
+
/** Owner-side counters for every live group on this page. */
|
|
2660
|
+
memoryGroups(): readonly MemoryGroupSnapshot[] {
|
|
2661
|
+
return this.groups?.snapshot() ?? [];
|
|
2662
|
+
}
|
|
2663
|
+
/** Admit an adopted runtime root before posting its worker request. Successful disposal
|
|
2664
|
+
* stop of a root with `stop`, or the embedder's `stopped()`, settles it once. */
|
|
2665
|
+
admitRootMemoryGroup(
|
|
2666
|
+
pid: number,
|
|
2667
|
+
program: { readonly module: WebAssembly.Module; readonly linkPlan: SharedLinkPlan },
|
|
2668
|
+
join: MemoryGroupLaunch = "new",
|
|
2669
|
+
): RootMemoryGroupMember {
|
|
2670
|
+
this.checkGuestImage(pid);
|
|
2671
|
+
requireGroupPlan(program?.module, program?.linkPlan);
|
|
2672
|
+
if (this.suspended) throw new Error("Process broker is disposed");
|
|
2673
|
+
const transport = this.roots.get(pid);
|
|
2674
|
+
if (!transport) throw new Error(`Unknown runtime root ${pid}`);
|
|
2675
|
+
if (this.rootGroups?.has(pid)) throw new Error(`Root ${pid} already has a memory group`);
|
|
2676
|
+
const ticket = this.options.reservations.admit({
|
|
2677
|
+
pid,
|
|
2678
|
+
executable: "root memory group",
|
|
2679
|
+
guest: { kind: "group" },
|
|
2680
|
+
group:
|
|
2681
|
+
join === "new"
|
|
2682
|
+
? {
|
|
2683
|
+
create: this.options.reservations.sizing.groupShape(
|
|
2684
|
+
this.options.memoryGroups?.maximumPages,
|
|
2685
|
+
),
|
|
2686
|
+
}
|
|
2687
|
+
: "join",
|
|
2688
|
+
connection: false,
|
|
2689
|
+
controls: false,
|
|
2690
|
+
});
|
|
2691
|
+
let lease: MemberLease | undefined;
|
|
2692
|
+
let bootstrap: ReturnType<MemberLease["launch"]> | undefined;
|
|
2693
|
+
try {
|
|
2694
|
+
const admitted = (lease = this.admitGroupMember(pid, transport, join, ticket.group));
|
|
2695
|
+
// Finish bootstrap preparation before committing ownership of the external member.
|
|
2696
|
+
admitted.group.buffer();
|
|
2697
|
+
const { request, transfer } = (bootstrap = admitted.launch());
|
|
2698
|
+
ticket.launched();
|
|
2699
|
+
this.controllerNativeStopFor(pid)?.bindGroup(admitted);
|
|
2700
|
+
(this.rootGroups ??= new Map()).set(pid, admitted);
|
|
2701
|
+
return Object.freeze({
|
|
2702
|
+
group: admitted.group,
|
|
2703
|
+
request,
|
|
2704
|
+
transfer: Object.freeze(transfer),
|
|
2705
|
+
terminating: () => admitted.stopRequested(),
|
|
2706
|
+
stopped: () => this.settleRootGroup(pid, admitted),
|
|
2707
|
+
});
|
|
2708
|
+
} catch (error) {
|
|
2709
|
+
// No bootstrap request escaped, so no external agent can hold this incarnation.
|
|
2710
|
+
bootstrap?.request.port.close();
|
|
2711
|
+
lease?.stopped();
|
|
2712
|
+
ticket.abort();
|
|
2713
|
+
throw error;
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
/** A settled root lease must not keep its group's backing reachable; debt stays tracked. */
|
|
2717
|
+
private settleRootGroup(pid: number, lease: MemberLease): void {
|
|
2718
|
+
lease.stopped();
|
|
2719
|
+
if (!lease.settled() || this.rootGroups?.get(pid) !== lease) return;
|
|
2720
|
+
this.rootStopped(pid);
|
|
2721
|
+
if (this.rootGroups?.get(pid) === lease) this.rootGroups.delete(pid);
|
|
2722
|
+
}
|
|
2723
|
+
private childMessage<T extends RuntimeWorkerRequest>(
|
|
2724
|
+
child: RuntimeChild,
|
|
2725
|
+
options: WorkerLaunchOptions<T>,
|
|
2726
|
+
data: RuntimeWorkerMessage,
|
|
2727
|
+
): void {
|
|
2728
|
+
const context = child.context;
|
|
2729
|
+
const transport = child.transport;
|
|
2730
|
+
const filesystem = child.filesystem;
|
|
2731
|
+
if (!this.currentChild(child)) {
|
|
2732
|
+
this.traceProcess(child.identity, "dropped", "stale-image");
|
|
2733
|
+
return;
|
|
2734
|
+
}
|
|
2735
|
+
if (data.type === "replaced") {
|
|
2736
|
+
this.acknowledgeImage(child, data);
|
|
2737
|
+
return;
|
|
2738
|
+
}
|
|
2739
|
+
if (data.type === "shared-control-allocation") {
|
|
2740
|
+
if (!options.graphics) child.launched?.controlAllocated(data.buffer);
|
|
2741
|
+
return;
|
|
2742
|
+
}
|
|
2743
|
+
if (data.type === "observation-error") {
|
|
2744
|
+
this.report(new Error(data.message));
|
|
2745
|
+
return;
|
|
2746
|
+
}
|
|
2747
|
+
if (data.type === "terminal-output") {
|
|
2748
|
+
// Bytes the guest was told it wrote are delivered even after a signal won.
|
|
2749
|
+
this.serviceTerminalOutput(child.identity.rootPid);
|
|
2750
|
+
return;
|
|
2751
|
+
}
|
|
2752
|
+
const filesystemRevoked = data.type === "runtime-proc" && isRevoked(filesystem);
|
|
2753
|
+
let selected: ReturnType<typeof readOutcome>,
|
|
2754
|
+
entered = false;
|
|
2755
|
+
try {
|
|
2756
|
+
selected = readOutcome(context.outcome);
|
|
2757
|
+
if (data.type === "error") entered = startStatus(context.outcome) === 0;
|
|
2758
|
+
} catch (error) {
|
|
2759
|
+
if (
|
|
2760
|
+
!(error instanceof ProcessError) ||
|
|
2761
|
+
(error.errno !== ProcessErrno.SRCH && error.errno !== ProcessErrno.CHILD)
|
|
2762
|
+
)
|
|
2763
|
+
throw error;
|
|
2764
|
+
if (data.type !== "runtime-proc") return;
|
|
2765
|
+
selected = null;
|
|
2766
|
+
}
|
|
2767
|
+
if (data.type === "runtime-proc") {
|
|
2768
|
+
if (workerProcessDirectoryId(data.transport) !== workerProcessDirectoryId(transport)) return;
|
|
2769
|
+
if (senderRevoked(selected, filesystemRevoked))
|
|
2770
|
+
this.rejectRuntimeMessage(
|
|
2771
|
+
data,
|
|
2772
|
+
context.pid,
|
|
2773
|
+
selected?.kind === "signaled" ? "sender-signaled" : "sender-revoked",
|
|
2774
|
+
);
|
|
2775
|
+
else {
|
|
2776
|
+
const message = this.executableMessage(data, options.executableName);
|
|
2777
|
+
void this.runtimeMessage(message, context.pid).catch((error) => this.report(error));
|
|
2778
|
+
}
|
|
2779
|
+
return;
|
|
2780
|
+
}
|
|
2781
|
+
if (data.type === "cleanup-error") {
|
|
2782
|
+
if (this.options.table.get(context.pid)?.image.phase === "retiring") {
|
|
2783
|
+
child.failed = true;
|
|
2784
|
+
context.fail(new Error(`Worker replacement cleanup: ${data.message}`));
|
|
2785
|
+
return;
|
|
2786
|
+
}
|
|
2787
|
+
child.failed = true;
|
|
2788
|
+
this.report(new Error(`${data.message}: ${data.cleanupErrors.join("; ")}`));
|
|
2789
|
+
if (data.signal) context.defaultSignal(data.signal);
|
|
2790
|
+
else context.exit(data.code);
|
|
2791
|
+
this.stopSafely(child);
|
|
2792
|
+
return;
|
|
2793
|
+
}
|
|
2794
|
+
if (selected?.kind === "signaled" && data.type !== "exit" && data.type !== "error") {
|
|
2795
|
+
options.onMessage?.(data, context);
|
|
2796
|
+
return;
|
|
2797
|
+
}
|
|
2798
|
+
if (data.type !== "exit" && data.type !== "error") {
|
|
2799
|
+
options.onMessage?.(data, context);
|
|
2800
|
+
return;
|
|
2801
|
+
}
|
|
2802
|
+
this.disposeNotifications(child);
|
|
2803
|
+
this.disposeNetwork(child);
|
|
2804
|
+
child.acknowledged = true;
|
|
2805
|
+
this.options.filesystem.reap(filesystem);
|
|
2806
|
+
if (data.cleanupErrors?.length)
|
|
2807
|
+
this.report(new Error(`Worker cleanup: ${data.cleanupErrors.join("; ")}`));
|
|
2808
|
+
if (data.type === "exit" && data.signal) context.defaultSignal(data.signal);
|
|
2809
|
+
else if (data.type === "exit") context.exit(data.code);
|
|
2810
|
+
else if (!entered)
|
|
2811
|
+
context.startFailed(new WorkerStartError(data.message, data.errno, data.diagnostic));
|
|
2812
|
+
else context.fail(new Error(data.message));
|
|
2813
|
+
}
|
|
2814
|
+
private acknowledgeImage(
|
|
2815
|
+
child: RuntimeChild,
|
|
2816
|
+
message: Extract<RuntimeWorkerMessage, { type: "replaced" }>,
|
|
2817
|
+
): void {
|
|
2818
|
+
if (message.cleanupErrors?.length) {
|
|
2819
|
+
child.failed = true;
|
|
2820
|
+
child.context.fail(
|
|
2821
|
+
new Error(`Worker replacement cleanup: ${message.cleanupErrors.join("; ")}`),
|
|
2822
|
+
);
|
|
2823
|
+
return;
|
|
2824
|
+
}
|
|
2825
|
+
child.acknowledged = true;
|
|
2826
|
+
child.replacementAcknowledged = true;
|
|
2827
|
+
void this.supervisor
|
|
2828
|
+
?.acknowledgeReplacement(child.context.pid, child.generation)
|
|
2829
|
+
.catch((error) => this.report(error));
|
|
2830
|
+
}
|
|
2831
|
+
private executableMessage(
|
|
2832
|
+
message: WorkerProcessMessage,
|
|
2833
|
+
name?: (executable: string) => string,
|
|
2834
|
+
): WorkerProcessMessage {
|
|
2835
|
+
if (!name) return message;
|
|
2836
|
+
if (message.operation === "spawn")
|
|
2837
|
+
return {
|
|
2838
|
+
...message,
|
|
2839
|
+
request: { ...message.request, executable: name(message.request.executable) },
|
|
2840
|
+
};
|
|
2841
|
+
if (message.operation === "exec")
|
|
2842
|
+
return {
|
|
2843
|
+
...message,
|
|
2844
|
+
request: { ...message.request, executable: name(message.request.executable) },
|
|
2845
|
+
};
|
|
2846
|
+
return message;
|
|
2847
|
+
}
|
|
2848
|
+
private childError(child: RuntimeChild, event: ErrorEvent): void {
|
|
2849
|
+
const context = child.context;
|
|
2850
|
+
event.preventDefault();
|
|
2851
|
+
if (!this.currentChild(child)) {
|
|
2852
|
+
this.traceProcess(child.identity, "dropped", "stale-image");
|
|
2853
|
+
return;
|
|
2854
|
+
}
|
|
2855
|
+
child.failed = true;
|
|
2856
|
+
this.disposeNetwork(child);
|
|
2857
|
+
let status: number;
|
|
2858
|
+
try {
|
|
2859
|
+
status = startStatus(context.outcome);
|
|
2860
|
+
} catch (error) {
|
|
2861
|
+
// Browser error delivery may outlive collection; it cannot target a recycled row.
|
|
2862
|
+
if (
|
|
2863
|
+
error instanceof ProcessError &&
|
|
2864
|
+
(error.errno === ProcessErrno.SRCH || error.errno === ProcessErrno.CHILD)
|
|
2865
|
+
)
|
|
2866
|
+
return;
|
|
2867
|
+
throw error;
|
|
2868
|
+
}
|
|
2869
|
+
if (status !== 0) context.startFailed(event.error ?? new Error(event.message));
|
|
2870
|
+
else context.fail(new Error(event.message));
|
|
2871
|
+
}
|
|
2872
|
+
private admitGroupMember(
|
|
2873
|
+
pid: number,
|
|
2874
|
+
transport: WorkerProcessTransport,
|
|
2875
|
+
join: MemoryGroupLaunch,
|
|
2876
|
+
headroom: Headroom | null = null,
|
|
2877
|
+
): MemberLease {
|
|
2878
|
+
const groups = (this.groups ??= new MemoryGroups(
|
|
2879
|
+
this.options.memoryGroups,
|
|
2880
|
+
this.options.reservations.groups,
|
|
2881
|
+
this.options.reservations.sizing,
|
|
2882
|
+
));
|
|
2883
|
+
const target =
|
|
2884
|
+
join === "inherit" ? groups.groupOf(workerProcessState(transport).parentPid) : join;
|
|
2885
|
+
if (!target) throw new ProcessError(ProcessErrno.SRCH, "parent has no memory group");
|
|
2886
|
+
const directory = transport.directory;
|
|
2887
|
+
return groups.admit(pid, workerProcessDirectoryId(transport), target, headroom, () =>
|
|
2888
|
+
this.terminalGroupAdmission(directory),
|
|
2889
|
+
);
|
|
2890
|
+
}
|
|
2891
|
+
|
|
2892
|
+
private terminalGroupAdmission(directory: SharedArrayBuffer): boolean {
|
|
2893
|
+
const wake = new Int32Array(directory, 4, 1);
|
|
2894
|
+
const seen = Atomics.load(wake, 0);
|
|
2895
|
+
try {
|
|
2896
|
+
const version = directoryAdmissionVersion(directory);
|
|
2897
|
+
if (!this.groupIntentsSettled(directory)) {
|
|
2898
|
+
this.deferGroupAdmission(directory, wake, seen);
|
|
2899
|
+
return false;
|
|
2900
|
+
}
|
|
2901
|
+
commitDirectoryAdmission(directory, version);
|
|
2902
|
+
this.cancelGroupAdmissionWatch(directory);
|
|
2903
|
+
return true;
|
|
2904
|
+
} catch (error) {
|
|
2905
|
+
if (
|
|
2906
|
+
!(error instanceof ProcessError) ||
|
|
2907
|
+
(error.errno !== ProcessErrno.NOTSUP && !isCollectedProcess(error))
|
|
2908
|
+
)
|
|
2909
|
+
throw error;
|
|
2910
|
+
this.deferGroupAdmission(directory, wake, seen);
|
|
2911
|
+
return false;
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2914
|
+
|
|
2915
|
+
private groupIntentsSettled(directory: SharedArrayBuffer): boolean {
|
|
2916
|
+
const domain = atomicsLoad(new BigInt64ArrayConstructor(directory, 8, 1), 0);
|
|
2917
|
+
const domainWords = new Uint32Array(directory, 8, 2);
|
|
2918
|
+
const lifetimeDomain = `${domainWords[0]}:${domainWords[1]}`;
|
|
2919
|
+
const sameDirectory = (source: ProcessObservationTransfer) =>
|
|
2920
|
+
source.kind === "directory" &&
|
|
2921
|
+
atomicsLoad(new BigInt64ArrayConstructor(source.directory, 8, 1), 0) === domain;
|
|
2922
|
+
for (const launch of this.pendingLaunches?.values() ?? [])
|
|
2923
|
+
if (launch.acquiring && sameDirectory(launch.observation)) return false;
|
|
2924
|
+
for (const preparation of this.pendingPreparations)
|
|
2925
|
+
if (sameDirectory(preparation.observation)) return false;
|
|
2926
|
+
for (const state of directoryProcesses(directory)) {
|
|
2927
|
+
const key = `directory:${domain}:${state.slot}:${state.pid}`;
|
|
2928
|
+
const root = this.roots.get(state.pid);
|
|
2929
|
+
if (root && observationKey(root) === key) continue;
|
|
2930
|
+
const child = this.children.get(state.pid);
|
|
2931
|
+
if (child && observationKey(child.transport) === key && this.currentChild(child)) {
|
|
2932
|
+
if (child.launch.pending?.acquiring) return false;
|
|
2933
|
+
continue;
|
|
2934
|
+
}
|
|
2935
|
+
if (this.settledGroupAcquisitions.has(key)) continue;
|
|
2936
|
+
if (this.settledGroupRecord(state.pid, key)) continue;
|
|
2937
|
+
if (
|
|
2938
|
+
controlLoad(state.confirmed) &&
|
|
2939
|
+
this.acquiredProcesses.get(state.pid) !== `${lifetimeDomain}:${state.slot}:${state.pid}`
|
|
2940
|
+
)
|
|
2941
|
+
continue;
|
|
2942
|
+
return false;
|
|
2943
|
+
}
|
|
2944
|
+
return true;
|
|
2945
|
+
}
|
|
2946
|
+
|
|
2947
|
+
private settledGroupRecord(pid: number, key: string): boolean {
|
|
2948
|
+
const record = this.options.table.get(pid);
|
|
2949
|
+
if (!record || observationKey(record.observation) !== key) return false;
|
|
2950
|
+
// A selected outcome prevents the not-yet-invoked adapter from ever acquiring a member.
|
|
2951
|
+
return (
|
|
2952
|
+
record.image.execution?.kind === "host" ||
|
|
2953
|
+
(record.image.nativeAcquisition.kind === "not-invoked" && !!readOutcome(record.outcome))
|
|
2954
|
+
);
|
|
2955
|
+
}
|
|
2956
|
+
|
|
2957
|
+
private deferGroupAdmission(directory: SharedArrayBuffer, wake: Int32Array, seen: number): void {
|
|
2958
|
+
if (this.groupAdmissionWatches.has(directory)) return;
|
|
2959
|
+
this.groupAdmissionWatches.set(directory, wake);
|
|
2960
|
+
const waiting = atomicsWaitAsync(wake, 0, seen);
|
|
2961
|
+
void Promise.resolve(waiting.value)
|
|
2962
|
+
.then(() => {
|
|
2963
|
+
if (this.groupAdmissionWatches.get(directory) !== wake) return;
|
|
2964
|
+
this.groupAdmissionWatches.delete(directory);
|
|
2965
|
+
this.groups?.settleStopping();
|
|
2966
|
+
})
|
|
2967
|
+
.catch((error) => this.report(error));
|
|
2968
|
+
}
|
|
2969
|
+
private cancelGroupAdmissionWatch(directory: SharedArrayBuffer): void {
|
|
2970
|
+
const wake = this.groupAdmissionWatches.get(directory);
|
|
2971
|
+
if (!wake) return;
|
|
2972
|
+
this.groupAdmissionWatches.delete(directory);
|
|
2973
|
+
Atomics.notify(wake, 0);
|
|
2974
|
+
}
|
|
2975
|
+
private writeStartupDiagnostic(
|
|
2976
|
+
pid: number,
|
|
2977
|
+
error: unknown,
|
|
2978
|
+
active: () => boolean,
|
|
2979
|
+
): void | Promise<void> {
|
|
2980
|
+
const record = this.options.table.get(pid);
|
|
2981
|
+
if (record?.state === "starting") this.traceProcess(record, "rejected", "start-failed");
|
|
2982
|
+
// Host spawns can also have a bookkeeping parent. Only an admitted runtime_proc child
|
|
2983
|
+
// has a parent consuming START_FAILED; keep its full diagnostic on the host, not fd 2.
|
|
2984
|
+
const runtimeChild =
|
|
2985
|
+
record !== undefined && record.parentPid !== 0 && this.transport.get(pid) !== undefined;
|
|
2986
|
+
if (runtimeChild) this.report(error);
|
|
2987
|
+
const controller = this.controllerFor(pid);
|
|
2988
|
+
if (controller?.startFailed) return controller.startFailed(error, active);
|
|
2989
|
+
if (runtimeChild) return;
|
|
2990
|
+
const stderr =
|
|
2991
|
+
this.children.get(pid)?.startupStderr ?? record?.image.descriptors.get(2)?.resource;
|
|
2992
|
+
if (stderr?.kind !== "pipe" && stderr?.kind !== "terminal") return;
|
|
2993
|
+
const bytes = new TextEncoder().encode(`runtime: process start failed: ${String(error)}\n`);
|
|
2994
|
+
const write = stderr.tryWrite;
|
|
2995
|
+
if (!write)
|
|
2996
|
+
throw new ProcessError(
|
|
2997
|
+
ProcessErrno.NOTSUP,
|
|
2998
|
+
"startup diagnostic requires immediate stderr writes",
|
|
2999
|
+
);
|
|
3000
|
+
const pending = drainDiagnostic(
|
|
3001
|
+
bytes,
|
|
3002
|
+
(bytes) => write.call(stderr, [bytes]),
|
|
3003
|
+
() => active() && !this.suspended,
|
|
3004
|
+
);
|
|
3005
|
+
if (pending) {
|
|
3006
|
+
// Await only our cancellable drains during broker teardown, never an arbitrary adapter
|
|
3007
|
+
// promise. The supervisor explicitly retires custom sink ownership on disposal.
|
|
3008
|
+
this.startupDiagnostics.add(pending);
|
|
3009
|
+
void pending.finally(() => this.startupDiagnostics.delete(pending)).catch(() => {});
|
|
3010
|
+
}
|
|
3011
|
+
return pending;
|
|
3012
|
+
}
|
|
3013
|
+
private collectRuntimeProcess(pid: number, directory?: string): void {
|
|
3014
|
+
for (const [rootPid, transport] of this.roots) {
|
|
3015
|
+
if (directory !== undefined && workerProcessDirectoryId(transport) !== directory) continue;
|
|
3016
|
+
const root = this.options.table.get(pid)?.rootPid;
|
|
3017
|
+
if (root !== undefined && root !== rootPid) continue;
|
|
3018
|
+
this.registries.get(rootPid)?.collectProcess(pid);
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
private quiesceProcess(pid: number): void | Promise<void> {
|
|
3022
|
+
this.cancelPreparations(pid);
|
|
3023
|
+
const child = this.children.get(pid);
|
|
3024
|
+
if (child && !this.roots.has(pid) && !this.reservedRoots.has(pid)) {
|
|
3025
|
+
if (child.finalQuiet) return;
|
|
3026
|
+
const terminal = this.terminalLifetimes.get(pid)?.quiesce();
|
|
3027
|
+
return (child.finalFence ??= Promise.all([this.imageFence(child), terminal])
|
|
3028
|
+
.then(() => this.joinCommandExec(child.transport))
|
|
3029
|
+
.then(() => {
|
|
3030
|
+
this.collectRuntimeProcess(pid);
|
|
3031
|
+
child.finalQuiet = true;
|
|
3032
|
+
}));
|
|
3033
|
+
}
|
|
3034
|
+
const pending = this.fences.get(pid);
|
|
3035
|
+
if (pending) return pending;
|
|
3036
|
+
const controller = this.controllerFor(pid);
|
|
3037
|
+
// The supervisor drops settled fence promises before physical stop is scheduled.
|
|
3038
|
+
// Retain completion only while this process still owns its controller.
|
|
3039
|
+
if (controller && this.quiescedControllers.has(pid)) return;
|
|
3040
|
+
const complete = () => {
|
|
3041
|
+
this.collectRuntimeProcess(pid);
|
|
3042
|
+
if (controller) this.quiescedControllers.add(pid);
|
|
3043
|
+
};
|
|
3044
|
+
let fence: void | Promise<void>;
|
|
3045
|
+
try {
|
|
3046
|
+
fence = this.processFence(pid);
|
|
3047
|
+
} catch (error) {
|
|
3048
|
+
fence = Promise.reject(error);
|
|
3049
|
+
}
|
|
3050
|
+
if (fence) {
|
|
3051
|
+
const pending = Promise.resolve(fence).then(complete);
|
|
3052
|
+
this.fences.set(pid, pending);
|
|
3053
|
+
return pending;
|
|
3054
|
+
}
|
|
3055
|
+
complete();
|
|
3056
|
+
}
|
|
3057
|
+
private revokeController(pid: number): void {
|
|
3058
|
+
const controller = this.controllerFor(pid);
|
|
3059
|
+
const child = this.children.get(pid);
|
|
3060
|
+
if (child) {
|
|
3061
|
+
child.revokeController?.();
|
|
3062
|
+
return;
|
|
3063
|
+
}
|
|
3064
|
+
const captured = this.capturedControllerRevocations.get(pid);
|
|
3065
|
+
if (captured) {
|
|
3066
|
+
captured();
|
|
3067
|
+
return;
|
|
3068
|
+
}
|
|
3069
|
+
if (!controller || this.revokedControllers.has(pid)) return;
|
|
3070
|
+
this.revokedControllers.add(pid);
|
|
3071
|
+
if (controller.filesystem) this.options.filesystem.revoke(controller.filesystem);
|
|
3072
|
+
controller.revoke?.();
|
|
3073
|
+
}
|
|
3074
|
+
private processFence(pid: number): void | Promise<void> {
|
|
3075
|
+
const pending: Promise<void>[] = [];
|
|
3076
|
+
const preparation = Array.from(this.pendingPreparations).find((entry) => entry.pid === pid);
|
|
3077
|
+
if (preparation) pending.push(preparation.settled);
|
|
3078
|
+
const terminal = this.terminalLifetimes.get(pid)?.quiesce();
|
|
3079
|
+
if (terminal) pending.push(terminal);
|
|
3080
|
+
// Lazy/external roots may have no supervisor record to invoke their revocation hook.
|
|
3081
|
+
this.revokeController(pid);
|
|
3082
|
+
const controller = this.controllerFor(pid);
|
|
3083
|
+
const threaded = this.children.get(pid);
|
|
3084
|
+
if (threaded?.threads) {
|
|
3085
|
+
const adapterFence = controller?.quiesce?.();
|
|
3086
|
+
if (adapterFence) pending.push(adapterFence);
|
|
3087
|
+
pending.push(
|
|
3088
|
+
threaded.threads.then((owner) => (owner ? owner.fence() : this.quiesceChild(threaded))),
|
|
3089
|
+
);
|
|
3090
|
+
if (controller?.filesystem && controller.filesystem.sections !== threaded.filesystem.sections)
|
|
3091
|
+
pending.push(this.options.filesystem.quiesce(controller.filesystem));
|
|
3092
|
+
return Promise.all(pending).then(() => {});
|
|
3093
|
+
}
|
|
3094
|
+
const adapter = controller?.quiesce?.();
|
|
3095
|
+
if (adapter) pending.push(adapter);
|
|
3096
|
+
if (controller?.filesystem && !controller.acknowledged?.())
|
|
3097
|
+
pending.push(this.options.filesystem.quiesce(controller.filesystem));
|
|
3098
|
+
const child = this.children.get(pid);
|
|
3099
|
+
if (child) {
|
|
3100
|
+
const filesystem = this.quiesceChild(child);
|
|
3101
|
+
if (filesystem) pending.push(filesystem);
|
|
3102
|
+
} else {
|
|
3103
|
+
const transport = this.transport.get(pid);
|
|
3104
|
+
if (transport) {
|
|
3105
|
+
const filesystem = this.filesystem(transport);
|
|
3106
|
+
// An adapter acknowledgement covers only its own identity, not another transport.
|
|
3107
|
+
if (!controller?.filesystem || filesystem.sections !== controller.filesystem.sections) {
|
|
3108
|
+
pending.push(this.options.filesystem.quiesce(filesystem));
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
const transport = this.transport.get(pid);
|
|
3113
|
+
if (transport && this.commandScope(transport))
|
|
3114
|
+
return Promise.all(pending).then(() => this.joinCommandExec(transport));
|
|
3115
|
+
if (pending.length) return Promise.all(pending).then(() => {});
|
|
3116
|
+
}
|
|
3117
|
+
private quiesceChild(child: RuntimeChild): void | Promise<void> {
|
|
3118
|
+
if (child.acknowledged && !child.replacementAcknowledged) return;
|
|
3119
|
+
return (child.quiescence ??= this.options.filesystem.quiesce(child.filesystem));
|
|
3120
|
+
}
|
|
3121
|
+
private disposeNetwork(child: RuntimeChild): void {
|
|
3122
|
+
try {
|
|
3123
|
+
child.graphics?.dispose();
|
|
3124
|
+
} catch (error) {
|
|
3125
|
+
this.report(error);
|
|
3126
|
+
}
|
|
3127
|
+
const network = child.network;
|
|
3128
|
+
child.network = undefined;
|
|
3129
|
+
try {
|
|
3130
|
+
network?.dispose();
|
|
3131
|
+
} catch (error) {
|
|
3132
|
+
this.report(error);
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
private disposeNotifications(child: RuntimeChild | undefined): void {
|
|
3136
|
+
void child?.notifications?.dispose().catch((error) => this.report(error));
|
|
3137
|
+
}
|
|
3138
|
+
private async stopUnstartedThread(child: RuntimeChild): Promise<void> {
|
|
3139
|
+
await this.quiesceChild(child);
|
|
3140
|
+
child.nativeReturned?.();
|
|
3141
|
+
}
|
|
3142
|
+
private async stopNotifications(child: RuntimeChild, errors: unknown[]): Promise<boolean> {
|
|
3143
|
+
try {
|
|
3144
|
+
await child.notifications?.dispose();
|
|
3145
|
+
return true;
|
|
3146
|
+
} catch (error) {
|
|
3147
|
+
errors.push(error);
|
|
3148
|
+
return false;
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
private launchState(context: object): RuntimeLaunch {
|
|
3152
|
+
let launch = this.launchStates.get(context);
|
|
3153
|
+
if (!launch) {
|
|
3154
|
+
launch = { active: false };
|
|
3155
|
+
this.launchStates.set(context, launch);
|
|
3156
|
+
}
|
|
3157
|
+
return launch;
|
|
3158
|
+
}
|
|
3159
|
+
private imageLaunches(): RuntimeLaunch[] {
|
|
3160
|
+
return Array.from(this.children.values(), (child) => child.launch);
|
|
3161
|
+
}
|
|
3162
|
+
private controllerFor(pid: number): ProcessController | undefined {
|
|
3163
|
+
return this.children.get(pid)?.controller ?? this.controllers.get(pid);
|
|
3164
|
+
}
|
|
3165
|
+
private capturedControllerStopFor(pid: number): (() => void | Promise<void>) | undefined {
|
|
3166
|
+
return this.children.get(pid)?.capturedControllerStop ?? this.capturedControllerStops.get(pid);
|
|
3167
|
+
}
|
|
3168
|
+
private controllerNativeStopFor(pid: number): NativeStopHandle | undefined {
|
|
3169
|
+
return this.children.get(pid)?.controllerNativeStop ?? this.controllerNativeStops.get(pid);
|
|
3170
|
+
}
|
|
3171
|
+
private controllerNativeReturnFor(pid: number): NativeReturnFollowers | undefined {
|
|
3172
|
+
return this.children.get(pid)?.controllerNativeReturn ?? this.controllerNativeReturns.get(pid);
|
|
3173
|
+
}
|
|
3174
|
+
private captureImageState(child: RuntimeChild): void {
|
|
3175
|
+
const pid = child.context.pid;
|
|
3176
|
+
if (this.roots.has(pid) || this.reservedRoots.has(pid)) return;
|
|
3177
|
+
child.controller = this.controllers.get(pid);
|
|
3178
|
+
child.controllerQuiet = this.quiescedControllers.has(pid);
|
|
3179
|
+
this.quiescedControllers.delete(pid);
|
|
3180
|
+
this.revokedControllers.delete(pid);
|
|
3181
|
+
child.revokeController = this.capturedControllerRevocations.get(pid);
|
|
3182
|
+
this.capturedControllerRevocations.delete(pid);
|
|
3183
|
+
child.capturedControllerStop = this.capturedControllerStops.get(pid);
|
|
3184
|
+
child.controllerNativeStop = this.controllerNativeStops.get(pid);
|
|
3185
|
+
child.controllerNativeReturn = this.controllerNativeReturns.get(pid);
|
|
3186
|
+
child.fence = this.fences.get(pid);
|
|
3187
|
+
child.controllerStopping = this.controllerStops?.get(pid);
|
|
3188
|
+
this.controllerStops?.delete(pid);
|
|
3189
|
+
this.launches?.delete(pid);
|
|
3190
|
+
this.pendingLaunches?.delete(pid);
|
|
3191
|
+
child.accesses = new WorkerExecutableAccess({
|
|
3192
|
+
active: () =>
|
|
3193
|
+
this.currentChild(child) &&
|
|
3194
|
+
!this.suspended &&
|
|
3195
|
+
!isRevoked(child.filesystem) &&
|
|
3196
|
+
this.options.table.get(pid)?.image.phase === "current",
|
|
3197
|
+
check: async (_sender, path, cwd, active) => {
|
|
3198
|
+
await this.options.registry.check(path, cwd, active);
|
|
3199
|
+
return 0;
|
|
3200
|
+
},
|
|
3201
|
+
});
|
|
3202
|
+
this.controllers.delete(pid);
|
|
3203
|
+
this.capturedControllerStops.delete(pid);
|
|
3204
|
+
this.controllerNativeStops.delete(pid);
|
|
3205
|
+
this.controllerNativeReturns.delete(pid);
|
|
3206
|
+
this.fences.delete(pid);
|
|
3207
|
+
}
|
|
3208
|
+
private controllerRevocation(controller: ProcessController): () => void {
|
|
3209
|
+
let revoked = false;
|
|
3210
|
+
return () => {
|
|
3211
|
+
if (revoked) return;
|
|
3212
|
+
revoked = true;
|
|
3213
|
+
if (controller.filesystem) this.options.filesystem.revoke(controller.filesystem);
|
|
3214
|
+
controller.revoke?.();
|
|
3215
|
+
};
|
|
3216
|
+
}
|
|
3217
|
+
private currentChild(child: RuntimeChild): boolean {
|
|
3218
|
+
const image = this.options.table.get(child.context.pid)?.image;
|
|
3219
|
+
return (
|
|
3220
|
+
this.children.get(child.context.pid) === child &&
|
|
3221
|
+
image?.generation === child.generation &&
|
|
3222
|
+
(image.phase === "current" || image.phase === "retiring")
|
|
3223
|
+
);
|
|
3224
|
+
}
|
|
3225
|
+
private canExec(transport: WorkerProcessTransport): boolean {
|
|
3226
|
+
const child = this.children.get(transport.pid);
|
|
3227
|
+
return (
|
|
3228
|
+
!!child?.worker &&
|
|
3229
|
+
this.options.table.get(transport.pid)?.processKind === "process" &&
|
|
3230
|
+
this.currentChild(child) &&
|
|
3231
|
+
!child.threads &&
|
|
3232
|
+
!child.stopped &&
|
|
3233
|
+
!child.stopping &&
|
|
3234
|
+
!child.failed &&
|
|
3235
|
+
!this.roots.has(transport.pid) &&
|
|
3236
|
+
!this.reservedRoots.has(transport.pid) &&
|
|
3237
|
+
!this.rootAdmissions.has(transport.pid) &&
|
|
3238
|
+
this.options.table.get(transport.pid)?.image.phase === "current" &&
|
|
3239
|
+
child.generation === transport.generation &&
|
|
3240
|
+
!this.options.table.get(transport.pid)?.image.request?.worker &&
|
|
3241
|
+
workerProcessDirectoryId(child.transport) === workerProcessDirectoryId(transport)
|
|
3242
|
+
);
|
|
3243
|
+
}
|
|
3244
|
+
private checkGuestImage(pid: number, generation?: number): void {
|
|
3245
|
+
const image = this.options.table.get(pid)?.image;
|
|
3246
|
+
if (image?.execution?.kind === "host")
|
|
3247
|
+
throw new ProcessError(
|
|
3248
|
+
ProcessErrno.NOTSUP,
|
|
3249
|
+
"host-only image cannot acquire a guest consumer",
|
|
3250
|
+
);
|
|
3251
|
+
if (generation !== undefined && image?.generation !== generation)
|
|
3252
|
+
throw new ProcessError(ProcessErrno.SRCH, "guest consumer image is no longer current");
|
|
3253
|
+
}
|
|
3254
|
+
private commitReplacement(
|
|
3255
|
+
pid: number,
|
|
3256
|
+
generation: number,
|
|
3257
|
+
resolved: ResolvedExecutable,
|
|
3258
|
+
): { rollback(): void } | undefined {
|
|
3259
|
+
const child = this.children.get(pid);
|
|
3260
|
+
if (!child || child.generation !== generation || !this.canExec(child.transport))
|
|
3261
|
+
throw new ProcessError(ProcessErrno.NOTSUP, "replacement lost its owned source image");
|
|
3262
|
+
const image = this.options.table.require(pid).image;
|
|
3263
|
+
const admission = workerProcessState(child.transport).imageAdmission;
|
|
3264
|
+
if (controlCas(admission, 0, generation, -generation) !== generation)
|
|
3265
|
+
throw new ProcessError(ProcessErrno.NOTSUP, "replacement source image admission is closed");
|
|
3266
|
+
const current = () => this.options.table.get(pid)?.image === image && image.phase === "current";
|
|
3267
|
+
let membership: { rollback(): void } | undefined;
|
|
3268
|
+
const rollback = () => {
|
|
3269
|
+
if (!current()) return;
|
|
3270
|
+
membership?.rollback();
|
|
3271
|
+
controlCas(admission, 0, -generation, generation);
|
|
3272
|
+
if (!readOutcome(child.context.outcome)) child.replacing = false;
|
|
3273
|
+
};
|
|
3274
|
+
try {
|
|
3275
|
+
membership = this.closeReplacementGroup(child, resolved);
|
|
3276
|
+
} catch (error) {
|
|
3277
|
+
rollback();
|
|
3278
|
+
throw error;
|
|
3279
|
+
}
|
|
3280
|
+
child.replacing = true;
|
|
3281
|
+
return { rollback };
|
|
3282
|
+
}
|
|
3283
|
+
private closeReplacementGroup(
|
|
3284
|
+
child: RuntimeChild,
|
|
3285
|
+
resolved: ResolvedExecutable,
|
|
3286
|
+
): { rollback(): void } | undefined {
|
|
3287
|
+
if (!child.group) return;
|
|
3288
|
+
if (resolved.kind !== "module" || resolved.execution?.kind !== "host")
|
|
3289
|
+
throw new ProcessError(
|
|
3290
|
+
ProcessErrno.NOTSUP,
|
|
3291
|
+
"shared caller requires a bound host-only target",
|
|
3292
|
+
);
|
|
3293
|
+
const directory = child.transport.directory;
|
|
3294
|
+
const version = directoryAdmissionVersion(directory);
|
|
3295
|
+
this.checkGroupIntents(child);
|
|
3296
|
+
commitDirectoryAdmission(directory, version);
|
|
3297
|
+
return child.group.closeAdmission();
|
|
3298
|
+
}
|
|
3299
|
+
private checkGroupIntents(source: RuntimeChild): void {
|
|
3300
|
+
const directory = source.identity.directory;
|
|
3301
|
+
for (const state of directoryProcesses(source.transport.directory)) {
|
|
3302
|
+
if (state.pid === source.context.pid) continue;
|
|
3303
|
+
if (this.pendingLaunches?.has(state.pid))
|
|
3304
|
+
throw new ProcessError(
|
|
3305
|
+
ProcessErrno.NOTSUP,
|
|
3306
|
+
"same-directory adapter acquisition is unresolved",
|
|
3307
|
+
);
|
|
3308
|
+
if (this.roots.has(state.pid)) continue;
|
|
3309
|
+
const child = this.children.get(state.pid);
|
|
3310
|
+
if (child?.launch.pending)
|
|
3311
|
+
throw new ProcessError(
|
|
3312
|
+
ProcessErrno.NOTSUP,
|
|
3313
|
+
"same-directory adapter acquisition is unresolved",
|
|
3314
|
+
);
|
|
3315
|
+
if (child && this.currentChild(child) && !child.failed) continue;
|
|
3316
|
+
const image = this.options.table.get(state.pid)?.image;
|
|
3317
|
+
if (image?.execution?.kind === "host") continue;
|
|
3318
|
+
if (controlLoad(state.confirmed) && !this.acquiredProcesses.has(state.pid)) continue;
|
|
3319
|
+
throw new ProcessError(ProcessErrno.NOTSUP, "same-directory group intent is unresolved");
|
|
3320
|
+
}
|
|
3321
|
+
for (const preparation of this.pendingPreparations) {
|
|
3322
|
+
if (preparation.pid === source.context.pid) continue;
|
|
3323
|
+
const root = this.roots.get(preparation.rootPid);
|
|
3324
|
+
if (root && workerProcessDirectoryId(root) === directory)
|
|
3325
|
+
throw new ProcessError(ProcessErrno.NOTSUP, "same-directory preparation is unresolved");
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3328
|
+
private reportReplacementFailure(pid: number, error: unknown): void {
|
|
3329
|
+
const image = this.options.table.get(pid)?.image;
|
|
3330
|
+
if (image && this.replacementDiagnostics.has(image)) return;
|
|
3331
|
+
if (image) this.replacementDiagnostics.add(image);
|
|
3332
|
+
this.report(error);
|
|
3333
|
+
}
|
|
3334
|
+
private imageFence(child: RuntimeChild): Promise<void> {
|
|
3335
|
+
if (child.fence) return child.fence;
|
|
3336
|
+
const controller = child.controller;
|
|
3337
|
+
child.revokeController?.();
|
|
3338
|
+
const pending: (void | Promise<void>)[] = [
|
|
3339
|
+
child.controllerQuiet ? undefined : controller?.quiesce?.(),
|
|
3340
|
+
];
|
|
3341
|
+
pending.push(
|
|
3342
|
+
child.threads
|
|
3343
|
+
? child.threads.then((owner) => (owner ? owner.fence() : this.quiesceChild(child)))
|
|
3344
|
+
: this.quiesceChild(child),
|
|
3345
|
+
);
|
|
3346
|
+
if (controller?.filesystem && controller.filesystem.sections !== child.filesystem.sections)
|
|
3347
|
+
pending.push(this.options.filesystem.quiesce(controller.filesystem));
|
|
3348
|
+
return (child.fence = Promise.all(pending).then(() => {
|
|
3349
|
+
child.controllerQuiet = true;
|
|
3350
|
+
}));
|
|
3351
|
+
}
|
|
3352
|
+
private async stopImage(pid: number, generation: number, active: () => boolean): Promise<void> {
|
|
3353
|
+
const child = this.children.get(pid);
|
|
3354
|
+
if (!child || child.generation !== generation)
|
|
3355
|
+
throw new Error("replacement lost its image owner");
|
|
3356
|
+
await this.stopPhysical(child, true);
|
|
3357
|
+
if (!active()) return;
|
|
3358
|
+
const terminal = this.terminalLifetimes.get(pid);
|
|
3359
|
+
if (terminal && !(await terminal.handoff(active)) && active())
|
|
3360
|
+
throw new ProcessError(
|
|
3361
|
+
ProcessErrno.CANCELED,
|
|
3362
|
+
"terminal image handoff is permanently revoked",
|
|
3363
|
+
);
|
|
3364
|
+
}
|
|
3365
|
+
private async finalizeProcess(pid: number): Promise<void> {
|
|
3366
|
+
const stopped = this.imageStops.get(pid);
|
|
3367
|
+
if (!stopped) return;
|
|
3368
|
+
await stopped;
|
|
3369
|
+
const returned = this.nativeLaunchReturns.get(pid);
|
|
3370
|
+
this.nativeLaunchReturns.delete(pid);
|
|
3371
|
+
returned?.();
|
|
3372
|
+
this.observationOwners.get(pid)?.close();
|
|
3373
|
+
this.terminalLifetimes.get(pid)?.stopped();
|
|
3374
|
+
this.collectRuntimeProcess(pid);
|
|
3375
|
+
this.revokeRuntimeProcess(pid);
|
|
3376
|
+
this.imageStops.delete(pid);
|
|
3377
|
+
this.releaseAcquiredProcess(pid);
|
|
3378
|
+
}
|
|
3379
|
+
private stop(child: RuntimeChild): Promise<void> {
|
|
3380
|
+
this.observationOwners.get(child.context.pid)?.close();
|
|
3381
|
+
return Promise.resolve(this.stopPhysical(child)).then(() =>
|
|
3382
|
+
this.finalizeProcess(child.context.pid),
|
|
3383
|
+
);
|
|
3384
|
+
}
|
|
3385
|
+
private stopWorker(child: RuntimeChild): Promise<void> {
|
|
3386
|
+
return child.replacing ? this.stopNativeResources(child) : this.stop(child);
|
|
3387
|
+
}
|
|
3388
|
+
private stopPhysical(child: RuntimeChild, replacing = false): void | Promise<void> {
|
|
3389
|
+
if (child.stopping) return child.stopping;
|
|
3390
|
+
child.accesses?.dispose();
|
|
3391
|
+
if (child.threads) {
|
|
3392
|
+
child.stopping = child.threads
|
|
3393
|
+
.then((owner) => (owner ? owner.stop() : this.stopUnstartedThread(child)))
|
|
3394
|
+
.then(() => {
|
|
3395
|
+
child.stopped = true;
|
|
3396
|
+
if (this.children.get(child.context.pid) === child)
|
|
3397
|
+
this.children.delete(child.context.pid);
|
|
3398
|
+
this.retireChildController(child.context.pid, child);
|
|
3399
|
+
});
|
|
3400
|
+
this.imageStops.set(child.context.pid, child.stopping);
|
|
3401
|
+
return child.stopping;
|
|
3402
|
+
}
|
|
3403
|
+
const stop = async () => {
|
|
3404
|
+
const errors: unknown[] = [];
|
|
3405
|
+
if (child.replacing) await settleStop(() => this.stopAcceptedAdapter(child), errors);
|
|
3406
|
+
await settleStop(() => this.stopNativeResources(child), errors);
|
|
3407
|
+
if (errors.length) {
|
|
3408
|
+
// Cleanup after a failed terminate proves nothing: keep group memory and capacity.
|
|
3409
|
+
child.group?.failed();
|
|
3410
|
+
child.launched?.failed(errors);
|
|
3411
|
+
throw new AggregateError(errors, "Child physical stop failed");
|
|
3412
|
+
}
|
|
3413
|
+
// The launch revocation backing stays strongly owned through physical guest stop.
|
|
3414
|
+
child.graphics = undefined;
|
|
3415
|
+
child.controllerNativeStop?.imageReturned();
|
|
3416
|
+
if (child.replacementAcknowledged) this.options.filesystem.reap(child.filesystem);
|
|
3417
|
+
child.group?.stopped();
|
|
3418
|
+
child.launched?.stopped();
|
|
3419
|
+
if (this.children.get(child.context.pid) === child) this.children.delete(child.context.pid);
|
|
3420
|
+
// Its accepted bytes stay with the root; its unused credit returns to other writers.
|
|
3421
|
+
child.output?.retire();
|
|
3422
|
+
this.serviceTerminalOutput(child.identity.rootPid);
|
|
3423
|
+
this.retireChildController(child.context.pid, child);
|
|
3424
|
+
child.adapter = undefined;
|
|
3425
|
+
};
|
|
3426
|
+
// Select SIGKILL before the quiesce fence revokes the filesystem: a guest that notices the
|
|
3427
|
+
// revocation first would otherwise exit 1 instead of reporting the stop's SIGKILL (137).
|
|
3428
|
+
// No change once an outcome is settled; exec replacement must not end the process.
|
|
3429
|
+
if (!replacing && !child.replacing) this.signalStop(child.context.pid);
|
|
3430
|
+
const fence = replacing ? this.imageFence(child) : this.quiesceProcess(child.context.pid);
|
|
3431
|
+
child.stopping = (fence ? fence.then(stop) : stop()).catch((error) => {
|
|
3432
|
+
this.observationOwners.get(child.context.pid)?.fail(error);
|
|
3433
|
+
child.group?.failed();
|
|
3434
|
+
child.launched?.failed([error]);
|
|
3435
|
+
throw error;
|
|
3436
|
+
});
|
|
3437
|
+
this.imageStops.set(child.context.pid, child.stopping);
|
|
3438
|
+
return child.stopping;
|
|
3439
|
+
}
|
|
3440
|
+
private async stopAcceptedAdapter(child: RuntimeChild): Promise<void> {
|
|
3441
|
+
await child.launch.pending?.acquired;
|
|
3442
|
+
if (!child.adapter)
|
|
3443
|
+
throw new Error("replacement source has no accepted adapter cleanup handle");
|
|
3444
|
+
await child.adapter.terminate();
|
|
3445
|
+
}
|
|
3446
|
+
private stopNativeResources(child: RuntimeChild): Promise<void> {
|
|
3447
|
+
if (child.nativeStopping) return child.nativeStopping;
|
|
3448
|
+
const stopped = Promise.withResolvers<void>();
|
|
3449
|
+
child.nativeStopping = stopped.promise;
|
|
3450
|
+
void this.stopNativeResourcesNow(child).then(stopped.resolve, stopped.reject);
|
|
3451
|
+
return stopped.promise;
|
|
3452
|
+
}
|
|
3453
|
+
private async stopNativeResourcesNow(child: RuntimeChild): Promise<void> {
|
|
3454
|
+
if (child.replacing) await this.imageFence(child);
|
|
3455
|
+
if (child.stopped) return;
|
|
3456
|
+
child.stopped = true;
|
|
3457
|
+
const errors: unknown[] = [];
|
|
3458
|
+
this.disposeNetwork(child);
|
|
3459
|
+
if (child.graphics) await settleStop(() => child.graphics!.retired(), errors);
|
|
3460
|
+
if (child.notifications) await this.stopNotifications(child, errors);
|
|
3461
|
+
await settleStop(() => this.terminateWorker(child), errors);
|
|
3462
|
+
await settleStop(
|
|
3463
|
+
() => child.controllerStopping?.pending ?? child.capturedControllerStop?.(),
|
|
3464
|
+
errors,
|
|
3465
|
+
);
|
|
3466
|
+
await settleStop(() => child.cleanup?.(), errors);
|
|
3467
|
+
if (errors.length) throw new AggregateError(errors, "Child native resource stop failed");
|
|
3468
|
+
}
|
|
3469
|
+
private async terminateWorker(child: RuntimeChild): Promise<void> {
|
|
3470
|
+
const worker = child.worker;
|
|
3471
|
+
if (!worker) return;
|
|
3472
|
+
let ended: void | Promise<void>;
|
|
3473
|
+
// terminate() never stops a busy Wasm thread on iOS Safari and takes about 2 s on Chromium,
|
|
3474
|
+
// and on WebKit it can crash the page when it lands while the guest is still calling host
|
|
3475
|
+
// imports in a loop. Select SIGKILL first (no change once an outcome is settled) so a guest
|
|
3476
|
+
// polling runtime_proc.signal(0, 4) or its fatal checkpoint unwinds, then give it a bounded
|
|
3477
|
+
// time to report that it finished, so terminate() lands on an idle worker; a group owner
|
|
3478
|
+
// can then reuse its pages (docs/host-abi.md, "Stop polling"). Exec replacement stops an
|
|
3479
|
+
// old image inside its exec call and must not end the process.
|
|
3480
|
+
if (!child.replacing) {
|
|
3481
|
+
this.signalStop(child.context.pid);
|
|
3482
|
+
// Await only a real wait: without one, terminate() stays in this synchronous step.
|
|
3483
|
+
const unwinding = guestUnwound(child);
|
|
3484
|
+
if (unwinding) await unwinding;
|
|
3485
|
+
}
|
|
3486
|
+
try {
|
|
3487
|
+
ended = worker.terminate();
|
|
3488
|
+
} finally {
|
|
3489
|
+
child.group?.stopRequested();
|
|
3490
|
+
}
|
|
3491
|
+
await ended;
|
|
3492
|
+
worker.onmessage = null;
|
|
3493
|
+
worker.onerror = null;
|
|
3494
|
+
child.worker = undefined;
|
|
3495
|
+
}
|
|
3496
|
+
private retireChildController(pid: number, child?: RuntimeChild): void {
|
|
3497
|
+
if (this.reservedRoots.has(pid) || this.roots.has(pid) || (!child && this.suspended)) return;
|
|
3498
|
+
const controller = child?.controller ?? this.controllers.get(pid);
|
|
3499
|
+
if (!child) {
|
|
3500
|
+
this.controllers.delete(pid);
|
|
3501
|
+
this.capturedControllerRevocations.delete(pid);
|
|
3502
|
+
}
|
|
3503
|
+
this.quiescedControllers.delete(pid);
|
|
3504
|
+
this.revokedControllers.delete(pid);
|
|
3505
|
+
if (!child) this.fences.delete(pid);
|
|
3506
|
+
this.releaseAcquiredProcess(pid);
|
|
3507
|
+
try {
|
|
3508
|
+
controller?.retired?.();
|
|
3509
|
+
} catch (error) {
|
|
3510
|
+
this.report(error);
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
private stopController(pid: number): Promise<void> | undefined {
|
|
3514
|
+
if (this.suspended || this.reservedRoots.has(pid)) return;
|
|
3515
|
+
const pending = this.controllerStops?.get(pid);
|
|
3516
|
+
if (pending) return pending.pending;
|
|
3517
|
+
const controller = this.controllerFor(pid);
|
|
3518
|
+
if (!controller) return;
|
|
3519
|
+
const nativeStop = this.controllerNativeStopFor(pid);
|
|
3520
|
+
const capturedStop = nativeStop?.terminate ?? this.capturedControllerStopFor(pid);
|
|
3521
|
+
const terminal = capturedStop ? this.terminalLifetimes.get(pid) : undefined;
|
|
3522
|
+
const group = nativeStop?.membership();
|
|
3523
|
+
const stopping = Promise.resolve(this.quiesceProcess(pid))
|
|
3524
|
+
.then(() => capturedStop?.())
|
|
3525
|
+
.then(() => {
|
|
3526
|
+
terminal?.stopped();
|
|
3527
|
+
if (group) this.settleRootGroup(pid, group);
|
|
3528
|
+
this.controllerStops?.delete(pid);
|
|
3529
|
+
this.retireChildController(pid);
|
|
3530
|
+
});
|
|
3531
|
+
(this.controllerStops ??= new Map()).set(pid, { pending: stopping, controllerStop: true });
|
|
3532
|
+
return stopping;
|
|
3533
|
+
}
|
|
3534
|
+
private async retireProcess(pid: number, rejectedTransferFenced = false): Promise<void> {
|
|
3535
|
+
await (this.children.get(pid)?.launch.pending ?? this.pendingLaunches?.get(pid))?.acquired;
|
|
3536
|
+
this.observationOwners.get(pid)?.close();
|
|
3537
|
+
// A rejected transfer never entered a guest adapter. Its own fence is already
|
|
3538
|
+
// complete, and shutdown waits for that rejection before it opens the global stop gate.
|
|
3539
|
+
if (this.suspended && !rejectedTransferFenced) {
|
|
3540
|
+
await this.retirementGate.promise;
|
|
3541
|
+
return;
|
|
3542
|
+
}
|
|
3543
|
+
const owner = this.observationOwners.get(pid);
|
|
3544
|
+
const child = this.children.get(pid);
|
|
3545
|
+
if (child) await this.stop(child);
|
|
3546
|
+
else {
|
|
3547
|
+
await this.stopController(pid);
|
|
3548
|
+
await this.finalizeProcess(pid);
|
|
3549
|
+
}
|
|
3550
|
+
await owner?.join();
|
|
3551
|
+
}
|
|
3552
|
+
private stopSafely(child: RuntimeChild): void {
|
|
3553
|
+
try {
|
|
3554
|
+
const pending = this.stop(child);
|
|
3555
|
+
if (pending) void pending.catch((error) => this.report(error));
|
|
3556
|
+
} catch (error) {
|
|
3557
|
+
this.report(error);
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
private states() {
|
|
3561
|
+
return Array.from(this.roots.values()).flatMap((root) =>
|
|
3562
|
+
Array.from(directoryProcesses(root.directory)),
|
|
3563
|
+
);
|
|
3564
|
+
}
|
|
3565
|
+
async kill(pid: number, signal: number): Promise<void> {
|
|
3566
|
+
const sig = checkedSignal(signal);
|
|
3567
|
+
const found = this.publishProcessSignal(pid, sig);
|
|
3568
|
+
const supervisor = await this.ready();
|
|
3569
|
+
if (this.suspended) return;
|
|
3570
|
+
if (supervisor.get(pid)) supervisor.observeSignal(pid, sig);
|
|
3571
|
+
else if (!found) supervisor.kill(pid, sig);
|
|
3572
|
+
}
|
|
3573
|
+
private publishProcessSignal(pid: number, signal: number, captured?: ProcessRecord): boolean {
|
|
3574
|
+
const target =
|
|
3575
|
+
captured ??
|
|
3576
|
+
this.states().find((state) => state.pid === pid)?.signals ??
|
|
3577
|
+
this.options.table.get(pid) ??
|
|
3578
|
+
this.reservedRoots.get(pid);
|
|
3579
|
+
if (!target) return false;
|
|
3580
|
+
requestSignal(target, signal);
|
|
3581
|
+
if (readOutcome(target.outcome)?.kind === "signaled") this.revokeRuntimeProcess(pid);
|
|
3582
|
+
this.wake();
|
|
3583
|
+
if (captured && this.supervisor?.get(pid) === captured)
|
|
3584
|
+
this.supervisor.observeSignal(pid, signal);
|
|
3585
|
+
return true;
|
|
3586
|
+
}
|
|
3587
|
+
/**
|
|
3588
|
+
* A physical stop's SIGKILL is a courtesy to a polling guest: if publishing it throws, the
|
|
3589
|
+
* stop reports that and goes on, so the worker is still fenced and terminated.
|
|
3590
|
+
*/
|
|
3591
|
+
private signalStop(pid: number): void {
|
|
3592
|
+
try {
|
|
3593
|
+
this.publishStopSignal(pid);
|
|
3594
|
+
} catch (error) {
|
|
3595
|
+
this.report(error);
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
/** Publication only, as at disposal: no revocation, supervisor callback or wake. */
|
|
3599
|
+
private publishStopSignal(pid: number): void {
|
|
3600
|
+
const target =
|
|
3601
|
+
this.states().find((state) => state.pid === pid)?.signals ??
|
|
3602
|
+
this.options.table.get(pid) ??
|
|
3603
|
+
this.reservedRoots.get(pid);
|
|
3604
|
+
if (target) this.requestSignalIfPresent(target, 9);
|
|
3605
|
+
}
|
|
3606
|
+
private requestSignalIfPresent(target: SignalTransport, signal: number): void {
|
|
3607
|
+
try {
|
|
3608
|
+
requestSignal(target, signal);
|
|
3609
|
+
} catch (error) {
|
|
3610
|
+
// Captured members can be collected after enumeration. Their vanished authority
|
|
3611
|
+
// must not prevent signalling/fencing the remaining consumers of a job or runtime.
|
|
3612
|
+
if (!isCollectedProcess(error)) throw error;
|
|
3613
|
+
}
|
|
3614
|
+
}
|
|
3615
|
+
async killJob(
|
|
3616
|
+
job: number,
|
|
3617
|
+
signal: number,
|
|
3618
|
+
reserved: readonly { pid: number; signals: SignalTransport }[] = [],
|
|
3619
|
+
): Promise<void> {
|
|
3620
|
+
const sig = checkedSignal(signal),
|
|
3621
|
+
states = this.states().filter((state) => state.job === job);
|
|
3622
|
+
const seen = new Set(states.map((state) => state.pid));
|
|
3623
|
+
const records = Array.from(this.options.table.values()).filter(
|
|
3624
|
+
(record) => record.job === job && !seen.has(record.pid),
|
|
3625
|
+
);
|
|
3626
|
+
// Generic reservations and admitted legacy processes select all terminal winners before
|
|
3627
|
+
// any callback can revoke capabilities. Observation never publishes the signal twice.
|
|
3628
|
+
for (const state of states) this.requestSignalIfPresent(state.signals, sig);
|
|
3629
|
+
for (const record of records) this.requestSignalIfPresent(record, sig);
|
|
3630
|
+
const published = new Set(
|
|
3631
|
+
states.map((state) => state.pid).concat(records.map((record) => record.pid)),
|
|
3632
|
+
);
|
|
3633
|
+
const roots = Array.from(this.reservedRoots.values()).filter(
|
|
3634
|
+
(root) => root.job === job && !published.has(root.pid),
|
|
3635
|
+
);
|
|
3636
|
+
const reservations = roots
|
|
3637
|
+
.map<{ pid: number; signals: SignalTransport }>((root) => ({ pid: root.pid, signals: root }))
|
|
3638
|
+
.concat(reserved);
|
|
3639
|
+
for (const target of reservations)
|
|
3640
|
+
if (!published.has(target.pid)) {
|
|
3641
|
+
this.requestSignalIfPresent(target.signals, sig);
|
|
3642
|
+
published.add(target.pid);
|
|
3643
|
+
}
|
|
3644
|
+
// Directory reservations can own pipe endpoints before a spawn message reaches the
|
|
3645
|
+
// supervisor. Freeze those rows too, after every member has selected its outcome.
|
|
3646
|
+
for (const state of states) {
|
|
3647
|
+
try {
|
|
3648
|
+
if (readOutcome(state.signals.outcome)?.kind === "signaled")
|
|
3649
|
+
this.revokeRuntimeProcess(state.pid);
|
|
3650
|
+
} catch (error) {
|
|
3651
|
+
if (!isCollectedProcess(error)) throw error;
|
|
3652
|
+
}
|
|
3653
|
+
}
|
|
3654
|
+
this.wake();
|
|
3655
|
+
const supervisor = await this.ready();
|
|
3656
|
+
if (this.suspended) return;
|
|
3657
|
+
for (const pid of published) if (supervisor.get(pid)) supervisor.observeSignal(pid, sig);
|
|
3658
|
+
}
|
|
3659
|
+
private wake(): void {
|
|
3660
|
+
for (const root of this.roots.values()) wakeWorkerProcess(root);
|
|
3661
|
+
for (const controller of this.controllers.values()) controller.wake?.();
|
|
3662
|
+
for (const child of this.children.values()) {
|
|
3663
|
+
child.controller?.wake?.();
|
|
3664
|
+
child.wake?.();
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3667
|
+
async rootExit(pid: number, code: number): Promise<void> {
|
|
3668
|
+
this.revokeRuntimeProcess(pid);
|
|
3669
|
+
if (!this.activation) {
|
|
3670
|
+
const root = this.reservedRoots.get(pid);
|
|
3671
|
+
if (root) claimOutcome(root.outcome, { kind: "exited", code });
|
|
3672
|
+
await this.quiesceProcess(pid);
|
|
3673
|
+
const transport = this.roots.get(pid);
|
|
3674
|
+
if (transport) {
|
|
3675
|
+
controlStore(workerProcessState(transport).confirmed, 0, 1);
|
|
3676
|
+
confirmWorkerProcessJob(transport);
|
|
3677
|
+
}
|
|
3678
|
+
if (root) this.completedRoots.add(pid);
|
|
3679
|
+
this.observationOwners.get(pid)?.close();
|
|
3680
|
+
this.retireRoots();
|
|
3681
|
+
return;
|
|
3682
|
+
}
|
|
3683
|
+
let supervisor: ProcessSupervisor | undefined;
|
|
3684
|
+
try {
|
|
3685
|
+
supervisor = await this.activation;
|
|
3686
|
+
} catch (error) {
|
|
3687
|
+
this.report(error);
|
|
3688
|
+
supervisor = this.supervisor;
|
|
3689
|
+
}
|
|
3690
|
+
if (supervisor?.get(pid)) {
|
|
3691
|
+
supervisor.exit(pid, code);
|
|
3692
|
+
await supervisor.waitForExit(0, pid);
|
|
3693
|
+
} else await this.quiesceProcess(pid);
|
|
3694
|
+
const transport = this.roots.get(pid);
|
|
3695
|
+
if (transport) {
|
|
3696
|
+
controlStore(workerProcessState(transport).confirmed, 0, 1);
|
|
3697
|
+
confirmWorkerProcessJob(transport);
|
|
3698
|
+
}
|
|
3699
|
+
if (this.reservedRoots.has(pid)) this.completedRoots.add(pid);
|
|
3700
|
+
this.observationOwners.get(pid)?.close();
|
|
3701
|
+
this.retireRoots();
|
|
3702
|
+
}
|
|
3703
|
+
private watch(): void {
|
|
3704
|
+
if (this.timer !== null || this.suspended) return;
|
|
3705
|
+
this.timer = setTimeout(() => {
|
|
3706
|
+
this.timer = null;
|
|
3707
|
+
try {
|
|
3708
|
+
this.transport.pump();
|
|
3709
|
+
} catch (error) {
|
|
3710
|
+
this.report(error);
|
|
3711
|
+
}
|
|
3712
|
+
if (this.children.size) this.watch();
|
|
3713
|
+
}, 4);
|
|
3714
|
+
}
|
|
3715
|
+
suspend(): void {
|
|
3716
|
+
if (this.suspended) return;
|
|
3717
|
+
this.suspended = true;
|
|
3718
|
+
this.cancelPreparations();
|
|
3719
|
+
this.workers.dispose();
|
|
3720
|
+
if (this.timer !== null) clearTimeout(this.timer);
|
|
3721
|
+
this.timer = null;
|
|
3722
|
+
// Publish every outcome before running user revocation callbacks.
|
|
3723
|
+
for (const state of this.states()) this.requestSignalIfPresent(state.signals, 9);
|
|
3724
|
+
for (const root of this.reservedRoots.values()) this.requestSignalIfPresent(root, 9);
|
|
3725
|
+
for (const record of this.options.table.values()) this.requestSignalIfPresent(record, 9);
|
|
3726
|
+
for (const state of this.states()) {
|
|
3727
|
+
this.revokeRuntimeProcess(state.pid);
|
|
3728
|
+
const transport = this.transport.get(state.pid);
|
|
3729
|
+
if (transport) this.options.filesystem.revoke(this.filesystem(transport));
|
|
3730
|
+
}
|
|
3731
|
+
for (const pid of this.controllers.keys()) {
|
|
3732
|
+
try {
|
|
3733
|
+
this.revokeController(pid);
|
|
3734
|
+
} catch (error) {
|
|
3735
|
+
this.report(error);
|
|
3736
|
+
}
|
|
3737
|
+
}
|
|
3738
|
+
// Retain every fence before transport disposal drops reservations and supervisor disposal
|
|
3739
|
+
// removes table records. Neither logical death nor terminate() proves admission quiescence.
|
|
3740
|
+
const pids = new Set(
|
|
3741
|
+
Array.from(this.options.table.values(), (record) => record.pid).concat(
|
|
3742
|
+
Array.from(this.controllers.keys()),
|
|
3743
|
+
this.states().map((state) => state.pid),
|
|
3744
|
+
),
|
|
3745
|
+
);
|
|
3746
|
+
for (const pid of pids)
|
|
3747
|
+
try {
|
|
3748
|
+
const pending = this.quiesceProcess(pid);
|
|
3749
|
+
if (pending) void pending.catch((error) => this.report(error));
|
|
3750
|
+
} catch (error) {
|
|
3751
|
+
this.fences.set(pid, Promise.reject(error));
|
|
3752
|
+
}
|
|
3753
|
+
this.transport.dispose();
|
|
3754
|
+
this.supervisor?.dispose();
|
|
3755
|
+
}
|
|
3756
|
+
async quiesce(): Promise<void> {
|
|
3757
|
+
await this.transport.settled();
|
|
3758
|
+
await Promise.all(this.rejectedTransfers.values());
|
|
3759
|
+
for (const scope of this.commandRoots?.values() ?? []) {
|
|
3760
|
+
await Promise.all(scope.pending);
|
|
3761
|
+
const failure = this.commandCleanupFailure(scope);
|
|
3762
|
+
if (failure) throw failure;
|
|
3763
|
+
}
|
|
3764
|
+
const pids = new Set(
|
|
3765
|
+
Array.from(this.options.table.values(), (record) => record.pid).concat(
|
|
3766
|
+
Array.from(this.controllers.keys()),
|
|
3767
|
+
Array.from(this.children.keys()),
|
|
3768
|
+
),
|
|
3769
|
+
);
|
|
3770
|
+
for (const pid of pids) this.quiesceProcess(pid);
|
|
3771
|
+
await Promise.all(
|
|
3772
|
+
Array.from(this.fences.values()).concat(
|
|
3773
|
+
Array.from(
|
|
3774
|
+
this.children.values(),
|
|
3775
|
+
(child) => child.finalFence ?? child.fence ?? Promise.resolve(),
|
|
3776
|
+
),
|
|
3777
|
+
),
|
|
3778
|
+
);
|
|
3779
|
+
}
|
|
3780
|
+
private stopDisposalController(
|
|
3781
|
+
pid: number,
|
|
3782
|
+
controller: ProcessController,
|
|
3783
|
+
failed: Set<ProcessController>,
|
|
3784
|
+
): Promise<void> {
|
|
3785
|
+
this.observationOwners.get(pid)?.close();
|
|
3786
|
+
const stopping = this.controllerStops?.get(pid);
|
|
3787
|
+
// A controller's auxiliary cleanup cannot certify a separately owned launch handle
|
|
3788
|
+
// or generic Worker, especially when that consumer's stop has failed.
|
|
3789
|
+
const nativeStop = this.controllerNativeStopFor(pid);
|
|
3790
|
+
const capturedStop = nativeStop?.terminate ?? this.capturedControllerStopFor(pid);
|
|
3791
|
+
const ownsConsumer = capturedStop && !this.launches?.has(pid) && !this.children.has(pid);
|
|
3792
|
+
const terminal = ownsConsumer ? this.terminalLifetimes.get(pid) : undefined;
|
|
3793
|
+
const pending = stopping?.controllerStop
|
|
3794
|
+
? stopping.pending
|
|
3795
|
+
: Promise.resolve().then(() => capturedStop?.());
|
|
3796
|
+
const group = ownsConsumer ? nativeStop?.membership() : undefined;
|
|
3797
|
+
return pending
|
|
3798
|
+
.then(() => {
|
|
3799
|
+
terminal?.stopped();
|
|
3800
|
+
if (group) this.settleRootGroup(pid, group);
|
|
3801
|
+
if (ownsConsumer) {
|
|
3802
|
+
this.rootStopped(pid);
|
|
3803
|
+
}
|
|
3804
|
+
})
|
|
3805
|
+
.catch((error) => {
|
|
3806
|
+
group?.failed();
|
|
3807
|
+
if (ownsConsumer) this.rootTickets.get(pid)?.failed([error]);
|
|
3808
|
+
failed.add(controller);
|
|
3809
|
+
throw error;
|
|
3810
|
+
});
|
|
3811
|
+
}
|
|
3812
|
+
private retireDisposedControllers(
|
|
3813
|
+
failed: ReadonlySet<ProcessController>,
|
|
3814
|
+
errors: unknown[],
|
|
3815
|
+
): void {
|
|
3816
|
+
const retainedRoots = new Set(
|
|
3817
|
+
Array.from(this.children.values(), (child) => child.identity.rootPid),
|
|
3818
|
+
);
|
|
3819
|
+
for (const [pid, controller] of this.controllers) {
|
|
3820
|
+
if (
|
|
3821
|
+
failed.has(controller) ||
|
|
3822
|
+
retainedRoots.has(pid) ||
|
|
3823
|
+
this.children.has(pid) ||
|
|
3824
|
+
this.launches?.has(pid) ||
|
|
3825
|
+
this.controllerStops?.has(pid)
|
|
3826
|
+
)
|
|
3827
|
+
continue;
|
|
3828
|
+
try {
|
|
3829
|
+
controller.retired?.();
|
|
3830
|
+
} catch (error) {
|
|
3831
|
+
errors.push(error);
|
|
3832
|
+
}
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3835
|
+
dispose(): Promise<void> {
|
|
3836
|
+
if (this.disposing) return this.disposing;
|
|
3837
|
+
let resolve!: () => void, reject!: (error: unknown) => void;
|
|
3838
|
+
const disposal = (this.disposing = new Promise<void>((accept, fail) => {
|
|
3839
|
+
resolve = accept;
|
|
3840
|
+
reject = fail;
|
|
3841
|
+
}));
|
|
3842
|
+
// Revocation callbacks may synchronously dispose their owner again.
|
|
3843
|
+
try {
|
|
3844
|
+
this.suspend();
|
|
3845
|
+
} catch (error) {
|
|
3846
|
+
reject(error);
|
|
3847
|
+
return disposal;
|
|
3848
|
+
}
|
|
3849
|
+
void (async () => {
|
|
3850
|
+
if (this.activation) {
|
|
3851
|
+
try {
|
|
3852
|
+
await this.activation;
|
|
3853
|
+
} catch (error) {
|
|
3854
|
+
this.report(error);
|
|
3855
|
+
}
|
|
3856
|
+
this.supervisor?.dispose();
|
|
3857
|
+
}
|
|
3858
|
+
await Promise.allSettled(this.startupDiagnostics);
|
|
3859
|
+
await Promise.all(
|
|
3860
|
+
Array.from(this.pendingPreparations.values(), (preparation) => preparation.settled),
|
|
3861
|
+
);
|
|
3862
|
+
await this.quiesce();
|
|
3863
|
+
// A controller stop may release a physical handle, but cannot consume authority
|
|
3864
|
+
// before a pending launcher acquires it. Then settle both stops before retirement.
|
|
3865
|
+
await Promise.all(
|
|
3866
|
+
Array.from(this.pendingLaunches?.values() ?? [], (launch) => launch.acquired).concat(
|
|
3867
|
+
this.imageLaunches().map((launch) => launch.pending?.acquired ?? Promise.resolve()),
|
|
3868
|
+
),
|
|
3869
|
+
);
|
|
3870
|
+
const physicalHandles = this.supervisor?.retireFencedProcesses();
|
|
3871
|
+
// Suspension freezes every owned pipe cursor; the filesystem fence above is still
|
|
3872
|
+
// mandatory. Attempt and settle every physical stop even if another consumer fails.
|
|
3873
|
+
const failedControllers = new Set<ProcessController>();
|
|
3874
|
+
const stops = Array.from(this.children.values(), (child) =>
|
|
3875
|
+
Promise.resolve().then(() => this.stop(child)),
|
|
3876
|
+
).concat(
|
|
3877
|
+
Array.from(this.controllers, ([pid, controller]) =>
|
|
3878
|
+
this.stopDisposalController(pid, controller, failedControllers),
|
|
3879
|
+
),
|
|
3880
|
+
Array.from(this.retainedRootStops, ([pid, controller]) =>
|
|
3881
|
+
this.stopDisposalController(pid, controller, failedControllers),
|
|
3882
|
+
),
|
|
3883
|
+
Array.from(this.controllerStops?.values() ?? [], (stopping) => stopping.pending),
|
|
3884
|
+
Array.from(this.pendingLaunches?.values() ?? [], (launch) => launch.settled).concat(
|
|
3885
|
+
this.imageLaunches().map((launch) => launch.pending?.settled ?? Promise.resolve()),
|
|
3886
|
+
),
|
|
3887
|
+
);
|
|
3888
|
+
if (physicalHandles) stops.push(physicalHandles);
|
|
3889
|
+
const errors: unknown[] = [];
|
|
3890
|
+
for (const result of await Promise.allSettled(stops))
|
|
3891
|
+
if (result.status === "rejected") errors.push(result.reason);
|
|
3892
|
+
try {
|
|
3893
|
+
this.pipes.dispose();
|
|
3894
|
+
} catch (error) {
|
|
3895
|
+
errors.push(error);
|
|
3896
|
+
}
|
|
3897
|
+
for (const pid of Array.from(this.imageStops.keys())) {
|
|
3898
|
+
try {
|
|
3899
|
+
await this.finalizeProcess(pid);
|
|
3900
|
+
} catch (error) {
|
|
3901
|
+
if (!errors.includes(error)) errors.push(error);
|
|
3902
|
+
}
|
|
3903
|
+
}
|
|
3904
|
+
for (const owner of Array.from(this.observationOwners.values())) {
|
|
3905
|
+
const failures = await owner.stopAll();
|
|
3906
|
+
for (const failure of failures) if (!errors.includes(failure)) errors.push(failure);
|
|
3907
|
+
}
|
|
3908
|
+
this.retireDisposedControllers(failedControllers, errors);
|
|
3909
|
+
const unsettled = this.groups?.unsettled() ?? 0;
|
|
3910
|
+
if (unsettled)
|
|
3911
|
+
errors.push(new Error(`${unsettled} memory group members have no proven physical stop`));
|
|
3912
|
+
if (errors.length) {
|
|
3913
|
+
const failure = new AggregateError(errors, "Process broker cleanup failed");
|
|
3914
|
+
this.retirementGate.reject(failure);
|
|
3915
|
+
throw failure;
|
|
3916
|
+
}
|
|
3917
|
+
this.retirementGate.resolve();
|
|
3918
|
+
this.reservedRoots.clear();
|
|
3919
|
+
this.descendantHooks.clear();
|
|
3920
|
+
this.signalPolicies.clear();
|
|
3921
|
+
this.completedRoots.clear();
|
|
3922
|
+
this.rootLeases.clear();
|
|
3923
|
+
this.roots.clear();
|
|
3924
|
+
this.commandRoots?.clear();
|
|
3925
|
+
this.outputs.clear();
|
|
3926
|
+
this.terminalOutputs.clear();
|
|
3927
|
+
this.registries.clear();
|
|
3928
|
+
this.controllers.clear();
|
|
3929
|
+
this.capturedControllerRevocations.clear();
|
|
3930
|
+
this.retainedRootStops.clear();
|
|
3931
|
+
this.controllerNativeStops.clear();
|
|
3932
|
+
this.capturedControllerStops.clear();
|
|
3933
|
+
this.controllerNativeReturns.clear();
|
|
3934
|
+
this.quiescedControllers.clear();
|
|
3935
|
+
this.revokedControllers.clear();
|
|
3936
|
+
this.controllerStops?.clear();
|
|
3937
|
+
this.launches?.clear();
|
|
3938
|
+
this.pendingLaunches?.clear();
|
|
3939
|
+
this.fences.clear();
|
|
3940
|
+
this.acquiredProcesses.clear();
|
|
3941
|
+
this.settledGroupAcquisitions.clear();
|
|
3942
|
+
for (const directory of this.groupAdmissionWatches.keys())
|
|
3943
|
+
this.cancelGroupAdmissionWatch(directory);
|
|
3944
|
+
for (const owner of this.observationOwners.values()) owner.close();
|
|
3945
|
+
this.terminalLifetimes.clear();
|
|
3946
|
+
this.stopTrackingConsumers();
|
|
3947
|
+
if (errors.length) throw new AggregateError(errors, "Process broker cleanup failed");
|
|
3948
|
+
})().then(resolve, reject);
|
|
3949
|
+
return disposal;
|
|
3950
|
+
}
|
|
3951
|
+
private report(error: unknown): void {
|
|
3952
|
+
try {
|
|
3953
|
+
if (this.options.onError) this.options.onError(error);
|
|
3954
|
+
else console.error("runtime: process controller failed", error);
|
|
3955
|
+
} catch {
|
|
3956
|
+
/* Diagnostics must not interrupt consumer fencing or cleanup. */
|
|
3957
|
+
}
|
|
3958
|
+
}
|
|
3959
|
+
}
|
|
3960
|
+
|
|
3961
|
+
async function settleStop(stop: () => void | Promise<void>, errors: unknown[]): Promise<void> {
|
|
3962
|
+
try {
|
|
3963
|
+
await stop();
|
|
3964
|
+
} catch (error) {
|
|
3965
|
+
errors.push(error);
|
|
3966
|
+
}
|
|
3967
|
+
}
|
|
3968
|
+
|
|
3969
|
+
/** One accepted adapter entry, including wrappers around the borrowed native Worker handle. */
|
|
3970
|
+
function ownedAdapterHandle(handle: ProcessHandle): ProcessHandle {
|
|
3971
|
+
let stopping: Promise<void> | undefined;
|
|
3972
|
+
const terminate = handle.terminate.bind(handle);
|
|
3973
|
+
return {
|
|
3974
|
+
terminate() {
|
|
3975
|
+
if (stopping) return stopping;
|
|
3976
|
+
const stopped = Promise.withResolvers<void>();
|
|
3977
|
+
stopping = stopped.promise;
|
|
3978
|
+
try {
|
|
3979
|
+
stopped.resolve(terminate());
|
|
3980
|
+
} catch (error) {
|
|
3981
|
+
stopped.reject(error);
|
|
3982
|
+
}
|
|
3983
|
+
return stopping;
|
|
3984
|
+
},
|
|
3985
|
+
};
|
|
3986
|
+
}
|
|
3987
|
+
|
|
3988
|
+
function terminalPreparationError(code: TerminalFailure): ProcessError {
|
|
3989
|
+
const errno =
|
|
3990
|
+
code === "CAPACITY"
|
|
3991
|
+
? ProcessErrno.AGAIN
|
|
3992
|
+
: code === "CANCELED" || code === "PROCESS_GONE"
|
|
3993
|
+
? ProcessErrno.CANCELED
|
|
3994
|
+
: code === "CLOSED" || code === "EXHAUSTED"
|
|
3995
|
+
? 29
|
|
3996
|
+
: ProcessErrno.INVAL;
|
|
3997
|
+
return new ProcessError(errno, `terminal preparation failed: ${code}`);
|
|
3998
|
+
}
|
|
3999
|
+
|
|
4000
|
+
function rootOutput(options: RuntimeRootOptions): TerminalOutputDelivery | undefined {
|
|
4001
|
+
const { output, tryOutput } = options;
|
|
4002
|
+
if (output && tryOutput) throw new TypeError("root output and tryOutput are exclusive");
|
|
4003
|
+
if (tryOutput) return (target, data) => tryOutput(target, data);
|
|
4004
|
+
if (!output) return undefined;
|
|
4005
|
+
return (target, data) => {
|
|
4006
|
+
output(target, data);
|
|
4007
|
+
return data.length;
|
|
4008
|
+
};
|
|
4009
|
+
}
|
|
4010
|
+
|
|
4011
|
+
class NativeObservationOwner {
|
|
4012
|
+
private readonly publish: () => void;
|
|
4013
|
+
private readonly key: string;
|
|
4014
|
+
private readonly stops = new Set<ProcessHandle>();
|
|
4015
|
+
private readonly finished = Promise.withResolvers<void>();
|
|
4016
|
+
private failure: { error: unknown } | undefined;
|
|
4017
|
+
private consumers = 0;
|
|
4018
|
+
private closed = false;
|
|
4019
|
+
private admitted = false;
|
|
4020
|
+
completed = false;
|
|
4021
|
+
constructor(
|
|
4022
|
+
transfer: ProcessObservationTransfer,
|
|
4023
|
+
private readonly onComplete: () => void,
|
|
4024
|
+
execution: boolean,
|
|
4025
|
+
) {
|
|
4026
|
+
this.admitted = execution;
|
|
4027
|
+
this.publish = captureNativeReturn(transfer);
|
|
4028
|
+
this.key = observationKey(transfer);
|
|
4029
|
+
void this.finished.promise.catch(() => {});
|
|
4030
|
+
}
|
|
4031
|
+
matches(transfer: ProcessObservationTransfer): boolean {
|
|
4032
|
+
return this.key === observationKey(transfer);
|
|
4033
|
+
}
|
|
4034
|
+
acceptExecution(): void {
|
|
4035
|
+
this.admitted = true;
|
|
4036
|
+
}
|
|
4037
|
+
join(): Promise<void> {
|
|
4038
|
+
return this.finished.promise;
|
|
4039
|
+
}
|
|
4040
|
+
fail(error: unknown): void {
|
|
4041
|
+
this.failure ??= { error };
|
|
4042
|
+
this.finished.reject(error);
|
|
4043
|
+
}
|
|
4044
|
+
acquire(): () => void {
|
|
4045
|
+
if (this.closed) throw new Error("Process native consumer admission is closed");
|
|
4046
|
+
this.admitted = true;
|
|
4047
|
+
this.consumers++;
|
|
4048
|
+
let returned = false;
|
|
4049
|
+
return () => {
|
|
4050
|
+
if (returned) return;
|
|
4051
|
+
returned = true;
|
|
4052
|
+
this.consumers--;
|
|
4053
|
+
this.complete();
|
|
4054
|
+
};
|
|
4055
|
+
}
|
|
4056
|
+
addStop(handle: ProcessHandle): void {
|
|
4057
|
+
this.stops.add(handle);
|
|
4058
|
+
}
|
|
4059
|
+
removeStop(handle: ProcessHandle): void {
|
|
4060
|
+
this.stops.delete(handle);
|
|
4061
|
+
}
|
|
4062
|
+
async stopAll(): Promise<unknown[]> {
|
|
4063
|
+
this.close();
|
|
4064
|
+
const results = await Promise.allSettled(
|
|
4065
|
+
Array.from(this.stops, (handle) => Promise.resolve().then(() => handle.terminate())),
|
|
4066
|
+
);
|
|
4067
|
+
const failures = results.filter((result) => result.status === "rejected");
|
|
4068
|
+
const errors = failures.map((result) => result.reason);
|
|
4069
|
+
if (this.failure && !errors.includes(this.failure.error)) errors.push(this.failure.error);
|
|
4070
|
+
if (!errors.length && this.consumers !== 0)
|
|
4071
|
+
errors.push(new Error("Process native consumers remain pending"));
|
|
4072
|
+
return errors;
|
|
4073
|
+
}
|
|
4074
|
+
close(): void {
|
|
4075
|
+
this.closed = true;
|
|
4076
|
+
if (!this.admitted) {
|
|
4077
|
+
this.finished.resolve();
|
|
4078
|
+
this.onComplete();
|
|
4079
|
+
return;
|
|
4080
|
+
}
|
|
4081
|
+
this.complete();
|
|
4082
|
+
}
|
|
4083
|
+
private complete(): void {
|
|
4084
|
+
if (!this.closed || this.consumers !== 0 || this.completed) return;
|
|
4085
|
+
this.publish();
|
|
4086
|
+
this.completed = true;
|
|
4087
|
+
this.finished.resolve();
|
|
4088
|
+
this.onComplete();
|
|
4089
|
+
}
|
|
4090
|
+
}
|
|
4091
|
+
interface NativeStopHandle extends ProcessHandle {
|
|
4092
|
+
bindGroup(lease: MemberLease): void;
|
|
4093
|
+
membership(): MemberLease | undefined;
|
|
4094
|
+
imageReturned(): void;
|
|
4095
|
+
acknowledgeReturn(): void;
|
|
4096
|
+
}
|
|
4097
|
+
type NativeStopState =
|
|
4098
|
+
| { kind: "invoking"; reentrant?: ReturnType<typeof Promise.withResolvers<void>> }
|
|
4099
|
+
| { kind: "returned"; result: void | Promise<void> };
|
|
4100
|
+
function ignoreNativeStopRejection(): void {}
|
|
4101
|
+
function nativeStopHandle(
|
|
4102
|
+
handle: ProcessHandle,
|
|
4103
|
+
terminal: TerminalProcessLifetime | undefined,
|
|
4104
|
+
returned: (() => void) | undefined,
|
|
4105
|
+
closeAdmission?: () => void,
|
|
4106
|
+
failed?: (error: unknown) => void,
|
|
4107
|
+
): NativeStopHandle {
|
|
4108
|
+
const terminate = handle.terminate;
|
|
4109
|
+
let state: NativeStopState | undefined;
|
|
4110
|
+
let group: MemberLease | undefined;
|
|
4111
|
+
let groupBound = false;
|
|
4112
|
+
let attempted = false;
|
|
4113
|
+
const invoke = (): void | Promise<void> => {
|
|
4114
|
+
try {
|
|
4115
|
+
return reflectApply(terminate, handle, []) as void | Promise<void>;
|
|
4116
|
+
} finally {
|
|
4117
|
+
attempted = true;
|
|
4118
|
+
group?.stopRequested();
|
|
4119
|
+
}
|
|
4120
|
+
};
|
|
4121
|
+
return {
|
|
4122
|
+
membership: () => group,
|
|
4123
|
+
bindGroup(lease) {
|
|
4124
|
+
if (groupBound) throw new Error("native consumer already has a memory group binding");
|
|
4125
|
+
groupBound = true;
|
|
4126
|
+
group = lease;
|
|
4127
|
+
if (attempted) group.stopRequested();
|
|
4128
|
+
},
|
|
4129
|
+
imageReturned() {
|
|
4130
|
+
if (state) return;
|
|
4131
|
+
state = { kind: "returned", result: undefined };
|
|
4132
|
+
returned?.();
|
|
4133
|
+
group = undefined;
|
|
4134
|
+
},
|
|
4135
|
+
acknowledgeReturn() {
|
|
4136
|
+
// A reentrant acknowledgement cannot erase a stop still invoking, pending or failed.
|
|
4137
|
+
if (state) return;
|
|
4138
|
+
state = { kind: "returned", result: undefined };
|
|
4139
|
+
closeAdmission?.();
|
|
4140
|
+
returned?.();
|
|
4141
|
+
terminal?.stopped();
|
|
4142
|
+
group = undefined;
|
|
4143
|
+
},
|
|
4144
|
+
terminate() {
|
|
4145
|
+
if (state?.kind === "returned") return state.result;
|
|
4146
|
+
if (state) {
|
|
4147
|
+
state.reentrant ??= Promise.withResolvers<void>();
|
|
4148
|
+
void state.reentrant.promise.catch(ignoreNativeStopRejection);
|
|
4149
|
+
return state.reentrant.promise;
|
|
4150
|
+
}
|
|
4151
|
+
const invoking: Extract<NativeStopState, { kind: "invoking" }> = { kind: "invoking" };
|
|
4152
|
+
state = invoking;
|
|
4153
|
+
const complete = () => {
|
|
4154
|
+
returned?.();
|
|
4155
|
+
terminal?.stopped();
|
|
4156
|
+
invoking.reentrant?.resolve();
|
|
4157
|
+
group = undefined;
|
|
4158
|
+
};
|
|
4159
|
+
const reject = (error: unknown): never => {
|
|
4160
|
+
group?.failed();
|
|
4161
|
+
failed?.(error);
|
|
4162
|
+
invoking.reentrant?.reject(error);
|
|
4163
|
+
throw error;
|
|
4164
|
+
};
|
|
4165
|
+
try {
|
|
4166
|
+
closeAdmission?.();
|
|
4167
|
+
const result = invoke();
|
|
4168
|
+
if (result)
|
|
4169
|
+
return (state = {
|
|
4170
|
+
kind: "returned",
|
|
4171
|
+
result: result.then(complete).catch(reject),
|
|
4172
|
+
}).result;
|
|
4173
|
+
complete();
|
|
4174
|
+
state = { kind: "returned", result: undefined };
|
|
4175
|
+
} catch (error) {
|
|
4176
|
+
group?.failed();
|
|
4177
|
+
failed?.(error);
|
|
4178
|
+
invoking.reentrant?.reject(error);
|
|
4179
|
+
const result = Promise.reject(error);
|
|
4180
|
+
void result.catch(ignoreNativeStopRejection);
|
|
4181
|
+
state = { kind: "returned", result };
|
|
4182
|
+
throw error;
|
|
4183
|
+
}
|
|
4184
|
+
},
|
|
4185
|
+
};
|
|
4186
|
+
}
|
|
4187
|
+
|
|
4188
|
+
function observationKey(transfer: ProcessObservationTransfer): string {
|
|
4189
|
+
if (transfer.kind === "standalone") return `standalone:${transfer.domain}:${transfer.pid}`;
|
|
4190
|
+
const domain = atomicsLoad(new BigInt64ArrayConstructor(transfer.directory, 8, 1), 0);
|
|
4191
|
+
return `directory:${domain}:${transfer.slot}:${transfer.pid}`;
|
|
4192
|
+
}
|
|
4193
|
+
|
|
4194
|
+
class NativeReturnFollowers {
|
|
4195
|
+
private state: { kind: "pending"; callbacks: (() => void)[] } | { kind: "returned" } = {
|
|
4196
|
+
kind: "pending",
|
|
4197
|
+
callbacks: [],
|
|
4198
|
+
};
|
|
4199
|
+
follow(callback: () => void): void {
|
|
4200
|
+
if (this.state.kind === "returned") return callback();
|
|
4201
|
+
this.state.callbacks.push(callback);
|
|
4202
|
+
}
|
|
4203
|
+
returned(): void {
|
|
4204
|
+
if (this.state.kind === "returned") return;
|
|
4205
|
+
const callbacks = this.state.callbacks;
|
|
4206
|
+
this.state = { kind: "returned" };
|
|
4207
|
+
for (let index = 0; index < callbacks.length; index++) callbacks[index]!();
|
|
4208
|
+
}
|
|
4209
|
+
}
|