- Removed the process from the parameter list of MmCreateMemoryArea. - Changed the 9th parameter of MmCreateMemoryArea to allocation flags. - Implemented SEC_NO_CHANGE. Modified: trunk/reactos/ntoskrnl/cc/view.c Modified: trunk/reactos/ntoskrnl/include/internal/mm.h Modified: trunk/reactos/ntoskrnl/ke/usercall.c Modified: trunk/reactos/ntoskrnl/mm/anonmem.c Modified: trunk/reactos/ntoskrnl/mm/cont.c Modified: trunk/reactos/ntoskrnl/mm/i386/page.c Modified: trunk/reactos/ntoskrnl/mm/iospace.c Modified: trunk/reactos/ntoskrnl/mm/marea.c Modified: trunk/reactos/ntoskrnl/mm/mdl.c Modified: trunk/reactos/ntoskrnl/mm/mminit.c Modified: trunk/reactos/ntoskrnl/mm/ncache.c Modified: trunk/reactos/ntoskrnl/mm/process.c Modified: trunk/reactos/ntoskrnl/mm/section.c Modified: trunk/reactos/ntoskrnl/mm/virtual.c Modified: trunk/reactos/ntoskrnl/ps/win32.c _____
Modified: trunk/reactos/ntoskrnl/cc/view.c --- trunk/reactos/ntoskrnl/cc/view.c 2005-11-13 14:15:08 UTC (rev 19207) +++ trunk/reactos/ntoskrnl/cc/view.c 2005-11-13 17:28:24 UTC (rev 19208) @@ -657,15 +657,14 @@
#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)) @@ -1366,15 +1365,14 @@
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)) _____
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h --- trunk/reactos/ntoskrnl/include/internal/mm.h 2005-11-13 14:15:08 UTC (rev 19207) +++ trunk/reactos/ntoskrnl/include/internal/mm.h 2005-11-13 17:28:24 UTC (rev 19208) @@ -215,7 +215,8 @@
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 @@ 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 );
_____
Modified: trunk/reactos/ntoskrnl/ke/usercall.c --- trunk/reactos/ntoskrnl/ke/usercall.c 2005-11-13 14:15:08 UTC (rev 19207) +++ trunk/reactos/ntoskrnl/ke/usercall.c 2005-11-13 17:28:24 UTC (rev 19208) @@ -108,15 +108,14 @@
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)) _____
Modified: trunk/reactos/ntoskrnl/mm/anonmem.c --- trunk/reactos/ntoskrnl/mm/anonmem.c 2005-11-13 14:15:08 UTC (rev 19207) +++ trunk/reactos/ntoskrnl/mm/anonmem.c 2005-11-13 17:28:24 UTC (rev 19208) @@ -727,15 +727,14 @@
} }
- 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 @@ 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; _____
Modified: trunk/reactos/ntoskrnl/mm/cont.c --- trunk/reactos/ntoskrnl/mm/cont.c 2005-11-13 14:15:08 UTC (rev 19207) +++ trunk/reactos/ntoskrnl/mm/cont.c 2005-11-13 17:28:24 UTC (rev 19208) @@ -71,29 +71,28 @@
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 @@ { MmCreateVirtualMapping(NULL, (char*)BaseAddress + (i * PAGE_SIZE), - Attributes, + Protect, &PBase, 1); } _____
Modified: trunk/reactos/ntoskrnl/mm/i386/page.c --- trunk/reactos/ntoskrnl/mm/i386/page.c 2005-11-13 14:15:08 UTC (rev 19207) +++ trunk/reactos/ntoskrnl/mm/i386/page.c 2005-11-13 17:28:24 UTC (rev 19208) @@ -2419,30 +2419,28 @@
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)) { _____
Modified: trunk/reactos/ntoskrnl/mm/iospace.c --- trunk/reactos/ntoskrnl/mm/iospace.c 2005-11-13 14:15:08 UTC (rev 19207) +++ trunk/reactos/ntoskrnl/mm/iospace.c 2005-11-13 17:28:24 UTC (rev 19208) @@ -54,7 +54,7 @@
MEMORY_AREA* marea; NTSTATUS Status; ULONG i; - ULONG Attributes; + ULONG Protect; PHYSICAL_ADDRESS BoundaryAddressMultiple; PFN_TYPE Pfn;
@@ -72,17 +72,21 @@ 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, + 0, FALSE, - FALSE, BoundaryAddressMultiple); MmUnlockAddressSpace(MmGetKernelAddressSpace());
@@ -91,16 +95,11 @@ 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)) _____
Modified: trunk/reactos/ntoskrnl/mm/marea.c --- trunk/reactos/ntoskrnl/mm/marea.c 2005-11-13 14:15:08 UTC (rev 19207) +++ trunk/reactos/ntoskrnl/mm/marea.c 2005-11-13 17:28:24 UTC (rev 19208) @@ -105,7 +105,7 @@
}
/** - * @name MmIterateFirstNode + * @name MmIterateLastNode * * @param Node * Head node of the MEMORY_AREA tree. @@ -123,7 +123,7 @@ }
/** - * @name MmIterateNextNode + * @name MmIteratePreviousNode * * @param Node * Current node in the tree. @@ -200,9 +200,9 @@ 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 @@ */
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 @@ *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 @@ 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; _____
Modified: trunk/reactos/ntoskrnl/mm/mdl.c --- trunk/reactos/ntoskrnl/mm/mdl.c 2005-11-13 14:15:08 UTC (rev 19207) +++ trunk/reactos/ntoskrnl/mm/mdl.c 2005-11-13 17:28:24 UTC (rev 19208) @@ -70,15 +70,14 @@
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 @@ /* 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 @@ 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 @@ /* 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, _____
Modified: trunk/reactos/ntoskrnl/mm/mminit.c --- trunk/reactos/ntoskrnl/mm/mminit.c 2005-11-13 14:15:08 UTC (rev 19207) +++ trunk/reactos/ntoskrnl/mm/mminit.c 2005-11-13 17:28:24 UTC (rev 19208) @@ -107,53 +107,49 @@
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 @@ * 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 @@ 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 @@ * 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 @@ */ 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; _____
Modified: trunk/reactos/ntoskrnl/mm/ncache.c --- trunk/reactos/ntoskrnl/mm/ncache.c 2005-11-13 14:15:08 UTC (rev 19207) +++ trunk/reactos/ntoskrnl/mm/ncache.c 2005-11-13 17:28:24 UTC (rev 19208) @@ -48,21 +48,20 @@
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 @@ { 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 @@ Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &NPage); MmCreateVirtualMapping (NULL, (char*)Result + (i * PAGE_SIZE), - Attributes, + Protect, &NPage, 1); } _____
Modified: trunk/reactos/ntoskrnl/mm/process.c --- trunk/reactos/ntoskrnl/mm/process.c 2005-11-13 14:15:08 UTC (rev 19207) +++ trunk/reactos/ntoskrnl/mm/process.c 2005-11-13 17:28:24 UTC (rev 19208) @@ -45,15 +45,14 @@
*/ 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 @@ 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 @@
/* 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 @@
/* 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 @@
/* 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 @@ if (!NT_SUCCESS(Status)) { DPRINT1("Failed to map process Image\n"); - goto exit; + return Status; }
/* Save the pointer */ _____
Modified: trunk/reactos/ntoskrnl/mm/section.c --- trunk/reactos/ntoskrnl/mm/section.c 2005-11-13 14:15:08 UTC (rev 19207) +++ trunk/reactos/ntoskrnl/mm/section.c 2005-11-13 17:28:24 UTC (rev 19208) @@ -1605,7 +1605,7 @@
{ Status = MmCreateVirtualMapping(AddressSpace->Process, Address, - MemoryArea->Attributes, + MemoryArea->Protect, &Page, 1); MmSetDirtyPage(AddressSpace->Process, Address); @@ -1622,7 +1622,7 @@ */ Status = MmCreateVirtualMapping(AddressSpace->Process, Address, - MemoryArea->Attributes, + MemoryArea->Protect, &Page, 1); MmSetDirtyPage(AddressSpace->Process, Address); @@ -1656,7 +1656,7 @@ { Status = MmCreateVirtualMapping(AddressSpace->Process, Address, - MemoryArea->Attributes, + MemoryArea->Protect, &Page, 1); MmSetDirtyPage(AddressSpace->Process, Address); @@ -1668,7 +1668,7 @@ { Status = MmCreateVirtualMapping(AddressSpace->Process, Address, - MemoryArea->Attributes, + MemoryArea->Protect, &Page, 1); MmSetDirtyPage(AddressSpace->Process, Address); @@ -1952,6 +1952,13 @@ 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 @@ 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 @@ } }
- /* - * 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 @@ }
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 @@
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 @@ 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,7 +3592,31 @@ 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();
if(PreviousMode != KernelMode) @@ -4285,15 +4302,14 @@ 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 @@
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 @@ 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 @@ } 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_EXEC UTE_READWRITE|PAGE_EXECUTE_WRITECOPY))) + { + CHECKPOINT1; + return STATUS_SECTION_PROTECTION; + } + /* check for execute access */ [truncated at 1000 lines; 154 more skipped]