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

586 Коммитов

Автор SHA1 Сообщение Дата
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
Rolf Bjarne Kvinge a8b3d9c296
[runtime] Call into managed code to call GC.Collect instead of using embedding API. (#10828)
Any performance difference will be neglible compared to running the GC, so
there's no compelling reason to use the embedding API.

This makes things a bit easier with CoreCLR, since the new code works there too.

This also required a few changes in delegates.t4 to make code generation for
functions without arguments work correctly.
2021-03-11 07:37:45 +01:00
Rolf Bjarne Kvinge 0e79b58fa8
[registrar] Remove redundant call to xamarin_register_nsobject from the dynamic registrar. (#10817)
The ctor we just called called it already.

Also, the static registrar doesn't have this call, so the dynamic registrar
shouldn't need it either.
2021-03-10 16:49:11 +01:00
Rolf Bjarne Kvinge bff4c7b1c2
[runtime] Move some code from native to managed for xamarin_release_managed_ref. (#10814)
* Avoids one usage of xamarin_set_nsobject_flags (which pokes into managed
  memory from native code, which won't be possible with CoreCLR).

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

* Since the code order is exactly the same, it shouldn't have any other side
  effects.
2021-03-09 14:57:50 +01:00
Rolf Bjarne Kvinge b22e0c3a6f
[runtime] Reduce code duplication a little bit. (#10807) 2021-03-09 07:43:51 +01:00
Rolf Bjarne Kvinge bccef33d3f
[runtime] Build a new version of libxamarin specifically for CoreCLR. (#10798)
We're currently only building for macOS, but we'll eventually build for Mac
Catalyst as well.
2021-03-08 07:57:55 +01:00
Rolf Bjarne Kvinge 80ed9d81bc
Add configure option to disable building for legacy Xamarin. (#10773)
* Add configure option to disable building for legacy Xamarin.

This can greatly speed up the debug-edit-build cycle when doing .NET
development, since it cuts down the build time in half more or less.

* Bump maccore.

New commits in xamarin/maccore:

* xamarin/maccore@548fa45432 [mlaunch] Disable building mlaunch when not including the legacy Xamarin build. (#2403)

Diff: 0562e08b12..548fa45432
2021-03-04 09:07:44 +01:00
Rolf Bjarne Kvinge 363f4611db
Use our [OBJC_]CFLAGS when compiling code for macOS. (#10771)
This required fixing a couple of compiler warnings in code that's now compiled
with more warnings + warnings-as-errors enabled:

    launcher.m:188:48: error: implicit conversion changes signedness: 'int' to 'unsigned long' [-Werror,-Wsign-conversion]
            argv = (char **) malloc (sizeof (char *) * (n + 1));
                                                     ~  ~~^~~
    launcher.m:609:67: error: implicit conversion changes signedness: 'int' to 'unsigned long' [-Werror,-Wsign-conversion]
                    char **new_argv = (char **) malloc (sizeof (char *) * (new_argc + 1 /* null terminated */));
                                                                        ~  ~~~~~~~~~^~~
2021-03-03 21:41:39 +01:00