summaryrefslogtreecommitdiffstats
path: root/toolkit/crashreporter/InjectCrashReporter.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/crashreporter/InjectCrashReporter.cpp
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.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 'toolkit/crashreporter/InjectCrashReporter.cpp')
-rw-r--r--toolkit/crashreporter/InjectCrashReporter.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/toolkit/crashreporter/InjectCrashReporter.cpp b/toolkit/crashreporter/InjectCrashReporter.cpp
new file mode 100644
index 0000000000..d9e6d062e5
--- /dev/null
+++ b/toolkit/crashreporter/InjectCrashReporter.cpp
@@ -0,0 +1,77 @@
+/* -*- 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