michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsXPCOM.h" michael@0: #include "nsXPCOMPrivate.h" michael@0: #include "nsXPCOMStrings.h" michael@0: #include "xptcall.h" michael@0: michael@0: #include michael@0: michael@0: /** michael@0: * Private Method to register an exit routine. This method michael@0: * used to allow you to setup a callback that will be called from michael@0: * the NS_ShutdownXPCOM function after all services and michael@0: * components have gone away. It was fatally flawed in that the component michael@0: * DLL could be released before the exit function was called; it is now a michael@0: * stub implementation that does nothing. michael@0: */ michael@0: XPCOM_API(nsresult) michael@0: NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, uint32_t priority); michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine); michael@0: michael@0: static const XPCOMFunctions kFrozenFunctions = { michael@0: XPCOM_GLUE_VERSION, michael@0: sizeof(XPCOMFunctions), michael@0: &NS_InitXPCOM2, michael@0: &NS_ShutdownXPCOM, michael@0: &NS_GetServiceManager, michael@0: &NS_GetComponentManager, michael@0: &NS_GetComponentRegistrar, michael@0: &NS_GetMemoryManager, michael@0: &NS_NewLocalFile, michael@0: &NS_NewNativeLocalFile, michael@0: &NS_RegisterXPCOMExitRoutine, michael@0: &NS_UnregisterXPCOMExitRoutine, michael@0: michael@0: // these functions were added post 1.4 michael@0: &NS_GetDebug, michael@0: nullptr, michael@0: michael@0: // these functions were added post 1.6 michael@0: &NS_StringContainerInit, michael@0: &NS_StringContainerFinish, michael@0: &NS_StringGetData, michael@0: &NS_StringSetData, michael@0: &NS_StringSetDataRange, michael@0: &NS_StringCopy, michael@0: &NS_CStringContainerInit, michael@0: &NS_CStringContainerFinish, michael@0: &NS_CStringGetData, michael@0: &NS_CStringSetData, michael@0: &NS_CStringSetDataRange, michael@0: &NS_CStringCopy, michael@0: &NS_CStringToUTF16, michael@0: &NS_UTF16ToCString, michael@0: &NS_StringCloneData, michael@0: &NS_CStringCloneData, michael@0: michael@0: // these functions were added post 1.7 (post Firefox 1.0) michael@0: &NS_Alloc, michael@0: &NS_Realloc, michael@0: &NS_Free, michael@0: &NS_StringContainerInit2, michael@0: &NS_CStringContainerInit2, michael@0: &NS_StringGetMutableData, michael@0: &NS_CStringGetMutableData, michael@0: nullptr, michael@0: michael@0: // these functions were added post 1.8 michael@0: &NS_DebugBreak, michael@0: &NS_LogInit, michael@0: &NS_LogTerm, michael@0: &NS_LogAddRef, michael@0: &NS_LogRelease, michael@0: &NS_LogCtor, michael@0: &NS_LogDtor, michael@0: &NS_LogCOMPtrAddRef, michael@0: &NS_LogCOMPtrRelease, michael@0: &NS_GetXPTCallStub, michael@0: &NS_DestroyXPTCallStub, michael@0: &NS_InvokeByIndex, michael@0: nullptr, michael@0: nullptr, michael@0: &NS_StringSetIsVoid, michael@0: &NS_StringGetIsVoid, michael@0: &NS_CStringSetIsVoid, michael@0: &NS_CStringGetIsVoid, michael@0: michael@0: // these functions were added post 1.9, but then made obsolete michael@0: nullptr, michael@0: nullptr, michael@0: michael@0: &NS_CycleCollectorSuspect3, michael@0: }; michael@0: michael@0: EXPORT_XPCOM_API(nsresult) michael@0: NS_GetFrozenFunctions(XPCOMFunctions *functions, const char* /* libraryPath */) michael@0: { michael@0: if (!functions) michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: michael@0: if (functions->version != XPCOM_GLUE_VERSION) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: uint32_t size = functions->size; michael@0: if (size > sizeof(XPCOMFunctions)) michael@0: size = sizeof(XPCOMFunctions); michael@0: michael@0: size -= offsetof(XPCOMFunctions, init); michael@0: michael@0: memcpy(&functions->init, &kFrozenFunctions.init, size); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: /* michael@0: * Stubs for nsXPCOMPrivate.h michael@0: */ michael@0: michael@0: EXPORT_XPCOM_API(nsresult) michael@0: NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, uint32_t priority) michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: EXPORT_XPCOM_API(nsresult) michael@0: NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine) michael@0: { michael@0: return NS_OK; michael@0: }