Backed out 2 changesets (bug 1682520) for causing build bustages on ProcessType.h CLOSED TREE

Backed out changeset 679e19334225 (bug 1682520)
Backed out changeset dad72c7e0d7b (bug 1682520)
This commit is contained in:
Cristian Tuns 2022-07-29 17:04:49 -04:00
Родитель 8f722351cf
Коммит 85e845a6dc
12 изменённых файлов: 92 добавлений и 295 удалений

Просмотреть файл

@ -9,8 +9,6 @@
#include "XREShellData.h"
#include "application.ini.h"
#include "mozilla/Bootstrap.h"
#include "mozilla/ProcessType.h"
#include "mozilla/RuntimeExceptionModule.h"
#if defined(XP_WIN)
# include <windows.h>
# include <stdlib.h>
@ -30,7 +28,6 @@
# include "freestanding/SharedSection.h"
# include "LauncherProcessWin.h"
# include "mozilla/GeckoArgs.h"
# include "mozilla/mscom/ProcessRuntime.h"
# include "mozilla/WindowsDllBlocklist.h"
# include "mozilla/WindowsDpiInitialization.h"
# include "mozilla/WindowsProcessMitigations.h"
@ -298,15 +295,6 @@ int main(int argc, char* argv[], char* envp[]) {
// We are launching as a content process, delegate to the appropriate
// main
if (argc > 1 && IsArg(argv[1], "contentproc")) {
// Set the process type. We don't remove the arg here as that will be done
// later in common code.
SetGeckoProcessType(argv[argc - 1]);
// Register an external module to report on otherwise uncatchable
// exceptions. Note that in child processes this must be called after Gecko
// process type has been set.
CrashReporter::RegisterRuntimeExceptionModule();
# ifdef HAS_DLL_BLOCKLIST
uint32_t initFlags =
gBlocklistInitFlags | eDllBlocklistInitFlagIsChildProcess;
@ -368,9 +356,6 @@ int main(int argc, char* argv[], char* envp[]) {
}
#endif
// Register an external module to report on otherwise uncatchable exceptions.
CrashReporter::RegisterRuntimeExceptionModule();
#ifdef HAS_DLL_BLOCKLIST
DllBlocklist_Initialize(gBlocklistInitFlags);
#endif

Просмотреть файл

@ -7,7 +7,6 @@
#include "../contentproc/plugin-container.cpp"
#include "mozilla/Bootstrap.h"
#include "mozilla/RuntimeExceptionModule.h"
#if defined(XP_WIN)
# include "mozilla/WindowsDllBlocklist.h"
# include "mozilla/GeckoArgs.h"
@ -67,15 +66,6 @@ int main(int argc, char* argv[]) {
if (UseForkServer(argc, argv)) {
ret = RunForkServer(std::move(bootstrap), argc, argv);
} else {
// Set the process type. We don't remove the arg here as that will be done
// later in common code.
SetGeckoProcessType(argv[argc - 1]);
// Register an external module to report on otherwise uncatchable
// exceptions. Note that in child processes this must be called after Gecko
// process type has been set.
CrashReporter::RegisterRuntimeExceptionModule();
#ifdef HAS_DLL_BLOCKLIST
uint32_t initFlags = eDllBlocklistInitFlagIsChildProcess;
# if defined(MOZ_SANDBOX)

Просмотреть файл

@ -1,58 +0,0 @@
/* -*- 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/. */
#include "ProcessType.h"
#include <cstring>
#include "mozilla/Assertions.h"
using namespace mozilla::startup;
namespace mozilla {
namespace startup {
GeckoProcessType sChildProcessType = GeckoProcessType_Default;
} // namespace startup
void SetGeckoProcessType(const char* aProcessTypeString) {
#if !defined(DEBUG)
// If not a DEBUG build then just return if sChildProcessType has already been
// set and is not fork server. In DEBUG builds we will check that process type
// matches the one already set if it is not fork server.
if (sChildProcessType != GeckoProcessType_Default &&
sChildProcessType != GeckoProcessType_ForkServer) {
return;
}
#endif
#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
process_bin_type, procinfo_typename, \
webidl_typename, allcaps_name) \
if (std::strcmp(aProcessTypeString, string_name) == 0) { \
MOZ_ASSERT_IF( \
sChildProcessType != GeckoProcessType_Default && \
sChildProcessType != GeckoProcessType_ForkServer, \
sChildProcessType == GeckoProcessType::GeckoProcessType_##enum_name); \
sChildProcessType = GeckoProcessType::GeckoProcessType_##enum_name; \
return; \
}
#define SKIP_PROCESS_TYPE_DEFAULT
#if !defined(MOZ_ENABLE_FORKSERVER)
# define SKIP_PROCESS_TYPE_FORKSERVER
#endif
#if !defined(ENABLE_TESTS)
# define SKIP_PROCESS_TYPE_IPDLUNITTEST
#endif
#include "mozilla/GeckoProcessTypes.h"
#undef SKIP_PROCESS_TYPE_IPDLUNITTEST
#undef SKIP_PROCESS_TYPE_FORKSERVER
#undef SKIP_PROCESS_TYPE_DEFAULT
#undef GECKO_PROCESS_TYPE
MOZ_CRASH("aProcessTypeString is not valid.");
}
} // namespace mozilla

Просмотреть файл

@ -1,44 +0,0 @@
/* -*- 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 IPC_PROCESSTYPE_H_
#define IPC_PROCESSTYPE_H_
#include "mozilla/Attributes.h"
#include "mozilla/Types.h"
// This enum is not dense. See GeckoProcessTypes.h for details.
enum GeckoProcessType {
#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
process_bin_type, procinfo_typename, \
webidl_typename, allcaps_name) \
GeckoProcessType_##enum_name = (enum_value),
#include "mozilla/GeckoProcessTypes.h"
#undef GECKO_PROCESS_TYPE
GeckoProcessType_End,
GeckoProcessType_Invalid = GeckoProcessType_End
};
namespace mozilla {
namespace startup {
extern MFBT_DATA GeckoProcessType sChildProcessType;
} // namespace startup
/**
* @return the GeckoProcessType of the current process.
*/
MFBT_API MOZ_ALWAYS_INLINE GeckoProcessType GetGeckoProcessType() {
return startup::sChildProcessType;
}
/**
* Set the gecko process type based on a null-terminated byte string.
*/
MFBT_API void SetGeckoProcessType(const char* aProcessTypeString);
} // namespace mozilla
#endif // IPC_PROCESSTYPE_H_

Просмотреть файл

@ -1,117 +0,0 @@
/* -*- 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/. */
#include "RuntimeExceptionModule.h"
#include <cstdint>
#include "mozilla/ProcessType.h"
#if defined(XP_WIN)
# include <windows.h>
# if defined(__MINGW32__) || defined(__MINGW64__)
// Add missing constants and types for mingw builds
# define HREPORT HANDLE
# define PWER_SUBMIT_RESULT WER_SUBMIT_RESULT*
# define WER_MAX_PREFERRED_MODULES_BUFFER (256)
# define WER_FAULT_REPORTING_DISABLE_SNAPSHOT_HANG (256)
# endif // defined(__MINGW32__) || defined(__MINGW64__)
# include <werapi.h> // For WerRegisterRuntimeExceptionModule()
# include <stdlib.h>
# include "mozilla/mozalloc_oom.h"
# include "mozilla/Unused.h"
using mozilla::Unused;
#endif
namespace CrashReporter {
#ifdef XP_WIN
struct InProcessWindowsErrorReportingData {
uint32_t mProcessType;
size_t* mOOMAllocationSizePtr;
};
static InProcessWindowsErrorReportingData gInProcessWerData;
const static size_t kModulePathLength = MAX_PATH + 1;
static wchar_t sModulePath[kModulePathLength];
bool GetRuntimeExceptionModulePath(wchar_t* aPath, const size_t aLength) {
const wchar_t* kModuleName = L"mozwer.dll";
DWORD res = ::GetModuleFileNameW(nullptr, aPath, aLength);
if ((res > 0) && (res != aLength)) {
wchar_t* last_backslash = wcsrchr(aPath, L'\\');
if (last_backslash) {
*(last_backslash + 1) = L'\0';
if (wcscat_s(aPath, aLength, kModuleName) == 0) {
return true;
}
}
}
return false;
}
#endif // XP_WIN
void RegisterRuntimeExceptionModule() {
#ifdef XP_WIN
# if defined(DEBUG)
// In debug builds, disable the crash reporter by default, and allow to
// enable it with the MOZ_CRASHREPORTER environment variable.
const char* envvar = getenv("MOZ_CRASHREPORTER");
if (!envvar || !*envvar) {
return;
}
# else
// In other builds, enable the crash reporter by default, and allow
// disabling it with the MOZ_CRASHREPORTER_DISABLE environment variable.
const char* envvar = getenv("MOZ_CRASHREPORTER_DISABLE");
if (envvar && *envvar) {
return;
}
# endif
// If sModulePath is set we have already registerd the module.
if (*sModulePath) {
return;
}
// If we fail to get the path just return.
if (!GetRuntimeExceptionModulePath(sModulePath, kModulePathLength)) {
return;
}
gInProcessWerData.mProcessType = mozilla::GetGeckoProcessType();
gInProcessWerData.mOOMAllocationSizePtr = &gOOMAllocationSize;
if (FAILED(::WerRegisterRuntimeExceptionModule(sModulePath,
&gInProcessWerData))) {
// The registration failed null out sModulePath to record this.
*sModulePath = L'\0';
return;
}
DWORD dwFlags = 0;
if (WerGetFlags(GetCurrentProcess(), &dwFlags) == S_OK) {
Unused << WerSetFlags(dwFlags | WER_FAULT_REPORTING_DISABLE_SNAPSHOT_HANG);
}
#endif // XP_WIN
}
void UnregisterRuntimeExceptionModule() {
#ifdef XP_WIN
// If sModulePath is set then we have registered the module.
if (*sModulePath) {
Unused << ::WerUnregisterRuntimeExceptionModule(sModulePath,
&gInProcessWerData);
*sModulePath = L'\0';
}
#endif // XP_WIN
}
} // namespace CrashReporter

Просмотреть файл

@ -1,20 +0,0 @@
/* -*- 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 RUNTIMEEXCEPTIONMODULE_H_
#define RUNTIMEEXCEPTIONMODULE_H_
#include "mozilla/Types.h"
namespace CrashReporter {
MFBT_API void RegisterRuntimeExceptionModule();
MFBT_API void UnregisterRuntimeExceptionModule();
} // namespace CrashReporter
#endif // RUNTIMEEXCEPTIONMODULE_H_

Просмотреть файл

@ -48,17 +48,6 @@ SOURCES += [
"Uptime.cpp",
]
if not CONFIG["JS_STANDALONE"]:
EXPORTS.mozilla += [
"ProcessType.h",
"RuntimeExceptionModule.h",
]
SOURCES += [
"ProcessType.cpp",
"RuntimeExceptionModule.cpp",
]
OS_LIBS += CONFIG["REALTIME_LIBS"]
if CONFIG["OS_ARCH"] == "WINNT":

Просмотреть файл

@ -20,7 +20,6 @@
#include "mozilla/Unused.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/Printf.h"
#include "mozilla/RuntimeExceptionModule.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/Sprintf.h"
#include "mozilla/StaticMutex.h"
@ -54,6 +53,14 @@
# include "mozilla/WindowsDllBlocklist.h"
# include "mozilla/WindowsVersion.h"
# include "psapi.h" // For PERFORMANCE_INFORMATION and K32GetPerformanceInfo()
# if defined(__MINGW32__) || defined(__MINGW64__)
// Add missing constants and types for mingw builds
# define HREPORT HANDLE
# define PWER_SUBMIT_RESULT WER_SUBMIT_RESULT*
# define WER_MAX_PREFERRED_MODULES_BUFFER (256)
# define WER_FAULT_REPORTING_DISABLE_SNAPSHOT_HANG (256)
# endif // defined(__MINGW32__) || defined(__MINGW64__)
# include "werapi.h" // For WerRegisterRuntimeExceptionModule()
#elif defined(XP_MACOSX)
# include "breakpad-client/mac/crash_generation/client_info.h"
# include "breakpad-client/mac/crash_generation/crash_generation_server.h"
@ -1924,6 +1931,53 @@ static void TeardownAnnotationFacilities() {
notesField = nullptr;
}
#ifdef XP_WIN
struct InProcessWindowsErrorReportingData {
uint32_t mProcessType;
size_t* mOOMAllocationSizePtr;
};
static InProcessWindowsErrorReportingData gInProcessWerData = {};
bool GetRuntimeExceptionModulePath(wchar_t* aPath, const size_t aLength) {
const wchar_t* kModuleName = L"mozwer.dll";
DWORD res = GetModuleFileName(nullptr, aPath, aLength);
if ((res > 0) && (res != aLength)) {
wchar_t* last_backslash = wcsrchr(aPath, L'\\');
if (last_backslash) {
*(last_backslash + 1) = L'\0';
if (wcscat_s(aPath, aLength, kModuleName) == 0) {
return true;
}
}
}
return false;
}
#endif // XP_WIN
static void RegisterRuntimeExceptionModule(
GeckoProcessType aProcessType =
GeckoProcessType::GeckoProcessType_Default) {
#ifdef XP_WIN
gInProcessWerData.mProcessType = aProcessType;
gInProcessWerData.mOOMAllocationSizePtr = &gOOMAllocationSize;
const size_t kPathLength = MAX_PATH + 1;
wchar_t path[kPathLength] = {};
if (GetRuntimeExceptionModulePath(path, kPathLength)) {
Unused << WerRegisterRuntimeExceptionModule(path, &gInProcessWerData);
DWORD dwFlags = 0;
if (WerGetFlags(GetCurrentProcess(), &dwFlags) == S_OK) {
Unused << WerSetFlags(dwFlags |
WER_FAULT_REPORTING_DISABLE_SNAPSHOT_HANG);
}
}
#endif // XP_WIN
}
nsresult SetExceptionHandler(nsIFile* aXREDirectory, bool force /*=false*/) {
if (gExceptionHandler) return NS_ERROR_ALREADY_INITIALIZED;
@ -3491,7 +3545,7 @@ bool CreateNotificationPipeForChild(int* childCrashFd, int* childCrashRemapFd) {
bool SetRemoteExceptionHandler(const char* aCrashPipe,
FileHandle aCrashTimeAnnotationFile) {
MOZ_ASSERT(!gExceptionHandler, "crash client already init'd");
RegisterRuntimeExceptionModule();
RegisterRuntimeExceptionModule(XRE_GetProcessType());
InitializeAnnotationFacilities();
#if defined(XP_WIN)

Просмотреть файл

@ -21,9 +21,7 @@
#include "mozilla/Poison.h"
#include "mozilla/Preferences.h"
#include "mozilla/Printf.h"
#include "mozilla/ProcessType.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/RuntimeExceptionModule.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/StaticPrefs_browser.h"
#include "mozilla/StaticPrefs_fission.h"
@ -4197,11 +4195,6 @@ int XREMain::XRE_mainInit(bool* aExitFlag) {
SaveWordToEnv("MOZ_CRASHREPORTER_STRINGS_OVERRIDE", overridePath);
}
}
} else {
// We might have registered a runtime exception module very early in process
// startup to catch early crashes. This is before we have access to ini file
// data, so unregister here if it turns out the crash reporter is disabled.
CrashReporter::UnregisterRuntimeExceptionModule();
}
#if defined(MOZ_SANDBOX) && defined(XP_WIN)
@ -6017,7 +6010,9 @@ nsresult XRE_DeinitCommandLine() {
return rv;
}
GeckoProcessType XRE_GetProcessType() { return GetGeckoProcessType(); }
GeckoProcessType XRE_GetProcessType() {
return mozilla::startup::sChildProcessType;
}
const char* XRE_GetProcessTypeString() {
return XRE_GeckoProcessTypeToString(XRE_GetProcessType());

Просмотреть файл

@ -139,6 +139,8 @@ namespace mozilla {
namespace startup {
Result<nsCOMPtr<nsIFile>, nsresult> GetIncompleteStartupFile(nsIFile* aProfLD);
extern GeckoProcessType sChildProcessType;
void IncreaseDescriptorLimits();
} // namespace startup

Просмотреть файл

@ -36,7 +36,6 @@
#include "nsAppRunner.h"
#include "nsExceptionHandler.h"
#include "mozilla/RuntimeExceptionModule.h"
#include "nsThreadUtils.h"
#include "nsJSUtils.h"
#include "nsWidgetsCID.h"
@ -68,7 +67,6 @@
#include "mozilla/AbstractThread.h"
#include "mozilla/FilePreferences.h"
#include "mozilla/IOInterposer.h"
#include "mozilla/ProcessType.h"
#include "mozilla/RDDProcessImpl.h"
#include "mozilla/ipc/UtilityProcessImpl.h"
#include "mozilla/UniquePtr.h"
@ -255,6 +253,10 @@ const char* XRE_ChildProcessTypeToAnnotation(GeckoProcessType aProcessType) {
}
}
namespace mozilla::startup {
GeckoProcessType sChildProcessType = GeckoProcessType_Default;
} // namespace mozilla::startup
#if defined(MOZ_WIDGET_ANDROID)
void XRE_SetAndroidChildFds(JNIEnv* env, const XRE_AndroidChildFds& fds) {
mozilla::jni::SetGeckoThreadEnv(env);
@ -267,7 +269,21 @@ void XRE_SetAndroidChildFds(JNIEnv* env, const XRE_AndroidChildFds& fds) {
#endif // defined(MOZ_WIDGET_ANDROID)
void XRE_SetProcessType(const char* aProcessTypeString) {
SetGeckoProcessType(aProcessTypeString);
static bool called = false;
if (called && sChildProcessType != GeckoProcessType_ForkServer) {
MOZ_CRASH();
}
called = true;
sChildProcessType = [&] {
for (GeckoProcessType t :
MakeEnumeratedRange(GeckoProcessType::GeckoProcessType_End)) {
if (!strcmp(XRE_GeckoProcessTypeToString(t), aProcessTypeString)) {
return t;
}
}
return GeckoProcessType_Invalid;
}();
#ifdef MOZ_MEMORY
// For the parent process, we're probably willing to accept an apparent
@ -490,12 +506,6 @@ nsresult XRE_InitChildProcess(int aArgc, char* aArgv[],
// Bug 684322 will add better visibility into this condition
NS_WARNING("Could not setup crash reporting\n");
}
} else {
// We might have registered a runtime exception module very early in
// process startup to catch early crashes. This is before we process the
// crash reporter arg, so unregister here if it turns out the crash
// reporter is disabled.
CrashReporter::UnregisterRuntimeExceptionModule();
}
}

Просмотреть файл

@ -9,7 +9,6 @@
#include "js/TypeDecls.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/ProcessType.h"
#include "mozilla/TimeStamp.h"
#include "nscore.h"
@ -340,6 +339,18 @@ void XRE_TermEmbedding();
*/
nsresult XRE_ParseAppData(nsIFile* aINIFile, mozilla::XREAppData& aAppData);
// This enum is not dense. See GeckoProcessTypes.h for details.
enum GeckoProcessType {
#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
process_bin_type, procinfo_typename, \
webidl_typename, allcaps_name) \
GeckoProcessType_##enum_name = enum_value,
#include "mozilla/GeckoProcessTypes.h"
#undef GECKO_PROCESS_TYPE
GeckoProcessType_End,
GeckoProcessType_Invalid = GeckoProcessType_End
};
const char* XRE_GeckoProcessTypeToString(GeckoProcessType aProcessType);
const char* XRE_ChildProcessTypeToAnnotation(GeckoProcessType aProcessType);