Author: jgardou
Date: Tue Feb 17 15:08:47 2015
New Revision: 66336
URL:
http://svn.reactos.org/svn/reactos?rev=66336&view=rev
Log:
[RTL/DPH]
- Do not merge memory blocks if they don't belong to the same VM "region"
(ie not allocated from the same NtAllocateVirtualMemory call)
Fixes failures of ZwProtectVirtualMemory calls.
Bugs see DPH rollin', they hatin'
Modified:
trunk/reactos/lib/rtl/heappage.c
Modified: trunk/reactos/lib/rtl/heappage.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/heappage.c?rev=663…
==============================================================================
--- trunk/reactos/lib/rtl/heappage.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/heappage.c [iso-8859-1] Tue Feb 17 15:08:47 2015
@@ -691,12 +691,35 @@
/* Check the previous node and merge if possible */
if (PrevNode->pVirtualBlock + PrevNode->nVirtualBlockSize ==
Node->pVirtualBlock)
{
- /* They are adjacent - merge! */
- PrevNode->nVirtualBlockSize += Node->nVirtualBlockSize;
- RtlpDphReturnNodeToUnusedList(DphRoot, Node);
- DphRoot->nAvailableAllocations--;
-
- Node = PrevNode;
+ /* Check they actually belong to the same virtual memory block */
+ NTSTATUS Status;
+ MEMORY_BASIC_INFORMATION MemoryBasicInfo;
+
+ Status = ZwQueryVirtualMemory(
+ ZwCurrentProcess(),
+ Node->pVirtualBlock,
+ MemoryBasicInformation,
+ &MemoryBasicInfo,
+ sizeof(MemoryBasicInfo),
+ NULL);
+
+ /* There is no way this can fail, we committed this memory! */
+ ASSERT(NT_SUCCESS(Status));
+
+ if ((PUCHAR)MemoryBasicInfo.AllocationBase <= PrevNode->pVirtualBlock)
+ {
+ /* They are adjacent, and from the same VM region. - merge! */
+ PrevNode->nVirtualBlockSize += Node->nVirtualBlockSize;
+ RtlpDphReturnNodeToUnusedList(DphRoot, Node);
+ DphRoot->nAvailableAllocations--;
+
+ Node = PrevNode;
+ }
+ else
+ {
+ /* Insert after PrevNode */
+ InsertTailList(&PrevNode->AvailableEntry,
&Node->AvailableEntry);
+ }
}
else
{
@@ -711,13 +734,31 @@
/* Node is not at the tail of the list, check if it's adjacent */
if (Node->pVirtualBlock + Node->nVirtualBlockSize ==
NextNode->pVirtualBlock)
{
- /* They are adjacent - merge! */
- Node->nVirtualBlockSize += NextNode->nVirtualBlockSize;
-
- /* Remove next entry from the list and put it into unused entries list
*/
- RemoveEntryList(&NextNode->AvailableEntry);
- RtlpDphReturnNodeToUnusedList(DphRoot, NextNode);
- DphRoot->nAvailableAllocations--;
+ /* Check they actually belong to the same virtual memory block */
+ NTSTATUS Status;
+ MEMORY_BASIC_INFORMATION MemoryBasicInfo;
+
+ Status = ZwQueryVirtualMemory(
+ ZwCurrentProcess(),
+ NextNode->pVirtualBlock,
+ MemoryBasicInformation,
+ &MemoryBasicInfo,
+ sizeof(MemoryBasicInfo),
+ NULL);
+
+ /* There is no way this can fail, we committed this memory! */
+ ASSERT(NT_SUCCESS(Status));
+
+ if ((PUCHAR)MemoryBasicInfo.AllocationBase <= Node->pVirtualBlock)
+ {
+ /* They are adjacent - merge! */
+ Node->nVirtualBlockSize += NextNode->nVirtualBlockSize;
+
+ /* Remove next entry from the list and put it into unused entries
list */
+ RemoveEntryList(&NextNode->AvailableEntry);
+ RtlpDphReturnNodeToUnusedList(DphRoot, NextNode);
+ DphRoot->nAvailableAllocations--;
+ }
}
}
}