ReactOS  0.4.14-dev-98-gb0d4763
CcPinMappedData_drv.c File Reference
#include <kmt_test.h>
#include <debug.h>
Include dependency graph for CcPinMappedData_drv.c:

Go to the source code of this file.

Classes

struct  _TEST_FCB
 
struct  _TEST_CONTEXT
 

Macros

#define NDEBUG
 
#define IOCTL_START_TEST   1
 
#define IOCTL_FINISH_TEST   2
 

Typedefs

typedef struct _TEST_FCB TEST_FCB
 
typedef struct _TEST_FCBPTEST_FCB
 
typedef struct _TEST_CONTEXT TEST_CONTEXT
 
typedef struct _TEST_CONTEXTPTEST_CONTEXT
 

Functions

NTSTATUS TestEntry (_In_ PDRIVER_OBJECT DriverObject, _In_ PCUNICODE_STRING RegistryPath, _Out_ PCWSTR *DeviceName, _Inout_ INT *Flags)
 
VOID TestUnload (_In_ PDRIVER_OBJECT DriverObject)
 
BOOLEAN NTAPI AcquireForLazyWrite (_In_ PVOID Context, _In_ BOOLEAN Wait)
 
VOID NTAPI ReleaseFromLazyWrite (_In_ PVOID Context)
 
BOOLEAN NTAPI AcquireForReadAhead (_In_ PVOID Context, _In_ BOOLEAN Wait)
 
VOID NTAPI ReleaseFromReadAhead (_In_ PVOID Context)
 
static PVOID MapAndLockUserBuffer (_In_ _Out_ PIRP Irp, _In_ ULONG BufferLength)
 
static VOID NTAPI PinInAnotherThread (IN PVOID Context)
 
static VOID NTAPI PinInAnotherThreadExclusive (IN PVOID Context)
 
static VOID PerformTest (ULONG TestId, PDEVICE_OBJECT DeviceObject)
 
static VOID CleanupTest (ULONG TestId, PDEVICE_OBJECT DeviceObject)
 
static NTSTATUS TestMessageHandler (_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG ControlCode, _In_opt_ PVOID Buffer, _In_ SIZE_T InLength, _Inout_ PSIZE_T OutLength)
 
static NTSTATUS TestIrpHandler (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PIO_STACK_LOCATION IoStack)
 

Variables

static ULONG TestTestId = -1
 
static PFILE_OBJECT TestFileObject
 
static PDEVICE_OBJECT TestDeviceObject
 
static KMT_IRP_HANDLER TestIrpHandler
 
static KMT_MESSAGE_HANDLER TestMessageHandler
 
static CACHE_MANAGER_CALLBACKS Callbacks
 
static CC_FILE_SIZES FileSizes
 

Macro Definition Documentation

◆ IOCTL_FINISH_TEST

#define IOCTL_FINISH_TEST   2

Definition at line 14 of file CcPinMappedData_drv.c.

◆ IOCTL_START_TEST

#define IOCTL_START_TEST   1

Definition at line 13 of file CcPinMappedData_drv.c.

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file CcPinMappedData_drv.c.

Typedef Documentation

◆ PTEST_CONTEXT

◆ PTEST_FCB

◆ TEST_CONTEXT

◆ TEST_FCB

Function Documentation

◆ AcquireForLazyWrite()

BOOLEAN NTAPI AcquireForLazyWrite ( _In_ PVOID  Context,
_In_ BOOLEAN  Wait 
)

Definition at line 70 of file CcPinMappedData_drv.c.

73 {
74  return TRUE;
75 }
#define TRUE
Definition: types.h:120

◆ AcquireForReadAhead()

BOOLEAN NTAPI AcquireForReadAhead ( _In_ PVOID  Context,
_In_ BOOLEAN  Wait 
)

Definition at line 87 of file CcPinMappedData_drv.c.

90 {
91  return TRUE;
92 }
#define TRUE
Definition: types.h:120

◆ CleanupTest()

static VOID CleanupTest ( ULONG  TestId,
PDEVICE_OBJECT  DeviceObject 
)
static

Definition at line 475 of file CcPinMappedData_drv.c.

478 {
480  CACHE_UNINITIALIZE_EVENT CacheUninitEvent;
481 
483  ok_eq_ulong(TestTestId, TestId);
484 
485  if (!skip(TestFileObject != NULL, "No test FO\n"))
486  {
488  {
489  KeInitializeEvent(&CacheUninitEvent.Event, NotificationEvent, FALSE);
490  CcUninitializeCacheMap(TestFileObject, &Zero, &CacheUninitEvent);
491  KeWaitForSingleObject(&CacheUninitEvent.Event, Executive, KernelMode, FALSE, NULL);
492  }
493 
494  if (TestFileObject->FsContext != NULL)
495  {
496  ExFreePool(TestFileObject->FsContext);
497  TestFileObject->FsContext = NULL;
498  TestFileObject->SectionObjectPointer = NULL;
499  }
500 
502  }
503 
506  TestTestId = -1;
507 }
#define ok_eq_ulong(value, expected)
#define LL
Definition: tui.h:85
#define ok_eq_pointer(value, expected)
static PDEVICE_OBJECT TestDeviceObject
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
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
#define RTL_CONSTANT_LARGE_INTEGER(quad_part)
Definition: rtltypes.h:414
#define CcIsFileCached(FO)
smooth NULL
Definition: ftsmooth.c:416
static ULONG TestTestId
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:284
IN PVCB IN VBO IN ULONG OUT PBCB OUT PVOID IN BOOLEAN IN BOOLEAN Zero
Definition: fatprocs.h:402
#define skip(...)
Definition: atltest.h:64
static PFILE_OBJECT TestFileObject
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by TestMessageHandler().

◆ MapAndLockUserBuffer()

static PVOID MapAndLockUserBuffer ( _In_ _Out_ PIRP  Irp,
_In_ ULONG  BufferLength 
)
static

Definition at line 117 of file CcPinMappedData_drv.c.

120 {
121  PMDL Mdl;
122 
123  if (Irp->MdlAddress == NULL)
124  {
125  Mdl = IoAllocateMdl(Irp->UserBuffer, BufferLength, FALSE, FALSE, Irp);
126  if (Mdl == NULL)
127  {
128  return NULL;
129  }
130 
131  _SEH2_TRY
132  {
133  MmProbeAndLockPages(Mdl, Irp->RequestorMode, IoWriteAccess);
134  }
136  {
137  IoFreeMdl(Mdl);
138  Irp->MdlAddress = NULL;
139  _SEH2_YIELD(return NULL);
140  }
141  _SEH2_END;
142  }
143 
145 }
_In_ PIRP Irp
Definition: csq.h:116
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
_SEH2_TRY
Definition: create.c:4250
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
_SEH2_END
Definition: create.c:4424
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6

Referenced by TestIrpHandler().

◆ PerformTest()

static VOID PerformTest ( ULONG  TestId,
PDEVICE_OBJECT  DeviceObject 
)
static

Definition at line 268 of file CcPinMappedData_drv.c.

271 {
272  PVOID Bcb, PinBcb, NewBcb;
273  BOOLEAN Ret;
274  PULONG Buffer;
275  PTEST_FCB Fcb;
277 
280  ok_eq_ulong(TestTestId, -1);
281 
283  TestTestId = TestId;
285  if (!skip(TestFileObject != NULL, "Failed to allocate FO\n"))
286  {
288  if (!skip(Fcb != NULL, "ExAllocatePool failed\n"))
289  {
290  RtlZeroMemory(Fcb, sizeof(TEST_FCB));
291  ExInitializeFastMutex(&Fcb->HeaderMutex);
292  FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex);
293 
294  TestFileObject->FsContext = Fcb;
295  TestFileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
296 
297  KmtStartSeh();
300 
301  if (!skip(CcIsFileCached(TestFileObject) == TRUE, "CcInitializeCacheMap failed\n"))
302  {
303  if (TestId == 0)
304  {
305  Ret = FALSE;
306  Offset.QuadPart = 0;
307  KmtStartSeh();
310 
311  if (!skip(Ret == TRUE, "CcMapData failed\n"))
312  {
313  Ret = FALSE;
314  PinBcb = Bcb;
315  ok_eq_ulong(Buffer[0x3000 / sizeof(ULONG)], 0xDEADBABE);
316 
317  KmtStartSeh();
320 
321  if (!skip(Ret == TRUE, "CcPinMappedData failed\n"))
322  {
323  ok(Bcb != PinBcb, "Returned same BCB!\n");
324  ok(*(PUSHORT)PinBcb == 0x2FD, "Not a BCB: %x\n", *(PUSHORT)PinBcb);
325 
326  /* Previous BCB isn't valid anymore! */
327  Bcb = PinBcb;
328  }
329 
330  CcUnpinData(Bcb);
331  }
332  }
333  else if (TestId == 1)
334  {
335  Ret = FALSE;
336  Offset.QuadPart = 0;
337  KmtStartSeh();
338  Ret = CcPinRead(TestFileObject, &Offset, FileSizes.FileSize.QuadPart - Offset.QuadPart, PIN_WAIT, &PinBcb, (PVOID *)&Buffer);
340 
341  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
342  {
343  ok(*(PUSHORT)PinBcb == 0x2FD, "Not a BCB: %x\n", *(PUSHORT)PinBcb);
344  ok_eq_ulong(Buffer[0x3000 / sizeof(ULONG)], 0xDEADBABE);
345 
346  Ret = FALSE;
347  KmtStartSeh();
350 
351  if (!skip(Ret == TRUE, "CcMapData failed\n"))
352  {
353  ok(Bcb != PinBcb, "Returned same BCB!\n");
354 
355  Ret = FALSE;
356  NewBcb = Bcb;
357  KmtStartSeh();
360 
361  if (!skip(Ret == TRUE, "CcPinMappedData failed\n"))
362  {
363  ok(Bcb != NewBcb, "Returned same BCB!\n");
364  ok_eq_pointer(NewBcb, PinBcb);
365  ok(*(PUSHORT)NewBcb == 0x2FD, "Not a BCB: %x\n", *(PUSHORT)NewBcb);
366 
367  /* Previous BCB isn't valid anymore! */
368  Bcb = NewBcb;
369  }
370 
371  CcUnpinData(Bcb);
372  }
373 
374  CcUnpinData(PinBcb);
375  }
376  }
377  else if (TestId == 2)
378  {
379  PTEST_CONTEXT TestContext;
380 
381  TestContext = ExAllocatePool(NonPagedPool, sizeof(TEST_CONTEXT));
382  if (!skip(TestContext != NULL, "ExAllocatePool failed\n"))
383  {
384  Ret = FALSE;
385  Offset.QuadPart = 0;
386  KmtStartSeh();
387  Ret = CcPinRead(TestFileObject, &Offset, FileSizes.FileSize.QuadPart - Offset.QuadPart, PIN_WAIT | PIN_EXCLUSIVE, &TestContext->Bcb, (PVOID *)&TestContext->Buffer);
389 
390  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
391  {
392  PKTHREAD ThreadHandle;
393 
394  ok(*(PUSHORT)TestContext->Bcb == 0x2FD, "Not a BCB: %x\n", *(PUSHORT)TestContext->Bcb);
395  ok_eq_ulong(TestContext->Buffer[0x3000 / sizeof(ULONG)], 0xDEADBABE);
396 
397  TestContext->Length = FileSizes.FileSize.QuadPart - Offset.QuadPart;
398  ThreadHandle = KmtStartThread(PinInAnotherThreadExclusive, TestContext);
399  KmtFinishThread(ThreadHandle, NULL);
400 
401  CcUnpinData(TestContext->Bcb);
402  }
403 
404  ExFreePool(TestContext);
405  }
406  }
407  else if (TestId == 3)
408  {
409  Ret = FALSE;
410  Offset.QuadPart = 0;
411  KmtStartSeh();
414 
415  if (!skip(Ret == TRUE, "CcMapData failed\n"))
416  {
417  Ret = FALSE;
418  PinBcb = Bcb;
419  ok_eq_ulong(Buffer[0x3000 / sizeof(ULONG)], 0xDEADBABE);
420 
421  KmtStartSeh();
424 
425  if (!skip(Ret == FALSE, "CcPinMappedData succeed\n"))
426  {
427  ok_eq_pointer(Bcb, PinBcb);
428  }
429  else
430  {
431  Bcb = PinBcb;
432  }
433 
434  CcUnpinData(Bcb);
435  }
436  }
437  else if (TestId == 4)
438  {
439  PTEST_CONTEXT TestContext;
440 
441  TestContext = ExAllocatePool(NonPagedPool, sizeof(TEST_CONTEXT));
442  if (!skip(TestContext != NULL, "ExAllocatePool failed\n"))
443  {
444  Ret = FALSE;
445  Offset.QuadPart = 0;
446  KmtStartSeh();
447  Ret = CcPinRead(TestFileObject, &Offset, FileSizes.FileSize.QuadPart - Offset.QuadPart, PIN_WAIT, &TestContext->Bcb, (PVOID *)&TestContext->Buffer);
449 
450  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
451  {
452  PKTHREAD ThreadHandle;
453 
454  ok(*(PUSHORT)TestContext->Bcb == 0x2FD, "Not a BCB: %x\n", *(PUSHORT)TestContext->Bcb);
455  ok_eq_ulong(TestContext->Buffer[0x3000 / sizeof(ULONG)], 0xDEADBABE);
456 
457  TestContext->Length = FileSizes.FileSize.QuadPart - Offset.QuadPart;
458  ThreadHandle = KmtStartThread(PinInAnotherThread, TestContext);
459  KmtFinishThread(ThreadHandle, NULL);
460 
461  CcUnpinData(TestContext->Bcb);
462  }
463 
464  ExFreePool(TestContext);
465  }
466  }
467  }
468  }
469  }
470 }
#define ok_eq_ulong(value, expected)
#define TRUE
Definition: types.h:120
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL)
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:931
static CACHE_MANAGER_CALLBACKS Callbacks
#define ok_eq_pointer(value, expected)
static PDEVICE_OBJECT TestDeviceObject
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:283
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define MAP_WAIT
#define PIN_WAIT
LARGE_INTEGER FileSize
Definition: cctypes.h:16
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define CcIsFileCached(FO)
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
PFILE_OBJECT NTAPI IoCreateStreamFileObject(IN PFILE_OBJECT FileObject, IN PDEVICE_OBJECT DeviceObject)
Definition: file.c:3186
BOOLEAN NTAPI CcMapData(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *BcbResult, OUT PVOID *Buffer)
Definition: pinsup.c:694
VOID NTAPI CcInitializeCacheMap(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes, IN BOOLEAN PinAccess, IN PCACHE_MANAGER_CALLBACKS Callbacks, IN PVOID LazyWriteContext)
Definition: fssup.c:193
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
static CC_FILE_SIZES FileSizes
static ULONG TestTestId
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define KmtStartSeh()
Definition: kmt_test.h:277
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL)
static VOID NTAPI PinInAnotherThread(IN PVOID Context)
static VOID NTAPI PinInAnotherThreadExclusive(IN PVOID Context)
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define PIN_IF_BCB
#define ok(value,...)
Definition: atltest.h:57
unsigned int * PULONG
Definition: retypes.h:1
#define PIN_EXCLUSIVE
#define skip(...)
Definition: atltest.h:64
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
BOOLEAN NTAPI CcPinMappedData(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, IN OUT PVOID *Bcb)
Definition: pinsup.c:774
_In_ PFCB Fcb
Definition: cdprocs.h:151
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
static PFILE_OBJECT TestFileObject
SECTION_OBJECT_POINTERS SectionObjectPointers
Definition: ntfs.h:514
unsigned short * PUSHORT
Definition: retypes.h:2
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by TestMessageHandler().

◆ PinInAnotherThread()

static VOID NTAPI PinInAnotherThread ( IN PVOID  Context)
static

Definition at line 150 of file CcPinMappedData_drv.c.

151 {
152  BOOLEAN Ret;
153  PULONG Buffer;
154  PVOID Bcb, PinBcb;
156  PTEST_CONTEXT TestContext;
157 
158  ok(TestFileObject != NULL, "Called in invalid context!\n");
160 
161  TestContext = Context;
162  ok(TestContext != NULL, "Called in invalid context!\n");
163  ok(TestContext->Bcb != NULL, "Called in invalid context!\n");
164  ok(TestContext->Buffer != NULL, "Called in invalid context!\n");
165  ok(TestContext->Length != 0, "Called in invalid context!\n");
166 
167  Ret = FALSE;
168  Offset.QuadPart = 0;
169 
170  KmtStartSeh();
171  Ret = CcMapData(TestFileObject, &Offset, TestContext->Length, MAP_WAIT, &Bcb, (PVOID *)&Buffer);
173 
174  if (!skip(Ret == TRUE, "CcMapData failed\n"))
175  {
176  ok(Bcb != TestContext->Bcb, "Returned same BCB!\n");
177  ok_eq_pointer(Buffer, TestContext->Buffer);
178 
179  Ret = FALSE;
180  PinBcb = Bcb;
181 
182  KmtStartSeh();
183  Ret = CcPinMappedData(TestFileObject, &Offset, FileSizes.FileSize.QuadPart - Offset.QuadPart, 0, &PinBcb);
185 
186  if (!skip(Ret == TRUE, "CcPinMappedData failed\n"))
187  {
188  ok(Bcb != PinBcb, "Returned same BCB!\n");
189  ok_eq_pointer(PinBcb, TestContext->Bcb);
190 
191  Bcb = PinBcb;
192  }
193 
194  CcUnpinData(Bcb);
195  }
196 }
#define ok_eq_ulong(value, expected)
#define TRUE
Definition: types.h:120
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
#define ok_eq_pointer(value, expected)
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:283
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define MAP_WAIT
LARGE_INTEGER FileSize
Definition: cctypes.h:16
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
BOOLEAN NTAPI CcMapData(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *BcbResult, OUT PVOID *Buffer)
Definition: pinsup.c:694
static CC_FILE_SIZES FileSizes
static ULONG TestTestId
#define KmtStartSeh()
Definition: kmt_test.h:277
#define ok(value,...)
Definition: atltest.h:57
unsigned int * PULONG
Definition: retypes.h:1
#define skip(...)
Definition: atltest.h:64
struct tagContext Context
Definition: acpixf.h:1024
BOOLEAN NTAPI CcPinMappedData(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, IN OUT PVOID *Bcb)
Definition: pinsup.c:774
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
static PFILE_OBJECT TestFileObject
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by PerformTest().

◆ PinInAnotherThreadExclusive()

static VOID NTAPI PinInAnotherThreadExclusive ( IN PVOID  Context)
static

Definition at line 201 of file CcPinMappedData_drv.c.

202 {
203  BOOLEAN Ret;
204  PULONG Buffer;
205  PVOID Bcb, PinBcb;
207  PTEST_CONTEXT TestContext;
208 
209  ok(TestFileObject != NULL, "Called in invalid context!\n");
211 
212  TestContext = Context;
213  ok(TestContext != NULL, "Called in invalid context!\n");
214  ok(TestContext->Bcb != NULL, "Called in invalid context!\n");
215  ok(TestContext->Buffer != NULL, "Called in invalid context!\n");
216  ok(TestContext->Length != 0, "Called in invalid context!\n");
217 
218  Ret = FALSE;
219  Offset.QuadPart = 0;
220 
221  KmtStartSeh();
222  Ret = CcMapData(TestFileObject, &Offset, TestContext->Length, MAP_WAIT, &Bcb, (PVOID *)&Buffer);
224 
225  if (!skip(Ret == TRUE, "CcMapData failed\n"))
226  {
227  ok(Bcb != TestContext->Bcb, "Returned same BCB!\n");
228  ok_eq_pointer(Buffer, TestContext->Buffer);
229 
230  Ret = FALSE;
231  PinBcb = Bcb;
232 
233  KmtStartSeh();
236 
237  if (!skip(Ret == FALSE, "CcPinMappedData succeed\n"))
238  {
239  ok_eq_pointer(PinBcb, Bcb);
240 
241  Ret = FALSE;
242  PinBcb = Bcb;
243 
244  KmtStartSeh();
245  Ret = CcPinMappedData(TestFileObject, &Offset, FileSizes.FileSize.QuadPart - Offset.QuadPart, 0, &PinBcb);
247 
248  if (!skip(Ret == FALSE, "CcPinMappedData succeed\n"))
249  {
250  ok_eq_pointer(PinBcb, Bcb);
251  }
252  else
253  {
254  Bcb = PinBcb;
255  }
256  }
257  else
258  {
259  Bcb = PinBcb;
260  }
261 
262  CcUnpinData(Bcb);
263  }
264 }
#define ok_eq_ulong(value, expected)
#define TRUE
Definition: types.h:120
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
#define ok_eq_pointer(value, expected)
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:283
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define MAP_WAIT
LARGE_INTEGER FileSize
Definition: cctypes.h:16
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
BOOLEAN NTAPI CcMapData(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *BcbResult, OUT PVOID *Buffer)
Definition: pinsup.c:694
static CC_FILE_SIZES FileSizes
static ULONG TestTestId
#define KmtStartSeh()
Definition: kmt_test.h:277
#define ok(value,...)
Definition: atltest.h:57
unsigned int * PULONG
Definition: retypes.h:1
#define PIN_EXCLUSIVE
#define skip(...)
Definition: atltest.h:64
struct tagContext Context
Definition: acpixf.h:1024
BOOLEAN NTAPI CcPinMappedData(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, IN OUT PVOID *Bcb)
Definition: pinsup.c:774
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
static PFILE_OBJECT TestFileObject
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by PerformTest().

◆ ReleaseFromLazyWrite()

VOID NTAPI ReleaseFromLazyWrite ( _In_ PVOID  Context)

Definition at line 79 of file CcPinMappedData_drv.c.

81 {
82  return;
83 }

◆ ReleaseFromReadAhead()

VOID NTAPI ReleaseFromReadAhead ( _In_ PVOID  Context)

Definition at line 96 of file CcPinMappedData_drv.c.

98 {
99  return;
100 }

◆ TestEntry()

NTSTATUS TestEntry ( _In_ PDRIVER_OBJECT  DriverObject,
_In_ PCUNICODE_STRING  RegistryPath,
_Out_ PCWSTR DeviceName,
_Inout_ INT Flags 
)

Definition at line 37 of file CcPinMappedData_drv.c.

42 {
44 
45  PAGED_CODE();
46 
48 
49  *DeviceName = L"CcPinMappedData";
50  *Flags = TESTENTRY_NO_EXCLUSIVE_DEVICE |
51  TESTENTRY_BUFFERED_IO_DEVICE |
52  TESTENTRY_NO_READONLY_DEVICE;
53 
56 
57 
58  return Status;
59 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define PAGED_CODE()
Definition: video.h:57
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS KmtRegisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
NTSTATUS KmtRegisterMessageHandler(IN ULONG ControlCode OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_MESSAGE_HANDLER MessageHandler)
static const WCHAR L[]
Definition: oid.c:1250
static KMT_MESSAGE_HANDLER TestMessageHandler
Status
Definition: gdiplustypes.h:24
static KMT_IRP_HANDLER TestIrpHandler
#define IRP_MJ_READ
Definition: rdpdr.c:46
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ TestIrpHandler()

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

Definition at line 547 of file CcPinMappedData_drv.c.

551 {
553 
554  PAGED_CODE();
555 
556  DPRINT("IRP %x/%x\n", IoStack->MajorFunction, IoStack->MinorFunction);
557  ASSERT(IoStack->MajorFunction == IRP_MJ_READ);
558 
560 
562  Irp->IoStatus.Information = 0;
563 
564  if (IoStack->MajorFunction == IRP_MJ_READ)
565  {
566  PMDL Mdl;
567  ULONG Length;
568  PVOID Buffer;
570 
571  Offset = IoStack->Parameters.Read.ByteOffset;
572  Length = IoStack->Parameters.Read.Length;
573 
575  ok_eq_pointer(IoStack->FileObject, TestFileObject);
576 
577  ok(FlagOn(Irp->Flags, IRP_NOCACHE), "Not coming from Cc\n");
578 
579  ok_irql(APC_LEVEL);
580  ok((Offset.QuadPart % PAGE_SIZE == 0 || Offset.QuadPart == 0), "Offset is not aligned: %I64i\n", Offset.QuadPart);
581  ok(Length % PAGE_SIZE == 0, "Length is not aligned: %I64i\n", Length);
582 
583  ok(Irp->AssociatedIrp.SystemBuffer == NULL, "A SystemBuffer was allocated!\n");
585  ok(Buffer != NULL, "Null pointer!\n");
586  RtlFillMemory(Buffer, Length, 0xBA);
587 
589  if (Offset.QuadPart <= 0x3000 && Offset.QuadPart + Length > 0x3000)
590  {
591  *(PULONG)((ULONG_PTR)Buffer + (ULONG_PTR)(0x3000 - Offset.QuadPart)) = 0xDEADBABE;
592  }
593 
594  Mdl = Irp->MdlAddress;
595  ok(Mdl != NULL, "Null pointer for MDL!\n");
596  ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) != 0, "MDL not locked\n");
597  ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) == 0, "MDL from non paged\n");
598  ok((Mdl->MdlFlags & MDL_IO_PAGE_READ) != 0, "Non paging IO\n");
599  ok((Irp->Flags & IRP_PAGING_IO) != 0, "Non paging IO\n");
600 
601  Irp->IoStatus.Information = Length;
602  }
603 
604  if (Status == STATUS_PENDING)
605  {
609  }
610  else
611  {
612  Irp->IoStatus.Status = Status;
614  }
615 
617 
618  return Status;
619 }
#define MDL_IO_PAGE_READ
Definition: mmtypes.h:24
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define ok_eq_pointer(value, expected)
static PDEVICE_OBJECT TestDeviceObject
LONG NTSTATUS
Definition: precomp.h:26
#define IRP_NOCACHE
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
smooth NULL
Definition: ftsmooth.c:416
#define MDL_SOURCE_IS_NONPAGED_POOL
Definition: mmtypes.h:20
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
#define MDL_PAGES_LOCKED
Definition: mmtypes.h:19
#define STATUS_PENDING
Definition: ntstatus.h:82
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
static PVOID MapAndLockUserBuffer(_In_ _Out_ PIRP Irp, _In_ ULONG BufferLength)
#define ok(value,...)
Definition: atltest.h:57
unsigned int * PULONG
Definition: retypes.h:1
#define IRP_PAGING_IO
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define ULONG_PTR
Definition: config.h:101
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
IoMarkIrpPending(Irp)
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
static PFILE_OBJECT TestFileObject
#define APC_LEVEL
Definition: env_spec_w32.h:695

◆ TestMessageHandler()

static NTSTATUS TestMessageHandler ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ ULONG  ControlCode,
_In_opt_ PVOID Buffer  ,
_In_ SIZE_T  InLength,
_Inout_ PSIZE_T  OutLength 
)
static

Definition at line 512 of file CcPinMappedData_drv.c.

518 {
520 
522 
523  switch (ControlCode)
524  {
525  case IOCTL_START_TEST:
526  ok_eq_ulong((ULONG)InLength, sizeof(ULONG));
528  break;
529 
530  case IOCTL_FINISH_TEST:
531  ok_eq_ulong((ULONG)InLength, sizeof(ULONG));
533  break;
534 
535  default:
537  break;
538  }
539 
541 
542  return Status;
543 }
#define IOCTL_FINISH_TEST
#define ok_eq_ulong(value, expected)
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
LONG NTSTATUS
Definition: precomp.h:26
static VOID CleanupTest(ULONG TestId, PDEVICE_OBJECT DeviceObject)
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
Definition: bufpool.h:45
static VOID PerformTest(ULONG TestId, PDEVICE_OBJECT DeviceObject)
#define IOCTL_START_TEST
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
unsigned int * PULONG
Definition: retypes.h:1
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ TestUnload()

VOID TestUnload ( _In_ PDRIVER_OBJECT  DriverObject)

Definition at line 62 of file CcPinMappedData_drv.c.

64 {
65  PAGED_CODE();
66 }
#define PAGED_CODE()
Definition: video.h:57

Variable Documentation

◆ Callbacks

CACHE_MANAGER_CALLBACKS Callbacks
static
Initial value:
= {
}
VOID NTAPI ReleaseFromReadAhead(_In_ PVOID Context)
VOID NTAPI ReleaseFromLazyWrite(_In_ PVOID Context)
BOOLEAN NTAPI AcquireForLazyWrite(_In_ PVOID Context, _In_ BOOLEAN Wait)
BOOLEAN NTAPI AcquireForReadAhead(_In_ PVOID Context, _In_ BOOLEAN Wait)

Definition at line 102 of file CcPinMappedData_drv.c.

Referenced by PerformTest().

◆ FileSizes

CC_FILE_SIZES FileSizes
static
Initial value:
= {
}
#define RTL_CONSTANT_LARGE_INTEGER(quad_part)
Definition: rtltypes.h:414
int64_t LONGLONG
Definition: typedefs.h:66

Definition at line 109 of file CcPinMappedData_drv.c.

Referenced by PerformTest(), PinInAnotherThread(), and PinInAnotherThreadExclusive().

◆ TestDeviceObject

PDEVICE_OBJECT TestDeviceObject
static

Definition at line 32 of file CcPinMappedData_drv.c.

Referenced by CleanupTest(), PerformTest(), and TestIrpHandler().

◆ TestFileObject

◆ TestIrpHandler

KMT_IRP_HANDLER TestIrpHandler
static

Definition at line 33 of file CcPinMappedData_drv.c.

Referenced by TestEntry().

◆ TestMessageHandler

KMT_MESSAGE_HANDLER TestMessageHandler
static

Definition at line 34 of file CcPinMappedData_drv.c.

Referenced by TestEntry().

◆ TestTestId

ULONG TestTestId = -1
static