This source file includes following definitions.
- CrashDumpAndTerminateHungChildProcess
- CrashDumpForHangDebugging
#include "chrome/browser/hang_monitor/hang_crash_dump_win.h"
#include "base/logging.h"
#include "chrome/common/chrome_constants.h"
#include "content/public/common/result_codes.h"
namespace {
static const int kTerminateTimeoutMS = 2000;
static const int kGenerateDumpTimeoutMS = 10000;
}
void CrashDumpAndTerminateHungChildProcess(HANDLE hprocess) {
typedef HANDLE (__cdecl *DumpFunction)(HANDLE);
static DumpFunction request_dump = NULL;
if (!request_dump) {
request_dump = reinterpret_cast<DumpFunction>(GetProcAddress(
GetModuleHandle(chrome::kBrowserProcessExecutableName),
"InjectDumpProcessWithoutCrash"));
DCHECK(request_dump) << "Failed loading DumpProcessWithoutCrash: error " <<
GetLastError();
}
if (request_dump) {
HANDLE remote_thread = request_dump(hprocess);
DCHECK(remote_thread) << "Failed creating remote thread: error " <<
GetLastError();
if (remote_thread) {
WaitForSingleObject(remote_thread, kGenerateDumpTimeoutMS);
CloseHandle(remote_thread);
}
}
TerminateProcess(hprocess, content::RESULT_CODE_HUNG);
WaitForSingleObject(hprocess, kTerminateTimeoutMS);
}
void CrashDumpForHangDebugging(HANDLE hprocess) {
if (hprocess == GetCurrentProcess()) {
typedef void (__cdecl *DumpFunction)();
DumpFunction request_dump = reinterpret_cast<DumpFunction>(GetProcAddress(
GetModuleHandle(chrome::kBrowserProcessExecutableName),
"DumpProcessWithoutCrash"));
DCHECK(request_dump) << "Failed loading DumpProcessWithoutCrash: error " <<
GetLastError();
if (request_dump)
request_dump();
} else {
typedef HANDLE (__cdecl *DumpFunction)(HANDLE);
DumpFunction request_dump = reinterpret_cast<DumpFunction>(GetProcAddress(
GetModuleHandle(chrome::kBrowserProcessExecutableName),
"InjectDumpForHangDebugging"));
DCHECK(request_dump) << "Failed loading InjectDumpForHangDebugging: error "
<< GetLastError();
if (request_dump) {
HANDLE remote_thread = request_dump(hprocess);
DCHECK(remote_thread) << "Failed creating remote thread: error " <<
GetLastError();
if (remote_thread) {
WaitForSingleObject(remote_thread, kGenerateDumpTimeoutMS);
CloseHandle(remote_thread);
}
}
}
}