Skip to content

[CoreCLR] Support marshal methods #9912

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

Merged
merged 7 commits into from
Mar 14, 2025

Conversation

simonrozsival
Copy link
Member

@simonrozsival simonrozsival commented Mar 12, 2025

This is a follow-up to #9805 and #9900

This PR makes it possible to enable marshal methods in CoreCLR apps in the Release configuration by using the $(AndroidEnableMarshalMethods)=true.

Note: It is not necessary to set $(_AndroidUseManagedMarshalMethodsLookup)=true manually when using CoreCLR. This is because the it is the only marshal methods lookup method supported on CoreCLR.

This PR contains the following changes:

  • The xamarin_app_init method is added to the pinvoke overrides
  • The configuration flags are now set and propagated correctly during initialization to ensure that the xamarin_app_init method is called when $(AndroidEnableMarshalMethods)=true.
  • We now prevent generating a _mm_wrapper method for methods which already have [UnmanagedCallersOnly] attributes
    in MarshalMethodsAssemblyRewriter. There was a bug in [Experimental] Add alternative way of resolving UCO function pointers for Marshal Methods #9805 which created a n_Activate_mm_mm_wrapper
    UCO which called the hand-written n_Activate_mm UCO. This wasn't caught earlier because Mono does not throw
    when a managed function calls an UCO. On CoreCLR, this codepath failed with Invalid Program: attempted to call a UnmanagedCallersOnly method from managed code..

@simonrozsival simonrozsival marked this pull request as ready for review March 13, 2025 13:46
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/coreclr-marshal-methods branch from 8524974 to 3780ce6 Compare March 13, 2025 22:07

[[gnu::visibility("default")]] extern void xamarin_app_init (JNIEnv *env, get_function_pointer_fn fn) noexcept;
#endif // def RELEASE
extern "C" [[gnu::visibility("default")]] void xamarin_app_init (JNIEnv *env, get_function_pointer_fn fn) noexcept;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this moved outside of the #if RELEASE block? Is it somehow present in Debug config builds? (Are those even meaningfully supported at present?)

Copy link
Contributor

@jonpryor jonpryor Mar 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…or maybe it always needs to exist because it's in the pinvoke-tables…

@jonpryor jonpryor merged commit d31a6bf into main Mar 14, 2025
58 checks passed
@jonpryor jonpryor deleted the dev/simonrozsival/coreclr-marshal-methods branch March 14, 2025 13:29
@github-actions github-actions bot locked and limited conversation to collaborators Apr 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants