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
;
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
);
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
,
39 "Unable to open remote process handle for crashreporter injection.");
44 LoadRemoteLibraryAndGetAddress(hProcess
, mInjectorPath
.get(), "Start");
46 NS_WARNING("Unable to inject crashreporter DLL.");
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.");
57 nsAutoHandle
hThread(CreateRemoteThread(hProcess
, nullptr, 0,
58 (LPTHREAD_START_ROUTINE
)proc
,
59 (void*)hRemotePipe
, 0, nullptr));
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
,
68 DUPLICATE_CLOSE_SOURCE
| DUPLICATE_SAME_ACCESS
)) {
77 } // namespace mozilla