Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 creates a | |
|
eroman
2012/09/17 19:23:48
creates --> create
yzshen1
2012/09/17 20:11:03
Done.
| |
| 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. | |
|
eroman
2012/09/17 19:23:48
Good description!
yzshen1
2012/09/17 20:11:03
Thanks!
On 2012/09/17 19:23:48, eroman wrote:
| |
| 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 } | |
| OLD | NEW |