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

705 Коммитов

Автор SHA1 Сообщение Дата
Rolf Bjarne Kvinge 3127c2e6c1 [net9.0] Merge main into net9.0. 2024-08-14 17:58:49 +02:00
Rolf Bjarne Kvinge f790ba0272
[src/runtime] Add extra checks to Runtime.IsUserType to detect invalid pointers. (#21001)
This will hopefully make it easier to diagnose these kinds of crashes:

    Thread 0 Crashed:
    0   libobjc.A.dylib                      0x00000001a6f6e7f8 object_getClass + 48
    1   MyTestDotNetApp.Net                  0x0000000104b90a68 do_icall (interp.c:2273)
    2   MyTestDotNetApp.Net                  0x0000000104b8f838 do_icall_wrapper (interp.c:2361)
    3   MyTestDotNetApp.Net                  0x0000000104b85214 interp_exec_method (interp.c:3885)
    4   MyTestDotNetApp.Net                  0x0000000104b82de8 interp_runtime_invoke (interp.c:2122)
    5   MyTestDotNetApp.Net                  0x0000000104b4aedc mono_jit_runtime_invoke (mini-runtime.c:3650)
    6   MyTestDotNetApp.Net                  0x0000000104a8b874 mono_runtime_try_invoke (object.c:2415)
    7   MyTestDotNetApp.Net                  0x0000000104a8d8a0 mono_runtime_invoke (object.c:2464)
    8   MyTestDotNetApp.Net                  0x0000000104c42b68 native_to_managed_trampoline_68(objc_object*, objc_selector*, _MonoMethod**, objc_object*, unsigned int) (registrar.mm:4511)
    9   MyTestDotNetApp.Net                  0x0000000104c42a00 +[__NSObject_Disposer drain:] (registrar.mm:20968)
    10  Foundation                           0x00000001adc13b14 __NSThreadPerformPerform + 260

This happens because we try to access freed/invalid memory, but unfortunately
the crash report / stack trace does not contain any hint whatsoever about the
memory that triggered the crash.

By adding an opt-in to validate the memory for a given object, we might be
able to detect this crash in a few cases, and instead throw a managed
exception with much more information.

A project opts-in by setting `_ValidateObjectPointers=true` in the csproj.

Ref: https://github.com/xamarin/xamarin-macios/issues/19493

---------

Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
2024-08-12 13:41:21 +02:00
Rolf Bjarne Kvinge 7cb7f705ca [net9.0] Merge main into net9.0. 2024-06-21 11:19:27 +02:00
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 e7586e4411 [net9.0] Merge main into net9.0. 2024-06-12 15:08:25 +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 0e537376a4 [net9.0] Merge main into net9.0. 2024-06-05 17:23:29 +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 8c39f793ac [net9.0] Merge main into net9.0. 2024-05-28 08:37:23 +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 f052e014d0 [net9.0] Merge main into net9.0. 2024-05-21 16:12:35 +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 5b62113f85 Merge remote-tracking branch 'origin/main' into bump-main-in-net9.0-2024-05-01 2024-05-06 14:27: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 3cc37f4998 [net9.0] Merge main into net9.0. 2024-03-18 18:38:20 +01: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 b17de38d2d Merge remote-tracking branch 'origin/main' into bump-main-in-net9.0-2024-02-19 2024-02-28 17:56:05 +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 3fb52c3ed7 [tests] Bump min OS versions in all tests. 2024-01-29 15:24:30 +01:00
dotnet-maestro[bot] ed1b6e55c0
[net9.0] Update dependencies from dotnet/installer (#19690)
This pull request updates the following dependencies

## Coherency Updates

The following updates ensure that dependencies with a *CoherentParentDependency*
attribute were produced in a build used as input to the parent dependency's build.
See [Dependency Description Format](https://github.com/dotnet/arcade/blob/master/Documentation/DependencyDescriptionFormat.md#dependency-description-overview)

- **Coherency Updates**:
  - **Microsoft.NET.ILLink.Tasks**: from 9.0.0-alpha.1.23618.7 to 9.0.0-alpha.1.24060.26 (parent: Microsoft.Dotnet.Sdk.Internal)
  - **Microsoft.AspNetCore.App.Ref**: from 9.0.0-alpha.1.23619.10 to 9.0.0-alpha.1.24060.28 (parent: Microsoft.Dotnet.Sdk.Internal)
  - **Microsoft.NETCore.App.Ref**: from 9.0.0-alpha.1.23618.7 to 9.0.0-alpha.1.24060.26 (parent: Microsoft.Dotnet.Sdk.Internal)
  - **Microsoft.NET.Workload.Emscripten.Current.Manifest-9.0.100.Transport**: from 9.0.0-alpha.1.23617.2 to 9.0.0-alpha.1.24053.1 (parent: Microsoft.NETCore.App.Ref)
  - **Microsoft.NETCore.App.Ref**: from 9.0.0-alpha.1.23618.7 to 9.0.0-alpha.1.24060.26 (parent: Microsoft.Dotnet.Sdk.Internal)

## From https://github.com/dotnet/installer

- **Subscription**: 3727984b-7a79-4ba3-37dd-08dbe6bddf31
- **Build**: 20240111.3
- **Date Produced**: January 11, 2024 11:13:41 AM UTC
- **Commit**: cc07296328b45ea6721d1c17662c3bc59aaff392
- **Branch**: refs/heads/main

- **Updates**:
  - **Microsoft.Dotnet.Sdk.Internal**: [from 9.0.100-alpha.1.23619.5 to 9.0.100-alpha.1.24061.3][81]
  - **Microsoft.NET.ILLink.Tasks**: [from 9.0.0-alpha.1.23618.7 to 9.0.0-alpha.1.24060.26][82]
  - **Microsoft.AspNetCore.App.Ref**: [from 9.0.0-alpha.1.23619.10 to 9.0.0-alpha.1.24060.28][83]
  - **Microsoft.NETCore.App.Ref**: [from 9.0.0-alpha.1.23618.7 to 9.0.0-alpha.1.24060.26][82]
  - **Microsoft.NET.Workload.Emscripten.Current.Manifest-9.0.100.Transport**: [from 9.0.0-alpha.1.23617.2 to 9.0.0-alpha.1.24053.1][84]
  - **Microsoft.NETCore.App.Ref**: [from 9.0.0-alpha.1.23618.7 to 9.0.0-alpha.1.24060.26][82]

[81]: 1d730bb539...cc07296328
[82]: c282395b63...e5bab5fa31
[83]: 496e975d09...4ed85056f5
[84]: 13ad0749b9...5cda86493a


---------

Co-authored-by: Meri Khamoyan <merikhamoyan@microsoft.com>
2024-01-12 09:36:03 +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