1 /* 2 * PROJECT: ReactOS kernel-mode tests 3 * LICENSE: GPLv2+ - See COPYING in the top level directory 4 * PURPOSE: Kernel-Mode Test Suite CcCopyRead test user-mode part 5 * PROGRAMMER: Pierre Schweitzer <pierre@reactos.org> 6 */ 7 8 #include <kmt_test.h> 9 10 START_TEST(CcCopyRead) 11 { 12 HANDLE Handle; 13 NTSTATUS Status; 14 LARGE_INTEGER ByteOffset; 15 IO_STATUS_BLOCK IoStatusBlock; 16 OBJECT_ATTRIBUTES ObjectAttributes; 17 PVOID Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, 1024); 18 UNICODE_STRING BigAlignmentTest = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\BigAlignmentTest"); 19 UNICODE_STRING SmallAlignmentTest = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\SmallAlignmentTest"); 20 UNICODE_STRING ReallySmallAlignmentTest = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\ReallySmallAlignmentTest"); 21 UNICODE_STRING FileBig = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-CcCopyRead\\FileBig"); 22 23 KmtLoadDriver(L"CcCopyRead", FALSE); 24 KmtOpenDriver(); 25 26 InitializeObjectAttributes(&ObjectAttributes, &SmallAlignmentTest, OBJ_CASE_INSENSITIVE, NULL, NULL); 27 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT); 28 ok_eq_hex(Status, STATUS_SUCCESS); 29 30 ByteOffset.QuadPart = 3; 31 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 3, &ByteOffset, NULL); 32 ok_eq_hex(Status, STATUS_SUCCESS); 33 ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA); 34 35 ByteOffset.QuadPart = 514; 36 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 514, &ByteOffset, NULL); 37 ok_eq_hex(Status, STATUS_SUCCESS); 38 ok_eq_hex(((USHORT *)Buffer)[242], 0xBABA); 39 ok_eq_hex(((USHORT *)Buffer)[243], 0xFFFF); 40 41 ByteOffset.QuadPart = 1000; 42 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 2, &ByteOffset, NULL); 43 ok_eq_hex(Status, STATUS_SUCCESS); 44 ok_eq_hex(((USHORT *)Buffer)[0], 0xFFFF); 45 ok_eq_hex(((USHORT *)Buffer)[1], 0xBABA); 46 47 NtClose(Handle); 48 49 InitializeObjectAttributes(&ObjectAttributes, &BigAlignmentTest, OBJ_CASE_INSENSITIVE, NULL, NULL); 50 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT); 51 ok_eq_hex(Status, STATUS_SUCCESS); 52 53 ByteOffset.QuadPart = 3; 54 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 3, &ByteOffset, NULL); 55 ok_eq_hex(Status, STATUS_SUCCESS); 56 ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA); 57 58 ByteOffset.QuadPart = 514; 59 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 514, &ByteOffset, NULL); 60 ok_eq_hex(Status, STATUS_SUCCESS); 61 ok_eq_hex(((USHORT *)Buffer)[242], 0xBABA); 62 ok_eq_hex(((USHORT *)Buffer)[243], 0xFFFF); 63 64 ByteOffset.QuadPart = 300000; 65 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 10, &ByteOffset, NULL); 66 ok_eq_hex(Status, STATUS_SUCCESS); 67 ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA); 68 69 ByteOffset.QuadPart = 999990; 70 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 10, &ByteOffset, NULL); 71 ok_eq_hex(Status, STATUS_SUCCESS); 72 ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA); 73 74 ByteOffset.QuadPart = 1000; 75 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 2, &ByteOffset, NULL); 76 ok_eq_hex(Status, STATUS_SUCCESS); 77 ok_eq_hex(((USHORT *)Buffer)[0], 0xFFFF); 78 ok_eq_hex(((USHORT *)Buffer)[1], 0xBABA); 79 80 NtClose(Handle); 81 82 InitializeObjectAttributes(&ObjectAttributes, &ReallySmallAlignmentTest, OBJ_CASE_INSENSITIVE, NULL, NULL); 83 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT); 84 ok_eq_hex(Status, STATUS_SUCCESS); 85 86 ByteOffset.QuadPart = 1; 87 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 61, &ByteOffset, NULL); 88 ok_eq_hex(Status, STATUS_SUCCESS); 89 ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA); 90 91 NtClose(Handle); 92 93 InitializeObjectAttributes(&ObjectAttributes, &FileBig, OBJ_CASE_INSENSITIVE, NULL, NULL); 94 Status = NtOpenFile(&Handle, FILE_ALL_ACCESS, &ObjectAttributes, &IoStatusBlock, 0, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT); 95 ok_eq_hex(Status, STATUS_SUCCESS); 96 97 ByteOffset.QuadPart = 0; 98 Status = NtReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Buffer, 1024, &ByteOffset, NULL); 99 ok_eq_hex(Status, STATUS_SUCCESS); 100 ok_eq_hex(((USHORT *)Buffer)[0], 0xBABA); 101 102 NtClose(Handle); 103 104 RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); 105 KmtCloseDriver(); 106 KmtUnloadDriver(); 107 } 108