michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim:set ts=4 sw=4 et cindent: */ 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 "nsXPCOMGlue.h" michael@0: michael@0: #include "nspr.h" michael@0: #include "nsDebug.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsXPCOMPrivate.h" michael@0: #include "nsCOMPtr.h" michael@0: #include michael@0: #include michael@0: michael@0: #include "mozilla/FileUtils.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: #define XPCOM_DEPENDENT_LIBS_LIST "dependentlibs.list" michael@0: michael@0: static XPCOMFunctions xpcomFunctions; michael@0: static bool do_preload = false; michael@0: michael@0: #if defined(XP_WIN) michael@0: #define READ_TEXTMODE L"rt" michael@0: #else michael@0: #define READ_TEXTMODE "r" michael@0: #endif michael@0: michael@0: #if defined(SUNOS4) || defined(NEXTSTEP) || \ michael@0: defined(XP_DARWIN) || \ michael@0: (defined(OPENBSD) || defined(NETBSD)) && !defined(__ELF__) michael@0: #define LEADING_UNDERSCORE "_" michael@0: #else michael@0: #define LEADING_UNDERSCORE michael@0: #endif michael@0: michael@0: #if defined(XP_WIN) michael@0: #include michael@0: #include michael@0: #define snprintf _snprintf michael@0: michael@0: typedef HINSTANCE LibHandleType; michael@0: michael@0: static LibHandleType michael@0: GetLibHandle(pathstr_t aDependentLib) michael@0: { michael@0: LibHandleType libHandle = michael@0: LoadLibraryExW(aDependentLib, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH); michael@0: michael@0: if (!libHandle) { michael@0: DWORD err = GetLastError(); michael@0: #ifdef DEBUG michael@0: LPVOID lpMsgBuf; michael@0: FormatMessage( michael@0: FORMAT_MESSAGE_ALLOCATE_BUFFER | michael@0: FORMAT_MESSAGE_FROM_SYSTEM | michael@0: FORMAT_MESSAGE_IGNORE_INSERTS, michael@0: nullptr, michael@0: err, michael@0: MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), michael@0: (LPTSTR) &lpMsgBuf, michael@0: 0, michael@0: nullptr michael@0: ); michael@0: wprintf(L"Error loading %ls: %s\n", aDependentLib, lpMsgBuf); michael@0: LocalFree(lpMsgBuf); michael@0: #endif michael@0: } michael@0: michael@0: return libHandle; michael@0: } michael@0: michael@0: static NSFuncPtr michael@0: GetSymbol(LibHandleType aLibHandle, const char *aSymbol) michael@0: { michael@0: return (NSFuncPtr) GetProcAddress(aLibHandle, aSymbol); michael@0: } michael@0: michael@0: static void michael@0: CloseLibHandle(LibHandleType aLibHandle) michael@0: { michael@0: FreeLibrary(aLibHandle); michael@0: } michael@0: michael@0: #elif defined(XP_MACOSX) michael@0: #include michael@0: michael@0: typedef const mach_header *LibHandleType; michael@0: michael@0: static LibHandleType michael@0: GetLibHandle(pathstr_t aDependentLib) michael@0: { michael@0: LibHandleType libHandle = NSAddImage(aDependentLib, michael@0: NSADDIMAGE_OPTION_RETURN_ON_ERROR | michael@0: NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME); michael@0: if (!libHandle) { michael@0: NSLinkEditErrors linkEditError; michael@0: int errorNum; michael@0: const char *errorString; michael@0: const char *fileName; michael@0: NSLinkEditError(&linkEditError, &errorNum, &fileName, &errorString); michael@0: fprintf(stderr, "XPCOMGlueLoad error %d:%d for file %s:\n%s\n", michael@0: linkEditError, errorNum, fileName, errorString); michael@0: } michael@0: return libHandle; michael@0: } michael@0: michael@0: static NSFuncPtr michael@0: GetSymbol(LibHandleType aLibHandle, const char *aSymbol) michael@0: { michael@0: // Try to use |NSLookupSymbolInImage| since it is faster than searching michael@0: // the global symbol table. If we couldn't get a mach_header pointer michael@0: // for the XPCOM dylib, then use |NSLookupAndBindSymbol| to search the michael@0: // global symbol table (this shouldn't normally happen, unless the user michael@0: // has called XPCOMGlueStartup(".") and relies on libxpcom.dylib michael@0: // already being loaded). michael@0: NSSymbol sym = nullptr; michael@0: if (aLibHandle) { michael@0: sym = NSLookupSymbolInImage(aLibHandle, aSymbol, michael@0: NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | michael@0: NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); michael@0: } else { michael@0: if (NSIsSymbolNameDefined(aSymbol)) michael@0: sym = NSLookupAndBindSymbol(aSymbol); michael@0: } michael@0: if (!sym) michael@0: return nullptr; michael@0: michael@0: return (NSFuncPtr) NSAddressOfSymbol(sym); michael@0: } michael@0: michael@0: static void michael@0: CloseLibHandle(LibHandleType aLibHandle) michael@0: { michael@0: // we cannot unload dylibs on OS X michael@0: } michael@0: michael@0: #else michael@0: #include michael@0: michael@0: #if defined(MOZ_LINKER) && !defined(ANDROID) michael@0: extern "C" { michael@0: NS_HIDDEN __typeof(dlopen) __wrap_dlopen; michael@0: NS_HIDDEN __typeof(dlsym) __wrap_dlsym; michael@0: NS_HIDDEN __typeof(dlclose) __wrap_dlclose; michael@0: } michael@0: michael@0: #define dlopen __wrap_dlopen michael@0: #define dlsym __wrap_dlsym michael@0: #define dlclose __wrap_dlclose michael@0: #endif michael@0: michael@0: #ifdef NS_TRACE_MALLOC michael@0: extern "C" { michael@0: NS_EXPORT_(__ptr_t) __libc_malloc(size_t); michael@0: NS_EXPORT_(__ptr_t) __libc_calloc(size_t, size_t); michael@0: NS_EXPORT_(__ptr_t) __libc_realloc(__ptr_t, size_t); michael@0: NS_EXPORT_(void) __libc_free(__ptr_t); michael@0: NS_EXPORT_(__ptr_t) __libc_memalign(size_t, size_t); michael@0: NS_EXPORT_(__ptr_t) __libc_valloc(size_t); michael@0: } michael@0: michael@0: static __ptr_t (*_malloc)(size_t) = __libc_malloc; michael@0: static __ptr_t (*_calloc)(size_t, size_t) = __libc_calloc; michael@0: static __ptr_t (*_realloc)(__ptr_t, size_t) = __libc_realloc; michael@0: static void (*_free)(__ptr_t) = __libc_free; michael@0: static __ptr_t (*_memalign)(size_t, size_t) = __libc_memalign; michael@0: static __ptr_t (*_valloc)(size_t) = __libc_valloc; michael@0: michael@0: NS_EXPORT_(__ptr_t) malloc(size_t size) michael@0: { michael@0: return _malloc(size); michael@0: } michael@0: michael@0: NS_EXPORT_(__ptr_t) calloc(size_t nmemb, size_t size) michael@0: { michael@0: return _calloc(nmemb, size); michael@0: } michael@0: michael@0: NS_EXPORT_(__ptr_t) realloc(__ptr_t ptr, size_t size) michael@0: { michael@0: return _realloc(ptr, size); michael@0: } michael@0: michael@0: NS_EXPORT_(void) free(__ptr_t ptr) michael@0: { michael@0: _free(ptr); michael@0: } michael@0: michael@0: NS_EXPORT_(void) cfree(__ptr_t ptr) michael@0: { michael@0: _free(ptr); michael@0: } michael@0: michael@0: NS_EXPORT_(__ptr_t) memalign(size_t boundary, size_t size) michael@0: { michael@0: return _memalign(boundary, size); michael@0: } michael@0: michael@0: NS_EXPORT_(int) michael@0: posix_memalign(void **memptr, size_t alignment, size_t size) michael@0: { michael@0: __ptr_t ptr = _memalign(alignment, size); michael@0: if (!ptr) michael@0: return ENOMEM; michael@0: *memptr = ptr; michael@0: return 0; michael@0: } michael@0: michael@0: NS_EXPORT_(__ptr_t) valloc(size_t size) michael@0: { michael@0: return _valloc(size); michael@0: } michael@0: #endif /* NS_TRACE_MALLOC */ michael@0: michael@0: typedef void *LibHandleType; michael@0: michael@0: static LibHandleType michael@0: GetLibHandle(pathstr_t aDependentLib) michael@0: { michael@0: LibHandleType libHandle = dlopen(aDependentLib, RTLD_GLOBAL | RTLD_LAZY); michael@0: if (!libHandle) { michael@0: fprintf(stderr, "XPCOMGlueLoad error for file %s:\n%s\n", aDependentLib, dlerror()); michael@0: } michael@0: return libHandle; michael@0: } michael@0: michael@0: static NSFuncPtr michael@0: GetSymbol(LibHandleType aLibHandle, const char *aSymbol) michael@0: { michael@0: return (NSFuncPtr) dlsym(aLibHandle, aSymbol); michael@0: } michael@0: michael@0: static void michael@0: CloseLibHandle(LibHandleType aLibHandle) michael@0: { michael@0: dlclose(aLibHandle); michael@0: } michael@0: #endif michael@0: michael@0: struct DependentLib michael@0: { michael@0: LibHandleType libHandle; michael@0: DependentLib *next; michael@0: }; michael@0: michael@0: static DependentLib *sTop; michael@0: michael@0: static void michael@0: AppendDependentLib(LibHandleType libHandle) michael@0: { michael@0: DependentLib *d = new DependentLib; michael@0: if (!d) michael@0: return; michael@0: michael@0: d->next = sTop; michael@0: d->libHandle = libHandle; michael@0: michael@0: sTop = d; michael@0: } michael@0: michael@0: static bool michael@0: ReadDependentCB(pathstr_t aDependentLib, bool do_preload) michael@0: { michael@0: if (do_preload) { michael@0: ReadAheadLib(aDependentLib); michael@0: } michael@0: LibHandleType libHandle = GetLibHandle(aDependentLib); michael@0: if (libHandle) { michael@0: AppendDependentLib(libHandle); michael@0: } michael@0: michael@0: return libHandle; michael@0: } michael@0: michael@0: #ifdef XP_WIN michael@0: static bool michael@0: ReadDependentCB(const char *aDependentLib, bool do_preload) michael@0: { michael@0: wchar_t wideDependentLib[MAX_PATH]; michael@0: MultiByteToWideChar(CP_UTF8, 0, aDependentLib, -1, wideDependentLib, MAX_PATH); michael@0: return ReadDependentCB(wideDependentLib, do_preload); michael@0: } michael@0: michael@0: inline FILE *TS_tfopen (const char *path, const wchar_t *mode) michael@0: { michael@0: wchar_t wPath[MAX_PATH]; michael@0: MultiByteToWideChar(CP_UTF8, 0, path, -1, wPath, MAX_PATH); michael@0: return _wfopen(wPath, mode); michael@0: } michael@0: #else michael@0: inline FILE *TS_tfopen (const char *path, const char *mode) michael@0: { michael@0: return fopen(path, mode); michael@0: } michael@0: #endif michael@0: michael@0: /* RAII wrapper for FILE descriptors */ michael@0: struct ScopedCloseFileTraits michael@0: { michael@0: typedef FILE *type; michael@0: static type empty() { return nullptr; } michael@0: static void release(type f) { michael@0: if (f) { michael@0: fclose(f); michael@0: } michael@0: } michael@0: }; michael@0: typedef Scoped ScopedCloseFile; michael@0: michael@0: static void michael@0: XPCOMGlueUnload() michael@0: { michael@0: #if !defined(XP_WIN) && !defined(XP_MACOSX) && defined(NS_TRACE_MALLOC) michael@0: if (sTop) { michael@0: _malloc = __libc_malloc; michael@0: _calloc = __libc_calloc; michael@0: _realloc = __libc_realloc; michael@0: _free = __libc_free; michael@0: _memalign = __libc_memalign; michael@0: _valloc = __libc_valloc; michael@0: } michael@0: #endif michael@0: michael@0: while (sTop) { michael@0: CloseLibHandle(sTop->libHandle); michael@0: michael@0: DependentLib *temp = sTop; michael@0: sTop = sTop->next; michael@0: michael@0: delete temp; michael@0: } michael@0: } michael@0: michael@0: #if defined(XP_WIN) michael@0: // like strpbrk but finds the *last* char, not the first michael@0: static const char* michael@0: ns_strrpbrk(const char *string, const char *strCharSet) michael@0: { michael@0: const char *found = nullptr; michael@0: for (; *string; ++string) { michael@0: for (const char *search = strCharSet; *search; ++search) { michael@0: if (*search == *string) { michael@0: found = string; michael@0: // Since we're looking for the last char, we save "found" michael@0: // until we're at the end of the string. michael@0: } michael@0: } michael@0: } michael@0: michael@0: return found; michael@0: } michael@0: #endif michael@0: michael@0: static GetFrozenFunctionsFunc michael@0: XPCOMGlueLoad(const char *xpcomFile) michael@0: { michael@0: char xpcomDir[MAXPATHLEN]; michael@0: #if defined(XP_WIN) michael@0: const char *lastSlash = ns_strrpbrk(xpcomFile, "/\\"); michael@0: #else michael@0: const char *lastSlash = strrchr(xpcomFile, '/'); michael@0: #endif michael@0: char *cursor; michael@0: if (lastSlash) { michael@0: size_t len = size_t(lastSlash - xpcomFile); michael@0: michael@0: if (len > MAXPATHLEN - sizeof(XPCOM_FILE_PATH_SEPARATOR michael@0: XPCOM_DEPENDENT_LIBS_LIST)) { michael@0: return nullptr; michael@0: } michael@0: memcpy(xpcomDir, xpcomFile, len); michael@0: strcpy(xpcomDir + len, XPCOM_FILE_PATH_SEPARATOR michael@0: XPCOM_DEPENDENT_LIBS_LIST); michael@0: cursor = xpcomDir + len + 1; michael@0: } else { michael@0: strcpy(xpcomDir, XPCOM_DEPENDENT_LIBS_LIST); michael@0: cursor = xpcomDir; michael@0: } michael@0: michael@0: if (getenv("MOZ_RUN_GTEST")) { michael@0: strcat(xpcomDir, ".gtest"); michael@0: } michael@0: michael@0: ScopedCloseFile flist; michael@0: flist = TS_tfopen(xpcomDir, READ_TEXTMODE); michael@0: if (!flist) { michael@0: return nullptr; michael@0: } michael@0: michael@0: *cursor = '\0'; michael@0: michael@0: char buffer[MAXPATHLEN]; michael@0: michael@0: while (fgets(buffer, sizeof(buffer), flist)) { michael@0: int l = strlen(buffer); michael@0: michael@0: // ignore empty lines and comments michael@0: if (l == 0 || *buffer == '#') { michael@0: continue; michael@0: } michael@0: michael@0: // cut the trailing newline, if present michael@0: if (buffer[l - 1] == '\n') michael@0: buffer[l - 1] = '\0'; michael@0: michael@0: if (l + size_t(cursor - xpcomDir) > MAXPATHLEN) { michael@0: return nullptr; michael@0: } michael@0: michael@0: strcpy(cursor, buffer); michael@0: if (!ReadDependentCB(xpcomDir, do_preload)) { michael@0: XPCOMGlueUnload(); michael@0: return nullptr; michael@0: } michael@0: } michael@0: michael@0: GetFrozenFunctionsFunc sym = michael@0: (GetFrozenFunctionsFunc) GetSymbol(sTop->libHandle, LEADING_UNDERSCORE "NS_GetFrozenFunctions"); michael@0: michael@0: if (!sym) { // No symbol found. michael@0: XPCOMGlueUnload(); michael@0: return nullptr; michael@0: } michael@0: michael@0: #if !defined(XP_WIN) && !defined(XP_MACOSX) && defined(NS_TRACE_MALLOC) michael@0: _malloc = (__ptr_t(*)(size_t)) GetSymbol(sTop->libHandle, "malloc"); michael@0: _calloc = (__ptr_t(*)(size_t, size_t)) GetSymbol(sTop->libHandle, "calloc"); michael@0: _realloc = (__ptr_t(*)(__ptr_t, size_t)) GetSymbol(sTop->libHandle, "realloc"); michael@0: _free = (void(*)(__ptr_t)) GetSymbol(sTop->libHandle, "free"); michael@0: _memalign = (__ptr_t(*)(size_t, size_t)) GetSymbol(sTop->libHandle, "memalign"); michael@0: _valloc = (__ptr_t(*)(size_t)) GetSymbol(sTop->libHandle, "valloc"); michael@0: #endif michael@0: michael@0: return sym; michael@0: } michael@0: michael@0: nsresult michael@0: XPCOMGlueLoadXULFunctions(const nsDynamicFunctionLoad *symbols) michael@0: { michael@0: // We don't null-check sXULLibHandle because this might work even michael@0: // if it is null (same as RTLD_DEFAULT) michael@0: michael@0: nsresult rv = NS_OK; michael@0: while (symbols->functionName) { michael@0: char buffer[512]; michael@0: snprintf(buffer, sizeof(buffer), michael@0: LEADING_UNDERSCORE "%s", symbols->functionName); michael@0: michael@0: *symbols->function = (NSFuncPtr) GetSymbol(sTop->libHandle, buffer); michael@0: if (!*symbols->function) michael@0: rv = NS_ERROR_LOSS_OF_SIGNIFICANT_DATA; michael@0: michael@0: ++symbols; michael@0: } michael@0: return rv; michael@0: } michael@0: michael@0: void XPCOMGlueEnablePreload() michael@0: { michael@0: do_preload = true; michael@0: } michael@0: michael@0: nsresult XPCOMGlueStartup(const char* xpcomFile) michael@0: { michael@0: xpcomFunctions.version = XPCOM_GLUE_VERSION; michael@0: xpcomFunctions.size = sizeof(XPCOMFunctions); michael@0: michael@0: if (!xpcomFile) michael@0: xpcomFile = XPCOM_DLL; michael@0: michael@0: GetFrozenFunctionsFunc func = XPCOMGlueLoad(xpcomFile); michael@0: if (!func) michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: michael@0: nsresult rv = (*func)(&xpcomFunctions, nullptr); michael@0: if (NS_FAILED(rv)) { michael@0: XPCOMGlueUnload(); michael@0: return rv; michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_InitXPCOM2(nsIServiceManager* *result, michael@0: nsIFile* binDirectory, michael@0: nsIDirectoryServiceProvider* appFileLocationProvider) michael@0: { michael@0: if (!xpcomFunctions.init) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.init(result, binDirectory, appFileLocationProvider); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_ShutdownXPCOM(nsIServiceManager* servMgr) michael@0: { michael@0: if (!xpcomFunctions.shutdown) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.shutdown(servMgr); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_GetServiceManager(nsIServiceManager* *result) michael@0: { michael@0: if (!xpcomFunctions.getServiceManager) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.getServiceManager(result); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_GetComponentManager(nsIComponentManager* *result) michael@0: { michael@0: if (!xpcomFunctions.getComponentManager) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.getComponentManager(result); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_GetComponentRegistrar(nsIComponentRegistrar* *result) michael@0: { michael@0: if (!xpcomFunctions.getComponentRegistrar) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.getComponentRegistrar(result); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_GetMemoryManager(nsIMemory* *result) michael@0: { michael@0: if (!xpcomFunctions.getMemoryManager) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.getMemoryManager(result); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_NewLocalFile(const nsAString &path, bool followLinks, nsIFile* *result) michael@0: { michael@0: if (!xpcomFunctions.newLocalFile) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.newLocalFile(path, followLinks, result); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_NewNativeLocalFile(const nsACString &path, bool followLinks, nsIFile* *result) michael@0: { michael@0: if (!xpcomFunctions.newNativeLocalFile) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.newNativeLocalFile(path, followLinks, result); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_GetDebug(nsIDebug* *result) michael@0: { michael@0: if (!xpcomFunctions.getDebug) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.getDebug(result); michael@0: } michael@0: michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_StringContainerInit(nsStringContainer &aStr) michael@0: { michael@0: if (!xpcomFunctions.stringContainerInit) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.stringContainerInit(aStr); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_StringContainerInit2(nsStringContainer &aStr, michael@0: const char16_t *aData, michael@0: uint32_t aDataLength, michael@0: uint32_t aFlags) michael@0: { michael@0: if (!xpcomFunctions.stringContainerInit2) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.stringContainerInit2(aStr, aData, aDataLength, aFlags); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_StringContainerFinish(nsStringContainer &aStr) michael@0: { michael@0: if (xpcomFunctions.stringContainerFinish) michael@0: xpcomFunctions.stringContainerFinish(aStr); michael@0: } michael@0: michael@0: XPCOM_API(uint32_t) michael@0: NS_StringGetData(const nsAString &aStr, const char16_t **aBuf, bool *aTerm) michael@0: { michael@0: if (!xpcomFunctions.stringGetData) { michael@0: *aBuf = nullptr; michael@0: return 0; michael@0: } michael@0: return xpcomFunctions.stringGetData(aStr, aBuf, aTerm); michael@0: } michael@0: michael@0: XPCOM_API(uint32_t) michael@0: NS_StringGetMutableData(nsAString &aStr, uint32_t aLen, char16_t **aBuf) michael@0: { michael@0: if (!xpcomFunctions.stringGetMutableData) { michael@0: *aBuf = nullptr; michael@0: return 0; michael@0: } michael@0: return xpcomFunctions.stringGetMutableData(aStr, aLen, aBuf); michael@0: } michael@0: michael@0: XPCOM_API(char16_t*) michael@0: NS_StringCloneData(const nsAString &aStr) michael@0: { michael@0: if (!xpcomFunctions.stringCloneData) michael@0: return nullptr; michael@0: return xpcomFunctions.stringCloneData(aStr); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_StringSetData(nsAString &aStr, const char16_t *aBuf, uint32_t aCount) michael@0: { michael@0: if (!xpcomFunctions.stringSetData) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: michael@0: return xpcomFunctions.stringSetData(aStr, aBuf, aCount); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_StringSetDataRange(nsAString &aStr, uint32_t aCutStart, uint32_t aCutLength, michael@0: const char16_t *aBuf, uint32_t aCount) michael@0: { michael@0: if (!xpcomFunctions.stringSetDataRange) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.stringSetDataRange(aStr, aCutStart, aCutLength, aBuf, aCount); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_StringCopy(nsAString &aDest, const nsAString &aSrc) michael@0: { michael@0: if (!xpcomFunctions.stringCopy) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.stringCopy(aDest, aSrc); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_StringSetIsVoid(nsAString &aStr, const bool aIsVoid) michael@0: { michael@0: if (xpcomFunctions.stringSetIsVoid) michael@0: xpcomFunctions.stringSetIsVoid(aStr, aIsVoid); michael@0: } michael@0: michael@0: XPCOM_API(bool) michael@0: NS_StringGetIsVoid(const nsAString &aStr) michael@0: { michael@0: if (!xpcomFunctions.stringGetIsVoid) michael@0: return false; michael@0: return xpcomFunctions.stringGetIsVoid(aStr); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_CStringContainerInit(nsCStringContainer &aStr) michael@0: { michael@0: if (!xpcomFunctions.cstringContainerInit) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.cstringContainerInit(aStr); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_CStringContainerInit2(nsCStringContainer &aStr, michael@0: const char *aData, michael@0: uint32_t aDataLength, michael@0: uint32_t aFlags) michael@0: { michael@0: if (!xpcomFunctions.cstringContainerInit2) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.cstringContainerInit2(aStr, aData, aDataLength, aFlags); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_CStringContainerFinish(nsCStringContainer &aStr) michael@0: { michael@0: if (xpcomFunctions.cstringContainerFinish) michael@0: xpcomFunctions.cstringContainerFinish(aStr); michael@0: } michael@0: michael@0: XPCOM_API(uint32_t) michael@0: NS_CStringGetData(const nsACString &aStr, const char **aBuf, bool *aTerm) michael@0: { michael@0: if (!xpcomFunctions.cstringGetData) { michael@0: *aBuf = nullptr; michael@0: return 0; michael@0: } michael@0: return xpcomFunctions.cstringGetData(aStr, aBuf, aTerm); michael@0: } michael@0: michael@0: XPCOM_API(uint32_t) michael@0: NS_CStringGetMutableData(nsACString &aStr, uint32_t aLen, char **aBuf) michael@0: { michael@0: if (!xpcomFunctions.cstringGetMutableData) { michael@0: *aBuf = nullptr; michael@0: return 0; michael@0: } michael@0: return xpcomFunctions.cstringGetMutableData(aStr, aLen, aBuf); michael@0: } michael@0: michael@0: XPCOM_API(char*) michael@0: NS_CStringCloneData(const nsACString &aStr) michael@0: { michael@0: if (!xpcomFunctions.cstringCloneData) michael@0: return nullptr; michael@0: return xpcomFunctions.cstringCloneData(aStr); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_CStringSetData(nsACString &aStr, const char *aBuf, uint32_t aCount) michael@0: { michael@0: if (!xpcomFunctions.cstringSetData) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.cstringSetData(aStr, aBuf, aCount); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_CStringSetDataRange(nsACString &aStr, uint32_t aCutStart, uint32_t aCutLength, michael@0: const char *aBuf, uint32_t aCount) michael@0: { michael@0: if (!xpcomFunctions.cstringSetDataRange) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.cstringSetDataRange(aStr, aCutStart, aCutLength, aBuf, aCount); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_CStringCopy(nsACString &aDest, const nsACString &aSrc) michael@0: { michael@0: if (!xpcomFunctions.cstringCopy) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.cstringCopy(aDest, aSrc); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_CStringSetIsVoid(nsACString &aStr, const bool aIsVoid) michael@0: { michael@0: if (xpcomFunctions.cstringSetIsVoid) michael@0: xpcomFunctions.cstringSetIsVoid(aStr, aIsVoid); michael@0: } michael@0: michael@0: XPCOM_API(bool) michael@0: NS_CStringGetIsVoid(const nsACString &aStr) michael@0: { michael@0: if (!xpcomFunctions.cstringGetIsVoid) michael@0: return false; michael@0: return xpcomFunctions.cstringGetIsVoid(aStr); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_CStringToUTF16(const nsACString &aSrc, nsCStringEncoding aSrcEncoding, nsAString &aDest) michael@0: { michael@0: if (!xpcomFunctions.cstringToUTF16) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.cstringToUTF16(aSrc, aSrcEncoding, aDest); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_UTF16ToCString(const nsAString &aSrc, nsCStringEncoding aDestEncoding, nsACString &aDest) michael@0: { michael@0: if (!xpcomFunctions.utf16ToCString) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: return xpcomFunctions.utf16ToCString(aSrc, aDestEncoding, aDest); michael@0: } michael@0: michael@0: XPCOM_API(void*) michael@0: NS_Alloc(size_t size) michael@0: { michael@0: if (!xpcomFunctions.allocFunc) michael@0: return nullptr; michael@0: return xpcomFunctions.allocFunc(size); michael@0: } michael@0: michael@0: XPCOM_API(void*) michael@0: NS_Realloc(void* ptr, size_t size) michael@0: { michael@0: if (!xpcomFunctions.reallocFunc) michael@0: return nullptr; michael@0: return xpcomFunctions.reallocFunc(ptr, size); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_Free(void* ptr) michael@0: { michael@0: if (xpcomFunctions.freeFunc) michael@0: xpcomFunctions.freeFunc(ptr); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_DebugBreak(uint32_t aSeverity, const char *aStr, const char *aExpr, michael@0: const char *aFile, int32_t aLine) michael@0: { michael@0: if (xpcomFunctions.debugBreakFunc) michael@0: xpcomFunctions.debugBreakFunc(aSeverity, aStr, aExpr, aFile, aLine); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_LogInit() michael@0: { michael@0: if (xpcomFunctions.logInitFunc) michael@0: xpcomFunctions.logInitFunc(); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_LogTerm() michael@0: { michael@0: if (xpcomFunctions.logTermFunc) michael@0: xpcomFunctions.logTermFunc(); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_LogAddRef(void *aPtr, nsrefcnt aNewRefCnt, michael@0: const char *aTypeName, uint32_t aInstanceSize) michael@0: { michael@0: if (xpcomFunctions.logAddRefFunc) michael@0: xpcomFunctions.logAddRefFunc(aPtr, aNewRefCnt, michael@0: aTypeName, aInstanceSize); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_LogRelease(void *aPtr, nsrefcnt aNewRefCnt, const char *aTypeName) michael@0: { michael@0: if (xpcomFunctions.logReleaseFunc) michael@0: xpcomFunctions.logReleaseFunc(aPtr, aNewRefCnt, aTypeName); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_LogCtor(void *aPtr, const char *aTypeName, uint32_t aInstanceSize) michael@0: { michael@0: if (xpcomFunctions.logCtorFunc) michael@0: xpcomFunctions.logCtorFunc(aPtr, aTypeName, aInstanceSize); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_LogDtor(void *aPtr, const char *aTypeName, uint32_t aInstanceSize) michael@0: { michael@0: if (xpcomFunctions.logDtorFunc) michael@0: xpcomFunctions.logDtorFunc(aPtr, aTypeName, aInstanceSize); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_LogCOMPtrAddRef(void *aCOMPtr, nsISupports *aObject) michael@0: { michael@0: if (xpcomFunctions.logCOMPtrAddRefFunc) michael@0: xpcomFunctions.logCOMPtrAddRefFunc(aCOMPtr, aObject); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_LogCOMPtrRelease(void *aCOMPtr, nsISupports *aObject) michael@0: { michael@0: if (xpcomFunctions.logCOMPtrReleaseFunc) michael@0: xpcomFunctions.logCOMPtrReleaseFunc(aCOMPtr, aObject); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_GetXPTCallStub(REFNSIID aIID, nsIXPTCProxy* aOuter, michael@0: nsISomeInterface* *aStub) michael@0: { michael@0: if (!xpcomFunctions.getXPTCallStubFunc) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: michael@0: return xpcomFunctions.getXPTCallStubFunc(aIID, aOuter, aStub); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_DestroyXPTCallStub(nsISomeInterface* aStub) michael@0: { michael@0: if (xpcomFunctions.destroyXPTCallStubFunc) michael@0: xpcomFunctions.destroyXPTCallStubFunc(aStub); michael@0: } michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, michael@0: uint32_t paramCount, nsXPTCVariant* params) michael@0: { michael@0: if (!xpcomFunctions.invokeByIndexFunc) michael@0: return NS_ERROR_NOT_INITIALIZED; michael@0: michael@0: return xpcomFunctions.invokeByIndexFunc(that, methodIndex, michael@0: paramCount, params); michael@0: } michael@0: michael@0: XPCOM_API(bool) michael@0: NS_CycleCollectorSuspect(nsISupports* obj) michael@0: { michael@0: if (!xpcomFunctions.cycleSuspectFunc) michael@0: return false; michael@0: michael@0: return xpcomFunctions.cycleSuspectFunc(obj); michael@0: } michael@0: michael@0: XPCOM_API(bool) michael@0: NS_CycleCollectorForget(nsISupports* obj) michael@0: { michael@0: if (!xpcomFunctions.cycleForgetFunc) michael@0: return false; michael@0: michael@0: return xpcomFunctions.cycleForgetFunc(obj); michael@0: } michael@0: michael@0: XPCOM_API(nsPurpleBufferEntry*) michael@0: NS_CycleCollectorSuspect2(void* obj, nsCycleCollectionParticipant *p) michael@0: { michael@0: if (!xpcomFunctions.cycleSuspect2Func) michael@0: return nullptr; michael@0: michael@0: return xpcomFunctions.cycleSuspect2Func(obj, p); michael@0: } michael@0: michael@0: XPCOM_API(void) michael@0: NS_CycleCollectorSuspect3(void* obj, nsCycleCollectionParticipant *p, michael@0: nsCycleCollectingAutoRefCnt* aRefCnt, michael@0: bool* aShouldDelete) michael@0: { michael@0: if (xpcomFunctions.cycleSuspect3Func) michael@0: xpcomFunctions.cycleSuspect3Func(obj, p, aRefCnt, aShouldDelete); michael@0: } michael@0: michael@0: XPCOM_API(bool) michael@0: NS_CycleCollectorForget2(nsPurpleBufferEntry* e) michael@0: { michael@0: if (!xpcomFunctions.cycleForget2Func) michael@0: return false; michael@0: michael@0: return xpcomFunctions.cycleForget2Func(e); michael@0: }