| 1 | // Copyright (c) 2009-2011 Apple Inc. All rights reserved. |
| 2 | |
| 3 | #ifndef __XPC_BASE_H__ |
| 4 | #define __XPC_BASE_H__ |
| 5 | |
| 6 | #include <sys/cdefs.h> |
| 7 | |
| 8 | #if !defined(__has_include) |
| 9 | #define __has_include(x) 0 |
| 10 | #endif // !defined(__has_include) |
| 11 | |
| 12 | #if !defined(__has_attribute) |
| 13 | #define __has_attribute(x) 0 |
| 14 | #endif // !defined(__has_attribute) |
| 15 | |
| 16 | #if !defined(__has_feature) |
| 17 | #define __has_feature(x) 0 |
| 18 | #endif // !defined(__has_feature) |
| 19 | |
| 20 | #if !defined(__has_extension) |
| 21 | #define __has_extension(x) 0 |
| 22 | #endif // !defined(__has_extension) |
| 23 | |
| 24 | #if __has_include(<xpc/availability.h>) |
| 25 | #include <xpc/availability.h> |
| 26 | #else // __has_include(<xpc/availability.h>) |
| 27 | #include <Availability.h> |
| 28 | #endif // __has_include(<xpc/availability.h>) |
| 29 | |
| 30 | #include <os/availability.h> |
| 31 | |
| 32 | #ifndef __XPC_INDIRECT__ |
| 33 | #error "Please #include <xpc/xpc.h> instead of this file directly." |
| 34 | #endif // __XPC_INDIRECT__ |
| 35 | |
| 36 | __BEGIN_DECLS |
| 37 | |
| 38 | #pragma mark Attribute Shims |
| 39 | #ifdef __GNUC__ |
| 40 | #define XPC_CONSTRUCTOR __attribute__((constructor)) |
| 41 | #define XPC_NORETURN __attribute__((__noreturn__)) |
| 42 | #define XPC_NOTHROW __attribute__((__nothrow__)) |
| 43 | #define XPC_NONNULL1 __attribute__((__nonnull__(1))) |
| 44 | #define XPC_NONNULL2 __attribute__((__nonnull__(2))) |
| 45 | #define XPC_NONNULL3 __attribute__((__nonnull__(3))) |
| 46 | #define XPC_NONNULL4 __attribute__((__nonnull__(4))) |
| 47 | #define XPC_NONNULL5 __attribute__((__nonnull__(5))) |
| 48 | #define XPC_NONNULL6 __attribute__((__nonnull__(6))) |
| 49 | #define XPC_NONNULL7 __attribute__((__nonnull__(7))) |
| 50 | #define XPC_NONNULL8 __attribute__((__nonnull__(8))) |
| 51 | #define XPC_NONNULL9 __attribute__((__nonnull__(9))) |
| 52 | #define XPC_NONNULL10 __attribute__((__nonnull__(10))) |
| 53 | #define XPC_NONNULL11 __attribute__((__nonnull__(11))) |
| 54 | #define XPC_NONNULL_ALL __attribute__((__nonnull__)) |
| 55 | #define XPC_SENTINEL __attribute__((__sentinel__)) |
| 56 | #define XPC_PURE __attribute__((__pure__)) |
| 57 | #define XPC_WARN_RESULT __attribute__((__warn_unused_result__)) |
| 58 | #define XPC_MALLOC __attribute__((__malloc__)) |
| 59 | #define XPC_UNUSED __attribute__((__unused__)) |
| 60 | #define XPC_USED __attribute__((__used__)) |
| 61 | #define XPC_PACKED __attribute__((__packed__)) |
| 62 | #define XPC_PRINTF(m, n) __attribute__((format(printf, m, n))) |
| 63 | #define XPC_INLINE static __inline__ __attribute__((__always_inline__)) |
| 64 | #define XPC_NOINLINE __attribute__((noinline)) |
| 65 | #define XPC_NOIMPL __attribute__((unavailable)) |
| 66 | |
| 67 | #if __has_attribute(noescape) |
| 68 | #define XPC_NOESCAPE __attribute__((__noescape__)) |
| 69 | #else |
| 70 | #define XPC_NOESCAPE |
| 71 | #endif |
| 72 | |
| 73 | #if __has_extension(attribute_unavailable_with_message) |
| 74 | #define XPC_UNAVAILABLE(m) __attribute__((unavailable(m))) |
| 75 | #else // __has_extension(attribute_unavailable_with_message) |
| 76 | #define XPC_UNAVAILABLE(m) XPC_NOIMPL |
| 77 | #endif // __has_extension(attribute_unavailable_with_message) |
| 78 | |
| 79 | #define XPC_EXPORT extern __attribute__((visibility("default"))) |
| 80 | #define XPC_NOEXPORT __attribute__((visibility("hidden"))) |
| 81 | #define XPC_WEAKIMPORT extern __attribute__((weak_import)) |
| 82 | #define XPC_DEBUGGER_EXCL XPC_NOEXPORT XPC_USED |
| 83 | #define XPC_TRANSPARENT_UNION __attribute__((transparent_union)) |
| 84 | #if __clang__ |
| 85 | #define XPC_DEPRECATED(m) __attribute__((deprecated(m))) |
| 86 | #else // __clang__ |
| 87 | #define XPC_DEPRECATED(m) __attribute__((deprecated)) |
| 88 | #endif // __clang |
| 89 | #ifndef XPC_TESTEXPORT |
| 90 | #define XPC_TESTEXPORT XPC_NOEXPORT |
| 91 | #endif // XPC_TESTEXPORT |
| 92 | |
| 93 | #if defined(__XPC_TEST__) && __XPC_TEST__ |
| 94 | #define XPC_TESTSTATIC |
| 95 | #define XPC_TESTEXTERN extern |
| 96 | #define XPC_TESTNORETURN |
| 97 | #else // defined(__XPC_TEST__) && __XPC_TEST__ |
| 98 | #define XPC_TESTSTATIC static |
| 99 | #define XPC_TESTNORETURN XPC_NORETURN |
| 100 | #endif // defined(__XPC_TEST__) && __XPC_TEST__ |
| 101 | |
| 102 | #if __has_feature(objc_arc) |
| 103 | #define XPC_GIVES_REFERENCE __strong |
| 104 | #define XPC_UNRETAINED __unsafe_unretained |
| 105 | #define XPC_BRIDGE(xo) ((__bridge void *)(xo)) |
| 106 | #define XPC_BRIDGEREF_BEGIN(xo) ((__bridge_retained void *)(xo)) |
| 107 | #define XPC_BRIDGEREF_BEGIN_WITH_REF(xo) ((__bridge void *)(xo)) |
| 108 | #define XPC_BRIDGEREF_MIDDLE(xo) ((__bridge id)(xo)) |
| 109 | #define XPC_BRIDGEREF_END(xo) ((__bridge_transfer id)(xo)) |
| 110 | #else // __has_feature(objc_arc) |
| 111 | #define XPC_GIVES_REFERENCE |
| 112 | #define XPC_UNRETAINED |
| 113 | #define XPC_BRIDGE(xo) (xo) |
| 114 | #define XPC_BRIDGEREF_BEGIN(xo) (xo) |
| 115 | #define XPC_BRIDGEREF_BEGIN_WITH_REF(xo) (xo) |
| 116 | #define XPC_BRIDGEREF_MIDDLE(xo) (xo) |
| 117 | #define XPC_BRIDGEREF_END(xo) (xo) |
| 118 | #endif // __has_feature(objc_arc) |
| 119 | |
| 120 | #define _xpc_unreachable() __builtin_unreachable() |
| 121 | #else // __GNUC__ |
| 122 | /*! @parseOnly */ |
| 123 | #define XPC_CONSTRUCTOR |
| 124 | /*! @parseOnly */ |
| 125 | #define XPC_NORETURN |
| 126 | /*! @parseOnly */ |
| 127 | #define XPC_NOTHROW |
| 128 | /*! @parseOnly */ |
| 129 | #define XPC_NONNULL1 |
| 130 | /*! @parseOnly */ |
| 131 | #define XPC_NONNULL2 |
| 132 | /*! @parseOnly */ |
| 133 | #define XPC_NONNULL3 |
| 134 | /*! @parseOnly */ |
| 135 | #define XPC_NONNULL4 |
| 136 | /*! @parseOnly */ |
| 137 | #define XPC_NONNULL5 |
| 138 | /*! @parseOnly */ |
| 139 | #define XPC_NONNULL6 |
| 140 | /*! @parseOnly */ |
| 141 | #define XPC_NONNULL7 |
| 142 | /*! @parseOnly */ |
| 143 | #define XPC_NONNULL8 |
| 144 | /*! @parseOnly */ |
| 145 | #define XPC_NONNULL9 |
| 146 | /*! @parseOnly */ |
| 147 | #define XPC_NONNULL10 |
| 148 | /*! @parseOnly */ |
| 149 | #define XPC_NONNULL11 |
| 150 | /*! @parseOnly */ |
| 151 | #define XPC_NONNULL(n) |
| 152 | /*! @parseOnly */ |
| 153 | #define XPC_NONNULL_ALL |
| 154 | /*! @parseOnly */ |
| 155 | #define XPC_SENTINEL |
| 156 | /*! @parseOnly */ |
| 157 | #define XPC_PURE |
| 158 | /*! @parseOnly */ |
| 159 | #define XPC_WARN_RESULT |
| 160 | /*! @parseOnly */ |
| 161 | #define XPC_MALLOC |
| 162 | /*! @parseOnly */ |
| 163 | #define XPC_UNUSED |
| 164 | /*! @parseOnly */ |
| 165 | #define XPC_PACKED |
| 166 | /*! @parseOnly */ |
| 167 | #define XPC_PRINTF(m, n) |
| 168 | /*! @parseOnly */ |
| 169 | #define XPC_INLINE static inline |
| 170 | /*! @parseOnly */ |
| 171 | #define XPC_NOINLINE |
| 172 | /*! @parseOnly */ |
| 173 | #define XPC_NOIMPL |
| 174 | /*! @parseOnly */ |
| 175 | #define XPC_EXPORT extern |
| 176 | /*! @parseOnly */ |
| 177 | #define XPC_WEAKIMPORT |
| 178 | /*! @parseOnly */ |
| 179 | #define XPC_DEPRECATED |
| 180 | /*! @parseOnly */ |
| 181 | #define XPC_UNAVAILABLE(m) |
| 182 | /*! @parseOnly */ |
| 183 | #define XPC_NOESCAPE |
| 184 | #endif // __GNUC__ |
| 185 | |
| 186 | #if __has_feature(assume_nonnull) |
| 187 | #define XPC_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") |
| 188 | #define XPC_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") |
| 189 | #else |
| 190 | #define XPC_ASSUME_NONNULL_BEGIN |
| 191 | #define XPC_ASSUME_NONNULL_END |
| 192 | #endif |
| 193 | |
| 194 | #if __has_feature(nullability_on_arrays) |
| 195 | #define XPC_NONNULL_ARRAY _Nonnull |
| 196 | #else |
| 197 | #define XPC_NONNULL_ARRAY |
| 198 | #endif |
| 199 | |
| 200 | #if defined(__has_ptrcheck) && __has_ptrcheck |
| 201 | #define XPC_PTR_ASSUMES_SINGLE __ptrcheck_abi_assume_single() |
| 202 | #define XPC_SINGLE __single |
| 203 | #define XPC_UNSAFE_INDEXABLE __unsafe_indexable |
| 204 | #define XPC_CSTRING XPC_UNSAFE_INDEXABLE |
| 205 | #define XPC_SIZEDBY(N) __sized_by(N) |
| 206 | #define XPC_COUNTEDBY(N) __counted_by(N) |
| 207 | #define XPC_UNSAFE_FORGE_SIZED_BY(_type, _ptr, _size) \ |
| 208 | 		__unsafe_forge_bidi_indexable(_type, _ptr, _size) |
| 209 | #define XPC_UNSAFE_FORGE_SINGLE(_type, _ptr) \ |
| 210 | 		__unsafe_forge_single(_type, _ptr) |
| 211 | #else // defined(__has_ptrcheck) ** __has_ptrcheck |
| 212 | #define XPC_PTR_ASSUMES_SINGLE |
| 213 | #define XPC_SINGLE |
| 214 | #define XPC_UNSAFE_INDEXABLE |
| 215 | #define XPC_CSTRING |
| 216 | #define XPC_SIZEDBY(N) |
| 217 | #define XPC_COUNTEDBY(N) |
| 218 | #define XPC_UNSAFE_FORGE_SIZED_BY(_type, _ptr, _size) ((_type)(_ptr)) |
| 219 | #define XPC_UNSAFE_FORGE_SINGLE(_type, _ptr) ((_type)(_ptr)) |
| 220 | #endif // defined(__has_ptrcheck) ** __has_ptrcheck |
| 221 | |
| 222 | #ifdef OS_CLOSED_OPTIONS |
| 223 | #define XPC_FLAGS_ENUM(_name, _type, ...) \ |
| 224 | 		OS_CLOSED_OPTIONS(_name, _type, __VA_ARGS__) |
| 225 | #else // OS_CLOSED_ENUM |
| 226 | #define XPC_FLAGS_ENUM(_name, _type, ...) \ |
| 227 | 		OS_ENUM(_name, _type, __VA_ARGS__) |
| 228 | #endif // OS_CLOSED_ENUM |
| 229 | |
| 230 | #ifdef OS_CLOSED_ENUM |
| 231 | #define XPC_ENUM(_name, _type, ...) \ |
| 232 | 		OS_CLOSED_ENUM(_name, _type, __VA_ARGS__) |
| 233 | #else // OS_CLOSED_ENUM |
| 234 | #define XPC_ENUM(_name, _type, ...) \ |
| 235 | 		OS_ENUM(_name, _type, __VA_ARGS__) |
| 236 | #endif // OS_CLOSED_ENUM |
| 237 | |
| 238 | #if __has_attribute(swift_name) |
| 239 | # define XPC_SWIFT_NAME(_name) __attribute__((swift_name(_name))) |
| 240 | #else |
| 241 | # define XPC_SWIFT_NAME(_name) // __has_attribute(swift_name) |
| 242 | #endif |
| 243 | |
| 244 | #define XPC_SWIFT_UNAVAILABLE(msg) __swift_unavailable(msg) |
| 245 | #define XPC_SWIFT_NOEXPORT XPC_SWIFT_UNAVAILABLE("Unavailable in Swift from the XPC C Module") |
| 246 | |
| 247 | #define XPC_SWIFT_SENDABLE __attribute__((__swift_attr__("@Sendable"))) |
| 248 | |
| 249 | __END_DECLS |
| 250 | |
| 251 | #endif // __XPC_BASE_H__ |