Bug 1888590 - Mark some subtests on trusted-types-event-handlers.html as failing...
[gecko.git] / toolkit / crashreporter / InjectCrashReporter.cpp
blobd9e6d062e535502d898bc659ad24347c5e7e4f23
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "InjectCrashReporter.h"
7 #include "nsDirectoryServiceUtils.h"
8 #include "nsDirectoryServiceDefs.h"
9 #include "windows/crash_generation/crash_generation_client.h"
10 #include "nsExceptionHandler.h"
11 #include "LoadLibraryRemote.h"
12 #include "nsWindowsHelpers.h"
14 using CrashReporter::GetChildNotificationPipe;
15 using google_breakpad::CrashGenerationClient;
17 namespace mozilla {
19 InjectCrashRunnable::InjectCrashRunnable(DWORD pid)
20 : Runnable("InjectCrashRunnable"), mPID(pid) {
21 nsCOMPtr<nsIFile> dll;
22 nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(dll));
23 if (NS_SUCCEEDED(rv)) {
24 dll->Append(u"breakpadinjector.dll"_ns);
25 dll->GetPath(mInjectorPath);
29 NS_IMETHODIMP
30 InjectCrashRunnable::Run() {
31 if (mInjectorPath.IsEmpty()) return NS_OK;
33 nsAutoHandle hProcess(OpenProcess(
34 PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_DUP_HANDLE |
35 PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ,
36 FALSE, mPID));
37 if (!hProcess) {
38 NS_WARNING(
39 "Unable to open remote process handle for crashreporter injection.");
40 return NS_OK;
43 void* proc =
44 LoadRemoteLibraryAndGetAddress(hProcess, mInjectorPath.get(), "Start");
45 if (!proc) {
46 NS_WARNING("Unable to inject crashreporter DLL.");
47 return NS_OK;
50 HANDLE hRemotePipe = CrashGenerationClient::DuplicatePipeToClientProcess(
51 NS_ConvertASCIItoUTF16(GetChildNotificationPipe()).get(), hProcess);
52 if (INVALID_HANDLE_VALUE == hRemotePipe) {
53 NS_WARNING("Unable to duplicate crash reporter pipe to process.");
54 return NS_OK;
57 nsAutoHandle hThread(CreateRemoteThread(hProcess, nullptr, 0,
58 (LPTHREAD_START_ROUTINE)proc,
59 (void*)hRemotePipe, 0, nullptr));
60 if (!hThread) {
61 NS_WARNING("Unable to CreateRemoteThread");
63 // We have to close the remote pipe or else our crash generation client
64 // will be stuck unable to accept other remote requests.
65 HANDLE toClose = INVALID_HANDLE_VALUE;
66 if (DuplicateHandle(hProcess, hRemotePipe, ::GetCurrentProcess(), &toClose,
67 0, FALSE,
68 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
69 CloseHandle(toClose);
70 return NS_OK;
74 return NS_OK;
77 } // namespace mozilla