ReactOS 0.4.15-dev-5667-ged97270
CcPinRead_drv.c File Reference
#include <kmt_test.h>
#include <debug.h>
Include dependency graph for CcPinRead_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
 
#define ok_bcb(B, L, O)
 

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 BOOLEAN TestWriteCalled = FALSE
 
static ULONGLONG Memory = 0
 
static BOOLEAN TS = FALSE
 
LARGE_INTEGER WriteOffset
 
ULONG WriteLength
 
static CACHE_MANAGER_CALLBACKS Callbacks
 
static CC_FILE_SIZES FileSizes
 
static CC_FILE_SIZES SmallFileSizes
 

Macro Definition Documentation

◆ IOCTL_FINISH_TEST

#define IOCTL_FINISH_TEST   2

Definition at line 14 of file CcPinRead_drv.c.

◆ IOCTL_START_TEST

#define IOCTL_START_TEST   1

Definition at line 13 of file CcPinRead_drv.c.

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file CcPinRead_drv.c.

◆ ok_bcb

#define ok_bcb (   B,
  L,
  O 
)
Value:
{ \
PPUBLIC_BCB public_bcb = (B); \
ok(public_bcb->NodeTypeCode == 0x2FD, "Not a BCB: %04x\n", public_bcb->NodeTypeCode); \
ok(public_bcb->NodeByteSize == 0, "Invalid size: %d\n", public_bcb->NodeByteSize); \
ok_eq_ulong(public_bcb->MappedLength, (L)); \
ok_eq_longlong(public_bcb->MappedFileOffset.QuadPart, (O)); \
}
#define B(row, col)
static const WCHAR O[]
Definition: oid.c:1251
#define L(x)
Definition: ntvdm.h:50
* PPUBLIC_BCB
Definition: cctypes.h:12

Definition at line 189 of file CcPinRead_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 106 of file CcPinRead_drv.c.

109{
110 return TRUE;
111}
#define TRUE
Definition: types.h:120

◆ AcquireForReadAhead()

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

Definition at line 123 of file CcPinRead_drv.c.

126{
127 return TRUE;
128}

◆ CleanupTest()

static VOID CleanupTest ( ULONG  TestId,
PDEVICE_OBJECT  DeviceObject 
)
static

Definition at line 691 of file CcPinRead_drv.c.

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}
static PDEVICE_OBJECT TestDeviceObject
Definition: CcPinRead_drv.c:32
static PFILE_OBJECT TestFileObject
Definition: CcPinRead_drv.c:31
static ULONG TestTestId
Definition: CcPinRead_drv.c:30
static BOOLEAN TestWriteCalled
Definition: CcPinRead_drv.c:35
#define ok_eq_pointer(value, expected)
#define ok_eq_ulong(value, expected)
#define skip(...)
Definition: atltest.h:64
#define CcIsFileCached(FO)
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#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 ExFreePool(addr)
Definition: env_spec_w32.h:352
IN PVCB IN VBO IN ULONG OUT PBCB OUT PVOID IN BOOLEAN IN BOOLEAN Zero
Definition: fatprocs.h:418
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:286
#define ok_bool_false(value, desc)
Definition: kmt_test.h:259
#define ok_bool_true(value, desc)
Definition: kmt_test.h:258
#define KernelMode
Definition: asm.h:34
#define RTL_CONSTANT_LARGE_INTEGER(quad_part)
Definition: rtltypes.h:418
@ NotificationEvent
#define LL
Definition: tui.h:150
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
@ Executive
Definition: ketypes.h:403
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by TestMessageHandler().

◆ MapAndLockUserBuffer()

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

Definition at line 159 of file CcPinRead_drv.c.

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}
_In_ PIRP Irp
Definition: csq.h:116
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define IoFreeMdl
Definition: fxmdl.h:89
#define IoAllocateMdl
Definition: fxmdl.h:88
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:931
@ NormalPagePriority
Definition: imports.h:56
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:162
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
@ IoWriteAccess
Definition: ketypes.h:852
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)

Referenced by TestIrpHandler().

◆ PerformTest()

static VOID PerformTest ( ULONG  TestId,
PDEVICE_OBJECT  DeviceObject 
)
static

Definition at line 400 of file CcPinRead_drv.c.

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}
static CC_FILE_SIZES SmallFileSizes
static BOOLEAN TS
Definition: CcPinRead_drv.c:37
static CC_FILE_SIZES FileSizes
#define ok_bcb(B, L, O)
ULONG WriteLength
Definition: CcPinRead_drv.c:40
static CACHE_MANAGER_CALLBACKS Callbacks
static VOID NTAPI PinInAnotherThread(IN PVOID Context)
static VOID NTAPI PinInAnotherThreadExclusive(IN PVOID Context)
unsigned char BOOLEAN
#define ok(value,...)
Definition: atltest.h:57
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
_In_ PFCB Fcb
Definition: cdprocs.h:159
Definition: bufpool.h:45
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define NonPagedPool
Definition: env_spec_w32.h:307
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:414
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
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
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
#define KmtStartSeh()
Definition: kmt_test.h:279
#define ok_eq_longlong(value, expected)
Definition: kmt_test.h:244
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:285
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL)
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL)
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define PIN_EXCLUSIVE
#define PIN_IF_BCB
#define PIN_WAIT
PFILE_OBJECT NTAPI IoCreateStreamFileObject(IN PFILE_OBJECT FileObject, IN PDEVICE_OBJECT DeviceObject)
Definition: file.c:3187
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
#define STATUS_SUCCESS
Definition: shellext.h:65
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
#define MAXULONG
Definition: typedefs.h:251
uint32_t * PULONG
Definition: typedefs.h:59
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
_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
#define VACB_MAPPING_GRANULARITY
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274

Referenced by TestMessageHandler().

◆ PinInAnotherThread()

static VOID NTAPI PinInAnotherThread ( IN PVOID  Context)
static

Definition at line 201 of file CcPinRead_drv.c.

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}
#define MAP_WAIT
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
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by PerformTest().

◆ PinInAnotherThreadExclusive()

static VOID NTAPI PinInAnotherThreadExclusive ( IN PVOID  Context)
static

Definition at line 319 of file CcPinRead_drv.c.

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}

Referenced by PerformTest().

◆ ReleaseFromLazyWrite()

VOID NTAPI ReleaseFromLazyWrite ( _In_ PVOID  Context)

Definition at line 115 of file CcPinRead_drv.c.

117{
118 return;
119}

◆ ReleaseFromReadAhead()

VOID NTAPI ReleaseFromReadAhead ( _In_ PVOID  Context)

Definition at line 132 of file CcPinRead_drv.c.

134{
135 return;
136}

◆ TestEntry()

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

Definition at line 43 of file CcPinRead_drv.c.

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}
#define PAGED_CODE()
static KMT_MESSAGE_HANDLER TestMessageHandler
Definition: CcPinRead_drv.c:34
static KMT_IRP_HANDLER TestIrpHandler
Definition: CcPinRead_drv.c:33
#define trace
Definition: atltest.h:70
LONG NTSTATUS
Definition: precomp.h:26
OSVERSIONINFOW VersionInfo
Definition: wkssvc.c:40
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
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
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 VER_SUITE_TERMINAL
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define VER_SUITE_SINGLEUSERTS
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:246
_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

◆ TestIrpHandler()

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

Definition at line 773 of file CcPinRead_drv.c.

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}
static PVOID MapAndLockUserBuffer(_In_ _Out_ PIRP Irp, _In_ ULONG BufferLength)
#define ULONG_PTR
Definition: config.h:101
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
IoMarkIrpPending(Irp)
#define ASSERT(a)
Definition: mode.c:44
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define DPRINT
Definition: sndvol32.h:71
int64_t LONGLONG
Definition: typedefs.h:68
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_PAGING_IO
#define IRP_NOCACHE
#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

◆ 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 738 of file CcPinRead_drv.c.

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}
#define IOCTL_FINISH_TEST
Definition: CcPinRead_drv.c:14
static VOID PerformTest(ULONG TestId, PDEVICE_OBJECT DeviceObject)
static VOID CleanupTest(ULONG TestId, PDEVICE_OBJECT DeviceObject)
#define IOCTL_START_TEST
Definition: CcPinRead_drv.c:13
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55

◆ TestUnload()

VOID TestUnload ( _In_ PDRIVER_OBJECT  DriverObject)

Definition at line 98 of file CcPinRead_drv.c.

100{
101 PAGED_CODE();
102}

Variable Documentation

◆ Callbacks

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

Definition at line 138 of file CcPinRead_drv.c.

Referenced by PerformTest().

◆ FileSizes

CC_FILE_SIZES FileSizes
static
Initial value:

Definition at line 145 of file CcPinRead_drv.c.

Referenced by PerformTest().

◆ Memory

ULONGLONG Memory = 0
static

Definition at line 36 of file CcPinRead_drv.c.

◆ SmallFileSizes

CC_FILE_SIZES SmallFileSizes
static
Initial value:

Definition at line 151 of file CcPinRead_drv.c.

Referenced by PerformTest().

◆ TestDeviceObject

PDEVICE_OBJECT TestDeviceObject
static

Definition at line 32 of file CcPinRead_drv.c.

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

◆ TestFileObject

PFILE_OBJECT TestFileObject
static

◆ TestIrpHandler

KMT_IRP_HANDLER TestIrpHandler
static

Definition at line 33 of file CcPinRead_drv.c.

Referenced by TestEntry().

◆ TestMessageHandler

KMT_MESSAGE_HANDLER TestMessageHandler
static

Definition at line 34 of file CcPinRead_drv.c.

Referenced by TestEntry().

◆ TestTestId

ULONG TestTestId = -1
static

◆ TestWriteCalled

BOOLEAN TestWriteCalled = FALSE
static

Definition at line 35 of file CcPinRead_drv.c.

Referenced by CleanupTest(), and TestIrpHandler().

◆ TS

BOOLEAN TS = FALSE
static

Definition at line 37 of file CcPinRead_drv.c.

Referenced by PerformTest(), and TestEntry().

◆ WriteLength

◆ WriteOffset

Definition at line 39 of file CcPinRead_drv.c.