| 1 | /* |
| 2 | * Copyright (c) 1999-2007 Apple Inc. All Rights Reserved. |
| 3 | * |
| 4 | * @APPLE_LICENSE_HEADER_START@ |
| 5 | * |
| 6 | * This file contains Original Code and/or Modifications of Original Code |
| 7 | * as defined in and that are subject to the Apple Public Source License |
| 8 | * Version 2.0 (the 'License'). You may not use this file except in |
| 9 | * compliance with the License. Please obtain a copy of the License at |
| 10 | * http://www.opensource.apple.com/apsl/ and read it before using this |
| 11 | * file. |
| 12 | * |
| 13 | * The Original Code and all software distributed under the License are |
| 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
| 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
| 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
| 18 | * Please see the License for the specific language governing rights and |
| 19 | * limitations under the License. |
| 20 | * |
| 21 | * @APPLE_LICENSE_HEADER_END@ |
| 22 | */ |
| 23 | |
| 24 | #ifndef _OBJC_MESSAGE_H |
| 25 | #define _OBJC_MESSAGE_H |
| 26 | |
| 27 | #include <objc/objc.h> |
| 28 | #include <objc/runtime.h> |
| 29 | |
| 30 | #ifndef OBJC_SUPER |
| 31 | #define OBJC_SUPER |
| 32 | |
| 33 | /// Specifies the superclass of an instance. |
| 34 | struct objc_super { |
| 35 | /// Specifies an instance of a class. |
| 36 | __unsafe_unretained _Nonnull id receiver; |
| 37 | |
| 38 | /// Specifies the particular superclass of the instance to message. |
| 39 | __unsafe_unretained _Nonnull Class super_class; |
| 40 | |
| 41 | /* super_class is the first class to search */ |
| 42 | }; |
| 43 | #endif |
| 44 | |
| 45 | |
| 46 | /* Basic Messaging Primitives |
| 47 | * |
| 48 | * On some architectures, use objc_msgSend_stret for some struct return types. |
| 49 | * On some architectures, use objc_msgSend_fpret for some float return types. |
| 50 | * On some architectures, use objc_msgSend_fp2ret for some float return types. |
| 51 | * |
| 52 | * These functions must be cast to an appropriate function pointer type |
| 53 | * before being called. |
| 54 | */ |
| 55 | #if !OBJC_OLD_DISPATCH_PROTOTYPES |
| 56 | #pragma clang diagnostic push |
| 57 | #pragma clang diagnostic ignored "-Wincompatible-library-redeclaration" |
| 58 | OBJC_EXPORT void |
| 59 | objc_msgSend(void /* id self, SEL op, ... */ ) |
| 60 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0); |
| 61 | |
| 62 | OBJC_EXPORT void |
| 63 | objc_msgSendSuper(void /* struct objc_super *super, SEL op, ... */ ) |
| 64 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0); |
| 65 | #pragma clang diagnostic pop |
| 66 | #else |
| 67 | /** |
| 68 | * Sends a message with a simple return value to an instance of a class. |
| 69 | * |
| 70 | * @param self A pointer to the instance of the class that is to receive the message. |
| 71 | * @param op The selector of the method that handles the message. |
| 72 | * @param ... |
| 73 | * A variable argument list containing the arguments to the method. |
| 74 | * |
| 75 | * @return The return value of the method. |
| 76 | * |
| 77 | * @note When it encounters a method call, the compiler generates a call to one of the |
| 78 | * functions \c objc_msgSend, \c objc_msgSend_stret, \c objc_msgSendSuper, or \c objc_msgSendSuper_stret. |
| 79 | * Messages sent to an object’s superclass (using the \c super keyword) are sent using \c objc_msgSendSuper; |
| 80 | * other messages are sent using \c objc_msgSend. Methods that have data structures as return values |
| 81 | * are sent using \c objc_msgSendSuper_stret and \c objc_msgSend_stret. |
| 82 | */ |
| 83 | OBJC_EXPORT id _Nullable |
| 84 | objc_msgSend(id _Nullable self, SEL _Nonnull op, ...) |
| 85 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0); |
| 86 | /** |
| 87 | * Sends a message with a simple return value to the superclass of an instance of a class. |
| 88 | * |
| 89 | * @param super A pointer to an \c objc_super data structure. Pass values identifying the |
| 90 | * context the message was sent to, including the instance of the class that is to receive the |
| 91 | * message and the superclass at which to start searching for the method implementation. |
| 92 | * @param op A pointer of type SEL. Pass the selector of the method that will handle the message. |
| 93 | * @param ... |
| 94 | * A variable argument list containing the arguments to the method. |
| 95 | * |
| 96 | * @return The return value of the method identified by \e op. |
| 97 | * |
| 98 | * @see objc_msgSend |
| 99 | */ |
| 100 | OBJC_EXPORT id _Nullable |
| 101 | objc_msgSendSuper(struct objc_super * _Nonnull super, SEL _Nonnull op, ...) |
| 102 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0); |
| 103 | #endif |
| 104 | |
| 105 | |
| 106 | /* Struct-returning Messaging Primitives |
| 107 | * |
| 108 | * Use these functions to call methods that return structs on the stack. |
| 109 | * On some architectures, some structures are returned in registers. |
| 110 | * Consult your local function call ABI documentation for details. |
| 111 | * |
| 112 | * These functions must be cast to an appropriate function pointer type |
| 113 | * before being called. |
| 114 | */ |
| 115 | #if !OBJC_OLD_DISPATCH_PROTOTYPES |
| 116 | #pragma clang diagnostic push |
| 117 | #pragma clang diagnostic ignored "-Wincompatible-library-redeclaration" |
| 118 | OBJC_EXPORT void |
| 119 | objc_msgSend_stret(void /* id self, SEL op, ... */ ) |
| 120 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0) |
| 121 | OBJC_ARM64_UNAVAILABLE; |
| 122 | |
| 123 | OBJC_EXPORT void |
| 124 | objc_msgSendSuper_stret(void /* struct objc_super *super, SEL op, ... */ ) |
| 125 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0) |
| 126 | OBJC_ARM64_UNAVAILABLE; |
| 127 | #pragma clang diagnostic pop |
| 128 | #else |
| 129 | /** |
| 130 | * Sends a message with a data-structure return value to an instance of a class. |
| 131 | * |
| 132 | * @see objc_msgSend |
| 133 | */ |
| 134 | OBJC_EXPORT void |
| 135 | objc_msgSend_stret(id _Nullable self, SEL _Nonnull op, ...) |
| 136 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0) |
| 137 | OBJC_ARM64_UNAVAILABLE; |
| 138 | |
| 139 | /** |
| 140 | * Sends a message with a data-structure return value to the superclass of an instance of a class. |
| 141 | * |
| 142 | * @see objc_msgSendSuper |
| 143 | */ |
| 144 | OBJC_EXPORT void |
| 145 | objc_msgSendSuper_stret(struct objc_super * _Nonnull super, |
| 146 | SEL _Nonnull op, ...) |
| 147 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0) |
| 148 | OBJC_ARM64_UNAVAILABLE; |
| 149 | #endif |
| 150 | |
| 151 | |
| 152 | /* Floating-point-returning Messaging Primitives |
| 153 | * |
| 154 | * Use these functions to call methods that return floating-point values |
| 155 | * on the stack. |
| 156 | * Consult your local function call ABI documentation for details. |
| 157 | * |
| 158 | * arm: objc_msgSend_fpret not used |
| 159 | * i386: objc_msgSend_fpret used for `float`, `double`, `long double`. |
| 160 | * x86-64: objc_msgSend_fpret used for `long double`. |
| 161 | * |
| 162 | * arm: objc_msgSend_fp2ret not used |
| 163 | * i386: objc_msgSend_fp2ret not used |
| 164 | * x86-64: objc_msgSend_fp2ret used for `_Complex long double`. |
| 165 | * |
| 166 | * These functions must be cast to an appropriate function pointer type |
| 167 | * before being called. |
| 168 | */ |
| 169 | #if !OBJC_OLD_DISPATCH_PROTOTYPES |
| 170 | #pragma clang diagnostic push |
| 171 | #pragma clang diagnostic ignored "-Wincompatible-library-redeclaration" |
| 172 | |
| 173 | # if defined(__i386__) |
| 174 | |
| 175 | OBJC_EXPORT void |
| 176 | objc_msgSend_fpret(void /* id self, SEL op, ... */ ) |
| 177 | OBJC_AVAILABLE(10.4, 2.0, 9.0, 1.0, 2.0); |
| 178 | |
| 179 | # elif defined(__x86_64__) |
| 180 | |
| 181 | OBJC_EXPORT void |
| 182 | objc_msgSend_fpret(void /* id self, SEL op, ... */ ) |
| 183 | OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0); |
| 184 | |
| 185 | OBJC_EXPORT void |
| 186 | objc_msgSend_fp2ret(void /* id self, SEL op, ... */ ) |
| 187 | OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0); |
| 188 | |
| 189 | #pragma clang diagnostic pop |
| 190 | # endif |
| 191 | |
| 192 | // !OBJC_OLD_DISPATCH_PROTOTYPES |
| 193 | #else |
| 194 | // OBJC_OLD_DISPATCH_PROTOTYPES |
| 195 | # if defined(__i386__) |
| 196 | |
| 197 | /** |
| 198 | * Sends a message with a floating-point return value to an instance of a class. |
| 199 | * |
| 200 | * @see objc_msgSend |
| 201 | * @note On the i386 platform, the ABI for functions returning a floating-point value is |
| 202 | * incompatible with that for functions returning an integral type. On the i386 platform, therefore, |
| 203 | * you must use \c objc_msgSend_fpret for functions returning non-integral type. For \c float or |
| 204 | * \c long \c double return types, cast the function to an appropriate function pointer type first. |
| 205 | */ |
| 206 | #pragma clang diagnostic push |
| 207 | #pragma clang diagnostic ignored "-Wincompatible-library-redeclaration" |
| 208 | OBJC_EXPORT double |
| 209 | objc_msgSend_fpret(id _Nullable self, SEL _Nonnull op, ...) |
| 210 | OBJC_AVAILABLE(10.4, 2.0, 9.0, 1.0, 2.0); |
| 211 | #pragma clang diagnostic pop |
| 212 | |
| 213 | /* Use objc_msgSendSuper() for fp-returning messages to super. */ |
| 214 | /* See also objc_msgSendv_fpret() below. */ |
| 215 | |
| 216 | # elif defined(__x86_64__) |
| 217 | /** |
| 218 | * Sends a message with a floating-point return value to an instance of a class. |
| 219 | * |
| 220 | * @see objc_msgSend |
| 221 | */ |
| 222 | OBJC_EXPORT long double |
| 223 | objc_msgSend_fpret(id _Nullable self, SEL _Nonnull op, ...) |
| 224 | OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0); |
| 225 | |
| 226 | # if __STDC_VERSION__ >= 199901L |
| 227 | OBJC_EXPORT _Complex long double |
| 228 | objc_msgSend_fp2ret(id _Nullable self, SEL _Nonnull op, ...) |
| 229 | OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0); |
| 230 | # else |
| 231 | OBJC_EXPORT void objc_msgSend_fp2ret(id _Nullable self, SEL _Nonnull op, ...) |
| 232 | OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0); |
| 233 | # endif |
| 234 | |
| 235 | /* Use objc_msgSendSuper() for fp-returning messages to super. */ |
| 236 | /* See also objc_msgSendv_fpret() below. */ |
| 237 | |
| 238 | # endif |
| 239 | |
| 240 | // OBJC_OLD_DISPATCH_PROTOTYPES |
| 241 | #endif |
| 242 | |
| 243 | |
| 244 | /* Direct Method Invocation Primitives |
| 245 | * Use these functions to call the implementation of a given Method. |
| 246 | * This is faster than calling method_getImplementation() and method_getName(). |
| 247 | * |
| 248 | * The receiver must not be nil. |
| 249 | * |
| 250 | * These functions must be cast to an appropriate function pointer type |
| 251 | * before being called. |
| 252 | */ |
| 253 | #if !OBJC_OLD_DISPATCH_PROTOTYPES |
| 254 | #pragma clang diagnostic push |
| 255 | #pragma clang diagnostic ignored "-Wincompatible-library-redeclaration" |
| 256 | OBJC_EXPORT void |
| 257 | method_invoke(void /* id receiver, Method m, ... */ ) |
| 258 | OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0); |
| 259 | |
| 260 | OBJC_EXPORT void |
| 261 | method_invoke_stret(void /* id receiver, Method m, ... */ ) |
| 262 | OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0) |
| 263 | OBJC_ARM64_UNAVAILABLE; |
| 264 | #pragma clang diagnostic pop |
| 265 | #else |
| 266 | OBJC_EXPORT id _Nullable |
| 267 | method_invoke(id _Nullable receiver, Method _Nonnull m, ...) |
| 268 | OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0); |
| 269 | |
| 270 | OBJC_EXPORT void |
| 271 | method_invoke_stret(id _Nullable receiver, Method _Nonnull m, ...) |
| 272 | OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0) |
| 273 | OBJC_ARM64_UNAVAILABLE; |
| 274 | #endif |
| 275 | |
| 276 | |
| 277 | /* Message Forwarding Primitives |
| 278 | * Use these functions to forward a message as if the receiver did not |
| 279 | * respond to it. |
| 280 | * |
| 281 | * The receiver must not be nil. |
| 282 | * |
| 283 | * class_getMethodImplementation() may return (IMP)_objc_msgForward. |
| 284 | * class_getMethodImplementation_stret() may return (IMP)_objc_msgForward_stret |
| 285 | * |
| 286 | * These functions must be cast to an appropriate function pointer type |
| 287 | * before being called. |
| 288 | * |
| 289 | * Before Mac OS X 10.6, _objc_msgForward must not be called directly |
| 290 | * but may be compared to other IMP values. |
| 291 | */ |
| 292 | #if !OBJC_OLD_DISPATCH_PROTOTYPES |
| 293 | #pragma clang diagnostic push |
| 294 | #pragma clang diagnostic ignored "-Wincompatible-library-redeclaration" |
| 295 | OBJC_EXPORT void |
| 296 | _objc_msgForward(void /* id receiver, SEL sel, ... */ ) |
| 297 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0); |
| 298 | |
| 299 | OBJC_EXPORT void |
| 300 | _objc_msgForward_stret(void /* id receiver, SEL sel, ... */ ) |
| 301 | OBJC_AVAILABLE(10.6, 3.0, 9.0, 1.0, 2.0) |
| 302 | OBJC_ARM64_UNAVAILABLE; |
| 303 | #pragma clang diagnostic pop |
| 304 | #else |
| 305 | OBJC_EXPORT id _Nullable |
| 306 | _objc_msgForward(id _Nonnull receiver, SEL _Nonnull sel, ...) |
| 307 | OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0); |
| 308 | |
| 309 | OBJC_EXPORT void |
| 310 | _objc_msgForward_stret(id _Nonnull receiver, SEL _Nonnull sel, ...) |
| 311 | OBJC_AVAILABLE(10.6, 3.0, 9.0, 1.0, 2.0) |
| 312 | OBJC_ARM64_UNAVAILABLE; |
| 313 | #endif |
| 314 | |
| 315 | #endif |