| 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 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // How long do we wait for the terminated thread or process to die (in ms) | 13 // How long do we wait for the terminated thread or process to die (in ms) |
| 14 static const int kTerminateTimeoutMS = 2000; | 14 static const int kTerminateTimeoutMS = 2000; |
| 15 | 15 |
| 16 // How long do we wait for the crash to be generated (in ms). | 16 // How long do we wait for the crash to be generated (in ms). |
| 17 static const int kGenerateDumpTimeoutMS = 10000; | 17 static const int kGenerateDumpTimeoutMS = 10000; |
| 18 | 18 |
| 19 } // namespace | 19 typedef HANDLE (__cdecl *DumpFunction)(HANDLE); |
| 20 | 20 |
| 21 void CrashDumpAndTerminateHungChildProcess(HANDLE hprocess) { | 21 void RunDumpFunction(HANDLE hprocess, DumpFunction request_dump) { |
| 22 // Before terminating the process we try collecting a dump. Which | 22 // Try collecting a dump. Which a transient thread in the child process will |
| 23 // a transient thread in the child process will do for us. | 23 // do for us. |
| 24 typedef HANDLE (__cdecl *DumpFunction)(HANDLE); | |
| 25 static DumpFunction request_dump = NULL; | |
| 26 if (!request_dump) { | |
| 27 request_dump = reinterpret_cast<DumpFunction>(GetProcAddress( | |
| 28 GetModuleHandle(chrome::kBrowserProcessExecutableName), | |
| 29 "InjectDumpProcessWithoutCrash")); | |
| 30 DCHECK(request_dump) << "Failed loading DumpProcessWithoutCrash: error " << | |
| 31 GetLastError(); | |
| 32 } | |
| 33 | |
| 34 if (request_dump) { | 24 if (request_dump) { |
| 35 HANDLE remote_thread = request_dump(hprocess); | 25 HANDLE remote_thread = request_dump(hprocess); |
| 36 DCHECK(remote_thread) << "Failed creating remote thread: error " << | 26 DCHECK(remote_thread) << "Failed creating remote thread: error " << |
| 37 GetLastError(); | 27 GetLastError(); |
| 38 if (remote_thread) { | 28 if (remote_thread) { |
| 39 WaitForSingleObject(remote_thread, kGenerateDumpTimeoutMS); | 29 WaitForSingleObject(remote_thread, kGenerateDumpTimeoutMS); |
| 40 CloseHandle(remote_thread); | 30 CloseHandle(remote_thread); |
| 41 } | 31 } |
| 42 } | 32 } |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
| 37 void CrashDumpAndTerminateHungChildProcess(HANDLE hprocess) { |
| 38 static DumpFunction request_dump = NULL; |
| 39 if (!request_dump) { |
| 40 request_dump = reinterpret_cast<DumpFunction>(GetProcAddress( |
| 41 GetModuleHandle(chrome::kBrowserProcessExecutableName), |
| 42 "InjectDumpProcessWithoutCrash")); |
| 43 DCHECK(request_dump) << "Failed loading DumpProcessWithoutCrash: error " << |
| 44 GetLastError(); |
| 45 } |
| 46 RunDumpFunction(hprocess, request_dump); |
| 43 | 47 |
| 44 TerminateProcess(hprocess, content::RESULT_CODE_HUNG); | 48 TerminateProcess(hprocess, content::RESULT_CODE_HUNG); |
| 45 WaitForSingleObject(hprocess, kTerminateTimeoutMS); | 49 WaitForSingleObject(hprocess, kTerminateTimeoutMS); |
| 46 } | 50 } |
| 51 |
| 52 void CrashDumpProcessHandlingPepper(HANDLE hprocess) { |
| 53 static DumpFunction request_dump = NULL; |
| 54 if (!request_dump) { |
| 55 request_dump = reinterpret_cast<DumpFunction>(GetProcAddress( |
| 56 GetModuleHandle(chrome::kBrowserProcessExecutableName), |
| 57 "InjectDumpProcessHandlingPepper")); |
| 58 DCHECK(request_dump) << "Failed loading DumpProcessHandlingPepper: error " |
| 59 << GetLastError(); |
| 60 } |
| 61 RunDumpFunction(hprocess, request_dump); |
| 62 } |
| OLD | NEW |