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 } // namespace |
20 | 20 |
21 void CrashDumpAndTerminateHungChildProcess(HANDLE hprocess) { | 21 void CrashDumpAndTerminateHungChildProcess(HANDLE hprocess) { |
22 // Before terminating the process we try collecting a dump. Which | 22 // Before terminating the process we try collecting a dump. Which |
23 // a transient thread in the child process will do for us. | 23 // a transient thread in the child process will do for us. |
24 typedef HANDLE (__cdecl *DumpFunction)(HANDLE); | 24 typedef HANDLE (__cdecl *DumpFunction)(HANDLE); |
25 static DumpFunction request_dump = NULL; | 25 static DumpFunction request_dump = NULL; |
26 if (!request_dump) { | 26 if (!request_dump) { |
27 request_dump = reinterpret_cast<DumpFunction>(GetProcAddress( | 27 request_dump = reinterpret_cast<DumpFunction>( |
28 GetModuleHandle(chrome::kBrowserProcessExecutableName), | 28 GetProcAddress(GetModuleHandle(chrome::kChromeElfDllName), |
29 "InjectDumpProcessWithoutCrash")); | 29 "InjectDumpProcessWithoutCrash")); |
30 DCHECK(request_dump) << "Failed loading DumpProcessWithoutCrash: error " << | 30 DCHECK(request_dump) << "Failed loading DumpProcessWithoutCrash: error " << |
31 GetLastError(); | 31 GetLastError(); |
32 } | 32 } |
33 | 33 |
34 if (request_dump) { | 34 if (request_dump) { |
35 HANDLE remote_thread = request_dump(hprocess); | 35 HANDLE remote_thread = request_dump(hprocess); |
36 DCHECK(remote_thread) << "Failed creating remote thread: error " << | 36 DCHECK(remote_thread) << "Failed creating remote thread: error " << |
37 GetLastError(); | 37 GetLastError(); |
38 if (remote_thread) { | 38 if (remote_thread) { |
39 WaitForSingleObject(remote_thread, kGenerateDumpTimeoutMS); | 39 WaitForSingleObject(remote_thread, kGenerateDumpTimeoutMS); |
40 CloseHandle(remote_thread); | 40 CloseHandle(remote_thread); |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 TerminateProcess(hprocess, content::RESULT_CODE_HUNG); | 44 TerminateProcess(hprocess, content::RESULT_CODE_HUNG); |
45 WaitForSingleObject(hprocess, kTerminateTimeoutMS); | 45 WaitForSingleObject(hprocess, kTerminateTimeoutMS); |
46 } | 46 } |
47 | 47 |
48 void CrashDumpForHangDebugging(HANDLE hprocess) { | 48 void CrashDumpForHangDebugging(HANDLE hprocess) { |
49 if (hprocess == GetCurrentProcess()) { | 49 if (hprocess == GetCurrentProcess()) { |
50 typedef void (__cdecl *DumpFunction)(); | 50 typedef void (__cdecl *DumpFunction)(); |
51 DumpFunction request_dump = reinterpret_cast<DumpFunction>(GetProcAddress( | 51 DumpFunction request_dump = reinterpret_cast<DumpFunction>(GetProcAddress( |
52 GetModuleHandle(chrome::kBrowserProcessExecutableName), | 52 GetModuleHandle(chrome::kChromeElfDllName), "DumpProcessWithoutCrash")); |
53 "DumpProcessWithoutCrash")); | |
54 DCHECK(request_dump) << "Failed loading DumpProcessWithoutCrash: error " << | 53 DCHECK(request_dump) << "Failed loading DumpProcessWithoutCrash: error " << |
55 GetLastError(); | 54 GetLastError(); |
56 if (request_dump) | 55 if (request_dump) |
57 request_dump(); | 56 request_dump(); |
58 } else { | 57 } else { |
59 typedef HANDLE (__cdecl *DumpFunction)(HANDLE); | 58 typedef HANDLE (__cdecl *DumpFunction)(HANDLE); |
60 DumpFunction request_dump = reinterpret_cast<DumpFunction>(GetProcAddress( | 59 DumpFunction request_dump = reinterpret_cast<DumpFunction>( |
61 GetModuleHandle(chrome::kBrowserProcessExecutableName), | 60 GetProcAddress(GetModuleHandle(chrome::kChromeElfDllName), |
62 "InjectDumpForHangDebugging")); | 61 "InjectDumpForHangDebugging")); |
63 DCHECK(request_dump) << "Failed loading InjectDumpForHangDebugging: error " | 62 DCHECK(request_dump) << "Failed loading InjectDumpForHangDebugging: error " |
64 << GetLastError(); | 63 << GetLastError(); |
65 if (request_dump) { | 64 if (request_dump) { |
66 HANDLE remote_thread = request_dump(hprocess); | 65 HANDLE remote_thread = request_dump(hprocess); |
67 DCHECK(remote_thread) << "Failed creating remote thread: error " << | 66 DCHECK(remote_thread) << "Failed creating remote thread: error " << |
68 GetLastError(); | 67 GetLastError(); |
69 if (remote_thread) { | 68 if (remote_thread) { |
70 WaitForSingleObject(remote_thread, kGenerateDumpTimeoutMS); | 69 WaitForSingleObject(remote_thread, kGenerateDumpTimeoutMS); |
71 CloseHandle(remote_thread); | 70 CloseHandle(remote_thread); |
72 } | 71 } |
73 } | 72 } |
74 } | 73 } |
75 } | 74 } |
OLD | NEW |