diff options
Diffstat (limited to 'src/coreclr/nativeaot')
4 files changed, 95 insertions, 1 deletions
diff --git a/src/coreclr/nativeaot/Directory.Build.props b/src/coreclr/nativeaot/Directory.Build.props index 953cf276bee..94ee1363ee0 100644 --- a/src/coreclr/nativeaot/Directory.Build.props +++ b/src/coreclr/nativeaot/Directory.Build.props @@ -59,6 +59,13 @@ <FeatureComWrappers>false</FeatureComWrappers> <FeatureComWrappers Condition="'$(TargetsWindows)' == 'true'">true</FeatureComWrappers> </PropertyGroup> + <PropertyGroup> + <FeatureObjCMarshal>false</FeatureObjCMarshal> + <FeatureObjCMarshal Condition="'$(TargetsOSX)' == 'true'">true</FeatureObjCMarshal> + </PropertyGroup> + <PropertyGroup> + <DefineConstants Condition="'$(FeatureObjCMarshal)' == 'true'">FEATURE_OBJCMARSHAL;$(DefineConstants)</DefineConstants> + </PropertyGroup> <!-- Platform specific properties --> <PropertyGroup Condition="'$(Platform)' == 'x64'"> diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs index 8e383b44d85..f5367d848d4 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs @@ -9,6 +9,7 @@ using System.Reflection; using System.Runtime; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ObjectiveC; using System.Runtime.Loader; using System.Text; using System.Threading; @@ -342,6 +343,17 @@ namespace Internal.Runtime.CompilerHelpers byte* methodName = (byte*)pCell->MethodName; IntPtr pTarget; +#if FEATURE_OBJCMARSHAL +#pragma warning disable CA1416 + if (pCell->IsObjectiveCMessageSend && ObjectiveCMarshal.TryGetGlobalMessageSendCallback(pCell->ObjectiveCMessageSendFunction, out pTarget)) + { + Debug.Assert(pTarget != IntPtr.Zero); + pCell->Target = pTarget; + return; + } +#pragma warning restore CA1416 +#endif + #if TARGET_WINDOWS CharSet charSetMangling = pCell->CharSetMangling; if (charSetMangling == 0) @@ -613,7 +625,11 @@ namespace Internal.Runtime.CompilerHelpers public IntPtr Target; public IntPtr MethodName; public ModuleFixupCell* Module; - public CharSet CharSetMangling; + private int Flags; + + public CharSet CharSetMangling => (CharSet)(Flags & MethodFixupCellFlagsConstants.CharSetMask); + public bool IsObjectiveCMessageSend => (Flags & MethodFixupCellFlagsConstants.IsObjectiveCMessageSendMask) != 0; + public int ObjectiveCMessageSendFunction => (Flags & MethodFixupCellFlagsConstants.ObjectiveCMessageSendFunctionMask) >> MethodFixupCellFlagsConstants.ObjectiveCMessageSendFunctionShift; } internal unsafe struct CustomMarshallerKey : IEquatable<CustomMarshallerKey> diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj index 0c0e84b3b7d..64926e9eeca 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj @@ -212,6 +212,7 @@ <Compile Include="System\Runtime\InteropServices\Marshal.NativeAot.cs" /> <Compile Include="System\Runtime\InteropServices\Marshal.Com.cs" Condition="'$(FeatureCominterop)' == 'true'" /> <Compile Include="System\Runtime\InteropServices\MemoryMarshal.NativeAot.cs" /> + <Compile Include="System\Runtime\InteropServices\ObjectiveCMarshal.NativeAot.cs" Condition="'$(FeatureObjCMarshal)' == 'true'" /> <Compile Include="System\Runtime\InteropServices\UnsafeGCHandle.cs" /> <Compile Include="System\Runtime\Intrinsics\X86\X86Base.NativeAot.cs" Condition="'$(SupportsX86Intrinsics)' == 'true'" /> <Compile Include="System\Runtime\JitInfo.NativeAot.cs" /> diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.NativeAot.cs new file mode 100644 index 00000000000..a7ab0249acb --- /dev/null +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.NativeAot.cs @@ -0,0 +1,70 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Diagnostics; +using System.Runtime.ExceptionServices; +using System.Threading; + +namespace System.Runtime.InteropServices.ObjectiveC +{ + public static unsafe partial class ObjectiveCMarshal + { + private static readonly IntPtr[] s_ObjcMessageSendFunctions = new IntPtr[(int)MessageSendFunction.MsgSendSuperStret + 1]; + + [ThreadStatic] + private static Exception? t_pendingExceptionObject; + + /// <summary> + /// Sets a pending exception to be thrown the next time the runtime is entered from an Objective-C msgSend P/Invoke. + /// </summary> + /// <param name="exception">The exception.</param> + /// <remarks> + /// If <c>null</c> is supplied any pending exception is discarded. + /// </remarks> + public static void SetMessageSendPendingException(Exception? exception) + { + t_pendingExceptionObject = exception; + } + + private static bool TrySetGlobalMessageSendCallback( + MessageSendFunction msgSendFunction, + IntPtr func) + { + return Interlocked.CompareExchange(ref s_ObjcMessageSendFunctions[(int)msgSendFunction], func, IntPtr.Zero) == IntPtr.Zero; + } + + internal static bool TryGetGlobalMessageSendCallback(int msgSendFunction, out IntPtr func) + { + func = s_ObjcMessageSendFunctions[msgSendFunction]; + return func != IntPtr.Zero; + } + + [StackTraceHidden] + internal static void ThrowPendingExceptionObject() + { + Exception? ex = t_pendingExceptionObject; + if (ex != null) + { + t_pendingExceptionObject = null; + ExceptionDispatchInfo.Throw(ex); + } + } + + private static bool TryInitializeReferenceTracker( + delegate* unmanaged<void> beginEndCallback, + delegate* unmanaged<IntPtr, int> isReferencedCallback, + delegate* unmanaged<IntPtr, void> trackedObjectEnteredFinalization) + { + throw new NotImplementedException(); + } + + private static IntPtr CreateReferenceTrackingHandleInternal( + object obj, + out int memInSizeT, + out IntPtr mem) + { + throw new NotImplementedException(); + } + } +} |