ReactOS 0.4.16-dev-334-g4d9f67c
MmMapLockedPagesSpecifyCache_drv.c File Reference
#include <kmt_test.h>
#include <debug.h>
#include "MmMapLockedPagesSpecifyCache.h"
Include dependency graph for MmMapLockedPagesSpecifyCache_drv.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS TestEntry (IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING RegistryPath, OUT PCWSTR *DeviceName, IN OUT INT *Flags)
 
VOID TestUnload (IN PDRIVER_OBJECT DriverObject)
 
VOID TestCleanEverything (VOID)
 
static NTSTATUS TestMessageHandler (IN PDEVICE_OBJECT DeviceObject, IN ULONG ControlCode, IN PVOID Buffer OPTIONAL, IN SIZE_T InLength, IN OUT PSIZE_T OutLength)
 
static NTSTATUS TestIrpHandler (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PIO_STACK_LOCATION IoStack)
 

Variables

static KMT_IRP_HANDLER TestIrpHandler
 
static KMT_MESSAGE_HANDLER TestMessageHandler
 
static PVOID CurrentBuffer
 
static PMDL CurrentMdl
 
static PVOID CurrentUser
 
static SIZE_T NonCachedLength
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file MmMapLockedPagesSpecifyCache_drv.c.

Function Documentation

◆ TestCleanEverything()

VOID TestCleanEverything ( VOID  )

Definition at line 53 of file MmMapLockedPagesSpecifyCache_drv.c.

54{
55 NTSTATUS SehStatus;
56
57 if (CurrentMdl == NULL)
58 {
59 return;
60 }
61
62 if (CurrentUser != NULL)
63 {
64 SehStatus = STATUS_SUCCESS;
66 {
68 }
70 {
71 SehStatus = _SEH2_GetExceptionCode();
72 }
74 ok_eq_hex(SehStatus, STATUS_SUCCESS);
76 }
77
78 SehStatus = STATUS_SUCCESS;
80 {
82 }
84 {
85 SehStatus = _SEH2_GetExceptionCode();
86 }
88 ok_eq_hex(SehStatus, STATUS_SUCCESS);
91 {
93 }
94 else
95 {
97 }
99}
static PMDL CurrentMdl
static PVOID CurrentUser
static PVOID CurrentBuffer
static SIZE_T NonCachedLength
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define IoFreeMdl
Definition: fxmdl.h:89
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1435
VOID NTAPI MmUnmapLockedPages(IN PVOID BaseAddress, IN PMDL Mdl)
Definition: mdlsup.c:837
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
VOID NTAPI MmFreeNonCachedMemory(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: ncache.c:172
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_END
Definition: pseh2_64.h:155
#define _SEH2_TRY
Definition: pseh2_64.h:55
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by TestMessageHandler().

◆ TestEntry()

NTSTATUS TestEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PCUNICODE_STRING  RegistryPath,
OUT PCWSTR DeviceName,
IN OUT INT Flags 
)

Definition at line 24 of file MmMapLockedPagesSpecifyCache_drv.c.

29{
31
32 PAGED_CODE();
33
36
37 *DeviceName = L"MmMapLockedPagesSpecifyCache";
38
41
42 return Status;
43}
#define PAGED_CODE()
static KMT_MESSAGE_HANDLER TestMessageHandler
static KMT_IRP_HANDLER TestIrpHandler
Status
Definition: gdiplustypes.h:25
NTSTATUS KmtRegisterMessageHandler(IN ULONG ControlCode OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_MESSAGE_HANDLER MessageHandler)
NTSTATUS KmtRegisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
#define L(x)
Definition: ntvdm.h:50
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define IRP_MJ_CLEANUP

◆ TestIrpHandler()

static NTSTATUS TestIrpHandler ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp,
_In_ PIO_STACK_LOCATION  IoStack 
)
static

Definition at line 267 of file MmMapLockedPagesSpecifyCache_drv.c.

271{
273
274 PAGED_CODE();
275
276 DPRINT("IRP %x/%x\n", IoStack->MajorFunction, IoStack->MinorFunction);
277 ASSERT(IoStack->MajorFunction == IRP_MJ_CLEANUP);
278
280 Irp->IoStatus.Information = 0;
281
282 if (IoStack->MajorFunction == IRP_MJ_CLEANUP)
283 {
286 }
287
288 if (Status == STATUS_PENDING)
289 {
293 }
294 else
295 {
296 Irp->IoStatus.Status = Status;
298 }
299
300 return Status;
301}
VOID TestCleanEverything(VOID)
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
IoMarkIrpPending(Irp)
#define ASSERT(a)
Definition: mode.c:44
#define IoCompleteRequest
Definition: irp.c:1240
#define DPRINT
Definition: sndvol32.h:73
#define IO_NO_INCREMENT
Definition: iotypes.h:598

◆ TestMessageHandler()

static NTSTATUS TestMessageHandler ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  ControlCode,
IN PVOID Buffer  OPTIONAL,
IN SIZE_T  InLength,
IN OUT PSIZE_T  OutLength 
)
static

Definition at line 103 of file MmMapLockedPagesSpecifyCache_drv.c.

109{
111 NTSTATUS SehStatus;
112
113 switch (ControlCode)
114 {
116 {
117 ok(Buffer != NULL, "Buffer is NULL\n");
118 ok_eq_size(InLength, sizeof(QUERY_BUFFER));
119 ok_eq_size(*OutLength, sizeof(QUERY_BUFFER));
121
123
124 ok(ExGetPreviousMode() == UserMode, "Not coming from umode!\n");
125 if (!skip(Buffer && InLength >= sizeof(QUERY_BUFFER) && *OutLength >= sizeof(QUERY_BUFFER), "Cannot read/write from/to buffer!\n"))
126 {
127 PQUERY_BUFFER QueryBuffer;
130
131 QueryBuffer = Buffer;
132 CacheType = (QueryBuffer->Cached ? MmCached : MmNonCached);
133 Length = QueryBuffer->Length;
135 ok(Length > 0, "Null size!\n");
136
137 if (!skip(Length > 0, "Null size!\n"))
138 {
139 if (QueryBuffer->Cached)
140 {
142 ok(CurrentBuffer != NULL, "ExAllocatePool failed!\n");
143 NonCachedLength = 0;
144 }
145 else
146 {
148 ok(CurrentBuffer != NULL, "MmAllocateNonCachedMemory failed!\n");
149 if (CurrentBuffer)
150 {
153 }
154 }
155 if (!skip(CurrentBuffer != NULL, "ExAllocatePool failed!\n"))
156 {
158 ok(CurrentMdl != NULL, "IoAllocateMdl failed!\n");
159 if (!skip(CurrentMdl != NULL, "IoAllocateMdl failed!\n"))
160 {
161 KIRQL Irql;
162
163 SehStatus = STATUS_SUCCESS;
165 {
167 }
169 {
170 SehStatus = _SEH2_GetExceptionCode();
171 }
172 _SEH2_END;
173 ok_eq_hex(SehStatus, STATUS_SUCCESS);
174
176 ok(Irql <= APC_LEVEL, "IRQL > APC_LEVEL: %d\n", Irql);
177
178 SehStatus = STATUS_SUCCESS;
179 _SEH2_TRY
180 {
181 CurrentUser = MmMapLockedPagesSpecifyCache(CurrentMdl, UserMode, CacheType, QueryBuffer->Buffer, FALSE, NormalPagePriority);
182 }
183 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
184 {
185 SehStatus = _SEH2_GetExceptionCode();
186 }
187 _SEH2_END;
188 if (QueryBuffer->Status != -1)
189 {
190 ok_eq_hex(SehStatus, QueryBuffer->Status);
191 if (NT_SUCCESS(QueryBuffer->Status))
192 {
193 ok(CurrentUser != NULL, "MmMapLockedPagesSpecifyCache failed!\n");
194 }
195 else
196 {
197 ok(CurrentUser == NULL, "MmMapLockedPagesSpecifyCache succeeded!\n");
198 }
199 }
200 QueryBuffer->Status = SehStatus;
201 }
202 else
203 {
204 ExFreePoolWithTag(CurrentBuffer, 'MLPC');
205 }
206 }
207 }
208
209 QueryBuffer->Buffer = CurrentUser;
210 *OutLength = sizeof(QUERY_BUFFER);
211 }
212
213 break;
214 }
215 case IOCTL_READ_BUFFER:
216 {
217 ok(Buffer != NULL, "Buffer is NULL\n");
218 ok_eq_size(InLength, sizeof(READ_BUFFER));
219 ok_eq_size(*OutLength, 0);
220 ok(CurrentMdl != NULL, "MDL is not in use!\n");
221
222 if (!skip(Buffer && InLength >= sizeof(READ_BUFFER), "Cannot read from buffer!\n"))
223 {
224 PREAD_BUFFER ReadBuffer;
225
226 ReadBuffer = Buffer;
227 if (!skip(ReadBuffer && ReadBuffer->Buffer == CurrentUser, "Cannot find matching MDL\n"))
228 {
229 if (ReadBuffer->Buffer != NULL)
230 {
231 USHORT i;
232 PULONG KBuffer = MmGetSystemAddressForMdlSafe(CurrentMdl, NormalPagePriority);
233 ok(KBuffer != NULL, "Failed to get kmode ptr\n");
234 ok(ReadBuffer->Length % sizeof(ULONG) == 0, "Invalid size: %d\n", ReadBuffer->Length);
235
236 if (!skip(Buffer != NULL, "Failed to get kmode ptr\n"))
237 {
238 for (i = 0; i < ReadBuffer->Length / sizeof(ULONG); ++i)
239 {
240 ok_eq_ulong(KBuffer[i], ReadBuffer->Pattern);
241 }
242 }
243 }
244 }
245
246 TestCleanEverything();
247 }
248
249 break;
250 }
251 case IOCTL_CLEAN:
252 {
253 TestCleanEverything();
254 break;
255 }
256 default:
257 ok(0, "Got an unknown message! DeviceObject=%p, ControlCode=%lu, Buffer=%p, In=%lu, Out=%lu bytes\n",
258 DeviceObject, ControlCode, Buffer, InLength, *OutLength);
259 break;
260 }
261
262 return Status;
263}
#define IOCTL_QUERY_BUFFER
#define read
Definition: acwin.h:96
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
#define ok_eq_pointer(value, expected)
Definition: apitest.h:59
#define ok_eq_size(value, expected)
Definition: apitest.h:69
@ Invalid
Definition: asmpp.cpp:30
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
void get(int argc, const char *argv[])
Definition: cmds.c:480
Definition: bufpool.h:45
_Out_ PKIRQL Irql
Definition: csq.h:179
static TAGID TAGID find
Definition: db.cpp:155
@ Out
@ In
#define FALSE
Definition: types.h:117
static WCHAR unknown[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1605
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ExGetPreviousMode
Definition: ex.h:140
#define IoAllocateMdl
Definition: fxmdl.h:88
GLsizeiptr size
Definition: glext.h:5919
GLdouble n
Definition: glext.h:7729
GLuint buffer
Definition: glext.h:5915
GLuint in
Definition: glext.h:9616
GLfloat GLfloat p
Definition: glext.h:8902
#define d
Definition: ke_i.h:81
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:931
PVOID NTAPI MmMapLockedPagesSpecifyCache(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN MEMORY_CACHING_TYPE CacheType, IN PVOID BaseAddress, IN ULONG BugCheckOnFailure, IN ULONG Priority)
Definition: mdlsup.c:660
static PVOID ptr
Definition: dispmode.c:27
PVOID NTAPI MmAllocateNonCachedMemory(IN SIZE_T NumberOfBytes)
Definition: ncache.c:25
#define KernelMode
Definition: asm.h:34
#define UserMode
Definition: asm.h:35
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
unsigned short USHORT
Definition: pedump.c:61
@ Failed
Definition: arc.h:79
CardRegion * from
Definition: spigame.cpp:19
Definition: tftpd.h:60
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
@ IoWriteAccess
Definition: ketypes.h:864
_Must_inspect_result_ _In_ PHYSICAL_ADDRESS _In_ PHYSICAL_ADDRESS _In_opt_ PHYSICAL_ADDRESS _In_ MEMORY_CACHING_TYPE CacheType
Definition: mmfuncs.h:217
MDL
Definition: mmtypes.h:117
enum _MEMORY_CACHING_TYPE MEMORY_CACHING_TYPE
@ MmCached
Definition: mmtypes.h:130
@ MmNonCached
Definition: mmtypes.h:129

◆ TestUnload()

VOID TestUnload ( IN PDRIVER_OBJECT  DriverObject)

Definition at line 46 of file MmMapLockedPagesSpecifyCache_drv.c.

48{
49 PAGED_CODE();
50}

Variable Documentation

◆ CurrentBuffer

PVOID CurrentBuffer
static

Definition at line 18 of file MmMapLockedPagesSpecifyCache_drv.c.

Referenced by TestCleanEverything(), and TestMessageHandler().

◆ CurrentMdl

◆ CurrentUser

PVOID CurrentUser
static

◆ NonCachedLength

SIZE_T NonCachedLength
static

Definition at line 21 of file MmMapLockedPagesSpecifyCache_drv.c.

Referenced by TestCleanEverything(), and TestMessageHandler().

◆ TestIrpHandler

KMT_IRP_HANDLER TestIrpHandler
static

Definition at line 15 of file MmMapLockedPagesSpecifyCache_drv.c.

Referenced by TestEntry().

◆ TestMessageHandler

KMT_MESSAGE_HANDLER TestMessageHandler
static

Definition at line 16 of file MmMapLockedPagesSpecifyCache_drv.c.

Referenced by TestEntry().