ReactOS  0.4.15-dev-1070-ge1a01de
CcPinRead_drv.c
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: Test driver for CcPinRead function
5  * PROGRAMMER: Pierre Schweitzer <pierre@reactos.org>
6  */
7 
8 #include <kmt_test.h>
9 
10 #define NDEBUG
11 #include <debug.h>
12 
13 #define IOCTL_START_TEST 1
14 #define IOCTL_FINISH_TEST 2
15 
16 typedef struct _TEST_FCB
17 {
22 
23 typedef struct _TEST_CONTEXT
24 {
25  PVOID Bcb;
26  PVOID Buffer;
27  ULONG Length;
29 
30 static ULONG TestTestId = -1;
33 static KMT_IRP_HANDLER TestIrpHandler;
34 static KMT_MESSAGE_HANDLER TestMessageHandler;
36 static ULONGLONG Memory = 0;
37 static BOOLEAN TS = FALSE;
38 
44  _Inout_ INT *Flags)
45 {
46  ULONG Length;
49  RTL_OSVERSIONINFOEXW VersionInfo;
50 
51  PAGED_CODE();
52 
54 
55  *DeviceName = L"CcPinRead";
56  *Flags = TESTENTRY_NO_EXCLUSIVE_DEVICE |
57  TESTENTRY_BUFFERED_IO_DEVICE |
58  TESTENTRY_NO_READONLY_DEVICE;
59 
63 
65  &SBI,
66  sizeof(SBI),
67  &Length);
68  if (NT_SUCCESS(Status))
69  {
70  Memory = (SBI.NumberOfPhysicalPages * SBI.PageSize) / 1024 / 1024;
71  }
72  else
73  {
75  }
76 
77  VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
78  Status = RtlGetVersion((PRTL_OSVERSIONINFOW)&VersionInfo);
79  if (NT_SUCCESS(Status))
80  {
81  TS = BooleanFlagOn(VersionInfo.wSuiteMask, VER_SUITE_TERMINAL) &&
82  !BooleanFlagOn(VersionInfo.wSuiteMask, VER_SUITE_SINGLEUSERTS);
83  }
84  else
85  {
87  }
88 
89  trace("System with %I64dMb RAM and terminal services %S\n", Memory, (TS ? L"enabled" : L"disabled"));
90 
91  return Status;
92 }
93 
94 VOID
97 {
98  PAGED_CODE();
99 }
100 
101 BOOLEAN
102 NTAPI
105  _In_ BOOLEAN Wait)
106 {
107  return TRUE;
108 }
109 
110 VOID
111 NTAPI
114 {
115  return;
116 }
117 
118 BOOLEAN
119 NTAPI
122  _In_ BOOLEAN Wait)
123 {
124  return TRUE;
125 }
126 
127 VOID
128 NTAPI
131 {
132  return;
133 }
134 
140 };
141 
143  RTL_CONSTANT_LARGE_INTEGER((LONGLONG)0x4000), // .AllocationSize
144  RTL_CONSTANT_LARGE_INTEGER((LONGLONG)0x4000), // .FileSize
145  RTL_CONSTANT_LARGE_INTEGER((LONGLONG)0x4000) // .ValidDataLength
146 };
147 
149  RTL_CONSTANT_LARGE_INTEGER((LONGLONG)512), // .AllocationSize
150  RTL_CONSTANT_LARGE_INTEGER((LONGLONG)496), // .FileSize
151  RTL_CONSTANT_LARGE_INTEGER((LONGLONG)496) // .ValidDataLength
152 };
153 
154 static
155 PVOID
157  _In_ _Out_ PIRP Irp,
159 {
160  PMDL Mdl;
161 
162  if (Irp->MdlAddress == NULL)
163  {
164  Mdl = IoAllocateMdl(Irp->UserBuffer, BufferLength, FALSE, FALSE, Irp);
165  if (Mdl == NULL)
166  {
167  return NULL;
168  }
169 
170  _SEH2_TRY
171  {
172  MmProbeAndLockPages(Mdl, Irp->RequestorMode, IoWriteAccess);
173  }
175  {
176  IoFreeMdl(Mdl);
177  Irp->MdlAddress = NULL;
178  _SEH2_YIELD(return NULL);
179  }
180  _SEH2_END;
181  }
182 
184 }
185 
186 #define ok_bcb(B, L, O) \
187 { \
188  PPUBLIC_BCB public_bcb = (B); \
189  ok(public_bcb->NodeTypeCode == 0x2FD, "Not a BCB: %x\n", public_bcb->NodeTypeCode); \
190  ok(public_bcb->NodeByteSize == 0, "Invalid size: %d\n", public_bcb->NodeByteSize); \
191  ok_eq_ulong(public_bcb->MappedLength, (L)); \
192  ok_eq_longlong(public_bcb->MappedFileOffset.QuadPart, (O)); \
193 }
194 
195 static
196 VOID
197 NTAPI
199 {
200  BOOLEAN Ret;
201  PULONG Buffer;
202  PVOID Bcb;
204  PTEST_CONTEXT TestContext;
205 
206  ok(TestFileObject != NULL, "Called in invalid context!\n");
208 
209  TestContext = Context;
210  ok(TestContext != NULL, "Called in invalid context!\n");
211  ok(TestContext->Bcb != NULL, "Called in invalid context!\n");
212  ok(TestContext->Buffer != NULL, "Called in invalid context!\n");
213  ok(TestContext->Length != 0, "Called in invalid context!\n");
214 
215  Ret = FALSE;
216  Offset.QuadPart = 0x1000;
217  KmtStartSeh();
218  Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_WAIT, &Bcb, (PVOID *)&Buffer);
220 
221  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
222  {
223  ok_bcb(Bcb, 12288, Offset.QuadPart);
224  ok_eq_pointer(Bcb, TestContext->Bcb);
225  ok_eq_pointer(Buffer, TestContext->Buffer);
226 
227  CcUnpinData(Bcb);
228  }
229 
230  KmtStartSeh();
231  Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_WAIT | PIN_IF_BCB, &Bcb, (PVOID *)&Buffer);
233 
234  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
235  {
236  ok_bcb(Bcb, 12288, Offset.QuadPart);
237  ok_eq_pointer(Bcb, TestContext->Bcb);
238  ok_eq_pointer(Buffer, TestContext->Buffer);
239 
240  CcUnpinData(Bcb);
241  }
242 
243  KmtStartSeh();
244  Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_EXCLUSIVE, &Bcb, (PVOID *)&Buffer);
246 
247  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
248  {
249  ok_bcb(Bcb, 12288, Offset.QuadPart);
250  ok_eq_pointer(Bcb, TestContext->Bcb);
251  ok_eq_pointer(Buffer, TestContext->Buffer);
252 
253  CcUnpinData(Bcb);
254  }
255 
256  KmtStartSeh();
257  Ret = CcMapData(TestFileObject, &Offset, TestContext->Length, MAP_WAIT, &Bcb, (PVOID *)&Buffer);
259 
260  if (!skip(Ret == TRUE, "CcMapData failed\n"))
261  {
262  ok(Bcb != TestContext->Bcb, "Returned same BCB!\n");
263  ok_eq_pointer(Buffer, TestContext->Buffer);
264 
265  CcUnpinData(Bcb);
266  }
267 
268  Offset.QuadPart = 0x1500;
269  TestContext->Length -= 0x500;
270 
271  KmtStartSeh();
272  Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_WAIT | PIN_IF_BCB, &Bcb, (PVOID *)&Buffer);
274 
275  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
276  {
277  ok_bcb(Bcb, 12288, 4096);
278  ok_eq_pointer(Bcb, TestContext->Bcb);
279  ok_eq_pointer(Buffer, (PVOID)((ULONG_PTR)TestContext->Buffer + 0x500));
280 
281  CcUnpinData(Bcb);
282  }
283 
284  KmtStartSeh();
285  Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_WAIT, &Bcb, (PVOID *)&Buffer);
287 
288  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
289  {
290  ok_bcb(Bcb, 12288, 4096);
291  ok_eq_pointer(Bcb, TestContext->Bcb);
292  ok_eq_pointer(Buffer, (PVOID)((ULONG_PTR)TestContext->Buffer + 0x500));
293 
294  CcUnpinData(Bcb);
295  }
296 
297  KmtStartSeh();
298  Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_EXCLUSIVE, &Bcb, (PVOID *)&Buffer);
300 
301  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
302  {
303  ok_bcb(Bcb, 12288, 4096);
304  ok_eq_pointer(Bcb, TestContext->Bcb);
305  ok_eq_pointer(Buffer, (PVOID)((ULONG_PTR)TestContext->Buffer + 0x500));
306 
307  CcUnpinData(Bcb);
308  }
309 
310  return;
311 }
312 
313 static
314 VOID
315 NTAPI
317 {
318  BOOLEAN Ret;
319  PULONG Buffer;
320  PVOID Bcb;
322  PTEST_CONTEXT TestContext;
323 
324  ok(TestFileObject != NULL, "Called in invalid context!\n");
326 
327  TestContext = Context;
328  ok(TestContext != NULL, "Called in invalid context!\n");
329  ok(TestContext->Bcb != NULL, "Called in invalid context!\n");
330  ok(TestContext->Buffer != NULL, "Called in invalid context!\n");
331  ok(TestContext->Length != 0, "Called in invalid context!\n");
332 
333  Ret = FALSE;
334  Offset.QuadPart = 0x1000;
335  KmtStartSeh();
336  Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_EXCLUSIVE, &Bcb, (PVOID *)&Buffer);
338  ok(Ret == FALSE, "CcPinRead succeed\n");
339 
340  if (Ret)
341  {
342  CcUnpinData(Bcb);
343  }
344 
345  KmtStartSeh();
346  Ret = CcMapData(TestFileObject, &Offset, TestContext->Length, 0, &Bcb, (PVOID *)&Buffer);
348 
349  if (!skip(Ret == TRUE, "CcMapData failed\n"))
350  {
351  ok(Bcb != TestContext->Bcb, "Returned same BCB!\n");
352  ok_eq_pointer(Buffer, TestContext->Buffer);
353 
354  CcUnpinData(Bcb);
355  }
356 
357  Offset.QuadPart = 0x1500;
358  TestContext->Length -= 0x500;
359 
360  KmtStartSeh();
361  Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_IF_BCB, &Bcb, (PVOID *)&Buffer);
363  ok(Ret == FALSE, "CcPinRead succeed\n");
364 
365  if (Ret)
366  {
367  CcUnpinData(Bcb);
368  }
369 
370  KmtStartSeh();
371  Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, 0, &Bcb, (PVOID *)&Buffer);
373  ok(Ret == FALSE, "CcPinRead succeed\n");
374 
375  if (Ret)
376  {
377  CcUnpinData(Bcb);
378  }
379 
380  KmtStartSeh();
381  Ret = CcMapData(TestFileObject, &Offset, TestContext->Length, 0, &Bcb, (PVOID *)&Buffer);
383 
384  if (!skip(Ret == TRUE, "CcMapData failed\n"))
385  {
386  ok(Bcb != TestContext->Bcb, "Returned same BCB!\n");
387  ok_eq_pointer(Buffer, (PVOID)((ULONG_PTR)TestContext->Buffer + 0x500));
388 
389  CcUnpinData(Bcb);
390  }
391 
392  return;
393 }
394 
395 static
396 VOID
398  ULONG TestId,
400 {
401  PVOID Bcb;
402  BOOLEAN Ret;
403  PULONG Buffer;
404  PTEST_FCB Fcb;
406 
409  ok_eq_ulong(TestTestId, -1);
410 
412  TestTestId = TestId;
414  if (!skip(TestFileObject != NULL, "Failed to allocate FO\n"))
415  {
417  if (!skip(Fcb != NULL, "ExAllocatePool failed\n"))
418  {
419  BOOLEAN PinAccess = (TestId != 4);
420 
421  RtlZeroMemory(Fcb, sizeof(TEST_FCB));
422  ExInitializeFastMutex(&Fcb->HeaderMutex);
423  FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex);
424 
425  TestFileObject->FsContext = Fcb;
426  TestFileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
427 
428  KmtStartSeh();
429  if (TestId < 6)
430  {
432  }
433  else
434  {
436  }
438 
439  if (!skip(CcIsFileCached(TestFileObject) == TRUE, "CcInitializeCacheMap failed\n"))
440  {
441  if (TestId < 3)
442  {
443  Ret = FALSE;
444  Offset.QuadPart = TestId * 0x1000;
445  KmtStartSeh();
448 
449  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
450  {
451  ok_bcb(Bcb, ((4 - TestId) * 4096), Offset.QuadPart);
452  ok_eq_ulong(Buffer[(0x3000 - TestId * 0x1000) / sizeof(ULONG)], 0xDEADBABE);
453 
454  CcUnpinData(Bcb);
455  }
456  }
457  else if (TestId == 3)
458  {
459  PTEST_CONTEXT TestContext;
460 
461  TestContext = ExAllocatePool(NonPagedPool, sizeof(TEST_CONTEXT));
462  if (!skip(TestContext != NULL, "ExAllocatePool failed\n"))
463  {
464  Ret = FALSE;
465  Offset.QuadPart = 0x1000;
466 
467  /* Try enforce BCB first */
468  KmtStartSeh();
471  ok(Ret == FALSE, "CcPinRead succeed\n");
472  if (Ret)
473  {
474  CcUnpinData(Bcb);
475  }
476 
477  KmtStartSeh();
478  Ret = CcPinRead(TestFileObject, &Offset, FileSizes.FileSize.QuadPart - Offset.QuadPart, PIN_WAIT, &TestContext->Bcb, &TestContext->Buffer);
480 
481  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
482  {
483  PKTHREAD ThreadHandle;
484 
485  ok_bcb(TestContext->Bcb, 12288, Offset.QuadPart);
486 
487  /* That's a bit rough but should do the job */
488 #ifdef _X86_
489  if (Memory >= 2 * 1024)
490  {
491  ok((TestContext->Buffer >= (PVOID)0xC1000000 && TestContext->Buffer < (PVOID)0xE0FFFFFF) ||
492  (TestContext->Buffer >= (PVOID)0xA4000000 && TestContext->Buffer < (PVOID)0xBFFFFFFF),
493  "Buffer %p not mapped in system space\n", TestContext->Buffer);
494  }
495  else if (TS)
496  {
497  ok(TestContext->Buffer >= (PVOID)0xC1000000 && TestContext->Buffer < (PVOID)0xDCFFFFFF,
498  "Buffer %p not mapped in system space\n", TestContext->Buffer);
499  }
500  else
501  {
502  ok(TestContext->Buffer >= (PVOID)0xC1000000 && TestContext->Buffer < (PVOID)0xDBFFFFFF,
503  "Buffer %p not mapped in system space\n", TestContext->Buffer);
504  }
505 #elif defined(_M_AMD64)
506  ok(TestContext->Buffer >= (PVOID)0xFFFFF98000000000 && TestContext->Buffer < (PVOID)0xFFFFFA8000000000,
507  "Buffer %p not mapped in system space\n", TestContext->Buffer);
508 #else
509  skip(FALSE, "System space mapping not defined\n");
510 #endif
511 
512  TestContext->Length = FileSizes.FileSize.QuadPart - Offset.QuadPart;
513  ThreadHandle = KmtStartThread(PinInAnotherThread, TestContext);
514  KmtFinishThread(ThreadHandle, NULL);
515 
516  TestContext->Length = FileSizes.FileSize.QuadPart - 2 * Offset.QuadPart;
517  ThreadHandle = KmtStartThread(PinInAnotherThread, TestContext);
518  KmtFinishThread(ThreadHandle, NULL);
519 
520  CcUnpinData(TestContext->Bcb);
521  }
522 
523  KmtStartSeh();
524  Ret = CcPinRead(TestFileObject, &Offset, FileSizes.FileSize.QuadPart - Offset.QuadPart, PIN_WAIT | PIN_EXCLUSIVE, &TestContext->Bcb, &TestContext->Buffer);
526 
527  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
528  {
529  PKTHREAD ThreadHandle;
530 
531  ok_bcb(TestContext->Bcb, 12288, Offset.QuadPart);
532 
533  TestContext->Length = FileSizes.FileSize.QuadPart - Offset.QuadPart;
534  ThreadHandle = KmtStartThread(PinInAnotherThreadExclusive, TestContext);
535  KmtFinishThread(ThreadHandle, NULL);
536 
537  CcUnpinData(TestContext->Bcb);
538  }
539 
540  ExFreePool(TestContext);
541  }
542  }
543  else if (TestId == 4)
544  {
545  Ret = FALSE;
546  Offset.QuadPart = 0x1000;
547  KmtStartSeh();
550 
551  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
552  {
553  ok_bcb(Bcb, 12288, Offset.QuadPart);
554  ok_eq_ulong(Buffer[0x2000 / sizeof(ULONG)], 0);
555 
556  CcUnpinData(Bcb);
557  }
558  }
559  else if (TestId == 5)
560  {
561  /* Pin after EOF */
562  Ret = FALSE;
563  Offset.QuadPart = FileSizes.FileSize.QuadPart + 0x1000;
564 
565  KmtStartSeh();
566  Ret = CcPinRead(TestFileObject, &Offset, 0x1000, 0, &Bcb, (PVOID *)&Buffer);
568  ok(Ret == FALSE, "CcPinRead succeed\n");
569 
570  if (Ret)
571  {
572  CcUnpinData(Bcb);
573  }
574 
575  /* Pin a VACB after EOF */
576  Ret = FALSE;
578 
579  KmtStartSeh();
580  Ret = CcPinRead(TestFileObject, &Offset, 0x1000, 0, &Bcb, (PVOID *)&Buffer);
582  ok(Ret == FALSE, "CcPinRead succeed\n");
583 
584  if (Ret)
585  {
586  CcUnpinData(Bcb);
587  }
588 
589  /* Pin more than a VACB */
590  Ret = FALSE;
591  Offset.QuadPart = 0x0;
592 
593  KmtStartSeh();
596  ok(Ret == FALSE, "CcPinRead succeed\n");
597 
598  if (Ret)
599  {
600  CcUnpinData(Bcb);
601  }
602  }
603  else if (TestId == 6)
604  {
605  Ret = FALSE;
606  Offset.QuadPart = 0;
607 
608  KmtStartSeh();
611 
612  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
613  {
614  ok_bcb(Bcb, PAGE_SIZE * 4, Offset.QuadPart);
617 
618  CcUnpinData(Bcb);
619  }
620  }
621  }
622  }
623  }
624 }
625 
626 
627 static
628 VOID
630  ULONG TestId,
632 {
634  CACHE_UNINITIALIZE_EVENT CacheUninitEvent;
635 
637  ok_eq_ulong(TestTestId, TestId);
638 
639  if (!skip(TestFileObject != NULL, "No test FO\n"))
640  {
642  {
643  KeInitializeEvent(&CacheUninitEvent.Event, NotificationEvent, FALSE);
644  CcUninitializeCacheMap(TestFileObject, &Zero, &CacheUninitEvent);
645  KeWaitForSingleObject(&CacheUninitEvent.Event, Executive, KernelMode, FALSE, NULL);
646  }
647 
648  if (TestFileObject->FsContext != NULL)
649  {
650  ExFreePool(TestFileObject->FsContext);
651  TestFileObject->FsContext = NULL;
652  TestFileObject->SectionObjectPointer = NULL;
653  }
654 
655  if (TestTestId == 6)
656  {
657  ok_bool_true(TestWriteCalled, "Write was not called!\n");
658  }
659  else
660  {
661  ok_bool_false(TestWriteCalled, "Write was unexpectedly called\n");
662  }
663 
665  }
666 
669  TestTestId = -1;
671 }
672 
673 
674 static
675 NTSTATUS
680  _In_ SIZE_T InLength,
681  _Inout_ PSIZE_T OutLength)
682 {
684 
686 
687  switch (ControlCode)
688  {
689  case IOCTL_START_TEST:
690  ok_eq_ulong((ULONG)InLength, sizeof(ULONG));
692  break;
693 
694  case IOCTL_FINISH_TEST:
695  ok_eq_ulong((ULONG)InLength, sizeof(ULONG));
697  break;
698 
699  default:
701  break;
702  }
703 
705 
706  return Status;
707 }
708 
709 static
710 NTSTATUS
713  _In_ PIRP Irp,
714  _In_ PIO_STACK_LOCATION IoStack)
715 {
717 
718  PAGED_CODE();
719 
720  DPRINT("IRP %x/%x\n", IoStack->MajorFunction, IoStack->MinorFunction);
721  ASSERT(IoStack->MajorFunction == IRP_MJ_READ ||
722  IoStack->MajorFunction == IRP_MJ_WRITE);
723 
725 
727  Irp->IoStatus.Information = 0;
728 
729  if (IoStack->MajorFunction == IRP_MJ_READ)
730  {
731  PMDL Mdl;
732  ULONG Length;
733  PVOID Buffer;
735 
736  Offset = IoStack->Parameters.Read.ByteOffset;
737  Length = IoStack->Parameters.Read.Length;
738 
740  ok_eq_pointer(IoStack->FileObject, TestFileObject);
741 
742  ok(FlagOn(Irp->Flags, IRP_NOCACHE), "Not coming from Cc\n");
743 
744  ok_irql(APC_LEVEL);
745  ok((Offset.QuadPart % PAGE_SIZE == 0 || Offset.QuadPart == 0), "Offset is not aligned: %I64i\n", Offset.QuadPart);
746  ok(Length % PAGE_SIZE == 0, "Length is not aligned: %I64i\n", Length);
747 
748  ok(Irp->AssociatedIrp.SystemBuffer == NULL, "A SystemBuffer was allocated!\n");
750  ok(Buffer != NULL, "Null pointer!\n");
751  RtlFillMemory(Buffer, Length, 0xBA);
752 
754  if (Offset.QuadPart <= 0x3000 && Offset.QuadPart + Length > 0x3000)
755  {
756  *(PULONG)((ULONG_PTR)Buffer + (ULONG_PTR)(0x3000 - Offset.QuadPart)) = 0xDEADBABE;
757  }
758 
759  Mdl = Irp->MdlAddress;
760  ok(Mdl != NULL, "Null pointer for MDL!\n");
761  ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) != 0, "MDL not locked\n");
762  ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) == 0, "MDL from non paged\n");
763  ok((Mdl->MdlFlags & MDL_IO_PAGE_READ) != 0, "Non paging IO\n");
764  ok((Irp->Flags & IRP_PAGING_IO) != 0, "Non paging IO\n");
765 
766  Irp->IoStatus.Information = Length;
767  }
768  else if (IoStack->MajorFunction == IRP_MJ_WRITE)
769  {
770  PMDL Mdl;
771  ULONG Length;
772  PVOID Buffer;
774 
775  Offset = IoStack->Parameters.Write.ByteOffset;
776  Length = IoStack->Parameters.Write.Length;
777 
778  ok(TestTestId == 6, "Unexpected test id: %d\n", TestTestId);
780  ok_eq_pointer(IoStack->FileObject, TestFileObject);
781 
782  ok(FlagOn(Irp->Flags, IRP_NOCACHE), "Not coming from Cc\n");
783 
784  ok_irql(PASSIVE_LEVEL);
785  ok(Offset.QuadPart == 0, "Offset is not null: %I64i\n", Offset.QuadPart);
786  ok(Length % PAGE_SIZE == 0, "Length is not aligned: %I64i\n", Length);
787  ok(Length == PAGE_SIZE * 4, "Length is not MappedLength-sized: %I64i\n", Length);
788 
790  ok(Buffer != NULL, "Null pointer!\n");
791 
792  Mdl = Irp->MdlAddress;
793  ok(Mdl != NULL, "Null pointer for MDL!\n");
794  ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) != 0, "MDL not locked\n");
795  ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) == 0, "MDL from non paged\n");
796  ok((Irp->Flags & IRP_PAGING_IO) != 0, "Non paging IO\n");
797 
798  ok_bool_false(TestWriteCalled, "Write has been unexpectedly called twice!\n");
800 
802  Irp->IoStatus.Information = Length;
803  }
804 
805  if (Status == STATUS_PENDING)
806  {
810  }
811  else
812  {
813  Irp->IoStatus.Status = Status;
815  }
816 
818 
819  return Status;
820 }
#define MDL_IO_PAGE_READ
Definition: mmtypes.h:24
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:269
#define ok_eq_ulong(value, expected)
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define IN
Definition: typedefs.h:39
#define IOCTL_FINISH_TEST
Definition: CcPinRead_drv.c:14
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL)
#define LL
Definition: tui.h:84
#define FsRtlEnterFileSystem
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:411
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
#define FsRtlExitFileSystem
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:931
static VOID PerformTest(ULONG TestId, PDEVICE_OBJECT DeviceObject)
static CACHE_MANAGER_CALLBACKS Callbacks
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
VOID NTAPI CcSetDirtyPinnedData(IN PVOID BcbVoid, IN OPTIONAL PLARGE_INTEGER Lsn)
Definition: cachesub.c:121
#define ok_eq_pointer(value, expected)
LONG NTSTATUS
Definition: precomp.h:26
static PFILE_OBJECT TestFileObject
Definition: CcPinRead_drv.c:31
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:283
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
static PDEVICE_OBJECT TestDeviceObject
Definition: CcPinRead_drv.c:32
#define IRP_NOCACHE
#define MAP_WAIT
static PVOID MapAndLockUserBuffer(_In_ _Out_ PIRP Irp, _In_ ULONG BufferLength)
#define PIN_WAIT
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
VOID TestUnload(_In_ PDRIVER_OBJECT DriverObject)
Definition: CcPinRead_drv.c:95
#define VER_SUITE_TERMINAL
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
struct _TEST_CONTEXT TEST_CONTEXT
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
int32_t INT
Definition: typedefs.h:58
#define _In_opt_
Definition: no_sal2.h:213
LARGE_INTEGER FileSize
Definition: cctypes.h:16
_SEH2_TRY
Definition: create.c:4226
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define ok_bool_false(value, desc)
Definition: kmt_test.h:257
#define ok_bool_true(value, desc)
Definition: kmt_test.h:256
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define RTL_CONSTANT_LARGE_INTEGER(quad_part)
Definition: rtltypes.h:416
static CC_FILE_SIZES SmallFileSizes
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define FALSE
Definition: types.h:117
static CC_FILE_SIZES FileSizes
#define CcIsFileCached(FO)
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
NTSYSAPI NTSTATUS NTAPI ZwQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
unsigned char BOOLEAN
NTSTATUS TestEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PCUNICODE_STRING RegistryPath, _Out_ PCWSTR *DeviceName, _Inout_ INT *Flags)
Definition: CcPinRead_drv.c:40
smooth NULL
Definition: ftsmooth.c:416
#define _Out_
Definition: no_sal2.h:323
#define MDL_SOURCE_IS_NONPAGED_POOL
Definition: mmtypes.h:20
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
Definition: bufpool.h:45
PFILE_OBJECT NTAPI IoCreateStreamFileObject(IN PFILE_OBJECT FileObject, IN PDEVICE_OBJECT DeviceObject)
Definition: file.c:3186
NTSTATUS KmtRegisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
FAST_MUTEX
Definition: extypes.h:17
int64_t LONGLONG
Definition: typedefs.h:68
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
_In_z_ PWSTR RegistryPath
Definition: classp.h:1930
NTSTATUS KmtRegisterMessageHandler(IN ULONG ControlCode OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_MESSAGE_HANDLER MessageHandler)
#define trace
Definition: atltest.h:70
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define MDL_PAGES_LOCKED
Definition: mmtypes.h:19
_In_ UCHAR BufferLength
Definition: scsi.h:4067
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
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:195
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
uint64_t ULONGLONG
Definition: typedefs.h:67
static VOID NTAPI PinInAnotherThread(IN PVOID Context)
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
static KMT_IRP_HANDLER TestIrpHandler
Definition: CcPinRead_drv.c:33
SECTION_OBJECT_POINTERS SectionObjectPointers
#define _Inout_
Definition: no_sal2.h:244
static BOOLEAN TS
Definition: CcPinRead_drv.c:37
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
* PFILE_OBJECT
Definition: iotypes.h:1978
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
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOLEAN NTAPI AcquireForLazyWrite(_In_ PVOID Context, _In_ BOOLEAN Wait)
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
BOOLEAN NTAPI AcquireForReadAhead(_In_ PVOID Context, _In_ BOOLEAN Wait)
FSRTL_ADVANCED_FCB_HEADER Header
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
ULONG LowPart
Definition: typedefs.h:106
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define KmtStartSeh()
Definition: kmt_test.h:277
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL)
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
#define _In_
Definition: no_sal2.h:204
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_SEH2_END
Definition: create.c:4400
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
static VOID CleanupTest(ULONG TestId, PDEVICE_OBJECT DeviceObject)
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define ok_bcb(B, L, O)
#define PIN_IF_BCB
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:286
#define VER_SUITE_SINGLEUSERTS
#define ok(value,...)
Definition: atltest.h:57
VOID NTAPI ReleaseFromLazyWrite(_In_ PVOID Context)
struct _TEST_FCB TEST_FCB
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
static KMT_MESSAGE_HANDLER TestMessageHandler
Definition: CcPinRead_drv.c:34
unsigned int * PULONG
Definition: retypes.h:1
#define IOCTL_START_TEST
Definition: CcPinRead_drv.c:13
struct _TEST_CONTEXT * PTEST_CONTEXT
static ULONGLONG Memory
Definition: CcPinRead_drv.c:36
#define PIN_EXCLUSIVE
#define IRP_PAGING_IO
IN PVCB IN VBO IN ULONG OUT PBCB OUT PVOID IN BOOLEAN IN BOOLEAN Zero
Definition: fatprocs.h:411
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define skip(...)
Definition: atltest.h:64
FAST_MUTEX HeaderMutex
static ULONG TestTestId
Definition: CcPinRead_drv.c:30
#define VACB_MAPPING_GRANULARITY
static BOOLEAN TestWriteCalled
Definition: CcPinRead_drv.c:35
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:581
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
static VOID NTAPI PinInAnotherThreadExclusive(IN PVOID Context)
_In_ PFCB Fcb
Definition: cdprocs.h:159
VOID NTAPI ReleaseFromReadAhead(_In_ PVOID Context)
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:3014
IoMarkIrpPending(Irp)
#define APC_LEVEL
Definition: env_spec_w32.h:695
SECTION_OBJECT_POINTERS SectionObjectPointers
Definition: ntfs.h:514
struct _TEST_FCB * PTEST_FCB
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
LONGLONG QuadPart
Definition: typedefs.h:114
#define PAGED_CODE()
IN BOOLEAN Wait
Definition: fatprocs.h:1538