Repository navigation
Add guarded COM borrowed-copy transactions for Audio, WIC and MF - #146
Merged
leileizhang (lei9444) merged 5 commits intoSep 9, 2026
Merged
leileizhang (lei9444) merged 5 commits into
leileizhang (lei9444) merged 5 commits into
Conversation
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
Keep target eligibility and existing borrowed-copy contracts unchanged while consuming named activation evidence. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9ef7fa55-eb2a-4360-bd17-05feae50fadb
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
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
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
leileizhang (lei9444)
merged commit Sep 9, 2026
318762d
into
feature/com-native-completion
1 check passed
leileizhang (lei9444)
added a commit
that referenced
this pull request
Sep 9, 2026
* 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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack and scope
PR3 of the four-PR roadmap, based on
feature/com-native-completion/ #145. #147 remains stacked on this branch. The activation target registry migration from #144 is preserved without expanding its target set.This adds synchronous owned-copy transactions, not native-backed JavaScript views or caller-asserted pointer lifetimes.
IAudioRenderClientwriteFramesCopy(data),writeSilence(frames)IAudioCaptureClientreadPacketCopy()IWICBitmapreadLockedBgra8Copy(rect)IMFMediaBufferreadCopy(),replaceCopy(data)Audio render/capture and linear MF are copy-only facades, not complete native-interface projections. WIC retains its complete methods and gains the read-copy operation. Complete coverage remains 5,697 / 7,929.
Plan-driven execution
The follow-up refactor replaces the original four family-specific execution flows, rather than merely relocating
expected(kind).dynwinrt-com-contractscrate contains one packaged registry of interface identities, exact IID/slot/ABI evidence, positional scalar units, acquisition/finalizer relationships, and typed operation recipes.before/acquire/aftersteps drive actual native calls. Frame, linear-byte and row extents drive checked bounds and copying. Transfer, native length commit, normal/abort cleanup, and result mappings are executed from the plan.The graph proof rejects an unrelated method substituted for cleanup, frame counts bound to native flag parameters, unavailable abort inputs, duplicate or dangling bindings, and mismatched owner lifetimes. Negative tests exercise this proof independently of whole-record admission.
Test-only records use different IIDs, slots, call names and argument orders for linear, frame-writer, frame-reader and row-copy interfaces. They perform actual byte copies and full/zero/owner cleanup through the same executor; misleading display labels cannot select an algorithm. Test registry injection is absent from production and JS test-hooks builds.
Preserved safety boundaries
Canonical-identity sidecars, observed successful Audio initialization/GetService provenance, owner-thread gates, callback suppression, exactly-once cleanup and poisoning remain intact. Audio byte sizes still come only from the format used by actual successful initialization, never caller block alignment or
GetMixFormat.Capture preserves empty/silent/timestamp-error handling. WIC uses a READ lock, native BGRA8 dimensions/stride/count, bounded pixel-row copies and owner Release, not an invented Unlock. Linear MF checks both native lengths, commits replacement length, and Unlocks after successful acquisition.
This does not make ownership or provenance user-declarable. New ownership models still require reviewed semantic support. No raw borrow addresses, escaping native buffers, general cross-apartment dispatch or new production interfaces are introduced. The 64 MiB cap, unsupported exclusive-event render and unsupported MF2D/plane/pitch cases remain unchanged; audio capture testing uses controlled fakes, not real recording.
The WinRT model, generated WinRT APIs and npm root surface are unchanged. A policy-free, fallible pre-dispatch hook in the private lowering backend permits the COM argument check described below; ordinary WinRT calls supply the existing no-op behavior. Build integration adds the shared crate and its validation coverage.
Shared COM argument admission
Ordinary invocation now checks managed COM arguments as well as the receiver. The common boundary rejects wrong-apartment, busy and poisoned references before argument conversion, and checks again after native argument coercion/QI, before entering the target vtable method. Rejection leaves tracked dispatch markers unset and preserves call-local cleanup.
Counted interface arrays, supported interface-bearing VARIANT/SAFEARRAY/DISPPARAMS containers, and private WinRT-backed array/typed-struct bookkeeping retain shared context slots. Containers built while idle cannot discard later poison by outliving their original wrappers or by extracting an alias. Unbound WinRT bookkeeping stays thread-safe and unaffiliated until first COM use; its ordinary cross-thread destruction does not leak deferred state.
This is not an
IMFSample::AddBufferspecial case. The generated media E2E uses a stock in-memory IMFSample and controlled IMFMediaBuffer fixture: a healthy carrier is accepted, while poisoned original/alias inputs are rejected and the sample's buffer count remains unchanged. Standard identity handling and deterministic release remain available; no blanket busy state is imposed on ordinary healthy calls.Evidence and regeneration
The same 26 exact selectors, fingerprints and Microsoft citations are retained for Win32Metadata 71.0.14-preview, SHA256
B64EE4818A7ED9F9D135038D58C51BD08369184D4D5ED428F20E9DE55DF8121D.Borrowed descriptors are version 2; the COM file-ownership manifest is version 5. Delete old generated COM bindings and fully regenerate all selected roots with matching runtime/codegen. There is no silent migration or mixed-version support. Unsafe support schema 12 and evidence IDs remain unchanged.
All seven public receiver declarations remain byte-identical to the pre-refactor baseline. Copy-only facades are still excluded from complete-interface counts.
Validation
An unrelated serial combination of existing dynamic-sink, metadata and native-call tests hits an access violation in
coerces_object_array_elements_to_the_expected_interface. A fresh build of unchanged parent2bad1cereproduces the same failure at the same test. Isolated suites pass; no unrelated native-call code or thresholds were changed to hide it. The earlier WinUI timing limitation remains documented separately.