int main(int argc, char **argv) { if (PR_GetEnv("MOZ_BREAK_ON_MAIN")) NS_BREAK(); if (argc < 5) { fprintf(stderr, "USAGE: TestIncrementalDownload <url> <file> <chunksize> <interval-in-seconds>\n"); return -1; } nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); if (NS_FAILED(rv)) return -1; int32_t chunkSize = atoi(argv[3]); int32_t interval = atoi(argv[4]); rv = DoIncrementalFetch(argv[1], argv[2], chunkSize, interval); if (NS_FAILED(rv)) fprintf(stderr, "ERROR: DoIncrementalFetch failed [%x]\n", static_cast<uint32_t>(rv)); NS_ShutdownXPCOM(nullptr); return 0; }
static JSBool DebugBreak(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { nsJSSh* shell; if (!GetJSShGlobal(cx, obj, &shell)) return JS_FALSE; NS_BREAK(); return JS_TRUE; }
const mozilla::Module* nsNativeModuleLoader::LoadModule(nsILocalFile* aFile) { nsresult rv; if (!NS_IsMainThread()) { // If this call is off the main thread, synchronously proxy it // to the main thread. nsRefPtr<LoadModuleMainThreadRunnable> r = new LoadModuleMainThreadRunnable(this, aFile); NS_DispatchToMainThread(r, NS_DISPATCH_SYNC); return r->mResult; } nsCOMPtr<nsIHashable> hashedFile(do_QueryInterface(aFile)); if (!hashedFile) { NS_ERROR("nsIFile is not nsIHashable"); return NULL; } nsCAutoString filePath; aFile->GetNativePath(filePath); NativeLoadData data; if (mLibraries.Get(hashedFile, &data)) { NS_ASSERTION(data.module, "Corrupt mLibraries hash"); LOG(PR_LOG_DEBUG, ("nsNativeModuleLoader::LoadModule(\"%s\") - found in cache", filePath.get())); return data.module; } // We haven't loaded this module before rv = aFile->Load(&data.library); if (NS_FAILED(rv)) { char errorMsg[1024] = "<unknown; can't get error from NSPR>"; if (PR_GetErrorTextLength() < (int) sizeof(errorMsg)) PR_GetErrorText(errorMsg); LOG(PR_LOG_ERROR, ("nsNativeModuleLoader::LoadModule(\"%s\") - load FAILED, " "rv: %lx, error:\n\t%s\n", filePath.get(), rv, errorMsg)); #ifdef DEBUG fprintf(stderr, "nsNativeModuleLoader::LoadModule(\"%s\") - load FAILED, " "rv: %lx, error:\n\t%s\n", filePath.get(), (unsigned long)rv, errorMsg); #endif return NULL; } #ifdef IMPLEMENT_BREAK_AFTER_LOAD nsCAutoString leafName; aFile->GetNativeLeafName(leafName); char *env = getenv("XPCOM_BREAK_ON_LOAD"); char *blist; if (env && *env && (blist = strdup(env))) { char *nextTok = blist; while (char *token = NS_strtok(":", &nextTok)) { if (leafName.Find(token, PR_TRUE) != kNotFound) { NS_BREAK(); } } free(blist); } #endif void *module = PR_FindSymbol(data.library, "NSModule"); if (module) { data.module = *(mozilla::Module const *const *) module; if (mLibraries.Put(hashedFile, data)) return data.module; } else { LOG(PR_LOG_ERROR, ("nsNativeModuleLoader::LoadModule(\"%s\") - " "Symbol NSModule not found", filePath.get())); } // at some point we failed, clean up data.module = nsnull; PR_UnloadLibrary(data.library); return NULL; }
void nsXULPrototypeCache::AbortFastLoads() { #ifdef DEBUG_brendan NS_BREAK(); #endif // Save a strong ref to the FastLoad file, so we can remove it after we // close open streams to it. nsCOMPtr<nsIFile> file = gFastLoadFile; // Flush the XUL cache for good measure, in case we cached a bogus/downrev // script, somehow. Flush(); // Clear the FastLoad set mFastLoadURITable.Clear(); if (! gFastLoadService) return; // Fetch the current input (if FastLoad file existed) or output (if we're // creating the FastLoad file during this app startup) stream. nsCOMPtr<nsIObjectInputStream> objectInput; nsCOMPtr<nsIObjectOutputStream> objectOutput; gFastLoadService->GetInputStream(getter_AddRefs(objectInput)); gFastLoadService->GetOutputStream(getter_AddRefs(objectOutput)); if (objectOutput) { gFastLoadService->SetOutputStream(nsnull); if (NS_SUCCEEDED(objectOutput->Close()) && gChecksumXULFastLoadFile) gFastLoadService->CacheChecksum(gFastLoadFile, objectOutput); } if (objectInput) { // If this is the last of one or more XUL master documents loaded // together at app startup, close the FastLoad service's singleton // input stream now. gFastLoadService->SetInputStream(nsnull); objectInput->Close(); } // Now rename or remove the file. if (file) { #ifdef DEBUG // Remove any existing Aborted.mfasl files generated in previous runs. nsCOMPtr<nsIFile> existingAbortedFile; file->Clone(getter_AddRefs(existingAbortedFile)); if (existingAbortedFile) { existingAbortedFile->SetLeafName(NS_LITERAL_STRING("Aborted.mfasl")); PRBool fileExists = PR_FALSE; existingAbortedFile->Exists(&fileExists); if (fileExists) existingAbortedFile->Remove(PR_FALSE); } file->MoveToNative(nsnull, NS_LITERAL_CSTRING("Aborted.mfasl")); #else file->Remove(PR_FALSE); #endif } // If the list is empty now, the FastLoad process is done. NS_RELEASE(gFastLoadService); NS_RELEASE(gFastLoadFile); }
const mozilla::Module* nsNativeModuleLoader::LoadModule(nsILocalFile* aFile) { nsresult rv; if (!NS_IsMainThread()) { // If this call is off the main thread, synchronously proxy it // to the main thread. nsRefPtr<LoadModuleMainThreadRunnable> r = new LoadModuleMainThreadRunnable(this, aFile); NS_DispatchToMainThread(r, NS_DISPATCH_SYNC); return r->mResult; } nsCOMPtr<nsIHashable> hashedFile(do_QueryInterface(aFile)); if (!hashedFile) { NS_ERROR("nsIFile is not nsIHashable"); return NULL; } nsCAutoString filePath; aFile->GetNativePath(filePath); NativeLoadData data; if (mLibraries.Get(hashedFile, &data)) { NS_ASSERTION(data.module, "Corrupt mLibraries hash"); LOG(PR_LOG_DEBUG, ("nsNativeModuleLoader::LoadModule(\"%s\") - found in cache", filePath.get())); return data.module; } // We haven't loaded this module before rv = aFile->Load(&data.library); if (NS_FAILED(rv)) { char errorMsg[1024] = "<unknown; can't get error from NSPR>"; if (PR_GetErrorTextLength() < (int) sizeof(errorMsg)) PR_GetErrorText(errorMsg); LogMessage("Failed to load native module at path '%s': (%lx) %s", filePath.get(), rv, errorMsg); return NULL; } #ifdef IMPLEMENT_BREAK_AFTER_LOAD nsCAutoString leafName; aFile->GetNativeLeafName(leafName); char *env = getenv("XPCOM_BREAK_ON_LOAD"); char *blist; if (env && *env && (blist = strdup(env))) { char *nextTok = blist; while (char *token = NS_strtok(":", &nextTok)) { if (leafName.Find(token, true) != kNotFound) { NS_BREAK(); } } free(blist); } #endif void *module = PR_FindSymbol(data.library, "NSModule"); if (!module) { LogMessage("Native module at path '%s' doesn't export symbol `NSModule`.", filePath.get()); PR_UnloadLibrary(data.library); return NULL; } data.module = *(mozilla::Module const *const *) module; if (mozilla::Module::kVersion != data.module->mVersion) { LogMessage("Native module at path '%s' is incompatible with this version of Firefox, has version %i, expected %i.", filePath.get(), data.module->mVersion, mozilla::Module::kVersion); PR_UnloadLibrary(data.library); return NULL; } mLibraries.Put(hashedFile, data); // infallible return data.module; }