@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,3361 @@
|
|
|
1
|
+
import {
|
|
2
|
+
commandExecTransfer,
|
|
3
|
+
commandTransferFailed,
|
|
4
|
+
initializeCommandExec,
|
|
5
|
+
readCommandTransferFailure
|
|
6
|
+
} from "../proc/command-transfer.js";
|
|
7
|
+
import { WorkerStartError } from "../proc/start-diagnostic.js";
|
|
8
|
+
import { requireGroupPlan } from "../link/issuance.js";
|
|
9
|
+
import {
|
|
10
|
+
admitProcessObservation,
|
|
11
|
+
captureNativeReturn
|
|
12
|
+
} from "../proc/observation.js";
|
|
13
|
+
import {
|
|
14
|
+
bindGraphicsLaunch,
|
|
15
|
+
graphicsLaunchRetention,
|
|
16
|
+
retainAllocationReceipts
|
|
17
|
+
} from "./display/launch-retention.js";
|
|
18
|
+
import { allocateSharedControl } from "../memory/control.js";
|
|
19
|
+
import {
|
|
20
|
+
bytes
|
|
21
|
+
} from "../memory/reservations.js";
|
|
22
|
+
import {
|
|
23
|
+
threadModuleDeclaration,
|
|
24
|
+
moduleMemoryDeclarations
|
|
25
|
+
} from "../memory/declarations.js";
|
|
26
|
+
import {
|
|
27
|
+
prepareTerminalDescendant,
|
|
28
|
+
terminalPreparationReceipt
|
|
29
|
+
} from "./terminal-session.js";
|
|
30
|
+
import {
|
|
31
|
+
atomicsWaitAsync,
|
|
32
|
+
atomicsLoad,
|
|
33
|
+
BigInt64ArrayConstructor,
|
|
34
|
+
reflectApply,
|
|
35
|
+
observeRejectedPromise,
|
|
36
|
+
isInstance,
|
|
37
|
+
PromiseConstructor
|
|
38
|
+
} from "../proc/intrinsics.js";
|
|
39
|
+
import { ReadyWorkerPool } from "./worker-pool.js";
|
|
40
|
+
import {
|
|
41
|
+
markStart,
|
|
42
|
+
observeStart,
|
|
43
|
+
processStartRecord,
|
|
44
|
+
startMessage,
|
|
45
|
+
startSnapshot
|
|
46
|
+
} from "./process-start.js";
|
|
47
|
+
import { createNotificationBridge } from "./notification-relay.js";
|
|
48
|
+
import { snapshotHostIdentity } from "./process-context.js";
|
|
49
|
+
import { drainDiagnostic } from "./diagnostic.js";
|
|
50
|
+
import {
|
|
51
|
+
MemoryGroups
|
|
52
|
+
} from "../group/state.js";
|
|
53
|
+
import { WorkerExecutableAccess, rejectWorkerAccess } from "../proc/worker-access.js";
|
|
54
|
+
import {
|
|
55
|
+
directoryGroups,
|
|
56
|
+
directoryCapacity,
|
|
57
|
+
collectDirectoryJob,
|
|
58
|
+
idleDirectoryAdmission,
|
|
59
|
+
directoryProcesses,
|
|
60
|
+
directoryAdmissionVersion,
|
|
61
|
+
commitDirectoryAdmission,
|
|
62
|
+
isCollectedProcess,
|
|
63
|
+
wakeDirectory
|
|
64
|
+
} from "../proc/directory.js";
|
|
65
|
+
import {
|
|
66
|
+
TaggedCells,
|
|
67
|
+
controlLoad,
|
|
68
|
+
controlStore,
|
|
69
|
+
controlCas
|
|
70
|
+
} from "../proc/control.js";
|
|
71
|
+
import { isRevoked } from "../fs/protocol.js";
|
|
72
|
+
import {
|
|
73
|
+
checkedSignal,
|
|
74
|
+
checkedProcessCwd,
|
|
75
|
+
snapshotLogicalProcessIdentity,
|
|
76
|
+
ProcessErrno,
|
|
77
|
+
ProcessError
|
|
78
|
+
} from "../proc/types.js";
|
|
79
|
+
import { requestSignal, createSignalState } from "../proc/signals.js";
|
|
80
|
+
import {
|
|
81
|
+
claimOutcome,
|
|
82
|
+
outcomeWord,
|
|
83
|
+
readOutcome,
|
|
84
|
+
startStatus,
|
|
85
|
+
serializeOutcome
|
|
86
|
+
} from "../proc/outcome.js";
|
|
87
|
+
import { WorkerProcessBroker } from "../proc/worker-broker.js";
|
|
88
|
+
import {
|
|
89
|
+
captureTerminalLifetime
|
|
90
|
+
} from "../proc/terminal-lifetime.js";
|
|
91
|
+
import {
|
|
92
|
+
reportProcessAdmission
|
|
93
|
+
} from "../proc/admission.js";
|
|
94
|
+
import {
|
|
95
|
+
confirmWorkerProcessJob,
|
|
96
|
+
installWorkerBindings,
|
|
97
|
+
wakeWorkerProcess,
|
|
98
|
+
workerProcessDirectoryId,
|
|
99
|
+
workerProcessState
|
|
100
|
+
} from "../proc/worker-client.js";
|
|
101
|
+
import { createFilesystemDescriptorCodec } from "../proc/filesystem-codec.js";
|
|
102
|
+
import { WorkerPipeBroker, WorkerPipeHost } from "../proc/worker-pipes.js";
|
|
103
|
+
import {
|
|
104
|
+
attachPipePublicationRegistry,
|
|
105
|
+
PipeEndpoint,
|
|
106
|
+
PipePublicationRegistry
|
|
107
|
+
} from "../proc/pipes.js";
|
|
108
|
+
import { createRuntimeTerminalCodec } from "./runtime-terminals.js";
|
|
109
|
+
import {
|
|
110
|
+
createTerminalOutput,
|
|
111
|
+
deliveredTerminalOutput,
|
|
112
|
+
TerminalOutputBudget
|
|
113
|
+
} from "./terminal-output.js";
|
|
114
|
+
import { packageIdentity } from "../programs/catalog.js";
|
|
115
|
+
import { preview1Launch } from "../programs/collection.js";
|
|
116
|
+
import {
|
|
117
|
+
CommandStdioError
|
|
118
|
+
} from "../proc/command.js";
|
|
119
|
+
const reservedDescendantData = ["filesystem", "pipeRegistry"];
|
|
120
|
+
const originalGraphicsGrants = new WeakMap;
|
|
121
|
+
const STOP_UNWIND_MS = 1000;
|
|
122
|
+
function guestFinished(type) {
|
|
123
|
+
return type === "exit" || type === "error" || type === "cleanup-error" || type === "observation-error";
|
|
124
|
+
}
|
|
125
|
+
function guestEnded(child) {
|
|
126
|
+
child.guestEnded = true;
|
|
127
|
+
child.endGuest?.();
|
|
128
|
+
}
|
|
129
|
+
function guestEntered(child) {
|
|
130
|
+
try {
|
|
131
|
+
return startStatus(child.context.outcome) === 0;
|
|
132
|
+
} catch {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function guestUnwound(child) {
|
|
137
|
+
if (child.guestEnded || !guestEntered(child))
|
|
138
|
+
return;
|
|
139
|
+
if (child.group?.closeParked())
|
|
140
|
+
return;
|
|
141
|
+
const unwound = Promise.withResolvers();
|
|
142
|
+
const cap = setTimeout(unwound.resolve, STOP_UNWIND_MS);
|
|
143
|
+
child.endGuest = unwound.resolve;
|
|
144
|
+
return unwound.promise.finally(() => {
|
|
145
|
+
clearTimeout(cap);
|
|
146
|
+
child.endGuest = undefined;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function senderRevoked(result, filesystemRevoked) {
|
|
150
|
+
return result?.kind === "signaled" || !result && filesystemRevoked;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export class BrowserProcessBroker {
|
|
154
|
+
options;
|
|
155
|
+
hostIdentity;
|
|
156
|
+
suspended = false;
|
|
157
|
+
pendingPreparations = new Set;
|
|
158
|
+
retirementGate = Promise.withResolvers();
|
|
159
|
+
disposing;
|
|
160
|
+
activation;
|
|
161
|
+
supervisor;
|
|
162
|
+
pipes;
|
|
163
|
+
workers = new ReadyWorkerPool;
|
|
164
|
+
roots = new Map;
|
|
165
|
+
reservedRoots = new Map;
|
|
166
|
+
completedRoots = new Set;
|
|
167
|
+
commandRoots;
|
|
168
|
+
rootLeases = new Map;
|
|
169
|
+
controllers = new Map;
|
|
170
|
+
signalPolicies = new Map;
|
|
171
|
+
revokedControllers = new Set;
|
|
172
|
+
quiescedControllers = new Set;
|
|
173
|
+
controllerStops;
|
|
174
|
+
launches;
|
|
175
|
+
pendingLaunches;
|
|
176
|
+
settledGroupAcquisitions = new Set;
|
|
177
|
+
groupAdmissionWatches = new Map;
|
|
178
|
+
descendantHooks = new Map;
|
|
179
|
+
outputs = new Map;
|
|
180
|
+
terminalOutputs = new Map;
|
|
181
|
+
registries = new Map;
|
|
182
|
+
children = new Map;
|
|
183
|
+
#operations;
|
|
184
|
+
#operationsUnavailable = false;
|
|
185
|
+
launchStates = new WeakMap;
|
|
186
|
+
fences = new Map;
|
|
187
|
+
startupDiagnostics = new Set;
|
|
188
|
+
rejectedTransfers = new Map;
|
|
189
|
+
cleanupCodec;
|
|
190
|
+
acquiredProcesses = new Map;
|
|
191
|
+
retainedRootStops = new Map;
|
|
192
|
+
capturedControllerRevocations = new Map;
|
|
193
|
+
capturedControllerStops = new Map;
|
|
194
|
+
controllerNativeReturns = new Map;
|
|
195
|
+
controllerNativeStops = new Map;
|
|
196
|
+
observationOwners = new Map;
|
|
197
|
+
neverConstructed = new WeakMap;
|
|
198
|
+
nativeLaunchReturns = new Map;
|
|
199
|
+
imageStops = new Map;
|
|
200
|
+
replacementDiagnostics = new WeakSet;
|
|
201
|
+
terminalLifetimes = new Map;
|
|
202
|
+
groups;
|
|
203
|
+
rootGroups;
|
|
204
|
+
rootAdmissions = new Map;
|
|
205
|
+
rootTickets = new Map;
|
|
206
|
+
rootGrants = new Map;
|
|
207
|
+
stopTrackingConsumers;
|
|
208
|
+
accesses = new WorkerExecutableAccess({
|
|
209
|
+
active: (sender) => !this.suspended && !isRevoked(this.filesystem(sender)),
|
|
210
|
+
check: async (_sender, path, cwd, active) => {
|
|
211
|
+
await this.options.registry.check(path, cwd, active);
|
|
212
|
+
return 0;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
timer = null;
|
|
216
|
+
transport;
|
|
217
|
+
constructor(options) {
|
|
218
|
+
this.options = options;
|
|
219
|
+
this.pipes = new WorkerPipeBroker({
|
|
220
|
+
allocateShared: (length) => options.reservations.buffer("control", { kind: "fixed-buffer", length: bytes(length) })
|
|
221
|
+
});
|
|
222
|
+
this.retirementGate.promise.catch(() => {});
|
|
223
|
+
this.hostIdentity = snapshotHostIdentity(options.hostIdentity);
|
|
224
|
+
this.transport = new WorkerProcessBroker({
|
|
225
|
+
supervisor: () => this.ready(),
|
|
226
|
+
codec: (transport) => this.descriptorCodec(transport),
|
|
227
|
+
discard: (token) => this.discardCodec().discard(token),
|
|
228
|
+
onPipe: (handle) => this.pipes.attach(handle),
|
|
229
|
+
pumpPipes: () => this.pipes.pump(),
|
|
230
|
+
onError: (error) => this.report(error),
|
|
231
|
+
onAdmission: options.onProcessAdmission,
|
|
232
|
+
nativeReturn: (transport) => this.processNativeReturn(transport),
|
|
233
|
+
onAdmitted: (transport) => this.acquireProcess(transport),
|
|
234
|
+
quiesce: (_pid, transport) => this.quiesceUnstarted(transport),
|
|
235
|
+
beforeAdmit: (transport) => this.checkCommandAdmission(transport),
|
|
236
|
+
transferCleanup: (transport, cleanup) => this.trackCommandTransfer(transport, cleanup),
|
|
237
|
+
retireRejected: (transport) => this.retireRejectedCommand(transport),
|
|
238
|
+
canExec: (transport) => this.canExec(transport),
|
|
239
|
+
discardExec: (transport) => {
|
|
240
|
+
const filesystem = this.filesystem(transport);
|
|
241
|
+
this.options.filesystem.revoke(filesystem);
|
|
242
|
+
if (this.commandScope(transport))
|
|
243
|
+
return this.options.filesystem.quiesce(filesystem);
|
|
244
|
+
this.options.filesystem.reap(filesystem);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
this.stopTrackingConsumers = options.table.onRemove((record) => {
|
|
248
|
+
this.releaseAcquiredProcess(record.pid);
|
|
249
|
+
this.settledGroupAcquisitions.delete(observationKey(record.observation));
|
|
250
|
+
this.groups?.settleStopping();
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
ready() {
|
|
254
|
+
return this.activation ??= (this.options.activate?.() ?? import("../proc/index.js")).then((proc) => {
|
|
255
|
+
const supervisor = this.supervisor = new proc.ProcessSupervisor({
|
|
256
|
+
registry: this.options.registry,
|
|
257
|
+
byteBackedGuestOnly: (rootPid) => rootPid !== undefined && !!this.commandRoots?.has(rootPid),
|
|
258
|
+
table: this.options.table,
|
|
259
|
+
launch: (context) => this.launchPrepared(context),
|
|
260
|
+
launchCommand: (context) => this.launchPrepared(context),
|
|
261
|
+
canConfirmExit: (pid) => {
|
|
262
|
+
const child = this.children.get(pid);
|
|
263
|
+
return this.suspended || (child ? child.threads !== undefined || child.acknowledged || child.failed : this.controllerFor(pid)?.canConfirmExit?.() ?? true);
|
|
264
|
+
},
|
|
265
|
+
quiesce: (pid) => this.quiesceProcess(pid),
|
|
266
|
+
retire: (pid) => this.retireProcess(pid),
|
|
267
|
+
stopImage: (pid, generation, active) => this.stopImage(pid, generation, active),
|
|
268
|
+
commitReplacement: (pid, generation, resolved) => this.commitReplacement(pid, generation, resolved),
|
|
269
|
+
replacementFailed: (pid, error) => this.reportReplacementFailure(pid, error),
|
|
270
|
+
staleImage: (pid) => {
|
|
271
|
+
const record = this.options.table.get(pid);
|
|
272
|
+
if (record)
|
|
273
|
+
this.traceProcess(record, "dropped", "stale-image");
|
|
274
|
+
},
|
|
275
|
+
startFailed: (pid, error, active) => this.writeStartupDiagnostic(pid, error, active),
|
|
276
|
+
onError: (error) => this.report(error)
|
|
277
|
+
});
|
|
278
|
+
supervisor.onChildExit((event) => {
|
|
279
|
+
this.revokeRuntimeProcess(event.pid);
|
|
280
|
+
const transport = this.transport.get(event.pid);
|
|
281
|
+
if (transport && !this.children.get(event.pid)?.acknowledged)
|
|
282
|
+
this.options.filesystem.revoke(this.filesystem(transport));
|
|
283
|
+
(async () => {
|
|
284
|
+
try {
|
|
285
|
+
this.controllerFor(event.pid)?.exited?.(event);
|
|
286
|
+
} finally {
|
|
287
|
+
const child = this.children.get(event.pid);
|
|
288
|
+
if (child)
|
|
289
|
+
await this.stop(child);
|
|
290
|
+
else {
|
|
291
|
+
await this.pendingLaunches?.get(event.pid)?.settled;
|
|
292
|
+
if (!this.launches?.has(event.pid))
|
|
293
|
+
await this.stopController(event.pid);
|
|
294
|
+
}
|
|
295
|
+
this.observationOwners.get(event.pid)?.close();
|
|
296
|
+
this.retireRoots();
|
|
297
|
+
}
|
|
298
|
+
})().catch((error) => this.report(error));
|
|
299
|
+
});
|
|
300
|
+
supervisor.onProcessQuiescent((event) => {
|
|
301
|
+
this.fences.delete(event.pid);
|
|
302
|
+
this.releaseAcquiredProcess(event.pid);
|
|
303
|
+
this.groups?.settleStopping();
|
|
304
|
+
});
|
|
305
|
+
supervisor.onJobReap(() => this.retireRoots());
|
|
306
|
+
for (const root of this.reservedRoots.values())
|
|
307
|
+
if (!supervisor.get(root.pid)) {
|
|
308
|
+
supervisor.createRoot(root);
|
|
309
|
+
supervisor.registerRevocation(root.pid, () => this.revokeController(root.pid));
|
|
310
|
+
}
|
|
311
|
+
for (const transport of this.roots.values())
|
|
312
|
+
this.activateRuntimeRoot(supervisor, transport);
|
|
313
|
+
if (this.suspended)
|
|
314
|
+
supervisor.dispose();
|
|
315
|
+
return supervisor;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
async launchPrepared(context) {
|
|
319
|
+
const descendant = this.descendant(context.pid);
|
|
320
|
+
if (!descendant)
|
|
321
|
+
return this.launchAdapter(context);
|
|
322
|
+
return this.prepareDescendant(context, descendant.hook, descendant.transport);
|
|
323
|
+
}
|
|
324
|
+
descendant(pid) {
|
|
325
|
+
const transport = this.transport.get(pid);
|
|
326
|
+
if (!transport)
|
|
327
|
+
return;
|
|
328
|
+
const { rootPid } = workerProcessState(transport);
|
|
329
|
+
const hook = rootPid === pid ? undefined : this.descendantHooks.get(rootPid);
|
|
330
|
+
if (!hook || hook.directory !== workerProcessDirectoryId(transport))
|
|
331
|
+
return;
|
|
332
|
+
return { hook, transport };
|
|
333
|
+
}
|
|
334
|
+
preparationFailure(context, hook, rootPid) {
|
|
335
|
+
if (this.suspended || this.descendantHooks.get(rootPid) !== hook)
|
|
336
|
+
return "CANCELED";
|
|
337
|
+
if (this.options.table.get(context.pid)?.image.generation !== context.generation || readOutcome(context.outcome))
|
|
338
|
+
return "CANCELED";
|
|
339
|
+
const root = this.roots.get(rootPid);
|
|
340
|
+
if (!root || readOutcome(workerProcessState(root).signals.outcome))
|
|
341
|
+
return "PROCESS_GONE";
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
beginPreparation(context, rootPid, initial, hook, descendant) {
|
|
345
|
+
const controller = new AbortController;
|
|
346
|
+
const release = this.retainRoot(rootPid);
|
|
347
|
+
let settle;
|
|
348
|
+
const settled = new Promise((resolve) => {
|
|
349
|
+
settle = resolve;
|
|
350
|
+
});
|
|
351
|
+
const record = {
|
|
352
|
+
pid: context.pid,
|
|
353
|
+
rootPid,
|
|
354
|
+
observation: context.observation,
|
|
355
|
+
controller,
|
|
356
|
+
settled,
|
|
357
|
+
phase: "preparing",
|
|
358
|
+
receipt: initial,
|
|
359
|
+
entry: "not-entered",
|
|
360
|
+
finish: () => {
|
|
361
|
+
if (record.phase === "settled" || record.phase === "settling")
|
|
362
|
+
return;
|
|
363
|
+
record.phase = "settling";
|
|
364
|
+
const completion = record.receipt.phase === "committed" ? { kind: "committed", entry: record.entry, receipt: record.receipt } : { kind: "rolled-back", receipt: record.receipt };
|
|
365
|
+
try {
|
|
366
|
+
const notification = hook.prepare.settled?.(descendant, completion);
|
|
367
|
+
if (notification !== undefined) {
|
|
368
|
+
if (isInstance(notification, PromiseConstructor))
|
|
369
|
+
observeRejectedPromise(notification);
|
|
370
|
+
throw new TypeError("preparation settlement must return undefined synchronously");
|
|
371
|
+
}
|
|
372
|
+
} catch (error) {
|
|
373
|
+
this.report(error);
|
|
374
|
+
} finally {
|
|
375
|
+
this.pendingPreparations.delete(record);
|
|
376
|
+
record.phase = "settled";
|
|
377
|
+
settle();
|
|
378
|
+
release();
|
|
379
|
+
this.groups?.settleStopping();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
this.pendingPreparations.add(record);
|
|
384
|
+
context.registerRevocation(() => {
|
|
385
|
+
if (record.phase === "preparing")
|
|
386
|
+
controller.abort();
|
|
387
|
+
});
|
|
388
|
+
return record;
|
|
389
|
+
}
|
|
390
|
+
async watchPreparation(context, hook, transport, record) {
|
|
391
|
+
const wake = new Int32Array(transport.directory, 4, 1);
|
|
392
|
+
while (this.pendingPreparations.has(record) && record.phase === "preparing") {
|
|
393
|
+
const seen = Atomics.load(wake, 0);
|
|
394
|
+
if (this.preparationFailure(context, hook, record.rootPid)) {
|
|
395
|
+
record.controller.abort();
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
const waiting = atomicsWaitAsync(wake, 0, seen);
|
|
399
|
+
if (waiting.async)
|
|
400
|
+
await waiting.value;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
async prepareDescendant(context, hook, transport) {
|
|
404
|
+
const state = workerProcessState(transport);
|
|
405
|
+
const root = this.roots.get(state.rootPid);
|
|
406
|
+
if (!root)
|
|
407
|
+
throw new ProcessError(ProcessErrno.CANCELED, "preparation root is gone");
|
|
408
|
+
const claims = { ...transport.data };
|
|
409
|
+
for (const key of reservedDescendantData)
|
|
410
|
+
delete claims[key];
|
|
411
|
+
const descendant = Object.freeze({
|
|
412
|
+
pid: state.pid,
|
|
413
|
+
parentPid: state.parentPid,
|
|
414
|
+
job: state.job,
|
|
415
|
+
data: Object.freeze(structuredClone(claims))
|
|
416
|
+
});
|
|
417
|
+
const initial = terminalPreparationReceipt(hook.prepare.terminal, root);
|
|
418
|
+
const record = this.beginPreparation(context, state.rootPid, initial, hook, descendant);
|
|
419
|
+
this.watchPreparation(context, hook, transport, record).catch((error) => {
|
|
420
|
+
record.controller.abort();
|
|
421
|
+
this.report(error);
|
|
422
|
+
});
|
|
423
|
+
try {
|
|
424
|
+
const result = await prepareTerminalDescendant({
|
|
425
|
+
terminal: hook.prepare.terminal,
|
|
426
|
+
root,
|
|
427
|
+
signal: record.controller.signal,
|
|
428
|
+
check: () => this.preparationFailure(context, hook, state.rootPid),
|
|
429
|
+
settled: (receipt) => {
|
|
430
|
+
record.receipt = receipt;
|
|
431
|
+
},
|
|
432
|
+
work: (turn) => hook.prepare.run(descendant, turn),
|
|
433
|
+
finish: (result, receipt) => {
|
|
434
|
+
record.receipt = receipt;
|
|
435
|
+
try {
|
|
436
|
+
if (result.kind === "error")
|
|
437
|
+
throw terminalPreparationError(result.code);
|
|
438
|
+
const failure = this.preparationFailure(context, hook, state.rootPid);
|
|
439
|
+
if (failure)
|
|
440
|
+
throw terminalPreparationError(failure);
|
|
441
|
+
record.phase = "handed-off";
|
|
442
|
+
record.entry = "adapter-invoked";
|
|
443
|
+
wakeDirectory(transport.directory);
|
|
444
|
+
return this.launchAdapter(context);
|
|
445
|
+
} finally {
|
|
446
|
+
record.finish();
|
|
447
|
+
wakeDirectory(transport.directory);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
if (result.kind === "error")
|
|
452
|
+
throw terminalPreparationError(result.code);
|
|
453
|
+
return result.value;
|
|
454
|
+
} finally {
|
|
455
|
+
record.finish();
|
|
456
|
+
wakeDirectory(transport.directory);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
cancelPreparations(pid) {
|
|
460
|
+
for (const record of this.pendingPreparations)
|
|
461
|
+
if (record.phase === "preparing" && (pid === undefined || record.pid === pid || record.rootPid === pid))
|
|
462
|
+
record.controller.abort();
|
|
463
|
+
}
|
|
464
|
+
launchAdapter(context) {
|
|
465
|
+
if (this.suspended)
|
|
466
|
+
throw new Error("Process broker is disposed");
|
|
467
|
+
const transport = this.transport.get(context.pid);
|
|
468
|
+
const command = transport && this.commandScope(transport);
|
|
469
|
+
if (command) {
|
|
470
|
+
this.traceProcess(context, "launching");
|
|
471
|
+
this.checkCommandAdmission(transport);
|
|
472
|
+
}
|
|
473
|
+
this.acquireObservation(context.observation, true);
|
|
474
|
+
const observation = this.observationOwners.get(context.pid);
|
|
475
|
+
const nativeReturned = this.nativeLaunchReturns.get(context.pid) ?? observation?.acquire();
|
|
476
|
+
let controllerReturn;
|
|
477
|
+
const failedLaunch = (error) => {
|
|
478
|
+
const child = this.children.get(context.pid);
|
|
479
|
+
if (child?.generation === context.generation)
|
|
480
|
+
return;
|
|
481
|
+
if (typeof error === "object" && error !== null && this.neverConstructed.get(error) === context.pid) {
|
|
482
|
+
if (context.generation === 1)
|
|
483
|
+
nativeReturned?.();
|
|
484
|
+
} else if (controllerReturn && nativeReturned)
|
|
485
|
+
controllerReturn.follow(nativeReturned);
|
|
486
|
+
else {
|
|
487
|
+
this.imageStops.delete(context.pid);
|
|
488
|
+
observation?.fail(error);
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
const invokeLauncher = () => {
|
|
492
|
+
if ("command" in context)
|
|
493
|
+
return this.launchCommand(context);
|
|
494
|
+
if (command || context.execution?.kind === "host")
|
|
495
|
+
return this.options.launch(context);
|
|
496
|
+
const controller = this.controllerFor(context.pid);
|
|
497
|
+
if (!controller?.launch)
|
|
498
|
+
return this.options.launch(context);
|
|
499
|
+
controllerReturn = this.controllerNativeReturnFor(context.pid);
|
|
500
|
+
const candidate = controller.launch(context);
|
|
501
|
+
if (candidate !== undefined && candidate !== null)
|
|
502
|
+
return candidate;
|
|
503
|
+
controllerReturn = undefined;
|
|
504
|
+
return this.options.launch(context);
|
|
505
|
+
};
|
|
506
|
+
if (nativeReturned)
|
|
507
|
+
this.nativeLaunchReturns.set(context.pid, nativeReturned);
|
|
508
|
+
if (!command)
|
|
509
|
+
this.traceProcess(context, "launching");
|
|
510
|
+
const launch = this.launchState(context);
|
|
511
|
+
launch.active = true;
|
|
512
|
+
(this.launches ??= new Set).add(context.pid);
|
|
513
|
+
let acquireLaunch, settleLaunch;
|
|
514
|
+
const pendingLaunch = {
|
|
515
|
+
observation: context.observation,
|
|
516
|
+
start: processStartRecord(context),
|
|
517
|
+
acquiring: true,
|
|
518
|
+
acquired: new Promise((resolve) => {
|
|
519
|
+
acquireLaunch = resolve;
|
|
520
|
+
}),
|
|
521
|
+
settled: new Promise((resolve) => {
|
|
522
|
+
settleLaunch = resolve;
|
|
523
|
+
})
|
|
524
|
+
};
|
|
525
|
+
launch.pending = pendingLaunch;
|
|
526
|
+
this.settledGroupAcquisitions.delete(observationKey(context.observation));
|
|
527
|
+
(this.pendingLaunches ??= new Map).set(context.pid, pendingLaunch);
|
|
528
|
+
const settled = () => {
|
|
529
|
+
pendingLaunch.acquiring = false;
|
|
530
|
+
this.settledGroupAcquisitions.add(observationKey(context.observation));
|
|
531
|
+
launch.pending = undefined;
|
|
532
|
+
if (this.pendingLaunches?.get(context.pid) === pendingLaunch)
|
|
533
|
+
this.pendingLaunches.delete(context.pid);
|
|
534
|
+
this.releaseAcquiredProcess(context.pid);
|
|
535
|
+
acquireLaunch();
|
|
536
|
+
settleLaunch();
|
|
537
|
+
this.groups?.settleStopping();
|
|
538
|
+
};
|
|
539
|
+
let launched;
|
|
540
|
+
try {
|
|
541
|
+
launched = invokeLauncher();
|
|
542
|
+
} catch (error) {
|
|
543
|
+
failedLaunch(error);
|
|
544
|
+
launch.active = false;
|
|
545
|
+
this.launches.delete(context.pid);
|
|
546
|
+
settled();
|
|
547
|
+
throw error;
|
|
548
|
+
}
|
|
549
|
+
const track = (handle) => {
|
|
550
|
+
pendingLaunch.acquiring = false;
|
|
551
|
+
this.settledGroupAcquisitions.add(observationKey(context.observation));
|
|
552
|
+
this.traceProcess(context, "launched");
|
|
553
|
+
const terminal = this.terminalLifetimes.get(context.pid);
|
|
554
|
+
if (this.children.has(context.pid) || !this.controllerFor(context.pid)) {
|
|
555
|
+
const child = this.children.get(context.pid);
|
|
556
|
+
const adapter = child?.generation === context.generation ? child.adapter = ownedAdapterHandle(handle) : undefined;
|
|
557
|
+
launch.active = false;
|
|
558
|
+
this.launches?.delete(context.pid);
|
|
559
|
+
settled();
|
|
560
|
+
return this.children.has(context.pid) ? adapter ?? handle : this.bindRootGroup(context.pid, nativeStopHandle(handle, terminal, nativeReturned, () => observation?.close(), (error) => observation?.fail(error)));
|
|
561
|
+
}
|
|
562
|
+
acquireLaunch();
|
|
563
|
+
const ownedHandle = this.bindRootGroup(context.pid, nativeStopHandle(handle, terminal, nativeReturned, () => observation?.close(), (error) => observation?.fail(error)));
|
|
564
|
+
this.groups?.settleStopping();
|
|
565
|
+
return {
|
|
566
|
+
terminate: () => {
|
|
567
|
+
let pending;
|
|
568
|
+
try {
|
|
569
|
+
const stopped = ownedHandle.terminate();
|
|
570
|
+
const stopController = this.controllerNativeStopFor(context.pid);
|
|
571
|
+
const stopCapturedController = () => stopController?.terminate();
|
|
572
|
+
pending = stopped ? stopped.then(stopCapturedController) : stopCapturedController();
|
|
573
|
+
} catch (error) {
|
|
574
|
+
settled();
|
|
575
|
+
throw error;
|
|
576
|
+
}
|
|
577
|
+
if (pending) {
|
|
578
|
+
const stopping = pending.then(() => {
|
|
579
|
+
this.controllerStops?.delete(context.pid);
|
|
580
|
+
launch.active = false;
|
|
581
|
+
this.launches?.delete(context.pid);
|
|
582
|
+
this.retireChildController(context.pid);
|
|
583
|
+
}).finally(settled);
|
|
584
|
+
(this.controllerStops ??= new Map).set(context.pid, {
|
|
585
|
+
pending: stopping,
|
|
586
|
+
controllerStop: false
|
|
587
|
+
});
|
|
588
|
+
return stopping;
|
|
589
|
+
}
|
|
590
|
+
launch.active = false;
|
|
591
|
+
this.launches?.delete(context.pid);
|
|
592
|
+
this.retireChildController(context.pid);
|
|
593
|
+
settled();
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
};
|
|
597
|
+
if (!("then" in launched))
|
|
598
|
+
return track(launched);
|
|
599
|
+
return Promise.resolve(launched).then(track, (error) => {
|
|
600
|
+
failedLaunch(error);
|
|
601
|
+
launch.active = false;
|
|
602
|
+
this.launches?.delete(context.pid);
|
|
603
|
+
settled();
|
|
604
|
+
if (readOutcome(context.outcome))
|
|
605
|
+
this.stopController(context.pid)?.catch((error) => this.report(error));
|
|
606
|
+
throw error;
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
launchCommand(context) {
|
|
610
|
+
const launch = this.options.launchCommand;
|
|
611
|
+
if (!launch)
|
|
612
|
+
throw new ProcessError(45, "Host commands are unavailable");
|
|
613
|
+
const record = this.options.table.require(context.pid);
|
|
614
|
+
const rootPid = record.rootPid;
|
|
615
|
+
if (rootPid === undefined)
|
|
616
|
+
throw new ProcessError(ProcessErrno.SRCH, "Command root is missing");
|
|
617
|
+
const root = this.options.table.require(rootPid);
|
|
618
|
+
const processes = Object.freeze({
|
|
619
|
+
snapshot: () => {
|
|
620
|
+
if (this.suspended || record.revoked || root.revoked || this.options.table.get(rootPid) !== root || readOutcome(root.outcome) || readOutcome(record.outcome) || context.command.definition.admission?.aborted || this.options.table.get(record.pid) !== record)
|
|
621
|
+
throw new CommandStdioError("CANCELED");
|
|
622
|
+
const rows = [];
|
|
623
|
+
for (const row of this.options.table.values()) {
|
|
624
|
+
if (row.rootPid !== rootPid || !row.image.request || row.revoked || row.state === "exited" || readOutcome(row.outcome))
|
|
625
|
+
continue;
|
|
626
|
+
rows.push({
|
|
627
|
+
pid: row.pid,
|
|
628
|
+
parentPid: row.parentPid,
|
|
629
|
+
executable: row.image.request.executable,
|
|
630
|
+
argv: row.image.request.argv.slice(),
|
|
631
|
+
state: row.state
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
return rows.sort((left, right) => left.pid - right.pid);
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
const transport = this.transport.get(context.pid);
|
|
638
|
+
const identity = transport ? this.filesystem(transport) : this.controllerFor(context.pid)?.filesystem;
|
|
639
|
+
if (identity)
|
|
640
|
+
context.registerRevocation(() => this.options.filesystem.revoke(identity));
|
|
641
|
+
const connectFilesystem = identity ? () => {
|
|
642
|
+
if (this.suspended || record.revoked || readOutcome(record.outcome))
|
|
643
|
+
throw new CommandStdioError("CANCELED");
|
|
644
|
+
return this.options.filesystem.connect(identity);
|
|
645
|
+
} : undefined;
|
|
646
|
+
return launch(context, {
|
|
647
|
+
processes,
|
|
648
|
+
signals: this.commandSignals(context, record, rootPid),
|
|
649
|
+
connectFilesystem
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
commandSignals(context, holder, rootPid) {
|
|
653
|
+
const definition = context.command.definition;
|
|
654
|
+
const policy = this.signalPolicies.get(rootPid);
|
|
655
|
+
const anchor = this.options.table.get(rootPid);
|
|
656
|
+
if (definition.signals !== "delegated" || !definition.owner || !policy || !anchor || !policy.packages.has(definition.owner))
|
|
657
|
+
return null;
|
|
658
|
+
const live = () => !this.suspended && !holder.revoked && !anchor.revoked && !definition.admission?.aborted && this.options.table.get(holder.pid) === holder && this.options.table.get(anchor.pid) === anchor && this.signalPolicies.get(anchor.pid) === policy && this.controllerFor(anchor.pid) === policy.controller && !readOutcome(holder.outcome) && !readOutcome(anchor.outcome);
|
|
659
|
+
return Object.freeze({
|
|
660
|
+
send: (pid, signal) => {
|
|
661
|
+
const sig = checkedSignal(signal);
|
|
662
|
+
if (!live())
|
|
663
|
+
return "revoked";
|
|
664
|
+
const target = this.options.table.get(pid);
|
|
665
|
+
if (!target || target.revoked || readOutcome(target.outcome))
|
|
666
|
+
return "missing";
|
|
667
|
+
if (target.rootPid !== anchor.pid || target === anchor)
|
|
668
|
+
return "denied";
|
|
669
|
+
this.publishProcessSignal(pid, sig, target);
|
|
670
|
+
return "sent";
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
registerController(pid, controller) {
|
|
675
|
+
if (this.suspended)
|
|
676
|
+
throw new Error("Process broker is disposed");
|
|
677
|
+
if (this.controllerFor(pid))
|
|
678
|
+
throw new Error(`Process ${pid} already has a controller`);
|
|
679
|
+
const observation = this.reservedRoots.get(pid)?.observation ?? this.options.table.get(pid)?.observation;
|
|
680
|
+
if (observation)
|
|
681
|
+
this.acquireObservation(observation);
|
|
682
|
+
const stop = controller.stop;
|
|
683
|
+
const capturedStop = stop ? () => reflectApply(stop, controller, []) : undefined;
|
|
684
|
+
const child = this.children.get(pid);
|
|
685
|
+
const revoke = this.controllerRevocation(controller);
|
|
686
|
+
if (child) {
|
|
687
|
+
child.revokeController = revoke;
|
|
688
|
+
child.controller = controller;
|
|
689
|
+
child.capturedControllerStop = capturedStop;
|
|
690
|
+
} else if (capturedStop)
|
|
691
|
+
this.capturedControllerStops.set(pid, capturedStop);
|
|
692
|
+
if (child)
|
|
693
|
+
child.controller = controller;
|
|
694
|
+
else {
|
|
695
|
+
this.controllers.set(pid, controller);
|
|
696
|
+
this.capturedControllerRevocations.set(pid, revoke);
|
|
697
|
+
}
|
|
698
|
+
this.captureControllerStop(pid);
|
|
699
|
+
this.acquireController(pid);
|
|
700
|
+
if (this.supervisor?.get(pid))
|
|
701
|
+
this.supervisor.registerCurrentImageRevocation(pid, revoke);
|
|
702
|
+
}
|
|
703
|
+
reserveRoot(root, controller = {}) {
|
|
704
|
+
if (this.suspended)
|
|
705
|
+
throw new Error("Process broker is disposed");
|
|
706
|
+
const initialCwd = root.cwd;
|
|
707
|
+
const cwd = checkedProcessCwd(initialCwd === undefined ? "/" : initialCwd);
|
|
708
|
+
const pid = root.pid ?? this.options.identities.pid(), job = root.job ?? this.options.identities.job();
|
|
709
|
+
this.options.identities.observePid(pid);
|
|
710
|
+
this.options.identities.observeJob(job);
|
|
711
|
+
const word = (value) => value instanceof TaggedCells ? value : value instanceof Int32Array ? value : new Int32Array(value ?? allocateSharedControl(4));
|
|
712
|
+
const reserved = {
|
|
713
|
+
...root,
|
|
714
|
+
pid,
|
|
715
|
+
job,
|
|
716
|
+
cwd,
|
|
717
|
+
signalState: createSignalState(root.signalState),
|
|
718
|
+
outcome: outcomeWord(root.outcome),
|
|
719
|
+
interrupt: word(root.interrupt),
|
|
720
|
+
requestedSignal: word(root.requestedSignal),
|
|
721
|
+
processIdentity: snapshotLogicalProcessIdentity({ pid, parentPid: 0 })
|
|
722
|
+
};
|
|
723
|
+
const observation = admitProcessObservation(pid, reserved.outcome, root.observation);
|
|
724
|
+
const admitted = { ...reserved, observation };
|
|
725
|
+
this.acquireObservation(observation);
|
|
726
|
+
const packages = controller.signalDelegation?.packages;
|
|
727
|
+
const policy = packages ? { controller, packages: new Set(packages.map((pkg) => packageIdentity(pkg))) } : undefined;
|
|
728
|
+
if (this.controllerFor(pid))
|
|
729
|
+
throw new Error(`Process ${pid} already has a controller`);
|
|
730
|
+
this.supervisor?.createRoot(admitted);
|
|
731
|
+
this.registerController(pid, controller);
|
|
732
|
+
this.reservedRoots.set(pid, admitted);
|
|
733
|
+
if (policy)
|
|
734
|
+
this.signalPolicies.set(pid, policy);
|
|
735
|
+
return pid;
|
|
736
|
+
}
|
|
737
|
+
retainRoot(pid) {
|
|
738
|
+
if (this.suspended)
|
|
739
|
+
throw new Error("Process broker is disposed");
|
|
740
|
+
if (!this.reservedRoots.has(pid))
|
|
741
|
+
throw new Error(`Unknown root process ${pid}`);
|
|
742
|
+
const releaseObservation = this.observationOwners.get(pid)?.acquire();
|
|
743
|
+
this.rootLeases.set(pid, (this.rootLeases.get(pid) ?? 0) + 1);
|
|
744
|
+
let released = false;
|
|
745
|
+
return () => {
|
|
746
|
+
if (released)
|
|
747
|
+
return;
|
|
748
|
+
released = true;
|
|
749
|
+
releaseObservation?.();
|
|
750
|
+
const remaining = (this.rootLeases.get(pid) ?? 1) - 1;
|
|
751
|
+
if (remaining)
|
|
752
|
+
this.rootLeases.set(pid, remaining);
|
|
753
|
+
else
|
|
754
|
+
this.rootLeases.delete(pid);
|
|
755
|
+
this.retireRoots();
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
retainsRoot(transport, pid, job) {
|
|
759
|
+
if (Array.from(directoryGroups(transport.directory)).some((group) => group.id !== job))
|
|
760
|
+
return true;
|
|
761
|
+
return Array.from(directoryProcesses(transport.directory)).some((state) => {
|
|
762
|
+
try {
|
|
763
|
+
return state.pid !== pid && (controlLoad(state.confirmed, 0) === 0 || state.job !== job && controlLoad(state.jobPending, 0) >= 0);
|
|
764
|
+
} catch (error) {
|
|
765
|
+
if (!isCollectedProcess(error))
|
|
766
|
+
throw error;
|
|
767
|
+
return false;
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
retireRoots() {
|
|
772
|
+
if (this.suspended)
|
|
773
|
+
return;
|
|
774
|
+
for (const pid of this.completedRoots) {
|
|
775
|
+
if (this.rootLeases.has(pid))
|
|
776
|
+
continue;
|
|
777
|
+
if (Array.from(this.options.table.values()).some((record) => record.pid !== pid && record.rootPid === pid && !record.result))
|
|
778
|
+
continue;
|
|
779
|
+
const transport = this.roots.get(pid), root = this.reservedRoots.get(pid);
|
|
780
|
+
if (transport && this.retainsRoot(transport, pid, root?.job))
|
|
781
|
+
continue;
|
|
782
|
+
const controller = this.controllerFor(pid);
|
|
783
|
+
this.observationOwners.get(pid)?.close();
|
|
784
|
+
this.transport.releaseRoot(pid);
|
|
785
|
+
this.options.table.remove(pid);
|
|
786
|
+
if (root && !this.options.table.job(root.job)?.members.size)
|
|
787
|
+
this.options.table.removeJob(root.job);
|
|
788
|
+
this.completedRoots.delete(pid);
|
|
789
|
+
this.commandRoots?.delete(pid);
|
|
790
|
+
this.reservedRoots.delete(pid);
|
|
791
|
+
this.descendantHooks.delete(pid);
|
|
792
|
+
this.signalPolicies.delete(pid);
|
|
793
|
+
if (controller && this.capturedControllerStops.has(pid))
|
|
794
|
+
this.retainedRootStops.set(pid, controller);
|
|
795
|
+
this.controllers.delete(pid);
|
|
796
|
+
this.capturedControllerRevocations.delete(pid);
|
|
797
|
+
this.quiescedControllers.delete(pid);
|
|
798
|
+
this.revokedControllers.delete(pid);
|
|
799
|
+
this.roots.delete(pid);
|
|
800
|
+
this.outputs.delete(pid);
|
|
801
|
+
this.retireTerminalOutput(pid);
|
|
802
|
+
this.registries.delete(pid);
|
|
803
|
+
this.fences.delete(pid);
|
|
804
|
+
this.releaseAcquiredProcess(pid);
|
|
805
|
+
try {
|
|
806
|
+
controller?.retired?.();
|
|
807
|
+
} catch (error) {
|
|
808
|
+
this.report(error);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
async adoptRoot(root, controller = {}) {
|
|
813
|
+
const ticket = this.options.reservations.admit({
|
|
814
|
+
pid: root.pid ?? 0,
|
|
815
|
+
executable: "external root",
|
|
816
|
+
guest: { kind: "declared", memories: root.memory },
|
|
817
|
+
group: "none",
|
|
818
|
+
connection: false,
|
|
819
|
+
controls: true
|
|
820
|
+
});
|
|
821
|
+
let pid;
|
|
822
|
+
try {
|
|
823
|
+
pid = this.reserveRoot(root, controller);
|
|
824
|
+
} catch (error) {
|
|
825
|
+
ticket.abort();
|
|
826
|
+
throw error;
|
|
827
|
+
}
|
|
828
|
+
this.rootAdmissions.set(pid, ticket);
|
|
829
|
+
this.rootTickets.set(pid, ticket.launched());
|
|
830
|
+
this.rootGrants.set(pid, ticket.control);
|
|
831
|
+
await this.ready();
|
|
832
|
+
if (this.suspended)
|
|
833
|
+
throw new Error("Process broker is disposed");
|
|
834
|
+
return pid;
|
|
835
|
+
}
|
|
836
|
+
async adoptRuntimeRoot(transport, options) {
|
|
837
|
+
if (this.suspended)
|
|
838
|
+
throw new Error("Process broker is disposed");
|
|
839
|
+
const cwd = checkedProcessCwd(transport.cwd);
|
|
840
|
+
const state = workerProcessState(transport);
|
|
841
|
+
if (this.controllerFor(state.pid))
|
|
842
|
+
throw new Error(`Process ${state.pid} already has a controller`);
|
|
843
|
+
if (state.parentPid !== 0)
|
|
844
|
+
throw new TypeError("root process has a parent");
|
|
845
|
+
if (state.processKind !== "process" || state.processIdentity.pid !== state.pid || state.processIdentity.parentPid !== 0)
|
|
846
|
+
throw new ProcessError(ProcessErrno.INVAL, "root process identity conflicts with reservation");
|
|
847
|
+
const existing = this.transport.get(state.pid);
|
|
848
|
+
if (existing && workerProcessDirectoryId(existing) !== workerProcessDirectoryId(transport))
|
|
849
|
+
throw new TypeError("process identity is already registered");
|
|
850
|
+
if (transport.identity !== this.options.identities.buffer)
|
|
851
|
+
throw new TypeError("root must borrow the runtime identity allocator");
|
|
852
|
+
this.filesystem(transport);
|
|
853
|
+
const data = transport.data;
|
|
854
|
+
if (data.pipeRegistry && !this.options.reservations.ownsBuffer("pipe-registry", data.pipeRegistry.buffer))
|
|
855
|
+
throw new TypeError("Root bootstrap requires a ledger-charged registry");
|
|
856
|
+
const guestControls = this.commandRoots?.get(state.pid)?.root !== transport;
|
|
857
|
+
const ticket = this.options.reservations.admit({
|
|
858
|
+
pid: workerProcessState(transport).pid,
|
|
859
|
+
executable: "adopted root",
|
|
860
|
+
guest: options.memory === "group" ? { kind: "group" } : { kind: "declared", memories: options.memory },
|
|
861
|
+
group: "none",
|
|
862
|
+
connection: false,
|
|
863
|
+
controls: guestControls
|
|
864
|
+
});
|
|
865
|
+
const previousData = transport.data;
|
|
866
|
+
let changedData = false;
|
|
867
|
+
let registeredRegistry;
|
|
868
|
+
try {
|
|
869
|
+
const output = rootOutput(options);
|
|
870
|
+
const prepare = options.prepareDescendant;
|
|
871
|
+
const descendant = prepare ? {
|
|
872
|
+
prepare: Object.freeze({
|
|
873
|
+
terminal: prepare.terminal,
|
|
874
|
+
run: prepare.run,
|
|
875
|
+
settled: prepare.settled
|
|
876
|
+
}),
|
|
877
|
+
directory: workerProcessDirectoryId(transport)
|
|
878
|
+
} : undefined;
|
|
879
|
+
const registry = data.pipeRegistry ? attachPipePublicationRegistry(data.pipeRegistry) : new PipePublicationRegistry({
|
|
880
|
+
wake: state.wake,
|
|
881
|
+
allocate: (length, maximum) => this.options.reservations.buffer("pipe-registry", {
|
|
882
|
+
kind: "growable-buffer",
|
|
883
|
+
initial: length,
|
|
884
|
+
maximum: bytes(maximum)
|
|
885
|
+
})
|
|
886
|
+
});
|
|
887
|
+
const bootstrap = { ...data, pipeRegistry: registry.handle() };
|
|
888
|
+
const registered = !registry.isRevoked(state.pid);
|
|
889
|
+
registry.registerProcess(state.pid);
|
|
890
|
+
if (!registered)
|
|
891
|
+
registeredRegistry = registry;
|
|
892
|
+
transport.data = bootstrap;
|
|
893
|
+
changedData = true;
|
|
894
|
+
this.acquireProcess(transport);
|
|
895
|
+
this.reserveRoot({ pid: state.pid, job: state.job, cwd, observation: transport, ...state.signals }, options);
|
|
896
|
+
this.transport.adoptRoot(transport);
|
|
897
|
+
this.roots.set(state.pid, transport);
|
|
898
|
+
this.acquireController(state.pid);
|
|
899
|
+
this.outputs.set(state.pid, output);
|
|
900
|
+
this.registries.set(state.pid, registry);
|
|
901
|
+
if (descendant)
|
|
902
|
+
this.descendantHooks.set(state.pid, descendant);
|
|
903
|
+
this.rootAdmissions.set(state.pid, ticket);
|
|
904
|
+
this.rootTickets.set(state.pid, ticket.launched());
|
|
905
|
+
if (guestControls)
|
|
906
|
+
this.rootGrants.set(state.pid, ticket.control);
|
|
907
|
+
} catch (error) {
|
|
908
|
+
if (changedData)
|
|
909
|
+
transport.data = previousData;
|
|
910
|
+
registeredRegistry?.collectProcess(state.pid);
|
|
911
|
+
ticket.abort();
|
|
912
|
+
throw error;
|
|
913
|
+
}
|
|
914
|
+
if (this.activation) {
|
|
915
|
+
const supervisor = await this.activation;
|
|
916
|
+
if (this.suspended)
|
|
917
|
+
throw new Error("Process broker is disposed");
|
|
918
|
+
this.activateRuntimeRoot(supervisor, transport);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
async adoptCommandRoot(transport, options) {
|
|
922
|
+
if (this.suspended || !this.supervisor)
|
|
923
|
+
throw new Error("Process broker is unavailable");
|
|
924
|
+
const processCapacity = directoryCapacity(transport.directory);
|
|
925
|
+
const registry = new PipePublicationRegistry({
|
|
926
|
+
processCapacity,
|
|
927
|
+
cellsPerProcess: 16,
|
|
928
|
+
maxCells: processCapacity * 128,
|
|
929
|
+
wake: workerProcessState(transport).wake,
|
|
930
|
+
allocate: (length, maximum) => this.options.reservations.buffer("pipe-registry", {
|
|
931
|
+
kind: "growable-buffer",
|
|
932
|
+
initial: length,
|
|
933
|
+
maximum: bytes(maximum)
|
|
934
|
+
})
|
|
935
|
+
});
|
|
936
|
+
initializeCommandExec(transport);
|
|
937
|
+
transport.data = { filesystem: options.filesystem, pipeRegistry: registry.handle() };
|
|
938
|
+
(this.commandRoots ??= new Map).set(transport.pid, {
|
|
939
|
+
root: transport,
|
|
940
|
+
pending: new Set,
|
|
941
|
+
failures: new Map,
|
|
942
|
+
stopped: false
|
|
943
|
+
});
|
|
944
|
+
try {
|
|
945
|
+
await this.adoptRuntimeRoot(transport, options);
|
|
946
|
+
} catch (error) {
|
|
947
|
+
if (!this.roots.has(transport.pid))
|
|
948
|
+
this.commandRoots?.delete(transport.pid);
|
|
949
|
+
throw error;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
commandScope(transport) {
|
|
953
|
+
if (!this.commandRoots?.size)
|
|
954
|
+
return;
|
|
955
|
+
let rootPid;
|
|
956
|
+
try {
|
|
957
|
+
rootPid = workerProcessState(transport).rootPid;
|
|
958
|
+
} catch (error) {
|
|
959
|
+
if (!isCollectedProcess(error))
|
|
960
|
+
throw error;
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
const scope = this.commandRoots.get(rootPid);
|
|
964
|
+
if (scope && workerProcessDirectoryId(scope.root) === workerProcessDirectoryId(transport))
|
|
965
|
+
return scope;
|
|
966
|
+
}
|
|
967
|
+
checkCommandAdmission(transport) {
|
|
968
|
+
const scope = this.commandScope(transport);
|
|
969
|
+
if (scope && this.commandAdmissionClosed(scope))
|
|
970
|
+
throw new ProcessError(ProcessErrno.SRCH, "Command is stopping");
|
|
971
|
+
}
|
|
972
|
+
commandAdmissionClosed(scope) {
|
|
973
|
+
return scope.stopped || scope.failures.size !== 0 || commandTransferFailed(scope.root.commandTransfer);
|
|
974
|
+
}
|
|
975
|
+
trackCommandTransfer(transport, cleanup) {
|
|
976
|
+
const scope = this.commandScope(transport);
|
|
977
|
+
if (!scope)
|
|
978
|
+
return cleanup();
|
|
979
|
+
const pending = Promise.resolve().then(cleanup);
|
|
980
|
+
scope.pending.add(pending);
|
|
981
|
+
const settle = () => {
|
|
982
|
+
scope.pending.delete(pending);
|
|
983
|
+
wakeWorkerProcess(scope.root);
|
|
984
|
+
};
|
|
985
|
+
pending.then(settle, (error) => {
|
|
986
|
+
scope.failures.set(transport, error);
|
|
987
|
+
settle();
|
|
988
|
+
});
|
|
989
|
+
return pending;
|
|
990
|
+
}
|
|
991
|
+
async retireRejectedCommand(transport) {
|
|
992
|
+
const returned = this.processNativeReturn(transport);
|
|
993
|
+
if (this.acquiredProcesses.get(transport.pid) === this.processLifetime(transport)) {
|
|
994
|
+
await this.retireProcess(transport.pid, true);
|
|
995
|
+
this.retireChildController(transport.pid);
|
|
996
|
+
}
|
|
997
|
+
returned();
|
|
998
|
+
}
|
|
999
|
+
commandCleanupFailure(scope) {
|
|
1000
|
+
if (scope.failures.size) {
|
|
1001
|
+
const [cause] = scope.failures.values();
|
|
1002
|
+
return new Error("Command transfer cleanup failed", { cause });
|
|
1003
|
+
}
|
|
1004
|
+
const buffer = scope.root.commandTransfer;
|
|
1005
|
+
return buffer ? readCommandTransferFailure(buffer)?.error : undefined;
|
|
1006
|
+
}
|
|
1007
|
+
async joinCommandExec(transport) {
|
|
1008
|
+
const scope = this.commandScope(transport);
|
|
1009
|
+
const handoff = commandExecTransfer(transport);
|
|
1010
|
+
if (!scope || !handoff)
|
|
1011
|
+
return;
|
|
1012
|
+
const state = workerProcessState(transport);
|
|
1013
|
+
for (;; ) {
|
|
1014
|
+
const expected = Atomics.load(state.wake, 0);
|
|
1015
|
+
const buffer = scope.root.commandTransfer;
|
|
1016
|
+
const local = buffer && readCommandTransferFailure(buffer);
|
|
1017
|
+
if (local?.kind === "exec" && local.pid === transport.pid && local.generation === transport.generation)
|
|
1018
|
+
throw local.error;
|
|
1019
|
+
const staged = controlLoad(handoff);
|
|
1020
|
+
if (staged === 0)
|
|
1021
|
+
return;
|
|
1022
|
+
for (const [transfer, cause] of scope.failures) {
|
|
1023
|
+
if (transfer.pid === transport.pid && transfer.generation === staged)
|
|
1024
|
+
throw new Error("Exec transfer cleanup failed", { cause });
|
|
1025
|
+
}
|
|
1026
|
+
await atomicsWaitAsync(state.wake, 0, expected).value;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
commandPipeHost(transport, postMessage) {
|
|
1030
|
+
const registry = this.registries.get(transport.pid);
|
|
1031
|
+
if (!registry || !this.commandRoots?.has(transport.pid))
|
|
1032
|
+
throw new Error("Command root is not admitted");
|
|
1033
|
+
return new WorkerPipeHost({
|
|
1034
|
+
transport,
|
|
1035
|
+
registry,
|
|
1036
|
+
postMessage,
|
|
1037
|
+
allocateShared: (length) => this.options.reservations.buffer("control", {
|
|
1038
|
+
kind: "fixed-buffer",
|
|
1039
|
+
length: bytes(length)
|
|
1040
|
+
})
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
stopCommandRoot(root) {
|
|
1044
|
+
const scope = this.commandRoots?.get(root.pid);
|
|
1045
|
+
if (!scope || scope.stopped)
|
|
1046
|
+
return;
|
|
1047
|
+
scope.stopped = true;
|
|
1048
|
+
this.stopCommandMembers(root);
|
|
1049
|
+
wakeWorkerProcess(root);
|
|
1050
|
+
}
|
|
1051
|
+
stopCommandMembers(root) {
|
|
1052
|
+
const members = Array.from(directoryProcesses(root.directory)).filter((state) => {
|
|
1053
|
+
try {
|
|
1054
|
+
return state.pid !== root.pid && !readOutcome(state.signals.outcome);
|
|
1055
|
+
} catch (error) {
|
|
1056
|
+
if (!isCollectedProcess(error))
|
|
1057
|
+
throw error;
|
|
1058
|
+
return false;
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
for (const state of members)
|
|
1062
|
+
this.requestSignalIfPresent(state.signals, 9);
|
|
1063
|
+
for (const state of members) {
|
|
1064
|
+
try {
|
|
1065
|
+
this.revokeRuntimeProcess(state.pid, workerProcessDirectoryId(root));
|
|
1066
|
+
} catch (error) {
|
|
1067
|
+
if (!isCollectedProcess(error))
|
|
1068
|
+
throw error;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
checkCommandCleanup(root, mayCollect) {
|
|
1073
|
+
const scope = this.commandRoots?.get(root.pid);
|
|
1074
|
+
const supervisor = this.supervisor;
|
|
1075
|
+
if (!scope || !supervisor)
|
|
1076
|
+
throw new Error("Command root is not admitted");
|
|
1077
|
+
const version = idleDirectoryAdmission(root.directory);
|
|
1078
|
+
if (scope.stopped)
|
|
1079
|
+
this.stopCommandMembers(root);
|
|
1080
|
+
this.transport.pump();
|
|
1081
|
+
this.serviceTerminalOutput(root.pid);
|
|
1082
|
+
const failure = this.commandCleanupFailure(scope);
|
|
1083
|
+
if (failure)
|
|
1084
|
+
throw failure;
|
|
1085
|
+
const retired = supervisor.rootConsumersRetired(root.pid);
|
|
1086
|
+
if (!mayCollect)
|
|
1087
|
+
return false;
|
|
1088
|
+
const ownJob = workerProcessState(root).job;
|
|
1089
|
+
for (const group of directoryGroups(root.directory)) {
|
|
1090
|
+
if (group.id === ownJob)
|
|
1091
|
+
continue;
|
|
1092
|
+
try {
|
|
1093
|
+
if (supervisor.job(group.id)) {
|
|
1094
|
+
if (supervisor.jobCleanupReady(root.pid, group.id))
|
|
1095
|
+
supervisor.reapJob(root.pid, group.id);
|
|
1096
|
+
} else if (controlLoad(group.pending) === 0) {
|
|
1097
|
+
collectDirectoryJob(root.directory, group.slot, group.id);
|
|
1098
|
+
}
|
|
1099
|
+
} catch (error) {
|
|
1100
|
+
if (!isCollectedProcess(error))
|
|
1101
|
+
throw error;
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
return retired && scope.pending.size === 0 && !Array.from(directoryGroups(root.directory)).some((group) => group.id !== ownJob) && !this.terminalOutputs.get(root.pid)?.pending() && version !== undefined && idleDirectoryAdmission(root.directory) === version;
|
|
1105
|
+
}
|
|
1106
|
+
async retireCommandRoot(root) {
|
|
1107
|
+
const owner = this.observationOwners.get(root.pid);
|
|
1108
|
+
await this.quiesceProcess(root.pid);
|
|
1109
|
+
await this.rootExit(root.pid, 0);
|
|
1110
|
+
this.rootStopped(root.pid);
|
|
1111
|
+
await owner?.join();
|
|
1112
|
+
this.pipes.pump();
|
|
1113
|
+
}
|
|
1114
|
+
bindPipeRegistry(transport) {
|
|
1115
|
+
const state = workerProcessState(transport);
|
|
1116
|
+
const registry = this.registries.get(state.rootPid);
|
|
1117
|
+
if (!registry)
|
|
1118
|
+
throw new ProcessError(ProcessErrno.SRCH, "Process has no admitted pipe registry");
|
|
1119
|
+
registry.registerProcess(state.pid);
|
|
1120
|
+
const data = transport.data;
|
|
1121
|
+
if (!data || typeof data !== "object")
|
|
1122
|
+
throw new TypeError("Process has no bootstrap data");
|
|
1123
|
+
transport.data = { ...data, pipeRegistry: registry.handle() };
|
|
1124
|
+
}
|
|
1125
|
+
activateRuntimeRoot(supervisor, transport) {
|
|
1126
|
+
const state = workerProcessState(transport);
|
|
1127
|
+
if (!supervisor.get(state.pid))
|
|
1128
|
+
supervisor.createRoot({
|
|
1129
|
+
observation: transport,
|
|
1130
|
+
pid: state.pid,
|
|
1131
|
+
job: state.job,
|
|
1132
|
+
cwd: transport.cwd,
|
|
1133
|
+
...state.signals
|
|
1134
|
+
});
|
|
1135
|
+
supervisor.registerRevocation(state.pid, () => this.revokeRuntimeProcess(state.pid));
|
|
1136
|
+
installWorkerBindings(transport, supervisor.get(state.pid).image.descriptors, this.descriptorCodec(transport));
|
|
1137
|
+
const result = readOutcome(state.signals.outcome);
|
|
1138
|
+
if (result?.kind === "signaled")
|
|
1139
|
+
supervisor.defaultSignal(state.pid, result.code);
|
|
1140
|
+
else if (result)
|
|
1141
|
+
supervisor.exit(state.pid, result.code);
|
|
1142
|
+
}
|
|
1143
|
+
filesystem(transport) {
|
|
1144
|
+
const identity = transport.data?.filesystem;
|
|
1145
|
+
if (!identity || typeof identity !== "object" || !Number.isSafeInteger(identity.owner) || identity.owner <= 0 || ![
|
|
1146
|
+
identity.epoch,
|
|
1147
|
+
identity.signal,
|
|
1148
|
+
identity.shared,
|
|
1149
|
+
identity.capabilities,
|
|
1150
|
+
identity.sections,
|
|
1151
|
+
identity.ownerStates,
|
|
1152
|
+
identity.requestBudget
|
|
1153
|
+
].every((buffer) => buffer instanceof SharedArrayBuffer && buffer.byteLength >= 4) || identity.ownerStates.byteLength < (identity.owner + 1) * 4 || !Array.isArray(identity.revocations) || !identity.revocations.length || !identity.revocations.every((buffer) => buffer instanceof SharedArrayBuffer && buffer.byteLength >= 4) || !Array.isArray(identity.segments) || !identity.segments.every((buffer) => buffer instanceof SharedArrayBuffer) || !Array.isArray(identity.reservations) || !Number.isFinite(identity.maxBytes))
|
|
1154
|
+
throw new TypeError("runtime process has no valid filesystem identity");
|
|
1155
|
+
return identity;
|
|
1156
|
+
}
|
|
1157
|
+
descriptorCodec(transport) {
|
|
1158
|
+
return this.pipes.codec(createRuntimeTerminalCodec({
|
|
1159
|
+
fallback: createFilesystemDescriptorCodec(this.filesystem(transport), undefined, () => this.options.filesystem.sweep?.()),
|
|
1160
|
+
output: deliveredTerminalOutput((target, data) => {
|
|
1161
|
+
const destination = this.outputFor(workerProcessState(transport).pid);
|
|
1162
|
+
return destination ? destination(target, data) : data.length;
|
|
1163
|
+
})
|
|
1164
|
+
}));
|
|
1165
|
+
}
|
|
1166
|
+
discardCodec() {
|
|
1167
|
+
return this.cleanupCodec ??= this.pipes.codec(createRuntimeTerminalCodec({
|
|
1168
|
+
fallback: createFilesystemDescriptorCodec(undefined, undefined, () => this.options.filesystem.sweep?.())
|
|
1169
|
+
}));
|
|
1170
|
+
}
|
|
1171
|
+
processLifetime(transport) {
|
|
1172
|
+
return `${workerProcessDirectoryId(transport)}:${transport.slot}:${transport.pid}`;
|
|
1173
|
+
}
|
|
1174
|
+
runtimeProcessLifetime(pid) {
|
|
1175
|
+
for (const root of this.roots.values()) {
|
|
1176
|
+
const state = Array.from(directoryProcesses(root.directory)).find((state) => state.pid === pid);
|
|
1177
|
+
if (state)
|
|
1178
|
+
return {
|
|
1179
|
+
key: `${workerProcessDirectoryId(root)}:${state.slot}:${pid}`,
|
|
1180
|
+
terminal: captureTerminalLifetime({ directory: root.directory, slot: state.slot, pid })
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
processNativeReturn(transport) {
|
|
1186
|
+
this.acquireController(transport.pid);
|
|
1187
|
+
const acquired = this.acquiredProcesses.get(transport.pid);
|
|
1188
|
+
const existing = this.observationOwners.get(transport.pid);
|
|
1189
|
+
if (acquired && acquired !== this.processLifetime(transport) || existing && !existing.matches(transport))
|
|
1190
|
+
return () => {};
|
|
1191
|
+
this.acquireObservation(transport, true);
|
|
1192
|
+
const owner = this.observationOwners.get(transport.pid);
|
|
1193
|
+
return () => owner.close();
|
|
1194
|
+
}
|
|
1195
|
+
captureControllerStop(pid) {
|
|
1196
|
+
const stop = this.capturedControllerStopFor(pid);
|
|
1197
|
+
if ((this.options.table.get(pid)?.image.generation ?? 1) > 1 && this.nativeLaunchReturns.has(pid))
|
|
1198
|
+
return;
|
|
1199
|
+
if (!stop || !this.observationOwners.has(pid) || this.controllerNativeStopFor(pid))
|
|
1200
|
+
return;
|
|
1201
|
+
const child = this.children.get(pid);
|
|
1202
|
+
const returned = new NativeReturnFollowers;
|
|
1203
|
+
const captured = this.captureConsumerStop(pid, stop, () => {
|
|
1204
|
+
if (!child) {
|
|
1205
|
+
this.controllerNativeStops.delete(pid);
|
|
1206
|
+
this.capturedControllerStops.delete(pid);
|
|
1207
|
+
this.controllerNativeReturns.delete(pid);
|
|
1208
|
+
}
|
|
1209
|
+
this.retainedRootStops.delete(pid);
|
|
1210
|
+
returned.returned();
|
|
1211
|
+
this.rootStopped(pid);
|
|
1212
|
+
});
|
|
1213
|
+
if (child) {
|
|
1214
|
+
child.controllerNativeReturn = returned;
|
|
1215
|
+
child.controllerNativeStop = captured;
|
|
1216
|
+
} else {
|
|
1217
|
+
this.controllerNativeReturns.set(pid, returned);
|
|
1218
|
+
this.controllerNativeStops.set(pid, captured);
|
|
1219
|
+
this.bindRootGroup(pid, captured);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
acquireObservation(transfer, execution = false) {
|
|
1223
|
+
const existing = this.observationOwners.get(transfer.pid);
|
|
1224
|
+
if (existing) {
|
|
1225
|
+
if (!existing.matches(transfer))
|
|
1226
|
+
throw new ProcessError(ProcessErrno.INVAL, "Process observation owner differs from admission");
|
|
1227
|
+
if (execution)
|
|
1228
|
+
existing.acceptExecution();
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
this.observationOwners.set(transfer.pid, new NativeObservationOwner(transfer, () => this.releaseObservationOwner(transfer.pid), execution));
|
|
1232
|
+
const controller = this.controllerFor(transfer.pid);
|
|
1233
|
+
if (controller)
|
|
1234
|
+
this.captureControllerStop(transfer.pid);
|
|
1235
|
+
}
|
|
1236
|
+
rootObservation(pid) {
|
|
1237
|
+
const observation = this.reservedRoots.get(pid)?.observation ?? this.options.table.get(pid)?.observation;
|
|
1238
|
+
if (!observation)
|
|
1239
|
+
throw new ProcessError(ProcessErrno.SRCH, "Process is not admitted");
|
|
1240
|
+
return observation;
|
|
1241
|
+
}
|
|
1242
|
+
acquireProcess(transport) {
|
|
1243
|
+
const lifetime = this.processLifetime(transport);
|
|
1244
|
+
const acquired = this.acquiredProcesses.get(transport.pid);
|
|
1245
|
+
if (acquired && acquired !== lifetime)
|
|
1246
|
+
throw new Error("process consumer belongs to another lifetime");
|
|
1247
|
+
this.acquiredProcesses.set(transport.pid, lifetime);
|
|
1248
|
+
if (!acquired && this.supervisor?.get(transport.pid))
|
|
1249
|
+
this.supervisor.registerRevocation(transport.pid, () => this.revokeRuntimeProcess(transport.pid));
|
|
1250
|
+
this.acquireObservation(transport, workerProcessState(transport).parentPid !== 0);
|
|
1251
|
+
if (!this.terminalLifetimes.has(transport.pid))
|
|
1252
|
+
this.terminalLifetimes.set(transport.pid, captureTerminalLifetime(transport));
|
|
1253
|
+
}
|
|
1254
|
+
acquireController(pid) {
|
|
1255
|
+
if (this.acquiredProcesses.has(pid) || !this.controllerFor(pid))
|
|
1256
|
+
return;
|
|
1257
|
+
const lifetime = this.runtimeProcessLifetime(pid);
|
|
1258
|
+
if (!lifetime)
|
|
1259
|
+
return;
|
|
1260
|
+
this.acquiredProcesses.set(pid, lifetime.key);
|
|
1261
|
+
this.terminalLifetimes.set(pid, lifetime.terminal);
|
|
1262
|
+
}
|
|
1263
|
+
releaseObservationOwner(pid) {
|
|
1264
|
+
this.observationOwners.delete(pid);
|
|
1265
|
+
this.nativeLaunchReturns.delete(pid);
|
|
1266
|
+
this.controllerNativeStops.delete(pid);
|
|
1267
|
+
this.capturedControllerStops.delete(pid);
|
|
1268
|
+
this.controllerNativeReturns.delete(pid);
|
|
1269
|
+
this.retainedRootStops.delete(pid);
|
|
1270
|
+
}
|
|
1271
|
+
releaseAcquiredProcess(pid) {
|
|
1272
|
+
if (this.options.table.get(pid) || this.nativeLaunchReturns.has(pid) || this.imageStops.has(pid) || !!this.controllerFor(pid) || this.children.has(pid) || this.launches?.has(pid) || this.pendingLaunches?.has(pid) || this.fences.has(pid))
|
|
1273
|
+
return;
|
|
1274
|
+
this.acquiredProcesses.delete(pid);
|
|
1275
|
+
this.terminalLifetimes.delete(pid);
|
|
1276
|
+
if (this.observationOwners.get(pid)?.completed)
|
|
1277
|
+
this.observationOwners.delete(pid);
|
|
1278
|
+
this.nativeLaunchReturns.delete(pid);
|
|
1279
|
+
}
|
|
1280
|
+
async quiesceUnstarted(transport) {
|
|
1281
|
+
this.acquireController(transport.pid);
|
|
1282
|
+
const acquired = this.acquiredProcesses.get(transport.pid) === this.processLifetime(transport);
|
|
1283
|
+
let filesystem;
|
|
1284
|
+
try {
|
|
1285
|
+
filesystem = this.filesystem(transport);
|
|
1286
|
+
} catch (error) {
|
|
1287
|
+
if (acquired)
|
|
1288
|
+
throw error;
|
|
1289
|
+
}
|
|
1290
|
+
const pending = [];
|
|
1291
|
+
if (filesystem) {
|
|
1292
|
+
this.options.filesystem.revoke(filesystem);
|
|
1293
|
+
pending.push(this.options.filesystem.quiesce(filesystem));
|
|
1294
|
+
}
|
|
1295
|
+
if (acquired)
|
|
1296
|
+
pending.push(Promise.resolve(this.quiesceProcess(transport.pid)));
|
|
1297
|
+
await Promise.all(pending);
|
|
1298
|
+
this.collectRuntimeProcess(transport.pid, workerProcessDirectoryId(transport));
|
|
1299
|
+
}
|
|
1300
|
+
outputDrained(rootPid) {
|
|
1301
|
+
this.serviceTerminalOutput(rootPid);
|
|
1302
|
+
}
|
|
1303
|
+
serviceTerminalOutput(rootPid) {
|
|
1304
|
+
const budget = this.terminalOutputs.get(rootPid);
|
|
1305
|
+
if (!budget || this.suspended)
|
|
1306
|
+
return;
|
|
1307
|
+
const destination = this.outputFor(rootPid);
|
|
1308
|
+
try {
|
|
1309
|
+
budget.service(destination ?? ((_target, data) => data.length));
|
|
1310
|
+
} catch (error) {
|
|
1311
|
+
this.report(error);
|
|
1312
|
+
}
|
|
1313
|
+
if (!budget.readers.size)
|
|
1314
|
+
this.terminalOutputs.delete(rootPid);
|
|
1315
|
+
}
|
|
1316
|
+
retireTerminalOutput(rootPid) {
|
|
1317
|
+
const budget = this.terminalOutputs.get(rootPid);
|
|
1318
|
+
this.terminalOutputs.delete(rootPid);
|
|
1319
|
+
const pending = budget?.pending();
|
|
1320
|
+
if (pending)
|
|
1321
|
+
this.report(new Error(`root ${rootPid} retired with ${pending} terminal output bytes undelivered`));
|
|
1322
|
+
}
|
|
1323
|
+
outputFor(pid) {
|
|
1324
|
+
const rootPid = this.options.table.get(pid)?.rootPid;
|
|
1325
|
+
if (rootPid !== undefined && this.outputs.has(rootPid))
|
|
1326
|
+
return this.outputs.get(rootPid);
|
|
1327
|
+
for (;; ) {
|
|
1328
|
+
if (this.outputs.has(pid))
|
|
1329
|
+
return this.outputs.get(pid);
|
|
1330
|
+
const parent = this.options.table.parentOf(pid);
|
|
1331
|
+
if (!parent)
|
|
1332
|
+
return;
|
|
1333
|
+
pid = parent;
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
revokeRuntimeProcess(pid, directoryId) {
|
|
1337
|
+
this.accesses.revoke(pid, directoryId);
|
|
1338
|
+
this.children.get(pid)?.accesses?.dispose();
|
|
1339
|
+
if (directoryId === undefined)
|
|
1340
|
+
this.disposeNotifications(this.children.get(pid));
|
|
1341
|
+
for (const [rootPid, transport] of this.roots) {
|
|
1342
|
+
if (directoryId !== undefined && workerProcessDirectoryId(transport) !== directoryId)
|
|
1343
|
+
continue;
|
|
1344
|
+
for (const state of directoryProcesses(transport.directory))
|
|
1345
|
+
if (state.pid === pid) {
|
|
1346
|
+
this.disposeNotifications(this.children.get(pid));
|
|
1347
|
+
this.registries.get(rootPid)?.revoke(pid);
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
async runtimeMessage(message, senderPid) {
|
|
1353
|
+
this.traceSpawn(message, "received");
|
|
1354
|
+
const sender = this.transport.getIdentity(senderPid);
|
|
1355
|
+
const consumingReceipt = message.operation === "reap-job" || message.operation === "reap-process";
|
|
1356
|
+
let filesystemRevoked = false;
|
|
1357
|
+
if (sender && !consumingReceipt) {
|
|
1358
|
+
try {
|
|
1359
|
+
filesystemRevoked = isRevoked(this.filesystem(sender));
|
|
1360
|
+
} catch (error) {
|
|
1361
|
+
this.rejectMessage(message, senderPid, "sender-revoked");
|
|
1362
|
+
throw error;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
let result = null;
|
|
1366
|
+
try {
|
|
1367
|
+
if (sender)
|
|
1368
|
+
result = readOutcome(workerProcessState(sender).signals.outcome);
|
|
1369
|
+
} catch (error) {
|
|
1370
|
+
if (!(error instanceof ProcessError) || error.errno !== ProcessErrno.SRCH && error.errno !== ProcessErrno.CHILD)
|
|
1371
|
+
throw error;
|
|
1372
|
+
}
|
|
1373
|
+
let retainedNotice = false;
|
|
1374
|
+
if (!sender && (message.operation === "spawn" || message.operation === "reap-job" || message.operation === "reap-process")) {
|
|
1375
|
+
const directory = workerProcessDirectoryId(message.transport);
|
|
1376
|
+
const root = Array.from(this.roots.values()).find((root) => workerProcessDirectoryId(root) === directory);
|
|
1377
|
+
if (root) {
|
|
1378
|
+
if (message.operation === "reap-job" || message.operation === "reap-process")
|
|
1379
|
+
retainedNotice = message.transport.pid === senderPid;
|
|
1380
|
+
else {
|
|
1381
|
+
try {
|
|
1382
|
+
retainedNotice = workerProcessState(message.transport).parentPid === senderPid;
|
|
1383
|
+
} catch (error) {
|
|
1384
|
+
if (!(error instanceof ProcessError) || error.errno !== ProcessErrno.SRCH && error.errno !== ProcessErrno.CHILD)
|
|
1385
|
+
throw error;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
const revoked = !consumingReceipt && senderRevoked(result, filesystemRevoked);
|
|
1391
|
+
const stopping = this.commandMessageStopped(message);
|
|
1392
|
+
if (!sender && !retainedNotice || this.suspended || revoked || stopping) {
|
|
1393
|
+
this.rejectMessage(message, senderPid, this.suspended ? "broker-disposed" : !sender ? "unknown-sender" : result?.kind === "signaled" ? "sender-signaled" : stopping ? "external-rejection" : "sender-revoked");
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
if (message.operation === "access" || message.operation === "access-cancel") {
|
|
1397
|
+
await this.accessMessage(message, senderPid, sender, result);
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1400
|
+
await this.transport.handle(message, senderPid);
|
|
1401
|
+
this.retireRoots();
|
|
1402
|
+
if (message.operation !== "pipe")
|
|
1403
|
+
this.watch();
|
|
1404
|
+
}
|
|
1405
|
+
commandMessageStopped(message) {
|
|
1406
|
+
if (message.operation !== "spawn" && message.operation !== "exec")
|
|
1407
|
+
return false;
|
|
1408
|
+
try {
|
|
1409
|
+
const scope = this.commandScope(message.transport);
|
|
1410
|
+
return scope !== undefined && this.commandAdmissionClosed(scope);
|
|
1411
|
+
} catch (error) {
|
|
1412
|
+
if (!isCollectedProcess(error))
|
|
1413
|
+
throw error;
|
|
1414
|
+
return false;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
async accessMessage(message, senderPid, sender, result) {
|
|
1418
|
+
if (!sender || result || workerProcessState(message.transport).pid !== senderPid || workerProcessDirectoryId(sender) !== workerProcessDirectoryId(message.transport)) {
|
|
1419
|
+
this.rejectMessage(message, senderPid, "wrong-sender");
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
await (this.children.get(senderPid)?.accesses ?? this.accesses).handle(message, sender);
|
|
1423
|
+
}
|
|
1424
|
+
rejectRuntimeMessage(message, senderPid, reason = "external-rejection") {
|
|
1425
|
+
this.traceSpawn(message, "received");
|
|
1426
|
+
this.rejectMessage(message, senderPid, reason);
|
|
1427
|
+
}
|
|
1428
|
+
traceProcess(identity, stage, reason) {
|
|
1429
|
+
if (!this.options.onProcessAdmission)
|
|
1430
|
+
return;
|
|
1431
|
+
const transport = this.transport.getIdentity(identity.pid);
|
|
1432
|
+
reportProcessAdmission(this.options.onProcessAdmission, identity, stage, reason, transport ? workerProcessDirectoryId(transport) : undefined);
|
|
1433
|
+
}
|
|
1434
|
+
traceSpawn(message, stage, reason) {
|
|
1435
|
+
if (message.operation !== "spawn" || !this.options.onProcessAdmission)
|
|
1436
|
+
return;
|
|
1437
|
+
try {
|
|
1438
|
+
reportProcessAdmission(this.options.onProcessAdmission, workerProcessState(message.transport), stage, reason, workerProcessDirectoryId(message.transport));
|
|
1439
|
+
} catch (error) {
|
|
1440
|
+
if (!(error instanceof ProcessError) || error.errno !== ProcessErrno.SRCH && error.errno !== ProcessErrno.CHILD)
|
|
1441
|
+
throw error;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
rejectMessage(message, senderPid, reason) {
|
|
1445
|
+
if (message.operation === "exec") {
|
|
1446
|
+
this.transport.rejectExec(message, new ProcessError(ProcessErrno.SRCH, "exec sender is unavailable")).catch((error) => this.report(error));
|
|
1447
|
+
return;
|
|
1448
|
+
}
|
|
1449
|
+
if (message.operation === "access" || message.operation === "access-cancel") {
|
|
1450
|
+
rejectWorkerAccess(message);
|
|
1451
|
+
return;
|
|
1452
|
+
}
|
|
1453
|
+
if (message.operation === "reap-job") {
|
|
1454
|
+
if (!this.suspended && senderPid !== undefined)
|
|
1455
|
+
this.transport.handle(message, senderPid).catch((error) => this.report(error));
|
|
1456
|
+
return;
|
|
1457
|
+
}
|
|
1458
|
+
if (message.operation !== "spawn")
|
|
1459
|
+
return;
|
|
1460
|
+
const transport = message.transport;
|
|
1461
|
+
let state;
|
|
1462
|
+
try {
|
|
1463
|
+
state = workerProcessState(transport);
|
|
1464
|
+
} catch (error) {
|
|
1465
|
+
if (error instanceof ProcessError && (error.errno === ProcessErrno.SRCH || error.errno === ProcessErrno.CHILD))
|
|
1466
|
+
return;
|
|
1467
|
+
throw error;
|
|
1468
|
+
}
|
|
1469
|
+
const directory = workerProcessDirectoryId(transport);
|
|
1470
|
+
const key = `${directory}:${state.pid}`;
|
|
1471
|
+
if (this.transport.getIdentity(state.pid, directory) || this.rejectedTransfers.has(key)) {
|
|
1472
|
+
this.traceSpawn(message, "dropped", "already-registered");
|
|
1473
|
+
return;
|
|
1474
|
+
}
|
|
1475
|
+
this.traceSpawn(message, "rejected", reason);
|
|
1476
|
+
requestSignal(state.signals, 9);
|
|
1477
|
+
this.revokeRuntimeProcess(state.pid, workerProcessDirectoryId(transport));
|
|
1478
|
+
let resolve, reject;
|
|
1479
|
+
const pending = new Promise((accept, fail) => {
|
|
1480
|
+
resolve = accept;
|
|
1481
|
+
reject = fail;
|
|
1482
|
+
});
|
|
1483
|
+
this.rejectedTransfers.set(key, pending);
|
|
1484
|
+
this.trackCommandTransfer(transport, () => this.releaseRejectedTransfer(transport)).then(resolve, reject);
|
|
1485
|
+
pending.then(() => this.rejectedTransfers.delete(key), (error) => this.report(error));
|
|
1486
|
+
}
|
|
1487
|
+
async releaseRejectedTransfer(transport) {
|
|
1488
|
+
const errors = [];
|
|
1489
|
+
const codec = this.discardCodec();
|
|
1490
|
+
for (const token of transport.resources) {
|
|
1491
|
+
try {
|
|
1492
|
+
codec.discard(token);
|
|
1493
|
+
} catch (error) {
|
|
1494
|
+
errors.push(error);
|
|
1495
|
+
this.report(error);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
wakeWorkerProcess(transport);
|
|
1499
|
+
await this.quiesceUnstarted(transport);
|
|
1500
|
+
const scope = this.commandScope(transport);
|
|
1501
|
+
if (errors.length) {
|
|
1502
|
+
if (scope)
|
|
1503
|
+
throw new AggregateError(errors, "Rejected spawn descriptor cleanup failed");
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
if (scope)
|
|
1507
|
+
await this.retireRejectedCommand(transport);
|
|
1508
|
+
controlStore(workerProcessState(transport).confirmed, 0, 1);
|
|
1509
|
+
confirmWorkerProcessJob(transport);
|
|
1510
|
+
}
|
|
1511
|
+
transportFor(pid) {
|
|
1512
|
+
return this.transport.get(pid);
|
|
1513
|
+
}
|
|
1514
|
+
releaseLegacyJob(job) {
|
|
1515
|
+
this.retireRoots();
|
|
1516
|
+
const record = this.options.table.job(job);
|
|
1517
|
+
if (!record || record.members.size || record.pendingMembers || this.states().some((state) => state.job === job))
|
|
1518
|
+
return;
|
|
1519
|
+
this.supervisor?.reapJob(record.ownerPid, job);
|
|
1520
|
+
}
|
|
1521
|
+
takeWorker(workerUrl) {
|
|
1522
|
+
if (this.suspended)
|
|
1523
|
+
throw new Error("Process broker is disposed");
|
|
1524
|
+
return this.workers.take(workerUrl);
|
|
1525
|
+
}
|
|
1526
|
+
rootControlGrant(pid) {
|
|
1527
|
+
const grant = this.rootGrants.get(pid);
|
|
1528
|
+
if (!grant)
|
|
1529
|
+
throw new ProcessError(ProcessErrno.SRCH, "Root is not admitted");
|
|
1530
|
+
return grant;
|
|
1531
|
+
}
|
|
1532
|
+
retainRootGraphics(pid, graphics, worker) {
|
|
1533
|
+
const ticket = this.rootAdmissions.get(pid);
|
|
1534
|
+
const launched = this.rootTickets.get(pid);
|
|
1535
|
+
if (!ticket || !launched)
|
|
1536
|
+
throw new ProcessError(ProcessErrno.SRCH, "Root is not admitted");
|
|
1537
|
+
const retention = ticket.retainControlsForGraphics();
|
|
1538
|
+
bindGraphicsLaunch(graphics, retention);
|
|
1539
|
+
retainAllocationReceipts(worker, launched, retention, (error) => this.report(error));
|
|
1540
|
+
}
|
|
1541
|
+
captureRootStop(pid, stop) {
|
|
1542
|
+
const captured = this.captureConsumerStop(pid, stop);
|
|
1543
|
+
return () => captured.terminate();
|
|
1544
|
+
}
|
|
1545
|
+
bindRootGroup(pid, handle) {
|
|
1546
|
+
const group = this.rootGroups?.get(pid);
|
|
1547
|
+
if (group)
|
|
1548
|
+
handle.bindGroup(group);
|
|
1549
|
+
return handle;
|
|
1550
|
+
}
|
|
1551
|
+
captureConsumerStop(pid, stop, onReturned) {
|
|
1552
|
+
const owner = this.observationOwners.get(pid);
|
|
1553
|
+
if (!owner)
|
|
1554
|
+
throw new ProcessError(ProcessErrno.SRCH, "Root is not admitted");
|
|
1555
|
+
const returned = owner.acquire();
|
|
1556
|
+
const handle = nativeStopHandle({ terminate: stop }, undefined, () => {
|
|
1557
|
+
owner.removeStop(handle);
|
|
1558
|
+
onReturned?.();
|
|
1559
|
+
returned();
|
|
1560
|
+
}, () => owner.close(), (error) => owner.fail(error));
|
|
1561
|
+
owner.addStop(handle);
|
|
1562
|
+
return handle;
|
|
1563
|
+
}
|
|
1564
|
+
rootStopped(pid) {
|
|
1565
|
+
const stop = this.controllerNativeStopFor(pid);
|
|
1566
|
+
if (stop) {
|
|
1567
|
+
stop.acknowledgeReturn();
|
|
1568
|
+
return;
|
|
1569
|
+
}
|
|
1570
|
+
this.rootTickets.get(pid)?.stopped();
|
|
1571
|
+
this.rootTickets.delete(pid);
|
|
1572
|
+
this.rootAdmissions.delete(pid);
|
|
1573
|
+
this.rootGrants.delete(pid);
|
|
1574
|
+
}
|
|
1575
|
+
rootControlAllocated(pid, buffer) {
|
|
1576
|
+
const ticket = this.rootTickets.get(pid);
|
|
1577
|
+
if (!ticket)
|
|
1578
|
+
throw new ProcessError(ProcessErrno.SRCH, "Root is not admitted");
|
|
1579
|
+
ticket.controlAllocated(buffer);
|
|
1580
|
+
}
|
|
1581
|
+
isIdleWorker(worker) {
|
|
1582
|
+
return this.workers.isIdle(worker);
|
|
1583
|
+
}
|
|
1584
|
+
workerMemory() {
|
|
1585
|
+
return Array.from(this.children.values(), (child) => {
|
|
1586
|
+
const bytes = Atomics.load(child.memory, 0);
|
|
1587
|
+
return { ...child.identity, bytes: bytes < 0n ? null : Number(bytes) };
|
|
1588
|
+
});
|
|
1589
|
+
}
|
|
1590
|
+
async prepareOperationDiagnostics() {
|
|
1591
|
+
try {
|
|
1592
|
+
const { OperationOwner } = await import("./operations/owner.js");
|
|
1593
|
+
this.#operations = new OperationOwner((length) => this.options.reservations.buffer("control", {
|
|
1594
|
+
kind: "fixed-buffer",
|
|
1595
|
+
length: bytes(length)
|
|
1596
|
+
}), ({ pid, generation, captureId }) => {
|
|
1597
|
+
const child = this.children.get(pid);
|
|
1598
|
+
return child?.generation === generation && child.operationCapture === captureId;
|
|
1599
|
+
});
|
|
1600
|
+
} catch {
|
|
1601
|
+
this.#operationsUnavailable = true;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
operationDiagnostics() {
|
|
1605
|
+
if (!this.options.observeOperations)
|
|
1606
|
+
return { status: "disabled" };
|
|
1607
|
+
try {
|
|
1608
|
+
return this.#operations?.snapshot() ?? {
|
|
1609
|
+
status: this.#operationsUnavailable ? "unavailable" : "empty"
|
|
1610
|
+
};
|
|
1611
|
+
} catch {
|
|
1612
|
+
return { status: "unavailable" };
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
captureOperations(child, options, enabled) {
|
|
1616
|
+
if (!enabled || !this.#operations || options.memoryGroup || options.memories?.length)
|
|
1617
|
+
return;
|
|
1618
|
+
const memories = moduleMemoryDeclarations(options.request.module);
|
|
1619
|
+
if (memories?.length !== 1 || memories[0]?.kind !== "private")
|
|
1620
|
+
return;
|
|
1621
|
+
try {
|
|
1622
|
+
const binding = this.#operations.enroll(child.identity.pid, child.generation);
|
|
1623
|
+
if (binding)
|
|
1624
|
+
child.operationCapture = binding.captureId;
|
|
1625
|
+
return binding;
|
|
1626
|
+
} catch {
|
|
1627
|
+
return;
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
connectWorkerFilesystem(filesystem, arena, binding) {
|
|
1631
|
+
if (!binding)
|
|
1632
|
+
return this.options.filesystem.connect(filesystem, arena);
|
|
1633
|
+
const { buffer, slot, captureId } = binding;
|
|
1634
|
+
return this.options.filesystem.connect(filesystem, arena, { buffer, slot, captureId });
|
|
1635
|
+
}
|
|
1636
|
+
startStates() {
|
|
1637
|
+
const states = [];
|
|
1638
|
+
for (const child of this.children.values()) {
|
|
1639
|
+
if (child.guestEnded || child.failed || child.stopped)
|
|
1640
|
+
continue;
|
|
1641
|
+
observeStart(child.start, child.memory, child.context.outcome);
|
|
1642
|
+
states.push(startSnapshot(child.start));
|
|
1643
|
+
}
|
|
1644
|
+
for (const launch of this.pendingLaunches?.values() ?? []) {
|
|
1645
|
+
if (this.children.get(launch.start.pid)?.start === launch.start)
|
|
1646
|
+
continue;
|
|
1647
|
+
states.push(startSnapshot(launch.start));
|
|
1648
|
+
}
|
|
1649
|
+
return states;
|
|
1650
|
+
}
|
|
1651
|
+
networkPathScope(context, directory) {
|
|
1652
|
+
if (this.suspended)
|
|
1653
|
+
throw new Error("Process broker is disposed");
|
|
1654
|
+
if (!Number.isSafeInteger(directory) || directory < 0)
|
|
1655
|
+
throw new TypeError("Network path scope requires a directory handle");
|
|
1656
|
+
const transport = this.transport.get(context.pid);
|
|
1657
|
+
if (!transport)
|
|
1658
|
+
throw new Error("process has no admitted worker transport");
|
|
1659
|
+
const state = workerProcessState(transport);
|
|
1660
|
+
if (state.parentPid !== context.parentPid || state.job !== context.job)
|
|
1661
|
+
throw new Error("process context does not match its admitted transport");
|
|
1662
|
+
if (readOutcome(context.outcome))
|
|
1663
|
+
throw new Error("process has already exited");
|
|
1664
|
+
const filesystem = this.filesystem(transport);
|
|
1665
|
+
if (isRevoked(filesystem))
|
|
1666
|
+
throw new Error("process filesystem is revoked");
|
|
1667
|
+
return Object.freeze({ filesystem, directory });
|
|
1668
|
+
}
|
|
1669
|
+
workerPlan(context, options) {
|
|
1670
|
+
const memories = moduleMemoryDeclarations(options.request.module);
|
|
1671
|
+
const guest = options.memoryGroup ? { kind: "declared", memories: options.memories ?? [] } : memories ? { kind: "declared", memories: memories.concat(options.memories ?? []) } : { kind: "undeclared" };
|
|
1672
|
+
const group = options.memoryGroup === "new" ? {
|
|
1673
|
+
create: this.options.reservations.sizing.groupShape(this.options.memoryGroups?.maximumPages)
|
|
1674
|
+
} : options.memoryGroup ? "join" : "none";
|
|
1675
|
+
return {
|
|
1676
|
+
pid: context.pid,
|
|
1677
|
+
executable: context.request.executable,
|
|
1678
|
+
guest,
|
|
1679
|
+
group,
|
|
1680
|
+
connection: true,
|
|
1681
|
+
controls: true
|
|
1682
|
+
};
|
|
1683
|
+
}
|
|
1684
|
+
launchWorker(context, options) {
|
|
1685
|
+
const graphicsOwner = options.graphics;
|
|
1686
|
+
let graphicsReleased = false;
|
|
1687
|
+
const graphics = graphicsOwner && {
|
|
1688
|
+
connection: graphicsOwner.connection,
|
|
1689
|
+
dispose() {
|
|
1690
|
+
if (graphicsReleased)
|
|
1691
|
+
return;
|
|
1692
|
+
graphicsReleased = true;
|
|
1693
|
+
graphicsOwner.dispose();
|
|
1694
|
+
},
|
|
1695
|
+
retired: () => graphicsOwner.retired()
|
|
1696
|
+
};
|
|
1697
|
+
if (graphics && graphicsOwner)
|
|
1698
|
+
originalGraphicsGrants.set(graphics, graphicsOwner);
|
|
1699
|
+
const owner = options.network;
|
|
1700
|
+
let released = false;
|
|
1701
|
+
const network = owner && {
|
|
1702
|
+
connection: owner.connection,
|
|
1703
|
+
dispose() {
|
|
1704
|
+
if (released)
|
|
1705
|
+
return;
|
|
1706
|
+
released = true;
|
|
1707
|
+
owner.dispose();
|
|
1708
|
+
}
|
|
1709
|
+
};
|
|
1710
|
+
try {
|
|
1711
|
+
this.checkGuestImage(context.pid, context.generation);
|
|
1712
|
+
if (options.memoryGroup)
|
|
1713
|
+
requireGroupPlan(options.request.module, "linkPlan" in options.request ? options.request.linkPlan : undefined);
|
|
1714
|
+
if (readOutcome(context.outcome))
|
|
1715
|
+
throw new ProcessError(ProcessErrno.SRCH, "process exited before worker admission");
|
|
1716
|
+
const threaded = threadModuleDeclaration(options.request.module);
|
|
1717
|
+
if (threaded && graphics)
|
|
1718
|
+
throw new Error("Threaded guests do not accept graphics grants");
|
|
1719
|
+
if (threaded)
|
|
1720
|
+
return this.launchThreadWorker(context, options, threaded);
|
|
1721
|
+
if (WebAssembly.Module.imports(options.request.module).some((entry) => entry.module === "wasi" && entry.name === "thread-spawn"))
|
|
1722
|
+
throw new Error("Threaded Preview 1 requires validated source bytes");
|
|
1723
|
+
return this.launchOwnedWorker(context, { ...options, network, graphics }, !!this.#operations && options[preview1Launch] === true);
|
|
1724
|
+
} catch (error) {
|
|
1725
|
+
if (!this.children.has(context.pid) && context.execution?.kind !== "host" && this.options.table.get(context.pid)?.image.execution?.kind !== "host" && typeof error === "object" && error !== null)
|
|
1726
|
+
this.neverConstructed.set(error, context.pid);
|
|
1727
|
+
try {
|
|
1728
|
+
graphics?.dispose();
|
|
1729
|
+
} catch (cleanup) {
|
|
1730
|
+
this.report(cleanup);
|
|
1731
|
+
}
|
|
1732
|
+
try {
|
|
1733
|
+
network?.dispose();
|
|
1734
|
+
} catch (cleanup) {
|
|
1735
|
+
this.report(cleanup);
|
|
1736
|
+
}
|
|
1737
|
+
throw error;
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
launchThreadWorker(context, options, declaration) {
|
|
1741
|
+
const { threaded: urls, cleanup } = options;
|
|
1742
|
+
if (!urls || options.memoryGroup || options.network || options.memories?.length || !options.request.interruptible)
|
|
1743
|
+
throw new Error("Threaded Preview 1 requires the explicit source-admitted thread launcher");
|
|
1744
|
+
if (this.suspended)
|
|
1745
|
+
throw new Error("Process broker is disposed");
|
|
1746
|
+
const transport = this.transport.get(context.pid);
|
|
1747
|
+
if (!transport || transport.generation !== context.generation || this.children.has(context.pid))
|
|
1748
|
+
throw new Error("process has no available worker transport");
|
|
1749
|
+
const state = workerProcessState(transport);
|
|
1750
|
+
const filesystem = this.filesystem(transport);
|
|
1751
|
+
this.bindPipeRegistry(transport);
|
|
1752
|
+
const memory = new BigInt64Array(allocateSharedControl(8));
|
|
1753
|
+
Atomics.store(memory, 0, -1n);
|
|
1754
|
+
const launch = this.launchState(context);
|
|
1755
|
+
const child = {
|
|
1756
|
+
generation: context.generation,
|
|
1757
|
+
transport,
|
|
1758
|
+
launch,
|
|
1759
|
+
start: launch.pending?.start ?? processStartRecord(context),
|
|
1760
|
+
nativeReturned: this.nativeLaunchReturns.get(context.pid),
|
|
1761
|
+
memory,
|
|
1762
|
+
filesystem,
|
|
1763
|
+
context,
|
|
1764
|
+
cleanup,
|
|
1765
|
+
identity: {
|
|
1766
|
+
pid: state.pid,
|
|
1767
|
+
parentPid: state.parentPid,
|
|
1768
|
+
rootPid: state.rootPid,
|
|
1769
|
+
job: state.job,
|
|
1770
|
+
directory: workerProcessDirectoryId(transport)
|
|
1771
|
+
},
|
|
1772
|
+
acknowledged: false,
|
|
1773
|
+
failed: false,
|
|
1774
|
+
stopped: false
|
|
1775
|
+
};
|
|
1776
|
+
this.captureImageState(child);
|
|
1777
|
+
this.children.set(context.pid, child);
|
|
1778
|
+
context.registerRevocation(() => {
|
|
1779
|
+
this.options.filesystem.revoke(filesystem);
|
|
1780
|
+
child.threads?.then((owner) => owner?.terminal()).catch((error) => this.report(error));
|
|
1781
|
+
});
|
|
1782
|
+
child.threads = import("../thread/runtime-owner.js").then(({ RuntimeThreadOwner }) => RuntimeThreadOwner.create({
|
|
1783
|
+
context,
|
|
1784
|
+
transport,
|
|
1785
|
+
declaration,
|
|
1786
|
+
urls,
|
|
1787
|
+
reservations: this.options.reservations,
|
|
1788
|
+
connect: (headroom) => this.options.filesystem.connect(filesystem, headroom),
|
|
1789
|
+
filesystemFence: () => this.options.filesystem.quiesce(filesystem),
|
|
1790
|
+
nativeReturned: () => child.nativeReturned?.(),
|
|
1791
|
+
cleanup: () => {
|
|
1792
|
+
const dispose = child.cleanup;
|
|
1793
|
+
child.cleanup = undefined;
|
|
1794
|
+
dispose?.();
|
|
1795
|
+
},
|
|
1796
|
+
failed: (error) => {
|
|
1797
|
+
this.report(error);
|
|
1798
|
+
if (startStatus(context.outcome) === 0)
|
|
1799
|
+
context.fail(error);
|
|
1800
|
+
else
|
|
1801
|
+
context.startFailed(error);
|
|
1802
|
+
}
|
|
1803
|
+
}));
|
|
1804
|
+
child.threads.catch((error) => {
|
|
1805
|
+
child.failed = true;
|
|
1806
|
+
context.startFailed(error);
|
|
1807
|
+
});
|
|
1808
|
+
this.watch();
|
|
1809
|
+
return { terminate: () => this.stop(child) };
|
|
1810
|
+
}
|
|
1811
|
+
launchOwnedWorker(context, options, observeOperations) {
|
|
1812
|
+
if (this.suspended) {
|
|
1813
|
+
options.network?.dispose();
|
|
1814
|
+
throw new Error("Process broker is disposed");
|
|
1815
|
+
}
|
|
1816
|
+
const transport = this.transport.get(context.pid);
|
|
1817
|
+
if (!transport || transport.generation !== context.generation || this.children.has(context.pid)) {
|
|
1818
|
+
options.network?.dispose();
|
|
1819
|
+
throw new Error(!transport ? "process has no admitted worker transport" : "process already has a worker");
|
|
1820
|
+
}
|
|
1821
|
+
const state = workerProcessState(transport);
|
|
1822
|
+
const ticket = this.options.reservations.admit(this.workerPlan(context, options));
|
|
1823
|
+
if (options.graphics) {
|
|
1824
|
+
try {
|
|
1825
|
+
const retention = ticket.retainControlsForGraphics();
|
|
1826
|
+
bindGraphicsLaunch(options.graphics, retention);
|
|
1827
|
+
const original = originalGraphicsGrants.get(options.graphics);
|
|
1828
|
+
if (original)
|
|
1829
|
+
bindGraphicsLaunch(original, retention);
|
|
1830
|
+
} catch (error) {
|
|
1831
|
+
ticket.abort();
|
|
1832
|
+
throw error;
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
let memory;
|
|
1836
|
+
try {
|
|
1837
|
+
memory = new BigInt64Array(allocateSharedControl(8));
|
|
1838
|
+
Atomics.store(memory, 0, -1n);
|
|
1839
|
+
} catch (error) {
|
|
1840
|
+
ticket.abort();
|
|
1841
|
+
throw error;
|
|
1842
|
+
}
|
|
1843
|
+
const filesystem = this.filesystem(transport);
|
|
1844
|
+
const launch = this.launchState(context);
|
|
1845
|
+
const child = {
|
|
1846
|
+
generation: context.generation,
|
|
1847
|
+
transport,
|
|
1848
|
+
launch,
|
|
1849
|
+
start: launch.pending?.start ?? processStartRecord(context),
|
|
1850
|
+
nativeReturned: this.nativeLaunchReturns.get(context.pid),
|
|
1851
|
+
ticket,
|
|
1852
|
+
memory,
|
|
1853
|
+
identity: {
|
|
1854
|
+
pid: state.pid,
|
|
1855
|
+
parentPid: state.parentPid,
|
|
1856
|
+
rootPid: state.rootPid,
|
|
1857
|
+
job: state.job,
|
|
1858
|
+
directory: workerProcessDirectoryId(transport)
|
|
1859
|
+
},
|
|
1860
|
+
filesystem,
|
|
1861
|
+
context,
|
|
1862
|
+
acknowledged: false,
|
|
1863
|
+
failed: false,
|
|
1864
|
+
stopped: false,
|
|
1865
|
+
cleanup: options.cleanup,
|
|
1866
|
+
network: options.network,
|
|
1867
|
+
graphics: options.graphics,
|
|
1868
|
+
wake: options.wake
|
|
1869
|
+
};
|
|
1870
|
+
this.captureImageState(child);
|
|
1871
|
+
this.children.set(context.pid, child);
|
|
1872
|
+
const operations = this.captureOperations(child, options, observeOperations);
|
|
1873
|
+
context.registerRevocation(() => this.disposeNetwork(child));
|
|
1874
|
+
let connection;
|
|
1875
|
+
let worker;
|
|
1876
|
+
let output;
|
|
1877
|
+
try {
|
|
1878
|
+
this.bindPipeRegistry(transport);
|
|
1879
|
+
output = child.output = createTerminalOutput();
|
|
1880
|
+
let budget = this.terminalOutputs.get(state.rootPid);
|
|
1881
|
+
if (!budget)
|
|
1882
|
+
this.terminalOutputs.set(state.rootPid, budget = new TerminalOutputBudget);
|
|
1883
|
+
budget.readers.add(output);
|
|
1884
|
+
context.registerRevocation(() => output.close());
|
|
1885
|
+
const stderr = context.descriptors.get(2)?.resource;
|
|
1886
|
+
if (stderr instanceof PipeEndpoint) {
|
|
1887
|
+
child.startupStderr = this.pipes.attach(stderr.handle()).duplicate(stderr);
|
|
1888
|
+
context.registerRevocation(() => child.startupStderr.close());
|
|
1889
|
+
}
|
|
1890
|
+
if (options.notificationWorkerUrl)
|
|
1891
|
+
child.notifications = createNotificationBridge(options.notificationWorkerUrl);
|
|
1892
|
+
context.registerRevocation(() => {
|
|
1893
|
+
this.options.filesystem.revoke(filesystem);
|
|
1894
|
+
});
|
|
1895
|
+
if (options.memoryGroup)
|
|
1896
|
+
child.group = this.admitGroupMember(context.pid, transport, options.memoryGroup, ticket.group);
|
|
1897
|
+
connection = this.connectWorkerFilesystem(filesystem, ticket.arena, operations);
|
|
1898
|
+
if (readOutcome(context.outcome))
|
|
1899
|
+
throw new ProcessError(ProcessErrno.SRCH, "process exited before worker construction");
|
|
1900
|
+
worker = child.worker = this.workers.take(options.workerUrl);
|
|
1901
|
+
markStart(child.start, "worker-constructed");
|
|
1902
|
+
this.imageStops.delete(context.pid);
|
|
1903
|
+
child.launched = ticket.launched();
|
|
1904
|
+
if (options.graphics)
|
|
1905
|
+
retainAllocationReceipts(worker, child.launched, graphicsLaunchRetention(options.graphics), (error) => this.report(error));
|
|
1906
|
+
} catch (error) {
|
|
1907
|
+
child.group?.abort();
|
|
1908
|
+
ticket.abort();
|
|
1909
|
+
child.failed = true;
|
|
1910
|
+
this.disposeNotifications(child);
|
|
1911
|
+
this.disposeNetwork(child);
|
|
1912
|
+
connection?.port.close();
|
|
1913
|
+
throw error;
|
|
1914
|
+
}
|
|
1915
|
+
const request = {
|
|
1916
|
+
...options.request,
|
|
1917
|
+
hostIdentity: this.hostIdentity,
|
|
1918
|
+
memoryObservation: memory.buffer,
|
|
1919
|
+
controlGrant: ticket.control,
|
|
1920
|
+
filesystem: connection,
|
|
1921
|
+
runtimeProcess: transport,
|
|
1922
|
+
outcome: serializeOutcome(context.outcome),
|
|
1923
|
+
observation: context.observation,
|
|
1924
|
+
startupStderr: child.startupStderr?.handle(),
|
|
1925
|
+
notifications: child.notifications?.connection,
|
|
1926
|
+
terminalOutput: output.buffer,
|
|
1927
|
+
network: options.network?.connection,
|
|
1928
|
+
graphics: options.graphics?.connection
|
|
1929
|
+
};
|
|
1930
|
+
const group = child.group?.launch();
|
|
1931
|
+
if (group)
|
|
1932
|
+
Object.assign(request, { memoryGroup: group.request });
|
|
1933
|
+
this.watch();
|
|
1934
|
+
worker.onmessage = ({ data }) => {
|
|
1935
|
+
startMessage(child.start, data, memory, context.outcome);
|
|
1936
|
+
if (guestFinished(data?.type))
|
|
1937
|
+
guestEnded(child);
|
|
1938
|
+
this.childMessage(child, options, data);
|
|
1939
|
+
};
|
|
1940
|
+
worker.onerror = (event) => {
|
|
1941
|
+
guestEnded(child);
|
|
1942
|
+
this.childError(child, event);
|
|
1943
|
+
};
|
|
1944
|
+
try {
|
|
1945
|
+
if (readOutcome(context.outcome))
|
|
1946
|
+
throw new ProcessError(ProcessErrno.SRCH, "process exited before worker publication");
|
|
1947
|
+
const ports = [request.filesystem.port];
|
|
1948
|
+
if (request.notifications)
|
|
1949
|
+
ports.push(request.notifications.port);
|
|
1950
|
+
if (request.network)
|
|
1951
|
+
ports.push(request.network.port);
|
|
1952
|
+
if (request.graphics)
|
|
1953
|
+
ports.push(request.graphics.port);
|
|
1954
|
+
const bootstrap = operations ? [request, operations] : request;
|
|
1955
|
+
worker.postMessage(bootstrap, group ? ports.concat(group.transfer) : ports);
|
|
1956
|
+
markStart(child.start, "start-posted");
|
|
1957
|
+
} catch (error) {
|
|
1958
|
+
child.failed = true;
|
|
1959
|
+
this.disposeNotifications(child);
|
|
1960
|
+
request.filesystem.port.close();
|
|
1961
|
+
this.disposeNetwork(child);
|
|
1962
|
+
throw error;
|
|
1963
|
+
}
|
|
1964
|
+
return { terminate: () => this.stopWorker(child) };
|
|
1965
|
+
}
|
|
1966
|
+
memoryGroupOf(pid) {
|
|
1967
|
+
return this.groups?.groupOf(pid);
|
|
1968
|
+
}
|
|
1969
|
+
memoryGroups() {
|
|
1970
|
+
return this.groups?.snapshot() ?? [];
|
|
1971
|
+
}
|
|
1972
|
+
admitRootMemoryGroup(pid, program, join = "new") {
|
|
1973
|
+
this.checkGuestImage(pid);
|
|
1974
|
+
requireGroupPlan(program?.module, program?.linkPlan);
|
|
1975
|
+
if (this.suspended)
|
|
1976
|
+
throw new Error("Process broker is disposed");
|
|
1977
|
+
const transport = this.roots.get(pid);
|
|
1978
|
+
if (!transport)
|
|
1979
|
+
throw new Error(`Unknown runtime root ${pid}`);
|
|
1980
|
+
if (this.rootGroups?.has(pid))
|
|
1981
|
+
throw new Error(`Root ${pid} already has a memory group`);
|
|
1982
|
+
const ticket = this.options.reservations.admit({
|
|
1983
|
+
pid,
|
|
1984
|
+
executable: "root memory group",
|
|
1985
|
+
guest: { kind: "group" },
|
|
1986
|
+
group: join === "new" ? {
|
|
1987
|
+
create: this.options.reservations.sizing.groupShape(this.options.memoryGroups?.maximumPages)
|
|
1988
|
+
} : "join",
|
|
1989
|
+
connection: false,
|
|
1990
|
+
controls: false
|
|
1991
|
+
});
|
|
1992
|
+
let lease;
|
|
1993
|
+
let bootstrap;
|
|
1994
|
+
try {
|
|
1995
|
+
const admitted = lease = this.admitGroupMember(pid, transport, join, ticket.group);
|
|
1996
|
+
admitted.group.buffer();
|
|
1997
|
+
const { request, transfer } = bootstrap = admitted.launch();
|
|
1998
|
+
ticket.launched();
|
|
1999
|
+
this.controllerNativeStopFor(pid)?.bindGroup(admitted);
|
|
2000
|
+
(this.rootGroups ??= new Map).set(pid, admitted);
|
|
2001
|
+
return Object.freeze({
|
|
2002
|
+
group: admitted.group,
|
|
2003
|
+
request,
|
|
2004
|
+
transfer: Object.freeze(transfer),
|
|
2005
|
+
terminating: () => admitted.stopRequested(),
|
|
2006
|
+
stopped: () => this.settleRootGroup(pid, admitted)
|
|
2007
|
+
});
|
|
2008
|
+
} catch (error) {
|
|
2009
|
+
bootstrap?.request.port.close();
|
|
2010
|
+
lease?.stopped();
|
|
2011
|
+
ticket.abort();
|
|
2012
|
+
throw error;
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
settleRootGroup(pid, lease) {
|
|
2016
|
+
lease.stopped();
|
|
2017
|
+
if (!lease.settled() || this.rootGroups?.get(pid) !== lease)
|
|
2018
|
+
return;
|
|
2019
|
+
this.rootStopped(pid);
|
|
2020
|
+
if (this.rootGroups?.get(pid) === lease)
|
|
2021
|
+
this.rootGroups.delete(pid);
|
|
2022
|
+
}
|
|
2023
|
+
childMessage(child, options, data) {
|
|
2024
|
+
const context = child.context;
|
|
2025
|
+
const transport = child.transport;
|
|
2026
|
+
const filesystem = child.filesystem;
|
|
2027
|
+
if (!this.currentChild(child)) {
|
|
2028
|
+
this.traceProcess(child.identity, "dropped", "stale-image");
|
|
2029
|
+
return;
|
|
2030
|
+
}
|
|
2031
|
+
if (data.type === "replaced") {
|
|
2032
|
+
this.acknowledgeImage(child, data);
|
|
2033
|
+
return;
|
|
2034
|
+
}
|
|
2035
|
+
if (data.type === "shared-control-allocation") {
|
|
2036
|
+
if (!options.graphics)
|
|
2037
|
+
child.launched?.controlAllocated(data.buffer);
|
|
2038
|
+
return;
|
|
2039
|
+
}
|
|
2040
|
+
if (data.type === "observation-error") {
|
|
2041
|
+
this.report(new Error(data.message));
|
|
2042
|
+
return;
|
|
2043
|
+
}
|
|
2044
|
+
if (data.type === "terminal-output") {
|
|
2045
|
+
this.serviceTerminalOutput(child.identity.rootPid);
|
|
2046
|
+
return;
|
|
2047
|
+
}
|
|
2048
|
+
const filesystemRevoked = data.type === "runtime-proc" && isRevoked(filesystem);
|
|
2049
|
+
let selected, entered = false;
|
|
2050
|
+
try {
|
|
2051
|
+
selected = readOutcome(context.outcome);
|
|
2052
|
+
if (data.type === "error")
|
|
2053
|
+
entered = startStatus(context.outcome) === 0;
|
|
2054
|
+
} catch (error) {
|
|
2055
|
+
if (!(error instanceof ProcessError) || error.errno !== ProcessErrno.SRCH && error.errno !== ProcessErrno.CHILD)
|
|
2056
|
+
throw error;
|
|
2057
|
+
if (data.type !== "runtime-proc")
|
|
2058
|
+
return;
|
|
2059
|
+
selected = null;
|
|
2060
|
+
}
|
|
2061
|
+
if (data.type === "runtime-proc") {
|
|
2062
|
+
if (workerProcessDirectoryId(data.transport) !== workerProcessDirectoryId(transport))
|
|
2063
|
+
return;
|
|
2064
|
+
if (senderRevoked(selected, filesystemRevoked))
|
|
2065
|
+
this.rejectRuntimeMessage(data, context.pid, selected?.kind === "signaled" ? "sender-signaled" : "sender-revoked");
|
|
2066
|
+
else {
|
|
2067
|
+
const message = this.executableMessage(data, options.executableName);
|
|
2068
|
+
this.runtimeMessage(message, context.pid).catch((error) => this.report(error));
|
|
2069
|
+
}
|
|
2070
|
+
return;
|
|
2071
|
+
}
|
|
2072
|
+
if (data.type === "cleanup-error") {
|
|
2073
|
+
if (this.options.table.get(context.pid)?.image.phase === "retiring") {
|
|
2074
|
+
child.failed = true;
|
|
2075
|
+
context.fail(new Error(`Worker replacement cleanup: ${data.message}`));
|
|
2076
|
+
return;
|
|
2077
|
+
}
|
|
2078
|
+
child.failed = true;
|
|
2079
|
+
this.report(new Error(`${data.message}: ${data.cleanupErrors.join("; ")}`));
|
|
2080
|
+
if (data.signal)
|
|
2081
|
+
context.defaultSignal(data.signal);
|
|
2082
|
+
else
|
|
2083
|
+
context.exit(data.code);
|
|
2084
|
+
this.stopSafely(child);
|
|
2085
|
+
return;
|
|
2086
|
+
}
|
|
2087
|
+
if (selected?.kind === "signaled" && data.type !== "exit" && data.type !== "error") {
|
|
2088
|
+
options.onMessage?.(data, context);
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
2091
|
+
if (data.type !== "exit" && data.type !== "error") {
|
|
2092
|
+
options.onMessage?.(data, context);
|
|
2093
|
+
return;
|
|
2094
|
+
}
|
|
2095
|
+
this.disposeNotifications(child);
|
|
2096
|
+
this.disposeNetwork(child);
|
|
2097
|
+
child.acknowledged = true;
|
|
2098
|
+
this.options.filesystem.reap(filesystem);
|
|
2099
|
+
if (data.cleanupErrors?.length)
|
|
2100
|
+
this.report(new Error(`Worker cleanup: ${data.cleanupErrors.join("; ")}`));
|
|
2101
|
+
if (data.type === "exit" && data.signal)
|
|
2102
|
+
context.defaultSignal(data.signal);
|
|
2103
|
+
else if (data.type === "exit")
|
|
2104
|
+
context.exit(data.code);
|
|
2105
|
+
else if (!entered)
|
|
2106
|
+
context.startFailed(new WorkerStartError(data.message, data.errno, data.diagnostic));
|
|
2107
|
+
else
|
|
2108
|
+
context.fail(new Error(data.message));
|
|
2109
|
+
}
|
|
2110
|
+
acknowledgeImage(child, message) {
|
|
2111
|
+
if (message.cleanupErrors?.length) {
|
|
2112
|
+
child.failed = true;
|
|
2113
|
+
child.context.fail(new Error(`Worker replacement cleanup: ${message.cleanupErrors.join("; ")}`));
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
child.acknowledged = true;
|
|
2117
|
+
child.replacementAcknowledged = true;
|
|
2118
|
+
this.supervisor?.acknowledgeReplacement(child.context.pid, child.generation).catch((error) => this.report(error));
|
|
2119
|
+
}
|
|
2120
|
+
executableMessage(message, name) {
|
|
2121
|
+
if (!name)
|
|
2122
|
+
return message;
|
|
2123
|
+
if (message.operation === "spawn")
|
|
2124
|
+
return {
|
|
2125
|
+
...message,
|
|
2126
|
+
request: { ...message.request, executable: name(message.request.executable) }
|
|
2127
|
+
};
|
|
2128
|
+
if (message.operation === "exec")
|
|
2129
|
+
return {
|
|
2130
|
+
...message,
|
|
2131
|
+
request: { ...message.request, executable: name(message.request.executable) }
|
|
2132
|
+
};
|
|
2133
|
+
return message;
|
|
2134
|
+
}
|
|
2135
|
+
childError(child, event) {
|
|
2136
|
+
const context = child.context;
|
|
2137
|
+
event.preventDefault();
|
|
2138
|
+
if (!this.currentChild(child)) {
|
|
2139
|
+
this.traceProcess(child.identity, "dropped", "stale-image");
|
|
2140
|
+
return;
|
|
2141
|
+
}
|
|
2142
|
+
child.failed = true;
|
|
2143
|
+
this.disposeNetwork(child);
|
|
2144
|
+
let status;
|
|
2145
|
+
try {
|
|
2146
|
+
status = startStatus(context.outcome);
|
|
2147
|
+
} catch (error) {
|
|
2148
|
+
if (error instanceof ProcessError && (error.errno === ProcessErrno.SRCH || error.errno === ProcessErrno.CHILD))
|
|
2149
|
+
return;
|
|
2150
|
+
throw error;
|
|
2151
|
+
}
|
|
2152
|
+
if (status !== 0)
|
|
2153
|
+
context.startFailed(event.error ?? new Error(event.message));
|
|
2154
|
+
else
|
|
2155
|
+
context.fail(new Error(event.message));
|
|
2156
|
+
}
|
|
2157
|
+
admitGroupMember(pid, transport, join, headroom = null) {
|
|
2158
|
+
const groups = this.groups ??= new MemoryGroups(this.options.memoryGroups, this.options.reservations.groups, this.options.reservations.sizing);
|
|
2159
|
+
const target = join === "inherit" ? groups.groupOf(workerProcessState(transport).parentPid) : join;
|
|
2160
|
+
if (!target)
|
|
2161
|
+
throw new ProcessError(ProcessErrno.SRCH, "parent has no memory group");
|
|
2162
|
+
const directory = transport.directory;
|
|
2163
|
+
return groups.admit(pid, workerProcessDirectoryId(transport), target, headroom, () => this.terminalGroupAdmission(directory));
|
|
2164
|
+
}
|
|
2165
|
+
terminalGroupAdmission(directory) {
|
|
2166
|
+
const wake = new Int32Array(directory, 4, 1);
|
|
2167
|
+
const seen = Atomics.load(wake, 0);
|
|
2168
|
+
try {
|
|
2169
|
+
const version = directoryAdmissionVersion(directory);
|
|
2170
|
+
if (!this.groupIntentsSettled(directory)) {
|
|
2171
|
+
this.deferGroupAdmission(directory, wake, seen);
|
|
2172
|
+
return false;
|
|
2173
|
+
}
|
|
2174
|
+
commitDirectoryAdmission(directory, version);
|
|
2175
|
+
this.cancelGroupAdmissionWatch(directory);
|
|
2176
|
+
return true;
|
|
2177
|
+
} catch (error) {
|
|
2178
|
+
if (!(error instanceof ProcessError) || error.errno !== ProcessErrno.NOTSUP && !isCollectedProcess(error))
|
|
2179
|
+
throw error;
|
|
2180
|
+
this.deferGroupAdmission(directory, wake, seen);
|
|
2181
|
+
return false;
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
groupIntentsSettled(directory) {
|
|
2185
|
+
const domain = atomicsLoad(new BigInt64ArrayConstructor(directory, 8, 1), 0);
|
|
2186
|
+
const domainWords = new Uint32Array(directory, 8, 2);
|
|
2187
|
+
const lifetimeDomain = `${domainWords[0]}:${domainWords[1]}`;
|
|
2188
|
+
const sameDirectory = (source) => source.kind === "directory" && atomicsLoad(new BigInt64ArrayConstructor(source.directory, 8, 1), 0) === domain;
|
|
2189
|
+
for (const launch of this.pendingLaunches?.values() ?? [])
|
|
2190
|
+
if (launch.acquiring && sameDirectory(launch.observation))
|
|
2191
|
+
return false;
|
|
2192
|
+
for (const preparation of this.pendingPreparations)
|
|
2193
|
+
if (sameDirectory(preparation.observation))
|
|
2194
|
+
return false;
|
|
2195
|
+
for (const state of directoryProcesses(directory)) {
|
|
2196
|
+
const key = `directory:${domain}:${state.slot}:${state.pid}`;
|
|
2197
|
+
const root = this.roots.get(state.pid);
|
|
2198
|
+
if (root && observationKey(root) === key)
|
|
2199
|
+
continue;
|
|
2200
|
+
const child = this.children.get(state.pid);
|
|
2201
|
+
if (child && observationKey(child.transport) === key && this.currentChild(child)) {
|
|
2202
|
+
if (child.launch.pending?.acquiring)
|
|
2203
|
+
return false;
|
|
2204
|
+
continue;
|
|
2205
|
+
}
|
|
2206
|
+
if (this.settledGroupAcquisitions.has(key))
|
|
2207
|
+
continue;
|
|
2208
|
+
if (this.settledGroupRecord(state.pid, key))
|
|
2209
|
+
continue;
|
|
2210
|
+
if (controlLoad(state.confirmed) && this.acquiredProcesses.get(state.pid) !== `${lifetimeDomain}:${state.slot}:${state.pid}`)
|
|
2211
|
+
continue;
|
|
2212
|
+
return false;
|
|
2213
|
+
}
|
|
2214
|
+
return true;
|
|
2215
|
+
}
|
|
2216
|
+
settledGroupRecord(pid, key) {
|
|
2217
|
+
const record = this.options.table.get(pid);
|
|
2218
|
+
if (!record || observationKey(record.observation) !== key)
|
|
2219
|
+
return false;
|
|
2220
|
+
return record.image.execution?.kind === "host" || record.image.nativeAcquisition.kind === "not-invoked" && !!readOutcome(record.outcome);
|
|
2221
|
+
}
|
|
2222
|
+
deferGroupAdmission(directory, wake, seen) {
|
|
2223
|
+
if (this.groupAdmissionWatches.has(directory))
|
|
2224
|
+
return;
|
|
2225
|
+
this.groupAdmissionWatches.set(directory, wake);
|
|
2226
|
+
const waiting = atomicsWaitAsync(wake, 0, seen);
|
|
2227
|
+
Promise.resolve(waiting.value).then(() => {
|
|
2228
|
+
if (this.groupAdmissionWatches.get(directory) !== wake)
|
|
2229
|
+
return;
|
|
2230
|
+
this.groupAdmissionWatches.delete(directory);
|
|
2231
|
+
this.groups?.settleStopping();
|
|
2232
|
+
}).catch((error) => this.report(error));
|
|
2233
|
+
}
|
|
2234
|
+
cancelGroupAdmissionWatch(directory) {
|
|
2235
|
+
const wake = this.groupAdmissionWatches.get(directory);
|
|
2236
|
+
if (!wake)
|
|
2237
|
+
return;
|
|
2238
|
+
this.groupAdmissionWatches.delete(directory);
|
|
2239
|
+
Atomics.notify(wake, 0);
|
|
2240
|
+
}
|
|
2241
|
+
writeStartupDiagnostic(pid, error, active) {
|
|
2242
|
+
const record = this.options.table.get(pid);
|
|
2243
|
+
if (record?.state === "starting")
|
|
2244
|
+
this.traceProcess(record, "rejected", "start-failed");
|
|
2245
|
+
const runtimeChild = record !== undefined && record.parentPid !== 0 && this.transport.get(pid) !== undefined;
|
|
2246
|
+
if (runtimeChild)
|
|
2247
|
+
this.report(error);
|
|
2248
|
+
const controller = this.controllerFor(pid);
|
|
2249
|
+
if (controller?.startFailed)
|
|
2250
|
+
return controller.startFailed(error, active);
|
|
2251
|
+
if (runtimeChild)
|
|
2252
|
+
return;
|
|
2253
|
+
const stderr = this.children.get(pid)?.startupStderr ?? record?.image.descriptors.get(2)?.resource;
|
|
2254
|
+
if (stderr?.kind !== "pipe" && stderr?.kind !== "terminal")
|
|
2255
|
+
return;
|
|
2256
|
+
const bytes = new TextEncoder().encode(`runtime: process start failed: ${String(error)}
|
|
2257
|
+
`);
|
|
2258
|
+
const write = stderr.tryWrite;
|
|
2259
|
+
if (!write)
|
|
2260
|
+
throw new ProcessError(ProcessErrno.NOTSUP, "startup diagnostic requires immediate stderr writes");
|
|
2261
|
+
const pending = drainDiagnostic(bytes, (bytes) => write.call(stderr, [bytes]), () => active() && !this.suspended);
|
|
2262
|
+
if (pending) {
|
|
2263
|
+
this.startupDiagnostics.add(pending);
|
|
2264
|
+
pending.finally(() => this.startupDiagnostics.delete(pending)).catch(() => {});
|
|
2265
|
+
}
|
|
2266
|
+
return pending;
|
|
2267
|
+
}
|
|
2268
|
+
collectRuntimeProcess(pid, directory) {
|
|
2269
|
+
for (const [rootPid, transport] of this.roots) {
|
|
2270
|
+
if (directory !== undefined && workerProcessDirectoryId(transport) !== directory)
|
|
2271
|
+
continue;
|
|
2272
|
+
const root = this.options.table.get(pid)?.rootPid;
|
|
2273
|
+
if (root !== undefined && root !== rootPid)
|
|
2274
|
+
continue;
|
|
2275
|
+
this.registries.get(rootPid)?.collectProcess(pid);
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
quiesceProcess(pid) {
|
|
2279
|
+
this.cancelPreparations(pid);
|
|
2280
|
+
const child = this.children.get(pid);
|
|
2281
|
+
if (child && !this.roots.has(pid) && !this.reservedRoots.has(pid)) {
|
|
2282
|
+
if (child.finalQuiet)
|
|
2283
|
+
return;
|
|
2284
|
+
const terminal = this.terminalLifetimes.get(pid)?.quiesce();
|
|
2285
|
+
return child.finalFence ??= Promise.all([this.imageFence(child), terminal]).then(() => this.joinCommandExec(child.transport)).then(() => {
|
|
2286
|
+
this.collectRuntimeProcess(pid);
|
|
2287
|
+
child.finalQuiet = true;
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2290
|
+
const pending = this.fences.get(pid);
|
|
2291
|
+
if (pending)
|
|
2292
|
+
return pending;
|
|
2293
|
+
const controller = this.controllerFor(pid);
|
|
2294
|
+
if (controller && this.quiescedControllers.has(pid))
|
|
2295
|
+
return;
|
|
2296
|
+
const complete = () => {
|
|
2297
|
+
this.collectRuntimeProcess(pid);
|
|
2298
|
+
if (controller)
|
|
2299
|
+
this.quiescedControllers.add(pid);
|
|
2300
|
+
};
|
|
2301
|
+
let fence;
|
|
2302
|
+
try {
|
|
2303
|
+
fence = this.processFence(pid);
|
|
2304
|
+
} catch (error) {
|
|
2305
|
+
fence = Promise.reject(error);
|
|
2306
|
+
}
|
|
2307
|
+
if (fence) {
|
|
2308
|
+
const pending = Promise.resolve(fence).then(complete);
|
|
2309
|
+
this.fences.set(pid, pending);
|
|
2310
|
+
return pending;
|
|
2311
|
+
}
|
|
2312
|
+
complete();
|
|
2313
|
+
}
|
|
2314
|
+
revokeController(pid) {
|
|
2315
|
+
const controller = this.controllerFor(pid);
|
|
2316
|
+
const child = this.children.get(pid);
|
|
2317
|
+
if (child) {
|
|
2318
|
+
child.revokeController?.();
|
|
2319
|
+
return;
|
|
2320
|
+
}
|
|
2321
|
+
const captured = this.capturedControllerRevocations.get(pid);
|
|
2322
|
+
if (captured) {
|
|
2323
|
+
captured();
|
|
2324
|
+
return;
|
|
2325
|
+
}
|
|
2326
|
+
if (!controller || this.revokedControllers.has(pid))
|
|
2327
|
+
return;
|
|
2328
|
+
this.revokedControllers.add(pid);
|
|
2329
|
+
if (controller.filesystem)
|
|
2330
|
+
this.options.filesystem.revoke(controller.filesystem);
|
|
2331
|
+
controller.revoke?.();
|
|
2332
|
+
}
|
|
2333
|
+
processFence(pid) {
|
|
2334
|
+
const pending = [];
|
|
2335
|
+
const preparation = Array.from(this.pendingPreparations).find((entry) => entry.pid === pid);
|
|
2336
|
+
if (preparation)
|
|
2337
|
+
pending.push(preparation.settled);
|
|
2338
|
+
const terminal = this.terminalLifetimes.get(pid)?.quiesce();
|
|
2339
|
+
if (terminal)
|
|
2340
|
+
pending.push(terminal);
|
|
2341
|
+
this.revokeController(pid);
|
|
2342
|
+
const controller = this.controllerFor(pid);
|
|
2343
|
+
const threaded = this.children.get(pid);
|
|
2344
|
+
if (threaded?.threads) {
|
|
2345
|
+
const adapterFence = controller?.quiesce?.();
|
|
2346
|
+
if (adapterFence)
|
|
2347
|
+
pending.push(adapterFence);
|
|
2348
|
+
pending.push(threaded.threads.then((owner) => owner ? owner.fence() : this.quiesceChild(threaded)));
|
|
2349
|
+
if (controller?.filesystem && controller.filesystem.sections !== threaded.filesystem.sections)
|
|
2350
|
+
pending.push(this.options.filesystem.quiesce(controller.filesystem));
|
|
2351
|
+
return Promise.all(pending).then(() => {});
|
|
2352
|
+
}
|
|
2353
|
+
const adapter = controller?.quiesce?.();
|
|
2354
|
+
if (adapter)
|
|
2355
|
+
pending.push(adapter);
|
|
2356
|
+
if (controller?.filesystem && !controller.acknowledged?.())
|
|
2357
|
+
pending.push(this.options.filesystem.quiesce(controller.filesystem));
|
|
2358
|
+
const child = this.children.get(pid);
|
|
2359
|
+
if (child) {
|
|
2360
|
+
const filesystem = this.quiesceChild(child);
|
|
2361
|
+
if (filesystem)
|
|
2362
|
+
pending.push(filesystem);
|
|
2363
|
+
} else {
|
|
2364
|
+
const transport = this.transport.get(pid);
|
|
2365
|
+
if (transport) {
|
|
2366
|
+
const filesystem = this.filesystem(transport);
|
|
2367
|
+
if (!controller?.filesystem || filesystem.sections !== controller.filesystem.sections) {
|
|
2368
|
+
pending.push(this.options.filesystem.quiesce(filesystem));
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
const transport = this.transport.get(pid);
|
|
2373
|
+
if (transport && this.commandScope(transport))
|
|
2374
|
+
return Promise.all(pending).then(() => this.joinCommandExec(transport));
|
|
2375
|
+
if (pending.length)
|
|
2376
|
+
return Promise.all(pending).then(() => {});
|
|
2377
|
+
}
|
|
2378
|
+
quiesceChild(child) {
|
|
2379
|
+
if (child.acknowledged && !child.replacementAcknowledged)
|
|
2380
|
+
return;
|
|
2381
|
+
return child.quiescence ??= this.options.filesystem.quiesce(child.filesystem);
|
|
2382
|
+
}
|
|
2383
|
+
disposeNetwork(child) {
|
|
2384
|
+
try {
|
|
2385
|
+
child.graphics?.dispose();
|
|
2386
|
+
} catch (error) {
|
|
2387
|
+
this.report(error);
|
|
2388
|
+
}
|
|
2389
|
+
const network = child.network;
|
|
2390
|
+
child.network = undefined;
|
|
2391
|
+
try {
|
|
2392
|
+
network?.dispose();
|
|
2393
|
+
} catch (error) {
|
|
2394
|
+
this.report(error);
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
disposeNotifications(child) {
|
|
2398
|
+
child?.notifications?.dispose().catch((error) => this.report(error));
|
|
2399
|
+
}
|
|
2400
|
+
async stopUnstartedThread(child) {
|
|
2401
|
+
await this.quiesceChild(child);
|
|
2402
|
+
child.nativeReturned?.();
|
|
2403
|
+
}
|
|
2404
|
+
async stopNotifications(child, errors) {
|
|
2405
|
+
try {
|
|
2406
|
+
await child.notifications?.dispose();
|
|
2407
|
+
return true;
|
|
2408
|
+
} catch (error) {
|
|
2409
|
+
errors.push(error);
|
|
2410
|
+
return false;
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
launchState(context) {
|
|
2414
|
+
let launch = this.launchStates.get(context);
|
|
2415
|
+
if (!launch) {
|
|
2416
|
+
launch = { active: false };
|
|
2417
|
+
this.launchStates.set(context, launch);
|
|
2418
|
+
}
|
|
2419
|
+
return launch;
|
|
2420
|
+
}
|
|
2421
|
+
imageLaunches() {
|
|
2422
|
+
return Array.from(this.children.values(), (child) => child.launch);
|
|
2423
|
+
}
|
|
2424
|
+
controllerFor(pid) {
|
|
2425
|
+
return this.children.get(pid)?.controller ?? this.controllers.get(pid);
|
|
2426
|
+
}
|
|
2427
|
+
capturedControllerStopFor(pid) {
|
|
2428
|
+
return this.children.get(pid)?.capturedControllerStop ?? this.capturedControllerStops.get(pid);
|
|
2429
|
+
}
|
|
2430
|
+
controllerNativeStopFor(pid) {
|
|
2431
|
+
return this.children.get(pid)?.controllerNativeStop ?? this.controllerNativeStops.get(pid);
|
|
2432
|
+
}
|
|
2433
|
+
controllerNativeReturnFor(pid) {
|
|
2434
|
+
return this.children.get(pid)?.controllerNativeReturn ?? this.controllerNativeReturns.get(pid);
|
|
2435
|
+
}
|
|
2436
|
+
captureImageState(child) {
|
|
2437
|
+
const pid = child.context.pid;
|
|
2438
|
+
if (this.roots.has(pid) || this.reservedRoots.has(pid))
|
|
2439
|
+
return;
|
|
2440
|
+
child.controller = this.controllers.get(pid);
|
|
2441
|
+
child.controllerQuiet = this.quiescedControllers.has(pid);
|
|
2442
|
+
this.quiescedControllers.delete(pid);
|
|
2443
|
+
this.revokedControllers.delete(pid);
|
|
2444
|
+
child.revokeController = this.capturedControllerRevocations.get(pid);
|
|
2445
|
+
this.capturedControllerRevocations.delete(pid);
|
|
2446
|
+
child.capturedControllerStop = this.capturedControllerStops.get(pid);
|
|
2447
|
+
child.controllerNativeStop = this.controllerNativeStops.get(pid);
|
|
2448
|
+
child.controllerNativeReturn = this.controllerNativeReturns.get(pid);
|
|
2449
|
+
child.fence = this.fences.get(pid);
|
|
2450
|
+
child.controllerStopping = this.controllerStops?.get(pid);
|
|
2451
|
+
this.controllerStops?.delete(pid);
|
|
2452
|
+
this.launches?.delete(pid);
|
|
2453
|
+
this.pendingLaunches?.delete(pid);
|
|
2454
|
+
child.accesses = new WorkerExecutableAccess({
|
|
2455
|
+
active: () => this.currentChild(child) && !this.suspended && !isRevoked(child.filesystem) && this.options.table.get(pid)?.image.phase === "current",
|
|
2456
|
+
check: async (_sender, path, cwd, active) => {
|
|
2457
|
+
await this.options.registry.check(path, cwd, active);
|
|
2458
|
+
return 0;
|
|
2459
|
+
}
|
|
2460
|
+
});
|
|
2461
|
+
this.controllers.delete(pid);
|
|
2462
|
+
this.capturedControllerStops.delete(pid);
|
|
2463
|
+
this.controllerNativeStops.delete(pid);
|
|
2464
|
+
this.controllerNativeReturns.delete(pid);
|
|
2465
|
+
this.fences.delete(pid);
|
|
2466
|
+
}
|
|
2467
|
+
controllerRevocation(controller) {
|
|
2468
|
+
let revoked = false;
|
|
2469
|
+
return () => {
|
|
2470
|
+
if (revoked)
|
|
2471
|
+
return;
|
|
2472
|
+
revoked = true;
|
|
2473
|
+
if (controller.filesystem)
|
|
2474
|
+
this.options.filesystem.revoke(controller.filesystem);
|
|
2475
|
+
controller.revoke?.();
|
|
2476
|
+
};
|
|
2477
|
+
}
|
|
2478
|
+
currentChild(child) {
|
|
2479
|
+
const image = this.options.table.get(child.context.pid)?.image;
|
|
2480
|
+
return this.children.get(child.context.pid) === child && image?.generation === child.generation && (image.phase === "current" || image.phase === "retiring");
|
|
2481
|
+
}
|
|
2482
|
+
canExec(transport) {
|
|
2483
|
+
const child = this.children.get(transport.pid);
|
|
2484
|
+
return !!child?.worker && this.options.table.get(transport.pid)?.processKind === "process" && this.currentChild(child) && !child.threads && !child.stopped && !child.stopping && !child.failed && !this.roots.has(transport.pid) && !this.reservedRoots.has(transport.pid) && !this.rootAdmissions.has(transport.pid) && this.options.table.get(transport.pid)?.image.phase === "current" && child.generation === transport.generation && !this.options.table.get(transport.pid)?.image.request?.worker && workerProcessDirectoryId(child.transport) === workerProcessDirectoryId(transport);
|
|
2485
|
+
}
|
|
2486
|
+
checkGuestImage(pid, generation) {
|
|
2487
|
+
const image = this.options.table.get(pid)?.image;
|
|
2488
|
+
if (image?.execution?.kind === "host")
|
|
2489
|
+
throw new ProcessError(ProcessErrno.NOTSUP, "host-only image cannot acquire a guest consumer");
|
|
2490
|
+
if (generation !== undefined && image?.generation !== generation)
|
|
2491
|
+
throw new ProcessError(ProcessErrno.SRCH, "guest consumer image is no longer current");
|
|
2492
|
+
}
|
|
2493
|
+
commitReplacement(pid, generation, resolved) {
|
|
2494
|
+
const child = this.children.get(pid);
|
|
2495
|
+
if (!child || child.generation !== generation || !this.canExec(child.transport))
|
|
2496
|
+
throw new ProcessError(ProcessErrno.NOTSUP, "replacement lost its owned source image");
|
|
2497
|
+
const image = this.options.table.require(pid).image;
|
|
2498
|
+
const admission = workerProcessState(child.transport).imageAdmission;
|
|
2499
|
+
if (controlCas(admission, 0, generation, -generation) !== generation)
|
|
2500
|
+
throw new ProcessError(ProcessErrno.NOTSUP, "replacement source image admission is closed");
|
|
2501
|
+
const current = () => this.options.table.get(pid)?.image === image && image.phase === "current";
|
|
2502
|
+
let membership;
|
|
2503
|
+
const rollback = () => {
|
|
2504
|
+
if (!current())
|
|
2505
|
+
return;
|
|
2506
|
+
membership?.rollback();
|
|
2507
|
+
controlCas(admission, 0, -generation, generation);
|
|
2508
|
+
if (!readOutcome(child.context.outcome))
|
|
2509
|
+
child.replacing = false;
|
|
2510
|
+
};
|
|
2511
|
+
try {
|
|
2512
|
+
membership = this.closeReplacementGroup(child, resolved);
|
|
2513
|
+
} catch (error) {
|
|
2514
|
+
rollback();
|
|
2515
|
+
throw error;
|
|
2516
|
+
}
|
|
2517
|
+
child.replacing = true;
|
|
2518
|
+
return { rollback };
|
|
2519
|
+
}
|
|
2520
|
+
closeReplacementGroup(child, resolved) {
|
|
2521
|
+
if (!child.group)
|
|
2522
|
+
return;
|
|
2523
|
+
if (resolved.kind !== "module" || resolved.execution?.kind !== "host")
|
|
2524
|
+
throw new ProcessError(ProcessErrno.NOTSUP, "shared caller requires a bound host-only target");
|
|
2525
|
+
const directory = child.transport.directory;
|
|
2526
|
+
const version = directoryAdmissionVersion(directory);
|
|
2527
|
+
this.checkGroupIntents(child);
|
|
2528
|
+
commitDirectoryAdmission(directory, version);
|
|
2529
|
+
return child.group.closeAdmission();
|
|
2530
|
+
}
|
|
2531
|
+
checkGroupIntents(source) {
|
|
2532
|
+
const directory = source.identity.directory;
|
|
2533
|
+
for (const state of directoryProcesses(source.transport.directory)) {
|
|
2534
|
+
if (state.pid === source.context.pid)
|
|
2535
|
+
continue;
|
|
2536
|
+
if (this.pendingLaunches?.has(state.pid))
|
|
2537
|
+
throw new ProcessError(ProcessErrno.NOTSUP, "same-directory adapter acquisition is unresolved");
|
|
2538
|
+
if (this.roots.has(state.pid))
|
|
2539
|
+
continue;
|
|
2540
|
+
const child = this.children.get(state.pid);
|
|
2541
|
+
if (child?.launch.pending)
|
|
2542
|
+
throw new ProcessError(ProcessErrno.NOTSUP, "same-directory adapter acquisition is unresolved");
|
|
2543
|
+
if (child && this.currentChild(child) && !child.failed)
|
|
2544
|
+
continue;
|
|
2545
|
+
const image = this.options.table.get(state.pid)?.image;
|
|
2546
|
+
if (image?.execution?.kind === "host")
|
|
2547
|
+
continue;
|
|
2548
|
+
if (controlLoad(state.confirmed) && !this.acquiredProcesses.has(state.pid))
|
|
2549
|
+
continue;
|
|
2550
|
+
throw new ProcessError(ProcessErrno.NOTSUP, "same-directory group intent is unresolved");
|
|
2551
|
+
}
|
|
2552
|
+
for (const preparation of this.pendingPreparations) {
|
|
2553
|
+
if (preparation.pid === source.context.pid)
|
|
2554
|
+
continue;
|
|
2555
|
+
const root = this.roots.get(preparation.rootPid);
|
|
2556
|
+
if (root && workerProcessDirectoryId(root) === directory)
|
|
2557
|
+
throw new ProcessError(ProcessErrno.NOTSUP, "same-directory preparation is unresolved");
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
reportReplacementFailure(pid, error) {
|
|
2561
|
+
const image = this.options.table.get(pid)?.image;
|
|
2562
|
+
if (image && this.replacementDiagnostics.has(image))
|
|
2563
|
+
return;
|
|
2564
|
+
if (image)
|
|
2565
|
+
this.replacementDiagnostics.add(image);
|
|
2566
|
+
this.report(error);
|
|
2567
|
+
}
|
|
2568
|
+
imageFence(child) {
|
|
2569
|
+
if (child.fence)
|
|
2570
|
+
return child.fence;
|
|
2571
|
+
const controller = child.controller;
|
|
2572
|
+
child.revokeController?.();
|
|
2573
|
+
const pending = [
|
|
2574
|
+
child.controllerQuiet ? undefined : controller?.quiesce?.()
|
|
2575
|
+
];
|
|
2576
|
+
pending.push(child.threads ? child.threads.then((owner) => owner ? owner.fence() : this.quiesceChild(child)) : this.quiesceChild(child));
|
|
2577
|
+
if (controller?.filesystem && controller.filesystem.sections !== child.filesystem.sections)
|
|
2578
|
+
pending.push(this.options.filesystem.quiesce(controller.filesystem));
|
|
2579
|
+
return child.fence = Promise.all(pending).then(() => {
|
|
2580
|
+
child.controllerQuiet = true;
|
|
2581
|
+
});
|
|
2582
|
+
}
|
|
2583
|
+
async stopImage(pid, generation, active) {
|
|
2584
|
+
const child = this.children.get(pid);
|
|
2585
|
+
if (!child || child.generation !== generation)
|
|
2586
|
+
throw new Error("replacement lost its image owner");
|
|
2587
|
+
await this.stopPhysical(child, true);
|
|
2588
|
+
if (!active())
|
|
2589
|
+
return;
|
|
2590
|
+
const terminal = this.terminalLifetimes.get(pid);
|
|
2591
|
+
if (terminal && !await terminal.handoff(active) && active())
|
|
2592
|
+
throw new ProcessError(ProcessErrno.CANCELED, "terminal image handoff is permanently revoked");
|
|
2593
|
+
}
|
|
2594
|
+
async finalizeProcess(pid) {
|
|
2595
|
+
const stopped = this.imageStops.get(pid);
|
|
2596
|
+
if (!stopped)
|
|
2597
|
+
return;
|
|
2598
|
+
await stopped;
|
|
2599
|
+
const returned = this.nativeLaunchReturns.get(pid);
|
|
2600
|
+
this.nativeLaunchReturns.delete(pid);
|
|
2601
|
+
returned?.();
|
|
2602
|
+
this.observationOwners.get(pid)?.close();
|
|
2603
|
+
this.terminalLifetimes.get(pid)?.stopped();
|
|
2604
|
+
this.collectRuntimeProcess(pid);
|
|
2605
|
+
this.revokeRuntimeProcess(pid);
|
|
2606
|
+
this.imageStops.delete(pid);
|
|
2607
|
+
this.releaseAcquiredProcess(pid);
|
|
2608
|
+
}
|
|
2609
|
+
stop(child) {
|
|
2610
|
+
this.observationOwners.get(child.context.pid)?.close();
|
|
2611
|
+
return Promise.resolve(this.stopPhysical(child)).then(() => this.finalizeProcess(child.context.pid));
|
|
2612
|
+
}
|
|
2613
|
+
stopWorker(child) {
|
|
2614
|
+
return child.replacing ? this.stopNativeResources(child) : this.stop(child);
|
|
2615
|
+
}
|
|
2616
|
+
stopPhysical(child, replacing = false) {
|
|
2617
|
+
if (child.stopping)
|
|
2618
|
+
return child.stopping;
|
|
2619
|
+
child.accesses?.dispose();
|
|
2620
|
+
if (child.threads) {
|
|
2621
|
+
child.stopping = child.threads.then((owner) => owner ? owner.stop() : this.stopUnstartedThread(child)).then(() => {
|
|
2622
|
+
child.stopped = true;
|
|
2623
|
+
if (this.children.get(child.context.pid) === child)
|
|
2624
|
+
this.children.delete(child.context.pid);
|
|
2625
|
+
this.retireChildController(child.context.pid, child);
|
|
2626
|
+
});
|
|
2627
|
+
this.imageStops.set(child.context.pid, child.stopping);
|
|
2628
|
+
return child.stopping;
|
|
2629
|
+
}
|
|
2630
|
+
const stop = async () => {
|
|
2631
|
+
const errors = [];
|
|
2632
|
+
if (child.replacing)
|
|
2633
|
+
await settleStop(() => this.stopAcceptedAdapter(child), errors);
|
|
2634
|
+
await settleStop(() => this.stopNativeResources(child), errors);
|
|
2635
|
+
if (errors.length) {
|
|
2636
|
+
child.group?.failed();
|
|
2637
|
+
child.launched?.failed(errors);
|
|
2638
|
+
throw new AggregateError(errors, "Child physical stop failed");
|
|
2639
|
+
}
|
|
2640
|
+
child.graphics = undefined;
|
|
2641
|
+
child.controllerNativeStop?.imageReturned();
|
|
2642
|
+
if (child.replacementAcknowledged)
|
|
2643
|
+
this.options.filesystem.reap(child.filesystem);
|
|
2644
|
+
child.group?.stopped();
|
|
2645
|
+
child.launched?.stopped();
|
|
2646
|
+
if (this.children.get(child.context.pid) === child)
|
|
2647
|
+
this.children.delete(child.context.pid);
|
|
2648
|
+
child.output?.retire();
|
|
2649
|
+
this.serviceTerminalOutput(child.identity.rootPid);
|
|
2650
|
+
this.retireChildController(child.context.pid, child);
|
|
2651
|
+
child.adapter = undefined;
|
|
2652
|
+
};
|
|
2653
|
+
if (!replacing && !child.replacing)
|
|
2654
|
+
this.signalStop(child.context.pid);
|
|
2655
|
+
const fence = replacing ? this.imageFence(child) : this.quiesceProcess(child.context.pid);
|
|
2656
|
+
child.stopping = (fence ? fence.then(stop) : stop()).catch((error) => {
|
|
2657
|
+
this.observationOwners.get(child.context.pid)?.fail(error);
|
|
2658
|
+
child.group?.failed();
|
|
2659
|
+
child.launched?.failed([error]);
|
|
2660
|
+
throw error;
|
|
2661
|
+
});
|
|
2662
|
+
this.imageStops.set(child.context.pid, child.stopping);
|
|
2663
|
+
return child.stopping;
|
|
2664
|
+
}
|
|
2665
|
+
async stopAcceptedAdapter(child) {
|
|
2666
|
+
await child.launch.pending?.acquired;
|
|
2667
|
+
if (!child.adapter)
|
|
2668
|
+
throw new Error("replacement source has no accepted adapter cleanup handle");
|
|
2669
|
+
await child.adapter.terminate();
|
|
2670
|
+
}
|
|
2671
|
+
stopNativeResources(child) {
|
|
2672
|
+
if (child.nativeStopping)
|
|
2673
|
+
return child.nativeStopping;
|
|
2674
|
+
const stopped = Promise.withResolvers();
|
|
2675
|
+
child.nativeStopping = stopped.promise;
|
|
2676
|
+
this.stopNativeResourcesNow(child).then(stopped.resolve, stopped.reject);
|
|
2677
|
+
return stopped.promise;
|
|
2678
|
+
}
|
|
2679
|
+
async stopNativeResourcesNow(child) {
|
|
2680
|
+
if (child.replacing)
|
|
2681
|
+
await this.imageFence(child);
|
|
2682
|
+
if (child.stopped)
|
|
2683
|
+
return;
|
|
2684
|
+
child.stopped = true;
|
|
2685
|
+
const errors = [];
|
|
2686
|
+
this.disposeNetwork(child);
|
|
2687
|
+
if (child.graphics)
|
|
2688
|
+
await settleStop(() => child.graphics.retired(), errors);
|
|
2689
|
+
if (child.notifications)
|
|
2690
|
+
await this.stopNotifications(child, errors);
|
|
2691
|
+
await settleStop(() => this.terminateWorker(child), errors);
|
|
2692
|
+
await settleStop(() => child.controllerStopping?.pending ?? child.capturedControllerStop?.(), errors);
|
|
2693
|
+
await settleStop(() => child.cleanup?.(), errors);
|
|
2694
|
+
if (errors.length)
|
|
2695
|
+
throw new AggregateError(errors, "Child native resource stop failed");
|
|
2696
|
+
}
|
|
2697
|
+
async terminateWorker(child) {
|
|
2698
|
+
const worker = child.worker;
|
|
2699
|
+
if (!worker)
|
|
2700
|
+
return;
|
|
2701
|
+
let ended;
|
|
2702
|
+
if (!child.replacing) {
|
|
2703
|
+
this.signalStop(child.context.pid);
|
|
2704
|
+
const unwinding = guestUnwound(child);
|
|
2705
|
+
if (unwinding)
|
|
2706
|
+
await unwinding;
|
|
2707
|
+
}
|
|
2708
|
+
try {
|
|
2709
|
+
ended = worker.terminate();
|
|
2710
|
+
} finally {
|
|
2711
|
+
child.group?.stopRequested();
|
|
2712
|
+
}
|
|
2713
|
+
await ended;
|
|
2714
|
+
worker.onmessage = null;
|
|
2715
|
+
worker.onerror = null;
|
|
2716
|
+
child.worker = undefined;
|
|
2717
|
+
}
|
|
2718
|
+
retireChildController(pid, child) {
|
|
2719
|
+
if (this.reservedRoots.has(pid) || this.roots.has(pid) || !child && this.suspended)
|
|
2720
|
+
return;
|
|
2721
|
+
const controller = child?.controller ?? this.controllers.get(pid);
|
|
2722
|
+
if (!child) {
|
|
2723
|
+
this.controllers.delete(pid);
|
|
2724
|
+
this.capturedControllerRevocations.delete(pid);
|
|
2725
|
+
}
|
|
2726
|
+
this.quiescedControllers.delete(pid);
|
|
2727
|
+
this.revokedControllers.delete(pid);
|
|
2728
|
+
if (!child)
|
|
2729
|
+
this.fences.delete(pid);
|
|
2730
|
+
this.releaseAcquiredProcess(pid);
|
|
2731
|
+
try {
|
|
2732
|
+
controller?.retired?.();
|
|
2733
|
+
} catch (error) {
|
|
2734
|
+
this.report(error);
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
stopController(pid) {
|
|
2738
|
+
if (this.suspended || this.reservedRoots.has(pid))
|
|
2739
|
+
return;
|
|
2740
|
+
const pending = this.controllerStops?.get(pid);
|
|
2741
|
+
if (pending)
|
|
2742
|
+
return pending.pending;
|
|
2743
|
+
const controller = this.controllerFor(pid);
|
|
2744
|
+
if (!controller)
|
|
2745
|
+
return;
|
|
2746
|
+
const nativeStop = this.controllerNativeStopFor(pid);
|
|
2747
|
+
const capturedStop = nativeStop?.terminate ?? this.capturedControllerStopFor(pid);
|
|
2748
|
+
const terminal = capturedStop ? this.terminalLifetimes.get(pid) : undefined;
|
|
2749
|
+
const group = nativeStop?.membership();
|
|
2750
|
+
const stopping = Promise.resolve(this.quiesceProcess(pid)).then(() => capturedStop?.()).then(() => {
|
|
2751
|
+
terminal?.stopped();
|
|
2752
|
+
if (group)
|
|
2753
|
+
this.settleRootGroup(pid, group);
|
|
2754
|
+
this.controllerStops?.delete(pid);
|
|
2755
|
+
this.retireChildController(pid);
|
|
2756
|
+
});
|
|
2757
|
+
(this.controllerStops ??= new Map).set(pid, { pending: stopping, controllerStop: true });
|
|
2758
|
+
return stopping;
|
|
2759
|
+
}
|
|
2760
|
+
async retireProcess(pid, rejectedTransferFenced = false) {
|
|
2761
|
+
await (this.children.get(pid)?.launch.pending ?? this.pendingLaunches?.get(pid))?.acquired;
|
|
2762
|
+
this.observationOwners.get(pid)?.close();
|
|
2763
|
+
if (this.suspended && !rejectedTransferFenced) {
|
|
2764
|
+
await this.retirementGate.promise;
|
|
2765
|
+
return;
|
|
2766
|
+
}
|
|
2767
|
+
const owner = this.observationOwners.get(pid);
|
|
2768
|
+
const child = this.children.get(pid);
|
|
2769
|
+
if (child)
|
|
2770
|
+
await this.stop(child);
|
|
2771
|
+
else {
|
|
2772
|
+
await this.stopController(pid);
|
|
2773
|
+
await this.finalizeProcess(pid);
|
|
2774
|
+
}
|
|
2775
|
+
await owner?.join();
|
|
2776
|
+
}
|
|
2777
|
+
stopSafely(child) {
|
|
2778
|
+
try {
|
|
2779
|
+
const pending = this.stop(child);
|
|
2780
|
+
if (pending)
|
|
2781
|
+
pending.catch((error) => this.report(error));
|
|
2782
|
+
} catch (error) {
|
|
2783
|
+
this.report(error);
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
states() {
|
|
2787
|
+
return Array.from(this.roots.values()).flatMap((root) => Array.from(directoryProcesses(root.directory)));
|
|
2788
|
+
}
|
|
2789
|
+
async kill(pid, signal) {
|
|
2790
|
+
const sig = checkedSignal(signal);
|
|
2791
|
+
const found = this.publishProcessSignal(pid, sig);
|
|
2792
|
+
const supervisor = await this.ready();
|
|
2793
|
+
if (this.suspended)
|
|
2794
|
+
return;
|
|
2795
|
+
if (supervisor.get(pid))
|
|
2796
|
+
supervisor.observeSignal(pid, sig);
|
|
2797
|
+
else if (!found)
|
|
2798
|
+
supervisor.kill(pid, sig);
|
|
2799
|
+
}
|
|
2800
|
+
publishProcessSignal(pid, signal, captured) {
|
|
2801
|
+
const target = captured ?? this.states().find((state) => state.pid === pid)?.signals ?? this.options.table.get(pid) ?? this.reservedRoots.get(pid);
|
|
2802
|
+
if (!target)
|
|
2803
|
+
return false;
|
|
2804
|
+
requestSignal(target, signal);
|
|
2805
|
+
if (readOutcome(target.outcome)?.kind === "signaled")
|
|
2806
|
+
this.revokeRuntimeProcess(pid);
|
|
2807
|
+
this.wake();
|
|
2808
|
+
if (captured && this.supervisor?.get(pid) === captured)
|
|
2809
|
+
this.supervisor.observeSignal(pid, signal);
|
|
2810
|
+
return true;
|
|
2811
|
+
}
|
|
2812
|
+
signalStop(pid) {
|
|
2813
|
+
try {
|
|
2814
|
+
this.publishStopSignal(pid);
|
|
2815
|
+
} catch (error) {
|
|
2816
|
+
this.report(error);
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
publishStopSignal(pid) {
|
|
2820
|
+
const target = this.states().find((state) => state.pid === pid)?.signals ?? this.options.table.get(pid) ?? this.reservedRoots.get(pid);
|
|
2821
|
+
if (target)
|
|
2822
|
+
this.requestSignalIfPresent(target, 9);
|
|
2823
|
+
}
|
|
2824
|
+
requestSignalIfPresent(target, signal) {
|
|
2825
|
+
try {
|
|
2826
|
+
requestSignal(target, signal);
|
|
2827
|
+
} catch (error) {
|
|
2828
|
+
if (!isCollectedProcess(error))
|
|
2829
|
+
throw error;
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
async killJob(job, signal, reserved = []) {
|
|
2833
|
+
const sig = checkedSignal(signal), states = this.states().filter((state) => state.job === job);
|
|
2834
|
+
const seen = new Set(states.map((state) => state.pid));
|
|
2835
|
+
const records = Array.from(this.options.table.values()).filter((record) => record.job === job && !seen.has(record.pid));
|
|
2836
|
+
for (const state of states)
|
|
2837
|
+
this.requestSignalIfPresent(state.signals, sig);
|
|
2838
|
+
for (const record of records)
|
|
2839
|
+
this.requestSignalIfPresent(record, sig);
|
|
2840
|
+
const published = new Set(states.map((state) => state.pid).concat(records.map((record) => record.pid)));
|
|
2841
|
+
const roots = Array.from(this.reservedRoots.values()).filter((root) => root.job === job && !published.has(root.pid));
|
|
2842
|
+
const reservations = roots.map((root) => ({ pid: root.pid, signals: root })).concat(reserved);
|
|
2843
|
+
for (const target of reservations)
|
|
2844
|
+
if (!published.has(target.pid)) {
|
|
2845
|
+
this.requestSignalIfPresent(target.signals, sig);
|
|
2846
|
+
published.add(target.pid);
|
|
2847
|
+
}
|
|
2848
|
+
for (const state of states) {
|
|
2849
|
+
try {
|
|
2850
|
+
if (readOutcome(state.signals.outcome)?.kind === "signaled")
|
|
2851
|
+
this.revokeRuntimeProcess(state.pid);
|
|
2852
|
+
} catch (error) {
|
|
2853
|
+
if (!isCollectedProcess(error))
|
|
2854
|
+
throw error;
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
2857
|
+
this.wake();
|
|
2858
|
+
const supervisor = await this.ready();
|
|
2859
|
+
if (this.suspended)
|
|
2860
|
+
return;
|
|
2861
|
+
for (const pid of published)
|
|
2862
|
+
if (supervisor.get(pid))
|
|
2863
|
+
supervisor.observeSignal(pid, sig);
|
|
2864
|
+
}
|
|
2865
|
+
wake() {
|
|
2866
|
+
for (const root of this.roots.values())
|
|
2867
|
+
wakeWorkerProcess(root);
|
|
2868
|
+
for (const controller of this.controllers.values())
|
|
2869
|
+
controller.wake?.();
|
|
2870
|
+
for (const child of this.children.values()) {
|
|
2871
|
+
child.controller?.wake?.();
|
|
2872
|
+
child.wake?.();
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
async rootExit(pid, code) {
|
|
2876
|
+
this.revokeRuntimeProcess(pid);
|
|
2877
|
+
if (!this.activation) {
|
|
2878
|
+
const root = this.reservedRoots.get(pid);
|
|
2879
|
+
if (root)
|
|
2880
|
+
claimOutcome(root.outcome, { kind: "exited", code });
|
|
2881
|
+
await this.quiesceProcess(pid);
|
|
2882
|
+
const transport = this.roots.get(pid);
|
|
2883
|
+
if (transport) {
|
|
2884
|
+
controlStore(workerProcessState(transport).confirmed, 0, 1);
|
|
2885
|
+
confirmWorkerProcessJob(transport);
|
|
2886
|
+
}
|
|
2887
|
+
if (root)
|
|
2888
|
+
this.completedRoots.add(pid);
|
|
2889
|
+
this.observationOwners.get(pid)?.close();
|
|
2890
|
+
this.retireRoots();
|
|
2891
|
+
return;
|
|
2892
|
+
}
|
|
2893
|
+
let supervisor;
|
|
2894
|
+
try {
|
|
2895
|
+
supervisor = await this.activation;
|
|
2896
|
+
} catch (error) {
|
|
2897
|
+
this.report(error);
|
|
2898
|
+
supervisor = this.supervisor;
|
|
2899
|
+
}
|
|
2900
|
+
if (supervisor?.get(pid)) {
|
|
2901
|
+
supervisor.exit(pid, code);
|
|
2902
|
+
await supervisor.waitForExit(0, pid);
|
|
2903
|
+
} else
|
|
2904
|
+
await this.quiesceProcess(pid);
|
|
2905
|
+
const transport = this.roots.get(pid);
|
|
2906
|
+
if (transport) {
|
|
2907
|
+
controlStore(workerProcessState(transport).confirmed, 0, 1);
|
|
2908
|
+
confirmWorkerProcessJob(transport);
|
|
2909
|
+
}
|
|
2910
|
+
if (this.reservedRoots.has(pid))
|
|
2911
|
+
this.completedRoots.add(pid);
|
|
2912
|
+
this.observationOwners.get(pid)?.close();
|
|
2913
|
+
this.retireRoots();
|
|
2914
|
+
}
|
|
2915
|
+
watch() {
|
|
2916
|
+
if (this.timer !== null || this.suspended)
|
|
2917
|
+
return;
|
|
2918
|
+
this.timer = setTimeout(() => {
|
|
2919
|
+
this.timer = null;
|
|
2920
|
+
try {
|
|
2921
|
+
this.transport.pump();
|
|
2922
|
+
} catch (error) {
|
|
2923
|
+
this.report(error);
|
|
2924
|
+
}
|
|
2925
|
+
if (this.children.size)
|
|
2926
|
+
this.watch();
|
|
2927
|
+
}, 4);
|
|
2928
|
+
}
|
|
2929
|
+
suspend() {
|
|
2930
|
+
if (this.suspended)
|
|
2931
|
+
return;
|
|
2932
|
+
this.suspended = true;
|
|
2933
|
+
this.cancelPreparations();
|
|
2934
|
+
this.workers.dispose();
|
|
2935
|
+
if (this.timer !== null)
|
|
2936
|
+
clearTimeout(this.timer);
|
|
2937
|
+
this.timer = null;
|
|
2938
|
+
for (const state of this.states())
|
|
2939
|
+
this.requestSignalIfPresent(state.signals, 9);
|
|
2940
|
+
for (const root of this.reservedRoots.values())
|
|
2941
|
+
this.requestSignalIfPresent(root, 9);
|
|
2942
|
+
for (const record of this.options.table.values())
|
|
2943
|
+
this.requestSignalIfPresent(record, 9);
|
|
2944
|
+
for (const state of this.states()) {
|
|
2945
|
+
this.revokeRuntimeProcess(state.pid);
|
|
2946
|
+
const transport = this.transport.get(state.pid);
|
|
2947
|
+
if (transport)
|
|
2948
|
+
this.options.filesystem.revoke(this.filesystem(transport));
|
|
2949
|
+
}
|
|
2950
|
+
for (const pid of this.controllers.keys()) {
|
|
2951
|
+
try {
|
|
2952
|
+
this.revokeController(pid);
|
|
2953
|
+
} catch (error) {
|
|
2954
|
+
this.report(error);
|
|
2955
|
+
}
|
|
2956
|
+
}
|
|
2957
|
+
const pids = new Set(Array.from(this.options.table.values(), (record) => record.pid).concat(Array.from(this.controllers.keys()), this.states().map((state) => state.pid)));
|
|
2958
|
+
for (const pid of pids)
|
|
2959
|
+
try {
|
|
2960
|
+
const pending = this.quiesceProcess(pid);
|
|
2961
|
+
if (pending)
|
|
2962
|
+
pending.catch((error) => this.report(error));
|
|
2963
|
+
} catch (error) {
|
|
2964
|
+
this.fences.set(pid, Promise.reject(error));
|
|
2965
|
+
}
|
|
2966
|
+
this.transport.dispose();
|
|
2967
|
+
this.supervisor?.dispose();
|
|
2968
|
+
}
|
|
2969
|
+
async quiesce() {
|
|
2970
|
+
await this.transport.settled();
|
|
2971
|
+
await Promise.all(this.rejectedTransfers.values());
|
|
2972
|
+
for (const scope of this.commandRoots?.values() ?? []) {
|
|
2973
|
+
await Promise.all(scope.pending);
|
|
2974
|
+
const failure = this.commandCleanupFailure(scope);
|
|
2975
|
+
if (failure)
|
|
2976
|
+
throw failure;
|
|
2977
|
+
}
|
|
2978
|
+
const pids = new Set(Array.from(this.options.table.values(), (record) => record.pid).concat(Array.from(this.controllers.keys()), Array.from(this.children.keys())));
|
|
2979
|
+
for (const pid of pids)
|
|
2980
|
+
this.quiesceProcess(pid);
|
|
2981
|
+
await Promise.all(Array.from(this.fences.values()).concat(Array.from(this.children.values(), (child) => child.finalFence ?? child.fence ?? Promise.resolve())));
|
|
2982
|
+
}
|
|
2983
|
+
stopDisposalController(pid, controller, failed) {
|
|
2984
|
+
this.observationOwners.get(pid)?.close();
|
|
2985
|
+
const stopping = this.controllerStops?.get(pid);
|
|
2986
|
+
const nativeStop = this.controllerNativeStopFor(pid);
|
|
2987
|
+
const capturedStop = nativeStop?.terminate ?? this.capturedControllerStopFor(pid);
|
|
2988
|
+
const ownsConsumer = capturedStop && !this.launches?.has(pid) && !this.children.has(pid);
|
|
2989
|
+
const terminal = ownsConsumer ? this.terminalLifetimes.get(pid) : undefined;
|
|
2990
|
+
const pending = stopping?.controllerStop ? stopping.pending : Promise.resolve().then(() => capturedStop?.());
|
|
2991
|
+
const group = ownsConsumer ? nativeStop?.membership() : undefined;
|
|
2992
|
+
return pending.then(() => {
|
|
2993
|
+
terminal?.stopped();
|
|
2994
|
+
if (group)
|
|
2995
|
+
this.settleRootGroup(pid, group);
|
|
2996
|
+
if (ownsConsumer) {
|
|
2997
|
+
this.rootStopped(pid);
|
|
2998
|
+
}
|
|
2999
|
+
}).catch((error) => {
|
|
3000
|
+
group?.failed();
|
|
3001
|
+
if (ownsConsumer)
|
|
3002
|
+
this.rootTickets.get(pid)?.failed([error]);
|
|
3003
|
+
failed.add(controller);
|
|
3004
|
+
throw error;
|
|
3005
|
+
});
|
|
3006
|
+
}
|
|
3007
|
+
retireDisposedControllers(failed, errors) {
|
|
3008
|
+
const retainedRoots = new Set(Array.from(this.children.values(), (child) => child.identity.rootPid));
|
|
3009
|
+
for (const [pid, controller] of this.controllers) {
|
|
3010
|
+
if (failed.has(controller) || retainedRoots.has(pid) || this.children.has(pid) || this.launches?.has(pid) || this.controllerStops?.has(pid))
|
|
3011
|
+
continue;
|
|
3012
|
+
try {
|
|
3013
|
+
controller.retired?.();
|
|
3014
|
+
} catch (error) {
|
|
3015
|
+
errors.push(error);
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
dispose() {
|
|
3020
|
+
if (this.disposing)
|
|
3021
|
+
return this.disposing;
|
|
3022
|
+
let resolve, reject;
|
|
3023
|
+
const disposal = this.disposing = new Promise((accept, fail) => {
|
|
3024
|
+
resolve = accept;
|
|
3025
|
+
reject = fail;
|
|
3026
|
+
});
|
|
3027
|
+
try {
|
|
3028
|
+
this.suspend();
|
|
3029
|
+
} catch (error) {
|
|
3030
|
+
reject(error);
|
|
3031
|
+
return disposal;
|
|
3032
|
+
}
|
|
3033
|
+
(async () => {
|
|
3034
|
+
if (this.activation) {
|
|
3035
|
+
try {
|
|
3036
|
+
await this.activation;
|
|
3037
|
+
} catch (error) {
|
|
3038
|
+
this.report(error);
|
|
3039
|
+
}
|
|
3040
|
+
this.supervisor?.dispose();
|
|
3041
|
+
}
|
|
3042
|
+
await Promise.allSettled(this.startupDiagnostics);
|
|
3043
|
+
await Promise.all(Array.from(this.pendingPreparations.values(), (preparation) => preparation.settled));
|
|
3044
|
+
await this.quiesce();
|
|
3045
|
+
await Promise.all(Array.from(this.pendingLaunches?.values() ?? [], (launch) => launch.acquired).concat(this.imageLaunches().map((launch) => launch.pending?.acquired ?? Promise.resolve())));
|
|
3046
|
+
const physicalHandles = this.supervisor?.retireFencedProcesses();
|
|
3047
|
+
const failedControllers = new Set;
|
|
3048
|
+
const stops = Array.from(this.children.values(), (child) => Promise.resolve().then(() => this.stop(child))).concat(Array.from(this.controllers, ([pid, controller]) => this.stopDisposalController(pid, controller, failedControllers)), Array.from(this.retainedRootStops, ([pid, controller]) => this.stopDisposalController(pid, controller, failedControllers)), Array.from(this.controllerStops?.values() ?? [], (stopping) => stopping.pending), Array.from(this.pendingLaunches?.values() ?? [], (launch) => launch.settled).concat(this.imageLaunches().map((launch) => launch.pending?.settled ?? Promise.resolve())));
|
|
3049
|
+
if (physicalHandles)
|
|
3050
|
+
stops.push(physicalHandles);
|
|
3051
|
+
const errors = [];
|
|
3052
|
+
for (const result of await Promise.allSettled(stops))
|
|
3053
|
+
if (result.status === "rejected")
|
|
3054
|
+
errors.push(result.reason);
|
|
3055
|
+
try {
|
|
3056
|
+
this.pipes.dispose();
|
|
3057
|
+
} catch (error) {
|
|
3058
|
+
errors.push(error);
|
|
3059
|
+
}
|
|
3060
|
+
for (const pid of Array.from(this.imageStops.keys())) {
|
|
3061
|
+
try {
|
|
3062
|
+
await this.finalizeProcess(pid);
|
|
3063
|
+
} catch (error) {
|
|
3064
|
+
if (!errors.includes(error))
|
|
3065
|
+
errors.push(error);
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
for (const owner of Array.from(this.observationOwners.values())) {
|
|
3069
|
+
const failures = await owner.stopAll();
|
|
3070
|
+
for (const failure of failures)
|
|
3071
|
+
if (!errors.includes(failure))
|
|
3072
|
+
errors.push(failure);
|
|
3073
|
+
}
|
|
3074
|
+
this.retireDisposedControllers(failedControllers, errors);
|
|
3075
|
+
const unsettled = this.groups?.unsettled() ?? 0;
|
|
3076
|
+
if (unsettled)
|
|
3077
|
+
errors.push(new Error(`${unsettled} memory group members have no proven physical stop`));
|
|
3078
|
+
if (errors.length) {
|
|
3079
|
+
const failure = new AggregateError(errors, "Process broker cleanup failed");
|
|
3080
|
+
this.retirementGate.reject(failure);
|
|
3081
|
+
throw failure;
|
|
3082
|
+
}
|
|
3083
|
+
this.retirementGate.resolve();
|
|
3084
|
+
this.reservedRoots.clear();
|
|
3085
|
+
this.descendantHooks.clear();
|
|
3086
|
+
this.signalPolicies.clear();
|
|
3087
|
+
this.completedRoots.clear();
|
|
3088
|
+
this.rootLeases.clear();
|
|
3089
|
+
this.roots.clear();
|
|
3090
|
+
this.commandRoots?.clear();
|
|
3091
|
+
this.outputs.clear();
|
|
3092
|
+
this.terminalOutputs.clear();
|
|
3093
|
+
this.registries.clear();
|
|
3094
|
+
this.controllers.clear();
|
|
3095
|
+
this.capturedControllerRevocations.clear();
|
|
3096
|
+
this.retainedRootStops.clear();
|
|
3097
|
+
this.controllerNativeStops.clear();
|
|
3098
|
+
this.capturedControllerStops.clear();
|
|
3099
|
+
this.controllerNativeReturns.clear();
|
|
3100
|
+
this.quiescedControllers.clear();
|
|
3101
|
+
this.revokedControllers.clear();
|
|
3102
|
+
this.controllerStops?.clear();
|
|
3103
|
+
this.launches?.clear();
|
|
3104
|
+
this.pendingLaunches?.clear();
|
|
3105
|
+
this.fences.clear();
|
|
3106
|
+
this.acquiredProcesses.clear();
|
|
3107
|
+
this.settledGroupAcquisitions.clear();
|
|
3108
|
+
for (const directory of this.groupAdmissionWatches.keys())
|
|
3109
|
+
this.cancelGroupAdmissionWatch(directory);
|
|
3110
|
+
for (const owner of this.observationOwners.values())
|
|
3111
|
+
owner.close();
|
|
3112
|
+
this.terminalLifetimes.clear();
|
|
3113
|
+
this.stopTrackingConsumers();
|
|
3114
|
+
if (errors.length)
|
|
3115
|
+
throw new AggregateError(errors, "Process broker cleanup failed");
|
|
3116
|
+
})().then(resolve, reject);
|
|
3117
|
+
return disposal;
|
|
3118
|
+
}
|
|
3119
|
+
report(error) {
|
|
3120
|
+
try {
|
|
3121
|
+
if (this.options.onError)
|
|
3122
|
+
this.options.onError(error);
|
|
3123
|
+
else
|
|
3124
|
+
console.error("runtime: process controller failed", error);
|
|
3125
|
+
} catch {}
|
|
3126
|
+
}
|
|
3127
|
+
}
|
|
3128
|
+
async function settleStop(stop, errors) {
|
|
3129
|
+
try {
|
|
3130
|
+
await stop();
|
|
3131
|
+
} catch (error) {
|
|
3132
|
+
errors.push(error);
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
function ownedAdapterHandle(handle) {
|
|
3136
|
+
let stopping;
|
|
3137
|
+
const terminate = handle.terminate.bind(handle);
|
|
3138
|
+
return {
|
|
3139
|
+
terminate() {
|
|
3140
|
+
if (stopping)
|
|
3141
|
+
return stopping;
|
|
3142
|
+
const stopped = Promise.withResolvers();
|
|
3143
|
+
stopping = stopped.promise;
|
|
3144
|
+
try {
|
|
3145
|
+
stopped.resolve(terminate());
|
|
3146
|
+
} catch (error) {
|
|
3147
|
+
stopped.reject(error);
|
|
3148
|
+
}
|
|
3149
|
+
return stopping;
|
|
3150
|
+
}
|
|
3151
|
+
};
|
|
3152
|
+
}
|
|
3153
|
+
function terminalPreparationError(code) {
|
|
3154
|
+
const errno = code === "CAPACITY" ? ProcessErrno.AGAIN : code === "CANCELED" || code === "PROCESS_GONE" ? ProcessErrno.CANCELED : code === "CLOSED" || code === "EXHAUSTED" ? 29 : ProcessErrno.INVAL;
|
|
3155
|
+
return new ProcessError(errno, `terminal preparation failed: ${code}`);
|
|
3156
|
+
}
|
|
3157
|
+
function rootOutput(options) {
|
|
3158
|
+
const { output, tryOutput } = options;
|
|
3159
|
+
if (output && tryOutput)
|
|
3160
|
+
throw new TypeError("root output and tryOutput are exclusive");
|
|
3161
|
+
if (tryOutput)
|
|
3162
|
+
return (target, data) => tryOutput(target, data);
|
|
3163
|
+
if (!output)
|
|
3164
|
+
return;
|
|
3165
|
+
return (target, data) => {
|
|
3166
|
+
output(target, data);
|
|
3167
|
+
return data.length;
|
|
3168
|
+
};
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3171
|
+
class NativeObservationOwner {
|
|
3172
|
+
onComplete;
|
|
3173
|
+
publish;
|
|
3174
|
+
key;
|
|
3175
|
+
stops = new Set;
|
|
3176
|
+
finished = Promise.withResolvers();
|
|
3177
|
+
failure;
|
|
3178
|
+
consumers = 0;
|
|
3179
|
+
closed = false;
|
|
3180
|
+
admitted = false;
|
|
3181
|
+
completed = false;
|
|
3182
|
+
constructor(transfer, onComplete, execution) {
|
|
3183
|
+
this.onComplete = onComplete;
|
|
3184
|
+
this.admitted = execution;
|
|
3185
|
+
this.publish = captureNativeReturn(transfer);
|
|
3186
|
+
this.key = observationKey(transfer);
|
|
3187
|
+
this.finished.promise.catch(() => {});
|
|
3188
|
+
}
|
|
3189
|
+
matches(transfer) {
|
|
3190
|
+
return this.key === observationKey(transfer);
|
|
3191
|
+
}
|
|
3192
|
+
acceptExecution() {
|
|
3193
|
+
this.admitted = true;
|
|
3194
|
+
}
|
|
3195
|
+
join() {
|
|
3196
|
+
return this.finished.promise;
|
|
3197
|
+
}
|
|
3198
|
+
fail(error) {
|
|
3199
|
+
this.failure ??= { error };
|
|
3200
|
+
this.finished.reject(error);
|
|
3201
|
+
}
|
|
3202
|
+
acquire() {
|
|
3203
|
+
if (this.closed)
|
|
3204
|
+
throw new Error("Process native consumer admission is closed");
|
|
3205
|
+
this.admitted = true;
|
|
3206
|
+
this.consumers++;
|
|
3207
|
+
let returned = false;
|
|
3208
|
+
return () => {
|
|
3209
|
+
if (returned)
|
|
3210
|
+
return;
|
|
3211
|
+
returned = true;
|
|
3212
|
+
this.consumers--;
|
|
3213
|
+
this.complete();
|
|
3214
|
+
};
|
|
3215
|
+
}
|
|
3216
|
+
addStop(handle) {
|
|
3217
|
+
this.stops.add(handle);
|
|
3218
|
+
}
|
|
3219
|
+
removeStop(handle) {
|
|
3220
|
+
this.stops.delete(handle);
|
|
3221
|
+
}
|
|
3222
|
+
async stopAll() {
|
|
3223
|
+
this.close();
|
|
3224
|
+
const results = await Promise.allSettled(Array.from(this.stops, (handle) => Promise.resolve().then(() => handle.terminate())));
|
|
3225
|
+
const failures = results.filter((result) => result.status === "rejected");
|
|
3226
|
+
const errors = failures.map((result) => result.reason);
|
|
3227
|
+
if (this.failure && !errors.includes(this.failure.error))
|
|
3228
|
+
errors.push(this.failure.error);
|
|
3229
|
+
if (!errors.length && this.consumers !== 0)
|
|
3230
|
+
errors.push(new Error("Process native consumers remain pending"));
|
|
3231
|
+
return errors;
|
|
3232
|
+
}
|
|
3233
|
+
close() {
|
|
3234
|
+
this.closed = true;
|
|
3235
|
+
if (!this.admitted) {
|
|
3236
|
+
this.finished.resolve();
|
|
3237
|
+
this.onComplete();
|
|
3238
|
+
return;
|
|
3239
|
+
}
|
|
3240
|
+
this.complete();
|
|
3241
|
+
}
|
|
3242
|
+
complete() {
|
|
3243
|
+
if (!this.closed || this.consumers !== 0 || this.completed)
|
|
3244
|
+
return;
|
|
3245
|
+
this.publish();
|
|
3246
|
+
this.completed = true;
|
|
3247
|
+
this.finished.resolve();
|
|
3248
|
+
this.onComplete();
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
function ignoreNativeStopRejection() {}
|
|
3252
|
+
function nativeStopHandle(handle, terminal, returned, closeAdmission, failed) {
|
|
3253
|
+
const terminate = handle.terminate;
|
|
3254
|
+
let state;
|
|
3255
|
+
let group;
|
|
3256
|
+
let groupBound = false;
|
|
3257
|
+
let attempted = false;
|
|
3258
|
+
const invoke = () => {
|
|
3259
|
+
try {
|
|
3260
|
+
return reflectApply(terminate, handle, []);
|
|
3261
|
+
} finally {
|
|
3262
|
+
attempted = true;
|
|
3263
|
+
group?.stopRequested();
|
|
3264
|
+
}
|
|
3265
|
+
};
|
|
3266
|
+
return {
|
|
3267
|
+
membership: () => group,
|
|
3268
|
+
bindGroup(lease) {
|
|
3269
|
+
if (groupBound)
|
|
3270
|
+
throw new Error("native consumer already has a memory group binding");
|
|
3271
|
+
groupBound = true;
|
|
3272
|
+
group = lease;
|
|
3273
|
+
if (attempted)
|
|
3274
|
+
group.stopRequested();
|
|
3275
|
+
},
|
|
3276
|
+
imageReturned() {
|
|
3277
|
+
if (state)
|
|
3278
|
+
return;
|
|
3279
|
+
state = { kind: "returned", result: undefined };
|
|
3280
|
+
returned?.();
|
|
3281
|
+
group = undefined;
|
|
3282
|
+
},
|
|
3283
|
+
acknowledgeReturn() {
|
|
3284
|
+
if (state)
|
|
3285
|
+
return;
|
|
3286
|
+
state = { kind: "returned", result: undefined };
|
|
3287
|
+
closeAdmission?.();
|
|
3288
|
+
returned?.();
|
|
3289
|
+
terminal?.stopped();
|
|
3290
|
+
group = undefined;
|
|
3291
|
+
},
|
|
3292
|
+
terminate() {
|
|
3293
|
+
if (state?.kind === "returned")
|
|
3294
|
+
return state.result;
|
|
3295
|
+
if (state) {
|
|
3296
|
+
state.reentrant ??= Promise.withResolvers();
|
|
3297
|
+
state.reentrant.promise.catch(ignoreNativeStopRejection);
|
|
3298
|
+
return state.reentrant.promise;
|
|
3299
|
+
}
|
|
3300
|
+
const invoking = { kind: "invoking" };
|
|
3301
|
+
state = invoking;
|
|
3302
|
+
const complete = () => {
|
|
3303
|
+
returned?.();
|
|
3304
|
+
terminal?.stopped();
|
|
3305
|
+
invoking.reentrant?.resolve();
|
|
3306
|
+
group = undefined;
|
|
3307
|
+
};
|
|
3308
|
+
const reject = (error) => {
|
|
3309
|
+
group?.failed();
|
|
3310
|
+
failed?.(error);
|
|
3311
|
+
invoking.reentrant?.reject(error);
|
|
3312
|
+
throw error;
|
|
3313
|
+
};
|
|
3314
|
+
try {
|
|
3315
|
+
closeAdmission?.();
|
|
3316
|
+
const result = invoke();
|
|
3317
|
+
if (result)
|
|
3318
|
+
return (state = {
|
|
3319
|
+
kind: "returned",
|
|
3320
|
+
result: result.then(complete).catch(reject)
|
|
3321
|
+
}).result;
|
|
3322
|
+
complete();
|
|
3323
|
+
state = { kind: "returned", result: undefined };
|
|
3324
|
+
} catch (error) {
|
|
3325
|
+
group?.failed();
|
|
3326
|
+
failed?.(error);
|
|
3327
|
+
invoking.reentrant?.reject(error);
|
|
3328
|
+
const result = Promise.reject(error);
|
|
3329
|
+
result.catch(ignoreNativeStopRejection);
|
|
3330
|
+
state = { kind: "returned", result };
|
|
3331
|
+
throw error;
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
};
|
|
3335
|
+
}
|
|
3336
|
+
function observationKey(transfer) {
|
|
3337
|
+
if (transfer.kind === "standalone")
|
|
3338
|
+
return `standalone:${transfer.domain}:${transfer.pid}`;
|
|
3339
|
+
const domain = atomicsLoad(new BigInt64ArrayConstructor(transfer.directory, 8, 1), 0);
|
|
3340
|
+
return `directory:${domain}:${transfer.slot}:${transfer.pid}`;
|
|
3341
|
+
}
|
|
3342
|
+
|
|
3343
|
+
class NativeReturnFollowers {
|
|
3344
|
+
state = {
|
|
3345
|
+
kind: "pending",
|
|
3346
|
+
callbacks: []
|
|
3347
|
+
};
|
|
3348
|
+
follow(callback) {
|
|
3349
|
+
if (this.state.kind === "returned")
|
|
3350
|
+
return callback();
|
|
3351
|
+
this.state.callbacks.push(callback);
|
|
3352
|
+
}
|
|
3353
|
+
returned() {
|
|
3354
|
+
if (this.state.kind === "returned")
|
|
3355
|
+
return;
|
|
3356
|
+
const callbacks = this.state.callbacks;
|
|
3357
|
+
this.state = { kind: "returned" };
|
|
3358
|
+
for (let index = 0;index < callbacks.length; index++)
|
|
3359
|
+
callbacks[index]();
|
|
3360
|
+
}
|
|
3361
|
+
}
|