[KMTESTS:MM]
[reactos.git] / rostests / kmtests / ntos_mm / NtCreateSection_user.c
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
10 START_TEST(NtCreateSection)
11 {
12 PVOID Buffer;
13 ULONG FileSize;
14 NTSTATUS Status;
15 LARGE_INTEGER MaxFileSize;
16 HANDLE Handle, SectionHandle;
17 IO_STATUS_BLOCK IoStatusBlock;
18 OBJECT_ATTRIBUTES ObjectAttributes;
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 */
27 InitializeObjectAttributes(&ObjectAttributes, &InvalidInit, OBJ_CASE_INSENSITIVE, NULL, NULL);
28 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
29 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
30 ok_eq_hex(Status, STATUS_SUCCESS);
31
32 MaxFileSize.QuadPart = 512;
33 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
34 PAGE_READWRITE, SEC_COMMIT, Handle);
35 ok_eq_hex(Status, STATUS_INVALID_FILE_FOR_SECTION);
36 NtClose(Handle);
37
38 /* Test 1 */
39 InitializeObjectAttributes(&ObjectAttributes, &InitOnCreate, OBJ_CASE_INSENSITIVE, NULL, NULL);
40 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
41 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
42 ok_eq_hex(Status, STATUS_SUCCESS);
43
44 MaxFileSize.QuadPart = 512;
45 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
46 PAGE_READWRITE, SEC_COMMIT, Handle);
47 ok_eq_hex(Status, STATUS_SUCCESS);
48
49 Buffer = NULL;
50 FileSize = 0;
51 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
52 &FileSize, ViewUnmap, 0, PAGE_READWRITE);
53 ok_eq_hex(Status, STATUS_SUCCESS);
54
55 KmtStartSeh();
56 memset(Buffer, 0xBA, 512);
57 KmtEndSeh(STATUS_SUCCESS);
58
59 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
60 NtClose(SectionHandle);
61 NtClose(Handle);
62
63 /* Test 2 */
64 InitializeObjectAttributes(&ObjectAttributes, &InitOnCreate, OBJ_CASE_INSENSITIVE, NULL, NULL);
65 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
66 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
67 ok_eq_hex(Status, STATUS_SUCCESS);
68
69 MaxFileSize.QuadPart = 4096;
70 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
71 PAGE_READWRITE, SEC_COMMIT, Handle);
72 ok_eq_hex(Status, STATUS_SUCCESS);
73
74 Buffer = NULL;
75 FileSize = 0;
76 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
77 &FileSize, ViewUnmap, 0, PAGE_READWRITE);
78 ok_eq_hex(Status, STATUS_SUCCESS);
79
80 KmtStartSeh();
81 memset(Buffer, 0xBA, 4096);
82 KmtEndSeh(STATUS_SUCCESS);
83
84 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
85 NtClose(SectionHandle);
86 NtClose(Handle);
87
88 /* Test 3 */
89 InitializeObjectAttributes(&ObjectAttributes, &InitOnRW, OBJ_CASE_INSENSITIVE, NULL, NULL);
90 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
91 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
92 ok_eq_hex(Status, STATUS_SUCCESS);
93
94 MaxFileSize.QuadPart = 512;
95 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
96 PAGE_READWRITE, SEC_COMMIT, Handle);
97 ok_eq_hex(Status, STATUS_SUCCESS);
98
99 Buffer = NULL;
100 FileSize = 0;
101 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
102 &FileSize, ViewUnmap, 0, PAGE_READWRITE);
103 ok_eq_hex(Status, STATUS_SUCCESS);
104
105 KmtStartSeh();
106 memset(Buffer, 0xBA, 512);
107 KmtEndSeh(STATUS_SUCCESS);
108
109 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
110 NtClose(SectionHandle);
111 NtClose(Handle);
112
113 /* Test 4 */
114 InitializeObjectAttributes(&ObjectAttributes, &InitOnRW, OBJ_CASE_INSENSITIVE, NULL, NULL);
115 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
116 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
117 ok_eq_hex(Status, STATUS_SUCCESS);
118
119 MaxFileSize.QuadPart = 4096;
120 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
121 PAGE_READWRITE, SEC_COMMIT, Handle);
122 ok_eq_hex(Status, STATUS_SUCCESS);
123
124 Buffer = NULL;
125 FileSize = 0;
126 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
127 &FileSize, ViewUnmap, 0, PAGE_READWRITE);
128 ok_eq_hex(Status, STATUS_SUCCESS);
129
130 KmtStartSeh();
131 memset(Buffer, 0xBA, 4096);
132 KmtEndSeh(STATUS_SUCCESS);
133
134 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
135 NtClose(SectionHandle);
136 NtClose(Handle);
137
138 /* Test 10 */
139 InitializeObjectAttributes(&ObjectAttributes, &InvalidInit, OBJ_CASE_INSENSITIVE, NULL, NULL);
140 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
141 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
142 ok_eq_hex(Status, STATUS_SUCCESS);
143
144 MaxFileSize.QuadPart = 512;
145 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
146 PAGE_READWRITE, SEC_COMMIT, Handle);
147 ok_eq_hex(Status, STATUS_INVALID_FILE_FOR_SECTION);
148 NtClose(Handle);
149
150 /* Test 11 */
151 InitializeObjectAttributes(&ObjectAttributes, &InitOnCreate, OBJ_CASE_INSENSITIVE, NULL, NULL);
152 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
153 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
154 ok_eq_hex(Status, STATUS_SUCCESS);
155
156 MaxFileSize.QuadPart = 512;
157 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
158 PAGE_READWRITE, SEC_COMMIT, Handle);
159 ok_eq_hex(Status, STATUS_SUCCESS);
160
161 Buffer = NULL;
162 FileSize = 0;
163 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
164 &FileSize, ViewUnmap, 0, PAGE_READWRITE);
165 ok_eq_hex(Status, STATUS_SUCCESS);
166
167 KmtStartSeh();
168 memset(Buffer, 0xBA, 512);
169 KmtEndSeh(STATUS_SUCCESS);
170
171 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
172 NtClose(SectionHandle);
173 NtClose(Handle);
174
175 /* Test 12 */
176 InitializeObjectAttributes(&ObjectAttributes, &InitOnCreate, OBJ_CASE_INSENSITIVE, NULL, NULL);
177 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
178 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
179 ok_eq_hex(Status, STATUS_SUCCESS);
180
181 MaxFileSize.QuadPart = 4096;
182 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
183 PAGE_READWRITE, SEC_COMMIT, Handle);
184 ok_eq_hex(Status, STATUS_SUCCESS);
185
186 Buffer = NULL;
187 FileSize = 0;
188 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
189 &FileSize, ViewUnmap, 0, PAGE_READWRITE);
190 ok_eq_hex(Status, STATUS_SUCCESS);
191
192 KmtStartSeh();
193 memset(Buffer, 0xBA, 4096);
194 KmtEndSeh(STATUS_SUCCESS);
195
196 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
197 NtClose(SectionHandle);
198 NtClose(Handle);
199
200 /* Test 13 */
201 InitializeObjectAttributes(&ObjectAttributes, &InitOnRW, OBJ_CASE_INSENSITIVE, NULL, NULL);
202 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
203 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
204 ok_eq_hex(Status, STATUS_SUCCESS);
205
206 MaxFileSize.QuadPart = 512;
207 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
208 PAGE_READWRITE, SEC_COMMIT, Handle);
209 ok_eq_hex(Status, STATUS_SUCCESS);
210
211 Buffer = NULL;
212 FileSize = 0;
213 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
214 &FileSize, ViewUnmap, 0, PAGE_READWRITE);
215 ok_eq_hex(Status, STATUS_SUCCESS);
216
217 KmtStartSeh();
218 memset(Buffer, 0xBA, 512);
219 KmtEndSeh(STATUS_SUCCESS);
220
221 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
222 NtClose(SectionHandle);
223 NtClose(Handle);
224
225 /* Test 14 */
226 InitializeObjectAttributes(&ObjectAttributes, &InitOnRW, OBJ_CASE_INSENSITIVE, NULL, NULL);
227 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
228 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
229 ok_eq_hex(Status, STATUS_SUCCESS);
230
231 MaxFileSize.QuadPart = 4096;
232 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
233 PAGE_READWRITE, SEC_COMMIT, Handle);
234 ok_eq_hex(Status, STATUS_SUCCESS);
235
236 Buffer = NULL;
237 FileSize = 0;
238 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
239 &FileSize, ViewUnmap, 0, PAGE_READWRITE);
240 ok_eq_hex(Status, STATUS_SUCCESS);
241
242 KmtStartSeh();
243 memset(Buffer, 0xBA, 4096);
244 KmtEndSeh(STATUS_SUCCESS);
245
246 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
247 NtClose(SectionHandle);
248 NtClose(Handle);
249
250 KmtCloseDriver();
251 KmtUnloadDriver();
252 }