[STORAHCI] Merge Storport Miniport driver by Aman Priyadarshi in GSoC.
[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 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
57 memset(Buffer, 0xBA, 512);
58 KmtEndSeh(STATUS_SUCCESS);
59
60 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
61 NtClose(SectionHandle);
62 NtClose(Handle);
63
64 /* Test 2 */
65 InitializeObjectAttributes(&ObjectAttributes, &InitOnCreate, OBJ_CASE_INSENSITIVE, NULL, NULL);
66 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
67 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
68 ok_eq_hex(Status, STATUS_SUCCESS);
69
70 MaxFileSize.QuadPart = 4096;
71 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
72 PAGE_READWRITE, SEC_COMMIT, Handle);
73 ok_eq_hex(Status, STATUS_SUCCESS);
74
75 Buffer = NULL;
76 FileSize = 0;
77 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
78 &FileSize, ViewUnmap, 0, PAGE_READWRITE);
79 ok_eq_hex(Status, STATUS_SUCCESS);
80
81 KmtStartSeh();
82 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
83 memset(Buffer, 0xBA, 4096);
84 KmtEndSeh(STATUS_SUCCESS);
85
86 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
87 NtClose(SectionHandle);
88 NtClose(Handle);
89
90 /* Test 3 */
91 InitializeObjectAttributes(&ObjectAttributes, &InitOnRW, OBJ_CASE_INSENSITIVE, NULL, NULL);
92 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
93 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
94 ok_eq_hex(Status, STATUS_SUCCESS);
95
96 MaxFileSize.QuadPart = 512;
97 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
98 PAGE_READWRITE, SEC_COMMIT, Handle);
99 ok_eq_hex(Status, STATUS_SUCCESS);
100
101 Buffer = NULL;
102 FileSize = 0;
103 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
104 &FileSize, ViewUnmap, 0, PAGE_READWRITE);
105 ok_eq_hex(Status, STATUS_SUCCESS);
106
107 KmtStartSeh();
108 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
109 memset(Buffer, 0xBA, 512);
110 KmtEndSeh(STATUS_SUCCESS);
111
112 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
113 NtClose(SectionHandle);
114 NtClose(Handle);
115
116 /* Test 4 */
117 InitializeObjectAttributes(&ObjectAttributes, &InitOnRW, OBJ_CASE_INSENSITIVE, NULL, NULL);
118 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
119 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
120 ok_eq_hex(Status, STATUS_SUCCESS);
121
122 MaxFileSize.QuadPart = 4096;
123 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
124 PAGE_READWRITE, SEC_COMMIT, Handle);
125 ok_eq_hex(Status, STATUS_SUCCESS);
126
127 Buffer = NULL;
128 FileSize = 0;
129 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
130 &FileSize, ViewUnmap, 0, PAGE_READWRITE);
131 ok_eq_hex(Status, STATUS_SUCCESS);
132
133 KmtStartSeh();
134 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
135 memset(Buffer, 0xBA, 4096);
136 KmtEndSeh(STATUS_SUCCESS);
137
138 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
139 NtClose(SectionHandle);
140 NtClose(Handle);
141
142 /* Test 10 */
143 InitializeObjectAttributes(&ObjectAttributes, &InvalidInit, OBJ_CASE_INSENSITIVE, NULL, NULL);
144 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
145 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
146 ok_eq_hex(Status, STATUS_SUCCESS);
147
148 MaxFileSize.QuadPart = 512;
149 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
150 PAGE_READWRITE, SEC_COMMIT, Handle);
151 ok_eq_hex(Status, STATUS_INVALID_FILE_FOR_SECTION);
152 NtClose(Handle);
153
154 /* Test 11 */
155 InitializeObjectAttributes(&ObjectAttributes, &InitOnCreate, OBJ_CASE_INSENSITIVE, NULL, NULL);
156 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
157 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
158 ok_eq_hex(Status, STATUS_SUCCESS);
159
160 MaxFileSize.QuadPart = 512;
161 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
162 PAGE_READWRITE, SEC_COMMIT, Handle);
163 ok_eq_hex(Status, STATUS_SUCCESS);
164
165 Buffer = NULL;
166 FileSize = 0;
167 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
168 &FileSize, ViewUnmap, 0, PAGE_READWRITE);
169 ok_eq_hex(Status, STATUS_SUCCESS);
170
171 KmtStartSeh();
172 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
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 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
199 memset(Buffer, 0xBA, 4096);
200 KmtEndSeh(STATUS_SUCCESS);
201
202 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
203 NtClose(SectionHandle);
204 NtClose(Handle);
205
206 /* Test 13 */
207 InitializeObjectAttributes(&ObjectAttributes, &InitOnRW, OBJ_CASE_INSENSITIVE, NULL, NULL);
208 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
209 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
210 ok_eq_hex(Status, STATUS_SUCCESS);
211
212 MaxFileSize.QuadPart = 512;
213 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
214 PAGE_READWRITE, SEC_COMMIT, Handle);
215 ok_eq_hex(Status, STATUS_SUCCESS);
216
217 Buffer = NULL;
218 FileSize = 0;
219 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
220 &FileSize, ViewUnmap, 0, PAGE_READWRITE);
221 ok_eq_hex(Status, STATUS_SUCCESS);
222
223 KmtStartSeh();
224 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
225 memset(Buffer, 0xBA, 512);
226 KmtEndSeh(STATUS_SUCCESS);
227
228 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
229 NtClose(SectionHandle);
230 NtClose(Handle);
231
232 /* Test 14 */
233 InitializeObjectAttributes(&ObjectAttributes, &InitOnRW, OBJ_CASE_INSENSITIVE, NULL, NULL);
234 Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
235 NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
236 ok_eq_hex(Status, STATUS_SUCCESS);
237
238 MaxFileSize.QuadPart = 4096;
239 Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
240 PAGE_READWRITE, SEC_COMMIT, Handle);
241 ok_eq_hex(Status, STATUS_SUCCESS);
242
243 Buffer = NULL;
244 FileSize = 0;
245 Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
246 &FileSize, ViewUnmap, 0, PAGE_READWRITE);
247 ok_eq_hex(Status, STATUS_SUCCESS);
248
249 KmtStartSeh();
250 ok(((PCHAR)Buffer)[0] == 0, "First byte is not null! %x\n", ((PCHAR)Buffer)[0]);
251 memset(Buffer, 0xBA, 4096);
252 KmtEndSeh(STATUS_SUCCESS);
253
254 NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
255 NtClose(SectionHandle);
256 NtClose(Handle);
257
258 KmtCloseDriver();
259 KmtUnloadDriver();
260 }