xcDll.cpp revision 489ce997e6d81472bf0d1322ad2b5b57ffa4c53d
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* nsDll
*
* Abstraction of a Dll. Stores modifiedTime and size for easy detection of
* change in dll.
*
* dp Suresh <dp@netscape.com>
*/
#include "xcDll.h"
#include "nsDebug.h"
#include "nsIComponentManager.h"
#include "nsIComponentLoaderManager.h"
#include "nsIModule.h"
#include "nsILocalFile.h"
#include "nsDirectoryServiceDefs.h"
#include "nsDirectoryServiceUtils.h"
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsString.h"
#include "nsITimelineService.h"
#include "nsModule.h"
#ifdef DEBUG
#if defined(VMS)
#include <ssdef.h>
#include <signal.h>
#endif
#endif /* defined(DEBUG) */
#include "nsTraceRefcntImpl.h"
#define UNLOAD_DEPENDENT_LIBS
#ifdef HPUX
#endif
#include "nsNativeComponentLoader.h"
#ifdef VBOX_USE_IPRT_IN_XPCOM
# include "nsMemory.h"
#endif
{
}
{
//#if DEBUG_dougt
// 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.
//Unload();
//#endif
}
void
{
}
nsDll::HasChanged()
{
if (!manager)
return PR_TRUE;
// If mod date has changed, then dll has changed
return PR_TRUE;
return changed;
}
{
if (m_instance != NULL)
{
// Already loaded
return (PR_TRUE);
}
if (m_dllSpec)
{
#ifdef NS_BUILD_REFCNT_LOGGING
#endif
// Load any library dependencies
// The Component Loader Manager may hold onto some extra data
// set by either the native component loader or the native
// component. We assume that this data is a space delimited
// listing of dependent libraries which are required to be
// loaded prior to us loading the given component. Once, the
// component is loaded into memory, we can release our hold
// on the dependent libraries with the assumption that the
// component library holds a reference via the OS so loader.
#if defined(XP_UNIX)
if (!manager)
return PR_TRUE;
#ifdef UNLOAD_DEPENDENT_LIBS
#endif
// if there was any extra data, treat it as a listing of dependent libs
{
// all dependent libraries are suppose to be in the "gre" directory.
// note that the gre directory is the same as the "bin" directory,
// when there isn't a real "gre" found.
if (!file)
return NS_ERROR_FAILURE;
// we are talking about a file in the GRE dir. Lets append something
// stupid right now, so that later we can just set the leaf name.
# ifdef VBOX_USE_IPRT_IN_XPCOM
# else
# endif
if (!buffer)
return NS_ERROR_OUT_OF_MEMORY;
char* newStr;
{
continue;
}
if (!path)
return NS_ERROR_FAILURE;
// Load this dependent library with the global flag and stash
// the result for later so that we can unload it.
// if the depend library path starts with a / we are
// going to assume that it is a full path and should
// be loaded without prepending the gre diretory
// location. We could have short circuited the
// SetNativeLeafName above, but this is clearer and
// the common case is a relative path.
if (token[0] == '/')
else
// if we couldn't load the dependent library. We did the best we
// can. Now just let us fail later if this really was a required
// dependency.
#ifdef UNLOAD_DEPENDENT_LIBS
if (lib)
#endif
}
# ifdef VBOX_USE_IPRT_IN_XPCOM
# else
# endif
}
#endif
// load the component
#if defined(XP_UNIX)
// Unload any of library dependencies we loaded earlier. The assumption
// here is that the component will have a "internal" reference count to
// the dependency library we just loaded.
// XXX should we unload later - or even at all?
#ifdef UNLOAD_DEPENDENT_LIBS
{
}
#endif
#endif
#ifdef NS_BUILD_REFCNT_LOGGING
if (m_instance) {
// Inform refcnt tracer of new library so that calls through the
// new library can be traced.
}
#endif
}
// 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.
#endif
}
{
if (m_instance == NULL)
return (PR_FALSE);
// Shutdown the dll
Shutdown();
#ifdef NS_BUILD_REFCNT_LOGGING
#endif
#ifdef NS_BUILD_REFCNT_LOGGING
#endif
if (ret == PR_SUCCESS)
{
m_instance = NULL;
return (PR_TRUE);
}
else
return (PR_FALSE);
}
{
return (NULL);
// If not already loaded, load it now.
return (NULL);
}
// Component dll specific functions
{
return NS_OK;
}
{
// using the backpointer of the loader.
if (!compMgr) return NS_ERROR_UNEXPECTED;
if (m_moduleObject)
{
*cobj = m_moduleObject;
return NS_OK;
}
// If not already loaded, load it now.
// We need a nsIFile for location
if (!m_dllSpec)
{
return NS_ERROR_FAILURE;
}
return NS_ERROR_FACTORY_NOT_LOADED;
if (NS_SUCCEEDED(rv))
{
*cobj = m_moduleObject;
}
return rv;
}
// These are used by BreakAfterLoad, below.
static int sBreakListCount = 0;
#endif
{
// Release the module object if we got one
if (m_moduleObject)
{
}
for (int i = 0; i < sBreakListCount; i++)
{
delete sBreakList[i];
sBreakList[i] = nsnull;
}
sBreakListCount = 0;
#endif
return NS_OK;
}
{
// return if invalid input
// return if nothing to break on
if (!firstTime && sBreakListCount == 0) return;
if (firstTime)
{
// Form the list of dlls to break on load
do
{
}
while (ofset != -1 && 16 > sBreakListCount); // avoiding vc6.0 compiler issue. count < thinks it is starting a template
}
// Find the dllname part of the string
for (int i=0; i<sBreakListCount; i++)
{
// Loading a dll that we want to break on
// Put your breakpoint here
// Break in the debugger here.
asm("int $3");
#endif
}
return;
}
#endif /* SHOULD_IMPLEMENT_BREAKAFTERLOAD */