diff --git a/src/libraries/Common/src/Interop/OSX/Interop.libobjc.cs b/src/libraries/Common/src/Interop/OSX/Interop.libobjc.cs index 799bfd19e0d5e..fc93bf18d8b7d 100644 --- a/src/libraries/Common/src/Interop/OSX/Interop.libobjc.cs +++ b/src/libraries/Common/src/Interop/OSX/Interop.libobjc.cs @@ -10,12 +10,6 @@ internal static partial class Interop { internal static partial class libobjc { -#if TARGET_ARM64 - private const string MessageSendStructReturnEntryPoint = "objc_msgSend"; -#else - private const string MessageSendStructReturnEntryPoint = "objc_msgSend_stret"; -#endif - [StructLayout(LayoutKind.Sequential)] private struct NSOperatingSystemVersion { @@ -28,8 +22,8 @@ private struct NSOperatingSystemVersion private static extern IntPtr objc_getClass(string className); [DllImport(Libraries.libobjc)] private static extern IntPtr sel_getUid(string selector); - [DllImport(Libraries.libobjc)] - private static extern IntPtr objc_msgSend(IntPtr basePtr, IntPtr selector); + [DllImport(Libraries.libobjc, EntryPoint = "objc_msgSend")] + private static extern IntPtr intptr_objc_msgSend(IntPtr basePtr, IntPtr selector); internal static Version GetOperatingSystemVersion() { @@ -37,12 +31,15 @@ internal static Version GetOperatingSystemVersion() int minor = 0; int patch = 0; - IntPtr processInfo = objc_msgSend(objc_getClass("NSProcessInfo"), sel_getUid("processInfo")); + IntPtr processInfo = intptr_objc_msgSend(objc_getClass("NSProcessInfo"), sel_getUid("processInfo")); if (processInfo != IntPtr.Zero) { - NSOperatingSystemVersion osVersion = get_operatingSystemVersion(processInfo, sel_getUid("operatingSystemVersion")); - +#if TARGET_ARM64 + NSOperatingSystemVersion osVersion = NSOperatingSystemVersion_objc_msgSend(processInfo, sel_getUid("operatingSystemVersion")); +#else + NSOperatingSystemVersion_objc_msgSend_stret(out NSOperatingSystemVersion osVersion, processInfo, sel_getUid("operatingSystemVersion")); +#endif checked { major = (int)osVersion.majorVersion; @@ -63,7 +60,10 @@ internal static Version GetOperatingSystemVersion() return new Version(major, minor, patch); } - [DllImport(Libraries.libobjc, EntryPoint = MessageSendStructReturnEntryPoint)] - private static extern NSOperatingSystemVersion get_operatingSystemVersion(IntPtr basePtr, IntPtr selector); + [DllImport(Libraries.libobjc, EntryPoint = "objc_msgSend")] + private static extern NSOperatingSystemVersion NSOperatingSystemVersion_objc_msgSend(IntPtr basePtr, IntPtr selector); + + [DllImport(Libraries.libobjc, EntryPoint = "objc_msgSend_stret")] + private static extern void NSOperatingSystemVersion_objc_msgSend_stret(out NSOperatingSystemVersion osVersion, IntPtr basePtr, IntPtr selector); } } diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs index 16523523fb295..a5d9bfd74b76b 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs @@ -69,13 +69,12 @@ internal static class MacSupport internal static CocoaContext GetCGContextForNSView(IntPtr handle) { - IntPtr graphicsContext = objc_msgSend(objc_getClass("NSGraphicsContext"), sel_registerName("currentContext")); - IntPtr ctx = objc_msgSend(graphicsContext, sel_registerName("graphicsPort")); - Rect bounds = default; + IntPtr graphicsContext = intptr_objc_msgSend(objc_getClass("NSGraphicsContext"), sel_registerName("currentContext")); + IntPtr ctx = intptr_objc_msgSend(graphicsContext, sel_registerName("graphicsPort")); CGContextSaveGState(ctx); - objc_msgSend_stret(ref bounds, handle, sel_registerName("bounds")); + Rect_objc_msgSend_stret(out Rect bounds, handle, sel_registerName("bounds")); var isFlipped = bool_objc_msgSend(handle, sel_registerName("isFlipped")); if (isFlipped) @@ -211,13 +210,12 @@ internal static void ReleaseContext(IntPtr port, IntPtr context) #region Cocoa Methods [DllImport("libobjc.dylib")] public static extern IntPtr objc_getClass(string className); - [DllImport("libobjc.dylib")] - public static extern IntPtr objc_msgSend(IntPtr basePtr, IntPtr selector, string argument); - [DllImport("libobjc.dylib")] - public static extern IntPtr objc_msgSend(IntPtr basePtr, IntPtr selector); - [DllImport("libobjc.dylib")] - public static extern void objc_msgSend_stret(ref Rect arect, IntPtr basePtr, IntPtr selector); [DllImport("libobjc.dylib", EntryPoint = "objc_msgSend")] + public static extern IntPtr intptr_objc_msgSend(IntPtr basePtr, IntPtr selector); + [DllImport("libobjc.dylib", EntryPoint = "objc_msgSend_stret")] + public static extern void Rect_objc_msgSend_stret(out Rect arect, IntPtr basePtr, IntPtr selector); + [DllImport("libobjc.dylib", EntryPoint = "objc_msgSend")] + [return:MarshalAs(UnmanagedType.U1)] public static extern bool bool_objc_msgSend(IntPtr handle, IntPtr selector); [DllImport("libobjc.dylib")] public static extern IntPtr sel_registerName(string selectorName);