module.c (7f70c6ca) | module.c (e372d74d) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 8 unchanged lines hidden (view full) --- 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 8 unchanged lines hidden (view full) --- 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 |
25#include "system.h" 26 | |
27#include <osl/module.h> 28#include <osl/diagnose.h> 29#include <osl/file.h> 30#include <osl/thread.h> 31 32#include <stdlib.h> 33#include <dlfcn.h> 34 | 25#include <osl/module.h> 26#include <osl/diagnose.h> 27#include <osl/file.h> 28#include <osl/thread.h> 29 30#include <stdlib.h> 31#include <dlfcn.h> 32 |
33#include "system.h" 34 35/* implemented in file.cxx */ |
|
35int UnicodeToText(char *, size_t, const sal_Unicode *, sal_Int32); 36 | 36int UnicodeToText(char *, size_t, const sal_Unicode *, sal_Int32); 37 |
37// static data for holding SAL dll module and full path 38static HMODULE hModSal; 39static char szSalDir[ _MAX_PATH]; 40static char szSalDrive[ _MAX_PATH]; 41 | |
42/*****************************************************************************/ 43/* osl_loadModule */ 44/*****************************************************************************/ 45 | 38/*****************************************************************************/ 39/* osl_loadModule */ 40/*****************************************************************************/ 41 |
46ULONG APIENTRY _DosLoadModule (PSZ pszObject, ULONG uObjectLen, PCSZ pszModule, 47 PHMODULE phmod) 48{ 49 APIRET rc; 50 rc = DosLoadModule( pszObject, uObjectLen, pszModule, phmod); 51 // YD 22/05/06 issue again if first call fails (why?) 52 if (rc == ERROR_INVALID_PARAMETER) 53 rc = DosLoadModule( pszObject, uObjectLen, pszModule, phmod); 54 return rc; 55} 56 57oslModule SAL_CALL osl_loadAsciiModule( const sal_Char* pModuleName, sal_Int32 nRtldMode ) 58{ 59 rtl_uString* pUniName = NULL; 60 rtl_uString_newFromAscii( &pUniName, pModuleName ); 61 oslModule aModule = osl_loadModule( pUniName, nRtldMode ); 62 rtl_uString_release( pUniName ); 63 return aModule; 64} 65 | |
66oslModule SAL_CALL osl_loadModule(rtl_uString *ustrModuleName, sal_Int32 nRtldMode) 67{ | 42oslModule SAL_CALL osl_loadModule(rtl_uString *ustrModuleName, sal_Int32 nRtldMode) 43{ |
68 HMODULE hModule; 69 BYTE szErrorMessage[256]; 70 APIRET rc; | |
71 oslModule pModule=0; 72 rtl_uString* ustrTmp = NULL; 73 74 OSL_ENSURE(ustrModuleName,"osl_loadModule : string is not valid"); 75 76 /* ensure ustrTmp hold valid string */ | 44 oslModule pModule=0; 45 rtl_uString* ustrTmp = NULL; 46 47 OSL_ENSURE(ustrModuleName,"osl_loadModule : string is not valid"); 48 49 /* ensure ustrTmp hold valid string */ |
77 if( osl_File_E_None != osl_getSystemPathFromFileURL( ustrModuleName, &ustrTmp ) ) 78 rtl_uString_assign( &ustrTmp, ustrModuleName ); | 50 if (osl_File_E_None != osl_getSystemPathFromFileURL(ustrModuleName, &ustrTmp)) 51 rtl_uString_assign(&ustrTmp, ustrModuleName); |
79 | 52 |
80 if( ustrTmp ) | 53 if (ustrTmp) |
81 { 82 char buffer[PATH_MAX]; 83 | 54 { 55 char buffer[PATH_MAX]; 56 |
84 if( UnicodeToText( buffer, PATH_MAX, ustrTmp->buffer, ustrTmp->length ) ) 85 { 86 char drive[_MAX_DRIVE], dir[_MAX_DIR]; 87 char fname[_MAX_FNAME], ext[_MAX_EXT]; 88 char* dot; 89 // 21/02/2006 YD dll names must be 8.3: since .uno.dll files 90 // have hardcoded names, I'm truncating names here and also in 91 // the build system 92 _splitpath (buffer, drive, dir, fname, ext); 93 if (strlen(fname)>8) 94 fname[8] = 0; // truncate to 8.3 95 dot = strchr( fname, '.'); 96 if (dot) 97 *dot = '\0'; // truncate on dot 98 // if drive is not specified, remove starting \ from dir name 99 // so dll is loaded from LIBPATH 100 if (drive[0] == 0 && dir[0] == '\\' && dir[1] == '\\') { 101 while( dir[0] == '\\') 102 strcpy( dir, dir+1); 103 } 104 _makepath( buffer, drive, dir, fname, ext); | 57 if (UnicodeToText(buffer, PATH_MAX, ustrTmp->buffer, ustrTmp->length)) 58 pModule = osl_loadAsciiModule(buffer, nRtldMode); 59 rtl_uString_release(ustrTmp); 60 } |
105 | 61 |
106#if OSL_DEBUG_LEVEL>10 107 debug_printf("osl_loadModule module %s", buffer); | 62 return pModule; 63} 64 65/*****************************************************************************/ 66/* osl_loadAsciiModule */ 67/*****************************************************************************/ 68 69oslModule SAL_CALL osl_loadAsciiModule(const sal_Char *pszModuleName, sal_Int32 nRtldMode) 70{ 71 char drive[_MAX_DRIVE], dir[_MAX_DIR]; 72 char fname[_MAX_FNAME], ext[_MAX_EXT]; 73 char buffer[PATH_MAX]; 74 char* dot; 75 void* hModule; 76 oslModule pModule = NULL; 77 78 if (!pszModuleName) 79 return NULL; 80 81 // 21/02/2006 YD dll names must be 8.3: since .uno.dll files 82 // have hardcoded names, I'm truncating names here and also in 83 // the build system 84 _splitpath (pszModuleName, drive, dir, fname, ext); 85 if (strlen(fname)>8) 86 fname[8] = 0; // truncate to 8.3 87 dot = strchr( fname, '.'); 88 if (dot) 89 *dot = '\0'; // truncate on dot 90 91 // if drive is not specified, remove starting \ from dir name 92 // so dll is loaded from LIBPATH 93 if (drive[0] == 0 && dir[0] == '\\' && dir[1] == '\\') { 94 while( dir[0] == '\\') 95 strcpy( dir, dir+1); 96 } 97 _makepath( buffer, drive, dir, fname, ext); 98 99#if OSL_DEBUG_LEVEL>1 100 debug_printf("osl_loadModule module %s", buffer); |
108#endif | 101#endif |
109 hModule = dlopen( buffer, RTLD_LOCAL); 110 if (hModule != NULL ) 111 pModule = (oslModule)hModule; 112 else 113 { 114 sal_Char szError[ PATH_MAX*2 ]; 115 sprintf( szError, "Module: %s; errno: %d;\n" 116 "Please contact technical support and report above informations.\n\n", 117 buffer, errno ); | 102 103 hModule = dlopen( buffer, RTLD_LOCAL); 104 if (hModule != NULL) 105 pModule = (oslModule)hModule; 106 else 107 { 108 sal_Char szError[ PATH_MAX*2 ]; 109 sprintf( szError, "Module: %s;\n error: %s;\n\n" 110 "Please contact technical support and report above informations.\n\n", 111 buffer, dlerror() ); |
118#if OSL_DEBUG_LEVEL>0 | 112#if OSL_DEBUG_LEVEL>0 |
119 fprintf( stderr, szError); | 113 debug_printf("osl_loadModule error %s", szError); |
120#endif | 114#endif |
121 debug_printf("osl_loadModule error %s", szError); 122 | 115 |
123#if (OSL_DEBUG_LEVEL==0) || !defined(OSL_DEBUG_LEVEL) | 116#if (OSL_DEBUG_LEVEL==0) || !defined(OSL_DEBUG_LEVEL) |
124 WinMessageBox(HWND_DESKTOP,HWND_DESKTOP, 125 szError, "Critical error: DosLoadModule failed", 126 0, MB_ERROR | MB_OK | MB_MOVEABLE); | 117 WinMessageBox(HWND_DESKTOP,HWND_DESKTOP, 118 szError, "Critical error: DosLoadModule failed", 119 0, MB_ERROR | MB_OK | MB_MOVEABLE); |
127#endif | 120#endif |
128 } 129 } 130 } | 121 } |
131 | 122 |
132 rtl_uString_release( ustrTmp ); 133 134 return pModule; | 123 return pModule; |
135} 136 137/*****************************************************************************/ 138/* osl_getModuleHandle */ 139/*****************************************************************************/ 140 141sal_Bool SAL_CALL 142osl_getModuleHandle(rtl_uString *pModuleName, oslModule *pResult) 143{ 144 HMODULE hmod; 145 APIRET rc; | 124} 125 126/*****************************************************************************/ 127/* osl_getModuleHandle */ 128/*****************************************************************************/ 129 130sal_Bool SAL_CALL 131osl_getModuleHandle(rtl_uString *pModuleName, oslModule *pResult) 132{ 133 HMODULE hmod; 134 APIRET rc; |
146 rc = DosQueryModuleHandle(pModuleName->buffer, &hmod); 147 if( rc == NO_ERROR) | 135 136 OSL_ENSURE(pModuleName,"osl_loadModule : string is not valid"); 137 138 if (pModuleName) |
148 { | 139 { |
149 *pResult = (oslModule) hmod; 150 return sal_True; | 140 char buffer[PATH_MAX]; 141 142 if (UnicodeToText(buffer, PATH_MAX, pModuleName->buffer, 143 pModuleName->length)) 144 { 145 rc = DosQueryModuleHandle(buffer, &hmod); 146 if( rc == NO_ERROR) 147 { 148 *pResult = (oslModule) hmod; 149 return sal_True; 150 } 151 } |
151 } | 152 } |
152 | 153 |
153 return sal_False; 154} 155 156/*****************************************************************************/ 157/* osl_unloadModule */ 158/*****************************************************************************/ | 154 return sal_False; 155} 156 157/*****************************************************************************/ 158/* osl_unloadModule */ 159/*****************************************************************************/ |
159void SAL_CALL osl_unloadModule(oslModule Module) | 160void SAL_CALL osl_unloadModule(oslModule hModule) |
160{ | 161{ |
161#if OSL_DEBUG_LEVEL>0 162 if (!Module) 163 fprintf( stderr, "osl_unloadModule NULL HANDLE.\n"); 164#endif 165 166 DosFreeModule((HMODULE)Module); | 162 if (hModule) 163 { 164 int nRet = dlclose(hModule); 165#if OSL_DEBUG_LEVEL > 1 166 if (nRet != 0) 167 { 168 debug_printf( "osl_unloadModule failed with %s\n", dlerror()); 169 } 170#else 171 (void) nRet; 172#endif /* if OSL_DEBUG_LEVEL */ 173 } |
167} 168 169/*****************************************************************************/ 170/* osl_getSymbol */ 171/*****************************************************************************/ 172void* SAL_CALL 173osl_getSymbol(oslModule Module, rtl_uString* pSymbolName) 174{ --- 112 unchanged lines hidden --- | 174} 175 176/*****************************************************************************/ 177/* osl_getSymbol */ 178/*****************************************************************************/ 179void* SAL_CALL 180osl_getSymbol(oslModule Module, rtl_uString* pSymbolName) 181{ --- 112 unchanged lines hidden --- |