Skip to content

Expand safe COM projections and lifecycle support - #144

Merged
leileizhang (lei9444) merged 4 commits into
mainfrom
feature/com-safe-entry
Sep 9, 2026
Merged

leileizhang (lei9444) merged 4 commits into
mainfrom
feature/com-safe-entry

Conversation

@lei9444

@lei9444 leileizhang (lei9444) commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Consolidates the four reviewed COM projection changes into one final PR, including the changes from #145, #146, and #147, which have been merged into this stack.

The goal is to expand safe, typed JavaScript COM usage while preserving dynwinrt's metadata-driven, purely dynamic architecture and existing WinRT behavior.

Included capabilities

Safe COM entry points

Public, non-consuming projectAs(value, InterfaceClass) performs real QI and returns an independently owned result. Bounded IMMDevice.activate(InterfaceClass) uses exact activation contracts, in-process context, native NULL parameters, and owned results. The named, documented activation-target registry preserves the original five-target allowlist without expansion. IMMDevice.getId() has exact CoTaskMem ownership.

Native completion to JavaScript Promise

A reusable native-only, one-shot completion mechanism initially supports the bounded ActivateAudioInterfaceAsync projection. Completion signals the initiating owner thread; it neither executes JavaScript nor moves apartment-bound results on the callback thread. Start/result/activation HRESULTs, early or duplicate completion, NULL results, and teardown are handled separately.

Guarded borrowed-buffer copies

Audio gains writeFramesCopy, writeSilence, and readPacketCopy; WIC gains readLockedBgra8Copy; linear MF gains readCopy and replaceCopy.

One shared reviewed contract registry and a typed, plan-driven executor control native bindings, extents, copies, commits, normal/abort cleanup, and result mapping. There is no per-family execution switch or compiled per-interface native adapter. Canonical-identity context sharing, observed Audio initialization/GetService provenance, owner-thread guards, exactly-once cleanup, and poisoning protect each transaction.

Common argument admission covers objects, aliases, and supported interface-bearing containers. Retained context survives original-wrapper release, and a final check after native coercion/QI rejects invalid receiver or argument state before dispatch. This closes the poisoned-buffer IMFSample.addBuffer() input path without an API-specific exception.

Explicit COM overload projection

Previously ambiguous ordinary methods receive stable <camelName>AtSlot<absoluteSlot> entry points. Existing distinguishable overload dispatch, native slots, ABI signatures, and lifecycle contracts remain unchanged. Collisions and unsupported synthesized/dynamic groups still fail closed. This promotes the same 24 additional complete-safe interfaces.

Compatibility and safety boundaries

The WinRT public model, generated WinRT APIs, and npm root API remain unchanged. Private lowering exposes only a generic fallible pre-dispatch hook; COM lifecycle policy stays in the COM binding layer. Unbound WinRT bookkeeping remains thread-safe until first COM use.

Unknown ABI or ownership contracts fail closed. Ordinary synchronous JavaScript COM callbacks retain their owner-thread restriction. This does not introduce general cross-apartment JavaScript scheduling, COM servers, public aggregation/custom-marshaling support, or full Automation callbacks.

Borrowed storage is exposed only as owned copies, with a 64 MiB operation cap. No native-backed JavaScript Buffer/ArrayBuffer or raw borrow address escapes. WIC copying is STA-only, READ-only BGRA8; general MF2D/plane/pitch access and exclusive event-driven Audio render remain unsupported. Writes are not promised atomic rollback.

Audio render/capture and linear MF are bounded copy-only facades, not complete native-interface projections, and remain excluded from the complete-safe census.

Regeneration requirement

Generated COM file-ownership manifests are now version 5, and borrowed-copy descriptors are version 2. Delete old generated COM output and fully regenerate all selected roots with matching runtime and codegen. Do not mix old and new wrappers or edit manifest versions manually. Unsafe support schema 12 is unchanged.

Current coverage and evidence

Against Microsoft.Windows.SDK.Win32Metadata 71.0.14-preview, the consolidated result is 5,721 / 7,929 complete-safe interface projections.

The exact-contract registry contains 532 registered and metadata-matched entries, with 431 consumed by complete-safe plans. These are dependency counts, not a claim that every entry independently adds an interface.

The constituent PRs retain detailed design and regression records covering native ownership/failure paths, x64/i686 ABI, generated JavaScript/TypeScript, stock WinRT/COM execution, and unchanged public API surfaces. Audio failure/capture scenarios use controlled fixtures rather than real hardware recording.

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
@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Mixed-language test coverage

Workflow status: ✅ Passed

Layer Lines Functions Branches/regions
Rust, including native .pyd/.node 84.67% 79.66% 84.13% regions
Generated Python projections 70.48% n/a 21.71% branches
JavaScript aggregate 21.62% 20.64% 54.35% branches
JavaScript runtime 30.33% 33.33% 40.74% branches
Generated WinRT projections 25.8% 19.3% 54.74% branches
Generated Classic COM projections 14.93% 24.39% 54.2% branches

View workflow run and download full HTML/LCOV/XML reports

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

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
@lei9444 leileizhang (lei9444) changed the title Add safe COM projectAs and ordinary endpoint activation Expand safe COM projections and lifecycle support Sep 9, 2026
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
@lei9444
leileizhang (lei9444) merged commit 5ea416b into main Sep 9, 2026
24 checks passed
@lei9444
leileizhang (lei9444) deleted the feature/com-safe-entry branch September 9, 2026 03:26
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.

2 participants