Added new MEMORY_AREA_NO_ACCESS type.

Make the top and bottom 64KB of process memory space and the 60KB above the shared user page from unaccessible.
Introduced MmSystemRangeStart.

svn path=/trunk/; revision=4705
This commit is contained in:
Eric Kohl 2003-05-17 19:16:39 +00:00
parent e1c437438c
commit 397169c1a8
5 changed files with 91 additions and 21 deletions

View file

@ -28,6 +28,7 @@ typedef ULONG SWAPENTRY;
#define MEMORY_AREA_SHARED_DATA (10) #define MEMORY_AREA_SHARED_DATA (10)
#define MEMORY_AREA_KERNEL_STACK (11) #define MEMORY_AREA_KERNEL_STACK (11)
#define MEMORY_AREA_PAGED_POOL (12) #define MEMORY_AREA_PAGED_POOL (12)
#define MEMORY_AREA_NO_ACCESS (13)
#define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) \ #define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) \
((x) / (4*1024*1024)) ((x) / (4*1024*1024))
@ -151,6 +152,12 @@ typedef struct _MADDRESS_SPACE
ULONG PageTableRefCountTableSize; ULONG PageTableRefCountTableSize;
} MADDRESS_SPACE, *PMADDRESS_SPACE; } MADDRESS_SPACE, *PMADDRESS_SPACE;
/* VARIABLES */
extern PVOID MmSystemRangeStart;
/* FUNCTIONS */ /* FUNCTIONS */
VOID MmLockAddressSpace(PMADDRESS_SPACE AddressSpace); VOID MmLockAddressSpace(PMADDRESS_SPACE AddressSpace);

View file

@ -218,7 +218,7 @@ PVOID MmFindGapBottomUp(PMADDRESS_SPACE AddressSpace, ULONG Length)
DPRINT("MmFindGapBottomUp(Length %x)\n",Length); DPRINT("MmFindGapBottomUp(Length %x)\n",Length);
ListHead = &AddressSpace->MAreaListHead; ListHead = &AddressSpace->MAreaListHead;
current_entry = ListHead->Flink; current_entry = ListHead->Flink;
while (current_entry->Flink!=ListHead) while (current_entry->Flink!=ListHead)
{ {
@ -273,9 +273,9 @@ PVOID MmFindGapTopDown(PMADDRESS_SPACE AddressSpace, ULONG Length)
DPRINT("MmFindGapTopDown(Length %lx)\n",Length); DPRINT("MmFindGapTopDown(Length %lx)\n",Length);
if (AddressSpace->LowestAddress < KERNEL_BASE) if (AddressSpace->LowestAddress < KERNEL_BASE) //(ULONG_PTR)MmSystemRangeStart)
{ {
HighestAddress = (PVOID)0x7FFE0000; /* Start below the PEB */ HighestAddress = MmHighestUserAddress;
} }
else else
{ {
@ -294,12 +294,12 @@ PVOID MmFindGapTopDown(PMADDRESS_SPACE AddressSpace, ULONG Length)
if (BottomAddress < HighestAddress) if (BottomAddress < HighestAddress)
{ {
Gap = TopAddress - BottomAddress; Gap = TopAddress - BottomAddress + 1;
DPRINT("Bottom %p Top %p Gap %lx\n", BottomAddress, TopAddress, Gap); DPRINT("Bottom %p Top %p Gap %lx\n", BottomAddress, TopAddress, Gap);
if (Gap >= Length) if (Gap >= Length)
{ {
DPRINT1("Found gap at %p\n", TopAddress - Length); DPRINT("Found gap at %p\n", TopAddress - Length);
return(TopAddress - Length); return(TopAddress - Length + 1);
} }
TopAddress = current->BaseAddress; TopAddress = current->BaseAddress;
} }
@ -308,11 +308,11 @@ PVOID MmFindGapTopDown(PMADDRESS_SPACE AddressSpace, ULONG Length)
if (current_entry == ListHead) if (current_entry == ListHead)
{ {
Address = (PVOID)HighestAddress - Length; Address = (PVOID)HighestAddress - Length + 1;
} }
else else
{ {
Address = TopAddress - Length; Address = TopAddress - Length + 1;
} }
/* Check if enough space for the block */ /* Check if enough space for the block */

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: mm.c,v 1.60 2002/09/08 10:23:35 chorns Exp $ /* $Id: mm.c,v 1.61 2003/05/17 19:16:02 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top directory * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -41,9 +41,11 @@
/* GLOBALS *****************************************************************/ /* GLOBALS *****************************************************************/
PVOID EXPORTED MmUserProbeAddress = NULL; PVOID EXPORTED MmUserProbeAddress = NULL;
PVOID EXPORTED MmHighestUserAddress = NULL; PVOID EXPORTED MmHighestUserAddress = NULL;
MM_STATS MmStats;
PVOID MmSystemRangeStart = NULL;
MM_STATS MmStats;
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
@ -76,6 +78,9 @@ NTSTATUS MmReleaseMemoryArea(PEPROCESS Process, PMEMORY_AREA Marea)
NULL); NULL);
break; break;
case MEMORY_AREA_NO_ACCESS:
return(STATUS_SUCCESS);
default: default:
KeBugCheck(0); KeBugCheck(0);
} }
@ -210,24 +215,24 @@ NTSTATUS MmAccessFault(KPROCESSOR_MODE Mode,
break; break;
case MEMORY_AREA_PAGED_POOL: case MEMORY_AREA_PAGED_POOL:
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
break; break;
case MEMORY_AREA_SECTION_VIEW: case MEMORY_AREA_SECTION_VIEW:
Status = MmAccessFaultSectionView(AddressSpace, Status = MmAccessFaultSectionView(AddressSpace,
MemoryArea, MemoryArea,
(PVOID)Address, (PVOID)Address,
Locked); Locked);
break; break;
case MEMORY_AREA_VIRTUAL_MEMORY: case MEMORY_AREA_VIRTUAL_MEMORY:
Status = STATUS_UNSUCCESSFUL; Status = STATUS_UNSUCCESSFUL;
break; break;
case MEMORY_AREA_SHARED_DATA: case MEMORY_AREA_SHARED_DATA:
Status = STATUS_UNSUCCESSFUL; Status = STATUS_UNSUCCESSFUL;
break; break;
default: default:
Status = STATUS_UNSUCCESSFUL; Status = STATUS_UNSUCCESSFUL;
break; break;

View file

@ -1,4 +1,4 @@
/* $Id: mminit.c,v 1.45 2003/05/17 15:28:58 ekohl Exp $ /* $Id: mminit.c,v 1.46 2003/05/17 19:16:03 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top directory * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -248,6 +248,7 @@ VOID MmInit1(ULONG FirstKrnlPhysAddr,
/* /*
* FIXME: Set this based on the system command line * FIXME: Set this based on the system command line
*/ */
MmSystemRangeStart = (PVOID)KERNEL_BASE; // 0xC0000000
MmUserProbeAddress = (PVOID)0x7fff0000; MmUserProbeAddress = (PVOID)0x7fff0000;
MmHighestUserAddress = (PVOID)0x7ffeffff; MmHighestUserAddress = (PVOID)0x7ffeffff;

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.100 2003/05/17 15:29:50 ekohl Exp $ /* $Id: process.c,v 1.101 2003/05/17 19:16:39 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -585,9 +585,66 @@ NtCreateProcess(OUT PHANDLE ProcessHandle,
/* /*
* Now we have created the process proper * Now we have created the process proper
*/ */
/* Create the shared data page */
MmLockAddressSpace(&Process->AddressSpace); MmLockAddressSpace(&Process->AddressSpace);
/* Protect the highest 64KB of the process address space */
BaseAddress = MmUserProbeAddress;
Status = MmCreateMemoryArea(Process,
&Process->AddressSpace,
MEMORY_AREA_NO_ACCESS,
&BaseAddress,
0x10000,
PAGE_NOACCESS,
&MemoryArea,
FALSE,
FALSE);
if (!NT_SUCCESS(Status))
{
MmUnlockAddressSpace(&Process->AddressSpace);
DPRINT1("Failed to protect the highest 64KB of the process address space\n");
KeBugCheck(0);
}
/* Protect the lowest 64KB of the process address space */
#if 0
BaseAddress = (PVOID)0x00000000;
Status = MmCreateMemoryArea(Process,
&Process->AddressSpace,
MEMORY_AREA_NO_ACCESS,
&BaseAddress,
0x10000,
PAGE_NOACCESS,
&MemoryArea,
FALSE,
FALSE);
if (!NT_SUCCESS(Status))
{
MmUnlockAddressSpace(&Process->AddressSpace);
DPRINT1("Failed to protect the lowest 64KB of the process address space\n");
KeBugCheck(0);
}
#endif
/* Protect the 60KB above the shared user page */
BaseAddress = (PVOID)USER_SHARED_DATA + PAGE_SIZE;
Status = MmCreateMemoryArea(Process,
&Process->AddressSpace,
MEMORY_AREA_NO_ACCESS,
&BaseAddress,
0x10000 - PAGE_SIZE,
PAGE_NOACCESS,
&MemoryArea,
FALSE,
FALSE);
if (!NT_SUCCESS(Status))
{
MmUnlockAddressSpace(&Process->AddressSpace);
DPRINT1("Failed to protect the memory above the shared user page\n");
KeBugCheck(0);
}
/* Create the shared data page */
BaseAddress = (PVOID)USER_SHARED_DATA; BaseAddress = (PVOID)USER_SHARED_DATA;
Status = MmCreateMemoryArea(Process, Status = MmCreateMemoryArea(Process,
&Process->AddressSpace, &Process->AddressSpace,