* PROJECT: ReactOS kernel-mode tests
* LICENSE: GPLv2+ - See COPYING in the top level directory
* PURPOSE: Kernel-Mode Test Suite Section Object test
- * PROGRAMMER: Thomas Faber <thfabba@gmx.de>
+ * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
*/
#include <kmt_test.h>
-#define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
-#define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok_eq_hex(ExceptionStatus, ExpectedStatus)
-
#define CheckObject(Handle, Pointers, Handles) do \
{ \
PUBLIC_OBJECT_BASIC_INFORMATION ObjectInfo; \
IN PFILE_OBJECT FileObject2)
{
NTSTATUS Status = STATUS_SUCCESS;
- NTSTATUS ExceptionStatus;
- const PVOID InvalidPointer = (PVOID)0x5555555555555555ULL;
PVOID SectionObject;
LARGE_INTEGER MaximumSize;
ULONG PointerCount1, PointerCount2;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(NULL, 0, NULL, NULL, 0, SEC_RESERVE, NULL, NULL);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PAGE_PROTECTION);
if (!KmtIsCheckedBuild)
{
/* PAGE_NOACCESS and missing SEC_RESERVE/SEC_COMMIT/SEC_IMAGE assert */
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_NOACCESS, SEC_RESERVE, NULL, NULL);
- EndSeh(STATUS_ACCESS_VIOLATION);
+ KmtEndSeh(STATUS_ACCESS_VIOLATION);
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_NOACCESS, 0, NULL, NULL);
- EndSeh(STATUS_ACCESS_VIOLATION);
+ KmtEndSeh(STATUS_ACCESS_VIOLATION);
}
- SectionObject = InvalidPointer;
- StartSeh()
+ SectionObject = KmtInvalidPointer;
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, NULL, 0, SEC_RESERVE, NULL, NULL);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PAGE_PROTECTION);
- ok_eq_pointer(SectionObject, InvalidPointer);
+ ok_eq_pointer(SectionObject, KmtInvalidPointer);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
- EndSeh(STATUS_ACCESS_VIOLATION);
+ KmtEndSeh(STATUS_ACCESS_VIOLATION);
- SectionObject = InvalidPointer;
- StartSeh()
+ SectionObject = KmtInvalidPointer;
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, NULL, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
- EndSeh(STATUS_ACCESS_VIOLATION);
- ok_eq_pointer(SectionObject, InvalidPointer);
+ KmtEndSeh(STATUS_ACCESS_VIOLATION);
+ ok_eq_pointer(SectionObject, KmtInvalidPointer);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
- SectionObject = InvalidPointer;
+ SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 0;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, NULL);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_FILE_FOR_SECTION);
ok_eq_longlong(MaximumSize.QuadPart, 0LL);
- ok_eq_pointer(SectionObject, InvalidPointer);
+ ok_eq_pointer(SectionObject, KmtInvalidPointer);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
MaximumSize.QuadPart = 0;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(NULL, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_4);
ok_eq_longlong(MaximumSize.QuadPart, 0LL);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
MaximumSize.QuadPart = 1;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(NULL, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
- EndSeh(STATUS_ACCESS_VIOLATION);
+ KmtEndSeh(STATUS_ACCESS_VIOLATION);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
- SectionObject = InvalidPointer;
+ SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 0;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_4);
ok_eq_longlong(MaximumSize.QuadPart, 0LL);
- ok_eq_pointer(SectionObject, InvalidPointer);
+ ok_eq_pointer(SectionObject, KmtInvalidPointer);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
/* page file section */
- SectionObject = InvalidPointer;
+ SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
- ok(SectionObject != InvalidPointer, "Section object pointer untouched\n");
+ ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
if (!skip(FileHandle1 != NULL && FileObject1 != NULL &&
PointerCount2 = 3;
/* image section */
CheckObject(FileHandle2, PointerCount2, 1L);
- SectionObject = InvalidPointer;
+ SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, NULL);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
- ok(SectionObject != InvalidPointer, "Section object pointer untouched\n");
+ ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, SEC_IMAGE);
TestMapView(SectionObject, FALSE, TRUE);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
CheckObject(FileHandle2, PointerCount2, 1L);
- SectionObject = InvalidPointer;
+ SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, FileObject2);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
- ok(SectionObject != InvalidPointer, "Section object pointer untouched\n");
+ ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
++PointerCount2;
CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, TRUE);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
//--PointerCount2; // ????
CheckObject(FileHandle2, PointerCount2, 1L);
- SectionObject = InvalidPointer;
+ SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject2);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
- ok(SectionObject != InvalidPointer, "Section object pointer untouched\n");
+ ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, TRUE);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
/* image section with inappropriate file */
CheckObject(FileHandle1, PointerCount1, 1L);
- SectionObject = InvalidPointer;
+ SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, NULL);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_IMAGE_NOT_MZ);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
- ok_eq_pointer(SectionObject, InvalidPointer);
+ ok_eq_pointer(SectionObject, KmtInvalidPointer);
CheckObject(FileHandle1, PointerCount1, 1L);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
CheckObject(FileHandle1, PointerCount1, 1L);
- SectionObject = InvalidPointer;
+ SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, FileObject1);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
- ok(SectionObject != InvalidPointer, "Section object pointer untouched\n");
+ ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
++PointerCount1;
CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
//--PointerCount1; // ????
CheckObject(FileHandle1, PointerCount1, 1L);
- SectionObject = InvalidPointer;
+ SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject1);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
- ok(SectionObject != InvalidPointer, "Section object pointer untouched\n");
+ ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
/* image section with two different files */
CheckObject(FileHandle1, PointerCount1, 1L);
- SectionObject = InvalidPointer;
+ SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject2);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
- ok(SectionObject != InvalidPointer, "Section object pointer untouched\n");
+ ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle1, PointerCount1, 1L);
CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, TRUE);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
CheckObject(FileHandle1, PointerCount1, 1L);
- SectionObject = InvalidPointer;
+ SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject1);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
- ok(SectionObject != InvalidPointer, "Section object pointer untouched\n");
+ ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle1, PointerCount1, 1L);
CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
/* data file section */
CheckObject(FileHandle1, PointerCount1, 1L);
- SectionObject = InvalidPointer;
+ SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, FileHandle1, NULL);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
- ok(SectionObject != InvalidPointer, "Section object pointer untouched\n");
+ ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
CheckObject(FileHandle1, PointerCount1, 1L);
- SectionObject = InvalidPointer;
+ SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, FileObject1);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
- ok(SectionObject != InvalidPointer, "Section object pointer untouched\n");
+ ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
CheckObject(FileHandle1, PointerCount1, 1L);
- SectionObject = InvalidPointer;
+ SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
- StartSeh()
+ KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, FileHandle1, FileObject1);
- EndSeh(STATUS_SUCCESS);
+ KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
- ok(SectionObject != InvalidPointer, "Section object pointer untouched\n");
+ ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE);
- if (SectionObject && SectionObject != InvalidPointer)
+ if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
CheckObject(FileHandle1, PointerCount1, 1L);
}
}
+static
+VOID
+TestPhysicalMemorySection(VOID)
+{
+ NTSTATUS Status;
+ UNICODE_STRING SectionName = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ HANDLE SectionHandle;
+ PVOID SectionObject;
+ PUCHAR MyPage;
+ PHYSICAL_ADDRESS MyPagePhysical;
+ PUCHAR ZeroPageContents;
+ PHYSICAL_ADDRESS ZeroPagePhysical;
+ PVOID Mapping;
+ PUCHAR MappingBytes;
+ SIZE_T ViewSize;
+ SIZE_T EqualBytes;
+
+ MyPage = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, 'MPmK');
+ if (skip(MyPage != NULL, "Out of memory\n"))
+ return;
+ MyPagePhysical = MmGetPhysicalAddress(MyPage);
+ RtlFillMemory(MyPage + 0 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0x23);
+ RtlFillMemory(MyPage + 1 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0x67);
+ RtlFillMemory(MyPage + 2 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0xab);
+ RtlFillMemory(MyPage + 3 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0xef);
+
+ ZeroPageContents = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, 'ZPmK');
+ if (skip(ZeroPageContents != NULL, "Out of memory\n"))
+ {
+ ExFreePoolWithTag(MyPage, 'MPmK');
+ return;
+ }
+ ZeroPagePhysical.QuadPart = 0;
+
+ Mapping = MmMapIoSpace(ZeroPagePhysical, PAGE_SIZE, MmCached);
+ if (skip(Mapping != NULL, "Failed to map zero page\n"))
+ {
+ ExFreePoolWithTag(ZeroPageContents, 'ZPmK');
+ ExFreePoolWithTag(MyPage, 'MPmK');
+ return;
+ }
+
+ RtlCopyMemory(ZeroPageContents, Mapping, PAGE_SIZE);
+ MmUnmapIoSpace(Mapping, PAGE_SIZE);
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &SectionName,
+ OBJ_KERNEL_HANDLE,
+ NULL,
+ NULL);
+ Status = ZwOpenSection(&SectionHandle, SECTION_ALL_ACCESS, &ObjectAttributes);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ if (!skip(NT_SUCCESS(Status), "No section\n"))
+ {
+ /* Map zero page and compare */
+ Mapping = NULL;
+ ViewSize = PAGE_SIZE;
+ Status = ZwMapViewOfSection(SectionHandle,
+ ZwCurrentProcess(),
+ &Mapping,
+ 0,
+ 0,
+ &ZeroPagePhysical,
+ &ViewSize,
+ ViewUnmap,
+ 0,
+ PAGE_READWRITE);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ if (!skip(NT_SUCCESS(Status), "No view\n"))
+ {
+ EqualBytes = RtlCompareMemory(Mapping,
+ ZeroPageContents,
+ PAGE_SIZE);
+ ok_eq_size(EqualBytes, PAGE_SIZE);
+ Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ }
+
+ /* Map the zero page non-cached */
+ Mapping = NULL;
+ ViewSize = PAGE_SIZE;
+ Status = ZwMapViewOfSection(SectionHandle,
+ ZwCurrentProcess(),
+ &Mapping,
+ 0,
+ 0,
+ &ZeroPagePhysical,
+ &ViewSize,
+ ViewUnmap,
+ 0,
+ PAGE_READWRITE | PAGE_NOCACHE);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ if (!skip(NT_SUCCESS(Status), "No view\n"))
+ {
+ EqualBytes = RtlCompareMemory(Mapping,
+ ZeroPageContents,
+ PAGE_SIZE);
+ ok_eq_size(EqualBytes, PAGE_SIZE);
+ Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ }
+
+ /* Map our NP page, compare, and check that modifications are reflected */
+ Mapping = NULL;
+ ViewSize = PAGE_SIZE;
+ Status = ZwMapViewOfSection(SectionHandle,
+ ZwCurrentProcess(),
+ &Mapping,
+ 0,
+ 0,
+ &MyPagePhysical,
+ &ViewSize,
+ ViewUnmap,
+ 0,
+ PAGE_READWRITE);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ if (!skip(NT_SUCCESS(Status), "No view\n"))
+ {
+ EqualBytes = RtlCompareMemory(Mapping,
+ MyPage,
+ PAGE_SIZE);
+ ok_eq_size(EqualBytes, PAGE_SIZE);
+
+ MappingBytes = Mapping;
+ ok(MappingBytes[5] == 0x23, "Mapping[5] = 0x%x\n", MappingBytes[5]);
+ ok(MyPage[5] == 0x23, "MyPage[5] = 0x%x\n", MyPage[5]);
+
+ MyPage[5] = 0x44;
+ ok(MappingBytes[5] == 0x44, "Mapping[5] = 0x%x\n", MappingBytes[5]);
+ ok(MyPage[5] == 0x44, "MyPage[5] = 0x%x\n", MyPage[5]);
+
+ MappingBytes[5] = 0x88;
+ ok(MappingBytes[5] == 0x88, "Mapping[5] = 0x%x\n", MappingBytes[5]);
+ ok(MyPage[5] == 0x88, "MyPage[5] = 0x%x\n", MyPage[5]);
+
+ Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ }
+
+ Status = ZwClose(SectionHandle);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ }
+
+ /* Try flag 0x80000000, which ROS calls SEC_PHYSICALMEMORY */
+ InitializeObjectAttributes(&ObjectAttributes,
+ NULL,
+ OBJ_KERNEL_HANDLE,
+ NULL,
+ NULL);
+ Status = ZwCreateSection(&SectionHandle,
+ SECTION_ALL_ACCESS,
+ &ObjectAttributes,
+ NULL,
+ PAGE_READWRITE,
+ 0x80000000,
+ NULL);
+ ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
+ if (NT_SUCCESS(Status))
+ ZwClose(SectionHandle);
+
+ /* Assertion failure: AllocationAttributes & SEC_IMAGE | SEC_RESERVE | SEC_COMMIT */
+ if (!KmtIsCheckedBuild)
+ {
+ InitializeObjectAttributes(&ObjectAttributes,
+ NULL,
+ OBJ_KERNEL_HANDLE,
+ NULL,
+ NULL);
+ Status = MmCreateSection(&SectionObject,
+ SECTION_ALL_ACCESS,
+ &ObjectAttributes,
+ NULL,
+ PAGE_READWRITE,
+ 0x80000000,
+ NULL,
+ NULL);
+ ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
+ if (NT_SUCCESS(Status))
+ ObDereferenceObject(SectionObject);
+ }
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ NULL,
+ OBJ_KERNEL_HANDLE,
+ NULL,
+ NULL);
+ Status = MmCreateSection(&SectionObject,
+ SECTION_ALL_ACCESS,
+ &ObjectAttributes,
+ NULL,
+ PAGE_READWRITE,
+ SEC_RESERVE | 0x80000000,
+ NULL,
+ NULL);
+ ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
+ if (NT_SUCCESS(Status))
+ ObDereferenceObject(SectionObject);
+
+ ExFreePoolWithTag(ZeroPageContents, 'ZPmK');
+ ExFreePoolWithTag(MyPage, 'MPmK');
+}
+
START_TEST(MmSection)
{
NTSTATUS Status;
if (!skip(Status == STATUS_SUCCESS && FileHandle1 != NULL, "Failed to open file 1\n"))
{
- Status = ObReferenceObjectByHandle(FileHandle1, FILE_READ_DATA | FILE_WRITE_DATA, IoFileObjectType, KernelMode, (PVOID *)&FileObject1, NULL);
+ Status = ObReferenceObjectByHandle(FileHandle1, FILE_READ_DATA | FILE_WRITE_DATA, *IoFileObjectType, KernelMode, (PVOID *)&FileObject1, NULL);
ok_eq_hex(Status, STATUS_SUCCESS);
ok(FileObject1 != NULL, "FileObject1 is NULL\n");
CheckObject(FileHandle1, 3L, 1L);
if (!skip(Status == STATUS_SUCCESS && FileHandle2 != NULL, "Failed to open file 2\n"))
{
- Status = ObReferenceObjectByHandle(FileHandle2, FILE_READ_DATA | FILE_WRITE_DATA, IoFileObjectType, KernelMode, (PVOID *)&FileObject2, NULL);
+ Status = ObReferenceObjectByHandle(FileHandle2, FILE_READ_DATA | FILE_WRITE_DATA, *IoFileObjectType, KernelMode, (PVOID *)&FileObject2, NULL);
ok_eq_hex(Status, STATUS_SUCCESS);
ok(FileObject2 != NULL, "FileObject2 is NULL\n");
}
ZwClose(FileHandle2);
if (FileHandle1)
ZwClose(FileHandle1);
+
+ TestPhysicalMemorySection();
}