ReactOS  0.4.15-dev-3187-ge372f2b
NtQueryInformationThread.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API tests
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: Tests for the NtQueryInformationThread API
5  * COPYRIGHT: Copyright 2020 George BiČ™oc <george.bisoc@reactos.org>
6  */
7 
8 #include "precomp.h"
9 #include <internal/ps_i.h>
10 
11 static
12 void
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 }
103 
104 static
105 void
107 {
108  ULONG InfoClass;
109 
110  /* Iterate over the process info classes and begin the tests */
111  for (InfoClass = 0; InfoClass < _countof(PsThreadInfoClass); InfoClass++)
112  {
113  /* The buffer is misaligned */
115  InfoClass,
116  (PVOID)(ULONG_PTR)1,
117  PsThreadInfoClass[InfoClass].RequiredSizeQUERY,
119 
120  /* We query an invalid buffer address */
122  InfoClass,
123  (PVOID)(ULONG_PTR)PsThreadInfoClass[InfoClass].AlignmentQUERY,
124  PsThreadInfoClass[InfoClass].RequiredSizeQUERY,
126 
127  /* The information length is wrong */
129  InfoClass,
130  (PVOID)(ULONG_PTR)PsThreadInfoClass[InfoClass].AlignmentQUERY,
131  PsThreadInfoClass[InfoClass].RequiredSizeQUERY - 1,
133  }
134 }
135 
137 {
140 }
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
KAFFINITY AffinityMask
Definition: compat.h:789
static void Test_ThreadBasicInformationClass(void)
LONG NTSTATUS
Definition: precomp.h:26
HANDLE UniqueProcess
Definition: compat.h:684
#define ok_hex(expression, result)
Definition: atltest.h:94
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
KPRIORITY BasePriority
Definition: compat.h:791
uint32_t ULONG_PTR
Definition: typedefs.h:65
HANDLE WINAPI GetCurrentThread(VOID)
Definition: proc.c:1148
Status
Definition: gdiplustypes.h:24
#define GetProcessHeap()
Definition: compat.h:595
#define trace
Definition: atltest.h:70
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define _countof(array)
Definition: sndvol32.h:68
VOID QuerySetThreadValidator(_In_ ALIGNMENT_PROBE_MODE ValidationMode, _In_ ULONG InfoClassIndex, _In_ PVOID InfoPointer, _In_ ULONG InfoLength, _In_ NTSTATUS ExpectedStatus)
Definition: probelib.c:189
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2624
HANDLE UniqueThread
Definition: compat.h:685
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:187
START_TEST(NtQueryInformationThread)
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define skip(...)
Definition: atltest.h:64
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:183
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
static const INFORMATION_CLASS_INFO PsThreadInfoClass[]
Definition: ps_i.h:360
#define HeapFree(x, y, z)
Definition: compat.h:594
Definition: precomp.h:18
static void Test_ThreadQueryAlignmentProbe(void)