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--;
+ }
}
}
}
Author: jgardou
Date: Tue Feb 17 14:19:05 2015
New Revision: 66334
URL: http://svn.reactos.org/svn/reactos?rev=66334&view=rev
Log:
[NTOSKRNL/MM]
- MiIsEntireRangeCommitted: Ensure the PTE we are checking is really faulted in.
- Prefer MiPteToPde and MiPdeToPte (which should really be called MiFirstPteInPde) instead of MiAddressToPte and MiPteToAddress
Fixes weird failed ASSERT in page fault handler when using DPH.
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] Tue Feb 17 14:19:05 2015
@@ -1994,14 +1994,13 @@
if (OnBoundary)
{
/* Is this PDE demand zero? */
- PointerPde = MiAddressToPte(PointerPte);
+ PointerPde = MiPteToPde(PointerPte);
if (PointerPde->u.Long != 0)
{
/* It isn't -- is it valid? */
if (PointerPde->u.Hard.Valid == 0)
{
/* Nope, fault it in */
- PointerPte = MiPteToAddress(PointerPde);
MiMakeSystemAddressValid(PointerPte, Process);
}
}
@@ -2009,13 +2008,13 @@
{
/* The PTE was already valid, so move to the next one */
PointerPde++;
- PointerPte = MiPteToAddress(PointerPde);
+ PointerPte = MiPdeToPte(PointerPde);
/* Is the entire VAD committed? If not, fail */
if (!Vad->u.VadFlags.MemCommit) return FALSE;
- /* Everything is committed so far past the range, return true */
- if (PointerPte > LastPte) return TRUE;
+ /* New loop iteration with our new, on-boundary PTE. */
+ continue;
}
}