Граф коммитов

586 Коммитов

Автор SHA1 Сообщение Дата
Rolf Bjarne Kvinge eafe528591
[runtime/tools] Implement finding native support libraries when linking statically. Fixes #10950, #11145 and #12100. (#12323)
* Add support for Mono Components.

* Modify how we look up symbols from native libraries shipped with Mono: we keep
  track of which native libraries we linked with, and depending on how we linked
  to those assemblies, we look the symbols up at runtime in either the current executable
  (if linking statically), or the actual library (where the P/Invoke says they're
  supposed to be).

* This means that we have to propagate how libmono is linked from the MSBuild code
  to the Application class so that our existing logic is able to correctly determine
  which native mono lib to use.

* Modify how we list the P/Invokes we need to preserve by taking into account the
  list of native libraries from Mono we have to link with (for .NET). For legacy
  Xamarin, I've reverted the logic to how it was before we started adding .NET support.

Fixes https://github.com/xamarin/xamarin-macios/issues/10950.
Fixes https://github.com/xamarin/xamarin-macios/issues/11145.
Fixes https://github.com/xamarin/xamarin-macios/issues/12100.
2021-08-03 17:06:58 +02:00
Rolf Bjarne Kvinge 440ff7c706
[runtime] Implement computing and passing the NATIVE_DLL_SEARCH_DIRECTORIES 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 https://github.com/xamarin/xamarin-macios/issues/10504
2021-08-02 09:25:54 +02:00
Rolf Bjarne Kvinge 3d822de007
[runtime] List all assemblies in TRUSTED_PLATFORM_ASSEMBLIES as pass it to MonoVM/CoreCLR. Fixes #12265. (#12272)
List all the assemblies in the app bundle and pass them to MonoVM/CoreCLR's in
the TRUSTED_PLATFORM_ASSEMBLIES initialization property.

This way CoreCLR knows where to find System.Private.CoreLib.dll for fat apps
(it's in the runtimeidentifier-specific subdirectory, and by default CoreCLR
will only look next to libcoreclr.dylib).

Fixes https://github.com/xamarin/xamarin-macios/issues/12265.
2021-07-29 07:45:24 +02:00
Rolf Bjarne Kvinge 9dcc4d07b4
[runtime] Fix the arguments to the managed main function when using CoreCLR. Fixes #12219. (#12239)
Also add tests.

Fixes https://github.com/xamarin/xamarin-macios/issues/12219.
2021-07-28 17:12:29 +02:00
Rolf Bjarne Kvinge 24351db16c [runtime/tools] Implement finding native mono lib for Mac Catalyst.
This also meant propagating how libmono is linked from the MSBuild code to the Application
class so that our existing logic is able to correctly determine which native mono
lib to use.
2021-07-22 10:36:21 +02:00
Rolf Bjarne Kvinge eddf7b6c8d [runtime] AOT is no longer limited to device builds. 2021-07-22 10:36:21 +02:00
Rolf Bjarne Kvinge 3c38f8ccd6
[dotnet] Enable autorelease pools for threadpools. Fixes #11750. (#12060)
Fixes https://github.com/xamarin/xamarin-macios/issues/11750.
2021-07-20 14:34:37 +02:00
Rolf Bjarne Kvinge d775794fd2
[dotnet] Create and parse runtimeconfig.bin when using CoreCLR. (#12122)
We need to process the runtimeconfig.json file somehow when using CoreCLR, and
the embedding API we use (coreclr_initialize) won't parse it for us. So re-use
the logic we already have to process runtimeconfig.json for MonoVM (which
involves converting it to a binary format at build time, which we then process
at runtime).
2021-07-16 16:15:17 +02:00
Rolf Bjarne Kvinge 6485ff2332
[runtime] Fix Runtime.Arch to be consistent on Mac Catalyst and work properly on ARM-based simulators. (#12125)
* Use the Apple-provided TARGET_OS_SIMULATOR define to determine if we're
  running in a simulator, instead of checking the current architecture. This
  way we properly detect ARM64-based simulators (and it'll work correctly in
  the future).

* Always set Runtime.Arch = SIMULATOR for Mac Catalyst. The final value for
  Runtime.Arch for Mac Catalyst is tracked in #10312, but this is a stop-gap
  measure to make sure we have the same value between X64 and ARM64 on Mac
  Catalyst, and until now we've had Runtime.Arch = SIMULATOR for X64, so just
  go with that for now.
2021-07-16 09:33:11 +02:00
Rolf Bjarne Kvinge d9664843e2
[runtime] Add logging when a P/Invoke can't be resolved in xamarin_pinvoke_override. (#12106)
Return early when we're not going to try resolving anything, which means that
if we didn't find something by the end, we know that it's because we failed
(and not because we weren't supposed to try), and we log that.

This makes it easier to diagnose a few failure conditions.
2021-07-14 17:52:40 +02:00
Rolf Bjarne Kvinge fc8fb4818c
[runtime] Set the current directory to the root directory of the app bundle for all platforms in .NET. (#12104)
To have consistent behavior in .NET, set the current directory to the root of
the app bundle for all platforms.

This is a breaking change for legacy Xamarin.Mac, which used to set the
current directory to the Contents/Resources subdirectory, but there's a simple
workaround for customers that depend on the old behavior (change it in Main
themselves), and I believe the consistent experience across platforms warrants
this change.

Note that we already had a breaking change here for macOS/.NET: we were
(unintentionally) setting the current directory to the Contents/MonoBundle
directory, which neither matched mobile platforms, nor the legacy Xamarin.Mac
behavior.

This solves the problem of what to do for Mac Catalyst apps, because there's
no need to choose between the macOS or the mobile behavior, since they're the
same.

This required changing the launch of macOS apps using CoreCLR to pass the full
path to the entry assembly, since the entry assembly isn't in the current
directory anymore.
2021-07-14 17:42:49 +02:00
Rolf Bjarne Kvinge 608dfb37bc [dotnet] Make the globalization data file an architecture-specific file.
This was adapted from https://github.com/xamarin/xamarin-macios/pull/11320.
2021-06-23 18:38:46 +02:00
Rolf Bjarne Kvinge f6e9f555de [runtime] Add a xamarin_locate_app_resource function. 2021-06-23 18:38:46 +02:00
Rolf Bjarne Kvinge 87de6ea653 [runtime] Add support for finding assemblies in an RID-specific subdirectory. 2021-06-18 10:24:28 +02:00
Rolf Bjarne Kvinge c8e854c151
[dotnet] Add support for generating a binary version of runtimeconfig.json. Fixes #11745. (#11887)
Use Mono's RuntimeConfigParserTask to parse the *.runtimeconfig.json file and
produce a binary version of it.

This also means implementing support for finding the on-disk location of the
file at runtime, and passing it to mono.

Ref: 01b7e73cd3/docs/design/mono/mobile-runtimeconfig-json.md

Fixes https://github.com/xamarin/xamarin-macios/issues/11745.
2021-06-16 15:22:02 +02:00
Rolf Bjarne Kvinge 7860ac8f85
[runtime] Disable LOG_MONOVM logging by default. (#11796)
This should have been disabled from the beginning.
2021-06-03 18:45:21 +02:00
Rolf Bjarne Kvinge 071ac6463e
[coreclr] Support for NSAutoreleasePools has now been implemented for background threads for both MonoVM and CoreCLR. Fixes #11256. (#11749)
Fixes https://github.com/xamarin/xamarin-macios/issues/11256.
2021-06-02 07:41:44 +02:00
Rolf Bjarne Kvinge f3b46b955f
[runtime] Add support for toggle refs to CoreCLR. (#11757)
The code contains comments explaining the new behavior.

Some tests that poked into the private 'flags' field on NSObject had to be
updated, because the field is now named differently in .NET.

I also added two more tests for toggle ref scenarios.
2021-06-02 00:13:49 +02:00
Rolf Bjarne Kvinge ebfeee6974
[runtime] Add missing release for call to mono_reflection_type_get_type. (#11756)
No more leaks!

Before:

    There were 205834 MonoObjects created, 205834 MonoObjects freed, so no leaked MonoObjects. (static registrar)
    There were 258092 MonoObjects created, 258013 MonoObjects freed, so 79 were not freed. (dynamic registrar)

After:

     There were 205834 MonoObjects created, 205834 MonoObjects freed, so no leaked MonoObjects. (static registrar)
     There were 258100 MonoObjects created, 258100 MonoObjects freed, so no leaked MonoObjects. (dynamic registrar)
2021-06-01 22:19:20 +02:00
Rolf Bjarne Kvinge 1c60b17bbe
[runtime] Show the typename of the MonoObjects we're leaking. (#11758)
This makes it a bit easier to figure out what's going on.
2021-06-01 20:43:50 +02:00
Rolf Bjarne Kvinge 1e1e0298bd
[runtime] Don't forget to free the method field in MonoMethodSignatures. (#11746)
Before:

    There were 258096 MonoObjects created, 246948 MonoObjects freed, so 11148 were not freed. (dynamic registrar)
    There were 205834 MonoObjects created, 205214 MonoObjects freed, so 620 were not freed. (static registrar)

After:

    There were 205834 MonoObjects created, 205222 MonoObjects freed, so 612 were not freed. (dynamic registrar)
    There were 258100 MonoObjects created, 258019 MonoObjects freed, so 81 were not freed. (static registrar)
2021-06-01 13:09:43 +02:00
Rolf Bjarne Kvinge 03685e70b8
[static registrar] Release the return value from xamarin_get_reflection_method_method in generated code. (#11748)
* If the return value from xamarin_get_reflection_method_method is cached in a
  static variable, we can only release at process exist.
* Otherwise just release at the end of the current method.

Before:

    There were 258096 MonoObjects created, 246948 MonoObjects freed, so 11148 were not freed. (dynamic registrar)
    There were 205834 MonoObjects created, 205214 MonoObjects freed, so 620 were not freed. (static registrar)

After:

    There were 258092 MonoObjects created, 246945 MonoObjects freed, so 11147 were not freed. (dynamic registrar)
    There were 205834 MonoObjects created, 205600 MonoObjects freed, so 234 were not freed. (static registrar)
2021-06-01 07:36:01 +02:00
Rolf Bjarne Kvinge 1b98f4ec9e
[runtime] Release the block_wrapper_queue and xamarin_wrapper_hash dictionaries upon process exit. (#11751)
While not strictly necessary to not leak (because the process is exiting
anyway), it makes it easier to read leak reports, because these dictionaries
won't show up as leaked memory anymore.

Before:

    There were 258096 MonoObjects created, 258015 MonoObjects freed, so 81 were not freed. (dynamic registrar)
    There were 205834 MonoObjects created, 205833 MonoObjects freed, so 1 were not freed. (static registrar)

After:

    There were 258104 MonoObjects created, 258025 MonoObjects freed, so 79 were not freed. (dynamic registrar)
    There were 205834 MonoObjects created, 205834 MonoObjects freed, so no leaked MonoObjects. (static registrar)
2021-06-01 07:35:29 +02:00
Rolf Bjarne Kvinge 2bee92225c
[runtime] Complete support for exception marshalling on CoreCLR. (#11734)
* [runtime] Add support for exception marshalling to CoreCLR.

* [runtime] Add an empty implementation of the toggle ref machinery.

We need this to use the unhandled exception handler support in CoreCLR,
because the ObjectiveCMarshal.Initialize call to initialize unhandled
exception support requires passing toggle ref callbacks as well.

* [tests] The TestConstrainedGenericType test can now be re-enabled, after a few updates.
2021-05-31 08:10:34 +02:00
Rolf Bjarne Kvinge 4f28fb2481
[dynamic registrar] Free the return value from mono_signature_get_params and mono_signature_get_return_type. (#11730)
Before:

    There were 258042 MonoObjects created, 235166 MonoObjects freed, so 22876 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 204219 MonoObjects freed, so 1585 were not freed. (static registrar)

After:

    There were 258066 MonoObjects created, 246781 MonoObjects freed, so 11285 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 204491 MonoObjects freed, so 1313 were not freed. (static registrar)
2021-05-31 08:02:45 +02:00
Rolf Bjarne Kvinge 6a83ed9169
[runtime] The return value from mono_class_from_mono_type must be released. (#11729)
Before:

    There were 258042 MonoObjects created, 235166 MonoObjects freed, so 22876 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 204219 MonoObjects freed, so 1585 were not freed. (static registrar)

After:

    There were 258050 MonoObjects created, 235177 MonoObjects freed, so 22873 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 204219 MonoObjects freed, so 1585 were not freed. (static registrar)
2021-05-31 08:02:11 +02:00
Rolf Bjarne Kvinge c12cb23414
[dynamic registrar] Out parameters must be released. (#11727)
Before:

    There were 258042 MonoObjects created, 235166 MonoObjects freed, so 22876 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 204219 MonoObjects freed, so 1585 were not freed. (static registrar)

After:

    There were 258058 MonoObjects created, 235308 MonoObjects freed, so 22750 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 204219 MonoObjects freed, so 1585 were not freed. (static registrar)
2021-05-31 08:01:24 +02:00
Rolf Bjarne Kvinge dc30bdf220
[registrar] Make sure to release the return value from xamarin_get_parameter_type. (#11725)
Before:

    There were 258046 MonoObjects created, 235142 MonoObjects freed, so 22904 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 204193 MonoObjects freed, so 1611 were not freed. (static registrar)

After:

    There were 258054 MonoObjects created, 235172 MonoObjects freed, so 22882 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 205190 MonoObjects freed, so 614 were not freed. (static registrar)
2021-05-28 16:19:47 +02:00
Rolf Bjarne Kvinge 57288a5ad4
[registrar] Return values from mono_value_box must be released. (#11708)
Before:

    There were 258046 MonoObjects created, 235142 MonoObjects freed, so 22904 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 204193 MonoObjects freed, so 1611 were not freed. (static registrar)

After:

    There were 258054 MonoObjects created, 235172 MonoObjects freed, so 22882 were not freed. (dynamic registrar)
    There were 205804 MonoObjects created, 204193 MonoObjects freed, so 1611 were not freed. (static registrar)
2021-05-27 16:43:11 +02:00
Rolf Bjarne Kvinge 013be35fc9
[runtime] Skip custom command line argument parsing for macOS and Mac Catalyst. (#11705)
Due to the following reasons:

* Desktop apps like macOS and Mac catalyst can be launched directly from the
  command line by users.
* It's trivial to set environment variables for desktop apps before launching
  them.
* All the different command line arguments we support for mobile targets can
  also be set using environment variables.

We don't need additional command line argument parsing for desktop platforms,
so just remove it.

The end result is that instead of doing this to run a specific unit test:

     path/to/macOS/app/MacOS/Contents/theapp --app-arg --test --app-arg MyTestFixture

This will now work:

     path/to/macOS/app/MacOS/Contents/theapp --test MyTestFixture

Which is how apps on desktop platforms should work anyway.
2021-05-27 16:42:09 +02:00
Rolf Bjarne Kvinge ba4fa19267
[runtime] Intercept the objc_msgSend family of functions using CoreCLR's supported mechanisms. (#11692)
This allows us to re-introduce a few tests.
2021-05-27 07:29:39 +02:00
Rolf Bjarne Kvinge 80c755ee2e
[runtime] Return values from mono_array_get must be released. (#11683)
Before:

    There were 257927 MonoObjects created, 144942 MonoObjects freed, so 112985 were not freed. (dynamic registrar)
    There were 205700 MonoObjects created, 113865 MonoObjects freed, so 91835 were not freed. (static registrar)

After:

    There were 257931 MonoObjects created, 235062 MonoObjects freed, so 22869 were not freed. (dynamic registrar)
    There were 205700 MonoObjects created, 203983 MonoObjects freed, so 1717 were not freed. (static registrar)
2021-05-26 15:09:51 +02:00
Rolf Bjarne Kvinge a266fd7ce7
[runtime] Don't include a workaround for a ancient bug anymore in .NET. (#11669)
The workaround doesn't work anymore anyway, this is printed on every launch:

> MonoTouch: Could not install sigaction override, unexpected sigaction implementation.

Ref: 054bbdce96
2021-05-25 21:30:35 +02:00
Rolf Bjarne Kvinge 5a0600491c
[runtime] Add support for tracking created and destroyed MonoObject* instances for CoreCLR. (#11657)
* [runtime] Add support for tracking created and destroyed MonoObject* instances for CoreCLR.

Implement a rudimentary way of tracking created and destroyed MonoObject*
instances, so that it's easy to find leaks.

* Add a xamarin_bridge_shutdown method that's called just before returning from xamarin_main.

And use it to dump the leaked MonoObject*s.
2021-05-25 08:19:27 +02:00
Rolf Bjarne Kvinge a447b3498a
[runtime/src] Update a few comments. (#11650) 2021-05-21 15:53:50 +02:00
Rolf Bjarne Kvinge 519c2f036f
[runtime] Fix typo in error message (#11651) 2021-05-21 15:53:10 +02:00
Rolf Bjarne Kvinge 279190e849
[runtime] Fix typo in logging statement (#11645) 2021-05-21 07:54:42 +02:00
Rolf Bjarne Kvinge 0dee77cd83
[runtime] Deal with the rest of the Mono Embedding API for CoreCLR. (#11642)
* [runtime] Mark numerous Mono Embedding API as used only by the MonoVM bridge.

* [runtime] Exclude more unused code from the CoreCLR build.

* There's no tracing in CoreCLR, so no need to process the MONO_TRACE environment
  variable (and set the trace options).
* There's no sdb debuggger, so that code can be skipped.
* The profiler support is very different, so skip that code too.
* We don't support AOT, nor aot data files, so skip that.

* [runtime] Stop generating dummy implementations of the Mono Embedding API for CoreCLR.

All of the Mono Embedding API now falls in either of these two categories:

* Only used by the MonoVM bridge.
* Has a CoreCLR implementation.

Which means that we don't need the code to generate dummy implementations for
methods that aren't in any of these two categories anymore.
2021-05-21 07:53:41 +02:00
Rolf Bjarne Kvinge fdf6b7f0cc
[runtime] Re-implement code that fetches the assembly name to use existing API implemented by CoreCLR. (#11612)
* [runtime] Re-implement code that fetches the assembly name to use existing API implemented by CoreCLR.

* Keep the MonoVM implementation as-is.
2021-05-20 19:04:58 +02:00
Rolf Bjarne Kvinge f8a19c7cbf
[runtime] Remove the declarations for mono_jit_parse_options and mono_gc_max_generation. (#11617)
We don't used these mono functions anymore.
2021-05-20 07:35:38 +02:00
Rolf Bjarne Kvinge f38187f054
[runtime] Refactor the toggle ref code to separate MonoVM-specific code and generic logic. (#11616)
This makes it simpler to impement the toggle ref logic for CoreCLR once we can
do that.
2021-05-20 07:35:23 +02:00
Rolf Bjarne Kvinge a6f0dbdd67
[runtime] Fix declaration of xamarin_bridge_get_method_declaring_type. (#11614)
The native xamarin_bridge_get_method_declaring_type method and the
corresponding managed method (GetMethodDeclaringType) takes and returns a
MonoObject*, not a GCHandle.

Due to the wonders of void pointers, this worked just fine before - there's no
actual change to the compiled code - but the code is now more consistent and
less confusing.
2021-05-20 07:34:17 +02:00
Rolf Bjarne Kvinge d60514b02b
[runtime] Postpone implementing mono_domain_set_config for CoreCLR. (#11610) 2021-05-20 07:33:26 +02:00
Rolf Bjarne Kvinge a33a86a9b7
[runtime] Implement mono_get_exception_out_of_memory for CoreCLR. (#11608) 2021-05-20 07:33:16 +02:00
Rolf Bjarne Kvinge 4dc2ef7da9
[runtime] Be a bit defensive after handling Objective-C exceptions and return a consistent value. (#11601)
The value should never be used if everything is working fine, but if something
is wrong, then this value will at least get consistent behavior.

The visible result for us right now is that monotouch-test will fail with a
test failure instead of crashing.
2021-05-19 07:35:46 +02:00
Rolf Bjarne Kvinge 022fa9c697
[runtime] Throw a runtime exception instead of execution engine exception. (#11599)
* One less Mono Embedding method used: good for CoreCLR.
* More consistent with the rest of our code / behavior.
2021-05-19 07:34:13 +02:00
Rolf Bjarne Kvinge 4cb58b0225
[CoreCLR] Disable debug spew by default. (#11595)
It just ends up flooding everything now because of the progress made.
2021-05-18 18:33:04 +02:00
Sebastien Pouliot bab6827b8d
[dotnet][linker] Eliminate code that is only required for CoreCLR on iOS and tvOS (#11577)
CoreCLR is being added for macOS only. We can eliminate a lot of recent
code additions (about half a megabyte in the past week) by eliminate code
branches under `if (IsCoreCLR)`.

Unlike handling (non required at runtime) custom attributes the
`ILLink.Substitutions.xml` will vary quite a bit across platforms so we
use a unique file for each platform.
2021-05-18 09:33:41 -04:00
Rolf Bjarne Kvinge ab14e07146
[runtime] Implement mono_class_value_size for CoreCLR. (#11554) 2021-05-14 15:19:34 +02:00
Rolf Bjarne Kvinge eab3accf26
[runtime] Implement mono_class_is_enum and mono_class_enum_basetype for CoreCLR. (#11553)
* [runtime] Implement mono_class_is_enum for CoreCLR.

* [runtime] Implement mono_class_enum_basetype for CoreCLR.
2021-05-14 15:19:23 +02:00