diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp index dff07aa3f8c0..24b89ce1aa9a 100644 --- a/js/xpconnect/src/XPCShellImpl.cpp +++ b/js/xpconnect/src/XPCShellImpl.cpp @@ -1063,14 +1063,16 @@ int XRE_XPCShellMain(int argc, char** argv, char** envp, PR_SetEnv("MOZ_DISABLE_ASAN_REPORTER=1"); #endif - if (PR_GetEnv("MOZ_CHAOSMODE")) { + if (auto* featureStr = PR_GetEnv("MOZ_CHAOSMODE")) { ChaosFeature feature = ChaosFeature::Any; - long featureInt = strtol(PR_GetEnv("MOZ_CHAOSMODE"), nullptr, 16); + long featureInt = strtol(featureStr, nullptr, 16); if (featureInt) { // NOTE: MOZ_CHAOSMODE=0 or a non-hex value maps to Any feature. feature = static_cast(featureInt); } ChaosMode::SetChaosFeature(feature); + ChaosMode::enterChaosMode(); + MOZ_ASSERT(ChaosMode::isActive(ChaosFeature::Any)); } if (ChaosMode::isActive(ChaosFeature::Any)) { diff --git a/mfbt/ChaosMode.cpp b/mfbt/ChaosMode.cpp index d090e8a37e92..b2a6fd40d440 100644 --- a/mfbt/ChaosMode.cpp +++ b/mfbt/ChaosMode.cpp @@ -10,8 +10,8 @@ namespace mozilla { namespace detail { -Atomic gChaosModeCounter(0); -ChaosFeature gChaosFeatures = None; +Atomic gChaosModeCounter(0); +ChaosFeature gChaosFeatures = ChaosFeature::Any; } /* namespace detail */ } /* namespace mozilla */ diff --git a/mfbt/ChaosMode.h b/mfbt/ChaosMode.h index faf7acddf391..145a75e38000 100644 --- a/mfbt/ChaosMode.h +++ b/mfbt/ChaosMode.h @@ -37,7 +37,7 @@ enum ChaosFeature { }; namespace detail { -extern MFBT_DATA Atomic gChaosModeCounter; +extern MFBT_DATA Atomic gChaosModeCounter; extern MFBT_DATA ChaosFeature gChaosFeatures; } // namespace detail @@ -53,17 +53,13 @@ class ChaosMode { } static bool isActive(ChaosFeature aFeature) { - if (detail::gChaosModeCounter > 0) { - return true; - } - return detail::gChaosFeatures & aFeature; + return detail::gChaosModeCounter > 0 && (detail::gChaosFeatures & aFeature); } /** * Increase the chaos mode activation level. An equivalent number of * calls to leaveChaosMode must be made in order to restore the original - * chaos mode state. If the activation level is nonzero all chaos mode - * features are activated. + * chaos mode state. */ static void enterChaosMode() { detail::gChaosModeCounter++; } diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index dd2021fbe478..f2b5d666fe23 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -3999,14 +3999,16 @@ int XREMain::XRE_mainInit(bool* aExitFlag) { } #endif // ANDROID - if (PR_GetEnv("MOZ_CHAOSMODE")) { + if (auto* featureStr = PR_GetEnv("MOZ_CHAOSMODE")) { ChaosFeature feature = ChaosFeature::Any; - long featureInt = strtol(PR_GetEnv("MOZ_CHAOSMODE"), nullptr, 16); + long featureInt = strtol(featureStr, nullptr, 16); if (featureInt) { // NOTE: MOZ_CHAOSMODE=0 or a non-hex value maps to Any feature. feature = static_cast(featureInt); } ChaosMode::SetChaosFeature(feature); + ChaosMode::enterChaosMode(); + MOZ_ASSERT(ChaosMode::isActive(ChaosFeature::Any)); } if (CheckArgExists("fxr")) {