Repository navigation
[src] Enable DisableRuntimeMarshalling and fix remaining non-blittable P/Invokes - #27123
rolfbjarne wants to merge 3 commits into
Conversation
…kes blittable In Mono.Cecil, ArrayType.Resolve () resolves to the array's element type. Because IsBlittableValueType did not check type.IsArray before calling type.Resolve (), arrays of value types were mistakenly treated as blittable value types. - Reject array types in IsBlittableValueType. - Key blitCache by type.FullName instead of type.Name. - Clear localResult between parameter checks in IsMethodBlittable. - Convert the 38 discovered array-based P/Invokes across Accelerate, CoreFoundation, CoreGraphics, CoreText, Foundation, ObjCRuntime, and Security to use pointers and fixed blocks. Co-authored-by: Copilot App <[email protected]>
…ning P/Invokes - Add [assembly: DisableRuntimeMarshalling] to src/AssemblyInfo.cs.in and a Cecil test (HasDisableRuntimeMarshallingAttribute) verifying it is present. - Strengthen BlittablePInvokes test to reject: - P/Invokes specifying a CharSet. - Non-blittable primitives (bool, char), including inside structs or pointers. - ByRef NFloat (out/ref nfloat). - Non-blittable parameter/return types inside function pointers. - Auto-layout structs, generic instances, and required/optional modifiers. - Remove unnecessary CharSet attributes from P/Invokes in CoreFoundation, CoreText, Network, and ObjCRuntime, and change char* in CFString P/Invokes to ushort*. - Replace out nfloat in CoreText (CTLine, CTRun) with nfloat* and fixed blocks. - Add blittable wrapper structs (CGEventTapInformation_Blittable and MPSImageHistogramInfo_Blittable) for structs with bool fields, and teach bgen to use [NativeName] when generating P/Invoke names for value types. Fixes #15684. Co-authored-by: Copilot App <[email protected]>
- Update CGEventTapInformation and MPSImageHistogramInfo under XAMCORE_5_0 to use private fields with public property accessors (and byte backing fields for bool properties), and guard the *_Blittable structs and consuming workarounds with !XAMCORE_5_0. - Remove redundant CallingConvention = CallingConvention.Cdecl from the modified Network P/Invokes. - Add and improve XML documentation for all modified public APIs, inline referenced external XML docs, and update Documentation.KnownFailures.txt. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved interop regressions can cause missing native SIMD symbols and vnode file-opening failures, while empty-array stream calls pass null buffers that break managed overrides.
4 open issues
What changed in this PR
This PR enables disabled runtime marshalling in the Apple platform assemblies, advancing #15684’s goal of reducing reliance on runtime marshalling support.
Changes:
- Converts remaining array-based and by-reference P/Invokes to pointers with explicit buffer pinning.
- Adds blittable struct adapters and updates binding-generator naming.
- Strengthens Cecil validation and updates public API documentation.
| File | Description |
|---|---|
| tests/cecil-tests/Documentation.KnownFailures.txt | Removes entries for newly documented APIs. |
| tests/cecil-tests/BlittablePInvokes.cs | Expands interop checks and verifies the assembly attribute. |
| src/Security/Items.cs | Pins password buffers for pointer-based imports. |
| src/ObjCRuntime/Runtime.cs | Pins UTF-8 buffers for native logging. |
| src/ObjCRuntime/Class.cs | Removes unnecessary charset metadata. |
| src/Network/NWWebSocketResponse.cs | Simplifies imports and documents response APIs. |
| src/Network/NWWebSocketOptions.cs | Simplifies imports and documents configuration methods. |
| src/Network/NWEndpoint.cs | Simplifies URL imports and adds documentation. |
| src/Network/NWBrowserDescriptor.cs | Simplifies Bonjour imports and documents properties. |
| src/MetalPerformanceShaders/MPSDefs.cs | Adds blittable histogram storage and conversions. |
| src/metalperformanceshaders.cs | Routes histogram bindings through compatibility adapters. |
| src/Foundation/NSOutputStream.cs | Pins array buffers for native writes. |
| src/Foundation/NSInputStream.cs | Pins array buffers for native reads. |
| src/CoreText/CTRun.cs | Converts glyph buffers and metric outputs to pointers. |
| src/CoreText/CTParagraphStyle.cs | Pins paragraph settings during native creation. |
| src/CoreText/CTLine.cs | Uses pointers for metric outputs. |
| src/CoreText/CTFrame.cs | Pins line-origin output buffers. |
| src/CoreText/CTFont.cs | Converts glyph operations to pointer-based imports. |
| src/CoreGraphics/CGPath.cs | Pins rectangle and point arrays. |
| src/CoreGraphics/CGEvent.cs | Adds blittable event-tap information storage. |
| src/CoreGraphics/CGContext.cs | Pins drawing buffers and expands documentation. |
| src/CoreGraphics/CGColorSpace.cs | Pins color tables and inlines documentation. |
| src/CoreGraphics/CGBitmapContext.cs | Passes retained pinned-buffer addresses directly. |
| src/CoreFoundation/CFString.cs | Uses UTF-16 pointers without charset metadata. |
| src/CoreFoundation/CFMutableString.cs | Removes charset metadata and documents append behavior. |
| src/CoreFoundation/CFDictionary.cs | Uses pointers for dictionary key/value buffers. |
| src/bgen/Generator.cs | Applies native names to generated interop signatures. |
| src/AssemblyInfo.cs.in | Enables DisableRuntimeMarshalling. |
| src/Accelerate/vImageTypes.cs | Uses pinned buffers and stack-allocated pointer arrays. |
| docs/api/CoreGraphics/CGContext.xml | Removes the external AddLines documentation block. |
| docs/api/CoreGraphics/CGColorSpace.xml | Removes documentation moved into source comments. |
Review effort: Balanced
| [assembly: AssemblyCompany ("Microsoft Corp.")] | ||
|
|
||
| [assembly: AssemblyMetadata ("IsTrimmable", "True")] | ||
| [assembly: DisableRuntimeMarshalling] |
| var nativeNameAttr = AttributeManager.GetCustomAttribute<ObjCRuntime.NativeNameAttribute> (mai.Type); | ||
| if (!string.IsNullOrEmpty (nativeNameAttr?.NativeName)) | ||
| return nativeNameAttr.NativeName; |
| fixed (byte* ptr = buffer) { | ||
| var result = objc_msgSend (Handle, Selector.GetHandle (selReadMaxLength), (IntPtr) ptr, len); |
| fixed (byte* ptr = buffer) { | ||
| var result = objc_msgSend (Handle, Selector.GetHandle (selWriteMaxLength), (IntPtr) ptr, len); |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
🔥 [PR Build #45b0726] Build failed (Build macOS tests) 🔥Build failed for the job 'Build macOS tests' (with job status 'Failed') Pipeline on Agent |
🔥 [CI Build #45b0726] Test results 🔥Test results❌ Tests failed on VSTS: test results 5 tests crashed, 138 tests failed, 56 tests passed. Failures❌ dotnettests tests (iOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (MacCatalyst)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (macOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (tvOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ framework tests1 tests failed, 1 tests passed.Failed tests
Html Report (VSDrops) Download ❌ fsharp tests3 tests failed, 1 tests passed.Failed tests
Html Report (VSDrops) Download ❌ interdependent-binding-projects tests3 tests failed, 1 tests passed.Failed tests
Html Report (VSDrops) Download ❌ introspection tests4 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ linker tests (iOS)10 tests failed, 11 tests passed.Failed tests
Html Report (VSDrops) Download ❌ linker tests (MacCatalyst)10 tests failed, 11 tests passed.Failed tests
Html Report (VSDrops) Download ❌ linker tests (macOS)10 tests failed, 11 tests passed.Failed tests
Html Report (VSDrops) Download ❌ linker tests (tvOS)10 tests failed, 11 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (iOS)20 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (MacCatalyst)20 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (macOS)20 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (tvOS)20 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ windows tests🔥 Failed catastrophically on VSTS: test results - windows (no summary found). Html Report (VSDrops) Download ❌ xcframework tests3 tests failed, 1 tests passed.Failed tests
Html Report (VSDrops) Download ❌ Tests on macOS Sonoma (14) testsHtml Report (VSDrops) Download ❌ Tests on macOS Sequoia (15) testsHtml Report (VSDrops) Download ❌ Tests on macOS Tahoe (26) testsHtml Report (VSDrops) Download ❌ Tests on macOS Golden Gate (27) testsHtml Report (VSDrops) Download Successes✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS testsLinux Build VerificationPipeline on Agent |
|


Description
This PR enables
[assembly: DisableRuntimeMarshalling]across the platform assemblies (Microsoft.iOS.dll,Microsoft.tvOS.dll,Microsoft.macOS.dll,Microsoft.MacCatalyst.dll), strengthens theBlittablePInvokesCecil test to catch all non-blittable P/Invoke patterns, and updates the remaining P/Invokes to be blittable.Changes
src/AssemblyInfo.cs.in:[assembly: DisableRuntimeMarshalling].tests/cecil-tests/BlittablePInvokes.cs:HasDisableRuntimeMarshallingAttributeto verify that all platform implementation assemblies have[DisableRuntimeMarshalling].IsBlittableValueTypeto checktype.IsArraybefore callingtype.Resolve ()(sinceArrayType.Resolve ()in Mono.Cecil resolves to the element type, which caused arrays of value types likebyte[]to be treated as blittable).bool,char) inIsBlittableValueType(which previously slipped through the struct field recursion check because their BCL struct definitions contain a single self-referentialm_valuefield).CharSet(!method.PInvokeInfo.IsCharSetNotSpec)."System.Runtime.InteropServices.NFloat&"fromtypesWeLikesoout/ref nfloatis rejected like all otherByReferencetypes.FunctionPointerType(delegate* unmanaged<...>), and rejectedIsAutoLayoutstructs,IsGenericInstance, andIsRequiredModifier/IsOptionalModifier.blitCachebytype.FullNameinstead oftype.Nameand clearedlocalResultper parameter inIsMethodBlittable.Accelerate,CoreFoundation,CoreGraphics,CoreText,Foundation,ObjCRuntime, andSecurityto use pointers andfixed/stackalloc.CharSet(and redundantCallingConvention = CallingConvention.Cdecl) from P/Invokes inCoreFoundation,CoreText,Network, andObjCRuntime, and changedchar*inCFStringP/Invokes toushort*.out nfloatinCTLineandCTRunwithnfloat*.CGEventTapInformationandMPSImageHistogramInfoto use private fields (bytefor boolean fields) and public property accessors underXAMCORE_5_0, added*_Blittablestructs under!XAMCORE_5_0, and updatedbgento honor[NativeName]on value types when generating P/Invoke names.tests/cecil-tests/Documentation.KnownFailures.txt.Fixes #15684.
Note
This pull request was generated with the assistance of GitHub Copilot.