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

693 Коммитов

Автор SHA1 Сообщение Дата
Rolf Bjarne Kvinge fc6ce95b52
[runtime] Convert the bindings-generator.csproj project to a .NET project. (#20743) 2024-06-19 15:11:28 +02:00
Rolf Bjarne Kvinge 1216646909
[runtime] Use strnlen instead of strlen. (#20702)
Apparently it's safer.
2024-06-10 13:02:42 +02:00
Rolf Bjarne Kvinge 34f58bbed4
[runtime] Use calloc instead of malloc. (#20692)
It's safer, since the returned memory is zero-initialized.

Also add tests.
2024-06-07 16:56:54 +02:00
Rolf Bjarne Kvinge 3ee3d44c17
[runtime] Remove dead code. (#20655) 2024-05-29 20:15:08 +02:00
Rolf Bjarne Kvinge a0b858ad47
[runtime] Call mono_unhandled_exception to raise AppDomain.UnhandledException. (#20656)
Call mono_unhandled_exception to raise AppDomain.UnhandledException when
managed exceptions are unhandled.

Partial fix for #15252 (for MonoVM, still pending for CoreCLR, which
needs https://github.com/dotnet/runtime/issues/102730 fixed first).
2024-05-29 20:14:47 +02:00
Rolf Bjarne Kvinge 536f0a1ab7
[runtime] Add support for additional type encodings. Fixes #18562. (#20521)
Fixes https://github.com/xamarin/xamarin-macios/issues/18562.
2024-05-23 16:21:43 +02:00
Rolf Bjarne Kvinge 7e8e887d5d
[runtime] Throw exception for condition we don't handle in the dynamic registrar. (#20568)
Throw an exception for a condition we don't handle in the dynamic registrar:
calling a base Objective-C constructor (init method) with arguments. Our
current implementation to call the base Objective-C constructor doesn't handle
any arguments, so if the method actually takes any arguments, those will just
be random memory. In other words: a consistent exception is better than a
random invalid memory access.
2024-05-20 18:57:42 +02:00
Rolf Bjarne Kvinge 350f597250
[runtime] Fix memory leak with BlockLiteral descriptors. Fixes #20503. (#20556)
We're using two different functions to atomically decrement a reference count,
the native `atomic_fetch_sub` and the managed `Interlocked.Decrement`.

Unfortunately the return value is not the same: `atomic_fetch_sub` returns the
original value before the subtraction, while `Interlocked.Decrement` returns
the subtracted value, while our code assumed the functions behaved the same.
This resulted in a memory leak, because we'd incorrectly expect `0` to be
returned from `atomic_fetch_sub` when the reference count reaches zero, and
thus not detect when the descriptor a block should be freed.

The fix is to update the expected return value from `atomic_fetch_sub` to be
`1` instead of `0`.

Fixes https://github.com/xamarin/xamarin-macios/issues/20503.
2024-05-06 09:05:58 +02:00
Rolf Bjarne Kvinge d794245b42
[runtime] Fix conserving stack trace when re-throwing marshalled exceptions. Fixes #19417. (#20316)
The stack trace from unhandled exception is now:

    Unhandled managed exception: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index') (System.ArgumentOutOfRangeException)
       at System.Collections.Generic.List`1[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].get_Item(Int32 index)
       at CrashiOS.RootViewController.GetItem() in /Users/rolf/test/bugs/StackTraceIssue/CrashiOS/RootViewController.cs:line 19
       at CrashiOS.RootViewController.<.ctor>b__1_0(Object _, EventArgs _) in /Users/rolf/test/bugs/StackTraceIssue/CrashiOS/RootViewController.cs:line 12
       at UIKit.UIBarButtonItem.Callback.Call(NSObject sender) in xamarin-macios/src/UIKit/UIBarButtonItem.cs:line 33
    --- End of stack trace from previous location ---
       at ObjCRuntime.Runtime.ThrowException(IntPtr gchandle) in xamarin-macios/src/ObjCRuntime/Runtime.cs:line 2655
       at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in xamarin-macios/src/UIKit/UIApplication.cs:line 64
       at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in xamarin-macios/src/UIKit/UIApplication.cs:line 96
       at Program.<Main>$(String[] args) in /Users/rolf/test/bugs/StackTraceIssue/CrashiOS/Main.cs:line 26

as opposed to:

    Unhandled managed exception: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index') (System.ArgumentOutOfRangeException)
       at ObjCRuntime.Runtime.ThrowException(IntPtr gchandle)
       at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName)
       at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)
       at Program.<Main>$(String[] args) in /Users/rolf/test/bugs/StackTraceIssue/CrashiOS/Main.cs:line 26

Fixes https://github.com/xamarin/xamarin-macios/issues/19417.
2024-03-18 15:02:12 +01:00
Rolf Bjarne Kvinge 9b8869b221
[runtime] Detect recursion when handling unhandled Objective-C exceptions. Fixes #14796. (#20276)
Detect recursion when handling unhandled Objective-C exceptions, which can happen if:

* We install a handler for unhandled Objective-C exceptions.
* An unhandled Objective-C exception is caught.
* We convert the unhandled Objective-C exception to a managed exception, and throw that.
* Nobody handles the managed exception either, so we convert it to an Objective-C exception and throw that.
* We re-enter the unhandled Objective-C exception handler, and the cycle continues.
* Eventually the process crashes due to a stack overflow.

Fixes https://github.com/xamarin/xamarin-macios/issues/14796.
2024-03-13 11:16:02 +01:00
Rolf Bjarne Kvinge a5fc5c1a88
[runtime] Fix min OS versions in various compiler and linker arguments. (#20275)
Once upon a time we needed to special case a higher min OS version that the
min OS version we supported for certain compiler/linker arguments, because we
used features not supported in the min OS version we supported.

That time has passed; in all cases our min OS version is now higher than the
special-cased min OS versions passed to native compilers/linkers, so we can
just use the actual min OS version we support.
2024-03-08 07:26:41 +01:00
Rolf Bjarne Kvinge dbbf9c3d86
[runtime] Don't register Runtime.CreateDelegateProxy when using the managed static registrar. (#20164)
It'll never be called from the generated code from the managed static
registrar, so there's no need to register it as a potential callback from
native code.

This makes the linker able to remove the Runtime.CreateDelegateProxy method
(and a few other methods as well) when using the managed static registrar (and
thus not warn about these methods doing un-trimmable stuff).

Contributes towards #10405.
2024-02-22 08:51:34 +01:00
Rolf Bjarne Kvinge b1cd69220f
[runtime] Don't register Runtime.GetGenericMethodFromToken when the managed static registrar is used. (#20144)
It'll never be called from the generated code from the managed static
registrar, so there's no need to register it as a potential callback from
native code.

This makes the linker able to remove the Runtime.GetGenericMethodFromToken
method (and a few other methods as well).

Contributes towards #10405.
2024-02-20 16:47:13 +01:00
Rolf Bjarne Kvinge 21705ee361
[runtime] Use objc_[retain|release|autorelease] instead of sending messages. (#19415)
Calling the direct functions instead of sending messages is slightly faster,
and additionally it may make some static analyzers think we've enabled ARC for
our Objective-C code (which we don't, because we need to manually manage
reference counting).

These direct functions aren't in any public header (they're in a private header),
but they're documented as part of ARC here: https://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime-support,
and clang emits references to these methods from user code, so it should be safe for us to use them.

Fixes https://github.com/xamarin/xamarin-macios/issues/19413.
2023-11-14 07:42:55 +01:00
Haritha Mohan da08b89077
[build] Add support for worktree checkouts (#19240)
Was messing around with worktrees but our repo failed to build due to
not identifying the proper git directory.

Fixes #18276
2023-10-19 09:22:37 -07:00
Steve Hawley f4a0ea9ac2
[dotnet] Test integration (#18543)
Fixed an issue where the C# class name was coming in with `,
AssemblyName` tacked on the end.
Fixed an issue where a class that had an entry in the map didn't have a
`class_ptr` which was causing an NRE.
Fixed a predicate for deciding when to mark the assembly for save.

Note - for an as yet undetermined reason, the linker is not picking up
that I'm marking the assembly for save, which is why the `true` test
cases are commented out.
This fixes issue 16671 https://github.com/xamarin/xamarin-macios/issues/16671
2023-10-17 10:29:12 -04:00
Rolf Bjarne Kvinge be6c348cfd [net8.0-xcode15] Merge net8.0 into net8.0-xcode15. 2023-09-14 07:25:58 +02:00
Rolf Bjarne Kvinge 7b3779fb71
[xcode15] Add back armv7k support for watchOS. Fixes #18902. (#18947)
Only i386 is gone from watchOS 4.0, not armv7k.

Fixes https://github.com/xamarin/xamarin-macios/issues/18902.
2023-09-11 19:00:40 +02:00
Rolf Bjarne Kvinge 673dd5782b [net8.0-xcode15] Merge net8.0 into net8.0-xcode15. 2023-09-08 10:31:44 +02:00
Rolf Bjarne Kvinge 86c82c91a3
[net8.0-xcode15] [runtime] Bump the min OS version in the Info.plist in Xamarin.framework. (#18912)
Bump the min OS version to match our actual min OS version.
2023-09-05 10:26:44 +02:00
Rolf Bjarne Kvinge b3c869080e
Merge branch 'net8.0' into new-find-icu-data 2023-09-05 08:48:37 +02:00
Ivan Povazan ed26faa94f Simplify icudat file lookup by specifying ICU_DAT_FILE_PATH as a RuntimeHostConfigurationOption 2023-09-01 18:50:55 +02:00
Rolf Bjarne Kvinge 7f3251cf1c [runtime] Fix additional hardcoded NuGet names. 2023-08-29 11:30:24 +02:00
Rolf Bjarne Kvinge 78b649c4e1 [net8.0] Merge main into net8.0. 2023-08-29 11:24:40 +02:00
Rolf Bjarne Kvinge 45225dc88d
[dotnet] Parameterize the pack names. (#18732)
We're going to change the pack names to support multi-targeting, so ahead
of the pack name change I'm changing the existing logic to use a variable
for the pack name in most places (this will make the rename much easier and
simpler).

These changes should have no effect by themselves.
2023-08-29 10:06:46 +02:00
Rolf Bjarne Kvinge 3beafbb9bb [build] Add support for skipping 32-bit watchOS device architectures by bumping the min watchOS version. 2023-08-04 11:47:27 -04:00
Ivan Povazan bcb8e5cfd3
Exclude assemblies from NativeAOT app bundles (#18532)
Since NativeAOT generates native libraries and executables that do not
rely on assemblies they were compiled from, all managed assemblies can
be excluded from the application bundle.

This reduces the size of the application bundle by `3,17Mb` (or ~19%
compared to the baseline)

| MAUI ios app | Base | This PR | diff (%) |
|--------------|-----------|-----------|----------|
| SOD (Mb)     | 50,13 | 41,93 | -16,3%      |
| .ipa (Mb)    | 16,59  | 13,43  | -19%      |

Fixes: https://github.com/xamarin/xamarin-macios/issues/18472
2023-07-06 12:52:28 -04:00
Rolf Bjarne Kvinge 3c912d7aea [dotnet] Treat the ICU data file as a resource instead of an assembly.
We can fix this better once this fix reaches us:

    https://github.com/dotnet/runtime/pull/87813

because then we can set the ICU data file at build time (to a relative path).
2023-06-22 08:44:47 +02:00
Rolf Bjarne Kvinge d5a53d65b7 [runtime] Add a native IsNativeAOT flag. 2023-06-21 20:49:52 +02:00
Rolf Bjarne Kvinge 9b24c5dba6 [runtime] NativeAOT does not support dynamic registration 2023-06-21 20:49:51 +02:00
Rolf Bjarne Kvinge f964b5a157 [runtime] Create a version of our runtime that can be used with NativeAOT.
This contributes towards https://github.com/xamarin/xamarin-macios/issues/17339.
2023-06-21 20:49:49 +02:00
Rolf Bjarne Kvinge 7a5fca4230
Update runtime/xamarin/runtime.h
Co-authored-by: Ivan Povazan <55002338+ivanpovazan@users.noreply.github.com>
2023-05-15 15:18:03 +02:00
Rolf Bjarne Kvinge fb6ed7b770 [runtime] Add an API to look up the native symbol for an [UnmanagedCallersOnly] method.
Add an API to look up the native symbol for an [UnmanagedCallersOnly] method from native code.
2023-05-11 13:10:30 +02:00
Rolf Bjarne Kvinge 34264cd98f [dotnet] Add an 'IsManagedStaticRegistrar' feature to the linker.
This way we can ask the linker to inline the Runtime.IsManagedStaticRegistrar property, and remove any dead code paths.
2023-05-11 12:21:53 +02:00
Rolf Bjarne Kvinge e56920642b
[runtime] Re-generate product.h when the current commit changes. (#18231)
This way the runtime libraries are always up-to-date after building
after making local commits.
2023-05-08 14:54:47 +02:00
Rolf Bjarne Kvinge 36af029204
Change all null checking expressions to use 'is' and 'is not'. (#18176)
Change all null checking expressions to use 'is null' and 'is not null'
instead of '== null' and '!= null'.

This was mostly done with sed, so code can probably be improved in many
other ways with manual inspection, but that will come over time.

Also add code to the autoformat script to automatically fix these issues in the future.
2023-05-05 17:52:19 +02:00
Rolf Bjarne Kvinge edd9881b12
[runtime] Always look for dynamic libraries relative to the root directory first. Fixes #xamarin/maccore@2668. (#18121)
Fixes https://github.com/xamarin/maccore/issues/2668.
2023-04-25 10:22:40 +02:00
Rolf Bjarne Kvinge efc7551e3f
[runtime] Add support for passing on a connect timeout to sdb. (#18037)
The timeout can be given:

* By setting the __XAMARIN_DEBUG_CONNECT_TIMEOUT__ environment variable for the app when launching it.
* By passing the XamarinDebugConnectTimeout MSBuild property to 'dotnet run' or 'dotnet build /t:Run'.
* By setting the IOSDebugConnectTimeout MSBuild property at build time.

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1778177.
2023-04-13 16:34:52 +02:00
Rolf Bjarne Kvinge 60fbd4d37e
[runtime] Remove native usage of MonoReferenceQueue and use a ConditionalWeakTable in managed code instead. (#17429)
This makes it possible to simplify and remove a good chunk of related code.

Especially for CoreCLR this should be a minor perf improvement, because we'll do fewer transitions between managed and native code.
2023-02-06 07:57:51 +01:00
Rolf Bjarne Kvinge 98819287cc
[runtime/generator] Add support for BindAs with CMVideoDimensions. (#17308)
This is required for some new iOS 16 APIs.
2023-01-25 15:34:28 +01:00
Rolf Bjarne Kvinge 480a6ed844
[src/runtime] Fix lookup of RID-specific satellite resources. Fixes #16847. (#17117)
If we're creating a universal app, and here are satellite assemblies that are not
identical across all RuntimeIdentifiers, those assemblies will be stored in a RuntimeIdentifier-specific
subdirectory during the build.

Unfortunately we didn't know how to find those assemblies at runtime, causing localizations
in universal apps to not work.

This change will:

* Add support for looking in the directory where RID-specific satellite assemblies
  are stored.
* Add an assembly resolution event handler to our CoreCLR bridge so that we can
  execute our custom lookup code.
* Add an assembly resource lookup test to monotouch-test.
* Add a macOS + Mac Catalyst variation of monotouch-test to xharness that triggers
  the bug (a universal test app).

Fixes https://github.com/xamarin/xamarin-macios/issues/16847.
2023-01-13 21:58:34 +01:00
Rolf Bjarne Kvinge 294314a518
[autoformat] Add the rest of the repository. (#16974) 2022-12-07 09:13:36 +01:00
Rolf Bjarne Kvinge 0a53f3cd60
Add automatic support for not building iOS 32-bit stuff when min iOS version is >= 11.0 (#16746)
There are no changes for 32-bit watchOS, because watchOS support is likely to
go away completely anyways.
2022-11-18 07:59:46 +01:00
Rolf Bjarne Kvinge ae0d5b534e
[perf] [runtime] Optimize startup by using function pointers instead of delegates for our native->managed bridge. (#16702)
Use function pointers to our managed callbacks instead of delegates for the native->managed bridge. This makes execution faster on AOT (because the AOT compiler can just emit the native function address, no need to go through the expensive marshalling machinery).

This involved a few changes to make the managed callbacks only use blittable types in the function signature:

* Use `sbyte` / `int8_t` instead of `bool`.
* Use pointers instead of `out`/`ref` arguments.
* Use `IntPtr` instead of `string` arguments.

The code rarely shows up in timing profiles before the change, and never after. This means that time-wise this doesn't save all that much, because there wasn't much to gain to begin with (but it's still a gain).

Memory-wise, we're now allocation 0,19 MiB less on startup (17,61 MiB vs 17,42 MiB).
2022-11-18 07:59:03 +01:00
Rolf Bjarne Kvinge 2f684ca72b
[runtime] Use the built-in support in MonoVM for autorelease pools on threadpool threads. Fixes #11788. (#16751)
MonoVM in .NET 6+ supports automatic autorelease pools on threadpool threads
just like CoreCLR does, so we can remove our custom mono profiler hooks to
accomplish this.

Fixes https://github.com/xamarin/xamarin-macios/issues/11788.
2022-11-15 17:44:41 +01:00
Rolf Bjarne Kvinge b8362b1079
[runtime] Validate that the static registrar code being registered was built using the same runtime. (#16652)
Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
2022-11-10 10:45:20 +01:00
Rolf Bjarne Kvinge 9bca30dce6 Merge remote-tracking branch 'origin/main' into bump-main-in-xcode14-2022-09-09 2022-09-09 16:54:19 +02:00
Rolf Bjarne Kvinge aa8ded8e51
[runtime] Store assemblies' MVID in the generated static registrar code. (#15795)
This will increase app size a little bit: the space for the MVID + 4 bytes for each
assembly, but we'll be able to validate and show a helpful error message if the generated
static registrar code does not match the assembly loaded at runtime.

It's also a step toward per-assembly static registration (ref: #12067).
2022-09-08 10:34:05 +02:00
Rolf Bjarne Kvinge 433c48a35e Merge remote-tracking branch 'origin/main' into bump-main-in-xcode14-2022-09-07 2022-09-07 10:56:00 +02:00
Rolf Bjarne Kvinge 75112818b6
[runtime] Use a custom native -> managed trampoline for calling NSObject.InvokeConformsToProtocol from the generated static registrar code. (#15830)
This avoids one case where we we embed metadata tokens to a different assembly
in the generated static registrar code.

This is required for supporting per-assembly static registration
(https://github.com/xamarin/xamarin-macios/issues/12067).
2022-09-02 15:54:34 +02:00