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>
10 START_TEST(NtCreateSection
)
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");
23 KmtLoadDriver(L
"NtCreateSection", FALSE
);
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
);
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 if (NT_SUCCESS(Status
)) NtClose(SectionHandle
);
37 Status
= NtClose(Handle
);
38 ok_eq_hex(Status
, STATUS_SUCCESS
);
41 InitializeObjectAttributes(&ObjectAttributes
, &InitOnCreate
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
42 Status
= NtCreateFile(&Handle
, GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, &ObjectAttributes
, &IoStatusBlock
,
43 NULL
, FILE_ATTRIBUTE_NORMAL
, 0, FILE_CREATE
, FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0);
44 ok_eq_hex(Status
, STATUS_SUCCESS
);
46 MaxFileSize
.QuadPart
= 512;
47 Status
= NtCreateSection(&SectionHandle
, SECTION_ALL_ACCESS
, 0, &MaxFileSize
,
48 PAGE_READWRITE
, SEC_COMMIT
, Handle
);
49 ok_eq_hex(Status
, STATUS_SUCCESS
);
53 Status
= NtMapViewOfSection(SectionHandle
, NtCurrentProcess(), &Buffer
, 0, 0, 0,
54 &FileSize
, ViewUnmap
, 0, PAGE_READWRITE
);
55 ok_eq_hex(Status
, STATUS_SUCCESS
);
58 ok(((PCHAR
)Buffer
)[0] == 0, "First byte is not null! %x\n", ((PCHAR
)Buffer
)[0]);
59 memset(Buffer
, 0xBA, 512);
60 KmtEndSeh(STATUS_SUCCESS
);
62 Status
= NtUnmapViewOfSection(NtCurrentProcess(), Buffer
);
63 ok_eq_hex(Status
, STATUS_SUCCESS
);
64 Status
= NtClose(SectionHandle
);
65 ok_eq_hex(Status
, STATUS_SUCCESS
);
66 Status
= NtClose(Handle
);
67 ok_eq_hex(Status
, STATUS_SUCCESS
);
70 InitializeObjectAttributes(&ObjectAttributes
, &InitOnCreate
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
71 Status
= NtCreateFile(&Handle
, GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, &ObjectAttributes
, &IoStatusBlock
,
72 NULL
, FILE_ATTRIBUTE_NORMAL
, 0, FILE_CREATE
, FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0);
73 ok_eq_hex(Status
, STATUS_SUCCESS
);
75 MaxFileSize
.QuadPart
= 4096;
76 Status
= NtCreateSection(&SectionHandle
, SECTION_ALL_ACCESS
, 0, &MaxFileSize
,
77 PAGE_READWRITE
, SEC_COMMIT
, Handle
);
78 ok_eq_hex(Status
, STATUS_SUCCESS
);
82 Status
= NtMapViewOfSection(SectionHandle
, NtCurrentProcess(), &Buffer
, 0, 0, 0,
83 &FileSize
, ViewUnmap
, 0, PAGE_READWRITE
);
84 ok_eq_hex(Status
, STATUS_SUCCESS
);
87 ok(((PCHAR
)Buffer
)[0] == 0, "First byte is not null! %x\n", ((PCHAR
)Buffer
)[0]);
88 memset(Buffer
, 0xBA, 4096);
89 KmtEndSeh(STATUS_SUCCESS
);
91 Status
= NtUnmapViewOfSection(NtCurrentProcess(), Buffer
);
92 ok_eq_hex(Status
, STATUS_SUCCESS
);
93 Status
= NtClose(SectionHandle
);
94 ok_eq_hex(Status
, STATUS_SUCCESS
);
95 Status
= NtClose(Handle
);
96 ok_eq_hex(Status
, STATUS_SUCCESS
);
99 InitializeObjectAttributes(&ObjectAttributes
, &InitOnRW
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
100 Status
= NtCreateFile(&Handle
, GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, &ObjectAttributes
, &IoStatusBlock
,
101 NULL
, FILE_ATTRIBUTE_NORMAL
, 0, FILE_CREATE
, FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0);
102 ok_eq_hex(Status
, STATUS_SUCCESS
);
104 MaxFileSize
.QuadPart
= 512;
105 Status
= NtCreateSection(&SectionHandle
, SECTION_ALL_ACCESS
, 0, &MaxFileSize
,
106 PAGE_READWRITE
, SEC_COMMIT
, Handle
);
107 ok_eq_hex(Status
, STATUS_SUCCESS
);
111 Status
= NtMapViewOfSection(SectionHandle
, NtCurrentProcess(), &Buffer
, 0, 0, 0,
112 &FileSize
, ViewUnmap
, 0, PAGE_READWRITE
);
113 ok_eq_hex(Status
, STATUS_SUCCESS
);
116 ok(((PCHAR
)Buffer
)[0] == 0, "First byte is not null! %x\n", ((PCHAR
)Buffer
)[0]);
117 memset(Buffer
, 0xBA, 512);
118 KmtEndSeh(STATUS_SUCCESS
);
120 Status
= NtUnmapViewOfSection(NtCurrentProcess(), Buffer
);
121 ok_eq_hex(Status
, STATUS_SUCCESS
);
122 Status
= NtClose(SectionHandle
);
123 ok_eq_hex(Status
, STATUS_SUCCESS
);
124 Status
= NtClose(Handle
);
125 ok_eq_hex(Status
, STATUS_SUCCESS
);
128 InitializeObjectAttributes(&ObjectAttributes
, &InitOnRW
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
129 Status
= NtCreateFile(&Handle
, GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, &ObjectAttributes
, &IoStatusBlock
,
130 NULL
, FILE_ATTRIBUTE_NORMAL
, 0, FILE_CREATE
, FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0);
131 ok_eq_hex(Status
, STATUS_SUCCESS
);
133 MaxFileSize
.QuadPart
= 4096;
134 Status
= NtCreateSection(&SectionHandle
, SECTION_ALL_ACCESS
, 0, &MaxFileSize
,
135 PAGE_READWRITE
, SEC_COMMIT
, Handle
);
136 ok_eq_hex(Status
, STATUS_SUCCESS
);
140 Status
= NtMapViewOfSection(SectionHandle
, NtCurrentProcess(), &Buffer
, 0, 0, 0,
141 &FileSize
, ViewUnmap
, 0, PAGE_READWRITE
);
142 ok_eq_hex(Status
, STATUS_SUCCESS
);
145 ok(((PCHAR
)Buffer
)[0] == 0, "First byte is not null! %x\n", ((PCHAR
)Buffer
)[0]);
146 memset(Buffer
, 0xBA, 4096);
147 KmtEndSeh(STATUS_SUCCESS
);
149 Status
= NtUnmapViewOfSection(NtCurrentProcess(), Buffer
);
150 ok_eq_hex(Status
, STATUS_SUCCESS
);
151 Status
= NtClose(SectionHandle
);
152 ok_eq_hex(Status
, STATUS_SUCCESS
);
153 Status
= NtClose(Handle
);
154 ok_eq_hex(Status
, STATUS_SUCCESS
);
157 InitializeObjectAttributes(&ObjectAttributes
, &InvalidInit
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
158 Status
= NtCreateFile(&Handle
, GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, &ObjectAttributes
, &IoStatusBlock
,
159 NULL
, FILE_ATTRIBUTE_NORMAL
, 0, FILE_OPEN
, FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0);
160 ok_eq_hex(Status
, STATUS_SUCCESS
);
162 MaxFileSize
.QuadPart
= 512;
163 Status
= NtCreateSection(&SectionHandle
, SECTION_ALL_ACCESS
, 0, &MaxFileSize
,
164 PAGE_READWRITE
, SEC_COMMIT
, Handle
);
165 ok_eq_hex(Status
, STATUS_INVALID_FILE_FOR_SECTION
);
166 if (NT_SUCCESS(Status
)) NtClose(SectionHandle
);
167 Status
= NtClose(Handle
);
168 ok_eq_hex(Status
, STATUS_SUCCESS
);
171 InitializeObjectAttributes(&ObjectAttributes
, &InitOnCreate
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
172 Status
= NtCreateFile(&Handle
, GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, &ObjectAttributes
, &IoStatusBlock
,
173 NULL
, FILE_ATTRIBUTE_NORMAL
, 0, FILE_OPEN
, FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0);
174 ok_eq_hex(Status
, STATUS_SUCCESS
);
176 MaxFileSize
.QuadPart
= 512;
177 Status
= NtCreateSection(&SectionHandle
, SECTION_ALL_ACCESS
, 0, &MaxFileSize
,
178 PAGE_READWRITE
, SEC_COMMIT
, Handle
);
179 ok_eq_hex(Status
, STATUS_SUCCESS
);
183 Status
= NtMapViewOfSection(SectionHandle
, NtCurrentProcess(), &Buffer
, 0, 0, 0,
184 &FileSize
, ViewUnmap
, 0, PAGE_READWRITE
);
185 ok_eq_hex(Status
, STATUS_SUCCESS
);
188 ok(((PCHAR
)Buffer
)[0] == 0, "First byte is not null! %x\n", ((PCHAR
)Buffer
)[0]);
189 memset(Buffer
, 0xBA, 512);
190 KmtEndSeh(STATUS_SUCCESS
);
192 Status
= NtUnmapViewOfSection(NtCurrentProcess(), Buffer
);
193 ok_eq_hex(Status
, STATUS_SUCCESS
);
194 Status
= NtClose(SectionHandle
);
195 ok_eq_hex(Status
, STATUS_SUCCESS
);
196 Status
= NtClose(Handle
);
197 ok_eq_hex(Status
, STATUS_SUCCESS
);
200 InitializeObjectAttributes(&ObjectAttributes
, &InitOnCreate
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
201 Status
= NtCreateFile(&Handle
, GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, &ObjectAttributes
, &IoStatusBlock
,
202 NULL
, FILE_ATTRIBUTE_NORMAL
, 0, FILE_OPEN
, FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0);
203 ok_eq_hex(Status
, STATUS_SUCCESS
);
205 MaxFileSize
.QuadPart
= 4096;
206 Status
= NtCreateSection(&SectionHandle
, SECTION_ALL_ACCESS
, 0, &MaxFileSize
,
207 PAGE_READWRITE
, SEC_COMMIT
, Handle
);
208 ok_eq_hex(Status
, STATUS_SUCCESS
);
212 Status
= NtMapViewOfSection(SectionHandle
, NtCurrentProcess(), &Buffer
, 0, 0, 0,
213 &FileSize
, ViewUnmap
, 0, PAGE_READWRITE
);
214 ok_eq_hex(Status
, STATUS_SUCCESS
);
217 ok(((PCHAR
)Buffer
)[0] == 0, "First byte is not null! %x\n", ((PCHAR
)Buffer
)[0]);
218 memset(Buffer
, 0xBA, 4096);
219 KmtEndSeh(STATUS_SUCCESS
);
221 Status
= NtUnmapViewOfSection(NtCurrentProcess(), Buffer
);
222 ok_eq_hex(Status
, STATUS_SUCCESS
);
223 Status
= NtClose(SectionHandle
);
224 ok_eq_hex(Status
, STATUS_SUCCESS
);
225 Status
= NtClose(Handle
);
226 ok_eq_hex(Status
, STATUS_SUCCESS
);
229 InitializeObjectAttributes(&ObjectAttributes
, &InitOnRW
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
230 Status
= NtCreateFile(&Handle
, GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, &ObjectAttributes
, &IoStatusBlock
,
231 NULL
, FILE_ATTRIBUTE_NORMAL
, 0, FILE_OPEN
, FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0);
232 ok_eq_hex(Status
, STATUS_SUCCESS
);
234 MaxFileSize
.QuadPart
= 512;
235 Status
= NtCreateSection(&SectionHandle
, SECTION_ALL_ACCESS
, 0, &MaxFileSize
,
236 PAGE_READWRITE
, SEC_COMMIT
, Handle
);
237 ok_eq_hex(Status
, STATUS_SUCCESS
);
241 Status
= NtMapViewOfSection(SectionHandle
, NtCurrentProcess(), &Buffer
, 0, 0, 0,
242 &FileSize
, ViewUnmap
, 0, PAGE_READWRITE
);
243 ok_eq_hex(Status
, STATUS_SUCCESS
);
246 ok(((PCHAR
)Buffer
)[0] == 0, "First byte is not null! %x\n", ((PCHAR
)Buffer
)[0]);
247 memset(Buffer
, 0xBA, 512);
248 KmtEndSeh(STATUS_SUCCESS
);
250 Status
= NtUnmapViewOfSection(NtCurrentProcess(), Buffer
);
251 ok_eq_hex(Status
, STATUS_SUCCESS
);
252 Status
= NtClose(SectionHandle
);
253 ok_eq_hex(Status
, STATUS_SUCCESS
);
254 Status
= NtClose(Handle
);
255 ok_eq_hex(Status
, STATUS_SUCCESS
);
258 InitializeObjectAttributes(&ObjectAttributes
, &InitOnRW
, OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
259 Status
= NtCreateFile(&Handle
, GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, &ObjectAttributes
, &IoStatusBlock
,
260 NULL
, FILE_ATTRIBUTE_NORMAL
, 0, FILE_OPEN
, FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0);
261 ok_eq_hex(Status
, STATUS_SUCCESS
);
263 MaxFileSize
.QuadPart
= 4096;
264 Status
= NtCreateSection(&SectionHandle
, SECTION_ALL_ACCESS
, 0, &MaxFileSize
,
265 PAGE_READWRITE
, SEC_COMMIT
, Handle
);
266 ok_eq_hex(Status
, STATUS_SUCCESS
);
270 Status
= NtMapViewOfSection(SectionHandle
, NtCurrentProcess(), &Buffer
, 0, 0, 0,
271 &FileSize
, ViewUnmap
, 0, PAGE_READWRITE
);
272 ok_eq_hex(Status
, STATUS_SUCCESS
);
275 ok(((PCHAR
)Buffer
)[0] == 0, "First byte is not null! %x\n", ((PCHAR
)Buffer
)[0]);
276 memset(Buffer
, 0xBA, 4096);
277 KmtEndSeh(STATUS_SUCCESS
);
279 Status
= NtUnmapViewOfSection(NtCurrentProcess(), Buffer
);
280 ok_eq_hex(Status
, STATUS_SUCCESS
);
281 Status
= NtClose(SectionHandle
);
282 ok_eq_hex(Status
, STATUS_SUCCESS
);
283 Status
= NtClose(Handle
);
284 ok_eq_hex(Status
, STATUS_SUCCESS
);