2016-11-10 21:02:48 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS kernel-mode tests
|
|
|
|
* LICENSE: GPLv2+ - See COPYING in the top level directory
|
|
|
|
* PURPOSE: Kernel-Mode Test Suite NtCreateSection test user-mode part
|
|
|
|
* PROGRAMMER: Pierre Schweitzer <pierre@reactos.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kmt_test.h>
|
|
|
|
|
|
|
|
START_TEST(NtCreateSection)
|
|
|
|
{
|
|
|
|
PVOID Buffer;
|
|
|
|
ULONG FileSize;
|
|
|
|
NTSTATUS Status;
|
|
|
|
LARGE_INTEGER MaxFileSize;
|
|
|
|
HANDLE Handle, SectionHandle;
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING InitOnCreate = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-NtCreateSection\\InitOnCreate");
|
|
|
|
UNICODE_STRING InitOnRW = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-NtCreateSection\\InitOnRW");
|
|
|
|
UNICODE_STRING InvalidInit = RTL_CONSTANT_STRING(L"\\Device\\Kmtest-NtCreateSection\\InvalidInit");
|
|
|
|
|
2016-11-13 16:42:16 +00:00
|
|
|
if (skip(0, "ROSTESTS-248: skipping kmtest:NtCreateSection because it hangs on testbot\n"))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-10 21:02:48 +00:00
|
|
|
KmtLoadDriver(L"NtCreateSection", FALSE);
|
|
|
|
KmtOpenDriver();
|
|
|
|
|
|
|
|
/* Test 0 */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes, &InvalidInit, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
|
|
|
|
NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
MaxFileSize.QuadPart = 512;
|
|
|
|
Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
|
|
|
|
PAGE_READWRITE, SEC_COMMIT, Handle);
|
|
|
|
ok_eq_hex(Status, STATUS_INVALID_FILE_FOR_SECTION);
|
|
|
|
NtClose(Handle);
|
|
|
|
|
|
|
|
/* Test 1 */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes, &InitOnCreate, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
|
|
|
|
NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
MaxFileSize.QuadPart = 512;
|
|
|
|
Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
|
|
|
|
PAGE_READWRITE, SEC_COMMIT, Handle);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
Buffer = NULL;
|
|
|
|
FileSize = 0;
|
|
|
|
Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
|
|
|
|
&FileSize, ViewUnmap, 0, PAGE_READWRITE);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
KmtStartSeh();
|
|
|
|
memset(Buffer, 0xBA, 512);
|
|
|
|
KmtEndSeh(STATUS_SUCCESS);
|
|
|
|
|
|
|
|
NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
|
|
|
|
NtClose(SectionHandle);
|
|
|
|
NtClose(Handle);
|
|
|
|
|
|
|
|
/* Test 2 */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes, &InitOnCreate, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
|
|
|
|
NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
MaxFileSize.QuadPart = 4096;
|
|
|
|
Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
|
|
|
|
PAGE_READWRITE, SEC_COMMIT, Handle);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
Buffer = NULL;
|
|
|
|
FileSize = 0;
|
|
|
|
Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
|
|
|
|
&FileSize, ViewUnmap, 0, PAGE_READWRITE);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
KmtStartSeh();
|
|
|
|
memset(Buffer, 0xBA, 4096);
|
|
|
|
KmtEndSeh(STATUS_SUCCESS);
|
|
|
|
|
|
|
|
NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
|
|
|
|
NtClose(SectionHandle);
|
|
|
|
NtClose(Handle);
|
|
|
|
|
|
|
|
/* Test 3 */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes, &InitOnRW, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
|
|
|
|
NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
MaxFileSize.QuadPart = 512;
|
|
|
|
Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
|
|
|
|
PAGE_READWRITE, SEC_COMMIT, Handle);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
Buffer = NULL;
|
|
|
|
FileSize = 0;
|
|
|
|
Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
|
|
|
|
&FileSize, ViewUnmap, 0, PAGE_READWRITE);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
KmtStartSeh();
|
|
|
|
memset(Buffer, 0xBA, 512);
|
|
|
|
KmtEndSeh(STATUS_SUCCESS);
|
|
|
|
|
|
|
|
NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
|
|
|
|
NtClose(SectionHandle);
|
|
|
|
NtClose(Handle);
|
|
|
|
|
|
|
|
/* Test 4 */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes, &InitOnRW, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
|
|
|
|
NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_CREATE, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
MaxFileSize.QuadPart = 4096;
|
|
|
|
Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
|
|
|
|
PAGE_READWRITE, SEC_COMMIT, Handle);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
Buffer = NULL;
|
|
|
|
FileSize = 0;
|
|
|
|
Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
|
|
|
|
&FileSize, ViewUnmap, 0, PAGE_READWRITE);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
KmtStartSeh();
|
|
|
|
memset(Buffer, 0xBA, 4096);
|
|
|
|
KmtEndSeh(STATUS_SUCCESS);
|
|
|
|
|
|
|
|
NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
|
|
|
|
NtClose(SectionHandle);
|
|
|
|
NtClose(Handle);
|
|
|
|
|
|
|
|
/* Test 10 */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes, &InvalidInit, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
|
|
|
|
NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
MaxFileSize.QuadPart = 512;
|
|
|
|
Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
|
|
|
|
PAGE_READWRITE, SEC_COMMIT, Handle);
|
|
|
|
ok_eq_hex(Status, STATUS_INVALID_FILE_FOR_SECTION);
|
|
|
|
NtClose(Handle);
|
|
|
|
|
|
|
|
/* Test 11 */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes, &InitOnCreate, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
|
|
|
|
NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
MaxFileSize.QuadPart = 512;
|
|
|
|
Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
|
|
|
|
PAGE_READWRITE, SEC_COMMIT, Handle);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
Buffer = NULL;
|
|
|
|
FileSize = 0;
|
|
|
|
Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
|
|
|
|
&FileSize, ViewUnmap, 0, PAGE_READWRITE);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
KmtStartSeh();
|
|
|
|
memset(Buffer, 0xBA, 512);
|
|
|
|
KmtEndSeh(STATUS_SUCCESS);
|
|
|
|
|
|
|
|
NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
|
|
|
|
NtClose(SectionHandle);
|
|
|
|
NtClose(Handle);
|
|
|
|
|
|
|
|
/* Test 12 */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes, &InitOnCreate, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
|
|
|
|
NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
MaxFileSize.QuadPart = 4096;
|
|
|
|
Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
|
|
|
|
PAGE_READWRITE, SEC_COMMIT, Handle);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
Buffer = NULL;
|
|
|
|
FileSize = 0;
|
|
|
|
Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
|
|
|
|
&FileSize, ViewUnmap, 0, PAGE_READWRITE);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
KmtStartSeh();
|
|
|
|
memset(Buffer, 0xBA, 4096);
|
|
|
|
KmtEndSeh(STATUS_SUCCESS);
|
|
|
|
|
|
|
|
NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
|
|
|
|
NtClose(SectionHandle);
|
|
|
|
NtClose(Handle);
|
|
|
|
|
|
|
|
/* Test 13 */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes, &InitOnRW, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
|
|
|
|
NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
MaxFileSize.QuadPart = 512;
|
|
|
|
Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
|
|
|
|
PAGE_READWRITE, SEC_COMMIT, Handle);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
Buffer = NULL;
|
|
|
|
FileSize = 0;
|
|
|
|
Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
|
|
|
|
&FileSize, ViewUnmap, 0, PAGE_READWRITE);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
KmtStartSeh();
|
|
|
|
memset(Buffer, 0xBA, 512);
|
|
|
|
KmtEndSeh(STATUS_SUCCESS);
|
|
|
|
|
|
|
|
NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
|
|
|
|
NtClose(SectionHandle);
|
|
|
|
NtClose(Handle);
|
|
|
|
|
|
|
|
/* Test 14 */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes, &InitOnRW, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
Status = NtCreateFile(&Handle, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock,
|
|
|
|
NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
MaxFileSize.QuadPart = 4096;
|
|
|
|
Status = NtCreateSection(&SectionHandle, SECTION_ALL_ACCESS, 0, &MaxFileSize,
|
|
|
|
PAGE_READWRITE, SEC_COMMIT, Handle);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
Buffer = NULL;
|
|
|
|
FileSize = 0;
|
|
|
|
Status = NtMapViewOfSection(SectionHandle, NtCurrentProcess(), &Buffer, 0, 0, 0,
|
|
|
|
&FileSize, ViewUnmap, 0, PAGE_READWRITE);
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
|
|
|
|
KmtStartSeh();
|
|
|
|
memset(Buffer, 0xBA, 4096);
|
|
|
|
KmtEndSeh(STATUS_SUCCESS);
|
|
|
|
|
|
|
|
NtUnmapViewOfSection(NtCurrentProcess(), Buffer);
|
|
|
|
NtClose(SectionHandle);
|
|
|
|
NtClose(Handle);
|
|
|
|
|
|
|
|
KmtCloseDriver();
|
|
|
|
KmtUnloadDriver();
|
|
|
|
}
|