本文整理汇总了C++中NSCreateObjectFileImageFromFile函数的典型用法代码示例。如果您正苦于以下问题:C++ NSCreateObjectFileImageFromFile函数的具体用法?C++ NSCreateObjectFileImageFromFile怎么用?C++ NSCreateObjectFileImageFromFile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NSCreateObjectFileImageFromFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ggDarwinDLOpen
/* ggDarwinDLOpen implements a "dlopen" wrapper
*/
gg_dlhand ggDarwinDLOpen(const char *filename, int flags)
{
gg_dlhand ret = NULL;
struct gg_dlhand_darwin_t *darwin_ret = NULL;
NSLinkEditErrorHandlers error_handlers;
const char *pathname, *modulename;
darwin_ret = (struct gg_dlhand_darwin_t *)malloc(sizeof(struct gg_dlhand_darwin_t));
if (darwin_ret == NULL) return ret;
ret = (void *)darwin_ret;
if (flags & GG_MODULE_GLOBAL) {
darwin_ret->nsmodule_flags = NSLINKMODULE_OPTION_NONE;
} else {
darwin_ret->nsmodule_flags = NSLINKMODULE_OPTION_PRIVATE;
} /* if */
splitstring(filename, &pathname, &modulename);
dlerror_code = NSCreateObjectFileImageFromFile(pathname, &darwin_ret->objectFileImage);
ggstrlcpy(dlerror_filename, filename, sizeof(dlerror_filename));
switch (dlerror_code) {
case NSObjectFileImageSuccess:
break;
case NSObjectFileImageFailure:
case NSObjectFileImageInappropriateFile:
case NSObjectFileImageArch:
case NSObjectFileImageFormat:
case NSObjectFileImageAccess:
goto err0;
} /* switch */
/* Install our own error handlers */
error_handlers.undefined = ggDarwinErrorUndefined;
error_handlers.multiple = ggDarwinErrorMultiple;
error_handlers.linkEdit = ggDarwinErrorLinkEdit;
#if 0
/* Let the default handlers do their work
* as long as our own error handlers are stubs.
*/
NSInstallLinkEditErrorHandlers(&error_handlers);
#endif
/* try to load the module now */
darwin_ret->nsmodule = NSLinkModule(darwin_ret->objectFileImage,
modulename, darwin_ret->nsmodule_flags);
/* Either we return successful here or the error handlers
* already aborted/exited the app before.
*/
return ret;
err0:
free(ret);
return NULL;
} /* ggDarwinDLOpen */
示例2: dlinit
static void *dlopen(const char *path, int mode)
{
void *handle= 0;
NSObjectFileImage ofi= 0;
if (!dlInitialised)
{
dlinit();
dlInitialised= 1;
}
if (!path)
return DL_APP_CONTEXT;
switch (NSCreateObjectFileImageFromFile(path, &ofi))
{
case NSObjectFileImageSuccess:
handle= NSLinkModule(ofi, path, NSLINKMODULE_OPTION_RETURN_ON_ERROR);
NSDestroyObjectFileImage(ofi);
break;
case NSObjectFileImageInappropriateFile:
handle= (void *)NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
break;
default:
handle= 0;
break;
}
if (!handle)
dlSetError("could not load shared object: %s", path);
dprintf((stderr, "dlopen: %s => %d\n", path, (int)handle));
return handle;
}
示例3: loadSharedObject
void *
loadSharedObject (const char *path) {
NSObjectFileImage image;
switch (NSCreateObjectFileImageFromFile(path, &image)) {
case NSObjectFileImageSuccess: {
NSModule module = NSLinkModule(image, path, NSLINKMODULE_OPTION_RETURN_ON_ERROR);
if (module) return module;
logDyldError("link module");
logMessage(LOG_ERR, "shared object not linked: %s", path);
break;
}
case NSObjectFileImageInappropriateFile:
logMessage(LOG_ERR, "inappropriate object type: %s", path);
break;
case NSObjectFileImageArch:
logMessage(LOG_ERR, "incorrect object architecture: %s", path);
break;
case NSObjectFileImageFormat:
logMessage(LOG_ERR, "invalid object format: %s", path);
break;
case NSObjectFileImageAccess:
logMessage(LOG_ERR, "inaccessible object: %s", path);
break;
case NSObjectFileImageFailure:
default:
logMessage(LOG_ERR, "shared object not loaded: %s", path);
break;
}
return NULL;
}
示例4: NSInstallLinkEditErrorHandlers
void *dlopen(char *filename, int unused)
{
NSObjectFileImage myImage;
NSModule myModule;
if (firstLoad)
{
/* If we are loading our first symbol (huzzah!) we should go ahead
* and install link editor error handling!
*/
NSLinkEditErrorHandlers linkEditorErrorHandlers;
linkEditorErrorHandlers.undefined = undefinedErrorHandler;
linkEditorErrorHandlers.multiple = multipleErrorHandler;
linkEditorErrorHandlers.linkEdit = linkEditErrorHandler;
NSInstallLinkEditErrorHandlers(&linkEditorErrorHandlers);
firstLoad = FALSE;
}
myDlError = NSCreateObjectFileImageFromFile(filename, &myImage);
if (myDlError != NSObjectFileImageSuccess)
return(NULL);
myModule = NSLinkModule(myImage, filename, NSLINKMODULE_OPTION_PRIVATE);
return((void *)myModule);
}
示例5: pr_LoadMachDyldModule
static NSModule
pr_LoadMachDyldModule(const char *name)
{
NSObjectFileImage ofi;
NSModule h = NULL;
if (NSCreateObjectFileImageFromFile(name, &ofi)
== NSObjectFileImageSuccess) {
h = NSLinkModule(ofi, name, NSLINKMODULE_OPTION_PRIVATE
| NSLINKMODULE_OPTION_RETURN_ON_ERROR);
if (h == NULL) {
NSLinkEditErrors linkEditError;
int errorNum;
const char *fileName;
const char *errorString;
NSLinkEditError(&linkEditError, &errorNum, &fileName, &errorString);
PR_LOG(_pr_linker_lm, PR_LOG_MIN,
("LoadMachDyldModule error %d:%d for file %s:\n%s",
linkEditError, errorNum, fileName, errorString));
}
if (NSDestroyObjectFileImage(ofi) == FALSE) {
if (h) {
(void)NSUnLinkModule(h, NSUNLINKMODULE_OPTION_NONE);
h = NULL;
}
}
}
return h;
}
示例6: caml_dlopen
void * caml_dlopen(char * libname, int for_execution)
{
NSObjectFileImage image;
entry_t *bentry = caml_lookup_bundle(libname);
NSObjectFileImageReturnCode retCode;
void *result = NULL;
if (bentry->count > 0)
return bentry->handle;
retCode = NSCreateObjectFileImageFromFile(libname, &image);
switch (retCode) {
case NSObjectFileImageSuccess:
dlerror_string = NULL;
result = (void*)NSLinkModule(image, libname, NSLINKMODULE_OPTION_BINDNOW
| NSLINKMODULE_OPTION_RETURN_ON_ERROR);
if (result != NULL) {
bentry->count++;
bentry->handle = result;
}
else NSDestroyObjectFileImage(image);
break;
case NSObjectFileImageAccess:
dlerror_string = "cannot access this bundle"; break;
case NSObjectFileImageArch:
dlerror_string = "this bundle has wrong CPU architecture"; break;
case NSObjectFileImageFormat:
case NSObjectFileImageInappropriateFile:
dlerror_string = "this file is not a proper bundle"; break;
default:
dlerror_string = "could not read object file"; break;
}
return result;
}
示例7: WXUNUSED
void *dlopen(const char *path, int WXUNUSED(mode) /* mode is ignored */)
{
NSObjectFileImage ofile;
NSModule handle = NULL;
int dyld_result = NSCreateObjectFileImageFromFile(path, &ofile);
if ( dyld_result != NSObjectFileImageSuccess )
{
handle = NULL;
}
else
{
handle = NSLinkModule
(
ofile,
path,
NSLINKMODULE_OPTION_BINDNOW |
NSLINKMODULE_OPTION_RETURN_ON_ERROR
);
}
if ( !handle )
TranslateError(path, dyld_result);
return handle;
}
示例8: int
/* dlopen */
void *darwin_dlopen(const char *path, int mode)
{
void *module = 0;
NSObjectFileImage ofi = 0;
NSObjectFileImageReturnCode ofirc;
static int (*make_private_module_public) (NSModule module) = 0;
unsigned int flags = NSLINKMODULE_OPTION_RETURN_ON_ERROR | NSLINKMODULE_OPTION_PRIVATE;
sys::coreout << "darwin try bind module: " << path << sys::eofl;
/* If we got no path, the app wants the global namespace, use -1 as the marker
in this case */
if (!path)
return (void *)-1;
/* Create the object file image, works for things linked with the -bundle arg to ld */
ofirc = NSCreateObjectFileImageFromFile(path, &ofi);
switch (ofirc)
{
case NSObjectFileImageSuccess:
/* It was okay, so use NSLinkModule to link in the image */
if (!(mode & RTLD_LAZY)) flags += NSLINKMODULE_OPTION_BINDNOW;
module = NSLinkModule(ofi, path,flags);
sys::coreout << "darwin bind module: " << path << sys::eofl;
/* Don't forget to destroy the object file image, unless you like leaks */
NSDestroyObjectFileImage(ofi);
/* If the mode was global, then change the module, this avoids
multiply defined symbol errors to first load private then make
global. Silly, isn't it. */
if ((mode & RTLD_GLOBAL))
{
if (!make_private_module_public)
{
_dyld_func_lookup("__dyld_NSMakePrivateModulePublic",
(unsigned long *)&make_private_module_public);
}
make_private_module_public(module);
}
break;
case NSObjectFileImageInappropriateFile:
/* It may have been a dynamic library rather than a bundle, try to load it */
module = (void *)NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
sys::coreout << " wrong filetype use addimage: " << (void*)module << sys::eofl;
break;
case NSObjectFileImageFailure:
error(0,"Object file setup failure : \"%s\"", path);
return 0;
case NSObjectFileImageArch:
error(0,"No object for this architecture : \"%s\"", path);
return 0;
case NSObjectFileImageFormat:
error(0,"Bad object file format : \"%s\"", path);
return 0;
case NSObjectFileImageAccess:
error(0,"Can't read object file : \"%s\"", path);
return 0;
}
if (!module)
error(0, "Can not open \"%s\"", path);
return module;
}
示例9: OW_LOG_DEBUG
SharedLibraryRef
dyldSharedLibraryLoader::loadSharedLibrary(const String& filename,
const LoggerRef& logger) const
{
OW_LOG_DEBUG(logger, Format("Load request for %1 received.", filename));
NSObjectFileImage image = 0;
NSObjectFileImageReturnCode dsoerr = NSCreateObjectFileImageFromFile(filename.c_str(), &image);
const char* err_msg = NULL;
NSModule libhandle = NULL;
if (dsoerr == NSObjectFileImageSuccess)
{
libhandle = NSLinkModule(image, filename.c_str(), NSLINKMODULE_OPTION_RETURN_ON_ERROR | NSLINKMODULE_OPTION_PRIVATE);
if (!libhandle)
{
NSLinkEditErrors errors;
int errorNumber;
const char *fileName;
NSLinkEditError(&errors, &errorNumber, &fileName, &err_msg);
}
NSDestroyObjectFileImage(image);
}
else if ((dsoerr == NSObjectFileImageFormat ||
dsoerr == NSObjectFileImageInappropriateFile) &&
NSAddLibrary(filename.c_str()) == TRUE)
{
OW_LOG_ERROR(logger, Format("NSCreateObject: %1 failed with error \"%2\"",
filename, dsoerr));
// libhandle = (NSModule)DYLD_LIBRARY_HANDLE;
}
else
{
err_msg = "cannot create object file image or add library";
OW_LOG_ERROR(logger, Format("NSCreateObject: %1 failed with error %2",
filename, dsoerr));
}
if (libhandle)
{
try
{
return SharedLibraryRef( new dyldSharedLibrary(libhandle,
filename));
}
catch (...)
{
NSUnLinkModule(libhandle, FALSE);
throw;
}
}
else
{
OW_LOG_ERROR(logger, Format("dyldSharedLibraryLoader::loadSharedLibrary:"
" %1", err_msg));
return SharedLibraryRef( 0 );
}
}
示例10: WXUNUSED
static void *wx_darwin_dlopen(const char *path, int WXUNUSED(mode) /* mode is ignored */)
{
NSObjectFileImage ofile;
NSModule handle = NULL;
unsigned dyld_result = NSCreateObjectFileImageFromFile(path, &ofile);
if ( dyld_result != NSObjectFileImageSuccess )
{
handle = NULL;
static const char *const errorStrings[] =
{
"%d: Object Image Load Failure",
"%d: Object Image Load Success",
"%d: Not an recognisable object file",
"%d: No valid architecture",
"%d: Object image has an invalid format",
"%d: Invalid access (permissions?)",
"%d: Unknown error code from NSCreateObjectFileImageFromFile"
};
const int index = dyld_result < WXSIZEOF(errorStrings)
? dyld_result
: WXSIZEOF(errorStrings) - 1;
// this call to sprintf() is safe as strings above are fixed at
// compile-time and are shorter than WXSIZEOF(dl_last_error)
sprintf(dl_last_error, errorStrings[index], dyld_result);
}
else
{
handle = NSLinkModule
(
ofile,
path,
NSLINKMODULE_OPTION_BINDNOW |
NSLINKMODULE_OPTION_RETURN_ON_ERROR
);
if ( !handle )
{
NSLinkEditErrors err;
int code;
const char *filename;
const char *errmsg;
NSLinkEditError(&err, &code, &filename, &errmsg);
strncpy(dl_last_error, errmsg, WXSIZEOF(dl_last_error)-1);
dl_last_error[WXSIZEOF(dl_last_error)-1] = '\0';
}
}
return handle;
}
示例11: pg_dlopen
void *
pg_dlopen(char *filename)
{
NSObjectFileImage image;
cofiff_result = NSCreateObjectFileImageFromFile(filename, &image);
if (cofiff_result != NSObjectFileImageSuccess)
return NULL;
return NSLinkModule(image, filename,
NSLINKMODULE_OPTION_BINDNOW |
NSLINKMODULE_OPTION_RETURN_ON_ERROR);
}
示例12: NSCreateObjectFileImageFromFile
void *vmddlopen( const char *path) {
NSObjectFileImage image;
NSObjectFileImageReturnCode retval;
NSModule module;
retval = NSCreateObjectFileImageFromFile(path, &image);
if (retval != NSObjectFileImageSuccess)
return NULL;
module = NSLinkModule(image, path,
NSLINKMODULE_OPTION_BINDNOW | NSLINKMODULE_OPTION_PRIVATE
| NSLINKMODULE_OPTION_RETURN_ON_ERROR);
return module; /* module will be NULL on error */
}
示例13: NSCreateObjectFileImageFromFile
void *ILDynLibraryOpen(const char *name)
{
NSObjectFileImage file;
NSObjectFileImageReturnCode result;
NSModule module;
void *image;
const char *msg;
/* Attempt to open the dylib file */
result = NSCreateObjectFileImageFromFile(name, &file);
if(result == NSObjectFileImageInappropriateFile)
{
/* May be an image, and not a bundle */
image = (void *)NSAddImage(name, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
if(image)
{
return image;
}
}
if(result != NSObjectFileImageSuccess)
{
switch(result)
{
case NSObjectFileImageFailure:
msg = " (NSObjectFileImageFailure)"; break;
case NSObjectFileImageInappropriateFile:
msg = " (NSObjectFileImageInappropriateFile)"; break;
case NSObjectFileImageArch:
msg = " (NSObjectFileImageArch)"; break;
case NSObjectFileImageFormat:
msg = " (NSObjectFileImageFormat)"; break;
case NSObjectFileImageAccess:
msg = " (NSObjectFileImageAccess)"; break;
default:
msg = ""; break;
}
#ifdef IL_DYNLIB_DEBUG
fprintf(stderr, "%s: could not load dynamic library%s\n", name, msg);
#endif
return 0;
}
/* Link the module dependencies */
module = NSLinkModule(file, name,
NSLINKMODULE_OPTION_BINDNOW |
NSLINKMODULE_OPTION_PRIVATE |
NSLINKMODULE_OPTION_RETURN_ON_ERROR);
return (void *)module;
}
示例14: vm_open
/* A function called through the vtable to open a module with this
loader. Returns an opaque representation of the newly opened
module for processing with this loader's other vtable functions. */
static lt_module
vm_open (lt_user_data loader_data, const char *filename,
lt_dladvise LT__UNUSED advise)
{
lt_module module = 0;
NSObjectFileImage ofi = 0;
if (!filename)
{
return (lt_module) -1;
}
switch (NSCreateObjectFileImageFromFile (filename, &ofi))
{
case NSObjectFileImageSuccess:
module = NSLinkModule (ofi, filename, NSLINKMODULE_OPTION_RETURN_ON_ERROR
| NSLINKMODULE_OPTION_PRIVATE
| NSLINKMODULE_OPTION_BINDNOW);
NSDestroyObjectFileImage (ofi);
if (module)
{
lt__module_export (module);
}
break;
case NSObjectFileImageInappropriateFile:
if (lt__image_symbol_p && lt__image_symbol)
{
module = (lt_module) lt__addimage(filename,
NSADDIMAGE_OPTION_RETURN_ON_ERROR);
}
break;
case NSObjectFileImageFailure:
case NSObjectFileImageArch:
case NSObjectFileImageFormat:
case NSObjectFileImageAccess:
/*NOWORK*/
break;
}
if (!module)
{
DYLD__SETERROR (CANNOT_OPEN);
}
return module;
}
示例15: mydlopen
static void *
mydlopen(char *path)
{
int dyld_result;
NSObjectFileImage ofile;
NSModule handle = NULL;
dyld_result = NSCreateObjectFileImageFromFile(path, &ofile);
if (dyld_result != NSObjectFileImageSuccess) {
LOCAL_dl_errno = dyld_result;
} else {
/* NSLinkModule will cause the run to abort on any link error's */
/* not very friendly but the error recovery functionality is limited */
handle = NSLinkModule(ofile, path, TRUE);
} return handle;
}