2 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
24 * Modification History
26 * October 31, 2000 Allan Nathanson <ajn@apple.com>
31 #include <sys/types.h>
32 #include <sys/param.h>
34 #include <mach-o/dyld.h>
35 #include <CoreFoundation/CoreFoundation.h>
37 #include "dy_framework.h"
42 static const void *image
= NULL
;
44 const char *framework
= "/System/Library/Frameworks/IOKit.framework/IOKit";
46 const char *suffix
= getenv("DYLD_IMAGE_SUFFIX");
47 char path
[MAXPATHLEN
];
49 strcpy(path
, framework
);
50 if (suffix
) strcat(path
, suffix
);
51 if (0 <= stat(path
, &statbuf
)) {
52 image
= NSAddImage(path
, NSADDIMAGE_OPTION_NONE
);
54 image
= NSAddImage(framework
, NSADDIMAGE_OPTION_NONE
);
61 __private_extern__ CFMutableDictionaryRef
62 _IOBSDNameMatching(mach_port_t masterPort
, unsigned int options
, const char *bsdName
)
64 static CFMutableDictionaryRef (*dyfunc
)(mach_port_t
, unsigned int, const char *) = NULL
;
66 void *image
= __loadIOKit();
67 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOBSDNameMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
69 return dyfunc
? dyfunc(masterPort
, options
, bsdName
) : NULL
;
73 __private_extern__ io_object_t
74 _IOIteratorNext(io_iterator_t iterator
)
76 static io_object_t (*dyfunc
)(io_iterator_t
) = NULL
;
78 void *image
= __loadIOKit();
79 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOIteratorNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
81 return dyfunc
? dyfunc(iterator
) : 0;
85 __private_extern__ kern_return_t
86 _IOMasterPort(mach_port_t bootstrapPort
, mach_port_t
*masterPort
)
88 static kern_return_t (*dyfunc
)(mach_port_t
, mach_port_t
*) = NULL
;
90 void *image
= __loadIOKit();
91 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOMasterPort", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
93 return dyfunc
? dyfunc(bootstrapPort
, masterPort
) : KERN_FAILURE
;
97 __private_extern__ kern_return_t
98 _IOObjectRelease(io_object_t object
)
100 static kern_return_t (*dyfunc
)(io_object_t
) = NULL
;
102 void *image
= __loadIOKit();
103 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOObjectRelease", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
105 return dyfunc
? dyfunc(object
) : KERN_FAILURE
;
109 __private_extern__ CFTypeRef
110 _IORegistryEntryCreateCFProperty(io_registry_entry_t entry
, CFStringRef key
, CFAllocatorRef allocator
, IOOptionBits options
)
112 static CFTypeRef (*dyfunc
)(io_registry_entry_t
, CFStringRef
, CFAllocatorRef
, IOOptionBits
) = NULL
;
114 void *image
= __loadIOKit();
115 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryCreateCFProperty", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
117 return dyfunc
? dyfunc(entry
, key
, allocator
, options
) : NULL
;
121 __private_extern__ kern_return_t
122 _IORegistryEntryCreateCFProperties(io_registry_entry_t entry
, CFMutableDictionaryRef
*properties
, CFAllocatorRef allocator
, IOOptionBits options
)
124 static kern_return_t (*dyfunc
)(io_registry_entry_t
, CFMutableDictionaryRef
*, CFAllocatorRef
, IOOptionBits
) = NULL
;
126 void *image
= __loadIOKit();
127 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryCreateCFProperties", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
129 return dyfunc
? dyfunc(entry
, properties
, allocator
, options
) : KERN_FAILURE
;
133 __private_extern__ kern_return_t
134 _IORegistryEntryGetParentEntry(io_registry_entry_t entry
, const io_name_t plane
, io_registry_entry_t
*parent
)
136 static kern_return_t (*dyfunc
)(io_registry_entry_t
, const io_name_t
, io_registry_entry_t
*) = NULL
;
138 void *image
= __loadIOKit();
139 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryGetParentEntry", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
141 return dyfunc
? dyfunc(entry
, plane
, parent
) : NULL
;
145 __private_extern__ kern_return_t
146 _IORegistryEntryGetPath(io_registry_entry_t entry
, const io_name_t plane
, io_string_t path
)
148 static kern_return_t (*dyfunc
)(io_registry_entry_t
, const io_name_t
, io_string_t
) = NULL
;
150 void *image
= __loadIOKit();
151 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryGetPath", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
153 return dyfunc
? dyfunc(entry
, plane
, path
) : KERN_FAILURE
;
157 __private_extern__ kern_return_t
158 _IOServiceGetMatchingServices(mach_port_t masterPort
, CFDictionaryRef matching
, io_iterator_t
*existing
)
160 static kern_return_t (*dyfunc
)(mach_port_t
, CFDictionaryRef
, io_iterator_t
*) = NULL
;
162 void *image
= __loadIOKit();
163 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOServiceGetMatchingServices", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
165 return dyfunc
? dyfunc(masterPort
, matching
, existing
) : KERN_FAILURE
;
169 __private_extern__ CFMutableDictionaryRef
170 _IOServiceMatching(const char *name
)
172 static CFMutableDictionaryRef (*dyfunc
)(const char *) = NULL
;
174 void *image
= __loadIOKit();
175 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOServiceMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
177 return dyfunc
? dyfunc(name
) : NULL
;