IN BOOLEAN GuiStack)
{
PMMPTE PointerPte;
- PFN_NUMBER StackPages;
+ PFN_NUMBER StackPages, PageFrameNumber;//, PageTableFrameNumber;
+ PMMPFN Pfn1;//, Pfn2;
ULONG i;
+ KIRQL OldIrql;
//
// This should be the guard page, so decrement by one
StackPages = BYTES_TO_PAGES(GuiStack ?
KERNEL_LARGE_STACK_SIZE : KERNEL_STACK_SIZE);
+ /* Acquire the PFN lock */
+ OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
+
//
// Loop them
//
//
if (PointerPte->u.Hard.Valid == 1)
{
- //
- // Nuke it
- //
- MmReleasePageMemoryConsumer(MC_NPPOOL, PFN_FROM_PTE(PointerPte));
+ /* Get the PTE's page */
+ PageFrameNumber = PFN_FROM_PTE(PointerPte);
+ Pfn1 = MiGetPfnEntry(PageFrameNumber);
+#if 0 // ARM3 might not own the page table, so don't take this risk. Leak it instead!
+ /* Now get the page of the page table mapping it */
+ PageTableFrameNumber = Pfn1->u4.PteFrame;
+ Pfn2 = MiGetPfnEntry(PageTableFrameNumber);
+
+ /* Remove a shared reference, since the page is going away */
+ MiDecrementShareCount(Pfn2, PageTableFrameNumber);
+#endif
+ /* Set the special pending delete marker */
+ Pfn1->PteAddress = (PMMPTE)((ULONG_PTR)Pfn1->PteAddress | 1);
+
+ /* And now delete the actual stack page */
+ MiDecrementShareCount(Pfn1, PageFrameNumber);
}
//
//
ASSERT(PointerPte->u.Hard.Valid == 0);
+ /* Release the PFN lock */
+ KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
+
//
// Release the PTEs
//
PFN_NUMBER StackPtes, StackPages;
PMMPTE PointerPte, StackPte;
PVOID BaseAddress;
- MMPTE TempPte;
+ MMPTE TempPte, InvalidPte;
KIRQL OldIrql;
PFN_NUMBER PageFrameIndex;
ULONG i;
if (GuiStack) PointerPte += BYTES_TO_PAGES(KERNEL_LARGE_STACK_SIZE -
KERNEL_LARGE_STACK_COMMIT);
- //
- // Setup the template stack PTE
- //
- TempPte = HyperTemplatePte;
- MI_MAKE_LOCAL_PAGE(&TempPte);
- MI_MAKE_DIRTY_PAGE(&TempPte);
- TempPte.u.Hard.PageFrameNumber = 0;
+
+ /* Setup the temporary invalid PTE */
+ MI_MAKE_SOFTWARE_PTE(&InvalidPte, MM_NOACCESS);
+
+ /* Setup the template stack PTE */
+ MI_MAKE_HARDWARE_PTE(&TempPte, PointerPte + 1, MM_READWRITE, 0);
//
// Acquire the PFN DB lock
// Next PTE
//
PointerPte++;
- ASSERT(PointerPte->u.Hard.Valid == 0);
- //
- // Get a page
- //
- PageFrameIndex = MmAllocPage(MC_NPPOOL, 0);
- TempPte.u.Hard.PageFrameNumber = PageFrameIndex;
+ /* Get a page and write the current invalid PTE */
+ PageFrameIndex = MiRemoveAnyPage(0);
+ MI_WRITE_INVALID_PTE(PointerPte, InvalidPte);
+
+ /* Initialize the PFN entry for this page */
+ MiInitializePfn(PageFrameIndex, PointerPte, 1);
- //
- // Write it
- //
- *PointerPte = TempPte;
+ /* Write the valid PTE */
+ TempPte.u.Hard.PageFrameNumber = PageFrameIndex;
+ MI_WRITE_VALID_PTE(PointerPte, TempPte);
}
// Bug #4835
PMMPTE LimitPte, NewLimitPte, LastPte;
PFN_NUMBER StackPages;
KIRQL OldIrql;
- MMPTE TempPte;
+ MMPTE TempPte, InvalidPte;
PFN_NUMBER PageFrameIndex;
//
LimitPte--;
StackPages = (LimitPte - NewLimitPte + 1);
- //
- // Setup the template stack PTE
- //
- TempPte = HyperTemplatePte;
- MI_MAKE_LOCAL_PAGE(&TempPte);
- MI_MAKE_DIRTY_PAGE(&TempPte);
- TempPte.u.Hard.PageFrameNumber = 0;
+ /* Setup the temporary invalid PTE */
+ MI_MAKE_SOFTWARE_PTE(&InvalidPte, MM_NOACCESS);
//
// Acquire the PFN DB lock
//
OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
-
+
//
// Loop each stack page
//
while (LimitPte >= NewLimitPte)
{
- //
- // Sanity check
- //
- ASSERT(LimitPte->u.Hard.Valid == 0);
+ /* Get a page and write the current invalid PTE */
+ PageFrameIndex = MiRemoveAnyPage(0);
+ MI_WRITE_INVALID_PTE(LimitPte, InvalidPte);
+
+ /* Initialize the PFN entry for this page */
+ MiInitializePfn(PageFrameIndex, LimitPte, 1);
- //
- // Get a page
- //
- PageFrameIndex = MmAllocPage(MC_NPPOOL, 0);
- TempPte.u.Hard.PageFrameNumber = PageFrameIndex;
+ /* Setup the template stack PTE */
+ MI_MAKE_HARDWARE_PTE(&TempPte, LimitPte, MM_READWRITE, PageFrameIndex);
- //
- // Write it
- //
- *LimitPte-- = TempPte;
+ /* Write the valid PTE */
+ MI_WRITE_VALID_PTE(LimitPte--, TempPte);
}
//
ImageConfigData = RtlImageDirectoryEntryToData(Peb->ImageBaseAddress,
TRUE,
IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG,
- &ViewSize);
+ (PULONG)&ViewSize);
if (ImageConfigData)
{
//
//
// Write subsystem data
//
- Peb->ImageSubSystem = NtHeaders->OptionalHeader.Subsystem;
- Peb->ImageSubSystemMajorVersion = NtHeaders->OptionalHeader.MajorSubsystemVersion;
- Peb->ImageSubSystemMinorVersion = NtHeaders->OptionalHeader.MinorSubsystemVersion;
+ Peb->ImageSubsystem = NtHeaders->OptionalHeader.Subsystem;
+ Peb->ImageSubsystemMajorVersion = NtHeaders->OptionalHeader.MajorSubsystemVersion;
+ Peb->ImageSubsystemMinorVersion = NtHeaders->OptionalHeader.MinorSubsystemVersion;
//
// Check for version data
//
// Set TIB Data
//
- Teb->Tib.ExceptionList = EXCEPTION_CHAIN_END;
- Teb->Tib.Self = (PNT_TIB)Teb;
+ Teb->NtTib.ExceptionList = EXCEPTION_CHAIN_END;
+ Teb->NtTib.Self = (PNT_TIB)Teb;
//
// Identify this as an OS/2 V3.0 ("Cruiser") TIB
//
- Teb->Tib.Version = 30 << 8;
+ Teb->NtTib.Version = 30 << 8;
//
// Set TEB Data
//
// Use initial TEB values
//
- Teb->Tib.StackBase = InitialTeb->StackBase;
- Teb->Tib.StackLimit = InitialTeb->StackLimit;
+ Teb->NtTib.StackBase = InitialTeb->StackBase;
+ Teb->NtTib.StackLimit = InitialTeb->StackLimit;
Teb->DeallocationStack = InitialTeb->AllocatedStackBase;
}
else
//
// Use grandparent TEB values
//
- Teb->Tib.StackBase = InitialTeb->PreviousStackBase;
- Teb->Tib.StackLimit = InitialTeb->PreviousStackLimit;
+ Teb->NtTib.StackBase = InitialTeb->PreviousStackBase;
+ Teb->NtTib.StackLimit = InitialTeb->PreviousStackLimit;
}
//