ReactOS  0.4.15-dev-2106-g6de3300
CcCopyWrite_drv.c File Reference
#include <kmt_test.h>
#include <debug.h>
Include dependency graph for CcCopyWrite_drv.c:

Go to the source code of this file.

Classes

struct  _TEST_FCB
 

Macros

#define NDEBUG
 
#define ok_read_called(_Offset, _Length)
 
#define ok_read_not_called()   ok(!ReadCalled, "CcCopyWrite shouldn't have triggered a read.\n")
 

Typedefs

typedef struct _TEST_FCB TEST_FCB
 
typedef struct _TEST_FCBPTEST_FCB
 

Functions

static BOOLEAN NTAPI FastIoRead (_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ ULONG Length, _In_ BOOLEAN Wait, _In_ ULONG LockKey, _Out_ PVOID Buffer, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
 
static BOOLEAN NTAPI FastIoWrite (_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ ULONG Length, _In_ BOOLEAN Wait, _In_ ULONG LockKey, _Out_ PVOID Buffer, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
 
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 reset_read (void)
 
static VOID Test_CcCopyWrite (PFILE_OBJECT FileObject)
 
static NTSTATUS TestIrpHandler (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PIO_STACK_LOCATION IoStack)
 

Variables

static PFILE_OBJECT TestFileObject
 
static PDEVICE_OBJECT TestDeviceObject
 
static KMT_IRP_HANDLER TestIrpHandler
 
static FAST_IO_DISPATCH TestFastIoDispatch
 
static BOOLEAN InBehaviourTest
 
BOOLEAN ReadCalled
 
LARGE_INTEGER ReadOffset
 
ULONG ReadLength
 
static CACHE_MANAGER_CALLBACKS Callbacks
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file CcCopyWrite_drv.c.

◆ ok_read_called

#define ok_read_called (   _Offset,
  _Length 
)
Value:
do { \
ok(ReadCalled, "CcCopyWrite should have triggerred a read.\n"); \
ok_eq_longlong(ReadOffset.QuadPart, _Offset); \
ok_eq_ulong(ReadLength, _Length); \
}while(0)
_Check_return_ _Ret_maybenull_ _In_ size_t _In_ size_t _Offset
Definition: malloc.h:143
ULONG ReadLength
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY _In_opt_ PWDFMEMORY_OFFSET ReadOffset
Definition: wdfusb.h:1996
BOOLEAN ReadCalled

Definition at line 186 of file CcCopyWrite_drv.c.

◆ ok_read_not_called

#define ok_read_not_called ( )    ok(!ReadCalled, "CcCopyWrite shouldn't have triggered a read.\n")

Definition at line 192 of file CcCopyWrite_drv.c.

Typedef Documentation

◆ PTEST_FCB

◆ TEST_FCB

Function Documentation

◆ AcquireForLazyWrite()

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

Definition at line 106 of file CcCopyWrite_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 CcCopyWrite_drv.c.

126 {
127  return TRUE;
128 }
#define TRUE
Definition: types.h:120

◆ FastIoRead()

static BOOLEAN NTAPI FastIoRead ( _In_ PFILE_OBJECT  FileObject,
_In_ PLARGE_INTEGER  FileOffset,
_In_ ULONG  Length,
_In_ BOOLEAN  Wait,
_In_ ULONG  LockKey,
_Out_ PVOID  Buffer,
_Out_ PIO_STATUS_BLOCK  IoStatus,
_In_ PDEVICE_OBJECT  DeviceObject 
)
static

Definition at line 34 of file CcCopyWrite_drv.c.

43 {
45  return FALSE;
46 }
return STATUS_NOT_SUPPORTED
#define FALSE
Definition: types.h:117
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:155

Referenced by TestEntry().

◆ FastIoWrite()

static BOOLEAN NTAPI FastIoWrite ( _In_ PFILE_OBJECT  FileObject,
_In_ PLARGE_INTEGER  FileOffset,
_In_ ULONG  Length,
_In_ BOOLEAN  Wait,
_In_ ULONG  LockKey,
_Out_ PVOID  Buffer,
_Out_ PIO_STATUS_BLOCK  IoStatus,
_In_ PDEVICE_OBJECT  DeviceObject 
)
static

Definition at line 51 of file CcCopyWrite_drv.c.

60 {
62  return FALSE;
63 }
return STATUS_NOT_SUPPORTED
#define FALSE
Definition: types.h:117
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:155

Referenced by TestEntry().

◆ MapAndLockUserBuffer()

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

Definition at line 147 of file CcCopyWrite_drv.c.

150 {
151  PMDL Mdl;
152 
153  if (Irp->MdlAddress == NULL)
154  {
155  Mdl = IoAllocateMdl(Irp->UserBuffer, BufferLength, FALSE, FALSE, Irp);
156  if (Mdl == NULL)
157  {
158  return NULL;
159  }
160 
161  _SEH2_TRY
162  {
163  MmProbeAndLockPages(Mdl, Irp->RequestorMode, IoWriteAccess);
164  }
166  {
167  IoFreeMdl(Mdl);
168  Irp->MdlAddress = NULL;
169  _SEH2_YIELD(return NULL);
170  }
171  _SEH2_END;
172  }
173 
175 }
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3767
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
_SEH2_TRY
Definition: create.c:4226
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#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:4400
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
#define NULL
Definition: types.h:112
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6

Referenced by TestIrpHandler().

◆ ReleaseFromLazyWrite()

VOID NTAPI ReleaseFromLazyWrite ( _In_ PVOID  Context)

Definition at line 115 of file CcCopyWrite_drv.c.

117 {
118  return;
119 }

◆ ReleaseFromReadAhead()

VOID NTAPI ReleaseFromReadAhead ( _In_ PVOID  Context)

Definition at line 132 of file CcCopyWrite_drv.c.

134 {
135  return;
136 }

◆ reset_read()

static void reset_read ( void  )
static

Definition at line 179 of file CcCopyWrite_drv.c.

180 {
181  ReadCalled = FALSE;
182  ReadOffset.QuadPart = MAXLONGLONG;
184 }
ULONG ReadLength
#define MAXLONGLONG
#define FALSE
Definition: types.h:117
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY _In_opt_ PWDFMEMORY_OFFSET ReadOffset
Definition: wdfusb.h:1996
#define MAXULONG
Definition: typedefs.h:251
BOOLEAN ReadCalled

Referenced by Test_CcCopyWrite().

◆ Test_CcCopyWrite()

static VOID Test_CcCopyWrite ( PFILE_OBJECT  FileObject)
static

Definition at line 196 of file CcCopyWrite_drv.c.

197 {
198 
199  BOOLEAN Ret;
201  CHAR Buffer[10];
202 
203  memset(Buffer, 0xAC, 10);
204 
205  /* Test bogus file object & file offset */
206  Ret = 'x';
207  KmtStartSeh()
208  Ret = CcCopyWrite(FileObject, NULL, 0, FALSE, NULL);
210  ok_eq_char(Ret, 'x');
211 
212  Ret = 'x';
213  Offset.QuadPart = 0;
214  KmtStartSeh()
215  Ret = CcCopyWrite(NULL, &Offset, 10, FALSE, Buffer);
217  ok_eq_char(Ret, 'x');
218 
219  /* What happens on invalid buffer */
220  Ret = 'x';
221  Offset.QuadPart = 0;
222  reset_read();
223  KmtStartSeh()
224  Ret = CcCopyWrite(FileObject, &Offset, 0, TRUE, NULL);
226  ok_bool_true(Ret, "CcCopyWrite(0, NULL) should succeed\n");
227  /* When there is nothing to write, there is no reason to read */
229 
230  Ret = 'x';
231  Offset.QuadPart = 0;
232  reset_read();
233  KmtStartSeh()
234  Ret = CcCopyWrite(FileObject, &Offset, 10, TRUE, NULL);
236  ok_eq_char(Ret, 'x');
237  /* This raises an exception, but it actually triggered a read */
239 
240  /* So this one succeeds, as the page is now resident */
241  Ret = 'x';
242  Offset.QuadPart = 0;
243  reset_read();
244  KmtStartSeh()
245  Ret = CcCopyWrite(FileObject, &Offset, 10, FALSE, Buffer);
247  ok_bool_true(Ret, "CcCopyWrite should succeed\n");
248  /* But there was no read triggered, as the page is already resident. */
250 
251  /* But this one doesn't */
252  Ret = 'x';
254  reset_read();
255  KmtStartSeh()
256  Ret = CcCopyWrite(FileObject, &Offset, 10, FALSE, Buffer);
258  ok_bool_false(Ret, "CcCopyWrite should fail\n");
259  /* But it triggered a read anyway. */
261 
262  /* Of course, waiting for it succeeds and triggers the read */
263  Ret = 'x';
264  Offset.QuadPart = PAGE_SIZE * 2;
265  reset_read();
266  KmtStartSeh()
267  Ret = CcCopyWrite(FileObject, &Offset, 10, TRUE, Buffer);
269  ok_bool_true(Ret, "CcCopyWrite should succeed\n");
271 }
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:283
GLdouble n
Definition: glext.h:7729
#define ok_eq_char(value, expected)
Definition: kmt_test.h:244
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define ok_bool_false(value, desc)
Definition: kmt_test.h:257
#define ok_bool_true(value, desc)
Definition: kmt_test.h:256
#define FALSE
Definition: types.h:117
#define STATUS_INVALID_USER_BUFFER
Definition: udferr_usr.h:166
unsigned char BOOLEAN
Definition: bufpool.h:45
return succeed
Definition: scsi.h:3736
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define KmtStartSeh()
Definition: kmt_test.h:277
BOOLEAN NTAPI CcCopyWrite(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, IN PVOID Buffer)
Definition: copysup.c:129
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define NULL
Definition: types.h:112
#define ok_read_not_called()
#define ok_read_called(_Offset, _Length)
ret QuadPart
Definition: rtlfuncs.h:3091
#define STATUS_SUCCESS
Definition: shellext.h:65
static void reset_read(void)
#define memset(x, y, z)
Definition: compat.h:39

Referenced by TestIrpHandler().

◆ TestEntry()

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

Definition at line 66 of file CcCopyWrite_drv.c.

71 {
73 
74  PAGED_CODE();
75 
77 
78  *DeviceName = L"CcCopyWrite";
79  *Flags = TESTENTRY_NO_EXCLUSIVE_DEVICE |
80  TESTENTRY_BUFFERED_IO_DEVICE |
81  TESTENTRY_NO_READONLY_DEVICE;
82 
88 
91  DriverObject->FastIoDispatch = &TestFastIoDispatch;
92 
93 
94  return Status;
95 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_FLUSH_BUFFERS
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
NTSTATUS KmtRegisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
static FAST_IO_DISPATCH TestFastIoDispatch
static const WCHAR L[]
Definition: oid.c:1250
PFAST_IO_READ FastIoRead
Definition: iotypes.h:1732
PFAST_IO_WRITE FastIoWrite
Definition: iotypes.h:1733
static KMT_IRP_HANDLER TestIrpHandler
#define NULL
Definition: types.h:112
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_CLEANUP
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define STATUS_SUCCESS
Definition: shellext.h:65
static BOOLEAN NTAPI FastIoWrite(_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ ULONG Length, _In_ BOOLEAN Wait, _In_ ULONG LockKey, _Out_ PVOID Buffer, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
static BOOLEAN NTAPI FastIoRead(_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ ULONG Length, _In_ BOOLEAN Wait, _In_ ULONG LockKey, _Out_ PVOID Buffer, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
#define PAGED_CODE()

◆ TestIrpHandler()

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

Definition at line 275 of file CcCopyWrite_drv.c.

279 {
282  PTEST_FCB Fcb;
283  CACHE_UNINITIALIZE_EVENT CacheUninitEvent;
284 
285  PAGED_CODE();
286 
287  DPRINT("IRP %x/%x\n", IoStack->MajorFunction, IoStack->MinorFunction);
288  ASSERT(IoStack->MajorFunction == IRP_MJ_CLEANUP ||
289  IoStack->MajorFunction == IRP_MJ_CREATE ||
290  IoStack->MajorFunction == IRP_MJ_READ ||
291  IoStack->MajorFunction == IRP_MJ_WRITE ||
292  IoStack->MajorFunction == IRP_MJ_FLUSH_BUFFERS);
293 
295  Irp->IoStatus.Information = 0;
296 
297  if (IoStack->MajorFunction == IRP_MJ_CREATE)
298  {
299  ok_irql(PASSIVE_LEVEL);
300 
301  if (IoStack->FileObject->FileName.Length >= 2 * sizeof(WCHAR))
302  {
304  TestFileObject = IoStack->FileObject;
305  }
306  Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(*Fcb), 'FwrI');
307  RtlZeroMemory(Fcb, sizeof(*Fcb));
308  ExInitializeFastMutex(&Fcb->HeaderMutex);
309  FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex);
310  if (IoStack->FileObject->FileName.Length >= 2 * sizeof(WCHAR) &&
311  IoStack->FileObject->FileName.Buffer[1] == 'B')
312  {
313  Fcb->Header.AllocationSize.QuadPart = 1000000;
314  Fcb->Header.FileSize.QuadPart = 1000000;
315  Fcb->Header.ValidDataLength.QuadPart = 1000000;
316  }
317  else if (IoStack->FileObject->FileName.Length >= 2 * sizeof(WCHAR) &&
318  IoStack->FileObject->FileName.Buffer[1] == 'S')
319  {
320  Fcb->Header.AllocationSize.QuadPart = 512;
321  Fcb->Header.FileSize.QuadPart = 512;
322  Fcb->Header.ValidDataLength.QuadPart = 512;
323  }
324  else if (IoStack->FileObject->FileName.Length >= 2 * sizeof(WCHAR) &&
325  IoStack->FileObject->FileName.Buffer[1] == 'V')
326  {
327  Fcb->Header.AllocationSize.QuadPart = 62;
328  Fcb->Header.FileSize.QuadPart = 62;
329  Fcb->Header.ValidDataLength.QuadPart = 62;
330  }
331  else
332  {
333  Fcb->Header.AllocationSize.QuadPart = 1004;
334  Fcb->Header.FileSize.QuadPart = 1004;
335  Fcb->Header.ValidDataLength.QuadPart = 1004;
336  }
337  Fcb->Header.IsFastIoPossible = FastIoIsNotPossible;
338  IoStack->FileObject->FsContext = Fcb;
339  IoStack->FileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
340 
341  CcInitializeCacheMap(IoStack->FileObject,
342  (PCC_FILE_SIZES)&Fcb->Header.AllocationSize,
343  FALSE, &Callbacks, NULL);
344 
345  Irp->IoStatus.Information = FILE_OPENED;
347  }
348  else if (IoStack->MajorFunction == IRP_MJ_READ)
349  {
350  PMDL Mdl;
351  ULONG Length;
352  PVOID Buffer;
354 
355  Offset = IoStack->Parameters.Read.ByteOffset;
356  Length = IoStack->Parameters.Read.Length;
357  Fcb = IoStack->FileObject->FsContext;
358 
360  ok_eq_pointer(IoStack->FileObject, TestFileObject);
361 
362  ok(BooleanFlagOn(Irp->Flags, IRP_NOCACHE), "IRP not coming from Cc!\n");
363  ok_irql(APC_LEVEL);
364  ok((Offset.QuadPart == 0 || Offset.QuadPart == 4096 || Offset.QuadPart == 8192), "Unexpected offset: %I64i\n", Offset.QuadPart);
365  ok(Length % PAGE_SIZE == 0, "Length is not aligned: %I64i\n", Length);
366 
367  ReadCalled = TRUE;
368  ReadOffset = Offset;
369  ReadLength = Length;
370 
371  ok(Irp->AssociatedIrp.SystemBuffer == NULL, "A SystemBuffer was allocated!\n");
373  ok(Buffer != NULL, "Null pointer!\n");
374  RtlFillMemory(Buffer, Length, 0xBA);
375 
377 
378  Mdl = Irp->MdlAddress;
379  ok(Mdl != NULL, "Null pointer for MDL!\n");
380  ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) != 0, "MDL not locked\n");
381  ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) == 0, "MDL from non paged\n");
382  ok((Mdl->MdlFlags & MDL_IO_PAGE_READ) != 0, "Non paging IO\n");
383  ok((Irp->Flags & IRP_PAGING_IO) != 0, "Non paging IO\n");
384 
385  Irp->IoStatus.Information = Length;
386  IoStack->FileObject->CurrentByteOffset.QuadPart = Offset.QuadPart + Length;
387  }
388  else if (IoStack->MajorFunction == IRP_MJ_WRITE)
389  {
390  PMDL Mdl;
391  ULONG Length;
392  PVOID Buffer;
394  static const UNICODE_STRING BehaviourTestFileName = RTL_CONSTANT_STRING(L"\\BehaviourTestFile");
395 
396  Offset = IoStack->Parameters.Read.ByteOffset;
397  Length = IoStack->Parameters.Read.Length;
398  Fcb = IoStack->FileObject->FsContext;
399 
400  ok_bool_false(InBehaviourTest, "Shouldn't trigger write from CcCopyWrite\n");
401  /* Check special file name */
402  InBehaviourTest = RtlCompareUnicodeString(&IoStack->FileObject->FileName, &BehaviourTestFileName, TRUE) == 0;
403 
404  if (!FlagOn(Irp->Flags, IRP_NOCACHE))
405  {
406  BOOLEAN Ret;
407 
408  ok_irql(PASSIVE_LEVEL);
409 
410  if (InBehaviourTest)
411  {
412  Test_CcCopyWrite(IoStack->FileObject);
413  Status = Irp->IoStatus.Status = STATUS_SUCCESS;
414  }
415  else
416  {
417  Buffer = Irp->AssociatedIrp.SystemBuffer;
418  ok(Buffer != NULL, "Null pointer!\n");
419 
420  Fcb->WriteLength = Length;
421 
422  _SEH2_TRY
423  {
424  Ret = CcCopyWrite(IoStack->FileObject, &Offset, Length, TRUE, Buffer);
425  ok_bool_true(Ret, "CcCopyWrite");
426  }
428  {
429  Irp->IoStatus.Status = _SEH2_GetExceptionCode();
430  }
431  _SEH2_END;
432 
433  Status = Irp->IoStatus.Status;
434  }
435  }
436  else
437  {
438  ok_irql(PASSIVE_LEVEL);
439 
440  if (InBehaviourTest)
441  {
442  /* We wrote only to the 1st and 3rd page */
443  ok((Offset.QuadPart == 0) || (Offset.QuadPart == PAGE_SIZE * 2), "Expected a non-cached write on 1st or 3rd page\n");
444  /* We wrote that much with CcCopyWrite */
446  }
447  else
448  {
449  ok((Offset.QuadPart == 0 || Offset.QuadPart == 4096), "Unexpected offset: %I64i\n", Offset.QuadPart);
450  ok_eq_ulong(Length, ROUND_TO_PAGES(Fcb->WriteLength));
451  }
452 
453  ok(Irp->AssociatedIrp.SystemBuffer == NULL, "A SystemBuffer was allocated!\n");
455  ok(Buffer != NULL, "Null pointer!\n");
456 
458 
459  Mdl = Irp->MdlAddress;
460  ok(Mdl != NULL, "Null pointer for MDL!\n");
461  ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) != 0, "MDL not locked\n");
462  ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) == 0, "MDL from non paged\n");
463  ok((Mdl->MdlFlags & MDL_IO_PAGE_READ) == 0, "MDL for read paging IO\n");
464  ok((Irp->Flags & IRP_PAGING_IO) != 0, "Non paging IO\n");
465  }
466 
468  }
469  else if (IoStack->MajorFunction == IRP_MJ_FLUSH_BUFFERS)
470  {
472 
473  Fcb = IoStack->FileObject->FsContext;
475 
477  }
478  else if (IoStack->MajorFunction == IRP_MJ_CLEANUP)
479  {
480  ok_irql(PASSIVE_LEVEL);
481  KeInitializeEvent(&CacheUninitEvent.Event, NotificationEvent, FALSE);
482  CcUninitializeCacheMap(IoStack->FileObject, &Zero, &CacheUninitEvent);
483  KeWaitForSingleObject(&CacheUninitEvent.Event, Executive, KernelMode, FALSE, NULL);
484  Fcb = IoStack->FileObject->FsContext;
485  ExFreePoolWithTag(Fcb, 'FwrI');
486  IoStack->FileObject->FsContext = NULL;
488  }
489 
490  if (Status == STATUS_PENDING)
491  {
495  }
496  else
497  {
498  Irp->IoStatus.Status = Status;
500  }
501 
502  return Status;
503 }
#define MDL_IO_PAGE_READ
Definition: mmtypes.h:24
#define ok_eq_ulong(value, expected)
return STATUS_NOT_SUPPORTED
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define LL
Definition: tui.h:84
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define IRP_MJ_FLUSH_BUFFERS
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
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:925
PFILE_OBJECT FileObject
Definition: ntfs.h:516
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define TRUE
Definition: types.h:120
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
#define ok_eq_pointer(value, expected)
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_OPENED
Definition: nt_native.h:769
#define IRP_NOCACHE
static PDEVICE_OBJECT TestDeviceObject
ULONG ReadLength
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
_SEH2_TRY
Definition: create.c:4226
#define ok_bool_false(value, desc)
Definition: kmt_test.h:257
#define ok_bool_true(value, desc)
Definition: kmt_test.h:256
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
static BOOLEAN InBehaviourTest
#define RTL_CONSTANT_LARGE_INTEGER(quad_part)
Definition: rtltypes.h:416
static PVOID MapAndLockUserBuffer(_In_ _Out_ PIRP Irp, _In_ ULONG BufferLength)
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY _In_opt_ PWDFMEMORY_OFFSET ReadOffset
Definition: wdfusb.h:1996
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
#define MDL_SOURCE_IS_NONPAGED_POOL
Definition: mmtypes.h:20
#define IoCompleteRequest
Definition: irp.c:1240
Definition: bufpool.h:45
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MDL_PAGES_LOCKED
Definition: mmtypes.h:19
#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
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
#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
static VOID Test_CcCopyWrite(PFILE_OBJECT FileObject)
BOOLEAN NTAPI CcCopyWrite(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, IN PVOID Buffer)
Definition: copysup.c:129
BOOLEAN ReadCalled
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_SEH2_END
Definition: create.c:4400
static CACHE_MANAGER_CALLBACKS Callbacks
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ROUND_TO_PAGES(Size)
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:286
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#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 IRP_MJ_CLEANUP
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:155
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#define DPRINT
Definition: sndvol32.h:71
_In_ PFCB Fcb
Definition: cdprocs.h:159
IoMarkIrpPending(Irp)
#define APC_LEVEL
Definition: env_spec_w32.h:695
SECTION_OBJECT_POINTERS SectionObjectPointers
Definition: ntfs.h:514
#define PAGED_CODE()
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
static PFILE_OBJECT TestFileObject

◆ TestUnload()

VOID TestUnload ( _In_ PDRIVER_OBJECT  DriverObject)

Definition at line 98 of file CcCopyWrite_drv.c.

100 {
101  PAGED_CODE();
102 }
#define PAGED_CODE()

Variable Documentation

◆ Callbacks

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

Definition at line 138 of file CcCopyWrite_drv.c.

Referenced by TestIrpHandler().

◆ InBehaviourTest

BOOLEAN InBehaviourTest
static

Definition at line 25 of file CcCopyWrite_drv.c.

Referenced by TestIrpHandler().

◆ ReadCalled

BOOLEAN ReadCalled

Definition at line 27 of file CcCopyWrite_drv.c.

Referenced by reset_read(), and TestIrpHandler().

◆ ReadLength

ULONG ReadLength

Definition at line 29 of file CcCopyWrite_drv.c.

Referenced by reset_read(), and TestIrpHandler().

◆ ReadOffset

Definition at line 28 of file CcCopyWrite_drv.c.

◆ TestDeviceObject

PDEVICE_OBJECT TestDeviceObject
static

Definition at line 22 of file CcCopyWrite_drv.c.

Referenced by TestIrpHandler().

◆ TestFastIoDispatch

FAST_IO_DISPATCH TestFastIoDispatch
static

Definition at line 24 of file CcCopyWrite_drv.c.

Referenced by TestEntry().

◆ TestFileObject

PFILE_OBJECT TestFileObject
static

Definition at line 21 of file CcCopyWrite_drv.c.

Referenced by TestIrpHandler().

◆ TestIrpHandler

KMT_IRP_HANDLER TestIrpHandler
static

Definition at line 23 of file CcCopyWrite_drv.c.

Referenced by TestEntry().