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

693 Коммитов

Автор SHA1 Сообщение Дата
Rolf Bjarne Kvinge f557936e9c
[runtime] Use the correct underlying types for our own nfloat/n(u)int types. (#12714)
Defining xm_nint_t to be 32-bit sized only on i386 is not the right thing to do for armv7.

Strangely enough this caused just a single test failure:

    MonoTouchFixtures.Foundation.CalendarTest
        [FAIL] TestFindNextDateAfterDateMatching :   Expected: <Foundation.MonoTouchException>
            But was:  null
            at MonoTouchFixtures.Foundation.CalendarTest.TestFindNextDateAfterDateMatching()

and that happened because:

1. We use a wrapper function around objc_msgSend:

    void *
    xamarin_IntPtr_objc_msgSend_IntPtr_IntPtr_nuint_exception (id self, SEL sel, void * p0, void * p1, xm_nuint_t p2, GCHandle *exception_gchandle)
    {
    	@try {
    		return ((func_xamarin_IntPtr_objc_msgSend_IntPtr_IntPtr_nuint_exception) objc_msgSend) (self, sel, p0, p1, p2);
    	} @catch (NSException *e) {
    		xamarin_process_nsexception_using_mode (e, true, exception_gchandle);
    		return NULL;
    	}
    }

2. Note that the second to last argument is an 'xm_nuint_t'. We told the
   native compiler this was a 64-bit value, when the managed P/Invoke would
   give it a 32-bit value. This had no effect on the 'p2' parameter, but it
   meant that clang would thing the next argument, 'exception_gchandle', would
   be somewhere it wasn't (the managed function would pass two 32-bit values,
   'p2' and 'exception_gchandle', which clang would merge into a single 64-bit
   'p2' argument, and then read random stuff for 'exception_gchandle').

3. Finally things would go sideways when we caught the exception and passed
   'exception_gchandle' to xamarin_process_nsexception_using_mode. In effect
   we'd ask xamarin_process_nsexception_using_mode to store the resulting
   gchandle in random memory. Amazingly it only resulted in a test failure
   (because upon return the managed location for the 'exception_gchandle'
   wasn't touched, and would have its initial value of 0, thus managed code
   would think no exception occurred).

So fix this to use the correct underlying types, instead of trying to figure
out the correct #if condition.

I'm not sure why we're using our own types here anyways, but this fix is the
smallest.
2021-09-15 09:17:43 +02:00
Rolf Bjarne Kvinge 048bee7080
[generator] Simplify native enums logic. (#12473)
Instead of generating one native P/Invoke signature with an int parameter and
another with a long parameter for methods that take [Native] enums, generate a
single nint parameter (and the same for the unsigned version).

This simplifies both the generator code and the generated code. The generator
diff contains *a lot* of changes like this:

    -	if (IntPtr.Size == 8) {
    -		ret = (ARAppClipCodeUrlDecodingState) global::ObjCRuntime.Messaging.Int64_objc_msgSend (this.Handle, Selector.GetHandle ("urlDecodingState"));
    -	} else {
    -		ret = (ARAppClipCodeUrlDecodingState) global::ObjCRuntime.Messaging.int_objc_msgSend (this.Handle, Selector.GetHandle ("urlDecodingState"));
    -	}
    +	ret = (ARKit.ARAppClipCodeUrlDecodingState) (long) global::ObjCRuntime.Messaging.nint_objc_msgSend (this.Handle, Selector.GetHandle ("urlDecodingState"));

An unlinked Xamarin.iOS.dll is ~300kb smaller (once linked the difference
should be minimal though).

I also made the min/max detection logic (check for int32.MinValue/MaxValue and
convert to int64.MinValue/MaxValue) specific to ARCH_32, since we don't need
it in 64-bit code.
2021-08-19 16:59:07 +02:00
Rolf Bjarne Kvinge 16ff955913
[runtime] Set the RUNTIME_IDENTIFER and APP_CONTEXT_BASE_DIRECTORY app context values. Fixes #12444. (#12446)
Mono and CoreCLR need this.

Fixes https://github.com/xamarin/xamarin-macios/issues/12444.
2021-08-17 15:30:27 +02:00
Rolf Bjarne Kvinge 7f5fcfc88b
[runtime] Skip early from xamarin_pinvoke_override to avoid a later logging statement. (#12443)
This avoids unnecessary and confusing logging which apparently claims that we
couldn't find a symbol, when we didn't even try (on purpose).
2021-08-17 08:05:18 +02:00
Rolf Bjarne Kvinge 2972e1b715
Fix some whitespace issues in various files. (#12399)
* Remove BOM
* Add EOL at end of file.
2021-08-11 10:06:46 +02:00
Rolf Bjarne Kvinge fb63f2388a
[runtime] Add support for logging exceptions that go through exception marshalling using an environment variable. Fixes #12343. (#12344)
Setting the XAMARIN_LOG_MARSHALLED_EXCEPTIONS environment variable will now
make us print all exceptions that go through exception marshalling, and how
we'll handle them.

Fixes https://github.com/xamarin/xamarin-macios/issues/12343.
2021-08-05 08:17:20 +02:00
Manuel de la Pena 9aef167b19
[PHASE] Add suppport for Xcode13 beta 2. (#12098) 2021-08-04 22:38:03 -04:00
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
Rolf Bjarne Kvinge 9a013fd4a7
[runtime] Implement xamarin_get_[nsnumber|nsvalue]_type for CoreCLR. (#11552)
* Remove a few unused xamarin_get_*_class functions.
* Make the remaining two (xamarin_get_[nsnumber|nsvalue]_type) return a
  MonoType* instead of MonoClass* - that makes things slightly simpler for
  CoreCLR (the MonoClass* return values from the previous functions were
  always converted to MonoType*s anyway).
* Implement the xamarin_get_[nsnumber|nsvalue]_type functions.
* Make the existing mono_get_string_class use the new (and more generic)
  xamarin_bridge_lookup_class method instead of the specific
  xamarin_bridge_get_string_class (which can now be removed).
2021-05-14 07:29:48 +02:00
Rolf Bjarne Kvinge 42740a5c95
[runtime] Make xamarin_bridge_free_mono_signature accept NULL signatures. (#11550) 2021-05-14 07:28:53 +02:00
Rolf Bjarne Kvinge adb355b757
[runtime] Add support for creating managed exceptions from native code for CoreCLR. (#11538) 2021-05-14 07:27:42 +02:00
Rolf Bjarne Kvinge 5795a62f77
[runtime] Implement mono_method_full_name for CoreCLR. (#11536) 2021-05-13 22:04:09 +02:00
Rolf Bjarne Kvinge 0a0a849b02
[runtime] Implement mono_class_is_nullable for CoreCLR. (#11528) 2021-05-13 22:03:22 +02:00
Rolf Bjarne Kvinge 427c5447db
[tools] Make exception marshalling the default for CoreCLR (and make it an error to choose otherwise). (#11535)
* Make 'throw Objective-C exception' the default for managed exception marshalling.
* Make 'throw managed exception' the default for Objective-C exception marshalling.
* Disallow the 'unwind through native frames' option: CoreCLR won't do it.
* Disallow the 'unwind through managed frames' option: it's the safeset
  option by far, and also matches the reverse case.
* Disallow the 'disable' option: this is also not safe, let's try to go the
  safe route with CoreCLR.
* Change the default in native code too.

Partial fix for #10940.
2021-05-13 20:59:18 +02:00
Rolf Bjarne Kvinge 83dbeda8c6
[runtime] Refactor xamarin_get_nsnumber_converter to use string comparisons instead of mono_type_get_type. (#11530)
This makes it easier for CoreCLR. Also, at least for CoreCLR, it's unlikely to
be slower, since we'd have to compute the MONO_TYPE_* value in any
compatibility function.
2021-05-13 20:56:02 +02:00
Rolf Bjarne Kvinge 64e19d2d34
[runtime] Implement mono_class_get_nullable_param for CoreCLR. (#11531) 2021-05-13 20:39:07 +02:00
Rolf Bjarne Kvinge 95dfc4fa39
[runtime] Implement mono_value_box for CoreCLR. (#11533) 2021-05-13 20:38:21 +02:00
Rolf Bjarne Kvinge 8f1f367424
[runtime] Fix call to xamarin_print_all_exceptions. (#11532)
Passing a 'MonoObject*' to a function that expects a GCHandle doesn't quite
work, so make sure to get a GCHandle for the exception we want to print
information about.
2021-05-13 20:38:12 +02:00
Rolf Bjarne Kvinge 751976a769
[CoreCLR] Stub out mono_runtime_set_pending_exception for CoreCLR. (#11521)
We need additional API in CoreCLR to support pending exception properly, and
this is in progress [1]. In the meantime, stub out parts of it, so that the
process doesn't abort. This way we'll have failing tests instead (and work in
other areas can progress, since the process doesn't abort).

[1]: https://github.com/dotnet/runtime/pull/52146
2021-05-13 07:12:17 +02:00
Rolf Bjarne Kvinge 6bc3d97908
[runtime] Implement functions for getting and setting array elements for CoreCLR. (#11519)
This is not the fastest implementation, but it's the simplest I could come up
with, with the target of sharing as much code as possible with MonoVM. It can
be improved later if we find out it's a slow path (these functions are not in
a common code path, very few API bindings end up here).
2021-05-13 07:11:49 +02:00
Rolf Bjarne Kvinge 39b0ca4934
[runtime] Implement mono_reflection_type_get_type for CoreCLR. (#11513)
This also meant reviewing calling code to make sure that the return value is
released when it should be.
2021-05-12 23:37:40 +02:00
Rolf Bjarne Kvinge b4fd5f1e63
[runtime] Implement mono_get_string_class for CoreCLR. (#11514) 2021-05-12 15:22:11 +02:00
Rolf Bjarne Kvinge 6e9d9b483d
[runtime] Implement mono_array_new and mono_array_length for CoreCLR. (#11515)
* [runtime] Implement mono_array_new for CoreCLR.

* [runtime] Implement mono_array_length for CoreCLR.
2021-05-12 15:21:56 +02:00
Rolf Bjarne Kvinge a3932e8765
Improve support for ARM64 on macOS. (#11501)
* Implement our xamarin_dyn_objc_msgSend[Super] overrides for ARM64.
* Modify mmp to use those overrides.
* Fix an issue with the existing xamarin_arm64_common_trampoline that caused
  exceptions to not unwind correctly.
* Add an ARM64 variation of xammac tests in xharness.
* Various test fixes.
2021-05-12 07:35:10 +02:00
Rolf Bjarne Kvinge af41f128de
[runtime] Implement mono_class_get_element_class for CoreCLR. (#11500) 2021-05-12 07:31:26 +02:00
Rolf Bjarne Kvinge a09a7d2523
[runtime] Implement the mono_g_hash_table functions for CoreCLR. (#11495) 2021-05-11 22:16:41 +02:00
Rolf Bjarne Kvinge dceb95e912 [runtime] Implement xamarin_dyn_objc_msgSend for ARM64. 2021-05-11 15:54:39 +02:00
Rolf Bjarne Kvinge a84d52f94e [runtime] Add correct prologue/epilogue to xamarin_arm64_common_trampoline
Also add Call Frame Information (CFI) / Canonical Frame Address (CFA) directives.

This is required for native exceptions to work properly (otherwise the native runtime
won’t be able to unwind stack frames correctly).
2021-05-11 15:54:39 +02:00
Rolf Bjarne Kvinge 178d9ae2ea [runtime/tools] Use the newly implemented objc_msgSend overrides for ARM64. 2021-05-11 15:54:39 +02:00
Rolf Bjarne Kvinge 8bb65492ec
[runtime] Implement mono_string_new and mono_string_to_utf8 for CoreCLR. (#11492)
* [runtime] Implement mono_string_to_utf8 for CoreCLR.

* [runtime] Implement mono_string_new for CoreCLR.
2021-05-11 15:16:01 +02:00
Rolf Bjarne Kvinge feed3b2636
[runtime] Implement mono_object_unbox for CoreCLR. (#11493) 2021-05-11 15:15:41 +02:00
Rolf Bjarne Kvinge 5692f34d4e
[runtime] Implement mono_class_get_type for CoreCLR. (#11494)
This also meant reviewing calling code to make sure that the return value is
released when it should be.
2021-05-11 15:15:03 +02:00
Rolf Bjarne Kvinge 88b8c332a7
[runtime] Implement mono_method_get_object for CoreCLR. (#11488)
This also meant reviewing calling code to make sure that the return value is
released when it should be.
2021-05-11 07:21:18 +02:00
Rolf Bjarne Kvinge e4fbc5198b
[runtime] Implement several xamarin_is_class_* variants for CoreCLR. (#11481)
When using the MonoVM, we compare MonoClass instances by pointer. This turns
out a bit complicated for CoreCLR, because our MonoClass instances are not
unique (there can be multiple MonoClass instances that refer to the same
type), so instead implement helper methods that do the comparison. This also
has the benefit of not requiring any memory allocations on CoreCLR.
2021-05-10 23:12:52 +02:00
Rolf Bjarne Kvinge 3623a13ab2
[runtime] Implement a managed implementation of a mono_reference_queue for CoreCLR. (#11487)
Also remove the declaration of mono_gc_reference_queue_free, it's never called.
2021-05-10 23:09:39 +02:00
Rolf Bjarne Kvinge 8fc51f7e8e
[runtime] Implement mono_type_get_object for CoreCLR. (#11484) 2021-05-10 15:38:13 +02:00
Rolf Bjarne Kvinge c14fa03336
[runtime] Implement mono_class_is_[valuetype|byref] for CoreCLR. (#11482)
* [runtime] Implement mono_type_is_byref for CoreCLR.

* [runtime] Implement mono_class_is_valuetype for CoreCLR.
2021-05-10 15:10:03 +02:00
Rolf Bjarne Kvinge d89d97d1fe
[runtime] Implement mono_class_get_name[space] for CoreCLR. (#11483) 2021-05-10 14:42:47 +02:00
Rolf Bjarne Kvinge 695eb003fb
[runtime] Implement mono_thread_detach_if_exiting and mono_free for CoreCLR. (#11480)
* [runtime] Implement mono_free for CoreCLR.

* [runtime] Implement mono_thread_detach_if_exiting for CoreCLR.
2021-05-10 07:25:45 +02:00
Rolf Bjarne Kvinge f61cc98c53
[runtime] Implement mono_class_is_delegate for CoreCLR. (#11476) 2021-05-07 22:21:19 +02:00
Rolf Bjarne Kvinge 1a689d3b14
[runtime] Implement mono_class_from_mono_type for CoreCLR. (#11470) 2021-05-07 15:47:03 +02:00
Rolf Bjarne Kvinge 63db14ec7d
[runtime] Implement mono_method_signature and related signature methods for CoreCLR. (#11465) 2021-05-06 16:19:59 +02:00
Rolf Bjarne Kvinge c51cba525a
[runtime] Implement mono_runtime_invoke for CoreCLR. (#11439)
* [runtime] Implement mono_runtime_invoke for CoreCLR.

* [runtime] We always need a native xamarin_mono_object_retain function.
2021-05-06 07:25:43 +02:00
Rolf Bjarne Kvinge 50b68d4aab
[runtime] Print more information about the exception for unhandled managed exceptions. (#11440)
This eases debugging when trying to figure out what went wrong.
2021-05-05 16:31:03 +02:00
Rolf Bjarne Kvinge 81300576ff
[runtime] Implement mono_object_isinst for CoreCLR. (#11427) 2021-05-04 20:20:46 +02:00
Rolf Bjarne Kvinge 41bf71a0e2
[runtime] Implement mono_object_get_class for CoreCLR. (#11398) 2021-05-04 14:31:20 +02:00
Rolf Bjarne Kvinge 0285689aa3
[runtime] Never disable exception marshalling for CoreCLR. (#11407) 2021-05-04 08:28:34 +02:00
Rolf Bjarne Kvinge 14e76c0139
[runtime] Return the exception from wrapper methods for exception marshalling. (#11382)
There's no general way to set a pending managed exception in CoreCLR (the
current plan is to support setting a pending managed exception for the
objc_msgSend family of functions). This means that the way we've implemented
custom wrappers that can handle Objective-C exceptions won't work, because
those wrappers currently tries to set a pending managed exception (which Mono
throws upon returning from the corresponding native wrapper function).

So rewrite this a bit: these custom wrappers now return a GCHandle with the
managed exception as an out parameter, and the calling managed code throws
that exception instead.

This also required adjusting a few API definitions to match how their wrapper
functions are defined.
2021-05-04 08:25:38 +02:00
Rolf Bjarne Kvinge f0a0d08aeb
[runtime] Call into managed code to handle runtime exceptions. (#11381)
* [runtime] Call into managed code to handle runtime exceptions.

This makes things easier for CoreCLR.

There should be no significant performance hits; this code path is
exceptional, and exceptions are already very heavy-weight anyways.

* Update to use xamarin_free instead of mono_free as per review.

* Port more to managed code.
2021-05-04 08:19:46 +02:00
Rolf Bjarne Kvinge 8e9f86aad8
[runtime] Implement mono_method_get_class for CoreCLR. (#11389) 2021-04-30 07:53:30 +02:00
Rolf Bjarne Kvinge 655f2f921f
[runtime] Implement xamarin_get_reflection_method_method for CoreCLR. (#11383) 2021-04-30 07:49:25 +02:00
Rolf Bjarne Kvinge 174bafe9b0
[runtime] MapKit is available on macOS/arm64. (#11363) 2021-04-29 14:45:58 +02:00
Rolf Bjarne Kvinge fdd386b68f
[runtime] Remove dead code. (#11354)
Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
2021-04-29 13:56:54 +02:00
Rolf Bjarne Kvinge a01a96a407
[runtime] Implement xamarin_[get|set]_flags_for_nsobject. (#11347) 2021-04-28 07:40:43 +02:00
Rolf Bjarne Kvinge 2b0a9f5bc1
[CoreCLR] Implement xamarin_get_nsobject_handle. (#11346) 2021-04-28 07:34:57 +02:00
Rolf Bjarne Kvinge e4960ad9e3
[dotnet] Build the partial static registrar for CoreCLR. (#11345)
* The generated static registration code will eventually be different.
* The generated code has to be compiled with different compiler flags.

This also required adding a new overload of xamarin_mono_object_release for the generated
code to compile.
2021-04-28 07:34:40 +02:00
Rolf Bjarne Kvinge 43f1d02dae
[CoreCLR] Implement xamarin_gchandle_get_target. (#11333)
This also meant reviewing calling code to make sure that MonoObject*s are
released when they should be, which meant reviewing every method that returns
a MonoObject*, and release the result.
2021-04-27 14:59:03 +02:00
Rolf Bjarne Kvinge 7b5a1c251c
[runtime] There's no need to attach/detach the current thread in CoreCLR. (#11307) 2021-04-26 07:46:55 +02:00
Rolf Bjarne Kvinge 5d42c933f1
[runtime] Move xamarin_create_managed_ref internal call to managed code. (#11271)
Move the xamarin_create_managed_ref internal call to managed code, to ease things
with CoreCLR.

In order to preserve performance, this wasn't a straight forward port.

* monotouch_create_managed_ref used to detect if there already was a GCHandle for
  a native object. To avoid a managed->native transition, this logic has now been
  moved into the code that sets the GCHandle (the xamarinSetGCHandle🎏 / xamarin_set_gchandle_trampoline
  code), and these methods return a value saying whether the GCHandle was set or
  not.

* xamarin_create_gchandle will check the retain count to determine whether to create
  a weak or a strong GCHandle for the managed object. In this particular case we
  should never need to create a strong GCHandle, which means that we don't need to
  check the retain count (saving a managed->native transition).

Using the new perftest (#11298), I get very similar numbers for both old code and new code: https://gist.github.com/rolfbjarne/e0fc2ae0f21da15062b4f051138679af (multiple runs). Sometimes the old code is faster, sometimes the new code is faster (although the old code tends to be the one who wins).

In any case there aren't any significant performance hits due to this change, so it should be good to go.
2021-04-23 18:42:11 +02:00
Rolf Bjarne Kvinge e2082fd04c
[CoreCLR] Implement mono_jit_exec. (#11264)
This required adding a helper method to get the assembly name for a given
MonoAssembly, since that's what CoreCLR uses to determine what to execute.

Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
2021-04-22 07:46:56 +02:00
Sebastien Pouliot 5accd102cf
[dotnet][tvos] Enable ICU (instead of using Invariant) and additional tests (#11247) 2021-04-21 20:19:05 -04:00
Rolf Bjarne Kvinge 6d127660d5
[runtime] Move the code to wrap every managed thread with an NSAutoreleasePool to the MonoVM bridge. (#11257)
The current implementation is MonoVM-specific, and won't work with CoreCLR
(something else will have to be implemented for CoreCLR, which is tracked
here: https://github.com/xamarin/xamarin-macios/issues/11256).
2021-04-21 16:21:09 +02:00
Rolf Bjarne Kvinge 320527a29b
[CoreCLR] Implement mono_assembly_get_object. (#11254) 2021-04-21 15:00:10 +02:00
dotnet-maestro[bot] e8f437319a
[main] Update dependencies from dotnet/installer (#11175)
* Update dependencies from https://github.com/dotnet/installer build 20210408.1

Microsoft.Dotnet.Sdk.Internal
 From Version 6.0.100-preview.3.21202.5 -> To Version 6.0.100-preview.4.21208.1

* Update dependencies from https://github.com/dotnet/installer build 20210409.4

Microsoft.Dotnet.Sdk.Internal
 From Version 6.0.100-preview.3.21202.5 -> To Version 6.0.100-preview.4.21209.4

* Update dependencies from https://github.com/dotnet/installer build 20210410.1

Microsoft.Dotnet.Sdk.Internal
 From Version 6.0.100-preview.3.21202.5 -> To Version 6.0.100-preview.4.21210.1

* same P4 specific fix as ccb43cba56
but the ICU support was added based on P3 but merged after ^

* Update dependencies from https://github.com/dotnet/installer build 20210412.5

Microsoft.Dotnet.Sdk.Internal
 From Version 6.0.100-preview.3.21202.5 -> To Version 6.0.100-preview.4.21212.5

* Update dependencies from https://github.com/dotnet/installer build 20210413.70

Microsoft.Dotnet.Sdk.Internal
 From Version 6.0.100-preview.3.21202.5 -> To Version 6.0.100-preview.4.21213.70

* Update dependencies from https://github.com/dotnet/installer build 20210414.14

Microsoft.Dotnet.Sdk.Internal
 From Version 6.0.100-preview.3.21202.5 -> To Version 6.0.100-preview.4.21214.14

* Update to new package names

Thanks @pjcollins for the heads up https://github.com/xamarin/xamarin-macios/pull/11175#issuecomment-819936692

* Update dependencies from https://github.com/dotnet/installer build 20210415.1

Microsoft.Dotnet.Sdk.Internal
 From Version 6.0.100-preview.3.21202.5 -> To Version 6.0.100-preview.4.21215.1

* Fix build (path changed to include '.mono')

* remove more '.mono' special case that are not needed anymore

* Update dependencies from https://github.com/dotnet/installer build 20210415.12

Microsoft.Dotnet.Sdk.Internal
 From Version 6.0.100-preview.3.21202.5 -> To Version 6.0.100-preview.4.21215.12

* Fix building apps (it now finds the native libs)

Credits to @filipnavara

8325f8dadc

* Add back IsTrimmable (or nothing gets linked)

* Update dependencies from https://github.com/dotnet/installer build 20210418.6

Microsoft.Dotnet.Sdk.Internal
 From Version 6.0.100-preview.3.21202.5 -> To Version 6.0.100-preview.4.21218.6

* Keep downloading the CoreCLR runtime packs.

* [runtime] Adjust the build to link with the correct runtime library for CoreCLR.

* [tests][monotouch-test] Ignore NSTimeZoneTest / All_28300 on dotnet as it hangs

Introduced with https://github.com/dotnet/runtime/pull/48931

Issue https://unicode-org.atlassian.net/browse/ICU-21591
PR https://github.com/unicode-org/icu/pull/1699

* [dotnet][msbuild] Add more (missing) '\'

Fix satellite/location assemblies and some unit tests

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Alex Soto <alex@alexsoto.me>
Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
Co-authored-by: Sebastien Pouliot <sebastien.pouliot@microsoft.com>
Co-authored-by: Sebastien Pouliot <sebastien.pouliot@gmail.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2021-04-20 09:09:56 -04:00
Sebastien Pouliot f85af095da
[dotnet] Add ICU support for iOS builds (#11163)
and re-enable some tests for dotnet

Part of the fix for https://github.com/xamarin/xamarin-macios/issues/8906

Known Issues
* [some Calendar are not the expected ones](https://github.com/dotnet/runtime/issues/50859)
* [No support for tvOS (bitcode)](https://github.com/dotnet/runtime/issues/48508)
2021-04-09 17:06:26 -04:00
Peter Collins 5c12fdfac9
[build] Use arcade dependency management tooling (#10890)
* [build] Use arcade dependency management tooling

* Apply feedback

* Apply second round of feedback

* Always make dotnet.config before trying to read it

* Debugging

* Update dependencies, trim tabs and spaces

* [dotnet] Remove the existing workload shipped with .NET and install our locally built ones.

The new version of .NET ships with our workloads, but those aren't
the workloads we want to use, so replace them with our own.

* Update .gitignores.

* Bump to 6.0.100-preview.3.21181.5

That required renaming simulator runtime packs...

* More rename for simulator packages

* moar (hopefully all)

* Bump to 6.0.100-preview.3.21201.11

This fix the issue with `Wait` that failed several tests in monotouch-tests

However it does not include the fix for AppConext.GetData on device (AOT)

Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
Co-authored-by: Sebastien Pouliot <sebastien@xamarin.com>
2021-04-02 00:02:27 -04:00
Rolf Bjarne Kvinge 7bc45c097a
[runtime] Don't start the toggle ref machinery in CoreCLR. (#10990)
The implementation will be completely different, where the hook into CoreCLR
is in managed code.

We still need to initialize the framework_peer_release_lock mutex, so move
that code out of gc_enable_new_refcount.
2021-03-30 18:06:23 -04:00
Rolf Bjarne Kvinge 6ce364860c
[CoreCLR] Implement xamarin_gchandle_new[_weakref] and xamarin_gchandle_free. (#10985) 2021-03-30 18:04:44 -04:00
Rolf Bjarne Kvinge 77b470cfaf
[CoreCLR] Implement mono_domain_get. (#10992) 2021-03-30 17:46:36 -04:00
Sebastien Pouliot b186bd675a
[dotnet] Call monovm_initialize before mono_jit_init (#11014)
Those are called respectively inside `xamarin_vm_initialize` and
`xamarin_bridge_initialize` functions.

This fix the **AppContext.GetData always return null for iOS** issue
https://github.com/dotnet/runtime/issues/50290

Thanks for @filipnavara for diagnosing this quicker than anyone else!

Added unit tests to ensure `AppContext.GetData` can read back the values
we're providing at startup.
2021-03-29 16:23:38 -04:00
Rolf Bjarne Kvinge a82575189b [CoreCLR] Add support for mono_assembly_open.
This includes going through all uses of mono_assembly_open, and make sure the release
the returned assembly.
2021-03-25 07:32:32 +01:00
Rolf Bjarne Kvinge 18ac48c5c8 [runtime] Make it possible to implement Mono Embedding API in the CoreCLR bridge
By making it possible to skip the automatically generated Mono Embedding API that
just asserts.
2021-03-25 07:32:32 +01:00
Rolf Bjarne Kvinge 2527679e34 [runtime] Add a MonoObject implementation for CoreCLR.
We need a way to represent a managed object in native code, and since most our existing
runtime code uses MonoObjects, we use the same for the CoreCLR bridge, just our own
version of it. In Mono, the MonoObjects are tracked by the GC (which scans the stack),
but we can't make CoreCLR scan the stack, so we use a reference counted version of
MonoObject instead - we just put the GCHandle into a reference counted MonoObject,
and when the MonoObject is freed, then we free the GCHandle as well.
2021-03-25 07:32:32 +01:00
Rolf Bjarne Kvinge 9a643594fb [runtime] Add support for generating managed delegates only for CoreCLR.
However, since our managed code is shared between CoreCLR and MonoVM, the best we
can do is to make these CoreCLR-only delegates .NET-only.
2021-03-25 07:32:32 +01:00
Rolf Bjarne Kvinge c8b6bc6c85
[dotnet] Build macOS/.NET for ARM64 as well. (#10959)
Partial fix for #10959.
2021-03-25 07:26:48 +01:00
Rolf Bjarne Kvinge 253061bf74
[runtime] Implement calling the managed Runtime.Initialize method from the CoreCLR bridge. (#10951)
* Move the existing logic to call Runtime.Initialize into the MonoVM code.
* Implement calling the managed Runtime.Initialize method from the CoreCLR bridge.

The call to Runtime.Initialize succeeds, which means we're now executing
managed code with CoreCLR for the first time.
2021-03-25 07:25:20 +01:00
Rolf Bjarne Kvinge 1b658149ff
[runtime] Fix argument name confusion in the xamarin_gchandle_new[_weakref] methods. (#10952)
This way the argument names match the argument names in the corresponding Mono Embedding API.

This is just an argument rename, no functional changes.
2021-03-24 17:38:01 +01:00
Rolf Bjarne Kvinge 3b2fa0d0b1
[runtime] Move the declaration of the MonoObject struct to MonoVM-specific code. (#10938)
The fields of the MonoObject struct is specific to MonoVM, so this makes sure
we don't accidentally poke into random memory on CoreCLR.

Co-authored-by: TJ Lambert <50846373+tj-devel709@users.noreply.github.com>
2021-03-24 14:55:03 +01:00
Rolf Bjarne Kvinge 43d3f8b0f5
[runtime] Make the exception_gchandle argument optional for callbacks to managed code in CoreCLR. (#10939)
If no exception handling is provided when calling a managed delegate from native
code, and the managed code throws, then we'll abort.

It's not entirely clear how we'll handle managed exceptions that go through native
code yet, so this makes the initial implementation easier. By making the exception
handling optional, it'll be easy to find all cases where we need to fix it later,
by making it non-optional. The alternative is to add exception handling code all
over the place that would potentially have to be updated when we figure out exactly
what needs to be done.
2021-03-24 09:26:31 +01:00
Rolf Bjarne Kvinge 9153edebda
[runtime] Redirect to our objc_msgSend wrapper functions when needed for .NET code. (#10932)
This makes the mono_dllmap_insert function unnecessary for .NET, so remove it.

Ref: https://github.com/dotnet/runtime/issues/48110
Ref: https://github.com/dotnet/runtime/issues/43204
Ref: #10504
2021-03-24 09:17:35 +01:00
Rolf Bjarne Kvinge b2248993de
[runtime] Don't register for GC callbacks with CoreCLR, this will be done in a completely different manner (through managed code). (#10931) 2021-03-23 07:35:38 +01:00
Rolf Bjarne Kvinge c406cc1da7
[runtime] Don't install any logging/printing handlers for CoreCLR, there's no equivalent. (#10927)
This also means that we don't have to generate CoreCLR wrappers for the corresponding
embedding API, so adjust the generated code accordingly.
2021-03-22 15:18:37 +01:00
Rolf Bjarne Kvinge d778cc28c8
[runtime/dotnet] Call coreclr_initialize/monovm_initialize at startup. (#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.
2021-03-22 08:04:56 +01:00
Rolf Bjarne Kvinge 307f97e529
[dotnet] Add a IsCoreCLR initialization flag. (#10900)
So that we can detect in managed code whether we're running with CoreCLR or
MonoVM.
2021-03-18 14:29:06 +01:00
Rolf Bjarne Kvinge af5651accf
[runtime] Move MonoVM-specific initialization to MonoVM-specific code. (#10899)
* [runtime] Download the CoreCLR embedding header file

* [runtime] Create VM-specific code and header files and include them in the build

* [runtime] Move MonoVM-specific initialization to MonoVM-specific code.
2021-03-18 07:23:39 +01:00
mathieubourgeois a921ee2fb1
Xamarin.Mac native Apple Silicon targetting support (#10115)
* Add support for Xamarin.Mac arm64

* Add compile product definition task

Xamarin.Mac can be provided with a ProductDefinition file for the generated pkg. Normally, providing a product definition was optional. However, with Apple Silicon, we have an extra issue : `productbuild` needs to know what architectures your package target. If not provided with them, it will guess to the best of its abilities. However, on Catalina and lower, the guess is x86_64, even if you have an arm64 slice. To fix this, we add a new task to compile the product definition and use this file to create the pkg. If you provide your own Product Definition, we can check and warn if the architectures don't match what we expect. If the file doesn't exist or there is no architecture, we set it ourselves based on our target architectures.

* Don't reference dynamic objC_send on arm64

When building in debug, we currently try to link dynamic objC_send symbols when targeting a 64-bit architecture. However, this is actually only defined on Intel architectures, not on arm64, so we end up failing because we're referring symbols that don't exist. Rework the `GetRequiredSymbols` to take an abi, and tag those symbols to only be valid on i386/x86_64, so they don't get referred at all when building on arm64, but still get referred in x86_64.

* Fix improper delete/move with already existing directories

* Fix stret requirement for Xamarin.Mac in arm64.

The generator supposes that we're running in x64 mode, refactor to take into account the possibility of running in arm64.

* Implement OS version generation in Product.plist, based on MinimumSystemVersion of the app

* Re-generalize some mmp registrar rules

`Microsoft.macOS.registrar` was missed by the current rule set

* Fix mmp tests

* Set E7072 as not translated

Tests were failing otherwise

* Rename Xamarin.Mac lib/x86_64 folder to 64bits (currently all targeted archs are the same)

* Fix style issues

* Fix `ToLower` usage for invariant usage

* Fix xtro-sharpie test
2021-03-17 21:48:02 -04:00
Rolf Bjarne Kvinge 46c999f0ad
[runtime] Resolve symlinks using API provided by NSString instead of Mono. (#10889)
Mono's way doesn't work with CoreCLR anyway.
2021-03-17 07:54:52 +01:00
Rolf Bjarne Kvinge ddf1645748
[runtime] Remove unnecessary cast (#10875) 2021-03-16 15:23:58 +01:00
Rolf Bjarne Kvinge 3087174202
[runtime] Use xamarin_gchandle_free instead of mono_gchandle_free. (#10874)
Our own functions support pointer-sized GCHandles, so this is one less place
to fix for CoreCLR.
2021-03-16 14:00:35 +01:00
Rolf Bjarne Kvinge bc340502fe
[runtime] Move parts of NSObject creation from native to managed. (#10869)
Move the creation of an uninitialized NSObject from native to managed, which:

* Removes the need for the mono_object_new Embedding API.
* Removes one location where we write to managed memory from native code (to
  write the handle + flags in the uninitialized NSObject).
* Makes things easier for CoreCLR.
2021-03-16 07:40:19 +01:00
Rolf Bjarne Kvinge a5f970069a
[runtime] Make xamarin_release_managed_ref a normal P/Invoke. (#10864)
* We already switch to GC Safe mode anyway, so there were no benefits from
  entering native code in a GC unsafe mode. In fact we used to switch to GC
  Safe mode for every statement in xamarin_release_managed_ref, and now we can
  execute everything in GC Safe mode without switching back and forth. This
  also means there should be no difference in behavior.

* All parameters are blittable, so there's no extra marshalling cost.

* Easier for CoreCLR.
2021-03-15 08:02:59 +01:00
Rolf Bjarne Kvinge 52aa993bba
[runtime] Move setting the NSObject flags in xamarin_create_managed_ref from native to managed code. (#10858)
* Less poking into managed memory from native code.
* Makes things easier for CoreCLR support.
2021-03-12 23:19:07 +01:00
Rolf Bjarne Kvinge 1003c987f2
[runtime] Move the call to Runtime.UnregisterNSObject from native to managed code. (#10857)
* Avoids a native->managed transition
* Avoids creating/destroying a GCHandle.
* Makes it possible to remove an argument from the call to
  xamarin_release_managed_ref.
* Makes things easier for CoreCLR.
2021-03-12 23:14:10 +01:00
Rolf Bjarne Kvinge 4e0978e46c
[runtime] Link the CoreCLR version of libxamarin with CoreCLR instead of Mono. (#10853)
* [runtime] Link the coreclr version of libxamarin with CoreCLR instead of Mono.

The diff might look a bit weird, because there's no changes specific to CoreCLR -
the difference is that we're in fact removing a special-case to link with Mono: we
used the DOTNET_$(rid)_LIBDIR variable to specify the directory where to find libcoreclr,
we now use DOTNET_CORECLR_$(rid)_LIBDIR when building for CoreCLR, but that's handled
by the default case, so no need to add any special casing. We still override DOTNET_osx-<arch>_LIBDIR
for MonoVM (no change needed for that).

* [runtime] Generate stubs for the mono embedding API when building for CoreCLR.

This makes libxamarin link successfully when building for CoreCLR.
2021-03-12 18:40:48 +01:00
Rolf Bjarne Kvinge e6247e0c6f
[runtime] Port the is_user_type function from native to managed code. (#10841)
* [runtime] Port the is_user_type function from native to managed code.

* This is a straight forward port of native code to managed code, and
  shouldn't have any significant side effects.

* Makes it possible to move more code from native to managed for
  xamarin_create_managed_ref and xamarin_release_managed_ref in the future.

* Update xtro.
2021-03-12 07:38:27 +01:00
Rolf Bjarne Kvinge e53176383e
[builds] Remove the code to optionally inject an x64 slice into our binaries. (#10846)
It's been disabled for a while, which indicates that Apple has fixed the issue
on their side, and we don't need this code anymore.
2021-03-12 07:38:07 +01:00
Rolf Bjarne Kvinge a392035fa7
[runtime] Move a few mono function declaration to the generated logic for mono function declarations instead of doing it manually. (#10849)
This makes things a little bit easier to when starting work with CoreCLR.
2021-03-12 07:37:27 +01:00
Rolf Bjarne Kvinge 4cfa6928ae
[runtime] Simplify the various print_all_exceptions methods a bit. (#10847)
Unify them into a single one (xamarin_print_all_exceptions), which takes the
GCHandle of the exception to create an NSString representation of.
2021-03-12 07:37:13 +01:00
Rolf Bjarne Kvinge 37723f600c
[runtime] Speed up make (#10848)
Make variables can have dashes, which means we don't have to convert dashes in
rids to underscores to be able to compose variable names.

This speeds up make because now we don't have to execute hundreds of
subprocesses when parsing the makefile.

Before:

    $ make -j16 > /dev/null && /usr/bin/time make && /usr/bin/time make && /usr/bin/time make
        2.11 real         0.57 user         1.26 sys
        2.15 real         0.57 user         1.28 sys
        2.17 real         0.58 user         1.30 sys

After:

    $ make -j16 > /dev/null && /usr/bin/time make && /usr/bin/time make && /usr/bin/time make
        0.52 real         0.18 user         0.25 sys
        0.52 real         0.18 user         0.25 sys
        0.52 real         0.18 user         0.26 sys

So now it's ~4x faster (1.6s) for make to figure out there's nothing to do.
2021-03-12 07:36:41 +01:00
Rolf Bjarne Kvinge 3af399e21f
[runtime] Remove unused mono functions. (#10825) 2021-03-11 08:48:17 +01:00
Rolf Bjarne Kvinge 4854d7b4da
[runtime] Simplify calls to xamarin_create_managed_ref. (#10826)
I don't see why we should avoid calling xamarin_create_managed_ref from
NSObject's managed code, and then immediately call xamarin_create_managed_ref
upon return from NSObject's managed code.

This code is old ([1]), and from my reading of it, there's no specific reason
it was done this way.

Simplify the logic to call xamarin_create_managed_ref from a single place
(NSObject's managed code).

[1]: e59c45d3f9
2021-03-11 08:47:36 +01:00