diff --git a/ntoskrnl/mm/ARM3/virtual.c b/ntoskrnl/mm/ARM3/virtual.c index 227879f3d51..1adcbdec1ad 100644 --- a/ntoskrnl/mm/ARM3/virtual.c +++ b/ntoskrnl/mm/ARM3/virtual.c @@ -2153,46 +2153,6 @@ MiIsEntireRangeCommitted(IN ULONG_PTR StartingAddress, return TRUE; } -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, @@ -2254,13 +2214,18 @@ MiProtectVirtualMemory(IN PEPROCESS Process, /* Check if this is a ROSMM VAD */ if (MI_IS_ROSMM_VAD(Vad)) { - /* Not very awesome hack */ + /* Not too shabby hack */ + ASSERT(((PMEMORY_AREA)Vad)->Type == MEMORY_AREA_SECTION_VIEW); + *NumberOfBytesToProtect = PAGE_ROUND_UP((ULONG_PTR)(*BaseAddress) + (*NumberOfBytesToProtect)) - PAGE_ROUND_DOWN(*BaseAddress); + *BaseAddress = (PVOID)PAGE_ROUND_DOWN(*BaseAddress); + Status = MmProtectSectionView(AddressSpace, + (PMEMORY_AREA)Vad, + *BaseAddress, + *NumberOfBytesToProtect, + NewAccessProtection, + OldAccessProtection); MmUnlockAddressSpace(AddressSpace); - return MiRosProtectVirtualMemory(Process, - BaseAddress, - NumberOfBytesToProtect, - NewAccessProtection, - OldAccessProtection); + return Status; } /* Make sure the address is within this VAD's boundaries */ diff --git a/ntoskrnl/mm/section.c b/ntoskrnl/mm/section.c index 9adcd6f3a86..abd27e1423f 100644 --- a/ntoskrnl/mm/section.c +++ b/ntoskrnl/mm/section.c @@ -2076,6 +2076,13 @@ MmProtectSectionView(PMMSUPPORT AddressSpace, NTSTATUS Status; ULONG_PTR MaxLength; + ASSERT(MemoryArea->Type == MEMORY_AREA_SECTION_VIEW); + + if (MemoryArea->DeleteInProgress) + { + return STATUS_UNSUCCESSFUL; + } + MaxLength = MA_GetEndingAddress(MemoryArea) - (ULONG_PTR)BaseAddress; if (Length > MaxLength) Length = (ULONG)MaxLength; @@ -2091,7 +2098,8 @@ MmProtectSectionView(PMMSUPPORT AddressSpace, return STATUS_INVALID_PAGE_PROTECTION; } - *OldProtect = Region->Protect; + if (OldProtect != NULL) + *OldProtect = Region->Protect; Status = MmAlterRegion(AddressSpace, (PVOID)MA_GetStartingAddress(MemoryArea), &MemoryArea->SectionData.RegionListHead, BaseAddress, Length, Region->Type, Protect,