ReactOS 0.4.16-dev-2491-g3dc6630
NtQueryInformationThread.c File Reference
#include "precomp.h"
#include <internal/ps_i.h>
Include dependency graph for NtQueryInformationThread.c:

Go to the source code of this file.

Functions

static void Test_ThreadBasicInformationClass (void)
 
static ULONG NTAPI DummyThread (_In_ PVOID Parameter)
 
static void Test_ThreadHideFromDebuggerClass (void)
 
static void Test_ThreadQueryAlignmentProbe (void)
 
 START_TEST (NtQueryInformationThread)
 

Function Documentation

◆ DummyThread()

static ULONG NTAPI DummyThread ( _In_ PVOID  Parameter)
static

Definition at line 106 of file NtQueryInformationThread.c.

108{
109 HANDLE hWaitEvent = (HANDLE)Parameter;
111
112 /* Indefinitely wait for the kill signal */
113 Status = NtWaitForSingleObject(hWaitEvent, FALSE, NULL);
115
117 return Status;
118}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
NTSTATUS NtTerminateThread(IN HANDLE ThreadHandle OPTIONAL, IN NTSTATUS ExitStatus)
Definition: kill.c:1279
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)
PVOID HANDLE
Definition: typedefs.h:73
#define NtCurrentThread()
Definition: winternl.h:5368
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336

Referenced by Test_ThreadHideFromDebuggerClass().

◆ START_TEST()

START_TEST ( NtQueryInformationThread  )

Definition at line 298 of file NtQueryInformationThread.c.

299{
303}
static void Test_ThreadHideFromDebuggerClass(void)
static void Test_ThreadBasicInformationClass(void)
static void Test_ThreadQueryAlignmentProbe(void)

◆ Test_ThreadBasicInformationClass()

static void Test_ThreadBasicInformationClass ( void  )
static

Definition at line 13 of file NtQueryInformationThread.c.

14{
16 PTHREAD_BASIC_INFORMATION ThreadInfoBasic;
18
20 if (!ThreadInfoBasic)
21 {
22 skip("Failed to allocate memory for THREAD_BASIC_INFORMATION!\n");
23 return;
24 }
25
26 /* Everything is NULL */
29 NULL,
30 0,
31 NULL);
33
34 /* Don't give a valid thread handle */
37 ThreadInfoBasic,
39 NULL);
41
42 /* The information length is incorrect */
45 ThreadInfoBasic,
46 0,
47 NULL);
49
50 /* Don't query anything from the function */
53 NULL,
55 NULL);
57
58 /* The buffer is misaligned and length information is wrong */
61 (PVOID)1,
62 0,
63 NULL);
65
66 /* The buffer is misaligned */
69 (PVOID)1,
71 NULL);
73
74 /* The buffer is misaligned, try with an alignment size of 2 */
77 (PVOID)2,
79 NULL);
81
82 /* Query the basic information we need from the thread */
85 ThreadInfoBasic,
89 ok(ReturnedLength != 0, "The size of the buffer pointed by ThreadInformation shouldn't be 0!\n");
90
91 /* Output the thread basic information details */
92 trace("ReturnedLength = %lu\n", ReturnedLength);
93 trace("ThreadInfoBasic->ExitStatus = 0x%08lx\n", ThreadInfoBasic->ExitStatus);
94 trace("ThreadInfoBasic->TebBaseAddress = %p\n", ThreadInfoBasic->TebBaseAddress);
95 trace("ThreadInfoBasic->ClientId.UniqueProcess = %p\n", ThreadInfoBasic->ClientId.UniqueProcess);
96 trace("ThreadInfoBasic->ClientId.UniqueThread = %p\n", ThreadInfoBasic->ClientId.UniqueThread);
97 trace("ThreadInfoBasic->AffinityMask = %lu\n", ThreadInfoBasic->AffinityMask);
98 trace("ThreadInfoBasic->Priority = %li\n", ThreadInfoBasic->Priority);
99 trace("ThreadInfoBasic->BasePriority = %li\n", ThreadInfoBasic->BasePriority);
100
101 HeapFree(GetProcessHeap(), 0, ThreadInfoBasic);
102}
#define ok_hex(expression, result)
Definition: atltest.h:94
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:188
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
@ ThreadBasicInformation
Definition: compat.h:935
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define STATUS_ACCESS_VIOLATION
NTSTATUS NTAPI NtQueryInformationThread(_In_ HANDLE ThreadHandle, _In_ THREADINFOCLASS ThreadInformationClass, _Out_writes_bytes_to_opt_(ThreadInformationLength, *ReturnLength) PVOID ThreadInformation, _In_ ULONG ThreadInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:2899
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
HANDLE UniqueThread
Definition: compat.h:826
HANDLE UniqueProcess
Definition: compat.h:825
KPRIORITY BasePriority
Definition: compat.h:932
KAFFINITY AffinityMask
Definition: compat.h:930
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
HANDLE WINAPI GetCurrentThread(void)
Definition: proc.c:1146

Referenced by START_TEST().

◆ Test_ThreadHideFromDebuggerClass()

static void Test_ThreadHideFromDebuggerClass ( void  )
static

Definition at line 122 of file NtQueryInformationThread.c.

123{
125 HANDLE hWaitEvent = NULL, hThread = NULL;
126 BOOLEAN IsThreadHidden;
127 ULONG UlongData;
129
131 {
132 skip("Skipping test as NtQueryInformationThread(ThreadHideFromDebugger) isn't supported prior to Vista\n");
133 return;
134 }
136
137 Status = NtCreateEvent(&hWaitEvent,
139 NULL,
141 FALSE);
143 ok(hWaitEvent != NULL, "Expected not NULL, got NULL\n");
144 if (!NT_SUCCESS(Status))
145 {
146 skip("Could not create the stop event! (Status 0x%08lx)\n", Status);
147 goto Quit;
148 }
149
150 /* Create the dummy thread and wait for it to start up */
152 NULL,
153 FALSE,
154 0,
155 0,
156 0,
158 (PVOID)hWaitEvent,
159 &hThread,
160 NULL);
162 ok(hThread != NULL, "Expected not NULL, got NULL\n");
163 if (!NT_SUCCESS(Status))
164 {
165 skip("Failed to create the dummy thread (Status 0x%08lx)\n", Status);
166 goto Quit;
167 }
168
169
170 /* Verify that the thread is debuggable by default */
171 IsThreadHidden = 0xCC;
174 &IsThreadHidden,
175 sizeof(IsThreadHidden),
176 NULL);
178 ok_bool_false(IsThreadHidden, "IsThreadHidden is");
179
180 /* Make the thread hidden from the debugger -- The wrong way (1) */
181 IsThreadHidden = TRUE;
184 &IsThreadHidden,
185 sizeof(IsThreadHidden));
186 if (IsWow64)
188 else
190
191 /* The thread is still debuggable */
192 IsThreadHidden = 0xCC;
195 &IsThreadHidden,
196 sizeof(IsThreadHidden),
197 NULL);
199 ok_bool_false(IsThreadHidden, "IsThreadHidden is");
200
201 /* Make the thread hidden from the debugger -- The wrong way (2) */
202 UlongData = TRUE;
205 &UlongData,
206 sizeof(UlongData));
208
209 /* The thread is still debuggable */
210 IsThreadHidden = 0xCC;
213 &IsThreadHidden,
214 sizeof(IsThreadHidden),
215 NULL);
217 ok_bool_false(IsThreadHidden, "IsThreadHidden is");
218
219 /* Make the thread hidden from the debugger -- The wrong way (3) */
220 UlongData = TRUE;
223 &UlongData,
224 sizeof(BOOLEAN));
226
227 /* The thread is still debuggable */
228 IsThreadHidden = 0xCC;
231 &IsThreadHidden,
232 sizeof(IsThreadHidden),
233 NULL);
235 ok_bool_false(IsThreadHidden, "IsThreadHidden is");
236
237 /* Make the thread hidden from the debugger -- This way works! */
240 NULL, 0);
242
243 /* Verify that the thread is now hidden from the debugger */
244 IsThreadHidden = 0xCC;
247 &IsThreadHidden,
248 sizeof(IsThreadHidden),
249 NULL);
251 ok_bool_true(IsThreadHidden, "IsThreadHidden is");
252
253
254 /* Send the kill signal and wait for the thread to terminate */
255 NtSetEvent(hWaitEvent, NULL);
257 /* Close the thread */
260Quit:
261 /* Close the event */
262 if (hWaitEvent)
263 NtClose(hWaitEvent);
264}
static ULONG NTAPI DummyThread(_In_ PVOID Parameter)
#define IsWow64()
Definition: NtReadFile.c:37
unsigned char BOOLEAN
Definition: actypes.h:127
#define GetNTVersion()
Definition: apitest.h:17
#define ok_bool_false(value, desc)
Definition: apitest.h:136
#define ok_bool_true(value, desc)
Definition: apitest.h:135
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
#define TRUE
Definition: types.h:120
@ ThreadHideFromDebugger
Definition: compat.h:952
#define GetCurrentProcess()
Definition: compat.h:759
#define IsWow64Process
Definition: compat.h:760
unsigned int BOOL
Definition: ntddk_ex.h:94
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
NTSYSAPI NTSTATUS NTAPI RtlCreateUserThread(_In_ PVOID ThreadContext, _Out_ HANDLE *OutThreadHandle, _Reserved_ PVOID Reserved1, _Reserved_ PVOID Reserved2, _Reserved_ PVOID Reserved3, _Reserved_ PVOID Reserved4, _Reserved_ PVOID Reserved5, _Reserved_ PVOID Reserved6, _Reserved_ PVOID Reserved7, _Reserved_ PVOID Reserved8)
HANDLE hThread
Definition: wizard.c:28
#define NtCurrentProcess()
Definition: nt_native.h:1660
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
@ NotificationEvent
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:463
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:96
NTSTATUS NTAPI NtSetInformationThread(_In_ HANDLE ThreadHandle, _In_ THREADINFOCLASS ThreadInformationClass, _In_reads_bytes_(ThreadInformationLength) PVOID ThreadInformation, _In_ ULONG ThreadInformationLength)
Definition: query.c:2269
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25

Referenced by START_TEST().

◆ Test_ThreadQueryAlignmentProbe()

static void Test_ThreadQueryAlignmentProbe ( void  )
static

Definition at line 268 of file NtQueryInformationThread.c.

269{
270 ULONG InfoClass;
271
272 /* Iterate over the process info classes and begin the tests */
273 for (InfoClass = 0; InfoClass < _countof(PsThreadInfoClass); InfoClass++)
274 {
275 /* The buffer is misaligned */
277 InfoClass,
278 (PVOID)(ULONG_PTR)1,
279 PsThreadInfoClass[InfoClass].RequiredSizeQUERY,
281
282 /* We query an invalid buffer address */
284 InfoClass,
285 (PVOID)(ULONG_PTR)PsThreadInfoClass[InfoClass].AlignmentQUERY,
286 PsThreadInfoClass[InfoClass].RequiredSizeQUERY,
288
289 /* The information length is wrong */
291 InfoClass,
292 (PVOID)(ULONG_PTR)PsThreadInfoClass[InfoClass].AlignmentQUERY,
293 PsThreadInfoClass[InfoClass].RequiredSizeQUERY - 1,
295 }
296}
@ QUERY
Definition: precomp.h:18
VOID QuerySetThreadValidator(_In_ ALIGNMENT_PROBE_MODE ValidationMode, _In_ ULONG InfoClassIndex, _In_ PVOID InfoPointer, _In_ ULONG InfoLength, _In_ NTSTATUS ExpectedStatus)
Definition: probelib.c:259
static const INFORMATION_CLASS_INFO PsThreadInfoClass[]
Definition: ps_i.h:362
#define _countof(array)
Definition: sndvol32.h:70
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by START_TEST().