xamarin-macios/runtime
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
..
xamarin [src/runtime] Add extra checks to Runtime.IsUserType to detect invalid pointers. (#21001) 2024-08-12 13:41:21 +02:00
.gitignore [runtime] Validate that the static registrar code being registered was built using the same runtime. (#16652) 2022-11-10 10:45:20 +01:00
COOP.md
Delegates.cs.t4 [runtime] Don't register Runtime.GetGenericMethodFromToken when the managed static registrar is used. (#20144) 2024-02-20 16:47:13 +01:00
EXCEPTIONS.md
Makefile [runtime] Convert the bindings-generator.csproj project to a .NET project. (#20743) 2024-06-19 15:11:28 +02:00
README.md
Xamarin.framework-iphoneos.Info.plist [net8.0-xcode15] [runtime] Bump the min OS version in the Info.plist in Xamarin.framework. (#18912) 2023-09-05 10:26:44 +02:00
Xamarin.framework-iphonesimulator.Info.plist [net8.0-xcode15] [runtime] Bump the min OS version in the Info.plist in Xamarin.framework. (#18912) 2023-09-05 10:26:44 +02:00
Xamarin.framework-tvos.Info.plist [net8.0-xcode15] [runtime] Bump the min OS version in the Info.plist in Xamarin.framework. (#18912) 2023-09-05 10:26:44 +02:00
Xamarin.framework-tvsimulator.Info.plist [net8.0-xcode15] [runtime] Bump the min OS version in the Info.plist in Xamarin.framework. (#18912) 2023-09-05 10:26:44 +02:00
Xamarin.framework-watchos.Info.plist [net8.0-xcode15] [runtime] Bump the min OS version in the Info.plist in Xamarin.framework. (#18912) 2023-09-05 10:26:44 +02:00
Xamarin.framework-watchsimulator.Info.plist [net8.0-xcode15] [runtime] Bump the min OS version in the Info.plist in Xamarin.framework. (#18912) 2023-09-05 10:26:44 +02:00
bindings-generator.cs [runtime] Convert the bindings-generator.csproj project to a .NET project. (#20743) 2024-06-19 15:11:28 +02:00
bindings-generator.csproj [runtime] Convert the bindings-generator.csproj project to a .NET project. (#20743) 2024-06-19 15:11:28 +02:00
bindings.h [UIKit] Wrap the call to UIApplicationMain in a @try/@catch handler. (#15746) 2022-08-26 13:56:33 +02:00
bindings.m [UIKit] Wrap the call to UIApplicationMain in a @try/@catch handler. (#15746) 2022-08-26 13:56:33 +02:00
coreclr-bridge.m [runtime] Use strnlen instead of strlen. (#20702) 2024-06-10 13:02:42 +02:00
delegates.h.t4
delegates.inc.t4 [runtime] Implement functions for getting and setting array elements for CoreCLR. (#11519) 2021-05-13 07:11:49 +02:00
delegates.t4 [runtime] Don't register Runtime.CreateDelegateProxy when using the managed static registrar. (#20164) 2024-02-22 08:51:34 +01:00
exports.t4 [runtime] Call mono_unhandled_exception to raise AppDomain.UnhandledException. (#20656) 2024-05-29 20:14:47 +02:00
extension-main.m
frameworks.h [runtime] MapKit is available on macOS/arm64. (#11363) 2021-04-29 14:45:58 +02:00
launcher.h
launcher.m [runtime] Use calloc instead of malloc. (#20692) 2024-06-07 16:56:54 +02:00
libmonotouch.csproj Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
libxammac.csproj Fix some whitespace issues in various files. (#12399) 2021-08-11 10:06:46 +02:00
main-internal.h
mono-runtime.h.t4 [tools] Use MONO_AOT_MODE_INTERP_ONLY instead of MONO_AOT_MODE_INTERP for x86_64. (#15429) 2022-07-12 09:56:51 +02:00
mono-runtime.m.t4 [runtime] Deal with the rest of the Mono Embedding API for CoreCLR. (#11642) 2021-05-21 07:53:41 +02:00
monotouch-debug.h [runtime] Move a few mono function declaration to the generated logic for mono function declarations instead of doing it manually. (#10849) 2021-03-12 07:37:27 +01:00
monotouch-debug.m [runtime] Use calloc instead of malloc. (#20692) 2024-06-07 16:56:54 +02:00
monotouch-main.m Exclude assemblies from NativeAOT app bundles (#18532) 2023-07-06 12:52:28 -04:00
monotouch-support.h
monovm-bridge.m [runtime] Call mono_unhandled_exception to raise AppDomain.UnhandledException. (#20656) 2024-05-29 20:14:47 +02:00
nativeaot-bridge.m [runtime] Create a version of our runtime that can be used with NativeAOT. 2023-06-21 20:49:49 +02:00
nsstring-localization.m
product.in.h [runtime] Validate that the static registrar code being registered was built using the same runtime. (#16652) 2022-11-10 10:45:20 +01:00
runtime-generated.h.t4 [runtime] Add support for generating managed delegates only for CoreCLR. 2021-03-25 07:32:32 +01:00
runtime-internal.h [runtime] Add support for tracking created and destroyed MonoObject* instances for CoreCLR. (#11657) 2021-05-25 08:19:27 +02:00
runtime.m [src/runtime] Add extra checks to Runtime.IsUserType to detect invalid pointers. (#21001) 2024-08-12 13:41:21 +02:00
shared.h [runtime] Move the code to wrap every managed thread with an NSAutoreleasePool to the MonoVM bridge. (#11257) 2021-04-21 16:21:09 +02:00
shared.m [runtime] Fix memory leak with BlockLiteral descriptors. Fixes #20503. (#20556) 2024-05-06 09:05:58 +02:00
slinked-list.h [runtime] Use calloc instead of malloc. (#20692) 2024-06-07 16:56:54 +02:00
trampolines-arm64-asm.s [runtime] Add correct prologue/epilogue to xamarin_arm64_common_trampoline 2021-05-11 15:54:39 +02:00
trampolines-arm64-objc_msgSend.inc.s [runtime] Be a bit defensive after handling Objective-C exceptions and return a consistent value. (#11601) 2021-05-19 07:35:46 +02:00
trampolines-arm64-objc_msgSend.s [runtime] Implement xamarin_dyn_objc_msgSend for ARM64. 2021-05-11 15:54:39 +02:00
trampolines-arm64-objc_msgSendSuper.s [runtime] Implement xamarin_dyn_objc_msgSend for ARM64. 2021-05-11 15:54:39 +02:00
trampolines-arm64.h Xamarin.Mac native Apple Silicon targetting support (#10115) 2021-03-17 21:48:02 -04:00
trampolines-arm64.m Use pointer-sized GCHandles everywhere. (#10597) 2021-02-11 08:18:38 +01:00
trampolines-i386-asm.s
trampolines-i386-objc_msgSend-copyframe.inc
trampolines-i386-objc_msgSend-post.inc
trampolines-i386-objc_msgSend-pre.inc
trampolines-i386-objc_msgSend.s
trampolines-i386-objc_msgSendSuper.s
trampolines-i386-objc_msgSendSuper_stret.s
trampolines-i386-objc_msgSend_stret.s
trampolines-i386.h
trampolines-i386.m Use pointer-sized GCHandles everywhere. (#10597) 2021-02-11 08:18:38 +01:00
trampolines-internal.h Use pointer-sized GCHandles everywhere. (#10597) 2021-02-11 08:18:38 +01:00
trampolines-invoke.m [runtime] Throw exception for condition we don't handle in the dynamic registrar. (#20568) 2024-05-20 18:57:42 +02:00
trampolines-varargs.h
trampolines-varargs.m Use pointer-sized GCHandles everywhere. (#10597) 2021-02-11 08:18:38 +01:00
trampolines-x86_64-asm.s
trampolines-x86_64-objc_msgSend-copyframe.inc
trampolines-x86_64-objc_msgSend-post.inc
trampolines-x86_64-objc_msgSend-pre.inc
trampolines-x86_64-objc_msgSend.s
trampolines-x86_64-objc_msgSendSuper.s
trampolines-x86_64-objc_msgSendSuper_stret.s
trampolines-x86_64-objc_msgSend_stret.s
trampolines-x86_64.h
trampolines-x86_64.m Use pointer-sized GCHandles everywhere. (#10597) 2021-02-11 08:18:38 +01:00
trampolines.m [runtime] Use calloc instead of malloc. (#20692) 2024-06-07 16:56:54 +02:00
xamarin-support.m [runtime] Use calloc instead of malloc. (#20692) 2024-06-07 16:56:54 +02:00

README.md

Native runtime

This directory contains the native runtime for Xamarin.iOS and Xamarin.Mac.

Cooperative GC

See COOP.md

Generated code

A few files are generated automatically:

delegates.h|inc, Delegates.cs

These files contain the code required to glue the native runtime and the managed runtime.

mono-runtime.m, xamarin/mono-runtime.h

These files contain code that makes other code, consumers of the mono runtime, oblivious to whether the mono runtime is linked statically, dynamically, or using dlopen at runtime.

If you need to use a new function from the Mono headers, add it to exports.t4.

If you need a new enum / constant / typedef / etc, add it to mono-runtime.h.t4.

Shipped headers

These are the headers shipped with XI/XM (they're not for public consumption, but we need them to build generated code on customers machine, in particular main.m and registrar.m)

xamarin/runtime.h xamarin/trampolines.h xamarin/main.h xamarin/xamarin.h