]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/dy_framework.c
configd-53.1.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / dy_framework.c
1 /*
2 * Copyright (c) 2002 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 /*
24 * Modification History
25 *
26 * October 31, 2000 Allan Nathanson <ajn@apple.com>
27 * - initial revision
28 */
29
30
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <sys/stat.h>
34 #include <mach-o/dyld.h>
35 #include <CoreFoundation/CoreFoundation.h>
36
37 #include "dy_framework.h"
38
39
40 static void *
41 __loadIOKit(void) {
42 static const void *image = NULL;
43 if (NULL == image) {
44 const char *framework = "/System/Library/Frameworks/IOKit.framework/IOKit";
45 struct stat statbuf;
46 const char *suffix = getenv("DYLD_IMAGE_SUFFIX");
47 char path[MAXPATHLEN];
48
49 strcpy(path, framework);
50 if (suffix) strcat(path, suffix);
51 if (0 <= stat(path, &statbuf)) {
52 image = NSAddImage(path, NSADDIMAGE_OPTION_NONE);
53 } else {
54 image = NSAddImage(framework, NSADDIMAGE_OPTION_NONE);
55 }
56 }
57 return (void *)image;
58 }
59
60
61 __private_extern__ CFMutableDictionaryRef
62 _IOBSDNameMatching(mach_port_t masterPort, unsigned int options, const char *bsdName)
63 {
64 static CFMutableDictionaryRef (*dyfunc)(mach_port_t, unsigned int, const char *) = NULL;
65 if (!dyfunc) {
66 void *image = __loadIOKit();
67 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOBSDNameMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
68 }
69 return dyfunc ? dyfunc(masterPort, options, bsdName) : NULL;
70 }
71
72
73 __private_extern__ io_object_t
74 _IOIteratorNext(io_iterator_t iterator)
75 {
76 static io_object_t (*dyfunc)(io_iterator_t) = NULL;
77 if (!dyfunc) {
78 void *image = __loadIOKit();
79 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOIteratorNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
80 }
81 return dyfunc ? dyfunc(iterator) : 0;
82 }
83
84
85 __private_extern__ kern_return_t
86 _IOMasterPort(mach_port_t bootstrapPort, mach_port_t *masterPort)
87 {
88 static kern_return_t (*dyfunc)(mach_port_t, mach_port_t *) = NULL;
89 if (!dyfunc) {
90 void *image = __loadIOKit();
91 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOMasterPort", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
92 }
93 return dyfunc ? dyfunc(bootstrapPort, masterPort) : KERN_FAILURE;
94 }
95
96
97 __private_extern__ kern_return_t
98 _IOObjectRelease(io_object_t object)
99 {
100 static kern_return_t (*dyfunc)(io_object_t) = NULL;
101 if (!dyfunc) {
102 void *image = __loadIOKit();
103 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOObjectRelease", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
104 }
105 return dyfunc ? dyfunc(object) : KERN_FAILURE;
106 }
107
108
109 __private_extern__ CFTypeRef
110 _IORegistryEntryCreateCFProperty(io_registry_entry_t entry, CFStringRef key, CFAllocatorRef allocator, IOOptionBits options)
111 {
112 static CFTypeRef (*dyfunc)(io_registry_entry_t, CFStringRef, CFAllocatorRef, IOOptionBits) = NULL;
113 if (!dyfunc) {
114 void *image = __loadIOKit();
115 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryCreateCFProperty", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
116 }
117 return dyfunc ? dyfunc(entry, key, allocator, options) : NULL;
118 }
119
120
121 __private_extern__ kern_return_t
122 _IORegistryEntryCreateCFProperties(io_registry_entry_t entry, CFMutableDictionaryRef *properties, CFAllocatorRef allocator, IOOptionBits options)
123 {
124 static kern_return_t (*dyfunc)(io_registry_entry_t, CFMutableDictionaryRef *, CFAllocatorRef, IOOptionBits) = NULL;
125 if (!dyfunc) {
126 void *image = __loadIOKit();
127 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryCreateCFProperties", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
128 }
129 return dyfunc ? dyfunc(entry, properties, allocator, options) : KERN_FAILURE;
130 }
131
132
133 __private_extern__ kern_return_t
134 _IORegistryEntryGetParentEntry(io_registry_entry_t entry, const io_name_t plane, io_registry_entry_t *parent)
135 {
136 static kern_return_t (*dyfunc)(io_registry_entry_t, const io_name_t, io_registry_entry_t *) = NULL;
137 if (!dyfunc) {
138 void *image = __loadIOKit();
139 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryGetParentEntry", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
140 }
141 return dyfunc ? dyfunc(entry, plane, parent) : NULL;
142 }
143
144
145 __private_extern__ kern_return_t
146 _IORegistryEntryGetPath(io_registry_entry_t entry, const io_name_t plane, io_string_t path)
147 {
148 static kern_return_t (*dyfunc)(io_registry_entry_t, const io_name_t, io_string_t) = NULL;
149 if (!dyfunc) {
150 void *image = __loadIOKit();
151 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryGetPath", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
152 }
153 return dyfunc ? dyfunc(entry, plane, path) : KERN_FAILURE;
154 }
155
156
157 __private_extern__ kern_return_t
158 _IOServiceGetMatchingServices(mach_port_t masterPort, CFDictionaryRef matching, io_iterator_t *existing)
159 {
160 static kern_return_t (*dyfunc)(mach_port_t, CFDictionaryRef, io_iterator_t *) = NULL;
161 if (!dyfunc) {
162 void *image = __loadIOKit();
163 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOServiceGetMatchingServices", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
164 }
165 return dyfunc ? dyfunc(masterPort, matching, existing) : KERN_FAILURE;
166 }
167
168
169 __private_extern__ CFMutableDictionaryRef
170 _IOServiceMatching(const char *name)
171 {
172 static CFMutableDictionaryRef (*dyfunc)(const char *) = NULL;
173 if (!dyfunc) {
174 void *image = __loadIOKit();
175 if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOServiceMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
176 }
177 return dyfunc ? dyfunc(name) : NULL;
178 }