- Changed the 9th parameter of MmCreateMemoryArea to allocation flags.
- Implemented SEC_NO_CHANGE.
svn path=/trunk/; revision=19208
#else
MmLockAddressSpace(MmGetKernelAddressSpace());
current->BaseAddress = NULL;
- Status = MmCreateMemoryArea(NULL,
- MmGetKernelAddressSpace(),
+ Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_CACHE_SEGMENT,
¤t->BaseAddress,
Bcb->CacheSegmentSize,
PAGE_READWRITE,
(PMEMORY_AREA*)¤t->MemoryArea,
FALSE,
- FALSE,
+ 0,
BoundaryAddressMultiple);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status))
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))
struct _MEMORY_AREA *LeftChild;
struct _MEMORY_AREA *RightChild;
ULONG Type;
- ULONG Attributes;
+ ULONG Protect;
+ ULONG Flags;
ULONG LockCount;
BOOLEAN DeleteInProgress;
ULONG PageOpCount;
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
);
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))
}
}
- 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))
{
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;
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());
{
MmCreateVirtualMapping(NULL,
(char*)BaseAddress + (i * PAGE_SIZE),
- Attributes,
+ Protect,
&PBase,
1);
}
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))
{
MEMORY_AREA* marea;
NTSTATUS Status;
ULONG i;
- ULONG Attributes;
+ ULONG Protect;
PHYSICAL_ADDRESS BoundaryAddressMultiple;
PFN_TYPE Pfn;
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());
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))
}
/**
- * @name MmIterateFirstNode
+ * @name MmIterateLastNode
*
* @param Node
* Head node of the MEMORY_AREA tree.
}
/**
- * @name MmIterateNextNode
+ * @name MmIteratePreviousNode
*
* @param Node
* Current node in the tree.
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");
*/
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;
*BaseAddress = MmFindGap(AddressSpace,
tmpLength,
Granularity,
- TopDown != 0);
+ (AllocationFlags & MEM_TOP_DOWN) == MEM_TOP_DOWN);
if ((*BaseAddress) == 0)
{
DPRINT("No suitable gap\n");
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;
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))
{
/* 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;
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))
/* 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,
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;
* 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__));
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__)) -
* 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();
*/
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;
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());
{
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;
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &NPage);
MmCreateVirtualMapping (NULL,
(char*)Result + (i * PAGE_SIZE),
- Attributes,
+ Protect,
&NPage,
1);
}
*/
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);
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 */
/* 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))
{
/* 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))
{
/* 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))
{
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to map process Image\n");
- goto exit;
+ return Status;
}
/* Save the pointer */
{
Status = MmCreateVirtualMapping(AddressSpace->Process,
Address,
- MemoryArea->Attributes,
+ MemoryArea->Protect,
&Page,
1);
MmSetDirtyPage(AddressSpace->Process, Address);
*/
Status = MmCreateVirtualMapping(AddressSpace->Process,
Address,
- MemoryArea->Attributes,
+ MemoryArea->Protect,
&Page,
1);
MmSetDirtyPage(AddressSpace->Process, Address);
{
Status = MmCreateVirtualMapping(AddressSpace->Process,
Address,
- MemoryArea->Attributes,
+ MemoryArea->Protect,
&Page,
1);
MmSetDirtyPage(AddressSpace->Process, Address);
{
Status = MmCreateVirtualMapping(AddressSpace->Process,
Address,
- MemoryArea->Attributes,
+ MemoryArea->Protect,
&Page,
1);
MmSetDirtyPage(AddressSpace->Process, Address);
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,
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;
}
}
- /*
- * Check the protection
- */
- if ((SectionPageProtection & PAGE_FLAGS_VALID_FROM_USER_MODE) !=
- SectionPageProtection)
- {
- return(STATUS_INVALID_PAGE_PROTECTION);
- }
-
Status = MmCreateSection(&SectionObject,
DesiredAccess,
ObjectAttributes,
}
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;
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))
{
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;
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();
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);
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)
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))
{
}
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 */
}
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))
{
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);
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,
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 -
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 -
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 -
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 -
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 -
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))