LLDB mainline
HostThreadWindows.cpp
Go to the documentation of this file.
1//===-- HostThreadWindows.cpp ---------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "lldb/Utility/Status.h"
11
14
15#include "llvm/ADT/STLExtras.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
20static void __stdcall ExitThreadProxy(ULONG_PTR dwExitCode) {
21 ::ExitThread(dwExitCode);
22}
23
26
29
31
33
35 if (!IsJoinable())
36 return Status(ERROR_INVALID_HANDLE, eErrorTypeWin32);
37
39 DWORD wait_result = ::WaitForSingleObject(m_thread, INFINITE);
40 if (wait_result == WAIT_OBJECT_0) {
41 if (result) {
42 DWORD exit_code = 0;
43 if (::GetExitCodeThread(m_thread, &exit_code))
44 *result = exit_code;
45 else
46 *result = 0;
47 }
48 } else {
49 error = Status(::GetLastError(), eErrorTypeWin32);
50 }
51
52 Reset();
53 return error;
54}
55
57 if (!::QueueUserAPC(&ExitThreadProxy, m_thread, 0))
58 return Status(::GetLastError(), eErrorTypeWin32);
59 return Status();
60}
61
63 return ::GetThreadId(m_thread);
64}
65
72
74 return GetThreadId() == ::GetThreadId(thread);
75}
76
78 struct ThreadBasicInformation {
79 LONG ExitStatus;
80 PVOID TebBaseAddress;
81 struct {
82 HANDLE UniqueProcess;
83 HANDLE UniqueThread;
84 } ClientId;
85 ULONG_PTR AffinityMask;
86 LONG Priority;
87 LONG BasePriority;
88 };
89 using NtQueryInformationThreadFn =
90 LONG(WINAPI *)(HANDLE ThreadHandle, ULONG ThreadInformationClass,
91 PVOID ThreadInformation, ULONG ThreadInformationLength,
92 PULONG ReturnLength);
93
94 static LazyImport<NtQueryInformationThreadFn> s_query_information_thread{
95 L"ntdll.dll", "NtQueryInformationThread"};
96 if (!s_query_information_thread)
98 auto NtQueryInformationThread = *s_query_information_thread;
99
100 HANDLE handle = GetSystemHandle();
101 if (!handle || handle == INVALID_HANDLE_VALUE)
103
104 ThreadBasicInformation info = {};
105 // ThreadInformationClass 0 is ThreadBasicInformation.
106 if (NtQueryInformationThread(handle, 0, &info, sizeof(info), nullptr) < 0)
108 if (!info.TebBaseAddress)
110
111 auto dict = std::make_shared<StructuredData::Dictionary>();
112 dict->AddIntegerItem("teb_address",
113 reinterpret_cast<uint64_t>(info.TebBaseAddress));
114 return dict;
115}
static llvm::raw_ostream & error(Stream &strm)
static void __stdcall ExitThreadProxy(ULONG_PTR dwExitCode)
void * HANDLE
HostNativeThreadBase(const HostNativeThreadBase &)=delete
Status Join(lldb::thread_result_t *result) override
StructuredData::ObjectSP GetExtendedInfo() const override
bool EqualsThread(lldb::thread_t thread) const override
An error handling class.
Definition Status.h:118
std::shared_ptr< Object > ObjectSP
#define LLDB_INVALID_HOST_THREAD
Definition lldb-types.h:69
A class that represents a running process on the host machine.
void * thread_result_t
Definition lldb-types.h:62
@ eErrorTypeWin32
Standard Win32 error codes.
pthread_t thread_t
Definition lldb-types.h:58
uint64_t tid_t
Definition lldb-types.h:85