Author: ion Date: Sun Sep 2 18:03:14 2012 New Revision: 57220
URL: http://svn.reactos.org/svn/reactos?rev=57220&view=rev Log: [NTOSKRNL]: Restore the protect hack, maybe it's not as no-op as it seems.
Modified: trunk/reactos/ntoskrnl/mm/ARM3/virtual.c
Modified: trunk/reactos/ntoskrnl/mm/ARM3/virtual.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/virtual.c?... ============================================================================== --- trunk/reactos/ntoskrnl/mm/ARM3/virtual.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/ARM3/virtual.c [iso-8859-1] Sun Sep 2 18:03:14 2012 @@ -1827,6 +1827,46 @@
NTSTATUS NTAPI +MiRosProtectVirtualMemory(IN PEPROCESS Process, + IN OUT PVOID *BaseAddress, + IN OUT PSIZE_T NumberOfBytesToProtect, + IN ULONG NewAccessProtection, + OUT PULONG OldAccessProtection OPTIONAL) +{ + PMEMORY_AREA MemoryArea; + PMMSUPPORT AddressSpace; + ULONG OldAccessProtection_; + NTSTATUS Status; + + *NumberOfBytesToProtect = PAGE_ROUND_UP((ULONG_PTR)(*BaseAddress) + (*NumberOfBytesToProtect)) - PAGE_ROUND_DOWN(*BaseAddress); + *BaseAddress = (PVOID)PAGE_ROUND_DOWN(*BaseAddress); + + AddressSpace = &Process->Vm; + MmLockAddressSpace(AddressSpace); + MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, *BaseAddress); + if (MemoryArea == NULL || MemoryArea->DeleteInProgress) + { + MmUnlockAddressSpace(AddressSpace); + return STATUS_UNSUCCESSFUL; + } + + if (OldAccessProtection == NULL) OldAccessProtection = &OldAccessProtection_; + + ASSERT(MemoryArea->Type == MEMORY_AREA_SECTION_VIEW); + Status = MmProtectSectionView(AddressSpace, + MemoryArea, + *BaseAddress, + *NumberOfBytesToProtect, + NewAccessProtection, + OldAccessProtection); + + MmUnlockAddressSpace(AddressSpace); + + return Status; +} + +NTSTATUS +NTAPI MiProtectVirtualMemory(IN PEPROCESS Process, IN OUT PVOID *BaseAddress, IN OUT PSIZE_T NumberOfBytesToProtect, @@ -1856,6 +1896,18 @@ DPRINT1("Invalid protection mask\n"); return STATUS_INVALID_PAGE_PROTECTION; } + + /* Check for ROS specific memory area */ + MemoryArea = MmLocateMemoryAreaByAddress(&Process->Vm, *BaseAddress); + if ((MemoryArea) && (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW)) + { + /* Evil hack */ + return MiRosProtectVirtualMemory(Process, + BaseAddress, + NumberOfBytesToProtect, + NewAccessProtection, + OldAccessProtection); + }
/* Lock the address space and make sure the process isn't already dead */ AddressSpace = MmGetCurrentAddressSpace(); @@ -1902,15 +1954,6 @@ DPRINT1("Trying to change protection of a NoChange VAD\n"); Status = STATUS_INVALID_PAGE_PROTECTION; goto FailPath; - } - - /* Check for ROS specific memory area */ - MemoryArea = MmLocateMemoryAreaByAddress(&Process->Vm, *BaseAddress); - if ((MemoryArea) && (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW)) - { - /* Empirical evidence suggests this is only used in one critical scenario and is always a no-op */ - OldProtect = NewAccessProtection; - goto RosReturn; }
/* Is this section, or private memory? */ @@ -2064,7 +2107,7 @@ /* Unlock the working set */ //MiUnlockProcessWorkingSet(Thread, Process); } -RosReturn: + /* Unlock the address space */ MmUnlockAddressSpace(AddressSpace);
@@ -3809,7 +3852,7 @@ Status = STATUS_INVALID_PARAMETER; goto FailPathNoLock; } - if ((AllocationType & MEM_PHYSICAL) ==MEM_PHYSICAL) + if ((AllocationType & MEM_PHYSICAL) == MEM_PHYSICAL) { DPRINT1("MEM_PHYSICAL not supported\n"); Status = STATUS_INVALID_PARAMETER;