- Removed the process from the parameter list of MmCreateMemoryArea.

- Changed the 9th parameter of MmCreateMemoryArea to allocation flags.  
- Implemented SEC_NO_CHANGE.

svn path=/trunk/; revision=19208
This commit is contained in:
Hartmut Birr 2005-11-13 17:28:24 +00:00
parent 1be846c026
commit 2fa81ffdfd
15 changed files with 231 additions and 190 deletions

View File

@ -657,15 +657,14 @@ CcRosCreateCacheSegment(PBCB Bcb,
#else
MmLockAddressSpace(MmGetKernelAddressSpace());
current->BaseAddress = NULL;
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_CACHE_SEGMENT,
&current->BaseAddress,
Bcb->CacheSegmentSize,
PAGE_READWRITE,
(PMEMORY_AREA*)&current->MemoryArea,
FALSE,
FALSE,
0,
BoundaryAddressMultiple);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status))
@ -1366,15 +1365,14 @@ CcInitView(VOID)
MmLockAddressSpace(MmGetKernelAddressSpace());
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_CACHE_SEGMENT,
&CiCacheSegMappingRegionBase,
CI_CACHESEG_MAPPING_REGION_SIZE,
0,
PAGE_READWRITE,
&marea,
FALSE,
FALSE,
0,
BoundaryAddressMultiple);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status))

View File

@ -215,7 +215,8 @@ typedef struct _MEMORY_AREA
struct _MEMORY_AREA *LeftChild;
struct _MEMORY_AREA *RightChild;
ULONG Type;
ULONG Attributes;
ULONG Protect;
ULONG Flags;
ULONG LockCount;
BOOLEAN DeleteInProgress;
ULONG PageOpCount;
@ -377,15 +378,14 @@ MmInitMemoryAreas(VOID);
NTSTATUS
STDCALL
MmCreateMemoryArea(
struct _EPROCESS* Process,
PMADDRESS_SPACE AddressSpace,
ULONG Type,
PVOID *BaseAddress,
ULONG_PTR Length,
ULONG Attributes,
ULONG Protection,
PMEMORY_AREA *Result,
BOOLEAN FixedAddress,
BOOLEAN TopDown,
ULONG AllocationFlags,
PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL
);

View File

@ -108,15 +108,14 @@ PsAllocateCallbackStack(ULONG StackSize)
BoundaryAddressMultiple.QuadPart = 0;
StackSize = PAGE_ROUND_UP(StackSize);
MmLockAddressSpace(MmGetKernelAddressSpace());
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_KERNEL_STACK,
&KernelStack,
StackSize,
0,
PAGE_READWRITE,
&StackArea,
FALSE,
FALSE,
0,
BoundaryAddressMultiple);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status))

View File

@ -727,15 +727,14 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
}
}
Status = MmCreateMemoryArea(Process,
AddressSpace,
Status = MmCreateMemoryArea(AddressSpace,
MEMORY_AREA_VIRTUAL_MEMORY,
&BaseAddress,
RegionSize,
Protect,
&MemoryArea,
PBaseAddress != 0,
(AllocationType & MEM_TOP_DOWN) == MEM_TOP_DOWN,
AllocationType & MEM_TOP_DOWN,
BoundaryAddressMultiple);
if (!NT_SUCCESS(Status))
{
@ -1000,7 +999,7 @@ MmQueryAnonMem(PMEMORY_AREA MemoryArea,
Address, &RegionBase);
Info->BaseAddress = RegionBase;
Info->AllocationBase = MemoryArea->StartingAddress;
Info->AllocationProtect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Protect;
Info->RegionSize = Region->Length;
Info->State = Region->Type;
Info->Protect = Region->Protect;

View File

@ -71,29 +71,28 @@ MmAllocateContiguousMemorySpecifyCache(IN SIZE_T NumberOfBytes,
NTSTATUS Status;
PVOID BaseAddress = NULL;
PFN_TYPE PBase;
ULONG Attributes;
ULONG Protect;
ULONG i;
Attributes = PAGE_EXECUTE_READWRITE | PAGE_SYSTEM;
Protect = PAGE_EXECUTE_READWRITE | PAGE_SYSTEM;
if (CacheType == MmNonCached || CacheType == MmWriteCombined)
{
Attributes |= PAGE_NOCACHE;
Protect |= PAGE_NOCACHE;
}
if (CacheType == MmWriteCombined)
{
Attributes |= PAGE_WRITECOMBINE;
Protect |= PAGE_WRITECOMBINE;
}
MmLockAddressSpace(MmGetKernelAddressSpace());
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_CONTINUOUS_MEMORY,
&BaseAddress,
NumberOfBytes,
0,
PAGE_READWRITE,
&MArea,
FALSE,
FALSE,
0,
(PHYSICAL_ADDRESS)0LL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
@ -120,7 +119,7 @@ MmAllocateContiguousMemorySpecifyCache(IN SIZE_T NumberOfBytes,
{
MmCreateVirtualMapping(NULL,
(char*)BaseAddress + (i * PAGE_SIZE),
Attributes,
Protect,
&PBase,
1);
}

View File

@ -2419,30 +2419,28 @@ MiInitPageDirectoryMap(VOID)
BoundaryAddressMultiple.QuadPart = 0;
BaseAddress = (PVOID)PAGETABLE_MAP;
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Ke386Pae ? 0x800000 : 0x400000,
0,
PAGE_READWRITE,
&kernel_map_desc,
TRUE,
FALSE,
0,
BoundaryAddressMultiple);
if (!NT_SUCCESS(Status))
{
KEBUGCHECK(0);
}
BaseAddress = (PVOID)HYPERSPACE;
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
0x400000,
0,
PAGE_READWRITE,
&hyperspace_desc,
TRUE,
FALSE,
0,
BoundaryAddressMultiple);
if (!NT_SUCCESS(Status))
{

View File

@ -54,7 +54,7 @@ MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
MEMORY_AREA* marea;
NTSTATUS Status;
ULONG i;
ULONG Attributes;
ULONG Protect;
PHYSICAL_ADDRESS BoundaryAddressMultiple;
PFN_TYPE Pfn;
@ -72,16 +72,20 @@ MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
Offset = PhysicalAddress.u.LowPart % PAGE_SIZE;
NumberOfBytes += Offset;
PhysicalAddress.QuadPart -= Offset;
Protect = PAGE_EXECUTE_READWRITE | PAGE_SYSTEM;
if (CacheEnable != MmCached)
{
Protect |= (PAGE_NOCACHE | PAGE_WRITETHROUGH);
}
MmLockAddressSpace(MmGetKernelAddressSpace());
Status = MmCreateMemoryArea (NULL,
MmGetKernelAddressSpace(),
Status = MmCreateMemoryArea (MmGetKernelAddressSpace(),
MEMORY_AREA_IO_MAPPING,
&Result,
NumberOfBytes,
0,
Protect,
&marea,
FALSE,
0,
FALSE,
BoundaryAddressMultiple);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
@ -91,16 +95,11 @@ MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
DPRINT("MmMapIoSpace failed (%lx)\n", Status);
return (NULL);
}
Attributes = PAGE_EXECUTE_READWRITE | PAGE_SYSTEM;
if (CacheEnable != MmCached)
{
Attributes |= (PAGE_NOCACHE | PAGE_WRITETHROUGH);
}
Pfn = PhysicalAddress.QuadPart >> PAGE_SHIFT;
for (i = 0; i < PAGE_ROUND_UP(NumberOfBytes); i += PAGE_SIZE, Pfn++)
{
Status = MmCreateVirtualMappingForKernel((char*)Result + i,
Attributes,
Protect,
&Pfn,
1);
if (!NT_SUCCESS(Status))

View File

@ -105,7 +105,7 @@ static PMEMORY_AREA MmIterateNextNode(PMEMORY_AREA Node)
}
/**
* @name MmIterateFirstNode
* @name MmIterateLastNode
*
* @param Node
* Head node of the MEMORY_AREA tree.
@ -123,7 +123,7 @@ static PMEMORY_AREA MmIterateLastNode(PMEMORY_AREA Node)
}
/**
* @name MmIterateNextNode
* @name MmIteratePreviousNode
*
* @param Node
* Current node in the tree.
@ -200,9 +200,9 @@ MmDumpMemoryAreas(PMADDRESS_SPACE AddressSpace)
Node != NULL;
Node = MmIterateNextNode(Node))
{
DbgPrint("Start %p End %p Attributes %x\n",
DbgPrint("Start %p End %p Protect %x Flags %x\n",
Node->StartingAddress, Node->EndingAddress,
Node->Attributes);
Node->Protect, Node->Flags);
}
DbgPrint("Finished MmDumpMemoryAreas()\n");
@ -928,15 +928,14 @@ MmFreeMemoryAreaByPtr(
*/
NTSTATUS STDCALL
MmCreateMemoryArea(PEPROCESS Process,
PMADDRESS_SPACE AddressSpace,
MmCreateMemoryArea(PMADDRESS_SPACE AddressSpace,
ULONG Type,
PVOID *BaseAddress,
ULONG_PTR Length,
ULONG Attributes,
ULONG Protect,
PMEMORY_AREA *Result,
BOOLEAN FixedAddress,
BOOLEAN TopDown,
ULONG AllocationFlags,
PHYSICAL_ADDRESS BoundaryAddressMultiple)
{
PVOID EndAddress;
@ -959,7 +958,7 @@ MmCreateMemoryArea(PEPROCESS Process,
*BaseAddress = MmFindGap(AddressSpace,
tmpLength,
Granularity,
TopDown != 0);
(AllocationFlags & MEM_TOP_DOWN) == MEM_TOP_DOWN);
if ((*BaseAddress) == 0)
{
DPRINT("No suitable gap\n");
@ -1007,7 +1006,8 @@ MmCreateMemoryArea(PEPROCESS Process,
MemoryArea->Type = Type;
MemoryArea->StartingAddress = *BaseAddress;
MemoryArea->EndingAddress = (PVOID)((ULONG_PTR)*BaseAddress + tmpLength);
MemoryArea->Attributes = Attributes;
MemoryArea->Protect = Protect;
MemoryArea->Flags = AllocationFlags;
MemoryArea->LockCount = 0;
MemoryArea->PageOpCount = 0;
MemoryArea->DeleteInProgress = FALSE;

View File

@ -70,15 +70,14 @@ MmInitializeMdlImplementation(VOID)
MiMdlMappingRegionBase = NULL;
MmLockAddressSpace(MmGetKernelAddressSpace());
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_MDL_MAPPING,
&MiMdlMappingRegionBase,
MI_MDL_MAPPING_REGION_SIZE,
0,
PAGE_READWRITE,
&Result,
FALSE,
FALSE,
0,
BoundaryAddressMultiple);
if (!NT_SUCCESS(Status))
{
@ -779,6 +778,12 @@ MmMapLockedPagesSpecifyCache ( IN PMDL Mdl,
/* FIXME: Implement Priority */
(void) Priority;
Protect = PAGE_READWRITE;
if (CacheType == MmNonCached)
Protect |= PAGE_NOCACHE;
else if (CacheType == MmWriteCombined)
DPRINT("CacheType MmWriteCombined not supported!\n");
/* Calculate the number of pages required. */
PageCount = PAGE_ROUND_UP(Mdl->ByteCount + Mdl->ByteOffset) / PAGE_SIZE;
@ -797,15 +802,14 @@ MmMapLockedPagesSpecifyCache ( IN PMDL Mdl,
CurrentProcess = PsGetCurrentProcess();
MmLockAddressSpace(&CurrentProcess->AddressSpace);
Status = MmCreateMemoryArea(CurrentProcess,
&CurrentProcess->AddressSpace,
Status = MmCreateMemoryArea(&CurrentProcess->AddressSpace,
MEMORY_AREA_MDL_MAPPING,
&Base,
PageCount * PAGE_SIZE,
0, /* PAGE_READWRITE? */
Protect,
&Result,
(Base != NULL),
FALSE,
0,
BoundaryAddressMultiple);
MmUnlockAddressSpace(&CurrentProcess->AddressSpace);
if (!NT_SUCCESS(Status))
@ -865,11 +869,6 @@ MmMapLockedPagesSpecifyCache ( IN PMDL Mdl,
/* Set the virtual mappings for the MDL pages. */
MdlPages = (PULONG)(Mdl + 1);
Protect = PAGE_READWRITE;
if (CacheType == MmNonCached)
Protect |= PAGE_NOCACHE;
else if (CacheType == MmWriteCombined)
DPRINT("CacheType MmWriteCombined not supported!\n");
if (Mdl->MdlFlags & MDL_IO_SPACE)
Status = MmCreateVirtualMappingUnsafe(CurrentProcess,
Base,

View File

@ -107,53 +107,49 @@ MmInitVirtualMemory(ULONG_PTR LastKernelAddress,
MiInitPageDirectoryMap();
BaseAddress = (PVOID)KPCR_BASE;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
PAGE_SIZE * MAXIMUM_PROCESSORS,
0,
PAGE_READWRITE,
&MArea,
TRUE,
FALSE,
0,
BoundaryAddressMultiple);
/* Local APIC base */
BaseAddress = (PVOID)0xFEE00000;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
PAGE_SIZE,
0,
PAGE_READWRITE,
&MArea,
TRUE,
FALSE,
0,
BoundaryAddressMultiple);
/* i/o APIC base */
BaseAddress = (PVOID)0xFEC00000;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
PAGE_SIZE,
0,
PAGE_READWRITE,
&MArea,
TRUE,
FALSE,
0,
BoundaryAddressMultiple);
BaseAddress = (PVOID)0xFF3A0000;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
0x20000,
0,
PAGE_READWRITE,
&MArea,
TRUE,
FALSE,
0,
BoundaryAddressMultiple);
BaseAddress = (PVOID)KERNEL_BASE;
@ -164,15 +160,14 @@ MmInitVirtualMemory(ULONG_PTR LastKernelAddress,
* No need to lock the address space at this point since no
* other threads are running.
*/
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
PAGE_EXECUTE_READ,
&MArea,
TRUE,
FALSE,
0,
BoundaryAddressMultiple);
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG_PTR)&_text_end__));
@ -181,15 +176,14 @@ MmInitVirtualMemory(ULONG_PTR LastKernelAddress,
PAGE_ROUND_UP(((ULONG_PTR)&_text_end__));
ParamLength = ParamLength - Length;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
PAGE_EXECUTE_READ,
&MArea,
TRUE,
FALSE,
0,
BoundaryAddressMultiple);
Length = PAGE_ROUND_UP(((ULONG_PTR)&_bss_end__)) -
@ -203,52 +197,48 @@ MmInitVirtualMemory(ULONG_PTR LastKernelAddress,
* No need to lock the address space at this point since we are
* the only thread running.
*/
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
PAGE_READWRITE,
&MArea,
TRUE,
FALSE,
0,
BoundaryAddressMultiple);
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG_PTR)&_bss_end__));
Length = LastKernelAddress - (ULONG_PTR)BaseAddress;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
PAGE_READWRITE,
&MArea,
TRUE,
FALSE,
0,
BoundaryAddressMultiple);
BaseAddress = MiNonPagedPoolStart;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
MiNonPagedPoolLength,
0,
PAGE_READWRITE,
&MArea,
TRUE,
FALSE,
0,
BoundaryAddressMultiple);
BaseAddress = MmPagedPoolBase;
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_PAGED_POOL,
&BaseAddress,
MmPagedPoolSize,
0,
PAGE_READWRITE,
&MArea,
TRUE,
FALSE,
0,
BoundaryAddressMultiple);
MmInitializePagedPool();
@ -258,15 +248,14 @@ MmInitVirtualMemory(ULONG_PTR LastKernelAddress,
*/
BaseAddress = (PVOID)KI_USER_SHARED_DATA;
Length = PAGE_SIZE;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
PAGE_READWRITE,
&MArea,
TRUE,
FALSE,
0,
BoundaryAddressMultiple);
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &Pfn);
MmSharedDataPagePhysicalAddress.QuadPart = Pfn << PAGE_SHIFT;

View File

@ -48,21 +48,20 @@ MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
MEMORY_AREA* marea;
NTSTATUS Status;
ULONG i;
ULONG Attributes;
ULONG Protect = PAGE_READWRITE|PAGE_SYSTEM|PAGE_NOCACHE|PAGE_WRITETHROUGH;
PHYSICAL_ADDRESS BoundaryAddressMultiple;
BoundaryAddressMultiple.QuadPart = 0;
MmLockAddressSpace(MmGetKernelAddressSpace());
Result = NULL;
Status = MmCreateMemoryArea (NULL,
MmGetKernelAddressSpace(),
Status = MmCreateMemoryArea (MmGetKernelAddressSpace(),
MEMORY_AREA_NO_CACHE,
&Result,
NumberOfBytes,
0,
Protect,
&marea,
FALSE,
FALSE,
0,
BoundaryAddressMultiple);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
@ -70,8 +69,7 @@ MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
{
return (NULL);
}
Attributes = PAGE_READWRITE | PAGE_SYSTEM | PAGE_NOCACHE |
PAGE_WRITETHROUGH;
for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / PAGE_SIZE); i++)
{
PFN_TYPE NPage;
@ -79,7 +77,7 @@ MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &NPage);
MmCreateVirtualMapping (NULL,
(char*)Result + (i * PAGE_SIZE),
Attributes,
Protect,
&NPage,
1);
}

View File

@ -45,15 +45,14 @@ MiCreatePebOrTeb(PEPROCESS Process,
*/
do {
DPRINT("Trying to allocate: %x\n", AllocatedBase);
Status = MmCreateMemoryArea(Process,
ProcessAddressSpace,
Status = MmCreateMemoryArea(ProcessAddressSpace,
MEMORY_AREA_PEB_OR_TEB,
&AllocatedBase,
PAGE_SIZE,
PAGE_READWRITE,
&MemoryArea,
TRUE,
FALSE,
0,
BoundaryAddressMultiple);
AllocatedBase = RVA(AllocatedBase, -PAGE_SIZE);
} while (Status != STATUS_SUCCESS);
@ -143,15 +142,14 @@ MmCreateKernelStack(BOOLEAN GuiStack)
MmLockAddressSpace(MmGetKernelAddressSpace());
/* Create a MAREA for the Kernel Stack */
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_KERNEL_STACK,
&KernelStack,
MM_STACK_SIZE,
0,
PAGE_READWRITE,
&StackArea,
FALSE,
FALSE,
0,
BoundaryAddressMultiple);
/* Unlock the Address Space */
@ -399,15 +397,14 @@ MmCreateProcessAddressSpace(IN PEPROCESS Process,
/* Protect the highest 64KB of the process address space */
BaseAddress = (PVOID)MmUserProbeAddress;
Status = MmCreateMemoryArea(Process,
ProcessAddressSpace,
Status = MmCreateMemoryArea(ProcessAddressSpace,
MEMORY_AREA_NO_ACCESS,
&BaseAddress,
0x10000,
PAGE_NOACCESS,
&MemoryArea,
FALSE,
FALSE,
0,
BoundaryAddressMultiple);
if (!NT_SUCCESS(Status))
{
@ -417,15 +414,14 @@ MmCreateProcessAddressSpace(IN PEPROCESS Process,
/* Protect the 60KB above the shared user page */
BaseAddress = (char*)USER_SHARED_DATA + PAGE_SIZE;
Status = MmCreateMemoryArea(Process,
ProcessAddressSpace,
Status = MmCreateMemoryArea(ProcessAddressSpace,
MEMORY_AREA_NO_ACCESS,
&BaseAddress,
0x10000 - PAGE_SIZE,
PAGE_NOACCESS,
&MemoryArea,
FALSE,
FALSE,
0,
BoundaryAddressMultiple);
if (!NT_SUCCESS(Status))
{
@ -435,15 +431,14 @@ MmCreateProcessAddressSpace(IN PEPROCESS Process,
/* Create the shared data page */
BaseAddress = (PVOID)USER_SHARED_DATA;
Status = MmCreateMemoryArea(Process,
ProcessAddressSpace,
Status = MmCreateMemoryArea(ProcessAddressSpace,
MEMORY_AREA_SHARED_DATA,
&BaseAddress,
PAGE_SIZE,
PAGE_READONLY,
PAGE_EXECUTE_READ,
&MemoryArea,
FALSE,
FALSE,
0,
BoundaryAddressMultiple);
if (!NT_SUCCESS(Status))
{
@ -478,7 +473,7 @@ MmCreateProcessAddressSpace(IN PEPROCESS Process,
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to map process Image\n");
goto exit;
return Status;
}
/* Save the pointer */

View File

@ -1605,7 +1605,7 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
{
Status = MmCreateVirtualMapping(AddressSpace->Process,
Address,
MemoryArea->Attributes,
MemoryArea->Protect,
&Page,
1);
MmSetDirtyPage(AddressSpace->Process, Address);
@ -1622,7 +1622,7 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
*/
Status = MmCreateVirtualMapping(AddressSpace->Process,
Address,
MemoryArea->Attributes,
MemoryArea->Protect,
&Page,
1);
MmSetDirtyPage(AddressSpace->Process, Address);
@ -1656,7 +1656,7 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
{
Status = MmCreateVirtualMapping(AddressSpace->Process,
Address,
MemoryArea->Attributes,
MemoryArea->Protect,
&Page,
1);
MmSetDirtyPage(AddressSpace->Process, Address);
@ -1668,7 +1668,7 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
{
Status = MmCreateVirtualMapping(AddressSpace->Process,
Address,
MemoryArea->Attributes,
MemoryArea->Protect,
&Page,
1);
MmSetDirtyPage(AddressSpace->Process, Address);
@ -1952,6 +1952,13 @@ MmProtectSectionView(PMADDRESS_SPACE AddressSpace,
Region = MmFindRegion(MemoryArea->StartingAddress,
&MemoryArea->Data.SectionData.RegionListHead,
BaseAddress, NULL);
if ((MemoryArea->Flags & SEC_NO_CHANGE) &&
Region->Protect != Protect)
{
CHECKPOINT1;
return STATUS_INVALID_PAGE_PROTECTION;
}
*OldProtect = Region->Protect;
Status = MmAlterRegion(AddressSpace, MemoryArea->StartingAddress,
&MemoryArea->Data.SectionData.RegionListHead,
@ -1993,7 +2000,7 @@ MmQuerySectionView(PMEMORY_AREA MemoryArea,
Info->Type = MEM_MAPPED;
}
Info->BaseAddress = RegionBaseAddress;
Info->AllocationProtect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Protect;
Info->RegionSize = Region->Length;
Info->State = MEM_COMMIT;
Info->Protect = Region->Protect;
@ -3377,15 +3384,6 @@ NtCreateSection (OUT PHANDLE SectionHandle,
}
}
/*
* Check the protection
*/
if ((SectionPageProtection & PAGE_FLAGS_VALID_FROM_USER_MODE) !=
SectionPageProtection)
{
return(STATUS_INVALID_PAGE_PROTECTION);
}
Status = MmCreateSection(&SectionObject,
DesiredAccess,
ObjectAttributes,
@ -3481,15 +3479,14 @@ NtOpenSection(PHANDLE SectionHandle,
}
NTSTATUS STATIC
MmMapViewOfSegment(PEPROCESS Process,
PMADDRESS_SPACE AddressSpace,
MmMapViewOfSegment(PMADDRESS_SPACE AddressSpace,
PSECTION_OBJECT Section,
PMM_SECTION_SEGMENT Segment,
PVOID* BaseAddress,
ULONG ViewSize,
ULONG Protect,
ULONG ViewOffset,
BOOL TopDown)
ULONG AllocationType)
{
PMEMORY_AREA MArea;
NTSTATUS Status;
@ -3497,15 +3494,14 @@ MmMapViewOfSegment(PEPROCESS Process,
BoundaryAddressMultiple.QuadPart = 0;
Status = MmCreateMemoryArea(Process,
AddressSpace,
Status = MmCreateMemoryArea(AddressSpace,
MEMORY_AREA_SECTION_VIEW,
BaseAddress,
ViewSize,
Protect,
&MArea,
FALSE,
TopDown,
AllocationType,
BoundaryAddressMultiple);
if (!NT_SUCCESS(Status))
{
@ -3514,11 +3510,8 @@ MmMapViewOfSegment(PEPROCESS Process,
return(Status);
}
ObReferenceObject((PVOID)Section);
ObReferenceObjectByPointer((PVOID)Section,
SECTION_MAP_READ,
NULL,
ExGetPreviousMode());
MArea->Data.SectionData.Segment = Segment;
MArea->Data.SectionData.Section = Section;
MArea->Data.SectionData.ViewOffset = ViewOffset;
@ -3599,6 +3592,30 @@ NtMapViewOfSection(IN HANDLE SectionHandle,
KPROCESSOR_MODE PreviousMode;
PMADDRESS_SPACE AddressSpace;
NTSTATUS Status = STATUS_SUCCESS;
ULONG tmpProtect;
/*
* Check the protection
*/
if (Protect & ~PAGE_FLAGS_VALID_FROM_USER_MODE)
{
CHECKPOINT1;
return STATUS_INVALID_PARAMETER_10;
}
tmpProtect = Protect & ~(PAGE_GUARD|PAGE_NOCACHE);
if (tmpProtect != PAGE_NOACCESS &&
tmpProtect != PAGE_READONLY &&
tmpProtect != PAGE_READWRITE &&
tmpProtect != PAGE_WRITECOPY &&
tmpProtect != PAGE_EXECUTE &&
tmpProtect != PAGE_EXECUTE_READ &&
tmpProtect != PAGE_EXECUTE_READWRITE &&
tmpProtect != PAGE_EXECUTE_WRITECOPY)
{
CHECKPOINT1;
return STATUS_INVALID_PAGE_PROTECTION;
}
PreviousMode = ExGetPreviousMode();
@ -4285,15 +4302,14 @@ MmAllocateSection (IN ULONG Length, PVOID BaseAddress)
AddressSpace = MmGetKernelAddressSpace();
Result = BaseAddress;
MmLockAddressSpace(AddressSpace);
Status = MmCreateMemoryArea (NULL,
AddressSpace,
Status = MmCreateMemoryArea (AddressSpace,
MEMORY_AREA_SYSTEM,
&Result,
Length,
0,
&marea,
FALSE,
FALSE,
0,
BoundaryAddressMultiple);
MmUnlockAddressSpace(AddressSpace);
@ -4395,9 +4411,24 @@ MmMapViewOfSection(IN PVOID SectionObject,
ASSERT(Process);
if (Protect != PAGE_READONLY &&
Protect != PAGE_READWRITE &&
Protect != PAGE_WRITECOPY &&
Protect != PAGE_EXECUTE &&
Protect != PAGE_EXECUTE_READ &&
Protect != PAGE_EXECUTE_READWRITE &&
Protect != PAGE_EXECUTE_WRITECOPY)
{
CHECKPOINT1;
return STATUS_INVALID_PAGE_PROTECTION;
}
Section = (PSECTION_OBJECT)SectionObject;
AddressSpace = &Process->AddressSpace;
AllocationType |= (Section->AllocationAttributes & SEC_NO_CHANGE);
MmLockAddressSpace(AddressSpace);
if (Section->AllocationAttributes & SEC_IMAGE)
@ -4458,15 +4489,14 @@ MmMapViewOfSection(IN PVOID SectionObject,
PVOID SBaseAddress = (PVOID)
((char*)ImageBase + (ULONG_PTR)SectionSegments[i].VirtualAddress);
MmLockSectionSegment(&SectionSegments[i]);
Status = MmMapViewOfSegment(Process,
AddressSpace,
Status = MmMapViewOfSegment(AddressSpace,
Section,
&SectionSegments[i],
&SBaseAddress,
SectionSegments[i].Length,
SectionSegments[i].Protection,
0,
FALSE);
0);
MmUnlockSectionSegment(&SectionSegments[i]);
if (!NT_SUCCESS(Status))
{
@ -4480,6 +4510,28 @@ MmMapViewOfSection(IN PVOID SectionObject,
}
else
{
/* check for write access */
if ((Protect & (PAGE_READWRITE|PAGE_EXECUTE_READWRITE)) &&
!(Section->SectionPageProtection & (PAGE_READWRITE|PAGE_EXECUTE_READWRITE)))
{
CHECKPOINT1;
return STATUS_SECTION_PROTECTION;
}
/* check for read access */
if ((Protect & (PAGE_READONLY|PAGE_WRITECOPY|PAGE_EXECUTE_READ|PAGE_EXECUTE_WRITECOPY)) &&
!(Section->SectionPageProtection & (PAGE_READONLY|PAGE_READWRITE|PAGE_WRITECOPY|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY)))
{
CHECKPOINT1;
return STATUS_SECTION_PROTECTION;
}
/* check for execute access */
if ((Protect & (PAGE_EXECUTE|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY)) &&
!(Section->SectionPageProtection & (PAGE_EXECUTE|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY)))
{
CHECKPOINT1;
return STATUS_SECTION_PROTECTION;
}
if (ViewSize == NULL)
{
/* Following this pointer would lead to us to the dark side */
@ -4512,15 +4564,14 @@ MmMapViewOfSection(IN PVOID SectionObject,
}
MmLockSectionSegment(Section->Segment);
Status = MmMapViewOfSegment(Process,
AddressSpace,
Status = MmMapViewOfSegment(AddressSpace,
Section,
Section->Segment,
BaseAddress,
*ViewSize,
Protect,
ViewOffset,
(AllocationType & MEM_TOP_DOWN) == MEM_TOP_DOWN);
AllocationType & (MEM_TOP_DOWN|SEC_NO_CHANGE));
MmUnlockSectionSegment(Section->Segment);
if (!NT_SUCCESS(Status))
{
@ -4624,15 +4675,14 @@ MmMapViewInSystemSpace (IN PVOID SectionObject,
MmLockSectionSegment(Section->Segment);
Status = MmMapViewOfSegment(NULL,
AddressSpace,
Status = MmMapViewOfSegment(AddressSpace,
Section,
Section->Segment,
MappedBase,
*ViewSize,
PAGE_READWRITE,
0,
FALSE);
0);
MmUnlockSectionSegment(Section->Segment);
MmUnlockAddressSpace(AddressSpace);
@ -4768,6 +4818,25 @@ MmCreateSection (OUT PSECTION_OBJECT * SectionObject,
IN HANDLE FileHandle OPTIONAL,
IN PFILE_OBJECT File OPTIONAL)
{
ULONG Protection;
/*
* Check the protection
*/
Protection = SectionPageProtection & ~(PAGE_GUARD|PAGE_NOCACHE);
if (Protection != PAGE_NOACCESS &&
Protection != PAGE_READONLY &&
Protection != PAGE_READWRITE &&
Protection != PAGE_WRITECOPY &&
Protection != PAGE_EXECUTE &&
Protection != PAGE_EXECUTE_READ &&
Protection != PAGE_EXECUTE_READWRITE &&
Protection != PAGE_EXECUTE_WRITECOPY)
{
CHECKPOINT1;
return STATUS_INVALID_PAGE_PROTECTION;
}
if (AllocationAttributes & SEC_IMAGE)
{
return(MmCreateImageSection(SectionObject,

View File

@ -186,8 +186,8 @@ MiQueryVirtualMemory (IN HANDLE ProcessHandle,
case MEMORY_AREA_NO_ACCESS:
Info->Type = MEM_PRIVATE;
Info->State = MEM_RESERVE;
Info->Protect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Attributes;
Info->Protect = MemoryArea->Protect;
Info->AllocationProtect = MemoryArea->Protect;
Info->BaseAddress = MemoryArea->StartingAddress;
Info->AllocationBase = MemoryArea->StartingAddress;
Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress -
@ -198,8 +198,8 @@ MiQueryVirtualMemory (IN HANDLE ProcessHandle,
case MEMORY_AREA_SHARED_DATA:
Info->Type = MEM_PRIVATE;
Info->State = MEM_COMMIT;
Info->Protect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Attributes;
Info->Protect = MemoryArea->Protect;
Info->AllocationProtect = MemoryArea->Protect;
Info->BaseAddress = MemoryArea->StartingAddress;
Info->AllocationBase = MemoryArea->StartingAddress;
Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress -
@ -210,8 +210,8 @@ MiQueryVirtualMemory (IN HANDLE ProcessHandle,
case MEMORY_AREA_SYSTEM:
Info->Type = 0;
Info->State = MEM_COMMIT;
Info->Protect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Attributes;
Info->Protect = MemoryArea->Protect;
Info->AllocationProtect = MemoryArea->Protect;
Info->BaseAddress = MemoryArea->StartingAddress;
Info->AllocationBase = MemoryArea->StartingAddress;
Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress -
@ -222,8 +222,8 @@ MiQueryVirtualMemory (IN HANDLE ProcessHandle,
case MEMORY_AREA_KERNEL_STACK:
Info->Type = 0;
Info->State = MEM_COMMIT;
Info->Protect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Attributes;
Info->Protect = MemoryArea->Protect;
Info->AllocationProtect = MemoryArea->Protect;
Info->BaseAddress = MemoryArea->StartingAddress;
Info->AllocationBase = MemoryArea->StartingAddress;
Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress -
@ -234,8 +234,8 @@ MiQueryVirtualMemory (IN HANDLE ProcessHandle,
case MEMORY_AREA_PAGED_POOL:
Info->Type = 0;
Info->State = MEM_COMMIT;
Info->Protect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Attributes;
Info->Protect = MemoryArea->Protect;
Info->AllocationProtect = MemoryArea->Protect;
Info->BaseAddress = MemoryArea->StartingAddress;
Info->AllocationBase = MemoryArea->StartingAddress;
Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress -

View File

@ -144,15 +144,14 @@ STDCALL
BoundaryAddressMultiple.QuadPart = 0;
StackSize = PAGE_ROUND_UP(StackSize);
MmLockAddressSpace(MmGetKernelAddressSpace());
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_KERNEL_STACK,
&KernelStack,
StackSize,
0,
PAGE_READWRITE,
&StackArea,
FALSE,
FALSE,
0,
BoundaryAddressMultiple);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status))