ReactOS  0.4.14-dev-317-g96040ec
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)
 
#define TestMapView(SectionObject, ExpectAtBase, ExpectM)
 

Functions

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 \
{ \
PUBLIC_OBJECT_BASIC_INFORMATION ObjectInfo; \
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)
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2938

Definition at line 10 of file MmSection.c.

◆ CheckSection

#define CheckSection (   SectionObject,
  SectionFlag 
)
Value:
do \
{ \
SECTION_BASIC_INFORMATION Sbi; \
HANDLE SectionHandle = NULL; \
NTSTATUS Status; \
if (skip(SectionObject != NULL && \
SectionObject != (PVOID)0x5555555555555555ULL, \
"No section object\n")) \
break; \
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)
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
#define LL
Definition: tui.h:85
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:2739
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
POBJECT_TYPE MmSectionObjectType
Definition: section.c:136
Status
Definition: gdiplustypes.h:24
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 skip(...)
Definition: atltest.h:64
#define SEC_FILE
Definition: mmtypes.h:95
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231

Definition at line 20 of file MmSection.c.

◆ TestMapView

#define TestMapView (   SectionObject,
  ExpectAtBase,
  ExpectM 
)

Definition at line 47 of file MmSection.c.

Function Documentation

◆ START_TEST()

START_TEST ( MmSection  )

Definition at line 816 of file MmSection.c.

817 {
819  HANDLE FileHandle1 = NULL, FileHandle2 = NULL;
820  PFILE_OBJECT FileObject1 = NULL, FileObject2 = NULL;
823  UNICODE_STRING FileName1 = RTL_CONSTANT_STRING(L"\\SystemRoot\\kmtest-MmSection.txt");
824  UNICODE_STRING FileName2 = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\ntdll.dll");
826  UCHAR FileData = 0;
827 
828  ok(ExGetPreviousMode() == UserMode, "Previous mode is kernel mode\n");
829  /* create a one-byte file that we can use */
834  ok(FileHandle1 != NULL, "FileHandle1 is NULL\n");
835  if (FileHandle1)
836  {
837  FileOffset.QuadPart = 0;
838  Status = ZwWriteFile(FileHandle1, NULL, NULL, NULL, &IoStatusBlock, &FileData, sizeof FileData, &FileOffset, NULL);
839  ok(Status == STATUS_SUCCESS || Status == STATUS_PENDING, "Status = 0x%08lx\n", Status);
840  Status = ZwWaitForSingleObject(FileHandle1, FALSE, NULL);
843  Status = ZwClose(FileHandle1);
845  FileHandle1 = NULL;
846  }
847 
852  ok(FileHandle1 != NULL, "FileHandle1 is NULL\n");
853  CheckObject(FileHandle1, 2L, 1L);
854 
859  ok(FileHandle2 != NULL, "FileHandle2 is NULL\n");
860 
861  if (!skip(Status == STATUS_SUCCESS && FileHandle1 != NULL, "Failed to open file 1\n"))
862  {
865  ok(FileObject1 != NULL, "FileObject1 is NULL\n");
866  CheckObject(FileHandle1, 3L, 1L);
867  }
868 
869  if (!skip(Status == STATUS_SUCCESS && FileHandle2 != NULL, "Failed to open file 2\n"))
870  {
873  ok(FileObject2 != NULL, "FileObject2 is NULL\n");
874  }
875 
876  trace("FileHandle1=%p, FileObject1=%p\n", FileHandle1, FileObject1);
877  trace("FileHandle2=%p, FileObject2=%p\n", FileHandle2, FileObject2);
878  TestCreateSection(FileHandle1, FileObject1, FileHandle2, FileObject2);
879 
880  if (FileObject2)
881  ObDereferenceObject(FileObject2);
882  if (FileObject1)
883  ObDereferenceObject(FileObject1);
884  if (FileHandle2)
885  ZwClose(FileHandle2);
886  if (FileHandle1)
887  ZwClose(FileHandle1);
888 
890 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
#define GENERIC_ALL
Definition: nt_native.h:92
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_OPENED
Definition: nt_native.h:769
#define ok_eq_ulongptr(value, expected)
Definition: kmt_test.h:249
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define FILE_SHARE_READ
Definition: compat.h:125
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:496
#define FILE_READ_DATA
Definition: nt_native.h:628
#define GENERIC_WRITE
Definition: nt_native.h:90
#define CheckObject(Handle, Pointers, Handles)
Definition: MmSection.c:10
smooth NULL
Definition: ftsmooth.c:416
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
#define trace
Definition: atltest.h:70
#define STATUS_PENDING
Definition: ntstatus.h:82
* PFILE_OBJECT
Definition: iotypes.h:1955
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
unsigned char UCHAR
Definition: xmlstorage.h:181
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define GENERIC_READ
Definition: compat.h:124
#define SYNCHRONIZE
Definition: nt_native.h:61
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define ok(value,...)
Definition: atltest.h:57
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define FILE_CREATED
Definition: nt_native.h:770
#define skip(...)
Definition: atltest.h:64
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
static VOID TestPhysicalMemorySection(VOID)
Definition: MmSection.c:401
#define ok_eq_hex(value, expected)
static const WCHAR FileName2[]
return STATUS_SUCCESS
Definition: btrfs.c:2938
static VOID TestCreateSection(IN HANDLE FileHandle1, IN PFILE_OBJECT FileObject1, IN HANDLE FileHandle2, IN PFILE_OBJECT FileObject2)
Definition: MmSection.c:88
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

◆ TestCreateSection()

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

Definition at line 88 of file MmSection.c.

93 {
97  ULONG PointerCount1, PointerCount2;
98 
99  KmtStartSeh()
103 
105  {
106  /* PAGE_NOACCESS and missing SEC_RESERVE/SEC_COMMIT/SEC_IMAGE assert */
107  KmtStartSeh()
110 
111  KmtStartSeh()
114  }
115 
117  KmtStartSeh()
122 
125 
126  KmtStartSeh()
129 
131  KmtStartSeh()
135 
138 
140  MaximumSize.QuadPart = 0;
141  KmtStartSeh()
147 
150 
151  MaximumSize.QuadPart = 0;
152  KmtStartSeh()
157 
160 
161  MaximumSize.QuadPart = 1;
162  KmtStartSeh()
166 
169 
171  MaximumSize.QuadPart = 0;
172  KmtStartSeh()
178 
181 
182  /* page file section */
184  MaximumSize.QuadPart = 1;
185  KmtStartSeh()
190  ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
191  ok(SectionObject != NULL, "Section object pointer NULL\n");
192 
195 
196  if (!skip(FileHandle1 != NULL && FileObject1 != NULL &&
197  FileHandle2 != NULL && FileObject2 != NULL, "No file handle or object\n"))
198  {
199  PointerCount1 = 3;
200  PointerCount2 = 3;
201  /* image section */
202  CheckObject(FileHandle2, PointerCount2, 1L);
204  MaximumSize.QuadPart = 1;
205  KmtStartSeh()
210  ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
211  ok(SectionObject != NULL, "Section object pointer NULL\n");
212  CheckObject(FileHandle2, PointerCount2, 1L);
215 
218 
219  CheckObject(FileHandle2, PointerCount2, 1L);
221  MaximumSize.QuadPart = 1;
222  KmtStartSeh()
227  ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
228  ok(SectionObject != NULL, "Section object pointer NULL\n");
229  ++PointerCount2;
230  CheckObject(FileHandle2, PointerCount2, 1L);
233 
236  //--PointerCount2; // ????
237 
238  CheckObject(FileHandle2, PointerCount2, 1L);
240  MaximumSize.QuadPart = 1;
241  KmtStartSeh()
242  Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject2);
246  ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
247  ok(SectionObject != NULL, "Section object pointer NULL\n");
248  CheckObject(FileHandle2, PointerCount2, 1L);
251 
254 
255  /* image section with inappropriate file */
256  CheckObject(FileHandle1, PointerCount1, 1L);
258  MaximumSize.QuadPart = 1;
259  KmtStartSeh()
265  CheckObject(FileHandle1, PointerCount1, 1L);
266 
269 
270  CheckObject(FileHandle1, PointerCount1, 1L);
272  MaximumSize.QuadPart = 1;
273  KmtStartSeh()
278  ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
279  ok(SectionObject != NULL, "Section object pointer NULL\n");
280  ++PointerCount1;
281  CheckObject(FileHandle1, PointerCount1, 1L);
284 
287  //--PointerCount1; // ????
288 
289  CheckObject(FileHandle1, PointerCount1, 1L);
291  MaximumSize.QuadPart = 1;
292  KmtStartSeh()
293  Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject1);
297  ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
298  ok(SectionObject != NULL, "Section object pointer NULL\n");
299  CheckObject(FileHandle1, PointerCount1, 1L);
302 
305 
306  /* image section with two different files */
307  CheckObject(FileHandle1, PointerCount1, 1L);
309  MaximumSize.QuadPart = 1;
310  KmtStartSeh()
311  Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject2);
315  ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
316  ok(SectionObject != NULL, "Section object pointer NULL\n");
317  CheckObject(FileHandle1, PointerCount1, 1L);
318  CheckObject(FileHandle2, PointerCount2, 1L);
321 
324 
325  CheckObject(FileHandle1, PointerCount1, 1L);
327  MaximumSize.QuadPart = 1;
328  KmtStartSeh()
329  Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject1);
333  ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
334  ok(SectionObject != NULL, "Section object pointer NULL\n");
335  CheckObject(FileHandle1, PointerCount1, 1L);
336  CheckObject(FileHandle2, PointerCount2, 1L);
339 
342 
343  /* data file section */
344  CheckObject(FileHandle1, PointerCount1, 1L);
346  MaximumSize.QuadPart = 1;
347  KmtStartSeh()
352  ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
353  ok(SectionObject != NULL, "Section object pointer NULL\n");
354  CheckObject(FileHandle1, PointerCount1, 1L);
357 
360 
361  CheckObject(FileHandle1, PointerCount1, 1L);
363  MaximumSize.QuadPart = 1;
364  KmtStartSeh()
369  ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
370  ok(SectionObject != NULL, "Section object pointer NULL\n");
371  CheckObject(FileHandle1, PointerCount1, 1L);
374 
377 
378  CheckObject(FileHandle1, PointerCount1, 1L);
380  MaximumSize.QuadPart = 1;
381  KmtStartSeh()
382  Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, FileHandle1, FileObject1);
386  ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
387  ok(SectionObject != NULL, "Section object pointer NULL\n");
388  CheckObject(FileHandle1, PointerCount1, 1L);
391 
394 
395  CheckObject(FileHandle1, PointerCount1, 1L);
396  }
397 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
#define KmtInvalidPointer
Definition: kmt_test.h:275
#define TRUE
Definition: types.h:120
#define LL
Definition: tui.h:85
#define ok_eq_longlong(value, expected)
Definition: kmt_test.h:242
#define CheckSection(SectionObject, SectionFlag)
Definition: MmSection.c:20
GLsizei const GLvoid * pointer
Definition: glext.h:5848
#define ok_eq_pointer(value, expected)
LONG NTSTATUS
Definition: precomp.h:26
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:283
GLdouble n
Definition: glext.h:7729
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
BOOLEAN KmtIsCheckedBuild
#define SEC_RESERVE
Definition: nt_native.h:1323
#define CheckObject(Handle, Pointers, Handles)
Definition: MmSection.c:10
#define PAGE_NOACCESS
Definition: nt_native.h:1302
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_INVALID_IMAGE_NOT_MZ
Definition: ntstatus.h:525
if(!(yy_init))
Definition: macro.lex.yy.c:714
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:4975
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:255
static const WCHAR L[]
Definition: oid.c:1250
#define STATUS_INVALID_PAGE_PROTECTION
Definition: ntstatus.h:291
#define KmtStartSeh()
Definition: kmt_test.h:277
Status
Definition: gdiplustypes.h:24
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define ok(value,...)
Definition: atltest.h:57
#define PAGE_READONLY
Definition: compat.h:127
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:360
#define TestMapView(SectionObject, ExpectAtBase, ExpectM)
Definition: MmSection.c:47
#define skip(...)
Definition: atltest.h:64
ret QuadPart
Definition: rtlfuncs.h:3091
unsigned int ULONG
Definition: retypes.h:1
#define SEC_IMAGE
Definition: mmtypes.h:96
#define ok_eq_hex(value, expected)
#define STATUS_INVALID_PARAMETER_4
Definition: ntstatus.h:464
return STATUS_SUCCESS
Definition: btrfs.c:2938
Definition: fci.c:126

Referenced by START_TEST().

◆ TestPhysicalMemorySection()

static VOID TestPhysicalMemorySection ( VOID  )
static

Definition at line 401 of file MmSection.c.

402 {
404  UNICODE_STRING SectionName = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
406  HANDLE SectionHandle;
408  PUCHAR MyPage;
409  PHYSICAL_ADDRESS MyPagePhysical;
410  PUCHAR ZeroPageContents;
411  PHYSICAL_ADDRESS ZeroPagePhysical;
413  PVOID Mapping;
414  SYSTEM_BASIC_INFORMATION BasicInfo;
415  PUCHAR MappingBytes;
417  SIZE_T EqualBytes;
418  struct
419  {
420  PVOID Mapping;
423  } *UserStruct;
424  PVOID UserMem;
425  SIZE_T UserSize;
426 
427  MyPage = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, 'MPmK');
428  if (skip(MyPage != NULL, "Out of memory\n"))
429  return;
430  MyPagePhysical = MmGetPhysicalAddress(MyPage);
431  RtlFillMemory(MyPage + 0 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0x23);
432  RtlFillMemory(MyPage + 1 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0x67);
433  RtlFillMemory(MyPage + 2 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0xab);
434  RtlFillMemory(MyPage + 3 * PAGE_SIZE / 4, PAGE_SIZE / 4, 0xef);
435 
436  ZeroPageContents = ExAllocatePoolWithTag(PagedPool, PAGE_SIZE, 'ZPmK');
437  if (skip(ZeroPageContents != NULL, "Out of memory\n"))
438  {
439  ExFreePoolWithTag(MyPage, 'MPmK');
440  return;
441  }
442  ZeroPagePhysical.QuadPart = 0;
443 
444  Mapping = MmMapIoSpace(ZeroPagePhysical, PAGE_SIZE, MmCached);
445  if (skip(Mapping != NULL, "Failed to map zero page\n"))
446  {
447  ExFreePoolWithTag(ZeroPageContents, 'ZPmK');
448  ExFreePoolWithTag(MyPage, 'MPmK');
449  return;
450  }
451 
452  RtlCopyMemory(ZeroPageContents, Mapping, PAGE_SIZE);
454 
456  &SectionName,
457  0,
458  NULL,
459  NULL);
462  if (!skip(NT_SUCCESS(Status), "No section\n"))
463  {
464  /* Map zero page and compare */
465  Mapping = NULL;
467  Status = ZwMapViewOfSection(SectionHandle,
469  &Mapping,
470  0,
471  0,
472  &ZeroPagePhysical,
473  &ViewSize,
474  ViewUnmap,
475  0,
478  if (!skip(NT_SUCCESS(Status), "No view\n"))
479  {
480  ok((LONG_PTR)Mapping > 0, "Mapping = %p\n", Mapping);
481  EqualBytes = RtlCompareMemory(Mapping,
482  ZeroPageContents,
483  PAGE_SIZE);
484  ok_eq_size(EqualBytes, PAGE_SIZE);
485  Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
487  }
488 
489  /* Map the zero page non-cached */
490  Mapping = NULL;
492  Status = ZwMapViewOfSection(SectionHandle,
494  &Mapping,
495  0,
496  0,
497  &ZeroPagePhysical,
498  &ViewSize,
499  ViewUnmap,
500  0,
503  if (!skip(NT_SUCCESS(Status), "No view\n"))
504  {
505  ok((LONG_PTR)Mapping > 0, "Mapping = %p\n", Mapping);
506  EqualBytes = RtlCompareMemory(Mapping,
507  ZeroPageContents,
508  PAGE_SIZE);
509  ok_eq_size(EqualBytes, PAGE_SIZE);
510  Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
512  }
513 
514  /* Map our NP page, compare, and check that modifications are reflected */
515  Mapping = NULL;
517  Status = ZwMapViewOfSection(SectionHandle,
519  &Mapping,
520  0,
521  0,
522  &MyPagePhysical,
523  &ViewSize,
524  ViewUnmap,
525  0,
528  if (!skip(NT_SUCCESS(Status), "No view\n"))
529  {
530  ok((LONG_PTR)Mapping > 0, "Mapping = %p\n", Mapping);
531  EqualBytes = RtlCompareMemory(Mapping,
532  MyPage,
533  PAGE_SIZE);
534  ok_eq_size(EqualBytes, PAGE_SIZE);
535 
536  MappingBytes = Mapping;
537  ok(MappingBytes[5] == 0x23, "Mapping[5] = 0x%x\n", MappingBytes[5]);
538  ok(MyPage[5] == 0x23, "MyPage[5] = 0x%x\n", MyPage[5]);
539 
540  MyPage[5] = 0x44;
541  ok(MappingBytes[5] == 0x44, "Mapping[5] = 0x%x\n", MappingBytes[5]);
542  ok(MyPage[5] == 0x44, "MyPage[5] = 0x%x\n", MyPage[5]);
543 
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]);
547 
548  Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
550  }
551 
552  /* Unaligned mapping will get aligned automatically */
553  Mapping = NULL;
554  ViewSize = PAGE_SIZE - 4;
555  PhysicalAddress.QuadPart = MyPagePhysical.QuadPart + 4;
556  Status = ZwMapViewOfSection(SectionHandle,
558  &Mapping,
559  0,
560  0,
562  &ViewSize,
563  ViewUnmap,
564  0,
567  if (!skip(NT_SUCCESS(Status), "No view\n"))
568  {
569  ok((LONG_PTR)Mapping > 0, "Mapping = %p\n", Mapping);
570  ok(((ULONG_PTR)Mapping % PAGE_SIZE) == 0, "Mapping = %p\n", Mapping);
572 
573  EqualBytes = RtlCompareMemory(Mapping,
574  MyPage,
575  PAGE_SIZE);
576  ok_eq_size(EqualBytes, PAGE_SIZE);
577 
578  Status = ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
580  }
581 
582  /* The following tests need to pass parameters in user mode */
583  UserStruct = NULL;
584  UserMem = NULL;
585  UserSize = PAGE_SIZE;
586  Status = ZwAllocateVirtualMemory(ZwCurrentProcess(),
587  &UserMem,
588  0,
589  &UserSize,
590  MEM_COMMIT,
593  if (NT_SUCCESS(Status))
594  UserStruct = UserMem;
595 
596  /* Find highest physical page -- only kernel can map beyond this */
598  &BasicInfo,
599  sizeof(BasicInfo),
600  NULL);
602  trace("HighestPhysicalPageNumber: %lx\n", BasicInfo.HighestPhysicalPageNumber);
603 
604  /* Start one page before highest physical -- succeeds for user/kernel */
605  Mapping = NULL;
608  Status = ZwMapViewOfSection(SectionHandle,
610  &Mapping,
611  0,
612  0,
614  &ViewSize,
615  ViewUnmap,
616  0,
619  if (NT_SUCCESS(Status))
620  ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
621 
622  /* Repeat from user mode */
623  if (!skip(UserStruct != NULL, "No user memory\n"))
624  {
625  KmtStartSeh()
626  UserStruct->Mapping = NULL;
628  UserStruct->ViewSize = PAGE_SIZE;
630 
631  Status = NtMapViewOfSection(SectionHandle,
633  &UserStruct->Mapping,
634  0,
635  0,
636  &UserStruct->PhysicalAddress,
637  &UserStruct->ViewSize,
638  ViewUnmap,
639  0,
642  if (NT_SUCCESS(Status))
643  {
644  KmtStartSeh()
645  ZwUnmapViewOfSection(ZwCurrentProcess(), UserStruct->Mapping);
647  }
648  }
649 
650  /* Now start at highest physical -- fails for user */
651  Mapping = NULL;
653  PhysicalAddress.QuadPart = (ULONGLONG)BasicInfo.HighestPhysicalPageNumber << PAGE_SHIFT;
654  Status = ZwMapViewOfSection(SectionHandle,
656  &Mapping,
657  0,
658  0,
660  &ViewSize,
661  ViewUnmap,
662  0,
665  if (NT_SUCCESS(Status))
666  ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
667 
668  /* Repeat from user mode */
669  if (!skip(UserStruct != NULL, "No user memory\n"))
670  {
671  KmtStartSeh()
672  UserStruct->Mapping = NULL;
674  UserStruct->ViewSize = PAGE_SIZE;
676 
677  Status = NtMapViewOfSection(SectionHandle,
679  &UserStruct->Mapping,
680  0,
681  0,
682  &UserStruct->PhysicalAddress,
683  &UserStruct->ViewSize,
684  ViewUnmap,
685  0,
688  if (NT_SUCCESS(Status))
689  {
690  KmtStartSeh()
691  ZwUnmapViewOfSection(ZwCurrentProcess(), UserStruct->Mapping);
693  }
694  }
695 
696  /* End of view crosses highest physical -- fails for user */
697  Mapping = NULL;
698  ViewSize = 2 * PAGE_SIZE;
699  PhysicalAddress.QuadPart = (ULONGLONG)(BasicInfo.HighestPhysicalPageNumber - 1) << PAGE_SHIFT;
700  Status = ZwMapViewOfSection(SectionHandle,
702  &Mapping,
703  0,
704  0,
706  &ViewSize,
707  ViewUnmap,
708  0,
711  if (NT_SUCCESS(Status))
712  ZwUnmapViewOfSection(ZwCurrentProcess(), Mapping);
713 
714  /* Repeat from user mode */
715  if (!skip(UserStruct != NULL, "No user memory\n"))
716  {
717  KmtStartSeh()
718  UserStruct->Mapping = NULL;
720  UserStruct->ViewSize = 2 * PAGE_SIZE;
722 
723  Status = NtMapViewOfSection(SectionHandle,
725  &UserStruct->Mapping,
726  0,
727  0,
728  &UserStruct->PhysicalAddress,
729  &UserStruct->ViewSize,
730  ViewUnmap,
731  0,
734  if (NT_SUCCESS(Status))
735  {
736  KmtStartSeh()
737  ZwUnmapViewOfSection(ZwCurrentProcess(), UserStruct->Mapping);
739  }
740  }
741 
742  /* Free user memory and close section */
743  if (!skip(UserStruct != NULL, "No user memory\n"))
744  {
745  UserSize = 0;
746  Status = ZwFreeVirtualMemory(ZwCurrentProcess(),
747  &UserMem,
748  &UserSize,
749  MEM_RELEASE);
751  }
752 
753  Status = ObCloseHandle(SectionHandle, UserMode);
755  }
756 
757  /* Try flag 0x80000000, which ROS calls SEC_PHYSICALMEMORY */
759  NULL,
761  NULL,
762  NULL);
763  Status = ZwCreateSection(&SectionHandle,
766  NULL,
768  0x80000000,
769  NULL);
771  if (NT_SUCCESS(Status))
772  ZwClose(SectionHandle);
773 
774  /* Assertion failure: AllocationAttributes & SEC_IMAGE | SEC_RESERVE | SEC_COMMIT */
775  if (!KmtIsCheckedBuild)
776  {
778  NULL,
780  NULL,
781  NULL);
785  NULL,
787  0x80000000,
788  NULL,
789  NULL);
791  if (NT_SUCCESS(Status))
793  }
794 
796  NULL,
798  NULL,
799  NULL);
803  NULL,
805  SEC_RESERVE | 0x80000000,
806  NULL,
807  NULL);
809  if (NT_SUCCESS(Status))
811 
812  ExFreePoolWithTag(ZeroPageContents, 'ZPmK');
813  ExFreePoolWithTag(MyPage, 'MPmK');
814 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
#define PAGE_NOCACHE
Definition: nt_native.h:1311
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define ok_eq_ulong(value, expected)
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define ok_eq_size(value, expected)
Definition: kmt_test.h:247
#define ZwCurrentProcess()
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
static PVOID Mapping[EMS_PHYSICAL_PAGES]
Definition: emsdrv.c:41
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:283
GLdouble n
Definition: glext.h:7729
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
#define MEM_COMMIT
Definition: nt_native.h:1313
static char memory[1024 *256]
Definition: process.c:116
uint32_t ULONG_PTR
Definition: typedefs.h:63
BOOLEAN KmtIsCheckedBuild
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define SEC_RESERVE
Definition: nt_native.h:1323
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:3554
NTSYSAPI NTSTATUS NTAPI ZwQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define trace
Definition: atltest.h:70
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:65
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:4975
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1061
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3376
static const WCHAR L[]
Definition: oid.c:1250
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define KmtStartSeh()
Definition: kmt_test.h:277
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:193
#define ok(value,...)
Definition: atltest.h:57
#define STATUS_INVALID_PARAMETER_6
Definition: ntstatus.h:466
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define skip(...)
Definition: atltest.h:64
#define MEM_RELEASE
Definition: nt_native.h:1316
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
ret QuadPart
Definition: rtlfuncs.h:3091
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
PHYSICAL_ADDRESS NTAPI MmGetPhysicalAddress(IN PVOID Address)
Definition: stubs.c:682
#define ok_eq_hex(value, expected)
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
NTSYSAPI NTSTATUS NTAPI ZwOpenSection(_Out_ PHANDLE SectionHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
void user(int argc, const char *argv[])
Definition: cmds.c:1350
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
LONGLONG QuadPart
Definition: typedefs.h:112
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by START_TEST().