mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 02:25:17 +00:00
Fix for memory management issue.
svn path=/trunk/; revision=1643
This commit is contained in:
parent
24fea578c1
commit
ac82b90278
4 changed files with 100 additions and 15 deletions
|
@ -1,4 +1,4 @@
|
||||||
# $Id: makefile,v 1.20 2000/11/20 19:59:10 ekohl Exp $
|
# $Id: makefile,v 1.21 2001/02/18 22:16:05 dwelch Exp $
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
PATH_TO_TOP = ../../..
|
PATH_TO_TOP = ../../..
|
||||||
|
@ -7,7 +7,7 @@ TARGET=ide
|
||||||
|
|
||||||
OBJECTS = $(TARGET).o $(TARGET).coff ../../../ntoskrnl/ntoskrnl.a
|
OBJECTS = $(TARGET).o $(TARGET).coff ../../../ntoskrnl/ntoskrnl.a
|
||||||
|
|
||||||
CFLAGS = -I.
|
CFLAGS = -I. -g
|
||||||
|
|
||||||
all: $(TARGET).sys.unstripped $(TARGET).sys
|
all: $(TARGET).sys.unstripped $(TARGET).sys
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: page.c,v 1.20 2001/02/18 17:43:32 dwelch Exp $
|
/* $Id: page.c,v 1.21 2001/02/18 22:16:05 dwelch Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top directory
|
* COPYRIGHT: See COPYING in the top directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -42,6 +42,8 @@
|
||||||
#define PAGETABLE_MAP (0xf0000000)
|
#define PAGETABLE_MAP (0xf0000000)
|
||||||
#define PAGEDIRECTORY_MAP (0xf0000000 + (PAGETABLE_MAP / (1024)))
|
#define PAGEDIRECTORY_MAP (0xf0000000 + (PAGETABLE_MAP / (1024)))
|
||||||
|
|
||||||
|
ULONG MmGlobalKernelPageDirectory[1024] = {0, };
|
||||||
|
|
||||||
/* FUNCTIONS ***************************************************************/
|
/* FUNCTIONS ***************************************************************/
|
||||||
|
|
||||||
PULONG
|
PULONG
|
||||||
|
@ -92,6 +94,8 @@ ProtectToPTE(ULONG flProtect)
|
||||||
(((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_PTE(v) (PULONG)(PAGETABLE_MAP + ((((ULONG)v / 1024))&(~0x3)))
|
||||||
|
|
||||||
|
#define ADDR_TO_PDE_OFFSET(v) (((ULONG)v / (4 * 1024 * 1024)))
|
||||||
|
|
||||||
NTSTATUS Mmi386ReleaseMmInfo(PEPROCESS Process)
|
NTSTATUS Mmi386ReleaseMmInfo(PEPROCESS Process)
|
||||||
{
|
{
|
||||||
DPRINT("Mmi386ReleaseMmInfo(Process %x)\n",Process);
|
DPRINT("Mmi386ReleaseMmInfo(Process %x)\n",Process);
|
||||||
|
@ -150,6 +154,10 @@ VOID MmDeletePageTable(PEPROCESS Process, PVOID Address)
|
||||||
KeAttachProcess(Process);
|
KeAttachProcess(Process);
|
||||||
}
|
}
|
||||||
*(ADDR_TO_PDE(Address)) = 0;
|
*(ADDR_TO_PDE(Address)) = 0;
|
||||||
|
if (Address >= (PVOID)KERNEL_BASE)
|
||||||
|
{
|
||||||
|
MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] = 0;
|
||||||
|
}
|
||||||
FLUSH_TLB;
|
FLUSH_TLB;
|
||||||
if (Process != NULL && Process != CurrentProcess)
|
if (Process != NULL && Process != CurrentProcess)
|
||||||
{
|
{
|
||||||
|
@ -180,6 +188,10 @@ VOID MmFreePageTable(PEPROCESS Process, PVOID Address)
|
||||||
}
|
}
|
||||||
npage = *(ADDR_TO_PDE(Address));
|
npage = *(ADDR_TO_PDE(Address));
|
||||||
*(ADDR_TO_PDE(Address)) = 0;
|
*(ADDR_TO_PDE(Address)) = 0;
|
||||||
|
if (Address >= (PVOID)KERNEL_BASE)
|
||||||
|
{
|
||||||
|
MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] = 0;
|
||||||
|
}
|
||||||
MmDereferencePage((PVOID)PAGE_MASK(npage));
|
MmDereferencePage((PVOID)PAGE_MASK(npage));
|
||||||
FLUSH_TLB;
|
FLUSH_TLB;
|
||||||
if (Process != NULL && Process != CurrentProcess)
|
if (Process != NULL && Process != CurrentProcess)
|
||||||
|
@ -201,6 +213,14 @@ NTSTATUS MmGetPageEntry2(PVOID PAddress, PULONG* Pte)
|
||||||
|
|
||||||
Pde = ADDR_TO_PDE(Address);
|
Pde = ADDR_TO_PDE(Address);
|
||||||
if ((*Pde) == 0)
|
if ((*Pde) == 0)
|
||||||
|
{
|
||||||
|
if (Address >= KERNEL_BASE &&
|
||||||
|
MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] != 0)
|
||||||
|
{
|
||||||
|
(*Pde) = MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)];
|
||||||
|
FLUSH_TLB;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
npage = (ULONG)MmAllocPage(0);
|
npage = (ULONG)MmAllocPage(0);
|
||||||
if (npage == 0)
|
if (npage == 0)
|
||||||
|
@ -208,9 +228,15 @@ NTSTATUS MmGetPageEntry2(PVOID PAddress, PULONG* Pte)
|
||||||
return(STATUS_NO_MEMORY);
|
return(STATUS_NO_MEMORY);
|
||||||
}
|
}
|
||||||
(*Pde) = npage | 0x7;
|
(*Pde) = npage | 0x7;
|
||||||
|
if (Address >= KERNEL_BASE)
|
||||||
|
{
|
||||||
|
MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] =
|
||||||
|
*Pde;
|
||||||
|
}
|
||||||
memset((PVOID)PAGE_ROUND_DOWN(ADDR_TO_PTE(Address)), 0, PAGESIZE);
|
memset((PVOID)PAGE_ROUND_DOWN(ADDR_TO_PTE(Address)), 0, PAGESIZE);
|
||||||
FLUSH_TLB;
|
FLUSH_TLB;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
*Pte = ADDR_TO_PTE(Address);
|
*Pte = ADDR_TO_PTE(Address);
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -244,6 +270,12 @@ ULONG MmGetPageEntry1(PVOID PAddress)
|
||||||
DPRINT("MmGetPageEntry(Address %x)\n", Address);
|
DPRINT("MmGetPageEntry(Address %x)\n", Address);
|
||||||
|
|
||||||
page_dir = ADDR_TO_PDE(Address);
|
page_dir = ADDR_TO_PDE(Address);
|
||||||
|
if ((*page_dir) == 0 &&
|
||||||
|
MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] != 0)
|
||||||
|
{
|
||||||
|
(*page_dir) = MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)];
|
||||||
|
FLUSH_TLB;
|
||||||
|
}
|
||||||
DPRINT("page_dir %x *page_dir %x\n",page_dir,*page_dir);
|
DPRINT("page_dir %x *page_dir %x\n",page_dir,*page_dir);
|
||||||
if ((*page_dir) == 0)
|
if ((*page_dir) == 0)
|
||||||
{
|
{
|
||||||
|
@ -301,6 +333,12 @@ VOID MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOL FreePage)
|
||||||
KeAttachProcess(Process);
|
KeAttachProcess(Process);
|
||||||
}
|
}
|
||||||
Pde = ADDR_TO_PDE(Address);
|
Pde = ADDR_TO_PDE(Address);
|
||||||
|
if ((*Pde) == 0 &&
|
||||||
|
MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] != 0)
|
||||||
|
{
|
||||||
|
(*Pde) = MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)];
|
||||||
|
FLUSH_TLB;
|
||||||
|
}
|
||||||
if ((*Pde) == 0)
|
if ((*Pde) == 0)
|
||||||
{
|
{
|
||||||
if (Process != NULL && Process != CurrentProcess)
|
if (Process != NULL && Process != CurrentProcess)
|
||||||
|
@ -338,12 +376,35 @@ VOID MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOL FreePage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOLEAN
|
||||||
|
Mmi386MakeKernelPageTableGlobal(PVOID PAddress)
|
||||||
|
{
|
||||||
|
PULONG page_dir;
|
||||||
|
ULONG Address = (ULONG)PAddress;
|
||||||
|
|
||||||
|
page_dir = ADDR_TO_PDE(Address);
|
||||||
|
if ((*page_dir) == 0 &&
|
||||||
|
MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] != 0)
|
||||||
|
{
|
||||||
|
(*page_dir) = MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)];
|
||||||
|
FLUSH_TLB;
|
||||||
|
return(TRUE);
|
||||||
|
}
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
BOOLEAN MmIsPageTablePresent(PVOID PAddress)
|
BOOLEAN MmIsPageTablePresent(PVOID PAddress)
|
||||||
{
|
{
|
||||||
PULONG page_dir;
|
PULONG page_dir;
|
||||||
ULONG Address = (ULONG)PAddress;
|
ULONG Address = (ULONG)PAddress;
|
||||||
|
|
||||||
page_dir = ADDR_TO_PDE(Address);
|
page_dir = ADDR_TO_PDE(Address);
|
||||||
|
if ((*page_dir) == 0 &&
|
||||||
|
MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] != 0)
|
||||||
|
{
|
||||||
|
(*page_dir) = MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)];
|
||||||
|
FLUSH_TLB;
|
||||||
|
}
|
||||||
return((*page_dir) == 0);
|
return((*page_dir) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,6 +418,12 @@ NTSTATUS MmCreatePageTable(PVOID PAddress)
|
||||||
|
|
||||||
page_dir = ADDR_TO_PDE(Address);
|
page_dir = ADDR_TO_PDE(Address);
|
||||||
DPRINT("page_dir %x *page_dir %x\n",page_dir,*page_dir);
|
DPRINT("page_dir %x *page_dir %x\n",page_dir,*page_dir);
|
||||||
|
if ((*page_dir) == 0 &&
|
||||||
|
MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] != 0)
|
||||||
|
{
|
||||||
|
(*page_dir) = MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)];
|
||||||
|
FLUSH_TLB;
|
||||||
|
}
|
||||||
if ((*page_dir) == 0)
|
if ((*page_dir) == 0)
|
||||||
{
|
{
|
||||||
npage = (ULONG)MmAllocPage(0);
|
npage = (ULONG)MmAllocPage(0);
|
||||||
|
@ -385,6 +452,12 @@ PULONG MmGetPageEntry(PVOID PAddress)
|
||||||
|
|
||||||
page_dir = ADDR_TO_PDE(Address);
|
page_dir = ADDR_TO_PDE(Address);
|
||||||
DPRINT("page_dir %x *page_dir %x\n",page_dir,*page_dir);
|
DPRINT("page_dir %x *page_dir %x\n",page_dir,*page_dir);
|
||||||
|
if ((*page_dir) == 0 &&
|
||||||
|
MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] != 0)
|
||||||
|
{
|
||||||
|
(*page_dir) = MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)];
|
||||||
|
FLUSH_TLB;
|
||||||
|
}
|
||||||
if ((*page_dir) == 0)
|
if ((*page_dir) == 0)
|
||||||
{
|
{
|
||||||
npage = (ULONG)MmAllocPage(0);
|
npage = (ULONG)MmAllocPage(0);
|
||||||
|
|
|
@ -26,6 +26,11 @@ extern VOID MmSafeCopyFromUserRestart(VOID);
|
||||||
extern VOID MmSafeCopyToUserUnsafeStart(VOID);
|
extern VOID MmSafeCopyToUserUnsafeStart(VOID);
|
||||||
extern VOID MmSafeCopyToUserRestart(VOID);
|
extern VOID MmSafeCopyToUserRestart(VOID);
|
||||||
|
|
||||||
|
extern ULONG MmGlobalKernelPageDirectory[1024];
|
||||||
|
|
||||||
|
BOOLEAN
|
||||||
|
Mmi386MakeKernelPageTableGlobal(PVOID Address);
|
||||||
|
|
||||||
/* FUNCTIONS *****************************************************************/
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
||||||
NTSTATUS MmPageFault(ULONG Cs,
|
NTSTATUS MmPageFault(ULONG Cs,
|
||||||
|
@ -49,6 +54,12 @@ NTSTATUS MmPageFault(ULONG Cs,
|
||||||
Mode = KernelMode;
|
Mode = KernelMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Mode == KernelMode && Cr2 >= KERNEL_BASE &&
|
||||||
|
Mmi386MakeKernelPageTableGlobal((PVOID)Cr2))
|
||||||
|
{
|
||||||
|
return(STATUS_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
if (ErrorCode & 0x1)
|
if (ErrorCode & 0x1)
|
||||||
{
|
{
|
||||||
Status = MmAccessFault(Mode, Cr2, FALSE);
|
Status = MmAccessFault(Mode, Cr2, FALSE);
|
||||||
|
|
|
@ -17,7 +17,8 @@ endif
|
||||||
#
|
#
|
||||||
ifeq ($(HOST),mingw32-linux)
|
ifeq ($(HOST),mingw32-linux)
|
||||||
NASM_FORMAT = win32
|
NASM_FORMAT = win32
|
||||||
PREFIX = i586-mingw32-
|
PREFIX = /usr/mingw32-cvs-000216/bin/mingw32-pc-
|
||||||
|
CPREFIX = i586-mingw32-
|
||||||
#PREFIX = /usr/mingw32-cvs-000207/bin/mingw32-cvs-000207-
|
#PREFIX = /usr/mingw32-cvs-000207/bin/mingw32-cvs-000207-
|
||||||
EXE_POSTFIX =
|
EXE_POSTFIX =
|
||||||
EXE_PREFIX = ./
|
EXE_PREFIX = ./
|
||||||
|
@ -48,8 +49,8 @@ FLOPPY_DIR = A:
|
||||||
DIST_DIR = dist
|
DIST_DIR = dist
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CC = $(PREFIX)gcc
|
CC = $(CPREFIX)gcc
|
||||||
CXX = $(PREFIX)g++
|
CXX = $(CPREFIX)g++
|
||||||
HOST_CC = gcc
|
HOST_CC = gcc
|
||||||
HOST_NM = nm
|
HOST_NM = nm
|
||||||
CFLAGS := $(CFLAGS) -I$(PATH_TO_TOP)/include -pipe
|
CFLAGS := $(CFLAGS) -I$(PATH_TO_TOP)/include -pipe
|
||||||
|
|
Loading…
Reference in a new issue