Changeset 101944 in vbox
- Timestamp:
- Nov 7, 2023 2:37:39 PM (13 months ago)
- Location:
- trunk/src/libs/xpcom18a4/xpcom
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/xpcom/build/nsXPComInit.cpp
r101920 r101944 39 39 #include "nsXPCOMPrivate.h" 40 40 #include "nscore.h" 41 #include "prlink.h"42 41 #include "nsCOMPtr.h" 43 42 #include "nsObserverList.h" -
trunk/src/libs/xpcom18a4/xpcom/components/xcDll.cpp
r101942 r101944 71 71 nsDll::nsDll(nsIFile *dllSpec, nsNativeComponentLoader *loader) 72 72 : m_dllSpec(do_QueryInterface(dllSpec)), 73 m_ instance(NULL),73 m_hMod(NIL_RTLDRMOD), 74 74 m_moduleObject(NULL), 75 75 m_loader(loader), … … 81 81 nsDll::~nsDll(void) 82 82 { 83 /** @todo r=aeichner Does this need fixing at all? */ 83 84 //#if DEBUG_dougt 84 85 // The dll gets deleted when the dllStore is destroyed. This happens on … … 120 121 PRBool nsDll::Load(void) 121 122 { 122 if (m_instance != NULL) 123 { 124 // Already loaded 125 return (PR_TRUE); 126 } 123 /* Already loaded? Nothing to do. */ 124 if (m_hMod != NIL_RTLDRMOD) 125 return PR_TRUE; 127 126 128 127 if (m_dllSpec) … … 132 131 #endif 133 132 134 // Load any library dependencies 135 // The Component Loader Manager may hold onto some extra data 136 // set by either the native component loader or the native 137 // component. We assume that this data is a space delimited 138 // listing of dependent libraries which are required to be 139 // loaded prior to us loading the given component. Once, the 140 // component is loaded into memory, we can release our hold 141 // on the dependent libraries with the assumption that the 142 // component library holds a reference via the OS so loader. 143 nsCOMPtr<nsIComponentLoaderManager> manager = do_QueryInterface(m_loader->mCompMgr); 144 if (!manager) 145 return PR_TRUE; 146 147 nsXPIDLCString extraData; 148 manager->GetOptionalData(m_dllSpec, nsnull, getter_Copies(extraData)); 149 150 nsVoidArray dependentLibArray; 151 152 // if there was any extra data, treat it as a listing of dependent libs 153 if (extraData != nsnull) 154 { 155 // all dependent libraries are suppose to be in the "gre" directory. 156 // note that the gre directory is the same as the "bin" directory, 157 // when there isn't a real "gre" found. 158 159 nsXPIDLCString path; 160 nsCOMPtr<nsIFile> file; 161 NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(file)); 162 163 if (!file) 164 return NS_ERROR_FAILURE; 165 166 // we are talking about a file in the GRE dir. Lets append something 167 // stupid right now, so that later we can just set the leaf name. 168 file->AppendNative(NS_LITERAL_CSTRING("dummy")); 169 170 char *buffer = (char *)nsMemory::Clone(extraData, strlen(extraData) + 1); 171 if (!buffer) 172 return NS_ERROR_OUT_OF_MEMORY; 173 174 char* newStr; 175 char *token = nsCRT::strtok(buffer, " ", &newStr); 176 while (token!=nsnull) 133 // Load any library dependencies 134 // The Component Loader Manager may hold onto some extra data 135 // set by either the native component loader or the native 136 // component. We assume that this data is a space delimited 137 // listing of dependent libraries which are required to be 138 // loaded prior to us loading the given component. Once, the 139 // component is loaded into memory, we can release our hold 140 // on the dependent libraries with the assumption that the 141 // component library holds a reference via the OS so loader. 142 nsCOMPtr<nsIComponentLoaderManager> manager = do_QueryInterface(m_loader->mCompMgr); 143 if (!manager) 144 return PR_TRUE; 145 146 nsXPIDLCString extraData; 147 manager->GetOptionalData(m_dllSpec, nsnull, getter_Copies(extraData)); 148 149 nsVoidArray dependentLibArray; 150 151 // if there was any extra data, treat it as a listing of dependent libs 152 if (extraData != nsnull) 177 153 { 178 nsCStringKey key(token); 179 if (m_loader->mLoadedDependentLibs.Get(&key)) { 154 // all dependent libraries are suppose to be in the "gre" directory. 155 // note that the gre directory is the same as the "bin" directory, 156 // when there isn't a real "gre" found. 157 158 nsXPIDLCString path; 159 nsCOMPtr<nsIFile> file; 160 NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(file)); 161 162 if (!file) 163 return NS_ERROR_FAILURE; 164 165 // we are talking about a file in the GRE dir. Lets append something 166 // stupid right now, so that later we can just set the leaf name. 167 file->AppendNative(NS_LITERAL_CSTRING("dummy")); 168 169 char *buffer = (char *)nsMemory::Clone(extraData, strlen(extraData) + 1); 170 if (!buffer) 171 return NS_ERROR_OUT_OF_MEMORY; 172 173 char* newStr; 174 char *token = nsCRT::strtok(buffer, " ", &newStr); 175 while (token!=nsnull) 176 { 177 nsCStringKey key(token); 178 if (m_loader->mLoadedDependentLibs.Get(&key)) { 179 token = nsCRT::strtok(newStr, " ", &newStr); 180 continue; 181 } 182 183 m_loader->mLoadedDependentLibs.Put(&key, (void*)1); 184 185 nsXPIDLCString libpath; 186 file->SetNativeLeafName(nsDependentCString(token)); 187 file->GetNativePath(path); 188 if (!path) 189 return NS_ERROR_FAILURE; 190 191 // Load this dependent library with the global flag and stash 192 // the result for later so that we can unload it. 193 const char *pszFilename = NULL; 194 195 // if the depend library path starts with a / we are 196 // going to assume that it is a full path and should 197 // be loaded without prepending the gre diretory 198 // location. We could have short circuited the 199 // SetNativeLeafName above, but this is clearer and 200 // the common case is a relative path. 201 if (token[0] == '/') 202 pszFilename = token; 203 else 204 pszFilename = path; 205 206 RTLDRMOD hMod = NIL_RTLDRMOD; 207 RTERRINFOSTATIC ErrInfo; 208 RTErrInfoInitStatic(&ErrInfo); 209 210 int vrc = RTLdrLoadEx(pszFilename, &hMod, RTLDRLOAD_FLAGS_LOCAL, &ErrInfo.Core); 211 // if we couldn't load the dependent library. We did the best we 212 // can. Now just let us fail later if this really was a required 213 // dependency. 214 if (RT_SUCCESS(vrc)) 215 dependentLibArray.AppendElement((void*)hMod); 216 180 217 token = nsCRT::strtok(newStr, " ", &newStr); 181 continue;182 218 } 183 184 m_loader->mLoadedDependentLibs.Put(&key, (void*)1); 185 186 nsXPIDLCString libpath; 187 file->SetNativeLeafName(nsDependentCString(token)); 188 file->GetNativePath(path); 189 if (!path) 190 return NS_ERROR_FAILURE; 191 192 // Load this dependent library with the global flag and stash 193 // the result for later so that we can unload it. 194 PRLibSpec libSpec; 195 libSpec.type = PR_LibSpec_Pathname; 196 197 // if the depend library path starts with a / we are 198 // going to assume that it is a full path and should 199 // be loaded without prepending the gre diretory 200 // location. We could have short circuited the 201 // SetNativeLeafName above, but this is clearer and 202 // the common case is a relative path. 203 204 if (token[0] == '/') 205 libSpec.value.pathname = token; 206 else 207 libSpec.value.pathname = path; 208 209 PRLibrary* lib = PR_LoadLibraryWithFlags(libSpec, PR_LD_LAZY|PR_LD_GLOBAL); 210 // if we couldn't load the dependent library. We did the best we 211 // can. Now just let us fail later if this really was a required 212 // dependency. 213 if (lib) 214 dependentLibArray.AppendElement((void*)lib); 215 216 token = nsCRT::strtok(newStr, " ", &newStr); 219 nsMemory::Free(buffer); 217 220 } 218 nsMemory::Free(buffer); 219 } 220 221 // load the component 222 nsCOMPtr<nsILocalFile> lf(do_QueryInterface(m_dllSpec)); 223 NS_ASSERTION(lf, "nsIFile here must implement a nsILocalFile"); 224 lf->Load(&m_instance); 225 226 // Unload any of library dependencies we loaded earlier. The assumption 227 // here is that the component will have a "internal" reference count to 228 // the dependency library we just loaded. 229 // XXX should we unload later - or even at all? 230 if (extraData != nsnull) 231 { 232 PRInt32 arrayCount = dependentLibArray.Count(); 233 for (PRInt32 index = 0; index < arrayCount; index++) 234 PR_UnloadLibrary((PRLibrary*)dependentLibArray.ElementAt(index)); 235 } 221 222 // load the component 223 nsCOMPtr<nsILocalFile> lf(do_QueryInterface(m_dllSpec)); 224 NS_ASSERTION(lf, "nsIFile here must implement a nsILocalFile"); 225 lf->Load(&m_hMod); 226 227 // Unload any of library dependencies we loaded earlier. The assumption 228 // here is that the component will have a "internal" reference count to 229 // the dependency library we just loaded. 230 // XXX should we unload later - or even at all? 231 if (extraData != nsnull) 232 { 233 PRInt32 arrayCount = dependentLibArray.Count(); 234 for (PRInt32 index = 0; index < arrayCount; index++) 235 RTLdrClose((RTLDRMOD)dependentLibArray.ElementAt(index)); 236 } 236 237 237 238 #ifdef NS_BUILD_REFCNT_LOGGING 238 239 nsTraceRefcntImpl::SetActivityIsLegal(PR_TRUE); 239 if (m_instance) { 240 if (m_hMod != NIL_RTLDRMOD) 241 { 240 242 // Inform refcnt tracer of new library so that calls through the 241 243 // new library can be traced. 242 244 nsXPIDLCString displayPath; 243 245 GetDisplayPath(displayPath); 244 nsTraceRefcntImpl::LoadLibrarySymbols(displayPath.get(), m_ instance);246 nsTraceRefcntImpl::LoadLibrarySymbols(displayPath.get(), m_hMod); 245 247 } 246 248 #endif 247 249 } 248 250 249 return ((m_ instance == NULL) ? PR_FALSE : PR_TRUE);251 return ((m_hMod == NIL_RTLDRMOD) ? PR_FALSE : PR_TRUE); 250 252 } 251 253 252 254 PRBool nsDll::Unload(void) 253 255 { 254 if (m_instance== NULL)255 return (PR_FALSE);256 if (m_hMod == NULL) 257 return PR_FALSE; 256 258 257 259 // Shutdown the dll … … 261 263 nsTraceRefcntImpl::SetActivityIsLegal(PR_FALSE); 262 264 #endif 263 PRStatus ret = PR_UnloadLibrary(m_instance);265 int vrc = RTLdrClose(m_hMod); 264 266 #ifdef NS_BUILD_REFCNT_LOGGING 265 267 nsTraceRefcntImpl::SetActivityIsLegal(PR_TRUE); 266 268 #endif 267 269 268 if (ret == PR_SUCCESS)269 270 m_instance = NULL;271 return (PR_TRUE);272 273 else 274 return (PR_FALSE);270 if (RT_SUCCESS(vrc)) 271 { 272 m_hMod = NIL_RTLDRMOD; 273 return PR_TRUE; 274 } 275 276 return PR_FALSE; 275 277 } 276 278 277 279 void * nsDll::FindSymbol(const char *symbol) 278 280 { 279 if (symbol == NULL) 280 return (NULL); 281 282 // If not already loaded, load it now. 283 if (Load() != PR_TRUE) 284 return (NULL); 285 286 return(PR_FindSymbol(m_instance, symbol)); 281 if (symbol == NULL) 282 return NULL; 283 284 // If not already loaded, load it now. 285 if (Load() != PR_TRUE) 286 return NULL; 287 288 void *pvSym = NULL; 289 int vrc = RTLdrGetSymbol(m_hMod, symbol, &pvSym); 290 RT_NOREF(vrc); 291 292 return pvSym; 287 293 } 288 294 … … 315 321 } 316 322 317 318 323 // If not already loaded, load it now. 324 if (Load() != PR_TRUE) return NS_ERROR_FAILURE; 319 325 320 326 // We need a nsIFile for location -
trunk/src/libs/xpcom18a4/xpcom/components/xcDll.h
r101942 r101944 47 47 #define xcDll_h__ 48 48 49 #include "prio.h"50 #include "prlink.h"51 49 #include "nsISupports.h" 52 50 #include "nsILocalFile.h" 53 51 #include "nsCOMPtr.h" 54 52 #include "nsString.h" 53 54 #include <iprt/errcore.h> 55 #include <iprt/ldr.h> 55 56 56 57 class nsNativeComponentLoader; … … 71 72 { 72 73 private: 73 nsCOMPtr<nsIFile> m_dllSpec; 74 PRLibrary *m_instance;74 nsCOMPtr<nsIFile> m_dllSpec; 75 RTLDRMOD m_hMod; 75 76 nsIModule *m_moduleObject; 76 77 nsNativeComponentLoader *m_loader; … … 80 81 81 82 public: 82 83 nsDll(nsIFile *dllSpec, nsNativeComponentLoader* loader);84 ~nsDll(void);85 83 86 // Dll Loading 87 PRBool Load(void); 88 PRBool Unload(void); 89 PRBool IsLoaded(void) 90 { 91 return ((m_instance != 0) ? PR_TRUE : PR_FALSE); 92 } 84 nsDll(nsIFile *dllSpec, nsNativeComponentLoader* loader); 85 ~nsDll(void); 86 87 // Dll Loading 88 PRBool Load(void); 89 PRBool Unload(void); 90 PRBool IsLoaded(void) { return ((m_hMod != NIL_RTLDRMOD) ? PR_TRUE : PR_FALSE); } 91 93 92 void MarkForUnload(PRBool mark) { m_markForUnload = mark; } 94 93 PRBool IsMarkedForUnload(void) { return m_markForUnload; } … … 98 97 nsresult Shutdown(void); 99 98 100 101 99 void *FindSymbol(const char *symbol); 100 102 101 PRBool HasChanged(void); 103 102 104 103 void GetDisplayPath(nsACString& string); 105 104 106 PRLibrary *GetInstance(void) { return (m_instance); } 105 #if 0 106 PRLibrary *GetInstance(void) { return (m_instance); } 107 #endif 107 108 108 109 // NS_RELEASE() is required to be done on objects returned -
trunk/src/libs/xpcom18a4/xpcom/io/nsILocalFile.idl
r1 r101944 43 43 %{C++ 44 44 #include "prio.h" 45 #include "prlink.h"46 45 #include <stdio.h> 46 47 #include <iprt/ldr.h> 47 48 %} 48 49 49 50 [ptr] native PRFileDescStar(PRFileDesc); 50 [ptr] native PRLibraryStar(PRLibrary);51 [ptr] native RTLDRMOD(RTLDRMODINTERNAL); 51 52 [ptr] native FILE(FILE); 52 53 … … 105 106 [noscript] FILE openANSIFileDesc(in string mode); 106 107 107 [noscript] PRLibraryStarload();108 [noscript] RTLDRMOD load(); 108 109 109 110 readonly attribute PRInt64 diskSpaceAvailable; -
trunk/src/libs/xpcom18a4/xpcom/io/nsLocalFileUnix.cpp
r101803 r101944 58 58 #include <ctype.h> 59 59 #include <locale.h> 60 #ifdef XP_BEOS61 #include <Path.h>62 #include <Entry.h>63 #include <Roster.h>64 #endif65 #if defined(VMS)66 #include <fabdef.h>67 #endif68 60 69 61 #include "nsDirectoryServiceDefs.h" … … 82 74 #include "nsNativeCharsetUtils.h" 83 75 84 // On some platforms file/directory name comparisons need to 85 // be case-blind. 86 #if defined(VMS) 87 #define FILE_STRCMP strcasecmp 88 #define FILE_STRNCMP strncasecmp 89 #else 90 #define FILE_STRCMP strcmp 91 #define FILE_STRNCMP strncmp 92 #endif 76 #include <iprt/errcore.h> 77 78 #define FILE_STRCMP strcmp 79 #define FILE_STRNCMP strncmp 93 80 94 81 #define VALIDATE_STAT_CACHE() \ … … 1532 1519 1533 1520 NS_IMETHODIMP 1534 nsLocalFile::Load( PRLibrary **_retval)1535 { 1536 CHECK_mPath(); 1537 NS_ENSURE_ARG_POINTER( _retval);1538 1539 *_retval = PR_LoadLibrary(mPath.get());1540 1541 if ( !*_retval)1521 nsLocalFile::Load(RTLDRMOD *phMod) 1522 { 1523 CHECK_mPath(); 1524 NS_ENSURE_ARG_POINTER(phMod); 1525 1526 RTLDRMOD hMod = NIL_RTLDRMOD; 1527 int vrc = RTLdrLoad(mPath.get(), &hMod); 1528 if (RT_FAILURE(vrc)) 1542 1529 return NS_ERROR_FAILURE; 1530 1531 *phMod = hMod; 1543 1532 return NS_OK; 1544 1533 } -
trunk/src/libs/xpcom18a4/xpcom/tests/RegFactory.cpp
r1 r101944 38 38 #include <iostream.h> 39 39 #include "plstr.h" 40 #include "prlink.h"41 40 #include "nsIComponentRegistrar.h" 42 41 #include "nsIComponentManager.h"
Note:
See TracChangeset
for help on using the changeset viewer.