Author: mjmartin Date: Sat May 9 13:54:50 2009 New Revision: 40857
URL: http://svn.reactos.org/svn/reactos?rev=40857&view=rev Log: - 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.
Modified: trunk/reactos/ntoskrnl/mm/anonmem.c
Modified: trunk/reactos/ntoskrnl/mm/anonmem.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/anonmem.c?rev=4... ============================================================================== --- trunk/reactos/ntoskrnl/mm/anonmem.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/anonmem.c [iso-8859-1] Sat May 9 13:54:50 2009 @@ -1034,26 +1034,48 @@ PULONG OldProtect) { PMM_REGION Region; - NTSTATUS Status; - - Region = MmFindRegion(MemoryArea->StartingAddress, - &MemoryArea->Data.VirtualMemoryData.RegionListHead, - BaseAddress, NULL); - if (Region->Type == MEM_COMMIT) - { - /* FIXME: check if the whole range is committed - * before altering the memory */ + NTSTATUS Status = STATUS_SUCCESS; + ULONG LengthCount = 0; + + /* 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)) + { *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