[MSPORTS] When the LPT port number gets changed, update the PortName and FriendlyName...
[reactos.git] / modules / rostests / kmtests / ntos_cc / CcPinRead_drv.c
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 {
18 FSRTL_ADVANCED_FCB_HEADER Header;
19 SECTION_OBJECT_POINTERS SectionObjectPointers;
20 FAST_MUTEX HeaderMutex;
21 } TEST_FCB, *PTEST_FCB;
22
23 typedef struct _TEST_CONTEXT
24 {
25 PVOID Bcb;
26 PVOID Buffer;
27 ULONG Length;
28 } TEST_CONTEXT, *PTEST_CONTEXT;
29
30 static ULONG TestTestId = -1;
31 static PFILE_OBJECT TestFileObject;
32 static PDEVICE_OBJECT TestDeviceObject;
33 static KMT_IRP_HANDLER TestIrpHandler;
34 static KMT_MESSAGE_HANDLER TestMessageHandler;
35
36 NTSTATUS
37 TestEntry(
38 _In_ PDRIVER_OBJECT DriverObject,
39 _In_ PCUNICODE_STRING RegistryPath,
40 _Out_ PCWSTR *DeviceName,
41 _Inout_ INT *Flags)
42 {
43 NTSTATUS Status = STATUS_SUCCESS;
44
45 PAGED_CODE();
46
47 UNREFERENCED_PARAMETER(RegistryPath);
48
49 *DeviceName = L"CcPinRead";
50 *Flags = TESTENTRY_NO_EXCLUSIVE_DEVICE |
51 TESTENTRY_BUFFERED_IO_DEVICE |
52 TESTENTRY_NO_READONLY_DEVICE;
53
54 KmtRegisterIrpHandler(IRP_MJ_READ, NULL, TestIrpHandler);
55 KmtRegisterMessageHandler(0, NULL, TestMessageHandler);
56
57
58 return Status;
59 }
60
61 VOID
62 TestUnload(
63 _In_ PDRIVER_OBJECT DriverObject)
64 {
65 PAGED_CODE();
66 }
67
68 BOOLEAN
69 NTAPI
70 AcquireForLazyWrite(
71 _In_ PVOID Context,
72 _In_ BOOLEAN Wait)
73 {
74 return TRUE;
75 }
76
77 VOID
78 NTAPI
79 ReleaseFromLazyWrite(
80 _In_ PVOID Context)
81 {
82 return;
83 }
84
85 BOOLEAN
86 NTAPI
87 AcquireForReadAhead(
88 _In_ PVOID Context,
89 _In_ BOOLEAN Wait)
90 {
91 return TRUE;
92 }
93
94 VOID
95 NTAPI
96 ReleaseFromReadAhead(
97 _In_ PVOID Context)
98 {
99 return;
100 }
101
102 static CACHE_MANAGER_CALLBACKS Callbacks = {
103 AcquireForLazyWrite,
104 ReleaseFromLazyWrite,
105 AcquireForReadAhead,
106 ReleaseFromReadAhead,
107 };
108
109 static CC_FILE_SIZES FileSizes = {
110 RTL_CONSTANT_LARGE_INTEGER((LONGLONG)0x4000), // .AllocationSize
111 RTL_CONSTANT_LARGE_INTEGER((LONGLONG)0x4000), // .FileSize
112 RTL_CONSTANT_LARGE_INTEGER((LONGLONG)0x4000) // .ValidDataLength
113 };
114
115 static
116 PVOID
117 MapAndLockUserBuffer(
118 _In_ _Out_ PIRP Irp,
119 _In_ ULONG BufferLength)
120 {
121 PMDL Mdl;
122
123 if (Irp->MdlAddress == NULL)
124 {
125 Mdl = IoAllocateMdl(Irp->UserBuffer, BufferLength, FALSE, FALSE, Irp);
126 if (Mdl == NULL)
127 {
128 return NULL;
129 }
130
131 _SEH2_TRY
132 {
133 MmProbeAndLockPages(Mdl, Irp->RequestorMode, IoWriteAccess);
134 }
135 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
136 {
137 IoFreeMdl(Mdl);
138 Irp->MdlAddress = NULL;
139 _SEH2_YIELD(return NULL);
140 }
141 _SEH2_END;
142 }
143
144 return MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
145 }
146
147 static
148 VOID
149 NTAPI
150 PinInAnotherThread(IN PVOID Context)
151 {
152 BOOLEAN Ret;
153 PULONG Buffer;
154 PVOID Bcb;
155 LARGE_INTEGER Offset;
156 PTEST_CONTEXT TestContext;
157
158 ok(TestFileObject != NULL, "Called in invalid context!\n");
159 ok_eq_ulong(TestTestId, 3);
160
161 TestContext = Context;
162 ok(TestContext != NULL, "Called in invalid context!\n");
163 ok(TestContext->Bcb != NULL, "Called in invalid context!\n");
164 ok(TestContext->Buffer != NULL, "Called in invalid context!\n");
165 ok(TestContext->Length != 0, "Called in invalid context!\n");
166
167 Ret = FALSE;
168 Offset.QuadPart = 0x1000;
169 KmtStartSeh();
170 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_WAIT, &Bcb, (PVOID *)&Buffer);
171 KmtEndSeh(STATUS_SUCCESS);
172
173 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
174 {
175 ok_eq_pointer(Bcb, TestContext->Bcb);
176 ok_eq_pointer(Buffer, TestContext->Buffer);
177
178 CcUnpinData(Bcb);
179 }
180
181 KmtStartSeh();
182 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_WAIT | PIN_IF_BCB, &Bcb, (PVOID *)&Buffer);
183 KmtEndSeh(STATUS_SUCCESS);
184
185 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
186 {
187 ok_eq_pointer(Bcb, TestContext->Bcb);
188 ok_eq_pointer(Buffer, TestContext->Buffer);
189
190 CcUnpinData(Bcb);
191 }
192
193 KmtStartSeh();
194 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_EXCLUSIVE, &Bcb, (PVOID *)&Buffer);
195 KmtEndSeh(STATUS_SUCCESS);
196
197 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
198 {
199 ok_eq_pointer(Bcb, TestContext->Bcb);
200 ok_eq_pointer(Buffer, TestContext->Buffer);
201
202 CcUnpinData(Bcb);
203 }
204
205 KmtStartSeh();
206 Ret = CcMapData(TestFileObject, &Offset, TestContext->Length, MAP_WAIT, &Bcb, (PVOID *)&Buffer);
207 KmtEndSeh(STATUS_SUCCESS);
208
209 if (!skip(Ret == TRUE, "CcMapData failed\n"))
210 {
211 ok(Bcb != TestContext->Bcb, "Returned same BCB!\n");
212 ok_eq_pointer(Buffer, TestContext->Buffer);
213
214 CcUnpinData(Bcb);
215 }
216
217 Offset.QuadPart = 0x1500;
218 TestContext->Length -= 0x500;
219
220 KmtStartSeh();
221 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_WAIT | PIN_IF_BCB, &Bcb, (PVOID *)&Buffer);
222 KmtEndSeh(STATUS_SUCCESS);
223
224 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
225 {
226 ok_eq_pointer(Bcb, TestContext->Bcb);
227 ok_eq_pointer(Buffer, (PVOID)((ULONG_PTR)TestContext->Buffer + 0x500));
228
229 CcUnpinData(Bcb);
230 }
231
232 KmtStartSeh();
233 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_WAIT, &Bcb, (PVOID *)&Buffer);
234 KmtEndSeh(STATUS_SUCCESS);
235
236 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
237 {
238 ok_eq_pointer(Bcb, TestContext->Bcb);
239 ok_eq_pointer(Buffer, (PVOID)((ULONG_PTR)TestContext->Buffer + 0x500));
240
241 CcUnpinData(Bcb);
242 }
243
244 KmtStartSeh();
245 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_EXCLUSIVE, &Bcb, (PVOID *)&Buffer);
246 KmtEndSeh(STATUS_SUCCESS);
247
248 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
249 {
250 ok_eq_pointer(Bcb, TestContext->Bcb);
251 ok_eq_pointer(Buffer, (PVOID)((ULONG_PTR)TestContext->Buffer + 0x500));
252
253 CcUnpinData(Bcb);
254 }
255
256 return;
257 }
258
259 static
260 VOID
261 NTAPI
262 PinInAnotherThreadExclusive(IN PVOID Context)
263 {
264 BOOLEAN Ret;
265 PULONG Buffer;
266 PVOID Bcb;
267 LARGE_INTEGER Offset;
268 PTEST_CONTEXT TestContext;
269
270 ok(TestFileObject != NULL, "Called in invalid context!\n");
271 ok_eq_ulong(TestTestId, 3);
272
273 TestContext = Context;
274 ok(TestContext != NULL, "Called in invalid context!\n");
275 ok(TestContext->Bcb != NULL, "Called in invalid context!\n");
276 ok(TestContext->Buffer != NULL, "Called in invalid context!\n");
277 ok(TestContext->Length != 0, "Called in invalid context!\n");
278
279 Ret = FALSE;
280 Offset.QuadPart = 0x1000;
281 KmtStartSeh();
282 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_EXCLUSIVE, &Bcb, (PVOID *)&Buffer);
283 KmtEndSeh(STATUS_SUCCESS);
284 ok(Ret == FALSE, "CcPinRead succeed\n");
285
286 if (Ret)
287 {
288 CcUnpinData(Bcb);
289 }
290
291 KmtStartSeh();
292 Ret = CcMapData(TestFileObject, &Offset, TestContext->Length, 0, &Bcb, (PVOID *)&Buffer);
293 KmtEndSeh(STATUS_SUCCESS);
294
295 if (!skip(Ret == TRUE, "CcMapData failed\n"))
296 {
297 ok(Bcb != TestContext->Bcb, "Returned same BCB!\n");
298 ok_eq_pointer(Buffer, TestContext->Buffer);
299
300 CcUnpinData(Bcb);
301 }
302
303 Offset.QuadPart = 0x1500;
304 TestContext->Length -= 0x500;
305
306 KmtStartSeh();
307 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, PIN_IF_BCB, &Bcb, (PVOID *)&Buffer);
308 KmtEndSeh(STATUS_SUCCESS);
309 ok(Ret == FALSE, "CcPinRead succeed\n");
310
311 if (Ret)
312 {
313 CcUnpinData(Bcb);
314 }
315
316 KmtStartSeh();
317 Ret = CcPinRead(TestFileObject, &Offset, TestContext->Length, 0, &Bcb, (PVOID *)&Buffer);
318 KmtEndSeh(STATUS_SUCCESS);
319 ok(Ret == FALSE, "CcPinRead succeed\n");
320
321 if (Ret)
322 {
323 CcUnpinData(Bcb);
324 }
325
326 KmtStartSeh();
327 Ret = CcMapData(TestFileObject, &Offset, TestContext->Length, 0, &Bcb, (PVOID *)&Buffer);
328 KmtEndSeh(STATUS_SUCCESS);
329
330 if (!skip(Ret == TRUE, "CcMapData failed\n"))
331 {
332 ok(Bcb != TestContext->Bcb, "Returned same BCB!\n");
333 ok_eq_pointer(Buffer, (PVOID)((ULONG_PTR)TestContext->Buffer + 0x500));
334
335 CcUnpinData(Bcb);
336 }
337
338 return;
339 }
340
341 static
342 VOID
343 PerformTest(
344 ULONG TestId,
345 PDEVICE_OBJECT DeviceObject)
346 {
347 PVOID Bcb;
348 BOOLEAN Ret;
349 PULONG Buffer;
350 PTEST_FCB Fcb;
351 LARGE_INTEGER Offset;
352
353 ok_eq_pointer(TestFileObject, NULL);
354 ok_eq_pointer(TestDeviceObject, NULL);
355 ok_eq_ulong(TestTestId, -1);
356
357 TestDeviceObject = DeviceObject;
358 TestTestId = TestId;
359 TestFileObject = IoCreateStreamFileObject(NULL, DeviceObject);
360 if (!skip(TestFileObject != NULL, "Failed to allocate FO\n"))
361 {
362 Fcb = ExAllocatePool(NonPagedPool, sizeof(TEST_FCB));
363 if (!skip(Fcb != NULL, "ExAllocatePool failed\n"))
364 {
365 BOOLEAN PinAccess = (TestId != 4);
366
367 RtlZeroMemory(Fcb, sizeof(TEST_FCB));
368 ExInitializeFastMutex(&Fcb->HeaderMutex);
369 FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex);
370
371 TestFileObject->FsContext = Fcb;
372 TestFileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
373
374 KmtStartSeh();
375 CcInitializeCacheMap(TestFileObject, &FileSizes, PinAccess, &Callbacks, NULL);
376 KmtEndSeh(STATUS_SUCCESS);
377
378 if (!skip(CcIsFileCached(TestFileObject) == TRUE, "CcInitializeCacheMap failed\n"))
379 {
380 if (TestId < 3)
381 {
382 Ret = FALSE;
383 Offset.QuadPart = TestId * 0x1000;
384 KmtStartSeh();
385 Ret = CcPinRead(TestFileObject, &Offset, FileSizes.FileSize.QuadPart - Offset.QuadPart, PIN_WAIT, &Bcb, (PVOID *)&Buffer);
386 KmtEndSeh(STATUS_SUCCESS);
387
388 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
389 {
390 ok_eq_ulong(Buffer[(0x3000 - TestId * 0x1000) / sizeof(ULONG)], 0xDEADBABE);
391
392 CcUnpinData(Bcb);
393 }
394 }
395 else if (TestId == 3)
396 {
397 PTEST_CONTEXT TestContext;
398
399 TestContext = ExAllocatePool(NonPagedPool, sizeof(TEST_CONTEXT));
400 if (!skip(Fcb != NULL, "ExAllocatePool failed\n"))
401 {
402 Ret = FALSE;
403 Offset.QuadPart = 0x1000;
404
405 /* Try enforce BCB first */
406 KmtStartSeh();
407 Ret = CcPinRead(TestFileObject, &Offset, FileSizes.FileSize.QuadPart - Offset.QuadPart, PIN_WAIT | PIN_IF_BCB, &Bcb, (PVOID *)&Buffer);
408 KmtEndSeh(STATUS_SUCCESS);
409 ok(Ret == FALSE, "CcPinRead succeed\n");
410 if (Ret)
411 {
412 CcUnpinData(Bcb);
413 }
414
415 KmtStartSeh();
416 Ret = CcPinRead(TestFileObject, &Offset, FileSizes.FileSize.QuadPart - Offset.QuadPart, PIN_WAIT, &TestContext->Bcb, &TestContext->Buffer);
417 KmtEndSeh(STATUS_SUCCESS);
418
419 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
420 {
421 PKTHREAD ThreadHandle;
422
423 #ifdef _X86_
424 /* FIXME: Should be fixed, will fail under certains conditions */
425 ok(TestContext->Buffer > (PVOID)0xC1000000 && TestContext->Buffer < (PVOID)0xDCFFFFFF,
426 "Buffer %p not mapped in system space\n", TestContext->Buffer);
427 #else
428 #ifdef _M_AMD64
429 ok(TestContext->Buffer > (PVOID)0xFFFFF98000000000 && TestContext->Buffer < (PVOID)0xFFFFFA8000000000,
430 "Buffer %p not mapped in system space\n", TestContext->Buffer);
431 #else
432 skip(FALSE, "System space mapping not defined\n");
433 #endif
434 #endif
435
436 TestContext->Length = FileSizes.FileSize.QuadPart - Offset.QuadPart;
437 ThreadHandle = KmtStartThread(PinInAnotherThread, TestContext);
438 KmtFinishThread(ThreadHandle, NULL);
439
440 TestContext->Length = FileSizes.FileSize.QuadPart - 2 * Offset.QuadPart;
441 ThreadHandle = KmtStartThread(PinInAnotherThread, TestContext);
442 KmtFinishThread(ThreadHandle, NULL);
443
444 CcUnpinData(TestContext->Bcb);
445 }
446
447 KmtStartSeh();
448 Ret = CcPinRead(TestFileObject, &Offset, FileSizes.FileSize.QuadPart - Offset.QuadPart, PIN_WAIT | PIN_EXCLUSIVE, &TestContext->Bcb, &TestContext->Buffer);
449 KmtEndSeh(STATUS_SUCCESS);
450
451 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
452 {
453 PKTHREAD ThreadHandle;
454
455 TestContext->Length = FileSizes.FileSize.QuadPart - Offset.QuadPart;
456 ThreadHandle = KmtStartThread(PinInAnotherThreadExclusive, TestContext);
457 KmtFinishThread(ThreadHandle, NULL);
458
459 CcUnpinData(TestContext->Bcb);
460 }
461
462 ExFreePool(TestContext);
463 }
464 }
465 else if (TestId == 4)
466 {
467 Ret = FALSE;
468 Offset.QuadPart = 0x1000;
469 KmtStartSeh();
470 Ret = CcPinRead(TestFileObject, &Offset, FileSizes.FileSize.QuadPart - Offset.QuadPart, PIN_WAIT, &Bcb, (PVOID *)&Buffer);
471 KmtEndSeh(STATUS_SUCCESS);
472
473 if (!skip(Ret == TRUE, "CcPinRead failed\n"))
474 {
475 ok_eq_ulong(Buffer[0x2000 / sizeof(ULONG)], 0);
476
477 CcUnpinData(Bcb);
478 }
479 }
480 else if (TestId == 5)
481 {
482 /* Pin after EOF */
483 Ret = FALSE;
484 Offset.QuadPart = FileSizes.FileSize.QuadPart + 0x1000;
485
486 KmtStartSeh();
487 Ret = CcPinRead(TestFileObject, &Offset, 0x1000, 0, &Bcb, (PVOID *)&Buffer);
488 KmtEndSeh(STATUS_SUCCESS);
489 ok(Ret == FALSE, "CcPinRead succeed\n");
490
491 if (Ret)
492 {
493 CcUnpinData(Bcb);
494 }
495
496 /* Pin a VACB after EOF */
497 Ret = FALSE;
498 Offset.QuadPart = FileSizes.FileSize.QuadPart + 0x1000 + VACB_MAPPING_GRANULARITY;
499
500 KmtStartSeh();
501 Ret = CcPinRead(TestFileObject, &Offset, 0x1000, 0, &Bcb, (PVOID *)&Buffer);
502 KmtEndSeh(STATUS_ACCESS_VIOLATION);
503 ok(Ret == FALSE, "CcPinRead succeed\n");
504
505 if (Ret)
506 {
507 CcUnpinData(Bcb);
508 }
509
510 /* Pin more than a VACB */
511 Ret = FALSE;
512 Offset.QuadPart = 0x0;
513
514 KmtStartSeh();
515 Ret = CcPinRead(TestFileObject, &Offset, 0x1000 + VACB_MAPPING_GRANULARITY, 0, &Bcb, (PVOID *)&Buffer);
516 KmtEndSeh(STATUS_SUCCESS);
517 ok(Ret == FALSE, "CcPinRead succeed\n");
518
519 if (Ret)
520 {
521 CcUnpinData(Bcb);
522 }
523 }
524 }
525 }
526 }
527 }
528
529
530 static
531 VOID
532 CleanupTest(
533 ULONG TestId,
534 PDEVICE_OBJECT DeviceObject)
535 {
536 LARGE_INTEGER Zero = RTL_CONSTANT_LARGE_INTEGER(0LL);
537 CACHE_UNINITIALIZE_EVENT CacheUninitEvent;
538
539 ok_eq_pointer(TestDeviceObject, DeviceObject);
540 ok_eq_ulong(TestTestId, TestId);
541
542 if (!skip(TestFileObject != NULL, "No test FO\n"))
543 {
544 if (CcIsFileCached(TestFileObject))
545 {
546 KeInitializeEvent(&CacheUninitEvent.Event, NotificationEvent, FALSE);
547 CcUninitializeCacheMap(TestFileObject, &Zero, &CacheUninitEvent);
548 KeWaitForSingleObject(&CacheUninitEvent.Event, Executive, KernelMode, FALSE, NULL);
549 }
550
551 if (TestFileObject->FsContext != NULL)
552 {
553 ExFreePool(TestFileObject->FsContext);
554 TestFileObject->FsContext = NULL;
555 TestFileObject->SectionObjectPointer = NULL;
556 }
557
558 ObDereferenceObject(TestFileObject);
559 }
560
561 TestFileObject = NULL;
562 TestDeviceObject = NULL;
563 TestTestId = -1;
564 }
565
566
567 static
568 NTSTATUS
569 TestMessageHandler(
570 _In_ PDEVICE_OBJECT DeviceObject,
571 _In_ ULONG ControlCode,
572 _In_opt_ PVOID Buffer,
573 _In_ SIZE_T InLength,
574 _Inout_ PSIZE_T OutLength)
575 {
576 NTSTATUS Status = STATUS_SUCCESS;
577
578 FsRtlEnterFileSystem();
579
580 switch (ControlCode)
581 {
582 case IOCTL_START_TEST:
583 ok_eq_ulong((ULONG)InLength, sizeof(ULONG));
584 PerformTest(*(PULONG)Buffer, DeviceObject);
585 break;
586
587 case IOCTL_FINISH_TEST:
588 ok_eq_ulong((ULONG)InLength, sizeof(ULONG));
589 CleanupTest(*(PULONG)Buffer, DeviceObject);
590 break;
591
592 default:
593 Status = STATUS_NOT_IMPLEMENTED;
594 break;
595 }
596
597 FsRtlExitFileSystem();
598
599 return Status;
600 }
601
602 static
603 NTSTATUS
604 TestIrpHandler(
605 _In_ PDEVICE_OBJECT DeviceObject,
606 _In_ PIRP Irp,
607 _In_ PIO_STACK_LOCATION IoStack)
608 {
609 NTSTATUS Status;
610
611 PAGED_CODE();
612
613 DPRINT("IRP %x/%x\n", IoStack->MajorFunction, IoStack->MinorFunction);
614 ASSERT(IoStack->MajorFunction == IRP_MJ_READ);
615
616 FsRtlEnterFileSystem();
617
618 Status = STATUS_NOT_SUPPORTED;
619 Irp->IoStatus.Information = 0;
620
621 if (IoStack->MajorFunction == IRP_MJ_READ)
622 {
623 PMDL Mdl;
624 ULONG Length;
625 PVOID Buffer;
626 LARGE_INTEGER Offset;
627
628 Offset = IoStack->Parameters.Read.ByteOffset;
629 Length = IoStack->Parameters.Read.Length;
630
631 ok_eq_pointer(DeviceObject, TestDeviceObject);
632 ok_eq_pointer(IoStack->FileObject, TestFileObject);
633
634 ok(FlagOn(Irp->Flags, IRP_NOCACHE), "Not coming from Cc\n");
635
636 ok_irql(APC_LEVEL);
637 ok((Offset.QuadPart % PAGE_SIZE == 0 || Offset.QuadPart == 0), "Offset is not aligned: %I64i\n", Offset.QuadPart);
638 ok(Length % PAGE_SIZE == 0, "Length is not aligned: %I64i\n", Length);
639
640 ok(Irp->AssociatedIrp.SystemBuffer == NULL, "A SystemBuffer was allocated!\n");
641 Buffer = MapAndLockUserBuffer(Irp, Length);
642 ok(Buffer != NULL, "Null pointer!\n");
643 RtlFillMemory(Buffer, Length, 0xBA);
644
645 Status = STATUS_SUCCESS;
646 if (Offset.QuadPart <= 0x3000 && Offset.QuadPart + Length > 0x3000)
647 {
648 *(PULONG)((ULONG_PTR)Buffer + (ULONG_PTR)(0x3000 - Offset.QuadPart)) = 0xDEADBABE;
649 }
650
651 Mdl = Irp->MdlAddress;
652 ok(Mdl != NULL, "Null pointer for MDL!\n");
653 ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) != 0, "MDL not locked\n");
654 ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) == 0, "MDL from non paged\n");
655 ok((Mdl->MdlFlags & MDL_IO_PAGE_READ) != 0, "Non paging IO\n");
656 ok((Irp->Flags & IRP_PAGING_IO) != 0, "Non paging IO\n");
657
658 Irp->IoStatus.Information = Length;
659 }
660
661 if (Status == STATUS_PENDING)
662 {
663 IoMarkIrpPending(Irp);
664 IoCompleteRequest(Irp, IO_NO_INCREMENT);
665 Status = STATUS_PENDING;
666 }
667 else
668 {
669 Irp->IoStatus.Status = Status;
670 IoCompleteRequest(Irp, IO_NO_INCREMENT);
671 }
672
673 FsRtlExitFileSystem();
674
675 return Status;
676 }