Skip to content

Add metadata-driven native COM one-shot completion (PR2/4) - #145

Merged
leileizhang (lei9444) merged 3 commits into
feature/com-safe-entryfrom
feature/com-native-completion
Sep 9, 2026
Merged

leileizhang (lei9444) merged 3 commits into
feature/com-safe-entryfrom
feature/com-native-completion

Conversation

@lei9444

Copy link
Copy Markdown
Contributor

Stack

PR2/4, based on feature/com-safe-entry / #144, not main. Preserves PR1's public COM projectAs registry and restricted synchronous endpoint activation. Do not merge ahead of PR1.

Scope

  • Generate activateAudioInterfaceAsync(deviceInterfacePath, GeneratedInterfaceClass): Promise<T> in the COM package, with complete IAudioClient and IAudioEndpointVolume dependencies.
  • Parse the actual WinMD DLL export and both complete interface contracts. Pin the five-argument, no-receiver system ABI, callback/operation IIDs and slot 3, and required receiving cells versus documented nullable interface contents. Reject metadata/descriptor drift.
  • Execute prepared COM-local libffi export/result plans, using System32 resolution and retained module lifetime. No per-interface compiled SDK adapter or production function-address injection.
  • Reuse the native sink static callback shape with canonical IUnknown, IAgileObject, and actual FTM-backed IMarshal. Only a one-shot token notifier is free-threaded. Original operations, results, plans, and deferreds remain owner-thread-local.
  • Handle early/duplicate completion, all HRESULT/NULL stages, exactly-once cleanup, bounded/reentrant starts, queued/in-flight/late environment teardown, addon lifetime, and event-loop release.
  • Keep synchronous JS callback owner-thread rejection and the public WinRT root unchanged. Add CI coverage and architecture/usage documentation.

Validation

  • cargo test -p dynwinrt: 288 passed, 1 existing WinAppSDK-only test ignored.
  • cargo test -p dynwinrt-codegen: 659 passed, including WinRT snapshots, exact WinMD, pure projection/rendering, and fail-closed drift coverage.
  • cargo check -p jswinrt_rs --features test-hooks --target i686-pc-windows-msvc: passed.
  • npm run test:native-completion: all 10 deterministic scenarios passed; fake five-argument export and full vtables, real FTM QI, legitimate MTA agile-reference marshaling, non-agile owner-created results, HRESULT cleanup, bounds, stale tokens, teardown, and liveness.
  • Combined serial AVA root/runtime, TSFN, raw, generated-unsafe, and native-completion regressions: 87 passed. Existing foreign-thread JS callback rejection remains covered.
  • npm run test:types, normal npm run build, and production root tests (52): passed.
  • Stock Windows E2E: WinRT JS 38/38, Classic COM 17/17.
  • cargo fmt --all --check and git diff --check: passed.

The optional WinUI timing assertion hit its existing cold-start threshold on initial runs; final serial validation passed, as did direct PR1/current comparisons. No unrelated timing code was changed.

Deliberate bounds / environment note

Only the two documented result targets and native NULL activation parameters are supported. No loopback/custom PROPVARIANT blobs, arbitrary JS apartment scheduling, generic aggregation/server API, timeout, AbortSignal, or OS cancellation claim. Dropping a Promise is not cancellation. Initiation stays on the caller's apartment, including Windows UI/consent requirements. Pending work is bounded to 256 per environment.

The optional successful live-speaker smoke could not run here: generated MediaDevice.getDefaultAudioRenderId returned no default render endpoint. A real export attempt did complete and correctly rejected with stage=activation, HRESULT 0x80070057. Deterministic coverage is green; no recording or microphone calls were made. The opt-in smoke only reads speaker channel count.

The complete-interface census is unchanged: this adds one bounded export consumer, not general flat-function or new complete-interface support.

Generate bounded audio activation promises with validated WinMD contracts,
libffi export/result plans, a native-only FTM signal sink, and owner-local
result collection. Preserve synchronous JS callback thread restrictions.
Cover publication, HRESULTs, ownership, teardown, bounds, and WinRT regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb
Preserve the existing synchronous and asynchronous activation target sets and native contracts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb
* Add guarded COM borrowed-copy transactions

Add metadata-validated owned-copy plans for Audio, WIC BGRA8 and linear
Media Foundation buffers. Observe real successful Audio initialization and
GetService calls, retain canonical identity provenance across aliases, and
finalize native borrows exactly once with thread and poison guards.

Preserve WIC's existing complete surface, keep three copy-only facades out
of complete-interface counts, require full regeneration, and add exact
metadata evidence, native fixtures, live x64/i686 tests and regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb

* Refactor COM borrowed copies into typed execution recipes

Centralize reviewed ABI and lifecycle evidence in a shared contracts crate. Execute typed bindings, bounds, copies and finalizers through one plan-driven runtime while preserving public APIs and supported interfaces.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb

* Guard managed COM arguments before native dispatch

Retain shared apartment and lifecycle contexts across interface aliases and supported containers. Recheck receivers and inputs after native coercion, preserve deferred WinRT lifetime behavior, and reject poisoned buffer inputs before IMFSample can retain them.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb

* Project ambiguous COM overloads as explicit slot-named methods (#147)

Preserve existing arity/shape dispatch for distinguishable groups. Emit stable AtSlot names for previously unsupported ordinary overloads without guessing ABI behavior, retain each validated method plan, reject alias collisions, and update exact coverage evidence.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb
@lei9444
leileizhang (lei9444) merged commit 1032d49 into feature/com-safe-entry Sep 9, 2026
1 check passed
@lei9444
leileizhang (lei9444) deleted the feature/com-native-completion branch September 9, 2026 01:46
leileizhang (lei9444) added a commit that referenced this pull request Sep 9, 2026
* Add safe COM projection and endpoint activation

Provide non-consuming COM projectAs with registered safe descriptors, restricted in-process IMMDevice activation with native NULL parameters, and exact GetId ownership. Preserve the WinRT root and dynamic architecture; require complete COM regeneration with manifest v3.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb

* Move endpoint activation targets into a cited contract registry

Preserve the five existing target IIDs, in-process context, native NULL parameters and owned result contract. Validate named evidence records and lower dynamic-length IID lists without changing generated bindings or coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb

* Add metadata-driven native COM one-shot completion (PR2/4) (#145)

* Add metadata-driven native COM one-shot completion

Generate bounded audio activation promises with validated WinMD contracts,
libffi export/result plans, a native-only FTM signal sink, and owner-local
result collection. Preserve synchronous JS callback thread restrictions.
Cover publication, HRESULTs, ownership, teardown, bounds, and WinRT regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb

* Add guarded COM borrowed-copy transactions for Audio, WIC and MF (#146)

* Add guarded COM borrowed-copy transactions

Add metadata-validated owned-copy plans for Audio, WIC BGRA8 and linear
Media Foundation buffers. Observe real successful Audio initialization and
GetService calls, retain canonical identity provenance across aliases, and
finalize native borrows exactly once with thread and poison guards.

Preserve WIC's existing complete surface, keep three copy-only facades out
of complete-interface counts, require full regeneration, and add exact
metadata evidence, native fixtures, live x64/i686 tests and regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb

* Refactor COM borrowed copies into typed execution recipes

Centralize reviewed ABI and lifecycle evidence in a shared contracts crate. Execute typed bindings, bounds, copies and finalizers through one plan-driven runtime while preserving public APIs and supported interfaces.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb

* Guard managed COM arguments before native dispatch

Retain shared apartment and lifecycle contexts across interface aliases and supported containers. Recheck receivers and inputs after native coercion, preserve deferred WinRT lifetime behavior, and reject poisoned buffer inputs before IMFSample can retain them.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb

* Project ambiguous COM overloads as explicit slot-named methods (#147)

Preserve existing arity/shape dispatch for distinguishable groups. Emit stable AtSlot names for previously unsupported ordinary overloads without guessing ABI behavior, retain each validated method plan, reject alias collisions, and update exact coverage evidence.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb

* Make COM declaration tests independent of built JS artifacts

Share the isolated COM runtime declaration fixture between overload and sink tests. Keep strict TypeScript and negative assertions while removing the coverage-time dependency on bindings/js/dist.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant