Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* vim:set ts=4 sw=4 et cindent: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "nsXPCOMGlue.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "nspr.h" |
michael@0 | 10 | #include "nsDebug.h" |
michael@0 | 11 | #include "nsIServiceManager.h" |
michael@0 | 12 | #include "nsXPCOMPrivate.h" |
michael@0 | 13 | #include "nsCOMPtr.h" |
michael@0 | 14 | #include <stdlib.h> |
michael@0 | 15 | #include <stdio.h> |
michael@0 | 16 | |
michael@0 | 17 | #include "mozilla/FileUtils.h" |
michael@0 | 18 | |
michael@0 | 19 | using namespace mozilla; |
michael@0 | 20 | |
michael@0 | 21 | #define XPCOM_DEPENDENT_LIBS_LIST "dependentlibs.list" |
michael@0 | 22 | |
michael@0 | 23 | static XPCOMFunctions xpcomFunctions; |
michael@0 | 24 | static bool do_preload = false; |
michael@0 | 25 | |
michael@0 | 26 | #if defined(XP_WIN) |
michael@0 | 27 | #define READ_TEXTMODE L"rt" |
michael@0 | 28 | #else |
michael@0 | 29 | #define READ_TEXTMODE "r" |
michael@0 | 30 | #endif |
michael@0 | 31 | |
michael@0 | 32 | #if defined(SUNOS4) || defined(NEXTSTEP) || \ |
michael@0 | 33 | defined(XP_DARWIN) || \ |
michael@0 | 34 | (defined(OPENBSD) || defined(NETBSD)) && !defined(__ELF__) |
michael@0 | 35 | #define LEADING_UNDERSCORE "_" |
michael@0 | 36 | #else |
michael@0 | 37 | #define LEADING_UNDERSCORE |
michael@0 | 38 | #endif |
michael@0 | 39 | |
michael@0 | 40 | #if defined(XP_WIN) |
michael@0 | 41 | #include <windows.h> |
michael@0 | 42 | #include <mbstring.h> |
michael@0 | 43 | #define snprintf _snprintf |
michael@0 | 44 | |
michael@0 | 45 | typedef HINSTANCE LibHandleType; |
michael@0 | 46 | |
michael@0 | 47 | static LibHandleType |
michael@0 | 48 | GetLibHandle(pathstr_t aDependentLib) |
michael@0 | 49 | { |
michael@0 | 50 | LibHandleType libHandle = |
michael@0 | 51 | LoadLibraryExW(aDependentLib, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH); |
michael@0 | 52 | |
michael@0 | 53 | if (!libHandle) { |
michael@0 | 54 | DWORD err = GetLastError(); |
michael@0 | 55 | #ifdef DEBUG |
michael@0 | 56 | LPVOID lpMsgBuf; |
michael@0 | 57 | FormatMessage( |
michael@0 | 58 | FORMAT_MESSAGE_ALLOCATE_BUFFER | |
michael@0 | 59 | FORMAT_MESSAGE_FROM_SYSTEM | |
michael@0 | 60 | FORMAT_MESSAGE_IGNORE_INSERTS, |
michael@0 | 61 | nullptr, |
michael@0 | 62 | err, |
michael@0 | 63 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
michael@0 | 64 | (LPTSTR) &lpMsgBuf, |
michael@0 | 65 | 0, |
michael@0 | 66 | nullptr |
michael@0 | 67 | ); |
michael@0 | 68 | wprintf(L"Error loading %ls: %s\n", aDependentLib, lpMsgBuf); |
michael@0 | 69 | LocalFree(lpMsgBuf); |
michael@0 | 70 | #endif |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | return libHandle; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | static NSFuncPtr |
michael@0 | 77 | GetSymbol(LibHandleType aLibHandle, const char *aSymbol) |
michael@0 | 78 | { |
michael@0 | 79 | return (NSFuncPtr) GetProcAddress(aLibHandle, aSymbol); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | static void |
michael@0 | 83 | CloseLibHandle(LibHandleType aLibHandle) |
michael@0 | 84 | { |
michael@0 | 85 | FreeLibrary(aLibHandle); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | #elif defined(XP_MACOSX) |
michael@0 | 89 | #include <mach-o/dyld.h> |
michael@0 | 90 | |
michael@0 | 91 | typedef const mach_header *LibHandleType; |
michael@0 | 92 | |
michael@0 | 93 | static LibHandleType |
michael@0 | 94 | GetLibHandle(pathstr_t aDependentLib) |
michael@0 | 95 | { |
michael@0 | 96 | LibHandleType libHandle = NSAddImage(aDependentLib, |
michael@0 | 97 | NSADDIMAGE_OPTION_RETURN_ON_ERROR | |
michael@0 | 98 | NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME); |
michael@0 | 99 | if (!libHandle) { |
michael@0 | 100 | NSLinkEditErrors linkEditError; |
michael@0 | 101 | int errorNum; |
michael@0 | 102 | const char *errorString; |
michael@0 | 103 | const char *fileName; |
michael@0 | 104 | NSLinkEditError(&linkEditError, &errorNum, &fileName, &errorString); |
michael@0 | 105 | fprintf(stderr, "XPCOMGlueLoad error %d:%d for file %s:\n%s\n", |
michael@0 | 106 | linkEditError, errorNum, fileName, errorString); |
michael@0 | 107 | } |
michael@0 | 108 | return libHandle; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | static NSFuncPtr |
michael@0 | 112 | GetSymbol(LibHandleType aLibHandle, const char *aSymbol) |
michael@0 | 113 | { |
michael@0 | 114 | // Try to use |NSLookupSymbolInImage| since it is faster than searching |
michael@0 | 115 | // the global symbol table. If we couldn't get a mach_header pointer |
michael@0 | 116 | // for the XPCOM dylib, then use |NSLookupAndBindSymbol| to search the |
michael@0 | 117 | // global symbol table (this shouldn't normally happen, unless the user |
michael@0 | 118 | // has called XPCOMGlueStartup(".") and relies on libxpcom.dylib |
michael@0 | 119 | // already being loaded). |
michael@0 | 120 | NSSymbol sym = nullptr; |
michael@0 | 121 | if (aLibHandle) { |
michael@0 | 122 | sym = NSLookupSymbolInImage(aLibHandle, aSymbol, |
michael@0 | 123 | NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | |
michael@0 | 124 | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); |
michael@0 | 125 | } else { |
michael@0 | 126 | if (NSIsSymbolNameDefined(aSymbol)) |
michael@0 | 127 | sym = NSLookupAndBindSymbol(aSymbol); |
michael@0 | 128 | } |
michael@0 | 129 | if (!sym) |
michael@0 | 130 | return nullptr; |
michael@0 | 131 | |
michael@0 | 132 | return (NSFuncPtr) NSAddressOfSymbol(sym); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | static void |
michael@0 | 136 | CloseLibHandle(LibHandleType aLibHandle) |
michael@0 | 137 | { |
michael@0 | 138 | // we cannot unload dylibs on OS X |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | #else |
michael@0 | 142 | #include <dlfcn.h> |
michael@0 | 143 | |
michael@0 | 144 | #if defined(MOZ_LINKER) && !defined(ANDROID) |
michael@0 | 145 | extern "C" { |
michael@0 | 146 | NS_HIDDEN __typeof(dlopen) __wrap_dlopen; |
michael@0 | 147 | NS_HIDDEN __typeof(dlsym) __wrap_dlsym; |
michael@0 | 148 | NS_HIDDEN __typeof(dlclose) __wrap_dlclose; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | #define dlopen __wrap_dlopen |
michael@0 | 152 | #define dlsym __wrap_dlsym |
michael@0 | 153 | #define dlclose __wrap_dlclose |
michael@0 | 154 | #endif |
michael@0 | 155 | |
michael@0 | 156 | #ifdef NS_TRACE_MALLOC |
michael@0 | 157 | extern "C" { |
michael@0 | 158 | NS_EXPORT_(__ptr_t) __libc_malloc(size_t); |
michael@0 | 159 | NS_EXPORT_(__ptr_t) __libc_calloc(size_t, size_t); |
michael@0 | 160 | NS_EXPORT_(__ptr_t) __libc_realloc(__ptr_t, size_t); |
michael@0 | 161 | NS_EXPORT_(void) __libc_free(__ptr_t); |
michael@0 | 162 | NS_EXPORT_(__ptr_t) __libc_memalign(size_t, size_t); |
michael@0 | 163 | NS_EXPORT_(__ptr_t) __libc_valloc(size_t); |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | static __ptr_t (*_malloc)(size_t) = __libc_malloc; |
michael@0 | 167 | static __ptr_t (*_calloc)(size_t, size_t) = __libc_calloc; |
michael@0 | 168 | static __ptr_t (*_realloc)(__ptr_t, size_t) = __libc_realloc; |
michael@0 | 169 | static void (*_free)(__ptr_t) = __libc_free; |
michael@0 | 170 | static __ptr_t (*_memalign)(size_t, size_t) = __libc_memalign; |
michael@0 | 171 | static __ptr_t (*_valloc)(size_t) = __libc_valloc; |
michael@0 | 172 | |
michael@0 | 173 | NS_EXPORT_(__ptr_t) malloc(size_t size) |
michael@0 | 174 | { |
michael@0 | 175 | return _malloc(size); |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | NS_EXPORT_(__ptr_t) calloc(size_t nmemb, size_t size) |
michael@0 | 179 | { |
michael@0 | 180 | return _calloc(nmemb, size); |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | NS_EXPORT_(__ptr_t) realloc(__ptr_t ptr, size_t size) |
michael@0 | 184 | { |
michael@0 | 185 | return _realloc(ptr, size); |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | NS_EXPORT_(void) free(__ptr_t ptr) |
michael@0 | 189 | { |
michael@0 | 190 | _free(ptr); |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | NS_EXPORT_(void) cfree(__ptr_t ptr) |
michael@0 | 194 | { |
michael@0 | 195 | _free(ptr); |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | NS_EXPORT_(__ptr_t) memalign(size_t boundary, size_t size) |
michael@0 | 199 | { |
michael@0 | 200 | return _memalign(boundary, size); |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | NS_EXPORT_(int) |
michael@0 | 204 | posix_memalign(void **memptr, size_t alignment, size_t size) |
michael@0 | 205 | { |
michael@0 | 206 | __ptr_t ptr = _memalign(alignment, size); |
michael@0 | 207 | if (!ptr) |
michael@0 | 208 | return ENOMEM; |
michael@0 | 209 | *memptr = ptr; |
michael@0 | 210 | return 0; |
michael@0 | 211 | } |
michael@0 | 212 | |
michael@0 | 213 | NS_EXPORT_(__ptr_t) valloc(size_t size) |
michael@0 | 214 | { |
michael@0 | 215 | return _valloc(size); |
michael@0 | 216 | } |
michael@0 | 217 | #endif /* NS_TRACE_MALLOC */ |
michael@0 | 218 | |
michael@0 | 219 | typedef void *LibHandleType; |
michael@0 | 220 | |
michael@0 | 221 | static LibHandleType |
michael@0 | 222 | GetLibHandle(pathstr_t aDependentLib) |
michael@0 | 223 | { |
michael@0 | 224 | LibHandleType libHandle = dlopen(aDependentLib, RTLD_GLOBAL | RTLD_LAZY); |
michael@0 | 225 | if (!libHandle) { |
michael@0 | 226 | fprintf(stderr, "XPCOMGlueLoad error for file %s:\n%s\n", aDependentLib, dlerror()); |
michael@0 | 227 | } |
michael@0 | 228 | return libHandle; |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | static NSFuncPtr |
michael@0 | 232 | GetSymbol(LibHandleType aLibHandle, const char *aSymbol) |
michael@0 | 233 | { |
michael@0 | 234 | return (NSFuncPtr) dlsym(aLibHandle, aSymbol); |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | static void |
michael@0 | 238 | CloseLibHandle(LibHandleType aLibHandle) |
michael@0 | 239 | { |
michael@0 | 240 | dlclose(aLibHandle); |
michael@0 | 241 | } |
michael@0 | 242 | #endif |
michael@0 | 243 | |
michael@0 | 244 | struct DependentLib |
michael@0 | 245 | { |
michael@0 | 246 | LibHandleType libHandle; |
michael@0 | 247 | DependentLib *next; |
michael@0 | 248 | }; |
michael@0 | 249 | |
michael@0 | 250 | static DependentLib *sTop; |
michael@0 | 251 | |
michael@0 | 252 | static void |
michael@0 | 253 | AppendDependentLib(LibHandleType libHandle) |
michael@0 | 254 | { |
michael@0 | 255 | DependentLib *d = new DependentLib; |
michael@0 | 256 | if (!d) |
michael@0 | 257 | return; |
michael@0 | 258 | |
michael@0 | 259 | d->next = sTop; |
michael@0 | 260 | d->libHandle = libHandle; |
michael@0 | 261 | |
michael@0 | 262 | sTop = d; |
michael@0 | 263 | } |
michael@0 | 264 | |
michael@0 | 265 | static bool |
michael@0 | 266 | ReadDependentCB(pathstr_t aDependentLib, bool do_preload) |
michael@0 | 267 | { |
michael@0 | 268 | if (do_preload) { |
michael@0 | 269 | ReadAheadLib(aDependentLib); |
michael@0 | 270 | } |
michael@0 | 271 | LibHandleType libHandle = GetLibHandle(aDependentLib); |
michael@0 | 272 | if (libHandle) { |
michael@0 | 273 | AppendDependentLib(libHandle); |
michael@0 | 274 | } |
michael@0 | 275 | |
michael@0 | 276 | return libHandle; |
michael@0 | 277 | } |
michael@0 | 278 | |
michael@0 | 279 | #ifdef XP_WIN |
michael@0 | 280 | static bool |
michael@0 | 281 | ReadDependentCB(const char *aDependentLib, bool do_preload) |
michael@0 | 282 | { |
michael@0 | 283 | wchar_t wideDependentLib[MAX_PATH]; |
michael@0 | 284 | MultiByteToWideChar(CP_UTF8, 0, aDependentLib, -1, wideDependentLib, MAX_PATH); |
michael@0 | 285 | return ReadDependentCB(wideDependentLib, do_preload); |
michael@0 | 286 | } |
michael@0 | 287 | |
michael@0 | 288 | inline FILE *TS_tfopen (const char *path, const wchar_t *mode) |
michael@0 | 289 | { |
michael@0 | 290 | wchar_t wPath[MAX_PATH]; |
michael@0 | 291 | MultiByteToWideChar(CP_UTF8, 0, path, -1, wPath, MAX_PATH); |
michael@0 | 292 | return _wfopen(wPath, mode); |
michael@0 | 293 | } |
michael@0 | 294 | #else |
michael@0 | 295 | inline FILE *TS_tfopen (const char *path, const char *mode) |
michael@0 | 296 | { |
michael@0 | 297 | return fopen(path, mode); |
michael@0 | 298 | } |
michael@0 | 299 | #endif |
michael@0 | 300 | |
michael@0 | 301 | /* RAII wrapper for FILE descriptors */ |
michael@0 | 302 | struct ScopedCloseFileTraits |
michael@0 | 303 | { |
michael@0 | 304 | typedef FILE *type; |
michael@0 | 305 | static type empty() { return nullptr; } |
michael@0 | 306 | static void release(type f) { |
michael@0 | 307 | if (f) { |
michael@0 | 308 | fclose(f); |
michael@0 | 309 | } |
michael@0 | 310 | } |
michael@0 | 311 | }; |
michael@0 | 312 | typedef Scoped<ScopedCloseFileTraits> ScopedCloseFile; |
michael@0 | 313 | |
michael@0 | 314 | static void |
michael@0 | 315 | XPCOMGlueUnload() |
michael@0 | 316 | { |
michael@0 | 317 | #if !defined(XP_WIN) && !defined(XP_MACOSX) && defined(NS_TRACE_MALLOC) |
michael@0 | 318 | if (sTop) { |
michael@0 | 319 | _malloc = __libc_malloc; |
michael@0 | 320 | _calloc = __libc_calloc; |
michael@0 | 321 | _realloc = __libc_realloc; |
michael@0 | 322 | _free = __libc_free; |
michael@0 | 323 | _memalign = __libc_memalign; |
michael@0 | 324 | _valloc = __libc_valloc; |
michael@0 | 325 | } |
michael@0 | 326 | #endif |
michael@0 | 327 | |
michael@0 | 328 | while (sTop) { |
michael@0 | 329 | CloseLibHandle(sTop->libHandle); |
michael@0 | 330 | |
michael@0 | 331 | DependentLib *temp = sTop; |
michael@0 | 332 | sTop = sTop->next; |
michael@0 | 333 | |
michael@0 | 334 | delete temp; |
michael@0 | 335 | } |
michael@0 | 336 | } |
michael@0 | 337 | |
michael@0 | 338 | #if defined(XP_WIN) |
michael@0 | 339 | // like strpbrk but finds the *last* char, not the first |
michael@0 | 340 | static const char* |
michael@0 | 341 | ns_strrpbrk(const char *string, const char *strCharSet) |
michael@0 | 342 | { |
michael@0 | 343 | const char *found = nullptr; |
michael@0 | 344 | for (; *string; ++string) { |
michael@0 | 345 | for (const char *search = strCharSet; *search; ++search) { |
michael@0 | 346 | if (*search == *string) { |
michael@0 | 347 | found = string; |
michael@0 | 348 | // Since we're looking for the last char, we save "found" |
michael@0 | 349 | // until we're at the end of the string. |
michael@0 | 350 | } |
michael@0 | 351 | } |
michael@0 | 352 | } |
michael@0 | 353 | |
michael@0 | 354 | return found; |
michael@0 | 355 | } |
michael@0 | 356 | #endif |
michael@0 | 357 | |
michael@0 | 358 | static GetFrozenFunctionsFunc |
michael@0 | 359 | XPCOMGlueLoad(const char *xpcomFile) |
michael@0 | 360 | { |
michael@0 | 361 | char xpcomDir[MAXPATHLEN]; |
michael@0 | 362 | #if defined(XP_WIN) |
michael@0 | 363 | const char *lastSlash = ns_strrpbrk(xpcomFile, "/\\"); |
michael@0 | 364 | #else |
michael@0 | 365 | const char *lastSlash = strrchr(xpcomFile, '/'); |
michael@0 | 366 | #endif |
michael@0 | 367 | char *cursor; |
michael@0 | 368 | if (lastSlash) { |
michael@0 | 369 | size_t len = size_t(lastSlash - xpcomFile); |
michael@0 | 370 | |
michael@0 | 371 | if (len > MAXPATHLEN - sizeof(XPCOM_FILE_PATH_SEPARATOR |
michael@0 | 372 | XPCOM_DEPENDENT_LIBS_LIST)) { |
michael@0 | 373 | return nullptr; |
michael@0 | 374 | } |
michael@0 | 375 | memcpy(xpcomDir, xpcomFile, len); |
michael@0 | 376 | strcpy(xpcomDir + len, XPCOM_FILE_PATH_SEPARATOR |
michael@0 | 377 | XPCOM_DEPENDENT_LIBS_LIST); |
michael@0 | 378 | cursor = xpcomDir + len + 1; |
michael@0 | 379 | } else { |
michael@0 | 380 | strcpy(xpcomDir, XPCOM_DEPENDENT_LIBS_LIST); |
michael@0 | 381 | cursor = xpcomDir; |
michael@0 | 382 | } |
michael@0 | 383 | |
michael@0 | 384 | if (getenv("MOZ_RUN_GTEST")) { |
michael@0 | 385 | strcat(xpcomDir, ".gtest"); |
michael@0 | 386 | } |
michael@0 | 387 | |
michael@0 | 388 | ScopedCloseFile flist; |
michael@0 | 389 | flist = TS_tfopen(xpcomDir, READ_TEXTMODE); |
michael@0 | 390 | if (!flist) { |
michael@0 | 391 | return nullptr; |
michael@0 | 392 | } |
michael@0 | 393 | |
michael@0 | 394 | *cursor = '\0'; |
michael@0 | 395 | |
michael@0 | 396 | char buffer[MAXPATHLEN]; |
michael@0 | 397 | |
michael@0 | 398 | while (fgets(buffer, sizeof(buffer), flist)) { |
michael@0 | 399 | int l = strlen(buffer); |
michael@0 | 400 | |
michael@0 | 401 | // ignore empty lines and comments |
michael@0 | 402 | if (l == 0 || *buffer == '#') { |
michael@0 | 403 | continue; |
michael@0 | 404 | } |
michael@0 | 405 | |
michael@0 | 406 | // cut the trailing newline, if present |
michael@0 | 407 | if (buffer[l - 1] == '\n') |
michael@0 | 408 | buffer[l - 1] = '\0'; |
michael@0 | 409 | |
michael@0 | 410 | if (l + size_t(cursor - xpcomDir) > MAXPATHLEN) { |
michael@0 | 411 | return nullptr; |
michael@0 | 412 | } |
michael@0 | 413 | |
michael@0 | 414 | strcpy(cursor, buffer); |
michael@0 | 415 | if (!ReadDependentCB(xpcomDir, do_preload)) { |
michael@0 | 416 | XPCOMGlueUnload(); |
michael@0 | 417 | return nullptr; |
michael@0 | 418 | } |
michael@0 | 419 | } |
michael@0 | 420 | |
michael@0 | 421 | GetFrozenFunctionsFunc sym = |
michael@0 | 422 | (GetFrozenFunctionsFunc) GetSymbol(sTop->libHandle, LEADING_UNDERSCORE "NS_GetFrozenFunctions"); |
michael@0 | 423 | |
michael@0 | 424 | if (!sym) { // No symbol found. |
michael@0 | 425 | XPCOMGlueUnload(); |
michael@0 | 426 | return nullptr; |
michael@0 | 427 | } |
michael@0 | 428 | |
michael@0 | 429 | #if !defined(XP_WIN) && !defined(XP_MACOSX) && defined(NS_TRACE_MALLOC) |
michael@0 | 430 | _malloc = (__ptr_t(*)(size_t)) GetSymbol(sTop->libHandle, "malloc"); |
michael@0 | 431 | _calloc = (__ptr_t(*)(size_t, size_t)) GetSymbol(sTop->libHandle, "calloc"); |
michael@0 | 432 | _realloc = (__ptr_t(*)(__ptr_t, size_t)) GetSymbol(sTop->libHandle, "realloc"); |
michael@0 | 433 | _free = (void(*)(__ptr_t)) GetSymbol(sTop->libHandle, "free"); |
michael@0 | 434 | _memalign = (__ptr_t(*)(size_t, size_t)) GetSymbol(sTop->libHandle, "memalign"); |
michael@0 | 435 | _valloc = (__ptr_t(*)(size_t)) GetSymbol(sTop->libHandle, "valloc"); |
michael@0 | 436 | #endif |
michael@0 | 437 | |
michael@0 | 438 | return sym; |
michael@0 | 439 | } |
michael@0 | 440 | |
michael@0 | 441 | nsresult |
michael@0 | 442 | XPCOMGlueLoadXULFunctions(const nsDynamicFunctionLoad *symbols) |
michael@0 | 443 | { |
michael@0 | 444 | // We don't null-check sXULLibHandle because this might work even |
michael@0 | 445 | // if it is null (same as RTLD_DEFAULT) |
michael@0 | 446 | |
michael@0 | 447 | nsresult rv = NS_OK; |
michael@0 | 448 | while (symbols->functionName) { |
michael@0 | 449 | char buffer[512]; |
michael@0 | 450 | snprintf(buffer, sizeof(buffer), |
michael@0 | 451 | LEADING_UNDERSCORE "%s", symbols->functionName); |
michael@0 | 452 | |
michael@0 | 453 | *symbols->function = (NSFuncPtr) GetSymbol(sTop->libHandle, buffer); |
michael@0 | 454 | if (!*symbols->function) |
michael@0 | 455 | rv = NS_ERROR_LOSS_OF_SIGNIFICANT_DATA; |
michael@0 | 456 | |
michael@0 | 457 | ++symbols; |
michael@0 | 458 | } |
michael@0 | 459 | return rv; |
michael@0 | 460 | } |
michael@0 | 461 | |
michael@0 | 462 | void XPCOMGlueEnablePreload() |
michael@0 | 463 | { |
michael@0 | 464 | do_preload = true; |
michael@0 | 465 | } |
michael@0 | 466 | |
michael@0 | 467 | nsresult XPCOMGlueStartup(const char* xpcomFile) |
michael@0 | 468 | { |
michael@0 | 469 | xpcomFunctions.version = XPCOM_GLUE_VERSION; |
michael@0 | 470 | xpcomFunctions.size = sizeof(XPCOMFunctions); |
michael@0 | 471 | |
michael@0 | 472 | if (!xpcomFile) |
michael@0 | 473 | xpcomFile = XPCOM_DLL; |
michael@0 | 474 | |
michael@0 | 475 | GetFrozenFunctionsFunc func = XPCOMGlueLoad(xpcomFile); |
michael@0 | 476 | if (!func) |
michael@0 | 477 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 478 | |
michael@0 | 479 | nsresult rv = (*func)(&xpcomFunctions, nullptr); |
michael@0 | 480 | if (NS_FAILED(rv)) { |
michael@0 | 481 | XPCOMGlueUnload(); |
michael@0 | 482 | return rv; |
michael@0 | 483 | } |
michael@0 | 484 | |
michael@0 | 485 | return NS_OK; |
michael@0 | 486 | } |
michael@0 | 487 | |
michael@0 | 488 | XPCOM_API(nsresult) |
michael@0 | 489 | NS_InitXPCOM2(nsIServiceManager* *result, |
michael@0 | 490 | nsIFile* binDirectory, |
michael@0 | 491 | nsIDirectoryServiceProvider* appFileLocationProvider) |
michael@0 | 492 | { |
michael@0 | 493 | if (!xpcomFunctions.init) |
michael@0 | 494 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 495 | return xpcomFunctions.init(result, binDirectory, appFileLocationProvider); |
michael@0 | 496 | } |
michael@0 | 497 | |
michael@0 | 498 | XPCOM_API(nsresult) |
michael@0 | 499 | NS_ShutdownXPCOM(nsIServiceManager* servMgr) |
michael@0 | 500 | { |
michael@0 | 501 | if (!xpcomFunctions.shutdown) |
michael@0 | 502 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 503 | return xpcomFunctions.shutdown(servMgr); |
michael@0 | 504 | } |
michael@0 | 505 | |
michael@0 | 506 | XPCOM_API(nsresult) |
michael@0 | 507 | NS_GetServiceManager(nsIServiceManager* *result) |
michael@0 | 508 | { |
michael@0 | 509 | if (!xpcomFunctions.getServiceManager) |
michael@0 | 510 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 511 | return xpcomFunctions.getServiceManager(result); |
michael@0 | 512 | } |
michael@0 | 513 | |
michael@0 | 514 | XPCOM_API(nsresult) |
michael@0 | 515 | NS_GetComponentManager(nsIComponentManager* *result) |
michael@0 | 516 | { |
michael@0 | 517 | if (!xpcomFunctions.getComponentManager) |
michael@0 | 518 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 519 | return xpcomFunctions.getComponentManager(result); |
michael@0 | 520 | } |
michael@0 | 521 | |
michael@0 | 522 | XPCOM_API(nsresult) |
michael@0 | 523 | NS_GetComponentRegistrar(nsIComponentRegistrar* *result) |
michael@0 | 524 | { |
michael@0 | 525 | if (!xpcomFunctions.getComponentRegistrar) |
michael@0 | 526 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 527 | return xpcomFunctions.getComponentRegistrar(result); |
michael@0 | 528 | } |
michael@0 | 529 | |
michael@0 | 530 | XPCOM_API(nsresult) |
michael@0 | 531 | NS_GetMemoryManager(nsIMemory* *result) |
michael@0 | 532 | { |
michael@0 | 533 | if (!xpcomFunctions.getMemoryManager) |
michael@0 | 534 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 535 | return xpcomFunctions.getMemoryManager(result); |
michael@0 | 536 | } |
michael@0 | 537 | |
michael@0 | 538 | XPCOM_API(nsresult) |
michael@0 | 539 | NS_NewLocalFile(const nsAString &path, bool followLinks, nsIFile* *result) |
michael@0 | 540 | { |
michael@0 | 541 | if (!xpcomFunctions.newLocalFile) |
michael@0 | 542 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 543 | return xpcomFunctions.newLocalFile(path, followLinks, result); |
michael@0 | 544 | } |
michael@0 | 545 | |
michael@0 | 546 | XPCOM_API(nsresult) |
michael@0 | 547 | NS_NewNativeLocalFile(const nsACString &path, bool followLinks, nsIFile* *result) |
michael@0 | 548 | { |
michael@0 | 549 | if (!xpcomFunctions.newNativeLocalFile) |
michael@0 | 550 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 551 | return xpcomFunctions.newNativeLocalFile(path, followLinks, result); |
michael@0 | 552 | } |
michael@0 | 553 | |
michael@0 | 554 | XPCOM_API(nsresult) |
michael@0 | 555 | NS_GetDebug(nsIDebug* *result) |
michael@0 | 556 | { |
michael@0 | 557 | if (!xpcomFunctions.getDebug) |
michael@0 | 558 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 559 | return xpcomFunctions.getDebug(result); |
michael@0 | 560 | } |
michael@0 | 561 | |
michael@0 | 562 | |
michael@0 | 563 | XPCOM_API(nsresult) |
michael@0 | 564 | NS_StringContainerInit(nsStringContainer &aStr) |
michael@0 | 565 | { |
michael@0 | 566 | if (!xpcomFunctions.stringContainerInit) |
michael@0 | 567 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 568 | return xpcomFunctions.stringContainerInit(aStr); |
michael@0 | 569 | } |
michael@0 | 570 | |
michael@0 | 571 | XPCOM_API(nsresult) |
michael@0 | 572 | NS_StringContainerInit2(nsStringContainer &aStr, |
michael@0 | 573 | const char16_t *aData, |
michael@0 | 574 | uint32_t aDataLength, |
michael@0 | 575 | uint32_t aFlags) |
michael@0 | 576 | { |
michael@0 | 577 | if (!xpcomFunctions.stringContainerInit2) |
michael@0 | 578 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 579 | return xpcomFunctions.stringContainerInit2(aStr, aData, aDataLength, aFlags); |
michael@0 | 580 | } |
michael@0 | 581 | |
michael@0 | 582 | XPCOM_API(void) |
michael@0 | 583 | NS_StringContainerFinish(nsStringContainer &aStr) |
michael@0 | 584 | { |
michael@0 | 585 | if (xpcomFunctions.stringContainerFinish) |
michael@0 | 586 | xpcomFunctions.stringContainerFinish(aStr); |
michael@0 | 587 | } |
michael@0 | 588 | |
michael@0 | 589 | XPCOM_API(uint32_t) |
michael@0 | 590 | NS_StringGetData(const nsAString &aStr, const char16_t **aBuf, bool *aTerm) |
michael@0 | 591 | { |
michael@0 | 592 | if (!xpcomFunctions.stringGetData) { |
michael@0 | 593 | *aBuf = nullptr; |
michael@0 | 594 | return 0; |
michael@0 | 595 | } |
michael@0 | 596 | return xpcomFunctions.stringGetData(aStr, aBuf, aTerm); |
michael@0 | 597 | } |
michael@0 | 598 | |
michael@0 | 599 | XPCOM_API(uint32_t) |
michael@0 | 600 | NS_StringGetMutableData(nsAString &aStr, uint32_t aLen, char16_t **aBuf) |
michael@0 | 601 | { |
michael@0 | 602 | if (!xpcomFunctions.stringGetMutableData) { |
michael@0 | 603 | *aBuf = nullptr; |
michael@0 | 604 | return 0; |
michael@0 | 605 | } |
michael@0 | 606 | return xpcomFunctions.stringGetMutableData(aStr, aLen, aBuf); |
michael@0 | 607 | } |
michael@0 | 608 | |
michael@0 | 609 | XPCOM_API(char16_t*) |
michael@0 | 610 | NS_StringCloneData(const nsAString &aStr) |
michael@0 | 611 | { |
michael@0 | 612 | if (!xpcomFunctions.stringCloneData) |
michael@0 | 613 | return nullptr; |
michael@0 | 614 | return xpcomFunctions.stringCloneData(aStr); |
michael@0 | 615 | } |
michael@0 | 616 | |
michael@0 | 617 | XPCOM_API(nsresult) |
michael@0 | 618 | NS_StringSetData(nsAString &aStr, const char16_t *aBuf, uint32_t aCount) |
michael@0 | 619 | { |
michael@0 | 620 | if (!xpcomFunctions.stringSetData) |
michael@0 | 621 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 622 | |
michael@0 | 623 | return xpcomFunctions.stringSetData(aStr, aBuf, aCount); |
michael@0 | 624 | } |
michael@0 | 625 | |
michael@0 | 626 | XPCOM_API(nsresult) |
michael@0 | 627 | NS_StringSetDataRange(nsAString &aStr, uint32_t aCutStart, uint32_t aCutLength, |
michael@0 | 628 | const char16_t *aBuf, uint32_t aCount) |
michael@0 | 629 | { |
michael@0 | 630 | if (!xpcomFunctions.stringSetDataRange) |
michael@0 | 631 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 632 | return xpcomFunctions.stringSetDataRange(aStr, aCutStart, aCutLength, aBuf, aCount); |
michael@0 | 633 | } |
michael@0 | 634 | |
michael@0 | 635 | XPCOM_API(nsresult) |
michael@0 | 636 | NS_StringCopy(nsAString &aDest, const nsAString &aSrc) |
michael@0 | 637 | { |
michael@0 | 638 | if (!xpcomFunctions.stringCopy) |
michael@0 | 639 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 640 | return xpcomFunctions.stringCopy(aDest, aSrc); |
michael@0 | 641 | } |
michael@0 | 642 | |
michael@0 | 643 | XPCOM_API(void) |
michael@0 | 644 | NS_StringSetIsVoid(nsAString &aStr, const bool aIsVoid) |
michael@0 | 645 | { |
michael@0 | 646 | if (xpcomFunctions.stringSetIsVoid) |
michael@0 | 647 | xpcomFunctions.stringSetIsVoid(aStr, aIsVoid); |
michael@0 | 648 | } |
michael@0 | 649 | |
michael@0 | 650 | XPCOM_API(bool) |
michael@0 | 651 | NS_StringGetIsVoid(const nsAString &aStr) |
michael@0 | 652 | { |
michael@0 | 653 | if (!xpcomFunctions.stringGetIsVoid) |
michael@0 | 654 | return false; |
michael@0 | 655 | return xpcomFunctions.stringGetIsVoid(aStr); |
michael@0 | 656 | } |
michael@0 | 657 | |
michael@0 | 658 | XPCOM_API(nsresult) |
michael@0 | 659 | NS_CStringContainerInit(nsCStringContainer &aStr) |
michael@0 | 660 | { |
michael@0 | 661 | if (!xpcomFunctions.cstringContainerInit) |
michael@0 | 662 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 663 | return xpcomFunctions.cstringContainerInit(aStr); |
michael@0 | 664 | } |
michael@0 | 665 | |
michael@0 | 666 | XPCOM_API(nsresult) |
michael@0 | 667 | NS_CStringContainerInit2(nsCStringContainer &aStr, |
michael@0 | 668 | const char *aData, |
michael@0 | 669 | uint32_t aDataLength, |
michael@0 | 670 | uint32_t aFlags) |
michael@0 | 671 | { |
michael@0 | 672 | if (!xpcomFunctions.cstringContainerInit2) |
michael@0 | 673 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 674 | return xpcomFunctions.cstringContainerInit2(aStr, aData, aDataLength, aFlags); |
michael@0 | 675 | } |
michael@0 | 676 | |
michael@0 | 677 | XPCOM_API(void) |
michael@0 | 678 | NS_CStringContainerFinish(nsCStringContainer &aStr) |
michael@0 | 679 | { |
michael@0 | 680 | if (xpcomFunctions.cstringContainerFinish) |
michael@0 | 681 | xpcomFunctions.cstringContainerFinish(aStr); |
michael@0 | 682 | } |
michael@0 | 683 | |
michael@0 | 684 | XPCOM_API(uint32_t) |
michael@0 | 685 | NS_CStringGetData(const nsACString &aStr, const char **aBuf, bool *aTerm) |
michael@0 | 686 | { |
michael@0 | 687 | if (!xpcomFunctions.cstringGetData) { |
michael@0 | 688 | *aBuf = nullptr; |
michael@0 | 689 | return 0; |
michael@0 | 690 | } |
michael@0 | 691 | return xpcomFunctions.cstringGetData(aStr, aBuf, aTerm); |
michael@0 | 692 | } |
michael@0 | 693 | |
michael@0 | 694 | XPCOM_API(uint32_t) |
michael@0 | 695 | NS_CStringGetMutableData(nsACString &aStr, uint32_t aLen, char **aBuf) |
michael@0 | 696 | { |
michael@0 | 697 | if (!xpcomFunctions.cstringGetMutableData) { |
michael@0 | 698 | *aBuf = nullptr; |
michael@0 | 699 | return 0; |
michael@0 | 700 | } |
michael@0 | 701 | return xpcomFunctions.cstringGetMutableData(aStr, aLen, aBuf); |
michael@0 | 702 | } |
michael@0 | 703 | |
michael@0 | 704 | XPCOM_API(char*) |
michael@0 | 705 | NS_CStringCloneData(const nsACString &aStr) |
michael@0 | 706 | { |
michael@0 | 707 | if (!xpcomFunctions.cstringCloneData) |
michael@0 | 708 | return nullptr; |
michael@0 | 709 | return xpcomFunctions.cstringCloneData(aStr); |
michael@0 | 710 | } |
michael@0 | 711 | |
michael@0 | 712 | XPCOM_API(nsresult) |
michael@0 | 713 | NS_CStringSetData(nsACString &aStr, const char *aBuf, uint32_t aCount) |
michael@0 | 714 | { |
michael@0 | 715 | if (!xpcomFunctions.cstringSetData) |
michael@0 | 716 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 717 | return xpcomFunctions.cstringSetData(aStr, aBuf, aCount); |
michael@0 | 718 | } |
michael@0 | 719 | |
michael@0 | 720 | XPCOM_API(nsresult) |
michael@0 | 721 | NS_CStringSetDataRange(nsACString &aStr, uint32_t aCutStart, uint32_t aCutLength, |
michael@0 | 722 | const char *aBuf, uint32_t aCount) |
michael@0 | 723 | { |
michael@0 | 724 | if (!xpcomFunctions.cstringSetDataRange) |
michael@0 | 725 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 726 | return xpcomFunctions.cstringSetDataRange(aStr, aCutStart, aCutLength, aBuf, aCount); |
michael@0 | 727 | } |
michael@0 | 728 | |
michael@0 | 729 | XPCOM_API(nsresult) |
michael@0 | 730 | NS_CStringCopy(nsACString &aDest, const nsACString &aSrc) |
michael@0 | 731 | { |
michael@0 | 732 | if (!xpcomFunctions.cstringCopy) |
michael@0 | 733 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 734 | return xpcomFunctions.cstringCopy(aDest, aSrc); |
michael@0 | 735 | } |
michael@0 | 736 | |
michael@0 | 737 | XPCOM_API(void) |
michael@0 | 738 | NS_CStringSetIsVoid(nsACString &aStr, const bool aIsVoid) |
michael@0 | 739 | { |
michael@0 | 740 | if (xpcomFunctions.cstringSetIsVoid) |
michael@0 | 741 | xpcomFunctions.cstringSetIsVoid(aStr, aIsVoid); |
michael@0 | 742 | } |
michael@0 | 743 | |
michael@0 | 744 | XPCOM_API(bool) |
michael@0 | 745 | NS_CStringGetIsVoid(const nsACString &aStr) |
michael@0 | 746 | { |
michael@0 | 747 | if (!xpcomFunctions.cstringGetIsVoid) |
michael@0 | 748 | return false; |
michael@0 | 749 | return xpcomFunctions.cstringGetIsVoid(aStr); |
michael@0 | 750 | } |
michael@0 | 751 | |
michael@0 | 752 | XPCOM_API(nsresult) |
michael@0 | 753 | NS_CStringToUTF16(const nsACString &aSrc, nsCStringEncoding aSrcEncoding, nsAString &aDest) |
michael@0 | 754 | { |
michael@0 | 755 | if (!xpcomFunctions.cstringToUTF16) |
michael@0 | 756 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 757 | return xpcomFunctions.cstringToUTF16(aSrc, aSrcEncoding, aDest); |
michael@0 | 758 | } |
michael@0 | 759 | |
michael@0 | 760 | XPCOM_API(nsresult) |
michael@0 | 761 | NS_UTF16ToCString(const nsAString &aSrc, nsCStringEncoding aDestEncoding, nsACString &aDest) |
michael@0 | 762 | { |
michael@0 | 763 | if (!xpcomFunctions.utf16ToCString) |
michael@0 | 764 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 765 | return xpcomFunctions.utf16ToCString(aSrc, aDestEncoding, aDest); |
michael@0 | 766 | } |
michael@0 | 767 | |
michael@0 | 768 | XPCOM_API(void*) |
michael@0 | 769 | NS_Alloc(size_t size) |
michael@0 | 770 | { |
michael@0 | 771 | if (!xpcomFunctions.allocFunc) |
michael@0 | 772 | return nullptr; |
michael@0 | 773 | return xpcomFunctions.allocFunc(size); |
michael@0 | 774 | } |
michael@0 | 775 | |
michael@0 | 776 | XPCOM_API(void*) |
michael@0 | 777 | NS_Realloc(void* ptr, size_t size) |
michael@0 | 778 | { |
michael@0 | 779 | if (!xpcomFunctions.reallocFunc) |
michael@0 | 780 | return nullptr; |
michael@0 | 781 | return xpcomFunctions.reallocFunc(ptr, size); |
michael@0 | 782 | } |
michael@0 | 783 | |
michael@0 | 784 | XPCOM_API(void) |
michael@0 | 785 | NS_Free(void* ptr) |
michael@0 | 786 | { |
michael@0 | 787 | if (xpcomFunctions.freeFunc) |
michael@0 | 788 | xpcomFunctions.freeFunc(ptr); |
michael@0 | 789 | } |
michael@0 | 790 | |
michael@0 | 791 | XPCOM_API(void) |
michael@0 | 792 | NS_DebugBreak(uint32_t aSeverity, const char *aStr, const char *aExpr, |
michael@0 | 793 | const char *aFile, int32_t aLine) |
michael@0 | 794 | { |
michael@0 | 795 | if (xpcomFunctions.debugBreakFunc) |
michael@0 | 796 | xpcomFunctions.debugBreakFunc(aSeverity, aStr, aExpr, aFile, aLine); |
michael@0 | 797 | } |
michael@0 | 798 | |
michael@0 | 799 | XPCOM_API(void) |
michael@0 | 800 | NS_LogInit() |
michael@0 | 801 | { |
michael@0 | 802 | if (xpcomFunctions.logInitFunc) |
michael@0 | 803 | xpcomFunctions.logInitFunc(); |
michael@0 | 804 | } |
michael@0 | 805 | |
michael@0 | 806 | XPCOM_API(void) |
michael@0 | 807 | NS_LogTerm() |
michael@0 | 808 | { |
michael@0 | 809 | if (xpcomFunctions.logTermFunc) |
michael@0 | 810 | xpcomFunctions.logTermFunc(); |
michael@0 | 811 | } |
michael@0 | 812 | |
michael@0 | 813 | XPCOM_API(void) |
michael@0 | 814 | NS_LogAddRef(void *aPtr, nsrefcnt aNewRefCnt, |
michael@0 | 815 | const char *aTypeName, uint32_t aInstanceSize) |
michael@0 | 816 | { |
michael@0 | 817 | if (xpcomFunctions.logAddRefFunc) |
michael@0 | 818 | xpcomFunctions.logAddRefFunc(aPtr, aNewRefCnt, |
michael@0 | 819 | aTypeName, aInstanceSize); |
michael@0 | 820 | } |
michael@0 | 821 | |
michael@0 | 822 | XPCOM_API(void) |
michael@0 | 823 | NS_LogRelease(void *aPtr, nsrefcnt aNewRefCnt, const char *aTypeName) |
michael@0 | 824 | { |
michael@0 | 825 | if (xpcomFunctions.logReleaseFunc) |
michael@0 | 826 | xpcomFunctions.logReleaseFunc(aPtr, aNewRefCnt, aTypeName); |
michael@0 | 827 | } |
michael@0 | 828 | |
michael@0 | 829 | XPCOM_API(void) |
michael@0 | 830 | NS_LogCtor(void *aPtr, const char *aTypeName, uint32_t aInstanceSize) |
michael@0 | 831 | { |
michael@0 | 832 | if (xpcomFunctions.logCtorFunc) |
michael@0 | 833 | xpcomFunctions.logCtorFunc(aPtr, aTypeName, aInstanceSize); |
michael@0 | 834 | } |
michael@0 | 835 | |
michael@0 | 836 | XPCOM_API(void) |
michael@0 | 837 | NS_LogDtor(void *aPtr, const char *aTypeName, uint32_t aInstanceSize) |
michael@0 | 838 | { |
michael@0 | 839 | if (xpcomFunctions.logDtorFunc) |
michael@0 | 840 | xpcomFunctions.logDtorFunc(aPtr, aTypeName, aInstanceSize); |
michael@0 | 841 | } |
michael@0 | 842 | |
michael@0 | 843 | XPCOM_API(void) |
michael@0 | 844 | NS_LogCOMPtrAddRef(void *aCOMPtr, nsISupports *aObject) |
michael@0 | 845 | { |
michael@0 | 846 | if (xpcomFunctions.logCOMPtrAddRefFunc) |
michael@0 | 847 | xpcomFunctions.logCOMPtrAddRefFunc(aCOMPtr, aObject); |
michael@0 | 848 | } |
michael@0 | 849 | |
michael@0 | 850 | XPCOM_API(void) |
michael@0 | 851 | NS_LogCOMPtrRelease(void *aCOMPtr, nsISupports *aObject) |
michael@0 | 852 | { |
michael@0 | 853 | if (xpcomFunctions.logCOMPtrReleaseFunc) |
michael@0 | 854 | xpcomFunctions.logCOMPtrReleaseFunc(aCOMPtr, aObject); |
michael@0 | 855 | } |
michael@0 | 856 | |
michael@0 | 857 | XPCOM_API(nsresult) |
michael@0 | 858 | NS_GetXPTCallStub(REFNSIID aIID, nsIXPTCProxy* aOuter, |
michael@0 | 859 | nsISomeInterface* *aStub) |
michael@0 | 860 | { |
michael@0 | 861 | if (!xpcomFunctions.getXPTCallStubFunc) |
michael@0 | 862 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 863 | |
michael@0 | 864 | return xpcomFunctions.getXPTCallStubFunc(aIID, aOuter, aStub); |
michael@0 | 865 | } |
michael@0 | 866 | |
michael@0 | 867 | XPCOM_API(void) |
michael@0 | 868 | NS_DestroyXPTCallStub(nsISomeInterface* aStub) |
michael@0 | 869 | { |
michael@0 | 870 | if (xpcomFunctions.destroyXPTCallStubFunc) |
michael@0 | 871 | xpcomFunctions.destroyXPTCallStubFunc(aStub); |
michael@0 | 872 | } |
michael@0 | 873 | |
michael@0 | 874 | XPCOM_API(nsresult) |
michael@0 | 875 | NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, |
michael@0 | 876 | uint32_t paramCount, nsXPTCVariant* params) |
michael@0 | 877 | { |
michael@0 | 878 | if (!xpcomFunctions.invokeByIndexFunc) |
michael@0 | 879 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 880 | |
michael@0 | 881 | return xpcomFunctions.invokeByIndexFunc(that, methodIndex, |
michael@0 | 882 | paramCount, params); |
michael@0 | 883 | } |
michael@0 | 884 | |
michael@0 | 885 | XPCOM_API(bool) |
michael@0 | 886 | NS_CycleCollectorSuspect(nsISupports* obj) |
michael@0 | 887 | { |
michael@0 | 888 | if (!xpcomFunctions.cycleSuspectFunc) |
michael@0 | 889 | return false; |
michael@0 | 890 | |
michael@0 | 891 | return xpcomFunctions.cycleSuspectFunc(obj); |
michael@0 | 892 | } |
michael@0 | 893 | |
michael@0 | 894 | XPCOM_API(bool) |
michael@0 | 895 | NS_CycleCollectorForget(nsISupports* obj) |
michael@0 | 896 | { |
michael@0 | 897 | if (!xpcomFunctions.cycleForgetFunc) |
michael@0 | 898 | return false; |
michael@0 | 899 | |
michael@0 | 900 | return xpcomFunctions.cycleForgetFunc(obj); |
michael@0 | 901 | } |
michael@0 | 902 | |
michael@0 | 903 | XPCOM_API(nsPurpleBufferEntry*) |
michael@0 | 904 | NS_CycleCollectorSuspect2(void* obj, nsCycleCollectionParticipant *p) |
michael@0 | 905 | { |
michael@0 | 906 | if (!xpcomFunctions.cycleSuspect2Func) |
michael@0 | 907 | return nullptr; |
michael@0 | 908 | |
michael@0 | 909 | return xpcomFunctions.cycleSuspect2Func(obj, p); |
michael@0 | 910 | } |
michael@0 | 911 | |
michael@0 | 912 | XPCOM_API(void) |
michael@0 | 913 | NS_CycleCollectorSuspect3(void* obj, nsCycleCollectionParticipant *p, |
michael@0 | 914 | nsCycleCollectingAutoRefCnt* aRefCnt, |
michael@0 | 915 | bool* aShouldDelete) |
michael@0 | 916 | { |
michael@0 | 917 | if (xpcomFunctions.cycleSuspect3Func) |
michael@0 | 918 | xpcomFunctions.cycleSuspect3Func(obj, p, aRefCnt, aShouldDelete); |
michael@0 | 919 | } |
michael@0 | 920 | |
michael@0 | 921 | XPCOM_API(bool) |
michael@0 | 922 | NS_CycleCollectorForget2(nsPurpleBufferEntry* e) |
michael@0 | 923 | { |
michael@0 | 924 | if (!xpcomFunctions.cycleForget2Func) |
michael@0 | 925 | return false; |
michael@0 | 926 | |
michael@0 | 927 | return xpcomFunctions.cycleForget2Func(e); |
michael@0 | 928 | } |