forked from OSchip/llvm-project
Fix HostProcessWindows for D120321
This commit is contained in:
parent
27d9a58407
commit
82951cfb8a
|
@ -34,8 +34,6 @@ public:
|
|||
bool monitor_signals) override;
|
||||
|
||||
private:
|
||||
static lldb::thread_result_t MonitorThread(void *thread_arg);
|
||||
|
||||
void Close();
|
||||
|
||||
bool m_owns_handle;
|
||||
|
|
|
@ -63,38 +63,36 @@ bool HostProcessWindows::IsRunning() const {
|
|||
return (code == STILL_ACTIVE);
|
||||
}
|
||||
|
||||
static lldb::thread_result_t
|
||||
MonitorThread(const Host::MonitorChildProcessCallback &callback,
|
||||
HANDLE process_handle) {
|
||||
DWORD exit_code;
|
||||
|
||||
::WaitForSingleObject(process_handle, INFINITE);
|
||||
::GetExitCodeProcess(process_handle, &exit_code);
|
||||
callback(::GetProcessId(process_handle), true, 0, exit_code);
|
||||
::CloseHandle(process_handle);
|
||||
return {};
|
||||
}
|
||||
|
||||
llvm::Expected<HostThread> HostProcessWindows::StartMonitoring(
|
||||
const Host::MonitorChildProcessCallback &callback, bool monitor_signals) {
|
||||
MonitorInfo *info = new MonitorInfo;
|
||||
info->callback = callback;
|
||||
HANDLE process_handle;
|
||||
|
||||
// Since the life of this HostProcessWindows instance and the life of the
|
||||
// process may be different, duplicate the handle so that the monitor thread
|
||||
// can have ownership over its own copy of the handle.
|
||||
if (::DuplicateHandle(GetCurrentProcess(), m_process, GetCurrentProcess(),
|
||||
&info->process_handle, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
|
||||
return ThreadLauncher::LaunchThread("ChildProcessMonitor",
|
||||
HostProcessWindows::MonitorThread,
|
||||
info);
|
||||
&process_handle, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
|
||||
return ThreadLauncher::LaunchThread(
|
||||
"ChildProcessMonitor", [callback, process_handle] {
|
||||
return MonitorThread(callback, process_handle);
|
||||
});
|
||||
} else {
|
||||
return llvm::errorCodeToError(llvm::mapWindowsError(GetLastError()));
|
||||
}
|
||||
}
|
||||
|
||||
lldb::thread_result_t HostProcessWindows::MonitorThread(void *thread_arg) {
|
||||
DWORD exit_code;
|
||||
|
||||
MonitorInfo *info = static_cast<MonitorInfo *>(thread_arg);
|
||||
if (info) {
|
||||
::WaitForSingleObject(info->process_handle, INFINITE);
|
||||
::GetExitCodeProcess(info->process_handle, &exit_code);
|
||||
info->callback(::GetProcessId(info->process_handle), true, 0, exit_code);
|
||||
::CloseHandle(info->process_handle);
|
||||
delete (info);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void HostProcessWindows::Close() {
|
||||
if (m_owns_handle && m_process != LLDB_INVALID_PROCESS)
|
||||
::CloseHandle(m_process);
|
||||
|
|
Loading…
Reference in New Issue