Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(589)

Side by Side Diff: chrome/browser/hang_monitor/hang_crash_dump_win.cc

Issue 10909241: Generate dumps for relevant renderers when users kill a hung pepper plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Dump&kill in blocking pool instead of on IO thread. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/hang_monitor/hang_crash_dump_win.h" 5 #include "chrome/browser/hang_monitor/hang_crash_dump_win.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/common/chrome_constants.h" 8 #include "chrome/common/chrome_constants.h"
9 #include "content/public/common/result_codes.h" 9 #include "content/public/common/result_codes.h"
10 #include "ppapi/shared_impl/ppapi_message_tracker.h"
10 11
11 namespace { 12 namespace {
12 13
13 // How long do we wait for the terminated thread or process to die (in ms) 14 // How long do we wait for the terminated thread or process to die (in ms)
14 static const int kTerminateTimeoutMS = 2000; 15 static const int kTerminateTimeoutMS = 2000;
15 16
16 // How long do we wait for the crash to be generated (in ms). 17 // How long do we wait for the crash to be generated (in ms).
17 static const int kGenerateDumpTimeoutMS = 10000; 18 static const int kGenerateDumpTimeoutMS = 10000;
18 19
20 DWORD WINAPI DumpIfHandlingPepper(void*) {
21 typedef void (__cdecl *DumpFunction)();
22 if (ppapi::PpapiMessageTracker::GetInstance()->IsHandlingMessage()) {
23 DumpFunction request_dump = reinterpret_cast<DumpFunction>(GetProcAddress(
24 GetModuleHandle(chrome::kBrowserProcessExecutableName),
25 "DumpProcessWithoutCrash"));
26 DCHECK(request_dump) << "Failed loading DumpProcessWithoutCrash: error " <<
27 GetLastError();
28 if (request_dump)
29 request_dump();
30 }
31 return 0;
32 }
33
19 } // namespace 34 } // namespace
20 35
21 void CrashDumpAndTerminateHungChildProcess(HANDLE hprocess) { 36 void CrashDumpAndTerminateHungChildProcess(HANDLE hprocess) {
22 // Before terminating the process we try collecting a dump. Which 37 // Before terminating the process we try collecting a dump. Which
23 // a transient thread in the child process will do for us. 38 // a transient thread in the child process will do for us.
24 typedef HANDLE (__cdecl *DumpFunction)(HANDLE); 39 typedef HANDLE (__cdecl *DumpFunction)(HANDLE);
25 static DumpFunction request_dump = NULL; 40 static DumpFunction request_dump = NULL;
26 if (!request_dump) { 41 if (!request_dump) {
27 request_dump = reinterpret_cast<DumpFunction>(GetProcAddress( 42 request_dump = reinterpret_cast<DumpFunction>(GetProcAddress(
28 GetModuleHandle(chrome::kBrowserProcessExecutableName), 43 GetModuleHandle(chrome::kBrowserProcessExecutableName),
29 "InjectDumpProcessWithoutCrash")); 44 "InjectDumpProcessWithoutCrash"));
30 DCHECK(request_dump) << "Failed loading DumpProcessWithoutCrash: error " << 45 DCHECK(request_dump) << "Failed loading DumpProcessWithoutCrash: error " <<
31 GetLastError(); 46 GetLastError();
32 } 47 }
33 48
34 if (request_dump) { 49 if (request_dump) {
35 HANDLE remote_thread = request_dump(hprocess); 50 HANDLE remote_thread = request_dump(hprocess);
36 DCHECK(remote_thread) << "Failed creating remote thread: error " << 51 DCHECK(remote_thread) << "Failed creating remote thread: error " <<
37 GetLastError(); 52 GetLastError();
38 if (remote_thread) { 53 if (remote_thread) {
39 WaitForSingleObject(remote_thread, kGenerateDumpTimeoutMS); 54 WaitForSingleObject(remote_thread, kGenerateDumpTimeoutMS);
40 CloseHandle(remote_thread); 55 CloseHandle(remote_thread);
41 } 56 }
42 } 57 }
43 58
44 TerminateProcess(hprocess, content::RESULT_CODE_HUNG); 59 TerminateProcess(hprocess, content::RESULT_CODE_HUNG);
45 WaitForSingleObject(hprocess, kTerminateTimeoutMS); 60 WaitForSingleObject(hprocess, kTerminateTimeoutMS);
46 } 61 }
62
63 void CrashDumpIfProcessHandlingPepper(HANDLE hprocess) {
64 // Unlike CrashDumpAndTerminateHungChildProcess() which creates a remote
65 // thread using function pointer relative to chrome.exe, here we create a
66 // remote thread using function pointer relative to chrome.dll. The reason is
67 // that there are separate PpapiMessageTracker singletons for chrome.dll and
68 // chrome.exe (in non-component build). We cannot access the information
69 // collected by PpapiMessageTracker of chrome.dll in chrome.exe.
70 //
71 // This is less safe, because chrome.dll may be loaded at different addresses
72 // in different processes. We could cause crash in that case. However, it
73 // should be rare and we are only doing this temporarily for debugging on the
74 // Canary channel.
75 HANDLE remote_thread = CreateRemoteThread(hprocess, NULL, 0,
76 DumpIfHandlingPepper, 0, 0, NULL);
77 DCHECK(remote_thread) << "Failed creating remote thread: error " <<
78 GetLastError();
79 if (remote_thread) {
80 WaitForSingleObject(remote_thread, kGenerateDumpTimeoutMS);
81 CloseHandle(remote_thread);
82 }
83 }
OLDNEW
« no previous file with comments | « chrome/browser/hang_monitor/hang_crash_dump_win.h ('k') | chrome/browser/ui/hung_plugin_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698