/* 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 LT__UNUSED loader_data, const char *filename, lt_dladvise LT__UNUSED advise) { static shl_t self = (shl_t) 0; lt_module module = shl_load (filename, LT_BIND_FLAGS, 0L); /* Since searching for a symbol against a NULL module handle will also look in everything else that was already loaded and exported with the -E compiler flag, we always cache a handle saved before any modules are loaded. */ if (!self) { void *address; shl_findsym (&self, "main", TYPE_UNDEFINED, &address); } if (!filename) { module = self; } else { module = shl_load (filename, LT_BIND_FLAGS, 0L); if (!module) { LT__SETERROR (CANNOT_OPEN); } } return module; }
static int dl_load(DSO *dso, const char *filename) { shl_t ptr; char translated[DSO_MAX_TRANSLATED_SIZE]; int len; /* The same comment as in dlfcn_load applies here. bleurgh. */ len = strlen(filename) + strlen(extension); if((dso->flags & DSO_FLAG_NAME_TRANSLATION) && (len + 3 < DSO_MAX_TRANSLATED_SIZE) && (strstr(filename, "/") == NULL)) { sprintf(translated, "lib%s%s", filename, extension); ptr = shl_load(translated, BIND_IMMEDIATE, NULL); } else ptr = shl_load(filename, BIND_IMMEDIATE, NULL); if(ptr == NULL) { DSOerr(DSO_F_DL_LOAD,DSO_R_LOAD_FAILED); return(0); } if(!sk_push(dso->meth_data, (char *)ptr)) { DSOerr(DSO_F_DL_LOAD,DSO_R_STACK_ERROR); shl_unload(ptr); return(0); } return(1); }
int TclpDlopen( Tcl_Interp *interp, /* Used for error reporting. */ Tcl_Obj *pathPtr, /* Name of the file containing the desired * code (UTF-8). */ Tcl_LoadHandle *loadHandle, /* Filled with token for dynamically loaded * file which will be passed back to * (*unloadProcPtr)() to unload the file. */ Tcl_FSUnloadFileProc **unloadProcPtr) /* Filled with address of Tcl_FSUnloadFileProc * function which should be used for this * file. */ { shl_t handle; CONST char *native; char *fileName = Tcl_GetString(pathPtr); /* * The flags below used to be BIND_IMMEDIATE; they were changed at the * suggestion of Wolfgang Kechel ([email protected]): "This enables * verbosity for missing symbols when loading a shared lib and allows to * load libtk8.0.sl into tclsh8.0 without problems. In general, this * delays resolving symbols until they are actually needed. Shared libs * do no longer need all libraries linked in when they are build." */ /* * First try the full path the user gave us. This is particularly * important if the cwd is inside a vfs, and we are trying to load using a * relative path. */ native = Tcl_FSGetNativePath(pathPtr); handle = shl_load(native, BIND_DEFERRED|BIND_VERBOSE, 0L); if (handle == NULL) { /* * Let the OS loader examine the binary search path for whatever * string the user gave us which hopefully refers to a file on the * binary path. */ Tcl_DString ds; native = Tcl_UtfToExternalDString(NULL, fileName, -1, &ds); handle = shl_load(native, BIND_DEFERRED|BIND_VERBOSE|DYNAMIC_PATH, 0L); Tcl_DStringFree(&ds); } if (handle == NULL) { Tcl_AppendResult(interp, "couldn't load file \"", fileName, "\": ", Tcl_PosixError(interp), (char *) NULL); return TCL_ERROR; } *loadHandle = (Tcl_LoadHandle) handle; *unloadProcPtr = &TclpUnloadFile; return TCL_OK; }
int main () { shl_t solib_handle; int dummy; int status; int (*solib_main) (int); /* Load a shlib, with immediate binding of all symbols. Note that the pathname of the loaded shlib is assumed to be relative to the testsuite directory (from whence the tested GDB is run), not from dot/. */ dummy = 1; /* Put some code between shl_ calls... */ solib_handle = shl_load ("gdb.base/solib1.sl", BIND_IMMEDIATE, 0); /* Find a function within the shlib, and call it. */ status = shl_findsym (&solib_handle, "solib_main", TYPE_PROCEDURE, (long *) &solib_main); status = (*solib_main) (dummy); /* Unload the shlib. */ status = shl_unload (solib_handle); /* Load a different shlib, with deferred binding of all symbols. */ dummy = 2; solib_handle = shl_load ("gdb.base/solib2.sl", BIND_DEFERRED, 0); /* Find a function within the shlib, and call it. */ status = shl_findsym (&solib_handle, "solib_main", TYPE_PROCEDURE, (long *) &solib_main); status = (*solib_main) (dummy); /* Unload the shlib. */ status = shl_unload (solib_handle); /* Reload the first shlib again, with deferred symbol binding this time. */ dummy = 3; solib_handle = shl_load ("gdb.base/solib1.sl", BIND_IMMEDIATE, 0); /* Unload it without trying to find any symbols in it. */ status = shl_unload (solib_handle); /* All done. */ dummy = -1; return 0; }
/* static */ wxDllType wxDynamicLibrary::RawLoad(const wxString& libname, int flags) { wxASSERT_MSG( !(flags & wxDL_NOW) || !(flags & wxDL_LAZY), wxT("wxDL_LAZY and wxDL_NOW are mutually exclusive.") ); #ifdef USE_POSIX_DL_FUNCS // we need to use either RTLD_NOW or RTLD_LAZY because if we call dlopen() // with flags == 0 recent versions of glibc just fail the call, so use // RTLD_NOW even if wxDL_NOW was not specified int rtldFlags = flags & wxDL_LAZY ? RTLD_LAZY : RTLD_NOW; if ( flags & wxDL_GLOBAL ) rtldFlags |= RTLD_GLOBAL; return dlopen(libname.fn_str(), rtldFlags); #else // !USE_POSIX_DL_FUNCS int shlFlags = 0; if ( flags & wxDL_LAZY ) { shlFlags |= BIND_DEFERRED; } else if ( flags & wxDL_NOW ) { shlFlags |= BIND_IMMEDIATE; } return shl_load(libname.fn_str(), shlFlags, 0); #endif // USE_POSIX_DL_FUNCS/!USE_POSIX_DL_FUNCS }
static XModuleType open_library (void) { char *library = libraryName; char *dot; XModuleType module; for (;;) { #if defined(hpux) module = shl_load(library, BIND_DEFERRED, 0L); #else #ifdef _MSC_VER module = LoadLibrary(library); #else module = dlopen(library, RTLD_LAZY); #endif #endif if (module) return module; dot = strrchr (library, '.'); if (!dot) break; *dot = '\0'; } return NULL; }
GError GPlugLoader::LoadFilePlug(const GChar8 *FullLibraryName) { GPlugHandle handle = NULL; // we don't wanna a null filename if (!FullLibraryName) return G_INVALID_PARAMETER; // unplug current library UnloadPlug(); #if defined(G_OS_WIN) && !defined(__CYGWIN__) handle = LoadLibraryA(FullLibraryName); #elif defined(G_OS_HPUX) // BIND_FIRST is necessary for some reason handle = shl_load(FullLibraryName, BIND_DEFERRED | BIND_FIRST | BIND_VERBOSE, 0); // other Unix (it works also on MacOSX and Tiger) #else handle = dlopen(FullLibraryName, RTLD_LAZY | RTLD_GLOBAL); // dlopen will not work with files in the current directory unless // they are prefaced with './' (DB - Nov 5, 2003). // So we must check if file was expressed as a local file (without path) GString fPath = StrUtils::ExtractFilePath(FullLibraryName); if ((!handle) && (fPath.length() <= 0)) { GString localLibraryName = GString("./") + GString(FullLibraryName); handle = dlopen(StrUtils::ToAscii(localLibraryName), RTLD_LAZY | RTLD_GLOBAL); } #endif if (!handle) return G_INVALID_FORMAT; gPlugHandle = handle; return G_NO_ERROR; }
void *dlopen(const char *fname, int mode) { shl_t handle; LibEntry entry = NULL; dlerrno = 0; if (fname == NULL) handle = PROG_HANDLE; else { handle = shl_load(fname, mode | BIND_VERBOSE, 0L); if (handle != NULL) { if ((entry = find_lib_entry(handle)) == NULL) { if ((entry = new_lib_entry(handle)) == NULL) { shl_unload(handle); handle = NULL; } } else increment_lib_entry_count(entry); } if (handle == NULL) { dlerrno = 1; sprintf(errbuf, "can't open %s", fname); } } #ifdef DEBUG printf("opening library %s, handle = %x, count = %d\n", fname, handle, entry ? lib_entry_count(entry) : -1); if (dlerrno) printf("%s\n", dlerror()); #endif return (void *) handle; }
dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, const char *pathname, FILE *fp) { dl_funcptr p; shl_t lib; int flags; char funcname[258]; flags = BIND_FIRST | BIND_DEFERRED; if (Py_VerboseFlag) { flags = DYNAMIC_PATH | BIND_FIRST | BIND_IMMEDIATE | BIND_NONFATAL | BIND_VERBOSE; printf("shl_load %s\n",pathname); } lib = shl_load(pathname, flags, 0); /* XXX Chuck Blake once wrote that 0 should be BIND_NOSTART? */ if (lib == NULL) { char buf[256]; if (Py_VerboseFlag) perror(pathname); sprintf(buf, "Failed to load %.200s", pathname); PyErr_SetString(PyExc_ImportError, buf); return NULL; } sprintf(funcname, FUNCNAME_PATTERN, shortname); if (Py_VerboseFlag) printf("shl_findsym %s\n", funcname); shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p); if (p == NULL && Py_VerboseFlag) perror(funcname); return p; }
//========================================================================================== static DLL *dll_load( const char *name ) { #if defined(_WIN32) || defined(WIN32) || defined(__WIN32__) return (DLL *) LoadLibrary( name ); #else // UNIX char dllname[512]; strcpy(dllname, name); #if defined MACOSX strcat(dllname, ".dylib"); return (DLL *) dlopen(dllname, RTLD_NOW); #elif defined LINUX || defined SUN strcat( dllname, ".so" ); return (DLL *) dlopen(dllname, RTLD_NOW); #elif defined HP || defined HPUX strcat(dllname, ".sl"); return shl_load(dllname, BIND_DEFERRED|DYNAMIC_PATH, 0L); #else strcat( dllname, ".so" ); return (DLL *) dlopen(dllname, RTLD_NOW); #endif #endif }
/* We reference count dlopen() and dlclose() of modules; unfortunately, * since XCloseIM, XCloseOM, XlcClose aren't wrapped, but directly * call the close method of the object, we leak a reference count every * time we open then close a module. Fixing this would require * either creating proxy objects or hooks for close_im/close_om * in XLCd */ static Bool open_object( XI18NObjectsList object, char *lc_dir) { char *path; if (object->refcount == 0) { path = __lc_path(object->dl_name, lc_dir); if (!path) return False; #if defined(hpux) object->dl_module = shl_load(path, BIND_DEFERRED, 0L); #else object->dl_module = dlopen(path, RTLD_LAZY); #endif Xfree(path); if (!object->dl_module) return False; } object->refcount++; return True; }
void * pg_dlopen(char *filename) { shl_t handle = shl_load(filename, BIND_DEFERRED, 0); return((void *) handle); }
static void *dlopen(const char *libname, int how) { shl_t lib; lib = shl_load(libname, how, 0L); return (void *)lib; }
void SharedLibraryImpl::loadImpl(const std::string& path) { FastMutex::ScopedLock lock(_mutex); if (_handle) throw LibraryAlreadyLoadedException(path); _handle = shl_load(path.c_str(), BIND_DEFERRED, 0); if (!_handle) throw LibraryLoadException(path); _path = path; }
bool QLibraryPrivate::load_sys() { if (QLibrary::isLibrary(fileName)) pHnd = (void*)shl_load(QFile::encodeName(fileName), BIND_DEFERRED | BIND_NONFATAL | DYNAMIC_PATH, 0); if (pluginState != IsAPlugin) { if (!pHnd) pHnd = (void*)shl_load(QFile::encodeName(fileName + ".sl"), BIND_DEFERRED | BIND_NONFATAL | DYNAMIC_PATH, 0); if (!pHnd) { QFileInfo fi(fileName); pHnd = (void*)shl_load(QFile::encodeName(fi.path() + "/lib" + fi.fileName() + ".sl"), BIND_DEFERRED | BIND_NONFATAL | DYNAMIC_PATH, 0); } } #if defined(QT_DEBUG_COMPONENT) if (!pHnd) qWarning("QLibrary: Cannot load %s", QFile::encodeName(fileName).constData()); #endif return pHnd != 0; }
void * loadSharedObject (const char *path) { #ifdef HAVE_SHL_LOAD shl_t object = shl_load(path, BIND_IMMEDIATE|BIND_VERBOSE|DYNAMIC_PATH, 0L); if (object) return object; logMessage(LOG_ERR, "Shared library '%s' not loaded: %s", path, strerror(errno)); #endif /* HAVE_SHL_LOAD */ return NULL; }
static void * dLoad(char * libName) { void *q; if(access(libName,R_OK)) return NULL; #ifdef __hpux return shl_load(libName,0,0L); #else q= dlopen(libName, RTLD_NOW); if(!q) printf("%s\n",dlerror()); return q; #endif }
void * dlopen(const char *file, int mode) { int flags = 0; if (mode & RTLD_NOW) flags |= BIND_IMMEDIATE; #ifdef NOT_USED if (mode & RTLD_LAZY) flags |= BIND_DEFERRED; #endif return shl_load(file, flags | BIND_VERBOSE, 0L); }
HINSTANCE myLoadLibrary(char *filename) { #if defined(_WINDOWS) return LoadLibrary( filename ); #elif defined(_HPUX11) return shl_load(filename, BIND_DEFERRED, 0L); #else { return dlopen(filename, RTLD_LAZY); } #endif }
void * pg_dlopen(char *filename) { /* * Use BIND_IMMEDIATE so that undefined symbols cause a failure return * from shl_load(), rather than an abort() later on when we attempt to * call the library! */ shl_t handle = shl_load(filename, BIND_IMMEDIATE | BIND_VERBOSE | DYNAMIC_PATH, 0L); return (void *) handle; }
OSCodeFragment::OSCodeFragment(const char* inPath) : fFragmentP(NULL) { #if defined(HPUX) || defined(HPUX10) shl_t handle; fFragmentP = shl_load(inPath, BIND_IMMEDIATE|BIND_VERBOSE|BIND_NOSTART, 0L); #elif defined(OSF1) ||\ (defined(__FreeBSD_version) && (__FreeBSD_version >= 220000)) fFragmentP = dlopen((char *)inPath, RTLD_NOW | RTLD_GLOBAL); #elif defined(__FreeBSD__) fFragmentP = dlopen(inPath, RTLD_NOW); #elif defined(__sgi__) fFragmentP = dlopen(inPath, RTLD_NOW); // not sure this should be either RTLD_NOW or RTLD_LAZY #elif defined(__Win32__) fFragmentP = ::LoadLibrary(inPath); #elif defined(__MacOSX__) CFStringRef theString = CFStringCreateWithCString( kCFAllocatorDefault, inPath, kCFStringEncodingASCII); // // In MacOSX, our "fragments" are CF bundles, which are really // directories, so our paths are paths to a directory CFURLRef bundleURL = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, theString, kCFURLPOSIXPathStyle, true); // // I figure CF is safe about having NULL passed // into its functions (if fBundle failed to get created). // So, I won't worry about error checking myself fFragmentP = CFBundleCreate( kCFAllocatorDefault, bundleURL ); Boolean success = false; if (fFragmentP != NULL) success = CFBundleLoadExecutable( fFragmentP ); if (!success && fFragmentP != NULL) { CFRelease( fFragmentP ); fFragmentP = NULL; } CFRelease(bundleURL); CFRelease(theString); #else fFragmentP = dlopen(inPath, RTLD_NOW | RTLD_GLOBAL); //fprintf (stderr, "%s\n", dlerror()); #endif }
void load_library() { std::string dllname = to_string(module_.string()); #if defined(LINUX) || defined(SUN) || defined(AIX) || defined(CYGWIN) handle_ = dlopen(dllname.c_str(), RTLD_NOW); if (handle_ == NULL) throw dll_exception(std::string("Could not load library: ") + dlerror() + ": " + module_.string()); #elif defined(HP) handle_ = shl_load(dllname.c_str(), BIND_DEFERRED|DYNAMIC_PATH, 0L); if (handle_ == NULL) throw dll_exception("Could not load library: " + module_.string()); #else /* This type of UNIX has no DLL support yet */ throw dll_exception("Unsupported Unix flavour (please report this): " + module_.string()); #endif }
void *ap_os_dso_load(const char *path) { #if defined(HPUX) || defined(HPUX10) shl_t handle; handle = shl_load(path, BIND_IMMEDIATE|BIND_VERBOSE|BIND_NOSTART, 0L); return (void *)handle; #else #if defined(OSF1) ||\ (defined(__FreeBSD_version) && (__FreeBSD_version >= 220000)) return dlopen((char *)path, RTLD_NOW); #else return dlopen(path, RTLD_NOW); #endif #endif }
/* * shl_load() does not appear to support making symbols invisible to * the global namespace. However, the default is to put the library * last in the search order, which is approximately what we want, * since it will cause symbols that conflict with existing symbols to * be invisible. It is unclear if BIND_FIRST should be used when * bind_local==0, since it may cause the loaded symbols to be used * preferentially to the application's symbols, which is Almost * Always Wrong. --ds */ static gpointer _g_module_open (const gchar *file_name, gboolean bind_lazy, gboolean bind_local) { shl_t shl_handle; shl_handle = shl_load (file_name, (bind_lazy ? BIND_DEFERRED : BIND_IMMEDIATE) | OPT_BIND_FLAGS, 0); if (!shl_handle) { /* the hp-docs say we should better abort() if errno==ENOSYM ;( */ g_module_set_error (g_strerror (errno)); } return (gpointer) shl_handle; }
dll_handle dlopen(char *fname, int mode) { shl_t h = shl_load(fname, BIND_DEFERRED, 0L); shl_t *hp = NULL; if (h) { hp = (shl_t *)malloc(sizeof (shl_t)); if (!hp) { shl_unload(h); } else { *hp = h; } } return (dll_handle)hp; }
Boolean DynamicLibrary::load(void) { // ensure the module is not already loaded PEGASUS_ASSERT(isLoaded() == false); CString cstr = _fileName.getCString(); //_handle = shl_load(cstr, BIND_IMMEDIATE | DYNAMIC_PATH | BIND_VERBOSE, 0L); _handle = shl_load(cstr, BIND_IMMEDIATE | DYNAMIC_PATH, 0L); // increment handle if valid if(_handle == 0) { _increment_handle(_handle); } return(isLoaded()); }
void* DSO_open(char* file,char** evalstring) { shl_t tt_handle; void *d_handle,**plugin_symtab,**plugin_utiltab; int rc,*iptr, (*fptr)(int); func_ptr *function_list; DSO_handle *dso_handle; void (*f)(void *s,void *u); /* these will just have to be void for now */ int i; *evalstring=NULL; mm_log( (1,"DSO_open(file '%s' (0x%08X), evalstring 0x%08X)\n",file,file,evalstring) ); if ( (tt_handle = shl_load(file, BIND_DEFERRED,0L)) == NULL) return NULL; if ( (shl_findsym(&tt_handle, I_EVALSTR,TYPE_UNDEFINED,(void*)evalstring))) return NULL; /* if ( (shl_findsym(&tt_handle, "symbol_table",TYPE_UNDEFINED,(void*)&plugin_symtab))) return NULL; if ( (shl_findsym(&tt_handle, "util_table",TYPE_UNDEFINED,&plugin_utiltab))) return NULL; (*plugin_symtab)=&symbol_table; (*plugin_utiltab)=&i_UTIL_table; */ if ( (shl_findsym(&tt_handle, I_INSTALL_TABLES ,TYPE_UNDEFINED, &f ))) return NULL; mm_log( (1,"Calling install_tables\n") ); f(&symbol_table,&i_UTIL_table); mm_log( (1,"Call ok.\n") ); if ( (shl_findsym(&tt_handle, I_FUNCTION_LIST ,TYPE_UNDEFINED,(func_ptr*)&function_list))) return NULL; if ( (dso_handle=(DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) /* checked 17jul05 tonyc */ return NULL; dso_handle->handle=tt_handle; /* needed to close again */ dso_handle->function_list=function_list; if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */ free(dso_handle); return NULL; } strcpy(dso_handle->filename,file); mm_log((1,"DSO_open <- (0x%X)\n",dso_handle)); return (void*)dso_handle; }
int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary) { shl_t myHandle; *pvLHandle = 0; myHandle = shl_load(pcLibrary, BIND_IMMEDIATE | BIND_VERBOSE | BIND_NOSTART, 0L); if (myHandle == 0) { Log3(PCSC_LOG_ERROR, "%s: %s", pcLibrary, strerror(errno)); return SCARD_F_UNKNOWN_ERROR; } *pvLHandle = (void *) myHandle; return SCARD_S_SUCCESS; }
// Open DLL and return dllhandle to it void* fxdllOpen(const FXchar *dllname){ if(dllname){ #ifndef WIN32 #ifdef HAVE_SHL_LOAD // HP-UX return shl_load(dllname,BIND_IMMEDIATE|BIND_NONFATAL|DYNAMIC_PATH,0L); #else #ifdef DL_LAZY // OpenBSD return dlopen(dllname,DL_LAZY); #else // POSIX return dlopen(dllname,RTLD_NOW|RTLD_GLOBAL); #endif #endif #else // WIN32 // Order of loading with LoadLibrary (or LoadLibraryEx with no // LOAD_WITH_ALTERED_SEARCH_PATH flag): // // 1. Directory from which the application was loaded. // 2. Current directory. // 3. System directory, as determined by GetSystemDirectory(). // 4. 16-bit system directory. // 5. Windows directory, as determined by GetWindowsDirectory(). // 6. Directories in the $PATH. // // With flag LOAD_WITH_ALTERED_SEARCH_PATH: // // 1. Directory specified by the filename path. // 2. Current directory. // 3. System directory. // 4. 16-bit system directory. // 5. Windows directory. // 6. Directories in the $PATH. // // We switched to the latter so sub-modules needed by a DLL are // plucked from the same place as dllname (thanks to Rafael de // Pelegrini Soares" <*****@*****.**>). //return LoadLibrary(dllname); return LoadLibraryExA(dllname,NULL,LOAD_WITH_ALTERED_SEARCH_PATH); #endif } return NULL; }
static int dl_load(DSO *dso) { shl_t ptr = NULL; /* * We don't do any fancy retries or anything, just take the method's (or * DSO's if it has the callback set) best translation of the * platform-independent filename and try once with that. */ char *filename = DSO_convert_filename(dso, NULL); if (filename == NULL) { DSOerr(DSO_F_DL_LOAD, DSO_R_NO_FILENAME); goto err; } ptr = shl_load(filename, BIND_IMMEDIATE | (dso->flags & DSO_FLAG_NO_NAME_TRANSLATION ? 0 : DYNAMIC_PATH), 0L); if (ptr == NULL) { char errbuf[160]; DSOerr(DSO_F_DL_LOAD, DSO_R_LOAD_FAILED); if (openssl_strerror_r(errno, errbuf, sizeof(errbuf))) ERR_add_error_data(4, "filename(", filename, "): ", errbuf); goto err; } if (!sk_push(dso->meth_data, (char *)ptr)) { DSOerr(DSO_F_DL_LOAD, DSO_R_STACK_ERROR); goto err; } /* * Success, stick the converted filename we've loaded under into the DSO * (it also serves as the indicator that we are currently loaded). */ dso->loaded_filename = filename; return (1); err: /* Cleanup! */ OPENSSL_free(filename); if (ptr != NULL) shl_unload(ptr); return (0); }