├── IOKitKeys.h ├── IOKitLib.c ├── IOKitLib.h ├── IOReturn.h ├── IOTypes.h ├── OSMessageNotification.h ├── Readme.md └── screenshot.jpg /IOKitKeys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_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. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 30 | * 31 | * Common symbol definitions for IOKit. 32 | * 33 | * HISTORY 34 | * 35 | */ 36 | 37 | 38 | #ifndef _IOKIT_IOKITKEYS_H 39 | #define _IOKIT_IOKITKEYS_H 40 | 41 | // properties found in the registry root 42 | #define kIOKitBuildVersionKey "IOKitBuildVersion" 43 | #define kIOKitDiagnosticsKey "IOKitDiagnostics" 44 | // a dictionary keyed by plane name 45 | #define kIORegistryPlanesKey "IORegistryPlanes" 46 | #define kIOCatalogueKey "IOCatalogue" 47 | 48 | // registry plane names 49 | #define kIOServicePlane "IOService" 50 | #define kIOPowerPlane "IOPower" 51 | #define kIODeviceTreePlane "IODeviceTree" 52 | #define kIOAudioPlane "IOAudio" 53 | #define kIOFireWirePlane "IOFireWire" 54 | #define kIOUSBPlane "IOUSB" 55 | 56 | // registry ID number 57 | #define kIORegistryEntryIDKey "IORegistryEntryID" 58 | 59 | // IOService class name 60 | #define kIOServiceClass "IOService" 61 | 62 | // IOResources class name 63 | #define kIOResourcesClass "IOResources" 64 | 65 | // IOService driver probing property names 66 | #define kIOClassKey "IOClass" 67 | #define kIOProbeScoreKey "IOProbeScore" 68 | #define kIOKitDebugKey "IOKitDebug" 69 | 70 | // IOService matching property names 71 | #define kIOProviderClassKey "IOProviderClass" 72 | #define kIONameMatchKey "IONameMatch" 73 | #define kIOPropertyMatchKey "IOPropertyMatch" 74 | #define kIOPathMatchKey "IOPathMatch" 75 | #define kIOLocationMatchKey "IOLocationMatch" 76 | #define kIOParentMatchKey "IOParentMatch" 77 | #define kIOResourceMatchKey "IOResourceMatch" 78 | #define kIOMatchedServiceCountKey "IOMatchedServiceCountMatch" 79 | 80 | #define kIONameMatchedKey "IONameMatched" 81 | 82 | #define kIOMatchCategoryKey "IOMatchCategory" 83 | #define kIODefaultMatchCategoryKey "IODefaultMatchCategory" 84 | 85 | // IOService default user client class, for loadable user clients 86 | #define kIOUserClientClassKey "IOUserClientClass" 87 | 88 | // key to find IOMappers 89 | #define kIOMapperIDKey "IOMapperID" 90 | 91 | #define kIOUserClientCrossEndianKey "IOUserClientCrossEndian" 92 | #define kIOUserClientCrossEndianCompatibleKey "IOUserClientCrossEndianCompatible" 93 | #define kIOUserClientSharedInstanceKey "IOUserClientSharedInstance" 94 | // diagnostic string describing the creating task 95 | #define kIOUserClientCreatorKey "IOUserClientCreator" 96 | 97 | // IOService notification types 98 | #define kIOPublishNotification "IOServicePublish" 99 | #define kIOFirstPublishNotification "IOServiceFirstPublish" 100 | #define kIOMatchedNotification "IOServiceMatched" 101 | #define kIOFirstMatchNotification "IOServiceFirstMatch" 102 | #define kIOTerminatedNotification "IOServiceTerminate" 103 | 104 | // IOService interest notification types 105 | #define kIOGeneralInterest "IOGeneralInterest" 106 | #define kIOBusyInterest "IOBusyInterest" 107 | #define kIOAppPowerStateInterest "IOAppPowerStateInterest" 108 | #define kIOPriorityPowerStateInterest "IOPriorityPowerStateInterest" 109 | 110 | #define kIOPlatformDeviceMessageKey "IOPlatformDeviceMessage" 111 | 112 | // IOService interest notification types 113 | #define kIOCFPlugInTypesKey "IOCFPlugInTypes" 114 | 115 | // properties found in services that implement command pooling 116 | #define kIOCommandPoolSizeKey "IOCommandPoolSize" // (OSNumber) 117 | 118 | // properties found in services that have transfer constraints 119 | #define kIOMaximumBlockCountReadKey "IOMaximumBlockCountRead" // (OSNumber) 120 | #define kIOMaximumBlockCountWriteKey "IOMaximumBlockCountWrite" // (OSNumber) 121 | #define kIOMaximumByteCountReadKey "IOMaximumByteCountRead" // (OSNumber) 122 | #define kIOMaximumByteCountWriteKey "IOMaximumByteCountWrite" // (OSNumber) 123 | #define kIOMaximumSegmentCountReadKey "IOMaximumSegmentCountRead" // (OSNumber) 124 | #define kIOMaximumSegmentCountWriteKey "IOMaximumSegmentCountWrite" // (OSNumber) 125 | #define kIOMaximumSegmentByteCountReadKey "IOMaximumSegmentByteCountRead" // (OSNumber) 126 | #define kIOMaximumSegmentByteCountWriteKey "IOMaximumSegmentByteCountWrite" // (OSNumber) 127 | #define kIOMinimumSegmentAlignmentByteCountKey "IOMinimumSegmentAlignmentByteCount" // (OSNumber) 128 | #define kIOMaximumSegmentAddressableBitCountKey "IOMaximumSegmentAddressableBitCount" // (OSNumber) 129 | 130 | // properties found in services that wish to describe an icon 131 | // 132 | // IOIcon = 133 | // { 134 | // CFBundleIdentifier = "com.example.driver.example"; 135 | // IOBundleResourceFile = "example.icns"; 136 | // }; 137 | // 138 | // where IOBundleResourceFile is the filename of the resource 139 | 140 | #define kIOIconKey "IOIcon" // (OSDictionary) 141 | #define kIOBundleResourceFileKey "IOBundleResourceFile" // (OSString) 142 | 143 | #define kIOBusBadgeKey "IOBusBadge" // (OSDictionary) 144 | #define kIODeviceIconKey "IODeviceIcon" // (OSDictionary) 145 | 146 | // property of root that describes the machine's serial number as a string 147 | #define kIOPlatformSerialNumberKey "IOPlatformSerialNumber" // (OSString) 148 | 149 | // property of root that describes the machine's UUID as a string 150 | #define kIOPlatformUUIDKey "IOPlatformUUID" // (OSString) 151 | 152 | // IODTNVRAM property keys 153 | #define kIONVRAMDeletePropertyKey "IONVRAM-DELETE-PROPERTY" 154 | #define kIODTNVRAMPanicInfoKey "aapl,panic-info" 155 | 156 | // keys for complex boot information 157 | #define kIOBootDeviceKey "IOBootDevice" // dict | array of dicts 158 | #define kIOBootDevicePathKey "IOBootDevicePath" // arch-neutral OSString 159 | #define kIOBootDeviceSizeKey "IOBootDeviceSize" // OSNumber of bytes 160 | 161 | // keys for OS Version information 162 | #define kOSBuildVersionKey "OS Build Version" 163 | 164 | #endif /* ! _IOKIT_IOKITKEYS_H */ 165 | -------------------------------------------------------------------------------- /IOKitLib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * The contents of this file constitute Original Code as defined in and 7 | * are subject to the Apple Public Source License Version 1.1 (the 8 | * "License"). You may not use this file except in compliance with the 9 | * License. Please obtain a copy of the License at 10 | * http://www.apple.com/publicsource and read it before using this file. 11 | * 12 | * This Original Code and all software distributed under the License are 13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the 17 | * License for the specific language governing rights and limitations 18 | * under the License. 19 | * 20 | * @APPLE_LICENSE_HEADER_END@ 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | 43 | #include 44 | 45 | #if __LP64__ 46 | static const int kIsLP64 = 1; 47 | typedef struct OSNotificationHeader64 NotificationHeader; 48 | 49 | // XXX gvdl: Need to conditionalise this for LP64 50 | #define mig_external __private_extern__ 51 | #include 52 | #undef mig_external 53 | 54 | #else 55 | 56 | // To stage the IOKitUser map the 64 bit aware APIs locally 57 | # if EMULATE_IOCONNECT 58 | # define EMULATE_IOCONNECT_64 1 59 | # define EMULATE_IOCONNECT_ASYNC_64 1 60 | # endif 61 | 62 | # if EMULATE_IOCONNECT_64 63 | # define io_connect_method em_connect_method 64 | # endif 65 | 66 | # if EMULATE_IOCONNECT_ASYNC_64 67 | # define io_connect_async_method em_connect_async_method 68 | # endif 69 | 70 | typedef struct OSNotificationHeader NotificationHeader; 71 | static const int kIsLP64 = 0; 72 | #include 73 | 74 | #endif 75 | 76 | 77 | /* 78 | * Ports 79 | */ 80 | 81 | extern mach_port_t mach_task_self(); 82 | const mach_port_t kIOMasterPortDefault = MACH_PORT_NULL; 83 | 84 | static mach_port_t 85 | __IOGetDefaultMasterPort() 86 | { 87 | mach_port_t masterPort; 88 | 89 | kern_return_t result = IOMasterPort(MACH_PORT_NULL, &masterPort); 90 | if( KERN_SUCCESS != result) 91 | masterPort = MACH_PORT_NULL; 92 | 93 | return( masterPort ); 94 | } 95 | 96 | kern_return_t 97 | IOMasterPort( mach_port_t bootstrapPort __unused, 98 | mach_port_t * masterPort ) 99 | { 100 | kern_return_t result = KERN_SUCCESS; 101 | mach_port_t host_port = 0; 102 | 103 | host_port = mach_host_self(); 104 | result = host_get_io_master(host_port, masterPort); 105 | 106 | /* Dispose of the host port to prevent security breaches and port 107 | * leaks. We don't care about the kern_return_t value of this 108 | * call for now as there's nothing we can do if it fails. 109 | */ 110 | if (host_port) mach_port_deallocate(mach_task_self(), host_port); 111 | return result; 112 | } 113 | 114 | kern_return_t 115 | IOCreateReceivePort( uint32_t msgType, mach_port_t * recvPort ) 116 | { 117 | kern_return_t res; 118 | switch (msgType) { 119 | case kOSNotificationMessageID: 120 | case kOSAsyncCompleteMessageID: 121 | res = mach_port_allocate(mach_task_self(), 122 | MACH_PORT_RIGHT_RECEIVE, recvPort); 123 | 124 | break; 125 | 126 | default: 127 | res = kIOReturnBadArgument; 128 | } 129 | return res; 130 | } 131 | 132 | /* 133 | * IOObject 134 | */ 135 | 136 | kern_return_t 137 | IOObjectRelease( 138 | io_object_t object ) 139 | { 140 | return( mach_port_deallocate( mach_task_self(), object )); 141 | } 142 | 143 | kern_return_t 144 | IOObjectRetain( 145 | io_object_t object ) 146 | { 147 | return( mach_port_mod_refs(mach_task_self(), 148 | object, 149 | MACH_PORT_RIGHT_SEND, 150 | 1 )); 151 | } 152 | 153 | kern_return_t 154 | IOObjectGetClass( 155 | io_object_t object, 156 | io_name_t className ) 157 | { 158 | return( io_object_get_class( object, className )); 159 | } 160 | 161 | 162 | CFStringRef 163 | IOObjectCopyClass(io_object_t object) 164 | { 165 | io_name_t my_name; 166 | CFStringRef my_str = NULL; 167 | 168 | // if there's no argument, no point going on. Return NULL. 169 | if (!object) 170 | return my_str; 171 | 172 | io_object_get_class( object, my_name ); 173 | my_str = CFStringCreateWithCString (kCFAllocatorDefault, my_name, kCFStringEncodingUTF8); 174 | 175 | return my_str; 176 | } 177 | 178 | CFStringRef 179 | IOObjectCopySuperclassForClass(CFStringRef classname) 180 | { 181 | io_name_t my_name, orig_name; 182 | CFStringRef my_str = NULL; 183 | char * my_cstr; 184 | kern_return_t kr; 185 | 186 | mach_port_t masterPort = __IOGetDefaultMasterPort(); 187 | 188 | // if there's no argument, no point going on. Return NULL. 189 | if (classname == NULL) { 190 | return my_str; 191 | } 192 | 193 | my_cstr = malloc(sizeof(char) * 128); 194 | CFStringGetCString (classname, my_cstr, 128, kCFStringEncodingUTF8); 195 | 196 | strncpy(orig_name, my_cstr, sizeof(io_name_t)); 197 | 198 | kr = io_object_get_superclass(masterPort, orig_name, my_name); 199 | if (kr == kIOReturnSuccess) { 200 | my_str = CFStringCreateWithCString (kCFAllocatorDefault, my_name, kCFStringEncodingUTF8); 201 | } 202 | free(my_cstr); 203 | 204 | return my_str; 205 | } 206 | 207 | CFStringRef 208 | IOObjectCopyBundleIdentifierForClass(CFStringRef classname) 209 | { 210 | io_name_t my_name, orig_name; 211 | CFStringRef my_str = NULL; 212 | char * my_cstr; 213 | kern_return_t kr; 214 | 215 | mach_port_t masterPort = __IOGetDefaultMasterPort(); 216 | 217 | // if there's no argument, no point going on. Return NULL. 218 | if (classname == NULL) { 219 | return my_str; 220 | } 221 | 222 | my_cstr = malloc(sizeof(char) * 128); 223 | CFStringGetCString (classname, my_cstr, 128, kCFStringEncodingUTF8); 224 | 225 | strncpy(orig_name, my_cstr, sizeof(io_name_t)); 226 | 227 | kr = io_object_get_bundle_identifier(masterPort, orig_name, my_name); 228 | if (kr == kIOReturnSuccess) { 229 | my_str = CFStringCreateWithCString (kCFAllocatorDefault, my_name, kCFStringEncodingUTF8); 230 | } 231 | free(my_cstr); 232 | 233 | return my_str; 234 | } 235 | 236 | boolean_t 237 | IOObjectConformsTo( 238 | io_object_t object, 239 | const io_name_t className ) 240 | { 241 | boolean_t conforms; 242 | 243 | if( kIOReturnSuccess != io_object_conforms_to( 244 | object, (char *) className, &conforms )) 245 | conforms = 0; 246 | 247 | return( conforms ); 248 | } 249 | 250 | boolean_t 251 | IOObjectIsEqualTo( 252 | io_object_t object, 253 | io_object_t anObject ) 254 | { 255 | return( object == anObject ); 256 | } 257 | 258 | uint32_t 259 | IOObjectGetRetainCount( 260 | io_object_t object ) 261 | { 262 | uint32_t count; 263 | 264 | if( kIOReturnSuccess != io_object_get_retain_count( object, &count)) 265 | count = 0; 266 | 267 | return( count ); 268 | } 269 | 270 | 271 | /* 272 | * IOIterator 273 | */ 274 | 275 | io_object_t 276 | IOIteratorNext( 277 | io_iterator_t iterator ) 278 | { 279 | io_object_t next; 280 | 281 | if( kIOReturnSuccess != io_iterator_next( iterator, &next)) 282 | next = 0; 283 | 284 | return( next ); 285 | } 286 | 287 | void 288 | IOIteratorReset( 289 | io_iterator_t iterator ) 290 | { 291 | io_iterator_reset( iterator ); 292 | } 293 | 294 | boolean_t 295 | IOIteratorIsValid( 296 | io_iterator_t iterator ) 297 | { 298 | boolean_t valid; 299 | 300 | if( kIOReturnSuccess != io_iterator_is_valid( iterator, &valid )) 301 | valid = FALSE; 302 | 303 | return( valid ); 304 | } 305 | 306 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 307 | 308 | /* 309 | * IOService 310 | */ 311 | 312 | io_service_t 313 | IOServiceGetMatchingService( 314 | mach_port_t masterPort, 315 | CFDictionaryRef matching ) 316 | { 317 | io_iterator_t iter = MACH_PORT_NULL; 318 | io_service_t service = MACH_PORT_NULL; 319 | 320 | IOServiceGetMatchingServices( masterPort, matching, &iter ); 321 | 322 | if( iter) { 323 | 324 | service = IOIteratorNext( iter ); 325 | IOObjectRelease( iter ); 326 | } 327 | 328 | return( service ); 329 | } 330 | 331 | kern_return_t 332 | IOServiceGetMatchingServices( 333 | mach_port_t masterPort, 334 | CFDictionaryRef matching, 335 | io_iterator_t * existing ) 336 | { 337 | kern_return_t kr; 338 | CFDataRef data; 339 | CFIndex dataLen; 340 | 341 | if (MACH_PORT_NULL == masterPort) 342 | masterPort = __IOGetDefaultMasterPort(); 343 | 344 | if( !matching) 345 | return( kIOReturnBadArgument); 346 | 347 | data = IOCFSerialize( matching, kNilOptions ); 348 | CFRelease( matching ); 349 | if( !data) 350 | return( kIOReturnUnsupported ); 351 | 352 | dataLen = CFDataGetLength(data); 353 | 354 | if ((size_t) dataLen < sizeof(io_string_t)) 355 | kr = io_service_get_matching_services( masterPort, 356 | (char *) CFDataGetBytePtr(data), existing ); 357 | else { 358 | kern_return_t result; 359 | 360 | kr = io_service_get_matching_services_ool( masterPort, 361 | (char *) CFDataGetBytePtr(data), dataLen, &result, existing ); 362 | if (KERN_SUCCESS == kr) 363 | kr = result; 364 | } 365 | 366 | CFRelease( data ); 367 | 368 | return( kr ); 369 | } 370 | 371 | kern_return_t 372 | IOServiceMatchPropertyTable( io_service_t service, CFDictionaryRef matching, 373 | boolean_t * matches ) 374 | { 375 | kern_return_t kr; 376 | CFDataRef data; 377 | CFIndex dataLen; 378 | 379 | if( !matching) 380 | return( kIOReturnBadArgument); 381 | 382 | data = IOCFSerialize( matching, kNilOptions ); 383 | if( !data) 384 | return( kIOReturnUnsupported ); 385 | 386 | 387 | dataLen = CFDataGetLength(data); 388 | 389 | if ((size_t) dataLen < sizeof(io_string_t)) 390 | kr = io_service_match_property_table( service, 391 | (char *) CFDataGetBytePtr(data), matches ); 392 | else { 393 | kern_return_t result; 394 | 395 | kr = io_service_match_property_table_ool( service, 396 | (char *) CFDataGetBytePtr(data), dataLen, &result, matches ); 397 | if (KERN_SUCCESS == kr) 398 | kr = result; 399 | } 400 | 401 | CFRelease( data ); 402 | 403 | return( kr ); 404 | } 405 | 406 | kern_return_t 407 | IOServiceAddNotification( 408 | mach_port_t masterPort, 409 | const io_name_t notificationType, 410 | CFDictionaryRef matching, 411 | mach_port_t wakePort, 412 | uintptr_t reference, 413 | io_iterator_t *notification ) 414 | { 415 | kern_return_t kr; 416 | CFDataRef data; 417 | CFIndex dataLen; 418 | 419 | if (MACH_PORT_NULL == masterPort) 420 | masterPort = __IOGetDefaultMasterPort(); 421 | 422 | if( !matching) 423 | return( kIOReturnBadArgument); 424 | 425 | data = IOCFSerialize( matching, kNilOptions ); 426 | CFRelease( matching ); 427 | if( !data) 428 | return( kIOReturnUnsupported ); 429 | 430 | dataLen = CFDataGetLength(data); 431 | 432 | if ((size_t) dataLen < sizeof(io_string_t)) 433 | kr = io_service_add_notification( masterPort, (char *) notificationType, 434 | (char *) CFDataGetBytePtr(data), 435 | wakePort, (io_user_reference_t *) &reference, 1, 436 | notification ); 437 | else { 438 | kern_return_t result; 439 | 440 | kr = io_service_add_notification_ool( masterPort, (char *) notificationType, 441 | (char *) CFDataGetBytePtr(data), dataLen, 442 | wakePort, (io_user_reference_t *) &reference, 1, 443 | &result, notification ); 444 | if (KERN_SUCCESS == kr) 445 | kr = result; 446 | } 447 | 448 | CFRelease( data ); 449 | 450 | return( kr ); 451 | } 452 | 453 | kern_return_t 454 | IOServiceAddMatchingNotification( 455 | IONotificationPortRef notifyPort, 456 | const io_name_t notificationType, 457 | CFDictionaryRef matching, 458 | IOServiceMatchingCallback callback, 459 | void * refcon, 460 | io_iterator_t * notification ) 461 | { 462 | kern_return_t kr; 463 | CFDataRef data; 464 | CFIndex dataLen; 465 | io_user_reference_t asyncRef[kIOMatchingCalloutCount]; 466 | 467 | if( !matching) 468 | return( kIOReturnBadArgument); 469 | 470 | data = IOCFSerialize( matching, kNilOptions ); 471 | CFRelease( matching ); 472 | if( !data) 473 | return( kIOReturnUnsupported ); 474 | 475 | asyncRef[kIOMatchingCalloutFuncIndex] = (io_user_reference_t) callback; 476 | asyncRef[kIOMatchingCalloutRefconIndex] = (io_user_reference_t) refcon; 477 | 478 | dataLen = CFDataGetLength(data); 479 | 480 | if ((size_t) dataLen < sizeof(io_string_t)) 481 | kr = io_service_add_notification( notifyPort->masterPort, 482 | (char *) notificationType, 483 | (char *) CFDataGetBytePtr(data), 484 | notifyPort->wakePort, 485 | asyncRef, kIOMatchingCalloutCount, notification ); 486 | else { 487 | kern_return_t result; 488 | 489 | kr = io_service_add_notification_ool( notifyPort->masterPort, 490 | (char *) notificationType, 491 | (char *) CFDataGetBytePtr(data), dataLen, 492 | notifyPort->wakePort, 493 | asyncRef, kIOMatchingCalloutCount, &result, notification ); 494 | if (KERN_SUCCESS == kr) 495 | kr = result; 496 | } 497 | 498 | CFRelease( data ); 499 | 500 | return( kr ); 501 | } 502 | 503 | kern_return_t 504 | IOServiceAddInterestNotification( 505 | IONotificationPortRef notifyPort, 506 | io_service_t service, 507 | const io_name_t interestType, 508 | IOServiceInterestCallback callback, 509 | void * refcon, 510 | io_object_t * notification ) 511 | { 512 | io_user_reference_t asyncRef[kIOInterestCalloutCount]; 513 | kern_return_t kr; 514 | 515 | asyncRef[kIOInterestCalloutFuncIndex] = (io_user_reference_t) callback; 516 | asyncRef[kIOInterestCalloutRefconIndex] = (io_user_reference_t) refcon; 517 | asyncRef[kIOInterestCalloutServiceIndex] = (io_user_reference_t) service; 518 | 519 | kr = io_service_add_interest_notification( service, (char *) interestType, 520 | notifyPort->wakePort, 521 | asyncRef, kIOInterestCalloutCount, 522 | notification ); 523 | 524 | return( kr ); 525 | } 526 | 527 | IONotificationPortRef 528 | IONotificationPortCreate( 529 | mach_port_t masterPort ) 530 | { 531 | kern_return_t kr; 532 | IONotificationPort * notify; 533 | 534 | if (MACH_PORT_NULL == masterPort) 535 | masterPort = __IOGetDefaultMasterPort(); 536 | 537 | notify = calloc( 1, sizeof( IONotificationPort)); 538 | if( !notify) 539 | return( 0 ); 540 | 541 | notify->masterPort = masterPort; 542 | 543 | kr = IOCreateReceivePort(kOSNotificationMessageID, ¬ify->wakePort); 544 | if( kr != kIOReturnSuccess) { 545 | free( notify ); 546 | return( 0 ); 547 | } 548 | 549 | return notify; 550 | } 551 | 552 | void 553 | IONotificationPortDestroy( 554 | IONotificationPortRef notify ) 555 | { 556 | if( notify->source) 557 | CFRelease( notify->source); 558 | 559 | mach_port_destroy( mach_task_self(), notify->wakePort); 560 | 561 | free( notify ); 562 | } 563 | 564 | CFRunLoopSourceRef 565 | IONotificationPortGetRunLoopSource( 566 | IONotificationPortRef notify ) 567 | { 568 | CFMachPortRef cfPort; 569 | CFMachPortContext context; 570 | CFRunLoopSourceRef cfSource; 571 | Boolean shouldFreeInfo; 572 | 573 | if( notify->source) 574 | return( notify->source ); 575 | 576 | context.version = 1; 577 | context.info = (void *) notify; 578 | context.retain = NULL; 579 | context.release = NULL; 580 | context.copyDescription = NULL; 581 | 582 | cfPort = CFMachPortCreateWithPort(NULL, notify->wakePort, 583 | IODispatchCalloutFromCFMessage, &context, &shouldFreeInfo); 584 | if (!cfPort) 585 | return( 0 ); 586 | 587 | cfSource = CFMachPortCreateRunLoopSource(NULL, cfPort, 0); 588 | CFRelease(cfPort); 589 | notify->source = cfSource; 590 | return( cfSource ); 591 | } 592 | 593 | mach_port_t 594 | IONotificationPortGetMachPort( 595 | IONotificationPortRef notify ) 596 | { 597 | return( notify->wakePort ); 598 | } 599 | 600 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 601 | 602 | /* 603 | * Matching creation helpers 604 | */ 605 | 606 | CFMutableDictionaryRef 607 | IOMakeMatching( 608 | mach_port_t masterPort, 609 | uint32_t type, 610 | uint32_t options, 611 | void * args, 612 | uint32_t argsSize ) 613 | { 614 | IOReturn err; 615 | CFMutableDictionaryRef result = 0; 616 | char * matching; 617 | 618 | if (MACH_PORT_NULL == masterPort) 619 | masterPort = __IOGetDefaultMasterPort(); 620 | 621 | matching = (char *) malloc( sizeof( io_string_t)); 622 | 623 | if( matching) { 624 | err = io_make_matching( masterPort, type, options, 625 | (char *)args, argsSize, matching ); 626 | if( KERN_SUCCESS == err) { 627 | result = (CFMutableDictionaryRef) IOCFUnserialize( matching, 628 | kCFAllocatorDefault, kNilOptions, 0 ); 629 | } 630 | free( matching ); 631 | } 632 | 633 | return( result ); 634 | } 635 | 636 | static CFMutableDictionaryRef 637 | MakeOneStringProp( 638 | CFStringRef key, 639 | const char * name ) 640 | { 641 | CFMutableDictionaryRef dict; 642 | CFStringRef string; 643 | 644 | dict = CFDictionaryCreateMutable( kCFAllocatorDefault, 0, 645 | &kCFTypeDictionaryKeyCallBacks, 646 | &kCFTypeDictionaryValueCallBacks); 647 | 648 | if( !dict) 649 | return( dict); 650 | 651 | string = CFStringCreateWithCString( kCFAllocatorDefault, name, 652 | kCFStringEncodingMacRoman ); 653 | 654 | if( string) { 655 | CFDictionarySetValue( dict, key, string ); 656 | CFRelease( string ); 657 | } else { 658 | CFRelease( dict ); 659 | dict = 0; 660 | } 661 | 662 | return( dict ); 663 | } 664 | 665 | CFMutableDictionaryRef 666 | IOServiceMatching( 667 | const char * name ) 668 | { 669 | return( MakeOneStringProp( CFSTR(kIOProviderClassKey), name ) ); 670 | } 671 | 672 | CFMutableDictionaryRef 673 | IOServiceNameMatching( 674 | const char * name ) 675 | { 676 | return( MakeOneStringProp( CFSTR(kIONameMatchKey), name )); 677 | } 678 | 679 | CFMutableDictionaryRef 680 | IOBSDNameMatching( 681 | mach_port_t masterPort, 682 | uint32_t options, 683 | const char * name ) 684 | { 685 | if (name == NULL) { return 0; } 686 | else { 687 | return( IOMakeMatching( masterPort, kIOBSDNameMatching, options, 688 | (void *)name, strlen( name) + 1)); 689 | } 690 | } 691 | 692 | CFMutableDictionaryRef 693 | IOOpenFirmwarePathMatching( 694 | mach_port_t masterPort, 695 | uint32_t options, 696 | const char * path ) 697 | { 698 | return( IOMakeMatching( masterPort, kIOOFPathMatching, options, 699 | (void *)path, strlen( path) + 1)); 700 | } 701 | 702 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 703 | 704 | kern_return_t 705 | OSGetNotificationFromMessage( 706 | mach_msg_header_t *msg, 707 | uint32_t index, 708 | uint32_t *type, 709 | uintptr_t *reference, 710 | void **content, 711 | vm_size_t *size ) 712 | { 713 | // The kernel handles the downcast of the reference vector for 32bit tasks 714 | NotificationHeader * header; 715 | 716 | if( msg->msgh_id != kOSNotificationMessageID) 717 | return( kIOReturnBadMessageID ); 718 | 719 | if( msg->msgh_size < (sizeof( mach_msg_header_t) 720 | + sizeof( NotificationHeader))) 721 | return( kIOReturnNoResources ); 722 | 723 | if( index) 724 | return( kIOReturnNoResources ); 725 | 726 | header = (NotificationHeader *) (msg + 1); 727 | if( type) 728 | *type = header->type; 729 | if( reference) 730 | *reference = (uintptr_t) header->reference[0]; 731 | if( size) 732 | *size = header->size; 733 | if( content) { 734 | if( header->size) 735 | *content = &header->content[0]; 736 | else 737 | *content = 0; 738 | } 739 | 740 | return( kIOReturnSuccess ); 741 | } 742 | 743 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 744 | 745 | 746 | void 747 | IODispatchCalloutFromMessage(void *cfPort, mach_msg_header_t *msg, void *info) 748 | { 749 | return( IODispatchCalloutFromCFMessage( cfPort, msg, -1, info )); 750 | } 751 | 752 | void 753 | IODispatchCalloutFromCFMessage(CFMachPortRef port __unused, 754 | void *_msg, CFIndex size __unused, void *info __unused) 755 | { 756 | struct ComplexMsg { 757 | mach_msg_header_t msgHdr; 758 | mach_msg_body_t msgBody; 759 | mach_msg_port_descriptor_t ports[1]; 760 | } * complexMsg = NULL; 761 | mach_msg_header_t * msg = (mach_msg_header_t *)_msg; 762 | NotificationHeader * header; 763 | io_iterator_t notifier = MACH_PORT_NULL; 764 | io_service_t service = MACH_PORT_NULL; 765 | uint32_t leftOver; 766 | boolean_t deliver = TRUE; 767 | 768 | if( msg->msgh_id != kOSNotificationMessageID) 769 | return; 770 | 771 | if( MACH_MSGH_BITS_COMPLEX & msg->msgh_bits) { 772 | 773 | complexMsg = (struct ComplexMsg *)_msg; 774 | 775 | if( complexMsg->msgBody.msgh_descriptor_count) 776 | service = complexMsg->ports[0].name; 777 | header = (NotificationHeader *) &complexMsg->ports[complexMsg->msgBody.msgh_descriptor_count]; 778 | 779 | } else 780 | header = (NotificationHeader *) (msg + 1); 781 | 782 | leftOver = msg->msgh_size - (((vm_address_t) (header + 1)) - ((vm_address_t) msg)); 783 | 784 | // remote port is the notification (an iterator_t) that fired 785 | notifier = msg->msgh_remote_port; 786 | 787 | if( MACH_PORT_NULL != notifier) { 788 | kern_return_t kr; 789 | mach_port_urefs_t urefs; 790 | 791 | kr = mach_port_get_refs( mach_task_self(), msg->msgh_remote_port, MACH_PORT_RIGHT_SEND, &urefs); 792 | if( (KERN_SUCCESS != kr) || (urefs < 2)) { 793 | // one ref carried by the message - < 2 means owner has released the notifier 794 | deliver = false; 795 | } 796 | } 797 | 798 | if(deliver) 799 | { 800 | switch( header->type ) 801 | { 802 | case kIOAsyncCompletionNotificationType: 803 | { 804 | IOAsyncCompletionContent *asyncHdr; 805 | 806 | asyncHdr = (IOAsyncCompletionContent *)(header + 1); 807 | leftOver = (leftOver - sizeof(*asyncHdr)) / sizeof(void *); 808 | void *func = (void *) header->reference[kIOAsyncCalloutFuncIndex]; 809 | void *refCon = (void *) header->reference[kIOAsyncCalloutRefconIndex]; 810 | switch (leftOver) { 811 | case 0: 812 | ((IOAsyncCallback0) func)(refCon, asyncHdr->result); 813 | break; 814 | case 1: 815 | ((IOAsyncCallback1) func)(refCon, asyncHdr->result, 816 | asyncHdr->args[0]); 817 | break; 818 | case 2: 819 | ((IOAsyncCallback2) func)(refCon, asyncHdr->result, 820 | asyncHdr->args[0], asyncHdr->args[1]); 821 | break; 822 | default: 823 | ((IOAsyncCallback) func)(refCon, asyncHdr->result, 824 | asyncHdr->args, leftOver); 825 | break; 826 | } 827 | break; 828 | } 829 | case kIOServiceMessageNotificationType: 830 | { 831 | IOServiceInterestContent * interestHdr; 832 | void * arg; 833 | 834 | interestHdr = (IOServiceInterestContent *)(header + 1); 835 | leftOver = (leftOver - sizeof(*interestHdr) + sizeof(interestHdr->messageArgument)) / sizeof(void *); 836 | if (leftOver <= 1) 837 | arg = interestHdr->messageArgument[0]; 838 | else 839 | arg = &interestHdr->messageArgument[0]; 840 | 841 | ((IOServiceInterestCallback)header->reference[kIOInterestCalloutFuncIndex])( 842 | (void *) header->reference[kIOInterestCalloutRefconIndex], 843 | service ? service : (io_service_t) header->reference[kIOInterestCalloutServiceIndex], 844 | interestHdr->messageType, arg ); 845 | break; 846 | } 847 | case kIOServicePublishNotificationType: 848 | case kIOServiceMatchedNotificationType: 849 | case kIOServiceTerminatedNotificationType: 850 | 851 | ((IOServiceMatchingCallback)header->reference[kIOMatchingCalloutFuncIndex])( 852 | (void *) header->reference[kIOMatchingCalloutRefconIndex], 853 | notifier); 854 | break; 855 | } 856 | } 857 | 858 | if( MACH_PORT_NULL != notifier) 859 | mach_port_deallocate( mach_task_self(), notifier ); 860 | if( complexMsg) 861 | { 862 | uint32_t i; 863 | for( i = 0; i < complexMsg->msgBody.msgh_descriptor_count; i++) 864 | mach_port_deallocate( mach_task_self(), complexMsg->ports[i].name ); 865 | } 866 | } 867 | 868 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 869 | 870 | kern_return_t 871 | IOServiceGetBusyState( 872 | io_service_t service, 873 | uint32_t * busyState ) 874 | { 875 | kern_return_t kr; 876 | 877 | kr = io_service_get_busy_state( service, busyState ); 878 | 879 | if( kr != KERN_SUCCESS) 880 | *busyState = 0; 881 | 882 | return( kr ); 883 | } 884 | 885 | kern_return_t 886 | IOServiceGetState( 887 | io_service_t service, 888 | uint64_t * state ) 889 | { 890 | kern_return_t kr; 891 | 892 | kr = io_service_get_state( service, state ); 893 | 894 | if( kr != KERN_SUCCESS) 895 | *state = 0; 896 | 897 | return( kr ); 898 | } 899 | 900 | kern_return_t 901 | IOKitGetBusyState( 902 | mach_port_t masterPort, 903 | uint32_t * busyState ) 904 | { 905 | io_service_t root; 906 | kern_return_t kr; 907 | 908 | if (MACH_PORT_NULL == masterPort) 909 | masterPort = __IOGetDefaultMasterPort(); 910 | 911 | kr = io_registry_entry_from_path( masterPort, 912 | kIOServicePlane ":/", &root ); 913 | 914 | if( kr == KERN_SUCCESS) { 915 | kr = io_service_get_busy_state( root, busyState ); 916 | IOObjectRelease( root ); 917 | 918 | } else 919 | *busyState = 0; 920 | 921 | return( kr ); 922 | } 923 | 924 | kern_return_t 925 | IOServiceWaitQuiet( 926 | io_service_t service, 927 | mach_timespec_t * waitTime ) 928 | { 929 | kern_return_t kr; 930 | mach_timespec_t defaultWait = { 0, -1 }; 931 | 932 | if( 0 == waitTime) 933 | waitTime = &defaultWait; 934 | 935 | kr = io_service_wait_quiet( service, *waitTime ); 936 | 937 | return( kr ); 938 | } 939 | 940 | 941 | kern_return_t 942 | IOKitWaitQuiet( 943 | mach_port_t masterPort, 944 | mach_timespec_t * waitTime ) 945 | { 946 | io_service_t root; 947 | kern_return_t kr; 948 | mach_timespec_t defaultWait = { 0, -1 }; 949 | 950 | if (MACH_PORT_NULL == masterPort) 951 | masterPort = __IOGetDefaultMasterPort(); 952 | 953 | kr = io_registry_entry_from_path( masterPort, 954 | kIOServicePlane ":/", &root ); 955 | 956 | if( kr == KERN_SUCCESS) { 957 | if( 0 == waitTime) 958 | waitTime = &defaultWait; 959 | kr = io_service_wait_quiet( root, *waitTime ); 960 | IOObjectRelease( root ); 961 | } 962 | 963 | return( kr ); 964 | } 965 | 966 | kern_return_t 967 | IOServiceOpen( 968 | io_service_t service, 969 | task_port_t owningTask, 970 | uint32_t type, 971 | io_connect_t * connect ) 972 | { 973 | kern_return_t kr; 974 | kern_return_t result; 975 | 976 | kr = io_service_open_extended( service, 977 | owningTask, type, NDR_record, NULL, 0, &result, connect ); 978 | 979 | #if 1 980 | if (MIG_BAD_ID == kr) 981 | { 982 | kr = io_service_open(service, owningTask, type, connect); 983 | result = kr; 984 | } 985 | #endif 986 | 987 | if (KERN_SUCCESS == kr) 988 | kr = result; 989 | 990 | return (kr); 991 | } 992 | 993 | kern_return_t 994 | IOServiceClose( 995 | io_connect_t connect ) 996 | { 997 | kern_return_t kr; 998 | 999 | kr = io_service_close( connect); 1000 | IOObjectRelease( connect ); 1001 | 1002 | return( kr ); 1003 | } 1004 | 1005 | kern_return_t 1006 | IOServiceRequestProbe( 1007 | io_service_t service, 1008 | uint32_t options ) 1009 | { 1010 | return( io_service_request_probe( service, options )); 1011 | } 1012 | 1013 | /* 1014 | * IOService connection 1015 | */ 1016 | kern_return_t 1017 | IOConnectAddRef( 1018 | io_connect_t connect ) 1019 | { 1020 | return mach_port_mod_refs(mach_task_self(), 1021 | connect, 1022 | MACH_PORT_RIGHT_SEND, 1023 | 1); 1024 | } 1025 | 1026 | kern_return_t 1027 | IOConnectRelease( 1028 | io_connect_t connect ) 1029 | { 1030 | // XXX gvdl: Check with Simon about last reference removal 1031 | return mach_port_mod_refs(mach_task_self(), 1032 | connect, 1033 | MACH_PORT_RIGHT_SEND, 1034 | -1); 1035 | } 1036 | 1037 | kern_return_t 1038 | IOConnectGetService( 1039 | io_connect_t connect, 1040 | io_service_t * service ) 1041 | { 1042 | return( io_connect_get_service( connect, service )); 1043 | } 1044 | 1045 | kern_return_t 1046 | IOConnectSetNotificationPort( 1047 | io_connect_t connect, 1048 | uint32_t type, 1049 | mach_port_t port, 1050 | uintptr_t reference ) 1051 | { 1052 | return( io_connect_set_notification_port( connect, 1053 | type, port, reference)); 1054 | } 1055 | 1056 | #if !__LP64__ 1057 | kern_return_t 1058 | IOConnectMapMemory( 1059 | io_connect_t connect, 1060 | uint32_t memoryType, 1061 | task_port_t intoTask, 1062 | vm_address_t *atAddress, 1063 | vm_size_t *ofSize, 1064 | IOOptionBits options ) 1065 | { 1066 | return io_connect_map_memory 1067 | (connect, memoryType, intoTask, atAddress, ofSize, options); 1068 | } 1069 | 1070 | kern_return_t IOConnectMapMemory64 1071 | #else 1072 | kern_return_t IOConnectMapMemory 1073 | #endif 1074 | (io_connect_t connect, 1075 | uint32_t memoryType, 1076 | task_port_t intoTask, 1077 | mach_vm_address_t *atAddress, 1078 | mach_vm_size_t *ofSize, 1079 | IOOptionBits options ) 1080 | { 1081 | return io_connect_map_memory_into_task 1082 | (connect, memoryType, intoTask, atAddress, ofSize, options); 1083 | } 1084 | 1085 | #if !__LP64__ 1086 | kern_return_t 1087 | IOConnectUnmapMemory( 1088 | io_connect_t connect, 1089 | uint32_t memoryType, 1090 | task_port_t fromTask, 1091 | vm_address_t atAddress ) 1092 | { 1093 | return io_connect_unmap_memory 1094 | (connect, memoryType, fromTask, atAddress); 1095 | } 1096 | 1097 | kern_return_t IOConnectUnmapMemory64 1098 | #else 1099 | kern_return_t IOConnectUnmapMemory 1100 | #endif 1101 | (io_connect_t connect, 1102 | uint32_t memoryType, 1103 | task_port_t fromTask, 1104 | mach_vm_address_t atAddress) 1105 | { 1106 | return io_connect_unmap_memory_from_task 1107 | (connect, memoryType, fromTask, atAddress); 1108 | } 1109 | 1110 | kern_return_t 1111 | IOConnectAddClient( 1112 | io_connect_t connect, 1113 | io_connect_t client ) 1114 | { 1115 | return( io_connect_add_client( connect, client)); 1116 | } 1117 | 1118 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1119 | 1120 | #if USE_TRAP_TRANSPORT 1121 | 1122 | #define kUseTrapTransport 1 1123 | __private_extern__ char checkBegin = 0, checkEnd = 0; 1124 | static __inline__ void checkPtrRange(void *ptr, IOByteCount cnt) 1125 | { 1126 | checkBegin = ((uint8_t *) ptr)[0]; 1127 | checkEnd = ((uint8_t *) ptr)[cnt]; 1128 | } 1129 | 1130 | #else 1131 | 1132 | #define kUseTrapTransport 0 1133 | 1134 | #endif /* USE_TRAP_TRANSPORT */ 1135 | 1136 | #define reinterpret_cast_mach_vm_address_t(p) \ 1137 | ((mach_vm_address_t) (uintptr_t) p) 1138 | 1139 | kern_return_t 1140 | IOConnectCallMethod( 1141 | mach_port_t connection, // In 1142 | uint32_t selector, // In 1143 | const uint64_t *input, // In 1144 | uint32_t inputCnt, // In 1145 | const void *inputStruct, // In 1146 | size_t inputStructCnt, // In 1147 | uint64_t *output, // Out 1148 | uint32_t *outputCnt, // In/Out 1149 | void *outputStruct, // Out 1150 | size_t *outputStructCntP) // In/Out 1151 | { 1152 | kern_return_t rtn; 1153 | 1154 | void *inb_input = 0; 1155 | mach_msg_type_number_t inb_input_size = 0; 1156 | void *inb_output = 0; 1157 | mach_msg_type_number_t inb_output_size = 0; 1158 | 1159 | mach_vm_address_t ool_input = 0; 1160 | mach_vm_size_t ool_input_size = 0; 1161 | mach_vm_address_t ool_output = 0; 1162 | mach_vm_size_t ool_output_size = 0; 1163 | 1164 | if (inputStructCnt <= sizeof(io_struct_inband_t)) { 1165 | inb_input = (void *) inputStruct; 1166 | inb_input_size = (mach_msg_type_number_t) inputStructCnt; 1167 | } 1168 | else { 1169 | ool_input = reinterpret_cast_mach_vm_address_t(inputStruct); 1170 | ool_input_size = inputStructCnt; 1171 | } 1172 | 1173 | if (!outputCnt) { 1174 | static uint32_t zero = 0; 1175 | outputCnt = &zero; 1176 | } 1177 | 1178 | if (outputStructCntP) { 1179 | size_t size = *outputStructCntP; 1180 | 1181 | if (size <= sizeof(io_struct_inband_t)) { 1182 | inb_output = outputStruct; 1183 | inb_output_size = (mach_msg_type_number_t) size; 1184 | } 1185 | else { 1186 | ool_output = reinterpret_cast_mach_vm_address_t(outputStruct); 1187 | ool_output_size = (mach_vm_size_t) size; 1188 | } 1189 | } 1190 | 1191 | rtn = io_connect_method(connection, selector, 1192 | (uint64_t *) input, inputCnt, 1193 | inb_input, inb_input_size, 1194 | ool_input, ool_input_size, 1195 | output, outputCnt, 1196 | inb_output, &inb_output_size, 1197 | ool_output, &ool_output_size); 1198 | 1199 | if (outputStructCntP) { 1200 | if (*outputStructCntP <= sizeof(io_struct_inband_t)) 1201 | *outputStructCntP = (size_t) inb_output_size; 1202 | else 1203 | *outputStructCntP = (size_t) ool_output_size; 1204 | } 1205 | 1206 | return rtn; 1207 | } 1208 | 1209 | kern_return_t 1210 | IOConnectCallAsyncMethod( 1211 | mach_port_t connection, // In 1212 | uint32_t selector, // In 1213 | mach_port_t wakePort, // In 1214 | uint64_t *reference, // In 1215 | uint32_t referenceCnt, // In 1216 | const uint64_t *input, // In 1217 | uint32_t inputCnt, // In 1218 | const void *inputStruct, // In 1219 | size_t inputStructCnt, // In 1220 | uint64_t *output, // Out 1221 | uint32_t *outputCnt, // In/Out 1222 | void *outputStruct, // Out 1223 | size_t *outputStructCntP) // In/Out 1224 | { 1225 | kern_return_t rtn; 1226 | 1227 | void *inb_input = 0; 1228 | mach_msg_type_number_t inb_input_size = 0; 1229 | void *inb_output = 0; 1230 | mach_msg_type_number_t inb_output_size = 0; 1231 | 1232 | mach_vm_address_t ool_input = 0; 1233 | mach_vm_size_t ool_input_size = 0; 1234 | mach_vm_address_t ool_output = 0; 1235 | mach_vm_size_t ool_output_size = 0; 1236 | 1237 | if (inputStructCnt <= sizeof(io_struct_inband_t)) { 1238 | inb_input = (void *) inputStruct; 1239 | inb_input_size = (mach_msg_type_number_t) inputStructCnt; 1240 | } 1241 | else { 1242 | ool_input = reinterpret_cast_mach_vm_address_t(inputStruct); 1243 | ool_input_size = inputStructCnt; 1244 | } 1245 | 1246 | if (!outputCnt) { 1247 | static uint32_t zero = 0; 1248 | outputCnt = &zero; 1249 | } 1250 | 1251 | if (outputStructCntP) { 1252 | size_t size = *outputStructCntP; 1253 | 1254 | if (size <= sizeof(io_struct_inband_t)) { 1255 | inb_output = outputStruct; 1256 | inb_output_size = (mach_msg_type_number_t) size; 1257 | } 1258 | else { 1259 | ool_output = reinterpret_cast_mach_vm_address_t(outputStruct); 1260 | ool_output_size = (mach_vm_size_t) size; 1261 | } 1262 | } 1263 | 1264 | rtn = io_connect_async_method(connection, wakePort, 1265 | reference, referenceCnt, 1266 | selector, 1267 | (uint64_t *) input, inputCnt, 1268 | inb_input, inb_input_size, 1269 | ool_input, ool_input_size, 1270 | output, outputCnt, 1271 | inb_output, &inb_output_size, 1272 | ool_output, &ool_output_size); 1273 | 1274 | if (outputStructCntP) { 1275 | if (*outputStructCntP <= sizeof(io_struct_inband_t)) 1276 | *outputStructCntP = (size_t) inb_output_size; 1277 | else 1278 | *outputStructCntP = (size_t) ool_output_size; 1279 | } 1280 | 1281 | return rtn; 1282 | } 1283 | 1284 | kern_return_t 1285 | IOConnectCallStructMethod( 1286 | mach_port_t connection, // In 1287 | uint32_t selector, // In 1288 | const void *inputStruct, // In 1289 | size_t inputStructCnt, // In 1290 | void *outputStruct, // Out 1291 | size_t *outputStructCnt) // In/Out 1292 | { 1293 | return IOConnectCallMethod(connection, selector, 1294 | NULL, 0, 1295 | inputStruct, inputStructCnt, 1296 | NULL, NULL, 1297 | outputStruct, outputStructCnt); 1298 | } 1299 | 1300 | kern_return_t 1301 | IOConnectCallAsyncStructMethod( 1302 | mach_port_t connection, // In 1303 | uint32_t selector, // In 1304 | mach_port_t wakePort, // In 1305 | uint64_t *reference, // In 1306 | uint32_t referenceCnt, // In 1307 | const void *inputStruct, // In 1308 | size_t inputStructCnt, // In 1309 | void *outputStruct, // Out 1310 | size_t *outputStructCnt) // In/Out 1311 | { 1312 | return IOConnectCallAsyncMethod(connection, selector, wakePort, 1313 | reference, referenceCnt, 1314 | NULL, 0, 1315 | inputStruct, inputStructCnt, 1316 | NULL, NULL, 1317 | outputStruct, outputStructCnt); 1318 | } 1319 | 1320 | kern_return_t 1321 | IOConnectCallScalarMethod( 1322 | mach_port_t connection, // In 1323 | uint32_t selector, // In 1324 | const uint64_t *input, // In 1325 | uint32_t inputCnt, // In 1326 | uint64_t *output, // Out 1327 | uint32_t *outputCnt) // In/Out 1328 | { 1329 | return IOConnectCallMethod(connection, selector, 1330 | input, inputCnt, 1331 | NULL, 0, 1332 | output, outputCnt, 1333 | NULL, NULL); 1334 | } 1335 | 1336 | kern_return_t 1337 | IOConnectCallAsyncScalarMethod( 1338 | mach_port_t connection, // In 1339 | uint32_t selector, // In 1340 | mach_port_t wakePort, // In 1341 | uint64_t *reference, // In 1342 | uint32_t referenceCnt, // In 1343 | const uint64_t *input, // In 1344 | uint32_t inputCnt, // In 1345 | uint64_t *output, // Out 1346 | uint32_t *outputCnt) // In/Out 1347 | { 1348 | return IOConnectCallAsyncMethod(connection, selector, wakePort, 1349 | reference, referenceCnt, 1350 | input, inputCnt, 1351 | NULL, 0, 1352 | output, outputCnt, 1353 | NULL, NULL); 1354 | } 1355 | 1356 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1357 | 1358 | kern_return_t 1359 | IOConnectTrap0(io_connect_t connect, 1360 | uint32_t index) 1361 | { 1362 | return iokit_user_client_trap(connect, index, 0, 0, 0, 0, 0, 0); 1363 | } 1364 | 1365 | kern_return_t 1366 | IOConnectTrap1(io_connect_t connect, 1367 | uint32_t index, 1368 | uintptr_t p1 ) 1369 | { 1370 | return iokit_user_client_trap(connect, index, p1, 0, 0, 0, 0, 0); 1371 | } 1372 | 1373 | kern_return_t 1374 | IOConnectTrap2(io_connect_t connect, 1375 | uint32_t index, 1376 | uintptr_t p1, 1377 | uintptr_t p2 ) 1378 | { 1379 | return iokit_user_client_trap(connect, index, p1, p2, 0, 0, 0, 0); 1380 | } 1381 | 1382 | kern_return_t 1383 | IOConnectTrap3(io_connect_t connect, 1384 | uint32_t index, 1385 | uintptr_t p1, 1386 | uintptr_t p2, 1387 | uintptr_t p3 ) 1388 | { 1389 | return iokit_user_client_trap(connect, index, p1, p2, p3, 0, 0, 0); 1390 | } 1391 | 1392 | kern_return_t 1393 | IOConnectTrap4(io_connect_t connect, 1394 | uint32_t index, 1395 | uintptr_t p1, 1396 | uintptr_t p2, 1397 | uintptr_t p3, 1398 | uintptr_t p4 ) 1399 | { 1400 | return iokit_user_client_trap(connect, index, p1, p2, p3, p4, 0, 0); 1401 | } 1402 | 1403 | kern_return_t 1404 | IOConnectTrap5(io_connect_t connect, 1405 | uint32_t index, 1406 | uintptr_t p1, 1407 | uintptr_t p2, 1408 | uintptr_t p3, 1409 | uintptr_t p4, 1410 | uintptr_t p5 ) 1411 | { 1412 | return iokit_user_client_trap(connect, index, p1, p2, p3, p4, p5, 0); 1413 | } 1414 | 1415 | kern_return_t 1416 | IOConnectTrap6(io_connect_t connect, 1417 | uint32_t index, 1418 | uintptr_t p1, 1419 | uintptr_t p2, 1420 | uintptr_t p3, 1421 | uintptr_t p4, 1422 | uintptr_t p5, 1423 | uintptr_t p6 ) 1424 | { 1425 | return iokit_user_client_trap(connect, index, p1, p2, p3, p4, p5, p6); 1426 | } 1427 | 1428 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1429 | 1430 | kern_return_t 1431 | IOConnectSetCFProperties( 1432 | io_connect_t connect, 1433 | CFTypeRef properties ) 1434 | { 1435 | CFDataRef data; 1436 | kern_return_t kr; 1437 | kern_return_t result; 1438 | 1439 | data = IOCFSerialize( properties, kNilOptions ); 1440 | if( !data) 1441 | return( kIOReturnUnsupported ); 1442 | 1443 | kr = io_connect_set_properties( connect, 1444 | (char *) CFDataGetBytePtr(data), CFDataGetLength(data), 1445 | &result ); 1446 | 1447 | CFRelease(data); 1448 | 1449 | if( KERN_SUCCESS == kr) 1450 | kr = result; 1451 | 1452 | return( kr ); 1453 | } 1454 | 1455 | kern_return_t 1456 | IOConnectSetCFProperty( 1457 | io_connect_t connect, 1458 | CFStringRef propertyName, 1459 | CFTypeRef property ) 1460 | { 1461 | CFDictionaryRef dict; 1462 | kern_return_t kr; 1463 | 1464 | CFTypeRef name = propertyName; 1465 | dict = CFDictionaryCreate( kCFAllocatorDefault, 1466 | &name, &property, 1, 1467 | &kCFTypeDictionaryKeyCallBacks, 1468 | &kCFTypeDictionaryValueCallBacks ); 1469 | if( !dict) 1470 | return( kIOReturnNoMemory ); 1471 | 1472 | kr = IOConnectSetCFProperties( connect, dict ); 1473 | CFRelease( dict ); 1474 | 1475 | return( kr ); 1476 | } 1477 | 1478 | 1479 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1480 | 1481 | /* 1482 | * IORegistry accessors 1483 | */ 1484 | 1485 | kern_return_t 1486 | IORegistryCreateIterator( 1487 | mach_port_t masterPort, 1488 | const io_name_t plane, 1489 | IOOptionBits options, 1490 | io_iterator_t * iterator ) 1491 | { 1492 | if (MACH_PORT_NULL == masterPort) 1493 | masterPort = __IOGetDefaultMasterPort(); 1494 | 1495 | return( io_registry_create_iterator( masterPort, (char *) plane, 1496 | options, iterator)); 1497 | } 1498 | 1499 | kern_return_t 1500 | IORegistryEntryCreateIterator( 1501 | io_registry_entry_t entry, 1502 | const io_name_t plane, 1503 | IOOptionBits options, 1504 | io_iterator_t * iterator ) 1505 | { 1506 | return( io_registry_entry_create_iterator( entry, (char *) plane, 1507 | options, iterator)); 1508 | } 1509 | 1510 | kern_return_t 1511 | IORegistryIteratorEnterEntry( 1512 | io_iterator_t iterator ) 1513 | { 1514 | return( io_registry_iterator_enter_entry( iterator)); 1515 | } 1516 | 1517 | 1518 | kern_return_t 1519 | IORegistryIteratorExitEntry( 1520 | io_iterator_t iterator ) 1521 | { 1522 | return( io_registry_iterator_exit_entry( iterator)); 1523 | } 1524 | 1525 | io_registry_entry_t 1526 | IORegistryEntryFromPath( 1527 | mach_port_t masterPort, 1528 | const io_string_t path ) 1529 | { 1530 | kern_return_t kr; 1531 | io_registry_entry_t entry; 1532 | 1533 | if (MACH_PORT_NULL == masterPort) 1534 | masterPort = __IOGetDefaultMasterPort(); 1535 | 1536 | kr = io_registry_entry_from_path( masterPort, (char *) path, &entry ); 1537 | if( kIOReturnSuccess != kr) 1538 | entry = 0; 1539 | 1540 | return( entry ); 1541 | } 1542 | 1543 | io_registry_entry_t 1544 | IORegistryGetRootEntry( 1545 | mach_port_t masterPort ) 1546 | { 1547 | kern_return_t kr; 1548 | io_registry_entry_t entry; 1549 | 1550 | if (MACH_PORT_NULL == masterPort) 1551 | masterPort = __IOGetDefaultMasterPort(); 1552 | 1553 | kr = io_registry_get_root_entry( masterPort, &entry ); 1554 | if( kIOReturnSuccess != kr) 1555 | entry = 0; 1556 | 1557 | return( entry ); 1558 | } 1559 | 1560 | kern_return_t 1561 | IORegistryEntryGetPath( 1562 | io_registry_entry_t entry, 1563 | const io_name_t plane, 1564 | io_string_t path ) 1565 | { 1566 | return( io_registry_entry_get_path( entry, (char *) plane, path )); 1567 | } 1568 | 1569 | boolean_t 1570 | IORegistryEntryInPlane( 1571 | io_registry_entry_t entry, 1572 | const io_name_t plane ) 1573 | { 1574 | boolean_t inPlane; 1575 | 1576 | if( kIOReturnSuccess != io_registry_entry_in_plane( 1577 | entry, (char *) plane, &inPlane )) 1578 | inPlane = false; 1579 | 1580 | return( inPlane ); 1581 | } 1582 | 1583 | kern_return_t 1584 | IORegistryEntryGetName( 1585 | io_registry_entry_t entry, 1586 | io_name_t name ) 1587 | { 1588 | return( io_registry_entry_get_name( entry, name )); 1589 | } 1590 | 1591 | kern_return_t 1592 | IORegistryEntryGetNameInPlane( 1593 | io_registry_entry_t entry, 1594 | const io_name_t plane, 1595 | io_name_t name ) 1596 | { 1597 | if( NULL == plane) 1598 | plane = ""; 1599 | return( io_registry_entry_get_name_in_plane( entry, 1600 | (char *) plane, name )); 1601 | } 1602 | 1603 | kern_return_t 1604 | IORegistryEntryGetLocationInPlane( 1605 | io_registry_entry_t entry, 1606 | const io_name_t plane, 1607 | io_name_t location ) 1608 | { 1609 | if( NULL == plane) 1610 | plane = ""; 1611 | return( io_registry_entry_get_location_in_plane( entry, 1612 | (char *) plane, location )); 1613 | } 1614 | 1615 | 1616 | kern_return_t 1617 | IORegistryEntryCreateCFProperties( 1618 | io_registry_entry_t entry, 1619 | CFMutableDictionaryRef * properties, 1620 | CFAllocatorRef allocator, 1621 | IOOptionBits options __unused ) 1622 | { 1623 | kern_return_t kr; 1624 | uint32_t size; 1625 | char * propertiesBuffer; 1626 | CFStringRef errorString; 1627 | const char * cstr; 1628 | 1629 | kr = io_registry_entry_get_properties(entry, &propertiesBuffer, &size); 1630 | if (kr != kIOReturnSuccess) return kr; 1631 | 1632 | *properties = (CFMutableDictionaryRef) 1633 | IOCFUnserialize(propertiesBuffer, allocator, 1634 | 0, &errorString); 1635 | if (!(*properties) && errorString) { 1636 | 1637 | if ((cstr = CFStringGetCStringPtr(errorString, 1638 | kCFStringEncodingMacRoman))) 1639 | printf("%s\n", cstr); 1640 | CFRelease(errorString); 1641 | } 1642 | 1643 | // free propertiesBuffer ! 1644 | vm_deallocate(mach_task_self(), (vm_address_t)propertiesBuffer, size); 1645 | 1646 | return( *properties ? kIOReturnSuccess : kIOReturnInternalError ); 1647 | } 1648 | 1649 | CFTypeRef 1650 | IORegistryEntryCreateCFProperty( 1651 | io_registry_entry_t entry, 1652 | CFStringRef key, 1653 | CFAllocatorRef allocator, 1654 | IOOptionBits options __unused ) 1655 | { 1656 | IOReturn kr; 1657 | CFTypeRef type; 1658 | uint32_t size; 1659 | char * propertiesBuffer; 1660 | CFStringRef errorString; 1661 | const char * cStr; 1662 | char * buffer = NULL; 1663 | 1664 | cStr = CFStringGetCStringPtr( key, kCFStringEncodingMacRoman); 1665 | if( !cStr) { 1666 | CFIndex bufferSize = CFStringGetMaximumSizeForEncoding( CFStringGetLength(key), 1667 | kCFStringEncodingMacRoman) + sizeof('\0'); 1668 | buffer = malloc( bufferSize); 1669 | if( buffer && CFStringGetCString( key, buffer, bufferSize, kCFStringEncodingMacRoman)) 1670 | cStr = buffer; 1671 | } 1672 | 1673 | if( cStr) 1674 | kr = io_registry_entry_get_property(entry, (char *) cStr, &propertiesBuffer, &size); 1675 | else 1676 | kr = kIOReturnError; 1677 | 1678 | if( buffer) 1679 | free( buffer); 1680 | 1681 | if( kr != kIOReturnSuccess) 1682 | return( NULL ); 1683 | 1684 | type = (CFMutableDictionaryRef) 1685 | IOCFUnserialize(propertiesBuffer, allocator, 1686 | 0, &errorString); 1687 | if (!type && errorString) { 1688 | 1689 | if ((cStr = CFStringGetCStringPtr(errorString, 1690 | kCFStringEncodingMacRoman))) 1691 | printf("%s\n", cStr); 1692 | CFRelease(errorString); 1693 | } 1694 | 1695 | // free propertiesBuffer ! 1696 | vm_deallocate(mach_task_self(), (vm_address_t)propertiesBuffer, size); 1697 | 1698 | return( type ); 1699 | } 1700 | 1701 | CFTypeRef 1702 | IORegistryEntrySearchCFProperty( 1703 | io_registry_entry_t entry, 1704 | const io_name_t plane, 1705 | CFStringRef key, 1706 | CFAllocatorRef allocator, 1707 | IOOptionBits options ) 1708 | { 1709 | IOReturn kr; 1710 | CFTypeRef type; 1711 | uint32_t size; 1712 | char * propertiesBuffer; 1713 | CFStringRef errorString; 1714 | const char * cStr; 1715 | char * buffer = NULL; 1716 | 1717 | cStr = CFStringGetCStringPtr( key, kCFStringEncodingMacRoman); 1718 | if( !cStr) { 1719 | CFIndex bufferSize = CFStringGetMaximumSizeForEncoding( CFStringGetLength(key), 1720 | kCFStringEncodingMacRoman) + sizeof('\0'); 1721 | buffer = malloc( bufferSize); 1722 | if( buffer && CFStringGetCString( key, buffer, bufferSize, kCFStringEncodingMacRoman)) 1723 | cStr = buffer; 1724 | } 1725 | 1726 | if( cStr) 1727 | kr = io_registry_entry_get_property_recursively(entry, (char *) plane, (char *) cStr, 1728 | options, &propertiesBuffer, &size); 1729 | else 1730 | kr = kIOReturnError; 1731 | 1732 | if( buffer) 1733 | free( buffer); 1734 | 1735 | if( kr != kIOReturnSuccess) 1736 | return( NULL ); 1737 | 1738 | type = (CFMutableDictionaryRef) 1739 | IOCFUnserialize(propertiesBuffer, allocator, 1740 | 0, &errorString); 1741 | if (!type && errorString) { 1742 | 1743 | if ((cStr = CFStringGetCStringPtr(errorString, 1744 | kCFStringEncodingMacRoman))) 1745 | printf("%s\n", cStr); 1746 | CFRelease(errorString); 1747 | } 1748 | 1749 | // free propertiesBuffer ! 1750 | vm_deallocate(mach_task_self(), (vm_address_t)propertiesBuffer, size); 1751 | 1752 | return( type ); 1753 | } 1754 | 1755 | kern_return_t 1756 | IORegistryEntryGetProperty( 1757 | io_registry_entry_t entry, 1758 | const io_name_t name, 1759 | io_struct_inband_t buffer, 1760 | uint32_t * size ) 1761 | { 1762 | 1763 | 1764 | return( io_registry_entry_get_property_bytes( entry, (char *) name, 1765 | buffer, size )); 1766 | } 1767 | 1768 | 1769 | kern_return_t 1770 | IORegistryEntrySetCFProperties( 1771 | io_registry_entry_t entry, 1772 | CFTypeRef properties ) 1773 | { 1774 | CFDataRef data; 1775 | kern_return_t kr; 1776 | kern_return_t result; 1777 | 1778 | data = IOCFSerialize( properties, kNilOptions ); 1779 | if( !data) 1780 | return( kIOReturnUnsupported ); 1781 | 1782 | kr = io_registry_entry_set_properties( entry, 1783 | (char *) CFDataGetBytePtr(data), CFDataGetLength(data), 1784 | &result ); 1785 | 1786 | CFRelease(data); 1787 | 1788 | if( KERN_SUCCESS == kr) 1789 | kr = result; 1790 | 1791 | return( kr ); 1792 | } 1793 | 1794 | kern_return_t 1795 | IORegistryEntrySetCFProperty( 1796 | io_registry_entry_t entry, 1797 | CFStringRef propertyName, 1798 | CFTypeRef property ) 1799 | { 1800 | CFDictionaryRef dict; 1801 | kern_return_t kr; 1802 | 1803 | dict = CFDictionaryCreate( kCFAllocatorDefault, 1804 | (const void **) &propertyName, (const void **) &property, 1, 1805 | &kCFTypeDictionaryKeyCallBacks, 1806 | &kCFTypeDictionaryValueCallBacks ); 1807 | if( !dict) 1808 | return( kIOReturnNoMemory ); 1809 | 1810 | kr = IORegistryEntrySetCFProperties( entry, dict ); 1811 | CFRelease( dict ); 1812 | 1813 | return( kr ); 1814 | } 1815 | 1816 | kern_return_t 1817 | IORegistryEntryGetChildIterator( 1818 | io_registry_entry_t entry, 1819 | const io_name_t plane, 1820 | io_iterator_t * iterator ) 1821 | { 1822 | return( io_registry_entry_get_child_iterator( entry, 1823 | (char *) plane, iterator)); 1824 | } 1825 | 1826 | kern_return_t 1827 | IORegistryEntryGetParentIterator( 1828 | io_registry_entry_t entry, 1829 | const io_name_t plane, 1830 | io_iterator_t * iterator ) 1831 | { 1832 | return( io_registry_entry_get_parent_iterator( entry, 1833 | (char *) plane, iterator)); 1834 | } 1835 | 1836 | kern_return_t 1837 | IORegistryEntryGetChildEntry( 1838 | io_registry_entry_t entry, 1839 | const io_name_t plane, 1840 | io_registry_entry_t * child ) 1841 | { 1842 | kern_return_t kr; 1843 | io_iterator_t iter; 1844 | 1845 | kr = IORegistryEntryGetChildIterator( entry, plane, &iter ); 1846 | 1847 | if( KERN_SUCCESS == kr) { 1848 | 1849 | *child = IOIteratorNext( iter ); 1850 | IOObjectRelease( iter ); 1851 | if( MACH_PORT_NULL == *child) 1852 | kr = kIOReturnNoDevice; 1853 | } 1854 | 1855 | return( kr ); 1856 | } 1857 | 1858 | kern_return_t 1859 | IORegistryEntryGetParentEntry( 1860 | io_registry_entry_t entry, 1861 | const io_name_t plane, 1862 | io_registry_entry_t * parent ) 1863 | { 1864 | kern_return_t kr; 1865 | io_iterator_t iter; 1866 | 1867 | kr = IORegistryEntryGetParentIterator( entry, plane, &iter ); 1868 | 1869 | if( KERN_SUCCESS == kr) { 1870 | 1871 | *parent = IOIteratorNext( iter ); 1872 | IOObjectRelease( iter ); 1873 | if( MACH_PORT_NULL == *parent) 1874 | kr = kIOReturnNoDevice; 1875 | } 1876 | 1877 | return( kr ); 1878 | } 1879 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1880 | 1881 | kern_return_t 1882 | IOServiceOFPathToBSDName(mach_port_t masterPort, 1883 | const io_name_t openFirmwarePath, 1884 | io_name_t bsdName) 1885 | { 1886 | kern_return_t kr; 1887 | io_registry_entry_t service; 1888 | io_iterator_t services; 1889 | 1890 | // Initialize return values. 1891 | 1892 | bsdName[0] = 0; 1893 | 1894 | // Find objects matching the given open firmware name. 1895 | 1896 | kr = IOServiceGetMatchingServices( 1897 | /* mach_port_t */ masterPort, 1898 | /* void * */ IOOpenFirmwarePathMatching( 1899 | /* mach_port_t */ masterPort, 1900 | /* uint32_t */ 0, 1901 | /* const char * */ openFirmwarePath ), 1902 | /* io_iterator * */ &services ); 1903 | 1904 | if( KERN_SUCCESS != kr ) return( kr ); 1905 | 1906 | // Obtain the first (and presumably the only) match. 1907 | 1908 | service = IOIteratorNext( services ); 1909 | 1910 | if( service ) { 1911 | 1912 | // Obtain the BSD name property from this object. 1913 | 1914 | uint32_t bsdNameSize = sizeof(io_name_t); 1915 | 1916 | kr = IORegistryEntryGetProperty( 1917 | /* mach_port_t */ service, 1918 | /* io_name_t */ kIOBSDNameKey, 1919 | /* io_struct_inband_t */ bsdName, 1920 | /* uint32_t * */ &bsdNameSize); 1921 | 1922 | if( KERN_SUCCESS != kr ) bsdName[0] = 0; 1923 | 1924 | IOObjectRelease( service ); 1925 | } 1926 | else { 1927 | kr = KERN_FAILURE; 1928 | } 1929 | 1930 | IOObjectRelease( services ); 1931 | 1932 | return kr; 1933 | } 1934 | 1935 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1936 | 1937 | kern_return_t 1938 | IOCatalogueSendData( 1939 | mach_port_t masterPort, 1940 | uint32_t flag, 1941 | const char *buffer, 1942 | uint32_t size ) 1943 | { 1944 | kern_return_t kr; 1945 | kern_return_t result; 1946 | 1947 | if (MACH_PORT_NULL == masterPort) 1948 | masterPort = __IOGetDefaultMasterPort(); 1949 | 1950 | kr = io_catalog_send_data( masterPort, flag, 1951 | (char *) buffer, size, &result ); 1952 | if( KERN_SUCCESS == kr) 1953 | kr = result; 1954 | 1955 | return( kr ); 1956 | } 1957 | 1958 | kern_return_t 1959 | IOCatalogueTerminate( 1960 | mach_port_t masterPort, 1961 | uint32_t flag, 1962 | io_name_t description ) 1963 | { 1964 | if (MACH_PORT_NULL == masterPort) 1965 | masterPort = __IOGetDefaultMasterPort(); 1966 | 1967 | return( io_catalog_terminate( masterPort, flag, description )); 1968 | } 1969 | 1970 | kern_return_t 1971 | IOCatalogueGetData( 1972 | mach_port_t masterPort, 1973 | uint32_t flag, 1974 | char **buffer, 1975 | uint32_t *size ) 1976 | { 1977 | if (MACH_PORT_NULL == masterPort) 1978 | masterPort = __IOGetDefaultMasterPort(); 1979 | 1980 | return ( io_catalog_get_data( masterPort, flag, (char **)buffer, (unsigned *)size ) ); 1981 | } 1982 | 1983 | kern_return_t 1984 | IOCatlogueGetGenCount( 1985 | mach_port_t masterPort, 1986 | uint32_t *genCount ) 1987 | { 1988 | if (MACH_PORT_NULL == masterPort) 1989 | masterPort = __IOGetDefaultMasterPort(); 1990 | 1991 | return ( io_catalog_get_gen_count( masterPort, genCount ) ); 1992 | } 1993 | 1994 | kern_return_t 1995 | IOCatalogueModuleLoaded( 1996 | mach_port_t masterPort, 1997 | io_name_t name ) 1998 | { 1999 | if (MACH_PORT_NULL == masterPort) 2000 | masterPort = __IOGetDefaultMasterPort(); 2001 | 2002 | return ( io_catalog_module_loaded( masterPort, name ) ); 2003 | } 2004 | 2005 | kern_return_t 2006 | IOCatalogueReset( 2007 | mach_port_t masterPort, 2008 | uint32_t flag ) 2009 | { 2010 | if (MACH_PORT_NULL == masterPort) 2011 | masterPort = __IOGetDefaultMasterPort(); 2012 | 2013 | return ( io_catalog_reset(masterPort, flag) ); 2014 | } 2015 | 2016 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 2017 | 2018 | // obsolete API 2019 | 2020 | kern_return_t 2021 | IORegistryCreateEnumerator( 2022 | mach_port_t masterPort, 2023 | mach_port_t * enumerator ) 2024 | { 2025 | if (MACH_PORT_NULL == masterPort) 2026 | masterPort = __IOGetDefaultMasterPort(); 2027 | 2028 | return( io_registry_create_iterator( masterPort, 2029 | "IOService", true, enumerator)); 2030 | } 2031 | 2032 | kern_return_t 2033 | IORegistryEnumeratorReset( 2034 | mach_port_t enumerator ) 2035 | { 2036 | return( io_iterator_reset( enumerator)); 2037 | } 2038 | 2039 | 2040 | static io_object_t lastRegIter; 2041 | 2042 | kern_return_t 2043 | IORegistryEnumeratorNextConforming( 2044 | mach_port_t enumerator, 2045 | const char * name, 2046 | boolean_t recursive __unused ) 2047 | { 2048 | io_object_t next = 0; 2049 | 2050 | while( (next = IOIteratorNext( enumerator ))) { 2051 | 2052 | if( IOObjectConformsTo( next, (char *) name )) 2053 | break; 2054 | 2055 | IOObjectRelease( next ); 2056 | } 2057 | 2058 | lastRegIter = next; 2059 | 2060 | return( next ? kIOReturnSuccess : kIOReturnNoDevice ); 2061 | } 2062 | 2063 | 2064 | #if 0 2065 | kern_return_t 2066 | IORegistryGetProperties( 2067 | mach_port_t enumerator , 2068 | void ** properties ) 2069 | { 2070 | return( IORegistryEntryGetProperties( lastRegIter, 2071 | (struct IOObject **)properties)); 2072 | } 2073 | #endif 2074 | 2075 | kern_return_t 2076 | IOOpenConnection( 2077 | mach_port_t enumerator __unused, 2078 | task_port_t owningTask, 2079 | uint32_t type, 2080 | mach_port_t * connect ) 2081 | { 2082 | kern_return_t kr; 2083 | 2084 | kr = io_service_open( lastRegIter, 2085 | owningTask, type, connect ); 2086 | 2087 | IOObjectRelease( lastRegIter ); 2088 | 2089 | return( kr ); 2090 | } 2091 | 2092 | 2093 | kern_return_t 2094 | IOCloseConnection( 2095 | mach_port_t connect ) 2096 | { 2097 | return( io_service_close( connect)); 2098 | } 2099 | 2100 | 2101 | kern_return_t 2102 | IOSetNotificationPort( 2103 | mach_port_t connect, 2104 | uint32_t type, 2105 | mach_port_t port ) 2106 | { 2107 | return( io_connect_set_notification_port( connect, type, port, 0)); 2108 | } 2109 | kern_return_t 2110 | IORegisterClient( 2111 | mach_port_t connect, 2112 | mach_port_t client ) 2113 | { 2114 | return( io_connect_add_client( connect, client)); 2115 | } 2116 | 2117 | kern_return_t 2118 | IORegistryDisposeEnumerator( 2119 | io_enumerator_t enumerator ) 2120 | { 2121 | return( IOObjectRelease( enumerator )); 2122 | } 2123 | 2124 | /* -------------------------- */ 2125 | 2126 | kern_return_t 2127 | IOCompatibiltyNumber( 2128 | mach_port_t connect __unused, 2129 | uint32_t * objectNumber ) 2130 | { 2131 | *objectNumber = 1; 2132 | return( kIOReturnSuccess); 2133 | } 2134 | 2135 | 2136 | void 2137 | IOInitContainerClasses() 2138 | { 2139 | } 2140 | 2141 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 2142 | 2143 | /* 32bit binary compatibility routines for deprecated APIs */ 2144 | #if !defined(__LP64__) 2145 | 2146 | // Compatability routines with 32bit IOKitLib 2147 | kern_return_t 2148 | IOConnectMethodScalarIScalarO( 2149 | io_connect_t connect, 2150 | uint32_t index, 2151 | IOItemCount inCount, 2152 | IOItemCount scalarOutputCount, 2153 | ... ) 2154 | { 2155 | uint64_t inData[6], outData[6]; 2156 | kern_return_t err; 2157 | uint32_t i, outCount; 2158 | va_list val; 2159 | 2160 | if (inCount + scalarOutputCount > 6) 2161 | return MIG_ARRAY_TOO_LARGE; 2162 | 2163 | va_start(val, scalarOutputCount); 2164 | for (i = 0; i < inCount; i++) 2165 | inData[i] = va_arg(val, uint32_t); 2166 | 2167 | outCount = scalarOutputCount; 2168 | err = IOConnectCallScalarMethod(connect, index, 2169 | inData, inCount, outData, &outCount); 2170 | 2171 | if( kIOReturnSuccess == err) { 2172 | for (i = 0; i < outCount; i++) { 2173 | uint32_t *out = va_arg(val, uint32_t *); 2174 | *out = (uint32_t) outData[i]; 2175 | } 2176 | } 2177 | va_end(val); 2178 | 2179 | return err; 2180 | } 2181 | 2182 | kern_return_t 2183 | IOConnectMethodScalarIStructureO( 2184 | io_connect_t connect, 2185 | uint32_t index, 2186 | IOItemCount inCount, 2187 | IOByteCount * outSizeP, 2188 | ... ) 2189 | { 2190 | uint64_t inData[6]; 2191 | void *out = NULL; 2192 | IOItemCount i; 2193 | va_list val; 2194 | 2195 | if (inCount > 6) 2196 | return MIG_ARRAY_TOO_LARGE; 2197 | 2198 | va_start(val, outSizeP); 2199 | for (i = 0; i < inCount; i++) 2200 | inData[i] = va_arg(val, uint32_t); 2201 | if (outSizeP && *outSizeP) 2202 | out = va_arg(val, void *); 2203 | 2204 | kern_return_t err = IOConnectCallMethod(connect, index, 2205 | inData, inCount, NULL, 0, 2206 | NULL, 0, out, outSizeP); 2207 | 2208 | va_end(val); 2209 | 2210 | return err; 2211 | } 2212 | 2213 | kern_return_t 2214 | IOConnectMethodScalarIStructureI( 2215 | io_connect_t connect, 2216 | uint32_t index, 2217 | IOItemCount inCount, 2218 | IOByteCount inSize, 2219 | ... ) 2220 | { 2221 | uint64_t inData[6]; 2222 | uint8_t *in = NULL; 2223 | va_list val; 2224 | 2225 | if (inCount > 6) 2226 | return MIG_ARRAY_TOO_LARGE; 2227 | 2228 | va_start(val, inSize); 2229 | for (IOItemCount i = 0; i < inCount; i++) 2230 | inData[i] = va_arg(val, uint32_t); 2231 | if (inSize) 2232 | in = va_arg(val, void *); 2233 | 2234 | kern_return_t err = IOConnectCallMethod(connect, index, 2235 | inData, inCount, in, inSize, 2236 | NULL, NULL, NULL, NULL); 2237 | 2238 | va_end(val); 2239 | 2240 | return err; 2241 | } 2242 | 2243 | kern_return_t 2244 | IOConnectMethodStructureIStructureO( 2245 | io_connect_t connect, 2246 | uint32_t index, 2247 | IOItemCount inSize, 2248 | IOByteCount * outSizeP, 2249 | void * in, 2250 | void * out ) 2251 | { 2252 | return IOConnectCallStructMethod(connect, index, in, inSize, out, outSizeP); 2253 | } 2254 | 2255 | kern_return_t 2256 | IOMapMemory( 2257 | io_connect_t connect, 2258 | uint32_t memoryType, 2259 | task_port_t intoTask, 2260 | vm_address_t * atAddress, 2261 | vm_size_t * ofSize, 2262 | uint32_t flags ) 2263 | { 2264 | return( io_connect_map_memory( connect, memoryType, intoTask, 2265 | atAddress, ofSize, flags)); 2266 | } 2267 | 2268 | #if MAP_32B_METHODS || EMULATE_IOCONNECT_64 || EMULATE_IOCONNECT_ASYNC_64 2269 | 2270 | // ILP32 - need to remap up to 64 bit scalars these are helpers 2271 | #define arrayCnt(type) (sizeof(type)/sizeof(type[0])) 2272 | static void inflate_vec(uint64_t *dp, int d, int *sp, int s) 2273 | { 2274 | if (d > s) 2275 | d = s; 2276 | 2277 | for (int i = 0; i < d; i++) 2278 | dp[i] = (uint32_t) sp[i]; 2279 | } 2280 | 2281 | static void deflate_vec(int *dp, int d, uint64_t *sp, int s) 2282 | { 2283 | if (d > s) 2284 | d = s; 2285 | 2286 | for (int i = 0; i < d; i++) 2287 | dp[i] = (int) sp[i]; 2288 | } 2289 | #endif // MAP_32B_METHODS || EMULATE_IOCONNECT_64 || EMULATE_IOCONNECT_ASYNC_64 2290 | 2291 | #if MAP_32B_METHODS 2292 | 2293 | // Compatability routines with earlier Mig interface routines 2294 | // Remember only ILP32 ONLY 2295 | kern_return_t 2296 | io_connect_map_memory( 2297 | io_connect_t connect, 2298 | uint32_t memoryType, 2299 | task_port_t intoTask, 2300 | vm_address_t *atAddress, 2301 | vm_size_t *ofSize, 2302 | IOOptionBits options) 2303 | { 2304 | kern_return_t rtn; 2305 | 2306 | mach_vm_address_t machAtAddress = *atAddress; 2307 | mach_vm_size_t machOfSize = *ofSize; 2308 | 2309 | rtn = io_connect_map_memory_into_task( 2310 | connect, memoryType, intoTask, &machAtAddress, &machOfSize, options); 2311 | 2312 | // Must be safe as we are have !__LP64__ checked 2313 | *atAddress = (vm_address_t) machAtAddress; 2314 | *ofSize = (vm_size_t) machOfSize; 2315 | 2316 | return rtn; 2317 | } 2318 | 2319 | kern_return_t 2320 | io_connect_unmap_memory( 2321 | io_connect_t connect, 2322 | uint32_t memoryType, 2323 | task_port_t fromTask, 2324 | vm_address_t atAddress) 2325 | { 2326 | // Must be safe as we are have !__LP64__ checked 2327 | return io_connect_unmap_memory_from_task 2328 | (connect, memoryType, fromTask, (mach_vm_address_t) atAddress); 2329 | } 2330 | 2331 | kern_return_t 2332 | io_connect_method_scalarI_scalarO( 2333 | mach_port_t connection, 2334 | int selector, 2335 | int *input, 2336 | mach_msg_type_number_t inputCnt, 2337 | int *output, 2338 | mach_msg_type_number_t *outputCnt) 2339 | { 2340 | kern_return_t rtn; 2341 | 2342 | // ILP32 - need to remap up to 64 bit scalars 2343 | io_scalar_inband64_t scalarData; 2344 | inflate_vec(scalarData, arrayCnt(scalarData), input, inputCnt); 2345 | 2346 | rtn = IOConnectCallMethod(connection, selector, 2347 | scalarData, inputCnt, NULL, 0, 2348 | scalarData, outputCnt, NULL, NULL); 2349 | 2350 | inputCnt = (rtn == KERN_SUCCESS && outputCnt)? *outputCnt : 0; 2351 | deflate_vec(output, inputCnt, scalarData, arrayCnt(scalarData)); 2352 | 2353 | return rtn; 2354 | } 2355 | 2356 | kern_return_t 2357 | io_async_method_scalarI_scalarO( 2358 | mach_port_t connection, 2359 | mach_port_t wakePort, 2360 | io_async_ref_t reference, 2361 | mach_msg_type_number_t referenceCnt, 2362 | int selector, 2363 | int *input, 2364 | mach_msg_type_number_t inputCnt, 2365 | int *output, 2366 | mach_msg_type_number_t *outputCnt) 2367 | { 2368 | kern_return_t rtn; 2369 | 2370 | // ILP32 - need to remap up to 64 bit scalars 2371 | io_scalar_inband64_t scalarData; 2372 | inflate_vec(scalarData, arrayCnt(scalarData), input, inputCnt); 2373 | io_async_ref64_t refrncData; 2374 | inflate_vec(refrncData, arrayCnt(refrncData), (int *) reference, referenceCnt); 2375 | 2376 | rtn = IOConnectCallAsyncMethod(connection, selector, wakePort, 2377 | refrncData, referenceCnt, 2378 | scalarData, inputCnt, 2379 | NULL, 0, 2380 | scalarData, outputCnt, 2381 | NULL, NULL); 2382 | 2383 | inputCnt = (rtn == KERN_SUCCESS && outputCnt)? *outputCnt : 0; 2384 | deflate_vec(output, inputCnt, scalarData, arrayCnt(scalarData)); 2385 | 2386 | return rtn; 2387 | } 2388 | 2389 | 2390 | kern_return_t 2391 | io_connect_method_scalarI_structureO( 2392 | mach_port_t connection, 2393 | int selector, 2394 | int *input, 2395 | mach_msg_type_number_t inputCnt, 2396 | io_struct_inband_t output, 2397 | mach_msg_type_number_t *outputCnt) 2398 | { 2399 | // ILP32 - need to remap up to 64 bit scalars 2400 | io_scalar_inband64_t scalarData; 2401 | inflate_vec(scalarData, arrayCnt(scalarData), input, inputCnt); 2402 | 2403 | return IOConnectCallMethod(connection, selector, 2404 | scalarData, inputCnt, 2405 | NULL, 0, 2406 | NULL, NULL, 2407 | output, (size_t *) outputCnt); 2408 | } 2409 | 2410 | kern_return_t 2411 | io_async_method_scalarI_structureO( 2412 | mach_port_t connection, 2413 | mach_port_t wakePort, 2414 | io_async_ref_t reference, 2415 | mach_msg_type_number_t referenceCnt, 2416 | int selector, 2417 | int *input, 2418 | mach_msg_type_number_t inputCnt, 2419 | io_struct_inband_t output, 2420 | mach_msg_type_number_t *outputCnt) 2421 | { 2422 | // ILP32 - need to remap up to 64 bit scalars 2423 | io_scalar_inband64_t scalarData; 2424 | inflate_vec(scalarData, arrayCnt(scalarData), input, inputCnt); 2425 | io_async_ref64_t refrncData; 2426 | inflate_vec(refrncData, arrayCnt(refrncData), (int*)reference, referenceCnt); 2427 | 2428 | return IOConnectCallAsyncMethod(connection, selector, wakePort, 2429 | refrncData, referenceCnt, 2430 | scalarData, inputCnt, 2431 | NULL, 0, 2432 | NULL, NULL, 2433 | output, (size_t *) outputCnt); 2434 | } 2435 | 2436 | 2437 | kern_return_t 2438 | io_connect_method_scalarI_structureI( 2439 | mach_port_t connection, 2440 | int selector, 2441 | io_scalar_inband_t input, 2442 | mach_msg_type_number_t inputCnt, 2443 | io_struct_inband_t inputStruct, 2444 | mach_msg_type_number_t inputStructCnt) 2445 | { 2446 | // ILP32 - need to remap up to 64 bit scalars 2447 | io_scalar_inband64_t scalarData; 2448 | inflate_vec(scalarData, arrayCnt(scalarData), input, inputCnt); 2449 | 2450 | return IOConnectCallMethod(connection, selector, 2451 | scalarData, inputCnt, 2452 | inputStruct, inputStructCnt, 2453 | NULL, NULL, 2454 | NULL, NULL); 2455 | } 2456 | 2457 | kern_return_t 2458 | io_async_method_scalarI_structureI( 2459 | mach_port_t connection, 2460 | mach_port_t wakePort, 2461 | io_async_ref_t reference, 2462 | mach_msg_type_number_t referenceCnt, 2463 | int selector, 2464 | io_scalar_inband_t input, 2465 | mach_msg_type_number_t inputCnt, 2466 | io_struct_inband_t inputStruct, 2467 | mach_msg_type_number_t inputStructCnt) 2468 | { 2469 | // ILP32 - need to remap up to 64 bit scalars 2470 | io_scalar_inband64_t scalarData; 2471 | inflate_vec(scalarData, arrayCnt(scalarData), input, inputCnt); 2472 | io_async_ref64_t refrncData; 2473 | inflate_vec(refrncData, arrayCnt(refrncData), (int*)reference, referenceCnt); 2474 | 2475 | return IOConnectCallAsyncMethod(connection, selector, wakePort, 2476 | refrncData, referenceCnt, 2477 | scalarData, inputCnt, 2478 | inputStruct, inputStructCnt, 2479 | NULL, NULL, 2480 | NULL, NULL); 2481 | } 2482 | 2483 | 2484 | kern_return_t 2485 | io_connect_method_structureI_structureO( 2486 | mach_port_t connection, 2487 | int selector, 2488 | io_struct_inband_t input, 2489 | mach_msg_type_number_t inputCnt, 2490 | io_struct_inband_t output, 2491 | mach_msg_type_number_t *outputCnt) 2492 | { 2493 | return IOConnectCallMethod(connection, selector, 2494 | NULL, 0, 2495 | input, inputCnt, 2496 | NULL, NULL, 2497 | output, (size_t *) outputCnt); 2498 | } 2499 | 2500 | kern_return_t 2501 | io_async_method_structureI_structureO( 2502 | mach_port_t connection, 2503 | mach_port_t wakePort, 2504 | io_async_ref_t reference, 2505 | mach_msg_type_number_t referenceCnt, 2506 | int selector, 2507 | io_struct_inband_t input, 2508 | mach_msg_type_number_t inputCnt, 2509 | io_struct_inband_t output, 2510 | mach_msg_type_number_t *outputCnt) 2511 | { 2512 | // ILP32 - need to remap up to 64 bit scalars 2513 | io_async_ref64_t refrncData; 2514 | inflate_vec(refrncData, arrayCnt(refrncData), (int*)reference, referenceCnt); 2515 | 2516 | return IOConnectCallAsyncMethod(connection, selector, wakePort, 2517 | refrncData, referenceCnt, 2518 | NULL, 0, 2519 | input, inputCnt, 2520 | NULL, NULL, 2521 | output, (size_t *) outputCnt); 2522 | } 2523 | #endif // MAP_32B_METHODS 2524 | 2525 | #if EMULATE_IOCONNECT_64 2526 | kern_return_t io_connect_method 2527 | ( 2528 | mach_port_t connection, 2529 | uint32_t selector, 2530 | io_scalar_inband64_t input, 2531 | mach_msg_type_number_t inputCnt, 2532 | io_struct_inband_t inband_input, 2533 | mach_msg_type_number_t inband_inputCnt, 2534 | mach_vm_address_t ool_input, 2535 | mach_vm_size_t ool_input_size __unused, 2536 | io_scalar_inband64_t output, 2537 | mach_msg_type_number_t *outputCnt, 2538 | io_struct_inband_t inband_output, 2539 | mach_msg_type_number_t *inband_outputCnt, 2540 | mach_vm_address_t ool_output, 2541 | mach_vm_size_t * ool_output_size __unused 2542 | ) 2543 | { 2544 | if (ool_input || ool_output) 2545 | return MIG_ARRAY_TOO_LARGE; 2546 | 2547 | if (inband_input && inband_output) { 2548 | // io_connect_method_structureI_structureO 2549 | return io_connect_method_structureI_structureO(connection, selector, 2550 | inband_input, inband_inputCnt, inband_output, inband_outputCnt); 2551 | } 2552 | 2553 | io_scalar_inband_t inData; 2554 | deflate_vec(inData, arrayCnt(inData), input, inputCnt); 2555 | 2556 | if (inband_input) { 2557 | // io_connect_method_scalarI_structureI 2558 | return io_connect_method_scalarI_structureI(connection, selector, 2559 | inData, inputCnt, inband_input, inband_inputCnt); 2560 | } 2561 | else if (inband_output) { 2562 | // io_connect_method_scalarI_structureO 2563 | return io_connect_method_scalarI_structureO(connection, selector, 2564 | inData, inputCnt, inband_output, inband_outputCnt); 2565 | } 2566 | 2567 | // io_connect_method_scalarI_scalarO 2568 | kern_return_t rtn = io_connect_method_scalarI_scalarO(connection, selector, 2569 | inData, inputCnt, inData, outputCnt); 2570 | inputCnt = (rtn == KERN_SUCCESS && outputCnt)? *outputCnt : 0; 2571 | inflate_vec(output, inputCnt, inData, arrayCnt(inData)); 2572 | return rtn; 2573 | } 2574 | #endif // EMULATE_IOCONNECT_64 2575 | 2576 | #if EMULATE_IOCONNECT_ASYNC_64 2577 | kern_return_t io_connect_async_method 2578 | ( 2579 | mach_port_t connection, 2580 | mach_port_t wake_port, 2581 | io_async_ref64_t reference, 2582 | mach_msg_type_number_t referenceCnt, 2583 | uint32_t selector, 2584 | io_scalar_inband64_t input, 2585 | mach_msg_type_number_t inputCnt, 2586 | io_struct_inband_t inband_input, 2587 | mach_msg_type_number_t inband_inputCnt, 2588 | mach_vm_address_t ool_input, 2589 | mach_vm_size_t ool_input_size __unused, 2590 | io_scalar_inband64_t output, 2591 | mach_msg_type_number_t *outputCnt, 2592 | io_struct_inband_t inband_output, 2593 | mach_msg_type_number_t *inband_outputCnt, 2594 | mach_vm_address_t ool_output, 2595 | mach_vm_size_t * ool_output_size __unused 2596 | ) 2597 | { 2598 | if (ool_input || ool_output) 2599 | return MIG_ARRAY_TOO_LARGE; 2600 | 2601 | io_async_ref_t refData; 2602 | deflate_vec((int*)refData, arrayCnt(refData), reference, referenceCnt); 2603 | 2604 | if (inband_input && inband_output) { 2605 | // io_async_method_structureI_structureO 2606 | return io_async_method_structureI_structureO( 2607 | connection, wake_port, refData, referenceCnt, selector, 2608 | inband_input, inband_inputCnt, inband_output, inband_outputCnt); 2609 | } 2610 | 2611 | io_scalar_inband_t inData; 2612 | deflate_vec(inData, arrayCnt(inData), input, inputCnt); 2613 | 2614 | if (inband_input) { 2615 | // io_async_method_scalarI_structureI 2616 | return io_async_method_scalarI_structureI( 2617 | connection, wake_port, refData, referenceCnt, selector, 2618 | inData, inputCnt, inband_input, inband_inputCnt); 2619 | } 2620 | else if (inband_output) { 2621 | // io_async_method_scalarI_structureO 2622 | return io_async_method_scalarI_structureO( 2623 | connection, wake_port, refData, referenceCnt, selector, 2624 | inData, inputCnt, inband_output, inband_outputCnt); 2625 | } 2626 | 2627 | // io_async_method_scalarI_scalarO 2628 | kern_return_t rtn = io_async_method_scalarI_scalarO( 2629 | connection, wake_port, refData, referenceCnt, selector, 2630 | inData, inputCnt, inData, outputCnt); 2631 | inputCnt = (rtn == KERN_SUCCESS && outputCnt)? *outputCnt : 0; 2632 | inflate_vec(output, inputCnt, inData, arrayCnt(inData)); 2633 | return rtn; 2634 | } 2635 | #endif // EMULATE_IOCONNECT_ASYNC_64 2636 | 2637 | 2638 | #endif /* !__LP64__ */ 2639 | 2640 | -------------------------------------------------------------------------------- /IOKitLib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * The contents of this file constitute Original Code as defined in and 7 | * are subject to the Apple Public Source License Version 1.1 (the 8 | * "License"). You may not use this file except in compliance with the 9 | * License. Please obtain a copy of the License at 10 | * http://www.apple.com/publicsource and read it before using this file. 11 | * 12 | * This Original Code and all software distributed under the License are 13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the 17 | * License for the specific language governing rights and limitations 18 | * under the License. 19 | * 20 | * @APPLE_LICENSE_HEADER_END@ 21 | */ 22 | /* 23 | * HISTORY 24 | * 25 | */ 26 | 27 | /* 28 | * IOKit user library 29 | */ 30 | 31 | #ifndef _IOKIT_IOKITLIB_H 32 | #define _IOKIT_IOKITLIB_H 33 | 34 | #ifdef KERNEL 35 | #error This file is not for kernel use 36 | #endif 37 | 38 | #include 39 | #include 40 | 41 | #include 42 | #include 43 | 44 | #include 45 | #include 46 | #include 47 | 48 | #include "IOTypes.h" 49 | #include "IOKitKeys.h" 50 | 51 | #include "OSMessageNotification.h" 52 | 53 | #include 54 | 55 | __BEGIN_DECLS 56 | 57 | /*! @header IOKitLib 58 | IOKitLib implements non-kernel task access to common IOKit object types - IORegistryEntry, IOService, IOIterator etc. These functions are generic - families may provide API that is more specific.
59 | IOKitLib represents IOKit objects outside the kernel with the types io_object_t, io_registry_entry_t, io_service_t, & io_connect_t. Function names usually begin with the type of object they are compatible with - eg. IOObjectRelease can be used with any io_object_t. Inside the kernel, the c++ class hierarchy allows the subclasses of each object type to receive the same requests from user level clients, for example in the kernel, IOService is a subclass of IORegistryEntry, which means any of the IORegistryEntryXXX functions in IOKitLib may be used with io_service_t's as well as io_registry_t's. There are functions available to introspect the class of the kernel object which any io_object_t et al. represents. 60 | IOKit objects returned by all functions should be released with IOObjectRelease. 61 | */ 62 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 63 | 64 | typedef struct IONotificationPort * IONotificationPortRef; 65 | 66 | 67 | /*! @typedef IOServiceMatchingCallback 68 | @abstract Callback function to be notified of IOService publication. 69 | @param refcon The refcon passed when the notification was installed. 70 | @param iterator The notification iterator which now has new objects. 71 | */ 72 | typedef void 73 | (*IOServiceMatchingCallback)( 74 | void * refcon, 75 | io_iterator_t iterator ); 76 | 77 | /*! @typedef IOServiceInterestCallback 78 | @abstract Callback function to be notified of changes in state of an IOService. 79 | @param refcon The refcon passed when the notification was installed. 80 | @param service The IOService whose state has changed. 81 | @param messageType A messageType enum, defined by IOKit/IOMessage.h or by the IOService's family. 82 | @param messageArgument An argument for the message, dependent on the messageType. 83 | */ 84 | 85 | typedef void 86 | (*IOServiceInterestCallback)( 87 | void * refcon, 88 | io_service_t service, 89 | uint32_t messageType, 90 | void * messageArgument ); 91 | 92 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 93 | 94 | /*! @const kIOMasterPortDefault 95 | @abstract The default mach port used to initiate communication with IOKit. 96 | @discussion When specifying a master port to IOKit functions, the NULL argument indicates "use the default". This is a synonym for NULL, if you'd rather use a named constant. 97 | */ 98 | 99 | extern 100 | const mach_port_t kIOMasterPortDefault; 101 | 102 | /*! @function IOMasterPort 103 | @abstract Returns the mach port used to initiate communication with IOKit. 104 | @discussion Functions that don't specify an existing object require the IOKit master port to be passed. This function obtains that port. 105 | @param bootstrapPort Pass MACH_PORT_NULL for the default. 106 | @param masterPort The master port is returned. 107 | @result A kern_return_t error code. */ 108 | 109 | kern_return_t 110 | IOMasterPort( mach_port_t bootstrapPort, 111 | mach_port_t * masterPort ); 112 | 113 | 114 | /*! @function IONotificationPortCreate 115 | @abstract Creates and returns a notification object for receiving IOKit notifications of new devices or state changes. 116 | @discussion Creates the notification object to receive notifications from IOKit of new device arrivals or state changes. The notification object can be supply a CFRunLoopSource, or mach_port_t to be used to listen for events. 117 | @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 118 | @result A reference to the notification object. */ 119 | 120 | IONotificationPortRef 121 | IONotificationPortCreate( 122 | mach_port_t masterPort ); 123 | 124 | /*! @function IONotificationPortDestroy 125 | @abstract Destroys a notification object created with IONotificationPortCreate. 126 | @param notify A reference to the notification object. */ 127 | 128 | void 129 | IONotificationPortDestroy( 130 | IONotificationPortRef notify ); 131 | 132 | /*! @function IONotificationPortGetRunLoopSource 133 | @abstract Returns a CFRunLoopSource to be used to listen for notifications. 134 | @discussion A notification object may deliver notifications to a CFRunLoop client by adding the run loop source returned by this function to the run loop. 135 | @param notify The notification object. 136 | @result A CFRunLoopSourceRef for the notification object. */ 137 | 138 | CFRunLoopSourceRef 139 | IONotificationPortGetRunLoopSource( 140 | IONotificationPortRef notify ); 141 | 142 | /*! @function IONotificationPortGetMachPort 143 | @abstract Returns a mach_port to be used to listen for notifications. 144 | @discussion A notification object may deliver notifications to a mach messaging client if they listen for messages on the port obtained from this function. Callbacks associated with the notifications may be delivered by calling IODispatchCalloutFromMessage with messages received 145 | @param notify The notification object. 146 | @result A mach_port for the notification object. */ 147 | 148 | mach_port_t 149 | IONotificationPortGetMachPort( 150 | IONotificationPortRef notify ); 151 | 152 | /*! @function IODispatchCalloutFromMessage 153 | @abstract Dispatches callback notifications from a mach message. 154 | @discussion A notification object may deliver notifications to a mach messaging client, which should call this function to generate the callbacks associated with the notifications arriving on the port. 155 | @param unused Not used, set to zero. 156 | @param msg A pointer to the message received. 157 | @param reference Pass the IONotificationPortRef for the object. */ 158 | 159 | void 160 | IODispatchCalloutFromMessage( 161 | void *unused, 162 | mach_msg_header_t *msg, 163 | void *reference ); 164 | 165 | /*! @function IOCreateReceivePort 166 | @abstract Creates and returns a mach port suitable for receiving IOKit messages of the specified type. 167 | @discussion In the future IOKit may use specialized messages and ports 168 | instead of the standard ports created by mach_port_allocate(). Use this 169 | function instead of mach_port_allocate() to ensure compatibility with future 170 | revisions of IOKit. 171 | @param msgType Type of message to be sent to this port 172 | (kOSNotificationMessageID or kOSAsyncCompleteMessageID) 173 | @param recvPort The created port is returned. 174 | @result A kern_return_t error code. */ 175 | 176 | kern_return_t 177 | IOCreateReceivePort( uint32_t msgType, mach_port_t * recvPort ); 178 | 179 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 180 | 181 | /* 182 | * IOObject 183 | */ 184 | 185 | /*! @function IOObjectRelease 186 | @abstract Releases an object handle previously returned by IOKitLib. 187 | @discussion All objects returned by IOKitLib should be released with this function when access to them is no longer needed. Using the object after it has been released may or may not return an error, depending on how many references the task has to the same object in the kernel. 188 | @param object The IOKit object to release. 189 | @result A kern_return_t error code. */ 190 | 191 | kern_return_t 192 | IOObjectRelease( 193 | io_object_t object ); 194 | 195 | /*! @function IOObjectRetain 196 | @abstract Retains an object handle previously returned by IOKitLib. 197 | @discussion Gives the caller an additional reference to an existing object handle previously returned by IOKitLib. 198 | @param object The IOKit object to retain. 199 | @result A kern_return_t error code. */ 200 | 201 | kern_return_t 202 | IOObjectRetain( 203 | io_object_t object ); 204 | 205 | /*! @function IOObjectGetClass 206 | @abstract Return the class name of an IOKit object. 207 | @discussion This function uses the OSMetaClass system in the kernel to derive the name of the class the object is an instance of. 208 | @param object The IOKit object. 209 | @param className Caller allocated buffer to receive the name string. 210 | @result A kern_return_t error code. */ 211 | 212 | kern_return_t 213 | IOObjectGetClass( 214 | io_object_t object, 215 | io_name_t className ); 216 | 217 | /*! @function CFStringRef IOObjectCopyClass 218 | @abstract Return the class name of an IOKit object. 219 | @discussion This function does the same thing as IOObjectGetClass, but returns the result as a CFStringRef. 220 | @param object The IOKit object. 221 | @result The resulting CFStringRef. This should be released by the caller. If a valid object is not passed in, then NULL is returned.*/ 222 | 223 | CFStringRef 224 | IOObjectCopyClass(io_object_t object) 225 | AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; 226 | 227 | /*! @function CFStringRef IOObjectCopySuperclassForClass 228 | @abstract Return the superclass name of the given class. 229 | @discussion This function uses the OSMetaClass system in the kernel to derive the name of the superclass of the class. 230 | @param classname The name of the class as a CFString. 231 | @result The resulting CFStringRef. This should be released by the caller. If there is no superclass, or a valid class name is not passed in, then NULL is returned.*/ 232 | 233 | CFStringRef 234 | IOObjectCopySuperclassForClass(CFStringRef classname) 235 | AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; 236 | 237 | /*! @function CFStringRef IOObjectCopyBundleIdentifierForClass 238 | @abstract Return the bundle identifier of the given class. 239 | @discussion This function uses the OSMetaClass system in the kernel to derive the name of the kmod, which is the same as the bundle identifier. 240 | @param classname The name of the class as a CFString. 241 | @result The resulting CFStringRef. This should be released by the caller. If a valid class name is not passed in, then NULL is returned.*/ 242 | 243 | CFStringRef 244 | IOObjectCopyBundleIdentifierForClass(CFStringRef classname) 245 | AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; 246 | 247 | /*! @function IOObjectConformsTo 248 | @abstract Performs an OSDynamicCast operation on an IOKit object. 249 | @discussion This function uses the OSMetaClass system in the kernel to determine if the object will dynamic cast to a class, specified as a C-string. In other words, if the object is of that class or a subclass. 250 | @param object An IOKit object. 251 | @param className The name of the class, as a C-string. 252 | @result If the object handle is valid, and represents an object in the kernel that dynamic casts to the class true is returned, otherwise false. */ 253 | 254 | boolean_t 255 | IOObjectConformsTo( 256 | io_object_t object, 257 | const io_name_t className ); 258 | 259 | /*! @function IOObjectIsEqualTo 260 | @abstract Checks two object handles to see if they represent the same kernel object. 261 | @discussion If two object handles are returned by IOKitLib functions, this function will compare them to see if they represent the same kernel object. 262 | @param object An IOKit object. 263 | @param anObject Another IOKit object. 264 | @result If both object handles are valid, and represent the same object in the kernel true is returned, otherwise false. */ 265 | 266 | boolean_t 267 | IOObjectIsEqualTo( 268 | io_object_t object, 269 | io_object_t anObject ); 270 | 271 | /*! @function IOObjectGetRetainCount 272 | @abstract Returns kernel retain count of an IOKit object. 273 | @discussion This function may be used in diagnostics to determine the current retain count of the kernel object. 274 | @param object An IOKit object. 275 | @result If the object handle is valid, the kernel objects retain count is returned, otherwise zero is returned. */ 276 | 277 | uint32_t 278 | IOObjectGetRetainCount( 279 | io_object_t object ); 280 | 281 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 282 | 283 | /* 284 | * IOIterator, subclass of IOObject 285 | */ 286 | 287 | /*! @function IOIteratorNext 288 | @abstract Returns the next object in an iteration. 289 | @discussion This function returns the next object in an iteration, or zero if no more remain or the iterator is invalid. 290 | @param iterator An IOKit iterator handle. 291 | @result If the iterator handle is valid, the next element in the iteration is returned, otherwise zero is returned. The element should be released by the caller when it is finished. */ 292 | 293 | io_object_t 294 | IOIteratorNext( 295 | io_iterator_t iterator ); 296 | 297 | /*! @function IOIteratorReset 298 | @abstract Resets an iteration back to the beginning. 299 | @discussion If an iterator is invalid, or if the caller wants to start over, IOIteratorReset will set the iteration back to the beginning. 300 | @param iterator An IOKit iterator handle. */ 301 | 302 | void 303 | IOIteratorReset( 304 | io_iterator_t iterator ); 305 | 306 | /*! @function IOIteratorIsValid 307 | @abstract Checks an iterator is still valid. 308 | @discussion Some iterators will be made invalid if changes are made to the structure they are iterating over. This function checks the iterator is still valid and should be called when IOIteratorNext returns zero. An invalid iterator can be reset and the iteration restarted. 309 | @param iterator An IOKit iterator handle. 310 | @result True if the iterator handle is valid, otherwise false is returned. */ 311 | 312 | boolean_t 313 | IOIteratorIsValid( 314 | io_iterator_t iterator ); 315 | 316 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 317 | 318 | /* 319 | * IOService, subclass of IORegistryEntry 320 | */ 321 | 322 | /*! 323 | @function IOServiceGetMatchingService 324 | @abstract Look up a registered IOService object that matches a matching dictionary. 325 | @discussion This is the preferred method of finding IOService objects currently registered by IOKit (that is, objects that have had their registerService() methods invoked). To find IOService objects that aren't yet registered, use an iterator as created by IORegistryEntryCreateIterator(). IOServiceAddMatchingNotification can also supply this information and install a notification of new IOServices. The matching information used in the matching dictionary may vary depending on the class of service being looked up. 326 | @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 327 | @param matching A CF dictionary containing matching information, of which one reference is always consumed by this function (Note prior to the Tiger release there was a small chance that the dictionary might not be released if there was an error attempting to serialize the dictionary). IOKitLib can construct matching dictionaries for common criteria with helper functions such as IOServiceMatching, IOServiceNameMatching, IOBSDNameMatching, IOOpenFirmwarePathMatching. 328 | @result The first service matched is returned on success. The service must be released by the caller. 329 | */ 330 | 331 | io_service_t 332 | IOServiceGetMatchingService( 333 | mach_port_t masterPort, 334 | CFDictionaryRef matching ); 335 | 336 | /*! @function IOServiceGetMatchingServices 337 | @abstract Look up registered IOService objects that match a matching dictionary. 338 | @discussion This is the preferred method of finding IOService objects currently registered by IOKit (that is, objects that have had their registerService() methods invoked). To find IOService objects that aren't yet registered, use an iterator as created by IORegistryEntryCreateIterator(). IOServiceAddMatchingNotification can also supply this information and install a notification of new IOServices. The matching information used in the matching dictionary may vary depending on the class of service being looked up. 339 | @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 340 | @param matching A CF dictionary containing matching information, of which one reference is always consumed by this function (Note prior to the Tiger release there was a small chance that the dictionary might not be released if there was an error attempting to serialize the dictionary). IOKitLib can construct matching dictionaries for common criteria with helper functions such as IOServiceMatching, IOServiceNameMatching, IOBSDNameMatching, IOOpenFirmwarePathMatching. 341 | @param existing An iterator handle is returned on success, and should be released by the caller when the iteration is finished. 342 | @result A kern_return_t error code. */ 343 | 344 | kern_return_t 345 | IOServiceGetMatchingServices( 346 | mach_port_t masterPort, 347 | CFDictionaryRef matching, 348 | io_iterator_t * existing ); 349 | 350 | 351 | kern_return_t 352 | IOServiceAddNotification( 353 | mach_port_t masterPort, 354 | const io_name_t notificationType, 355 | CFDictionaryRef matching, 356 | mach_port_t wakePort, 357 | uintptr_t reference, 358 | io_iterator_t * notification ) DEPRECATED_ATTRIBUTE; 359 | 360 | /*! @function IOServiceAddMatchingNotification 361 | @abstract Look up registered IOService objects that match a matching dictionary, and install a notification request of new IOServices that match. 362 | @discussion This is the preferred method of finding IOService objects that may arrive at any time. The type of notification specifies the state change the caller is interested in, on IOService's that match the match dictionary. Notification types are identified by name, and are defined in IOKitKeys.h. The matching information used in the matching dictionary may vary depending on the class of service being looked up. 363 | @param notifyPort A IONotificationPortRef object that controls how messages will be sent when the armed notification is fired. When the notification is delivered, the io_iterator_t representing the notification should be iterated through to pick up all outstanding objects. When the iteration is finished the notification is rearmed. See IONotificationPortCreate. 364 | @param notificationType A notification type from IOKitKeys.h 365 |
kIOPublishNotification Delivered when an IOService is registered. 366 |
kIOFirstPublishNotification Delivered when an IOService is registered, but only once per IOService instance. Some IOService's may be reregistered when their state is changed. 367 |
kIOMatchedNotification Delivered when an IOService has had all matching drivers in the kernel probed and started. 368 |
kIOFirstMatchNotification Delivered when an IOService has had all matching drivers in the kernel probed and started, but only once per IOService instance. Some IOService's may be reregistered when their state is changed. 369 |
kIOTerminatedNotification Delivered after an IOService has been terminated. 370 | @param matching A CF dictionary containing matching information, of which one reference is always consumed by this function (Note prior to the Tiger release there was a small chance that the dictionary might not be released if there was an error attempting to serialize the dictionary). IOKitLib can construct matching dictionaries for common criteria with helper functions such as IOServiceMatching, IOServiceNameMatching, IOBSDNameMatching, IOOpenFirmwarePathMatching. 371 | @param callback A callback function called when the notification fires. 372 | @param refCon A reference constant for the callbacks use. 373 | @param notification An iterator handle is returned on success, and should be released by the caller when the notification is to be destroyed. The notification is armed when the iterator is emptied by calls to IOIteratorNext - when no more objects are returned, the notification is armed. Note the notification is not armed when first created. 374 | @result A kern_return_t error code. */ 375 | 376 | kern_return_t 377 | IOServiceAddMatchingNotification( 378 | IONotificationPortRef notifyPort, 379 | const io_name_t notificationType, 380 | CFDictionaryRef matching, 381 | IOServiceMatchingCallback callback, 382 | void * refCon, 383 | io_iterator_t * notification ); 384 | 385 | /*! @function IOServiceAddInterestNotification 386 | @abstract Register for notification of state changes in an IOService. 387 | @discussion IOService objects deliver notifications of their state changes to their clients via the IOService::message API, and to other interested parties including callers of this function. Message type s are defined IOKit/IOMessage.h. 388 | @param notifyPort A IONotificationPortRef object that controls how messages will be sent when the notification is fired. See IONotificationPortCreate. 389 | @param interestType A notification type from IOKitKeys.h 390 |
kIOGeneralInterest General state changes delivered via the IOService::message API. 391 |
kIOBusyInterest Delivered when the IOService changes its busy state to or from zero. The message argument contains the new busy state causing the notification. 392 | @param callback A callback function called when the notification fires, with messageType and messageArgument for the state change. 393 | @param refCon A reference constant for the callbacks use. 394 | @param notification An object handle is returned on success, and should be released by the caller when the notification is to be destroyed. 395 | @result A kern_return_t error code. */ 396 | 397 | kern_return_t 398 | IOServiceAddInterestNotification( 399 | IONotificationPortRef notifyPort, 400 | io_service_t service, 401 | const io_name_t interestType, 402 | IOServiceInterestCallback callback, 403 | void * refCon, 404 | io_object_t * notification ); 405 | 406 | /*! @function IOServiceMatchPropertyTable 407 | @abstract Match an IOService objects with matching dictionary. 408 | @discussion This function calls the matching method of an IOService object and returns the boolean result. 409 | @param service The IOService object to match. 410 | @param matching A CF dictionary containing matching information. IOKitLib can construct matching dictionaries for common criteria with helper functions such as IOServiceMatching, IOServiceNameMatching, IOBSDNameMatching, IOOpenFirmwarePathMatching. 411 | @param matches The boolean result is returned. 412 | @result A kern_return_t error code. */ 413 | 414 | kern_return_t 415 | IOServiceMatchPropertyTable( 416 | io_service_t service, 417 | CFDictionaryRef matching, 418 | boolean_t * matches ); 419 | 420 | /*! @function IOServiceGetBusyState 421 | @abstract Returns the busyState of an IOService. 422 | @discussion Many activities in IOService are asynchronous. When registration, matching, or termination is in progress on an IOService, its busyState is increased by one. Change in busyState to or from zero also changes the IOService's provider's busyState by one, which means that an IOService is marked busy when any of the above activities is ocurring on it or any of its clients. 423 | @param service The IOService whose busyState to return. 424 | @param busyState The busyState count is returned. 425 | @result A kern_return_t error code. */ 426 | 427 | kern_return_t 428 | IOServiceGetBusyState( 429 | io_service_t service, 430 | uint32_t * busyState ); 431 | 432 | /*! @function IOServiceWaitQuiet 433 | @abstract Wait for an IOService's busyState to be zero. 434 | @discussion Blocks the caller until an IOService is non busy, see IOServiceGetBusyState. 435 | @param service The IOService wait on. 436 | @param waitTime Specifies a maximum time to wait. 437 | @result Returns an error code if mach synchronization primitives fail, kIOReturnTimeout, or kIOReturnSuccess. */ 438 | 439 | kern_return_t 440 | IOServiceWaitQuiet( 441 | io_service_t service, 442 | mach_timespec_t * waitTime ); 443 | 444 | /*! @function IOKitGetBusyState 445 | @abstract Returns the busyState of all IOServices. 446 | @discussion Many activities in IOService are asynchronous. When registration, matching, or termination is in progress on an IOService, its busyState is increased by one. Change in busyState to or from zero also changes the IOService's provider's busyState by one, which means that an IOService is marked busy when any of the above activities is ocurring on it or any of its clients. IOKitGetBusyState returns the busy state of the root of the service plane which reflects the busy state of all IOServices. 447 | @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 448 | @param busyState The busyState count is returned. 449 | @result A kern_return_t error code. */ 450 | 451 | kern_return_t 452 | IOKitGetBusyState( 453 | mach_port_t masterPort, 454 | uint32_t * busyState ); 455 | 456 | /*! @function IOKitWaitQuiet 457 | @abstract Wait for a all IOServices' busyState to be zero. 458 | @discussion Blocks the caller until all IOServices are non busy, see IOKitGetBusyState. 459 | @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 460 | @param waitTime Specifies a maximum time to wait. 461 | @result Returns an error code if mach synchronization primitives fail, kIOReturnTimeout, or kIOReturnSuccess. */ 462 | 463 | kern_return_t 464 | IOKitWaitQuiet( 465 | mach_port_t masterPort, 466 | mach_timespec_t * waitTime ); 467 | 468 | /*! @function IOServiceOpen 469 | @abstract A request to create a connection to an IOService. 470 | @discussion A non kernel client may request a connection be opened via the IOServiceOpen() library function, which will call IOService::newUserClient in the kernel. The rules & capabilities of user level clients are family dependent, the default IOService implementation returns kIOReturnUnsupported. 471 | @param service The IOService object to open a connection to, usually obtained via the IOServiceGetMatchingServices or IOServiceAddNotification APIs. 472 | @param owningTask The mach task requesting the connection. 473 | @param type A constant specifying the type of connection to be created, interpreted only by the IOService's family. 474 | @param connect An io_connect_t handle is returned on success, to be used with the IOConnectXXX APIs. It should be destroyed with IOServiceClose(). 475 | @result A return code generated by IOService::newUserClient. */ 476 | 477 | kern_return_t 478 | IOServiceOpen( 479 | io_service_t service, 480 | task_port_t owningTask, 481 | uint32_t type, 482 | io_connect_t * connect ); 483 | 484 | /*! @function IOServiceRequestProbe 485 | @abstract A request to rescan a bus for device changes. 486 | @discussion A non kernel client may request a bus or controller rescan for added or removed devices, if the bus family does automatically notice such changes. For example, SCSI bus controllers do not notice device changes. The implementation of this routine is family dependent, and the default IOService implementation returns kIOReturnUnsupported. 487 | @param service The IOService object to request a rescan, usually obtained via the IOServiceGetMatchingServices or IOServiceAddNotification APIs. 488 | @param options An options mask, interpreted only by the IOService's family. 489 | @result A return code generated by IOService::requestProbe. */ 490 | 491 | kern_return_t 492 | IOServiceRequestProbe( 493 | io_service_t service, 494 | uint32_t options ); 495 | 496 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 497 | 498 | /* 499 | * IOService connection 500 | */ 501 | 502 | /*! @function IOServiceClose 503 | @abstract Close a connection to an IOService and destroy the connect handle. 504 | @discussion A connection created with the IOServiceOpen should be closed when the connection is no longer to be used with IOServiceClose. 505 | @param connect The connect handle created by IOServiceOpen. It will be destroyed by this function, and should not be released with IOObjectRelease. 506 | @result A kern_return_t error code. */ 507 | 508 | kern_return_t 509 | IOServiceClose( 510 | io_connect_t connect ); 511 | 512 | /*! @function IOConnectAddRef 513 | @abstract Adds a reference to the connect handle. 514 | @discussion Adds a reference to the connect handle. 515 | @param connect The connect handle created by IOServiceOpen. 516 | @result A kern_return_t error code. */ 517 | 518 | kern_return_t 519 | IOConnectAddRef( 520 | io_connect_t connect ); 521 | 522 | /*! @function IOConnectRelease 523 | @abstract Remove a reference to the connect handle. 524 | @discussion Removes a reference to the connect handle. If the last reference is removed an implicit IOServiceClose is performed. 525 | @param connect The connect handle created by IOServiceOpen. 526 | @result A kern_return_t error code. */ 527 | 528 | kern_return_t 529 | IOConnectRelease( 530 | io_connect_t connect ); 531 | 532 | /*! @function IOConnectGetService 533 | @abstract Returns the IOService a connect handle was opened on. 534 | @discussion Finds the service object a connection was opened on. 535 | @param connect The connect handle created by IOServiceOpen. 536 | @param service On succes, the service handle the connection was opened on, which should be released with IOObjectRelease. 537 | @result A kern_return_t error code. */ 538 | 539 | kern_return_t 540 | IOConnectGetService( 541 | io_connect_t connect, 542 | io_service_t * service ); 543 | 544 | /*! @function IOConnectSetNotificationPort 545 | @abstract Set a port to receive family specific notifications. 546 | @discussion This is a generic method to pass a mach port send right to be be used by family specific notifications. 547 | @param connect The connect handle created by IOServiceOpen. 548 | @param type The type of notification requested, not interpreted by IOKit and family defined. 549 | @param port The port to which to send notifications. 550 | @param reference Some families may support passing a reference parameter for the callers use with the notification. 551 | @result A kern_return_t error code. */ 552 | 553 | kern_return_t 554 | IOConnectSetNotificationPort( 555 | io_connect_t connect, 556 | uint32_t type, 557 | mach_port_t port, 558 | uintptr_t reference ); 559 | 560 | /*! @function IOConnectMapMemory 561 | @abstract Map hardware or shared memory into the caller's task. 562 | @discussion This is a generic method to create a mapping in the callers task. The family will interpret the type parameter to determine what sort of mapping is being requested. Cache modes and placed mappings may be requested by the caller. 563 | @param connect The connect handle created by IOServiceOpen. 564 | @param memoryType What is being requested to be mapped, not interpreted by IOKit and family defined. The family may support physical hardware or shared memory mappings. 565 | @param intoTask The task port for the task in which to create the mapping. This may be different to the task which the opened the connection. 566 | @param atAddress An in/out parameter - if the kIOMapAnywhere option is not set, the caller should pass the address where it requests the mapping be created, otherwise nothing need to set on input. The address of the mapping created is passed back on sucess. 567 | @param ofSize The size of the mapping created is passed back on success. 568 | @result A kern_return_t error code. */ 569 | 570 | #if !__LP64__ 571 | kern_return_t 572 | IOConnectMapMemory( 573 | io_connect_t connect, 574 | uint32_t memoryType, 575 | task_port_t intoTask, 576 | vm_address_t *atAddress, 577 | vm_size_t *ofSize, 578 | IOOptionBits options ); 579 | 580 | kern_return_t IOConnectMapMemory64 581 | #else 582 | kern_return_t IOConnectMapMemory 583 | #endif 584 | (io_connect_t connect, 585 | uint32_t memoryType, 586 | task_port_t intoTask, 587 | mach_vm_address_t *atAddress, 588 | mach_vm_size_t *ofSize, 589 | IOOptionBits options ); 590 | 591 | /*! @function IOConnectUnmapMemory 592 | @abstract Remove a mapping made with IOConnectMapMemory. 593 | @discussion This is a generic method to remove a mapping in the callers task. 594 | @param connect The connect handle created by IOServiceOpen. 595 | @param memoryType The memory type originally requested in IOConnectMapMemory. 596 | @param intoTask The task port for the task in which to remove the mapping. This may be different to the task which the opened the connection. 597 | @param atAddress The address of the mapping to be removed. 598 | @result A kern_return_t error code. */ 599 | 600 | #if !__LP64__ 601 | kern_return_t 602 | IOConnectUnmapMemory( 603 | io_connect_t connect, 604 | uint32_t memoryType, 605 | task_port_t fromTask, 606 | vm_address_t atAddress ); 607 | 608 | kern_return_t IOConnectUnmapMemory64 609 | #else 610 | kern_return_t IOConnectUnmapMemory 611 | #endif 612 | (io_connect_t connect, 613 | uint32_t memoryType, 614 | task_port_t fromTask, 615 | mach_vm_address_t atAddress ); 616 | 617 | /*! @function IOConnectSetCFProperties 618 | @abstract Set CF container based properties on a connection. 619 | @discussion This is a generic method to pass a CF container of properties to the connection. The properties are interpreted by the family and commonly represent configuration settings, but may be interpreted as anything. 620 | @param connect The connect handle created by IOServiceOpen. 621 | @param properties A CF container - commonly a CFDictionary but this is not enforced. The container should consist of objects which are understood by IOKit - these are currently : CFDictionary, CFArray, CFSet, CFString, CFData, CFNumber, CFBoolean, and are passed in the kernel as the corresponding OSDictionary etc. objects. 622 | @result A kern_return_t error code returned by the family. */ 623 | 624 | kern_return_t 625 | IOConnectSetCFProperties( 626 | io_connect_t connect, 627 | CFTypeRef properties ); 628 | 629 | /*! @function IOConnectSetCFProperty 630 | @abstract Set a CF container based property on a connection. 631 | @discussion This is a generic method to pass a CF property to the connection. The property is interpreted by the family and commonly represent configuration settings, but may be interpreted as anything. 632 | @param connect The connect handle created by IOServiceOpen. 633 | @param propertyName The name of the property as a CFString. 634 | @param property A CF container - should consist of objects which are understood by IOKit - these are currently : CFDictionary, CFArray, CFSet, CFString, CFData, CFNumber, CFBoolean, and are passed in the kernel as the corresponding OSDictionary etc. objects. 635 | @result A kern_return_t error code returned by the object. */ 636 | 637 | kern_return_t 638 | IOConnectSetCFProperty( 639 | io_connect_t connect, 640 | CFStringRef propertyName, 641 | CFTypeRef property ); 642 | 643 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 644 | 645 | // Combined LP64 & ILP32 Extended IOUserClient::externalMethod 646 | 647 | kern_return_t 648 | IOConnectCallMethod( 649 | mach_port_t connection, // In 650 | uint32_t selector, // In 651 | const uint64_t *input, // In 652 | uint32_t inputCnt, // In 653 | const void *inputStruct, // In 654 | size_t inputStructCnt, // In 655 | uint64_t *output, // Out 656 | uint32_t *outputCnt, // In/Out 657 | void *outputStruct, // Out 658 | size_t *outputStructCnt) // In/Out 659 | AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; 660 | 661 | kern_return_t 662 | IOConnectCallAsyncMethod( 663 | mach_port_t connection, // In 664 | uint32_t selector, // In 665 | mach_port_t wake_port, // In 666 | uint64_t *reference, // In 667 | uint32_t referenceCnt, // In 668 | const uint64_t *input, // In 669 | uint32_t inputCnt, // In 670 | const void *inputStruct, // In 671 | size_t inputStructCnt, // In 672 | uint64_t *output, // Out 673 | uint32_t *outputCnt, // In/Out 674 | void *outputStruct, // Out 675 | size_t *outputStructCnt) // In/Out 676 | AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; 677 | 678 | kern_return_t 679 | IOConnectCallStructMethod( 680 | mach_port_t connection, // In 681 | uint32_t selector, // In 682 | const void *inputStruct, // In 683 | size_t inputStructCnt, // In 684 | void *outputStruct, // Out 685 | size_t *outputStructCnt) // In/Out 686 | AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; 687 | 688 | kern_return_t 689 | IOConnectCallAsyncStructMethod( 690 | mach_port_t connection, // In 691 | uint32_t selector, // In 692 | mach_port_t wake_port, // In 693 | uint64_t *reference, // In 694 | uint32_t referenceCnt, // In 695 | const void *inputStruct, // In 696 | size_t inputStructCnt, // In 697 | void *outputStruct, // Out 698 | size_t *outputStructCnt) // In/Out 699 | AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; 700 | 701 | kern_return_t 702 | IOConnectCallScalarMethod( 703 | mach_port_t connection, // In 704 | uint32_t selector, // In 705 | const uint64_t *input, // In 706 | uint32_t inputCnt, // In 707 | uint64_t *output, // Out 708 | uint32_t *outputCnt) // In/Out 709 | AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; 710 | 711 | kern_return_t 712 | IOConnectCallAsyncScalarMethod( 713 | mach_port_t connection, // In 714 | uint32_t selector, // In 715 | mach_port_t wake_port, // In 716 | uint64_t *reference, // In 717 | uint32_t referenceCnt, // In 718 | const uint64_t *input, // In 719 | uint32_t inputCnt, // In 720 | uint64_t *output, // Out 721 | uint32_t *outputCnt) // In/Out 722 | AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; 723 | 724 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 725 | 726 | kern_return_t 727 | IOConnectTrap0(io_connect_t connect, 728 | uint32_t index ); 729 | 730 | kern_return_t 731 | IOConnectTrap1(io_connect_t connect, 732 | uint32_t index, 733 | uintptr_t p1 ); 734 | 735 | kern_return_t 736 | IOConnectTrap2(io_connect_t connect, 737 | uint32_t index, 738 | uintptr_t p1, 739 | uintptr_t p2); 740 | 741 | kern_return_t 742 | IOConnectTrap3(io_connect_t connect, 743 | uint32_t index, 744 | uintptr_t p1, 745 | uintptr_t p2, 746 | uintptr_t p3); 747 | 748 | kern_return_t 749 | IOConnectTrap4(io_connect_t connect, 750 | uint32_t index, 751 | uintptr_t p1, 752 | uintptr_t p2, 753 | uintptr_t p3, 754 | uintptr_t p4); 755 | 756 | kern_return_t 757 | IOConnectTrap5(io_connect_t connect, 758 | uint32_t index, 759 | uintptr_t p1, 760 | uintptr_t p2, 761 | uintptr_t p3, 762 | uintptr_t p4, 763 | uintptr_t p5); 764 | 765 | kern_return_t 766 | IOConnectTrap6(io_connect_t connect, 767 | uint32_t index, 768 | uintptr_t p1, 769 | uintptr_t p2, 770 | uintptr_t p3, 771 | uintptr_t p4, 772 | uintptr_t p5, 773 | uintptr_t p6); 774 | 775 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 776 | 777 | /*! @function IOConnectAddClient 778 | @abstract Inform a connection of a second connection. 779 | @discussion This is a generic method to inform a family connection of a second connection, and is rarely used. 780 | @param connect The connect handle created by IOServiceOpen. 781 | @param client Another connect handle created by IOServiceOpen. 782 | @result A kern_return_t error code returned by the family. */ 783 | 784 | kern_return_t 785 | IOConnectAddClient( 786 | io_connect_t connect, 787 | io_connect_t client ); 788 | 789 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 790 | 791 | /* 792 | * IORegistry accessors 793 | */ 794 | 795 | /*! @function IORegistryGetRootEntry 796 | @abstract Return a handle to the registry root. 797 | @discussion This method provides an accessor to the root of the registry for the machine. The root may be passed to a registry iterator when iterating a plane, and contains properties that describe the available planes, and diagnostic information for IOKit. 798 | @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 799 | @result A handle to the IORegistryEntry root instance, to be released with IOObjectRelease by the caller, or MACH_PORT_NULL on failure. */ 800 | 801 | io_registry_entry_t 802 | IORegistryGetRootEntry( 803 | mach_port_t masterPort ); 804 | 805 | /*! @function IORegistryEntryFromPath 806 | @abstract Looks up a registry entry by path. 807 | @discussion This function parses paths to lookup registry entries. The path should begin with ':' If there are characters remaining unparsed after an entry has been looked up, this is considered an invalid lookup. Paths are further documented in IORegistryEntry.h 808 | @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 809 | @param path A C-string path. 810 | @result A handle to the IORegistryEntry witch was found with the path, to be released with IOObjectRelease by the caller, or MACH_PORT_NULL on failure. */ 811 | 812 | io_registry_entry_t 813 | IORegistryEntryFromPath( 814 | mach_port_t masterPort, 815 | const io_string_t path ); 816 | 817 | // options for IORegistryCreateIterator(), IORegistryEntryCreateIterator, IORegistryEntrySearchCFProperty() 818 | enum { 819 | kIORegistryIterateRecursively = 0x00000001, 820 | kIORegistryIterateParents = 0x00000002 821 | }; 822 | 823 | /*! @function IORegistryCreateIterator 824 | @abstract Create an iterator rooted at the registry root. 825 | @discussion This method creates an IORegistryIterator in the kernel that is set up with options to iterate children of the registry root entry, and to recurse automatically into entries as they are returned, or only when instructed with calls to IORegistryIteratorEnterEntry. The iterator object keeps track of entries that have been recursed into previously to avoid loops. 826 | @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 827 | @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 828 | @param options kIORegistryIterateRecursively may be set to recurse automatically into each entry as it is returned from IOIteratorNext calls on the registry iterator. 829 | @param iterator A created iterator handle, to be released by the caller when it has finished with it. 830 | @result A kern_return_t error code. */ 831 | 832 | kern_return_t 833 | IORegistryCreateIterator( 834 | mach_port_t masterPort, 835 | const io_name_t plane, 836 | IOOptionBits options, 837 | io_iterator_t * iterator ); 838 | 839 | /*! @function IORegistryEntryCreateIterator 840 | @abstract Create an iterator rooted at a given registry entry. 841 | @discussion This method creates an IORegistryIterator in the kernel that is set up with options to iterate children or parents of a root entry, and to recurse automatically into entries as they are returned, or only when instructed with calls to IORegistryIteratorEnterEntry. The iterator object keeps track of entries that have been recursed into previously to avoid loops. 842 | @param entry The root entry to begin the iteration at. 843 | @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 844 | @param options kIORegistryIterateRecursively may be set to recurse automatically into each entry as it is returned from IOIteratorNext calls on the registry iterator. kIORegistryIterateParents may be set to iterate the parents of each entry, by default the children are iterated. 845 | @param iterator A created iterator handle, to be released by the caller when it has finished with it. 846 | @result A kern_return_t error code. */ 847 | 848 | kern_return_t 849 | IORegistryEntryCreateIterator( 850 | io_registry_entry_t entry, 851 | const io_name_t plane, 852 | IOOptionBits options, 853 | io_iterator_t * iterator ); 854 | 855 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 856 | 857 | /* 858 | * IORegistryIterator, subclass of IOIterator 859 | */ 860 | 861 | /*! @function IORegistryIteratorEnterEntry 862 | @abstract Recurse into the current entry in the registry iteration. 863 | @discussion This method makes the current entry, ie. the last entry returned by IOIteratorNext, the root in a new level of recursion. 864 | @result A kern_return_t error code. */ 865 | 866 | kern_return_t 867 | IORegistryIteratorEnterEntry( 868 | io_iterator_t iterator ); 869 | 870 | /*! @function IORegistryIteratorExitEntry 871 | @abstract Exits a level of recursion, restoring the current entry. 872 | @discussion This method undoes an IORegistryIteratorEnterEntry, restoring the current entry. If there are no more levels of recursion to exit false is returned, otherwise true is returned. 873 | @result kIOReturnSuccess if a level of recursion was undone, kIOReturnNoDevice if no recursive levels are left in the iteration. */ 874 | 875 | kern_return_t 876 | IORegistryIteratorExitEntry( 877 | io_iterator_t iterator ); 878 | 879 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 880 | 881 | /* 882 | * IORegistryEntry, subclass of IOObject 883 | */ 884 | 885 | /*! @function IORegistryEntryGetName 886 | @abstract Returns a C-string name assigned to a registry entry. 887 | @discussion Registry entries can be named in a particular plane, or globally. This function returns the entry's global name. The global name defaults to the entry's meta class name if it has not been named. 888 | @param entry The registry entry handle whose name to look up. 889 | @param name The caller's buffer to receive the name. 890 | @result A kern_return_t error code. */ 891 | 892 | kern_return_t 893 | IORegistryEntryGetName( 894 | io_registry_entry_t entry, 895 | io_name_t name ); 896 | 897 | /*! @function IORegistryEntryGetNameInPlane 898 | @abstract Returns a C-string name assigned to a registry entry, in a specified plane. 899 | @discussion Registry entries can be named in a particular plane, or globally. This function returns the entry's name in the specified plane or global name if it has not been named in that plane. The global name defaults to the entry's meta class name if it has not been named. 900 | @param entry The registry entry handle whose name to look up. 901 | @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 902 | @param name The caller's buffer to receive the name. 903 | @result A kern_return_t error code. */ 904 | 905 | kern_return_t 906 | IORegistryEntryGetNameInPlane( 907 | io_registry_entry_t entry, 908 | const io_name_t plane, 909 | io_name_t name ); 910 | 911 | /*! @function IORegistryEntryGetLocationInPlane 912 | @abstract Returns a C-string location assigned to a registry entry, in a specified plane. 913 | @discussion Registry entries can given a location string in a particular plane, or globally. If the entry has had a location set in the specified plane that location string will be returned, otherwise the global location string is returned. If no global location string has been set, an error is returned. 914 | @param entry The registry entry handle whose name to look up. 915 | @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 916 | @param location The caller's buffer to receive the location string. 917 | @result A kern_return_t error code. */ 918 | 919 | kern_return_t 920 | IORegistryEntryGetLocationInPlane( 921 | io_registry_entry_t entry, 922 | const io_name_t plane, 923 | io_name_t location ); 924 | 925 | /*! @function IORegistryEntryGetPath 926 | @abstract Create a path for a registry entry. 927 | @discussion The path for a registry entry is copied to the caller's buffer. The path describes the entry's attachment in a particular plane, which must be specified. The path begins with the plane name followed by a colon, and then followed by '/' separated path components for each of the entries between the root and the registry entry. An alias may also exist for the entry, and will be returned if available. 928 | @param entry The registry entry handle whose path to look up. 929 | @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 930 | @param path A char buffer allocated by the caller. 931 | @result IORegistryEntryGetPath will fail if the entry is not attached in the plane, or if the buffer is not large enough to contain the path. */ 932 | 933 | kern_return_t 934 | IORegistryEntryGetPath( 935 | io_registry_entry_t entry, 936 | const io_name_t plane, 937 | io_string_t path ); 938 | 939 | /*! @function IORegistryEntryCreateCFProperties 940 | @abstract Create a CF dictionary representation of a registry entry's property table. 941 | @discussion This function creates an instantaneous snapshot of a registry entry's property table, creating a CFDictionary analogue in the caller's task. Not every object available in the kernel is represented as a CF container; currently OSDictionary, OSArray, OSSet, OSSymbol, OSString, OSData, OSNumber, OSBoolean are created as their CF counterparts. 942 | @param entry The registry entry handle whose property table to copy. 943 | @param properties A CFDictionary is created and returned the caller on success. The caller should release with CFRelease. 944 | @param allocator The CF allocator to use when creating the CF containers. 945 | @param options No options are currently defined. 946 | @result A kern_return_t error code. */ 947 | 948 | kern_return_t 949 | IORegistryEntryCreateCFProperties( 950 | io_registry_entry_t entry, 951 | CFMutableDictionaryRef * properties, 952 | CFAllocatorRef allocator, 953 | IOOptionBits options ); 954 | 955 | /*! @function IORegistryEntryCreateCFProperty 956 | @abstract Create a CF representation of a registry entry's property. 957 | @discussion This function creates an instantaneous snapshot of a registry entry property, creating a CF container analogue in the caller's task. Not every object available in the kernel is represented as a CF container; currently OSDictionary, OSArray, OSSet, OSSymbol, OSString, OSData, OSNumber, OSBoolean are created as their CF counterparts. 958 | @param entry The registry entry handle whose property to copy. 959 | @param key A CFString specifying the property name. 960 | @param allocator The CF allocator to use when creating the CF container. 961 | @param options No options are currently defined. 962 | @result A CF container is created and returned the caller on success. The caller should release with CFRelease. */ 963 | 964 | CFTypeRef 965 | IORegistryEntryCreateCFProperty( 966 | io_registry_entry_t entry, 967 | CFStringRef key, 968 | CFAllocatorRef allocator, 969 | IOOptionBits options ); 970 | 971 | /*! @function IORegistryEntrySearchCFProperty 972 | @abstract Create a CF representation of a registry entry's property. 973 | @discussion This function creates an instantaneous snapshot of a registry entry property, creating a CF container analogue in the caller's task. Not every object available in the kernel is represented as a CF container; currently OSDictionary, OSArray, OSSet, OSSymbol, OSString, OSData, OSNumber, OSBoolean are created as their CF counterparts. 974 | This function will search for a property, starting first with specified registry entry's property table, then iterating recusively through either the parent registry entries or the child registry entries of this entry. Once the first occurrence is found, it will lookup and return the value of the property, using the same semantics as IORegistryEntryCreateCFProperty. The iteration keeps track of entries that have been recursed into previously to avoid loops. 975 | @param entry The registry entry at which to start the search. 976 | @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 977 | @param key A CFString specifying the property name. 978 | @param allocator The CF allocator to use when creating the CF container. 979 | @param options kIORegistryIterateRecursively may be set to recurse automatically into the registry hierarchy. Without this option, this method degenerates into the standard IORegistryEntryCreateCFProperty() call. kIORegistryIterateParents may be set to iterate the parents of the entry, in place of the children. 980 | @result A CF container is created and returned the caller on success. The caller should release with CFRelease. */ 981 | 982 | CFTypeRef 983 | IORegistryEntrySearchCFProperty( 984 | io_registry_entry_t entry, 985 | const io_name_t plane, 986 | CFStringRef key, 987 | CFAllocatorRef allocator, 988 | IOOptionBits options ); 989 | 990 | /* @function IORegistryEntryGetProperty - deprecated, 991 | use IORegistryEntryCreateCFProperty */ 992 | 993 | kern_return_t 994 | IORegistryEntryGetProperty( 995 | io_registry_entry_t entry, 996 | const io_name_t propertyName, 997 | io_struct_inband_t buffer, 998 | uint32_t * size ); 999 | 1000 | /*! @function IORegistryEntrySetCFProperties 1001 | @abstract Set CF container based properties in a registry entry. 1002 | @discussion This is a generic method to pass a CF container of properties to an object in the registry. Setting properties in a registry entry is not generally supported, it is more common to support IOConnectSetCFProperties for connection based property setting. The properties are interpreted by the object. 1003 | @param entry The registry entry whose properties to set. 1004 | @param properties A CF container - commonly a CFDictionary but this is not enforced. The container should consist of objects which are understood by IOKit - these are currently : CFDictionary, CFArray, CFSet, CFString, CFData, CFNumber, CFBoolean, and are passed in the kernel as the corresponding OSDictionary etc. objects. 1005 | @result A kern_return_t error code returned by the object. */ 1006 | 1007 | kern_return_t 1008 | IORegistryEntrySetCFProperties( 1009 | io_registry_entry_t entry, 1010 | CFTypeRef properties ); 1011 | 1012 | /*! @function IORegistryEntrySetCFProperty 1013 | @abstract Set a CF container based property in a registry entry. 1014 | @discussion This is a generic method to pass a CF container as a property to an object in the registry. Setting properties in a registry entry is not generally supported, it is more common to support IOConnectSetCFProperty for connection based property setting. The property is interpreted by the object. 1015 | @param entry The registry entry whose property to set. 1016 | @param propertyName The name of the property as a CFString. 1017 | @param property A CF container - should consist of objects which are understood by IOKit - these are currently : CFDictionary, CFArray, CFSet, CFString, CFData, CFNumber, CFBoolean, and are passed in the kernel as the corresponding OSDictionary etc. objects. 1018 | @result A kern_return_t error code returned by the object. */ 1019 | 1020 | kern_return_t 1021 | IORegistryEntrySetCFProperty( 1022 | io_registry_entry_t entry, 1023 | CFStringRef propertyName, 1024 | CFTypeRef property ); 1025 | 1026 | /*! @function IORegistryEntryGetChildIterator 1027 | @abstract Returns an iterator over an registry entry's child entries in a plane. 1028 | @discussion This method creates an iterator which will return each of a registry entry's child entries in a specified plane. 1029 | @param entry The registry entry whose children to iterate over. 1030 | @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 1031 | @param iterator The created iterator over the children of the entry, on success. The iterator must be released when the iteration is finished. 1032 | @result A kern_return_t error code. */ 1033 | 1034 | kern_return_t 1035 | IORegistryEntryGetChildIterator( 1036 | io_registry_entry_t entry, 1037 | const io_name_t plane, 1038 | io_iterator_t * iterator ); 1039 | 1040 | /*! @function IORegistryEntryGetChildEntry 1041 | @abstract Returns the first child of a registry entry in a plane. 1042 | @discussion This function will return the child which first attached to a registry entry in a plane. 1043 | @param entry The registry entry whose child to look up. 1044 | @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 1045 | @param child The first child of the registry entry, on success. The child must be released by the caller. 1046 | @result A kern_return_t error code. */ 1047 | 1048 | kern_return_t 1049 | IORegistryEntryGetChildEntry( 1050 | io_registry_entry_t entry, 1051 | const io_name_t plane, 1052 | io_registry_entry_t * child ); 1053 | 1054 | /*! @function IORegistryEntryGetParentIterator 1055 | @abstract Returns an iterator over an registry entry's parent entries in a plane. 1056 | @discussion This method creates an iterator which will return each of a registry entry's parent entries in a specified plane. 1057 | @param entry The registry entry whose parents to iterate over. 1058 | @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 1059 | @param iterator The created iterator over the parents of the entry, on success. The iterator must be released when the iteration is finished. 1060 | @result A kern_return_t error. */ 1061 | 1062 | kern_return_t 1063 | IORegistryEntryGetParentIterator( 1064 | io_registry_entry_t entry, 1065 | const io_name_t plane, 1066 | io_iterator_t * iterator ); 1067 | 1068 | /*! @function IORegistryEntryGetParentEntry 1069 | @abstract Returns the first parent of a registry entry in a plane. 1070 | @discussion This function will return the parent to which the registry entry was first attached in a plane. 1071 | @param entry The registry entry whose parent to look up. 1072 | @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 1073 | @param child The first parent of the registry entry, on success. The parent must be released by the caller. 1074 | @result A kern_return_t error code. */ 1075 | 1076 | kern_return_t 1077 | IORegistryEntryGetParentEntry( 1078 | io_registry_entry_t entry, 1079 | const io_name_t plane, 1080 | io_registry_entry_t * parent ); 1081 | 1082 | /*! @function IORegistryEntryInPlane 1083 | @abstract Determines if the registry entry is attached in a plane. 1084 | @discussion This method determines if the entry is attached in a plane to any other entry. 1085 | @param entry The registry entry. 1086 | @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 1087 | @result If the entry has a parent in the plane, true is returned, otherwise false is returned. */ 1088 | 1089 | boolean_t 1090 | IORegistryEntryInPlane( 1091 | io_registry_entry_t entry, 1092 | const io_name_t plane ); 1093 | 1094 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1095 | 1096 | /* 1097 | * Matching dictionary creation helpers 1098 | */ 1099 | 1100 | /*! @function IOServiceMatching 1101 | @abstract Create a matching dictionary that specifies an IOService class match. 1102 | @discussion A very common matching criteria for IOService is based on its class. IOServiceMatching will create a matching dictionary that specifies any IOService of a class, or its subclasses. The class is specified by C-string name. 1103 | @param name The class name, as a const C-string. Class matching is successful on IOService's of this class or any subclass. 1104 | @result The matching dictionary created, is returned on success, or zero on failure. The dictionary is commonly passed to IOServiceGetMatchingServices or IOServiceAddNotification which will consume a reference, otherwise it should be released with CFRelease by the caller. */ 1105 | 1106 | CFMutableDictionaryRef 1107 | IOServiceMatching( 1108 | const char * name ); 1109 | 1110 | /*! @function IOServiceNameMatching 1111 | @abstract Create a matching dictionary that specifies an IOService name match. 1112 | @discussion A common matching criteria for IOService is based on its name. IOServiceNameMatching will create a matching dictionary that specifies an IOService with a given name. Some IOServices created from the OpenFirmware device tree will perform name matching on the standard OF compatible, name, model properties. 1113 | @param name The IOService name, as a const C-string. 1114 | @result The matching dictionary created, is returned on success, or zero on failure. The dictionary is commonly passed to IOServiceGetMatchingServices or IOServiceAddNotification which will consume a reference, otherwise it should be released with CFRelease by the caller. */ 1115 | 1116 | CFMutableDictionaryRef 1117 | IOServiceNameMatching( 1118 | const char * name ); 1119 | 1120 | /*! @function IOBSDNameMatching 1121 | @abstract Create a matching dictionary that specifies an IOService match based on BSD device name. 1122 | @discussion IOServices that represent BSD devices have an associated BSD name. This function creates a matching dictionary that will match IOService's with a given BSD name. 1123 | @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 1124 | @param options No options are currently defined. 1125 | @param bsdName The BSD name, as a const char *. 1126 | @result The matching dictionary created, is returned on success, or zero on failure. The dictionary is commonly passed to IOServiceGetMatchingServices or IOServiceAddNotification which will consume a reference, otherwise it should be released with CFRelease by the caller. */ 1127 | 1128 | CFMutableDictionaryRef 1129 | IOBSDNameMatching( 1130 | mach_port_t masterPort, 1131 | uint32_t options, 1132 | const char * bsdName ); 1133 | 1134 | /*! @function IOOpenFirmwarePathMatching 1135 | @abstract Create a matching dictionary that specifies an IOService match based on an OpenFirmware device path. 1136 | @discussion Certain IOServices (currently, block and ethernet boot devices) may be looked up by a path that specifies their location in the OpenFirmware device tree, represented in the registry by the kIODeviceTreePlane plane. This function creates a matching dictionary that will match IOService's found with a given OpenFirmware device path. 1137 | @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 1138 | @param options No options are currently defined. 1139 | @param path The OpenFirmware device path, as a const char *. 1140 | @result The matching dictionary created, is returned on success, or zero on failure. The dictionary is commonly passed to IOServiceGetMatchingServices or IOServiceAddNotification which will consume a reference, otherwise it should be released with CFRelease by the caller. */ 1141 | 1142 | CFMutableDictionaryRef 1143 | IOOpenFirmwarePathMatching( 1144 | mach_port_t masterPort, 1145 | uint32_t options, 1146 | const char * path ); 1147 | 1148 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1149 | 1150 | /*! @function IOServiceOFPathToBSDName 1151 | @abstract Utility to look up an IOService from its OpenFirmware device path, and return its BSD device name if available. 1152 | @discussion Certain IOServices (currently, block and ethernet boot devices) may be looked up by a path that specifies their location in the OpenFirmware device tree, represented in the registry by the kIODeviceTreePlane plane. This function looks up an IOService object with a given OpenFirmware device path, and returns its associated BSD device name. 1153 | @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 1154 | @param openFirmwarePath The OpenFirmware device path, as a const char *. 1155 | @param bsdName The BSD name, as a const char *, is copied to the callers buffer. 1156 | @result A kern_return_t error code. */ 1157 | 1158 | kern_return_t 1159 | IOServiceOFPathToBSDName(mach_port_t masterPort, 1160 | const io_name_t openFirmwarePath, 1161 | io_name_t bsdName); 1162 | 1163 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1164 | 1165 | /*! @typedef IOAsyncCallback0 1166 | @abstract standard callback function for asynchronous I/O requests with 1167 | no extra arguments beyond a refcon and result code. 1168 | @param refcon The refcon passed into the original I/O request 1169 | @param result The result of the I/O operation 1170 | */ 1171 | typedef void (*IOAsyncCallback0)(void *refcon, IOReturn result); 1172 | 1173 | /*! @typedef IOAsyncCallback1 1174 | @abstract standard callback function for asynchronous I/O requests with 1175 | one extra argument beyond a refcon and result code. 1176 | This is often a count of the number of bytes transferred 1177 | @param refcon The refcon passed into the original I/O request 1178 | @param result The result of the I/O operation 1179 | @param arg0 Extra argument 1180 | */ 1181 | typedef void (*IOAsyncCallback1)(void *refcon, IOReturn result, void *arg0); 1182 | 1183 | /*! @typedef IOAsyncCallback2 1184 | @abstract standard callback function for asynchronous I/O requests with 1185 | two extra arguments beyond a refcon and result code. 1186 | @param refcon The refcon passed into the original I/O request 1187 | @param result The result of the I/O operation 1188 | @param arg0 Extra argument 1189 | @param arg1 Extra argument 1190 | */ 1191 | typedef void (*IOAsyncCallback2)(void *refcon, IOReturn result, void *arg0, void *arg1); 1192 | 1193 | /*! @typedef IOAsyncCallback 1194 | @abstract standard callback function for asynchronous I/O requests with 1195 | lots of extra arguments beyond a refcon and result code. 1196 | @param refcon The refcon passed into the original I/O request 1197 | @param result The result of the I/O operation 1198 | @param args Array of extra arguments 1199 | @param numArgs Number of extra arguments 1200 | */ 1201 | typedef void (*IOAsyncCallback)(void *refcon, IOReturn result, void **args, 1202 | uint32_t numArgs); 1203 | 1204 | 1205 | /* Internal use */ 1206 | 1207 | kern_return_t 1208 | OSGetNotificationFromMessage( 1209 | mach_msg_header_t * msg, 1210 | uint32_t index, 1211 | uint32_t * type, 1212 | uintptr_t * reference, 1213 | void ** content, 1214 | vm_size_t * size ); 1215 | 1216 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1217 | 1218 | /* Internal use */ 1219 | 1220 | kern_return_t 1221 | IOCatalogueSendData( 1222 | mach_port_t masterPort, 1223 | uint32_t flag, 1224 | const char *buffer, 1225 | uint32_t size ); 1226 | 1227 | kern_return_t 1228 | IOCatalogueTerminate( 1229 | mach_port_t masterPort, 1230 | uint32_t flag, 1231 | io_name_t description ); 1232 | 1233 | kern_return_t 1234 | IOCatalogueGetData( 1235 | mach_port_t masterPort, 1236 | uint32_t flag, 1237 | char **buffer, 1238 | uint32_t *size ); 1239 | 1240 | kern_return_t 1241 | IOCatalogueModuleLoaded( 1242 | mach_port_t masterPort, 1243 | io_name_t name ); 1244 | 1245 | kern_return_t 1246 | IOCatalogueReset( 1247 | mach_port_t masterPort, 1248 | uint32_t flag ); 1249 | 1250 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1251 | 1252 | // obsolete API 1253 | 1254 | #if !defined(__LP64__) 1255 | 1256 | // for Power Mgt 1257 | 1258 | typedef struct IOObject IOObject; 1259 | 1260 | // for MacOS.app 1261 | 1262 | kern_return_t 1263 | IORegistryDisposeEnumerator( 1264 | io_enumerator_t enumerator ) DEPRECATED_ATTRIBUTE; 1265 | 1266 | kern_return_t 1267 | IOMapMemory( 1268 | io_connect_t connect, 1269 | uint32_t memoryType, 1270 | task_port_t intoTask, 1271 | vm_address_t * atAddress, 1272 | vm_size_t * ofSize, 1273 | uint32_t flags ) DEPRECATED_ATTRIBUTE; 1274 | 1275 | // for CGS 1276 | 1277 | kern_return_t 1278 | IOCompatibiltyNumber( 1279 | mach_port_t connect, 1280 | uint32_t * objectNumber ) DEPRECATED_ATTRIBUTE; 1281 | 1282 | // Traditional IOUserClient transport routines 1283 | kern_return_t 1284 | IOConnectMethodScalarIScalarO( 1285 | io_connect_t connect, 1286 | uint32_t index, 1287 | IOItemCount scalarInputCount, 1288 | IOItemCount scalarOutputCount, 1289 | ... ) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5; 1290 | 1291 | kern_return_t 1292 | IOConnectMethodScalarIStructureO( 1293 | io_connect_t connect, 1294 | uint32_t index, 1295 | IOItemCount scalarInputCount, 1296 | IOByteCount * structureSize, 1297 | ... ) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5; 1298 | 1299 | kern_return_t 1300 | IOConnectMethodScalarIStructureI( 1301 | io_connect_t connect, 1302 | uint32_t index, 1303 | IOItemCount scalarInputCount, 1304 | IOByteCount structureSize, 1305 | ... ) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5; 1306 | 1307 | kern_return_t 1308 | IOConnectMethodStructureIStructureO( 1309 | io_connect_t connect, 1310 | uint32_t index, 1311 | IOItemCount structureInputSize, 1312 | IOByteCount * structureOutputSize, 1313 | void * inputStructure, 1314 | void * ouputStructure ) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5; 1315 | 1316 | // Compatability with earlier Mig interface routines 1317 | #if IOCONNECT_NO_32B_METHODS 1318 | 1319 | kern_return_t 1320 | io_connect_map_memory( 1321 | io_connect_t connect, 1322 | uint32_t memoryType, 1323 | task_port_t intoTask, 1324 | vm_address_t *atAddress, 1325 | vm_size_t *ofSize, 1326 | IOOptionBits options) DEPRECATED_ATTRIBUTE; 1327 | 1328 | kern_return_t 1329 | io_connect_unmap_memory( 1330 | io_connect_t connect, 1331 | uint32_t memoryType, 1332 | task_port_t fromTask, 1333 | vm_address_t atAddress) DEPRECATED_ATTRIBUTE; 1334 | 1335 | kern_return_t 1336 | io_connect_method_scalarI_scalarO( 1337 | mach_port_t connection, 1338 | int selector, 1339 | io_scalar_inband_t input, 1340 | mach_msg_type_number_t inputCnt, 1341 | io_scalar_inband_t output, 1342 | mach_msg_type_number_t *outputCnt) DEPRECATED_ATTRIBUTE; 1343 | 1344 | kern_return_t 1345 | io_connect_method_scalarI_structureO( 1346 | mach_port_t connection, 1347 | int selector, 1348 | io_scalar_inband_t input, 1349 | mach_msg_type_number_t inputCnt, 1350 | io_struct_inband_t output, 1351 | mach_msg_type_number_t *outputCnt) DEPRECATED_ATTRIBUTE; 1352 | 1353 | kern_return_t 1354 | io_connect_method_scalarI_structureI( 1355 | mach_port_t connection, 1356 | int selector, 1357 | io_scalar_inband_t input, 1358 | mach_msg_type_number_t inputCnt, 1359 | io_struct_inband_t inputStruct, 1360 | mach_msg_type_number_t inputStructCnt) DEPRECATED_ATTRIBUTE; 1361 | 1362 | kern_return_t 1363 | io_connect_method_structureI_structureO( 1364 | mach_port_t connection, 1365 | int selector, 1366 | io_struct_inband_t input, 1367 | mach_msg_type_number_t inputCnt, 1368 | io_struct_inband_t output, 1369 | mach_msg_type_number_t *outputCnt) DEPRECATED_ATTRIBUTE; 1370 | 1371 | kern_return_t 1372 | io_async_method_scalarI_scalarO( 1373 | mach_port_t connection, 1374 | mach_port_t wake_port, 1375 | io_async_ref_t reference, 1376 | mach_msg_type_number_t referenceCnt, 1377 | int selector, 1378 | io_scalar_inband_t input, 1379 | mach_msg_type_number_t inputCnt, 1380 | io_scalar_inband_t output, 1381 | mach_msg_type_number_t *outputCnt) DEPRECATED_ATTRIBUTE; 1382 | 1383 | kern_return_t 1384 | io_async_method_scalarI_structureO( 1385 | mach_port_t connection, 1386 | mach_port_t wake_port, 1387 | io_async_ref_t reference, 1388 | mach_msg_type_number_t referenceCnt, 1389 | int selector, 1390 | io_scalar_inband_t input, 1391 | mach_msg_type_number_t inputCnt, 1392 | io_struct_inband_t output, 1393 | mach_msg_type_number_t *outputCnt) DEPRECATED_ATTRIBUTE; 1394 | 1395 | kern_return_t 1396 | io_async_method_scalarI_structureI( 1397 | mach_port_t connection, 1398 | mach_port_t wake_port, 1399 | io_async_ref_t reference, 1400 | mach_msg_type_number_t referenceCnt, 1401 | int selector, 1402 | io_scalar_inband_t input, 1403 | mach_msg_type_number_t inputCnt, 1404 | io_struct_inband_t inputStruct, 1405 | mach_msg_type_number_t inputStructCnt) DEPRECATED_ATTRIBUTE; 1406 | 1407 | kern_return_t 1408 | io_async_method_structureI_structureO( 1409 | mach_port_t connection, 1410 | mach_port_t wake_port, 1411 | io_async_ref_t reference, 1412 | mach_msg_type_number_t referenceCnt, 1413 | int selector, 1414 | io_struct_inband_t input, 1415 | mach_msg_type_number_t inputCnt, 1416 | io_struct_inband_t output, 1417 | mach_msg_type_number_t *outputCnt) DEPRECATED_ATTRIBUTE; 1418 | #endif // IOCONNECT_NO_32B_METHODS 1419 | 1420 | #endif /* defined(__LP64__) */ 1421 | 1422 | __END_DECLS 1423 | 1424 | #endif /* ! _IOKIT_IOKITLIB_H */ 1425 | -------------------------------------------------------------------------------- /IOReturn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998-2002 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_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. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * HISTORY 30 | */ 31 | 32 | /* 33 | * Core IOReturn values. Others may be family defined. 34 | */ 35 | 36 | #ifndef __IOKIT_IORETURN_H 37 | #define __IOKIT_IORETURN_H 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | #include 44 | 45 | typedef kern_return_t IOReturn; 46 | 47 | #ifndef sys_iokit 48 | #define sys_iokit err_system(0x38) 49 | #endif /* sys_iokit */ 50 | #define sub_iokit_common err_sub(0) 51 | #define sub_iokit_usb err_sub(1) 52 | #define sub_iokit_firewire err_sub(2) 53 | #define sub_iokit_block_storage err_sub(4) 54 | #define sub_iokit_graphics err_sub(5) 55 | #define sub_iokit_networking err_sub(6) 56 | #define sub_iokit_bluetooth err_sub(8) 57 | #define sub_iokit_pmu err_sub(9) 58 | #define sub_iokit_acpi err_sub(10) 59 | #define sub_iokit_smbus err_sub(11) 60 | #define sub_iokit_ahci err_sub(12) 61 | #define sub_iokit_powermanagement err_sub(13) 62 | //#define sub_iokit_hidsystem err_sub(14) 63 | #define sub_iokit_scsi err_sub(16) 64 | //#define sub_iokit_pccard err_sub(21) 65 | 66 | #define sub_iokit_vendor_specific err_sub(-2) 67 | #define sub_iokit_reserved err_sub(-1) 68 | 69 | #define iokit_common_err(return) (sys_iokit|sub_iokit_common|return) 70 | #define iokit_family_err(sub,return) (sys_iokit|sub|return) 71 | #define iokit_vendor_specific_err(return) (sys_iokit|sub_iokit_vendor_specific|return) 72 | 73 | #define kIOReturnSuccess KERN_SUCCESS // OK 74 | #define kIOReturnError iokit_common_err(0x2bc) // general error 75 | #define kIOReturnNoMemory iokit_common_err(0x2bd) // can't allocate memory 76 | #define kIOReturnNoResources iokit_common_err(0x2be) // resource shortage 77 | #define kIOReturnIPCError iokit_common_err(0x2bf) // error during IPC 78 | #define kIOReturnNoDevice iokit_common_err(0x2c0) // no such device 79 | #define kIOReturnNotPrivileged iokit_common_err(0x2c1) // privilege violation 80 | #define kIOReturnBadArgument iokit_common_err(0x2c2) // invalid argument 81 | #define kIOReturnLockedRead iokit_common_err(0x2c3) // device read locked 82 | #define kIOReturnLockedWrite iokit_common_err(0x2c4) // device write locked 83 | #define kIOReturnExclusiveAccess iokit_common_err(0x2c5) // exclusive access and 84 | // device already open 85 | #define kIOReturnBadMessageID iokit_common_err(0x2c6) // sent/received messages 86 | // had different msg_id 87 | #define kIOReturnUnsupported iokit_common_err(0x2c7) // unsupported function 88 | #define kIOReturnVMError iokit_common_err(0x2c8) // misc. VM failure 89 | #define kIOReturnInternalError iokit_common_err(0x2c9) // internal error 90 | #define kIOReturnIOError iokit_common_err(0x2ca) // General I/O error 91 | //#define kIOReturn???Error iokit_common_err(0x2cb) // ??? 92 | #define kIOReturnCannotLock iokit_common_err(0x2cc) // can't acquire lock 93 | #define kIOReturnNotOpen iokit_common_err(0x2cd) // device not open 94 | #define kIOReturnNotReadable iokit_common_err(0x2ce) // read not supported 95 | #define kIOReturnNotWritable iokit_common_err(0x2cf) // write not supported 96 | #define kIOReturnNotAligned iokit_common_err(0x2d0) // alignment error 97 | #define kIOReturnBadMedia iokit_common_err(0x2d1) // Media Error 98 | #define kIOReturnStillOpen iokit_common_err(0x2d2) // device(s) still open 99 | #define kIOReturnRLDError iokit_common_err(0x2d3) // rld failure 100 | #define kIOReturnDMAError iokit_common_err(0x2d4) // DMA failure 101 | #define kIOReturnBusy iokit_common_err(0x2d5) // Device Busy 102 | #define kIOReturnTimeout iokit_common_err(0x2d6) // I/O Timeout 103 | #define kIOReturnOffline iokit_common_err(0x2d7) // device offline 104 | #define kIOReturnNotReady iokit_common_err(0x2d8) // not ready 105 | #define kIOReturnNotAttached iokit_common_err(0x2d9) // device not attached 106 | #define kIOReturnNoChannels iokit_common_err(0x2da) // no DMA channels left 107 | #define kIOReturnNoSpace iokit_common_err(0x2db) // no space for data 108 | //#define kIOReturn???Error iokit_common_err(0x2dc) // ??? 109 | #define kIOReturnPortExists iokit_common_err(0x2dd) // port already exists 110 | #define kIOReturnCannotWire iokit_common_err(0x2de) // can't wire down 111 | // physical memory 112 | #define kIOReturnNoInterrupt iokit_common_err(0x2df) // no interrupt attached 113 | #define kIOReturnNoFrames iokit_common_err(0x2e0) // no DMA frames enqueued 114 | #define kIOReturnMessageTooLarge iokit_common_err(0x2e1) // oversized msg received 115 | // on interrupt port 116 | #define kIOReturnNotPermitted iokit_common_err(0x2e2) // not permitted 117 | #define kIOReturnNoPower iokit_common_err(0x2e3) // no power to device 118 | #define kIOReturnNoMedia iokit_common_err(0x2e4) // media not present 119 | #define kIOReturnUnformattedMedia iokit_common_err(0x2e5)// media not formatted 120 | #define kIOReturnUnsupportedMode iokit_common_err(0x2e6) // no such mode 121 | #define kIOReturnUnderrun iokit_common_err(0x2e7) // data underrun 122 | #define kIOReturnOverrun iokit_common_err(0x2e8) // data overrun 123 | #define kIOReturnDeviceError iokit_common_err(0x2e9) // the device is not working properly! 124 | #define kIOReturnNoCompletion iokit_common_err(0x2ea) // a completion routine is required 125 | #define kIOReturnAborted iokit_common_err(0x2eb) // operation aborted 126 | #define kIOReturnNoBandwidth iokit_common_err(0x2ec) // bus bandwidth would be exceeded 127 | #define kIOReturnNotResponding iokit_common_err(0x2ed) // device not responding 128 | #define kIOReturnIsoTooOld iokit_common_err(0x2ee) // isochronous I/O request for distant past! 129 | #define kIOReturnIsoTooNew iokit_common_err(0x2ef) // isochronous I/O request for distant future 130 | #define kIOReturnNotFound iokit_common_err(0x2f0) // data was not found 131 | #define kIOReturnInvalid iokit_common_err(0x1) // should never be seen 132 | 133 | #ifdef __cplusplus 134 | } 135 | #endif 136 | 137 | #endif /* ! __IOKIT_IORETURN_H */ 138 | -------------------------------------------------------------------------------- /IOTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998-2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_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. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef __IOKIT_IOTYPES_H 29 | #define __IOKIT_IOTYPES_H 30 | 31 | #ifndef IOKIT 32 | #define IOKIT 1 33 | #endif /* !IOKIT */ 34 | 35 | #if KERNEL 36 | #include 37 | #else 38 | #include 39 | #include 40 | #endif 41 | 42 | #include "IOReturn.h" 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | #ifndef NULL 49 | #if defined (__cplusplus) 50 | #define NULL 0 51 | #else 52 | #define NULL ((void *)0) 53 | #endif 54 | #endif 55 | 56 | /* 57 | * Simple data types. 58 | */ 59 | #ifndef __MACTYPES__ /* CF MacTypes.h */ 60 | #ifndef __TYPES__ /* guess... Mac Types.h */ 61 | 62 | #include 63 | #include 64 | 65 | #endif /* __TYPES__ */ 66 | #endif /* __MACTYPES__ */ 67 | 68 | #if KERNEL 69 | #include 70 | #endif 71 | 72 | typedef UInt32 IOOptionBits; 73 | typedef SInt32 IOFixed; 74 | typedef UInt32 IOVersion; 75 | typedef UInt32 IOItemCount; 76 | typedef UInt32 IOCacheMode; 77 | 78 | typedef UInt32 IOByteCount32; 79 | typedef UInt64 IOByteCount64; 80 | 81 | typedef UInt32 IOPhysicalAddress32; 82 | typedef UInt64 IOPhysicalAddress64; 83 | typedef UInt32 IOPhysicalLength32; 84 | typedef UInt64 IOPhysicalLength64; 85 | 86 | #ifdef __LP64__ 87 | typedef mach_vm_address_t IOVirtualAddress; 88 | #else 89 | typedef vm_address_t IOVirtualAddress; 90 | #endif 91 | 92 | #if defined(__LP64__) && defined(KERNEL) 93 | typedef IOByteCount64 IOByteCount; 94 | #else 95 | typedef IOByteCount32 IOByteCount; 96 | #endif 97 | 98 | typedef IOVirtualAddress IOLogicalAddress; 99 | 100 | #if defined(__LP64__) && defined(KERNEL) 101 | 102 | typedef IOPhysicalAddress64 IOPhysicalAddress; 103 | typedef IOPhysicalLength64 IOPhysicalLength; 104 | #define IOPhysical32( hi, lo ) ((UInt64) lo + ((UInt64)(hi) << 32)) 105 | #define IOPhysSize 64 106 | 107 | #else 108 | 109 | typedef IOPhysicalAddress32 IOPhysicalAddress; 110 | typedef IOPhysicalLength32 IOPhysicalLength; 111 | #define IOPhysical32( hi, lo ) (lo) 112 | #define IOPhysSize 32 113 | 114 | #endif 115 | 116 | 117 | typedef struct 118 | { 119 | IOPhysicalAddress address; 120 | IOByteCount length; 121 | } IOPhysicalRange; 122 | 123 | typedef struct 124 | { 125 | IOVirtualAddress address; 126 | IOByteCount length; 127 | } IOVirtualRange; 128 | 129 | #ifdef __LP64__ 130 | typedef IOVirtualRange IOAddressRange; 131 | #else /* !__LP64__ */ 132 | typedef struct 133 | { 134 | mach_vm_address_t address; 135 | mach_vm_size_t length; 136 | } IOAddressRange; 137 | #endif /* !__LP64__ */ 138 | 139 | /* 140 | * Map between #defined or enum'd constants and text description. 141 | */ 142 | typedef struct { 143 | int value; 144 | const char *name; 145 | } IONamedValue; 146 | 147 | 148 | /* 149 | * Memory alignment -- specified as a power of two. 150 | */ 151 | typedef unsigned int IOAlignment; 152 | 153 | #define IO_NULL_VM_TASK ((vm_task_t)0) 154 | 155 | 156 | /* 157 | * Pull in machine specific stuff. 158 | */ 159 | 160 | //#include 161 | 162 | #ifndef MACH_KERNEL 163 | 164 | #ifndef __IOKIT_PORTS_DEFINED__ 165 | #define __IOKIT_PORTS_DEFINED__ 166 | #ifdef KERNEL 167 | typedef struct OSObject * io_object_t; 168 | #else /* KERNEL */ 169 | typedef mach_port_t io_object_t; 170 | #endif /* KERNEL */ 171 | #endif /* __IOKIT_PORTS_DEFINED__ */ 172 | 173 | #include 174 | 175 | typedef io_object_t io_connect_t; 176 | typedef io_object_t io_enumerator_t; 177 | typedef io_object_t io_iterator_t; 178 | typedef io_object_t io_registry_entry_t; 179 | typedef io_object_t io_service_t; 180 | 181 | #define IO_OBJECT_NULL ((io_object_t) 0) 182 | 183 | #endif /* MACH_KERNEL */ 184 | 185 | // IOConnectMapMemory memoryTypes 186 | enum { 187 | kIODefaultMemoryType = 0 188 | }; 189 | 190 | enum { 191 | kIODefaultCache = 0, 192 | kIOInhibitCache = 1, 193 | kIOWriteThruCache = 2, 194 | kIOCopybackCache = 3, 195 | kIOWriteCombineCache = 4 196 | }; 197 | 198 | // IOMemory mapping options 199 | enum { 200 | kIOMapAnywhere = 0x00000001, 201 | 202 | kIOMapCacheMask = 0x00000700, 203 | kIOMapCacheShift = 8, 204 | kIOMapDefaultCache = kIODefaultCache << kIOMapCacheShift, 205 | kIOMapInhibitCache = kIOInhibitCache << kIOMapCacheShift, 206 | kIOMapWriteThruCache = kIOWriteThruCache << kIOMapCacheShift, 207 | kIOMapCopybackCache = kIOCopybackCache << kIOMapCacheShift, 208 | kIOMapWriteCombineCache = kIOWriteCombineCache << kIOMapCacheShift, 209 | 210 | kIOMapUserOptionsMask = 0x00000fff, 211 | 212 | kIOMapReadOnly = 0x00001000, 213 | 214 | kIOMapStatic = 0x01000000, 215 | kIOMapReference = 0x02000000, 216 | kIOMapUnique = 0x04000000 217 | #ifdef XNU_KERNEL_PRIVATE 218 | , kIOMap64Bit = 0x08000000 219 | #endif 220 | }; 221 | 222 | /*! @enum Scale Factors 223 | @discussion Used when a scale_factor parameter is required to define a unit of time. 224 | @constant kNanosecondScale Scale factor for nanosecond based times. 225 | @constant kMicrosecondScale Scale factor for microsecond based times. 226 | @constant kMillisecondScale Scale factor for millisecond based times. 227 | @constant kTickScale Scale factor for the standard (100Hz) tick. 228 | @constant kSecondScale Scale factor for second based times. */ 229 | 230 | enum { 231 | kNanosecondScale = 1, 232 | kMicrosecondScale = 1000, 233 | kMillisecondScale = 1000 * 1000, 234 | kSecondScale = 1000 * 1000 * 1000, 235 | kTickScale = (kSecondScale / 100) 236 | }; 237 | 238 | /* compatibility types */ 239 | 240 | #ifndef KERNEL 241 | 242 | typedef unsigned int IODeviceNumber; 243 | 244 | #endif 245 | 246 | #ifdef __cplusplus 247 | } 248 | #endif 249 | 250 | #endif /* ! __IOKIT_IOTYPES_H */ 251 | -------------------------------------------------------------------------------- /OSMessageNotification.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | /* 24 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 25 | * 26 | * HISTORY 27 | * 28 | */ 29 | 30 | #ifndef __OS_OSMESSAGENOTIFICATION_H 31 | #define __OS_OSMESSAGENOTIFICATION_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | #include 38 | #include "IOReturn.h" 39 | 40 | enum { 41 | kFirstIOKitNotificationType = 100, 42 | kIOServicePublishNotificationType = 100, 43 | kIOServiceMatchedNotificationType = 101, 44 | kIOServiceTerminatedNotificationType = 102, 45 | kIOAsyncCompletionNotificationType = 150, 46 | kIOServiceMessageNotificationType = 160, 47 | kLastIOKitNotificationType = 199 48 | }; 49 | 50 | enum { 51 | kOSNotificationMessageID = 53, 52 | kOSAsyncCompleteMessageID = 57, 53 | kMaxAsyncArgs = 16 54 | }; 55 | 56 | enum { 57 | kIOAsyncReservedIndex = 0, 58 | kIOAsyncReservedCount, 59 | 60 | kIOAsyncCalloutFuncIndex = kIOAsyncReservedCount, 61 | kIOAsyncCalloutRefconIndex, 62 | kIOAsyncCalloutCount, 63 | 64 | kIOMatchingCalloutFuncIndex = kIOAsyncReservedCount, 65 | kIOMatchingCalloutRefconIndex, 66 | kIOMatchingCalloutCount, 67 | 68 | kIOInterestCalloutFuncIndex = kIOAsyncReservedCount, 69 | kIOInterestCalloutRefconIndex, 70 | kIOInterestCalloutServiceIndex, 71 | kIOInterestCalloutCount 72 | }; 73 | 74 | enum { 75 | kOSAsyncRefCount = 8, 76 | kOSAsyncRefSize = 32 77 | }; 78 | typedef natural_t OSAsyncReference[kOSAsyncRefCount]; 79 | 80 | struct OSNotificationHeader { 81 | vm_size_t size; /* content size */ 82 | natural_t type; 83 | OSAsyncReference reference; 84 | 85 | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) 86 | unsigned char content[]; 87 | #else 88 | unsigned char content[0]; 89 | #endif 90 | }; 91 | 92 | struct IOServiceInterestContent { 93 | natural_t messageType; 94 | void * messageArgument[1]; 95 | }; 96 | 97 | struct IOAsyncCompletionContent { 98 | IOReturn result; 99 | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) 100 | void * args[]; 101 | #else 102 | void * args[0]; 103 | #endif 104 | }; 105 | 106 | #ifndef __cplusplus 107 | typedef struct OSNotificationHeader OSNotificationHeader; 108 | typedef struct IOServiceInterestContent IOServiceInterestContent; 109 | typedef struct IOAsyncCompletionContent IOAsyncCompletionContent; 110 | #endif 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | 116 | #endif /* __OS_OSMESSAGENOTIFICATION_H */ 117 | 118 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | IOKit for iOS SDK7.0 2 | ======= 3 | 4 | ![](https://github.com/obaby/IOKit/blob/master/screenshot.jpg?raw=true) 5 | 6 | 在某些时候可能会用到IOKit来获取一些信息,但是将sdk从6.x升级到7.0的sdk之后就会发现那个libIOKit.dylib找不到了。晚上的办法是将6.x的sdk复制到7.0的sdk下,或者创建一个符号链接。 7 | 8 | 其实还有另外的一个解决办法,在7.0之后这个东西只是不是dylib了,而是成了一个framework。在这个目录下 9 | 10 | /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/IOKit.framework,所以只需要将工程中的iokit用framework替换掉就可以了。另外这个并没有头文件,如果要用也得自己去提取相关的头文件。可以用classdump来生成。我用的是apple xun中的头文件,效果是一样的,这里整理了一下,需要的直接放入工程目录下引入IOKitLib.h就可以了。 -------------------------------------------------------------------------------- /screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obaby/IOKit/764c13ec8cbe9be1362716dbee5dfdfc0dcae807/screenshot.jpg --------------------------------------------------------------------------------