reactos/rostests/kmtests/ntos_mm/NtCreateSection_user.c

258 lines
10 KiB
C
Raw Normal View History

/*
* 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");
if (skip(0, "ROSTESTS-248: skipping kmtest:NtCreateSection because it hangs on testbot\n"))
{
return;
}
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();
}