├── .gitignore ├── Makefile ├── README.md ├── Tweak.mm ├── Tweak.xm ├── XPCSniffer.plist ├── all.png ├── control ├── libproc └── libproc.h ├── packages └── com.evilpenguin.xpcsniffer_0.2.1-1+debug_iphoneos-arm.deb └── xpc ├── activity.h ├── availability.h ├── base.h ├── connection.h ├── debug.h ├── endpoint.h └── xpc.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## VSCode 26 | .vscode 27 | 28 | ## Theos 29 | .theos 30 | 31 | # DS Files 32 | .DS_Store 33 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | THEOS_DEVICE_IP = 127.0.0.1 2 | THEOS_DEVICE_PORT = 2222 3 | DEBUG = 1 4 | 5 | include $(THEOS)/makefiles/common.mk 6 | 7 | TARGET := iphone:13.0 8 | ARCHS := arm64 arm64e 9 | TWEAK_NAME = XPCSniffer 10 | $(TWEAK_NAME)_FILES = Tweak.xm 11 | $(TWEAK_NAME)_CFLAGS += -DTHEOS_LEAN_AND_MEAN -Wno-shift-negative-value -Wno-int-to-pointer-cast 12 | $(TWEAK_NAME)_FRAMEWORKS = CoreFoundation Foundation 13 | 14 | include $(THEOS_MAKE_PATH)/tweak.mk 15 | 16 | after-install:: 17 | install.exec "killall -9 SpringBoard" 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XPCSniffer 2 | XPCSniffer will dump XPC information to a file and the console. 3 | 4 | Usage 5 | ---------- 6 | - Open up the Console.app on macOS 7 | - Search for `XPCSniffer` on your device 8 | - Output will be `+[XPCSniffer] Writing to /var/mobile/Containers/Data/Application/APP_UUID/Library/Caches/XPCSNiffer.log` 9 | - SSH into your device and `tail -f /var/mobile/Containers/Data/Application/APP_UUID/Library/Caches/XPCSniffer.log` 10 | 11 | Notes 12 | ---------- 13 | - Update the filter plist with the `Bundles` or `Executables` you want to dump. 14 | - Set `DEBUG` to `1` or `0` inside the Makefile for logging. 15 | - Use [`jlutil`](http://newosxbook.com/tools/jlutil.html) to parse the `bplist16` data. 16 | 17 | Screenshot 18 | ---------- 19 | ![All](all.png) 20 | 21 | Example Output 22 | ---------- 23 | ``` 24 | {"connection_name":"com.apple.backboard.system-app-server","process_id":4148,"connection_time":"Tue Nov 10 17:32:37 2020","xpc_message":{"isAlive":true},"process_name":"backboardd","connection_address":"0x281084240"} 25 | {"connection_name":"com.apple.backboard.system-app-server","process_id":4148,"connection_time":"Tue Nov 10 17:32:47 2020","xpc_message":{"isAlive":true},"process_name":"backboardd","connection_address":"0x281084240"} 26 | {"connection_name":"com.apple.backboard.system-app-server","process_id":4148,"connection_time":"Tue Nov 10 17:32:57 2020","xpc_message":{"isAlive":true},"process_name":"backboardd","connection_address":"0x281084240"} 27 | {"connection_name":"com.apple.backboard.system-app-server","process_id":4148,"connection_time":"Tue Nov 10 17:33:07 2020","xpc_message":{"isAlive":true},"process_name":"backboardd","connection_address":"0x281084240"} 28 | {"connection_name":"com.apple.backboard.system-app-server","process_id":4148,"connection_time":"Tue Nov 10 17:33:17 2020","xpc_message":{"isAlive":true},"process_name":"backboardd","connection_address":"0x281084240"} 29 | {"connection_name":"com.apple.backboard.system-app-server","process_id":4148,"connection_time":"Tue Nov 10 17:33:27 2020","xpc_message":{"isAlive":true},"process_name":"backboardd","connection_address":"0x281084240"} 30 | {"connection_name":"com.apple.backboard.system-app-server","process_id":4148,"connection_time":"Tue Nov 10 17:33:37 2020","xpc_message":{"isAlive":true},"process_name":"backboardd","connection_address":"0x281084240"} 31 | {"connection_name":"com.apple.runningboard","process_id":31,"connection_time":"Tue Nov 10 17:31:47 2020","xpc_message":{"clientPid":10857,"bsx_class":"RBSAssertionIdentifier","count":13699,"serverPid":31,"rbs_selector":"async_invalidateAssertionWithIdentifier:"},"process_name":"SpringBoard","connection_address":"0x281084180"} 32 | ``` 33 | -------------------------------------------------------------------------------- /Tweak.mm: -------------------------------------------------------------------------------- 1 | /* 2 | * XPCSniffer 3 | * 4 | * Created by EvilPenguin 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "libproc/libproc.h" 14 | #include "xpc/xpc.h" 15 | #include "substrate.h" 16 | 17 | #define INSN_CALL 0x94000000, 0xFC000000 18 | 19 | #pragma mark - variables 20 | 21 | static dispatch_queue_t _xpcsniffer_queue = dispatch_queue_create("XPCSniffer", DISPATCH_QUEUE_SERIAL); 22 | static CFPropertyListRef (*__CFBinaryPlistCreate15)(const uint8_t *, uint64_t) = nil; 23 | 24 | #pragma mark - functions 25 | 26 | static uint64_t _xpcsniffer_real_signextend_64(uint64_t imm, uint8_t bit); 27 | static uintptr_t *_xpcsniffer_step64(uint32_t *base, size_t length, uint8_t step_count, uint32_t what, uint32_t mask); 28 | static NSString *_xpcsniffer_get_timestring(); 29 | static NSMutableDictionary *_xpcsniffer_dictionary(xpc_connection_t connection); 30 | static NSString *_xpcsniffer_connection_name(xpc_connection_t connection); 31 | static NSString *_xpcsniffer_proc_name(int pid); 32 | static bool _xpcsniffer_message_dump(const char *key, xpc_object_t value, NSMutableDictionary *logDictionary) ; 33 | static bool _xpcsniffer_dumper(xpc_object_t obj, NSMutableDictionary *logDictionary); 34 | static int _xpcsniffer_bplist_type(const char *bytes, size_t length); 35 | static NSString *_xpcsniffer_parse_bplist(const char *bytes, size_t length, int type); 36 | 37 | #pragma mark - private 38 | 39 | #ifdef DEBUG 40 | #define DLog(FORMAT, ...) syslog(LOG_ERR, "+[XPCSniffer] %s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]); 41 | #else 42 | #define DLog(...) (void)0 43 | #endif 44 | 45 | static uint64_t _xpcsniffer_real_signextend_64(uint64_t imm, uint8_t bit) { 46 | if ((imm >> bit) & 1) 47 | return (-1LL << (bit + 1)) + imm; 48 | 49 | return imm; 50 | } 51 | 52 | static uintptr_t *_xpcsniffer_step64(uint32_t *base, size_t length, uint8_t step_count, uint32_t what, uint32_t mask) { 53 | uint32_t *start = (uint32_t *)base; 54 | uint32_t *end = start + length; 55 | uint8_t current_step_count = 0; 56 | 57 | while (start < end) { 58 | uint32_t operation = *start; 59 | if ((operation & mask) == what) { 60 | if (++current_step_count == step_count) { 61 | signed imm = (operation & 0x3ffffff) << 2; 62 | imm = _xpcsniffer_real_signextend_64(imm, 27); 63 | uintptr_t addr = reinterpret_cast(start) + imm; 64 | 65 | return (uintptr_t *)addr; 66 | } 67 | } 68 | start++; 69 | } 70 | 71 | return NULL; 72 | } 73 | 74 | static NSString *_xpcsniffer_get_timestring() { 75 | time_t now = time(NULL); 76 | char *timeString = ctime(&now); 77 | timeString[strlen(timeString) - 1] = '\0'; 78 | 79 | return [NSString stringWithUTF8String:timeString]; 80 | } 81 | 82 | static NSMutableDictionary *_xpcsniffer_dictionary(xpc_connection_t connection) { 83 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 84 | dictionary[@"connection_address"] = [NSString stringWithFormat:@"%p", connection]; 85 | dictionary[@"connection_time"] = _xpcsniffer_get_timestring(); 86 | dictionary[@"xpc_message"] = [NSMutableDictionary dictionary]; 87 | 88 | return dictionary; 89 | } 90 | 91 | static NSString *_xpcsniffer_connection_name(xpc_connection_t connection) { 92 | const char *name = xpc_connection_get_name(connection); 93 | if (name) return @(name); 94 | 95 | return @"?"; 96 | } 97 | 98 | static NSString *_xpcsniffer_proc_name(int pid) { 99 | static char buffer[2048]; 100 | proc_name(pid, buffer, 2048); 101 | 102 | if (strlen(buffer) == 0) { 103 | buffer[0] = '?'; 104 | } 105 | 106 | return @(buffer); 107 | } 108 | 109 | static NSString *_xpcsniffer_hex_string(const char *bytes, size_t length) { 110 | NSMutableString *hexString = [NSMutableString string]; 111 | for (int i = 0; i < length; i++) [hexString appendFormat:@"%02x ", (unsigned char)bytes[i]]; 112 | 113 | return hexString; 114 | } 115 | 116 | static bool _xpcsniffer_message_dump(const char *key, xpc_object_t value, NSMutableDictionary *logDictionary) { 117 | NSString *logKey = [NSString stringWithUTF8String:key]; 118 | xpc_type_t type = xpc_get_type(value); 119 | 120 | if (type == XPC_TYPE_NULL) logDictionary[logKey] = @"NULL"; 121 | else if (type == XPC_TYPE_ACTIVITY) logDictionary[logKey] = @"Activity"; 122 | else if (type == XPC_TYPE_DATE) logDictionary[logKey] = @"Date"; 123 | else if (type == XPC_TYPE_SHMEM) logDictionary[logKey] = @"Shared memory"; 124 | else if (type == XPC_TYPE_ENDPOINT) logDictionary[logKey] = @"XPC Endpoint"; 125 | else if (type == XPC_TYPE_BOOL) logDictionary[logKey] = @(xpc_bool_get_value(value)); 126 | else if (type == XPC_TYPE_DOUBLE) logDictionary[logKey] = @(xpc_double_get_value(value)); 127 | else if (type == XPC_TYPE_INT64) logDictionary[logKey] = @(xpc_int64_get_value(value)); 128 | else if (type == XPC_TYPE_UINT64) logDictionary[logKey] = @(xpc_uint64_get_value(value)); 129 | else if (type == XPC_TYPE_STRING) logDictionary[logKey] = @(xpc_string_get_string_ptr(value)); 130 | else if (type == XPC_TYPE_UUID) { 131 | char buf[256]; 132 | uuid_unparse(xpc_uuid_get_bytes(value), buf); 133 | logDictionary[logKey] = @(buf); 134 | } 135 | else if (type == XPC_TYPE_FD) { 136 | char buf[4096]; 137 | int fd = xpc_fd_dup(value); 138 | fcntl(fd, F_GETPATH, buf); 139 | 140 | logDictionary[logKey] = @(buf); 141 | } 142 | else if (type == XPC_TYPE_DATA) { 143 | size_t length = xpc_data_get_length(value); 144 | const char *bytes = (const char *)xpc_data_get_bytes_ptr(value); 145 | 146 | if (bytes) { 147 | int plistType = _xpcsniffer_bplist_type(bytes, length); 148 | if (plistType >= 0) { 149 | logDictionary[logKey] = _xpcsniffer_parse_bplist(bytes, length, plistType); 150 | } 151 | else { 152 | logDictionary[logKey] = _xpcsniffer_hex_string(bytes, length); 153 | } 154 | } 155 | } 156 | else if (type == XPC_TYPE_ARRAY) { 157 | _xpcsniffer_dumper(value, logDictionary); 158 | } 159 | else if (type == XPC_TYPE_DICTIONARY) { 160 | _xpcsniffer_dumper(value, logDictionary); 161 | } 162 | else { 163 | logDictionary[logKey] = [NSString stringWithFormat:@"Unknown: %p", type]; 164 | } 165 | 166 | return true; 167 | } 168 | 169 | static int _xpcsniffer_bplist_type(const char *bytes, size_t length) { 170 | int type = -1; 171 | 172 | if (bytes && length >= 8) { 173 | if (memcmp(bytes, "bplist16", 8) == 0) type = 16; 174 | else if (memcmp(bytes, "bplist15", 8) == 0) type = 15; 175 | else if (memcmp(bytes, "bplist00", 8) == 0) type = 0; 176 | } 177 | 178 | return type; 179 | } 180 | 181 | static NSString *_xpcsniffer_parse_bplist(const char *bytes, size_t length, int type) { 182 | NSString *returnValue = nil; 183 | 184 | switch (type) { 185 | // bplist00 186 | case 0: { 187 | NSError *error = nil; 188 | NSData *data = [NSData dataWithBytes:bytes length:length]; 189 | id plist = [NSPropertyListSerialization propertyListWithData:data options:0 format:nil error:&error]; 190 | if (!error && plist) returnValue = [plist description]; 191 | 192 | break; 193 | } 194 | // bplist15 195 | case 15: { 196 | if (__CFBinaryPlistCreate15) { 197 | CFPropertyListRef plist = __CFBinaryPlistCreate15((const uint8_t *)bytes, length); 198 | if (plist) { 199 | CFErrorRef dataError = nil; 200 | CFDataRef xmlData = CFPropertyListCreateData(kCFAllocatorDefault, plist, kCFPropertyListXMLFormat_v1_0, 0, &dataError); 201 | if (!dataError && xmlData) { 202 | NSData *data = (__bridge NSData *)xmlData; 203 | returnValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 204 | 205 | CFRelease(xmlData); 206 | } 207 | } 208 | } 209 | else { 210 | returnValue = _xpcsniffer_hex_string(bytes, length); 211 | } 212 | 213 | break; 214 | } 215 | // bplist16 216 | case 16: 217 | returnValue = _xpcsniffer_hex_string(bytes, length); 218 | break; 219 | } 220 | 221 | return returnValue; 222 | } 223 | 224 | static bool _xpcsniffer_dumper(xpc_object_t obj, NSMutableDictionary *logDictionary) { 225 | xpc_type_t type = xpc_get_type(obj); 226 | 227 | if (type == XPC_TYPE_CONNECTION) { 228 | int pid = xpc_connection_get_pid(obj); 229 | logDictionary[@"connection_name"] = _xpcsniffer_connection_name(obj); 230 | logDictionary[@"process_id"] = @(pid); 231 | logDictionary[@"process_name"] = _xpcsniffer_proc_name(pid); 232 | } 233 | else if (type == XPC_TYPE_ARRAY) { 234 | size_t count = xpc_array_get_count(obj); 235 | if (count > 0) { 236 | xpc_array_apply(obj, ^(size_t index, xpc_object_t value) { 237 | NSString *key = [NSString stringWithFormat:@"array_level_%lu", index]; 238 | logDictionary[key] = [NSMutableDictionary dictionary]; 239 | 240 | return _xpcsniffer_dumper(value, logDictionary[key]); 241 | }); 242 | } 243 | } 244 | else if (type == XPC_TYPE_DICTIONARY) { 245 | size_t count = xpc_dictionary_get_count(obj); 246 | if (count > 0) { 247 | xpc_dictionary_apply(obj, ^(const char *key, xpc_object_t value) { 248 | return _xpcsniffer_message_dump(key, value, logDictionary); 249 | }); 250 | } 251 | } 252 | 253 | return true; 254 | } 255 | 256 | static void _xpcsniffer_log_to_file(NSDictionary *dictionary) { 257 | dispatch_async(_xpcsniffer_queue, ^{ 258 | NSString *cachesDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]; 259 | NSString *logPath = [cachesDirectory stringByAppendingPathComponent:@"XPCSniffer.log"]; 260 | NSLog(@"+[XPCSniffer] Writing to %@", logPath); 261 | 262 | if (![NSFileManager.defaultManager fileExistsAtPath:logPath]) { 263 | [NSData.data writeToFile:logPath atomically:YES]; 264 | } 265 | 266 | // Make message 267 | NSError *error = nil; 268 | NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:&error]; 269 | if (!error && jsonData) { 270 | NSString *message = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 271 | message = [message stringByAppendingString:@"\n"]; 272 | 273 | // Append message 274 | NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:logPath]; 275 | [handle truncateFileAtOffset:handle.seekToEndOfFile]; 276 | [handle writeData:[message dataUsingEncoding:NSUTF8StringEncoding]]; 277 | [handle closeFile]; 278 | } 279 | }); 280 | } 281 | 282 | #pragma mark - xpc_connection_create 283 | 284 | // xpc_connection_t xpc_connection_create(const char *name, dispatch_queue_t targetq); 285 | __unused static xpc_connection_t (*orig_xpc_connection_create)(const char *name, dispatch_queue_t targetq); 286 | __unused static xpc_connection_t new_xpc_connection_create(const char *name, dispatch_queue_t targetq) { 287 | DLog(@"xpc_connection_create(\"%s\", targetq=%p);", name, targetq); 288 | 289 | xpc_connection_t returned = orig_xpc_connection_create(name, targetq); 290 | DLog(@"orig_xpc_connection_create(%p)", returned); 291 | 292 | return returned; 293 | } 294 | 295 | #pragma mark - xpc_pipe_routine 296 | 297 | // int xpc_pipe_routine(xpc_object_t xpcPipe, xpc_object_t *in, xpc_object_t *out); 298 | __unused static int (*orig_xpc_pipe_routine)(xpc_object_t xpcPipe, xpc_object_t *in, xpc_object_t *out); 299 | __unused static int new_xpc_pipe_routine (xpc_object_t xpcPipe, xpc_object_t *in, xpc_object_t *out) { 300 | // Call orig 301 | int returnValue = orig_xpc_pipe_routine(xpcPipe, in, out); 302 | 303 | // Log 304 | xpc_object_t message = *out; 305 | NSMutableDictionary *logDictionary = _xpcsniffer_dictionary(message); 306 | logDictionary[@"pipe_desc"] = @(xpc_copy_description(xpcPipe)); 307 | _xpcsniffer_dumper(message, logDictionary[@"xpc_message"]); 308 | DLog(@"XPC_PRO %@", logDictionary); 309 | 310 | return returnValue; 311 | } 312 | 313 | #pragma mark - xpc_connection_send_message 314 | 315 | // void xpc_connection_send_message(xpc_connection_t connection, xpc_object_t message); 316 | __unused static void (*orig_xpc_connection_send_message)(xpc_connection_t connection, xpc_object_t message); 317 | __unused static void new_xpc_connection_send_message(xpc_connection_t connection, xpc_object_t message) { 318 | NSMutableDictionary *logDictionary = _xpcsniffer_dictionary(connection); 319 | 320 | _xpcsniffer_dumper(connection, logDictionary); 321 | _xpcsniffer_dumper(message, logDictionary[@"xpc_message"]); 322 | 323 | DLog(@"XPC_CSM %@", logDictionary); 324 | _xpcsniffer_log_to_file(logDictionary); 325 | 326 | orig_xpc_connection_send_message(connection, message); 327 | } 328 | 329 | #pragma mark - xpc_connection_send_message_with_reply 330 | 331 | // void xpc_connection_send_message_with_reply(xpc_connection_t connection, xpc_object_t message, dispatch_queue_t replyq, xpc_handler_t handler); 332 | __unused static void (*orig_xpc_connection_send_message_with_reply)(xpc_connection_t connection, xpc_object_t message, dispatch_queue_t replyq, xpc_handler_t handler); 333 | __unused static void new_xpc_connection_send_message_with_reply(xpc_connection_t connection, xpc_object_t message, dispatch_queue_t replyq, xpc_handler_t handler) { 334 | NSMutableDictionary *logDictionary = _xpcsniffer_dictionary(connection); 335 | 336 | _xpcsniffer_dumper(connection, logDictionary); 337 | _xpcsniffer_dumper(message, logDictionary[@"xpc_message"]); 338 | DLog(@"XPC_CSMR %@", logDictionary); 339 | _xpcsniffer_log_to_file(logDictionary); 340 | 341 | orig_xpc_connection_send_message_with_reply(connection, message, replyq, handler); 342 | } 343 | 344 | #pragma mark - xpc_connection_send_message_with_reply_sync 345 | 346 | // xpc_object_t xpc_connection_send_message_with_reply_sync(xpc_connection_t connection, xpc_object_t message); 347 | __unused static xpc_object_t (*orig_xpc_connection_send_message_with_reply_sync)(xpc_connection_t connection, xpc_object_t message); 348 | __unused static xpc_object_t new_xpc_connection_send_message_with_reply_sync(xpc_connection_t connection, xpc_object_t message) { 349 | NSMutableDictionary *logDictionary = _xpcsniffer_dictionary(connection); 350 | 351 | _xpcsniffer_dumper(connection, logDictionary); 352 | _xpcsniffer_dumper(message, logDictionary[@"xpc_message"]); 353 | DLog(@"XPC_CSMRS %@", logDictionary); 354 | _xpcsniffer_log_to_file(logDictionary); 355 | 356 | return orig_xpc_connection_send_message_with_reply_sync(connection, message); 357 | } 358 | 359 | #pragma mark - ctor 360 | 361 | %ctor { 362 | @autoreleasepool { 363 | DLog(@"~~ Hooking ~~"); 364 | 365 | // CoreFoundation 366 | void *cf_handle = dlopen("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation", RTLD_NOW); 367 | DLog(@"cf_handle: %p", cf_handle); 368 | 369 | // _CFXPCCreateCFObjectFromXPCMessage 370 | uint32_t *_CFXPCCreateCFObjectFromXPCMessage = (uint32_t *)dlsym(cf_handle, "_CFXPCCreateCFObjectFromXPCMessage"); 371 | DLog(@"_CFXPCCreateCFObjectFromXPCMessage %p", _CFXPCCreateCFObjectFromXPCMessage); 372 | 373 | // __CFBinaryPlistCreate15 374 | __CFBinaryPlistCreate15 = (CFPropertyListRef(*)(const uint8_t *, uint64_t))_xpcsniffer_step64(_CFXPCCreateCFObjectFromXPCMessage, 64, 2, INSN_CALL); 375 | DLog(@"__CFBinaryPlistCreate15 %p", __CFBinaryPlistCreate15); 376 | 377 | // libxpc 378 | void *libxpc_handle = dlopen("/usr/lib/system/libxpc.dylib", RTLD_NOW); 379 | DLog(@"libxpc: %p", libxpc_handle); 380 | 381 | // xpc_connection_create 382 | void *xpc_connection_create = dlsym(libxpc_handle, "xpc_connection_create"); 383 | if (xpc_connection_create) { 384 | DLog(@"xpc_connection_create %p", xpc_connection_create); 385 | MSHookFunction((void *)xpc_connection_create, (void *)new_xpc_connection_create, (void **)&orig_xpc_connection_create); 386 | } 387 | 388 | // xpc_pipe_routine 389 | void *xpc_pipe_routine = dlsym(libxpc_handle, "xpc_pipe_routine"); 390 | if (xpc_pipe_routine) { 391 | DLog(@"xpc_pipe_routine %p", xpc_pipe_routine); 392 | MSHookFunction((void *)xpc_pipe_routine, (void *)new_xpc_pipe_routine, (void **)&orig_xpc_pipe_routine); 393 | } 394 | 395 | // xpc_connection_send_message 396 | void *xpc_connection_send_message = dlsym(libxpc_handle, "xpc_connection_send_message"); 397 | if (xpc_connection_send_message) { 398 | DLog(@"xpc_connection_send_message %p", xpc_connection_send_message); 399 | MSHookFunction((void *)xpc_connection_send_message, (void *)new_xpc_connection_send_message, (void **)&orig_xpc_connection_send_message); 400 | } 401 | 402 | // xpc_connection_send_message_with_reply 403 | void *xpc_connection_send_message_with_reply = dlsym(libxpc_handle, "xpc_connection_send_message_with_reply"); 404 | if (xpc_connection_send_message_with_reply) { 405 | DLog(@"xpc_connection_send_message_with_reply %p", xpc_connection_send_message_with_reply); 406 | MSHookFunction((void *)xpc_connection_send_message_with_reply, (void *)new_xpc_connection_send_message_with_reply, (void **)&orig_xpc_connection_send_message_with_reply); 407 | } 408 | 409 | // xpc_connection_send_message_with_reply_sync 410 | void *xpc_connection_send_message_with_reply_sync = dlsym(libxpc_handle, "xpc_connection_send_message_with_reply_sync"); 411 | if (xpc_connection_send_message_with_reply_sync) { 412 | DLog(@"xpc_connection_send_message_with_reply_sync %p", xpc_connection_send_message_with_reply_sync); 413 | MSHookFunction((void *)xpc_connection_send_message_with_reply_sync, (void *)new_xpc_connection_send_message_with_reply_sync, (void **)&orig_xpc_connection_send_message_with_reply_sync); 414 | } 415 | 416 | DLog(@"~~ End Hooking ~~"); 417 | } 418 | } -------------------------------------------------------------------------------- /Tweak.xm: -------------------------------------------------------------------------------- 1 | Tweak.mm -------------------------------------------------------------------------------- /XPCSniffer.plist: -------------------------------------------------------------------------------- 1 | { 2 | Filter = { 3 | Bundles = ( 4 | "com.apple.UIKit", 5 | "com.apple.itunesstored", 6 | "com.apple.appstored", 7 | "com.apple.AppStore", 8 | ); 9 | Executables = ( 10 | "securityd", 11 | "trustd", 12 | ); 13 | }; 14 | } -------------------------------------------------------------------------------- /all.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilpenguin/XPCSniffer/976dd26c299b38cf6542f619332c3f59e0cebcbe/all.png -------------------------------------------------------------------------------- /control: -------------------------------------------------------------------------------- 1 | Package: com.evilpenguin.xpcsniffer 2 | Name: XPCSniffer 3 | Depends: mobilesubstrate 4 | Version: 0.2.1 5 | Architecture: iphoneos-arm 6 | Description: XPCSniffer 7 | Maintainer: EvilPenguin 8 | Author: EvilPenguin 9 | Section: Tweaks 10 | -------------------------------------------------------------------------------- /libproc/libproc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006, 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 | #ifndef _LIBPROC_H_ 24 | #define _LIBPROC_H_ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | //#include 31 | #include 32 | 33 | //#include 34 | 35 | /* 36 | * This header file contains private interfaces to obtain process information. 37 | * These interfaces are subject to change in future releases. 38 | */ 39 | 40 | /*! 41 | @define PROC_LISTPIDSPATH_PATH_IS_VOLUME 42 | @discussion This flag indicates that all processes that hold open 43 | file references on the volume associated with the specified 44 | path should be returned. 45 | */ 46 | #define PROC_LISTPIDSPATH_PATH_IS_VOLUME 1 47 | 48 | 49 | /*! 50 | @define PROC_LISTPIDSPATH_EXCLUDE_EVTONLY 51 | @discussion This flag indicates that file references that were opened 52 | with the O_EVTONLY flag should be excluded from the matching 53 | criteria. 54 | */ 55 | #define PROC_LISTPIDSPATH_EXCLUDE_EVTONLY 2 56 | 57 | __BEGIN_DECLS 58 | 59 | int proc_listpids(uint32_t type, uint32_t typeinfo, void *buffer, int buffersize); 60 | 61 | /*! 62 | @function proc_listpidspath 63 | @discussion A function which will search through the current 64 | processes looking for open file references which match 65 | a specified path or volume. 66 | @param type types of processes to be searched (see proc_listpids) 67 | @param typeinfo adjunct information for type 68 | @param path file or volume path 69 | @param pathflags flags to control which files should be considered 70 | during the process search. 71 | @param buffer a C array of int-sized values to be filled with 72 | process identifiers that hold an open file reference 73 | matching the specified path or volume. Pass NULL to 74 | obtain the minimum buffer size needed to hold the 75 | currently active processes. 76 | @param buffersize the size (in bytes) of the provided buffer. 77 | @result the number of bytes of data returned in the provided buffer; 78 | -1 if an error was encountered; 79 | */ 80 | int proc_listpidspath(uint32_t type, 81 | uint32_t typeinfo, 82 | const char *path, 83 | uint32_t pathflags, 84 | void *buffer, 85 | int buffersize); 86 | 87 | int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize); 88 | int proc_pidfdinfo(int pid, int fd, int flavor, void * buffer, int buffersize); 89 | int proc_name(int pid, void * buffer, uint32_t buffersize); 90 | int proc_regionfilename(int pid, uint64_t address, void * buffer, uint32_t buffersize); 91 | int proc_kmsgbuf(void * buffer, uint32_t buffersize); 92 | int proc_pidpath(int pid, void * buffer, uint32_t buffersize); 93 | int proc_libversion(int *major, int * minor); 94 | 95 | __END_DECLS 96 | 97 | #endif /*_LIBPROC_H_ */ 98 | -------------------------------------------------------------------------------- /packages/com.evilpenguin.xpcsniffer_0.2.1-1+debug_iphoneos-arm.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilpenguin/XPCSniffer/976dd26c299b38cf6542f619332c3f59e0cebcbe/packages/com.evilpenguin.xpcsniffer_0.2.1-1+debug_iphoneos-arm.deb -------------------------------------------------------------------------------- /xpc/activity.h: -------------------------------------------------------------------------------- 1 | #ifndef __XPC_ACTIVITY_H__ 2 | #define __XPC_ACTIVITY_H__ 3 | 4 | #ifndef __XPC_INDIRECT__ 5 | #error "Please #include instead of this file directly." 6 | // For HeaderDoc. 7 | #include 8 | #endif // __XPC_INDIRECT__ 9 | 10 | #ifdef __BLOCKS__ 11 | 12 | XPC_ASSUME_NONNULL_BEGIN 13 | __BEGIN_DECLS 14 | 15 | /* 16 | * The following are a collection of keys and values used to set an activity's 17 | * execution criteria. 18 | */ 19 | 20 | /*! 21 | * @constant XPC_ACTIVITY_INTERVAL 22 | * An integer property indicating the desired time interval (in seconds) of the 23 | * activity. The activity will not be run more than once per time interval. 24 | * Due to the nature of XPC Activity finding an opportune time to run 25 | * the activity, any two occurrences may be more or less than 'interval' 26 | * seconds apart, but on average will be 'interval' seconds apart. 27 | * The presence of this key implies the following, unless overridden: 28 | * - XPC_ACTIVITY_REPEATING with a value of true 29 | * - XPC_ACTIVITY_DELAY with a value of half the 'interval' 30 | * The delay enforces a minimum distance between any two occurrences. 31 | * - XPC_ACTIVITY_GRACE_PERIOD with a value of half the 'interval'. 32 | * The grace period is the amount of time allowed to pass after the end of 33 | * the interval before more aggressive scheduling occurs. The grace period 34 | * does not increase the size of the interval. 35 | */ 36 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 37 | XPC_EXPORT 38 | const char * const XPC_ACTIVITY_INTERVAL; 39 | 40 | /*! 41 | * @constant XPC_ACTIVITY_REPEATING 42 | * A boolean property indicating whether this is a repeating activity. 43 | */ 44 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 45 | XPC_EXPORT 46 | const char * const XPC_ACTIVITY_REPEATING; 47 | 48 | /*! 49 | * @constant XPC_ACTIVITY_DELAY 50 | * An integer property indicating the number of seconds to delay before 51 | * beginning the activity. 52 | */ 53 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 54 | XPC_EXPORT 55 | const char * const XPC_ACTIVITY_DELAY; 56 | 57 | /*! 58 | * @constant XPC_ACTIVITY_GRACE_PERIOD 59 | * An integer property indicating the number of seconds to allow as a grace 60 | * period before the scheduling of the activity becomes more aggressive. 61 | */ 62 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 63 | XPC_EXPORT 64 | const char * const XPC_ACTIVITY_GRACE_PERIOD; 65 | 66 | 67 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 68 | XPC_EXPORT 69 | const int64_t XPC_ACTIVITY_INTERVAL_1_MIN; 70 | 71 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 72 | XPC_EXPORT 73 | const int64_t XPC_ACTIVITY_INTERVAL_5_MIN; 74 | 75 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 76 | XPC_EXPORT 77 | const int64_t XPC_ACTIVITY_INTERVAL_15_MIN; 78 | 79 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 80 | XPC_EXPORT 81 | const int64_t XPC_ACTIVITY_INTERVAL_30_MIN; 82 | 83 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 84 | XPC_EXPORT 85 | const int64_t XPC_ACTIVITY_INTERVAL_1_HOUR; 86 | 87 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 88 | XPC_EXPORT 89 | const int64_t XPC_ACTIVITY_INTERVAL_4_HOURS; 90 | 91 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 92 | XPC_EXPORT 93 | const int64_t XPC_ACTIVITY_INTERVAL_8_HOURS; 94 | 95 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 96 | XPC_EXPORT 97 | const int64_t XPC_ACTIVITY_INTERVAL_1_DAY; 98 | 99 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 100 | XPC_EXPORT 101 | const int64_t XPC_ACTIVITY_INTERVAL_7_DAYS; 102 | 103 | /*! 104 | * @constant XPC_ACTIVITY_PRIORITY 105 | * A string property indicating the priority of the activity. 106 | */ 107 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 108 | XPC_EXPORT 109 | const char * const XPC_ACTIVITY_PRIORITY; 110 | 111 | /*! 112 | * @constant XPC_ACTIVITY_PRIORITY_MAINTENANCE 113 | * A string indicating activity is maintenance priority. 114 | * 115 | * Maintenance priority is intended for user-invisible maintenance tasks 116 | * such as garbage collection or optimization. 117 | * 118 | * Maintenance activities are not permitted to run if the device thermal 119 | * condition exceeds a nominal level or if the battery level is lower than 20%. 120 | * In Low Power Mode (on supported devices), maintenance activities are not 121 | * permitted to run while the device is on battery, or plugged in and the 122 | * battery level is lower than 30%. 123 | */ 124 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 125 | XPC_EXPORT 126 | const char * const XPC_ACTIVITY_PRIORITY_MAINTENANCE; 127 | 128 | /*! 129 | * @constant XPC_ACTIVITY_PRIORITY_UTILITY 130 | * A string indicating activity is utility priority. 131 | * 132 | * Utility priority is intended for user-visible tasks such as fetching data 133 | * from the network, copying files, or importing data. 134 | * 135 | * Utility activities are not permitted to run if the device thermal condition 136 | * exceeds a moderate level or if the battery level is less than 10%. In Low 137 | * Power Mode (on supported devices) when on battery power, utility activities 138 | * are only permitted when they are close to their deadline (90% of their time 139 | * window has elapsed). 140 | */ 141 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 142 | XPC_EXPORT 143 | const char * const XPC_ACTIVITY_PRIORITY_UTILITY; 144 | 145 | /*! 146 | * @constant XPC_ACTIVITY_ALLOW_BATTERY 147 | * A Boolean value indicating whether the activity should be allowed to run 148 | * while the computer is on battery power. The default value is false for 149 | * maintenance priority activity and true for utility priority activity. 150 | */ 151 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 152 | XPC_EXPORT 153 | const char * const XPC_ACTIVITY_ALLOW_BATTERY; 154 | 155 | /*! 156 | * @constant XPC_ACTIVITY_REQUIRE_SCREEN_SLEEP 157 | * A Boolean value indicating whether the activity should only be performed 158 | * while device appears to be asleep. Note that the definition of screen sleep 159 | * may vary by platform and may include states where the device is known to be 160 | * idle despite the fact that the display itself is still powered. Defaults to 161 | * false. 162 | */ 163 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 164 | XPC_EXPORT 165 | const char * const XPC_ACTIVITY_REQUIRE_SCREEN_SLEEP; // bool 166 | 167 | /*! 168 | * @constant XPC_ACTIVITY_REQUIRE_BATTERY_LEVEL 169 | * An integer percentage of minimum battery charge required to allow the 170 | * activity to run. A default minimum battery level is determined by the 171 | * system. 172 | */ 173 | __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_9, __MAC_10_9, __IPHONE_7_0, __IPHONE_7_0, 174 | "REQUIRE_BATTERY_LEVEL is not implemented") 175 | XPC_EXPORT 176 | const char * const XPC_ACTIVITY_REQUIRE_BATTERY_LEVEL; // int (%) 177 | 178 | /*! 179 | * @constant XPC_ACTIVITY_REQUIRE_HDD_SPINNING 180 | * A Boolean value indicating whether the activity should only be performed 181 | * while the hard disk drive (HDD) is spinning. Computers with flash storage 182 | * are considered to be equivalent to HDD spinning. Defaults to false. 183 | */ 184 | __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_9, __MAC_10_9, __IPHONE_7_0, __IPHONE_7_0, 185 | "REQUIRE_HDD_SPINNING is not implemented") 186 | XPC_EXPORT 187 | const char * const XPC_ACTIVITY_REQUIRE_HDD_SPINNING; // bool 188 | 189 | /*! 190 | * @define XPC_TYPE_ACTIVITY 191 | * A type representing the XPC activity object. 192 | */ 193 | #define XPC_TYPE_ACTIVITY (&_xpc_type_activity) 194 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 195 | XPC_EXPORT 196 | XPC_TYPE(_xpc_type_activity); 197 | 198 | /*! 199 | * @typedef xpc_activity_t 200 | * 201 | * @abstract 202 | * An XPC activity object. 203 | * 204 | * @discussion 205 | * This object represents a set of execution criteria and a current execution 206 | * state for background activity on the system. Once an activity is registered, 207 | * the system will evaluate its criteria to determine whether the activity is 208 | * eligible to run under current system conditions. When an activity becomes 209 | * eligible to run, its execution state will be updated and an invocation of 210 | * its handler block will be made. 211 | */ 212 | XPC_DECL(xpc_activity); 213 | 214 | /*! 215 | * @typedef xpc_activity_handler_t 216 | * 217 | * @abstract 218 | * A block that is called when an XPC activity becomes eligible to run. 219 | */ 220 | XPC_NONNULL1 221 | typedef void (^xpc_activity_handler_t)(xpc_activity_t activity); 222 | 223 | /*! 224 | * @constant XPC_ACTIVITY_CHECK_IN 225 | * This constant may be passed to xpc_activity_register() as the criteria 226 | * dictionary in order to check in with the system for previously registered 227 | * activity using the same identifier (for example, an activity taken from a 228 | * launchd property list). 229 | */ 230 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 231 | XPC_EXPORT 232 | const xpc_object_t XPC_ACTIVITY_CHECK_IN; 233 | 234 | /*! 235 | * @function xpc_activity_register 236 | * 237 | * @abstract 238 | * Registers an activity with the system. 239 | * 240 | * @discussion 241 | * Registers a new activity with the system. The criteria of the activity are 242 | * described by the dictionary passed to this function. If an activity with the 243 | * same identifier already exists, the criteria provided override the existing 244 | * criteria unless the special dictionary XPC_ACTIVITY_CHECK_IN is used. The 245 | * XPC_ACTIVITY_CHECK_IN dictionary instructs the system to first look up an 246 | * existing activity without modifying its criteria. Once the existing activity 247 | * is found (or a new one is created with an empty set of criteria) the handler 248 | * will be called with an activity object in the XPC_ACTIVITY_STATE_CHECK_IN 249 | * state. 250 | * 251 | * @param identifier 252 | * A unique identifier for the activity. Each application has its own namespace. 253 | * The identifier should remain constant across registrations, relaunches of 254 | * the application, and reboots. It should identify the kind of work being done, 255 | * not a particular invocation of the work. 256 | * 257 | * @param criteria 258 | * A dictionary of criteria for the activity. 259 | * 260 | * @param handler 261 | * The handler block to be called when the activity changes state to one of the 262 | * following states: 263 | * - XPC_ACTIVITY_STATE_CHECK_IN (optional) 264 | * - XPC_ACTIVITY_STATE_RUN 265 | * 266 | * The handler block is never invoked reentrantly. It will be invoked on a 267 | * dispatch queue with an appropriate priority to perform the activity. 268 | */ 269 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 270 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 XPC_NONNULL3 271 | void 272 | xpc_activity_register(const char *identifier, xpc_object_t criteria, 273 | xpc_activity_handler_t handler); 274 | 275 | /*! 276 | * @function xpc_activity_copy_criteria 277 | * 278 | * @abstract 279 | * Returns an XPC dictionary describing the execution criteria of an activity. 280 | * This will return NULL in cases where the activity has already completed, e.g. 281 | * when checking in to an event that finished and was not rescheduled. 282 | */ 283 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 284 | XPC_EXPORT XPC_WARN_RESULT XPC_RETURNS_RETAINED XPC_NONNULL1 285 | xpc_object_t _Nullable 286 | xpc_activity_copy_criteria(xpc_activity_t activity); 287 | 288 | /*! 289 | * @function xpc_activity_set_criteria 290 | * 291 | * @abstract 292 | * Modifies the execution criteria of an activity. 293 | */ 294 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 295 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 296 | void 297 | xpc_activity_set_criteria(xpc_activity_t activity, xpc_object_t criteria); 298 | 299 | /*! 300 | * @enum xpc_activity_state_t 301 | * An activity is defined to be in one of the following states. Applications 302 | * may check the current state of the activity using xpc_activity_get_state() 303 | * in the handler block provided to xpc_activity_register(). 304 | * 305 | * The application can modify the state of the activity by calling 306 | * xpc_activity_set_state() with one of the following: 307 | * - XPC_ACTIVITY_STATE_DEFER 308 | * - XPC_ACTIVITY_STATE_CONTINUE 309 | * - XPC_ACTIVITY_STATE_DONE 310 | * 311 | * @constant XPC_ACTIVITY_STATE_CHECK_IN 312 | * An activity in this state has just completed a checkin with the system after 313 | * XPC_ACTIVITY_CHECK_IN was provided as the criteria dictionary to 314 | * xpc_activity_register. The state gives the application an opportunity to 315 | * inspect and modify the activity's criteria. 316 | * 317 | * @constant XPC_ACTIVITY_STATE_WAIT 318 | * An activity in this state is waiting for an opportunity to run. This value 319 | * is never returned within the activity's handler block, as the block is 320 | * invoked in response to XPC_ACTIVITY_STATE_CHECK_IN or XPC_ACTIVITY_STATE_RUN. 321 | * 322 | * Note: 323 | * A launchd job may idle exit while an activity is in the wait state and be 324 | * relaunched in response to the activity becoming runnable. The launchd job 325 | * simply needs to re-register for the activity on its next launch by passing 326 | * XPC_ACTIVITY_STATE_CHECK_IN to xpc_activity_register(). 327 | * 328 | * @constant XPC_ACTIVITY_STATE_RUN 329 | * An activity in this state is eligible to run based on its criteria. 330 | * 331 | * @constant XPC_ACTIVITY_STATE_DEFER 332 | * An application may pass this value to xpc_activity_set_state() to indicate 333 | * that the activity should be deferred (placed back into the WAIT state) until 334 | * a time when its criteria are met again. Deferring an activity does not reset 335 | * any of its time-based criteria (in other words, it will remain past due). 336 | * 337 | * IMPORTANT: 338 | * This should be done in response to observing xpc_activity_should_defer(). 339 | * It should not be done unilaterally. If you determine that conditions are bad 340 | * to do your activity's work for reasons you can't express in a criteria 341 | * dictionary, you should set the activity's state to XPC_ACTIVITY_STATE_DONE. 342 | * 343 | * 344 | * @constant XPC_ACTIVITY_STATE_CONTINUE 345 | * An application may pass this value to xpc_activity_set_state() to indicate 346 | * that the activity will continue its operation beyond the return of its 347 | * handler block. This can be used to extend an activity to include asynchronous 348 | * operations. The activity's handler block will not be invoked again until the 349 | * state has been updated to either XPC_ACTIVITY_STATE_DEFER or, in the case 350 | * of repeating activity, XPC_ACTIVITY_STATE_DONE. 351 | * 352 | * @constant XPC_ACTIVITY_STATE_DONE 353 | * An application may pass this value to xpc_activity_set_state() to indicate 354 | * that the activity has completed. For non-repeating activity, the resources 355 | * associated with the activity will be automatically released upon return from 356 | * the handler block. For repeating activity, timers present in the activity's 357 | * criteria will be reset. 358 | */ 359 | enum { 360 | XPC_ACTIVITY_STATE_CHECK_IN, 361 | XPC_ACTIVITY_STATE_WAIT, 362 | XPC_ACTIVITY_STATE_RUN, 363 | XPC_ACTIVITY_STATE_DEFER, 364 | XPC_ACTIVITY_STATE_CONTINUE, 365 | XPC_ACTIVITY_STATE_DONE, 366 | }; 367 | typedef long xpc_activity_state_t; 368 | 369 | /*! 370 | * @function xpc_activity_get_state 371 | * 372 | * @abstract 373 | * Returns the current state of an activity. 374 | */ 375 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 376 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 377 | xpc_activity_state_t 378 | xpc_activity_get_state(xpc_activity_t activity); 379 | 380 | /*! 381 | * @function xpc_activity_set_state 382 | * 383 | * @abstract 384 | * Updates the current state of an activity. 385 | * 386 | * @return 387 | * Returns true if the state was successfully updated; otherwise, returns 388 | * false if the requested state transition is not valid. 389 | */ 390 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 391 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 392 | bool 393 | xpc_activity_set_state(xpc_activity_t activity, xpc_activity_state_t state); 394 | 395 | /*! 396 | * @function xpc_activity_should_defer 397 | * 398 | * @abstract 399 | * Test whether an activity should be deferred. 400 | * 401 | * @discussion 402 | * This function may be used to test whether the criteria of a long-running 403 | * activity are still satisfied. If not, the system indicates that the 404 | * application should defer the activity. The application may acknowledge the 405 | * deferral by calling xpc_activity_set_state() with XPC_ACTIVITY_STATE_DEFER. 406 | * Once deferred, the system will place the activity back into the WAIT state 407 | * and re-invoke the handler block at the earliest opportunity when the criteria 408 | * are once again satisfied. 409 | * 410 | * @return 411 | * Returns true if the activity should be deferred. 412 | */ 413 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 414 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 415 | bool 416 | xpc_activity_should_defer(xpc_activity_t activity); 417 | 418 | /*! 419 | * @function xpc_activity_unregister 420 | * 421 | * @abstract 422 | * Unregisters an activity found by its identifier. 423 | * 424 | * @discussion 425 | * A dynamically registered activity will be deleted in response to this call. 426 | * Statically registered activity (from a launchd property list) will be 427 | * deleted until the job is next loaded (e.g. at next boot). 428 | * 429 | * Unregistering an activity has no effect on any outstanding xpc_activity_t 430 | * objects or any currently executing xpc_activity_handler_t blocks; however, 431 | * no new handler block invocations will be made after it is unregistered. 432 | * 433 | * @param identifier 434 | * The identifier of the activity to unregister. 435 | */ 436 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) 437 | XPC_EXPORT XPC_NONNULL1 438 | void 439 | xpc_activity_unregister(const char *identifier); 440 | 441 | __END_DECLS 442 | XPC_ASSUME_NONNULL_END 443 | 444 | #endif // __BLOCKS__ 445 | 446 | #endif // __XPC_ACTIVITY_H__ 447 | 448 | -------------------------------------------------------------------------------- /xpc/availability.h: -------------------------------------------------------------------------------- 1 | #ifndef __XPC_AVAILABILITY_H__ 2 | #define __XPC_AVAILABILITY_H__ 3 | 4 | #include 5 | 6 | // Certain parts of the project use all the project's headers but have to build 7 | // against newer OSX SDKs than ebuild uses -- liblaunch_host being the example. 8 | // So we need to define these. 9 | #ifndef __MAC_10_15 10 | #define __MAC_10_15 101500 11 | #define __AVAILABILITY_INTERNAL__MAC_10_15 \ 12 | __attribute__((availability(macosx, introduced=10.15))) 13 | #endif // __MAC_10_15 14 | 15 | #ifndef __MAC_10_14 16 | #define __MAC_10_14 101400 17 | #define __AVAILABILITY_INTERNAL__MAC_10_14 \ 18 | __attribute__((availability(macosx, introduced=10.14))) 19 | #endif // __MAC_10_14 20 | 21 | #ifndef __MAC_10_13 22 | #define __MAC_10_13 101300 23 | #define __AVAILABILITY_INTERNAL__MAC_10_13 \ 24 | __attribute__((availability(macosx, introduced=10.13))) 25 | #endif // __MAC_10_13 26 | 27 | #ifndef __MAC_10_12 28 | #define __MAC_10_12 101200 29 | #define __AVAILABILITY_INTERNAL__MAC_10_12 \ 30 | __attribute__((availability(macosx, introduced=10.12))) 31 | #endif // __MAC_10_12 32 | 33 | #ifndef __MAC_10_11 34 | #define __MAC_10_11 101100 35 | #define __AVAILABILITY_INTERNAL__MAC_10_11 \ 36 | __attribute__((availability(macosx, introduced=10.11))) 37 | #endif // __MAC_10_11 38 | 39 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_2_DEP__MAC_10_11 40 | #define __AVAILABILITY_INTERNAL__MAC_10_2_DEP__MAC_10_11 41 | #endif // __AVAILABILITY_INTERNAL__MAC_10_2_DEP__MAC_10_11 42 | 43 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_3_DEP__MAC_10_11 44 | #define __AVAILABILITY_INTERNAL__MAC_10_3_DEP__MAC_10_11 45 | #endif // __AVAILABILITY_INTERNAL__MAC_10_3_DEP__MAC_10_11 46 | 47 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_4_DEP__MAC_10_11 48 | #define __AVAILABILITY_INTERNAL__MAC_10_4_DEP__MAC_10_11 49 | #endif // __AVAILABILITY_INTERNAL__MAC_10_4_DEP__MAC_10_11 50 | 51 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_5_DEP__MAC_10_11 52 | #define __AVAILABILITY_INTERNAL__MAC_10_5_DEP__MAC_10_11 53 | #endif // __AVAILABILITY_INTERNAL__MAC_10_5_DEP__MAC_10_11 54 | 55 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_6_DEP__MAC_10_11 56 | #define __AVAILABILITY_INTERNAL__MAC_10_6_DEP__MAC_10_11 57 | #endif // __AVAILABILITY_INTERNAL__MAC_10_6_DEP__MAC_10_11 58 | 59 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_7_DEP__MAC_10_11 60 | #define __AVAILABILITY_INTERNAL__MAC_10_7_DEP__MAC_10_11 61 | #endif // __AVAILABILITY_INTERNAL__MAC_10_7_DEP__MAC_10_11 62 | 63 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_8_DEP__MAC_10_11 64 | #define __AVAILABILITY_INTERNAL__MAC_10_8_DEP__MAC_10_11 65 | #endif // __AVAILABILITY_INTERNAL__MAC_10_8_DEP__MAC_10_11 66 | 67 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_9_DEP__MAC_10_11 68 | #define __AVAILABILITY_INTERNAL__MAC_10_9_DEP__MAC_10_11 69 | #endif // __AVAILABILITY_INTERNAL__MAC_10_9_DEP__MAC_10_11 70 | 71 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_10_DEP__MAC_10_11 72 | #define __AVAILABILITY_INTERNAL__MAC_10_10_DEP__MAC_10_11 73 | #endif // __AVAILABILITY_INTERNAL__MAC_10_10_DEP__MAC_10_11 74 | 75 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_11_DEP__MAC_10_11 76 | #define __AVAILABILITY_INTERNAL__MAC_10_11_DEP__MAC_10_11 77 | #endif // __AVAILABILITY_INTERNAL__MAC_10_11_DEP__MAC_10_11 78 | 79 | #ifndef __AVAILABILITY_INTERNAL__MAC_10_6_DEP__MAC_10_13 80 | #define __AVAILABILITY_INTERNAL__MAC_10_6_DEP__MAC_10_13 81 | #endif // __AVAILABILITY_INTERNAL__MAC_10_6_DEP__MAC_10_13 82 | 83 | #if __has_include() 84 | #include 85 | #else // __has_include() 86 | #ifndef IPHONE_SIMULATOR_HOST_MIN_VERSION_REQUIRED 87 | #define IPHONE_SIMULATOR_HOST_MIN_VERSION_REQUIRED 999999 88 | #endif // IPHONE_SIMULATOR_HOST_MIN_VERSION_REQUIRED 89 | #endif // __has_include() 90 | 91 | #ifndef __WATCHOS_UNAVAILABLE 92 | #define __WATCHOS_UNAVAILABLE 93 | #endif 94 | 95 | #ifndef __TVOS_UNAVAILABLE 96 | #define __TVOS_UNAVAILABLE 97 | #endif 98 | 99 | // simulator host-side bits build against SDKs not having __*_AVAILABLE() yet 100 | #ifndef __OSX_AVAILABLE 101 | #define __OSX_AVAILABLE(...) 102 | #endif 103 | 104 | #ifndef __IOS_AVAILABLE 105 | #define __IOS_AVAILABLE(...) 106 | #endif 107 | 108 | #ifndef __TVOS_AVAILABLE 109 | #define __TVOS_AVAILABLE(...) 110 | #endif 111 | 112 | #ifndef __WATCHOS_AVAILABLE 113 | #define __WATCHOS_AVAILABLE(...) 114 | #endif 115 | 116 | #ifndef __API_AVAILABLE 117 | #define __API_AVAILABLE(...) 118 | #endif 119 | 120 | #endif // __XPC_AVAILABILITY_H__ 121 | -------------------------------------------------------------------------------- /xpc/base.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009-2011 Apple Inc. All rights reserved. 2 | 3 | #ifndef __XPC_BASE_H__ 4 | #define __XPC_BASE_H__ 5 | 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | #if !defined(__has_include) 11 | #define __has_include(x) 0 12 | #endif // !defined(__has_include) 13 | 14 | #if !defined(__has_attribute) 15 | #define __has_attribute(x) 0 16 | #endif // !defined(__has_attribute) 17 | 18 | #if !defined(__has_feature) 19 | #define __has_feature(x) 0 20 | #endif // !defined(__has_feature) 21 | 22 | #if !defined(__has_extension) 23 | #define __has_extension(x) 0 24 | #endif // !defined(__has_extension) 25 | 26 | #if __has_include() 27 | #include 28 | #else // __has_include() 29 | #include 30 | #endif // __has_include() 31 | 32 | #ifndef __XPC_INDIRECT__ 33 | #error "Please #include instead of this file directly." 34 | #endif // __XPC_INDIRECT__ 35 | 36 | #pragma mark Attribute Shims 37 | #ifdef __GNUC__ 38 | #define XPC_CONSTRUCTOR __attribute__((constructor)) 39 | #define XPC_NORETURN __attribute__((__noreturn__)) 40 | #define XPC_NOTHROW __attribute__((__nothrow__)) 41 | #define XPC_NONNULL1 __attribute__((__nonnull__(1))) 42 | #define XPC_NONNULL2 __attribute__((__nonnull__(2))) 43 | #define XPC_NONNULL3 __attribute__((__nonnull__(3))) 44 | #define XPC_NONNULL4 __attribute__((__nonnull__(4))) 45 | #define XPC_NONNULL5 __attribute__((__nonnull__(5))) 46 | #define XPC_NONNULL6 __attribute__((__nonnull__(6))) 47 | #define XPC_NONNULL7 __attribute__((__nonnull__(7))) 48 | #define XPC_NONNULL8 __attribute__((__nonnull__(8))) 49 | #define XPC_NONNULL9 __attribute__((__nonnull__(9))) 50 | #define XPC_NONNULL10 __attribute__((__nonnull__(10))) 51 | #define XPC_NONNULL11 __attribute__((__nonnull__(11))) 52 | #define XPC_NONNULL_ALL __attribute__((__nonnull__)) 53 | #define XPC_SENTINEL __attribute__((__sentinel__)) 54 | #define XPC_PURE __attribute__((__pure__)) 55 | #define XPC_WARN_RESULT __attribute__((__warn_unused_result__)) 56 | #define XPC_MALLOC __attribute__((__malloc__)) 57 | #define XPC_UNUSED __attribute__((__unused__)) 58 | #define XPC_USED __attribute__((__used__)) 59 | #define XPC_PACKED __attribute__((__packed__)) 60 | #define XPC_PRINTF(m, n) __attribute__((format(printf, m, n))) 61 | #define XPC_INLINE static __inline__ __attribute__((__always_inline__)) 62 | #define XPC_NOINLINE __attribute__((noinline)) 63 | #define XPC_NOIMPL __attribute__((unavailable)) 64 | 65 | #if __has_attribute(noescape) 66 | #define XPC_NOESCAPE __attribute__((__noescape__)) 67 | #else 68 | #define XPC_NOESCAPE 69 | #endif 70 | 71 | #if __has_extension(attribute_unavailable_with_message) 72 | #define XPC_UNAVAILABLE(m) __attribute__((unavailable(m))) 73 | #else // __has_extension(attribute_unavailable_with_message) 74 | #define XPC_UNAVAILABLE(m) XPC_NOIMPL 75 | #endif // __has_extension(attribute_unavailable_with_message) 76 | 77 | #define XPC_EXPORT extern __attribute__((visibility("default"))) 78 | #define XPC_NOEXPORT __attribute__((visibility("hidden"))) 79 | #define XPC_WEAKIMPORT extern __attribute__((weak_import)) 80 | #define XPC_DEBUGGER_EXCL XPC_NOEXPORT XPC_USED 81 | #define XPC_TRANSPARENT_UNION __attribute__((transparent_union)) 82 | #if __clang__ 83 | #define XPC_DEPRECATED(m) __attribute__((deprecated(m))) 84 | #else // __clang__ 85 | #define XPC_DEPRECATED(m) __attribute__((deprecated)) 86 | #endif // __clang 87 | 88 | #if defined(__XPC_TEST__) && __XPC_TEST__ 89 | #define XPC_TESTSTATIC 90 | #define XPC_TESTEXTERN(x) extern x 91 | #else // defined(__XPC_TEST__) && __XPC_TEST__ 92 | #define XPC_TESTSTATIC static 93 | #define XPC_TESTEXTERN(x) 94 | #endif // defined(__XPC_TEST__) && __XPC_TEST__ 95 | 96 | #if __has_feature(objc_arc) 97 | #define XPC_GIVES_REFERENCE __strong 98 | #define XPC_UNRETAINED __unsafe_unretained 99 | #define XPC_BRIDGE(xo) ((__bridge void *)(xo)) 100 | #define XPC_BRIDGEREF_BEGIN(xo) ((__bridge_retained void *)(xo)) 101 | #define XPC_BRIDGEREF_BEGIN_WITH_REF(xo) ((__bridge void *)(xo)) 102 | #define XPC_BRIDGEREF_MIDDLE(xo) ((__bridge id)(xo)) 103 | #define XPC_BRIDGEREF_END(xo) ((__bridge_transfer id)(xo)) 104 | #else // __has_feature(objc_arc) 105 | #define XPC_GIVES_REFERENCE 106 | #define XPC_UNRETAINED 107 | #define XPC_BRIDGE(xo) (xo) 108 | #define XPC_BRIDGEREF_BEGIN(xo) (xo) 109 | #define XPC_BRIDGEREF_BEGIN_WITH_REF(xo) (xo) 110 | #define XPC_BRIDGEREF_MIDDLE(xo) (xo) 111 | #define XPC_BRIDGEREF_END(xo) (xo) 112 | #endif // __has_feature(objc_arc) 113 | 114 | #define _xpc_unreachable() __builtin_unreachable() 115 | #else // __GNUC__ 116 | /*! @parseOnly */ 117 | #define XPC_CONSTRUCTOR 118 | /*! @parseOnly */ 119 | #define XPC_NORETURN 120 | /*! @parseOnly */ 121 | #define XPC_NOTHROW 122 | /*! @parseOnly */ 123 | #define XPC_NONNULL1 124 | /*! @parseOnly */ 125 | #define XPC_NONNULL2 126 | /*! @parseOnly */ 127 | #define XPC_NONNULL3 128 | /*! @parseOnly */ 129 | #define XPC_NONNULL4 130 | /*! @parseOnly */ 131 | #define XPC_NONNULL5 132 | /*! @parseOnly */ 133 | #define XPC_NONNULL6 134 | /*! @parseOnly */ 135 | #define XPC_NONNULL7 136 | /*! @parseOnly */ 137 | #define XPC_NONNULL8 138 | /*! @parseOnly */ 139 | #define XPC_NONNULL9 140 | /*! @parseOnly */ 141 | #define XPC_NONNULL10 142 | /*! @parseOnly */ 143 | #define XPC_NONNULL11 144 | /*! @parseOnly */ 145 | #define XPC_NONNULL(n) 146 | /*! @parseOnly */ 147 | #define XPC_NONNULL_ALL 148 | /*! @parseOnly */ 149 | #define XPC_SENTINEL 150 | /*! @parseOnly */ 151 | #define XPC_PURE 152 | /*! @parseOnly */ 153 | #define XPC_WARN_RESULT 154 | /*! @parseOnly */ 155 | #define XPC_MALLOC 156 | /*! @parseOnly */ 157 | #define XPC_UNUSED 158 | /*! @parseOnly */ 159 | #define XPC_PACKED 160 | /*! @parseOnly */ 161 | #define XPC_PRINTF(m, n) 162 | /*! @parseOnly */ 163 | #define XPC_INLINE static inline 164 | /*! @parseOnly */ 165 | #define XPC_NOINLINE 166 | /*! @parseOnly */ 167 | #define XPC_NOIMPL 168 | /*! @parseOnly */ 169 | #define XPC_EXPORT extern 170 | /*! @parseOnly */ 171 | #define XPC_WEAKIMPORT 172 | /*! @parseOnly */ 173 | #define XPC_DEPRECATED 174 | /*! @parseOnly */ 175 | #define XPC_UNAVAILABLE(m) 176 | /*! @parseOnly */ 177 | #define XPC_NOESCAPE 178 | #endif // __GNUC__ 179 | 180 | #if __has_feature(assume_nonnull) 181 | #define XPC_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") 182 | #define XPC_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") 183 | #else 184 | #define XPC_ASSUME_NONNULL_BEGIN 185 | #define XPC_ASSUME_NONNULL_END 186 | #endif 187 | 188 | #if __has_feature(nullability_on_arrays) 189 | #define XPC_NONNULL_ARRAY _Nonnull 190 | #else 191 | #define XPC_NONNULL_ARRAY 192 | #endif 193 | 194 | #ifdef OS_CLOSED_OPTIONS 195 | #define XPC_FLAGS_ENUM(_name, _type, ...) \ 196 | OS_CLOSED_OPTIONS(_name, _type, __VA_ARGS__) 197 | #else // OS_CLOSED_ENUM 198 | #define XPC_FLAGS_ENUM(_name, _type, ...) \ 199 | OS_ENUM(_name, _type, __VA_ARGS__) 200 | #endif // OS_CLOSED_ENUM 201 | 202 | #ifdef OS_CLOSED_ENUM 203 | #define XPC_ENUM(_name, _type, ...) \ 204 | OS_CLOSED_ENUM(_name, _type, __VA_ARGS__) 205 | #else // OS_CLOSED_ENUM 206 | #define XPC_ENUM(_name, _type, ...) \ 207 | OS_ENUM(_name, _type, __VA_ARGS__) 208 | #endif // OS_CLOSED_ENUM 209 | 210 | __END_DECLS 211 | 212 | #endif // __XPC_BASE_H__ 213 | -------------------------------------------------------------------------------- /xpc/connection.h: -------------------------------------------------------------------------------- 1 | #ifndef __XPC_CONNECTION_H__ 2 | #define __XPC_CONNECTION_H__ 3 | 4 | #ifndef __XPC_INDIRECT__ 5 | #error "Please #include instead of this file directly." 6 | // For HeaderDoc. 7 | #include 8 | #endif // __XPC_INDIRECT__ 9 | 10 | #ifndef __BLOCKS__ 11 | #error "XPC connections require Blocks support." 12 | #endif // __BLOCKS__ 13 | 14 | XPC_ASSUME_NONNULL_BEGIN 15 | __BEGIN_DECLS 16 | 17 | /*! 18 | * @constant XPC_ERROR_CONNECTION_INTERRUPTED 19 | * Will be delivered to the connection's event handler if the remote service 20 | * exited. The connection is still live even in this case, and resending a 21 | * message will cause the service to be launched on-demand. This error serves 22 | * as a client's indication that it should resynchronize any state that it had 23 | * given the service. 24 | * 25 | * Any messages in the queue to be sent will be unwound and canceled when this 26 | * error occurs. In the case where a message waiting to be sent has a reply 27 | * handler, that handler will be invoked with this error. In the context of the 28 | * reply handler, this error indicates that a reply to the message will never 29 | * arrive. 30 | * 31 | * Messages that do not have reply handlers associated with them will be 32 | * silently disposed of. This error will only be given to peer connections. 33 | */ 34 | #define XPC_ERROR_CONNECTION_INTERRUPTED \ 35 | XPC_GLOBAL_OBJECT(_xpc_error_connection_interrupted) 36 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 37 | XPC_EXPORT 38 | const struct _xpc_dictionary_s _xpc_error_connection_interrupted; 39 | 40 | /*! 41 | * @constant XPC_ERROR_CONNECTION_INVALID 42 | * Will be delivered to the connection's event handler if the named service 43 | * provided to xpc_connection_create() could not be found in the XPC service 44 | * namespace. The connection is useless and should be disposed of. 45 | * 46 | * Any messages in the queue to be sent will be unwound and canceled when this 47 | * error occurs, similarly to the behavior when XPC_ERROR_CONNECTION_INTERRUPTED 48 | * occurs. The only difference is that the XPC_ERROR_CONNECTION_INVALID will be 49 | * given to outstanding reply handlers and the connection's event handler. 50 | * 51 | * This error may be given to any type of connection. 52 | */ 53 | #define XPC_ERROR_CONNECTION_INVALID \ 54 | XPC_GLOBAL_OBJECT(_xpc_error_connection_invalid) 55 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 56 | XPC_EXPORT 57 | const struct _xpc_dictionary_s _xpc_error_connection_invalid; 58 | 59 | /*! 60 | * @constant XPC_ERROR_TERMINATION_IMMINENT 61 | * On macOS, this error will be delivered to a peer connection's event handler 62 | * when the XPC runtime has determined that the program should exit and that 63 | * all outstanding transactions must be wound down, and no new transactions can 64 | * be opened. 65 | * 66 | * After this error has been delivered to the event handler, no more messages 67 | * will be received by the connection. The runtime will still attempt to deliver 68 | * outgoing messages, but this error should be treated as an indication that 69 | * the program will exit very soon, and any outstanding business over the 70 | * connection should be wrapped up as quickly as possible and the connection 71 | * canceled shortly thereafter. 72 | * 73 | * This error will only be delivered to peer connections received through a 74 | * listener or the xpc_main() event handler. 75 | */ 76 | #define XPC_ERROR_TERMINATION_IMMINENT \ 77 | XPC_GLOBAL_OBJECT(_xpc_error_termination_imminent) 78 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 79 | XPC_EXPORT 80 | const struct _xpc_dictionary_s _xpc_error_termination_imminent; 81 | 82 | /*! 83 | * @constant XPC_CONNECTION_MACH_SERVICE_LISTENER 84 | * Passed to xpc_connection_create_mach_service(). This flag indicates that the 85 | * caller is the listener for the named service. This flag may only be passed 86 | * for services which are advertised in the process' launchd.plist(5). You may 87 | * not use this flag to dynamically add services to the Mach bootstrap 88 | * namespace. 89 | */ 90 | #define XPC_CONNECTION_MACH_SERVICE_LISTENER (1 << 0) 91 | 92 | /*! 93 | * @constant XPC_CONNECTION_MACH_SERVICE_PRIVILEGED 94 | * Passed to xpc_connection_create_mach_service(). This flag indicates that the 95 | * job advertising the service name in its launchd.plist(5) should be in the 96 | * privileged Mach bootstrap. This is typically accomplished by placing your 97 | * launchd.plist(5) in /Library/LaunchDaemons. If specified alongside the 98 | * XPC_CONNECTION_MACH_SERVICE_LISTENER flag, this flag is a no-op. 99 | */ 100 | #define XPC_CONNECTION_MACH_SERVICE_PRIVILEGED (1 << 1) 101 | 102 | /*! 103 | * @typedef xpc_finalizer_f 104 | * A function that is invoked when a connection is being torn down and its 105 | * context needs to be freed. The sole argument is the value that was given to 106 | * {@link xpc_connection_set_context} or NULL if no context has been set. It is 107 | * not safe to reference the connection from within this function. 108 | * 109 | * @param value 110 | * The context object that is to be disposed of. 111 | */ 112 | typedef void (*xpc_finalizer_t)(void * _Nullable value); 113 | 114 | /*! 115 | * @function xpc_connection_create 116 | * Creates a new connection object. 117 | * 118 | * @param name 119 | * If non-NULL, the name of the service with which to connect. The returned 120 | * connection will be a peer. 121 | * 122 | * If NULL, an anonymous listener connection will be created. You can embed the 123 | * ability to create new peer connections in an endpoint, which can be inserted 124 | * into a message and sent to another process . 125 | * 126 | * @param targetq 127 | * The GCD queue to which the event handler block will be submitted. This 128 | * parameter may be NULL, in which case the connection's target queue will be 129 | * libdispatch's default target queue, defined as DISPATCH_TARGET_QUEUE_DEFAULT. 130 | * The target queue may be changed later with a call to 131 | * xpc_connection_set_target_queue(). 132 | * 133 | * @result 134 | * A new connection object. The caller is responsible for disposing of the 135 | * returned object with {@link xpc_release} when it is no longer needed. 136 | * 137 | * @discussion 138 | * This method will succeed even if the named service does not exist. This is 139 | * because the XPC namespace is not queried for the service name until the 140 | * connection has been activated. See {@link xpc_connection_activate()}. 141 | * 142 | * XPC connections, like dispatch sources, are returned in an inactive state, so 143 | * you must call {@link xpc_connection_activate()} in order to begin receiving 144 | * events from the connection. Also like dispatch sources, connections must be 145 | * activated and not suspended in order to be safely released. It is 146 | * a programming error to release an inactive or suspended connection. 147 | */ 148 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 149 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT 150 | xpc_connection_t 151 | xpc_connection_create(const char * _Nullable name, 152 | dispatch_queue_t _Nullable targetq); 153 | 154 | /*! 155 | * @function xpc_connection_create_mach_service 156 | * Creates a new connection object representing a Mach service. 157 | * 158 | * @param name 159 | * The name of the remote service with which to connect. The service name must 160 | * exist in a Mach bootstrap that is accessible to the process and be advertised 161 | * in a launchd.plist. 162 | * 163 | * @param targetq 164 | * The GCD queue to which the event handler block will be submitted. This 165 | * parameter may be NULL, in which case the connection's target queue will be 166 | * libdispatch's default target queue, defined as DISPATCH_TARGET_QUEUE_DEFAULT. 167 | * The target queue may be changed later with a call to 168 | * xpc_connection_set_target_queue(). 169 | * 170 | * @param flags 171 | * Additional attributes with which to create the connection. 172 | * 173 | * @result 174 | * A new connection object. 175 | * 176 | * @discussion 177 | * If the XPC_CONNECTION_MACH_SERVICE_LISTENER flag is given to this method, 178 | * then the connection returned will be a listener connection. Otherwise, a peer 179 | * connection will be returned. See the documentation for 180 | * {@link xpc_connection_set_event_handler()} for the semantics of listener 181 | * connections versus peer connections. 182 | * 183 | * This method will succeed even if the named service does not exist. This is 184 | * because the Mach namespace is not queried for the service name until the 185 | * connection has been activated. See {@link xpc_connection_activate()}. 186 | */ 187 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 188 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1 189 | xpc_connection_t 190 | xpc_connection_create_mach_service(const char *name, 191 | dispatch_queue_t _Nullable targetq, uint64_t flags); 192 | 193 | /*! 194 | * @function xpc_connection_create_from_endpoint 195 | * Creates a new connection from the given endpoint. 196 | * 197 | * @param endpoint 198 | * The endpoint from which to create the new connection. 199 | * 200 | * @result 201 | * A new peer connection to the listener represented by the given endpoint. 202 | * 203 | * The same responsibilities of setting an event handler and activating the 204 | * connection after calling xpc_connection_create() apply to the connection 205 | * returned by this API. Since the connection yielded by this API is not 206 | * associated with a name (and therefore is not rediscoverable), this connection 207 | * will receive XPC_ERROR_CONNECTION_INVALID if the listening side crashes, 208 | * exits or cancels the listener connection. 209 | */ 210 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 211 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL_ALL 212 | xpc_connection_t 213 | xpc_connection_create_from_endpoint(xpc_endpoint_t endpoint); 214 | 215 | /*! 216 | * @function xpc_connection_set_target_queue 217 | * Sets the target queue of the given connection. 218 | * 219 | * @param connection 220 | * The connection object which is to be manipulated. 221 | * 222 | * @param targetq 223 | * The GCD queue to which the event handler block will be submitted. This 224 | * parameter may be NULL, in which case the connection's target queue will be 225 | * libdispatch's default target queue, defined as DISPATCH_TARGET_QUEUE_DEFAULT. 226 | * 227 | * @discussion 228 | * Setting the target queue is asynchronous and non-preemptive and therefore 229 | * this method will not interrupt the execution of an already-running event 230 | * handler block. Setting the target queue may be likened to issuing a barrier 231 | * to the connection which does the actual work of changing the target queue. 232 | * 233 | * The XPC runtime guarantees this non-preemptiveness even for concurrent target 234 | * queues. If the target queue is a concurrent queue, then XPC still guarantees 235 | * that there will never be more than one invocation of the connection's event 236 | * handler block executing concurrently. If you wish to process events 237 | * concurrently, you can dispatch_async(3) to a concurrent queue from within 238 | * the event handler. 239 | * 240 | * IMPORTANT: When called from within the event handler block, 241 | * dispatch_get_current_queue(3) is NOT guaranteed to return a pointer to the 242 | * queue set with this method. 243 | * 244 | * Despite this seeming inconsistency, the XPC runtime guarantees that, when the 245 | * target queue is a serial queue, the event handler block will execute 246 | * synchonously with respect to other blocks submitted to that same queue. When 247 | * the target queue is a concurrent queue, the event handler block may run 248 | * concurrently with other blocks submitted to that queue, but it will never run 249 | * concurrently with other invocations of itself for the same connection, as 250 | * discussed previously. 251 | */ 252 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 253 | XPC_EXPORT XPC_NONNULL1 254 | void 255 | xpc_connection_set_target_queue(xpc_connection_t connection, 256 | dispatch_queue_t _Nullable targetq); 257 | 258 | /*! 259 | * @function xpc_connection_set_event_handler 260 | * Sets the event handler block for the connection. 261 | * 262 | * @param connection 263 | * The connection object which is to be manipulated. 264 | * 265 | * @param handler 266 | * The event handler block. 267 | * 268 | * @discussion 269 | * Setting the event handler is asynchronous and non-preemptive, and therefore 270 | * this method will not interrupt the execution of an already-running event 271 | * handler block. If the event handler is executing at the time of this call, it 272 | * will finish, and then the connection's event handler will be changed before 273 | * the next invocation of the event handler. The XPC runtime guarantees this 274 | * non-preemptiveness even for concurrent target queues. 275 | * 276 | * Connection event handlers are non-reentrant, so it is safe to call 277 | * xpc_connection_set_event_handler() from within the event handler block. 278 | * 279 | * The event handler's execution should be treated as a barrier to all 280 | * connection activity. When it is executing, the connection will not attempt to 281 | * send or receive messages, including reply messages. Thus, it is not safe to 282 | * call xpc_connection_send_message_with_reply_sync() on the connection from 283 | * within the event handler. 284 | * 285 | * You do not hold a reference on the object received as the event handler's 286 | * only argument. Regardless of the type of object received, it is safe to call 287 | * xpc_retain() on the object to obtain a reference to it. 288 | * 289 | * A connection may receive different events depending upon whether it is a 290 | * listener or not. Any connection may receive an error in its event handler. 291 | * But while normal connections may receive messages in addition to errors, 292 | * listener connections will receive connections and and not messages. 293 | * 294 | * Connections received by listeners are equivalent to those returned by 295 | * xpc_connection_create() with a non-NULL name argument and a NULL targetq 296 | * argument with the exception that you do not hold a reference on them. 297 | * You must set an event handler and activate the connection. If you do not wish 298 | * to accept the connection, you may simply call xpc_connection_cancel() on it 299 | * and return. The runtime will dispose of it for you. 300 | * 301 | * If there is an error in the connection, this handler will be invoked with the 302 | * error dictionary as its argument. This dictionary will be one of the well- 303 | * known XPC_ERROR_* dictionaries. 304 | * 305 | * Regardless of the type of event, ownership of the event object is NOT 306 | * implicitly transferred. Thus, the object will be released and deallocated at 307 | * some point in the future after the event handler returns. If you wish the 308 | * event's lifetime to persist, you must retain it with xpc_retain(). 309 | * 310 | * Connections received through the event handler will be released and 311 | * deallocated after the connection has gone invalid and delivered that event to 312 | * its event handler. 313 | */ 314 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 315 | XPC_EXPORT XPC_NONNULL_ALL 316 | void 317 | xpc_connection_set_event_handler(xpc_connection_t connection, 318 | xpc_handler_t handler); 319 | 320 | /*! 321 | * @function xpc_connection_activate 322 | * Activates the connection. Connections start in an inactive state, so you must 323 | * call xpc_connection_activate() on a connection before it will send or receive 324 | * any messages. 325 | * 326 | * @param connection 327 | * The connection object which is to be manipulated. 328 | * 329 | * @discussion 330 | * Calling xpc_connection_activate() on an active connection has no effect. 331 | * Releasing the last reference on an inactive connection that was created with 332 | * an xpc_connection_create*() call is undefined. 333 | * 334 | * For backward compatibility reasons, xpc_connection_resume() on an inactive 335 | * and not otherwise suspended xpc connection has the same effect as calling 336 | * xpc_connection_activate(). For new code, using xpc_connection_activate() 337 | * is preferred. 338 | */ 339 | __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) 340 | __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0) 341 | XPC_EXPORT XPC_NONNULL_ALL 342 | void 343 | xpc_connection_activate(xpc_connection_t connection); 344 | 345 | /*! 346 | * @function xpc_connection_suspend 347 | * Suspends the connection so that the event handler block will not fire and 348 | * that the connection will not attempt to send any messages it has in its 349 | * queue. All calls to xpc_connection_suspend() must be balanced with calls to 350 | * xpc_connection_resume() before releasing the last reference to the 351 | * connection. 352 | * 353 | * @param connection 354 | * The connection object which is to be manipulated. 355 | * 356 | * @discussion 357 | * Suspension is asynchronous and non-preemptive, and therefore this method will 358 | * not interrupt the execution of an already-running event handler block. If 359 | * the event handler is executing at the time of this call, it will finish, and 360 | * then the connection will be suspended before the next scheduled invocation 361 | * of the event handler. The XPC runtime guarantees this non-preemptiveness even 362 | * for concurrent target queues. 363 | * 364 | * Connection event handlers are non-reentrant, so it is safe to call 365 | * xpc_connection_suspend() from within the event handler block. 366 | */ 367 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 368 | XPC_EXPORT XPC_NONNULL_ALL 369 | void 370 | xpc_connection_suspend(xpc_connection_t connection); 371 | 372 | /*! 373 | * @function xpc_connection_resume 374 | * Resumes the connection. 375 | * 376 | * @param connection 377 | * The connection object which is to be manipulated. 378 | * 379 | * @discussion 380 | * In order for a connection to become live, every call to 381 | * xpc_connection_suspend() must be balanced with a call to 382 | * xpc_connection_resume(). 383 | * 384 | * For backward compatibility reasons, xpc_connection_resume() on an inactive 385 | * and not otherwise suspended xpc connection has the same effect as calling 386 | * xpc_connection_activate(). For new code, using xpc_connection_activate() 387 | * is preferred. 388 | * 389 | * Calling xpc_connection_resume() more times than xpc_connection_suspend() 390 | * has been called is otherwise considered an error. 391 | */ 392 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 393 | XPC_EXPORT XPC_NONNULL_ALL 394 | void 395 | xpc_connection_resume(xpc_connection_t connection); 396 | 397 | /*! 398 | * @function xpc_connection_send_message 399 | * Sends a message over the connection to the destination service. 400 | * 401 | * @param connection 402 | * The connection over which the message shall be sent. 403 | * 404 | * @param message 405 | * The message to send. This must be a dictionary object. This dictionary is 406 | * logically copied by the connection, so it is safe to modify the dictionary 407 | * after this call. 408 | * 409 | * @discussion 410 | * Messages are delivered in FIFO order. This API is safe to call from multiple 411 | * GCD queues. There is no indication that a message was delivered successfully. 412 | * This is because even once the message has been successfully enqueued on the 413 | * remote end, there are no guarantees about when the runtime will dequeue the 414 | * message and invoke the other connection's event handler block. 415 | * 416 | * If this API is used to send a message that is in reply to another message, 417 | * there is no guarantee of ordering between the invocations of the connection's 418 | * event handler and the reply handler for that message, even if they are 419 | * targeted to the same queue. 420 | * 421 | * After extensive study, we have found that clients who are interested in 422 | * the state of the message on the server end are typically holding open 423 | * transactions related to that message. And the only reliable way to track the 424 | * lifetime of that transaction is at the protocol layer. So the server should 425 | * send a reply message, which upon receiving, will cause the client to close 426 | * its transaction. 427 | */ 428 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 429 | XPC_EXPORT XPC_NONNULL_ALL 430 | void 431 | xpc_connection_send_message(xpc_connection_t connection, xpc_object_t message); 432 | 433 | /*! 434 | * @function xpc_connection_send_barrier 435 | * Issues a barrier against the connection's message-send activity. 436 | * 437 | * @param connection 438 | * The connection against which the barrier is to be issued. 439 | * 440 | * @param barrier 441 | * The barrier block to issue. This barrier prevents concurrent message-send 442 | * activity on the connection. No messages will be sent while the barrier block 443 | * is executing. 444 | * 445 | * @discussion 446 | * XPC guarantees that, even if the connection's target queue is a concurrent 447 | * queue, there are no other messages being sent concurrently while the barrier 448 | * block is executing. XPC does not guarantee that the receipt of messages 449 | * (either through the connection's event handler or through reply handlers) 450 | * will be suspended while the barrier is executing. 451 | * 452 | * A barrier is issued relative to the message-send queue. Thus, if you call 453 | * xpc_connection_send_message() five times and then call 454 | * xpc_connection_send_barrier(), the barrier will be invoked after the fifth 455 | * message has been sent and its memory disposed of. You may safely cancel a 456 | * connection from within a barrier block. 457 | * 458 | * If a barrier is issued after sending a message which expects a reply, the 459 | * behavior is the same as described above. The receipt of a reply message will 460 | * not influence when the barrier runs. 461 | * 462 | * A barrier block can be useful for throttling resource consumption on the 463 | * connected side of a connection. For example, if your connection sends many 464 | * large messages, you can use a barrier to limit the number of messages that 465 | * are inflight at any given time. This can be particularly useful for messages 466 | * that contain kernel resources (like file descriptors) which have a system- 467 | * wide limit. 468 | * 469 | * If a barrier is issued on a canceled connection, it will be invoked 470 | * immediately. If a connection has been canceled and still has outstanding 471 | * barriers, those barriers will be invoked as part of the connection's 472 | * unwinding process. 473 | * 474 | * It is important to note that a barrier block's execution order is not 475 | * guaranteed with respect to other blocks that have been scheduled on the 476 | * target queue of the connection. Or said differently, 477 | * xpc_connection_send_barrier(3) is not equivalent to dispatch_async(3). 478 | */ 479 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 480 | XPC_EXPORT XPC_NONNULL_ALL 481 | void 482 | xpc_connection_send_barrier(xpc_connection_t connection, 483 | dispatch_block_t barrier); 484 | 485 | /*! 486 | * @function xpc_connection_send_message_with_reply 487 | * Sends a message over the connection to the destination service and associates 488 | * a handler to be invoked when the remote service sends a reply message. 489 | * 490 | * @param connection 491 | * The connection over which the message shall be sent. 492 | * 493 | * @param message 494 | * The message to send. This must be a dictionary object. 495 | * 496 | * @param replyq 497 | * The GCD queue to which the reply handler will be submitted. This may be a 498 | * concurrent queue. 499 | * 500 | * @param handler 501 | * The handler block to invoke when a reply to the message is received from 502 | * the connection. If the remote service exits prematurely before the reply was 503 | * received, the XPC_ERROR_CONNECTION_INTERRUPTED error will be returned. 504 | * If the connection went invalid before the message could be sent, the 505 | * XPC_ERROR_CONNECTION_INVALID error will be returned. 506 | * 507 | * @discussion 508 | * If the given GCD queue is a concurrent queue, XPC cannot guarantee that there 509 | * will not be multiple reply handlers being invoked concurrently. XPC does not 510 | * guarantee any ordering for the invocation of reply handers. So if multiple 511 | * messages are waiting for replies and the connection goes invalid, there is no 512 | * guarantee that the reply handlers will be invoked in FIFO order. Similarly, 513 | * XPC does not guarantee that reply handlers will not run concurrently with 514 | * the connection's event handler in the case that the reply queue and the 515 | * connection's target queue are the same concurrent queue. 516 | */ 517 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 518 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 XPC_NONNULL4 519 | void 520 | xpc_connection_send_message_with_reply(xpc_connection_t connection, 521 | xpc_object_t message, dispatch_queue_t _Nullable replyq, 522 | xpc_handler_t handler); 523 | 524 | /*! 525 | * @function xpc_connection_send_message_with_reply_sync 526 | * Sends a message over the connection and blocks the caller until a reply is 527 | * received. 528 | * 529 | * @param connection 530 | * The connection over which the message shall be sent. 531 | * 532 | * @param message 533 | * The message to send. This must be a dictionary object. 534 | * 535 | * @result 536 | * The message that the remote service sent in reply to the original message. 537 | * If the remote service exits prematurely before the reply was received, the 538 | * XPC_ERROR_CONNECTION_INTERRUPTED error will be returned. If the connection 539 | * went invalid before the message could be sent, the 540 | * XPC_ERROR_CONNECTION_INVALID error will be returned. 541 | * 542 | * You are responsible for releasing the returned object. 543 | * 544 | * @discussion 545 | * This API is primarily for transitional purposes. Its implementation is 546 | * conceptually equivalent to calling xpc_connection_send_message_with_reply() 547 | * and then immediately blocking the calling thread on a semaphore and 548 | * signaling the semaphore from the reply block. 549 | * 550 | * Be judicious about your use of this API. It can block indefinitely, so if you 551 | * are using it to implement an API that can be called from the main thread, you 552 | * may wish to consider allowing the API to take a queue and callback block so 553 | * that results may be delivered asynchronously if possible. 554 | */ 555 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 556 | XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT XPC_RETURNS_RETAINED 557 | xpc_object_t 558 | xpc_connection_send_message_with_reply_sync(xpc_connection_t connection, 559 | xpc_object_t message); 560 | 561 | /*! 562 | * @function xpc_connection_cancel 563 | * Cancels the connection and ensures that its event handler will not fire 564 | * again. After this call, any messages that have not yet been sent will be 565 | * discarded, and the connection will be unwound. If there are messages that are 566 | * awaiting replies, they will have their reply handlers invoked with the 567 | * XPC_ERROR_CONNECTION_INVALID error. 568 | * 569 | * @param connection 570 | * The connection object which is to be manipulated. 571 | * 572 | * @discussion 573 | * Cancellation is asynchronous and non-preemptive and therefore this method 574 | * will not interrupt the execution of an already-running event handler block. 575 | * If the event handler is executing at the time of this call, it will finish, 576 | * and then the connection will be canceled, causing a final invocation of the 577 | * event handler to be scheduled with the XPC_ERROR_CONNECTION_INVALID error. 578 | * After that invocation, there will be no further invocations of the event 579 | * handler. 580 | * 581 | * The XPC runtime guarantees this non-preemptiveness even for concurrent target 582 | * queues. 583 | */ 584 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 585 | XPC_EXPORT XPC_NONNULL_ALL 586 | void 587 | xpc_connection_cancel(xpc_connection_t connection); 588 | 589 | /*! 590 | * @function xpc_connection_get_name 591 | * Returns the name of the service with which the connections was created. 592 | * 593 | * @param connection 594 | * The connection object which is to be examined. 595 | * 596 | * @result 597 | * The name of the remote service. If you obtained the connection through an 598 | * invocation of another connection's event handler, NULL is returned. 599 | */ 600 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 601 | XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT 602 | const char * _Nullable 603 | xpc_connection_get_name(xpc_connection_t connection); 604 | 605 | /*! 606 | * @function xpc_connection_get_euid 607 | * Returns the EUID of the remote peer. 608 | * 609 | * @param connection 610 | * The connection object which is to be examined. 611 | * 612 | * @result 613 | * The EUID of the remote peer at the time the connection was made. 614 | */ 615 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 616 | XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT 617 | uid_t 618 | xpc_connection_get_euid(xpc_connection_t connection); 619 | 620 | /*! 621 | * @function xpc_connection_get_egid 622 | * Returns the EGID of the remote peer. 623 | * 624 | * @param connection 625 | * The connection object which is to be examined. 626 | * 627 | * @result 628 | * The EGID of the remote peer at the time the connection was made. 629 | */ 630 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 631 | XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT 632 | gid_t 633 | xpc_connection_get_egid(xpc_connection_t connection); 634 | 635 | /*! 636 | * @function xpc_connection_get_pid 637 | * Returns the PID of the remote peer. 638 | * 639 | * @param connection 640 | * The connection object which is to be examined. 641 | * 642 | * @result 643 | * The PID of the remote peer. 644 | * 645 | * @discussion 646 | * A given PID is not guaranteed to be unique across an entire boot cycle. 647 | * Great care should be taken when dealing with this information, as it can go 648 | * stale after the connection is established. OS X recycles PIDs, and therefore 649 | * another process could spawn and claim the PID before a message is actually 650 | * received from the connection. 651 | * 652 | * XPC will deliver an error to your event handler if the remote process goes 653 | * away, but there are no guarantees as to the timing of this notification's 654 | * delivery either at the kernel layer or at the XPC layer. 655 | */ 656 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 657 | XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT 658 | pid_t 659 | xpc_connection_get_pid(xpc_connection_t connection); 660 | 661 | /*! 662 | * @function xpc_connection_get_asid 663 | * Returns the audit session identifier of the remote peer. 664 | * 665 | * @param connection 666 | * The connection object which is to be examined. 667 | * 668 | * @result 669 | * The audit session ID of the remote peer at the time the connection was made. 670 | */ 671 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 672 | XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT 673 | au_asid_t 674 | xpc_connection_get_asid(xpc_connection_t connection); 675 | 676 | /*! 677 | * @function xpc_connection_set_context 678 | * Sets context on an connection. 679 | * 680 | * @param connection 681 | * The connection which is to be manipulated. 682 | * 683 | * @param context 684 | * The context to associate with the connection. 685 | * 686 | * @discussion 687 | * If you must manage the memory of the context object, you must set a finalizer 688 | * to dispose of it. If this method is called on a connection which already has 689 | * context associated with it, the finalizer will NOT be invoked. The finalizer 690 | * is only invoked when the connection is being deallocated. 691 | * 692 | * It is recommended that, instead of changing the actual context pointer 693 | * associated with the object, you instead change the state of the context 694 | * object itself. 695 | */ 696 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 697 | XPC_EXPORT XPC_NONNULL1 698 | void 699 | xpc_connection_set_context(xpc_connection_t connection, 700 | void * _Nullable context); 701 | 702 | /*! 703 | * @function xpc_connection_get_context 704 | * Returns the context associated with the connection. 705 | * 706 | * @param connection 707 | * The connection which is to be examined. 708 | * 709 | * @result 710 | * The context associated with the connection. NULL if there has been no context 711 | * associated with the object. 712 | */ 713 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 714 | XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT 715 | void * _Nullable 716 | xpc_connection_get_context(xpc_connection_t connection); 717 | 718 | /*! 719 | * @function xpc_connection_set_finalizer_f 720 | * Sets the finalizer for the given connection. 721 | * 722 | * @param connection 723 | * The connection on which to set the finalizer. 724 | * 725 | * @param finalizer 726 | * The function that will be invoked when the connection's retain count has 727 | * dropped to zero and is being torn down. 728 | * 729 | * @discussion 730 | * This method disposes of the context value associated with a connection, as 731 | * set by {@link xpc_connection_set_context}. 732 | * 733 | * For many uses of context objects, this API allows for a convenient shorthand 734 | * for freeing them. For example, for a context object allocated with malloc(3): 735 | * 736 | * xpc_connection_set_finalizer_f(object, free); 737 | */ 738 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 739 | XPC_EXPORT XPC_NONNULL1 740 | void 741 | xpc_connection_set_finalizer_f(xpc_connection_t connection, 742 | xpc_finalizer_t _Nullable finalizer); 743 | 744 | __END_DECLS 745 | XPC_ASSUME_NONNULL_END 746 | 747 | #endif // __XPC_CONNECTION_H__ 748 | -------------------------------------------------------------------------------- /xpc/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef __XPC_DEBUG_H__ 2 | #define __XPC_DEBUG_H__ 3 | 4 | /*! 5 | * @function xpc_debugger_api_misuse_info 6 | * Returns a pointer to a string describing the reason XPC aborted the calling 7 | * process. On OS X, this will be the same string present in the "Application 8 | * Specific Information" section of the crash report. 9 | * 10 | * @result 11 | * A pointer to the human-readable string describing the reason the caller was 12 | * aborted. If XPC was not responsible for the program's termination, NULL will 13 | * be returned. 14 | * 15 | * @discussion 16 | * This function is only callable from within a debugger. It is not meant to be 17 | * called by the program directly. 18 | */ 19 | XPC_DEBUGGER_EXCL 20 | const char * 21 | xpc_debugger_api_misuse_info(void); 22 | 23 | #endif // __XPC_DEBUG_H__ 24 | -------------------------------------------------------------------------------- /xpc/endpoint.h: -------------------------------------------------------------------------------- 1 | #ifndef __XPC_ENDPOINT_H__ 2 | #define __XPC_ENDPOINT_H__ 3 | 4 | /*! 5 | * @function xpc_endpoint_create 6 | * Creates a new endpoint from a connection that is suitable for embedding into 7 | * messages. 8 | * 9 | * @param connection 10 | * Only connections obtained through calls to xpc_connection_create*() may be 11 | * given to this API. Passing any other type of connection is not supported and 12 | * will result in undefined behavior. 13 | * 14 | * @result 15 | * A new endpoint object. 16 | */ 17 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 18 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1 19 | xpc_endpoint_t _Nonnull 20 | xpc_endpoint_create(xpc_connection_t _Nonnull connection); 21 | 22 | #endif // __XPC_ENDPOINT_H__ 23 | -------------------------------------------------------------------------------- /xpc/xpc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009-2011 Apple Inc. All rights reserved. 2 | 3 | #ifndef __XPC_H__ 4 | #define __XPC_H__ 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #ifndef __XPC_INDIRECT__ 22 | #define __XPC_INDIRECT__ 23 | #endif // __XPC_INDIRECT__ 24 | 25 | #include 26 | 27 | #if __has_include() 28 | #include 29 | #else // __has_include() 30 | #define XPC_TRANSACTION_DEPRECATED 31 | #endif // __has_include() 32 | 33 | XPC_ASSUME_NONNULL_BEGIN 34 | __BEGIN_DECLS 35 | 36 | #ifndef __OSX_AVAILABLE_STARTING 37 | #define __OSX_AVAILABLE_STARTING(x, y) 38 | #endif // __OSX_AVAILABLE_STARTING 39 | 40 | #define XPC_API_VERSION 20121012 41 | 42 | /*! 43 | * @typedef xpc_type_t 44 | * A type that describes XPC object types. 45 | */ 46 | typedef const struct _xpc_type_s * xpc_type_t; 47 | #ifndef XPC_TYPE 48 | #define XPC_TYPE(type) const struct _xpc_type_s type 49 | #endif // XPC_TYPE 50 | 51 | /*! 52 | * @typedef xpc_object_t 53 | * A type that can describe all XPC objects. Dictionaries, arrays, strings, etc. 54 | * are all described by this type. 55 | * 56 | * XPC objects are created with a retain count of 1, and therefore it is the 57 | * caller's responsibility to call xpc_release() on them when they are no longer 58 | * needed. 59 | */ 60 | 61 | #if OS_OBJECT_USE_OBJC 62 | /* By default, XPC objects are declared as Objective-C types when building with 63 | * an Objective-C compiler. This allows them to participate in ARC, in RR 64 | * management by the Blocks runtime and in leaks checking by the static 65 | * analyzer, and enables them to be added to Cocoa collections. 66 | * 67 | * See for details. 68 | */ 69 | OS_OBJECT_DECL(xpc_object); 70 | #ifndef XPC_DECL 71 | #define XPC_DECL(name) typedef xpc_object_t name##_t 72 | #endif // XPC_DECL 73 | 74 | #define XPC_GLOBAL_OBJECT(object) ((OS_OBJECT_BRIDGE xpc_object_t)&(object)) 75 | #define XPC_RETURNS_RETAINED OS_OBJECT_RETURNS_RETAINED 76 | XPC_INLINE XPC_NONNULL_ALL 77 | void 78 | _xpc_object_validate(xpc_object_t object) { 79 | void *isa = *(void * volatile *)(OS_OBJECT_BRIDGE void *)object; 80 | (void)isa; 81 | } 82 | #else // OS_OBJECT_USE_OBJC 83 | typedef void * xpc_object_t; 84 | #define XPC_DECL(name) typedef struct _##name##_s * name##_t 85 | #define XPC_GLOBAL_OBJECT(object) (&(object)) 86 | #define XPC_RETURNS_RETAINED 87 | #endif // OS_OBJECT_USE_OBJC 88 | 89 | /*! 90 | * @typedef xpc_handler_t 91 | * The type of block that is accepted by the XPC connection APIs. 92 | * 93 | * @param object 94 | * An XPC object that is to be handled. If there was an error, this object will 95 | * be equal to one of the well-known XPC_ERROR_* dictionaries and can be 96 | * compared with the equality operator. 97 | * 98 | * @discussion 99 | * You are not responsible for releasing the event object. 100 | */ 101 | #if __BLOCKS__ 102 | typedef void (^xpc_handler_t)(xpc_object_t object); 103 | #endif // __BLOCKS__ 104 | 105 | /*! 106 | * @define XPC_TYPE_CONNECTION 107 | * A type representing a connection to a named service. This connection is 108 | * bidirectional and can be used to both send and receive messages. A 109 | * connection carries the credentials of the remote service provider. 110 | */ 111 | #define XPC_TYPE_CONNECTION (&_xpc_type_connection) 112 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 113 | XPC_EXPORT 114 | XPC_TYPE(_xpc_type_connection); 115 | XPC_DECL(xpc_connection); 116 | 117 | /*! 118 | * @typedef xpc_connection_handler_t 119 | * The type of the function that will be invoked for a bundled XPC service when 120 | * there is a new connection on the service. 121 | * 122 | * @param connection 123 | * A new connection that is equivalent to one received by a listener connection. 124 | * See the documentation for {@link xpc_connection_set_event_handler} for the 125 | * semantics associated with the received connection. 126 | */ 127 | typedef void (*xpc_connection_handler_t)(xpc_connection_t connection); 128 | 129 | /*! 130 | * @define XPC_TYPE_ENDPOINT 131 | * A type representing a connection in serialized form. Unlike a connection, an 132 | * endpoint is an inert object that does not have any runtime activity 133 | * associated with it. Thus, it is safe to pass an endpoint in a message. Upon 134 | * receiving an endpoint, the recipient can use 135 | * xpc_connection_create_from_endpoint() to create as many distinct connections 136 | * as desired. 137 | */ 138 | #define XPC_TYPE_ENDPOINT (&_xpc_type_endpoint) 139 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 140 | XPC_EXPORT 141 | XPC_TYPE(_xpc_type_endpoint); 142 | XPC_DECL(xpc_endpoint); 143 | 144 | /*! 145 | * @define XPC_TYPE_NULL 146 | * A type representing a null object. This type is useful for disambiguating 147 | * an unset key in a dictionary and one which has been reserved but set empty. 148 | * Also, this type is a way to represent a "null" value in dictionaries, which 149 | * do not accept NULL. 150 | */ 151 | #define XPC_TYPE_NULL (&_xpc_type_null) 152 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 153 | XPC_EXPORT 154 | XPC_TYPE(_xpc_type_null); 155 | 156 | /*! 157 | * @define XPC_TYPE_BOOL 158 | * A type representing a Boolean value. 159 | */ 160 | #define XPC_TYPE_BOOL (&_xpc_type_bool) 161 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 162 | XPC_EXPORT 163 | XPC_TYPE(_xpc_type_bool); 164 | 165 | /*! 166 | * @define XPC_BOOL_TRUE 167 | * A constant representing a Boolean value of true. You may compare a Boolean 168 | * object against this constant to determine its value. 169 | */ 170 | #define XPC_BOOL_TRUE XPC_GLOBAL_OBJECT(_xpc_bool_true) 171 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 172 | XPC_EXPORT 173 | const struct _xpc_bool_s _xpc_bool_true; 174 | 175 | /*! 176 | * @define XPC_BOOL_FALSE 177 | * A constant representing a Boolean value of false. You may compare a Boolean 178 | * object against this constant to determine its value. 179 | */ 180 | #define XPC_BOOL_FALSE XPC_GLOBAL_OBJECT(_xpc_bool_false) 181 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 182 | XPC_EXPORT 183 | const struct _xpc_bool_s _xpc_bool_false; 184 | 185 | /*! 186 | * @define XPC_TYPE_INT64 187 | * A type representing a signed, 64-bit integer value. 188 | */ 189 | #define XPC_TYPE_INT64 (&_xpc_type_int64) 190 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 191 | XPC_EXPORT 192 | XPC_TYPE(_xpc_type_int64); 193 | 194 | /*! 195 | * @define XPC_TYPE_UINT64 196 | * A type representing an unsigned, 64-bit integer value. 197 | */ 198 | #define XPC_TYPE_UINT64 (&_xpc_type_uint64) 199 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 200 | XPC_EXPORT 201 | XPC_TYPE(_xpc_type_uint64); 202 | 203 | /*! 204 | * @define XPC_TYPE_DOUBLE 205 | * A type representing an IEEE-compliant, double-precision floating point value. 206 | */ 207 | #define XPC_TYPE_DOUBLE (&_xpc_type_double) 208 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 209 | XPC_EXPORT 210 | XPC_TYPE(_xpc_type_double); 211 | 212 | /*! 213 | * @define XPC_TYPE_DATE 214 | * A type representing a date interval. The interval is with respect to the 215 | * Unix epoch. XPC dates are in Unix time and are thus unaware of local time 216 | * or leap seconds. 217 | */ 218 | #define XPC_TYPE_DATE (&_xpc_type_date) 219 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 220 | XPC_EXPORT 221 | XPC_TYPE(_xpc_type_date); 222 | 223 | /*! 224 | * @define XPC_TYPE_DATA 225 | * A type representing a an arbitrary buffer of bytes. 226 | */ 227 | #define XPC_TYPE_DATA (&_xpc_type_data) 228 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 229 | XPC_EXPORT 230 | XPC_TYPE(_xpc_type_data); 231 | 232 | /*! 233 | * @define XPC_TYPE_STRING 234 | * A type representing a NUL-terminated C-string. 235 | */ 236 | #define XPC_TYPE_STRING (&_xpc_type_string) 237 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 238 | XPC_EXPORT 239 | XPC_TYPE(_xpc_type_string); 240 | 241 | /*! 242 | * @define XPC_TYPE_UUID 243 | * A type representing a Universally Unique Identifier as defined by uuid(3). 244 | */ 245 | #define XPC_TYPE_UUID (&_xpc_type_uuid) 246 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 247 | XPC_EXPORT 248 | XPC_TYPE(_xpc_type_uuid); 249 | 250 | /*! 251 | * @define XPC_TYPE_FD 252 | * A type representing a POSIX file descriptor. 253 | */ 254 | #define XPC_TYPE_FD (&_xpc_type_fd) 255 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 256 | XPC_EXPORT 257 | XPC_TYPE(_xpc_type_fd); 258 | 259 | /*! 260 | * @define XPC_TYPE_SHMEM 261 | * A type representing a region of shared memory. 262 | */ 263 | #define XPC_TYPE_SHMEM (&_xpc_type_shmem) 264 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 265 | XPC_EXPORT 266 | XPC_TYPE(_xpc_type_shmem); 267 | 268 | /*! 269 | * @define XPC_TYPE_ARRAY 270 | * A type representing an array of XPC objects. This array must be contiguous, 271 | * i.e. it cannot contain NULL values. If you wish to indicate that a slot 272 | * is empty, you can insert a null object. The array will grow as needed to 273 | * accommodate more objects. 274 | */ 275 | #define XPC_TYPE_ARRAY (&_xpc_type_array) 276 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 277 | XPC_EXPORT 278 | XPC_TYPE(_xpc_type_array); 279 | 280 | /*! 281 | * @define XPC_TYPE_DICTIONARY 282 | * A type representing a dictionary of XPC objects, keyed off of C-strings. 283 | * You may insert NULL values into this collection. The dictionary will grow 284 | * as needed to accommodate more key/value pairs. 285 | */ 286 | #define XPC_TYPE_DICTIONARY (&_xpc_type_dictionary) 287 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 288 | XPC_EXPORT 289 | XPC_TYPE(_xpc_type_dictionary); 290 | 291 | /*! 292 | * @define XPC_TYPE_ERROR 293 | * A type representing an error object. Errors in XPC are dictionaries, but 294 | * xpc_get_type() will return this type when given an error object. You 295 | * cannot create an error object directly; XPC will only give them to handlers. 296 | * These error objects have pointer values that are constant across the lifetime 297 | * of your process and can be safely compared. 298 | * 299 | * These constants are enumerated in the header for the connection object. Error 300 | * dictionaries may reserve keys so that they can be queried to obtain more 301 | * detailed information about the error. Currently, the only reserved key is 302 | * XPC_ERROR_KEY_DESCRIPTION. 303 | */ 304 | #define XPC_TYPE_ERROR (&_xpc_type_error) 305 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 306 | XPC_EXPORT 307 | XPC_TYPE(_xpc_type_error); 308 | 309 | /*! 310 | * @define XPC_ERROR_KEY_DESCRIPTION 311 | * In an error dictionary, querying for this key will return a string object 312 | * that describes the error in a human-readable way. 313 | */ 314 | #define XPC_ERROR_KEY_DESCRIPTION _xpc_error_key_description 315 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 316 | XPC_EXPORT 317 | const char * const _xpc_error_key_description; 318 | 319 | /*! 320 | * @define XPC_EVENT_KEY_NAME 321 | * In an event dictionary, this querying for this key will return a string 322 | * object that describes the event. 323 | */ 324 | #define XPC_EVENT_KEY_NAME _xpc_event_key_name 325 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 326 | XPC_EXPORT 327 | const char * const _xpc_event_key_name; 328 | 329 | XPC_ASSUME_NONNULL_END 330 | #if !defined(__XPC_BUILDING_XPC__) || !__XPC_BUILDING_XPC__ 331 | #include 332 | #include 333 | #if __BLOCKS__ 334 | #include 335 | #include 336 | #endif // __BLOCKS__ 337 | #undef __XPC_INDIRECT__ 338 | //#include 339 | #endif // !defined(__XPC_BUILDING_XPC__) || !__XPC_BUILDING_XPC__ 340 | XPC_ASSUME_NONNULL_BEGIN 341 | 342 | #pragma mark XPC Object Protocol 343 | /*! 344 | * @function xpc_retain 345 | * 346 | * @abstract 347 | * Increments the reference count of an object. 348 | * 349 | * @param object 350 | * The object which is to be manipulated. 351 | * 352 | * @result 353 | * The object which was given. 354 | * 355 | * @discussion 356 | * Calls to xpc_retain() must be balanced with calls to xpc_release() 357 | * to avoid leaking memory. 358 | */ 359 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 360 | XPC_EXPORT XPC_NONNULL1 361 | xpc_object_t 362 | xpc_retain(xpc_object_t object); 363 | #if OS_OBJECT_USE_OBJC_RETAIN_RELEASE 364 | #undef xpc_retain 365 | #define xpc_retain(object) ({ xpc_object_t _o = (object); \ 366 | _xpc_object_validate(_o); [_o retain]; }) 367 | #endif // OS_OBJECT_USE_OBJC_RETAIN_RELEASE 368 | 369 | /*! 370 | * @function xpc_release 371 | * 372 | * @abstract 373 | * Decrements the reference count of an object. 374 | * 375 | * @param object 376 | * The object which is to be manipulated. 377 | * 378 | * @discussion 379 | * The caller must take care to balance retains and releases. When creating or 380 | * retaining XPC objects, the creator obtains a reference on the object. Thus, 381 | * it is the caller's responsibility to call xpc_release() on those objects when 382 | * they are no longer needed. 383 | */ 384 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 385 | XPC_EXPORT XPC_NONNULL1 386 | void 387 | xpc_release(xpc_object_t object); 388 | #if OS_OBJECT_USE_OBJC_RETAIN_RELEASE 389 | #undef xpc_release 390 | #define xpc_release(object) ({ xpc_object_t _o = (object); \ 391 | _xpc_object_validate(_o); [_o release]; }) 392 | #endif // OS_OBJECT_USE_OBJC_RETAIN_RELEASE 393 | 394 | /*! 395 | * @function xpc_get_type 396 | * 397 | * @abstract 398 | * Returns the type of an object. 399 | * 400 | * @param object 401 | * The object to examine. 402 | * 403 | * @result 404 | * An opaque pointer describing the type of the object. This pointer is suitable 405 | * direct comparison to exported type constants with the equality operator. 406 | */ 407 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 408 | XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT 409 | xpc_type_t 410 | xpc_get_type(xpc_object_t object); 411 | 412 | /*! 413 | * @function xpc_type_get_name 414 | * 415 | * @abstract 416 | * Returns a string describing an XPC object type. 417 | * 418 | * @param type 419 | * The type to describe. 420 | * 421 | * @result 422 | * A string describing the type of an object, like "string" or "int64". 423 | * This string should not be freed or modified. 424 | */ 425 | __OSX_AVAILABLE_STARTING(__MAC_10_15, __IPHONE_13_0) 426 | XPC_EXPORT XPC_NONNULL1 427 | const char * 428 | xpc_type_get_name(xpc_type_t type); 429 | 430 | /*! 431 | * @function xpc_copy 432 | * 433 | * @abstract 434 | * Creates a copy of the object. 435 | * 436 | * @param object 437 | * The object to copy. 438 | * 439 | * @result 440 | * The new object. NULL if the object type does not support copying or if 441 | * sufficient memory for the copy could not be allocated. Service objects do 442 | * not support copying. 443 | * 444 | * @discussion 445 | * When called on an array or dictionary, xpc_copy() will perform a deep copy. 446 | * 447 | * The object returned is not necessarily guaranteed to be a new object, and 448 | * whether it is will depend on the implementation of the object being copied. 449 | */ 450 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 451 | XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT XPC_RETURNS_RETAINED 452 | xpc_object_t _Nullable 453 | xpc_copy(xpc_object_t object); 454 | 455 | /*! 456 | * @function xpc_equal 457 | * 458 | * @abstract 459 | * Compares two objects for equality. 460 | * 461 | * @param object1 462 | * The first object to compare. 463 | * 464 | * @param object2 465 | * The second object to compare. 466 | * 467 | * @result 468 | * Returns true if the objects are equal, otherwise false. Two objects must be 469 | * of the same type in order to be equal. 470 | * 471 | * For two arrays to be equal, they must contain the same values at the 472 | * same indexes. For two dictionaries to be equal, they must contain the same 473 | * values for the same keys. 474 | * 475 | * Two objects being equal implies that their hashes (as returned by xpc_hash()) 476 | * are also equal. 477 | */ 478 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 479 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 XPC_WARN_RESULT 480 | bool 481 | xpc_equal(xpc_object_t object1, xpc_object_t object2); 482 | 483 | /*! 484 | * @function xpc_hash 485 | * 486 | * @abstract 487 | * Calculates a hash value for the given object. 488 | * 489 | * @param object 490 | * The object for which to calculate a hash value. This value may be modded 491 | * with a table size for insertion into a dictionary-like data structure. 492 | * 493 | * @result 494 | * The calculated hash value. 495 | * 496 | * @discussion 497 | * Note that the computed hash values for any particular type and value of an 498 | * object can change from across releases and platforms and should not be 499 | * assumed to be constant across all time and space or stored persistently. 500 | */ 501 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 502 | XPC_EXPORT XPC_NONNULL1 XPC_WARN_RESULT 503 | size_t 504 | xpc_hash(xpc_object_t object); 505 | 506 | /*! 507 | * @function xpc_copy_description 508 | * 509 | * @abstract 510 | * Copies a debug string describing the object. 511 | * 512 | * @param object 513 | * The object which is to be examined. 514 | * 515 | * @result 516 | * A string describing object which contains information useful for debugging. 517 | * This string should be disposed of with free(3) when done. 518 | */ 519 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 520 | XPC_EXPORT XPC_MALLOC XPC_WARN_RESULT XPC_NONNULL1 521 | char * 522 | xpc_copy_description(xpc_object_t object); 523 | 524 | #pragma mark XPC Object Types 525 | #pragma mark Null 526 | /*! 527 | * @function xpc_null_create 528 | * 529 | * @abstract 530 | * Creates an XPC object representing the null object. 531 | * 532 | * @result 533 | * A new null object. 534 | */ 535 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 536 | XPC_EXPORT XPC_RETURNS_RETAINED XPC_WARN_RESULT 537 | xpc_object_t 538 | xpc_null_create(void); 539 | 540 | #pragma mark Boolean 541 | /*! 542 | * @function xpc_bool_create 543 | * 544 | * @abstract 545 | * Creates an XPC Boolean object. 546 | * 547 | * @param value 548 | * The Boolean primitive value which is to be boxed. 549 | * 550 | * @result 551 | * A new Boolean object. 552 | */ 553 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 554 | XPC_EXPORT XPC_RETURNS_RETAINED XPC_WARN_RESULT 555 | xpc_object_t 556 | xpc_bool_create(bool value); 557 | 558 | /*! 559 | * @function xpc_bool_get_value 560 | * 561 | * @abstract 562 | * Returns the underlying Boolean value from the object. 563 | * 564 | * @param xbool 565 | * The Boolean object which is to be examined. 566 | * 567 | * @result 568 | * The underlying Boolean value or false if the given object was not an XPC 569 | * Boolean object. 570 | */ 571 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 572 | XPC_EXPORT 573 | bool 574 | xpc_bool_get_value(xpc_object_t xbool); 575 | 576 | #pragma mark Signed Integer 577 | /*! 578 | * @function xpc_int64_create 579 | * 580 | * @abstract 581 | * Creates an XPC signed integer object. 582 | * 583 | * @param value 584 | * The signed integer value which is to be boxed. 585 | * 586 | * @result 587 | * A new signed integer object. 588 | */ 589 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 590 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT 591 | xpc_object_t 592 | xpc_int64_create(int64_t value); 593 | 594 | /*! 595 | * @function xpc_int64_get_value 596 | * 597 | * @abstract 598 | * Returns the underlying signed 64-bit integer value from an object. 599 | * 600 | * @param xint 601 | * The signed integer object which is to be examined. 602 | * 603 | * @result 604 | * The underlying signed 64-bit value or 0 if the given object was not an XPC 605 | * integer object. 606 | */ 607 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 608 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 609 | int64_t 610 | xpc_int64_get_value(xpc_object_t xint); 611 | 612 | #pragma mark Unsigned Integer 613 | /*! 614 | * @function xpc_uint64_create 615 | * 616 | * @abstract 617 | * Creates an XPC unsigned integer object. 618 | * 619 | * @param value 620 | * The unsigned integer value which is to be boxed. 621 | * 622 | * @result 623 | * A new unsigned integer object. 624 | */ 625 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 626 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT 627 | xpc_object_t 628 | xpc_uint64_create(uint64_t value); 629 | 630 | /*! 631 | * @function xpc_uint64_get_value 632 | * 633 | * @abstract 634 | * Returns the underlying unsigned 64-bit integer value from an object. 635 | * 636 | * @param xuint 637 | * The unsigned integer object which is to be examined. 638 | * 639 | * @result 640 | * The underlying unsigned integer value or 0 if the given object was not an XPC 641 | * unsigned integer object. 642 | */ 643 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 644 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 645 | uint64_t 646 | xpc_uint64_get_value(xpc_object_t xuint); 647 | 648 | #pragma mark Double 649 | /*! 650 | * @function xpc_double_create 651 | * 652 | * @abstract 653 | * Creates an XPC double object. 654 | * 655 | * @param value 656 | * The floating point quantity which is to be boxed. 657 | * 658 | * @result 659 | * A new floating point object. 660 | */ 661 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 662 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT 663 | xpc_object_t 664 | xpc_double_create(double value); 665 | 666 | /*! 667 | * @function xpc_double_get_value 668 | * 669 | * @abstract 670 | * Returns the underlying double-precision floating point value from an object. 671 | * 672 | * @param xdouble 673 | * The floating point object which is to be examined. 674 | * 675 | * @result 676 | * The underlying floating point value or NAN if the given object was not an XPC 677 | * floating point object. 678 | */ 679 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 680 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 681 | double 682 | xpc_double_get_value(xpc_object_t xdouble); 683 | 684 | #pragma mark Date 685 | /*! 686 | * @function xpc_date_create 687 | * 688 | * @abstract 689 | * Creates an XPC date object. 690 | * 691 | * @param interval 692 | * The date interval which is to be boxed. Negative values indicate the number 693 | * of nanoseconds before the epoch. Positive values indicate the number of 694 | * nanoseconds after the epoch. 695 | * 696 | * @result 697 | * A new date object. 698 | */ 699 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 700 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT 701 | xpc_object_t 702 | xpc_date_create(int64_t interval); 703 | 704 | /*! 705 | * @function xpc_date_create_from_current 706 | * 707 | * @abstract 708 | * Creates an XPC date object representing the current date. 709 | * 710 | * @result 711 | * A new date object representing the current date. 712 | */ 713 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 714 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT 715 | xpc_object_t 716 | xpc_date_create_from_current(void); 717 | 718 | /*! 719 | * @function xpc_date_get_value 720 | * 721 | * @abstract 722 | * Returns the underlying date interval from an object. 723 | * 724 | * @param xdate 725 | * The date object which is to be examined. 726 | * 727 | * @result 728 | * The underlying date interval or 0 if the given object was not an XPC date 729 | * object. 730 | */ 731 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 732 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 733 | int64_t 734 | xpc_date_get_value(xpc_object_t xdate); 735 | 736 | #pragma mark Data 737 | /*! 738 | * @function xpc_data_create 739 | * 740 | * @abstract 741 | * Creates an XPC object representing buffer of bytes. 742 | * 743 | * @param bytes 744 | * The buffer of bytes which is to be boxed. You may create an empty data object 745 | * by passing NULL for this parameter and 0 for the length. Passing NULL with 746 | * any other length will result in undefined behavior. 747 | * 748 | * @param length 749 | * The number of bytes which are to be boxed. 750 | * 751 | * @result 752 | * A new data object. 753 | * 754 | * @discussion 755 | * This method will copy the buffer given into internal storage. After calling 756 | * this method, it is safe to dispose of the given buffer. 757 | */ 758 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 759 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT 760 | xpc_object_t 761 | xpc_data_create(const void * _Nullable bytes, size_t length); 762 | 763 | /*! 764 | * @function xpc_data_create_with_dispatch_data 765 | * 766 | * @abstract 767 | * Creates an XPC object representing buffer of bytes described by the given GCD 768 | * data object. 769 | * 770 | * @param ddata 771 | * The GCD data object containing the bytes which are to be boxed. This object 772 | * is retained by the data object. 773 | * 774 | * @result 775 | * A new data object. 776 | * 777 | * @discussion 778 | * The object returned by this method will refer to the buffer returned by 779 | * dispatch_data_create_map(). The point where XPC will make the call to 780 | * dispatch_data_create_map() is undefined. 781 | */ 782 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 783 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1 784 | xpc_object_t 785 | xpc_data_create_with_dispatch_data(dispatch_data_t ddata); 786 | 787 | /*! 788 | * @function xpc_data_get_length 789 | * 790 | * @abstract 791 | * Returns the length of the data encapsulated by an XPC data object. 792 | * 793 | * @param xdata 794 | * The data object which is to be examined. 795 | * 796 | * @result 797 | * The length of the underlying boxed data or 0 if the given object was not an 798 | * XPC data object. 799 | */ 800 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 801 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 802 | size_t 803 | xpc_data_get_length(xpc_object_t xdata); 804 | 805 | /*! 806 | * @function xpc_data_get_bytes_ptr 807 | * 808 | * @abstract 809 | * Returns a pointer to the internal storage of a data object. 810 | * 811 | * @param xdata 812 | * The data object which is to be examined. 813 | * 814 | * @result 815 | * A pointer to the underlying boxed data or NULL if the given object was not an 816 | * XPC data object. 817 | */ 818 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 819 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 820 | const void * _Nullable 821 | xpc_data_get_bytes_ptr(xpc_object_t xdata); 822 | 823 | /*! 824 | * @function xpc_data_get_bytes 825 | * 826 | * @abstract 827 | * Copies the bytes stored in an data objects into the specified buffer. 828 | * 829 | * @param xdata 830 | * The data object which is to be examined. 831 | * 832 | * @param buffer 833 | * The buffer in which to copy the data object's bytes. 834 | * 835 | * @param off 836 | * The offset at which to begin the copy. If this offset is greater than the 837 | * length of the data element, nothing is copied. Pass 0 to start the copy 838 | * at the beginning of the buffer. 839 | * 840 | * @param length 841 | * The length of the destination buffer. 842 | * 843 | * @result 844 | * The number of bytes that were copied into the buffer or 0 if the given object 845 | * was not an XPC data object. 846 | */ 847 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 848 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 XPC_NONNULL2 849 | size_t 850 | xpc_data_get_bytes(xpc_object_t xdata, 851 | void *buffer, size_t off, size_t length); 852 | 853 | #pragma mark String 854 | /*! 855 | * @function xpc_string_create 856 | * 857 | * @abstract 858 | * Creates an XPC object representing a NUL-terminated C-string. 859 | * 860 | * @param string 861 | * The C-string which is to be boxed. 862 | * 863 | * @result 864 | * A new string object. 865 | */ 866 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 867 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1 868 | xpc_object_t 869 | xpc_string_create(const char *string); 870 | 871 | /*! 872 | * @function xpc_string_create_with_format 873 | * 874 | * @abstract 875 | * Creates an XPC object representing a C-string that is generated from the 876 | * given format string and arguments. 877 | * 878 | * @param fmt 879 | * The printf(3)-style format string from which to construct the final C-string 880 | * to be boxed. 881 | * 882 | * @param ... 883 | * The arguments which correspond to those specified in the format string. 884 | * 885 | * @result 886 | * A new string object. 887 | */ 888 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 889 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1 890 | XPC_PRINTF(1, 2) 891 | xpc_object_t 892 | xpc_string_create_with_format(const char *fmt, ...); 893 | 894 | /*! 895 | * @function xpc_string_create_with_format_and_arguments 896 | * 897 | * @abstract 898 | * Creates an XPC object representing a C-string that is generated from the 899 | * given format string and argument list pointer. 900 | * 901 | * @param fmt 902 | * The printf(3)-style format string from which to construct the final C-string 903 | * to be boxed. 904 | * 905 | * @param ap 906 | * A pointer to the arguments which correspond to those specified in the format 907 | * string. 908 | * 909 | * @result 910 | * A new string object. 911 | */ 912 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 913 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1 914 | XPC_PRINTF(1, 0) 915 | xpc_object_t 916 | xpc_string_create_with_format_and_arguments(const char *fmt, va_list ap); 917 | 918 | /*! 919 | * @function xpc_string_get_length 920 | * 921 | * @abstract 922 | * Returns the length of the underlying string. 923 | * 924 | * @param xstring 925 | * The string object which is to be examined. 926 | * 927 | * @result 928 | * The length of the underlying string, not including the NUL-terminator, or 0 929 | * if the given object was not an XPC string object. 930 | */ 931 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 932 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL 933 | size_t 934 | xpc_string_get_length(xpc_object_t xstring); 935 | 936 | /*! 937 | * @function xpc_string_get_string_ptr 938 | * 939 | * @abstract 940 | * Returns a pointer to the internal storage of a string object. 941 | * 942 | * @param xstring 943 | * The string object which is to be examined. 944 | * 945 | * @result 946 | * A pointer to the string object's internal storage or NULL if the given object 947 | * was not an XPC string object. 948 | */ 949 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 950 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 951 | const char * _Nullable 952 | xpc_string_get_string_ptr(xpc_object_t xstring); 953 | 954 | #pragma mark UUID 955 | /*! 956 | * @function xpc_uuid_create 957 | * 958 | * @abstract 959 | * Creates an XPC object representing a universally-unique identifier (UUID) as 960 | * described by uuid(3). 961 | * 962 | * @param uuid 963 | * The UUID which is to be boxed. 964 | * 965 | * @result 966 | * A new UUID object. 967 | */ 968 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 969 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1 970 | xpc_object_t 971 | xpc_uuid_create(const uuid_t XPC_NONNULL_ARRAY uuid); 972 | 973 | /*! 974 | * @function xpc_uuid_get_bytes 975 | * 976 | * @abstract 977 | * Returns a pointer to the the boxed UUID bytes in an XPC UUID object. 978 | * 979 | * @param xuuid 980 | * The UUID object which is to be examined. 981 | * 982 | * @result 983 | * The underlying uuid_t bytes or NULL if the given object was not 984 | * an XPC UUID object. The returned pointer may be safely passed to the uuid(3) 985 | * APIs. 986 | */ 987 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 988 | XPC_EXPORT XPC_NONNULL1 989 | const uint8_t * _Nullable 990 | xpc_uuid_get_bytes(xpc_object_t xuuid); 991 | 992 | #pragma mark File Descriptors 993 | /*! 994 | * @function xpc_fd_create 995 | * 996 | * @abstract 997 | * Creates an XPC object representing a POSIX file descriptor. 998 | * 999 | * @param fd 1000 | * The file descriptor which is to be boxed. 1001 | * 1002 | * @result 1003 | * A new file descriptor object. NULL if sufficient memory could not be 1004 | * allocated or if the given file descriptor was not valid. 1005 | * 1006 | * @discussion 1007 | * This method performs the equivalent of a dup(2) on the descriptor, and thus 1008 | * it is safe to call close(2) on the descriptor after boxing it with a file 1009 | * descriptor object. 1010 | * 1011 | * IMPORTANT: Pointer equality is the ONLY valid test for equality between two 1012 | * file descriptor objects. There is no reliable way to determine whether two 1013 | * file descriptors refer to the same inode with the same capabilities, so two 1014 | * file descriptor objects created from the same underlying file descriptor 1015 | * number will not compare equally with xpc_equal(). This is also true of a 1016 | * file descriptor object created using xpc_copy() and the original. 1017 | * 1018 | * This also implies that two collections containing file descriptor objects 1019 | * cannot be equal unless the exact same object was inserted into both. 1020 | */ 1021 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1022 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT 1023 | xpc_object_t _Nullable 1024 | xpc_fd_create(int fd); 1025 | 1026 | /*! 1027 | * @function xpc_fd_dup 1028 | * 1029 | * @abstract 1030 | * Returns a file descriptor that is equivalent to the one boxed by the file 1031 | * file descriptor object. 1032 | * 1033 | * @param xfd 1034 | * The file descriptor object which is to be examined. 1035 | * 1036 | * @result 1037 | * A file descriptor that is equivalent to the one originally given to 1038 | * xpc_fd_create(). If the descriptor could not be created or if the given 1039 | * object was not an XPC file descriptor, -1 is returned. 1040 | * 1041 | * @discussion 1042 | * Multiple invocations of xpc_fd_dup() will not return the same file descriptor 1043 | * number, but they will return descriptors that are equivalent, as though they 1044 | * had been created by dup(2). 1045 | * 1046 | * The caller is responsible for calling close(2) on the returned descriptor. 1047 | */ 1048 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1049 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 1050 | int 1051 | xpc_fd_dup(xpc_object_t xfd); 1052 | 1053 | #pragma mark Shared Memory 1054 | /*! 1055 | * @function xpc_shmem_create 1056 | * 1057 | * @abstract 1058 | * Creates an XPC object representing the given shared memory region. 1059 | * 1060 | * @param region 1061 | * A pointer to a region of shared memory, created through a call to mmap(2) 1062 | * with the MAP_SHARED flag, which is to be boxed. 1063 | * 1064 | * @param length 1065 | * The length of the region. 1066 | * 1067 | * @result 1068 | * A new shared memory object. 1069 | * 1070 | * @discussion 1071 | * Only memory regions whose exact characteristics are known to the caller 1072 | * should be boxed using this API. Memory returned from malloc(3) may not be 1073 | * safely shared on either OS X or iOS because the underlying virtual memory 1074 | * objects for malloc(3)ed allocations are owned by the malloc(3) subsystem and 1075 | * not the caller of malloc(3). 1076 | * 1077 | * If you wish to share a memory region that you receive from another subsystem, 1078 | * part of the interface contract with that other subsystem must include how to 1079 | * create the region of memory, or sharing it may be unsafe. 1080 | * 1081 | * Certain operations may internally fragment a region of memory in a way that 1082 | * would truncate the range detected by the shared memory object. vm_copy(), for 1083 | * example, may split the region into multiple parts to avoid copying certain 1084 | * page ranges. For this reason, it is recommended that you delay all VM 1085 | * operations until the shared memory object has been created so that the VM 1086 | * system knows that the entire range is intended for sharing. 1087 | */ 1088 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1089 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1 1090 | xpc_object_t 1091 | xpc_shmem_create(void *region, size_t length); 1092 | 1093 | /*! 1094 | * @function xpc_shmem_map 1095 | * 1096 | * @abstract 1097 | * Maps the region boxed by the XPC shared memory object into the caller's 1098 | * address space. 1099 | * 1100 | * @param xshmem 1101 | * The shared memory object to be examined. 1102 | * 1103 | * @param region 1104 | * On return, this will point to the region at which the shared memory was 1105 | * mapped. 1106 | * 1107 | * @result 1108 | * The length of the region that was mapped. If the mapping failed or if the 1109 | * given object was not an XPC shared memory object, 0 is returned. The length 1110 | * of the mapped region will always be an integral page size, even if the 1111 | * creator of the region specified a non-integral page size. 1112 | * 1113 | * @discussion 1114 | * The resulting region must be disposed of with munmap(2). 1115 | * 1116 | * It is the responsibility of the caller to manage protections on the new 1117 | * region accordingly. 1118 | */ 1119 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1120 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL 1121 | size_t 1122 | xpc_shmem_map(xpc_object_t xshmem, void * _Nullable * _Nonnull region); 1123 | 1124 | #pragma mark Array 1125 | /*! 1126 | * @typedef xpc_array_applier_t 1127 | * A block to be invoked for every value in the array. 1128 | * 1129 | * @param index 1130 | * The current index in the iteration. 1131 | * 1132 | * @param value 1133 | * The current value in the iteration. 1134 | * 1135 | * @result 1136 | * A Boolean indicating whether iteration should continue. 1137 | */ 1138 | #ifdef __BLOCKS__ 1139 | typedef bool (^xpc_array_applier_t)(size_t index, xpc_object_t _Nonnull value); 1140 | #endif // __BLOCKS__ 1141 | 1142 | /*! 1143 | * @function xpc_array_create 1144 | * 1145 | * @abstract 1146 | * Creates an XPC object representing an array of XPC objects. 1147 | * 1148 | * @discussion 1149 | * This array must be contiguous and cannot contain any NULL values. If you 1150 | * wish to insert the equivalent of a NULL value, you may use the result of 1151 | * {@link xpc_null_create}. 1152 | * 1153 | * @param objects 1154 | * An array of XPC objects which is to be boxed. The order of this array is 1155 | * preserved in the object. If this array contains a NULL value, the behavior 1156 | * is undefined. This parameter may be NULL only if the count is 0. 1157 | * 1158 | * @param count 1159 | * The number of objects in the given array. If the number passed is less than 1160 | * the actual number of values in the array, only the specified number of items 1161 | * are inserted into the resulting array. If the number passed is more than 1162 | * the the actual number of values, the behavior is undefined. 1163 | * 1164 | * @result 1165 | * A new array object. 1166 | */ 1167 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1168 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT 1169 | xpc_object_t 1170 | xpc_array_create(const xpc_object_t _Nonnull * _Nullable objects, size_t count); 1171 | 1172 | /*! 1173 | * @function xpc_array_set_value 1174 | * 1175 | * @abstract 1176 | * Inserts the specified object into the array at the specified index. 1177 | * 1178 | * @param xarray 1179 | * The array object which is to be manipulated. 1180 | * 1181 | * @param index 1182 | * The index at which to insert the value. This value must lie within the index 1183 | * space of the array (0 to N-1 inclusive, where N is the count of the array). 1184 | * If the index is outside that range, the behavior is undefined. 1185 | * 1186 | * @param value 1187 | * The object to insert. This value is retained by the array and cannot be 1188 | * NULL. If there is already a value at the specified index, it is released, 1189 | * and the new value is inserted in its place. 1190 | */ 1191 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1192 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL3 1193 | void 1194 | xpc_array_set_value(xpc_object_t xarray, size_t index, xpc_object_t value); 1195 | 1196 | /*! 1197 | * @function xpc_array_append_value 1198 | * 1199 | * @abstract 1200 | * Appends an object to an XPC array. 1201 | * 1202 | * @param xarray 1203 | * The array object which is to be manipulated. 1204 | * 1205 | * @param value 1206 | * The object to append. This object is retained by the array. 1207 | */ 1208 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1209 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 1210 | void 1211 | xpc_array_append_value(xpc_object_t xarray, xpc_object_t value); 1212 | 1213 | /*! 1214 | * @function xpc_array_get_count 1215 | * 1216 | * @abstract 1217 | * Returns the count of values currently in the array. 1218 | * 1219 | * @param xarray 1220 | * The array object which is to be examined. 1221 | * 1222 | * @result 1223 | * The count of values in the array or 0 if the given object was not an XPC 1224 | * array. 1225 | */ 1226 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1227 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 1228 | size_t 1229 | xpc_array_get_count(xpc_object_t xarray); 1230 | 1231 | /*! 1232 | * @function xpc_array_get_value 1233 | * 1234 | * @abstract 1235 | * Returns the value at the specified index in the array. 1236 | * 1237 | * @param xarray 1238 | * The array object which is to be examined. 1239 | * 1240 | * @param index 1241 | * The index of the value to obtain. This value must lie within the range of 1242 | * indexes as specified in xpc_array_set_value(). 1243 | * 1244 | * @result 1245 | * The object at the specified index within the array or NULL if the given 1246 | * object was not an XPC array. 1247 | * 1248 | * @discussion 1249 | * This method does not grant the caller a reference to the underlying object, 1250 | * and thus the caller is not responsible for releasing the object. 1251 | */ 1252 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1253 | XPC_EXPORT XPC_NONNULL_ALL 1254 | xpc_object_t 1255 | xpc_array_get_value(xpc_object_t xarray, size_t index); 1256 | 1257 | /*! 1258 | * @function xpc_array_apply 1259 | * 1260 | * @abstract 1261 | * Invokes the given block for every value in the array. 1262 | * 1263 | * @param xarray 1264 | * The array object which is to be examined. 1265 | * 1266 | * @param applier 1267 | * The block which this function applies to every element in the array. 1268 | * 1269 | * @result 1270 | * A Boolean indicating whether iteration of the array completed successfully. 1271 | * Iteration will only fail if the applier block returns false. 1272 | * 1273 | * @discussion 1274 | * You should not modify an array's contents during iteration. The array indexes 1275 | * are iterated in order. 1276 | */ 1277 | #ifdef __BLOCKS__ 1278 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1279 | XPC_EXPORT XPC_NONNULL_ALL 1280 | bool 1281 | xpc_array_apply(xpc_object_t xarray, XPC_NOESCAPE xpc_array_applier_t applier); 1282 | #endif // __BLOCKS__ 1283 | 1284 | #pragma mark Array Primitive Setters 1285 | /*! 1286 | * @define XPC_ARRAY_APPEND 1287 | * A constant that may be passed as the destination index to the class of 1288 | * primitive XPC array setters indicating that the given primitive should be 1289 | * appended to the array. 1290 | */ 1291 | #define XPC_ARRAY_APPEND ((size_t)(-1)) 1292 | 1293 | /*! 1294 | * @function xpc_array_set_bool 1295 | * 1296 | * @abstract 1297 | * Inserts a bool (primitive) value into an array. 1298 | * 1299 | * @param xarray 1300 | * The array object which is to be manipulated. 1301 | * 1302 | * @param index 1303 | * The index at which to insert the value. This value must lie within the index 1304 | * space of the array (0 to N-1 inclusive, where N is the count of the array) or 1305 | * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is 1306 | * undefined. 1307 | * 1308 | * @param value 1309 | * The bool value to insert. After calling this method, the XPC 1310 | * object corresponding to the primitive value inserted may be safely retrieved 1311 | * with {@link xpc_array_get_value()}. 1312 | */ 1313 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1314 | XPC_EXPORT XPC_NONNULL1 1315 | void 1316 | xpc_array_set_bool(xpc_object_t xarray, size_t index, bool value); 1317 | 1318 | /*! 1319 | * @function xpc_array_set_int64 1320 | * 1321 | * @abstract 1322 | * Inserts an int64_t (primitive) value into an array. 1323 | * 1324 | * @param xarray 1325 | * The array object which is to be manipulated. 1326 | * 1327 | * @param index 1328 | * The index at which to insert the value. This value must lie within the index 1329 | * space of the array (0 to N-1 inclusive, where N is the count of the array) or 1330 | * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is 1331 | * undefined. 1332 | * 1333 | * @param value 1334 | * The int64_t value to insert. After calling this method, the XPC 1335 | * object corresponding to the primitive value inserted may be safely retrieved 1336 | * with {@link xpc_array_get_value()}. 1337 | */ 1338 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1339 | XPC_EXPORT XPC_NONNULL1 1340 | void 1341 | xpc_array_set_int64(xpc_object_t xarray, size_t index, int64_t value); 1342 | 1343 | /*! 1344 | * @function xpc_array_set_uint64 1345 | * 1346 | * @abstract 1347 | * Inserts a uint64_t (primitive) value into an array. 1348 | * 1349 | * @param xarray 1350 | * The array object which is to be manipulated. 1351 | * 1352 | * @param index 1353 | * The index at which to insert the value. This value must lie within the index 1354 | * space of the array (0 to N-1 inclusive, where N is the count of the array) or 1355 | * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is 1356 | * undefined. 1357 | * 1358 | * @param value 1359 | * The uint64_t value to insert. After calling this method, the XPC 1360 | * object corresponding to the primitive value inserted may be safely retrieved 1361 | * with {@link xpc_array_get_value()}. 1362 | */ 1363 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1364 | XPC_EXPORT XPC_NONNULL1 1365 | void 1366 | xpc_array_set_uint64(xpc_object_t xarray, size_t index, uint64_t value); 1367 | 1368 | /*! 1369 | * @function xpc_array_set_double 1370 | * 1371 | * @abstract 1372 | * Inserts a double (primitive) value into an array. 1373 | * 1374 | * @param xarray 1375 | * The array object which is to be manipulated. 1376 | * 1377 | * @param index 1378 | * The index at which to insert the value. This value must lie within the index 1379 | * space of the array (0 to N-1 inclusive, where N is the count of the array) or 1380 | * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is 1381 | * undefined. 1382 | * 1383 | * @param value 1384 | * The double value to insert. After calling this method, the XPC 1385 | * object corresponding to the primitive value inserted may be safely retrieved 1386 | * with {@link xpc_array_get_value()}. 1387 | */ 1388 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1389 | XPC_EXPORT XPC_NONNULL1 1390 | void 1391 | xpc_array_set_double(xpc_object_t xarray, size_t index, double value); 1392 | 1393 | /*! 1394 | * @function xpc_array_set_date 1395 | * 1396 | * @abstract 1397 | * Inserts a date value into an array. 1398 | * 1399 | * @param xarray 1400 | * The array object which is to be manipulated. 1401 | * 1402 | * @param index 1403 | * The index at which to insert the value. This value must lie within the index 1404 | * space of the array (0 to N-1 inclusive, where N is the count of the array) or 1405 | * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is 1406 | * undefined. 1407 | * 1408 | * @param value 1409 | * The date value to insert, represented as an int64_t. After 1410 | * calling this method, the XPC object corresponding to the primitive value 1411 | * inserted may be safely retrieved with {@link xpc_array_get_value()}. 1412 | */ 1413 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1414 | XPC_EXPORT XPC_NONNULL1 1415 | void 1416 | xpc_array_set_date(xpc_object_t xarray, size_t index, int64_t value); 1417 | 1418 | /*! 1419 | * @function xpc_array_set_data 1420 | * 1421 | * @abstract 1422 | * Inserts a raw data value into an array. 1423 | * 1424 | * @param xarray 1425 | * The array object which is to be manipulated. 1426 | * 1427 | * @param index 1428 | * The index at which to insert the value. This value must lie within the index 1429 | * space of the array (0 to N-1 inclusive, where N is the count of the array) or 1430 | * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is 1431 | * undefined. 1432 | * 1433 | * @param bytes 1434 | * The raw data to insert. After calling this method, the XPC object 1435 | * corresponding to the primitive value inserted may be safely retrieved with 1436 | * {@link xpc_array_get_value()}. 1437 | * 1438 | * @param length 1439 | * The length of the data. 1440 | */ 1441 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1442 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL3 1443 | void 1444 | xpc_array_set_data(xpc_object_t xarray, size_t index, const void *bytes, 1445 | size_t length); 1446 | 1447 | /*! 1448 | * @function xpc_array_set_string 1449 | * 1450 | * @abstract 1451 | * Inserts a C string into an array. 1452 | * 1453 | * @param xarray 1454 | * The array object which is to be manipulated. 1455 | * 1456 | * @param index 1457 | * The index at which to insert the value. This value must lie within the index 1458 | * space of the array (0 to N-1 inclusive, where N is the count of the array) or 1459 | * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is 1460 | * undefined. 1461 | * 1462 | * @param string 1463 | * The C string to insert. After calling this method, the XPC object 1464 | * corresponding to the primitive value inserted may be safely retrieved with 1465 | * {@link xpc_array_get_value()}. 1466 | */ 1467 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1468 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL3 1469 | void 1470 | xpc_array_set_string(xpc_object_t xarray, size_t index, const char *string); 1471 | 1472 | /*! 1473 | * @function xpc_array_set_uuid 1474 | * 1475 | * @abstract 1476 | * Inserts a uuid_t (primitive) value into an array. 1477 | * 1478 | * @param xarray 1479 | * The array object which is to be manipulated. 1480 | * 1481 | * @param index 1482 | * The index at which to insert the value. This value must lie within the index 1483 | * space of the array (0 to N-1 inclusive, where N is the count of the array) or 1484 | * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is 1485 | * undefined. 1486 | * 1487 | * @param uuid 1488 | * The UUID primitive to insert. After calling this method, the XPC object 1489 | * corresponding to the primitive value inserted may be safely retrieved with 1490 | * {@link xpc_array_get_value()}. 1491 | */ 1492 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1493 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL3 1494 | void 1495 | xpc_array_set_uuid(xpc_object_t xarray, size_t index, 1496 | const uuid_t XPC_NONNULL_ARRAY uuid); 1497 | 1498 | /*! 1499 | * @function xpc_array_set_fd 1500 | * 1501 | * @abstract 1502 | * Inserts a file descriptor into an array. 1503 | * 1504 | * @param xarray 1505 | * The array object which is to be manipulated. 1506 | * 1507 | * @param index 1508 | * The index at which to insert the value. This value must lie within the index 1509 | * space of the array (0 to N-1 inclusive, where N is the count of the array) or 1510 | * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is 1511 | * undefined. 1512 | * 1513 | * @param fd 1514 | * The file descriptor to insert. After calling this method, the XPC object 1515 | * corresponding to the primitive value inserted may be safely retrieved with 1516 | * {@link xpc_array_get_value()}. 1517 | */ 1518 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1519 | XPC_EXPORT XPC_NONNULL1 1520 | void 1521 | xpc_array_set_fd(xpc_object_t xarray, size_t index, int fd); 1522 | 1523 | /*! 1524 | * @function xpc_array_set_connection 1525 | * 1526 | * @abstract 1527 | * Inserts a connection into an array. 1528 | * 1529 | * @param xarray 1530 | * The array object which is to be manipulated. 1531 | * 1532 | * @param index 1533 | * The index at which to insert the value. This value must lie within the index 1534 | * space of the array (0 to N-1 inclusive, where N is the count of the array) or 1535 | * be XPC_ARRAY_APPEND. If the index is outside that range, the behavior is 1536 | * undefined. 1537 | * 1538 | * @param connection 1539 | * The connection to insert. After calling this method, the XPC object 1540 | * corresponding to the primitive value inserted may be safely retrieved with 1541 | * {@link xpc_array_get_value()}. The connection is NOT retained by the array. 1542 | */ 1543 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1544 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL3 1545 | void 1546 | xpc_array_set_connection(xpc_object_t xarray, size_t index, 1547 | xpc_connection_t connection); 1548 | 1549 | #pragma mark Array Primitive Getters 1550 | /*! 1551 | * @function xpc_array_get_bool 1552 | * 1553 | * @abstract 1554 | * Gets a bool primitive value from an array directly. 1555 | * 1556 | * @param xarray 1557 | * The array which is to be examined. 1558 | * 1559 | * @param index 1560 | * The index of the value to obtain. This value must lie within the index space 1561 | * of the array (0 to N-1 inclusive, where N is the count of the array). If the 1562 | * index is outside that range, the behavior is undefined. 1563 | * 1564 | * @result 1565 | * The underlying bool value at the specified index. false if the 1566 | * value at the specified index is not a Boolean value. 1567 | */ 1568 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1569 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 1570 | bool 1571 | xpc_array_get_bool(xpc_object_t xarray, size_t index); 1572 | 1573 | /*! 1574 | * @function xpc_array_get_int64 1575 | * 1576 | * @abstract 1577 | * Gets an int64_t primitive value from an array directly. 1578 | * 1579 | * @param xarray 1580 | * The array which is to be examined. 1581 | * 1582 | * @param index 1583 | * The index of the value to obtain. This value must lie within the index space 1584 | * of the array (0 to N-1 inclusive, where N is the count of the array). If the 1585 | * index is outside that range, the behavior is undefined. 1586 | * 1587 | * @result 1588 | * The underlying int64_t value at the specified index. 0 if the 1589 | * value at the specified index is not a signed integer value. 1590 | */ 1591 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1592 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 1593 | int64_t 1594 | xpc_array_get_int64(xpc_object_t xarray, size_t index); 1595 | 1596 | /*! 1597 | * @function xpc_array_get_uint64 1598 | * 1599 | * @abstract 1600 | * Gets a uint64_t primitive value from an array directly. 1601 | * 1602 | * @param xarray 1603 | * The array which is to be examined. 1604 | * 1605 | * @param index 1606 | * The index of the value to obtain. This value must lie within the index space 1607 | * of the array (0 to N-1 inclusive, where N is the count of the array). If the 1608 | * index is outside that range, the behavior is undefined. 1609 | * 1610 | * @result 1611 | * The underlying uint64_t value at the specified index. 0 if the 1612 | * value at the specified index is not an unsigned integer value. 1613 | */ 1614 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1615 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 1616 | uint64_t 1617 | xpc_array_get_uint64(xpc_object_t xarray, size_t index); 1618 | 1619 | /*! 1620 | * @function xpc_array_get_double 1621 | * 1622 | * @abstract 1623 | * Gets a double primitive value from an array directly. 1624 | * 1625 | * @param xarray 1626 | * The array which is to be examined. 1627 | * 1628 | * @param index 1629 | * The index of the value to obtain. This value must lie within the index space 1630 | * of the array (0 to N-1 inclusive, where N is the count of the array). If the 1631 | * index is outside that range, the behavior is undefined. 1632 | * 1633 | * @result 1634 | * The underlying double value at the specified index. NAN if the 1635 | * value at the specified index is not a floating point value. 1636 | */ 1637 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1638 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 1639 | double 1640 | xpc_array_get_double(xpc_object_t xarray, size_t index); 1641 | 1642 | /*! 1643 | * @function xpc_array_get_date 1644 | * 1645 | * @abstract 1646 | * Gets a date interval from an array directly. 1647 | * 1648 | * @param xarray 1649 | * The array which is to be examined. 1650 | * 1651 | * @param index 1652 | * The index of the value to obtain. This value must lie within the index space 1653 | * of the array (0 to N-1 inclusive, where N is the count of the array). If the 1654 | * index is outside that range, the behavior is undefined. 1655 | * 1656 | * @result 1657 | * The underlying date interval at the specified index. 0 if the value at the 1658 | * specified index is not a date value. 1659 | */ 1660 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1661 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 1662 | int64_t 1663 | xpc_array_get_date(xpc_object_t xarray, size_t index); 1664 | 1665 | /*! 1666 | * @function xpc_array_get_data 1667 | * 1668 | * @abstract 1669 | * Gets a pointer to the raw bytes of a data object from an array directly. 1670 | * 1671 | * @param xarray 1672 | * The array which is to be examined. 1673 | * 1674 | * @param index 1675 | * The index of the value to obtain. This value must lie within the index space 1676 | * of the array (0 to N-1 inclusive, where N is the count of the array). If the 1677 | * index is outside that range, the behavior is undefined. 1678 | * 1679 | * @param length 1680 | * Upon return output, will contain the length of the data corresponding to the 1681 | * specified key. 1682 | * 1683 | * @result 1684 | * The underlying bytes at the specified index. NULL if the value at the 1685 | * specified index is not a data value. 1686 | */ 1687 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1688 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 1689 | const void * _Nullable 1690 | xpc_array_get_data(xpc_object_t xarray, size_t index, 1691 | size_t * _Nullable length); 1692 | 1693 | /*! 1694 | * @function xpc_array_get_string 1695 | * 1696 | * @abstract 1697 | * Gets a C string value from an array directly. 1698 | * 1699 | * @param xarray 1700 | * The array which is to be examined. 1701 | * 1702 | * @param index 1703 | * The index of the value to obtain. This value must lie within the index space 1704 | * of the array (0 to N-1 inclusive, where N is the count of the array). If the 1705 | * index is outside that range, the behavior is undefined. 1706 | * 1707 | * @result 1708 | * The underlying C string at the specified index. NULL if the value at the 1709 | * specified index is not a C string value. 1710 | */ 1711 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1712 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 1713 | const char * _Nullable 1714 | xpc_array_get_string(xpc_object_t xarray, size_t index); 1715 | 1716 | /*! 1717 | * @function xpc_array_get_uuid 1718 | * 1719 | * @abstract 1720 | * Gets a uuid_t value from an array directly. 1721 | * 1722 | * @param xarray 1723 | * The array which is to be examined. 1724 | * 1725 | * @param index 1726 | * The index of the value to obtain. This value must lie within the index space 1727 | * of the array (0 to N-1 inclusive, where N is the count of the array). If the 1728 | * index is outside that range, the behavior is undefined. 1729 | * 1730 | * @result 1731 | * The underlying uuid_t value at the specified index. The null 1732 | * UUID if the value at the specified index is not a UUID value. The returned 1733 | * pointer may be safely passed to the uuid(3) APIs. 1734 | */ 1735 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1736 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 1737 | const uint8_t * _Nullable 1738 | xpc_array_get_uuid(xpc_object_t xarray, size_t index); 1739 | 1740 | /*! 1741 | * @function xpc_array_dup_fd 1742 | * 1743 | * @abstract 1744 | * Gets a file descriptor from an array directly. 1745 | * 1746 | * @param xarray 1747 | * The array which is to be examined. 1748 | * 1749 | * @param index 1750 | * The index of the value to obtain. This value must lie within the index space 1751 | * of the array (0 to N-1 inclusive, where N is the count of the array). If the 1752 | * index is outside that range, the behavior is undefined. 1753 | * 1754 | * @result 1755 | * A new file descriptor created from the value at the specified index. You are 1756 | * responsible for close(2)ing this descriptor. -1 if the value at the specified 1757 | * index is not a file descriptor value. 1758 | */ 1759 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1760 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 1761 | int 1762 | xpc_array_dup_fd(xpc_object_t xarray, size_t index); 1763 | 1764 | /*! 1765 | * @function xpc_array_create_connection 1766 | * 1767 | * @abstract 1768 | * Creates a connection object from an array directly. 1769 | * 1770 | * @param xarray 1771 | * The array which is to be examined. 1772 | * 1773 | * @param index 1774 | * The index of the value to obtain. This value must lie within the index space 1775 | * of the array (0 to N-1 inclusive, where N is the count of the array). If the 1776 | * index is outside that range, the behavior is undefined. 1777 | * 1778 | * @result 1779 | * A new connection created from the value at the specified index. You are 1780 | * responsible for calling xpc_release() on the returned connection. NULL if the 1781 | * value at the specified index is not an endpoint containing a connection. Each 1782 | * call to this method for the same index in the same array will yield a 1783 | * different connection. See {@link xpc_connection_create_from_endpoint()} for 1784 | * discussion as to the responsibilities when dealing with the returned 1785 | * connection. 1786 | */ 1787 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1788 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1 1789 | xpc_connection_t _Nullable 1790 | xpc_array_create_connection(xpc_object_t xarray, size_t index); 1791 | 1792 | /*! 1793 | * @function xpc_array_get_dictionary 1794 | * 1795 | * @abstract 1796 | * Returns the dictionary at the specified index in the array. 1797 | * 1798 | * @param xarray 1799 | * The array object which is to be examined. 1800 | * 1801 | * @param index 1802 | * The index of the value to obtain. This value must lie within the range of 1803 | * indexes as specified in xpc_array_set_value(). 1804 | * 1805 | * @result 1806 | * The object at the specified index within the array or NULL if the given 1807 | * object was not an XPC array or if the the value at the specified index was 1808 | * not a dictionary. 1809 | * 1810 | * @discussion 1811 | * This method does not grant the caller a reference to the underlying object, 1812 | * and thus the caller is not responsible for releasing the object. 1813 | */ 1814 | __OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0) 1815 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL 1816 | xpc_object_t _Nullable 1817 | xpc_array_get_dictionary(xpc_object_t xarray, size_t index); 1818 | 1819 | /*! 1820 | * @function xpc_array_get_array 1821 | * 1822 | * @abstract 1823 | * Returns the array at the specified index in the array. 1824 | * 1825 | * @param xarray 1826 | * The array object which is to be examined. 1827 | * 1828 | * @param index 1829 | * The index of the value to obtain. This value must lie within the range of 1830 | * indexes as specified in xpc_array_set_value(). 1831 | * 1832 | * @result 1833 | * The object at the specified index within the array or NULL if the given 1834 | * object was not an XPC array or if the the value at the specified index was 1835 | * not an array. 1836 | * 1837 | * @discussion 1838 | * This method does not grant the caller a reference to the underlying object, 1839 | * and thus the caller is not responsible for releasing the object. 1840 | */ 1841 | __OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0) 1842 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL 1843 | xpc_object_t _Nullable 1844 | xpc_array_get_array(xpc_object_t xarray, size_t index); 1845 | 1846 | #pragma mark Dictionary 1847 | /*! 1848 | * @typedef xpc_dictionary_applier_t 1849 | * A block to be invoked for every key/value pair in the dictionary. 1850 | * 1851 | * @param key 1852 | * The current key in the iteration. 1853 | * 1854 | * @param value 1855 | * The current value in the iteration. 1856 | * 1857 | * @result 1858 | * A Boolean indicating whether iteration should continue. 1859 | */ 1860 | #ifdef __BLOCKS__ 1861 | typedef bool (^xpc_dictionary_applier_t)(const char * _Nonnull key, 1862 | xpc_object_t _Nonnull value); 1863 | #endif // __BLOCKS__ 1864 | 1865 | /*! 1866 | * @function xpc_dictionary_create 1867 | * 1868 | * @abstract 1869 | * Creates an XPC object representing a dictionary of XPC objects keyed to 1870 | * C-strings. 1871 | * 1872 | * @param keys 1873 | * An array of C-strings that are to be the keys for the values to be inserted. 1874 | * Each element of this array is copied into the dictionary's internal storage. 1875 | * Elements of this array may NOT be NULL. 1876 | * 1877 | * @param values 1878 | * A C-array that is parallel to the array of keys, consisting of objects that 1879 | * are to be inserted. Each element in this array is retained. Elements in this 1880 | * array may be NULL. 1881 | * 1882 | * @param count 1883 | * The number of key/value pairs in the given arrays. If the count is less than 1884 | * the actual count of values, only that many key/value pairs will be inserted 1885 | * into the dictionary. 1886 | * 1887 | * If the count is more than the the actual count of key/value pairs, the 1888 | * behavior is undefined. If one array is NULL and the other is not, the 1889 | * behavior is undefined. If both arrays are NULL and the count is non-0, the 1890 | * behavior is undefined. 1891 | * 1892 | * @result 1893 | * The new dictionary object. 1894 | */ 1895 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1896 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT 1897 | xpc_object_t 1898 | xpc_dictionary_create(const char * _Nonnull const * _Nullable keys, 1899 | const xpc_object_t _Nullable * _Nullable values, size_t count); 1900 | 1901 | /*! 1902 | * @function xpc_dictionary_create_reply 1903 | * 1904 | * @abstract 1905 | * Creates a dictionary that is in reply to the given dictionary. 1906 | * 1907 | * @param original 1908 | * The original dictionary that is to be replied to. 1909 | * 1910 | * @result 1911 | * The new dictionary object. NULL if the object was not a dictionary with a 1912 | * reply context. 1913 | * 1914 | * @discussion 1915 | * After completing successfully on a dictionary, this method may not be called 1916 | * again on that same dictionary. Attempts to do so will return NULL. 1917 | * 1918 | * When this dictionary is sent across the reply connection, the remote end's 1919 | * reply handler is invoked. 1920 | */ 1921 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1922 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL_ALL 1923 | xpc_object_t _Nullable 1924 | xpc_dictionary_create_reply(xpc_object_t original); 1925 | 1926 | /*! 1927 | * @function xpc_dictionary_set_value 1928 | * 1929 | * @abstract 1930 | * Sets the value for the specified key to the specified object. 1931 | * 1932 | * @param xdict 1933 | * The dictionary object which is to be manipulated. 1934 | * 1935 | * @param key 1936 | * The key for which the value shall be set. 1937 | * 1938 | * @param value 1939 | * The object to insert. The object is retained by the dictionary. If there 1940 | * already exists a value for the specified key, the old value is released 1941 | * and overwritten by the new value. This parameter may be NULL, in which case 1942 | * the value corresponding to the specified key is deleted if present. 1943 | */ 1944 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1945 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 1946 | void 1947 | xpc_dictionary_set_value(xpc_object_t xdict, const char *key, 1948 | xpc_object_t _Nullable value); 1949 | 1950 | /*! 1951 | * @function xpc_dictionary_get_value 1952 | * 1953 | * @abstract 1954 | * Returns the value for the specified key. 1955 | * 1956 | * @param xdict 1957 | * The dictionary object which is to be examined. 1958 | * 1959 | * @param key 1960 | * The key whose value is to be obtained. 1961 | * 1962 | * @result 1963 | * The object for the specified key within the dictionary. NULL if there is no 1964 | * value associated with the specified key or if the given object was not an 1965 | * XPC dictionary. 1966 | * 1967 | * @discussion 1968 | * This method does not grant the caller a reference to the underlying object, 1969 | * and thus the caller is not responsible for releasing the object. 1970 | */ 1971 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1972 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 XPC_NONNULL2 1973 | xpc_object_t _Nullable 1974 | xpc_dictionary_get_value(xpc_object_t xdict, const char *key); 1975 | 1976 | /*! 1977 | * @function xpc_dictionary_get_count 1978 | * 1979 | * @abstract 1980 | * Returns the number of values stored in the dictionary. 1981 | * 1982 | * @param xdict 1983 | * The dictionary object which is to be examined. 1984 | * 1985 | * @result 1986 | * The number of values stored in the dictionary or 0 if the given object was 1987 | * not an XPC dictionary. Calling xpc_dictionary_set_value() with a non-NULL 1988 | * value will increment the count. Calling xpc_dictionary_set_value() with a 1989 | * NULL value will decrement the count. 1990 | */ 1991 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 1992 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 1993 | size_t 1994 | xpc_dictionary_get_count(xpc_object_t xdict); 1995 | 1996 | /*! 1997 | * @function xpc_dictionary_apply 1998 | * 1999 | * @abstract 2000 | * Invokes the given block for every key/value pair in the dictionary. 2001 | * 2002 | * @param xdict 2003 | * The dictionary object which is to be examined. 2004 | * 2005 | * @param applier 2006 | * The block which this function applies to every key/value pair in the 2007 | * dictionary. 2008 | * 2009 | * @result 2010 | * A Boolean indicating whether iteration of the dictionary completed 2011 | * successfully. Iteration will only fail if the applier block returns false. 2012 | * 2013 | * @discussion 2014 | * You should not modify a dictionary's contents during iteration. There is no 2015 | * guaranteed order of iteration over dictionaries. 2016 | */ 2017 | #ifdef __BLOCKS__ 2018 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2019 | XPC_EXPORT XPC_NONNULL_ALL 2020 | bool 2021 | xpc_dictionary_apply(xpc_object_t xdict, 2022 | XPC_NOESCAPE xpc_dictionary_applier_t applier); 2023 | #endif // __BLOCKS__ 2024 | 2025 | /*! 2026 | * @function xpc_dictionary_get_remote_connection 2027 | * 2028 | * @abstract 2029 | * Returns the connection from which the dictionary was received. 2030 | * 2031 | * @param xdict 2032 | * The dictionary object which is to be examined. 2033 | * 2034 | * @result 2035 | * If the dictionary was received by a connection event handler or a dictionary 2036 | * created through xpc_dictionary_create_reply(), a connection object over which 2037 | * a reply message can be sent is returned. For any other dictionary, NULL is 2038 | * returned. 2039 | */ 2040 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2041 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL 2042 | xpc_connection_t _Nullable 2043 | xpc_dictionary_get_remote_connection(xpc_object_t xdict); 2044 | 2045 | #pragma mark Dictionary Primitive Setters 2046 | /*! 2047 | * @function xpc_dictionary_set_bool 2048 | * 2049 | * @abstract 2050 | * Inserts a bool (primitive) value into a dictionary. 2051 | * 2052 | * @param xdict 2053 | * The dictionary which is to be manipulated. 2054 | * 2055 | * @param key 2056 | * The key for which the primitive value shall be set. 2057 | * 2058 | * @param value 2059 | * The bool value to insert. After calling this method, the XPC 2060 | * object corresponding to the primitive value inserted may be safely retrieved 2061 | * with {@link xpc_dictionary_get_value()}. 2062 | */ 2063 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2064 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 2065 | void 2066 | xpc_dictionary_set_bool(xpc_object_t xdict, const char *key, bool value); 2067 | 2068 | /*! 2069 | * @function xpc_dictionary_set_int64 2070 | * 2071 | * @abstract 2072 | * Inserts an int64_t (primitive) value into a dictionary. 2073 | * 2074 | * @param xdict 2075 | * The dictionary which is to be manipulated. 2076 | * 2077 | * @param key 2078 | * The key for which the primitive value shall be set. 2079 | * 2080 | * @param value 2081 | * The int64_t value to insert. After calling this method, the XPC 2082 | * object corresponding to the primitive value inserted may be safely retrieved 2083 | * with {@link xpc_dictionary_get_value()}. 2084 | */ 2085 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2086 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 2087 | void 2088 | xpc_dictionary_set_int64(xpc_object_t xdict, const char *key, int64_t value); 2089 | 2090 | /*! 2091 | * @function xpc_dictionary_set_uint64 2092 | * 2093 | * @abstract 2094 | * Inserts a uint64_t (primitive) value into a dictionary. 2095 | * 2096 | * @param xdict 2097 | * The dictionary which is to be manipulated. 2098 | * 2099 | * @param key 2100 | * The key for which the primitive value shall be set. 2101 | * 2102 | * @param value 2103 | * The uint64_t value to insert. After calling this method, the XPC 2104 | * object corresponding to the primitive value inserted may be safely retrieved 2105 | * with {@link xpc_dictionary_get_value()}. 2106 | */ 2107 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2108 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 2109 | void 2110 | xpc_dictionary_set_uint64(xpc_object_t xdict, const char *key, uint64_t value); 2111 | 2112 | /*! 2113 | * @function xpc_dictionary_set_double 2114 | * 2115 | * @abstract 2116 | * Inserts a double (primitive) value into a dictionary. 2117 | * 2118 | * @param xdict 2119 | * The dictionary which is to be manipulated. 2120 | * 2121 | * @param key 2122 | * The key for which the primitive value shall be set. 2123 | * 2124 | * @param value 2125 | * The double value to insert. After calling this method, the XPC 2126 | * object corresponding to the primitive value inserted may be safely retrieved 2127 | * with {@link xpc_dictionary_get_value()}. 2128 | */ 2129 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2130 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 2131 | void 2132 | xpc_dictionary_set_double(xpc_object_t xdict, const char *key, double value); 2133 | 2134 | /*! 2135 | * @function xpc_dictionary_set_date 2136 | * 2137 | * @abstract 2138 | * Inserts a date (primitive) value into a dictionary. 2139 | * 2140 | * @param xdict 2141 | * The dictionary which is to be manipulated. 2142 | * 2143 | * @param key 2144 | * The key for which the primitive value shall be set. 2145 | * 2146 | * @param value 2147 | * The date value to insert. After calling this method, the XPC object 2148 | * corresponding to the primitive value inserted may be safely retrieved with 2149 | * {@link xpc_dictionary_get_value()}. 2150 | */ 2151 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2152 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 2153 | void 2154 | xpc_dictionary_set_date(xpc_object_t xdict, const char *key, int64_t value); 2155 | 2156 | /*! 2157 | * @function xpc_dictionary_set_data 2158 | * 2159 | * @abstract 2160 | * Inserts a raw data value into a dictionary. 2161 | * 2162 | * @param xdict 2163 | * The dictionary which is to be manipulated. 2164 | * 2165 | * @param key 2166 | * The key for which the primitive value shall be set. 2167 | * 2168 | * @param bytes 2169 | * The bytes to insert. After calling this method, the XPC object corresponding 2170 | * to the primitive value inserted may be safely retrieved with 2171 | * {@link xpc_dictionary_get_value()}. 2172 | * 2173 | * @param length 2174 | * The length of the data. 2175 | */ 2176 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2177 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 XPC_NONNULL3 2178 | void 2179 | xpc_dictionary_set_data(xpc_object_t xdict, const char *key, const void *bytes, 2180 | size_t length); 2181 | 2182 | /*! 2183 | * @function xpc_dictionary_set_string 2184 | * 2185 | * @abstract 2186 | * Inserts a C string value into a dictionary. 2187 | * 2188 | * @param xdict 2189 | * The dictionary which is to be manipulated. 2190 | * 2191 | * @param key 2192 | * The key for which the primitive value shall be set. 2193 | * 2194 | * @param string 2195 | * The C string to insert. After calling this method, the XPC object 2196 | * corresponding to the primitive value inserted may be safely retrieved with 2197 | * {@link xpc_dictionary_get_value()}. 2198 | */ 2199 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2200 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 XPC_NONNULL3 2201 | void 2202 | xpc_dictionary_set_string(xpc_object_t xdict, const char *key, 2203 | const char *string); 2204 | 2205 | /*! 2206 | * @function xpc_dictionary_set_uuid 2207 | * 2208 | * @abstract 2209 | * Inserts a uuid (primitive) value into an array. 2210 | * 2211 | * @param xdict 2212 | * The dictionary which is to be manipulated. 2213 | * 2214 | * @param key 2215 | * The key for which the primitive value shall be set. 2216 | * 2217 | * @param uuid 2218 | * The uuid_t value to insert. After calling this method, the XPC 2219 | * object corresponding to the primitive value inserted may be safely retrieved 2220 | * with {@link xpc_dictionary_get_value()}. 2221 | */ 2222 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2223 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 XPC_NONNULL3 2224 | void 2225 | xpc_dictionary_set_uuid(xpc_object_t xdict, const char *key, 2226 | const uuid_t XPC_NONNULL_ARRAY uuid); 2227 | 2228 | /*! 2229 | * @function xpc_dictionary_set_fd 2230 | * 2231 | * @abstract 2232 | * Inserts a file descriptor into a dictionary. 2233 | * 2234 | * @param xdict 2235 | * The dictionary which is to be manipulated. 2236 | * 2237 | * @param key 2238 | * The key for which the primitive value shall be set. 2239 | * 2240 | * @param fd 2241 | * The file descriptor to insert. After calling this method, the XPC object 2242 | * corresponding to the primitive value inserted may be safely retrieved 2243 | * with {@link xpc_dictionary_get_value()}. 2244 | */ 2245 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2246 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 2247 | void 2248 | xpc_dictionary_set_fd(xpc_object_t xdict, const char *key, int fd); 2249 | 2250 | /*! 2251 | * @function xpc_dictionary_set_connection 2252 | * 2253 | * @abstract 2254 | * Inserts a connection into a dictionary. 2255 | * 2256 | * @param xdict 2257 | * The dictionary which is to be manipulated. 2258 | * 2259 | * @param key 2260 | * The key for which the primitive value shall be set. 2261 | * 2262 | * @param connection 2263 | * The connection to insert. After calling this method, the XPC object 2264 | * corresponding to the primitive value inserted may be safely retrieved 2265 | * with {@link xpc_dictionary_get_value()}. The connection is NOT retained by 2266 | * the dictionary. 2267 | */ 2268 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2269 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 XPC_NONNULL3 2270 | void 2271 | xpc_dictionary_set_connection(xpc_object_t xdict, const char *key, 2272 | xpc_connection_t connection); 2273 | 2274 | #pragma mark Dictionary Primitive Getters 2275 | /*! 2276 | * @function xpc_dictionary_get_bool 2277 | * 2278 | * @abstract 2279 | * Gets a bool primitive value from a dictionary directly. 2280 | * 2281 | * @param xdict 2282 | * The dictionary object which is to be examined. 2283 | * 2284 | * @param key 2285 | * The key whose value is to be obtained. 2286 | * 2287 | * @result 2288 | * The underlying bool value for the specified key. false if the 2289 | * the value for the specified key is not a Boolean value or if there is no 2290 | * value for the specified key. 2291 | */ 2292 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2293 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL 2294 | bool 2295 | xpc_dictionary_get_bool(xpc_object_t xdict, const char *key); 2296 | 2297 | /*! 2298 | * @function xpc_dictionary_get_int64 2299 | * 2300 | * @abstract 2301 | * Gets an int64 primitive value from a dictionary directly. 2302 | * 2303 | * @param xdict 2304 | * The dictionary object which is to be examined. 2305 | * 2306 | * @param key 2307 | * The key whose value is to be obtained. 2308 | * 2309 | * @result 2310 | * The underlying int64_t value for the specified key. 0 if the 2311 | * value for the specified key is not a signed integer value or if there is no 2312 | * value for the specified key. 2313 | */ 2314 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2315 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL 2316 | int64_t 2317 | xpc_dictionary_get_int64(xpc_object_t xdict, const char *key); 2318 | 2319 | /*! 2320 | * @function xpc_dictionary_get_uint64 2321 | * 2322 | * @abstract 2323 | * Gets a uint64 primitive value from a dictionary directly. 2324 | * 2325 | * @param xdict 2326 | * The dictionary object which is to be examined. 2327 | * 2328 | * @param key 2329 | * The key whose value is to be obtained. 2330 | * 2331 | * @result 2332 | * The underlying uint64_t value for the specified key. 0 if the 2333 | * value for the specified key is not an unsigned integer value or if there is 2334 | * no value for the specified key. 2335 | */ 2336 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2337 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL 2338 | uint64_t 2339 | xpc_dictionary_get_uint64(xpc_object_t xdict, const char *key); 2340 | 2341 | /*! 2342 | * @function xpc_dictionary_get_double 2343 | * 2344 | * @abstract 2345 | * Gets a double primitive value from a dictionary directly. 2346 | * 2347 | * @param xdict 2348 | * The dictionary object which is to be examined. 2349 | * 2350 | * @param key 2351 | * The key whose value is to be obtained. 2352 | * 2353 | * @result 2354 | * The underlying double value for the specified key. NAN if the 2355 | * value for the specified key is not a floating point value or if there is no 2356 | * value for the specified key. 2357 | */ 2358 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2359 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL 2360 | double 2361 | xpc_dictionary_get_double(xpc_object_t xdict, const char *key); 2362 | 2363 | /*! 2364 | * @function xpc_dictionary_get_date 2365 | * 2366 | * @abstract 2367 | * Gets a date value from a dictionary directly. 2368 | * 2369 | * @param xdict 2370 | * The dictionary object which is to be examined. 2371 | * 2372 | * @param key 2373 | * The key whose value is to be obtained. 2374 | * 2375 | * @result 2376 | * The underlying date interval for the specified key. 0 if the value for the 2377 | * specified key is not a date value or if there is no value for the specified 2378 | * key. 2379 | */ 2380 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2381 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL 2382 | int64_t 2383 | xpc_dictionary_get_date(xpc_object_t xdict, const char *key); 2384 | 2385 | /*! 2386 | * @function xpc_dictionary_get_data 2387 | * 2388 | * @abstract 2389 | * Gets a raw data value from a dictionary directly. 2390 | * 2391 | * @param xdict 2392 | * The dictionary object which is to be examined. 2393 | * 2394 | * @param key 2395 | * The key whose value is to be obtained. 2396 | * 2397 | * @param length 2398 | * For the data type, the third parameter, upon output, will contain the length 2399 | * of the data corresponding to the specified key. May be NULL. 2400 | * 2401 | * @result 2402 | * The underlying raw data for the specified key. NULL if the value for the 2403 | * specified key is not a data value or if there is no value for the specified 2404 | * key. 2405 | */ 2406 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2407 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 2408 | const void * _Nullable 2409 | xpc_dictionary_get_data(xpc_object_t xdict, const char *key, 2410 | size_t * _Nullable length); 2411 | 2412 | /*! 2413 | * @function xpc_dictionary_get_string 2414 | * 2415 | * @abstract 2416 | * Gets a C string value from a dictionary directly. 2417 | * 2418 | * @param xdict 2419 | * The dictionary object which is to be examined. 2420 | * 2421 | * @param key 2422 | * The key whose value is to be obtained. 2423 | * 2424 | * @result 2425 | * The underlying C string for the specified key. NULL if the value for the 2426 | * specified key is not a C string value or if there is no value for the 2427 | * specified key. 2428 | */ 2429 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2430 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL 2431 | const char * _Nullable 2432 | xpc_dictionary_get_string(xpc_object_t xdict, const char *key); 2433 | 2434 | /*! 2435 | * @function xpc_dictionary_get_uuid 2436 | * 2437 | * @abstract 2438 | * Gets a uuid value from a dictionary directly. 2439 | * 2440 | * @param xdict 2441 | * The dictionary object which is to be examined. 2442 | * 2443 | * @param key 2444 | * The key whose value is to be obtained. 2445 | * 2446 | * @result 2447 | * The underlying uuid_t value for the specified key. NULL is the 2448 | * value at the specified index is not a UUID value. The returned pointer may be 2449 | * safely passed to the uuid(3) APIs. 2450 | */ 2451 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2452 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1 XPC_NONNULL2 2453 | const uint8_t * _Nullable 2454 | xpc_dictionary_get_uuid(xpc_object_t xdict, const char *key); 2455 | 2456 | /*! 2457 | * @function xpc_dictionary_dup_fd 2458 | * 2459 | * @abstract 2460 | * Creates a file descriptor from a dictionary directly. 2461 | * 2462 | * @param xdict 2463 | * The dictionary object which is to be examined. 2464 | * 2465 | * @param key 2466 | * The key whose value is to be obtained. 2467 | * 2468 | * @result 2469 | * A new file descriptor created from the value for the specified key. You are 2470 | * responsible for close(2)ing this descriptor. -1 if the value for the 2471 | * specified key is not a file descriptor value or if there is no value for the 2472 | * specified key. 2473 | */ 2474 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2475 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL 2476 | int 2477 | xpc_dictionary_dup_fd(xpc_object_t xdict, const char *key); 2478 | 2479 | /*! 2480 | * @function xpc_dictionary_create_connection 2481 | * 2482 | * @abstract 2483 | * Creates a connection from a dictionary directly. 2484 | * 2485 | * @param xdict 2486 | * The dictionary object which is to be examined. 2487 | * 2488 | * @param key 2489 | * The key whose value is to be obtained. 2490 | * 2491 | * @result 2492 | * A new connection created from the value for the specified key. You are 2493 | * responsible for calling xpc_release() on the returned connection. NULL if the 2494 | * value for the specified key is not an endpoint containing a connection or if 2495 | * there is no value for the specified key. Each call to this method for the 2496 | * same key in the same dictionary will yield a different connection. See 2497 | * {@link xpc_connection_create_from_endpoint()} for discussion as to the 2498 | * responsibilities when dealing with the returned connection. 2499 | */ 2500 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2501 | XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL_ALL 2502 | xpc_connection_t _Nullable 2503 | xpc_dictionary_create_connection(xpc_object_t xdict, const char *key); 2504 | 2505 | /*! 2506 | * @function xpc_dictionary_get_dictionary 2507 | * 2508 | * @abstract 2509 | * Returns the dictionary value for the specified key. 2510 | * 2511 | * @param xdict 2512 | * The dictionary object which is to be examined. 2513 | * 2514 | * @param key 2515 | * The key whose value is to be obtained. 2516 | * 2517 | * @result 2518 | * The object for the specified key within the dictionary. NULL if there is no 2519 | * value associated with the specified key, if the given object was not an 2520 | * XPC dictionary, or if the object for the specified key is not a dictionary. 2521 | * 2522 | * @discussion 2523 | * This method does not grant the caller a reference to the underlying object, 2524 | * and thus the caller is not responsible for releasing the object. 2525 | */ 2526 | __OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0) 2527 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL 2528 | xpc_object_t _Nullable 2529 | xpc_dictionary_get_dictionary(xpc_object_t xdict, const char *key); 2530 | 2531 | /*! 2532 | * @function xpc_dictionary_get_array 2533 | * 2534 | * @abstract 2535 | * Returns the array value for the specified key. 2536 | * 2537 | * @param xdict 2538 | * The dictionary object which is to be examined. 2539 | * 2540 | * @param key 2541 | * The key whose value is to be obtained. 2542 | * 2543 | * @result 2544 | * The object for the specified key within the dictionary. NULL if there is no 2545 | * value associated with the specified key, if the given object was not an 2546 | * XPC dictionary, or if the object for the specified key is not an array. 2547 | * 2548 | * @discussion 2549 | * This method does not grant the caller a reference to the underlying object, 2550 | * and thus the caller is not responsible for releasing the object. 2551 | */ 2552 | __OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0) 2553 | XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL 2554 | xpc_object_t _Nullable 2555 | xpc_dictionary_get_array(xpc_object_t xdict, const char *key); 2556 | 2557 | #pragma mark Runtime 2558 | /*! 2559 | * @function xpc_main 2560 | * The springboard into the XPCService runtime. This function will set up your 2561 | * service bundle's listener connection and manage it automatically. After this 2562 | * initial setup, this function will, by default, call dispatch_main(). You may 2563 | * override this behavior by setting the RunLoopType key in your XPC service 2564 | * bundle's Info.plist under the XPCService dictionary. 2565 | * 2566 | * @param handler 2567 | * The handler with which to accept new connections. 2568 | */ 2569 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2570 | XPC_EXPORT XPC_NORETURN XPC_NONNULL1 2571 | void 2572 | xpc_main(xpc_connection_handler_t handler); 2573 | 2574 | #pragma mark Transactions 2575 | /*! 2576 | * @function xpc_transaction_begin 2577 | * Informs the XPC runtime that a transaction has begun and that the service 2578 | * should not exit due to inactivity. 2579 | * 2580 | * @discussion 2581 | * A service with no outstanding transactions may automatically exit due to 2582 | * inactivity as determined by the system. 2583 | * 2584 | * This function may be used to manually manage transactions in cases where 2585 | * their automatic management (as described below) does not meet the needs of an 2586 | * XPC service. This function also updates the transaction count used for sudden 2587 | * termination, i.e. vproc_transaction_begin(), and these two interfaces may be 2588 | * used in combination. 2589 | * 2590 | * The XPC runtime will automatically begin a transaction on behalf of a service 2591 | * when a new message is received. If no reply message is expected, the 2592 | * transaction is automatically ended when the connection event handler returns. 2593 | * If a reply message is created, the transaction will end when the reply 2594 | * message is sent or released. An XPC service may use xpc_transaction_begin() 2595 | * and xpc_transaction_end() to inform the XPC runtime about activity that 2596 | * occurs outside of this common pattern. 2597 | * 2598 | * On macOS, when the XPC runtime has determined that the service should exit, 2599 | * the event handlers for all active peer connections will receive 2600 | * {@link XPC_ERROR_TERMINATION_IMMINENT} as an indication that they should 2601 | * unwind their existing transactions. After this error is delivered to a 2602 | * connection's event handler, no more messages will be delivered to the 2603 | * connection. 2604 | */ 2605 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2606 | XPC_TRANSACTION_DEPRECATED 2607 | XPC_EXPORT 2608 | void 2609 | xpc_transaction_begin(void); 2610 | 2611 | /*! 2612 | * @function xpc_transaction_end 2613 | * Informs the XPC runtime that a transaction has ended. 2614 | * 2615 | * @discussion 2616 | * As described in {@link xpc_transaction_begin()}, this API may be used 2617 | * interchangeably with vproc_transaction_end(). 2618 | * 2619 | * See the discussion for {@link xpc_transaction_begin()} for details regarding 2620 | * the XPC runtime's idle-exit policy. 2621 | */ 2622 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2623 | XPC_TRANSACTION_DEPRECATED 2624 | XPC_EXPORT 2625 | void 2626 | xpc_transaction_end(void); 2627 | 2628 | #pragma mark XPC Event Stream 2629 | /*! 2630 | * @function xpc_set_event_stream_handler 2631 | * Sets the event handler to invoke when streamed events are received. 2632 | * 2633 | * @param stream 2634 | * The name of the event stream for which this handler will be invoked. 2635 | * 2636 | * @param targetq 2637 | * The GCD queue to which the event handler block will be submitted. This 2638 | * parameter may be NULL, in which case the connection's target queue will be 2639 | * libdispatch's default target queue, defined as DISPATCH_TARGET_QUEUE_DEFAULT. 2640 | * 2641 | * @param handler 2642 | * The event handler block. The event which this block receives as its first 2643 | * parameter will always be a dictionary which contains the XPC_EVENT_KEY_NAME 2644 | * key. The value for this key will be a string whose value is the name assigned 2645 | * to the XPC event specified in the launchd.plist. Future keys may be added to 2646 | * this dictionary. 2647 | * 2648 | * @discussion 2649 | * Multiple calls to this function for the same event stream will result in 2650 | * undefined behavior. 2651 | */ 2652 | #if __BLOCKS__ 2653 | __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0) 2654 | XPC_EXPORT XPC_NONNULL1 XPC_NONNULL3 2655 | void 2656 | xpc_set_event_stream_handler(const char *stream, 2657 | dispatch_queue_t _Nullable targetq, xpc_handler_t handler); 2658 | #endif // __BLOCKS__ 2659 | 2660 | __END_DECLS 2661 | XPC_ASSUME_NONNULL_END 2662 | 2663 | #endif // __XPC_H__ 2664 | --------------------------------------------------------------------------------