ok_eq_ulong(ObjectInfo.HandleCount, Handles); \
} while (0)
+#define CheckSection(SectionObject, SectionFlag) do \
+{ \
+ SECTION_BASIC_INFORMATION Sbi; \
+ HANDLE SectionHandle = NULL; \
+ NTSTATUS Status; \
+ if (skip(SectionObject != NULL && \
+ SectionObject != (PVOID)0x5555555555555555ULL, \
+ "blah\n")) \
+ break; \
+ Status = ObOpenObjectByPointer(SectionObject, OBJ_KERNEL_HANDLE, \
+ NULL, 0, MmSectionObjectType, \
+ KernelMode, &SectionHandle); \
+ ok_eq_hex(Status, STATUS_SUCCESS); \
+ ok(SectionHandle != NULL, "Section handle null\n"); \
+ if (!skip(NT_SUCCESS(Status) && SectionHandle, \
+ "No section handle\n")) \
+ { \
+ Status = ZwQuerySection(SectionHandle, SectionBasicInformation, \
+ &Sbi, sizeof Sbi, NULL); \
+ ok_eq_hex(Status, STATUS_SUCCESS); \
+ ok_eq_pointer(Sbi.BaseAddress, NULL); \
+ ok_eq_longlong(Sbi.Size.QuadPart, 1LL); \
+ ok_eq_hex(Sbi.Attributes, SectionFlag | SEC_FILE); \
+ ZwClose(SectionHandle); \
+ } \
+} while (0)
+
+#define TestMapView(SectionObject, ExpectAtBase, ExpectM) do \
+{ \
+ NTSTATUS Status; \
+ PVOID BaseAddress = NULL; \
+ SIZE_T ViewSize = 0; \
+ LARGE_INTEGER SectionOffset; \
+ if (skip(SectionObject != NULL && \
+ SectionObject != (PVOID)0x5555555555555555ULL, \
+ "No section object\n")) \
+ break; \
+ \
+ SectionOffset.QuadPart = 0; \
+ Status = MmMapViewOfSection(SectionObject, PsGetCurrentProcess(), \
+ &BaseAddress, 0, 1, &SectionOffset, \
+ &ViewSize, ViewUnmap, 0, PAGE_READONLY); \
+ ok_eq_hex(Status, ExpectAtBase ? STATUS_SUCCESS : STATUS_IMAGE_NOT_AT_BASE);\
+ if (!skip(NT_SUCCESS(Status), "Section not mapped\n")) \
+ { \
+ ok_eq_uint(*(PUCHAR)BaseAddress, ExpectM ? 'M' : 0); \
+ Status = MmUnmapViewOfSection(PsGetCurrentProcess(), BaseAddress); \
+ ok_eq_hex(Status, STATUS_SUCCESS); \
+ } \
+} while (0)
+
static
VOID
TestCreateSection(
ok(SectionObject != InvalidPointer, "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)
ObDereferenceObject(SectionObject);
ok(SectionObject != NULL, "Section object pointer NULL\n");
++PointerCount2;
CheckObject(FileHandle2, PointerCount2, 1L);
+ CheckSection(SectionObject, 0);
+ TestMapView(SectionObject, TRUE, TRUE);
if (SectionObject && SectionObject != InvalidPointer)
ObDereferenceObject(SectionObject);
ok(SectionObject != InvalidPointer, "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)
ObDereferenceObject(SectionObject);
ok(SectionObject != NULL, "Section object pointer NULL\n");
++PointerCount1;
CheckObject(FileHandle1, PointerCount1, 1L);
+ CheckSection(SectionObject, 0);
+ TestMapView(SectionObject, TRUE, FALSE);
if (SectionObject && SectionObject != InvalidPointer)
ObDereferenceObject(SectionObject);
ok(SectionObject != InvalidPointer, "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)
+ ObDereferenceObject(SectionObject);
+
+ /* image section with two different files */
+ CheckObject(FileHandle1, PointerCount1, 1L);
+ SectionObject = InvalidPointer;
+ MaximumSize.QuadPart = 1;
+ StartSeh()
+ Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject2);
+ EndSeh(STATUS_SUCCESS);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ ok_eq_longlong(MaximumSize.QuadPart, 1LL);
+ ok(SectionObject != InvalidPointer, "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)
+ ObDereferenceObject(SectionObject);
+
+ CheckObject(FileHandle1, PointerCount1, 1L);
+ SectionObject = InvalidPointer;
+ MaximumSize.QuadPart = 1;
+ StartSeh()
+ Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject1);
+ EndSeh(STATUS_SUCCESS);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+ ok_eq_longlong(MaximumSize.QuadPart, 1LL);
+ ok(SectionObject != InvalidPointer, "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)
ObDereferenceObject(SectionObject);
ok(SectionObject != InvalidPointer, "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)
ObDereferenceObject(SectionObject);
ok(SectionObject != InvalidPointer, "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)
ObDereferenceObject(SectionObject);
ok(SectionObject != InvalidPointer, "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)
ObDereferenceObject(SectionObject);
LARGE_INTEGER FileOffset;
UCHAR FileData = 0;
+ ok(ExGetPreviousMode() == UserMode, "Previous mode is kernel mode\n");
/* create a one-byte file that we can use */
InitializeObjectAttributes(&ObjectAttributes, &FileName1, OBJ_CASE_INSENSITIVE, NULL, NULL);
Status = ZwCreateFile(&FileHandle1, GENERIC_ALL, &ObjectAttributes, &IoStatusBlock, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_SUPERSEDE, FILE_NON_DIRECTORY_FILE, NULL, 0);