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