ReactOS 0.4.16-dev-2110-ge3521eb
MmSection.c File Reference
#include <kmt_test.h>
Include dependency graph for MmSection.c:

Go to the source code of this file.

Macros

#define CheckObject(Handle, Pointers, Handles)
 
#define CheckSection(SectionObject, SectionFlag)   CheckSection_(__LINE__, SectionObject, SectionFlag)
 
#define TestMapView(SectionObject, ExpectAtBase, ExpectM)
 

Functions

static void CheckSection_ (ULONG Line, PVOID SectionObject, ULONG SectionFlag)
 
static VOID TestCreateSection (IN HANDLE FileHandle1, IN PFILE_OBJECT FileObject1, IN HANDLE FileHandle2, IN PFILE_OBJECT FileObject2)
 
static VOID TestPhysicalMemorySection (VOID)
 
 START_TEST (MmSection)
 

Macro Definition Documentation

◆ CheckObject

#define CheckObject (   Handle,
  Pointers,
  Handles 
)
Value:
do \
{ \
Status = ZwQueryObject(Handle, ObjectBasicInformation, \
&ObjectInfo, sizeof ObjectInfo, NULL); \
ok_eq_hex(Status, STATUS_SUCCESS); \
ok_eq_ulong(ObjectInfo.PointerCount, Pointers); \
ok_eq_ulong(ObjectInfo.HandleCount, Handles); \
} while (0)
@ ObjectBasicInformation
Definition: DriverTester.h:54
#define NULL
Definition: types.h:112
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
#define STATUS_SUCCESS
Definition: shellext.h:65

Definition at line 10 of file MmSection.c.

◆ CheckSection

#define CheckSection (   SectionObject,
  SectionFlag 
)    CheckSection_(__LINE__, SectionObject, SectionFlag)

Definition at line 50 of file MmSection.c.

◆ TestMapView

#define TestMapView (   SectionObject,
  ExpectAtBase,
  ExpectM 
)

Definition at line 52 of file MmSection.c.

Function Documentation

◆ CheckSection_()

static void CheckSection_ ( ULONG  Line,
PVOID  SectionObject,
ULONG  SectionFlag 
)
static

Definition at line 22 of file MmSection.c.

23{
25 HANDLE SectionHandle = NULL;
27
28 if (skip(SectionObject != NULL &&
29 SectionObject != (PVOID)0x5555555555555555ULL,
30 "No section object\n"))
31 return;
32
35 KernelMode, &SectionHandle);
36 ok(Status == STATUS_SUCCESS, "Line %lu: Status = 0x%lx, expected STATUS_SUCCESS\n", Line, Status);
37 ok(SectionHandle != NULL, "Line %lu: Section handle null\n", Line);
38 if (!skip(NT_SUCCESS(Status) && SectionHandle,
39 "No section handle\n"))
40 {
42 &Sbi, sizeof Sbi, NULL);
43 ok(Status == STATUS_SUCCESS, "Line %lu: Status = 0x%lx, expected STATUS_SUCCESS\n", Line, Status);
44 ok(Sbi.BaseAddress == NULL, "Line %lu: Sbi.BaseAddress = 0x%p, expected NULL\n", Line, Sbi.BaseAddress);
45 ok(Sbi.Size.QuadPart == 1LL, "Line %lu: Sbi.Size.QuadPart = 0x%I64x, expected 1\n", Line, Sbi.Size.QuadPart);
46 ok(Sbi.Attributes == (SectionFlag | SEC_FILE), "Line %lu: Sbi.Attributes = 0x%lx, expected 0x%x\n", Line, Sbi.Attributes, (SectionFlag | SEC_FILE));
47 ZwClose(SectionHandle);
48 }
49}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define KernelMode
Definition: asm.h:38
NTSYSAPI NTSTATUS NTAPI ZwQuerySection(_In_ HANDLE SectionHandle, _In_ SECTION_INFORMATION_CLASS SectionInformationClass, _Out_ PVOID SectionInformation, _In_ SIZE_T Length, _Out_opt_ PSIZE_T ResultLength)
#define SEC_FILE
Definition: mmtypes.h:96
@ SectionBasicInformation
Definition: mmtypes.h:195
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI ObOpenObjectByPointer(IN PVOID Object, IN ULONG HandleAttributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PHANDLE Handle)
Definition: obhandle.c:2742
POBJECT_TYPE MmSectionObjectType
Definition: section.c:192
Definition: ncftp.h:79
LARGE_INTEGER Size
Definition: mmtypes.h:336
LONGLONG QuadPart
Definition: typedefs.h:114

◆ START_TEST()

START_TEST ( MmSection  )

Definition at line 986 of file MmSection.c.

987{
989 HANDLE FileHandle1 = NULL, FileHandle2 = NULL;
990 PFILE_OBJECT FileObject1 = NULL, FileObject2 = NULL;
993 UNICODE_STRING FileName1 = RTL_CONSTANT_STRING(L"\\SystemRoot\\kmtest-MmSection.txt");
994 UNICODE_STRING FileName2 = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\ntdll.dll");
996 UCHAR FileData = 0;
997
998 ok(ExGetPreviousMode() == UserMode, "Previous mode is kernel mode\n");
999 /* create a one-byte file that we can use */
1004 ok(FileHandle1 != NULL, "FileHandle1 is NULL\n");
1005 if (FileHandle1)
1006 {
1007 FileOffset.QuadPart = 0;
1008 Status = ZwWriteFile(FileHandle1, NULL, NULL, NULL, &IoStatusBlock, &FileData, sizeof FileData, &FileOffset, NULL);
1009 ok(Status == STATUS_SUCCESS || Status == STATUS_PENDING, "Status = 0x%08lx\n", Status);
1010 Status = ZwWaitForSingleObject(FileHandle1, FALSE, NULL);
1013 Status = ZwClose(FileHandle1);
1015 FileHandle1 = NULL;
1016 }
1017
1022 ok(FileHandle1 != NULL, "FileHandle1 is NULL\n");
1024 CheckObject(FileHandle1, 2L, 1L);
1025#ifdef _M_IX86
1026 else
1027 CheckObject(FileHandle1, 33L, 1L);
1028#else
1029 else
1030 CheckObject(FileHandle1, 32769L, 1L);
1031#endif
1032
1037 ok(FileHandle2 != NULL, "FileHandle2 is NULL\n");
1038
1039 if (!skip(Status == STATUS_SUCCESS && FileHandle1 != NULL, "Failed to open file 1\n"))
1040 {
1043 ok(FileObject1 != NULL, "FileObject1 is NULL\n");
1045 CheckObject(FileHandle1, 3L, 1L);
1046#ifdef _M_IX86
1047 else
1048 CheckObject(FileHandle1, 32L, 1L);
1049#else
1050 else
1051 CheckObject(FileHandle1, 32768L, 1L);
1052#endif
1053 }
1054
1055 if (!skip(Status == STATUS_SUCCESS && FileHandle2 != NULL, "Failed to open file 2\n"))
1056 {
1059 ok(FileObject2 != NULL, "FileObject2 is NULL\n");
1060 }
1061
1062 trace("FileHandle1=%p, FileObject1=%p\n", FileHandle1, FileObject1);
1063 trace("FileHandle2=%p, FileObject2=%p\n", FileHandle2, FileObject2);
1064 TestCreateSection(FileHandle1, FileObject1, FileHandle2, FileObject2);
1065
1066 if (FileObject2)
1067 ObDereferenceObject(FileObject2);
1068 if (FileObject1)
1069 ObDereferenceObject(FileObject1);
1070 if (FileHandle2)
1071 ZwClose(FileHandle2);
1072 if (FileHandle1)
1073 ZwClose(FileHandle1);
1074
1076}
static VOID TestCreateSection(IN HANDLE FileHandle1, IN PFILE_OBJECT FileObject1, IN HANDLE FileHandle2, IN PFILE_OBJECT FileObject2)
Definition: MmSection.c:93
static VOID TestPhysicalMemorySection(VOID)
Definition: MmSection.c:536
#define CheckObject(Handle, Pointers, Handles)
Definition: MmSection.c:10
static const WCHAR FileName2[]
#define ok_eq_hex(value, expected)
Definition: apitest.h:134
#define GetNTVersion()
Definition: apitest.h:17
#define ok_eq_ulongptr(value, expected)
Definition: apitest.h:128
#define trace
Definition: atltest.h:70
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define FALSE
Definition: types.h:117
#define GENERIC_READ
Definition: compat.h:135
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
#define L(x)
Definition: resources.c:13
#define ExGetPreviousMode
Definition: ex.h:143
#define FILE_OPEN
Definition: from_kernel.h:54
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define UserMode
Definition: asm.h:39
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define FILE_READ_DATA
Definition: nt_native.h:628
#define FILE_CREATED
Definition: nt_native.h:770
#define GENERIC_ALL
Definition: nt_native.h:92
#define FILE_OPENED
Definition: nt_native.h:769
#define GENERIC_WRITE
Definition: nt_native.h:90
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
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)
Definition: obref.c:494
#define _WIN32_WINNT_WIN8
Definition: sdkddkver.h:29
#define STATUS_PENDING
Definition: telnetd.h:14
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
* PFILE_OBJECT
Definition: iotypes.h:1998
#define ObDereferenceObject
Definition: obfuncs.h:203
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ TestCreateSection()

static VOID TestCreateSection ( IN HANDLE  FileHandle1,
IN PFILE_OBJECT  FileObject1,
IN HANDLE  FileHandle2,
IN PFILE_OBJECT  FileObject2 
)
static

Definition at line 93 of file MmSection.c.

98{
99 NTSTATUS Status = STATUS_SUCCESS, ExceptionStatus = STATUS_SUCCESS;
102 ULONG PointerCount1, PointerCount2;
103
105 {
107 }
109 {
110 ExceptionStatus = _SEH2_GetExceptionCode();
111 }
112 _SEH2_END;
113
115 {
116 ok_eq_hex(ExceptionStatus, STATUS_SUCCESS);
118 }
119 else
120 {
121 ok_eq_hex(ExceptionStatus, STATUS_ACCESS_VIOLATION);
123 }
124
126 {
127 /* PAGE_NOACCESS and missing SEC_RESERVE/SEC_COMMIT/SEC_IMAGE assert */
131
135 }
136
139 {
141 }
143 {
144 ExceptionStatus = _SEH2_GetExceptionCode();
145 }
146 _SEH2_END;
147
149 {
150 ok_eq_hex(ExceptionStatus, STATUS_SUCCESS);
152 }
153 else
154 {
155 ok_eq_hex(ExceptionStatus, STATUS_ACCESS_VIOLATION);
157 }
159
162
166
172
175
184
187
194
197
204
207
213
216
225
228
229 /* page file section */
237 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
238 ok(SectionObject != NULL, "Section object pointer NULL\n");
239
242
243 if (!skip(FileHandle1 != NULL && FileObject1 != NULL &&
244 FileHandle2 != NULL && FileObject2 != NULL, "No file handle or object\n"))
245 {
247 {
248 PointerCount1 = 3;
249 PointerCount2 = 3;
250 }
251 else
252 {
253#ifdef _M_IX86
254 PointerCount1 = 31;
255 PointerCount2 = 33;
256#else
257 PointerCount1 = 32767;
258 PointerCount2 = 32769;
259#endif
260 }
261 /* image section */
262 CheckObject(FileHandle2, PointerCount2, 1L);
264 MaximumSize.QuadPart = 1;
270 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
271 ok(SectionObject != NULL, "Section object pointer NULL\n");
273 PointerCount2 -= 2;
274 CheckObject(FileHandle2, PointerCount2, 1L);
278
281
283 PointerCount2--;
284 CheckObject(FileHandle2, PointerCount2, 1L);
292 else
296 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
297 ok(SectionObject != NULL, "Section object pointer NULL\n");
299 ++PointerCount2;
301 --PointerCount2;
302 CheckObject(FileHandle2, PointerCount2, 1L);
305
308
310 PointerCount2--;
311 CheckObject(FileHandle2, PointerCount2, 1L);
315 Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject2);
319 else
323 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
324 ok(SectionObject != NULL, "Section object pointer NULL\n");
326 PointerCount2--;
327 CheckObject(FileHandle2, PointerCount2, 1L);
330
333
334 /* image section with inappropriate file */
335 CheckObject(FileHandle1, PointerCount1, 1L);
345 PointerCount1 -= 2;
346 CheckObject(FileHandle1, PointerCount1, 1L);
347
350
352 PointerCount1--;
353 CheckObject(FileHandle1, PointerCount1, 1L);
361 else
365 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
366 ok(SectionObject != NULL, "Section object pointer NULL\n");
368 ++PointerCount1;
370 --PointerCount1;
371 CheckObject(FileHandle1, PointerCount1, 1L);
374
377
379 --PointerCount1;
380 CheckObject(FileHandle1, PointerCount1, 1L);
384 Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject1);
388 else
392 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
393 ok(SectionObject != NULL, "Section object pointer NULL\n");
395 --PointerCount1;
396 CheckObject(FileHandle1, PointerCount1, 1L);
399
402
403 /* image section with two different files */
405 --PointerCount1;
406 CheckObject(FileHandle1, PointerCount1, 1L);
410 Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject2);
414 else
418 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
419 ok(SectionObject != NULL, "Section object pointer NULL\n");
421 {
422 --PointerCount1;
423 --PointerCount2;
424 }
425 CheckObject(FileHandle1, PointerCount1, 1L);
426 CheckObject(FileHandle2, PointerCount2, 1L);
429
432
434 --PointerCount1;
435 CheckObject(FileHandle1, PointerCount1, 1L);
437 MaximumSize.QuadPart = 1;
439 Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject1);
443 else
447 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
448 ok(SectionObject != NULL, "Section object pointer NULL\n");
450 {
451 --PointerCount1;
452 --PointerCount2;
453 }
454 CheckObject(FileHandle1, PointerCount1, 1L);
455 CheckObject(FileHandle2, PointerCount2, 1L);
458
461
462 /* data file section */
464 --PointerCount1;
465 CheckObject(FileHandle1, PointerCount1, 1L);
467 MaximumSize.QuadPart = 1;
473 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
474 ok(SectionObject != NULL, "Section object pointer NULL\n");
476 PointerCount1 -= 2;
477 CheckObject(FileHandle1, PointerCount1, 1L);
481
484
486 --PointerCount1;
487 CheckObject(FileHandle1, PointerCount1, 1L);
494 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
495 ok(SectionObject != NULL, "Section object pointer NULL\n");
497 --PointerCount1;
498 CheckObject(FileHandle1, PointerCount1, 1L);
502
505
507 --PointerCount1;
508 CheckObject(FileHandle1, PointerCount1, 1L);
512 Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, FileHandle1, FileObject1);
516 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
517 ok(SectionObject != NULL, "Section object pointer NULL\n");
519 --PointerCount1;
520 CheckObject(FileHandle1, PointerCount1, 1L);
524
527
529 --PointerCount1;
530 CheckObject(FileHandle1, PointerCount1, 1L);
531 }
532}
#define TestMapView(SectionObject, ExpectAtBase, ExpectM)
Definition: MmSection.c:52
#define CheckSection(SectionObject, SectionFlag)
Definition: MmSection.c:50
#define ok_eq_pointer(value, expected)
Definition: apitest.h:116
#define ok_eq_longlong(value, expected)
Definition: apitest.h:121
#define TRUE
Definition: types.h:120
#define PAGE_READONLY
Definition: compat.h:138
#define STATUS_ACCESS_VIOLATION
GLdouble n
Definition: glext.h:7729
GLsizei const GLvoid * pointer
Definition: glext.h:5848
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define KmtStartSeh()
Definition: kmt_test.h:285
#define KmtInvalidPointer
Definition: kmt_test.h:283
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:291
BOOLEAN KmtIsCheckedBuild
if(dx< 0)
Definition: linetemp.h:194
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:362
#define SEC_IMAGE
Definition: mmtypes.h:97
#define SEC_RESERVE
Definition: nt_native.h:1326
#define PAGE_NOACCESS
Definition: nt_native.h:1305
#define STATUS_INVALID_PARAMETER_4
Definition: ntstatus.h:572
#define STATUS_INVALID_IMAGE_NOT_MZ
Definition: ntstatus.h:633
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:362
#define STATUS_INVALID_PARAMETER_6
Definition: ntstatus.h:574
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:399
#define STATUS_SECTION_TOO_BIG
Definition: ntstatus.h:394
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:181
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:82
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
#define _WIN32_WINNT_WIN10
Definition: sdkddkver.h:32
#define _WIN32_WINNT_WS03
Definition: sdkddkver.h:23
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)
Definition: section.c:4671
Definition: fci.c:127
else
Definition: tritemp.h:161
#define LL
Definition: tui.h:166
uint32_t ULONG
Definition: typedefs.h:59
ret QuadPart
Definition: rtlfuncs.h:3106

Referenced by START_TEST().

◆ TestPhysicalMemorySection()

static VOID TestPhysicalMemorySection ( VOID  )
static

Definition at line 536 of file MmSection.c.

537{
539 UNICODE_STRING SectionName = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
541 HANDLE SectionHandle;
543 PUCHAR MyPage;
544 PHYSICAL_ADDRESS MyPagePhysical;
545 PUCHAR ZeroPageContents;
546 PHYSICAL_ADDRESS ZeroPagePhysical;
549 SYSTEM_BASIC_INFORMATION BasicInfo;
550 PUCHAR MappingBytes;
552 SIZE_T EqualBytes;
553 struct
554 {
558 } *UserStruct;
559 PVOID UserMem;
560 SIZE_T UserSize;
561
563 if (skip(MyPage != NULL, "Out of memory\n"))
564 return;
565 MyPagePhysical = MmGetPhysicalAddress(MyPage);
566 RtlFillMemory(MyPage + 0 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0x23);
567 RtlFillMemory(MyPage + 1 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0x67);
568 RtlFillMemory(MyPage + 2 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0xab);
569 RtlFillMemory(MyPage + 3 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0xef);
570
571 ZeroPageContents = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, 'ZPmK');
572 if (skip(ZeroPageContents != NULL, "Out of memory\n"))
573 {
574 ExFreePoolWithTag(MyPage, 'MPmK');
575 return;
576 }
577 ZeroPagePhysical.QuadPart = 0;
578
579 Mapping = MmMapIoSpace(ZeroPagePhysical, PAGE_SIZE, MmCached);
580 if (skip(Mapping != NULL, "Failed to map zero page\n"))
581 {
582 ExFreePoolWithTag(ZeroPageContents, 'ZPmK');
583 ExFreePoolWithTag(MyPage, 'MPmK');
584 return;
585 }
586
587 RtlCopyMemory(ZeroPageContents, Mapping, PAGE_SIZE);
589
591 &SectionName,
592 0,
593 NULL,
594 NULL);
597 if (!skip(NT_SUCCESS(Status), "No section\n"))
598 {
599 /* Map zero page and compare */
600 Mapping = NULL;
602 Status = ZwMapViewOfSection(SectionHandle,
604 &Mapping,
605 0,
606 0,
607 &ZeroPagePhysical,
608 &ViewSize,
609 ViewUnmap,
610 0,
613 if (!skip(NT_SUCCESS(Status), "No view\n"))
614 {
615 ok((LONG_PTR)Mapping > 0, "Mapping = %p\n", Mapping);
616 EqualBytes = RtlCompareMemory(Mapping,
617 ZeroPageContents,
618 PAGE_SIZE);
619 ok_eq_size(EqualBytes, PAGE_SIZE);
620 Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
622 }
623
624 /* Map the zero page non-cached */
625 Mapping = NULL;
627 Status = ZwMapViewOfSection(SectionHandle,
629 &Mapping,
630 0,
631 0,
632 &ZeroPagePhysical,
633 &ViewSize,
634 ViewUnmap,
635 0,
638 if (!skip(NT_SUCCESS(Status), "No view\n"))
639 {
640 ok((LONG_PTR)Mapping > 0, "Mapping = %p\n", Mapping);
641 EqualBytes = RtlCompareMemory(Mapping,
642 ZeroPageContents,
643 PAGE_SIZE);
644 ok_eq_size(EqualBytes, PAGE_SIZE);
645 Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
647 }
648
649 /* Map the zero page with write combining */
650 Mapping = NULL;
652 Status = ZwMapViewOfSection(SectionHandle,
654 &Mapping,
655 0,
656 0,
657 &ZeroPagePhysical,
658 &ViewSize,
659 ViewUnmap,
660 0,
663 if (!skip(NT_SUCCESS(Status), "No view\n"))
664 {
665 ok((LONG_PTR)Mapping > 0, "Mapping = %p\n", Mapping);
666 EqualBytes = RtlCompareMemory(Mapping,
667 ZeroPageContents,
668 PAGE_SIZE);
669 ok_eq_size(EqualBytes, PAGE_SIZE);
670 Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
672 }
673
674 /* Map our NP page, compare, and check that modifications are reflected */
675 Mapping = NULL;
677 Status = ZwMapViewOfSection(SectionHandle,
679 &Mapping,
680 0,
681 0,
682 &MyPagePhysical,
683 &ViewSize,
684 ViewUnmap,
685 0,
688 if (!skip(NT_SUCCESS(Status), "No view\n"))
689 {
690 ok((LONG_PTR)Mapping > 0, "Mapping = %p\n", Mapping);
691 EqualBytes = RtlCompareMemory(Mapping,
692 MyPage,
693 PAGE_SIZE);
694 ok_eq_size(EqualBytes, PAGE_SIZE);
695
696 MappingBytes = Mapping;
697 ok(MappingBytes[5] == 0x23, "Mapping[5] = 0x%x\n", MappingBytes[5]);
698 ok(MyPage[5] == 0x23, "MyPage[5] = 0x%x\n", MyPage[5]);
699
700 MyPage[5] = 0x44;
701 ok(MappingBytes[5] == 0x44, "Mapping[5] = 0x%x\n", MappingBytes[5]);
702 ok(MyPage[5] == 0x44, "MyPage[5] = 0x%x\n", MyPage[5]);
703
704 MappingBytes[5] = 0x88;
705 ok(MappingBytes[5] == 0x88, "Mapping[5] = 0x%x\n", MappingBytes[5]);
706 ok(MyPage[5] == 0x88, "MyPage[5] = 0x%x\n", MyPage[5]);
707
708 Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
710 }
711
712 /* Unaligned mapping will get aligned automatically */
713 Mapping = NULL;
714 ViewSize = PAGE_SIZE - 4;
715 PhysicalAddress.QuadPart = MyPagePhysical.QuadPart + 4;
716 Status = ZwMapViewOfSection(SectionHandle,
718 &Mapping,
719 0,
720 0,
722 &ViewSize,
723 ViewUnmap,
724 0,
727 if (!skip(NT_SUCCESS(Status), "No view\n"))
728 {
729 ok((LONG_PTR)Mapping > 0, "Mapping = %p\n", Mapping);
730 ok(((ULONG_PTR)Mapping % PAGE_SIZE) == 0, "Mapping = %p\n", Mapping);
733
734 EqualBytes = RtlCompareMemory(Mapping,
735 MyPage,
736 PAGE_SIZE);
737 ok_eq_size(EqualBytes, PAGE_SIZE);
738
739 Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
741 }
742
743 /* The following tests need to pass parameters in user mode */
744 UserStruct = NULL;
745 UserMem = NULL;
746 UserSize = PAGE_SIZE;
747 Status = ZwAllocateVirtualMemory(ZwCurrentProcess(),
748 &UserMem,
749 0,
750 &UserSize,
754 if (NT_SUCCESS(Status))
755 UserStruct = UserMem;
756
757 /* Find highest physical page -- only kernel can map beyond this */
759 &BasicInfo,
760 sizeof(BasicInfo),
761 NULL);
763 trace("HighestPhysicalPageNumber: %lx\n", BasicInfo.HighestPhysicalPageNumber);
764
765 /* Start one page before highest physical -- succeeds for user/kernel */
766 Mapping = NULL;
769 Status = ZwMapViewOfSection(SectionHandle,
771 &Mapping,
772 0,
773 0,
775 &ViewSize,
776 ViewUnmap,
777 0,
780 if (NT_SUCCESS(Status))
781 ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
782
783 /* Repeat from user mode */
784 if (!skip(UserStruct != NULL, "No user memory\n"))
785 {
787 UserStruct->Mapping = NULL;
789 UserStruct->ViewSize = PAGE_SIZE;
791
792 Status = NtMapViewOfSection(SectionHandle,
794 &UserStruct->Mapping,
795 0,
796 0,
797 &UserStruct->PhysicalAddress,
798 &UserStruct->ViewSize,
799 ViewUnmap,
800 0,
804 {
806 ZwUnmapViewOfSection(ZwCurrentProcess(), UserStruct->Mapping);
808 }
809 }
810
811 /* Now start at highest physical -- fails for user */
812 Mapping = NULL;
814 PhysicalAddress.QuadPart = (ULONGLONG)BasicInfo.HighestPhysicalPageNumber << PAGE_SHIFT;
815 Status = ZwMapViewOfSection(SectionHandle,
817 &Mapping,
818 0,
819 0,
821 &ViewSize,
822 ViewUnmap,
823 0,
827 ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
828
829 /* Repeat from user mode */
830 if (!skip(UserStruct != NULL, "No user memory\n"))
831 {
833 UserStruct->Mapping = NULL;
835 UserStruct->ViewSize = PAGE_SIZE;
837
838 Status = NtMapViewOfSection(SectionHandle,
840 &UserStruct->Mapping,
841 0,
842 0,
843 &UserStruct->PhysicalAddress,
844 &UserStruct->ViewSize,
845 ViewUnmap,
846 0,
850 else
853 {
855 ZwUnmapViewOfSection(ZwCurrentProcess(), UserStruct->Mapping);
857 }
858 }
859
860 /* End of view crosses highest physical -- fails for user */
861 Mapping = NULL;
862 ViewSize = 2 * PAGE_SIZE;
863 PhysicalAddress.QuadPart = (ULONGLONG)(BasicInfo.HighestPhysicalPageNumber - 1) << PAGE_SHIFT;
864 Status = ZwMapViewOfSection(SectionHandle,
866 &Mapping,
867 0,
868 0,
870 &ViewSize,
871 ViewUnmap,
872 0,
876 ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
877
878 /* Repeat from user mode */
879 if (!skip(UserStruct != NULL, "No user memory\n"))
880 {
882 UserStruct->Mapping = NULL;
884 UserStruct->ViewSize = 2 * PAGE_SIZE;
886
887 Status = NtMapViewOfSection(SectionHandle,
889 &UserStruct->Mapping,
890 0,
891 0,
892 &UserStruct->PhysicalAddress,
893 &UserStruct->ViewSize,
894 ViewUnmap,
895 0,
899 else
902 {
904 ZwUnmapViewOfSection(ZwCurrentProcess(), UserStruct->Mapping);
906 }
907 }
908
909 /* Free user memory and close section */
910 if (!skip(UserStruct != NULL, "No user memory\n"))
911 {
912 UserSize = 0;
913 Status = ZwFreeVirtualMemory(ZwCurrentProcess(),
914 &UserMem,
915 &UserSize,
918 }
919
920 Status = ObCloseHandle(SectionHandle, UserMode);
922 }
923
924 /* Try flag 0x80000000, which ROS calls SEC_PHYSICALMEMORY */
926 NULL,
928 NULL,
929 NULL);
930 Status = ZwCreateSection(&SectionHandle,
933 NULL,
935 0x80000000,
936 NULL);
938 if (NT_SUCCESS(Status))
939 ZwClose(SectionHandle);
940
941 /* Assertion failure: AllocationAttributes & SEC_IMAGE | SEC_RESERVE | SEC_COMMIT */
943 {
945 NULL,
947 NULL,
948 NULL);
952 NULL,
954 0x80000000,
955 NULL,
956 NULL);
958 if (NT_SUCCESS(Status))
960 }
961
963 {
965 NULL,
967 NULL,
968 NULL);
972 NULL,
974 SEC_RESERVE | 0x80000000,
975 NULL,
976 NULL);
978 if (NT_SUCCESS(Status))
980 }
981
982 ExFreePoolWithTag(ZeroPageContents, 'ZPmK');
983 ExFreePoolWithTag(MyPage, 'MPmK');
984}
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)
Definition: section.c:3257
#define ok_eq_ulong(value, expected)
Definition: apitest.h:120
#define ok_eq_size(value, expected)
Definition: apitest.h:126
void user(int argc, const char *argv[])
Definition: cmds.c:1350
static PVOID Mapping[EMS_PHYSICAL_PAGES]
Definition: emsdrv.c:41
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define NonPagedPool
Definition: env_spec_w32.h:307
#define PagedPool
Definition: env_spec_w32.h:308
NTSYSAPI NTSTATUS NTAPI ZwQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
@ SystemBasicInformation
Definition: ntddk_ex.h:11
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:603
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:193
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
static char memory[1024 *256]
Definition: process.c:116
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
NTSYSAPI NTSTATUS NTAPI ZwOpenSection(_Out_ PHANDLE SectionHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:408
#define PAGE_NOCACHE
Definition: nt_native.h:1314
#define PAGE_READWRITE
Definition: nt_native.h:1307
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1296
#define NtCurrentProcess()
Definition: nt_native.h:1660
@ ViewUnmap
Definition: nt_native.h:1282
#define MEM_RELEASE
Definition: nt_native.h:1319
#define MEM_COMMIT
Definition: nt_native.h:1316
PHYSICAL_ADDRESS NTAPI MmGetPhysicalAddress(IN PVOID Address)
Definition: stubs.c:685
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3379
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
uint64_t ULONGLONG
Definition: typedefs.h:67
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098
@ MmCached
Definition: mmtypes.h:130
#define PAGE_WRITECOMBINE
Definition: mmtypes.h:78
#define ZwCurrentProcess()

Referenced by START_TEST().