MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / dlopen

Function dlopen

tests/licensedcode/data/perf/udll.cxx:187–243  ·  view source on GitHub ↗

dlopen */

Source from the content-addressed store, hash-verified

185
186/* dlopen */
187static void *dlopen(const char *path, int mode)
188{
189 void *module = 0;
190 NSObjectFileImage ofi = 0;
191 NSObjectFileImageReturnCode ofirc;
192 static int (*make_private_module_public) (NSModule module) = 0;
193 unsigned int flags = NSLINKMODULE_OPTION_RETURN_ON_ERROR | NSLINKMODULE_OPTION_PRIVATE;
194
195 /* If we got no path, the app wants the global namespace, use -1 as the marker
196 in this case */
197 if (!path)
198 return (void *)-1;
199
200 /* Create the object file image, works for things linked with the -bundle arg to ld */
201 ofirc = NSCreateObjectFileImageFromFile(path, &ofi);
202 switch (ofirc)
203 {
204 case NSObjectFileImageSuccess:
205 /* It was okay, so use NSLinkModule to link in the image */
206 if (!(mode & RTLD_LAZY)) flags += NSLINKMODULE_OPTION_BINDNOW;
207 module = NSLinkModule(ofi, path,flags);
208 /* Don't forget to destroy the object file image, unless you like leaks */
209 NSDestroyObjectFileImage(ofi);
210 /* If the mode was global, then change the module, this avoids
211 multiply defined symbol errors to first load private then make
212 global. Silly, isn't it. */
213 if ((mode & RTLD_GLOBAL))
214 {
215 if (!make_private_module_public)
216 {
217 _dyld_func_lookup("__dyld_NSMakePrivateModulePublic",
218 (unsigned long *)&make_private_module_public);
219 }
220 make_private_module_public(module);
221 }
222 break;
223 case NSObjectFileImageInappropriateFile:
224 /* It may have been a dynamic library rather than a bundle, try to load it */
225 module = (void *)NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
226 break;
227 case NSObjectFileImageFailure:
228 error(0,"Object file setup failure : \"%s\"", path);
229 return 0;
230 case NSObjectFileImageArch:
231 error(0,"No object for this architecture : \"%s\"", path);
232 return 0;
233 case NSObjectFileImageFormat:
234 error(0,"Bad object file format : \"%s\"", path);
235 return 0;
236 case NSObjectFileImageAccess:
237 error(0,"Can't read object file : \"%s\"", path);
238 return 0;
239 }
240 if (!module)
241 error(0, "Can not open \"%s\"", path);
242 return module;
243}
244

Callers 1

OpenMethod · 0.70

Calls 1

errorFunction · 0.70

Tested by

no test coverage detected