ReactOS 0.4.16-dev-340-g0540c21
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
16typedef struct _TEST_FCB
17{
22
23typedef struct _TEST_CONTEXT
24{
25 PVOID Bcb;
29
30static ULONG TestTestId = -1;
33static KMT_IRP_HANDLER TestIrpHandler;
34static KMT_MESSAGE_HANDLER TestMessageHandler;
36static ULONGLONG Memory = 0;
37static BOOLEAN TS = FALSE;
38
41
48{
53
54 PAGED_CODE();
55
57
58 *DeviceName = L"CcPinRead";
59 *Flags = TESTENTRY_NO_EXCLUSIVE_DEVICE |
60 TESTENTRY_BUFFERED_IO_DEVICE |
61 TESTENTRY_NO_READONLY_DEVICE;
62
66
68 &SBI,
69 sizeof(SBI),
70 &Length);
71 if (NT_SUCCESS(Status))
72 {
73 Memory = (SBI.NumberOfPhysicalPages * SBI.PageSize) / 1024 / 1024;
74 }
75 else
76 {
78 }
79
82 if (NT_SUCCESS(Status))
83 {
86 }
87 else
88 {
90 }
91
92 trace("System with %I64dMb RAM and terminal services %S\n", Memory, (TS ? L"enabled" : L"disabled"));
93
94 return Status;
95}
96
97VOID
100{
101 PAGED_CODE();
102}
103
105NTAPI
109{
110 return TRUE;
111}
112
113VOID
114NTAPI
117{
118 return;
119}
120
122NTAPI
126{
127 return TRUE;
128}
129
130VOID
131NTAPI
134{
135 return;
136}
137
143};
144
146 RTL_CONSTANT_LARGE_INTEGER((LONGLONG)0x4000), // .AllocationSize
147 RTL_CONSTANT_LARGE_INTEGER((LONGLONG)0x4000), // .FileSize
148 RTL_CONSTANT_LARGE_INTEGER((LONGLONG)0x4000) // .ValidDataLength
149};
150
152 RTL_CONSTANT_LARGE_INTEGER((LONGLONG)512), // .AllocationSize
153 RTL_CONSTANT_LARGE_INTEGER((LONGLONG)496), // .FileSize
154 RTL_CONSTANT_LARGE_INTEGER((LONGLONG)496) // .ValidDataLength
155};
156
157static
158PVOID
162{
163 PMDL Mdl;
164
165 if (Irp->MdlAddress == NULL)
166 {
167 Mdl = IoAllocateMdl(Irp->UserBuffer, BufferLength, FALSE, FALSE, Irp);
168 if (Mdl == NULL)
169 {
170 return NULL;
171 }
172
174 {
175 MmProbeAndLockPages(Mdl, Irp->RequestorMode, IoWriteAccess);
176 }
178 {
179 IoFreeMdl(Mdl);
180 Irp->MdlAddress = NULL;
181 _SEH2_YIELD(return NULL);
182 }
183 _SEH2_END;
184 }
185
187}
188
189#define ok_bcb(B, L, O) \
190{ \
191 PPUBLIC_BCB public_bcb = (B); \
192 ok(public_bcb->NodeTypeCode == 0x2FD, "Not a BCB: %04x\n", public_bcb->NodeTypeCode); \
193 ok(public_bcb->NodeByteSize == 0, "Invalid size: %d\n", public_bcb->NodeByteSize); \
194 ok_eq_ulong(public_bcb->MappedLength, (L)); \
195 ok_eq_longlong(public_bcb->MappedFileOffset.QuadPart, (O)); \
196}
197
198static
199VOID
200NTAPI
202{
203 BOOLEAN Ret;
205 PVOID Bcb;
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 = 0x1000;
220 KmtStartSeh();
221 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_WAIT, &Bcb, (PVOID *)&Buffer);
223
224 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
225 {
226 ok_bcb(Bcb, 12288, Offset.QuadPart);
227 ok_eq_pointer(Bcb, TestContext->Bcb);
228 ok_eq_pointer(Buffer, TestContext->Buffer);
229
231 }
232
233 KmtStartSeh();
234 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_WAIT | PIN_IF_BCB, &Bcb, (PVOID *)&Buffer);
236
237 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
238 {
239 ok_bcb(Bcb, 12288, Offset.QuadPart);
240 ok_eq_pointer(Bcb, TestContext->Bcb);
241 ok_eq_pointer(Buffer, TestContext->Buffer);
242
244 }
245
246 KmtStartSeh();
247 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_EXCLUSIVE, &Bcb, (PVOID *)&Buffer);
249
250 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
251 {
252 ok_bcb(Bcb, 12288, Offset.QuadPart);
253 ok_eq_pointer(Bcb, TestContext->Bcb);
254 ok_eq_pointer(Buffer, TestContext->Buffer);
255
257 }
258
259 KmtStartSeh();
260 Ret = CcMapData(TestFileObject, &Offset, TestContext->Length, MAP_WAIT, &Bcb, (PVOID *)&Buffer);
262
263 if (!skip(Ret == TRUE, "CcMapData failed\n"))
264 {
265 ok(Bcb != TestContext->Bcb, "Returned same BCB!\n");
266 ok_eq_pointer(Buffer, TestContext->Buffer);
267
269 }
270
271 Offset.QuadPart = 0x1500;
272 TestContext->Length -= 0x500;
273
274 KmtStartSeh();
275 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_WAIT | PIN_IF_BCB, &Bcb, (PVOID *)&Buffer);
277
278 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
279 {
280 ok_bcb(Bcb, 12288, 4096);
281 ok_eq_pointer(Bcb, TestContext->Bcb);
282 ok_eq_pointer(Buffer, (PVOID)((ULONG_PTR)TestContext->Buffer + 0x500));
283
285 }
286
287 KmtStartSeh();
288 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_WAIT, &Bcb, (PVOID *)&Buffer);
290
291 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
292 {
293 ok_bcb(Bcb, 12288, 4096);
294 ok_eq_pointer(Bcb, TestContext->Bcb);
295 ok_eq_pointer(Buffer, (PVOID)((ULONG_PTR)TestContext->Buffer + 0x500));
296
298 }
299
300 KmtStartSeh();
301 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_EXCLUSIVE, &Bcb, (PVOID *)&Buffer);
303
304 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
305 {
306 ok_bcb(Bcb, 12288, 4096);
307 ok_eq_pointer(Bcb, TestContext->Bcb);
308 ok_eq_pointer(Buffer, (PVOID)((ULONG_PTR)TestContext->Buffer + 0x500));
309
311 }
312
313 return;
314}
315
316static
317VOID
318NTAPI
320{
321 BOOLEAN Ret;
323 PVOID Bcb;
325 PTEST_CONTEXT TestContext;
326
327 ok(TestFileObject != NULL, "Called in invalid context!\n");
329
330 TestContext = Context;
331 ok(TestContext != NULL, "Called in invalid context!\n");
332 ok(TestContext->Bcb != NULL, "Called in invalid context!\n");
333 ok(TestContext->Buffer != NULL, "Called in invalid context!\n");
334 ok(TestContext->Length != 0, "Called in invalid context!\n");
335
336 Ret = FALSE;
337 Offset.QuadPart = 0x1000;
338 KmtStartSeh();
339 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_EXCLUSIVE, &Bcb, (PVOID *)&Buffer);
341 ok(Ret == FALSE, "CcPinRead succeed\n");
342
343 if (Ret)
344 {
346 }
347
348 KmtStartSeh();
349 Ret = CcMapData(TestFileObject, &Offset, TestContext->Length, 0, &Bcb, (PVOID *)&Buffer);
351
352 if (!skip(Ret == TRUE, "CcMapData failed\n"))
353 {
354 ok(Bcb != TestContext->Bcb, "Returned same BCB!\n");
355 ok_eq_pointer(Buffer, TestContext->Buffer);
356
358 }
359
360 Offset.QuadPart = 0x1500;
361 TestContext->Length -= 0x500;
362
363 KmtStartSeh();
364 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_IF_BCB, &Bcb, (PVOID *)&Buffer);
366 ok(Ret == FALSE, "CcPinRead succeed\n");
367
368 if (Ret)
369 {
371 }
372
373 KmtStartSeh();
374 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, 0, &Bcb, (PVOID *)&Buffer);
376 ok(Ret == FALSE, "CcPinRead succeed\n");
377
378 if (Ret)
379 {
381 }
382
383 KmtStartSeh();
384 Ret = CcMapData(TestFileObject, &Offset, TestContext->Length, 0, &Bcb, (PVOID *)&Buffer);
386
387 if (!skip(Ret == TRUE, "CcMapData failed\n"))
388 {
389 ok(Bcb != TestContext->Bcb, "Returned same BCB!\n");
390 ok_eq_pointer(Buffer, (PVOID)((ULONG_PTR)TestContext->Buffer + 0x500));
391
393 }
394
395 return;
396}
397
398static
399VOID
401 ULONG TestId,
403{
404 PVOID Bcb;
405 BOOLEAN Ret;
409
413
415 TestTestId = TestId;
417 if (!skip(TestFileObject != NULL, "Failed to allocate FO\n"))
418 {
420 if (!skip(Fcb != NULL, "ExAllocatePool failed\n"))
421 {
422 BOOLEAN PinAccess = (TestId != 4);
423
424 RtlZeroMemory(Fcb, sizeof(TEST_FCB));
425 ExInitializeFastMutex(&Fcb->HeaderMutex);
426 FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex);
427
428 TestFileObject->FsContext = Fcb;
429 TestFileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
430
431 KmtStartSeh();
432 if (TestId < 6)
433 {
435 }
436 else
437 {
439 }
441
442 if (!skip(CcIsFileCached(TestFileObject) == TRUE, "CcInitializeCacheMap failed\n"))
443 {
444 if (TestId < 3)
445 {
446 Ret = FALSE;
447 Offset.QuadPart = TestId * 0x1000;
448 KmtStartSeh();
451
452 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
453 {
454 ok_bcb(Bcb, ((4 - TestId) * 4096), Offset.QuadPart);
455 ok_eq_ulong(Buffer[(0x3000 - TestId * 0x1000) / sizeof(ULONG)], 0xDEADBABE);
456
458 }
459 }
460 else if (TestId == 3)
461 {
462 PTEST_CONTEXT TestContext;
463
464 TestContext = ExAllocatePool(NonPagedPool, sizeof(TEST_CONTEXT));
465 if (!skip(TestContext != NULL, "ExAllocatePool failed\n"))
466 {
467 Ret = FALSE;
468 Offset.QuadPart = 0x1000;
469
470 /* Try enforce BCB first */
471 KmtStartSeh();
474 ok(Ret == FALSE, "CcPinRead succeed\n");
475 if (Ret)
476 {
478 }
479
480 KmtStartSeh();
481 Ret = CcPinRead(TestFileObject, &Offset, FileSizes.FileSize.QuadPart - Offset.QuadPart, PIN_WAIT, &TestContext->Bcb, &TestContext->Buffer);
483
484 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
485 {
486 PKTHREAD ThreadHandle;
487
488 ok_bcb(TestContext->Bcb, 12288, Offset.QuadPart);
489
490 /* That's a bit rough but should do the job */
491#ifdef _X86_
492 if (Memory >= 2 * 1024)
493 {
494 ok((TestContext->Buffer >= (PVOID)0xC1000000 && TestContext->Buffer < (PVOID)0xE0FFFFFF) ||
495 (TestContext->Buffer >= (PVOID)0xA4000000 && TestContext->Buffer < (PVOID)0xBFFFFFFF),
496 "Buffer %p not mapped in system space\n", TestContext->Buffer);
497 }
498 else if (TS)
499 {
500 ok(TestContext->Buffer >= (PVOID)0xC1000000 && TestContext->Buffer < (PVOID)0xDCFFFFFF,
501 "Buffer %p not mapped in system space\n", TestContext->Buffer);
502 }
503 else
504 {
505 ok(TestContext->Buffer >= (PVOID)0xC1000000 && TestContext->Buffer < (PVOID)0xDBFFFFFF,
506 "Buffer %p not mapped in system space\n", TestContext->Buffer);
507 }
508#elif defined(_M_AMD64)
509 ok(TestContext->Buffer >= (PVOID)0xFFFFF98000000000 && TestContext->Buffer < (PVOID)0xFFFFFA8000000000,
510 "Buffer %p not mapped in system space\n", TestContext->Buffer);
511#else
512 skip(FALSE, "System space mapping not defined\n");
513#endif
514
515 TestContext->Length = FileSizes.FileSize.QuadPart - Offset.QuadPart;
516 ThreadHandle = KmtStartThread(PinInAnotherThread, TestContext);
517 KmtFinishThread(ThreadHandle, NULL);
518
519 TestContext->Length = FileSizes.FileSize.QuadPart - 2 * Offset.QuadPart;
520 ThreadHandle = KmtStartThread(PinInAnotherThread, TestContext);
521 KmtFinishThread(ThreadHandle, NULL);
522
523 CcUnpinData(TestContext->Bcb);
524 }
525
526 KmtStartSeh();
527 Ret = CcPinRead(TestFileObject, &Offset, FileSizes.FileSize.QuadPart - Offset.QuadPart, PIN_WAIT | PIN_EXCLUSIVE, &TestContext->Bcb, &TestContext->Buffer);
529
530 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
531 {
532 PKTHREAD ThreadHandle;
533
534 ok_bcb(TestContext->Bcb, 12288, Offset.QuadPart);
535
536 TestContext->Length = FileSizes.FileSize.QuadPart - Offset.QuadPart;
537 ThreadHandle = KmtStartThread(PinInAnotherThreadExclusive, TestContext);
538 KmtFinishThread(ThreadHandle, NULL);
539
540 CcUnpinData(TestContext->Bcb);
541 }
542
543 ExFreePool(TestContext);
544 }
545 }
546 else if (TestId == 4)
547 {
548 Ret = FALSE;
549 Offset.QuadPart = 0x1000;
550 KmtStartSeh();
553
554 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
555 {
556 ok_bcb(Bcb, 12288, Offset.QuadPart);
557 ok_eq_ulong(Buffer[0x2000 / sizeof(ULONG)], 0);
558
560 }
561 }
562 else if (TestId == 5)
563 {
566
567 /* Pin after EOF */
568 Ret = FALSE;
569 Offset.QuadPart = FileSizes.FileSize.QuadPart + 0x1000;
570
571 KmtStartSeh();
572 Ret = CcPinRead(TestFileObject, &Offset, 0x1000, PIN_WAIT, &Bcb, (PVOID *)&Buffer);
574 ok(Ret == TRUE, "CcPinRead failed\n");
575 if (Ret)
576 {
578 }
579
580 /* Pin a VACB after EOF */
581 Ret = FALSE;
583
584 KmtStartSeh();
585 Ret = CcPinRead(TestFileObject, &Offset, 0x1000, PIN_WAIT, &Bcb, (PVOID *)&Buffer);
587 ok(Ret == TRUE, "CcPinRead failed\n");
588 if (Ret)
589 {
591 }
592
593 /* Pin after Allocation */
594 Ret = FALSE;
595 Offset.QuadPart = FileSizes.AllocationSize.QuadPart + 0x1000;
596
597 KmtStartSeh();
598 Ret = CcPinRead(TestFileObject, &Offset, 0x1000, PIN_WAIT, &Bcb, (PVOID *)&Buffer);
600 ok(Ret == TRUE, "CcPinRead failed\n");
601 if (Ret)
602 {
603 /* Set this one dirty */
605
607
608 WriteOffset.QuadPart = -1LL;
610 /* Flush to trigger the write */
611 CcFlushCache(TestFileObject->SectionObjectPointer, &Offset, 0x1000, NULL);
612
613 ok_eq_longlong(WriteOffset.QuadPart, Offset.QuadPart);
614 ok_eq_ulong(WriteLength, 0x1000);
615 }
616
617 /* Pin a VACB after Allocation */
618 Ret = FALSE;
620
621 KmtStartSeh();
622 Ret = CcPinRead(TestFileObject, &Offset, 0x1000, PIN_WAIT, &Bcb, (PVOID *)&Buffer);
624 ok(Ret == TRUE, "CcPinRead failed\n");
625 if (Ret)
626 {
627 /* Set this one dirty */
629
631
632 WriteOffset.QuadPart = -1LL;
634 /* Flush to trigger the write */
635 CcFlushCache(TestFileObject->SectionObjectPointer, &Offset, 0x1000, NULL);
636
637 ok_eq_longlong(WriteOffset.QuadPart, Offset.QuadPart);
638 ok_eq_ulong(WriteLength, 0x1000);
639 }
640
641 /* Pin more than a VACB */
642 Ret = FALSE;
643 Offset.QuadPart = 0x0;
644
645 KmtStartSeh();
648 ok(Ret == TRUE, "CcPinRead failed\n");
649 if (Ret)
650 {
651 /* Set this one dirty */
653
655
656 /* The data is dirtified through the VACB */
657 WriteOffset.QuadPart = -1LL;
659 CcFlushCache(TestFileObject->SectionObjectPointer, &Offset, VACB_MAPPING_GRANULARITY + 0x1000, NULL);
660
661 ok_eq_longlong(WriteOffset.QuadPart, Offset.QuadPart);
663 }
664 }
665 else if (TestId == 6)
666 {
667 Ret = FALSE;
668 Offset.QuadPart = 0;
669
670 KmtStartSeh();
673
674 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
675 {
676 ok_bcb(Bcb, PAGE_SIZE * 4, Offset.QuadPart);
679
681 }
682 }
683 }
684 }
685 }
686}
687
688
689static
690VOID
692 ULONG TestId,
694{
696 CACHE_UNINITIALIZE_EVENT CacheUninitEvent;
697
699 ok_eq_ulong(TestTestId, TestId);
700
701 if (!skip(TestFileObject != NULL, "No test FO\n"))
702 {
704 {
705 KeInitializeEvent(&CacheUninitEvent.Event, NotificationEvent, FALSE);
706 CcUninitializeCacheMap(TestFileObject, &Zero, &CacheUninitEvent);
708 }
709
710 if (TestFileObject->FsContext != NULL)
711 {
712 ExFreePool(TestFileObject->FsContext);
713 TestFileObject->FsContext = NULL;
714 TestFileObject->SectionObjectPointer = NULL;
715 }
716
717 if (TestTestId == 6)
718 {
719 ok_bool_true(TestWriteCalled, "Write was not called!\n");
720 }
721 else
722 {
723 ok_bool_false(TestWriteCalled, "Write was unexpectedly called\n");
724 }
725
727 }
728
731 TestTestId = -1;
733}
734
735
736static
742 _In_ SIZE_T InLength,
743 _Inout_ PSIZE_T OutLength)
744{
746
748
749 switch (ControlCode)
750 {
751 case IOCTL_START_TEST:
752 ok_eq_ulong((ULONG)InLength, sizeof(ULONG));
754 break;
755
757 ok_eq_ulong((ULONG)InLength, sizeof(ULONG));
759 break;
760
761 default:
763 break;
764 }
765
767
768 return Status;
769}
770
771static
775 _In_ PIRP Irp,
776 _In_ PIO_STACK_LOCATION IoStack)
777{
779
780 PAGED_CODE();
781
782 DPRINT("IRP %x/%x\n", IoStack->MajorFunction, IoStack->MinorFunction);
783 ASSERT(IoStack->MajorFunction == IRP_MJ_READ ||
784 IoStack->MajorFunction == IRP_MJ_WRITE);
785
787
789 Irp->IoStatus.Information = 0;
790
791 if (IoStack->MajorFunction == IRP_MJ_READ)
792 {
793 PMDL Mdl;
797
798 Offset = IoStack->Parameters.Read.ByteOffset;
799 Length = IoStack->Parameters.Read.Length;
800
802 ok_eq_pointer(IoStack->FileObject, TestFileObject);
803
804 ok(FlagOn(Irp->Flags, IRP_NOCACHE), "Not coming from Cc\n");
805
806 ok_irql(APC_LEVEL);
807 ok((Offset.QuadPart % PAGE_SIZE == 0 || Offset.QuadPart == 0), "Offset is not aligned: %I64i\n", Offset.QuadPart);
808 ok(Length % PAGE_SIZE == 0, "Length is not aligned: %I64i\n", Length);
809
810 ok(Irp->AssociatedIrp.SystemBuffer == NULL, "A SystemBuffer was allocated!\n");
812 ok(Buffer != NULL, "Null pointer!\n");
814
816 if (Offset.QuadPart <= 0x3000 && Offset.QuadPart + Length > 0x3000)
817 {
818 *(PULONG)((ULONG_PTR)Buffer + (ULONG_PTR)(0x3000 - Offset.QuadPart)) = 0xDEADBABE;
819 }
820
821 Mdl = Irp->MdlAddress;
822 ok(Mdl != NULL, "Null pointer for MDL!\n");
823 ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) != 0, "MDL not locked\n");
824 ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) == 0, "MDL from non paged\n");
825 ok((Mdl->MdlFlags & MDL_IO_PAGE_READ) != 0, "Non paging IO\n");
826 ok((Irp->Flags & IRP_PAGING_IO) != 0, "Non paging IO\n");
827
828 Irp->IoStatus.Information = Length;
829 }
830 else if (IoStack->MajorFunction == IRP_MJ_WRITE)
831 {
832 PMDL Mdl;
836
837 Offset = IoStack->Parameters.Write.ByteOffset;
838 Length = IoStack->Parameters.Write.Length;
839
840 ok((TestTestId == 5) || (TestTestId == 6), "Unexpected test id: %d\n", TestTestId);
842 ok_eq_pointer(IoStack->FileObject, TestFileObject);
843
844 ok(FlagOn(Irp->Flags, IRP_NOCACHE), "Not coming from Cc\n");
845
846 ok_irql(PASSIVE_LEVEL);
847
848 if (TestTestId == 5)
849 {
850 /* This assumes continuous writes. */
851 if (WriteOffset.QuadPart != -1)
852 {
853 LONGLONG WriteEnd = WriteOffset.QuadPart + WriteLength;
854
855 if (WriteOffset.QuadPart > Offset.QuadPart)
857 if (WriteEnd < (Offset.QuadPart + Length))
858 WriteLength = (Offset.QuadPart + Length) - WriteOffset.QuadPart;
859 }
860 else
861 {
864 }
865 }
866 else
867 {
868 ok(Offset.QuadPart == 0, "Offset is not null: %I64i\n", Offset.QuadPart);
869 ok(Length % PAGE_SIZE == 0, "Length is not aligned: %I64i\n", Length);
870 ok(Length == PAGE_SIZE * 4, "Length is not MappedLength-sized: %I64i\n", Length);
871
873 ok(Buffer != NULL, "Null pointer!\n");
874
875 Mdl = Irp->MdlAddress;
876 ok(Mdl != NULL, "Null pointer for MDL!\n");
877 ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) != 0, "MDL not locked\n");
878 ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) == 0, "MDL from non paged\n");
879 ok((Irp->Flags & IRP_PAGING_IO) != 0, "Non paging IO\n");
880
881 ok_bool_false(TestWriteCalled, "Write has been unexpectedly called twice!\n");
883 }
884
886 Irp->IoStatus.Information = Length;
887 }
888
889 if (Status == STATUS_PENDING)
890 {
894 }
895 else
896 {
897 Irp->IoStatus.Status = Status;
899 }
900
902
903 return Status;
904}
#define PAGED_CODE()
struct _TEST_CONTEXT TEST_CONTEXT
static CC_FILE_SIZES SmallFileSizes
static BOOLEAN TS
Definition: CcPinRead_drv.c:37
VOID NTAPI ReleaseFromReadAhead(_In_ PVOID Context)
static PDEVICE_OBJECT TestDeviceObject
Definition: CcPinRead_drv.c:32
static PFILE_OBJECT TestFileObject
Definition: CcPinRead_drv.c:31
#define IOCTL_FINISH_TEST
Definition: CcPinRead_drv.c:14
static CC_FILE_SIZES FileSizes
static VOID PerformTest(ULONG TestId, PDEVICE_OBJECT DeviceObject)
struct _TEST_FCB TEST_FCB
static ULONG TestTestId
Definition: CcPinRead_drv.c:30
LARGE_INTEGER WriteOffset
Definition: CcPinRead_drv.c:39
#define ok_bcb(B, L, O)
BOOLEAN NTAPI AcquireForReadAhead(_In_ PVOID Context, _In_ BOOLEAN Wait)
static VOID CleanupTest(ULONG TestId, PDEVICE_OBJECT DeviceObject)
struct _TEST_FCB * PTEST_FCB
VOID TestUnload(_In_ PDRIVER_OBJECT DriverObject)
Definition: CcPinRead_drv.c:98
static BOOLEAN TestWriteCalled
Definition: CcPinRead_drv.c:35
#define IOCTL_START_TEST
Definition: CcPinRead_drv.c:13
struct _TEST_CONTEXT * PTEST_CONTEXT
ULONG WriteLength
Definition: CcPinRead_drv.c:40
static PVOID MapAndLockUserBuffer(_In_ _Out_ PIRP Irp, _In_ ULONG BufferLength)
static CACHE_MANAGER_CALLBACKS Callbacks
static KMT_MESSAGE_HANDLER TestMessageHandler
Definition: CcPinRead_drv.c:34
VOID NTAPI ReleaseFromLazyWrite(_In_ PVOID Context)
NTSTATUS TestEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PCUNICODE_STRING RegistryPath, _Out_ PCWSTR *DeviceName, _Inout_ INT *Flags)
Definition: CcPinRead_drv.c:43
static VOID NTAPI PinInAnotherThread(IN PVOID Context)
BOOLEAN NTAPI AcquireForLazyWrite(_In_ PVOID Context, _In_ BOOLEAN Wait)
static KMT_IRP_HANDLER TestIrpHandler
Definition: CcPinRead_drv.c:33
static VOID NTAPI PinInAnotherThreadExclusive(IN PVOID Context)
unsigned char BOOLEAN
#define ok_eq_pointer(value, expected)
Definition: apitest.h:59
#define ok_eq_ulong(value, expected)
Definition: apitest.h:63
#define ok_eq_longlong(value, expected)
Definition: apitest.h:64
#define ok_bool_false(value, desc)
Definition: apitest.h:79
#define ok_bool_true(value, desc)
Definition: apitest.h:78
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
LONG NTSTATUS
Definition: precomp.h:26
OSVERSIONINFOW VersionInfo
Definition: wkssvc.c:40
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
VOID NTAPI CcSetDirtyPinnedData(IN PVOID BcbVoid, IN OPTIONAL PLARGE_INTEGER Lsn)
Definition: cachesub.c:121
#define CcIsFileCached(FO)
_In_ PFCB Fcb
Definition: cdprocs.h:159
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
#define ULONG_PTR
Definition: config.h:101
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:415
IN PVCB IN VBO IN ULONG OUT PBCB OUT PVOID IN BOOLEAN IN BOOLEAN Zero
Definition: fatprocs.h:419
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
NTSYSAPI NTSTATUS NTAPI ZwQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
@ SystemBasicInformation
Definition: ntddk_ex.h:11
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
VOID NTAPI CcSetFileSizes(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes)
Definition: fssup.c:356
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
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:286
#define IoFreeMdl
Definition: fxmdl.h:89
#define IoAllocateMdl
Definition: fxmdl.h:88
Status
Definition: gdiplustypes.h:25
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
IoMarkIrpPending(Irp)
#define KmtStartSeh()
Definition: kmt_test.h:282
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:288
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL)
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL)
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)
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:931
#define ASSERT(a)
Definition: mode.c:44
@ NormalPagePriority
Definition: imports.h:54
#define KernelMode
Definition: asm.h:34
#define RTL_CONSTANT_LARGE_INTEGER(quad_part)
Definition: rtltypes.h:418
#define _Inout_
Definition: no_sal2.h:162
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
#define VER_SUITE_TERMINAL
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
#define VER_SUITE_SINGLEUSERTS
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
@ NotificationEvent
#define PIN_EXCLUSIVE
#define PIN_IF_BCB
#define MAP_WAIT
#define PIN_WAIT
PFILE_OBJECT NTAPI IoCreateStreamFileObject(IN PFILE_OBJECT FileObject, IN PDEVICE_OBJECT DeviceObject)
Definition: file.c:3187
#define IoCompleteRequest
Definition: irp.c:1240
#define L(x)
Definition: ntvdm.h:50
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
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
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
#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 _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
LARGE_INTEGER FileSize
Definition: cctypes.h:16
LARGE_INTEGER AllocationSize
Definition: cctypes.h:15
SECTION_OBJECT_POINTERS SectionObjectPointers
Definition: ntfs.h:518
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:925
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:246
SECTION_OBJECT_POINTERS SectionObjectPointers
FAST_MUTEX HeaderMutex
FSRTL_ADVANCED_FCB_HEADER Header
#define LL
Definition: tui.h:167
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
#define MAXULONG
Definition: typedefs.h:251
uint32_t * PULONG
Definition: typedefs.h:59
const uint16_t * PCWSTR
Definition: typedefs.h:57
int64_t LONGLONG
Definition: typedefs.h:68
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG _In_ _Out_ WDFMEMORY * Memory
Definition: wdfmemory.h:169
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY _In_opt_ PWDFMEMORY_OFFSET WriteOffset
Definition: wdfusb.h:1921
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define VACB_MAPPING_GRANULARITY
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
FAST_MUTEX
Definition: extypes.h:17
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_PAGING_IO
* PFILE_OBJECT
Definition: iotypes.h:1998
#define IRP_NOCACHE
@ Executive
Definition: ketypes.h:415
@ IoWriteAccess
Definition: ketypes.h:864
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
#define MDL_PAGES_LOCKED
Definition: mmtypes.h:19
#define MDL_IO_PAGE_READ
Definition: mmtypes.h:24
#define MDL_SOURCE_IS_NONPAGED_POOL
Definition: mmtypes.h:20
#define ObDereferenceObject
Definition: obfuncs.h:203