summaryrefslogtreecommitdiffstats
path: root/xpcom/base/IntentionalCrash.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /xpcom/base/IntentionalCrash.h
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xpcom/base/IntentionalCrash.h')
-rw-r--r--xpcom/base/IntentionalCrash.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/xpcom/base/IntentionalCrash.h b/xpcom/base/IntentionalCrash.h
new file mode 100644
index 0000000000..6c1f3496c8
--- /dev/null
+++ b/xpcom/base/IntentionalCrash.h
@@ -0,0 +1,68 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_IntentionalCrash_h
+#define mozilla_IntentionalCrash_h
+
+#include <string>
+#include <sstream>
+#include <stdlib.h>
+#include <stdio.h>
+
+#ifdef XP_WIN
+# include <process.h>
+# define getpid _getpid
+#else
+# include <unistd.h>
+#endif
+
+namespace mozilla {
+
+inline void NoteIntentionalCrash(const char* aProcessType) {
+// In opt builds we don't actually have the leak checking enabled, and the
+// sandbox doesn't allow writing to this path, so we just disable this
+// function's behaviour.
+#ifdef MOZ_DEBUG
+ char* f = getenv("XPCOM_MEM_BLOAT_LOG");
+ if (!f) {
+ return;
+ }
+
+ fprintf(stderr, "XPCOM_MEM_BLOAT_LOG: %s\n", f);
+
+ std::ostringstream bloatName;
+ std::string processType(aProcessType);
+ if (!processType.compare("default")) {
+ bloatName << f;
+ } else {
+ std::string bloatLog(f);
+
+ bool hasExt = false;
+ if (bloatLog.size() >= 4 &&
+ bloatLog.compare(bloatLog.size() - 4, 4, ".log", 4) == 0) {
+ hasExt = true;
+ bloatLog.erase(bloatLog.size() - 4, 4);
+ }
+
+ bloatName << bloatLog << "_" << processType << "_pid" << getpid();
+ if (hasExt) {
+ bloatName << ".log";
+ }
+ }
+
+ fprintf(stderr, "Writing to log: %s\n", bloatName.str().c_str());
+
+ FILE* processfd = fopen(bloatName.str().c_str(), "a");
+ if (processfd) {
+ fprintf(processfd, "==> process %d will purposefully crash\n", getpid());
+ fclose(processfd);
+ }
+#endif
+}
+
+} // namespace mozilla
+
+#endif // mozilla_IntentionalCrash_h