ReactOS 0.4.15-dev-7924-g5949c20
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{
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");
23
24 Error = KmtLoadAndOpenDriver(L"NtCreateSection", FALSE);
26 if (Error)
27 return;
28
29 /* Test 0 */
34
35 MaxFileSize.QuadPart = 512;
36 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
39 if (NT_SUCCESS(Status)) NtClose(SectionHandle);
42
43 /* Test 1 */
48
49 MaxFileSize.QuadPart = 512;
50 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
53
54 Buffer = NULL;
55 FileSize = 0;
56 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
59
61 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
62 memset(Buffer, 0xBA, 512);
64
67 Status = NtClose(SectionHandle);
71
72 /* Test 2 */
77
78 MaxFileSize.QuadPart = 4096;
79 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
82
83 Buffer = NULL;
84 FileSize = 0;
85 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
88
90 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
91 memset(Buffer, 0xBA, 4096);
93
96 Status = NtClose(SectionHandle);
100
101 /* Test 3 */
106
107 MaxFileSize.QuadPart = 512;
108 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
111
112 Buffer = NULL;
113 FileSize = 0;
114 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
117
118 KmtStartSeh();
119 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
120 memset(Buffer, 0xBA, 512);
122
125 Status = NtClose(SectionHandle);
129
130 /* Test 4 */
135
136 MaxFileSize.QuadPart = 4096;
137 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
140
141 Buffer = NULL;
142 FileSize = 0;
143 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
146
147 KmtStartSeh();
148 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
149 memset(Buffer, 0xBA, 4096);
151
154 Status = NtClose(SectionHandle);
158
159 /* Test 10 */
164
165 MaxFileSize.QuadPart = 512;
166 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
169 if (NT_SUCCESS(Status)) NtClose(SectionHandle);
172
173 /* Test 11 */
178
179 MaxFileSize.QuadPart = 512;
180 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
183
184 Buffer = NULL;
185 FileSize = 0;
186 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
189
190 KmtStartSeh();
191 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
192 memset(Buffer, 0xBA, 512);
194
197 Status = NtClose(SectionHandle);
201
202 /* Test 12 */
207
208 MaxFileSize.QuadPart = 4096;
209 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
212
213 Buffer = NULL;
214 FileSize = 0;
215 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
218
219 KmtStartSeh();
220 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
221 memset(Buffer, 0xBA, 4096);
223
226 Status = NtClose(SectionHandle);
230
231 /* Test 13 */
236
237 MaxFileSize.QuadPart = 512;
238 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
241
242 Buffer = NULL;
243 FileSize = 0;
244 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
247
248 KmtStartSeh();
249 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
250 memset(Buffer, 0xBA, 512);
252
255 Status = NtClose(SectionHandle);
259
260 /* Test 14 */
265
266 MaxFileSize.QuadPart = 4096;
267 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
270
271 Buffer = NULL;
272 FileSize = 0;
273 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
276
277 KmtStartSeh();
278 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
279 memset(Buffer, 0xBA, 4096);
281
284 Status = NtClose(SectionHandle);
288
291}
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3848
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:3441
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:3622
static UNICODE_STRING InitOnCreate
static UNICODE_STRING InitOnRW
static UNICODE_STRING InvalidInit
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define ok_eq_int(value, expected)
Definition: apitest.h:60
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
BOOL Error
Definition: chkdsk.c:66
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define GENERIC_READ
Definition: compat.h:135
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_OPEN
Definition: from_kernel.h:54
#define FILE_CREATE
Definition: from_kernel.h:55
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define KmtStartSeh()
Definition: kmt_test.h:282
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:288
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define SEC_COMMIT
Definition: mmtypes.h:100
#define SYNCHRONIZE
Definition: nt_native.h:61
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define NtCurrentProcess()
Definition: nt_native.h:1657
@ ViewUnmap
Definition: nt_native.h:1279
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
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 GENERIC_WRITE
Definition: nt_native.h:90
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
#define L(x)
Definition: ntvdm.h:50
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_SUCCESS
Definition: shellext.h:65
DWORD KmtLoadAndOpenDriver(IN PCWSTR ServiceName, IN BOOLEAN RestartIfRunning)
Definition: support.c:213
VOID KmtCloseDriver(VOID)
Definition: support.c:236
VOID KmtUnloadDriver(VOID)
Definition: support.c:167
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
ULONG_PTR SIZE_T
Definition: typedefs.h:80
char * PCHAR
Definition: typedefs.h:51
LONGLONG QuadPart
Definition: typedefs.h:114