ReactOS 0.4.16-dev-1188-gc03d779
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:194
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 832 of file MmSection.c.

833{
835 HANDLE FileHandle1 = NULL, FileHandle2 = NULL;
836 PFILE_OBJECT FileObject1 = NULL, FileObject2 = NULL;
839 UNICODE_STRING FileName1 = RTL_CONSTANT_STRING(L"\\SystemRoot\\kmtest-MmSection.txt");
840 UNICODE_STRING FileName2 = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\ntdll.dll");
842 UCHAR FileData = 0;
843
844 ok(ExGetPreviousMode() == UserMode, "Previous mode is kernel mode\n");
845 /* create a one-byte file that we can use */
850 ok(FileHandle1 != NULL, "FileHandle1 is NULL\n");
851 if (FileHandle1)
852 {
853 FileOffset.QuadPart = 0;
854 Status = ZwWriteFile(FileHandle1, NULL, NULL, NULL, &IoStatusBlock, &FileData, sizeof FileData, &FileOffset, NULL);
855 ok(Status == STATUS_SUCCESS || Status == STATUS_PENDING, "Status = 0x%08lx\n", Status);
856 Status = ZwWaitForSingleObject(FileHandle1, FALSE, NULL);
859 Status = ZwClose(FileHandle1);
861 FileHandle1 = NULL;
862 }
863
868 ok(FileHandle1 != NULL, "FileHandle1 is NULL\n");
869 CheckObject(FileHandle1, 2L, 1L);
870
875 ok(FileHandle2 != NULL, "FileHandle2 is NULL\n");
876
877 if (!skip(Status == STATUS_SUCCESS && FileHandle1 != NULL, "Failed to open file 1\n"))
878 {
881 ok(FileObject1 != NULL, "FileObject1 is NULL\n");
882 CheckObject(FileHandle1, 3L, 1L);
883 }
884
885 if (!skip(Status == STATUS_SUCCESS && FileHandle2 != NULL, "Failed to open file 2\n"))
886 {
889 ok(FileObject2 != NULL, "FileObject2 is NULL\n");
890 }
891
892 trace("FileHandle1=%p, FileObject1=%p\n", FileHandle1, FileObject1);
893 trace("FileHandle2=%p, FileObject2=%p\n", FileHandle2, FileObject2);
894 TestCreateSection(FileHandle1, FileObject1, FileHandle2, FileObject2);
895
896 if (FileObject2)
897 ObDereferenceObject(FileObject2);
898 if (FileObject1)
899 ObDereferenceObject(FileObject1);
900 if (FileHandle2)
901 ZwClose(FileHandle2);
902 if (FileHandle1)
903 ZwClose(FileHandle1);
904
906}
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:416
#define CheckObject(Handle, Pointers, Handles)
Definition: MmSection.c:10
static const WCHAR FileName2[]
#define ok_eq_hex(value, expected)
Definition: apitest.h:58
#define ok_eq_ulongptr(value, expected)
Definition: apitest.h:52
#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 STATUS_PENDING
Definition: d3dkmdt.h:43
#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 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
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#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
#define L(x)
Definition: ntvdm.h:50
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 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{
102 ULONG PointerCount1, PointerCount2;
103
108
110 {
111 /* PAGE_NOACCESS and missing SEC_RESERVE/SEC_COMMIT/SEC_IMAGE assert */
115
119 }
120
127
130
134
140
143
152
155
162
165
172
175
181
184
193
196
197 /* page file section */
205 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
206 ok(SectionObject != NULL, "Section object pointer NULL\n");
207
210
211 if (!skip(FileHandle1 != NULL && FileObject1 != NULL &&
212 FileHandle2 != NULL && FileObject2 != NULL, "No file handle or object\n"))
213 {
214 PointerCount1 = 3;
215 PointerCount2 = 3;
216 /* image section */
217 CheckObject(FileHandle2, PointerCount2, 1L);
219 MaximumSize.QuadPart = 1;
225 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
226 ok(SectionObject != NULL, "Section object pointer NULL\n");
227 CheckObject(FileHandle2, PointerCount2, 1L);
230
233
234 CheckObject(FileHandle2, PointerCount2, 1L);
242 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
243 ok(SectionObject != NULL, "Section object pointer NULL\n");
244 //++PointerCount2;
245 CheckObject(FileHandle2, PointerCount2, 1L);
248
251 //--PointerCount2; // ????
252
253 CheckObject(FileHandle2, PointerCount2, 1L);
257 Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject2);
261 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
262 ok(SectionObject != NULL, "Section object pointer NULL\n");
263 CheckObject(FileHandle2, PointerCount2, 1L);
266
269
270 /* image section with inappropriate file */
271 CheckObject(FileHandle1, PointerCount1, 1L);
280 CheckObject(FileHandle1, PointerCount1, 1L);
281
284
285 CheckObject(FileHandle1, PointerCount1, 1L);
293 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
294 ok(SectionObject != NULL, "Section object pointer NULL\n");
295 ++PointerCount1;
296 CheckObject(FileHandle1, PointerCount1, 1L);
299
302 //--PointerCount1; // ????
303
304 CheckObject(FileHandle1, PointerCount1, 1L);
308 Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject1);
312 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
313 ok(SectionObject != NULL, "Section object pointer NULL\n");
314 CheckObject(FileHandle1, PointerCount1, 1L);
317
320
321 /* image section with two different files */
322 CheckObject(FileHandle1, PointerCount1, 1L);
326 Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject2);
330 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
331 ok(SectionObject != NULL, "Section object pointer NULL\n");
332 CheckObject(FileHandle1, PointerCount1, 1L);
333 CheckObject(FileHandle2, PointerCount2, 1L);
336
339
340 CheckObject(FileHandle1, PointerCount1, 1L);
344 Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject1);
348 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
349 ok(SectionObject != NULL, "Section object pointer NULL\n");
350 CheckObject(FileHandle1, PointerCount1, 1L);
351 CheckObject(FileHandle2, PointerCount2, 1L);
354
357
358 /* data file section */
359 CheckObject(FileHandle1, PointerCount1, 1L);
367 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
368 ok(SectionObject != NULL, "Section object pointer NULL\n");
369 CheckObject(FileHandle1, PointerCount1, 1L);
372
375
376 CheckObject(FileHandle1, PointerCount1, 1L);
384 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
385 ok(SectionObject != NULL, "Section object pointer NULL\n");
386 CheckObject(FileHandle1, PointerCount1, 1L);
389
392
393 CheckObject(FileHandle1, PointerCount1, 1L);
397 Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, FileHandle1, FileObject1);
401 ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
402 ok(SectionObject != NULL, "Section object pointer NULL\n");
403 CheckObject(FileHandle1, PointerCount1, 1L);
406
409
410 CheckObject(FileHandle1, PointerCount1, 1L);
411 }
412}
#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:40
#define ok_eq_longlong(value, expected)
Definition: apitest.h:45
#define TRUE
Definition: types.h:120
#define PAGE_READONLY
Definition: compat.h:138
GLdouble n
Definition: glext.h:7729
GLsizei const GLvoid * pointer
Definition: glext.h:5848
#define KmtStartSeh()
Definition: kmt_test.h:282
#define KmtInvalidPointer
Definition: kmt_test.h:280
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:288
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:1323
#define PAGE_NOACCESS
Definition: nt_native.h:1302
#define STATUS_INVALID_PARAMETER_4
Definition: ntstatus.h:478
#define STATUS_INVALID_IMAGE_NOT_MZ
Definition: ntstatus.h:539
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:305
#define STATUS_SECTION_TOO_BIG
Definition: ntstatus.h:300
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:4632
Definition: fci.c:127
#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 416 of file MmSection.c.

417{
419 UNICODE_STRING SectionName = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
421 HANDLE SectionHandle;
423 PUCHAR MyPage;
424 PHYSICAL_ADDRESS MyPagePhysical;
425 PUCHAR ZeroPageContents;
426 PHYSICAL_ADDRESS ZeroPagePhysical;
429 SYSTEM_BASIC_INFORMATION BasicInfo;
430 PUCHAR MappingBytes;
432 SIZE_T EqualBytes;
433 struct
434 {
438 } *UserStruct;
439 PVOID UserMem;
440 SIZE_T UserSize;
441
443 if (skip(MyPage != NULL, "Out of memory\n"))
444 return;
445 MyPagePhysical = MmGetPhysicalAddress(MyPage);
446 RtlFillMemory(MyPage + 0 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0x23);
447 RtlFillMemory(MyPage + 1 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0x67);
448 RtlFillMemory(MyPage + 2 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0xab);
449 RtlFillMemory(MyPage + 3 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0xef);
450
451 ZeroPageContents = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, 'ZPmK');
452 if (skip(ZeroPageContents != NULL, "Out of memory\n"))
453 {
454 ExFreePoolWithTag(MyPage, 'MPmK');
455 return;
456 }
457 ZeroPagePhysical.QuadPart = 0;
458
459 Mapping = MmMapIoSpace(ZeroPagePhysical, PAGE_SIZE, MmCached);
460 if (skip(Mapping != NULL, "Failed to map zero page\n"))
461 {
462 ExFreePoolWithTag(ZeroPageContents, 'ZPmK');
463 ExFreePoolWithTag(MyPage, 'MPmK');
464 return;
465 }
466
467 RtlCopyMemory(ZeroPageContents, Mapping, PAGE_SIZE);
469
471 &SectionName,
472 0,
473 NULL,
474 NULL);
477 if (!skip(NT_SUCCESS(Status), "No section\n"))
478 {
479 /* Map zero page and compare */
480 Mapping = NULL;
482 Status = ZwMapViewOfSection(SectionHandle,
484 &Mapping,
485 0,
486 0,
487 &ZeroPagePhysical,
488 &ViewSize,
489 ViewUnmap,
490 0,
493 if (!skip(NT_SUCCESS(Status), "No view\n"))
494 {
495 ok((LONG_PTR)Mapping > 0, "Mapping = %p\n", Mapping);
496 EqualBytes = RtlCompareMemory(Mapping,
497 ZeroPageContents,
498 PAGE_SIZE);
499 ok_eq_size(EqualBytes, PAGE_SIZE);
500 Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
502 }
503
504 /* Map the zero page non-cached */
505 Mapping = NULL;
507 Status = ZwMapViewOfSection(SectionHandle,
509 &Mapping,
510 0,
511 0,
512 &ZeroPagePhysical,
513 &ViewSize,
514 ViewUnmap,
515 0,
518 if (!skip(NT_SUCCESS(Status), "No view\n"))
519 {
520 ok((LONG_PTR)Mapping > 0, "Mapping = %p\n", Mapping);
521 EqualBytes = RtlCompareMemory(Mapping,
522 ZeroPageContents,
523 PAGE_SIZE);
524 ok_eq_size(EqualBytes, PAGE_SIZE);
525 Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
527 }
528
529 /* Map our NP page, compare, and check that modifications are reflected */
530 Mapping = NULL;
532 Status = ZwMapViewOfSection(SectionHandle,
534 &Mapping,
535 0,
536 0,
537 &MyPagePhysical,
538 &ViewSize,
539 ViewUnmap,
540 0,
543 if (!skip(NT_SUCCESS(Status), "No view\n"))
544 {
545 ok((LONG_PTR)Mapping > 0, "Mapping = %p\n", Mapping);
546 EqualBytes = RtlCompareMemory(Mapping,
547 MyPage,
548 PAGE_SIZE);
549 ok_eq_size(EqualBytes, PAGE_SIZE);
550
551 MappingBytes = Mapping;
552 ok(MappingBytes[5] == 0x23, "Mapping[5] = 0x%x\n", MappingBytes[5]);
553 ok(MyPage[5] == 0x23, "MyPage[5] = 0x%x\n", MyPage[5]);
554
555 MyPage[5] = 0x44;
556 ok(MappingBytes[5] == 0x44, "Mapping[5] = 0x%x\n", MappingBytes[5]);
557 ok(MyPage[5] == 0x44, "MyPage[5] = 0x%x\n", MyPage[5]);
558
559 MappingBytes[5] = 0x88;
560 ok(MappingBytes[5] == 0x88, "Mapping[5] = 0x%x\n", MappingBytes[5]);
561 ok(MyPage[5] == 0x88, "MyPage[5] = 0x%x\n", MyPage[5]);
562
563 Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
565 }
566
567 /* Unaligned mapping will get aligned automatically */
568 Mapping = NULL;
569 ViewSize = PAGE_SIZE - 4;
570 PhysicalAddress.QuadPart = MyPagePhysical.QuadPart + 4;
571 Status = ZwMapViewOfSection(SectionHandle,
573 &Mapping,
574 0,
575 0,
577 &ViewSize,
578 ViewUnmap,
579 0,
582 if (!skip(NT_SUCCESS(Status), "No view\n"))
583 {
584 ok((LONG_PTR)Mapping > 0, "Mapping = %p\n", Mapping);
585 ok(((ULONG_PTR)Mapping % PAGE_SIZE) == 0, "Mapping = %p\n", Mapping);
588
589 EqualBytes = RtlCompareMemory(Mapping,
590 MyPage,
591 PAGE_SIZE);
592 ok_eq_size(EqualBytes, PAGE_SIZE);
593
594 Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
596 }
597
598 /* The following tests need to pass parameters in user mode */
599 UserStruct = NULL;
600 UserMem = NULL;
601 UserSize = PAGE_SIZE;
602 Status = ZwAllocateVirtualMemory(ZwCurrentProcess(),
603 &UserMem,
604 0,
605 &UserSize,
609 if (NT_SUCCESS(Status))
610 UserStruct = UserMem;
611
612 /* Find highest physical page -- only kernel can map beyond this */
614 &BasicInfo,
615 sizeof(BasicInfo),
616 NULL);
618 trace("HighestPhysicalPageNumber: %lx\n", BasicInfo.HighestPhysicalPageNumber);
619
620 /* Start one page before highest physical -- succeeds for user/kernel */
621 Mapping = NULL;
624 Status = ZwMapViewOfSection(SectionHandle,
626 &Mapping,
627 0,
628 0,
630 &ViewSize,
631 ViewUnmap,
632 0,
635 if (NT_SUCCESS(Status))
636 ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
637
638 /* Repeat from user mode */
639 if (!skip(UserStruct != NULL, "No user memory\n"))
640 {
642 UserStruct->Mapping = NULL;
644 UserStruct->ViewSize = PAGE_SIZE;
646
647 Status = NtMapViewOfSection(SectionHandle,
649 &UserStruct->Mapping,
650 0,
651 0,
652 &UserStruct->PhysicalAddress,
653 &UserStruct->ViewSize,
654 ViewUnmap,
655 0,
659 {
661 ZwUnmapViewOfSection(ZwCurrentProcess(), UserStruct->Mapping);
663 }
664 }
665
666 /* Now start at highest physical -- fails for user */
667 Mapping = NULL;
669 PhysicalAddress.QuadPart = (ULONGLONG)BasicInfo.HighestPhysicalPageNumber << PAGE_SHIFT;
670 Status = ZwMapViewOfSection(SectionHandle,
672 &Mapping,
673 0,
674 0,
676 &ViewSize,
677 ViewUnmap,
678 0,
682 ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
683
684 /* Repeat from user mode */
685 if (!skip(UserStruct != NULL, "No user memory\n"))
686 {
688 UserStruct->Mapping = NULL;
690 UserStruct->ViewSize = PAGE_SIZE;
692
693 Status = NtMapViewOfSection(SectionHandle,
695 &UserStruct->Mapping,
696 0,
697 0,
698 &UserStruct->PhysicalAddress,
699 &UserStruct->ViewSize,
700 ViewUnmap,
701 0,
705 {
707 ZwUnmapViewOfSection(ZwCurrentProcess(), UserStruct->Mapping);
709 }
710 }
711
712 /* End of view crosses highest physical -- fails for user */
713 Mapping = NULL;
714 ViewSize = 2 * PAGE_SIZE;
715 PhysicalAddress.QuadPart = (ULONGLONG)(BasicInfo.HighestPhysicalPageNumber - 1) << PAGE_SHIFT;
716 Status = ZwMapViewOfSection(SectionHandle,
718 &Mapping,
719 0,
720 0,
722 &ViewSize,
723 ViewUnmap,
724 0,
728 ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
729
730 /* Repeat from user mode */
731 if (!skip(UserStruct != NULL, "No user memory\n"))
732 {
734 UserStruct->Mapping = NULL;
736 UserStruct->ViewSize = 2 * PAGE_SIZE;
738
739 Status = NtMapViewOfSection(SectionHandle,
741 &UserStruct->Mapping,
742 0,
743 0,
744 &UserStruct->PhysicalAddress,
745 &UserStruct->ViewSize,
746 ViewUnmap,
747 0,
751 {
753 ZwUnmapViewOfSection(ZwCurrentProcess(), UserStruct->Mapping);
755 }
756 }
757
758 /* Free user memory and close section */
759 if (!skip(UserStruct != NULL, "No user memory\n"))
760 {
761 UserSize = 0;
762 Status = ZwFreeVirtualMemory(ZwCurrentProcess(),
763 &UserMem,
764 &UserSize,
767 }
768
769 Status = ObCloseHandle(SectionHandle, UserMode);
771 }
772
773 /* Try flag 0x80000000, which ROS calls SEC_PHYSICALMEMORY */
775 NULL,
777 NULL,
778 NULL);
779 Status = ZwCreateSection(&SectionHandle,
782 NULL,
784 0x80000000,
785 NULL);
787 if (NT_SUCCESS(Status))
788 ZwClose(SectionHandle);
789
790 /* Assertion failure: AllocationAttributes & SEC_IMAGE | SEC_RESERVE | SEC_COMMIT */
792 {
794 NULL,
796 NULL,
797 NULL);
801 NULL,
803 0x80000000,
804 NULL,
805 NULL);
807 if (NT_SUCCESS(Status))
809 }
810
812 NULL,
814 NULL,
815 NULL);
819 NULL,
821 SEC_RESERVE | 0x80000000,
822 NULL,
823 NULL);
825 if (NT_SUCCESS(Status))
827
828 ExFreePoolWithTag(ZeroPageContents, 'ZPmK');
829 ExFreePoolWithTag(MyPage, 'MPmK');
830}
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:44
#define ok_eq_size(value, expected)
Definition: apitest.h:50
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:599
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:1311
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define NtCurrentProcess()
Definition: nt_native.h:1657
@ ViewUnmap
Definition: nt_native.h:1279
#define MEM_RELEASE
Definition: nt_native.h:1316
#define MEM_COMMIT
Definition: nt_native.h:1313
PHYSICAL_ADDRESS NTAPI MmGetPhysicalAddress(IN PVOID Address)
Definition: stubs.c:685
#define STATUS_INVALID_PARAMETER_6
Definition: ntstatus.h:480
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 ZwCurrentProcess()

Referenced by START_TEST().