diff options
author | mfe <mfe@openoffice.org> | 2001-02-28 12:03:22 +0000 |
---|---|---|
committer | mfe <mfe@openoffice.org> | 2001-02-28 12:03:22 +0000 |
commit | 5129c7f504c9ac267bb0b691997a601052e9ffe5 (patch) | |
tree | 35961560769010cb6203f316dfd953494d85fd07 /sal/osl/unx | |
parent | e3b668165de29c7733b84182cc8865fb4274a713 (diff) |
- Solaris 2.5.1 hack removed
- NOT_IMPL section removed
Diffstat (limited to 'sal/osl/unx')
-rw-r--r-- | sal/osl/unx/module.c | 571 |
1 files changed, 31 insertions, 540 deletions
diff --git a/sal/osl/unx/module.c b/sal/osl/unx/module.c index dd0d9967ea70..d998c077f57e 100644 --- a/sal/osl/unx/module.c +++ b/sal/osl/unx/module.c @@ -2,9 +2,9 @@ * * $RCSfile: module.c,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: mfe $ $Date: 2001-02-20 10:35:38 $ + * last change: $Author: mfe $ $Date: 2001-02-28 13:03:22 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -72,8 +72,15 @@ #include <osl/module.h> #endif +#ifndef _OSL_THREAD_H_ +#include <osl/thread.h> +#endif + #include "system.h" + +#if defined(DEBUG) #include <stdio.h> +#endif #ifdef MACOSX #ifndef _OSL_PROCESS_H_ @@ -87,92 +94,10 @@ extern int _dlclose(void *handle); oslModule SAL_CALL osl_psz_loadModule(const sal_Char *pszModuleName, sal_Int32 nRtldMode); void* SAL_CALL osl_psz_getSymbol(oslModule hModule, const sal_Char* pszSymbolName); -#if defined(SOLARIS) - -#include <sys/utsname.h> - -/* osl_getSolarisRelease - * make a single integer from solaris release string */ - -sal_Int32 SAL_CALL osl_getSolarisRelease() -{ - struct utsname aRelease; - static int nRelease = 0; - - if ( nRelease != 0 ) - { - /* computed once, returned many */ - return nRelease; - } - else - if ( uname( &aRelease ) > -1 ) - { - int nTokens; - int nMajor, nMinor, nMMinor; - - /* release will be something like 5.5.1 or 5.6 */ - nTokens = sscanf(aRelease.release, "%i.%i.%i\n", - &nMajor, &nMinor, &nMMinor ); - - switch ( nTokens ) - { - case 0: nMajor = 0; - /* fall thru */ - case 1: nMinor = 0; - /* fall thru */ - case 2: nMMinor = 0; - break; - case 3: - default: - /* 3 tokens cannot match more than 3 times */ - break; - } - - /* will be something like 551 or 560, dont expect a minor release - * number larger than 9 */ - nRelease = nMajor * 100 + nMinor * 10 + nMMinor; - - /* okay, the paranoic case */ - if ( nRelease == 0 ) - nRelease = -1; - } - else - { - /* never saw uname fail, but just in case - * (must be very old solaris) */ - nRelease = -1; - } - - return nRelease; -} - -#endif /*****************************************************************************/ /* osl_loadModule */ /*****************************************************************************/ -#if defined(SOLARIS) -/* - * mfe: #65566# and #68661# - * Under 5.5.1 we can't use dlclose due to relocation error with libsk - * The First fix was to dlopen all libs with RTLD_GLOBAL but we did - * encounter problems with Java then (zip symbols) - * The error occurs when an implicit dlclose was called - * We catch dlclose here and leave all libs opened via dlopen unclosed - */ - -int dlclose(void *handle) -{ - int nRet; - sal_Int32 release; - release = osl_getSolarisRelease(); - if ( release >= 560 ) - { - nRet=_dlclose(handle); - } - return nRet; -} -#endif oslModule SAL_CALL osl_loadModule(rtl_uString *ustrModuleName, sal_Int32 nRtldMode) { @@ -192,7 +117,7 @@ oslModule SAL_CALL osl_loadModule(rtl_uString *ustrModuleName, sal_Int32 nRtldMo pszModuleName=rtl_string_getStr(strModuleName); #if defined(DEBUG) - fprintf(stderr,"lib to load : [%s]\n",pszModuleName); + fprintf(stderr,"osl_loadModule : lib to load : [%s]\n",pszModuleName); #endif if ( strncmp(pszModuleName,"//./",4) == 0 ) @@ -358,6 +283,7 @@ void SAL_CALL osl_unloadModule(oslModule hModule) if (hModule) { #ifndef NO_DL_FUNCTIONS +/* mfe : isn't needed anymore, is it? */ #ifndef GCC /* gcc (2.9.1 (egcs), 295) registers atexit handlers for * static destructors which obviously cannot @@ -365,10 +291,18 @@ void SAL_CALL osl_unloadModule(oslModule hModule) * is not to dlclose libraries. Since most of them are closed at shutdown * this does not make that much a difference */ - dlclose(hModule); + int nRet = 0; -#endif -#endif + nRet = dlclose(hModule); +#if defined(DEBUG) + if ( nRet != 0 ) + { + fprintf( stderr, "osl_getsymbol: cannot close lib for reason: %s\n", dlerror() ); + } +#endif /* if DEBUG */ + +#endif /* ifndef GCC */ +#endif /* ifndef NO_DL_FUNCTIONS */ } #endif /* MACOSX */ @@ -467,464 +401,21 @@ void* SAL_CALL osl_psz_getSymbol(oslModule hModule, const sal_Char* pszSymbolNam if (hModule && pszSymbolName) { #ifndef NO_DL_FUNCTIONS - return dlsym(hModule, pszSymbolName); -#endif - } - return NULL; - -#endif /* MACOSX */ -} - -/*****************************************************************************/ -/* NYI */ -/*****************************************************************************/ -#ifdef NOT_IMPL - - -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <stdlib.h> -#ifdef AIX -#include <errno.h> -#include <sys/types.h> -#include <sys/ldr.h> -#include <a.out.h> -#include <ldfcn.h> -#define _H_FCNTL -#define LIBPATH "LIBPATH" -#elif defined HPUX -#include <dl.h> -#include <errno.h> -#define LIBPATH "SHLIB_PATH" -#elif defined S390 -#include <errno.h> -#include <dll.h> -#define LIBPATH "LIPPATH" -#else -#include <dlfcn.h> -#define LIBPATH "LD_LIBRARY_PATH" -#endif + void* pSym = 0; -#ifdef AIX -struct SymbolEntry -{ - String aSymbolName; - void *aSymbolAdress; -}; -DECLARE_LIST(SymbolTable, SymbolEntry*); -#endif - -struct LibraryPrivateData -{ - String aLibname; - ULONG nRefCount; - -#ifdef HPUX - shl_t aHandle; -#elif S390 - dllhandle *aHandle; -#else - void *aHandle; -#endif + pSym = dlsym(hModule, pszSymbolName); -#ifdef AIX - SymbolTable aSymbolTable; +#ifdef DEBUG + if( ! pSym ) + fprintf( stderr, "osl_getsymbol: cannot get Symbol %s for reason: %s\n", + pszSymbolName, dlerror() ); #endif -#if defined AIX || defined HPUX - void (*init)(void); - void (*exit)(void); -#endif + return pSym; - LibraryPrivateData( const String & aName ) - : aLibname (aName), nRefCount (1), aHandle (NULL) -#if defined AIX || defined HPUX - , init (NULL), exit (NULL) #endif - {} -}; - -static String aError; - -DECLARE_LIST(LibraryList, LibraryPrivateData*); -static LibraryList aLibraryList; - -#if defined AIX || defined HPUX -inline void SetError (const sal_Char* const pError, BOOL bErrno = FALSE) -{ - aError = pError; - if (bErrno) - { - aError += ' '; - aError += strerror(errno); - } - aError += '\n'; -#ifdef DBG_UTIL - DBG_ASSERTWARNING (TRUE, aError.GetStr()); -#endif -} -#endif - -inline String FindLibrary( const String &rPathname ) -{ - if (rPathname.Search('/') != STRING_NOTFOUND) - return access(rPathname.GetStr(), F_OK | R_OK | X_OK) - ? String() : (String)rPathname; - String aLibpath (getenv (LIBPATH)); - String aPathName; - USHORT nToken = aLibpath.GetTokenCount (':'); - for (USHORT i = 0; i < nToken; i++) - { - aPathName = aLibpath.GetToken (i, ':'); - aPathName += '/'; - aPathName += rPathname; - if (! access(aPathName.GetStr(), F_OK | R_OK | X_OK)) - return aPathName; - } - return String(); -} - -#ifdef HPUX - -inline void *FindFunction(LibraryPrivateData *pPriv, const String & rSymbol) -{ - void *pReturn; - if (shl_findsym( &pPriv->aHandle, rFuncName.GetStr(), - TYPE_PROCEDURE, &pReturn) == -1) - { - SetError("FindFunction", TRUE); - pReturn = NULL; - } - return pReturn; -} - -inline BOOL Load(LibraryPrivateData *pPriv, const String & rPathname) -{ - pPriv->aHandle = shl_load(rPathname.GetStr(), - (BIND_DEFERRED | BIND_NONFATAL | DYNAMIC_PATH), 0L); - BOOL ret = (pPriv->aHandle != NULL); - if (ret) - { - String aSymbol("_GLOBAL__FI_"); - String aSymbol += pPriv->aLibName; - aSymbol.SearchAndReplace('.', '_'); - pPriv->init = FindFunction(pPriv, Symbol); - aSymbol.SearchAndReplace('I', 'D'); - pPriv->exit = FindFunction(pPriv, Symbol); - if (pPriv->init) - (pPriv->init)(); } - else - SetError("Load:", TRUE); - return (ret); -} - -inline BOOL Unload (LibraryPrivateData *pPriv) { - BOOL ret = TRUE; - if (pPriv) - { - if (pPriv->exit) - (pPriv->exit)(); - ret = (shl_unload (pPriv->aHandle) != -1); - if (! ret) - SetError("Unload:", TRUE); - } - return (ret); -} - -#elif defined AIX - -inline struct ld_info *GetInfo (void) -{ - for (ULONG size = 4096; TRUE; size += 4096) - { - sal_Char *pBuffer = new sal_Char [size]; - if (! pBuffer) { - SetError("GetInfo: out of memory"); - return NULL; - } - if (loadquery (L_GETINFO, pBuffer, size) != -1) - return ((struct ld_info *) pBuffer); - delete[] pBuffer; - if (errno != ENOMEM) - return NULL; - } -} - -class MainEntry -{ - void *pPoint; - MainEntry () - { - struct ld_info *pLdInfo = GetInfo (); - if (pLdInfo) - { - pPoint = pLdInfo->ldinfo_dataorg; - delete[] pLdInfo; - } - else - { - pPoint = NULL; - SetError("MainEntryPoint: cannot find"); - } - } -} - -static MainEntry aMainEntryPoint; - -inline void *FindFunction(LibraryPrivateData *pPriv, const String & rSymbol) -{ - SymbolEntry *pSymbolEntry; - for (pSymbolEntry = pPriv->aSymbolTable.First(); - pSymbolEntry && (pSymbolEntry->aSymbolName != rFuncName); - pSymbolEntry = pPriv->aSymbolTable.Next()) - ; - void *ret = pSymbolEntry ? pSymbolEntry->aSymbolAdress : NULL; - if (ret) - { - String aTmp("FindFunction: symbol "); - aTmp += rFuncName; - aTmp += " not found"; - SetError(aTmp.GetStr()); - } - return ret; -} - -inline BOOL Load(LibraryPrivateData *pPriv, const String & rPathname) -{ - String aPathName = FindLibrary (rPathname); - if (!aPathName) - { - String aTmp = "Load: "; - aTmp += rPathname; - aTmp += " not found"; - SetError (aTmp.GetStr()); - return FALSE; - } - - pPriv->aHandle = load ((sal_Char*)aPathName.GetStr(), L_NOAUTODEFER, NULL); - if (! pPriv->aHandle) - { - String aTmp = "LOad: load:"; - aTmp += rPathname; - aTmp += ':'; - SetError (aTmp.GetStr(), TRUE); - return FALSE; - } - - if (loadbind(NULL, aMainEntryPoint.aPoint , pPriv->aHandle) == -1) - { - unload (pPriv->aHandle); - SetError("Load: loadbind:", TRUE); - return FALSE; - } - - LDFILE *pLdFile = ldopen ((sal_Char*) aPathName.GetStr(), NULL); - if (! pLdFile) - { - struct ld_info *pLdInfo; - if (!(pLdInfo = GetInfo())); - { - SetError("Load: cannot find symbol table"); - return FALSE; - } - while (pLdInfo && (! pLdFile)) - { - if (pLdInfo->ldinfo_dataorg == pPriv->aHandle) - pLdFile = ldopen (pLdInfo->ldinfo_filename,pLdFile); - else - pLdInfo = pLdInfo->ldinfo_next ? - (struct ld_info *)((sal_Char *) pLdInfo) + - pLdInfo->ldinfo_next : - NULL; - } - delete[] pLdInfo; - if (! pLdFile) - { - SetError("Library::Library:"); - return FALSE; - } - } - if (TYPE(pLdFile) != U802TOCMAGIC) - { - while (ldclose (pLdFile) == FAILURE) - ; - SetError("Library::Library: bad magic"); - return FALSE; - } - - SCNHDR aSectionHeader; - if (ldnshread (pLdFile, _LOADER, &aSectionHeader) != SUCCESS) - { - while (ldclose (pLdFile) == FAILURE) - ; - SetError("Library::Library: cannot read loader section header"); - return FALSE; - } - if (FSEEK(pLdFile, aSectionHeader.s_scnptr, BEGINNING) != OKFSEEK) { - while (ldclose (pLdFile) == FAILURE) - ; - SetError("Load: cannot seek to loader section"); - return FALSE; - } - sal_Char *pBuffer = new sal_Char [aSectionHeader.s_size]; - if (FREAD(pBuffer, aSectionHeader.s_size, 1, pLdFile) != 1) - { - while (ldclose (pLdFile) == FAILURE) - ; - SetError("Load: cannot read loader section"); - return FALSE; - } - int i = ((LDHDR *)pBuffer)->l_nsyms; - for (LDSYM *pSymbol = (LDSYM*) (pBuffer + LDHDRSZ); i--; pSymbol++) - { - if (LDR_EXPORT (*pSymbol)) - { - SymbolEntry *pSymbolEntry = new SymbolEntry; - pSymbolEntry->aSymbolName = pSymbol->l_zeroes ? - pSymbol->l_name : - pSymbol->l_offset + ((LDHDR *)pBuffer)->l_stoff + pBuffer; - pSymbolEntry->aSymbolAdress = (void *)((sal_uInt32) - pPriv->aHandle + pSymbol->l_value); - pPriv->aSymbolTable.Insert(pSymbolEntry); - } - } - delete[] pBuffer; - while(ldclose(pLdFile) == FAILURE) - ; - - struct dl_info { void (*init)(void); void (*exit)(void); } - *pInfo = (struct dl_info *) FindFunction ("dl_info"); - if (pInfo) - { - pPriv->exit = pInfo->exit; - pPriv->init = pInfo->init; - if (pPriv->init) - pPriv->init(); - } - return TRUE; -} - -inline BOOL Unload (LibraryPrivateData *pPriv) -{ - if (pPriv->exit) - pPriv->exit(); - if (unload (pPriv->aHandle) == -1) - SetError("Unload", TRUE); - for (SymbolEntry *pSymbolEntry = pPriv->aSymbolTable.First(); - pSymbolEntry; pSymbolEntry = pPriv->aSymbolTable.Next()) - delete pSymbolEntry; -} - -#elif S390 - -inline void *FindFunction(LibraryPrivateData *pPriv, const String & rFuncname) -{ - void *pReturn = (void *)(dllqueryfn(pPriv->aHandle, (sal_Char*) rFuncname.GetStr())); - if (pReturn == NULL) - aError = strerror(errno); - return pReturn; -} - -inline BOOL Load(LibraryPrivateData *pPriv, const String & rPathname) -{ - pPriv->aHandle = dllload((sal_Char *) rPathname.GetStr()); - if (pPriv->aHandle == NULL) - aError = strerror(errno); - return (pPriv->aHandle != NULL); -} - -inline BOOL Unload (LibraryPrivateData *pPriv) -{ - BOOL bRet = (dllfree(pPriv->aHandle) == 0); - if (!bRet) - aError = strerror(errno); - return bRet; -} - -#else - -inline void *FindFunction(LibraryPrivateData *pPriv, const String & rFuncname) -{ - void *pReturn = dlsym(pPriv->aHandle, rFuncname.GetStr()); - aError = dlerror(); - return pReturn; -} - -inline BOOL Load(LibraryPrivateData *pPriv, const String & rPathname) -{ - pPriv->aHandle = dlopen((sal_Char *) rPathname.GetStr(), RTLD_LAZY); - aError = dlerror(); - return (pPriv->aHandle != NULL); -} - -inline BOOL Unload (LibraryPrivateData *pPriv) -{ -#ifndef LINUX - BOOL ret = (dlclose(pPriv->aHandle) != 0); - aError = dlerror(); - return ret; -#else - /* gcc 2.9.1 (egcs) registers atexit handlers which obviously cannot - * be called after dlclose. A compiler "feature". The workaround for now - * is not to dlclose libraries. Since most of them are closed at shutdown - * this does not make that much a difference - */ - return TRUE; -#endif -} - -#endif - -BOOL Library::ModulFound( const String &rPathname ) -{ - return FindLibrary (rPathname).Len(); -} - -Library::Library(const String & rPathname) -{ - sal_Char *pLibname = strrchr (rPathname.GetStr(), '/'); - String aLibname(pLibname ? String(pLibname) : (String)rPathname); - - for (pPriv = aLibraryList.First(); - pPriv && (pPriv->aLibname != aLibname); - pPriv = aLibraryList.Next()) - ; - if (pPriv) - { - pPriv->nRefCount++; - return; - } - pPriv = new LibraryPrivateData (aLibname); - if (Load(pPriv, rPathname)) - aLibraryList.Insert(pPriv); - else - { - delete pPriv; - pPriv = NULL; - } -} - -Library::~Library() -{ - if (pPriv && --pPriv->nRefCount) - { - Unload (pPriv); - delete pPriv; - pPriv = NULL; - aLibraryList.Remove(pPriv); - } -} - -void* Library::GetFunction(const String & rFuncName) const -{ - return pPriv ? FindFunction(pPriv, rFuncName) : NULL; -} + return NULL; -BOOL Library::ModulFound () const { - return ((pPriv != NULL) && (pPriv->aHandle != NULL)); +#endif /* MACOSX */ } - -#endif - |