@waffle-os/runtime 0.0.0-stage → 0.0.145
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/browser/diagnostic.ts +58 -0
- package/browser/display/generated/graphics-layout.ts +18 -0
- package/browser/display/guest.ts +87 -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/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/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 +18 -0
- package/browser/process-broker.ts +3859 -0
- package/browser/process-context.ts +56 -0
- package/browser/process-start.ts +130 -0
- package/browser/publication-authority.ts +437 -0
- package/browser/runtime-terminals.ts +183 -0
- package/browser/service-worker.ts +237 -0
- package/browser/shared-fs.ts +725 -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 +131 -0
- package/browser/worker-pool.ts +17 -0
- package/browser/worker.ts +1589 -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/diagnostic.js +42 -0
- package/dist/browser/display/generated/graphics-layout.js +17 -0
- package/dist/browser/display/guest.js +78 -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/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/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 +13 -0
- package/dist/browser/process-broker.js +3062 -0
- package/dist/browser/process-context.js +22 -0
- package/dist/browser/process-start.js +71 -0
- package/dist/browser/publication-authority.js +404 -0
- package/dist/browser/runtime-terminals.js +97 -0
- package/dist/browser/service-worker.js +196 -0
- package/dist/browser/shared-fs.js +563 -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 +107 -0
- package/dist/browser/worker-pool.js +14 -0
- package/dist/browser/worker.js +1208 -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 +1745 -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/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 +1732 -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.js +8 -0
- package/dist/proc/control.js +145 -0
- package/dist/proc/directory.js +790 -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 +251 -0
- package/dist/proc/intrinsics.js +98 -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 +1301 -0
- package/dist/proc/registry.js +293 -0
- package/dist/proc/signals.js +179 -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 +1541 -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 +853 -0
- package/dist/proc/worker-client.js +856 -0
- package/dist/proc/worker-pipes.js +165 -0
- package/dist/programs/catalog.js +27 -0
- package/dist/programs/collection.js +276 -0
- package/dist/programs/download.js +70 -0
- package/dist/programs/index.js +358 -0
- package/dist/runtime.js +761 -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 +2187 -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/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 +2163 -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 +151 -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 +695 -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.ts +53 -0
- package/proc/control.ts +198 -0
- package/proc/directory.ts +928 -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 +342 -0
- package/proc/intrinsics.ts +98 -0
- package/proc/node-wasi.ts +397 -0
- package/proc/observation.ts +293 -0
- package/proc/outcome.ts +276 -0
- package/proc/pipes.ts +1546 -0
- package/proc/registry.ts +521 -0
- package/proc/signals.ts +247 -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 +1852 -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 +1024 -0
- package/proc/worker-client.ts +1133 -0
- package/proc/worker-pipes.ts +212 -0
- package/programs/catalog.ts +44 -0
- package/programs/collection.ts +349 -0
- package/programs/download.ts +92 -0
- package/programs/index.ts +584 -0
- package/runtime.ts +1062 -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 +109 -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 +64 -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 +559 -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 +318 -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/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 +286 -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 +550 -0
- package/tests/filesystem-request-memory.test.ts +202 -0
- package/tests/filesystem-request-pool.test.ts +408 -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/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/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/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 +94 -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 +229 -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/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 +88 -0
- package/tests/page-runner/browser-controls-runner.test.ts +360 -0
- package/tests/page-runner/browser-controls-runner.ts +129 -0
- package/tests/page-runner/browser-controls-suite.ts +426 -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 +36 -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 +116 -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 +1234 -0
- package/tests/page-runner/suite-query.test.ts +164 -0
- package/tests/page-runner/suite-startup.test.ts +63 -0
- package/tests/page-runner/threads-runtime-browser.test.ts +70 -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 +236 -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 +235 -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 +184 -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 +82 -0
- package/tests/process-start-browser.ts +120 -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 +1999 -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-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 +92 -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 +280 -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 +96 -0
- package/tests/threads-runtime-browser.ts +483 -0
- package/tests/threads-runtime-cases.ts +21 -0
- package/tests/threads-runtime-cleanup.test.ts +58 -0
- package/tests/threads-runtime-cleanup.ts +42 -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-control.ts +388 -0
- package/tests/threads-runtime-fd-descriptors.test.ts +43 -0
- package/tests/threads-runtime-fd-filesystem.ts +41 -0
- package/tests/threads-runtime-fd-module.ts +91 -0
- package/tests/threads-runtime-fd-service.ts +54 -0
- package/tests/threads-runtime-host.ts +19 -0
- package/tests/threads-runtime-late-read-service.ts +46 -0
- package/tests/threads-runtime-modules.ts +114 -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 +49 -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/worker-access.test.ts +331 -0
- package/tests/worker-final-completion.test.ts +434 -0
- package/tests/worker-memory-bootstrap.test.ts +219 -0
- package/tests/worker-memory-broker.test.ts +658 -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 +1636 -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 +1431 -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 +554 -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
- package/README.md +0 -3
package/fs/shared.ts
ADDED
|
@@ -0,0 +1,2454 @@
|
|
|
1
|
+
import { WatchRing } from "./watch-ring.js";
|
|
2
|
+
import type { MemoryBudget } from "./memory-budget.js";
|
|
3
|
+
import { allocateStartupRoot } from "./root-memory-budget.js";
|
|
4
|
+
import { DirtyAdmission, DIRTY_NODE_UNITS } from "./dirty-admission.js";
|
|
5
|
+
import {
|
|
6
|
+
ReaderPagePressure,
|
|
7
|
+
SharedPageVersion,
|
|
8
|
+
truncateBoundaryEnd,
|
|
9
|
+
} from "./shared-version-pages.js";
|
|
10
|
+
import {
|
|
11
|
+
IdentityAllocator,
|
|
12
|
+
readIdentityWords,
|
|
13
|
+
writeIdentityWords,
|
|
14
|
+
type FileIdentity,
|
|
15
|
+
type FileId,
|
|
16
|
+
type FileVersion,
|
|
17
|
+
} from "./file-identity.js";
|
|
18
|
+
import { typedArraySet } from "../proc/intrinsics.js";
|
|
19
|
+
import {
|
|
20
|
+
PublicationDomain,
|
|
21
|
+
type PublicationAdmission,
|
|
22
|
+
type PreparedPublication,
|
|
23
|
+
} from "./publication.js";
|
|
24
|
+
import type { PublicationBuffers, PublicationConnection } from "./publication-internal.js";
|
|
25
|
+
import type { FileHandle, FileStat, FileTime } from "../core/index.js";
|
|
26
|
+
import { fileTimeMs, fileTimeNow, msFileTime } from "../core/filesystem.js";
|
|
27
|
+
import {
|
|
28
|
+
FilesystemError,
|
|
29
|
+
DEFAULT_SHARED_MAX_BYTES,
|
|
30
|
+
State,
|
|
31
|
+
createFilesystemSegment,
|
|
32
|
+
normalizeSharedMaxBytes,
|
|
33
|
+
type FilesystemSection,
|
|
34
|
+
} from "./protocol.js";
|
|
35
|
+
export { SHARED_SEGMENT_BYTES, DEFAULT_SHARED_MAX_BYTES } from "./protocol.js";
|
|
36
|
+
|
|
37
|
+
import {
|
|
38
|
+
DATA_PAGE_BYTES,
|
|
39
|
+
DATA_PAGES_PER_SEGMENT,
|
|
40
|
+
TOTAL_DATA_PAGES,
|
|
41
|
+
MAX_FILE_PAGES,
|
|
42
|
+
TABLE_ENTRIES,
|
|
43
|
+
DIRECT_LEAVES,
|
|
44
|
+
FILE_ROOT_WORDS,
|
|
45
|
+
MAX_FILES,
|
|
46
|
+
TABLE_BLOCKS,
|
|
47
|
+
ROOT_CELL_BASE,
|
|
48
|
+
PAGE_CELLS,
|
|
49
|
+
SLOT_WORDS,
|
|
50
|
+
HEADER_WORDS,
|
|
51
|
+
SLOT_OFFSET,
|
|
52
|
+
TABLE_OWNER_OFFSET,
|
|
53
|
+
PAGE_CELL_OFFSET,
|
|
54
|
+
WATCH_OFFSET,
|
|
55
|
+
DATA_OFFSET,
|
|
56
|
+
SHARED_ROOT_BYTES,
|
|
57
|
+
} from "./storage-geometry.js";
|
|
58
|
+
import { SHARED_SEGMENT_BYTES } from "./shared-capacity.js";
|
|
59
|
+
export { SLOT_WORDS } from "./storage-geometry.js";
|
|
60
|
+
|
|
61
|
+
const MAGIC = 0x42574653;
|
|
62
|
+
const NLINK = 23;
|
|
63
|
+
const FILE_ID = 13;
|
|
64
|
+
const FILE_VERSION = 17;
|
|
65
|
+
const DIRTY_SIZE = 21;
|
|
66
|
+
const DIRTY_MARK = 22;
|
|
67
|
+
const GLOBAL_LOCK = 1;
|
|
68
|
+
const SERVICE_OWNER = 0x7fffffff;
|
|
69
|
+
const USED_PAGES = 2;
|
|
70
|
+
const RETIRED_PAGE = -1;
|
|
71
|
+
// Allocator-protected floor for reincarnated handles, even when a collision moves their slot.
|
|
72
|
+
// Header words 5 and 6 belong to connection owner allocation and attachment probing.
|
|
73
|
+
const FREED_REVISION_LOW = 7;
|
|
74
|
+
const FREED_REVISION_HIGH = 8;
|
|
75
|
+
// Global-lock accelerators. Nothing below a hint is free; ownership stays authoritative.
|
|
76
|
+
const PHYSICAL_HINT = 27;
|
|
77
|
+
const TABLE_HINT = 28;
|
|
78
|
+
const PINNED_PAGES = 29;
|
|
79
|
+
const MODE = 12;
|
|
80
|
+
const FILE_SIZE = 1;
|
|
81
|
+
// File times are unsigned 64-bit nanoseconds in two words each, starting on an even word.
|
|
82
|
+
const MTIME = 2;
|
|
83
|
+
const ATIME = 24;
|
|
84
|
+
const CTIME = 26;
|
|
85
|
+
const INO = 4;
|
|
86
|
+
const CAPACITY = 5;
|
|
87
|
+
const REFS = 6;
|
|
88
|
+
const UNLINKED = 7;
|
|
89
|
+
const FILE_LOCK = 8;
|
|
90
|
+
const HANDLE = 9;
|
|
91
|
+
const REVISION = 10;
|
|
92
|
+
// Bit 0 is residency; the remaining bits extend the revision beyond a 32-bit counter.
|
|
93
|
+
const REVISION_STATE = 11;
|
|
94
|
+
const RESIDENT = 1;
|
|
95
|
+
|
|
96
|
+
// The intrinsic copy, so a guest iovec subclass's set() cannot reenter under a file lock. WASI
|
|
97
|
+
// iovecs are plain views; a subclass's overridden length/buffer/byteOffset getters still run there.
|
|
98
|
+
const copyBytes = Uint8Array.prototype.set;
|
|
99
|
+
|
|
100
|
+
export class MissingSegmentError extends Error {}
|
|
101
|
+
export class MissingDataError extends Error {}
|
|
102
|
+
export interface SharedFileSnapshot {
|
|
103
|
+
stat: FileStat;
|
|
104
|
+
data: Uint8Array;
|
|
105
|
+
revision: number;
|
|
106
|
+
}
|
|
107
|
+
export interface SharedFileInfo extends FileStat {
|
|
108
|
+
capacity: number;
|
|
109
|
+
}
|
|
110
|
+
export interface SharedSegment {
|
|
111
|
+
buffer: SharedArrayBuffer;
|
|
112
|
+
index: number;
|
|
113
|
+
}
|
|
114
|
+
/** The owner's private record of one write staged for a client that lacks the target segment.
|
|
115
|
+
* `cells` is that stage request's own header: word 0 is its state and word 1 the position the
|
|
116
|
+
* client committed at. `bytes` is the owner's private copy, dropped once the stage settles. */
|
|
117
|
+
export interface StagedWrite {
|
|
118
|
+
readonly slot: number;
|
|
119
|
+
readonly handle: FileHandle;
|
|
120
|
+
readonly cells: Int32Array;
|
|
121
|
+
bytes: Uint8Array | undefined;
|
|
122
|
+
}
|
|
123
|
+
const STAGE_STATE = 0;
|
|
124
|
+
const STAGE_POSITION = 1;
|
|
125
|
+
|
|
126
|
+
/** Fix only growable shared sources; ordinary/fixed WASM sources keep their original iovec.
|
|
127
|
+
* A source can grow while waiting for a lock or copying another iovec. Capacity checks,
|
|
128
|
+
* byte counts and the copy must all use the same bounds, including a nonzero byteOffset.
|
|
129
|
+
*/
|
|
130
|
+
export function fixedWriteSources(chunks: readonly Uint8Array[]): readonly Uint8Array[] {
|
|
131
|
+
let fixed: Uint8Array[] | undefined;
|
|
132
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
133
|
+
const chunk = chunks[i]!;
|
|
134
|
+
const buffer = chunk.buffer;
|
|
135
|
+
if (buffer instanceof SharedArrayBuffer && "growable" in buffer && buffer.growable) {
|
|
136
|
+
fixed ??= chunks.slice();
|
|
137
|
+
fixed[i] = new Uint8Array(buffer, chunk.byteOffset, chunk.byteLength);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return fixed ?? chunks;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
interface PlannedIdentityRevision {
|
|
144
|
+
readonly identity: FileIdentity;
|
|
145
|
+
readonly allocation: IdentityAllocator;
|
|
146
|
+
}
|
|
147
|
+
/** Shared metadata and a pool of fixed data segments. The owner state builds a segment when a
|
|
148
|
+
* page in it is first needed; every other state holds only the segments it was given. A page
|
|
149
|
+
* table entry can name a page in a segment this agent lacks: each path below resolves its
|
|
150
|
+
* backing before it changes anything, and a miss sends that operation to the owner. */
|
|
151
|
+
export class SharedFilesystemState {
|
|
152
|
+
readonly buffer: SharedArrayBuffer;
|
|
153
|
+
readonly dirtyAdmission: DirtyAdmission;
|
|
154
|
+
readonly identities: IdentityAllocator;
|
|
155
|
+
identityGroup = false;
|
|
156
|
+
readonly cells: Int32Array;
|
|
157
|
+
readonly owners: Int32Array;
|
|
158
|
+
readonly slots: Int32Array;
|
|
159
|
+
/** The slot table again, as 64-bit cells for the time fields. */
|
|
160
|
+
private readonly times: BigUint64Array;
|
|
161
|
+
readonly pages: Int32Array;
|
|
162
|
+
private readonly tableOwners: Int32Array;
|
|
163
|
+
readonly segments: SharedArrayBuffer[];
|
|
164
|
+
readonly pendingSegments: SharedSegment[] = [];
|
|
165
|
+
private readonly firstBytes: Uint8Array;
|
|
166
|
+
private readonly pageViews: (Uint8Array | undefined)[] = [];
|
|
167
|
+
/** Scratch for one direct read's resolved source pages; see sourcePages. */
|
|
168
|
+
private readonly readViews: Uint8Array[] = [];
|
|
169
|
+
private readViewsBusy = false;
|
|
170
|
+
/** Owner only: unsettled staged writes by file slot. Empty on every client state. */
|
|
171
|
+
private readonly staged = new Map<number, StagedWrite[]>();
|
|
172
|
+
private serviceMutation = false;
|
|
173
|
+
private globalOwner: number | undefined;
|
|
174
|
+
private globalDepth = 0;
|
|
175
|
+
private fileOwnsGlobal = new Set<number>();
|
|
176
|
+
private currentOwner: number | undefined;
|
|
177
|
+
readonly publication?: PublicationDomain;
|
|
178
|
+
readonly watch: WatchRing;
|
|
179
|
+
private readonly pageReaders?: Int32Array;
|
|
180
|
+
onContention?: () => void;
|
|
181
|
+
constructor(
|
|
182
|
+
buffer?: SharedArrayBuffer,
|
|
183
|
+
maxBytes = DEFAULT_SHARED_MAX_BYTES,
|
|
184
|
+
readonly lockOwner = SERVICE_OWNER,
|
|
185
|
+
segments: readonly SharedArrayBuffer[] = [],
|
|
186
|
+
private readonly section?: FilesystemSection,
|
|
187
|
+
publication?: PublicationBuffers,
|
|
188
|
+
readonly startupMemoryBudget?: MemoryBudget,
|
|
189
|
+
) {
|
|
190
|
+
if (buffer && startupMemoryBudget)
|
|
191
|
+
throw new TypeError("an imported root cannot use startup allocation admission");
|
|
192
|
+
const allocation = startupMemoryBudget
|
|
193
|
+
? allocateStartupRoot(startupMemoryBudget, SHARED_ROOT_BYTES)
|
|
194
|
+
: undefined;
|
|
195
|
+
this.buffer = buffer ?? allocation?.buffer ?? SharedFilesystemState.createBuffer();
|
|
196
|
+
buffer = this.buffer;
|
|
197
|
+
try {
|
|
198
|
+
this.dirtyAdmission = new DirtyAdmission(buffer);
|
|
199
|
+
if (publication) this.publication = new PublicationDomain(publication, lockOwner, section);
|
|
200
|
+
if (publication?.pageReaders) this.pageReaders = new Int32Array(publication.pageReaders);
|
|
201
|
+
this.cells = new Int32Array(buffer, 0, HEADER_WORDS);
|
|
202
|
+
this.watch = new WatchRing(buffer, WATCH_OFFSET);
|
|
203
|
+
this.identities = new IdentityAllocator(new Int32Array(buffer, 16 * 4, 9));
|
|
204
|
+
const initialized = Atomics.compareExchange(this.cells, 0, 0, MAGIC);
|
|
205
|
+
if (initialized === 0) {
|
|
206
|
+
Atomics.store(this.cells, USED_PAGES, 0);
|
|
207
|
+
Atomics.store(this.cells, 4, normalizeSharedMaxBytes(maxBytes) / SHARED_SEGMENT_BYTES);
|
|
208
|
+
}
|
|
209
|
+
while (initialized !== 0 && Atomics.load(this.cells, 0) !== MAGIC) {
|
|
210
|
+
/* another connection initializes */
|
|
211
|
+
}
|
|
212
|
+
this.owners = new Int32Array(buffer, HEADER_WORDS * 4, TOTAL_DATA_PAGES);
|
|
213
|
+
this.slots = new Int32Array(buffer, SLOT_OFFSET * 4, MAX_FILES * SLOT_WORDS);
|
|
214
|
+
this.times = new BigUint64Array(buffer, SLOT_OFFSET * 4, (MAX_FILES * SLOT_WORDS) / 2);
|
|
215
|
+
this.tableOwners = new Int32Array(buffer, TABLE_OWNER_OFFSET * 4, TABLE_BLOCKS);
|
|
216
|
+
this.pages = new Int32Array(buffer, PAGE_CELL_OFFSET * 4, PAGE_CELLS);
|
|
217
|
+
this.firstBytes = new Uint8Array(buffer, DATA_OFFSET, SHARED_SEGMENT_BYTES);
|
|
218
|
+
this.segments = [buffer].concat(segments);
|
|
219
|
+
allocation?.publish();
|
|
220
|
+
} catch (error) {
|
|
221
|
+
allocation?.cancel();
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
retainVersionPages(handle: FileHandle, offset: number, length: number): SharedPageVersion {
|
|
226
|
+
this.globalLock();
|
|
227
|
+
try {
|
|
228
|
+
const slot = this.slot(handle);
|
|
229
|
+
this.settleUnderLock(slot);
|
|
230
|
+
this.checkFile(slot, handle);
|
|
231
|
+
this.checkAccess(slot, 4);
|
|
232
|
+
if (!this.pageReaders) throw new FilesystemError(58, "page retention is not enabled");
|
|
233
|
+
const size = this.slots[this.at(slot, FILE_SIZE)]!;
|
|
234
|
+
if (!(this.slots[this.at(slot, REVISION_STATE)]! & RESIDENT))
|
|
235
|
+
throw new MissingDataError("shared filesystem file has not been loaded");
|
|
236
|
+
if (
|
|
237
|
+
!Number.isSafeInteger(offset) ||
|
|
238
|
+
!Number.isSafeInteger(length) ||
|
|
239
|
+
offset < 0 ||
|
|
240
|
+
length < 0 ||
|
|
241
|
+
offset > Number.MAX_SAFE_INTEGER - length ||
|
|
242
|
+
offset + length > size
|
|
243
|
+
)
|
|
244
|
+
throw new RangeError("invalid retained extent");
|
|
245
|
+
let additional = 0;
|
|
246
|
+
for (
|
|
247
|
+
let logical = Math.floor(offset / DATA_PAGE_BYTES);
|
|
248
|
+
length && logical < Math.ceil((offset + length) / DATA_PAGE_BYTES);
|
|
249
|
+
logical++
|
|
250
|
+
) {
|
|
251
|
+
if (!this.pageReaders[this.pages[this.pageAt(slot, logical)]! - 1])
|
|
252
|
+
additional += DATA_PAGE_BYTES;
|
|
253
|
+
}
|
|
254
|
+
if (additional > 256 * 1024 * 1024 - this.readerPinBytes())
|
|
255
|
+
throw new ReaderPagePressure("reader page capacity exhausted");
|
|
256
|
+
const first = Math.floor(offset / DATA_PAGE_BYTES);
|
|
257
|
+
const count = length ? Math.ceil((offset + length) / DATA_PAGE_BYTES) - first : 0;
|
|
258
|
+
const pages = new Uint32Array(count);
|
|
259
|
+
for (let index = 0; index < count; index++) {
|
|
260
|
+
pages[index] = this.pages[this.pageAt(slot, first + index)]! - 1;
|
|
261
|
+
this.segmentBuffer(pages[index]!);
|
|
262
|
+
}
|
|
263
|
+
const version = new SharedPageVersion(
|
|
264
|
+
offset,
|
|
265
|
+
length,
|
|
266
|
+
pages,
|
|
267
|
+
(physical, target, targetAt, start, bytes) =>
|
|
268
|
+
target.set(this.segmentFor(physical).subarray(start, start + bytes), targetAt),
|
|
269
|
+
() => this.releaseVersionPages(pages),
|
|
270
|
+
);
|
|
271
|
+
for (const physical of pages)
|
|
272
|
+
if (Atomics.add(this.pageReaders, physical, 1) === 0) this.cells[PINNED_PAGES]!++;
|
|
273
|
+
return version;
|
|
274
|
+
} finally {
|
|
275
|
+
this.globalUnlock();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
readerPinBytes(): number {
|
|
279
|
+
return this.pageReaders ? this.cells[PINNED_PAGES]! * DATA_PAGE_BYTES : 0;
|
|
280
|
+
}
|
|
281
|
+
private releaseVersionPages(pages: Uint32Array): void {
|
|
282
|
+
this.globalLock(undefined, this.lockOwner, false, "release");
|
|
283
|
+
try {
|
|
284
|
+
for (const physical of pages) {
|
|
285
|
+
if (Atomics.sub(this.pageReaders!, physical, 1) !== 1) continue;
|
|
286
|
+
this.cells[PINNED_PAGES]!--;
|
|
287
|
+
if (this.owners[physical] === RETIRED_PAGE) this.detachVersionPage(physical);
|
|
288
|
+
}
|
|
289
|
+
} finally {
|
|
290
|
+
this.globalUnlock();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
private detachVersionPage(physical: number): void {
|
|
294
|
+
if (this.pageReaders?.[physical]) {
|
|
295
|
+
this.owners[physical] = RETIRED_PAGE;
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
this.segmentFor(physical).fill(0);
|
|
299
|
+
this.releasePhysical(physical);
|
|
300
|
+
Atomics.sub(this.cells, USED_PAGES, 1);
|
|
301
|
+
this.dirtyAdmission.capacityReleased();
|
|
302
|
+
}
|
|
303
|
+
/** The hint falls before ownership clears, so death in between costs only a rescan. */
|
|
304
|
+
private releasePhysical(physical: number): void {
|
|
305
|
+
if (physical < this.cells[PHYSICAL_HINT]!) this.cells[PHYSICAL_HINT] = physical;
|
|
306
|
+
this.owners[physical] = 0;
|
|
307
|
+
}
|
|
308
|
+
private physicalPageLimit(): number {
|
|
309
|
+
return Atomics.load(this.cells, 4) * DATA_PAGES_PER_SEGMENT;
|
|
310
|
+
}
|
|
311
|
+
/** The lowest free physical page, or -1. A miss rescans so a hint never reports exhaustion. */
|
|
312
|
+
private freePhysical(): number {
|
|
313
|
+
const limit = this.physicalPageLimit();
|
|
314
|
+
const hinted = this.owners.indexOf(0, this.cells[PHYSICAL_HINT]!);
|
|
315
|
+
if (hinted >= 0 && hinted < limit) return hinted;
|
|
316
|
+
const lowest = this.owners.indexOf(0);
|
|
317
|
+
return lowest >= 0 && lowest < limit ? lowest : -1;
|
|
318
|
+
}
|
|
319
|
+
private reserveVersionPage(slot: number): number {
|
|
320
|
+
const physical = this.freePhysical();
|
|
321
|
+
if (physical < 0) throw new FilesystemError(6, "retained page copy capacity exhausted");
|
|
322
|
+
this.ensureSegment(Math.floor(physical / DATA_PAGES_PER_SEGMENT));
|
|
323
|
+
this.owners[physical] = slot;
|
|
324
|
+
this.cells[PHYSICAL_HINT] = physical + 1;
|
|
325
|
+
return physical;
|
|
326
|
+
}
|
|
327
|
+
private prepareVersionPages(
|
|
328
|
+
slot: number,
|
|
329
|
+
offset: number,
|
|
330
|
+
end: number,
|
|
331
|
+
dirtySize?: number,
|
|
332
|
+
): () => void {
|
|
333
|
+
if (!this.pageReaders || offset === end) return () => {};
|
|
334
|
+
// A cold replacement's old size can exceed capacity; unbacked pages have no mapping or pin.
|
|
335
|
+
const last = Math.min(Math.ceil(end / DATA_PAGE_BYTES), this.slots[this.at(slot, CAPACITY)]!);
|
|
336
|
+
let additional = 0;
|
|
337
|
+
for (let logical = Math.floor(offset / DATA_PAGE_BYTES); logical < last; logical++) {
|
|
338
|
+
if (this.pageReaders[this.pages[this.pageAt(slot, logical)]! - 1])
|
|
339
|
+
additional += DATA_PAGE_BYTES;
|
|
340
|
+
}
|
|
341
|
+
const resident = this.residentBytes() + additional;
|
|
342
|
+
if (dirtySize === undefined) this.dirtyAdmission.resident(resident);
|
|
343
|
+
else this.checkDirty(slot, dirtySize, resident);
|
|
344
|
+
const replacements: { entry: number; previous: number; physical: number }[] = [];
|
|
345
|
+
try {
|
|
346
|
+
for (let logical = Math.floor(offset / DATA_PAGE_BYTES); logical < last; logical++) {
|
|
347
|
+
const entry = this.pageAt(slot, logical);
|
|
348
|
+
const previous = this.pages[entry]! - 1;
|
|
349
|
+
if (!this.pageReaders[previous]) continue;
|
|
350
|
+
const physical = this.reserveVersionPage(slot);
|
|
351
|
+
replacements.push({ entry, previous, physical });
|
|
352
|
+
this.segmentFor(physical).set(this.segmentFor(previous));
|
|
353
|
+
}
|
|
354
|
+
} catch (error) {
|
|
355
|
+
for (const replacement of replacements) this.releasePhysical(replacement.physical);
|
|
356
|
+
// A copy page can need a new segment. A native refusal there is exhaustion, not EFBIG.
|
|
357
|
+
if (error instanceof RangeError)
|
|
358
|
+
throw new FilesystemError(51, "shared filesystem segment allocation failed");
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
for (const { entry, previous, physical } of replacements) {
|
|
362
|
+
this.pages[entry] = physical + 1;
|
|
363
|
+
this.owners[previous] = RETIRED_PAGE;
|
|
364
|
+
}
|
|
365
|
+
Atomics.add(this.cells, USED_PAGES, replacements.length);
|
|
366
|
+
return () => {
|
|
367
|
+
for (const { entry, previous, physical } of replacements) {
|
|
368
|
+
this.pages[entry] = previous + 1;
|
|
369
|
+
this.owners[previous] = slot;
|
|
370
|
+
this.detachVersionPage(physical);
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
/** Reserves growth and every COW page before publication can change any logical state. */
|
|
375
|
+
prepareVersionWrite(
|
|
376
|
+
handle: FileHandle,
|
|
377
|
+
offset: number,
|
|
378
|
+
length: number,
|
|
379
|
+
size: number,
|
|
380
|
+
): { rollback(): void; commit(): void } {
|
|
381
|
+
const slot = this.slot(handle);
|
|
382
|
+
this.lock(this.at(slot, FILE_LOCK));
|
|
383
|
+
const capacity = this.slots[this.at(slot, CAPACITY)]!;
|
|
384
|
+
let undo: (() => void) | undefined;
|
|
385
|
+
try {
|
|
386
|
+
this.allocate(slot, Math.ceil(size / DATA_PAGE_BYTES));
|
|
387
|
+
undo = this.prepareVersionPages(slot, offset, offset + length);
|
|
388
|
+
} catch (error) {
|
|
389
|
+
this.trimCapacity(slot, capacity);
|
|
390
|
+
throw error;
|
|
391
|
+
} finally {
|
|
392
|
+
this.unlock(this.at(slot, FILE_LOCK));
|
|
393
|
+
}
|
|
394
|
+
let active = true;
|
|
395
|
+
return {
|
|
396
|
+
commit: () => {
|
|
397
|
+
active = false;
|
|
398
|
+
},
|
|
399
|
+
rollback: () => {
|
|
400
|
+
if (!active) return;
|
|
401
|
+
active = false;
|
|
402
|
+
undo();
|
|
403
|
+
this.trimCapacity(slot, capacity);
|
|
404
|
+
},
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
private trimCapacity(slot: number, needed: number): void {
|
|
408
|
+
const capacity = this.slots[this.at(slot, CAPACITY)]!;
|
|
409
|
+
for (let logical = needed; logical < capacity; logical++) {
|
|
410
|
+
const entry = this.pageAt(slot, logical);
|
|
411
|
+
this.detachVersionPage(this.pages[entry]! - 1);
|
|
412
|
+
this.pages[entry] = 0;
|
|
413
|
+
}
|
|
414
|
+
this.slots[this.at(slot, CAPACITY)] = needed;
|
|
415
|
+
this.trimPageTables(slot, needed);
|
|
416
|
+
}
|
|
417
|
+
static createBuffer(memoryBudget?: MemoryBudget): SharedArrayBuffer {
|
|
418
|
+
if (!memoryBudget) return new SharedArrayBuffer(SHARED_ROOT_BYTES);
|
|
419
|
+
const allocation = allocateStartupRoot(memoryBudget, SHARED_ROOT_BYTES);
|
|
420
|
+
try {
|
|
421
|
+
allocation.publish();
|
|
422
|
+
return allocation.buffer;
|
|
423
|
+
} catch (error) {
|
|
424
|
+
allocation.cancel();
|
|
425
|
+
throw error;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** Attaches an announced segment at its index. A segment is always complete when it is
|
|
430
|
+
* announced. Delivery can repeat, arrive out of order or follow a launch snapshot, so the
|
|
431
|
+
* first wrapper accepted for an index stays and later ones are ignored. */
|
|
432
|
+
addSegment(buffer: SharedArrayBuffer, index: number): void {
|
|
433
|
+
if (
|
|
434
|
+
buffer.byteLength !== SHARED_SEGMENT_BYTES ||
|
|
435
|
+
!Number.isInteger(index) ||
|
|
436
|
+
index < 1 ||
|
|
437
|
+
index >= Atomics.load(this.cells, 4)
|
|
438
|
+
)
|
|
439
|
+
throw new RangeError("invalid shared filesystem segment");
|
|
440
|
+
this.segments[index] ??= buffer;
|
|
441
|
+
}
|
|
442
|
+
takeNewSegments(): SharedSegment[] {
|
|
443
|
+
const out = this.pendingSegments.slice();
|
|
444
|
+
this.pendingSegments.length = 0;
|
|
445
|
+
return out;
|
|
446
|
+
}
|
|
447
|
+
private segmentBuffer(page: number): SharedArrayBuffer {
|
|
448
|
+
const buffer = this.segments[Math.floor(page / DATA_PAGES_PER_SEGMENT)];
|
|
449
|
+
if (!buffer)
|
|
450
|
+
throw new MissingSegmentError("shared filesystem segment has not reached this guest");
|
|
451
|
+
return buffer;
|
|
452
|
+
}
|
|
453
|
+
/** Resolves the backing of logical pages [first, end) in this agent's directory. Callers run
|
|
454
|
+
* it under the file lock before they change a destination, a page or any accounting, so a
|
|
455
|
+
* MissingSegmentError always means nothing happened. Every page in the range must be mapped. */
|
|
456
|
+
private requireBacking(slot: number, first: number, end: number): void {
|
|
457
|
+
for (let logical = first; logical < end; logical++)
|
|
458
|
+
this.segmentBuffer(this.pages[this.pageAt(slot, logical)]! - 1);
|
|
459
|
+
}
|
|
460
|
+
/** The page views of logical pages [first, end), resolved once and then used for the copy, so
|
|
461
|
+
* resolving them before the first byte moves costs a read almost nothing. Throws
|
|
462
|
+
* MissingSegmentError, with nothing copied, for a page this agent cannot reach. `views` is the
|
|
463
|
+
* state's scratch array unless a read is already using it: a guest iovec getter can reenter
|
|
464
|
+
* another read during the copy. */
|
|
465
|
+
private sourcePages(slot: number, first: number, end: number, views: Uint8Array[]): void {
|
|
466
|
+
const pages = this.pages;
|
|
467
|
+
for (let index = 0; index < end - first; index++)
|
|
468
|
+
views[index] = this.segmentFor(pages[this.pageAt(slot, first + index)]! - 1);
|
|
469
|
+
}
|
|
470
|
+
/** A write over reader-pinned pages copies each one to the lowest free page. Only the owner
|
|
471
|
+
* can build the segment such a page may need, so any other agent checks here, before it
|
|
472
|
+
* prepares anything, that its directory already holds every copy target. */
|
|
473
|
+
private requireCopyBacking(slot: number, first: number, end: number): void {
|
|
474
|
+
if (!this.pageReaders || this.lockOwner === SERVICE_OWNER) return;
|
|
475
|
+
const limit = this.physicalPageLimit();
|
|
476
|
+
let from = this.cells[PHYSICAL_HINT]!;
|
|
477
|
+
for (let logical = first; logical < end; logical++) {
|
|
478
|
+
if (!this.pageReaders[this.pages[this.pageAt(slot, logical)]! - 1]) continue;
|
|
479
|
+
const free = this.owners.indexOf(0, from);
|
|
480
|
+
// Exhaustion is reported by the copy itself, with its own errno.
|
|
481
|
+
if (free < 0 || free >= limit) return;
|
|
482
|
+
this.segmentBuffer(free);
|
|
483
|
+
from = free + 1;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
private hasPinnedPage(slot: number, first: number, end: number): boolean {
|
|
487
|
+
if (!this.pageReaders) return false;
|
|
488
|
+
for (let logical = first; logical < end; logical++)
|
|
489
|
+
if (this.pageReaders[this.pages[this.pageAt(slot, logical)]! - 1]) return true;
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
private segmentFor(page: number): Uint8Array {
|
|
493
|
+
const cached = this.pageViews[page];
|
|
494
|
+
if (cached) return cached;
|
|
495
|
+
const segment = Math.floor(page / DATA_PAGES_PER_SEGMENT);
|
|
496
|
+
const local = page % DATA_PAGES_PER_SEGMENT;
|
|
497
|
+
const buffer = this.segmentBuffer(page);
|
|
498
|
+
// Physical pages may be recycled between files, but their backing buffer and byte offset
|
|
499
|
+
// never change, so a page view stays valid for the life of this state.
|
|
500
|
+
const bytes =
|
|
501
|
+
segment === 0
|
|
502
|
+
? this.firstBytes.subarray(local * DATA_PAGE_BYTES, (local + 1) * DATA_PAGE_BYTES)
|
|
503
|
+
: new Uint8Array(buffer, local * DATA_PAGE_BYTES, DATA_PAGE_BYTES);
|
|
504
|
+
this.pageViews[page] = bytes;
|
|
505
|
+
return bytes;
|
|
506
|
+
}
|
|
507
|
+
private findSlot(handle: FileHandle, create = false): number {
|
|
508
|
+
if (!Number.isInteger(handle) || handle < 0 || handle >= 0x7ffffffe) return 0;
|
|
509
|
+
const start = handle % (MAX_FILES - 1);
|
|
510
|
+
let available = 0;
|
|
511
|
+
for (let probe = 0; probe < MAX_FILES - 1; probe++) {
|
|
512
|
+
const slot = ((start + probe) % (MAX_FILES - 1)) + 1;
|
|
513
|
+
const key = Atomics.load(this.slots, this.at(slot, HANDLE));
|
|
514
|
+
if (key === handle + 1) return slot;
|
|
515
|
+
if (key <= 0 && !available) available = slot;
|
|
516
|
+
// A matching tombstone ends this handle's probe chain, even after table saturation.
|
|
517
|
+
if (key === 0 || key === -handle - 1) return create ? available : 0;
|
|
518
|
+
}
|
|
519
|
+
return create ? available : 0;
|
|
520
|
+
}
|
|
521
|
+
private slot(handle: FileHandle): number {
|
|
522
|
+
const slot = this.findSlot(handle);
|
|
523
|
+
if (!slot) throw new FilesystemError(8);
|
|
524
|
+
return slot;
|
|
525
|
+
}
|
|
526
|
+
private at(slot: number, field: number): number {
|
|
527
|
+
return slot * SLOT_WORDS + field;
|
|
528
|
+
}
|
|
529
|
+
private rootCell(slot: number, index: number): number {
|
|
530
|
+
return ROOT_CELL_BASE + slot * FILE_ROOT_WORDS + index;
|
|
531
|
+
}
|
|
532
|
+
/** Follows a published link to the first cell of its child block. */
|
|
533
|
+
private childCells(cell: number): number {
|
|
534
|
+
return (Atomics.load(this.pages, cell) - 1) * TABLE_ENTRIES;
|
|
535
|
+
}
|
|
536
|
+
/** The cell holding a leaf's block. A logical index alone selects direct or tail. */
|
|
537
|
+
private leafCell(slot: number, leaf: number): number {
|
|
538
|
+
if (leaf < DIRECT_LEAVES) return this.rootCell(slot, leaf);
|
|
539
|
+
const tail = leaf - DIRECT_LEAVES;
|
|
540
|
+
const top = this.childCells(this.rootCell(slot, DIRECT_LEAVES));
|
|
541
|
+
return this.childCells(top + Math.floor(tail / TABLE_ENTRIES)) + (tail % TABLE_ENTRIES);
|
|
542
|
+
}
|
|
543
|
+
private pageAt(slot: number, logical: number): number {
|
|
544
|
+
const leaf = Math.floor(logical / TABLE_ENTRIES);
|
|
545
|
+
return this.childCells(this.leafCell(slot, leaf)) + (logical % TABLE_ENTRIES);
|
|
546
|
+
}
|
|
547
|
+
private takeBlock(slot: number): number {
|
|
548
|
+
const hinted = this.tableOwners.indexOf(0, this.cells[TABLE_HINT]!);
|
|
549
|
+
const block = hinted >= 0 ? hinted : this.tableOwners.indexOf(0);
|
|
550
|
+
if (block < 0) throw new FilesystemError(51, "shared filesystem page tables exhausted");
|
|
551
|
+
Atomics.store(this.tableOwners, block, slot);
|
|
552
|
+
this.cells[TABLE_HINT] = block + 1;
|
|
553
|
+
return block;
|
|
554
|
+
}
|
|
555
|
+
/** Links an existing or new child. Pool blocks are zero whenever they are free. */
|
|
556
|
+
private ensureLink(slot: number, cell: number): void {
|
|
557
|
+
if (!Atomics.load(this.pages, cell)) Atomics.store(this.pages, cell, this.takeBlock(slot) + 1);
|
|
558
|
+
}
|
|
559
|
+
private ensureLeaf(slot: number, leaf: number): void {
|
|
560
|
+
if (leaf < DIRECT_LEAVES) return this.ensureLink(slot, this.rootCell(slot, leaf));
|
|
561
|
+
const tail = leaf - DIRECT_LEAVES;
|
|
562
|
+
const topLink = this.rootCell(slot, DIRECT_LEAVES);
|
|
563
|
+
this.ensureLink(slot, topLink);
|
|
564
|
+
const branchLink = this.childCells(topLink) + Math.floor(tail / TABLE_ENTRIES);
|
|
565
|
+
this.ensureLink(slot, branchLink);
|
|
566
|
+
this.ensureLink(slot, this.childCells(branchLink) + (tail % TABLE_ENTRIES));
|
|
567
|
+
}
|
|
568
|
+
/** Earlier leaves are complete, so a growth pass starts at the first missing one. */
|
|
569
|
+
private reservePageTables(slot: number, from: number, needed: number): void {
|
|
570
|
+
const last = Math.ceil(needed / TABLE_ENTRIES);
|
|
571
|
+
for (let leaf = Math.ceil(from / TABLE_ENTRIES); leaf < last; leaf++)
|
|
572
|
+
this.ensureLeaf(slot, leaf);
|
|
573
|
+
}
|
|
574
|
+
private releaseCell(cell: number): void {
|
|
575
|
+
const block = Atomics.exchange(this.pages, cell, 0) - 1;
|
|
576
|
+
if (block < 0) return;
|
|
577
|
+
this.pages.fill(0, block * TABLE_ENTRIES, (block + 1) * TABLE_ENTRIES);
|
|
578
|
+
if (block < this.cells[TABLE_HINT]!) this.cells[TABLE_HINT] = block;
|
|
579
|
+
Atomics.store(this.tableOwners, block, 0);
|
|
580
|
+
}
|
|
581
|
+
/** Releases the branch's leaves from keep on, and the branch itself once none remain. */
|
|
582
|
+
private trimBranch(cell: number, keep: number): void {
|
|
583
|
+
if (!Atomics.load(this.pages, cell)) return;
|
|
584
|
+
const branch = this.childCells(cell);
|
|
585
|
+
for (let entry = keep; entry < TABLE_ENTRIES; entry++) this.releaseCell(branch + entry);
|
|
586
|
+
if (!keep) this.releaseCell(cell);
|
|
587
|
+
}
|
|
588
|
+
private trimPageTables(slot: number, needed: number): void {
|
|
589
|
+
const keep = Math.ceil(needed / TABLE_ENTRIES);
|
|
590
|
+
for (let leaf = keep; leaf < DIRECT_LEAVES; leaf++) this.releaseCell(this.rootCell(slot, leaf));
|
|
591
|
+
const topLink = this.rootCell(slot, DIRECT_LEAVES);
|
|
592
|
+
if (!Atomics.load(this.pages, topLink)) return;
|
|
593
|
+
const tailKeep = Math.max(0, keep - DIRECT_LEAVES);
|
|
594
|
+
const top = this.childCells(topLink);
|
|
595
|
+
const partial = tailKeep % TABLE_ENTRIES;
|
|
596
|
+
if (partial) this.trimBranch(top + Math.floor(tailKeep / TABLE_ENTRIES), partial);
|
|
597
|
+
for (let entry = Math.ceil(tailKeep / TABLE_ENTRIES); entry < TABLE_ENTRIES; entry++)
|
|
598
|
+
this.trimBranch(top + entry, 0);
|
|
599
|
+
if (!tailKeep) this.releaseCell(topLink);
|
|
600
|
+
}
|
|
601
|
+
/** The slot of a registered regular file, or 0. A live handle keeps its slot until it is freed. */
|
|
602
|
+
fileSlot(handle: FileHandle): number {
|
|
603
|
+
const slot = this.findSlot(handle);
|
|
604
|
+
return slot !== 0 && Atomics.load(this.slots, this.at(slot, 0)) === 1 ? slot : 0;
|
|
605
|
+
}
|
|
606
|
+
hasFile(handle: FileHandle): boolean {
|
|
607
|
+
const slot = this.findSlot(handle);
|
|
608
|
+
return slot !== 0 && Atomics.load(this.slots, this.at(slot, 0)) === 1;
|
|
609
|
+
}
|
|
610
|
+
isUnlinked(handle: FileHandle): boolean {
|
|
611
|
+
const slot = this.findSlot(handle);
|
|
612
|
+
return slot !== 0 && Atomics.load(this.slots, this.at(slot, UNLINKED)) !== 0;
|
|
613
|
+
}
|
|
614
|
+
/** Spin for a held lock. Only a contended caller checks revocation here; every acquirer
|
|
615
|
+
* checks it once after its locks are held, so a revoked guest never proceeds under a lock. */
|
|
616
|
+
private contend(
|
|
617
|
+
cells: Int32Array,
|
|
618
|
+
index: number,
|
|
619
|
+
revoked: (() => boolean) | undefined,
|
|
620
|
+
owner: number,
|
|
621
|
+
): void {
|
|
622
|
+
for (;;) {
|
|
623
|
+
if (revoked?.()) throw new FilesystemError(11);
|
|
624
|
+
this.publication?.assertLive();
|
|
625
|
+
this.onContention?.();
|
|
626
|
+
if (Atomics.compareExchange(cells, index, 0, owner) === 0) return;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
private assertLockAccess(access: "data" | "activation" | "release"): void {
|
|
630
|
+
if (access === "release") return;
|
|
631
|
+
if (access === "activation") this.publication?.assertLive();
|
|
632
|
+
else this.publication?.assertAccess();
|
|
633
|
+
}
|
|
634
|
+
private lock(
|
|
635
|
+
index: number,
|
|
636
|
+
revoked?: () => boolean,
|
|
637
|
+
owner = this.lockOwner,
|
|
638
|
+
access: "data" | "release" = "data",
|
|
639
|
+
): void {
|
|
640
|
+
const global =
|
|
641
|
+
(this.dirtyAdmission.enabled || !!this.publication || this.identities.active) &&
|
|
642
|
+
this.globalOwner === undefined;
|
|
643
|
+
if (global) this.globalLock(revoked, owner, false, access);
|
|
644
|
+
else this.assertLockAccess(access);
|
|
645
|
+
this.section?.enter();
|
|
646
|
+
let held = false;
|
|
647
|
+
try {
|
|
648
|
+
if (Atomics.compareExchange(this.slots, index, 0, owner) !== 0)
|
|
649
|
+
this.contend(this.slots, index, revoked, owner);
|
|
650
|
+
held = true;
|
|
651
|
+
if (revoked?.()) throw new FilesystemError(11);
|
|
652
|
+
// Every owner operation on a file first applies the staged writes its clients committed,
|
|
653
|
+
// so no owner path can serve, persist or reclaim that file's older bytes.
|
|
654
|
+
if (this.staged.size) this.settleStaged((index - FILE_LOCK) / SLOT_WORDS);
|
|
655
|
+
if (global) this.fileOwnsGlobal.add(index);
|
|
656
|
+
} catch (error) {
|
|
657
|
+
if (held) Atomics.compareExchange(this.slots, index, owner, 0);
|
|
658
|
+
this.section?.exit();
|
|
659
|
+
if (global) this.globalUnlock(owner);
|
|
660
|
+
throw error;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
private unlock(index: number, owner = this.lockOwner): void {
|
|
664
|
+
Atomics.compareExchange(this.slots, index, owner, 0);
|
|
665
|
+
this.section?.exit();
|
|
666
|
+
if (!this.fileOwnsGlobal.delete(index)) return;
|
|
667
|
+
this.globalUnlock(owner);
|
|
668
|
+
}
|
|
669
|
+
private globalLock(
|
|
670
|
+
revoked?: () => boolean,
|
|
671
|
+
owner = this.lockOwner,
|
|
672
|
+
nonblocking = false,
|
|
673
|
+
access: "data" | "activation" | "release" = "data",
|
|
674
|
+
revocation: "global" | "file" = "global",
|
|
675
|
+
): void {
|
|
676
|
+
if (this.globalOwner === owner) {
|
|
677
|
+
this.assertLockAccess(access);
|
|
678
|
+
this.globalDepth++;
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
if (this.serviceMutation && owner === SERVICE_OWNER) {
|
|
682
|
+
this.assertLockAccess(access);
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
this.section?.enter();
|
|
686
|
+
let held = false;
|
|
687
|
+
try {
|
|
688
|
+
held = Atomics.compareExchange(this.cells, GLOBAL_LOCK, 0, owner) === 0;
|
|
689
|
+
if (!held && nonblocking) throw new FilesystemError(6);
|
|
690
|
+
if (!held) this.contend(this.cells, GLOBAL_LOCK, revoked, owner);
|
|
691
|
+
held = true;
|
|
692
|
+
if (revocation === "global" && revoked?.()) throw new FilesystemError(11);
|
|
693
|
+
this.assertLockAccess(access);
|
|
694
|
+
this.globalOwner = owner;
|
|
695
|
+
} catch (error) {
|
|
696
|
+
if (held) Atomics.compareExchange(this.cells, GLOBAL_LOCK, owner, 0);
|
|
697
|
+
this.section?.exit();
|
|
698
|
+
throw error;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
private globalUnlock(owner = this.lockOwner): void {
|
|
702
|
+
if (this.globalDepth > 0) {
|
|
703
|
+
this.globalDepth--;
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
if (this.serviceMutation) return;
|
|
707
|
+
this.globalOwner = undefined;
|
|
708
|
+
Atomics.compareExchange(this.cells, GLOBAL_LOCK, owner, 0);
|
|
709
|
+
this.section?.exit();
|
|
710
|
+
}
|
|
711
|
+
activateResidentAuthority(): void {
|
|
712
|
+
this.globalLock(undefined, this.lockOwner, false, "activation");
|
|
713
|
+
try {
|
|
714
|
+
this.publication!.activateResident();
|
|
715
|
+
} finally {
|
|
716
|
+
this.globalUnlock();
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
beginServiceMutation(epoch: Int32Array, residentGrant = 0): void {
|
|
720
|
+
this.globalLock();
|
|
721
|
+
try {
|
|
722
|
+
this.publication?.assertCurrent(residentGrant);
|
|
723
|
+
} catch (error) {
|
|
724
|
+
this.globalUnlock();
|
|
725
|
+
throw error;
|
|
726
|
+
}
|
|
727
|
+
this.serviceMutation = true;
|
|
728
|
+
Atomics.add(epoch, 0, 1);
|
|
729
|
+
}
|
|
730
|
+
endServiceMutation(epoch: Int32Array): void {
|
|
731
|
+
Atomics.add(epoch, 0, 1);
|
|
732
|
+
this.serviceMutation = false;
|
|
733
|
+
this.globalUnlock();
|
|
734
|
+
}
|
|
735
|
+
get ownsServiceMutation(): boolean {
|
|
736
|
+
return this.serviceMutation;
|
|
737
|
+
}
|
|
738
|
+
mutate<T>(
|
|
739
|
+
epoch: Int32Array | undefined,
|
|
740
|
+
revoked: (() => boolean) | undefined,
|
|
741
|
+
fn: () => T,
|
|
742
|
+
owner = this.lockOwner,
|
|
743
|
+
): T {
|
|
744
|
+
this.globalLock(revoked, owner);
|
|
745
|
+
if (epoch) Atomics.add(epoch, 0, 1);
|
|
746
|
+
const previous = this.currentOwner;
|
|
747
|
+
this.currentOwner = owner;
|
|
748
|
+
try {
|
|
749
|
+
this.publication?.assertCurrent();
|
|
750
|
+
return fn();
|
|
751
|
+
} finally {
|
|
752
|
+
this.currentOwner = previous;
|
|
753
|
+
if (epoch) Atomics.add(epoch, 0, 1);
|
|
754
|
+
this.globalUnlock(owner);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
private time(slot: number, field: number): FileTime {
|
|
758
|
+
return Atomics.load(this.times, (slot * SLOT_WORDS + field) / 2);
|
|
759
|
+
}
|
|
760
|
+
private setTime(slot: number, field: number, time: FileTime): void {
|
|
761
|
+
Atomics.store(this.times, (slot * SLOT_WORDS + field) / 2, time);
|
|
762
|
+
}
|
|
763
|
+
/** Content changes set mtime and ctime together. */
|
|
764
|
+
private setModified(slot: number, time: FileTime): void {
|
|
765
|
+
this.setTime(slot, MTIME, time);
|
|
766
|
+
this.setTime(slot, CTIME, time);
|
|
767
|
+
}
|
|
768
|
+
private storeTimes(slot: number, times: Pick<FileStat, "atime" | "mtime" | "ctime">): void {
|
|
769
|
+
this.setTime(slot, ATIME, times.atime);
|
|
770
|
+
this.setTime(slot, MTIME, times.mtime);
|
|
771
|
+
this.setTime(slot, CTIME, times.ctime);
|
|
772
|
+
}
|
|
773
|
+
private sameTimes(slot: number, times: Pick<FileStat, "atime" | "mtime" | "ctime">): boolean {
|
|
774
|
+
return (
|
|
775
|
+
this.time(slot, ATIME) === times.atime &&
|
|
776
|
+
this.time(slot, MTIME) === times.mtime &&
|
|
777
|
+
this.time(slot, CTIME) === times.ctime
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
/** Revision reads and increments are covered by the file lock, including the carry. */
|
|
781
|
+
private getRevision(slot: number): number {
|
|
782
|
+
const base = slot * SLOT_WORDS;
|
|
783
|
+
return (
|
|
784
|
+
(this.slots[base + REVISION_STATE]! >>> 1) * 0x100000000 +
|
|
785
|
+
(this.slots[base + REVISION]! >>> 0)
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
private changed(slot: number): void {
|
|
789
|
+
const base = slot * SLOT_WORDS,
|
|
790
|
+
low = this.slots[base + REVISION]!;
|
|
791
|
+
this.slots[base + REVISION] = low + 1;
|
|
792
|
+
if (low === -1) this.slots[base + REVISION_STATE] = this.slots[base + REVISION_STATE]! + 2;
|
|
793
|
+
}
|
|
794
|
+
private residentBytes(): number {
|
|
795
|
+
return Atomics.load(this.cells, USED_PAGES) * DATA_PAGE_BYTES;
|
|
796
|
+
}
|
|
797
|
+
private checkDirty(slot: number, size: number, resident = this.residentBytes()): void {
|
|
798
|
+
this.dirtyAdmission.checkFile(
|
|
799
|
+
resident,
|
|
800
|
+
this.slots[this.at(slot, DIRTY_SIZE)]!,
|
|
801
|
+
size,
|
|
802
|
+
this.slots[this.at(slot, DIRTY_MARK)] !== 1,
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
private dirty(slot: number, size = this.slots[this.at(slot, FILE_SIZE)]!): void {
|
|
806
|
+
if (!this.dirtyAdmission.enabled) return;
|
|
807
|
+
const previous = this.slots[this.at(slot, DIRTY_SIZE)]!;
|
|
808
|
+
this.dirtyAdmission.file(
|
|
809
|
+
this.residentBytes(),
|
|
810
|
+
previous,
|
|
811
|
+
size,
|
|
812
|
+
this.slots[this.at(slot, DIRTY_MARK)] !== 1,
|
|
813
|
+
);
|
|
814
|
+
this.slots[this.at(slot, DIRTY_SIZE)] = Math.max(previous, size);
|
|
815
|
+
this.slots[this.at(slot, DIRTY_MARK)] = 1;
|
|
816
|
+
}
|
|
817
|
+
checkDirtyGrowth(handle: FileHandle, size: number): void {
|
|
818
|
+
this.checkDirty(this.slot(handle), size);
|
|
819
|
+
}
|
|
820
|
+
prepareDirtyMutation(files: ReadonlyMap<FileHandle, number>, namespace: number): void {
|
|
821
|
+
let bytes = 0,
|
|
822
|
+
metadata = 0;
|
|
823
|
+
for (const [handle, size] of files) {
|
|
824
|
+
const slot = this.slot(handle);
|
|
825
|
+
this.checkDirty(slot, size);
|
|
826
|
+
bytes += Math.max(0, size - this.slots[this.at(slot, DIRTY_SIZE)]!) * 2;
|
|
827
|
+
if (this.slots[this.at(slot, DIRTY_MARK)] !== 1) metadata += DIRTY_NODE_UNITS;
|
|
828
|
+
}
|
|
829
|
+
this.dirtyAdmission.mutation(this.residentBytes(), namespace, bytes, metadata);
|
|
830
|
+
for (const [handle, size] of files) {
|
|
831
|
+
const slot = this.slot(handle);
|
|
832
|
+
this.slots[this.at(slot, DIRTY_SIZE)] = Math.max(
|
|
833
|
+
size,
|
|
834
|
+
this.slots[this.at(slot, DIRTY_SIZE)]!,
|
|
835
|
+
);
|
|
836
|
+
this.slots[this.at(slot, DIRTY_MARK)] = 1;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
cleanDirty(revision: number, namespace: number): void {
|
|
840
|
+
if (!this.dirtyAdmission.clean(revision, namespace)) return;
|
|
841
|
+
for (let slot = 1; slot < MAX_FILES; slot++) {
|
|
842
|
+
this.slots[this.at(slot, DIRTY_SIZE)] = 0;
|
|
843
|
+
this.slots[this.at(slot, DIRTY_MARK)] = 0;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
private checkFile(slot: number, handle: FileHandle): void {
|
|
847
|
+
if (this.slots[this.at(slot, HANDLE)] !== handle + 1) throw new FilesystemError(8);
|
|
848
|
+
if (this.slots[this.at(slot, 0)] !== 1) throw new FilesystemError(31);
|
|
849
|
+
}
|
|
850
|
+
private ensureSegment(segment: number): void {
|
|
851
|
+
if (segment >= Atomics.load(this.cells, 4))
|
|
852
|
+
throw new FilesystemError(51, "shared filesystem storage exhausted");
|
|
853
|
+
if (segment === 0 || this.segments[segment]) return;
|
|
854
|
+
// A second builder would create backing the owner never sees. Everyone else asks the owner.
|
|
855
|
+
if (this.lockOwner !== SERVICE_OWNER)
|
|
856
|
+
throw new MissingSegmentError("only the filesystem owner creates segments");
|
|
857
|
+
// A native refusal leaves the directory unchanged, and a later request may try again. A
|
|
858
|
+
// segment that was built stays, even when the allocation that needed it then fails.
|
|
859
|
+
const buffer = createFilesystemSegment();
|
|
860
|
+
this.segments[segment] = buffer;
|
|
861
|
+
this.pendingSegments.push({ buffer, index: segment });
|
|
862
|
+
}
|
|
863
|
+
private allocate(slot: number, needed: number): void {
|
|
864
|
+
const current = Atomics.load(this.slots, this.at(slot, CAPACITY));
|
|
865
|
+
if (needed <= current) return;
|
|
866
|
+
if (needed > MAX_FILE_PAGES) throw new RangeError("shared filesystem file is too large");
|
|
867
|
+
const target = this.dirtyAdmission.enabled
|
|
868
|
+
? needed
|
|
869
|
+
: Math.max(needed, Math.min(MAX_FILE_PAGES, Math.max(1, current * 2)));
|
|
870
|
+
this.dirtyAdmission.resident(this.residentBytes() + (target - current) * DATA_PAGE_BYTES);
|
|
871
|
+
const allocated: number[] = [];
|
|
872
|
+
const rollback = () => {
|
|
873
|
+
for (const physical of allocated) {
|
|
874
|
+
this.segmentFor(physical).fill(0);
|
|
875
|
+
this.releasePhysical(physical);
|
|
876
|
+
}
|
|
877
|
+
allocated.length = 0;
|
|
878
|
+
this.trimPageTables(slot, current);
|
|
879
|
+
};
|
|
880
|
+
const take = (count: number) => {
|
|
881
|
+
while (allocated.length < count) {
|
|
882
|
+
const physical = this.freePhysical();
|
|
883
|
+
if (physical < 0) return;
|
|
884
|
+
this.ensureSegment(Math.floor(physical / DATA_PAGES_PER_SEGMENT));
|
|
885
|
+
Atomics.store(this.owners, physical, slot);
|
|
886
|
+
this.cells[PHYSICAL_HINT] = physical + 1;
|
|
887
|
+
allocated.push(physical);
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
try {
|
|
891
|
+
take(target - current);
|
|
892
|
+
if (allocated.length !== target - current && target !== needed) {
|
|
893
|
+
rollback();
|
|
894
|
+
take(needed - current);
|
|
895
|
+
}
|
|
896
|
+
if (allocated.length !== needed - current && allocated.length !== target - current)
|
|
897
|
+
throw new FilesystemError(51, "shared filesystem storage exhausted");
|
|
898
|
+
// Finish potentially throwing initialization before publishing any page-table entries.
|
|
899
|
+
for (const physical of allocated) this.segmentFor(physical).fill(0);
|
|
900
|
+
this.reservePageTables(slot, current, current + allocated.length);
|
|
901
|
+
for (let i = 0; i < allocated.length; i++)
|
|
902
|
+
Atomics.store(this.pages, this.pageAt(slot, current + i), allocated[i]! + 1);
|
|
903
|
+
Atomics.store(this.slots, this.at(slot, CAPACITY), current + allocated.length);
|
|
904
|
+
Atomics.add(this.cells, USED_PAGES, allocated.length);
|
|
905
|
+
this.trimPageTables(slot, current + allocated.length);
|
|
906
|
+
} catch (error) {
|
|
907
|
+
rollback();
|
|
908
|
+
if (error instanceof RangeError)
|
|
909
|
+
throw new FilesystemError(51, "shared filesystem segment allocation failed");
|
|
910
|
+
throw error;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
private refreshRegistered(slot: number, stat: FileStat): boolean {
|
|
914
|
+
if (!this.slots[this.at(slot, 0)] || this.slots[this.at(slot, INO)] !== stat.ino) return false;
|
|
915
|
+
Atomics.store(this.slots, this.at(slot, NLINK), stat.nlink);
|
|
916
|
+
if (this.slots[this.at(slot, MODE)] !== (stat.mode ?? -1)) {
|
|
917
|
+
this.slots[this.at(slot, MODE)] = stat.mode ?? -1;
|
|
918
|
+
this.changed(slot);
|
|
919
|
+
}
|
|
920
|
+
if (stat.kind === "directory" && !this.sameTimes(slot, stat)) {
|
|
921
|
+
this.storeTimes(slot, stat);
|
|
922
|
+
this.changed(slot);
|
|
923
|
+
}
|
|
924
|
+
return true;
|
|
925
|
+
}
|
|
926
|
+
register(
|
|
927
|
+
handle: FileHandle,
|
|
928
|
+
stat: FileStat,
|
|
929
|
+
data?: Uint8Array,
|
|
930
|
+
resident = true,
|
|
931
|
+
identity?: FileIdentity,
|
|
932
|
+
): void {
|
|
933
|
+
this.globalLock();
|
|
934
|
+
try {
|
|
935
|
+
const slot = this.findSlot(handle, true);
|
|
936
|
+
if (!slot) throw new FilesystemError(51, "shared filesystem identity table exhausted");
|
|
937
|
+
this.lock(this.at(slot, FILE_LOCK));
|
|
938
|
+
let pinned = false;
|
|
939
|
+
try {
|
|
940
|
+
if (this.refreshRegistered(slot, stat)) return;
|
|
941
|
+
this.dirtyAdmission.pin(1, this.residentBytes());
|
|
942
|
+
pinned = true;
|
|
943
|
+
const loaded = resident || stat.size === 0;
|
|
944
|
+
if (stat.kind === "file" && loaded) {
|
|
945
|
+
this.allocate(slot, Math.ceil(Math.max(data?.length ?? 0, stat.size) / DATA_PAGE_BYTES));
|
|
946
|
+
if (data?.length) this.copyInto(slot, data, 0);
|
|
947
|
+
}
|
|
948
|
+
Atomics.store(
|
|
949
|
+
this.slots,
|
|
950
|
+
this.at(slot, 0),
|
|
951
|
+
stat.kind === "file" ? 1 : stat.kind === "symlink" ? 3 : stat.kind === "socket" ? 4 : 2,
|
|
952
|
+
);
|
|
953
|
+
Atomics.store(this.slots, this.at(slot, FILE_SIZE), stat.size);
|
|
954
|
+
Atomics.store(this.slots, this.at(slot, INO), stat.ino);
|
|
955
|
+
Atomics.store(this.slots, this.at(slot, NLINK), stat.nlink);
|
|
956
|
+
this.storeTimes(slot, stat);
|
|
957
|
+
Atomics.store(this.slots, this.at(slot, MODE), stat.mode ?? -1);
|
|
958
|
+
const floor =
|
|
959
|
+
(this.cells[FREED_REVISION_HIGH]! >>> 0) * 0x100000000 +
|
|
960
|
+
(this.cells[FREED_REVISION_LOW]! >>> 0);
|
|
961
|
+
const revision = Math.max(this.getRevision(slot), floor) + 1;
|
|
962
|
+
this.slots[this.at(slot, REVISION)] = revision >>> 0;
|
|
963
|
+
this.slots[this.at(slot, REVISION_STATE)] =
|
|
964
|
+
Math.floor(revision / 0x100000000) * 2 + (loaded ? RESIDENT : 0);
|
|
965
|
+
if (identity) this.installIdentity(slot, identity);
|
|
966
|
+
Atomics.store(this.slots, this.at(slot, HANDLE), handle + 1);
|
|
967
|
+
} catch (error) {
|
|
968
|
+
if (pinned) this.dirtyAdmission.pin(-1, this.residentBytes());
|
|
969
|
+
throw error;
|
|
970
|
+
} finally {
|
|
971
|
+
this.unlock(this.at(slot, FILE_LOCK));
|
|
972
|
+
}
|
|
973
|
+
} finally {
|
|
974
|
+
this.globalUnlock();
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
/** Waits for the global lock like stat() does: another owner's critical section is short, and
|
|
978
|
+
* the owner's contention sweep reclaims a dead holder's lock. A non-blocking probe here failed
|
|
979
|
+
* blocking descriptor reads with EAGAIN. revoked ends the wait for a cancelled request. */
|
|
980
|
+
identity(handle: FileHandle, revoked?: () => boolean): FileIdentity | undefined {
|
|
981
|
+
this.globalLock(revoked, this.lockOwner);
|
|
982
|
+
try {
|
|
983
|
+
const slot = this.findSlot(handle);
|
|
984
|
+
if (!slot) return undefined;
|
|
985
|
+
const id = readIdentityWords(this.slots, this.at(slot, FILE_ID));
|
|
986
|
+
if (id === 0n) return undefined;
|
|
987
|
+
return {
|
|
988
|
+
id: id as FileId,
|
|
989
|
+
version: readIdentityWords(this.slots, this.at(slot, FILE_VERSION)) as FileVersion,
|
|
990
|
+
};
|
|
991
|
+
} finally {
|
|
992
|
+
this.globalUnlock();
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
updateIdentity(handle: FileHandle, identity: FileIdentity): void {
|
|
996
|
+
const slot = this.findSlot(handle);
|
|
997
|
+
if (slot) this.installIdentity(slot, identity);
|
|
998
|
+
}
|
|
999
|
+
private installIdentity(slot: number, identity: FileIdentity): void {
|
|
1000
|
+
writeIdentityWords(this.slots, this.at(slot, FILE_ID), identity.id);
|
|
1001
|
+
writeIdentityWords(this.slots, this.at(slot, FILE_VERSION), identity.version);
|
|
1002
|
+
}
|
|
1003
|
+
private prepareIdentityVersion(
|
|
1004
|
+
slot: number,
|
|
1005
|
+
changed: boolean,
|
|
1006
|
+
): PlannedIdentityRevision | undefined {
|
|
1007
|
+
if (!changed || this.identityGroup || !this.identities.active) return undefined;
|
|
1008
|
+
const id = readIdentityWords(this.slots, this.at(slot, FILE_ID));
|
|
1009
|
+
if (id === 0n) throw new FilesystemError(29, "missing shared file identity");
|
|
1010
|
+
const allocation = this.identities.stage();
|
|
1011
|
+
return { allocation, identity: { id: id as FileId, version: allocation.versions(1)[0]! } };
|
|
1012
|
+
}
|
|
1013
|
+
private commitIdentityVersion(slot: number, revision: PlannedIdentityRevision | undefined): void {
|
|
1014
|
+
if (!revision) return;
|
|
1015
|
+
this.identities.copyFrom(revision.allocation);
|
|
1016
|
+
this.installIdentity(slot, revision.identity);
|
|
1017
|
+
this.watch.change(revision.identity.id, this.slots[this.at(slot, MODE)]!);
|
|
1018
|
+
}
|
|
1019
|
+
private publicationFile(slot: number, revision: PlannedIdentityRevision | undefined) {
|
|
1020
|
+
const id = readIdentityWords(this.slots, this.at(slot, FILE_ID));
|
|
1021
|
+
if (id === 0n) throw new FilesystemError(29, "missing shared file identity");
|
|
1022
|
+
return {
|
|
1023
|
+
birthHistory: this.publication!.buffers.history,
|
|
1024
|
+
ino: this.slots[this.at(slot, INO)]!,
|
|
1025
|
+
id: id as FileId,
|
|
1026
|
+
version:
|
|
1027
|
+
revision?.identity.version ??
|
|
1028
|
+
(readIdentityWords(this.slots, this.at(slot, FILE_VERSION)) as FileVersion),
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
/** Install persisted bytes without changing the file's metadata or dirty revision. */
|
|
1032
|
+
hydrate(handle: FileHandle, data: Uint8Array): void {
|
|
1033
|
+
this.globalLock();
|
|
1034
|
+
try {
|
|
1035
|
+
const slot = this.slot(handle);
|
|
1036
|
+
this.lock(this.at(slot, FILE_LOCK));
|
|
1037
|
+
try {
|
|
1038
|
+
this.checkFile(slot, handle);
|
|
1039
|
+
if (this.slots[this.at(slot, REVISION_STATE)]! & RESIDENT) return;
|
|
1040
|
+
if (data.length !== this.slots[this.at(slot, FILE_SIZE)])
|
|
1041
|
+
throw new RangeError("persisted file size does not match shared metadata");
|
|
1042
|
+
this.allocate(slot, Math.ceil(data.length / DATA_PAGE_BYTES));
|
|
1043
|
+
this.copyInto(slot, data, 0);
|
|
1044
|
+
this.slots[this.at(slot, REVISION_STATE)]! |= RESIDENT;
|
|
1045
|
+
} finally {
|
|
1046
|
+
this.unlock(this.at(slot, FILE_LOCK));
|
|
1047
|
+
}
|
|
1048
|
+
} finally {
|
|
1049
|
+
this.globalUnlock();
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
isResident(handle: FileHandle): boolean {
|
|
1053
|
+
const slot = this.findSlot(handle);
|
|
1054
|
+
if (!slot) return false;
|
|
1055
|
+
this.lock(this.at(slot, FILE_LOCK));
|
|
1056
|
+
try {
|
|
1057
|
+
return (
|
|
1058
|
+
this.slots[this.at(slot, HANDLE)] === handle + 1 &&
|
|
1059
|
+
this.slots[this.at(slot, 0)] === 1 &&
|
|
1060
|
+
(this.slots[this.at(slot, REVISION_STATE)]! & RESIDENT) !== 0
|
|
1061
|
+
);
|
|
1062
|
+
} finally {
|
|
1063
|
+
this.unlock(this.at(slot, FILE_LOCK));
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
/** Bounded by the resident identity table, not the size of the persisted namespace. */
|
|
1067
|
+
registeredHandles(): FileHandle[] {
|
|
1068
|
+
const handles: FileHandle[] = [];
|
|
1069
|
+
for (let slot = 1; slot < MAX_FILES; slot++) {
|
|
1070
|
+
const handle = Atomics.load(this.slots, this.at(slot, HANDLE)) - 1;
|
|
1071
|
+
if (handle >= 0) handles.push(handle);
|
|
1072
|
+
}
|
|
1073
|
+
return handles;
|
|
1074
|
+
}
|
|
1075
|
+
revision(
|
|
1076
|
+
handle: FileHandle,
|
|
1077
|
+
nonblocking = false,
|
|
1078
|
+
revoked?: () => boolean,
|
|
1079
|
+
owner = this.lockOwner,
|
|
1080
|
+
): number | undefined {
|
|
1081
|
+
return this.current(nonblocking, revoked, owner, () =>
|
|
1082
|
+
this.revisionLocked(handle, nonblocking, revoked, owner),
|
|
1083
|
+
);
|
|
1084
|
+
}
|
|
1085
|
+
private revisionLocked(
|
|
1086
|
+
handle: FileHandle,
|
|
1087
|
+
nonblocking: boolean,
|
|
1088
|
+
revoked: (() => boolean) | undefined,
|
|
1089
|
+
owner: number,
|
|
1090
|
+
): number | undefined {
|
|
1091
|
+
const slot = this.findSlot(handle);
|
|
1092
|
+
if (!slot) return undefined;
|
|
1093
|
+
const lock = this.at(slot, FILE_LOCK);
|
|
1094
|
+
this.section?.enter();
|
|
1095
|
+
try {
|
|
1096
|
+
if (Atomics.compareExchange(this.slots, lock, 0, owner) !== 0) {
|
|
1097
|
+
if (nonblocking) throw new FilesystemError(6);
|
|
1098
|
+
this.contend(this.slots, lock, revoked, owner);
|
|
1099
|
+
}
|
|
1100
|
+
} catch (error) {
|
|
1101
|
+
this.section?.exit();
|
|
1102
|
+
throw error;
|
|
1103
|
+
}
|
|
1104
|
+
try {
|
|
1105
|
+
if (revoked?.()) throw new FilesystemError(11);
|
|
1106
|
+
return this.slots[this.at(slot, HANDLE)] === handle + 1 && this.slots[this.at(slot, 0)]
|
|
1107
|
+
? this.getRevision(slot)
|
|
1108
|
+
: undefined;
|
|
1109
|
+
} finally {
|
|
1110
|
+
this.unlock(this.at(slot, FILE_LOCK), owner);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
/** One file lock covers the bytes, stat and revision; the returned bytes are an owned copy. */
|
|
1114
|
+
snapshot(handle: FileHandle): SharedFileSnapshot | undefined {
|
|
1115
|
+
const slot = this.findSlot(handle);
|
|
1116
|
+
if (!slot) return undefined;
|
|
1117
|
+
this.lock(this.at(slot, FILE_LOCK));
|
|
1118
|
+
try {
|
|
1119
|
+
const base = slot * SLOT_WORDS;
|
|
1120
|
+
if (
|
|
1121
|
+
this.slots[base + HANDLE] !== handle + 1 ||
|
|
1122
|
+
this.slots[base] !== 1 ||
|
|
1123
|
+
!(this.slots[base + REVISION_STATE]! & RESIDENT)
|
|
1124
|
+
)
|
|
1125
|
+
return undefined;
|
|
1126
|
+
const stat: FileStat = {
|
|
1127
|
+
kind: "file",
|
|
1128
|
+
ino: this.slots[base + INO]!,
|
|
1129
|
+
nlink: this.slots[base + NLINK]! >>> 0,
|
|
1130
|
+
size: this.slots[base + FILE_SIZE]!,
|
|
1131
|
+
atime: this.time(slot, ATIME),
|
|
1132
|
+
mtime: this.time(slot, MTIME),
|
|
1133
|
+
ctime: this.time(slot, CTIME),
|
|
1134
|
+
...this.modeField(slot),
|
|
1135
|
+
};
|
|
1136
|
+
const data = new Uint8Array(stat.size);
|
|
1137
|
+
for (let position = 0; position < data.length; position += DATA_PAGE_BYTES) {
|
|
1138
|
+
const count = Math.min(DATA_PAGE_BYTES, data.length - position);
|
|
1139
|
+
const page = this.segmentFor(
|
|
1140
|
+
this.pages[this.pageAt(slot, position / DATA_PAGE_BYTES)]! - 1,
|
|
1141
|
+
);
|
|
1142
|
+
data.set(count === DATA_PAGE_BYTES ? page : page.subarray(0, count), position);
|
|
1143
|
+
}
|
|
1144
|
+
return { stat, data, revision: this.getRevision(slot) };
|
|
1145
|
+
} finally {
|
|
1146
|
+
this.unlock(this.at(slot, FILE_LOCK));
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
/** Eviction may discard a linked file only after its exact revision has been persisted.
|
|
1150
|
+
* Service-owned references include transient client cache entries, not just open descriptors. */
|
|
1151
|
+
evict(handle: FileHandle, revision: number): boolean {
|
|
1152
|
+
this.globalLock();
|
|
1153
|
+
try {
|
|
1154
|
+
const slot = this.findSlot(handle);
|
|
1155
|
+
if (!slot) return false;
|
|
1156
|
+
this.lock(this.at(slot, FILE_LOCK));
|
|
1157
|
+
try {
|
|
1158
|
+
if (
|
|
1159
|
+
this.slots[this.at(slot, HANDLE)] !== handle + 1 ||
|
|
1160
|
+
!this.slots[this.at(slot, 0)] ||
|
|
1161
|
+
this.slots[this.at(slot, REFS)] !== 0 ||
|
|
1162
|
+
this.getRevision(slot) !== revision
|
|
1163
|
+
)
|
|
1164
|
+
return false;
|
|
1165
|
+
this.freeLocked(slot);
|
|
1166
|
+
return true;
|
|
1167
|
+
} finally {
|
|
1168
|
+
this.unlock(this.at(slot, FILE_LOCK));
|
|
1169
|
+
}
|
|
1170
|
+
} finally {
|
|
1171
|
+
this.globalUnlock();
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
/** Drop a persisted payload without revoking open or transient cached identities. */
|
|
1175
|
+
unload(handle: FileHandle, revision: number): boolean {
|
|
1176
|
+
this.globalLock();
|
|
1177
|
+
try {
|
|
1178
|
+
const slot = this.findSlot(handle);
|
|
1179
|
+
if (!slot) return false;
|
|
1180
|
+
this.lock(this.at(slot, FILE_LOCK));
|
|
1181
|
+
try {
|
|
1182
|
+
if (
|
|
1183
|
+
this.slots[this.at(slot, HANDLE)] !== handle + 1 ||
|
|
1184
|
+
this.slots[this.at(slot, 0)] !== 1 ||
|
|
1185
|
+
this.getRevision(slot) !== revision
|
|
1186
|
+
)
|
|
1187
|
+
return false;
|
|
1188
|
+
this.freePagesLocked(slot);
|
|
1189
|
+
if (this.slots[this.at(slot, FILE_SIZE)])
|
|
1190
|
+
this.slots[this.at(slot, REVISION_STATE)]! &= ~RESIDENT;
|
|
1191
|
+
return true;
|
|
1192
|
+
} finally {
|
|
1193
|
+
this.unlock(this.at(slot, FILE_LOCK));
|
|
1194
|
+
}
|
|
1195
|
+
} finally {
|
|
1196
|
+
this.globalUnlock();
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
info(
|
|
1200
|
+
handle: FileHandle,
|
|
1201
|
+
revoked?: () => boolean,
|
|
1202
|
+
owner = this.lockOwner,
|
|
1203
|
+
): SharedFileInfo | undefined {
|
|
1204
|
+
return this.current(false, revoked, owner, () => this.infoLocked(handle, revoked, owner));
|
|
1205
|
+
}
|
|
1206
|
+
private infoLocked(
|
|
1207
|
+
handle: FileHandle,
|
|
1208
|
+
revoked?: () => boolean,
|
|
1209
|
+
owner = this.lockOwner,
|
|
1210
|
+
): SharedFileInfo | undefined {
|
|
1211
|
+
const slot = this.findSlot(handle);
|
|
1212
|
+
if (!slot) return undefined;
|
|
1213
|
+
this.lock(this.at(slot, FILE_LOCK), revoked, owner);
|
|
1214
|
+
try {
|
|
1215
|
+
if (
|
|
1216
|
+
Atomics.load(this.slots, this.at(slot, HANDLE)) !== handle + 1 ||
|
|
1217
|
+
Atomics.load(this.slots, this.at(slot, 0)) !== 1
|
|
1218
|
+
)
|
|
1219
|
+
return undefined;
|
|
1220
|
+
return {
|
|
1221
|
+
kind: "file",
|
|
1222
|
+
ino: Atomics.load(this.slots, this.at(slot, INO)),
|
|
1223
|
+
nlink: Atomics.load(this.slots, this.at(slot, NLINK)) >>> 0,
|
|
1224
|
+
size: Atomics.load(this.slots, this.at(slot, FILE_SIZE)),
|
|
1225
|
+
atime: this.time(slot, ATIME),
|
|
1226
|
+
mtime: this.time(slot, MTIME),
|
|
1227
|
+
ctime: this.time(slot, CTIME),
|
|
1228
|
+
...this.modeField(slot),
|
|
1229
|
+
capacity: Atomics.load(this.slots, this.at(slot, CAPACITY)) * DATA_PAGE_BYTES,
|
|
1230
|
+
};
|
|
1231
|
+
} finally {
|
|
1232
|
+
this.unlock(this.at(slot, FILE_LOCK), owner);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
stat(handle: FileHandle, revoked?: () => boolean, owner = this.lockOwner): FileStat | undefined {
|
|
1236
|
+
return this.current(false, revoked, owner, () => this.statLocked(handle, revoked, owner));
|
|
1237
|
+
}
|
|
1238
|
+
private statLocked(
|
|
1239
|
+
handle: FileHandle,
|
|
1240
|
+
revoked?: () => boolean,
|
|
1241
|
+
owner = this.lockOwner,
|
|
1242
|
+
): FileStat | undefined {
|
|
1243
|
+
const slot = this.findSlot(handle);
|
|
1244
|
+
if (!slot) return undefined;
|
|
1245
|
+
this.lock(this.at(slot, FILE_LOCK), revoked, owner);
|
|
1246
|
+
try {
|
|
1247
|
+
const kind = Atomics.load(this.slots, this.at(slot, 0));
|
|
1248
|
+
if (!kind || Atomics.load(this.slots, this.at(slot, HANDLE)) !== handle + 1) return undefined;
|
|
1249
|
+
return {
|
|
1250
|
+
kind: kind === 1 ? "file" : kind === 3 ? "symlink" : kind === 4 ? "socket" : "directory",
|
|
1251
|
+
ino: Atomics.load(this.slots, this.at(slot, INO)),
|
|
1252
|
+
nlink: Atomics.load(this.slots, this.at(slot, NLINK)) >>> 0,
|
|
1253
|
+
size: kind !== 2 ? Atomics.load(this.slots, this.at(slot, FILE_SIZE)) : 0,
|
|
1254
|
+
atime: this.time(slot, ATIME),
|
|
1255
|
+
mtime: this.time(slot, MTIME),
|
|
1256
|
+
ctime: this.time(slot, CTIME),
|
|
1257
|
+
...this.modeField(slot),
|
|
1258
|
+
};
|
|
1259
|
+
} finally {
|
|
1260
|
+
this.unlock(this.at(slot, FILE_LOCK), owner);
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
/** A name change of the inode. The tree records the same ctime for persistence, so the
|
|
1264
|
+
* revision, and with it the persisted payload, stays unchanged. */
|
|
1265
|
+
setNlink(handle: FileHandle, nlink: number, ctime: FileTime): void {
|
|
1266
|
+
const slot = this.findSlot(handle);
|
|
1267
|
+
if (!slot) return;
|
|
1268
|
+
this.lock(this.at(slot, FILE_LOCK));
|
|
1269
|
+
try {
|
|
1270
|
+
if (this.slots[this.at(slot, HANDLE)] !== handle + 1) return;
|
|
1271
|
+
Atomics.store(this.slots, this.at(slot, NLINK), nlink);
|
|
1272
|
+
this.setTime(slot, CTIME, ctime);
|
|
1273
|
+
} finally {
|
|
1274
|
+
this.unlock(this.at(slot, FILE_LOCK));
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
private modeField(slot: number): Pick<FileStat, "mode"> {
|
|
1278
|
+
const mode = Atomics.load(this.slots, this.at(slot, MODE));
|
|
1279
|
+
return mode < 0 ? {} : { mode };
|
|
1280
|
+
}
|
|
1281
|
+
private checkAccess(slot: number, access: number): void {
|
|
1282
|
+
const mode = this.slots[this.at(slot, MODE)]!;
|
|
1283
|
+
if (mode >= 0 && ((mode >>> 6) & access) !== access) throw new FilesystemError(2);
|
|
1284
|
+
}
|
|
1285
|
+
setMode(handle: FileHandle, mode: number, ctime = fileTimeNow()): void {
|
|
1286
|
+
const slot = this.slot(handle);
|
|
1287
|
+
this.lock(this.at(slot, FILE_LOCK));
|
|
1288
|
+
try {
|
|
1289
|
+
if (this.slots[this.at(slot, HANDLE)] !== handle + 1) throw new FilesystemError(8);
|
|
1290
|
+
const changed = this.slots[this.at(slot, MODE)] !== mode;
|
|
1291
|
+
const version = this.prepareIdentityVersion(slot, changed);
|
|
1292
|
+
if (!changed) return;
|
|
1293
|
+
this.dirty(slot);
|
|
1294
|
+
this.slots[this.at(slot, MODE)] = mode;
|
|
1295
|
+
this.setTime(slot, CTIME, ctime);
|
|
1296
|
+
this.changed(slot);
|
|
1297
|
+
this.commitIdentityVersion(slot, version);
|
|
1298
|
+
} finally {
|
|
1299
|
+
this.unlock(this.at(slot, FILE_LOCK));
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
private copyInto(slot: number, source: Uint8Array, offset: number): void {
|
|
1303
|
+
let at = offset;
|
|
1304
|
+
for (let sourceAt = 0; sourceAt < source.length;) {
|
|
1305
|
+
const logical = Math.floor(at / DATA_PAGE_BYTES);
|
|
1306
|
+
const page = Atomics.load(this.pages, this.pageAt(slot, logical)) - 1;
|
|
1307
|
+
const inPage = at % DATA_PAGE_BYTES;
|
|
1308
|
+
const count = Math.min(source.length - sourceAt, DATA_PAGE_BYTES - inPage);
|
|
1309
|
+
this.segmentFor(page).set(source.subarray(sourceAt, sourceAt + count), inPage);
|
|
1310
|
+
at += count;
|
|
1311
|
+
sourceAt += count;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
read(
|
|
1315
|
+
handle: FileHandle,
|
|
1316
|
+
chunks: readonly Uint8Array[],
|
|
1317
|
+
offset: number,
|
|
1318
|
+
revoked?: () => boolean,
|
|
1319
|
+
owner = this.lockOwner,
|
|
1320
|
+
): number {
|
|
1321
|
+
const slot = this.slot(handle);
|
|
1322
|
+
this.lock(this.at(slot, FILE_LOCK), revoked, owner);
|
|
1323
|
+
try {
|
|
1324
|
+
this.checkFile(slot, handle);
|
|
1325
|
+
this.checkAccess(slot, 4);
|
|
1326
|
+
if (!(this.slots[this.at(slot, REVISION_STATE)]! & RESIDENT))
|
|
1327
|
+
throw new MissingDataError("shared filesystem file has not been loaded");
|
|
1328
|
+
const size = Atomics.load(this.slots, this.at(slot, FILE_SIZE));
|
|
1329
|
+
let total = 0;
|
|
1330
|
+
for (const chunk of chunks) {
|
|
1331
|
+
let at = 0;
|
|
1332
|
+
while (at < chunk.length && offset + total < size) {
|
|
1333
|
+
const position = offset + total;
|
|
1334
|
+
const page =
|
|
1335
|
+
Atomics.load(this.pages, this.pageAt(slot, Math.floor(position / DATA_PAGE_BYTES))) - 1;
|
|
1336
|
+
const inPage = position % DATA_PAGE_BYTES;
|
|
1337
|
+
const count = Math.min(chunk.length - at, size - position, DATA_PAGE_BYTES - inPage);
|
|
1338
|
+
chunk.set(this.segmentFor(page).subarray(inPage, inPage + count), at);
|
|
1339
|
+
at += count;
|
|
1340
|
+
total += count;
|
|
1341
|
+
}
|
|
1342
|
+
if (at < chunk.length) break;
|
|
1343
|
+
}
|
|
1344
|
+
return total;
|
|
1345
|
+
} finally {
|
|
1346
|
+
this.unlock(this.at(slot, FILE_LOCK), owner);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
/* Direct client paths. A live file's size, timestamp and page entries below its size change only
|
|
1350
|
+
* under its file lock; capacity and the page entries above it change only under the global lock.
|
|
1351
|
+
* Each direct path holds the lock covering every field it touches, so it uses plain Int32 reads
|
|
1352
|
+
* and writes (aligned, never torn) ordered by the lock's acquiring and releasing atomics. Lock
|
|
1353
|
+
* words, the epoch and revocation stay atomic. */
|
|
1354
|
+
/** Client read of an open file from its cached slot: one file lock, one revocation check after
|
|
1355
|
+
* locking, then a coherent copy straight into the guest iovecs. Every size change holds the
|
|
1356
|
+
* same lock, so the copy is the file's content at one instant. */
|
|
1357
|
+
current<T>(
|
|
1358
|
+
nonblocking: boolean,
|
|
1359
|
+
revoked: (() => boolean) | undefined,
|
|
1360
|
+
owner: number,
|
|
1361
|
+
read: () => T,
|
|
1362
|
+
): T {
|
|
1363
|
+
if (!this.publication) return read();
|
|
1364
|
+
if ((this.serviceMutation && owner === SERVICE_OWNER) || this.currentOwner === owner) {
|
|
1365
|
+
this.publication?.assertLive();
|
|
1366
|
+
this.publication?.assertAccess();
|
|
1367
|
+
return read();
|
|
1368
|
+
}
|
|
1369
|
+
this.globalLock(revoked, owner, nonblocking);
|
|
1370
|
+
try {
|
|
1371
|
+
this.publication?.assertCurrent();
|
|
1372
|
+
return read();
|
|
1373
|
+
} finally {
|
|
1374
|
+
this.globalUnlock(owner);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
directRead(
|
|
1379
|
+
slot: number,
|
|
1380
|
+
handle: FileHandle,
|
|
1381
|
+
chunks: readonly Uint8Array[],
|
|
1382
|
+
offset: number,
|
|
1383
|
+
revoked: () => boolean,
|
|
1384
|
+
owner: number,
|
|
1385
|
+
nonblocking = false,
|
|
1386
|
+
): number {
|
|
1387
|
+
return this.current(nonblocking, revoked, owner, () =>
|
|
1388
|
+
this.directReadLocked(slot, handle, chunks, offset, revoked, owner, nonblocking),
|
|
1389
|
+
);
|
|
1390
|
+
}
|
|
1391
|
+
private directReadLocked(
|
|
1392
|
+
slot: number,
|
|
1393
|
+
handle: FileHandle,
|
|
1394
|
+
chunks: readonly Uint8Array[],
|
|
1395
|
+
offset: number,
|
|
1396
|
+
revoked: () => boolean,
|
|
1397
|
+
owner: number,
|
|
1398
|
+
nonblocking = false,
|
|
1399
|
+
): number {
|
|
1400
|
+
const slots = this.slots,
|
|
1401
|
+
base = slot * SLOT_WORDS,
|
|
1402
|
+
lock = base + FILE_LOCK;
|
|
1403
|
+
this.section?.enter();
|
|
1404
|
+
try {
|
|
1405
|
+
if (Atomics.compareExchange(slots, lock, 0, owner) !== 0) {
|
|
1406
|
+
if (nonblocking) throw new FilesystemError(6);
|
|
1407
|
+
this.contend(slots, lock, revoked, owner);
|
|
1408
|
+
}
|
|
1409
|
+
} catch (error) {
|
|
1410
|
+
this.section?.exit();
|
|
1411
|
+
throw error;
|
|
1412
|
+
}
|
|
1413
|
+
try {
|
|
1414
|
+
if (revoked()) throw new FilesystemError(11);
|
|
1415
|
+
if (slots[base + HANDLE] !== handle + 1) throw new FilesystemError(8);
|
|
1416
|
+
this.checkAccess(slot, 4);
|
|
1417
|
+
if (!(slots[base + REVISION_STATE]! & RESIDENT))
|
|
1418
|
+
throw new MissingDataError("shared filesystem file has not been loaded");
|
|
1419
|
+
let requested = 0;
|
|
1420
|
+
for (let i = 0; i < chunks.length; i++) requested += chunks[i]!.length;
|
|
1421
|
+
// Resolve every source page before the first destination byte changes: a range can start
|
|
1422
|
+
// in a segment this agent holds and end in one it lacks. Bytes at or past the end of the
|
|
1423
|
+
// file need no backing, so an empty read and a read at EOF never ask for a segment.
|
|
1424
|
+
const size = Math.min(slots[base + FILE_SIZE]!, offset + requested);
|
|
1425
|
+
if (size <= offset) return 0;
|
|
1426
|
+
const first = Math.floor(offset / DATA_PAGE_BYTES);
|
|
1427
|
+
const scratch = !this.readViewsBusy;
|
|
1428
|
+
const views = scratch ? this.readViews : [];
|
|
1429
|
+
this.sourcePages(slot, first, Math.ceil(size / DATA_PAGE_BYTES), views);
|
|
1430
|
+
if (scratch) this.readViewsBusy = true;
|
|
1431
|
+
try {
|
|
1432
|
+
return this.copyPages(views, first, chunks, offset, size);
|
|
1433
|
+
} finally {
|
|
1434
|
+
if (scratch) this.readViewsBusy = false;
|
|
1435
|
+
}
|
|
1436
|
+
} finally {
|
|
1437
|
+
Atomics.compareExchange(slots, lock, owner, 0);
|
|
1438
|
+
this.section?.exit();
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
/** Copies file bytes [offset, size) from resolved page views into the iovecs. */
|
|
1442
|
+
private copyPages(
|
|
1443
|
+
views: readonly Uint8Array[],
|
|
1444
|
+
first: number,
|
|
1445
|
+
chunks: readonly Uint8Array[],
|
|
1446
|
+
offset: number,
|
|
1447
|
+
size: number,
|
|
1448
|
+
): number {
|
|
1449
|
+
let position = offset;
|
|
1450
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
1451
|
+
const chunk = chunks[i]!,
|
|
1452
|
+
length = chunk.length;
|
|
1453
|
+
let at = 0;
|
|
1454
|
+
while (at < length && position < size) {
|
|
1455
|
+
const inPage = position % DATA_PAGE_BYTES;
|
|
1456
|
+
const count = Math.min(length - at, size - position, DATA_PAGE_BYTES - inPage);
|
|
1457
|
+
const page = views[(position - inPage) / DATA_PAGE_BYTES - first]!;
|
|
1458
|
+
copyBytes.call(
|
|
1459
|
+
chunk,
|
|
1460
|
+
count === DATA_PAGE_BYTES ? page : page.subarray(inPage, inPage + count),
|
|
1461
|
+
at,
|
|
1462
|
+
);
|
|
1463
|
+
at += count;
|
|
1464
|
+
position += count;
|
|
1465
|
+
}
|
|
1466
|
+
if (at < length) break;
|
|
1467
|
+
}
|
|
1468
|
+
return position - offset;
|
|
1469
|
+
}
|
|
1470
|
+
private readyGlobal(revoked: () => boolean, owner: number): boolean {
|
|
1471
|
+
try {
|
|
1472
|
+
this.globalLock(revoked, owner, true);
|
|
1473
|
+
return true;
|
|
1474
|
+
} catch (error) {
|
|
1475
|
+
if (error instanceof FilesystemError && error.errno === 6) return false;
|
|
1476
|
+
throw error;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
/** Probe without spinning or changing file data. True means ready, false means lock contention,
|
|
1480
|
+
* and undefined requests hydration. The same locks gate a successful retry. */
|
|
1481
|
+
directReadiness(
|
|
1482
|
+
slot: number,
|
|
1483
|
+
handle: FileHandle,
|
|
1484
|
+
writing: boolean,
|
|
1485
|
+
revoked: () => boolean,
|
|
1486
|
+
owner: number,
|
|
1487
|
+
): boolean | undefined {
|
|
1488
|
+
this.section?.enter();
|
|
1489
|
+
const lock = slot * SLOT_WORDS + FILE_LOCK;
|
|
1490
|
+
let global = false,
|
|
1491
|
+
file = false;
|
|
1492
|
+
try {
|
|
1493
|
+
if (revoked()) throw new FilesystemError(11);
|
|
1494
|
+
if (writing || this.publication) {
|
|
1495
|
+
global = this.readyGlobal(revoked, owner);
|
|
1496
|
+
if (!global) return false;
|
|
1497
|
+
}
|
|
1498
|
+
file = Atomics.compareExchange(this.slots, lock, 0, owner) === 0;
|
|
1499
|
+
if (!file) return false;
|
|
1500
|
+
if (this.slots[slot * SLOT_WORDS + HANDLE] !== handle + 1) throw new FilesystemError(8);
|
|
1501
|
+
return this.slots[slot * SLOT_WORDS + REVISION_STATE]! & RESIDENT ? true : undefined;
|
|
1502
|
+
} finally {
|
|
1503
|
+
if (file) Atomics.compareExchange(this.slots, lock, owner, 0);
|
|
1504
|
+
if (global) this.globalUnlock(owner);
|
|
1505
|
+
this.section?.exit();
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
private copyChunks(slot: number, chunks: readonly Uint8Array[], offset: number): void {
|
|
1509
|
+
const pages = this.pages;
|
|
1510
|
+
let position = offset;
|
|
1511
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
1512
|
+
const chunk = chunks[i]!,
|
|
1513
|
+
length = chunk.length;
|
|
1514
|
+
for (let at = 0; at < length;) {
|
|
1515
|
+
const inPage = position % DATA_PAGE_BYTES;
|
|
1516
|
+
const count = Math.min(length - at, DATA_PAGE_BYTES - inPage);
|
|
1517
|
+
const page = this.segmentFor(
|
|
1518
|
+
pages[this.pageAt(slot, (position - inPage) / DATA_PAGE_BYTES)]! - 1,
|
|
1519
|
+
);
|
|
1520
|
+
// A fixed-length source view never changes length; build sub-views without species lookup.
|
|
1521
|
+
page.set(
|
|
1522
|
+
count === length ? chunk : new Uint8Array(chunk.buffer, chunk.byteOffset + at, count),
|
|
1523
|
+
inPage,
|
|
1524
|
+
);
|
|
1525
|
+
at += count;
|
|
1526
|
+
position += count;
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
/** Client in-capacity write at offset, or append at EOF, under one global mutation (odd epoch)
|
|
1531
|
+
* and one file lock, with one revocation check once both are held. Returns the end offset, or
|
|
1532
|
+
* the negated size the service must grow to after both locks exit. Sources must be fixed-length
|
|
1533
|
+
* views; callers reject negative offsets. */
|
|
1534
|
+
private direct(
|
|
1535
|
+
slot: number,
|
|
1536
|
+
handle: FileHandle,
|
|
1537
|
+
chunks: readonly Uint8Array[],
|
|
1538
|
+
append: boolean,
|
|
1539
|
+
offset: number,
|
|
1540
|
+
total: number,
|
|
1541
|
+
epoch: Int32Array,
|
|
1542
|
+
revoked: () => boolean,
|
|
1543
|
+
owner: number,
|
|
1544
|
+
nonblocking = false,
|
|
1545
|
+
admission?: PublicationAdmission,
|
|
1546
|
+
): number {
|
|
1547
|
+
const slots = this.slots,
|
|
1548
|
+
base = slot * SLOT_WORDS,
|
|
1549
|
+
lock = base + FILE_LOCK;
|
|
1550
|
+
this.globalLock(revoked, owner, nonblocking, "data", "file");
|
|
1551
|
+
Atomics.add(epoch, 0, 1);
|
|
1552
|
+
try {
|
|
1553
|
+
if (Atomics.compareExchange(slots, lock, 0, owner) !== 0) {
|
|
1554
|
+
if (nonblocking) throw new FilesystemError(6);
|
|
1555
|
+
this.contend(slots, lock, revoked, owner);
|
|
1556
|
+
}
|
|
1557
|
+
try {
|
|
1558
|
+
if (revoked()) throw new FilesystemError(11);
|
|
1559
|
+
if (slots[base + HANDLE] !== handle + 1) throw new FilesystemError(8);
|
|
1560
|
+
this.checkAccess(slot, 2);
|
|
1561
|
+
const size = slots[base + FILE_SIZE]!;
|
|
1562
|
+
const at = append ? size : offset;
|
|
1563
|
+
this.publication?.assertCurrent();
|
|
1564
|
+
if (this.publication && !admission)
|
|
1565
|
+
throw new FilesystemError(28, "publication admission required");
|
|
1566
|
+
if (!total) {
|
|
1567
|
+
if (this.publication && admission) {
|
|
1568
|
+
this.publication.verifyAdmission(
|
|
1569
|
+
admission,
|
|
1570
|
+
append ? { kind: "append", handle } : { kind: "write", handle, offset },
|
|
1571
|
+
new Uint8Array(),
|
|
1572
|
+
);
|
|
1573
|
+
this.publication.commit(
|
|
1574
|
+
this.publication.prepare(
|
|
1575
|
+
admission,
|
|
1576
|
+
append ? { kind: "append", written: 0, offset: at } : { kind: "number", value: 0 },
|
|
1577
|
+
[],
|
|
1578
|
+
),
|
|
1579
|
+
);
|
|
1580
|
+
}
|
|
1581
|
+
return at;
|
|
1582
|
+
}
|
|
1583
|
+
const end = at + total;
|
|
1584
|
+
if (
|
|
1585
|
+
!(slots[base + REVISION_STATE]! & RESIDENT) ||
|
|
1586
|
+
end > slots[base + CAPACITY]! * DATA_PAGE_BYTES
|
|
1587
|
+
)
|
|
1588
|
+
return -Math.max(1, end);
|
|
1589
|
+
// Resolve every target page, and every page a reader-pinned target would be copied to,
|
|
1590
|
+
// before dirty admission, identity or publication preparation and the first byte. A
|
|
1591
|
+
// miss then means nothing happened, and the caller takes the write to the owner.
|
|
1592
|
+
const first = Math.floor(at / DATA_PAGE_BYTES),
|
|
1593
|
+
last = Math.ceil(end / DATA_PAGE_BYTES);
|
|
1594
|
+
this.requireBacking(slot, first, last);
|
|
1595
|
+
this.requireCopyBacking(slot, first, last);
|
|
1596
|
+
this.checkDirty(slot, Math.max(size, end));
|
|
1597
|
+
const mtime = Date.now();
|
|
1598
|
+
const identity = this.prepareIdentityVersion(slot, true);
|
|
1599
|
+
const prepared = this.prepareDirectPublication(
|
|
1600
|
+
slot,
|
|
1601
|
+
chunks,
|
|
1602
|
+
append,
|
|
1603
|
+
at,
|
|
1604
|
+
end,
|
|
1605
|
+
size,
|
|
1606
|
+
mtime,
|
|
1607
|
+
identity,
|
|
1608
|
+
admission,
|
|
1609
|
+
);
|
|
1610
|
+
this.prepareVersionPages(slot, at, end, Math.max(size, end));
|
|
1611
|
+
this.dirty(slot, Math.max(size, end));
|
|
1612
|
+
this.commitDirectBytes(
|
|
1613
|
+
slot,
|
|
1614
|
+
prepared ? [prepared.bytes] : chunks,
|
|
1615
|
+
at,
|
|
1616
|
+
end,
|
|
1617
|
+
size,
|
|
1618
|
+
mtime,
|
|
1619
|
+
prepared?.publication,
|
|
1620
|
+
identity,
|
|
1621
|
+
);
|
|
1622
|
+
return end;
|
|
1623
|
+
} finally {
|
|
1624
|
+
Atomics.compareExchange(slots, lock, owner, 0);
|
|
1625
|
+
}
|
|
1626
|
+
} finally {
|
|
1627
|
+
Atomics.add(epoch, 0, 1);
|
|
1628
|
+
this.globalUnlock(owner);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
private commitDirectBytes(
|
|
1632
|
+
slot: number,
|
|
1633
|
+
chunks: readonly Uint8Array[],
|
|
1634
|
+
at: number,
|
|
1635
|
+
end: number,
|
|
1636
|
+
size: number,
|
|
1637
|
+
mtime: number,
|
|
1638
|
+
publication?: PreparedPublication,
|
|
1639
|
+
identity?: PlannedIdentityRevision,
|
|
1640
|
+
): void {
|
|
1641
|
+
const base = slot * SLOT_WORDS;
|
|
1642
|
+
try {
|
|
1643
|
+
this.copyChunks(slot, chunks, at);
|
|
1644
|
+
if (end > size) this.slots[base + FILE_SIZE] = end;
|
|
1645
|
+
this.setModified(slot, msFileTime(mtime));
|
|
1646
|
+
this.changed(slot);
|
|
1647
|
+
this.commitIdentityVersion(slot, identity);
|
|
1648
|
+
if (publication) this.publication!.commit(publication);
|
|
1649
|
+
} catch (error) {
|
|
1650
|
+
// Once a byte may have changed, failure is unknown, never a no-effect retry.
|
|
1651
|
+
this.publication?.stop();
|
|
1652
|
+
throw error;
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
private prepareDirectPublication(
|
|
1656
|
+
slot: number,
|
|
1657
|
+
chunks: readonly Uint8Array[],
|
|
1658
|
+
append: boolean,
|
|
1659
|
+
at: number,
|
|
1660
|
+
end: number,
|
|
1661
|
+
oldSize: number,
|
|
1662
|
+
mtime: number,
|
|
1663
|
+
identity: PlannedIdentityRevision | undefined,
|
|
1664
|
+
admission?: PublicationAdmission,
|
|
1665
|
+
): { publication: PreparedPublication; bytes: Uint8Array } | undefined {
|
|
1666
|
+
const domain = this.publication;
|
|
1667
|
+
if (!domain) return;
|
|
1668
|
+
if (!admission) throw new FilesystemError(28, "publication admission required");
|
|
1669
|
+
if (end - at > domain.limits.inputBytes)
|
|
1670
|
+
throw new FilesystemError(6, "publication input bound exceeded");
|
|
1671
|
+
const bytes = new Uint8Array(end - at);
|
|
1672
|
+
let offset = 0;
|
|
1673
|
+
for (const chunk of chunks) {
|
|
1674
|
+
typedArraySet(bytes, chunk, offset);
|
|
1675
|
+
offset += chunk.length;
|
|
1676
|
+
}
|
|
1677
|
+
domain.verifyAdmission(
|
|
1678
|
+
admission,
|
|
1679
|
+
append
|
|
1680
|
+
? { kind: "append", handle: this.slots[slot * SLOT_WORDS + HANDLE]! - 1 }
|
|
1681
|
+
: { kind: "write", handle: this.slots[slot * SLOT_WORDS + HANDLE]! - 1, offset: at },
|
|
1682
|
+
bytes,
|
|
1683
|
+
);
|
|
1684
|
+
const file = this.publicationFile(slot, identity);
|
|
1685
|
+
const publication = domain.prepare(
|
|
1686
|
+
admission,
|
|
1687
|
+
append
|
|
1688
|
+
? { kind: "append", written: bytes.length, offset: end }
|
|
1689
|
+
: { kind: "number", value: bytes.length },
|
|
1690
|
+
[
|
|
1691
|
+
{
|
|
1692
|
+
kind: "bytes",
|
|
1693
|
+
file,
|
|
1694
|
+
offset: at,
|
|
1695
|
+
bytes,
|
|
1696
|
+
size: Math.max(oldSize, end),
|
|
1697
|
+
version: domain.nextContentVersion(file.ino),
|
|
1698
|
+
},
|
|
1699
|
+
{ kind: "metadata", file, mode: this.slots[slot * SLOT_WORDS + MODE]!, mtime },
|
|
1700
|
+
],
|
|
1701
|
+
);
|
|
1702
|
+
return { publication, bytes };
|
|
1703
|
+
}
|
|
1704
|
+
directWrite(
|
|
1705
|
+
slot: number,
|
|
1706
|
+
handle: FileHandle,
|
|
1707
|
+
chunks: readonly Uint8Array[],
|
|
1708
|
+
offset: number,
|
|
1709
|
+
total: number,
|
|
1710
|
+
epoch: Int32Array,
|
|
1711
|
+
revoked: () => boolean,
|
|
1712
|
+
owner: number,
|
|
1713
|
+
nonblocking = false,
|
|
1714
|
+
admission?: PublicationAdmission,
|
|
1715
|
+
): number | undefined {
|
|
1716
|
+
return this.direct(
|
|
1717
|
+
slot,
|
|
1718
|
+
handle,
|
|
1719
|
+
chunks,
|
|
1720
|
+
false,
|
|
1721
|
+
offset,
|
|
1722
|
+
total,
|
|
1723
|
+
epoch,
|
|
1724
|
+
revoked,
|
|
1725
|
+
owner,
|
|
1726
|
+
nonblocking,
|
|
1727
|
+
admission,
|
|
1728
|
+
) < 0
|
|
1729
|
+
? undefined
|
|
1730
|
+
: total;
|
|
1731
|
+
}
|
|
1732
|
+
directAppend(
|
|
1733
|
+
slot: number,
|
|
1734
|
+
handle: FileHandle,
|
|
1735
|
+
chunks: readonly Uint8Array[],
|
|
1736
|
+
total: number,
|
|
1737
|
+
epoch: Int32Array,
|
|
1738
|
+
revoked: () => boolean,
|
|
1739
|
+
owner: number,
|
|
1740
|
+
nonblocking = false,
|
|
1741
|
+
admission?: PublicationAdmission,
|
|
1742
|
+
): { written: number; offset: number } | number {
|
|
1743
|
+
const end = this.direct(
|
|
1744
|
+
slot,
|
|
1745
|
+
handle,
|
|
1746
|
+
chunks,
|
|
1747
|
+
true,
|
|
1748
|
+
0,
|
|
1749
|
+
total,
|
|
1750
|
+
epoch,
|
|
1751
|
+
revoked,
|
|
1752
|
+
owner,
|
|
1753
|
+
nonblocking,
|
|
1754
|
+
admission,
|
|
1755
|
+
);
|
|
1756
|
+
return end < 0 ? -end : { written: total, offset: end };
|
|
1757
|
+
}
|
|
1758
|
+
/** Client commit of a write the owner has staged, for target pages in a segment this agent
|
|
1759
|
+
* lacks. It runs under the same nonblocking locks, odd epoch and data section as a direct
|
|
1760
|
+
* write and touches only attached metadata: the commit point hands the stage to the owner by
|
|
1761
|
+
* exchanging its state from Complete to Committed, then clears the file's resident bit. That
|
|
1762
|
+
* bit already sends every direct read, write and readiness probe to the owner, and the owner
|
|
1763
|
+
* copies the staged bytes into the file's existing pages before it serves anything. So the
|
|
1764
|
+
* write is visible from the call that returns its count, needs no free page, and does not
|
|
1765
|
+
* depend on what the file held when it was staged.
|
|
1766
|
+
*
|
|
1767
|
+
* Returns the end offset, or undefined when nothing was committed and the stage has to be
|
|
1768
|
+
* prepared again: the owner withdrew it, the file is not resident (another agent's commit is
|
|
1769
|
+
* waiting for the owner, or the file is not loaded), the end no longer fits the capacity, or
|
|
1770
|
+
* a target page became reader-pinned. Lock contention throws errno 6 and keeps the stage. */
|
|
1771
|
+
commitStagedWrite(
|
|
1772
|
+
slot: number,
|
|
1773
|
+
handle: FileHandle,
|
|
1774
|
+
cells: Int32Array,
|
|
1775
|
+
bytes: Uint8Array,
|
|
1776
|
+
append: boolean,
|
|
1777
|
+
offset: number,
|
|
1778
|
+
epoch: Int32Array,
|
|
1779
|
+
revoked: () => boolean,
|
|
1780
|
+
owner: number,
|
|
1781
|
+
admission?: PublicationAdmission,
|
|
1782
|
+
): number | undefined {
|
|
1783
|
+
const slots = this.slots,
|
|
1784
|
+
base = slot * SLOT_WORDS,
|
|
1785
|
+
lock = base + FILE_LOCK;
|
|
1786
|
+
this.globalLock(revoked, owner, true, "data", "file");
|
|
1787
|
+
Atomics.add(epoch, 0, 1);
|
|
1788
|
+
try {
|
|
1789
|
+
if (Atomics.compareExchange(slots, lock, 0, owner) !== 0) throw new FilesystemError(6);
|
|
1790
|
+
try {
|
|
1791
|
+
if (revoked()) throw new FilesystemError(11);
|
|
1792
|
+
if (slots[base + HANDLE] !== handle + 1) throw new FilesystemError(8);
|
|
1793
|
+
this.checkAccess(slot, 2);
|
|
1794
|
+
this.publication?.assertCurrent();
|
|
1795
|
+
if (this.publication && !admission)
|
|
1796
|
+
throw new FilesystemError(28, "publication admission required");
|
|
1797
|
+
if (Atomics.load(cells, STAGE_STATE) !== State.Complete) return undefined;
|
|
1798
|
+
const size = slots[base + FILE_SIZE]!;
|
|
1799
|
+
const at = append ? size : offset;
|
|
1800
|
+
const end = at + bytes.length;
|
|
1801
|
+
if (
|
|
1802
|
+
!(slots[base + REVISION_STATE]! & RESIDENT) ||
|
|
1803
|
+
end > slots[base + CAPACITY]! * DATA_PAGE_BYTES
|
|
1804
|
+
)
|
|
1805
|
+
return undefined;
|
|
1806
|
+
const first = Math.floor(at / DATA_PAGE_BYTES),
|
|
1807
|
+
last = Math.ceil(end / DATA_PAGE_BYTES);
|
|
1808
|
+
// The owner applies in place, so a pinned page has to be relocated by a new stage.
|
|
1809
|
+
if (this.hasPinnedPage(slot, first, last)) return undefined;
|
|
1810
|
+
this.checkDirty(slot, Math.max(size, end));
|
|
1811
|
+
const mtime = Date.now();
|
|
1812
|
+
const identity = this.prepareIdentityVersion(slot, true);
|
|
1813
|
+
const prepared = this.prepareDirectPublication(
|
|
1814
|
+
slot,
|
|
1815
|
+
[bytes],
|
|
1816
|
+
append,
|
|
1817
|
+
at,
|
|
1818
|
+
end,
|
|
1819
|
+
size,
|
|
1820
|
+
mtime,
|
|
1821
|
+
identity,
|
|
1822
|
+
admission,
|
|
1823
|
+
);
|
|
1824
|
+
this.dirty(slot, Math.max(size, end));
|
|
1825
|
+
// Commit point. The owner's withdrawal is the opposing exchange from the same value,
|
|
1826
|
+
// so exactly one of them wins and a lost race here has changed no file state.
|
|
1827
|
+
Atomics.store(cells, STAGE_POSITION, at);
|
|
1828
|
+
if (
|
|
1829
|
+
Atomics.compareExchange(cells, STAGE_STATE, State.Complete, State.Committed) !==
|
|
1830
|
+
State.Complete
|
|
1831
|
+
)
|
|
1832
|
+
return undefined;
|
|
1833
|
+
try {
|
|
1834
|
+
// The revision moves before the gate closes. If this agent dies between the two, the
|
|
1835
|
+
// owner finds a committed stage on a resident file and finishes the write itself; at
|
|
1836
|
+
// every later point the revision has already moved. Applied bytes are never left
|
|
1837
|
+
// under an old revision.
|
|
1838
|
+
this.changed(slot);
|
|
1839
|
+
slots[base + REVISION_STATE] = slots[base + REVISION_STATE]! & ~RESIDENT;
|
|
1840
|
+
if (end > size) slots[base + FILE_SIZE] = end;
|
|
1841
|
+
this.setModified(slot, msFileTime(mtime));
|
|
1842
|
+
this.commitIdentityVersion(slot, identity);
|
|
1843
|
+
if (prepared) this.publication!.commit(prepared.publication);
|
|
1844
|
+
} catch (error) {
|
|
1845
|
+
// The write is committed; a failure after that point is unknown, never a retry.
|
|
1846
|
+
this.publication?.stop();
|
|
1847
|
+
throw error;
|
|
1848
|
+
}
|
|
1849
|
+
return end;
|
|
1850
|
+
} finally {
|
|
1851
|
+
Atomics.compareExchange(slots, lock, owner, 0);
|
|
1852
|
+
}
|
|
1853
|
+
} finally {
|
|
1854
|
+
Atomics.add(epoch, 0, 1);
|
|
1855
|
+
this.globalUnlock(owner);
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
/** Owner only. Records a write for a client that cannot reach the target pages itself, and
|
|
1859
|
+
* leaves the file so that client can commit without the owner: capacity covers the end and,
|
|
1860
|
+
* with page retention on, no target page is reader-pinned. The file's bytes, size, timestamp
|
|
1861
|
+
* and revision do not change, and the staged bytes take no filesystem page: they stay in this
|
|
1862
|
+
* private record until that client commits and the owner applies them. */
|
|
1863
|
+
stageWrite(
|
|
1864
|
+
handle: FileHandle,
|
|
1865
|
+
offset: number,
|
|
1866
|
+
append: boolean,
|
|
1867
|
+
bytes: Uint8Array,
|
|
1868
|
+
cells: Int32Array,
|
|
1869
|
+
): StagedWrite {
|
|
1870
|
+
if (this.lockOwner !== SERVICE_OWNER)
|
|
1871
|
+
throw new FilesystemError(58, "only the filesystem owner stages writes");
|
|
1872
|
+
if (!Number.isSafeInteger(offset) || offset < 0 || !bytes.length) throw new FilesystemError(28);
|
|
1873
|
+
this.globalLock();
|
|
1874
|
+
try {
|
|
1875
|
+
const slot = this.slot(handle);
|
|
1876
|
+
this.checkFile(slot, handle);
|
|
1877
|
+
this.checkAccess(slot, 2);
|
|
1878
|
+
const at = append ? this.slots[this.at(slot, FILE_SIZE)]! : offset;
|
|
1879
|
+
const end = at + bytes.length;
|
|
1880
|
+
this.growLocked(handle, end);
|
|
1881
|
+
this.prepareVersionWrite(handle, at, bytes.length, end).commit();
|
|
1882
|
+
const stage: StagedWrite = { slot, handle, cells, bytes };
|
|
1883
|
+
const stages = this.staged.get(slot);
|
|
1884
|
+
if (stages) stages.push(stage);
|
|
1885
|
+
else this.staged.set(slot, [stage]);
|
|
1886
|
+
return stage;
|
|
1887
|
+
} finally {
|
|
1888
|
+
this.globalUnlock();
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
/** Owner only. Ends one staged write, exactly once: applies it when its client committed it,
|
|
1892
|
+
* and otherwise withdraws it so that no later commit can succeed. The record remembers that it
|
|
1893
|
+
* settled, so a repeated or late call does nothing: it cannot replay bytes over newer content,
|
|
1894
|
+
* lift the gate of a newer stage on the same file, or read a request block that was reused. */
|
|
1895
|
+
settleStagedWrite(stage: StagedWrite): void {
|
|
1896
|
+
if (!stage.bytes) return;
|
|
1897
|
+
const lock = this.at(stage.slot, FILE_LOCK);
|
|
1898
|
+
// Taking the file lock applies every committed stage of this file, this one included.
|
|
1899
|
+
this.lock(lock, undefined, this.lockOwner, "release");
|
|
1900
|
+
try {
|
|
1901
|
+
if (!stage.bytes) return;
|
|
1902
|
+
this.forgetStaged(stage);
|
|
1903
|
+
Atomics.compareExchange(stage.cells, STAGE_STATE, State.Complete, State.Cancelled);
|
|
1904
|
+
// No commit can be in flight under this file lock, except from an agent that was reaped
|
|
1905
|
+
// while it was still running. Its exchange is then the one that won.
|
|
1906
|
+
if (Atomics.load(stage.cells, STAGE_STATE) === State.Committed) this.applyStaged(stage);
|
|
1907
|
+
else stage.bytes = undefined;
|
|
1908
|
+
} finally {
|
|
1909
|
+
this.unlock(lock);
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
private forgetStaged(stage: StagedWrite): void {
|
|
1913
|
+
const stages = this.staged.get(stage.slot);
|
|
1914
|
+
const index = stages ? stages.indexOf(stage) : -1;
|
|
1915
|
+
if (index < 0) return;
|
|
1916
|
+
stages!.splice(index, 1);
|
|
1917
|
+
if (!stages!.length) this.staged.delete(stage.slot);
|
|
1918
|
+
}
|
|
1919
|
+
/** For owner paths that read or reshape a file's pages without taking its file lock. Taking
|
|
1920
|
+
* the lock is what applies the file's committed stages. */
|
|
1921
|
+
private settleUnderLock(slot: number): void {
|
|
1922
|
+
if (!this.staged.size) return;
|
|
1923
|
+
this.lock(this.at(slot, FILE_LOCK), undefined, this.lockOwner, "release");
|
|
1924
|
+
this.unlock(this.at(slot, FILE_LOCK));
|
|
1925
|
+
}
|
|
1926
|
+
/** Owner only, with this slot's file lock held. Commit needs that lock too, so each stage
|
|
1927
|
+
* here is either wholly committed or not committed at all. */
|
|
1928
|
+
private settleStaged(slot: number): void {
|
|
1929
|
+
const stages = this.staged.get(slot);
|
|
1930
|
+
if (!stages) return;
|
|
1931
|
+
const committed = stages.filter(
|
|
1932
|
+
(stage) => Atomics.load(stage.cells, STAGE_STATE) === State.Committed,
|
|
1933
|
+
);
|
|
1934
|
+
for (const stage of committed) {
|
|
1935
|
+
this.forgetStaged(stage);
|
|
1936
|
+
this.applyStaged(stage);
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
/** Copies a committed stage into the file's own pages and makes the file resident again. The
|
|
1940
|
+
* committing client already published the size, timestamp and revision. One that died right
|
|
1941
|
+
* after its commit point changed none of them, so the owner finishes that write here. */
|
|
1942
|
+
private applyStaged(stage: StagedWrite): void {
|
|
1943
|
+
const bytes = stage.bytes;
|
|
1944
|
+
stage.bytes = undefined;
|
|
1945
|
+
if (!bytes) return;
|
|
1946
|
+
const slots = this.slots,
|
|
1947
|
+
base = stage.slot * SLOT_WORDS;
|
|
1948
|
+
// A handle never names another file, and a freed slot holds no pages to write into.
|
|
1949
|
+
if (slots[base + HANDLE] !== stage.handle + 1 || slots[base] !== 1) return;
|
|
1950
|
+
const at = Atomics.load(stage.cells, STAGE_POSITION);
|
|
1951
|
+
const end = at + bytes.length;
|
|
1952
|
+
if (!slots[base + CAPACITY]) return;
|
|
1953
|
+
if (at >= 0 && end <= slots[base + CAPACITY]! * DATA_PAGE_BYTES) {
|
|
1954
|
+
this.copyInto(stage.slot, bytes, at);
|
|
1955
|
+
if (slots[base + FILE_SIZE]! < end) slots[base + FILE_SIZE] = end;
|
|
1956
|
+
if (slots[base + REVISION_STATE]! & RESIDENT) this.changed(stage.slot);
|
|
1957
|
+
}
|
|
1958
|
+
slots[base + REVISION_STATE] = slots[base + REVISION_STATE]! | RESIDENT;
|
|
1959
|
+
}
|
|
1960
|
+
/** Caller owns the global mutation lock. Undefined asks for service growth after unlock. */
|
|
1961
|
+
tryWrite(
|
|
1962
|
+
handle: FileHandle,
|
|
1963
|
+
chunks: readonly Uint8Array[],
|
|
1964
|
+
offset: number,
|
|
1965
|
+
total: number,
|
|
1966
|
+
revoked?: () => boolean,
|
|
1967
|
+
owner = this.lockOwner,
|
|
1968
|
+
): number | undefined {
|
|
1969
|
+
const slot = this.slot(handle);
|
|
1970
|
+
if (Atomics.load(this.slots, this.at(slot, 0)) !== 1) throw new FilesystemError(31);
|
|
1971
|
+
if (!total) return 0;
|
|
1972
|
+
this.lock(this.at(slot, FILE_LOCK), revoked, owner);
|
|
1973
|
+
try {
|
|
1974
|
+
if (revoked?.()) throw new FilesystemError(11);
|
|
1975
|
+
this.checkFile(slot, handle);
|
|
1976
|
+
this.checkAccess(slot, 2);
|
|
1977
|
+
const end = offset + total;
|
|
1978
|
+
if (
|
|
1979
|
+
!(this.slots[this.at(slot, REVISION_STATE)]! & RESIDENT) ||
|
|
1980
|
+
end > Atomics.load(this.slots, this.at(slot, CAPACITY)) * DATA_PAGE_BYTES
|
|
1981
|
+
)
|
|
1982
|
+
return undefined;
|
|
1983
|
+
const identity = this.prepareIdentityVersion(slot, true);
|
|
1984
|
+
this.prepareVersionPages(
|
|
1985
|
+
slot,
|
|
1986
|
+
offset,
|
|
1987
|
+
end,
|
|
1988
|
+
Math.max(this.slots[this.at(slot, FILE_SIZE)]!, end),
|
|
1989
|
+
);
|
|
1990
|
+
this.dirty(slot, Math.max(this.slots[this.at(slot, FILE_SIZE)]!, end));
|
|
1991
|
+
let at = offset;
|
|
1992
|
+
for (const chunk of chunks) {
|
|
1993
|
+
this.copyInto(slot, chunk, at);
|
|
1994
|
+
at += chunk.length;
|
|
1995
|
+
}
|
|
1996
|
+
if (end > Atomics.load(this.slots, this.at(slot, FILE_SIZE)))
|
|
1997
|
+
Atomics.store(this.slots, this.at(slot, FILE_SIZE), end);
|
|
1998
|
+
this.setModified(slot, fileTimeNow());
|
|
1999
|
+
this.changed(slot);
|
|
2000
|
+
this.commitIdentityVersion(slot, identity);
|
|
2001
|
+
return total;
|
|
2002
|
+
} finally {
|
|
2003
|
+
this.unlock(this.at(slot, FILE_LOCK), owner);
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
write(
|
|
2007
|
+
handle: FileHandle,
|
|
2008
|
+
chunks: readonly Uint8Array[],
|
|
2009
|
+
offset: number,
|
|
2010
|
+
revoked?: () => boolean,
|
|
2011
|
+
owner = this.lockOwner,
|
|
2012
|
+
): number {
|
|
2013
|
+
chunks = fixedWriteSources(chunks);
|
|
2014
|
+
const total = chunks.reduce((size, chunk) => size + chunk.length, 0);
|
|
2015
|
+
const written = this.tryWrite(handle, chunks, offset, total, revoked, owner);
|
|
2016
|
+
if (written === undefined) throw new RangeError("file needs growth");
|
|
2017
|
+
return written;
|
|
2018
|
+
}
|
|
2019
|
+
/** Caller owns the global mutation lock. A number asks for service growth after unlock. */
|
|
2020
|
+
tryAppend(
|
|
2021
|
+
handle: FileHandle,
|
|
2022
|
+
chunks: readonly Uint8Array[],
|
|
2023
|
+
total: number,
|
|
2024
|
+
revoked?: () => boolean,
|
|
2025
|
+
owner = this.lockOwner,
|
|
2026
|
+
): { written: number; offset: number } | number {
|
|
2027
|
+
const slot = this.slot(handle);
|
|
2028
|
+
if (Atomics.load(this.slots, this.at(slot, 0)) !== 1) throw new FilesystemError(31);
|
|
2029
|
+
this.lock(this.at(slot, FILE_LOCK), revoked, owner);
|
|
2030
|
+
try {
|
|
2031
|
+
this.checkFile(slot, handle);
|
|
2032
|
+
this.checkAccess(slot, 2);
|
|
2033
|
+
const offset = Atomics.load(this.slots, this.at(slot, FILE_SIZE));
|
|
2034
|
+
if (!total) return { written: 0, offset };
|
|
2035
|
+
if (
|
|
2036
|
+
!(this.slots[this.at(slot, REVISION_STATE)]! & RESIDENT) ||
|
|
2037
|
+
offset + total > Atomics.load(this.slots, this.at(slot, CAPACITY)) * DATA_PAGE_BYTES
|
|
2038
|
+
)
|
|
2039
|
+
return offset + total;
|
|
2040
|
+
const identity = this.prepareIdentityVersion(slot, true);
|
|
2041
|
+
this.prepareVersionPages(slot, offset, offset + total, offset + total);
|
|
2042
|
+
this.dirty(slot, offset + total);
|
|
2043
|
+
let at = offset;
|
|
2044
|
+
for (const chunk of chunks) {
|
|
2045
|
+
this.copyInto(slot, chunk, at);
|
|
2046
|
+
at += chunk.length;
|
|
2047
|
+
}
|
|
2048
|
+
Atomics.store(this.slots, this.at(slot, FILE_SIZE), at);
|
|
2049
|
+
this.setModified(slot, fileTimeNow());
|
|
2050
|
+
this.changed(slot);
|
|
2051
|
+
this.commitIdentityVersion(slot, identity);
|
|
2052
|
+
return { written: total, offset: at };
|
|
2053
|
+
} finally {
|
|
2054
|
+
this.unlock(this.at(slot, FILE_LOCK), owner);
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
append(
|
|
2058
|
+
handle: FileHandle,
|
|
2059
|
+
chunks: readonly Uint8Array[],
|
|
2060
|
+
revoked?: () => boolean,
|
|
2061
|
+
owner = this.lockOwner,
|
|
2062
|
+
): { written: number; offset: number } {
|
|
2063
|
+
chunks = fixedWriteSources(chunks);
|
|
2064
|
+
const total = chunks.reduce((size, chunk) => size + chunk.length, 0);
|
|
2065
|
+
const result = this.tryAppend(handle, chunks, total, revoked, owner);
|
|
2066
|
+
if (typeof result === "number") throw new RangeError("file needs growth");
|
|
2067
|
+
return result;
|
|
2068
|
+
}
|
|
2069
|
+
growLocked(handle: FileHandle, size: number): void {
|
|
2070
|
+
const slot = this.slot(handle);
|
|
2071
|
+
// A client waiting on a file whose staged write is committed asks for growth to become
|
|
2072
|
+
// ready, so that write is applied here.
|
|
2073
|
+
this.settleUnderLock(slot);
|
|
2074
|
+
const needed = Math.ceil(size / DATA_PAGE_BYTES);
|
|
2075
|
+
const capacity = this.slots[this.at(slot, CAPACITY)]!;
|
|
2076
|
+
this.checkDirty(
|
|
2077
|
+
slot,
|
|
2078
|
+
size,
|
|
2079
|
+
this.residentBytes() + Math.max(0, needed - capacity) * DATA_PAGE_BYTES,
|
|
2080
|
+
);
|
|
2081
|
+
this.allocate(slot, needed);
|
|
2082
|
+
}
|
|
2083
|
+
grow(handle: FileHandle, size: number): void {
|
|
2084
|
+
this.globalLock();
|
|
2085
|
+
try {
|
|
2086
|
+
this.growLocked(handle, size);
|
|
2087
|
+
} finally {
|
|
2088
|
+
this.globalUnlock();
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
resize(
|
|
2092
|
+
handle: FileHandle,
|
|
2093
|
+
size: number,
|
|
2094
|
+
truncate: boolean,
|
|
2095
|
+
revoked?: () => boolean,
|
|
2096
|
+
owner = this.lockOwner,
|
|
2097
|
+
admission?: PublicationAdmission,
|
|
2098
|
+
): number {
|
|
2099
|
+
const slot = this.slot(handle);
|
|
2100
|
+
this.lock(this.at(slot, FILE_LOCK), revoked, owner);
|
|
2101
|
+
try {
|
|
2102
|
+
this.checkFile(slot, handle);
|
|
2103
|
+
this.checkAccess(slot, 2);
|
|
2104
|
+
const old = Atomics.load(this.slots, this.at(slot, FILE_SIZE));
|
|
2105
|
+
const resident = (this.slots[this.at(slot, REVISION_STATE)]! & RESIDENT) !== 0;
|
|
2106
|
+
const capacity = Atomics.load(this.slots, this.at(slot, CAPACITY));
|
|
2107
|
+
// A file that is not resident but still maps pages can be waiting for the owner to apply
|
|
2108
|
+
// a committed staged write. Only the owner may replace it, after that apply.
|
|
2109
|
+
if (!resident && (!(truncate && size === 0) || (capacity && owner !== SERVICE_OWNER)))
|
|
2110
|
+
throw new MissingDataError("shared filesystem file has not been loaded");
|
|
2111
|
+
if (size > capacity * DATA_PAGE_BYTES) throw new RangeError("file needs growth");
|
|
2112
|
+
// Truncation zeroes the removed range and copies a reader-pinned boundary page. Resolve
|
|
2113
|
+
// both before dirty admission, identity or publication preparation.
|
|
2114
|
+
if (resident && truncate && size < old) {
|
|
2115
|
+
const first = Math.floor(size / DATA_PAGE_BYTES);
|
|
2116
|
+
this.requireBacking(slot, first, Math.ceil(old / DATA_PAGE_BYTES));
|
|
2117
|
+
this.requireCopyBacking(
|
|
2118
|
+
slot,
|
|
2119
|
+
first,
|
|
2120
|
+
Math.ceil(truncateBoundaryEnd(size, old) / DATA_PAGE_BYTES),
|
|
2121
|
+
);
|
|
2122
|
+
}
|
|
2123
|
+
const next = truncate ? size : Math.max(old, size);
|
|
2124
|
+
const time = truncate ? fileTimeNow() : this.time(slot, MTIME);
|
|
2125
|
+
const identity = this.prepareIdentityVersion(
|
|
2126
|
+
slot,
|
|
2127
|
+
next !== old || time !== this.time(slot, MTIME),
|
|
2128
|
+
);
|
|
2129
|
+
if (truncate || next !== old) this.checkDirty(slot, next);
|
|
2130
|
+
const publication = admission
|
|
2131
|
+
? this.prepareResize(slot, handle, size, truncate, next, time, identity, admission)
|
|
2132
|
+
: undefined;
|
|
2133
|
+
if (resident && truncate && size < old)
|
|
2134
|
+
this.prepareVersionPages(slot, size, truncateBoundaryEnd(size, old), next);
|
|
2135
|
+
if (truncate || next !== old) this.dirty(slot, next);
|
|
2136
|
+
if (resident && truncate && size < old) this.zeroTruncatedPages(slot, size, old);
|
|
2137
|
+
Atomics.store(this.slots, this.at(slot, FILE_SIZE), next);
|
|
2138
|
+
this.slots[this.at(slot, REVISION_STATE)]! |= RESIDENT;
|
|
2139
|
+
if (truncate) this.setModified(slot, time);
|
|
2140
|
+
if (truncate || next !== old) this.changed(slot);
|
|
2141
|
+
this.commitIdentityVersion(slot, identity);
|
|
2142
|
+
if (publication) this.publication!.commit(publication);
|
|
2143
|
+
return 0;
|
|
2144
|
+
} finally {
|
|
2145
|
+
this.unlock(this.at(slot, FILE_LOCK), owner);
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
private zeroTruncatedPages(slot: number, size: number, old: number): void {
|
|
2149
|
+
let position = size;
|
|
2150
|
+
while (position < old) {
|
|
2151
|
+
const page =
|
|
2152
|
+
Atomics.load(this.pages, this.pageAt(slot, Math.floor(position / DATA_PAGE_BYTES))) - 1;
|
|
2153
|
+
const count = Math.min(old - position, DATA_PAGE_BYTES - (position % DATA_PAGE_BYTES));
|
|
2154
|
+
// Whole pinned pages leave the live mapping in reclaimLocked, unchanged for readers.
|
|
2155
|
+
if (position % DATA_PAGE_BYTES || !this.pageReaders?.[page])
|
|
2156
|
+
this.segmentFor(page).fill(
|
|
2157
|
+
0,
|
|
2158
|
+
position % DATA_PAGE_BYTES,
|
|
2159
|
+
(position % DATA_PAGE_BYTES) + count,
|
|
2160
|
+
);
|
|
2161
|
+
position += count;
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
private prepareResize(
|
|
2165
|
+
slot: number,
|
|
2166
|
+
handle: FileHandle,
|
|
2167
|
+
size: number,
|
|
2168
|
+
truncate: boolean,
|
|
2169
|
+
next: number,
|
|
2170
|
+
time: FileTime,
|
|
2171
|
+
identity: PlannedIdentityRevision | undefined,
|
|
2172
|
+
admission: PublicationAdmission,
|
|
2173
|
+
): PreparedPublication {
|
|
2174
|
+
const domain = this.publication!;
|
|
2175
|
+
domain.verifyAdmission(admission, { kind: "resize", handle, size, truncate }, new Uint8Array());
|
|
2176
|
+
const file = this.publicationFile(slot, identity);
|
|
2177
|
+
const changes: import("./publication.js").PublicationEffect[] = [];
|
|
2178
|
+
if (next !== this.slots[this.at(slot, FILE_SIZE)])
|
|
2179
|
+
changes.push({
|
|
2180
|
+
kind: "resize",
|
|
2181
|
+
file,
|
|
2182
|
+
size: next,
|
|
2183
|
+
version: domain.nextContentVersion(file.ino),
|
|
2184
|
+
});
|
|
2185
|
+
this.pushMtimeEffect(changes, slot, file, time);
|
|
2186
|
+
return domain.prepare(admission, { kind: "number", value: 0 }, changes);
|
|
2187
|
+
}
|
|
2188
|
+
/** The workspace sees whole-millisecond mtimes; a change below that, or of atime alone,
|
|
2189
|
+
* is not a workspace effect. */
|
|
2190
|
+
private pushMtimeEffect(
|
|
2191
|
+
changes: import("./publication.js").PublicationEffect[],
|
|
2192
|
+
slot: number,
|
|
2193
|
+
file: import("./publication.js").PublicationFile,
|
|
2194
|
+
time: FileTime | null,
|
|
2195
|
+
): void {
|
|
2196
|
+
if (time === null) return;
|
|
2197
|
+
const mtime = fileTimeMs(time);
|
|
2198
|
+
if (mtime !== fileTimeMs(this.time(slot, MTIME)))
|
|
2199
|
+
changes.push({ kind: "metadata", file, mode: this.slots[this.at(slot, MODE)]!, mtime });
|
|
2200
|
+
}
|
|
2201
|
+
private prepareTimes(
|
|
2202
|
+
slot: number,
|
|
2203
|
+
handle: FileHandle,
|
|
2204
|
+
atime: FileTime | null,
|
|
2205
|
+
mtime: FileTime | null,
|
|
2206
|
+
identity: PlannedIdentityRevision | undefined,
|
|
2207
|
+
admission: PublicationAdmission,
|
|
2208
|
+
): PreparedPublication {
|
|
2209
|
+
const domain = this.publication!;
|
|
2210
|
+
domain.verifyAdmission(admission, { kind: "setTimes", handle, atime, mtime }, new Uint8Array());
|
|
2211
|
+
const file = this.publicationFile(slot, identity);
|
|
2212
|
+
const changes: import("./publication.js").PublicationEffect[] = [];
|
|
2213
|
+
this.pushMtimeEffect(changes, slot, file, mtime);
|
|
2214
|
+
return domain.prepare(admission, { kind: "number", value: 0 }, changes);
|
|
2215
|
+
}
|
|
2216
|
+
/** Service-only: caller holds the global allocator/mutation lock. */
|
|
2217
|
+
reclaimLocked(handle: FileHandle): void {
|
|
2218
|
+
const slot = this.slot(handle);
|
|
2219
|
+
this.lock(this.at(slot, FILE_LOCK));
|
|
2220
|
+
try {
|
|
2221
|
+
const needed = Math.ceil(
|
|
2222
|
+
Atomics.load(this.slots, this.at(slot, FILE_SIZE)) / DATA_PAGE_BYTES,
|
|
2223
|
+
);
|
|
2224
|
+
const capacity = Atomics.load(this.slots, this.at(slot, CAPACITY));
|
|
2225
|
+
for (let logical = needed; logical < capacity; logical++) {
|
|
2226
|
+
const physical = Atomics.load(this.pages, this.pageAt(slot, logical)) - 1;
|
|
2227
|
+
this.detachVersionPage(physical);
|
|
2228
|
+
Atomics.store(this.pages, this.pageAt(slot, logical), 0);
|
|
2229
|
+
}
|
|
2230
|
+
Atomics.store(this.slots, this.at(slot, CAPACITY), needed);
|
|
2231
|
+
|
|
2232
|
+
this.trimPageTables(slot, needed);
|
|
2233
|
+
} finally {
|
|
2234
|
+
this.unlock(this.at(slot, FILE_LOCK));
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
/** Null leaves a time alone; ctime is the caller's single clock reading for this change. */
|
|
2238
|
+
setTimes(
|
|
2239
|
+
handle: FileHandle,
|
|
2240
|
+
atime: FileTime | null,
|
|
2241
|
+
mtime: FileTime | null,
|
|
2242
|
+
ctime: FileTime,
|
|
2243
|
+
revoked?: () => boolean,
|
|
2244
|
+
owner = this.lockOwner,
|
|
2245
|
+
admission?: PublicationAdmission,
|
|
2246
|
+
): number {
|
|
2247
|
+
const slot = this.slot(handle);
|
|
2248
|
+
this.lock(this.at(slot, FILE_LOCK), revoked, owner);
|
|
2249
|
+
try {
|
|
2250
|
+
if (this.slots[this.at(slot, HANDLE)] !== handle + 1) throw new FilesystemError(8);
|
|
2251
|
+
// The owner may set times on a read-only file, as on Linux; see MemFS.setTimes.
|
|
2252
|
+
this.checkDirty(slot, this.slots[this.at(slot, FILE_SIZE)]!);
|
|
2253
|
+
const next = {
|
|
2254
|
+
atime: atime ?? this.time(slot, ATIME),
|
|
2255
|
+
mtime: mtime ?? this.time(slot, MTIME),
|
|
2256
|
+
ctime,
|
|
2257
|
+
};
|
|
2258
|
+
// Setting the times a file already has is no new version, though ctime still moves.
|
|
2259
|
+
const identity = this.prepareIdentityVersion(
|
|
2260
|
+
slot,
|
|
2261
|
+
next.atime !== this.time(slot, ATIME) || next.mtime !== this.time(slot, MTIME),
|
|
2262
|
+
);
|
|
2263
|
+
const publication = admission
|
|
2264
|
+
? this.prepareTimes(slot, handle, atime, mtime, identity, admission)
|
|
2265
|
+
: undefined;
|
|
2266
|
+
this.dirty(slot);
|
|
2267
|
+
this.storeTimes(slot, next);
|
|
2268
|
+
this.changed(slot);
|
|
2269
|
+
this.commitIdentityVersion(slot, identity);
|
|
2270
|
+
if (publication) this.publication!.commit(publication);
|
|
2271
|
+
return 0;
|
|
2272
|
+
} finally {
|
|
2273
|
+
this.unlock(this.at(slot, FILE_LOCK), owner);
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
retain(handle: FileHandle): void {
|
|
2277
|
+
this.section?.enter();
|
|
2278
|
+
try {
|
|
2279
|
+
const slot = this.slot(handle);
|
|
2280
|
+
this.lock(this.at(slot, FILE_LOCK));
|
|
2281
|
+
try {
|
|
2282
|
+
if (this.slots[this.at(slot, HANDLE)] !== handle + 1) throw new FilesystemError(8);
|
|
2283
|
+
Atomics.add(this.slots, this.at(slot, REFS), 1);
|
|
2284
|
+
} finally {
|
|
2285
|
+
this.unlock(this.at(slot, FILE_LOCK));
|
|
2286
|
+
}
|
|
2287
|
+
} finally {
|
|
2288
|
+
this.section?.exit();
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
release(handle: FileHandle): void {
|
|
2292
|
+
this.section?.enter();
|
|
2293
|
+
try {
|
|
2294
|
+
const slot = this.slot(handle);
|
|
2295
|
+
let free = false;
|
|
2296
|
+
this.lock(this.at(slot, FILE_LOCK), undefined, this.lockOwner, "release");
|
|
2297
|
+
try {
|
|
2298
|
+
if (this.slots[this.at(slot, HANDLE)] !== handle + 1) throw new FilesystemError(8);
|
|
2299
|
+
const refs = Atomics.sub(this.slots, this.at(slot, REFS), 1) - 1;
|
|
2300
|
+
free = refs === 0 && this.slots[this.at(slot, UNLINKED)] !== 0;
|
|
2301
|
+
} finally {
|
|
2302
|
+
this.unlock(this.at(slot, FILE_LOCK));
|
|
2303
|
+
}
|
|
2304
|
+
if (free) this.free(handle, "release");
|
|
2305
|
+
} finally {
|
|
2306
|
+
this.section?.exit();
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
unlink(handle: FileHandle): void {
|
|
2310
|
+
this.section?.enter();
|
|
2311
|
+
try {
|
|
2312
|
+
const slot = this.findSlot(handle);
|
|
2313
|
+
if (!slot) return;
|
|
2314
|
+
// Namespace mutation owns the global lock. A revocation callback may mark a pinned
|
|
2315
|
+
// file while its writer still holds the file lock, so only actual reclamation takes it.
|
|
2316
|
+
Atomics.store(this.slots, this.at(slot, UNLINKED), 1);
|
|
2317
|
+
if (Atomics.load(this.slots, this.at(slot, REFS)) === 0) this.free(handle);
|
|
2318
|
+
} finally {
|
|
2319
|
+
this.section?.exit();
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
/** Service namespace mutation owns the global lock, as for unlink. Relinking does not
|
|
2323
|
+
* change the persisted payload or its revision; it cancels last-close reclamation. */
|
|
2324
|
+
relink(handle: FileHandle): void {
|
|
2325
|
+
this.section?.enter();
|
|
2326
|
+
try {
|
|
2327
|
+
const slot = this.findSlot(handle);
|
|
2328
|
+
if (slot) Atomics.store(this.slots, this.at(slot, UNLINKED), 0);
|
|
2329
|
+
} finally {
|
|
2330
|
+
this.section?.exit();
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
/** Both global and file locks are held. */
|
|
2334
|
+
private freePagesLocked(slot: number): void {
|
|
2335
|
+
const count = Atomics.load(this.slots, this.at(slot, CAPACITY));
|
|
2336
|
+
for (let logical = 0; logical < count; logical++) {
|
|
2337
|
+
const physical = Atomics.load(this.pages, this.pageAt(slot, logical)) - 1;
|
|
2338
|
+
if (physical >= 0) this.detachVersionPage(physical);
|
|
2339
|
+
Atomics.store(this.pages, this.pageAt(slot, logical), 0);
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2342
|
+
this.trimPageTables(slot, 0);
|
|
2343
|
+
Atomics.store(this.slots, this.at(slot, CAPACITY), 0);
|
|
2344
|
+
}
|
|
2345
|
+
/** Both global and file locks are held. Keep the lock and generation until after publication. */
|
|
2346
|
+
private freeLocked(slot: number): void {
|
|
2347
|
+
if (this.slots[this.at(slot, UNLINKED)])
|
|
2348
|
+
this.publication?.forgetContent(this.slots[this.at(slot, INO)]!);
|
|
2349
|
+
this.freePagesLocked(slot);
|
|
2350
|
+
this.dirtyAdmission.pin(-1, this.residentBytes());
|
|
2351
|
+
this.slots[this.at(slot, DIRTY_SIZE)] = 0;
|
|
2352
|
+
this.slots[this.at(slot, DIRTY_MARK)] = 0;
|
|
2353
|
+
const revision = this.getRevision(slot);
|
|
2354
|
+
const floor =
|
|
2355
|
+
(this.cells[FREED_REVISION_HIGH]! >>> 0) * 0x100000000 +
|
|
2356
|
+
(this.cells[FREED_REVISION_LOW]! >>> 0);
|
|
2357
|
+
if (revision > floor) {
|
|
2358
|
+
this.cells[FREED_REVISION_LOW] = revision >>> 0;
|
|
2359
|
+
this.cells[FREED_REVISION_HIGH] = Math.floor(revision / 0x100000000);
|
|
2360
|
+
}
|
|
2361
|
+
for (let field = 0; field < HANDLE; field++)
|
|
2362
|
+
if (field !== FILE_LOCK) Atomics.store(this.slots, this.at(slot, field), 0);
|
|
2363
|
+
this.slots[this.at(slot, REVISION_STATE)]! &= ~RESIDENT;
|
|
2364
|
+
// Preserve the removed handle as a lookup terminator without moving any live slot.
|
|
2365
|
+
const key = this.at(slot, HANDLE);
|
|
2366
|
+
Atomics.store(this.slots, key, -this.slots[key]!);
|
|
2367
|
+
}
|
|
2368
|
+
private free(handle: FileHandle, access: "data" | "release" = "data"): void {
|
|
2369
|
+
this.globalLock(undefined, this.lockOwner, false, access);
|
|
2370
|
+
try {
|
|
2371
|
+
const slot = this.findSlot(handle);
|
|
2372
|
+
if (!slot) return;
|
|
2373
|
+
this.lock(this.at(slot, FILE_LOCK), undefined, this.lockOwner, access);
|
|
2374
|
+
try {
|
|
2375
|
+
if (
|
|
2376
|
+
this.slots[this.at(slot, HANDLE)] !== handle + 1 ||
|
|
2377
|
+
!this.slots[this.at(slot, UNLINKED)] ||
|
|
2378
|
+
this.slots[this.at(slot, REFS)]
|
|
2379
|
+
)
|
|
2380
|
+
return;
|
|
2381
|
+
this.freeLocked(slot);
|
|
2382
|
+
} finally {
|
|
2383
|
+
this.unlock(this.at(slot, FILE_LOCK));
|
|
2384
|
+
}
|
|
2385
|
+
} finally {
|
|
2386
|
+
this.globalUnlock();
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
ownerActive(owner: number): boolean {
|
|
2390
|
+
if (Atomics.load(this.cells, GLOBAL_LOCK) === owner) return true;
|
|
2391
|
+
for (let slot = 1; slot < MAX_FILES; slot++)
|
|
2392
|
+
if (Atomics.load(this.slots, this.at(slot, FILE_LOCK)) === owner) return true;
|
|
2393
|
+
return false;
|
|
2394
|
+
}
|
|
2395
|
+
revokeOwner(owner: number, epoch?: Int32Array): void {
|
|
2396
|
+
if (!owner || owner === SERVICE_OWNER) return;
|
|
2397
|
+
this.publication?.revokeOwner(owner);
|
|
2398
|
+
// Keep the global lock held while repairing its epoch: another writer must not enter
|
|
2399
|
+
// between releasing the dead owner and publishing the matching even epoch.
|
|
2400
|
+
const ownsGlobal =
|
|
2401
|
+
Atomics.compareExchange(this.cells, GLOBAL_LOCK, owner, SERVICE_OWNER) === owner;
|
|
2402
|
+
for (let slot = 1; slot < MAX_FILES; slot++)
|
|
2403
|
+
Atomics.compareExchange(this.slots, this.at(slot, FILE_LOCK), owner, 0);
|
|
2404
|
+
if (ownsGlobal) {
|
|
2405
|
+
if (epoch && Atomics.load(epoch, 0) & 1) Atomics.add(epoch, 0, 1);
|
|
2406
|
+
Atomics.compareExchange(this.cells, GLOBAL_LOCK, SERVICE_OWNER, 0);
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
resources(): {
|
|
2410
|
+
bytes: number;
|
|
2411
|
+
poolBytes: number;
|
|
2412
|
+
metadataBytes: number;
|
|
2413
|
+
usedBytes: number;
|
|
2414
|
+
freeBytes: number;
|
|
2415
|
+
maxBytes: number;
|
|
2416
|
+
files: number;
|
|
2417
|
+
} {
|
|
2418
|
+
let files = 0;
|
|
2419
|
+
for (let slot = 1; slot < MAX_FILES; slot++)
|
|
2420
|
+
if (Atomics.load(this.slots, this.at(slot, 0))) files++;
|
|
2421
|
+
const usedBytes = Atomics.load(this.cells, USED_PAGES) * DATA_PAGE_BYTES;
|
|
2422
|
+
const poolBytes = this.segments
|
|
2423
|
+
.slice(1)
|
|
2424
|
+
.reduce((bytes, buffer) => bytes + buffer.byteLength, SHARED_SEGMENT_BYTES);
|
|
2425
|
+
const metadataBytes =
|
|
2426
|
+
this.buffer.byteLength - SHARED_SEGMENT_BYTES + (this.pageReaders?.byteLength ?? 0);
|
|
2427
|
+
return {
|
|
2428
|
+
bytes: poolBytes + metadataBytes,
|
|
2429
|
+
poolBytes,
|
|
2430
|
+
metadataBytes,
|
|
2431
|
+
usedBytes,
|
|
2432
|
+
freeBytes: poolBytes - usedBytes,
|
|
2433
|
+
maxBytes: Atomics.load(this.cells, 4) * SHARED_SEGMENT_BYTES,
|
|
2434
|
+
files,
|
|
2435
|
+
};
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
/** This connection's revocation word or any ancestor's. An indexed scan: Array#some with a
|
|
2439
|
+
* callback costs several times more in WebKit, and every direct I/O call checks it. */
|
|
2440
|
+
export function sharedRevoked(connection: {
|
|
2441
|
+
revocations: SharedArrayBuffer[];
|
|
2442
|
+
ownerStates: SharedArrayBuffer;
|
|
2443
|
+
publication?: PublicationConnection;
|
|
2444
|
+
}): () => boolean {
|
|
2445
|
+
const words = [new Int32Array(connection.ownerStates, 0, 1)].concat(
|
|
2446
|
+
connection.revocations.map((buffer) => new Int32Array(buffer)),
|
|
2447
|
+
);
|
|
2448
|
+
if (connection.publication)
|
|
2449
|
+
words.push(new Int32Array(connection.publication.buffers.control, 0, 1));
|
|
2450
|
+
return () => {
|
|
2451
|
+
for (let i = 0; i < words.length; i++) if (Atomics.load(words[i]!, 0) !== 0) return true;
|
|
2452
|
+
return false;
|
|
2453
|
+
};
|
|
2454
|
+
}
|