From 0b387721846fd334c56c8d12963faaaa884d2889 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 9 May 2009 09:54:50 +0000 Subject: [PATCH] - MmProtectAnonMem: Search all Regions in Memory Area up to Length for MEM_COMMIT prior to altering memory protection. Fixes 6 kernel32_winetest for virtual memory. svn path=/trunk/; revision=40857 --- reactos/ntoskrnl/mm/anonmem.c | 46 ++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/reactos/ntoskrnl/mm/anonmem.c b/reactos/ntoskrnl/mm/anonmem.c index 1c4f1eb4e93..c41a67449c8 100644 --- a/reactos/ntoskrnl/mm/anonmem.c +++ b/reactos/ntoskrnl/mm/anonmem.c @@ -1034,26 +1034,48 @@ MmProtectAnonMem(PMMSUPPORT AddressSpace, PULONG OldProtect) { PMM_REGION Region; - NTSTATUS Status; + NTSTATUS Status = STATUS_SUCCESS; + ULONG LengthCount = 0; - Region = MmFindRegion(MemoryArea->StartingAddress, - &MemoryArea->Data.VirtualMemoryData.RegionListHead, - BaseAddress, NULL); - if (Region->Type == MEM_COMMIT) + /* Search all Regions in MemoryArea up to Length */ + /* Every Region up to Length must be committed for success */ + for (;;) + { + Region = MmFindRegion(MemoryArea->StartingAddress, + &MemoryArea->Data.VirtualMemoryData.RegionListHead, + (PVOID)((ULONG_PTR)BaseAddress + (ULONG_PTR)LengthCount), NULL); + + /* If a Region was found and it is committed */ + if ((Region) && (Region->Type == MEM_COMMIT)) + { + LengthCount += Region->Length; + if (Length <= LengthCount) break; + continue; + } + /* If Region was found and it is not commited */ + else if (Region) + { + Status = STATUS_NOT_COMMITTED; + break; + } + /* If no Region was found at all */ + else if (LengthCount == 0) + { + Status = STATUS_INVALID_ADDRESS; + break; + } + } + + if (NT_SUCCESS(Status)) { - /* FIXME: check if the whole range is committed - * before altering the memory */ *OldProtect = Region->Protect; Status = MmAlterRegion(AddressSpace, MemoryArea->StartingAddress, &MemoryArea->Data.VirtualMemoryData.RegionListHead, BaseAddress, Length, Region->Type, Protect, MmModifyAttributes); } - else - { - Status = STATUS_NOT_COMMITTED; - } - return(Status); + + return (Status); } NTSTATUS NTAPI