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

Xamarin iOS should call monovm_initialize for .NET 6 #10504

Closed
4 tasks done
Tracked by #44736
CoffeeFlux opened this issue Jan 22, 2021 · 5 comments · Fixed by #12309
Closed
4 tasks done
Tracked by #44736

Xamarin iOS should call monovm_initialize for .NET 6 #10504

CoffeeFlux opened this issue Jan 22, 2021 · 5 comments · Fixed by #12309
Assignees
Labels
dotnet An issue or pull request related to .NET (6) dotnet-pri1 .NET 6: important for stable release estimate-2w feature A feature to be implemented iOS Issues affecting Xamarin.iOS macOS Issues affecting Xamarin.Mac
Milestone

Comments

@CoffeeFlux
Copy link

CoffeeFlux commented Jan 22, 2021

monovm_initialize is a cleaned-up equivalent to coreclr_initialize, which is one of the .NET Core hosting functions in CoreClrHost.h.

Signature: https:/dotnet/runtime/blob/1d9e50cb4735df46d3de0cee5791e97295eaf588/src/mono/mono/mini/mono-private-unstable.h#L30

It needs to be called in net6 embedding projects before the runtime is started. Specifically, what it's doing is:

  • Passing in various runtime properties, a subset of which we support. The important ones are:
    • TRUSTED_PLATFORM_ASSEMBLIES: Hard-coded list of assemblies, intended to be used for the BCL and fast-path'd in the loading algorithm. They also have some ALC loading implications (default context only).
    • APP_PATHS: Essentially the same as MONO_PATH. Prefer TRUSTED_PLATFORM_ASSEMBLIES where possible.
    • NATIVE_DLL_SEARCH_DIRECTORIES: Extra directories to check when loading native libraries for pinvokes.
    • System.Globalization.Invariant: Alternative way to set the DOTNET_SYSTEM_GLOBALIZATION_INVARIANT env var.
    • PINVOKE_OVERRIDE: First-chance native callback to control P/Invoke resolution, see Static linking of native libs dotnet/runtime#44505
  • Adding netcore-specific loader hooks, some of which use those properties
  • Setting the runtime to use strict assembly name checking, as we still default to the historical behavior otherwise

The runtime properties are also set in files like .runtimeconfig.json, which is parsed in by the default host and passed to coreclr_initialize. Mono embedders not using the default host will have to handle this themselves, probably at build time in the case of Xamarin, if they wish to support those files.

Applications not calling monovm_initialize may result in a runtime error at some undetermined point in the future.



Time estimate: 2 weeks

@rolfbjarne rolfbjarne self-assigned this Jan 22, 2021
@rolfbjarne rolfbjarne added dotnet An issue or pull request related to .NET (6) iOS Issues affecting Xamarin.iOS macOS Issues affecting Xamarin.Mac enhancement The issue or pull request is an enhancement labels Jan 22, 2021
@rolfbjarne rolfbjarne added this to the .NET 6 milestone Jan 22, 2021
@rolfbjarne
Copy link
Member

OK, I'll have a look at this.

Is monovm_initialize already available to call, or do I have to wait until it's implemented?

@CoffeeFlux
Copy link
Author

Already implemented. It's called by the default dotnet host, so if it didn't work we wouldn't function anywhere.

@CoffeeFlux
Copy link
Author

The main limitations with it right now are:

@lambdageek
Copy link
Member

Worth adding, monovm_intialize is also responsible for surfacing System.AppContext properties from the embedding host through the runtime up to managed https://gist.github.com/lambdageek/c6f101503b6db9876e281e677980b6df

@rolfbjarne rolfbjarne added dotnet-pri0 .NET 6: required for stable release feature A feature to be implemented and removed enhancement The issue or pull request is an enhancement labels Feb 3, 2021
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Mar 18, 2021
We need to call coreclr_initialize/monovm_initialize at startup, so do that.
This is a partial implementation, in that we're not setting all the properties
that we should, and also the PINVOKE_OVERRIDE callback is not doing everything
it should either yet.

Ref: xamarin#10504.
rolfbjarne added a commit that referenced this issue Mar 22, 2021
#10909)

We need to call coreclr_initialize/monovm_initialize at startup, so do that.
This is a partial implementation, in that we're not setting all the properties
that we should, and also the PINVOKE_OVERRIDE callback is not doing everything
it should either yet.

Ref: #10504.
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Mar 22, 2021
…for .NET code.

This makes the mono_dllmap_insert function unnecessary for .NET, so remove it.

Ref: dotnet/runtime#48110
Ref: dotnet/runtime#43204
Ref: xamarin#10504
rolfbjarne added a commit that referenced this issue Mar 24, 2021
…for .NET code. (#10932)

This makes the mono_dllmap_insert function unnecessary for .NET, so remove it.

Ref: dotnet/runtime#48110
Ref: dotnet/runtime#43204
Ref: #10504
@rolfbjarne rolfbjarne added dotnet-pri1 .NET 6: important for stable release and removed dotnet-pri0 .NET 6: required for stable release labels May 10, 2021
@rolfbjarne
Copy link
Member

We're adding all the assemblies in the app bundle to TRUSTED_PLATFORM_ASSEMBLIES, so APP_PATHS shouldn't be needed.

rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jul 30, 2021
…TORIES runtime property. Fixes xamarin#10504.

This adds support to compute the NATIVE_DLL_SEARCH_DIRECTORIES value and pass
it to the runtime. It's the last property listed in xamarin#10504, so this fixes that
issue.

Fixes xamarin#10504
rolfbjarne added a commit that referenced this issue Aug 2, 2021
…TORIES runtime property. Fixes #10504. (#12309)

This adds support to compute the NATIVE_DLL_SEARCH_DIRECTORIES value and pass
it to the runtime. It's the last property listed in #10504, so this fixes that
issue.

Fixes #10504
@ghost ghost locked as resolved and limited conversation to collaborators Apr 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dotnet An issue or pull request related to .NET (6) dotnet-pri1 .NET 6: important for stable release estimate-2w feature A feature to be implemented iOS Issues affecting Xamarin.iOS macOS Issues affecting Xamarin.Mac
Projects
None yet
3 participants