2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * October 31, 2000 Allan Nathanson <ajn@apple.com>
32 #include <sys/types.h>
33 #include <sys/param.h>
35 #include <mach-o/dyld.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 #undef IOBSDNameMatching
65 static typeof (IOBSDNameMatching
) *dyfunc
= NULL
;
67 void *image
= __loadIOKit();
68 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOBSDNameMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
70 return dyfunc
? dyfunc(masterPort
, options
, bsdName
) : NULL
;
74 __private_extern__ io_object_t
75 _IOIteratorNext(io_iterator_t iterator
)
78 static typeof (IOIteratorNext
) *dyfunc
= NULL
;
80 void *image
= __loadIOKit();
81 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOIteratorNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
83 return dyfunc
? dyfunc(iterator
) : 0;
87 __private_extern__ kern_return_t
88 _IOMasterPort(mach_port_t bootstrapPort
, mach_port_t
*masterPort
)
91 static typeof (IOMasterPort
) *dyfunc
= NULL
;
93 void *image
= __loadIOKit();
94 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOMasterPort", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
96 return dyfunc
? dyfunc(bootstrapPort
, masterPort
) : KERN_FAILURE
;
100 __private_extern__ boolean_t
101 _IOObjectConformsTo(io_object_t object
, const io_name_t className
)
103 #undef IOObjectConformsTo
104 static typeof (IOObjectConformsTo
) *dyfunc
= NULL
;
106 void *image
= __loadIOKit();
107 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOObjectConformsTo", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
109 return dyfunc
? dyfunc(object
, className
) : FALSE
;
113 __private_extern__ boolean_t
114 _IOObjectGetClass(io_object_t object
, io_name_t className
)
116 #undef IOObjectGetClass
117 static typeof (IOObjectGetClass
) *dyfunc
= NULL
;
119 void *image
= __loadIOKit();
120 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOObjectGetClass", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
122 return dyfunc
? dyfunc(object
, className
) : FALSE
;
126 __private_extern__ kern_return_t
127 _IOObjectRelease(io_object_t object
)
129 #undef IOObjectRelease
130 static typeof (IOObjectRelease
) *dyfunc
= NULL
;
132 void *image
= __loadIOKit();
133 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOObjectRelease", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
135 return dyfunc
? dyfunc(object
) : KERN_FAILURE
;
139 __private_extern__ CFTypeRef
140 _IORegistryEntryCreateCFProperty(io_registry_entry_t entry
, CFStringRef key
, CFAllocatorRef allocator
, IOOptionBits options
)
142 #undef IORegistryEntryCreateCFProperty
143 static typeof (IORegistryEntryCreateCFProperty
) *dyfunc
= NULL
;
145 void *image
= __loadIOKit();
146 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryCreateCFProperty", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
148 return dyfunc
? dyfunc(entry
, key
, allocator
, options
) : NULL
;
152 __private_extern__ kern_return_t
153 _IORegistryEntryCreateCFProperties(io_registry_entry_t entry
, CFMutableDictionaryRef
*properties
, CFAllocatorRef allocator
, IOOptionBits options
)
155 #undef IORegistryEntryCreateCFProperties
156 static typeof (IORegistryEntryCreateCFProperties
) *dyfunc
= NULL
;
158 void *image
= __loadIOKit();
159 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryCreateCFProperties", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
161 return dyfunc
? dyfunc(entry
, properties
, allocator
, options
) : KERN_FAILURE
;
165 __private_extern__ kern_return_t
166 _IORegistryEntryCreateIterator(mach_port_t masterPort
, const io_name_t plane
, IOOptionBits options
, io_iterator_t
*iterator
)
168 #undef IORegistryEntryCreateIterator
169 static typeof (IORegistryEntryCreateIterator
) *dyfunc
= NULL
;
171 void *image
= __loadIOKit();
172 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryCreateIterator", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
174 return dyfunc
? dyfunc(masterPort
, plane
, options
, iterator
) : KERN_FAILURE
;
178 __private_extern__ kern_return_t
179 _IORegistryEntryGetName(io_registry_entry_t entry
, io_name_t name
)
181 #undef IORegistryEntryGetName
182 static typeof (IORegistryEntryGetName
) *dyfunc
= NULL
;
184 void *image
= __loadIOKit();
185 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryGetName", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
187 return dyfunc
? dyfunc(entry
, name
) : KERN_FAILURE
;
191 __private_extern__ kern_return_t
192 _IORegistryEntryGetParentEntry(io_registry_entry_t entry
, const io_name_t plane
, io_registry_entry_t
*parent
)
194 #undef IORegistryEntryGetParentEntry
195 static typeof (IORegistryEntryGetParentEntry
) *dyfunc
= NULL
;
197 void *image
= __loadIOKit();
198 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryGetParentEntry", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
200 return dyfunc
? dyfunc(entry
, plane
, parent
) : KERN_FAILURE
;
204 __private_extern__ kern_return_t
205 _IORegistryEntryGetPath(io_registry_entry_t entry
, const io_name_t plane
, io_string_t path
)
207 #undef IORegistryEntryGetPath
208 static typeof (IORegistryEntryGetPath
) *dyfunc
= NULL
;
210 void *image
= __loadIOKit();
211 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryGetPath", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
213 return dyfunc
? dyfunc(entry
, plane
, path
) : KERN_FAILURE
;
217 __private_extern__ CFTypeRef
218 _IORegistryEntrySearchCFProperty(io_registry_entry_t entry
, const io_name_t plane
, CFStringRef key
, CFAllocatorRef allocator
, IOOptionBits options
)
220 #undef IORegistryEntrySearchCFProperty
221 static typeof (IORegistryEntrySearchCFProperty
) *dyfunc
= NULL
;
223 void *image
= __loadIOKit();
224 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntrySearchCFProperty", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
226 return dyfunc
? dyfunc(entry
, plane
, key
, allocator
, options
) : NULL
;
230 __private_extern__ kern_return_t
231 _IOServiceGetMatchingServices(mach_port_t masterPort
, CFDictionaryRef matching
, io_iterator_t
*existing
)
233 #undef IOServiceGetMatchingServices
234 static typeof (IOServiceGetMatchingServices
) *dyfunc
= NULL
;
236 void *image
= __loadIOKit();
237 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOServiceGetMatchingServices", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
239 return dyfunc
? dyfunc(masterPort
, matching
, existing
) : KERN_FAILURE
;
243 __private_extern__ CFMutableDictionaryRef
244 _IOServiceMatching(const char *name
)
246 #undef IOServiceMatching
247 static typeof (IOServiceMatching
) *dyfunc
= NULL
;
249 void *image
= __loadIOKit();
250 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOServiceMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
252 return dyfunc
? dyfunc(name
) : NULL
;
256 __loadSecurity(void) {
257 static const void *image
= NULL
;
259 const char *framework
= "/System/Library/Frameworks/Security.framework/Security";
261 const char *suffix
= getenv("DYLD_IMAGE_SUFFIX");
262 char path
[MAXPATHLEN
];
264 strcpy(path
, framework
);
265 if (suffix
) strcat(path
, suffix
);
266 if (0 <= stat(path
, &statbuf
)) {
267 image
= NSAddImage(path
, NSADDIMAGE_OPTION_NONE
);
269 image
= NSAddImage(framework
, NSADDIMAGE_OPTION_NONE
);
272 return (void *)image
;
276 __private_extern__ OSStatus
277 _SecKeychainItemCopyContent(SecKeychainItemRef itemRef
, SecItemClass
*itemClass
, SecKeychainAttributeList
*attrList
, UInt32
*length
, void **outData
)
279 #undef SecKeychainItemCopyContent
280 static typeof (SecKeychainItemCopyContent
) *dyfunc
= NULL
;
282 void *image
= __loadSecurity();
283 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_SecKeychainItemCopyContent", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
285 return dyfunc
? dyfunc(itemRef
, itemClass
, attrList
, length
, outData
) : -1;
288 __private_extern__ OSStatus
289 _SecKeychainSearchCopyNext(SecKeychainSearchRef searchRef
, SecKeychainItemRef
*itemRef
)
291 #undef SecKeychainSearchCopyNext
292 static typeof (SecKeychainSearchCopyNext
) *dyfunc
= NULL
;
294 void *image
= __loadSecurity();
295 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_SecKeychainSearchCopyNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
297 return dyfunc
? dyfunc(searchRef
, itemRef
) : -1;
300 __private_extern__ OSStatus
301 _SecKeychainSearchCreateFromAttributes(CFTypeRef keychainOrArray
, SecItemClass itemClass
, const SecKeychainAttributeList
*attrList
, SecKeychainSearchRef
*searchRef
)
303 #undef SecKeychainSearchCreateFromAttributes
304 static typeof (SecKeychainSearchCreateFromAttributes
) *dyfunc
= NULL
;
306 void *image
= __loadSecurity();
307 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_SecKeychainSearchCreateFromAttributes", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
309 return dyfunc
? dyfunc(keychainOrArray
, itemClass
, attrList
, searchRef
) : -1;