Author: ros-arm-bringup Date: Fri Aug 15 20:58:59 2008 New Revision: 35364
URL: http://svn.reactos.org/svn/reactos?rev=35364&view=rev Log: Implement InterlockedComparePte and InterlockedCompareExchangePte to: 1) Avoid all the casting currently being done 2) Allow portability with other platforms so that the code can be potentially shared later.
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h trunk/reactos/ntoskrnl/mm/i386/page.c
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/m... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] Fri Aug 15 20:58:59 2008 @@ -163,6 +163,13 @@ #define PAGE_IS_WRITECOPY \ (PAGE_WRITECOPY | \ PAGE_EXECUTE_WRITECOPY) + + +#define InterlockedCompareExchangePte(PointerPte, Exchange, Comperand) \ + InterlockedCompareExchange((PLONG)(PointerPte), Exchange, Comperand) + +#define InterlockedExchangePte(PointerPte, Value) \ + InterlockedExchange((PLONG)(PointerPte), Value)
typedef struct {
Modified: trunk/reactos/ntoskrnl/mm/i386/page.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/i386/page.c?rev... ============================================================================== --- trunk/reactos/ntoskrnl/mm/i386/page.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/i386/page.c [iso-8859-1] Fri Aug 15 20:58:59 2008 @@ -331,7 +331,7 @@ { KEBUGCHECK(0); } - if (0 == InterlockedCompareExchangeUL(&PageDir[PdeOffset], 0, 0)) + if (0 == InterlockedCompareExchangePte(&PageDir[PdeOffset], 0, 0)) { if (Create == FALSE) { @@ -343,7 +343,7 @@ { KEBUGCHECK(0); } - Entry = InterlockedCompareExchangeUL(&PageDir[PdeOffset], PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0); + Entry = InterlockedCompareExchangePte(&PageDir[PdeOffset], PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0); if (Entry != 0) { MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn); @@ -363,11 +363,11 @@ return Pt + ADDR_TO_PTE_OFFSET(Address); } PageDir = (PULONG)MiAddressToPde(Address); - if (0 == InterlockedCompareExchangeUL(PageDir, 0, 0)) + if (0 == InterlockedCompareExchangePte(PageDir, 0, 0)) { if (Address >= MmSystemRangeStart) { - if (0 == InterlockedCompareExchangeUL(&MmGlobalKernelPageDirectory[PdeOffset], 0, 0)) + if (0 == InterlockedCompareExchangePte(&MmGlobalKernelPageDirectory[PdeOffset], 0, 0)) { if (Create == FALSE) { @@ -383,12 +383,12 @@ { Entry |= PA_GLOBAL; } - if(0 != InterlockedCompareExchangeUL(&MmGlobalKernelPageDirectory[PdeOffset], Entry, 0)) + if(0 != InterlockedCompareExchangePte(&MmGlobalKernelPageDirectory[PdeOffset], Entry, 0)) { MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn); } } - (void)InterlockedExchangeUL(PageDir, MmGlobalKernelPageDirectory[PdeOffset]); + InterlockedExchangePte(PageDir, MmGlobalKernelPageDirectory[PdeOffset]); } else { @@ -401,7 +401,7 @@ { KEBUGCHECK(0); } - Entry = InterlockedCompareExchangeUL(PageDir, PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0); + Entry = InterlockedCompareExchangePte(PageDir, PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0); if (Entry != 0) { MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn); @@ -476,7 +476,7 @@ do { Pte = *Pt; - } while (Pte != InterlockedCompareExchangeUL(Pt, Pte & ~PA_PRESENT, Pte)); + } while (Pte != InterlockedCompareExchangePte(Pt, Pte & ~PA_PRESENT, Pte));
MiFlushTlb(Pt, Address); WasValid = (PAGE_MASK(Pte) != 0); @@ -510,7 +510,7 @@ /* * Set the entry to zero */ - (void)InterlockedExchangeUL(Pt, 0); + InterlockedExchangePte(Pt, 0); MiFlushTlb(Pt, Address); } } @@ -549,7 +549,7 @@ /* * Atomically set the entry to zero and get the old value. */ - Pte = InterlockedExchangeUL(Pt, 0); + Pte = InterlockedExchangePte(Pt, 0);
MiFlushTlb(Pt, Address);
@@ -604,7 +604,7 @@ /* * Atomically set the entry to zero and get the old value. */ - Pte = InterlockedExchangeUL(Pt, 0); + Pte = InterlockedExchangePte(Pt, 0);
MiFlushTlb(Pt, Address);
@@ -659,7 +659,7 @@ do { Pte = *Pt; - } while (Pte != InterlockedCompareExchangeUL(Pt, Pte & ~PA_ACCESSED, Pte)); + } while (Pte != InterlockedCompareExchangePte(Pt, Pte & ~PA_ACCESSED, Pte));
if (Pte & PA_ACCESSED) { @@ -696,7 +696,7 @@ do { Pte = *Pt; - } while (Pte != InterlockedCompareExchangeUL(Pt, Pte & ~PA_DIRTY, Pte)); + } while (Pte != InterlockedCompareExchangePte(Pt, Pte & ~PA_DIRTY, Pte));
if (Pte & PA_DIRTY) { @@ -730,7 +730,7 @@ do { Pte = *Pt; - } while (Pte != InterlockedCompareExchangeUL(Pt, Pte | PA_DIRTY, Pte)); + } while (Pte != InterlockedCompareExchangePte(Pt, Pte | PA_DIRTY, Pte)); if (!(Pte & PA_DIRTY)) { MiFlushTlb(Pt, Address); @@ -757,7 +757,7 @@ do { Pte = *Pt; - } while (Pte != InterlockedCompareExchangeUL(Pt, Pte | PA_PRESENT, Pte)); + } while (Pte != InterlockedCompareExchangePte(Pt, Pte | PA_PRESENT, Pte)); if (!(Pte & PA_PRESENT)) { MiFlushTlb(Pt, Address); @@ -859,7 +859,7 @@ { KEBUGCHECK(0); } - (void)InterlockedExchangeUL(Pt, PFN_TO_PTE(Pages[i]) | Attributes); + InterlockedExchangePte(Pt, PFN_TO_PTE(Pages[i]) | Attributes); }
return(STATUS_SUCCESS); @@ -899,7 +899,7 @@ { MmMarkPageUnmapped(PTE_TO_PFN((Pte))); } - (void)InterlockedExchangeUL(Pt, SwapEntry << 1); + InterlockedExchangePte(Pt, SwapEntry << 1); if (Pte != 0) { MiFlushTlb(Pt, Address); @@ -1018,7 +1018,7 @@ { MmMarkPageUnmapped(PTE_TO_PFN((Pte))); } - (void)InterlockedExchangeUL(Pt, PFN_TO_PTE(Pages[i]) | Attributes); + InterlockedExchangePte(Pt, PFN_TO_PTE(Pages[i]) | Attributes); if (Pte != 0) { if (Address > MmSystemRangeStart || @@ -1138,7 +1138,7 @@ { KEBUGCHECK(0); } - InterlockedExchange((PLONG)Pt, PAGE_MASK(*Pt) | Attributes | (*Pt & (PA_ACCESSED|PA_DIRTY))); + InterlockedExchangePte(Pt, PAGE_MASK(*Pt) | Attributes | (*Pt & (PA_ACCESSED|PA_DIRTY))); MiFlushTlb(Pt, Address); }
@@ -1243,7 +1243,7 @@
ASSERT (IS_HYPERSPACE(Address));
- Entry = InterlockedExchange((PLONG)MiAddressToPte(Address), PFN_TO_PTE(NewPage) | PA_PRESENT | PA_READWRITE); + Entry = InterlockedExchangePte(MiAddressToPte(Address), PFN_TO_PTE(NewPage) | PA_PRESENT | PA_READWRITE); Pfn = PTE_TO_PFN(Entry);
__invlpg(Address); @@ -1259,7 +1259,7 @@
ASSERT (IS_HYPERSPACE(Address));
- Entry = InterlockedExchange((PLONG)MiAddressToPte(Address), 0); + Entry = InterlockedExchangePte(MiAddressToPte(Address), 0); Pfn = PTE_TO_PFN(Entry);
__invlpg(Address); @@ -1293,7 +1293,7 @@ { if (Offset != ADDR_TO_PDE_OFFSET(PAGETABLE_MAP)) { - (void)InterlockedCompareExchangeUL(&Pde[Offset], MmGlobalKernelPageDirectory[Offset], 0); + InterlockedCompareExchangePte(&Pde[Offset], MmGlobalKernelPageDirectory[Offset], 0); } } if (Pde != (PULONG)PAGEDIRECTORY_MAP)