summaryrefslogtreecommitdiffstats
path: root/mfbt/Assertions.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
commit9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /mfbt/Assertions.cpp
parentInitial commit. (diff)
downloadthunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.tar.xz
thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mfbt/Assertions.cpp')
-rw-r--r--mfbt/Assertions.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/mfbt/Assertions.cpp b/mfbt/Assertions.cpp
new file mode 100644
index 0000000000..7721677f19
--- /dev/null
+++ b/mfbt/Assertions.cpp
@@ -0,0 +1,52 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#include "mozilla/Assertions.h"
+#include "mozilla/Atomics.h"
+#include "mozilla/Sprintf.h"
+
+#include <stdarg.h>
+
+MOZ_BEGIN_EXTERN_C
+
+/*
+ * The crash reason is defined as a global variable here rather than in the
+ * crash reporter itself to make it available to all code, even libraries like
+ * JS that don't link with the crash reporter directly. This value will only
+ * be consumed if the crash reporter is used by the target application.
+ */
+MFBT_DATA const char* gMozCrashReason = nullptr;
+
+static char sPrintfCrashReason[sPrintfCrashReasonSize] = {};
+
+// Accesses to this atomic are not included in web replay recordings, so that
+// if we crash in an area where recorded events are not allowed the true reason
+// for the crash is not obscured by a record/replay error.
+static mozilla::Atomic<bool, mozilla::SequentiallyConsistent> sCrashing(false);
+
+MFBT_API MOZ_COLD MOZ_NEVER_INLINE MOZ_FORMAT_PRINTF(1, 2) const
+ char* MOZ_CrashPrintf(const char* aFormat, ...) {
+ if (!sCrashing.compareExchange(false, true)) {
+ // In the unlikely event of a race condition, skip
+ // setting the crash reason and just crash safely.
+ MOZ_RELEASE_ASSERT(false);
+ }
+ va_list aArgs;
+ va_start(aArgs, aFormat);
+ int ret = VsprintfLiteral(sPrintfCrashReason, aFormat, aArgs);
+ va_end(aArgs);
+ MOZ_RELEASE_ASSERT(
+ ret >= 0 && size_t(ret) < sPrintfCrashReasonSize,
+ "Could not write the explanation string to the supplied buffer!");
+ return sPrintfCrashReason;
+}
+
+MOZ_END_EXTERN_C
+
+MFBT_API MOZ_NORETURN MOZ_COLD void mozilla::detail::InvalidArrayIndex_CRASH(
+ size_t aIndex, size_t aLength) {
+ MOZ_CRASH_UNSAFE_PRINTF("ElementAt(aIndex = %zu, aLength = %zu)", aIndex,
+ aLength);
+}