Skip to content

Commit 07344f8

Browse files
committed
Bug 1868304 - Add temporary code in Nightly to diagnose SetReservedClientInfo assertion. r=pbone,dom-worker-reviewers,asuth
To help investigate the crash in bug 1761208, this patch adds code to register the top frames of the call stack when reservedClientInfo is set, such that it can be recovered from crash dumps. We only add this code for Nightly Windows x64 builds because we get a Nightly crash on this assertion for almost every Nightly build, always coming from Windows x64. So this should be enough and there is no need to impact other builds. This code only needs to live for a few Nightly builds and can/should be removed once we have caught the faulty call stack. Differential Revision: https://phabricator.services.mozilla.com/D195525
1 parent 432aa01 commit 07344f8

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

netwerk/base/LoadInfo.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "mozilla/dom/WindowGlobalParent.h"
2323
#include "mozilla/net/CookieJarSettings.h"
2424
#include "mozilla/NullPrincipal.h"
25+
#include "mozilla/StackWalk.h"
2526
#include "mozilla/StaticPrefs_network.h"
2627
#include "mozilla/StaticPrefs_security.h"
2728
#include "mozIThirdPartyUtil.h"
@@ -50,6 +51,23 @@ using namespace mozilla::dom;
5051

5152
namespace mozilla::net {
5253

54+
#if defined(NIGHTLY_BUILD) && defined(XP_WIN) && defined(_M_X64)
55+
/* static */ void LoadInfo::StackTrace::StackWalkCallback(uint32_t aFrameNumber,
56+
void* aPc, void* aSp,
57+
void* aClosure) {
58+
StackTrace* st = (StackTrace*)aClosure;
59+
MOZ_ASSERT(st->mLength < kMaxFrames);
60+
st->mPcs[st->mLength] = aPc;
61+
st->mLength++;
62+
MOZ_ASSERT(st->mLength == aFrameNumber);
63+
}
64+
65+
void LoadInfo::StackTrace::Fill() {
66+
mLength = 0;
67+
MozStackWalk(StackWalkCallback, nullptr, kMaxFrames, this);
68+
}
69+
#endif // NIGHTLY_BUILD && XP_WIN && _M_X64
70+
5371
static nsCString CurrentRemoteType() {
5472
MOZ_ASSERT(XRE_IsParentProcess() || XRE_IsContentProcess());
5573
if (ContentChild* cc = ContentChild::GetSingleton()) {
@@ -773,6 +791,11 @@ LoadInfo::LoadInfo(
773791
mHasInjectedCookieForCookieBannerHandling(
774792
aHasInjectedCookieForCookieBannerHandling),
775793
mWasSchemelessInput(aWasSchemelessInput) {
794+
#if defined(NIGHTLY_BUILD) && defined(XP_WIN) && defined(_M_X64)
795+
if (mReservedClientInfo.isSome()) {
796+
mReservedClientInfoEmplaceTrace.Fill();
797+
}
798+
#endif // NIGHTLY_BUILD && XP_WIN && _M_X64
776799
// Only top level TYPE_DOCUMENT loads can have a null loadingPrincipal
777800
MOZ_ASSERT(mLoadingPrincipal ||
778801
aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT);
@@ -2126,6 +2149,15 @@ UniquePtr<ClientSource> LoadInfo::TakeReservedClientSource() {
21262149
return std::move(mReservedClientSource);
21272150
}
21282151

2152+
#if defined(NIGHTLY_BUILD) && defined(XP_WIN) && defined(_M_X64)
2153+
[[clang::optnone]] MOZ_NEVER_INLINE static void CrashWithEmplaceTrace(
2154+
const LoadInfo::StackTrace& aEmplaceStackTrace) {
2155+
// Make a copy of the stack trace available on the crashing thread's stack
2156+
LoadInfo::StackTrace emplaceStackTrace [[maybe_unused]]{aEmplaceStackTrace};
2157+
MOZ_CRASH("mReservedClientInfo already set, emplace stack trace available");
2158+
}
2159+
#endif // NIGHTLY_BUILD && XP_WIN && _M_X64
2160+
21292161
void LoadInfo::SetReservedClientInfo(const ClientInfo& aClientInfo) {
21302162
MOZ_DIAGNOSTIC_ASSERT(mInitialClientInfo.isNothing());
21312163
// Treat assignments of the same value as a no-op. The emplace below
@@ -2134,10 +2166,16 @@ void LoadInfo::SetReservedClientInfo(const ClientInfo& aClientInfo) {
21342166
if (mReservedClientInfo.ref() == aClientInfo) {
21352167
return;
21362168
}
2169+
#if defined(NIGHTLY_BUILD) && defined(XP_WIN) && defined(_M_X64)
2170+
CrashWithEmplaceTrace(mReservedClientInfoEmplaceTrace);
2171+
#endif // NIGHTLY_BUILD && XP_WIN && _M_X64
21372172
MOZ_DIAGNOSTIC_ASSERT(false, "mReservedClientInfo already set");
21382173
mReservedClientInfo.reset();
21392174
}
21402175
mReservedClientInfo.emplace(aClientInfo);
2176+
#if defined(NIGHTLY_BUILD) && defined(XP_WIN) && defined(_M_X64)
2177+
mReservedClientInfoEmplaceTrace.Fill();
2178+
#endif // NIGHTLY_BUILD && XP_WIN && _M_X64
21412179
}
21422180

21432181
void LoadInfo::OverrideReservedClientInfoInParent(
@@ -2148,6 +2186,9 @@ void LoadInfo::OverrideReservedClientInfoInParent(
21482186
mInitialClientInfo.reset();
21492187
mReservedClientInfo.reset();
21502188
mReservedClientInfo.emplace(aClientInfo);
2189+
#if defined(NIGHTLY_BUILD) && defined(XP_WIN) && defined(_M_X64)
2190+
mReservedClientInfoEmplaceTrace.Fill();
2191+
#endif // NIGHTLY_BUILD && XP_WIN && _M_X64
21512192
}
21522193

21532194
const Maybe<ClientInfo>& LoadInfo::GetReservedClientInfo() {

netwerk/base/LoadInfo.h

+26
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,32 @@ class LoadInfo final : public nsILoadInfo {
305305
Maybe<mozilla::dom::ClientInfo> mClientInfo;
306306
UniquePtr<mozilla::dom::ClientSource> mReservedClientSource;
307307
Maybe<mozilla::dom::ClientInfo> mReservedClientInfo;
308+
309+
// Diagnostics code for bug 1761208
310+
#if defined(NIGHTLY_BUILD) && defined(XP_WIN) && defined(_M_X64)
311+
public:
312+
class StackTrace {
313+
public:
314+
static const size_t kMaxFrames = 24;
315+
316+
// The number of PCs in the stack trace.
317+
size_t mLength;
318+
319+
// The PCs in the stack trace. Only the first mLength are initialized.
320+
const void* mPcs[kMaxFrames];
321+
322+
public:
323+
void Fill();
324+
325+
private:
326+
static void StackWalkCallback(uint32_t aFrameNumber, void* aPc, void* aSp,
327+
void* aClosure);
328+
};
329+
330+
private:
331+
StackTrace mReservedClientInfoEmplaceTrace;
332+
#endif // NIGHTLY_BUILD && XP_WIN && _M_X64
333+
308334
Maybe<mozilla::dom::ClientInfo> mInitialClientInfo;
309335
Maybe<mozilla::dom::ServiceWorkerDescriptor> mController;
310336
RefPtr<mozilla::dom::PerformanceStorage> mPerformanceStorage;

0 commit comments

Comments
 (0)