ReactOS 0.4.15-dev-7906-g1b85a5f
NtReadFile.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for NtReadFile
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8#include "precomp.h"
9
10static
11BOOL
13{
14#ifdef _WIN64
15 return TRUE;
16#else
19
22 &IsWow64,
23 sizeof(IsWow64),
24 NULL);
25 if (NT_SUCCESS(Status))
26 {
27 return IsWow64 != 0;
28 }
29
30 return FALSE;
31#endif
32}
33
34static
37{
38 return Is64BitSystem() ? 48 : 28;
39}
40
42{
45 UNICODE_STRING FileName = RTL_CONSTANT_STRING(L"\\SystemRoot\\ntdll-apitest-NtReadFile-test.bin");
51 FILE_DISPOSITION_INFORMATION DispositionInfo;
52 ULONG TooLargeDataSize = (MAXUSHORT + 1 - SizeOfMdl()) / sizeof(ULONG_PTR) * PAGE_SIZE; // 0x3FF9000 on x86
53 ULONG LargeMdlMaxDataSize = TooLargeDataSize - PAGE_SIZE;
54
55 trace("System is %d bits, Size of MDL: %lu\n", Is64BitSystem() ? 64 : 32, SizeOfMdl());
56 trace("Max MDL data size: 0x%lx bytes\n", LargeMdlMaxDataSize);
57
58 ByteOffset.QuadPart = 0;
59
60 Buffer = NULL;
61 BufferSize = TooLargeDataSize;
63 &Buffer,
64 0,
68 if (!NT_SUCCESS(Status))
69 {
70 skip("Failed to allocate memory, status %lx\n", Status);
71 return;
72 }
73
75 &FileName,
77 NULL,
78 NULL);
82 &IoStatus,
83 NULL,
84 0,
85 0,
89 NULL,
90 0);
92
93 ByteOffset.QuadPart = 0x10000;
95 NULL,
96 NULL,
97 NULL,
98 &IoStatus,
99 Buffer,
100 BufferSize - 0x10000,
101 &ByteOffset,
102 NULL);
104 ByteOffset.QuadPart = 0;
105
106 /* non-cached, max size -- succeeds */
108 NULL,
109 NULL,
110 NULL,
111 &IoStatus,
112 Buffer,
113 LargeMdlMaxDataSize - PAGE_SIZE,
114 &ByteOffset,
115 NULL);
117
118 /* non-cached, max size -- succeeds */
120 NULL,
121 NULL,
122 NULL,
123 &IoStatus,
124 Buffer,
125 LargeMdlMaxDataSize,
126 &ByteOffset,
127 NULL);
129
130 /* non-cached, too large -- fails to allocate MDL
131 * Note: this returns STATUS_SUCCESS on Win7 -- higher MDL size limit */
133 NULL,
134 NULL,
135 NULL,
136 &IoStatus,
137 Buffer,
138 LargeMdlMaxDataSize + PAGE_SIZE,
139 &ByteOffset,
140 NULL);
142
143 /* non-cached, unaligned -- fails with invalid parameter */
145 NULL,
146 NULL,
147 NULL,
148 &IoStatus,
149 Buffer,
150 LargeMdlMaxDataSize + 1,
151 &ByteOffset,
152 NULL);
154
155 DispositionInfo.DeleteFile = TRUE;
157 &IoStatus,
158 &DispositionInfo,
159 sizeof(DispositionInfo),
164
168 &IoStatus,
169 NULL,
170 0,
171 0,
174 NULL,
175 0);
177
178 ByteOffset.QuadPart = 0x10000;
180 NULL,
181 NULL,
182 NULL,
183 &IoStatus,
184 Buffer,
185 BufferSize - 0x10000,
186 &ByteOffset,
187 NULL);
189 ByteOffset.QuadPart = 0;
190
191 /* cached: succeeds with arbitrary length */
193 NULL,
194 NULL,
195 NULL,
196 &IoStatus,
197 Buffer,
198 LargeMdlMaxDataSize,
199 &ByteOffset,
200 NULL);
202
204 NULL,
205 NULL,
206 NULL,
207 &IoStatus,
208 Buffer,
209 LargeMdlMaxDataSize + 1,
210 &ByteOffset,
211 NULL);
213
215 NULL,
216 NULL,
217 NULL,
218 &IoStatus,
219 Buffer,
220 TooLargeDataSize,
221 &ByteOffset,
222 NULL);
224
225 DispositionInfo.DeleteFile = TRUE;
227 &IoStatus,
228 &DispositionInfo,
229 sizeof(DispositionInfo),
234
236 &Buffer,
237 &BufferSize,
240}
static BOOL Is64BitSystem(VOID)
Definition: NtReadFile.c:12
static ULONG SizeOfMdl(VOID)
Definition: NtReadFile.c:36
#define ok_hex(expression, result)
Definition: atltest.h:94
#define trace
Definition: atltest.h:70
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define BufferSize
Definition: mmc.h:75
#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:32
#define PAGE_SIZE
Definition: env_spec_w32.h:49
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:731
unsigned int BOOL
Definition: ntddk_ex.h:94
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
@ FileDispositionInformation
Definition: from_kernel.h:74
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
Status
Definition: gdiplustypes.h:25
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
@ ProcessWow64Information
Definition: winternl.h:396
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define FILE_READ_DATA
Definition: nt_native.h:628
#define PAGE_READWRITE
Definition: nt_native.h:1304
NTSYSAPI NTSTATUS NTAPI NtWriteFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID WriteBuffer, IN ULONG WriteBufferLength, IN PLARGE_INTEGER FileOffset OPTIONAL, IN PULONG LockOperationKey OPTIONAL)
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSYSAPI NTSTATUS NTAPI NtSetInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
Definition: iofunc.c:3096
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define DELETE
Definition: nt_native.h:57
#define MEM_RESERVE
Definition: nt_native.h:1314
#define MEM_RELEASE
Definition: nt_native.h:1316
NTSTATUS NTAPI NtCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG CreateDisposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength)
#define MEM_COMMIT
Definition: nt_native.h:1313
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5230
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4492
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define MAXUSHORT
Definition: typedefs.h:83
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
BOOL IsWow64(VOID)
Definition: user_lib.cpp:579
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254