diff --git a/reactos/ntoskrnl/include/internal/mm.h b/reactos/ntoskrnl/include/internal/mm.h index 4f7037d38cd..4b47d0c9a0e 100644 --- a/reactos/ntoskrnl/include/internal/mm.h +++ b/reactos/ntoskrnl/include/internal/mm.h @@ -235,7 +235,7 @@ MmDeleteVirtualMapping(struct _EPROCESS* Process, BOOL FreePage, BOOL* WasDirty, PHYSICAL_ADDRESS* PhysicalPage); -VOID MmUpdatePageDir(PULONG LocalPageDir, PVOID Address); +VOID MmUpdateStackPageDir(PULONG LocalPageDir, struct _KTHREAD* KThread); #define MM_PAGE_CLEAN (0) #define MM_PAGE_DIRTY (1) diff --git a/reactos/ntoskrnl/ke/process.c b/reactos/ntoskrnl/ke/process.c index c9694d349e8..a2974a468b5 100644 --- a/reactos/ntoskrnl/ke/process.c +++ b/reactos/ntoskrnl/ke/process.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: process.c,v 1.13 2003/05/08 05:26:36 gvg Exp $ +/* $Id: process.c,v 1.14 2003/06/01 19:50:04 hbirr Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/ke/process.c @@ -44,7 +44,6 @@ KeAttachProcess (PEPROCESS Process) { KIRQL oldlvl; PETHREAD CurrentThread; - PVOID ESP; PULONG AttachedProcessPageDir; ULONG PageDir; @@ -69,11 +68,8 @@ KeAttachProcess (PEPROCESS Process) To prevent this, make sure the page directory of the process we're attaching to is up-to-date. */ - __asm__("mov %%esp,%0\n\t" - : "=r" (ESP)); - AttachedProcessPageDir = ExAllocatePageWithPhysPage(Process->Pcb.DirectoryTableBase); - MmUpdatePageDir(AttachedProcessPageDir, ESP); + MmUpdateStackPageDir(AttachedProcessPageDir, &CurrentThread->Tcb); ExUnmapPage(AttachedProcessPageDir); CurrentThread->OldProcess = PsGetCurrentProcess(); diff --git a/reactos/ntoskrnl/mm/i386/page.c b/reactos/ntoskrnl/mm/i386/page.c index 40ae991f72f..406cb7fa946 100644 --- a/reactos/ntoskrnl/mm/i386/page.c +++ b/reactos/ntoskrnl/mm/i386/page.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: page.c,v 1.50 2003/05/17 13:45:04 hbirr Exp $ +/* $Id: page.c,v 1.51 2003/06/01 19:50:04 hbirr Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/mm/i386/page.c @@ -115,10 +115,10 @@ ProtectToPTE(ULONG flProtect) #define ADDR_TO_PAGE_TABLE(v) (((ULONG)(v)) / (4 * 1024 * 1024)) #define ADDR_TO_PDE(v) (PULONG)(PAGEDIRECTORY_MAP + \ - (((ULONG)v / (1024 * 1024))&(~0x3))) + ((((ULONG)(v)) / (1024 * 1024))&(~0x3))) #define ADDR_TO_PTE(v) (PULONG)(PAGETABLE_MAP + ((((ULONG)v / 1024))&(~0x3))) -#define ADDR_TO_PDE_OFFSET(v) (((ULONG)v / (4 * 1024 * 1024))) +#define ADDR_TO_PDE_OFFSET(v) ((((ULONG)(v)) / (4 * 1024 * 1024))) NTSTATUS Mmi386ReleaseMmInfo(PEPROCESS Process) { @@ -1247,13 +1247,18 @@ MmGetPhysicalAddress(PVOID vaddr) VOID -MmUpdatePageDir(PULONG LocalPageDir, PVOID Address) +MmUpdateStackPageDir(PULONG LocalPageDir, PKTHREAD PThread) { - unsigned Entry = ADDR_TO_PDE_OFFSET(Address); + unsigned EntryBase = ADDR_TO_PDE_OFFSET(PThread->StackLimit); + unsigned EntryTop = ADDR_TO_PDE_OFFSET(PThread->InitialStack - PAGE_SIZE); - if (0 == LocalPageDir[Entry]) + if (0 == LocalPageDir[EntryBase]) { - LocalPageDir[Entry] = MmGlobalKernelPageDirectory[Entry]; + LocalPageDir[EntryBase] = MmGlobalKernelPageDirectory[EntryBase]; + } + if (EntryBase != EntryTop && 0 == LocalPageDir[EntryTop]) + { + LocalPageDir[EntryTop] = MmGlobalKernelPageDirectory[EntryTop]; } }