Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for DisableRuntimeMarshallingAttribute #15684

Open
rolfbjarne opened this issue Aug 16, 2022 · 0 comments
Open

Add support for DisableRuntimeMarshallingAttribute #15684

rolfbjarne opened this issue Aug 16, 2022 · 0 comments
Assignees
Labels
dotnet An issue or pull request related to .NET (6) enhancement The issue or pull request is an enhancement
Milestone

Comments

@rolfbjarne
Copy link
Member

rolfbjarne commented Aug 16, 2022

The runtime is adding an assembly-level DisableRuntimeMarshallingAttribute, which does a few things:

  • Consider all unmanaged types as blittable.
  • Disables support for runtime marshalling.

If all assemblies (with P/Invokes) have this attribute, then we don't need to include support for runtime marshalling into an app. Mono has removed this support into a component (dotnet/runtime#61685), which means that it should be fairly easy to shrink apps a bit by:

  • Automatically detect whether all assemblies with P/Invokes have this attribute.
  • Disable the inclusion of the runtime marshalling component.

A prerequisite would be to fix our platform assembly (Microsoft.iOS.dll, etc) to have the DisableRuntimeMarshalling attribute, which would need either:

a) Enable source-generated DllImports, or
b) Fix all our P/invokes to only use blittable types.

The solution forward is probably to do a) first, and then check each dll import the source-generator modified to see if we can modify the DllImport to use blittable types only (since I suspect most DllImports aren't blittable by accident, and can easily be made blittable to avoid the source generator add unnecessary code).

Note that b) would likely require us to write a (cecil) test to ensure that all P/Invokes only use blittable types, because we can't rely on the compiler (dotnet/roslyn#64086).

Ref: #15668

@rolfbjarne rolfbjarne added enhancement The issue or pull request is an enhancement dotnet An issue or pull request related to .NET (6) labels Aug 16, 2022
@rolfbjarne rolfbjarne added this to the .NET 8 milestone Aug 16, 2022
stephen-hawley added a commit that referenced this issue Dec 6, 2022
…16525)

This adds a unit test to check for blittability of arguments to
pinvokes.
@rolfbjarne rolfbjarne modified the milestones: .NET 8, .NET 9 Sep 20, 2023
rolfbjarne added a commit that referenced this issue Dec 13, 2023
Also introduce a few other improvements:

* Add an varation that takes an 'out bool' instead of a 'ref bool'. According
  to the documentation the value is out-only.
* Name this variation according to our guidelines (with a verb).
* Deprecate the old version.

Contributes towards #15684.
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Dec 19, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Dec 19, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Dec 21, 2023
…ures.

Also fix the signature for the Dispose method - it has to override the base
implementation, not provide a new implementation.

Contributes towards xamarin#15684.
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Dec 22, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Dec 22, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Dec 22, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Dec 22, 2023
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Dec 22, 2023
rolfbjarne added a commit that referenced this issue Jan 2, 2024
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue May 24, 2024
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue May 27, 2024
rolfbjarne added a commit that referenced this issue May 28, 2024
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue May 28, 2024
rolfbjarne added a commit that referenced this issue May 29, 2024
rolfbjarne added a commit that referenced this issue May 29, 2024
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue May 29, 2024
rolfbjarne added a commit that referenced this issue May 31, 2024
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue May 31, 2024
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 3, 2024
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 4, 2024
…e other structs.

* The AVSampleCursor type was made available on all platforms two years ago (as
  opposed to only macOS before that), so update availability attributes accordingly.

* Also make a few structs used by AVSampleCursor blittable (AVSampleCursorSyncInfo,
  AVSampleCursorDependencyInfo, AVSampleCursorChunkInfo, AVSampleCursorAudioDependencyInfo)

  This got a bit complicated, because some of the non-blittable members of these structs
  are public. This meant a workaround had to be implemented:

  * Rename the properties that use these structures - appending "_Blittable" - and
    make them internal.
  * Create internal "*_Blittable" versions of the structures, and a make the "_Blittable"
    properties return these structures.
  * Bind the properties again, wrapping the internal versions and manually converting
    from the blittable structures to the non-blittable structures.

  Note that since some of the properties are new on iOS and tvOS, we don't need the
  compatibility workaround for these platforms.

Contributes towards xamarin#15684.
rolfbjarne added a commit that referenced this issue Jun 6, 2024
…e other structs. (#20685)

* The AVSampleCursor type was made available on all platforms two years ago (as
  opposed to only macOS before that), so update availability attributes accordingly.

* Also make a few structs used by AVSampleCursor blittable (AVSampleCursorSyncInfo,
  AVSampleCursorDependencyInfo, AVSampleCursorChunkInfo, AVSampleCursorAudioDependencyInfo)

  This got a bit complicated, because some of the non-blittable members of these structs
  are public. This meant a workaround had to be implemented:

  * Rename the properties that use these structures - appending "_Blittable" - and
    make them internal.
  * Create internal "*_Blittable" versions of the structures, and a make the "_Blittable"
    properties return these structures.
  * Bind the properties again, wrapping the internal versions and manually converting
    from the blittable structures to the non-blittable structures.

  Note that since some of the properties are new on iOS and tvOS, we don't need the
  compatibility workaround for these platforms.

Contributes towards #15684.
@github-project-automation github-project-automation bot moved this to .NET catchup in .NET 9 Aug 27, 2024
@rolfbjarne rolfbjarne modified the milestones: .NET 9, .NET 10 Sep 27, 2024
@rolfbjarne rolfbjarne removed this from .NET 9 Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet An issue or pull request related to .NET (6) enhancement The issue or pull request is an enhancement
Projects
None yet
Development

No branches or pull requests

2 participants