Bug 1896636 - Remove the crash reporter injector r=KrisWright

This was used to inject our crash reporting infrastructure into the Flash
processes and has been unused since Flash support has been removed.

Differential Revision: https://phabricator.services.mozilla.com/D210308
This commit is contained in:
Gabriele Svelto 2024-05-17 09:24:33 +00:00
parent f0b9488bb5
commit f7797d93fe
13 changed files with 13 additions and 852 deletions

View file

@ -389,9 +389,6 @@ bin/libfreebl_64int_3.so
@BINPATH@/@DLL_PREFIX@mozwer@DLL_SUFFIX@
#endif
#endif
#ifdef MOZ_CRASHREPORTER_INJECTOR
@BINPATH@/breakpadinjector.dll
#endif
#endif
; [ minidump-analyzer ]

View file

@ -1,77 +0,0 @@
/* -*- Mode: C++; tab-width: 8; 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 "InjectCrashReporter.h"
#include "nsDirectoryServiceUtils.h"
#include "nsDirectoryServiceDefs.h"
#include "windows/crash_generation/crash_generation_client.h"
#include "nsExceptionHandler.h"
#include "LoadLibraryRemote.h"
#include "nsWindowsHelpers.h"
using CrashReporter::GetChildNotificationPipe;
using google_breakpad::CrashGenerationClient;
namespace mozilla {
InjectCrashRunnable::InjectCrashRunnable(DWORD pid)
: Runnable("InjectCrashRunnable"), mPID(pid) {
nsCOMPtr<nsIFile> dll;
nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(dll));
if (NS_SUCCEEDED(rv)) {
dll->Append(u"breakpadinjector.dll"_ns);
dll->GetPath(mInjectorPath);
}
}
NS_IMETHODIMP
InjectCrashRunnable::Run() {
if (mInjectorPath.IsEmpty()) return NS_OK;
nsAutoHandle hProcess(OpenProcess(
PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_DUP_HANDLE |
PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ,
FALSE, mPID));
if (!hProcess) {
NS_WARNING(
"Unable to open remote process handle for crashreporter injection.");
return NS_OK;
}
void* proc =
LoadRemoteLibraryAndGetAddress(hProcess, mInjectorPath.get(), "Start");
if (!proc) {
NS_WARNING("Unable to inject crashreporter DLL.");
return NS_OK;
}
HANDLE hRemotePipe = CrashGenerationClient::DuplicatePipeToClientProcess(
NS_ConvertASCIItoUTF16(GetChildNotificationPipe()).get(), hProcess);
if (INVALID_HANDLE_VALUE == hRemotePipe) {
NS_WARNING("Unable to duplicate crash reporter pipe to process.");
return NS_OK;
}
nsAutoHandle hThread(CreateRemoteThread(hProcess, nullptr, 0,
(LPTHREAD_START_ROUTINE)proc,
(void*)hRemotePipe, 0, nullptr));
if (!hThread) {
NS_WARNING("Unable to CreateRemoteThread");
// We have to close the remote pipe or else our crash generation client
// will be stuck unable to accept other remote requests.
HANDLE toClose = INVALID_HANDLE_VALUE;
if (DuplicateHandle(hProcess, hRemotePipe, ::GetCurrentProcess(), &toClose,
0, FALSE,
DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
CloseHandle(toClose);
return NS_OK;
}
}
return NS_OK;
}
} // namespace mozilla

View file

@ -1,27 +0,0 @@
/* -*- Mode: C++; tab-width: 8; 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/. */
#ifndef InjectCrashReporter_h
#define InjectCrashReporter_h
#include "nsThreadUtils.h"
#include <windows.h>
namespace mozilla {
class InjectCrashRunnable : public Runnable {
public:
explicit InjectCrashRunnable(DWORD pid);
NS_IMETHOD Run() override;
private:
DWORD mPID;
nsString mInjectorPath;
};
} // Namespace mozilla
#endif

View file

@ -1,459 +0,0 @@
/* 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 __GNUC__
// disable warnings about pointer <-> DWORD conversions
# pragma warning(disable : 4311 4312)
#endif
#ifdef _WIN64
# define POINTER_TYPE ULONGLONG
#else
# define POINTER_TYPE DWORD
#endif
#include <windows.h>
#include <winnt.h>
#include <stdlib.h>
#ifdef DEBUG_OUTPUT
# include <stdio.h>
#endif
#include "nsWindowsHelpers.h"
typedef const unsigned char* FileView;
template <>
class nsAutoRefTraits<FileView> {
public:
typedef FileView RawRef;
static FileView Void() { return nullptr; }
static void Release(RawRef aView) {
if (nullptr != aView) UnmapViewOfFile(aView);
}
};
#ifndef IMAGE_SIZEOF_BASE_RELOCATION
// Vista SDKs no longer define IMAGE_SIZEOF_BASE_RELOCATION!?
# define IMAGE_SIZEOF_BASE_RELOCATION (sizeof(IMAGE_BASE_RELOCATION))
#endif
#include "LoadLibraryRemote.h"
typedef struct {
PIMAGE_NT_HEADERS headers;
unsigned char* localCodeBase;
unsigned char* remoteCodeBase;
HMODULE* modules;
int numModules;
} MEMORYMODULE, *PMEMORYMODULE;
typedef BOOL(WINAPI* DllEntryProc)(HINSTANCE hinstDLL, DWORD fdwReason,
LPVOID lpReserved);
#define GET_HEADER_DICTIONARY(module, idx) \
&(module)->headers->OptionalHeader.DataDirectory[idx]
#ifdef DEBUG_OUTPUT
static void OutputLastError(const char* msg) {
char* tmp;
char* tmpmsg;
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&tmp, 0,
nullptr);
tmpmsg = (char*)LocalAlloc(LPTR, strlen(msg) + strlen(tmp) + 3);
sprintf(tmpmsg, "%s: %s", msg, tmp);
OutputDebugStringA(tmpmsg);
LocalFree(tmpmsg);
LocalFree(tmp);
}
#endif
static void CopySections(const unsigned char* data,
PIMAGE_NT_HEADERS old_headers, PMEMORYMODULE module) {
int i;
unsigned char* codeBase = module->localCodeBase;
unsigned char* dest;
PIMAGE_SECTION_HEADER section = IMAGE_FIRST_SECTION(module->headers);
for (i = 0; i < module->headers->FileHeader.NumberOfSections;
i++, section++) {
dest = codeBase + section->VirtualAddress;
memset(dest, 0, section->Misc.VirtualSize);
if (section->SizeOfRawData) {
memcpy(dest, data + section->PointerToRawData, section->SizeOfRawData);
}
// section->Misc.PhysicalAddress = (POINTER_TYPE) module->remoteCodeBase +
// section->VirtualAddress;
}
}
static bool CopyRegion(HANDLE hRemoteProcess, void* remoteAddress,
void* localAddress, DWORD size, DWORD protect) {
if (size > 0) {
// Copy the data from local->remote and set the memory protection
if (!VirtualAllocEx(hRemoteProcess, remoteAddress, size, MEM_COMMIT,
PAGE_READWRITE))
return false;
if (!WriteProcessMemory(hRemoteProcess, remoteAddress, localAddress, size,
nullptr)) {
#ifdef DEBUG_OUTPUT
OutputLastError("Error writing remote memory.\n");
#endif
return false;
}
DWORD oldProtect;
if (VirtualProtectEx(hRemoteProcess, remoteAddress, size, protect,
&oldProtect) == 0) {
#ifdef DEBUG_OUTPUT
OutputLastError("Error protecting memory page");
#endif
return false;
}
}
return true;
}
// Protection flags for memory pages (Executable, Readable, Writeable)
static int ProtectionFlags[2][2][2] = {
{
// not executable
{PAGE_NOACCESS, PAGE_WRITECOPY},
{PAGE_READONLY, PAGE_READWRITE},
},
{
// executable
{PAGE_EXECUTE, PAGE_EXECUTE_WRITECOPY},
{PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE},
},
};
static bool FinalizeSections(PMEMORYMODULE module, HANDLE hRemoteProcess) {
#ifdef DEBUG_OUTPUT
fprintf(stderr, "Finalizing sections: local base %p, remote base %p\n",
module->localCodeBase, module->remoteCodeBase);
#endif
int i;
int numSections = module->headers->FileHeader.NumberOfSections;
if (numSections < 1) return false;
PIMAGE_SECTION_HEADER section = IMAGE_FIRST_SECTION(module->headers);
// Copy any data before the first section (i.e. the image header)
if (!CopyRegion(hRemoteProcess, module->remoteCodeBase, module->localCodeBase,
section->VirtualAddress, PAGE_READONLY))
return false;
// loop through all sections and change access flags
for (i = 0; i < numSections; i++, section++) {
DWORD protect, size;
int executable = (section->Characteristics & IMAGE_SCN_MEM_EXECUTE) != 0;
int readable = (section->Characteristics & IMAGE_SCN_MEM_READ) != 0;
int writeable = (section->Characteristics & IMAGE_SCN_MEM_WRITE) != 0;
// determine protection flags based on characteristics
protect = ProtectionFlags[executable][readable][writeable];
if (section->Characteristics & IMAGE_SCN_MEM_NOT_CACHED) {
protect |= PAGE_NOCACHE;
}
void* remoteAddress = module->remoteCodeBase + section->VirtualAddress;
void* localAddress = module->localCodeBase + section->VirtualAddress;
// determine size of region
size = section->Misc.VirtualSize;
#ifdef DEBUG_OUTPUT
fprintf(stderr,
"Copying section %s to %p, size %x, executable %i readable %i "
"writeable %i\n",
section->Name, remoteAddress, size, executable, readable,
writeable);
#endif
if (!CopyRegion(hRemoteProcess, remoteAddress, localAddress, size, protect))
return false;
}
return true;
}
static void PerformBaseRelocation(PMEMORYMODULE module, SIZE_T delta) {
DWORD i;
unsigned char* codeBase = module->localCodeBase;
PIMAGE_DATA_DIRECTORY directory =
GET_HEADER_DICTIONARY(module, IMAGE_DIRECTORY_ENTRY_BASERELOC);
if (directory->Size > 0) {
PIMAGE_BASE_RELOCATION relocation =
(PIMAGE_BASE_RELOCATION)(codeBase + directory->VirtualAddress);
for (; relocation->VirtualAddress > 0;) {
unsigned char* dest = codeBase + relocation->VirtualAddress;
unsigned short* relInfo = (unsigned short*)((unsigned char*)relocation +
IMAGE_SIZEOF_BASE_RELOCATION);
for (i = 0;
i < ((relocation->SizeOfBlock - IMAGE_SIZEOF_BASE_RELOCATION) / 2);
i++, relInfo++) {
DWORD* patchAddrHL;
#ifdef _WIN64
ULONGLONG* patchAddr64;
#endif
int type, offset;
// the upper 4 bits define the type of relocation
type = *relInfo >> 12;
// the lower 12 bits define the offset
offset = *relInfo & 0xfff;
switch (type) {
case IMAGE_REL_BASED_ABSOLUTE:
// skip relocation
break;
case IMAGE_REL_BASED_HIGHLOW:
// change complete 32 bit address
patchAddrHL = (DWORD*)(dest + offset);
*patchAddrHL += delta;
break;
#ifdef _WIN64
case IMAGE_REL_BASED_DIR64:
patchAddr64 = (ULONGLONG*)(dest + offset);
*patchAddr64 += delta;
break;
#endif
default:
// printf("Unknown relocation: %d\n", type);
break;
}
}
// advance to next relocation block
relocation = (PIMAGE_BASE_RELOCATION)(((char*)relocation) +
relocation->SizeOfBlock);
}
}
}
static int BuildImportTable(PMEMORYMODULE module) {
int result = 1;
unsigned char* codeBase = module->localCodeBase;
PIMAGE_DATA_DIRECTORY directory =
GET_HEADER_DICTIONARY(module, IMAGE_DIRECTORY_ENTRY_IMPORT);
if (directory->Size > 0) {
PIMAGE_IMPORT_DESCRIPTOR importDesc =
(PIMAGE_IMPORT_DESCRIPTOR)(codeBase + directory->VirtualAddress);
PIMAGE_IMPORT_DESCRIPTOR importEnd =
(PIMAGE_IMPORT_DESCRIPTOR)(codeBase + directory->VirtualAddress +
directory->Size);
for (; importDesc < importEnd && importDesc->Name; importDesc++) {
POINTER_TYPE* thunkRef;
FARPROC* funcRef;
HMODULE handle = GetModuleHandleA((LPCSTR)(codeBase + importDesc->Name));
if (handle == nullptr) {
#if DEBUG_OUTPUT
OutputLastError("Can't load library");
#endif
result = 0;
break;
}
module->modules = (HMODULE*)realloc(
module->modules, (module->numModules + 1) * (sizeof(HMODULE)));
if (module->modules == nullptr) {
result = 0;
break;
}
module->modules[module->numModules++] = handle;
if (importDesc->OriginalFirstThunk) {
thunkRef = (POINTER_TYPE*)(codeBase + importDesc->OriginalFirstThunk);
funcRef = (FARPROC*)(codeBase + importDesc->FirstThunk);
} else {
// no hint table
thunkRef = (POINTER_TYPE*)(codeBase + importDesc->FirstThunk);
funcRef = (FARPROC*)(codeBase + importDesc->FirstThunk);
}
for (; *thunkRef; thunkRef++, funcRef++) {
if (IMAGE_SNAP_BY_ORDINAL(*thunkRef)) {
*funcRef =
(FARPROC)GetProcAddress(handle, (LPCSTR)IMAGE_ORDINAL(*thunkRef));
} else {
PIMAGE_IMPORT_BY_NAME thunkData =
(PIMAGE_IMPORT_BY_NAME)(codeBase + (*thunkRef));
*funcRef = (FARPROC)GetProcAddress(handle, (LPCSTR)&thunkData->Name);
}
if (*funcRef == 0) {
result = 0;
break;
}
}
if (!result) {
break;
}
}
}
return result;
}
static void* MemoryGetProcAddress(PMEMORYMODULE module, const char* name);
void* LoadRemoteLibraryAndGetAddress(HANDLE hRemoteProcess,
const WCHAR* library, const char* symbol) {
// Map the DLL into memory
nsAutoHandle hLibrary(CreateFile(library, GENERIC_READ, FILE_SHARE_READ,
nullptr, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, nullptr));
if (INVALID_HANDLE_VALUE == hLibrary) {
#if DEBUG_OUTPUT
OutputLastError("Couldn't CreateFile the library.\n");
#endif
return nullptr;
}
nsAutoHandle hMapping(
CreateFileMapping(hLibrary, nullptr, PAGE_READONLY, 0, 0, nullptr));
if (!hMapping) {
#if DEBUG_OUTPUT
OutputLastError("Couldn't CreateFileMapping.\n");
#endif
return nullptr;
}
nsAutoRef<FileView> data(
(const unsigned char*)MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0));
if (!data) {
#if DEBUG_OUTPUT
OutputLastError("Couldn't MapViewOfFile.\n");
#endif
return nullptr;
}
SIZE_T locationDelta;
PIMAGE_DOS_HEADER dos_header = (PIMAGE_DOS_HEADER)data.get();
if (dos_header->e_magic != IMAGE_DOS_SIGNATURE) {
#if DEBUG_OUTPUT
OutputDebugStringA("Not a valid executable file.\n");
#endif
return nullptr;
}
PIMAGE_NT_HEADERS old_header =
(PIMAGE_NT_HEADERS)(data + dos_header->e_lfanew);
if (old_header->Signature != IMAGE_NT_SIGNATURE) {
#if DEBUG_OUTPUT
OutputDebugStringA("No PE header found.\n");
#endif
return nullptr;
}
// reserve memory for image of library in this process and the target process
unsigned char* localCode = (unsigned char*)VirtualAlloc(
nullptr, old_header->OptionalHeader.SizeOfImage, MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!localCode) {
#if DEBUG_OUTPUT
OutputLastError("Can't reserve local memory.");
#endif
}
unsigned char* remoteCode = (unsigned char*)VirtualAllocEx(
hRemoteProcess, nullptr, old_header->OptionalHeader.SizeOfImage,
MEM_RESERVE, PAGE_EXECUTE_READ);
if (!remoteCode) {
#if DEBUG_OUTPUT
OutputLastError("Can't reserve remote memory.");
#endif
}
MEMORYMODULE result;
result.localCodeBase = localCode;
result.remoteCodeBase = remoteCode;
result.numModules = 0;
result.modules = nullptr;
// copy PE header to code
memcpy(localCode, dos_header,
dos_header->e_lfanew + old_header->OptionalHeader.SizeOfHeaders);
result.headers =
reinterpret_cast<PIMAGE_NT_HEADERS>(localCode + dos_header->e_lfanew);
// update position
result.headers->OptionalHeader.ImageBase = (POINTER_TYPE)remoteCode;
// copy sections from DLL file block to new memory location
CopySections(data, old_header, &result);
// adjust base address of imported data
locationDelta = (SIZE_T)(remoteCode - old_header->OptionalHeader.ImageBase);
if (locationDelta != 0) {
PerformBaseRelocation(&result, locationDelta);
}
// load required dlls and adjust function table of imports
if (!BuildImportTable(&result)) {
return nullptr;
}
// mark memory pages depending on section headers and release
// sections that are marked as "discardable"
if (!FinalizeSections(&result, hRemoteProcess)) {
return nullptr;
}
return MemoryGetProcAddress(&result, symbol);
}
static void* MemoryGetProcAddress(PMEMORYMODULE module, const char* name) {
unsigned char* localCodeBase = module->localCodeBase;
int idx = -1;
DWORD i, *nameRef;
WORD* ordinal;
PIMAGE_EXPORT_DIRECTORY exports;
PIMAGE_DATA_DIRECTORY directory =
GET_HEADER_DICTIONARY(module, IMAGE_DIRECTORY_ENTRY_EXPORT);
if (directory->Size == 0) {
// no export table found
return nullptr;
}
exports =
(PIMAGE_EXPORT_DIRECTORY)(localCodeBase + directory->VirtualAddress);
if (exports->NumberOfNames == 0 || exports->NumberOfFunctions == 0) {
// DLL doesn't export anything
return nullptr;
}
// search function name in list of exported names
nameRef = (DWORD*)(localCodeBase + exports->AddressOfNames);
ordinal = (WORD*)(localCodeBase + exports->AddressOfNameOrdinals);
for (i = 0; i < exports->NumberOfNames; i++, nameRef++, ordinal++) {
if (stricmp(name, (const char*)(localCodeBase + (*nameRef))) == 0) {
idx = *ordinal;
break;
}
}
if (idx == -1) {
// exported symbol not found
return nullptr;
}
if ((DWORD)idx > exports->NumberOfFunctions) {
// name <-> ordinal number don't match
return nullptr;
}
// AddressOfFunctions contains the RVAs to the "real" functions
return module->remoteCodeBase +
(*(DWORD*)(localCodeBase + exports->AddressOfFunctions + (idx * 4)));
}

View file

@ -1,23 +0,0 @@
/* 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 LoadLibraryRemote_h
#define LoadLibraryRemote_h
#include <windows.h>
/**
* Inject a library into a remote process. This injection has the following
* restrictions:
*
* - The DLL being injected must only depend on kernel32 and user32.
* - The entry point of the DLL is not run. If the DLL uses the CRT, it is
* the responsibility of the caller to make sure that _CRT_INIT is called.
* - There is no support for unloading a library once it has been loaded.
* - The symbol must be a named symbol and not an ordinal.
*/
void* LoadRemoteLibraryAndGetAddress(HANDLE hRemoteProcess,
const WCHAR* library, const char* symbol);
#endif // LoadLibraryRemote_h

View file

@ -1,29 +0,0 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
FINAL_LIBRARY = "breakpadinjector"
for var in ("UNICODE", "UNICODE_", "BREAKPAD_NO_TERMINATE_THREAD"):
DEFINES[var] = True
LOCAL_INCLUDES += [
"/toolkit/crashreporter/breakpad-client",
"/toolkit/crashreporter/google-breakpad/src",
]
include("/toolkit/crashreporter/google-breakpad/src/common/windows/objs.mozbuild")
include("/toolkit/crashreporter/breakpad-client/windows/handler/objs.mozbuild")
include("/toolkit/crashreporter/breakpad-client/windows/crash_generation/objs.mozbuild")
include("/toolkit/crashreporter/breakpad-client/windows/common/objs.mozbuild")
SOURCES += objs_common
SOURCES += objs_crash_generation
SOURCES += objs_handler
SOURCES += objs_client_common
USE_STATIC_LIBS = True
DisableStlWrapping()

View file

@ -1,35 +0,0 @@
/* 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 <windows.h>
#include "windows/handler/exception_handler.h"
using google_breakpad::ExceptionHandler;
using std::wstring;
extern "C" BOOL WINAPI DummyEntryPoint(HINSTANCE instance, DWORD reason,
void* reserved) {
__debugbreak();
return FALSE; // We're being loaded remotely, this shouldn't happen!
}
// support.microsoft.com/kb/94248
extern "C" BOOL WINAPI _CRT_INIT(HINSTANCE hinstDLL, DWORD fdwReason,
LPVOID lpReserved);
extern "C" __declspec(dllexport) DWORD Start(void* context) {
// Because the remote DLL injector does not call DllMain, we have to
// initialize the CRT manually
_CRT_INIT(nullptr, DLL_PROCESS_ATTACH, nullptr);
HANDLE hCrashPipe = reinterpret_cast<HANDLE>(context);
ExceptionHandler* e = new (std::nothrow) ExceptionHandler(
wstring(), nullptr, nullptr, nullptr, ExceptionHandler::HANDLER_ALL,
MiniDumpNormal, hCrashPipe, nullptr);
if (e) e->set_handle_debug_exceptions(true);
return 1;
}

View file

@ -1,27 +0,0 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
SOURCES += [
"injector.cpp",
]
SharedLibrary("breakpadinjector")
include("/ipc/chromium/chromium-config.mozbuild")
LOCAL_INCLUDES += [
"/toolkit/crashreporter/breakpad-client",
"/toolkit/crashreporter/google-breakpad/src",
]
USE_STATIC_LIBS = True
if CONFIG["CC_TYPE"] in ("clang", "gcc"):
LDFLAGS += ["-Wl,-e,_DummyEntryPoint@12"]
else:
LDFLAGS += ["-ENTRY:DummyEntryPoint"]
DisableStlWrapping()

View file

@ -33,9 +33,6 @@ if CONFIG["MOZ_CRASHREPORTER"]:
"mozwer-rust",
]
if CONFIG["MOZ_CRASHREPORTER_INJECTOR"]:
DIRS += ["breakpad-windows-standalone"]
elif CONFIG["OS_ARCH"] == "Darwin":
DIRS += [
"breakpad-client",
@ -77,13 +74,6 @@ if CONFIG["MOZ_CRASHREPORTER"]:
"mozannotation_server",
]
if CONFIG["MOZ_CRASHREPORTER_INJECTOR"]:
DIRS += ["injector"]
UNIFIED_SOURCES += [
"InjectCrashReporter.cpp",
"LoadLibraryRemote.cpp",
]
TEST_DIRS += ["test"]
UNIFIED_SOURCES += [

View file

@ -209,14 +209,6 @@ void OOPInit() {}
const char* GetChildNotificationPipe() { return nullptr; }
#endif
#ifdef MOZ_CRASHREPORTER_INJECTOR
void InjectCrashReporterIntoProcess(DWORD processID,
InjectorCrashCallback* cb) {}
void UnregisterInjectorCallback(DWORD processID) {}
#endif // MOZ_CRASHREPORTER_INJECTOR
bool GetLastRunCrashID(nsAString& id) { return false; }
#if !defined(XP_WIN) && !defined(XP_MACOSX)

View file

@ -91,11 +91,6 @@
# error "Not yet implemented for this platform"
#endif // defined(XP_WIN)
#ifdef MOZ_CRASHREPORTER_INJECTOR
# include "InjectCrashReporter.h"
using mozilla::InjectCrashRunnable;
#endif
#ifdef XP_WIN
# include <filesystem>
#endif
@ -293,26 +288,13 @@ static FileHandle gMagicChildCrashReportFd =
static Mutex* dumpMapLock;
struct ChildProcessData : public nsUint32HashKey {
explicit ChildProcessData(KeyTypePointer aKey)
: nsUint32HashKey(aKey),
sequence(0),
annotations(nullptr),
minidumpOnly(false)
#ifdef MOZ_CRASHREPORTER_INJECTOR
,
callback(nullptr)
#endif
{
}
: nsUint32HashKey(aKey), sequence(0), annotations(nullptr) {}
nsCOMPtr<nsIFile> minidump;
// Each crashing process is assigned an increasing sequence number to
// indicate which process crashed first.
uint32_t sequence;
UniquePtr<AnnotationTable> annotations;
bool minidumpOnly; // If true then no annotations are present
#ifdef MOZ_CRASHREPORTER_INJECTOR
InjectorCrashCallback* callback;
#endif
};
typedef nsTHashtable<ChildProcessData> ChildMinidumpMap;
@ -320,21 +302,6 @@ static ChildMinidumpMap* pidToMinidump;
static uint32_t crashSequence;
static bool OOPInitialized();
#ifdef MOZ_CRASHREPORTER_INJECTOR
static nsIThread* sInjectorThread;
class ReportInjectedCrash : public Runnable {
public:
explicit ReportInjectedCrash(uint32_t pid)
: Runnable("ReportInjectedCrash"), mPID(pid) {}
NS_IMETHOD Run() override;
private:
uint32_t mPID;
};
#endif // MOZ_CRASHREPORTER_INJECTOR
void RecordMainThreadId() {
gMainThreadId =
#if defined(XP_UNIX)
@ -3393,29 +3360,17 @@ static void OnChildProcessDumpRequested(
// add an error to the minidump to highlight this fact.
{
#ifdef MOZ_CRASHREPORTER_INJECTOR
bool runCallback;
#endif
{
MutexAutoLock lock(*dumpMapLock);
ChildProcessData* pd = pidToMinidump->PutEntry(pid);
MOZ_ASSERT(!pd->minidump);
pd->minidump = minidump;
pd->sequence = ++crashSequence;
pd->annotations = MakeUnique<AnnotationTable>();
AnnotationTable& annotations = *(pd->annotations);
AddSharedAnnotations(annotations);
AddChildProcessAnnotations(annotations, child_annotations);
MutexAutoLock lock(*dumpMapLock);
ChildProcessData* pd = pidToMinidump->PutEntry(pid);
MOZ_ASSERT(!pd->minidump);
pd->minidump = minidump;
pd->sequence = ++crashSequence;
pd->annotations = MakeUnique<AnnotationTable>();
AnnotationTable& annotations = *(pd->annotations);
AddSharedAnnotations(annotations);
AddChildProcessAnnotations(annotations, child_annotations);
MaybeAnnotateDumperError(aClientInfo, annotations);
#ifdef MOZ_CRASHREPORTER_INJECTOR
runCallback = nullptr != pd->callback;
#endif
}
#ifdef MOZ_CRASHREPORTER_INJECTOR
if (runCallback) NS_DispatchToMainThread(new ReportInjectedCrash(pid));
#endif
MaybeAnnotateDumperError(aClientInfo, annotations);
}
if (child_annotations) {
@ -3511,13 +3466,6 @@ static void OOPDeinit() {
return;
}
#ifdef MOZ_CRASHREPORTER_INJECTOR
if (sInjectorThread) {
sInjectorThread->Shutdown();
NS_RELEASE(sInjectorThread);
}
#endif
delete crashServer;
crashServer = nullptr;
@ -3544,59 +3492,6 @@ const char* GetChildNotificationPipe() {
}
#endif
#ifdef MOZ_CRASHREPORTER_INJECTOR
void InjectCrashReporterIntoProcess(DWORD processID,
InjectorCrashCallback* cb) {
if (!GetEnabled()) return;
if (!OOPInitialized()) OOPInit();
if (!sInjectorThread) {
if (NS_FAILED(NS_NewNamedThread("CrashRep Inject", &sInjectorThread)))
return;
}
{
MutexAutoLock lock(*dumpMapLock);
ChildProcessData* pd = pidToMinidump->PutEntry(processID);
MOZ_ASSERT(!pd->minidump && !pd->callback);
pd->callback = cb;
pd->minidumpOnly = true;
}
nsCOMPtr<nsIRunnable> r = new InjectCrashRunnable(processID);
sInjectorThread->Dispatch(r, nsIEventTarget::DISPATCH_NORMAL);
}
NS_IMETHODIMP
ReportInjectedCrash::Run() {
// Crash reporting may have been disabled after this method was dispatched
if (!OOPInitialized()) return NS_OK;
InjectorCrashCallback* cb;
{
MutexAutoLock lock(*dumpMapLock);
ChildProcessData* pd = pidToMinidump->GetEntry(mPID);
if (!pd || !pd->callback) return NS_OK;
MOZ_ASSERT(pd->minidump);
cb = pd->callback;
}
cb->OnCrash(mPID);
return NS_OK;
}
void UnregisterInjectorCallback(DWORD processID) {
if (!OOPInitialized()) return;
MutexAutoLock lock(*dumpMapLock);
pidToMinidump->RemoveEntry(processID);
}
#endif // MOZ_CRASHREPORTER_INJECTOR
#if defined(XP_LINUX)
// Parent-side API for children
@ -3696,11 +3591,8 @@ bool TakeMinidumpForChild(uint32_t childPid, nsIFile** dump,
if (!pd) return false;
NS_IF_ADDREF(*dump = pd->minidump);
// Only plugin process minidumps taken using the injector don't have
// annotations.
if (!pd->minidumpOnly) {
aAnnotations = *(pd->annotations);
}
aAnnotations = *(pd->annotations);
if (aSequence) {
*aSequence = pd->sequence;
}

View file

@ -284,28 +284,6 @@ bool CreateMinidumpsAndPair(ProcessHandle aTargetPid,
// Parent-side API for children
const char* GetChildNotificationPipe();
# ifdef MOZ_CRASHREPORTER_INJECTOR
// Inject a crash report client into an arbitrary process, and inform the
// callback object when it crashes. Parent process only.
class InjectorCrashCallback {
public:
InjectorCrashCallback() {}
/**
* Inform the callback of a crash. The client code should call
* TakeMinidumpForChild to remove it from the PID mapping table.
*
* The callback will not be fired if the client has already called
* TakeMinidumpForChild for this process ID.
*/
virtual void OnCrash(DWORD processID) = 0;
};
// This method implies OOPInit
void InjectCrashReporterIntoProcess(DWORD processID, InjectorCrashCallback* cb);
void UnregisterInjectorCallback(DWORD processID);
# endif
#else
// Parent-side API for children

View file

@ -3134,17 +3134,6 @@ with only_when(compile_environment):
when=depends(target)(lambda t: t.os == "GNU" and t.kernel == "Linux"),
)
set_config(
"MOZ_CRASHREPORTER_INJECTOR",
True,
when=depends(target)(lambda t: t.os == "WINNT" and t.bitness == 32),
)
set_define(
"MOZ_CRASHREPORTER_INJECTOR",
True,
when=depends(target)(lambda t: t.os == "WINNT" and t.bitness == 32),
)
# If we have any service that uploads data (and requires data submission
# policy alert), set MOZ_DATA_REPORTING.