Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include <string> |
michael@0 | 6 | #include <sstream> |
michael@0 | 7 | #include <stdlib.h> |
michael@0 | 8 | #include <stdio.h> |
michael@0 | 9 | |
michael@0 | 10 | #ifdef XP_WIN |
michael@0 | 11 | #include <process.h> |
michael@0 | 12 | #define getpid _getpid |
michael@0 | 13 | #else |
michael@0 | 14 | #include <unistd.h> |
michael@0 | 15 | #endif |
michael@0 | 16 | |
michael@0 | 17 | #ifndef mozilla_IntentionalCrash_h |
michael@0 | 18 | #define mozilla_IntentionalCrash_h |
michael@0 | 19 | |
michael@0 | 20 | namespace mozilla { |
michael@0 | 21 | |
michael@0 | 22 | inline void |
michael@0 | 23 | NoteIntentionalCrash(const char* processType) |
michael@0 | 24 | { |
michael@0 | 25 | char* f = getenv("XPCOM_MEM_BLOAT_LOG"); |
michael@0 | 26 | |
michael@0 | 27 | if (!f) |
michael@0 | 28 | return; |
michael@0 | 29 | |
michael@0 | 30 | fprintf(stderr, "XPCOM_MEM_BLOAT_LOG: %s\n", f); |
michael@0 | 31 | |
michael@0 | 32 | std::string bloatLog(f); |
michael@0 | 33 | |
michael@0 | 34 | bool hasExt = false; |
michael@0 | 35 | if (bloatLog.size() >= 4 && |
michael@0 | 36 | 0 == bloatLog.compare(bloatLog.size() - 4, 4, ".log", 4)) { |
michael@0 | 37 | hasExt = true; |
michael@0 | 38 | bloatLog.erase(bloatLog.size() - 4, 4); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | std::ostringstream bloatName; |
michael@0 | 42 | bloatName << bloatLog << "_" << processType << "_pid" << getpid(); |
michael@0 | 43 | if (hasExt) |
michael@0 | 44 | bloatName << ".log"; |
michael@0 | 45 | |
michael@0 | 46 | fprintf(stderr, "Writing to log: %s\n", bloatName.str().c_str()); |
michael@0 | 47 | |
michael@0 | 48 | FILE* processfd = fopen(bloatName.str().c_str(), "a"); |
michael@0 | 49 | fprintf(processfd, "==> process %d will purposefully crash\n", getpid()); |
michael@0 | 50 | fclose(processfd); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | } // namespace mozilla |
michael@0 | 54 | |
michael@0 | 55 | #endif // mozilla_IntentionalCrash_h |