1999-08-31 21:40:21 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
1999-02-01 22:40:48 +00:00
|
|
|
/*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-02-01 22:40:48 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-02-01 22:40:48 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-02-01 22:40:48 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-02-01 22:40:48 +00:00
|
|
|
*/
|
|
|
|
|
1999-02-03 15:39:13 +00:00
|
|
|
/* nsDll
|
1999-02-01 22:40:48 +00:00
|
|
|
*
|
|
|
|
* Abstraction of a Dll. Stores modifiedTime and size for easy detection of
|
|
|
|
* change in dll.
|
|
|
|
*
|
|
|
|
* dp Suresh <dp@netscape.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "xcDll.h"
|
1999-08-09 00:19:08 +00:00
|
|
|
#include "nsDebug.h"
|
1999-06-22 14:02:58 +00:00
|
|
|
#include "nsIComponentManager.h"
|
1999-08-09 00:19:08 +00:00
|
|
|
#include "nsIModule.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "nsILocalFile.h"
|
1999-08-13 19:27:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "nsCRT.h"
|
2000-01-28 09:44:05 +00:00
|
|
|
#include "nsString.h"
|
2000-02-21 22:56:55 +00:00
|
|
|
#if defined(VMS) && defined(DEBUG)
|
|
|
|
#include <lib$routines.h>
|
|
|
|
#include <ssdef.h>
|
|
|
|
#endif
|
1999-10-06 01:09:13 +00:00
|
|
|
|
1999-06-22 14:02:58 +00:00
|
|
|
nsDll::nsDll(const char *codeDllName, int type)
|
2000-01-24 21:28:28 +00:00
|
|
|
: m_dllName(NULL),
|
1999-08-11 01:46:43 +00:00
|
|
|
m_instance(NULL), m_status(DLL_OK), m_moduleObject(NULL),
|
1999-09-13 22:34:42 +00:00
|
|
|
m_persistentDescriptor(NULL), m_nativePath(NULL),
|
|
|
|
m_markForUnload(PR_FALSE), m_registryLocation(0)
|
|
|
|
|
1999-02-01 22:40:48 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
m_modDate = LL_Zero();
|
|
|
|
m_size = LL_Zero();
|
|
|
|
|
1999-06-22 14:02:58 +00:00
|
|
|
if (!codeDllName || !*codeDllName)
|
|
|
|
{
|
|
|
|
m_status = DLL_INVALID_PARAM;
|
|
|
|
return;
|
|
|
|
}
|
1999-07-31 00:28:51 +00:00
|
|
|
m_dllName = nsCRT::strdup(codeDllName);
|
1999-06-22 14:02:58 +00:00
|
|
|
if (!m_dllName)
|
|
|
|
{
|
|
|
|
m_status = DLL_NO_MEM;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1999-02-03 18:49:04 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
nsDll::nsDll(nsIFile *dllSpec, const char *registryLocation)
|
|
|
|
: m_dllName(NULL),
|
1999-08-11 01:46:43 +00:00
|
|
|
m_instance(NULL), m_status(DLL_OK), m_moduleObject(NULL),
|
1999-08-13 19:27:58 +00:00
|
|
|
m_persistentDescriptor(NULL), m_nativePath(NULL), m_markForUnload(PR_FALSE)
|
1999-08-11 01:46:43 +00:00
|
|
|
|
1999-06-22 14:02:58 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
m_modDate = LL_Zero();
|
|
|
|
m_size = LL_Zero();
|
|
|
|
m_dllSpec = dllSpec;
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
m_registryLocation = nsCRT::strdup(registryLocation);
|
1999-06-22 14:02:58 +00:00
|
|
|
Init(dllSpec);
|
1999-09-01 06:22:54 +00:00
|
|
|
// Populate m_modDate and m_size
|
|
|
|
if (NS_FAILED(Sync()))
|
|
|
|
{
|
|
|
|
m_status = DLL_INVALID_PARAM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
nsDll::nsDll(nsIFile *dllSpec, const char *registryLocation, PRInt64* modDate, PRInt64* fileSize)
|
|
|
|
: m_dllName(NULL),
|
1999-09-01 06:22:54 +00:00
|
|
|
m_instance(NULL), m_status(DLL_OK), m_moduleObject(NULL),
|
|
|
|
m_persistentDescriptor(NULL), m_nativePath(NULL), m_markForUnload(PR_FALSE)
|
|
|
|
|
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
m_modDate = LL_Zero();
|
|
|
|
m_size = LL_Zero();
|
|
|
|
m_dllSpec = dllSpec;
|
|
|
|
|
1999-09-01 06:22:54 +00:00
|
|
|
m_registryLocation = nsCRT::strdup(registryLocation);
|
|
|
|
Init(dllSpec);
|
2000-01-24 21:28:28 +00:00
|
|
|
|
|
|
|
if (modDate)
|
|
|
|
m_modDate = *modDate;
|
|
|
|
else
|
|
|
|
m_modDate = LL_Zero();
|
|
|
|
|
|
|
|
if (fileSize)
|
|
|
|
m_size = *fileSize;
|
|
|
|
else
|
|
|
|
m_size = LL_Zero();
|
|
|
|
|
1999-02-01 22:40:48 +00:00
|
|
|
}
|
|
|
|
|
1999-06-22 14:02:58 +00:00
|
|
|
nsDll::nsDll(const char *libPersistentDescriptor)
|
2000-01-24 21:28:28 +00:00
|
|
|
: m_dllName(NULL),
|
1999-08-11 01:46:43 +00:00
|
|
|
m_instance(NULL), m_status(DLL_OK), m_moduleObject(NULL),
|
1999-09-13 22:34:42 +00:00
|
|
|
m_persistentDescriptor(NULL), m_nativePath(NULL),
|
|
|
|
m_markForUnload(PR_FALSE), m_registryLocation(0)
|
1999-08-11 01:46:43 +00:00
|
|
|
|
1999-06-22 14:02:58 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
m_modDate = LL_Zero();
|
|
|
|
m_size = LL_Zero();
|
|
|
|
|
1999-06-22 14:02:58 +00:00
|
|
|
Init(libPersistentDescriptor);
|
1999-09-01 06:22:54 +00:00
|
|
|
// Populate m_modDate and m_size
|
|
|
|
if (NS_FAILED(Sync()))
|
|
|
|
{
|
|
|
|
m_status = DLL_INVALID_PARAM;
|
|
|
|
}
|
1999-06-22 14:02:58 +00:00
|
|
|
}
|
1999-02-09 20:30:34 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
nsDll::nsDll(const char *libPersistentDescriptor, PRInt64* modDate, PRInt64* fileSize)
|
|
|
|
: m_dllName(NULL),
|
1999-08-11 01:46:43 +00:00
|
|
|
m_instance(NULL), m_status(DLL_OK), m_moduleObject(NULL),
|
1999-09-13 22:34:42 +00:00
|
|
|
m_persistentDescriptor(NULL), m_nativePath(NULL),
|
|
|
|
m_markForUnload(PR_FALSE), m_registryLocation(0)
|
1999-08-11 01:46:43 +00:00
|
|
|
|
1999-02-09 20:30:34 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
m_modDate = LL_Zero();
|
|
|
|
m_size = LL_Zero();
|
|
|
|
|
1999-06-22 14:02:58 +00:00
|
|
|
Init(libPersistentDescriptor);
|
|
|
|
|
|
|
|
// and overwrite the modData and fileSize
|
2000-01-24 21:28:28 +00:00
|
|
|
|
|
|
|
if (modDate)
|
|
|
|
m_modDate = *modDate;
|
|
|
|
else
|
|
|
|
m_modDate = LL_Zero();
|
|
|
|
|
|
|
|
if (fileSize)
|
|
|
|
m_size = *fileSize;
|
|
|
|
else
|
|
|
|
m_size = LL_Zero();
|
1999-06-22 14:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-01-24 21:28:28 +00:00
|
|
|
nsDll::Init(nsIFile *dllSpec)
|
1999-06-22 14:02:58 +00:00
|
|
|
{
|
|
|
|
// Addref the m_dllSpec
|
|
|
|
m_dllSpec = dllSpec;
|
|
|
|
|
|
|
|
// Make sure we are dealing with a file
|
|
|
|
PRBool isFile = PR_FALSE;
|
1999-08-25 05:26:25 +00:00
|
|
|
nsresult rv = m_dllSpec->IsFile(&isFile);
|
1999-06-22 14:02:58 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
m_status = DLL_INVALID_PARAM;
|
|
|
|
return;
|
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
|
1999-06-22 14:02:58 +00:00
|
|
|
if (isFile == PR_FALSE)
|
|
|
|
{
|
|
|
|
// Not a file. Cant work with it.
|
|
|
|
m_status = DLL_NOT_FILE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_status = DLL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDll::Init(const char *libPersistentDescriptor)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2000-01-24 21:28:28 +00:00
|
|
|
m_modDate = LL_Zero();
|
|
|
|
m_size = LL_Zero();
|
1999-02-09 20:30:34 +00:00
|
|
|
|
1999-06-22 14:02:58 +00:00
|
|
|
if (libPersistentDescriptor == NULL)
|
1999-02-09 20:30:34 +00:00
|
|
|
{
|
|
|
|
m_status = DLL_INVALID_PARAM;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-06-22 14:02:58 +00:00
|
|
|
// Create a FileSpec from the persistentDescriptor
|
2000-01-24 21:28:28 +00:00
|
|
|
nsCOMPtr<nsILocalFile> dllSpec;
|
|
|
|
|
|
|
|
nsCID clsid;
|
|
|
|
nsComponentManager::ProgIDToClassID(NS_LOCAL_FILE_PROGID, &clsid);
|
|
|
|
rv = nsComponentManager::CreateInstance(clsid, nsnull,
|
|
|
|
NS_GET_IID(nsILocalFile),
|
|
|
|
(void**)getter_AddRefs(dllSpec));
|
1999-06-22 14:02:58 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
m_status = DLL_INVALID_PARAM;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
rv = dllSpec->InitWithPath((char *)libPersistentDescriptor);
|
1999-06-22 14:02:58 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
m_status = DLL_INVALID_PARAM;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-02-09 20:30:34 +00:00
|
|
|
}
|
|
|
|
|
1999-06-22 14:02:58 +00:00
|
|
|
|
1999-02-03 15:39:13 +00:00
|
|
|
nsDll::~nsDll(void)
|
1999-02-01 22:40:48 +00:00
|
|
|
{
|
1999-10-07 21:03:48 +00:00
|
|
|
#if 0
|
1999-09-28 19:42:06 +00:00
|
|
|
// The dll gets deleted when the dllStore is destroyed. This happens on
|
|
|
|
// app shutdown. At that point, unloading dlls can cause crashes if we have
|
|
|
|
// - dll dependencies
|
|
|
|
// - callbacks
|
|
|
|
// - static dtors
|
|
|
|
// Hence turn it back on after all the above have been removed.
|
1999-07-31 00:28:51 +00:00
|
|
|
Unload();
|
1999-09-28 19:42:06 +00:00
|
|
|
#endif
|
1999-06-22 14:02:58 +00:00
|
|
|
if (m_dllName)
|
1999-07-31 00:28:51 +00:00
|
|
|
nsCRT::free(m_dllName);
|
1999-08-11 01:46:43 +00:00
|
|
|
if (m_persistentDescriptor)
|
|
|
|
nsCRT::free(m_persistentDescriptor);
|
|
|
|
if (m_nativePath)
|
|
|
|
nsCRT::free(m_nativePath);
|
1999-08-31 21:40:21 +00:00
|
|
|
if (m_registryLocation)
|
|
|
|
nsCRT::free(m_registryLocation);
|
1999-08-11 01:46:43 +00:00
|
|
|
|
1999-02-01 22:40:48 +00:00
|
|
|
}
|
|
|
|
|
1999-09-01 06:22:54 +00:00
|
|
|
nsresult
|
|
|
|
nsDll::Sync()
|
|
|
|
{
|
|
|
|
if (!m_dllSpec)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Populate m_modDate and m_size
|
2000-01-24 21:28:28 +00:00
|
|
|
nsresult rv = m_dllSpec->GetLastModificationDate(&m_modDate);
|
1999-09-01 06:22:54 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = m_dllSpec->GetFileSize(&m_size);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
|
1999-06-22 14:02:58 +00:00
|
|
|
const char *
|
2000-01-24 21:28:28 +00:00
|
|
|
nsDll::GetDisplayPath()
|
1999-06-22 14:02:58 +00:00
|
|
|
{
|
|
|
|
if (m_dllName)
|
|
|
|
return m_dllName;
|
1999-08-11 01:46:43 +00:00
|
|
|
if (m_nativePath)
|
|
|
|
return m_nativePath;
|
2000-01-24 21:28:28 +00:00
|
|
|
m_dllSpec->GetPath(&m_nativePath);
|
1999-08-11 01:46:43 +00:00
|
|
|
return m_nativePath;
|
1999-06-22 14:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
nsDll::GetPersistentDescriptorString()
|
|
|
|
{
|
|
|
|
if (m_dllName)
|
|
|
|
return m_dllName;
|
1999-08-11 01:46:43 +00:00
|
|
|
if (m_persistentDescriptor)
|
|
|
|
return m_persistentDescriptor;
|
2000-01-24 21:28:28 +00:00
|
|
|
m_dllSpec->GetPath(&m_persistentDescriptor);
|
1999-08-11 01:46:43 +00:00
|
|
|
return m_persistentDescriptor;
|
1999-06-22 14:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDll::HasChanged()
|
|
|
|
{
|
|
|
|
if (m_dllName)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// If mod date has changed, then dll has changed
|
2000-01-24 21:28:28 +00:00
|
|
|
PRInt64 currentDate;
|
|
|
|
|
|
|
|
nsresult rv = m_dllSpec->GetLastModificationDate(¤tDate);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || LL_NE(currentDate, m_modDate))
|
1999-06-22 14:02:58 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
// If size has changed, then dll has changed
|
2000-01-24 21:28:28 +00:00
|
|
|
PRInt64 aSize;
|
1999-06-22 14:02:58 +00:00
|
|
|
rv = m_dllSpec->GetFileSize(&aSize);
|
2000-01-24 21:28:28 +00:00
|
|
|
if (NS_FAILED(rv) || LL_NE(aSize, m_size))
|
1999-06-22 14:02:58 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-02-18 00:24:38 +00:00
|
|
|
|
1999-02-03 15:39:13 +00:00
|
|
|
PRBool nsDll::Load(void)
|
1999-02-01 22:40:48 +00:00
|
|
|
{
|
|
|
|
if (m_status != DLL_OK)
|
|
|
|
{
|
|
|
|
return (PR_FALSE);
|
|
|
|
}
|
|
|
|
if (m_instance != NULL)
|
|
|
|
{
|
|
|
|
// Already loaded
|
|
|
|
return (PR_TRUE);
|
|
|
|
}
|
1999-06-22 14:02:58 +00:00
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
if (m_dllSpec)
|
1999-06-22 14:02:58 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(m_dllSpec);
|
|
|
|
|
|
|
|
if (localFile)
|
|
|
|
localFile->Load(&m_instance);
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
if (m_instance) {
|
|
|
|
// Inform refcnt tracer of new library so that calls through the
|
|
|
|
// new library can be traced.
|
|
|
|
char* displayPath;
|
|
|
|
m_dllSpec->GetPath(&displayPath);
|
|
|
|
nsTraceRefcnt::LoadLibrarySymbols(displayPath, m_instance);
|
|
|
|
nsAllocator::Free(displayPath);
|
|
|
|
}
|
|
|
|
#endif
|
1999-06-22 14:02:58 +00:00
|
|
|
}
|
2000-01-24 21:28:28 +00:00
|
|
|
else if (m_dllName)
|
1999-06-22 14:02:58 +00:00
|
|
|
{
|
2000-01-24 21:28:28 +00:00
|
|
|
// if there is not an nsIFile, but there is a dll name, just try to load that..
|
|
|
|
m_instance = PR_LoadLibrary(m_dllName);
|
|
|
|
|
1999-10-24 22:01:09 +00:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2000-01-24 21:28:28 +00:00
|
|
|
if (m_instance) {
|
|
|
|
// Inform refcnt tracer of new library so that calls through the
|
|
|
|
// new library can be traced.
|
|
|
|
nsTraceRefcnt::LoadLibrarySymbols(m_dllName, m_instance);
|
|
|
|
}
|
|
|
|
#endif
|
1999-10-24 22:01:09 +00:00
|
|
|
}
|
2000-01-24 21:28:28 +00:00
|
|
|
|
2000-01-28 09:44:05 +00:00
|
|
|
#if defined(DEBUG) && defined(XP_UNIX)
|
|
|
|
// Debugging help for components. Component dlls need to have their
|
|
|
|
// symbols loaded before we can put a breakpoint in the debugger.
|
|
|
|
// This will help figureing out the point when the dll was loaded.
|
|
|
|
BreakAfterLoad(GetDisplayPath());
|
|
|
|
#endif
|
|
|
|
|
1999-06-22 14:02:58 +00:00
|
|
|
return ((m_instance == NULL) ? PR_FALSE : PR_TRUE);
|
1999-02-01 22:40:48 +00:00
|
|
|
}
|
|
|
|
|
1999-02-03 15:39:13 +00:00
|
|
|
PRBool nsDll::Unload(void)
|
1999-02-01 22:40:48 +00:00
|
|
|
{
|
|
|
|
if (m_status != DLL_OK || m_instance == NULL)
|
|
|
|
return (PR_FALSE);
|
1999-08-09 00:19:08 +00:00
|
|
|
|
1999-09-26 18:06:41 +00:00
|
|
|
// Shutdown the dll
|
|
|
|
Shutdown();
|
1999-08-09 00:19:08 +00:00
|
|
|
|
1999-02-01 22:40:48 +00:00
|
|
|
PRStatus ret = PR_UnloadLibrary(m_instance);
|
|
|
|
if (ret == PR_SUCCESS)
|
|
|
|
{
|
|
|
|
m_instance = NULL;
|
|
|
|
return (PR_TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return (PR_FALSE);
|
|
|
|
}
|
|
|
|
|
1999-02-03 15:39:13 +00:00
|
|
|
void * nsDll::FindSymbol(const char *symbol)
|
1999-02-01 22:40:48 +00:00
|
|
|
{
|
|
|
|
if (symbol == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
// If not already loaded, load it now.
|
|
|
|
if (Load() != PR_TRUE)
|
|
|
|
return (NULL);
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
return(PR_FindSymbol(m_instance, symbol));
|
1999-02-01 22:40:48 +00:00
|
|
|
}
|
1999-08-09 00:19:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Component dll specific functions
|
2000-01-24 21:28:28 +00:00
|
|
|
nsresult nsDll::GetDllSpec(nsIFile **fsobj)
|
1999-08-09 00:19:08 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(m_dllSpec, "m_dllSpec NULL");
|
|
|
|
NS_ASSERTION(fsobj, "xcDll::GetModule : Null argument" );
|
|
|
|
|
|
|
|
*fsobj = m_dllSpec;
|
2000-01-24 21:28:28 +00:00
|
|
|
NS_ADDREF(*fsobj);
|
1999-08-09 00:19:08 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsDll::GetModule(nsISupports *servMgr, nsIModule **cobj)
|
|
|
|
{
|
1999-08-13 19:27:58 +00:00
|
|
|
nsIComponentManager *compMgr;
|
|
|
|
nsresult rv = NS_GetGlobalComponentManager(&compMgr);
|
|
|
|
NS_ASSERTION(compMgr, "Global Component Manager is null" );
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-08-09 00:19:08 +00:00
|
|
|
NS_ASSERTION(cobj, "xcDll::GetModule : Null argument" );
|
|
|
|
|
|
|
|
if (m_moduleObject)
|
|
|
|
{
|
|
|
|
NS_ADDREF(m_moduleObject);
|
|
|
|
*cobj = m_moduleObject;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If not already loaded, load it now.
|
|
|
|
if (Load() != PR_TRUE) return NS_ERROR_FAILURE;
|
|
|
|
|
2000-01-24 21:28:28 +00:00
|
|
|
// We need a nsIFile for location. If we dont
|
1999-08-09 00:19:08 +00:00
|
|
|
// have one, create one.
|
2000-01-24 21:28:28 +00:00
|
|
|
if (!m_dllSpec && m_dllName)
|
1999-08-09 00:19:08 +00:00
|
|
|
{
|
|
|
|
// Create m_dllSpec from m_dllName
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGetModuleProc proc =
|
|
|
|
(nsGetModuleProc) FindSymbol(NS_GET_MODULE_SYMBOL);
|
|
|
|
|
1999-08-31 21:40:21 +00:00
|
|
|
if (proc == NULL)
|
|
|
|
return NS_ERROR_FACTORY_NOT_LOADED;
|
1999-08-09 00:19:08 +00:00
|
|
|
|
1999-08-13 19:27:58 +00:00
|
|
|
rv = (*proc) (compMgr, m_dllSpec, &m_moduleObject);
|
1999-08-09 00:19:08 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
NS_ADDREF(m_moduleObject);
|
|
|
|
*cobj = m_moduleObject;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
1999-09-26 18:06:41 +00:00
|
|
|
|
|
|
|
nsresult nsDll::Shutdown(void)
|
|
|
|
{
|
|
|
|
// Release the module object if we got one
|
|
|
|
nsrefcnt refcnt;
|
|
|
|
if (m_moduleObject)
|
|
|
|
{
|
|
|
|
NS_RELEASE2(m_moduleObject, refcnt);
|
|
|
|
NS_ASSERTION(refcnt == 0, "Dll moduleObject refcount non zero");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
}
|
2000-01-28 09:44:05 +00:00
|
|
|
|
|
|
|
void nsDll::BreakAfterLoad(const char *nsprPath)
|
|
|
|
{
|
2000-04-12 06:20:59 +00:00
|
|
|
#ifndef XP_BEOS
|
2000-01-28 09:44:05 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
static PRBool firstTime = PR_TRUE;
|
|
|
|
static nsCString breakList[16];
|
|
|
|
static int count = 0;
|
|
|
|
|
|
|
|
// return if invalid input
|
|
|
|
if (!nsprPath || !*nsprPath) return;
|
|
|
|
|
|
|
|
// return if nothing to break on
|
|
|
|
if (!firstTime && count == 0) return;
|
|
|
|
|
|
|
|
if (firstTime)
|
|
|
|
{
|
|
|
|
firstTime = PR_FALSE;
|
|
|
|
// Form the list of dlls to break on load
|
|
|
|
nsCAutoString envList(getenv("XPCOM_BREAK_ON_LOAD"));
|
|
|
|
if (envList.IsEmpty()) return;
|
|
|
|
PRInt32 ofset = 0;
|
|
|
|
PRInt32 start = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ofset = envList.FindChar(':', PR_TRUE, start);
|
|
|
|
envList.Mid(breakList[count], start, ofset);
|
|
|
|
count++;
|
|
|
|
start = ofset + 1;
|
|
|
|
}
|
2000-04-25 05:09:49 +00:00
|
|
|
while (ofset != -1 && 16 > count); // avoiding vc6.0 compiler issue. count < thinks it is starting a template
|
2000-01-28 09:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find the dllname part of the string
|
|
|
|
nsCString currentPath(nsprPath);
|
|
|
|
PRInt32 lastSep = currentPath.RFindCharInSet(":\\/");
|
|
|
|
|
|
|
|
for (int i=0; i<count; i++)
|
|
|
|
if (currentPath.Find(breakList[i], PR_TRUE, lastSep) > 0)
|
|
|
|
{
|
|
|
|
// Loading a dll that we want to break on
|
|
|
|
// Put your breakpoint here
|
|
|
|
printf("...Loading module %s\n", nsprPath);
|
|
|
|
// Break in the debugger here.
|
2000-03-25 08:54:22 +00:00
|
|
|
#if defined(linux) && defined(__i386)
|
2000-01-28 09:44:05 +00:00
|
|
|
asm("int $3");
|
2000-03-25 08:54:22 +00:00
|
|
|
#elif defined(VMS)
|
|
|
|
lib$signal(SS$_DEBUG);
|
2000-02-21 22:56:55 +00:00
|
|
|
#endif
|
2000-01-28 09:44:05 +00:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
2000-04-12 06:20:59 +00:00
|
|
|
#endif /* !XP_BEOS */
|
2000-01-28 09:44:05 +00:00
|
|
|
return;
|
|
|
|
}
|