xpcom/glue/standalone/nsXPCOMGlue.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/glue/standalone/nsXPCOMGlue.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,928 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* vim:set ts=4 sw=4 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "nsXPCOMGlue.h"
    1.11 +
    1.12 +#include "nspr.h"
    1.13 +#include "nsDebug.h"
    1.14 +#include "nsIServiceManager.h"
    1.15 +#include "nsXPCOMPrivate.h"
    1.16 +#include "nsCOMPtr.h"
    1.17 +#include <stdlib.h>
    1.18 +#include <stdio.h>
    1.19 +
    1.20 +#include "mozilla/FileUtils.h"
    1.21 +
    1.22 +using namespace mozilla;
    1.23 +
    1.24 +#define XPCOM_DEPENDENT_LIBS_LIST "dependentlibs.list"
    1.25 +
    1.26 +static XPCOMFunctions xpcomFunctions;
    1.27 +static bool do_preload = false;
    1.28 +
    1.29 +#if defined(XP_WIN)
    1.30 +#define READ_TEXTMODE L"rt"
    1.31 +#else
    1.32 +#define READ_TEXTMODE "r"
    1.33 +#endif
    1.34 +
    1.35 +#if defined(SUNOS4) || defined(NEXTSTEP) || \
    1.36 +    defined(XP_DARWIN) || \
    1.37 +    (defined(OPENBSD) || defined(NETBSD)) && !defined(__ELF__)
    1.38 +#define LEADING_UNDERSCORE "_"
    1.39 +#else
    1.40 +#define LEADING_UNDERSCORE
    1.41 +#endif
    1.42 +
    1.43 +#if defined(XP_WIN)
    1.44 +#include <windows.h>
    1.45 +#include <mbstring.h>
    1.46 +#define snprintf _snprintf
    1.47 +
    1.48 +typedef HINSTANCE LibHandleType;
    1.49 +
    1.50 +static LibHandleType
    1.51 +GetLibHandle(pathstr_t aDependentLib)
    1.52 +{
    1.53 +    LibHandleType libHandle =
    1.54 +        LoadLibraryExW(aDependentLib, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);
    1.55 +
    1.56 +    if (!libHandle) {
    1.57 +        DWORD err = GetLastError();
    1.58 +#ifdef DEBUG
    1.59 +        LPVOID lpMsgBuf;
    1.60 +        FormatMessage(
    1.61 +                      FORMAT_MESSAGE_ALLOCATE_BUFFER |
    1.62 +                      FORMAT_MESSAGE_FROM_SYSTEM |
    1.63 +                      FORMAT_MESSAGE_IGNORE_INSERTS,
    1.64 +                      nullptr,
    1.65 +                      err,
    1.66 +                      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    1.67 +                      (LPTSTR) &lpMsgBuf,
    1.68 +                      0,
    1.69 +                      nullptr
    1.70 +                      );
    1.71 +        wprintf(L"Error loading %ls: %s\n", aDependentLib, lpMsgBuf);
    1.72 +        LocalFree(lpMsgBuf);
    1.73 +#endif
    1.74 +    }
    1.75 +
    1.76 +    return libHandle;
    1.77 +}
    1.78 +
    1.79 +static NSFuncPtr
    1.80 +GetSymbol(LibHandleType aLibHandle, const char *aSymbol)
    1.81 +{
    1.82 +    return (NSFuncPtr) GetProcAddress(aLibHandle, aSymbol);
    1.83 +}
    1.84 +
    1.85 +static void
    1.86 +CloseLibHandle(LibHandleType aLibHandle)
    1.87 +{
    1.88 +    FreeLibrary(aLibHandle);
    1.89 +}
    1.90 +
    1.91 +#elif defined(XP_MACOSX)
    1.92 +#include <mach-o/dyld.h>
    1.93 +
    1.94 +typedef const mach_header *LibHandleType;
    1.95 +
    1.96 +static LibHandleType
    1.97 +GetLibHandle(pathstr_t aDependentLib)
    1.98 +{
    1.99 +    LibHandleType libHandle = NSAddImage(aDependentLib,
   1.100 +                                         NSADDIMAGE_OPTION_RETURN_ON_ERROR |
   1.101 +                                         NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME);
   1.102 +    if (!libHandle) {
   1.103 +        NSLinkEditErrors linkEditError;
   1.104 +        int errorNum;
   1.105 +        const char *errorString;
   1.106 +        const char *fileName;
   1.107 +        NSLinkEditError(&linkEditError, &errorNum, &fileName, &errorString);
   1.108 +        fprintf(stderr, "XPCOMGlueLoad error %d:%d for file %s:\n%s\n",
   1.109 +                linkEditError, errorNum, fileName, errorString);
   1.110 +    }
   1.111 +    return libHandle;
   1.112 +}
   1.113 +
   1.114 +static NSFuncPtr
   1.115 +GetSymbol(LibHandleType aLibHandle, const char *aSymbol)
   1.116 +{
   1.117 +    // Try to use |NSLookupSymbolInImage| since it is faster than searching
   1.118 +    // the global symbol table.  If we couldn't get a mach_header pointer
   1.119 +    // for the XPCOM dylib, then use |NSLookupAndBindSymbol| to search the
   1.120 +    // global symbol table (this shouldn't normally happen, unless the user
   1.121 +    // has called XPCOMGlueStartup(".") and relies on libxpcom.dylib
   1.122 +    // already being loaded).
   1.123 +    NSSymbol sym = nullptr;
   1.124 +    if (aLibHandle) {
   1.125 +        sym = NSLookupSymbolInImage(aLibHandle, aSymbol,
   1.126 +                                 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
   1.127 +                                 NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
   1.128 +    } else {
   1.129 +        if (NSIsSymbolNameDefined(aSymbol))
   1.130 +            sym = NSLookupAndBindSymbol(aSymbol);
   1.131 +    }
   1.132 +    if (!sym)
   1.133 +        return nullptr;
   1.134 +
   1.135 +    return (NSFuncPtr) NSAddressOfSymbol(sym);
   1.136 +}
   1.137 +
   1.138 +static void
   1.139 +CloseLibHandle(LibHandleType aLibHandle)
   1.140 +{
   1.141 +    // we cannot unload dylibs on OS X
   1.142 +}
   1.143 +
   1.144 +#else
   1.145 +#include <dlfcn.h>
   1.146 +
   1.147 +#if defined(MOZ_LINKER) && !defined(ANDROID)
   1.148 +extern "C" {
   1.149 +NS_HIDDEN __typeof(dlopen) __wrap_dlopen;
   1.150 +NS_HIDDEN __typeof(dlsym) __wrap_dlsym;
   1.151 +NS_HIDDEN __typeof(dlclose) __wrap_dlclose;
   1.152 +}
   1.153 +
   1.154 +#define dlopen __wrap_dlopen
   1.155 +#define dlsym __wrap_dlsym
   1.156 +#define dlclose __wrap_dlclose
   1.157 +#endif
   1.158 +
   1.159 +#ifdef NS_TRACE_MALLOC
   1.160 +extern "C" {
   1.161 +NS_EXPORT_(__ptr_t) __libc_malloc(size_t);
   1.162 +NS_EXPORT_(__ptr_t) __libc_calloc(size_t, size_t);
   1.163 +NS_EXPORT_(__ptr_t) __libc_realloc(__ptr_t, size_t);
   1.164 +NS_EXPORT_(void)    __libc_free(__ptr_t);
   1.165 +NS_EXPORT_(__ptr_t) __libc_memalign(size_t, size_t);
   1.166 +NS_EXPORT_(__ptr_t) __libc_valloc(size_t);
   1.167 +}
   1.168 +
   1.169 +static __ptr_t (*_malloc)(size_t) = __libc_malloc;
   1.170 +static __ptr_t (*_calloc)(size_t, size_t) = __libc_calloc;
   1.171 +static __ptr_t (*_realloc)(__ptr_t, size_t) = __libc_realloc;
   1.172 +static void (*_free)(__ptr_t) = __libc_free;
   1.173 +static __ptr_t (*_memalign)(size_t, size_t) = __libc_memalign;
   1.174 +static __ptr_t (*_valloc)(size_t) = __libc_valloc;
   1.175 +
   1.176 +NS_EXPORT_(__ptr_t) malloc(size_t size)
   1.177 +{
   1.178 +    return _malloc(size);
   1.179 +}
   1.180 +
   1.181 +NS_EXPORT_(__ptr_t) calloc(size_t nmemb, size_t size)
   1.182 +{
   1.183 +    return _calloc(nmemb, size);
   1.184 +}
   1.185 +
   1.186 +NS_EXPORT_(__ptr_t) realloc(__ptr_t ptr, size_t size)
   1.187 +{
   1.188 +    return _realloc(ptr, size);
   1.189 +}
   1.190 +
   1.191 +NS_EXPORT_(void) free(__ptr_t ptr)
   1.192 +{
   1.193 +    _free(ptr);
   1.194 +}
   1.195 +
   1.196 +NS_EXPORT_(void) cfree(__ptr_t ptr)
   1.197 +{
   1.198 +    _free(ptr);
   1.199 +}
   1.200 +
   1.201 +NS_EXPORT_(__ptr_t) memalign(size_t boundary, size_t size)
   1.202 +{
   1.203 +    return _memalign(boundary, size);
   1.204 +}
   1.205 +
   1.206 +NS_EXPORT_(int)
   1.207 +posix_memalign(void **memptr, size_t alignment, size_t size)
   1.208 +{
   1.209 +    __ptr_t ptr = _memalign(alignment, size);
   1.210 +    if (!ptr)
   1.211 +        return ENOMEM;
   1.212 +    *memptr = ptr;
   1.213 +    return 0;
   1.214 +}
   1.215 +
   1.216 +NS_EXPORT_(__ptr_t) valloc(size_t size)
   1.217 +{
   1.218 +    return _valloc(size);
   1.219 +}
   1.220 +#endif /* NS_TRACE_MALLOC */
   1.221 +
   1.222 +typedef void *LibHandleType;
   1.223 +
   1.224 +static LibHandleType
   1.225 +GetLibHandle(pathstr_t aDependentLib)
   1.226 +{
   1.227 +    LibHandleType libHandle = dlopen(aDependentLib, RTLD_GLOBAL | RTLD_LAZY);
   1.228 +    if (!libHandle) {
   1.229 +        fprintf(stderr, "XPCOMGlueLoad error for file %s:\n%s\n", aDependentLib, dlerror());
   1.230 +    }
   1.231 +    return libHandle;
   1.232 +}
   1.233 +
   1.234 +static NSFuncPtr
   1.235 +GetSymbol(LibHandleType aLibHandle, const char *aSymbol)
   1.236 +{
   1.237 +    return (NSFuncPtr) dlsym(aLibHandle, aSymbol);
   1.238 +}
   1.239 +
   1.240 +static void
   1.241 +CloseLibHandle(LibHandleType aLibHandle)
   1.242 +{
   1.243 +    dlclose(aLibHandle);
   1.244 +}
   1.245 +#endif
   1.246 +
   1.247 +struct DependentLib
   1.248 +{
   1.249 +    LibHandleType libHandle;
   1.250 +    DependentLib *next;
   1.251 +};
   1.252 +
   1.253 +static DependentLib *sTop;
   1.254 +
   1.255 +static void
   1.256 +AppendDependentLib(LibHandleType libHandle)
   1.257 +{
   1.258 +    DependentLib *d = new DependentLib;
   1.259 +    if (!d)
   1.260 +        return;
   1.261 +
   1.262 +    d->next = sTop;
   1.263 +    d->libHandle = libHandle;
   1.264 +
   1.265 +    sTop = d;
   1.266 +}
   1.267 +
   1.268 +static bool
   1.269 +ReadDependentCB(pathstr_t aDependentLib, bool do_preload)
   1.270 +{
   1.271 +    if (do_preload) {
   1.272 +        ReadAheadLib(aDependentLib);
   1.273 +    }
   1.274 +    LibHandleType libHandle = GetLibHandle(aDependentLib);
   1.275 +    if (libHandle) {
   1.276 +        AppendDependentLib(libHandle);
   1.277 +    }
   1.278 +
   1.279 +    return libHandle;
   1.280 +}
   1.281 +
   1.282 +#ifdef XP_WIN
   1.283 +static bool
   1.284 +ReadDependentCB(const char *aDependentLib, bool do_preload)
   1.285 +{
   1.286 +    wchar_t wideDependentLib[MAX_PATH];
   1.287 +    MultiByteToWideChar(CP_UTF8, 0, aDependentLib, -1, wideDependentLib, MAX_PATH);
   1.288 +    return ReadDependentCB(wideDependentLib, do_preload);
   1.289 +}
   1.290 +
   1.291 +inline FILE *TS_tfopen (const char *path, const wchar_t *mode)
   1.292 +{
   1.293 +    wchar_t wPath[MAX_PATH];
   1.294 +    MultiByteToWideChar(CP_UTF8, 0, path, -1, wPath, MAX_PATH);
   1.295 +    return _wfopen(wPath, mode);
   1.296 +}
   1.297 +#else
   1.298 +inline FILE *TS_tfopen (const char *path, const char *mode)
   1.299 +{
   1.300 +    return fopen(path, mode);
   1.301 +}
   1.302 +#endif
   1.303 +
   1.304 +/* RAII wrapper for FILE descriptors */
   1.305 +struct ScopedCloseFileTraits
   1.306 +{
   1.307 +    typedef FILE *type;
   1.308 +    static type empty() { return nullptr; }
   1.309 +    static void release(type f) {
   1.310 +        if (f) {
   1.311 +            fclose(f);
   1.312 +        }
   1.313 +    }
   1.314 +};
   1.315 +typedef Scoped<ScopedCloseFileTraits> ScopedCloseFile;
   1.316 +
   1.317 +static void
   1.318 +XPCOMGlueUnload()
   1.319 +{
   1.320 +#if !defined(XP_WIN) && !defined(XP_MACOSX) && defined(NS_TRACE_MALLOC)
   1.321 +    if (sTop) {
   1.322 +        _malloc = __libc_malloc;
   1.323 +        _calloc = __libc_calloc;
   1.324 +        _realloc = __libc_realloc;
   1.325 +        _free = __libc_free;
   1.326 +        _memalign = __libc_memalign;
   1.327 +        _valloc = __libc_valloc;
   1.328 +    }
   1.329 +#endif
   1.330 +
   1.331 +    while (sTop) {
   1.332 +        CloseLibHandle(sTop->libHandle);
   1.333 +
   1.334 +        DependentLib *temp = sTop;
   1.335 +        sTop = sTop->next;
   1.336 +
   1.337 +        delete temp;
   1.338 +    }
   1.339 +}
   1.340 +
   1.341 +#if defined(XP_WIN)
   1.342 +// like strpbrk but finds the *last* char, not the first
   1.343 +static const char*
   1.344 +ns_strrpbrk(const char *string, const char *strCharSet)
   1.345 +{
   1.346 +    const char *found = nullptr;
   1.347 +    for (; *string; ++string) {
   1.348 +        for (const char *search = strCharSet; *search; ++search) {
   1.349 +            if (*search == *string) {
   1.350 +                found = string;
   1.351 +                // Since we're looking for the last char, we save "found"
   1.352 +                // until we're at the end of the string.
   1.353 +            }
   1.354 +        }
   1.355 +    }
   1.356 +
   1.357 +    return found;
   1.358 +}
   1.359 +#endif
   1.360 +
   1.361 +static GetFrozenFunctionsFunc
   1.362 +XPCOMGlueLoad(const char *xpcomFile)
   1.363 +{
   1.364 +    char xpcomDir[MAXPATHLEN];
   1.365 +#if defined(XP_WIN)
   1.366 +    const char *lastSlash = ns_strrpbrk(xpcomFile, "/\\");
   1.367 +#else
   1.368 +    const char *lastSlash = strrchr(xpcomFile, '/');
   1.369 +#endif
   1.370 +    char *cursor;
   1.371 +    if (lastSlash) {
   1.372 +        size_t len = size_t(lastSlash - xpcomFile);
   1.373 +
   1.374 +        if (len > MAXPATHLEN - sizeof(XPCOM_FILE_PATH_SEPARATOR
   1.375 +                                      XPCOM_DEPENDENT_LIBS_LIST)) {
   1.376 +            return nullptr;
   1.377 +        }
   1.378 +        memcpy(xpcomDir, xpcomFile, len);
   1.379 +        strcpy(xpcomDir + len, XPCOM_FILE_PATH_SEPARATOR
   1.380 +                               XPCOM_DEPENDENT_LIBS_LIST);
   1.381 +        cursor = xpcomDir + len + 1;
   1.382 +    } else {
   1.383 +        strcpy(xpcomDir, XPCOM_DEPENDENT_LIBS_LIST);
   1.384 +        cursor = xpcomDir;
   1.385 +    }
   1.386 +
   1.387 +    if (getenv("MOZ_RUN_GTEST")) {
   1.388 +        strcat(xpcomDir, ".gtest");
   1.389 +    }
   1.390 +
   1.391 +    ScopedCloseFile flist;
   1.392 +    flist = TS_tfopen(xpcomDir, READ_TEXTMODE);
   1.393 +    if (!flist) {
   1.394 +        return nullptr;
   1.395 +    }
   1.396 +
   1.397 +    *cursor = '\0';
   1.398 +
   1.399 +    char buffer[MAXPATHLEN];
   1.400 +
   1.401 +    while (fgets(buffer, sizeof(buffer), flist)) {
   1.402 +        int l = strlen(buffer);
   1.403 +
   1.404 +        // ignore empty lines and comments
   1.405 +        if (l == 0 || *buffer == '#') {
   1.406 +            continue;
   1.407 +        }
   1.408 +
   1.409 +        // cut the trailing newline, if present
   1.410 +        if (buffer[l - 1] == '\n')
   1.411 +            buffer[l - 1] = '\0';
   1.412 +
   1.413 +        if (l + size_t(cursor - xpcomDir) > MAXPATHLEN) {
   1.414 +            return nullptr;
   1.415 +        }
   1.416 +
   1.417 +        strcpy(cursor, buffer);
   1.418 +        if (!ReadDependentCB(xpcomDir, do_preload)) {
   1.419 +            XPCOMGlueUnload();
   1.420 +            return nullptr;
   1.421 +        }
   1.422 +    }
   1.423 +
   1.424 +    GetFrozenFunctionsFunc sym =
   1.425 +        (GetFrozenFunctionsFunc) GetSymbol(sTop->libHandle, LEADING_UNDERSCORE "NS_GetFrozenFunctions");
   1.426 +
   1.427 +    if (!sym) { // No symbol found.
   1.428 +        XPCOMGlueUnload();
   1.429 +        return nullptr;
   1.430 +    }
   1.431 +
   1.432 +#if !defined(XP_WIN) && !defined(XP_MACOSX) && defined(NS_TRACE_MALLOC)
   1.433 +    _malloc = (__ptr_t(*)(size_t)) GetSymbol(sTop->libHandle, "malloc");
   1.434 +    _calloc = (__ptr_t(*)(size_t, size_t)) GetSymbol(sTop->libHandle, "calloc");
   1.435 +    _realloc = (__ptr_t(*)(__ptr_t, size_t)) GetSymbol(sTop->libHandle, "realloc");
   1.436 +    _free = (void(*)(__ptr_t)) GetSymbol(sTop->libHandle, "free");
   1.437 +    _memalign = (__ptr_t(*)(size_t, size_t)) GetSymbol(sTop->libHandle, "memalign");
   1.438 +    _valloc = (__ptr_t(*)(size_t)) GetSymbol(sTop->libHandle, "valloc");
   1.439 +#endif
   1.440 +
   1.441 +    return sym;
   1.442 +}
   1.443 +
   1.444 +nsresult
   1.445 +XPCOMGlueLoadXULFunctions(const nsDynamicFunctionLoad *symbols)
   1.446 +{
   1.447 +    // We don't null-check sXULLibHandle because this might work even
   1.448 +    // if it is null (same as RTLD_DEFAULT)
   1.449 +
   1.450 +    nsresult rv = NS_OK;
   1.451 +    while (symbols->functionName) {
   1.452 +        char buffer[512];
   1.453 +        snprintf(buffer, sizeof(buffer),
   1.454 +                 LEADING_UNDERSCORE "%s", symbols->functionName);
   1.455 +
   1.456 +        *symbols->function = (NSFuncPtr) GetSymbol(sTop->libHandle, buffer);
   1.457 +        if (!*symbols->function)
   1.458 +            rv = NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
   1.459 +
   1.460 +        ++symbols;
   1.461 +    }
   1.462 +    return rv;
   1.463 +}
   1.464 +
   1.465 +void XPCOMGlueEnablePreload()
   1.466 +{
   1.467 +    do_preload = true;
   1.468 +}
   1.469 +
   1.470 +nsresult XPCOMGlueStartup(const char* xpcomFile)
   1.471 +{
   1.472 +    xpcomFunctions.version = XPCOM_GLUE_VERSION;
   1.473 +    xpcomFunctions.size    = sizeof(XPCOMFunctions);
   1.474 +
   1.475 +    if (!xpcomFile)
   1.476 +        xpcomFile = XPCOM_DLL;
   1.477 +
   1.478 +    GetFrozenFunctionsFunc func = XPCOMGlueLoad(xpcomFile);
   1.479 +    if (!func)
   1.480 +        return NS_ERROR_NOT_AVAILABLE;
   1.481 +
   1.482 +    nsresult rv = (*func)(&xpcomFunctions, nullptr);
   1.483 +    if (NS_FAILED(rv)) {
   1.484 +        XPCOMGlueUnload();
   1.485 +        return rv;
   1.486 +    }
   1.487 +
   1.488 +    return NS_OK;
   1.489 +}
   1.490 +
   1.491 +XPCOM_API(nsresult)
   1.492 +NS_InitXPCOM2(nsIServiceManager* *result, 
   1.493 +              nsIFile* binDirectory,
   1.494 +              nsIDirectoryServiceProvider* appFileLocationProvider)
   1.495 +{
   1.496 +    if (!xpcomFunctions.init)
   1.497 +        return NS_ERROR_NOT_INITIALIZED;
   1.498 +    return xpcomFunctions.init(result, binDirectory, appFileLocationProvider);
   1.499 +}
   1.500 +
   1.501 +XPCOM_API(nsresult)
   1.502 +NS_ShutdownXPCOM(nsIServiceManager* servMgr)
   1.503 +{
   1.504 +    if (!xpcomFunctions.shutdown)
   1.505 +        return NS_ERROR_NOT_INITIALIZED;
   1.506 +    return xpcomFunctions.shutdown(servMgr);
   1.507 +}
   1.508 +
   1.509 +XPCOM_API(nsresult)
   1.510 +NS_GetServiceManager(nsIServiceManager* *result)
   1.511 +{
   1.512 +    if (!xpcomFunctions.getServiceManager)
   1.513 +        return NS_ERROR_NOT_INITIALIZED;
   1.514 +    return xpcomFunctions.getServiceManager(result);
   1.515 +}
   1.516 +
   1.517 +XPCOM_API(nsresult)
   1.518 +NS_GetComponentManager(nsIComponentManager* *result)
   1.519 +{
   1.520 +    if (!xpcomFunctions.getComponentManager)
   1.521 +        return NS_ERROR_NOT_INITIALIZED;
   1.522 +    return xpcomFunctions.getComponentManager(result);
   1.523 +}
   1.524 +
   1.525 +XPCOM_API(nsresult)
   1.526 +NS_GetComponentRegistrar(nsIComponentRegistrar* *result)
   1.527 +{
   1.528 +    if (!xpcomFunctions.getComponentRegistrar)
   1.529 +        return NS_ERROR_NOT_INITIALIZED;
   1.530 +    return xpcomFunctions.getComponentRegistrar(result);
   1.531 +}
   1.532 +
   1.533 +XPCOM_API(nsresult)
   1.534 +NS_GetMemoryManager(nsIMemory* *result)
   1.535 +{
   1.536 +    if (!xpcomFunctions.getMemoryManager)
   1.537 +        return NS_ERROR_NOT_INITIALIZED;
   1.538 +    return xpcomFunctions.getMemoryManager(result);
   1.539 +}
   1.540 +
   1.541 +XPCOM_API(nsresult)
   1.542 +NS_NewLocalFile(const nsAString &path, bool followLinks, nsIFile* *result)
   1.543 +{
   1.544 +    if (!xpcomFunctions.newLocalFile)
   1.545 +        return NS_ERROR_NOT_INITIALIZED;
   1.546 +    return xpcomFunctions.newLocalFile(path, followLinks, result);
   1.547 +}
   1.548 +
   1.549 +XPCOM_API(nsresult)
   1.550 +NS_NewNativeLocalFile(const nsACString &path, bool followLinks, nsIFile* *result)
   1.551 +{
   1.552 +    if (!xpcomFunctions.newNativeLocalFile)
   1.553 +        return NS_ERROR_NOT_INITIALIZED;
   1.554 +    return xpcomFunctions.newNativeLocalFile(path, followLinks, result);
   1.555 +}
   1.556 +
   1.557 +XPCOM_API(nsresult)
   1.558 +NS_GetDebug(nsIDebug* *result)
   1.559 +{
   1.560 +    if (!xpcomFunctions.getDebug)
   1.561 +        return NS_ERROR_NOT_INITIALIZED;
   1.562 +    return xpcomFunctions.getDebug(result);
   1.563 +}
   1.564 +
   1.565 +
   1.566 +XPCOM_API(nsresult)
   1.567 +NS_StringContainerInit(nsStringContainer &aStr)
   1.568 +{
   1.569 +    if (!xpcomFunctions.stringContainerInit)
   1.570 +        return NS_ERROR_NOT_INITIALIZED;
   1.571 +    return xpcomFunctions.stringContainerInit(aStr);
   1.572 +}
   1.573 +
   1.574 +XPCOM_API(nsresult)
   1.575 +NS_StringContainerInit2(nsStringContainer &aStr,
   1.576 +                        const char16_t   *aData,
   1.577 +                        uint32_t           aDataLength,
   1.578 +                        uint32_t           aFlags)
   1.579 +{
   1.580 +    if (!xpcomFunctions.stringContainerInit2)
   1.581 +        return NS_ERROR_NOT_INITIALIZED;
   1.582 +    return xpcomFunctions.stringContainerInit2(aStr, aData, aDataLength, aFlags);
   1.583 +}
   1.584 +
   1.585 +XPCOM_API(void)
   1.586 +NS_StringContainerFinish(nsStringContainer &aStr)
   1.587 +{
   1.588 +    if (xpcomFunctions.stringContainerFinish)
   1.589 +        xpcomFunctions.stringContainerFinish(aStr);
   1.590 +}
   1.591 +
   1.592 +XPCOM_API(uint32_t)
   1.593 +NS_StringGetData(const nsAString &aStr, const char16_t **aBuf, bool *aTerm)
   1.594 +{
   1.595 +    if (!xpcomFunctions.stringGetData) {
   1.596 +        *aBuf = nullptr;
   1.597 +        return 0;
   1.598 +    }
   1.599 +    return xpcomFunctions.stringGetData(aStr, aBuf, aTerm);
   1.600 +}
   1.601 +
   1.602 +XPCOM_API(uint32_t)
   1.603 +NS_StringGetMutableData(nsAString &aStr, uint32_t aLen, char16_t **aBuf)
   1.604 +{
   1.605 +    if (!xpcomFunctions.stringGetMutableData) {
   1.606 +        *aBuf = nullptr;
   1.607 +        return 0;
   1.608 +    }
   1.609 +    return xpcomFunctions.stringGetMutableData(aStr, aLen, aBuf);
   1.610 +}
   1.611 +
   1.612 +XPCOM_API(char16_t*)
   1.613 +NS_StringCloneData(const nsAString &aStr)
   1.614 +{
   1.615 +    if (!xpcomFunctions.stringCloneData)
   1.616 +        return nullptr;
   1.617 +    return xpcomFunctions.stringCloneData(aStr);
   1.618 +}
   1.619 +
   1.620 +XPCOM_API(nsresult)
   1.621 +NS_StringSetData(nsAString &aStr, const char16_t *aBuf, uint32_t aCount)
   1.622 +{
   1.623 +    if (!xpcomFunctions.stringSetData)
   1.624 +        return NS_ERROR_NOT_INITIALIZED;
   1.625 +
   1.626 +    return xpcomFunctions.stringSetData(aStr, aBuf, aCount);
   1.627 +}
   1.628 +
   1.629 +XPCOM_API(nsresult)
   1.630 +NS_StringSetDataRange(nsAString &aStr, uint32_t aCutStart, uint32_t aCutLength,
   1.631 +                      const char16_t *aBuf, uint32_t aCount)
   1.632 +{
   1.633 +    if (!xpcomFunctions.stringSetDataRange)
   1.634 +        return NS_ERROR_NOT_INITIALIZED;
   1.635 +    return xpcomFunctions.stringSetDataRange(aStr, aCutStart, aCutLength, aBuf, aCount);
   1.636 +}
   1.637 +
   1.638 +XPCOM_API(nsresult)
   1.639 +NS_StringCopy(nsAString &aDest, const nsAString &aSrc)
   1.640 +{
   1.641 +    if (!xpcomFunctions.stringCopy)
   1.642 +        return NS_ERROR_NOT_INITIALIZED;
   1.643 +    return xpcomFunctions.stringCopy(aDest, aSrc);
   1.644 +}
   1.645 +
   1.646 +XPCOM_API(void)
   1.647 +NS_StringSetIsVoid(nsAString &aStr, const bool aIsVoid)
   1.648 +{
   1.649 +    if (xpcomFunctions.stringSetIsVoid)
   1.650 +        xpcomFunctions.stringSetIsVoid(aStr, aIsVoid);
   1.651 +}
   1.652 +
   1.653 +XPCOM_API(bool)
   1.654 +NS_StringGetIsVoid(const nsAString &aStr)
   1.655 +{
   1.656 +    if (!xpcomFunctions.stringGetIsVoid)
   1.657 +        return false;
   1.658 +    return xpcomFunctions.stringGetIsVoid(aStr);
   1.659 +}
   1.660 +
   1.661 +XPCOM_API(nsresult)
   1.662 +NS_CStringContainerInit(nsCStringContainer &aStr)
   1.663 +{
   1.664 +    if (!xpcomFunctions.cstringContainerInit)
   1.665 +        return NS_ERROR_NOT_INITIALIZED;
   1.666 +    return xpcomFunctions.cstringContainerInit(aStr);
   1.667 +}
   1.668 +
   1.669 +XPCOM_API(nsresult)
   1.670 +NS_CStringContainerInit2(nsCStringContainer &aStr,
   1.671 +                         const char         *aData,
   1.672 +                         uint32_t           aDataLength,
   1.673 +                         uint32_t           aFlags)
   1.674 +{
   1.675 +    if (!xpcomFunctions.cstringContainerInit2)
   1.676 +        return NS_ERROR_NOT_INITIALIZED;
   1.677 +    return xpcomFunctions.cstringContainerInit2(aStr, aData, aDataLength, aFlags);
   1.678 +}
   1.679 +
   1.680 +XPCOM_API(void)
   1.681 +NS_CStringContainerFinish(nsCStringContainer &aStr)
   1.682 +{
   1.683 +    if (xpcomFunctions.cstringContainerFinish)
   1.684 +        xpcomFunctions.cstringContainerFinish(aStr);
   1.685 +}
   1.686 +
   1.687 +XPCOM_API(uint32_t)
   1.688 +NS_CStringGetData(const nsACString &aStr, const char **aBuf, bool *aTerm)
   1.689 +{
   1.690 +    if (!xpcomFunctions.cstringGetData) {
   1.691 +        *aBuf = nullptr;
   1.692 +        return 0;
   1.693 +    }
   1.694 +    return xpcomFunctions.cstringGetData(aStr, aBuf, aTerm);
   1.695 +}
   1.696 +
   1.697 +XPCOM_API(uint32_t)
   1.698 +NS_CStringGetMutableData(nsACString &aStr, uint32_t aLen, char **aBuf)
   1.699 +{
   1.700 +    if (!xpcomFunctions.cstringGetMutableData) {
   1.701 +        *aBuf = nullptr;
   1.702 +        return 0;
   1.703 +    }
   1.704 +    return xpcomFunctions.cstringGetMutableData(aStr, aLen, aBuf);
   1.705 +}
   1.706 +
   1.707 +XPCOM_API(char*)
   1.708 +NS_CStringCloneData(const nsACString &aStr)
   1.709 +{
   1.710 +    if (!xpcomFunctions.cstringCloneData)
   1.711 +        return nullptr;
   1.712 +    return xpcomFunctions.cstringCloneData(aStr);
   1.713 +}
   1.714 +
   1.715 +XPCOM_API(nsresult)
   1.716 +NS_CStringSetData(nsACString &aStr, const char *aBuf, uint32_t aCount)
   1.717 +{
   1.718 +    if (!xpcomFunctions.cstringSetData)
   1.719 +        return NS_ERROR_NOT_INITIALIZED;
   1.720 +    return xpcomFunctions.cstringSetData(aStr, aBuf, aCount);
   1.721 +}
   1.722 +
   1.723 +XPCOM_API(nsresult)
   1.724 +NS_CStringSetDataRange(nsACString &aStr, uint32_t aCutStart, uint32_t aCutLength,
   1.725 +                       const char *aBuf, uint32_t aCount)
   1.726 +{
   1.727 +    if (!xpcomFunctions.cstringSetDataRange)
   1.728 +        return NS_ERROR_NOT_INITIALIZED;
   1.729 +    return xpcomFunctions.cstringSetDataRange(aStr, aCutStart, aCutLength, aBuf, aCount);
   1.730 +}
   1.731 +
   1.732 +XPCOM_API(nsresult)
   1.733 +NS_CStringCopy(nsACString &aDest, const nsACString &aSrc)
   1.734 +{
   1.735 +    if (!xpcomFunctions.cstringCopy)
   1.736 +        return NS_ERROR_NOT_INITIALIZED;
   1.737 +    return xpcomFunctions.cstringCopy(aDest, aSrc);
   1.738 +}
   1.739 +
   1.740 +XPCOM_API(void)
   1.741 +NS_CStringSetIsVoid(nsACString &aStr, const bool aIsVoid)
   1.742 +{
   1.743 +    if (xpcomFunctions.cstringSetIsVoid)
   1.744 +        xpcomFunctions.cstringSetIsVoid(aStr, aIsVoid);
   1.745 +}
   1.746 +
   1.747 +XPCOM_API(bool)
   1.748 +NS_CStringGetIsVoid(const nsACString &aStr)
   1.749 +{
   1.750 +    if (!xpcomFunctions.cstringGetIsVoid)
   1.751 +        return false;
   1.752 +    return xpcomFunctions.cstringGetIsVoid(aStr);
   1.753 +}
   1.754 +
   1.755 +XPCOM_API(nsresult)
   1.756 +NS_CStringToUTF16(const nsACString &aSrc, nsCStringEncoding aSrcEncoding, nsAString &aDest)
   1.757 +{
   1.758 +    if (!xpcomFunctions.cstringToUTF16)
   1.759 +        return NS_ERROR_NOT_INITIALIZED;
   1.760 +    return xpcomFunctions.cstringToUTF16(aSrc, aSrcEncoding, aDest);
   1.761 +}
   1.762 +
   1.763 +XPCOM_API(nsresult)
   1.764 +NS_UTF16ToCString(const nsAString &aSrc, nsCStringEncoding aDestEncoding, nsACString &aDest)
   1.765 +{
   1.766 +    if (!xpcomFunctions.utf16ToCString)
   1.767 +        return NS_ERROR_NOT_INITIALIZED;
   1.768 +    return xpcomFunctions.utf16ToCString(aSrc, aDestEncoding, aDest);
   1.769 +}
   1.770 +
   1.771 +XPCOM_API(void*)
   1.772 +NS_Alloc(size_t size)
   1.773 +{
   1.774 +    if (!xpcomFunctions.allocFunc)
   1.775 +        return nullptr;
   1.776 +    return xpcomFunctions.allocFunc(size);
   1.777 +}
   1.778 +
   1.779 +XPCOM_API(void*)
   1.780 +NS_Realloc(void* ptr, size_t size)
   1.781 +{
   1.782 +    if (!xpcomFunctions.reallocFunc)
   1.783 +        return nullptr;
   1.784 +    return xpcomFunctions.reallocFunc(ptr, size);
   1.785 +}
   1.786 +
   1.787 +XPCOM_API(void)
   1.788 +NS_Free(void* ptr)
   1.789 +{
   1.790 +    if (xpcomFunctions.freeFunc)
   1.791 +        xpcomFunctions.freeFunc(ptr);
   1.792 +}
   1.793 +
   1.794 +XPCOM_API(void)
   1.795 +NS_DebugBreak(uint32_t aSeverity, const char *aStr, const char *aExpr,
   1.796 +              const char *aFile, int32_t aLine)
   1.797 +{
   1.798 +    if (xpcomFunctions.debugBreakFunc)
   1.799 +        xpcomFunctions.debugBreakFunc(aSeverity, aStr, aExpr, aFile, aLine);
   1.800 +}
   1.801 +
   1.802 +XPCOM_API(void)
   1.803 +NS_LogInit()
   1.804 +{
   1.805 +    if (xpcomFunctions.logInitFunc)
   1.806 +        xpcomFunctions.logInitFunc();
   1.807 +}
   1.808 +
   1.809 +XPCOM_API(void)
   1.810 +NS_LogTerm()
   1.811 +{
   1.812 +    if (xpcomFunctions.logTermFunc)
   1.813 +        xpcomFunctions.logTermFunc();
   1.814 +}
   1.815 +
   1.816 +XPCOM_API(void)
   1.817 +NS_LogAddRef(void *aPtr, nsrefcnt aNewRefCnt,
   1.818 +             const char *aTypeName, uint32_t aInstanceSize)
   1.819 +{
   1.820 +    if (xpcomFunctions.logAddRefFunc)
   1.821 +        xpcomFunctions.logAddRefFunc(aPtr, aNewRefCnt,
   1.822 +                                     aTypeName, aInstanceSize);
   1.823 +}
   1.824 +
   1.825 +XPCOM_API(void)
   1.826 +NS_LogRelease(void *aPtr, nsrefcnt aNewRefCnt, const char *aTypeName)
   1.827 +{
   1.828 +    if (xpcomFunctions.logReleaseFunc)
   1.829 +        xpcomFunctions.logReleaseFunc(aPtr, aNewRefCnt, aTypeName);
   1.830 +}
   1.831 +
   1.832 +XPCOM_API(void)
   1.833 +NS_LogCtor(void *aPtr, const char *aTypeName, uint32_t aInstanceSize)
   1.834 +{
   1.835 +    if (xpcomFunctions.logCtorFunc)
   1.836 +        xpcomFunctions.logCtorFunc(aPtr, aTypeName, aInstanceSize);
   1.837 +}
   1.838 +
   1.839 +XPCOM_API(void)
   1.840 +NS_LogDtor(void *aPtr, const char *aTypeName, uint32_t aInstanceSize)
   1.841 +{
   1.842 +    if (xpcomFunctions.logDtorFunc)
   1.843 +        xpcomFunctions.logDtorFunc(aPtr, aTypeName, aInstanceSize);
   1.844 +}
   1.845 +
   1.846 +XPCOM_API(void)
   1.847 +NS_LogCOMPtrAddRef(void *aCOMPtr, nsISupports *aObject)
   1.848 +{
   1.849 +    if (xpcomFunctions.logCOMPtrAddRefFunc)
   1.850 +        xpcomFunctions.logCOMPtrAddRefFunc(aCOMPtr, aObject);
   1.851 +}
   1.852 +
   1.853 +XPCOM_API(void)
   1.854 +NS_LogCOMPtrRelease(void *aCOMPtr, nsISupports *aObject)
   1.855 +{
   1.856 +    if (xpcomFunctions.logCOMPtrReleaseFunc)
   1.857 +        xpcomFunctions.logCOMPtrReleaseFunc(aCOMPtr, aObject);
   1.858 +}
   1.859 +
   1.860 +XPCOM_API(nsresult)
   1.861 +NS_GetXPTCallStub(REFNSIID aIID, nsIXPTCProxy* aOuter,
   1.862 +                  nsISomeInterface* *aStub)
   1.863 +{
   1.864 +    if (!xpcomFunctions.getXPTCallStubFunc)
   1.865 +        return NS_ERROR_NOT_INITIALIZED;
   1.866 +
   1.867 +    return xpcomFunctions.getXPTCallStubFunc(aIID, aOuter, aStub);
   1.868 +}
   1.869 +
   1.870 +XPCOM_API(void)
   1.871 +NS_DestroyXPTCallStub(nsISomeInterface* aStub)
   1.872 +{
   1.873 +    if (xpcomFunctions.destroyXPTCallStubFunc)
   1.874 +        xpcomFunctions.destroyXPTCallStubFunc(aStub);
   1.875 +}
   1.876 +
   1.877 +XPCOM_API(nsresult)
   1.878 +NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex,
   1.879 +                 uint32_t paramCount, nsXPTCVariant* params)
   1.880 +{
   1.881 +    if (!xpcomFunctions.invokeByIndexFunc)
   1.882 +        return NS_ERROR_NOT_INITIALIZED;
   1.883 +
   1.884 +    return xpcomFunctions.invokeByIndexFunc(that, methodIndex,
   1.885 +                                            paramCount, params);
   1.886 +}
   1.887 +
   1.888 +XPCOM_API(bool)
   1.889 +NS_CycleCollectorSuspect(nsISupports* obj)
   1.890 +{
   1.891 +    if (!xpcomFunctions.cycleSuspectFunc)
   1.892 +        return false;
   1.893 +
   1.894 +    return xpcomFunctions.cycleSuspectFunc(obj);
   1.895 +}
   1.896 +
   1.897 +XPCOM_API(bool)
   1.898 +NS_CycleCollectorForget(nsISupports* obj)
   1.899 +{
   1.900 +    if (!xpcomFunctions.cycleForgetFunc)
   1.901 +        return false;
   1.902 +
   1.903 +    return xpcomFunctions.cycleForgetFunc(obj);
   1.904 +}
   1.905 +
   1.906 +XPCOM_API(nsPurpleBufferEntry*)
   1.907 +NS_CycleCollectorSuspect2(void* obj, nsCycleCollectionParticipant *p)
   1.908 +{
   1.909 +    if (!xpcomFunctions.cycleSuspect2Func)
   1.910 +        return nullptr;
   1.911 +
   1.912 +    return xpcomFunctions.cycleSuspect2Func(obj, p);
   1.913 +}
   1.914 +
   1.915 +XPCOM_API(void)
   1.916 +NS_CycleCollectorSuspect3(void* obj, nsCycleCollectionParticipant *p,
   1.917 +                          nsCycleCollectingAutoRefCnt* aRefCnt,
   1.918 +                          bool* aShouldDelete)
   1.919 +{
   1.920 +    if (xpcomFunctions.cycleSuspect3Func)
   1.921 +        xpcomFunctions.cycleSuspect3Func(obj, p, aRefCnt, aShouldDelete);
   1.922 +}
   1.923 +
   1.924 +XPCOM_API(bool)
   1.925 +NS_CycleCollectorForget2(nsPurpleBufferEntry* e)
   1.926 +{
   1.927 +    if (!xpcomFunctions.cycleForget2Func)
   1.928 +        return false;
   1.929 +
   1.930 +    return xpcomFunctions.cycleForget2Func(e);
   1.931 +}

mercurial