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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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