Revert "Revert "Merge branch 'master' of https://github.com/mono/mono""
[mono.git] / mono / utils / mono-threads-mach-helper.c
index ec4220838f2939a4da12e6a91ef51f7cd7964d67..0e95d4e878e6eb1c7f3789dc8c13b92fdd456731 100644 (file)
@@ -72,7 +72,20 @@ mono_threads_install_dead_letter (void)
        dict = objc_msgSend (cur, threadDictionary);
        if (dict && objc_msgSend (dict, objectForKey, mono_dead_letter_key) == nil) {
                id value = objc_msgSend (objc_msgSend ((id)mono_dead_letter_class, alloc), init);
+
+#ifdef TARGET_ARM64
+               /*
+                * See the 'Dispatch Objective-C Messages Using the Method Function’s Prototype' section in
+                * the '64-Bit Transition Guide for Cocoa Touch' as to why this is required.
+                */
+               {
+                       void (*action)(id, SEL, id, id) = (void (*)(id, SEL, id, id)) objc_msgSend;
+                       action (dict, setObjectForKey, value, mono_dead_letter_key);
+               }
+#else
                objc_msgSend (dict, setObjectForKey, value, mono_dead_letter_key);
+#endif
+
                objc_msgSend (value, release);
        }
 }
@@ -84,6 +97,7 @@ mono_threads_init_dead_letter (void)
        id nsautoreleasepool = objc_getClass ("NSAutoreleasePool");
        SEL stringWithUTF8String = sel_registerName ("stringWithUTF8String:");
        SEL retain = sel_registerName ("retain");
+       id pool;
 
        nsthread = (Class)objc_getClass ("NSThread");
        nsobject = (Class)objc_getClass ("NSObject");
@@ -105,8 +119,17 @@ mono_threads_init_dead_letter (void)
        objc_registerClassPair (mono_dead_letter_class);
 
        // create the dict key
-       id pool = objc_msgSend (objc_msgSend (nsautoreleasepool, alloc), init);
+       pool = objc_msgSend (objc_msgSend (nsautoreleasepool, alloc), init);
+
+#ifdef TARGET_ARM64
+       {
+               id (*action)(id, SEL, char*) = (id (*)(id, SEL, char*)) objc_msgSend;
+               mono_dead_letter_key = action(nsstring, stringWithUTF8String, "mono-dead-letter");
+       }
+#else
        mono_dead_letter_key = objc_msgSend (nsstring, stringWithUTF8String, "mono-dead-letter");
+#endif
+
        objc_msgSend (mono_dead_letter_key, retain);
        objc_msgSend (pool, release);
 }