ReactOS  r75400
kmt_test_kernel.h
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS kernel-mode tests
3  * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4  * PURPOSE: Kernel-Mode Test Suite test framework declarations
5  * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #ifndef _KMTEST_TEST_KERNEL_H_
9 #define _KMTEST_TEST_KERNEL_H_
10 
11 #if !defined _KMTEST_TEST_H_
12 #error include kmt_test.h instead of including kmt_test_kernel.h
13 #endif /* !defined _KMTEST_TEST_H_ */
14 
18 {
19  "Create",
20  "CreateNamedPipe",
21  "Close",
22  "Read",
23  "Write",
24  "QueryInformation",
25  "SetInformation",
26  "QueryEa",
27  "SetEa",
28  "FlushBuffers",
29  "QueryVolumeInformation",
30  "SetVolumeInformation",
31  "DirectoryControl",
32  "FileSystemControl",
33  "DeviceControl",
34  "InternalDeviceControl/Scsi",
35  "Shutdown",
36  "LockControl",
37  "Cleanup",
38  "CreateMailslot",
39  "QuerySecurity",
40  "SetSecurity",
41  "Power",
42  "SystemControl",
43  "DeviceChange",
44  "QueryQuota",
45  "SetQuota",
46  "Pnp/PnpPower"
47 };
48 
50 {
52  if (Irql > NewIrql)
53  KeLowerIrql(NewIrql);
54  else if (Irql < NewIrql)
55  KeRaiseIrql(NewIrql, &Irql);
56 }
57 
59 {
60  return (__readeflags() & (1 << 9)) != 0;
61 }
62 
63 typedef struct _POOL_HEADER
64 {
65  union
66  {
67  struct
68  {
69 #ifdef _M_AMD64
71  USHORT PoolIndex:8;
72  USHORT BlockSize:8;
73  USHORT PoolType:8;
74 #else
79 #endif
80  };
82  };
83 #ifdef _M_AMD64
84  ULONG PoolTag;
85 #endif
86  union
87  {
88 #ifdef _M_AMD64
89  PEPROCESS ProcessBilled;
90 #else
92 #endif
93  struct
94  {
97  };
98  };
100 
102 {
103  PPOOL_HEADER Header;
104 
105  /* it's not so easy for allocations of PAGE_SIZE */
106  if (((ULONG_PTR)Memory & (PAGE_SIZE - 1)) == 0)
107  return 'TooL';
108 
109  Header = Memory;
110  Header--;
111 
112  return Header->PoolTag;
113 }
114 
116 {
117  PPOOL_HEADER Header;
118 
119  /* it's not so easy for allocations of PAGE_SIZE */
120  if (((ULONG_PTR)Memory & (PAGE_SIZE - 1)) == 0)
121  return 0;
122 
123  Header = Memory;
124  Header--;
125 
126  return Header->PoolType;
127 }
128 
130 {
131  UNICODE_STRING RoutineNameString;
132  RtlInitUnicodeString(&RoutineNameString, (PWSTR)RoutineName);
133  return MmGetSystemRoutineAddress(&RoutineNameString);
134 }
135 
137 {
140  HANDLE ThreadHandle;
142 
143  InitializeObjectAttributes(&ObjectAttributes,
144  NULL,
146  NULL,
147  NULL);
148  ThreadHandle = INVALID_HANDLE_VALUE;
149  Status = PsCreateSystemThread(&ThreadHandle,
150  SYNCHRONIZE,
151  &ObjectAttributes,
152  NULL,
153  NULL,
154  StartRoutine,
155  StartContext);
156  ok_eq_hex(Status, STATUS_SUCCESS);
157  if (!skip(NT_SUCCESS(Status) && ThreadHandle != NULL && ThreadHandle != INVALID_HANDLE_VALUE, "No thread\n"))
158  {
159  Status = ObReferenceObjectByHandle(ThreadHandle,
160  SYNCHRONIZE,
161  *PsThreadType,
162  KernelMode,
163  &ThreadObject,
164  NULL);
165  ok_eq_hex(Status, STATUS_SUCCESS);
166  ObCloseHandle(ThreadHandle, KernelMode);
167  }
168  return ThreadObject;
169 }
170 
172 {
174 
175  if (skip(Thread != NULL, "No thread\n"))
176  return;
177 
178  if (Event)
180  Status = KeWaitForSingleObject(Thread,
181  Executive,
182  KernelMode,
183  FALSE,
184  NULL);
185  ok_eq_hex(Status, STATUS_SUCCESS);
187 }
188 
189 INT __cdecl KmtVSNPrintF(PSTR Buffer, SIZE_T BufferMaxLength, PCSTR Format, va_list Arguments) KMT_FORMAT(ms_printf, 3, 0);
190 
191 #endif /* !defined _KMTEST_TEST_KERNEL_H_ */
DWORD *typedef PVOID
Definition: winlogon.h:52
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define STATUS_SUCCESS
Definition: contextmenu.cpp:55
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
const uint16_t * PCWSTR
Definition: typedefs.h:56
#define IN
Definition: typedefs.h:39
INT __cdecl KmtVSNPrintF(PSTR Buffer, SIZE_T BufferMaxLength, PCSTR Format, va_list Arguments) KMT_FORMAT(ms_printf
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
PCSTR KmtMajorFunctionNames[]
#define TRUE
Definition: types.h:120
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL)
USHORT PoolTagHash
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define __cdecl
Definition: accygwin.h:78
_In_ ULONG _In_opt_ POBJECT_ATTRIBUTES _In_opt_ HANDLE _Out_opt_ PCLIENT_ID _In_ PKSTART_ROUTINE StartRoutine
Definition: psfuncs.h:87
const char * PCSTR
Definition: typedefs.h:52
PVOID *typedef PWSTR
Definition: winlogon.h:57
struct _POOL_HEADER POOL_HEADER
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_Out_ PKIRQL Irql
Definition: csq.h:179
int32_t INT
Definition: typedefs.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:64
UCHAR KIRQL
Definition: env_spec_w32.h:591
BOOLEAN KmtIsCheckedBuild
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:388
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1456
#define FALSE
Definition: types.h:117
KSTART_ROUTINE * PKSTART_ROUTINE
Definition: ketypes.h:472
Definition: Header.h:8
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3452
USHORT AllocatorBackTraceIndex
smooth NULL
Definition: ftsmooth.c:513
VOID KmtSetIrql(IN KIRQL NewIrql)
BOOLEAN KmtIsMultiProcessorBuild
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
struct _POOL_HEADER * PPOOL_HEADER
unsigned char BOOLEAN
ACPI_EFI_MEMORY_TYPE UINTN ACPI_EFI_PHYSICAL_ADDRESS * Memory
Definition: acefiex.h:525
#define KMT_FORMAT(type, fmt, first)
Definition: kmt_test.h:163
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
PVOID KmtGetSystemRoutineAddress(IN PCWSTR RoutineName)
USHORT KmtGetPoolType(PVOID Memory)
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3369
POBJECT_TYPE PsThreadType
Definition: thread.c:20
IN REFCLSID IN PUNKNOWN IN POOL_TYPE PoolType
Definition: unknown.h:68
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define SYNCHRONIZE
Definition: nt_native.h:61
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL)
Status
Definition: gdiplustypes.h:24
BOOLEAN KmtAreInterruptsEnabled(VOID)
ULONG_PTR SIZE_T
Definition: typedefs.h:79
#define NT_SUCCESS(StatCode)
Definition: cmd.c:149
DWORD *typedef HANDLE
Definition: winlogon.h:52
LONG NTSTATUS
Definition: DriverTester.h:11
USHORT PreviousSize
unsigned short USHORT
Definition: pedump.c:61
ULONG KmtGetPoolTag(PVOID Memory)
#define skip(...)
Definition: CString.cpp:57
signed char * PSTR
Definition: retypes.h:7
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ok_eq_hex(value, expected)
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
IN HDEVINFO IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
Definition: devinst.c:44
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _In_ _IRQL_restores_ KIRQL NewIrql
Definition: ke.h:114