ReactOS  0.4.15-dev-3297-g037c744
NtReadFile.c File Reference
#include "precomp.h"
Include dependency graph for NtReadFile.c:

Go to the source code of this file.

Functions

static BOOL Is64BitSystem (VOID)
 
static ULONG SizeOfMdl (VOID)
 
 START_TEST (NtReadFile)
 

Function Documentation

◆ Is64BitSystem()

static BOOL Is64BitSystem ( VOID  )
static

Definition at line 12 of file NtReadFile.c.

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 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NULL
Definition: types.h:112
BOOL IsWow64(VOID)
Definition: user_lib.cpp:579
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59

Referenced by SizeOfMdl(), and START_TEST().

◆ SizeOfMdl()

static ULONG SizeOfMdl ( VOID  )
static

Definition at line 36 of file NtReadFile.c.

37 {
38  return Is64BitSystem() ? 48 : 28;
39 }
static BOOL Is64BitSystem(VOID)
Definition: NtReadFile.c:12

Referenced by FxRequestBuffer::GetOrAllocateMdl(), FxRequestBuffer::GetOrAllocateMdlWorker(), and START_TEST().

◆ START_TEST()

START_TEST ( NtReadFile  )

Definition at line 41 of file NtReadFile.c.

42 {
45  UNICODE_STRING FileName = RTL_CONSTANT_STRING(L"\\SystemRoot\\ntdll-apitest-NtReadFile-test.bin");
46  PVOID Buffer;
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,
65  &BufferSize,
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,
238  MEM_RELEASE);
240 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS NTAPI NtSetInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define MEM_COMMIT
Definition: nt_native.h:1313
#define ok_hex(expression, result)
Definition: atltest.h:94
uint32_t ULONG_PTR
Definition: typedefs.h:65
HANDLE FileHandle
Definition: stats.c:38
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
#define FILE_READ_DATA
Definition: nt_native.h:628
#define MEM_RESERVE
Definition: nt_native.h:1314
Definition: bufpool.h:45
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
#define trace
Definition: atltest.h:70
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 NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3398
static ULONG SizeOfMdl(VOID)
Definition: NtReadFile.c:36
static const WCHAR L[]
Definition: oid.c:1250
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 FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define SYNCHRONIZE
Definition: nt_native.h:61
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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:4481
#define NULL
Definition: types.h:112
static BOOL Is64BitSystem(VOID)
Definition: NtReadFile.c:12
#define MAXUSHORT
Definition: typedefs.h:83
#define skip(...)
Definition: atltest.h:64
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define MEM_RELEASE
Definition: nt_native.h:1316
__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 FILE_SUPERSEDE
Definition: from_kernel.h:53
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#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 BufferSize
Definition: mmc.h:75
#define DELETE
Definition: nt_native.h:57
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:725
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5204