ReactOS  0.4.15-dev-1197-g8081ba9
NtCreateSection_user.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS kernel-mode tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: Kernel-Mode Test Suite NtCreateSection test user-mode part
5  * PROGRAMMER: Pierre Schweitzer <pierre@reactos.org>
6  */
7 
8 #include <kmt_test.h>
9 
11 {
12  PVOID Buffer;
15  LARGE_INTEGER MaxFileSize;
16  HANDLE Handle, SectionHandle;
19  UNICODE_STRING InitOnCreate = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-NtCreateSection\\InitOnCreate");
20  UNICODE_STRING InitOnRW = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-NtCreateSection\\InitOnRW");
21  UNICODE_STRING InvalidInit = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-NtCreateSection\\InvalidInit");
22 
23  KmtLoadDriver(L"NtCreateSection", FALSE);
24  KmtOpenDriver();
25 
26  /* Test 0 */
31 
32  MaxFileSize.QuadPart = 512;
33  Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
36  if (NT_SUCCESS(Status)) NtClose(SectionHandle);
39 
40  /* Test 1 */
45 
46  MaxFileSize.QuadPart = 512;
47  Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
50 
51  Buffer = NULL;
52  FileSize = 0;
53  Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
56 
57  KmtStartSeh();
58  ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
59  memset(Buffer, 0xBA, 512);
61 
64  Status = NtClose(SectionHandle);
68 
69  /* Test 2 */
74 
75  MaxFileSize.QuadPart = 4096;
76  Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
79 
80  Buffer = NULL;
81  FileSize = 0;
82  Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
85 
86  KmtStartSeh();
87  ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
88  memset(Buffer, 0xBA, 4096);
90 
93  Status = NtClose(SectionHandle);
97 
98  /* Test 3 */
103 
104  MaxFileSize.QuadPart = 512;
105  Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
108 
109  Buffer = NULL;
110  FileSize = 0;
111  Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
114 
115  KmtStartSeh();
116  ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
117  memset(Buffer, 0xBA, 512);
119 
122  Status = NtClose(SectionHandle);
124  Status = NtClose(Handle);
126 
127  /* Test 4 */
132 
133  MaxFileSize.QuadPart = 4096;
134  Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
137 
138  Buffer = NULL;
139  FileSize = 0;
140  Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
143 
144  KmtStartSeh();
145  ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
146  memset(Buffer, 0xBA, 4096);
148 
151  Status = NtClose(SectionHandle);
153  Status = NtClose(Handle);
155 
156  /* Test 10 */
161 
162  MaxFileSize.QuadPart = 512;
163  Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
166  if (NT_SUCCESS(Status)) NtClose(SectionHandle);
167  Status = NtClose(Handle);
169 
170  /* Test 11 */
175 
176  MaxFileSize.QuadPart = 512;
177  Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
180 
181  Buffer = NULL;
182  FileSize = 0;
183  Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
186 
187  KmtStartSeh();
188  ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
189  memset(Buffer, 0xBA, 512);
191 
194  Status = NtClose(SectionHandle);
196  Status = NtClose(Handle);
198 
199  /* Test 12 */
204 
205  MaxFileSize.QuadPart = 4096;
206  Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
209 
210  Buffer = NULL;
211  FileSize = 0;
212  Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
215 
216  KmtStartSeh();
217  ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
218  memset(Buffer, 0xBA, 4096);
220 
223  Status = NtClose(SectionHandle);
225  Status = NtClose(Handle);
227 
228  /* Test 13 */
233 
234  MaxFileSize.QuadPart = 512;
235  Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
238 
239  Buffer = NULL;
240  FileSize = 0;
241  Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
244 
245  KmtStartSeh();
246  ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
247  memset(Buffer, 0xBA, 512);
249 
252  Status = NtClose(SectionHandle);
254  Status = NtClose(Handle);
256 
257  /* Test 14 */
262 
263  MaxFileSize.QuadPart = 4096;
264  Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
267 
268  Buffer = NULL;
269  FileSize = 0;
270  Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
273 
274  KmtStartSeh();
275  ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
276  memset(Buffer, 0xBA, 4096);
278 
281  Status = NtClose(SectionHandle);
283  Status = NtClose(Handle);
285 
286  KmtCloseDriver();
287  KmtUnloadDriver();
288 }
signed char * PCHAR
Definition: retypes.h:7
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3782
NTSTATUS NTAPI NtCreateSection(OUT PHANDLE SectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize OPTIONAL, IN ULONG SectionPageProtection OPTIONAL, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL)
Definition: section.c:3373
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_CREATE
Definition: from_kernel.h:55
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:283
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define SEC_COMMIT
Definition: mmtypes.h:99
#define FALSE
Definition: types.h:117
#define GENERIC_WRITE
Definition: nt_native.h:90
NTSTATUS NTAPI NtMapViewOfSection(IN HANDLE SectionHandle, IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
Definition: section.c:3554
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NtCurrentProcess()
Definition: nt_native.h:1657
_In_ HANDLE Handle
Definition: extypes.h:390
VOID KmtCloseDriver(VOID)
Definition: support.c:207
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)
static UNICODE_STRING InitOnCreate
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
#define GENERIC_READ
Definition: compat.h:135
#define SYNCHRONIZE
Definition: nt_native.h:61
#define KmtStartSeh()
Definition: kmt_test.h:277
#define FILE_OPEN
Definition: from_kernel.h:54
ULONG_PTR SIZE_T
Definition: typedefs.h:80
VOID KmtUnloadDriver(VOID)
Definition: support.c:156
static UNICODE_STRING InvalidInit
#define ok(value,...)
Definition: atltest.h:57
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
static UNICODE_STRING InitOnRW
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ok_eq_hex(value, expected)
VOID KmtLoadDriver(IN PCWSTR ServiceName, IN BOOLEAN RestartIfRunning)
Definition: support.c:128
VOID KmtOpenDriver(VOID)
Definition: support.c:181
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define memset(x, y, z)
Definition: compat.h:39
LONGLONG QuadPart
Definition: typedefs.h:114
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
START_TEST(NtCreateSection)