10#define CheckObject(Handle, Pointers, Handles) do \
12 PUBLIC_OBJECT_BASIC_INFORMATION ObjectInfo; \
13 Status = ZwQueryObject(Handle, ObjectBasicInformation, \
14 &ObjectInfo, sizeof ObjectInfo, NULL); \
15 ok_eq_hex(Status, STATUS_SUCCESS); \
16 ok_eq_ulong(ObjectInfo.PointerCount, Pointers); \
17 ok_eq_ulong(ObjectInfo.HandleCount, Handles); \
20#define CheckSection(SectionObject, SectionFlag) do \
22 SECTION_BASIC_INFORMATION Sbi; \
23 HANDLE SectionHandle = NULL; \
25 if (skip(SectionObject != NULL && \
26 SectionObject != (PVOID)0x5555555555555555ULL, \
27 "No section object\n")) \
29 Status = ObOpenObjectByPointer(SectionObject, OBJ_KERNEL_HANDLE, \
30 NULL, 0, MmSectionObjectType, \
31 KernelMode, &SectionHandle); \
32 ok_eq_hex(Status, STATUS_SUCCESS); \
33 ok(SectionHandle != NULL, "Section handle null\n"); \
34 if (!skip(NT_SUCCESS(Status) && SectionHandle, \
35 "No section handle\n")) \
37 Status = ZwQuerySection(SectionHandle, SectionBasicInformation, \
38 &Sbi, sizeof Sbi, NULL); \
39 ok_eq_hex(Status, STATUS_SUCCESS); \
40 ok_eq_pointer(Sbi.BaseAddress, NULL); \
41 ok_eq_longlong(Sbi.Size.QuadPart, 1LL); \
42 ok_eq_hex(Sbi.Attributes, SectionFlag | SEC_FILE); \
43 ZwClose(SectionHandle); \
47#define TestMapView(SectionObject, ExpectAtBase, ExpectM) do \
50 PVOID BaseAddress = NULL; \
51 SIZE_T ViewSize = 0; \
52 LARGE_INTEGER SectionOffset; \
53 if (skip(SectionObject != NULL && \
54 SectionObject != (PVOID)0x5555555555555555ULL, \
55 "No section object\n")) \
58 SectionOffset.QuadPart = 0; \
59 Status = MmMapViewOfSection(SectionObject, PsGetCurrentProcess(), \
60 &BaseAddress, 0, 1, &SectionOffset, \
61 &ViewSize, ViewUnmap, 0, PAGE_READONLY); \
62 ok_eq_hex(Status, ExpectAtBase ? STATUS_SUCCESS : STATUS_IMAGE_NOT_AT_BASE);\
63 if (!skip(NT_SUCCESS(Status), "Section not mapped\n")) \
65 ok((LONG_PTR)BaseAddress > 0, "BaseAddress = %p\n", BaseAddress); \
66 ok_eq_uint(*(PUCHAR)BaseAddress, ExpectM ? 'M' : 0); \
67 Status = MmUnmapViewOfSection(PsGetCurrentProcess(), BaseAddress); \
68 ok_eq_hex(Status, STATUS_SUCCESS); \
72 Status = MmMapViewOfSection(SectionObject, PsGetCurrentProcess(), \
73 &BaseAddress, 0, 1, &SectionOffset, \
74 &ViewSize, ViewUnmap, 0, \
75 PAGE_READONLY | PAGE_NOCACHE); \
76 ok_eq_hex(Status, ExpectAtBase ? STATUS_SUCCESS : STATUS_IMAGE_NOT_AT_BASE);\
77 if (!skip(NT_SUCCESS(Status), "Section not mapped\n")) \
79 ok((LONG_PTR)BaseAddress > 0, "BaseAddress = %p\n", BaseAddress); \
80 ok_eq_uint(*(PUCHAR)BaseAddress, ExpectM ? 'M' : 0); \
81 Status = MmUnmapViewOfSection(PsGetCurrentProcess(), BaseAddress); \
82 ok_eq_hex(Status, STATUS_SUCCESS); \
97 ULONG PointerCount1, PointerCount2;
197 FileHandle2 !=
NULL && FileObject2 !=
NULL,
"No file handle or object\n"))
428 if (
skip(MyPage !=
NULL,
"Out of memory\n"))
437 if (
skip(ZeroPageContents !=
NULL,
"Out of memory\n"))
467 Status = ZwMapViewOfSection(SectionHandle,
492 Status = ZwMapViewOfSection(SectionHandle,
517 Status = ZwMapViewOfSection(SectionHandle,
537 ok(MappingBytes[5] == 0x23,
"Mapping[5] = 0x%x\n", MappingBytes[5]);
538 ok(MyPage[5] == 0x23,
"MyPage[5] = 0x%x\n", MyPage[5]);
541 ok(MappingBytes[5] == 0x44,
"Mapping[5] = 0x%x\n", MappingBytes[5]);
542 ok(MyPage[5] == 0x44,
"MyPage[5] = 0x%x\n", MyPage[5]);
544 MappingBytes[5] = 0x88;
545 ok(MappingBytes[5] == 0x88,
"Mapping[5] = 0x%x\n", MappingBytes[5]);
546 ok(MyPage[5] == 0x88,
"MyPage[5] = 0x%x\n", MyPage[5]);
556 Status = ZwMapViewOfSection(SectionHandle,
594 UserStruct = UserMem;
608 Status = ZwMapViewOfSection(SectionHandle,
623 if (!
skip(UserStruct !=
NULL,
"No user memory\n"))
626 UserStruct->Mapping =
NULL;
633 &UserStruct->Mapping,
636 &UserStruct->PhysicalAddress,
637 &UserStruct->ViewSize,
654 Status = ZwMapViewOfSection(SectionHandle,
669 if (!
skip(UserStruct !=
NULL,
"No user memory\n"))
672 UserStruct->Mapping =
NULL;
679 &UserStruct->Mapping,
682 &UserStruct->PhysicalAddress,
683 &UserStruct->ViewSize,
700 Status = ZwMapViewOfSection(SectionHandle,
715 if (!
skip(UserStruct !=
NULL,
"No user memory\n"))
718 UserStruct->Mapping =
NULL;
725 &UserStruct->Mapping,
728 &UserStruct->PhysicalAddress,
729 &UserStruct->ViewSize,
743 if (!
skip(UserStruct !=
NULL,
"No user memory\n"))
763 Status = ZwCreateSection(&SectionHandle,
831 Status = ZwCreateFile(&FileHandle1,
GENERIC_WRITE |
SYNCHRONIZE, &
ObjectAttributes, &
IoStatusBlock,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ,
FILE_SUPERSEDE,
FILE_NON_DIRECTORY_FILE,
NULL, 0);
834 ok(FileHandle1 !=
NULL,
"FileHandle1 is NULL\n");
849 Status = ZwCreateFile(&FileHandle1,
GENERIC_ALL, &
ObjectAttributes, &
IoStatusBlock,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ,
FILE_OPEN,
FILE_NON_DIRECTORY_FILE |
FILE_DELETE_ON_CLOSE,
NULL, 0);
852 ok(FileHandle1 !=
NULL,
"FileHandle1 is NULL\n");
856 Status = ZwCreateFile(&FileHandle2,
GENERIC_READ, &
ObjectAttributes, &
IoStatusBlock,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ,
FILE_OPEN,
FILE_NON_DIRECTORY_FILE,
NULL, 0);
859 ok(FileHandle2 !=
NULL,
"FileHandle2 is NULL\n");
865 ok(FileObject1 !=
NULL,
"FileObject1 is NULL\n");
873 ok(FileObject2 !=
NULL,
"FileObject2 is NULL\n");
876 trace(
"FileHandle1=%p, FileObject1=%p\n", FileHandle1, FileObject1);
877 trace(
"FileHandle2=%p, FileObject2=%p\n", FileHandle2, FileObject2);
NTSTATUS NTAPI NtMapViewOfSection(IN HANDLE SectionHandle, IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
static VOID TestCreateSection(IN HANDLE FileHandle1, IN PFILE_OBJECT FileObject1, IN HANDLE FileHandle2, IN PFILE_OBJECT FileObject2)
#define TestMapView(SectionObject, ExpectAtBase, ExpectM)
static VOID TestPhysicalMemorySection(VOID)
#define CheckObject(Handle, Pointers, Handles)
#define CheckSection(SectionObject, SectionFlag)
#define ok_eq_hex(value, expected)
static const WCHAR FileName2[]
#define ok_eq_pointer(value, expected)
#define ok_eq_ulong(value, expected)
#define FILE_NON_DIRECTORY_FILE
#define FILE_DELETE_ON_CLOSE
static FILEDATA FileData[MAX_FDS]
_In_ PFCB _In_ LONGLONG FileOffset
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
#define NT_SUCCESS(StatCode)
#define FILE_ATTRIBUTE_NORMAL
static PVOID Mapping[EMS_PHYSICAL_PAGES]
#define ExAllocatePoolWithTag(hernya, size, tag)
#define RtlCompareMemory(s1, s2, l)
#define ExGetPreviousMode
NTSYSAPI NTSTATUS NTAPI ZwQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
#define OBJ_KERNEL_HANDLE
#define OBJ_CASE_INSENSITIVE
#define RtlFillMemory(Dest, Length, Fill)
POBJECT_TYPE IoFileObjectType
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
#define ok_eq_longlong(value, expected)
#define ok_eq_size(value, expected)
#define ok_eq_ulongptr(value, expected)
#define KmtInvalidPointer
#define KmtEndSeh(ExpectedStatus)
BOOLEAN KmtIsCheckedBuild
#define ExFreePoolWithTag(_P, _T)
static OUT PIO_STATUS_BLOCK IoStatusBlock
#define InitializeObjectAttributes(p, n, a, r, s)
NTSYSAPI NTSTATUS NTAPI ZwOpenSection(_Out_ PHANDLE SectionHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define SECTION_ALL_ACCESS
#define NtCurrentProcess()
PHYSICAL_ADDRESS NTAPI MmGetPhysicalAddress(IN PVOID Address)
#define STATUS_INVALID_PARAMETER_4
#define STATUS_INVALID_IMAGE_NOT_MZ
#define STATUS_INVALID_FILE_FOR_SECTION
#define STATUS_ACCESS_VIOLATION
#define STATUS_INVALID_PARAMETER_6
#define STATUS_INVALID_PAGE_PROTECTION
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
NTSTATUS NTAPI MmCreateSection(OUT PVOID *Section, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize, IN ULONG SectionPageProtection, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL, IN PFILE_OBJECT FileObject OPTIONAL)
#define RTL_CONSTANT_STRING(s)
#define RtlCopyMemory(Destination, Source, Length)
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
#define ObDereferenceObject
#define ZwCurrentProcess()