2008-02-14 03:08:20 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2005-01-26 13:58:37 +00:00
|
|
|
* FILE: ntoskrnl/mm/mminit.c
|
2008-02-14 03:08:20 +00:00
|
|
|
* PURPOSE: Memory Manager Initialization
|
|
|
|
* PROGRAMMERS:
|
2000-07-04 08:52:47 +00:00
|
|
|
*/
|
|
|
|
|
2008-02-14 03:08:20 +00:00
|
|
|
/* INCLUDES ******************************************************************/
|
2000-07-04 08:52:47 +00:00
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
2008-01-06 15:12:41 +00:00
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
2000-07-04 08:52:47 +00:00
|
|
|
|
- Fix a bug in memory area creation: Static memory areas had the static flag embedded in their type, so code that was switch()ing on the type would fail to recognize the actual type, because MEMORY_AREA_STATIC was ORed in.
- Add a new memory area type: MEMORY_AREA_OWNED_BY_ARM3. This will allow us to instruct the ReactOS Memory MAnager to "Back. The Fuck. Off." during page faults and such, so we can handle page faults inside ARM3-owned PTEs ourselves.
- Right now, all ARM3 PTEs and data is nonpaged, so no page faults should happen, but this may change in the future.
- Also will allow us to manage our own PDEs so we can do on-demand inpage instead of syncing with the ReactOS Mm hack cache.
- Create all memory areas in one shot in MmCreateSystemMemoryAreas (get rid of MiInitPageDirectoryMap and MiInitPagedPool memory area creation).
- Mark all of ours as owned by ARM3.
- Make them all static.
- The only non-ARM3 one right now is paged pool, we own all the other static areas.
- Move this code into mm, instead of mm/ARM3, since memory areas are not an ARM3 concept.
- Also create memory areas for session space, session view, and other ARM3 memory ranges, so nobody touches those ranges.
- Dump the kernel address space after all this is done, in a MmDbg function in mm.
- This cleans up ARM3 of some ROS-specific code, and also collapses Phase 1 and 2 into a single phase.
svn path=/trunk/; revision=43486
2009-10-15 18:54:35 +00:00
|
|
|
#define MODULE_INVOLVED_IN_ARM3
|
|
|
|
#include "ARM3/miarm.h"
|
|
|
|
|
2008-02-14 03:08:20 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
2007-10-02 20:09:31 +00:00
|
|
|
|
2010-10-05 15:55:52 +00:00
|
|
|
VOID NTAPI MiInitializeUserPfnBitmap(VOID);
|
|
|
|
|
|
|
|
HANDLE MpwThreadHandle;
|
|
|
|
KEVENT MpwThreadEvent;
|
|
|
|
|
2010-03-29 04:49:07 +00:00
|
|
|
BOOLEAN Mm64BitPhysicalAddress = FALSE;
|
- Create mmsup.c in ReactOS memory manager directory. It hosts misc support functions:
- Copy kmap.c here, since it's the very definition of "misc support function"
- Copy some exported functions in mm.c which were listed as "misc functions"
- Warn that current implementation of MmIsNonPagedSystemAddressValid will kill kittens.
- Rename mm.c to mmfault.c, since other than the misc functions now in mmsup.c, it was all routines to handle page/access faults.
- Warn that MmIsAddressValid, as currently implemented, kills puppies.
- Move WriteWatch functions to virtual.c since they're part of the Virtual API system call set already hosted there.
- Move the global variables that people had been throwing in here to mminit.c, which is slightly more appropriate.
- Move wset.c's MmTrimUserMemory to balance.c, since that's where all other similar functions are located.
- Incidentally, kill wset.c, as this was the only function present.
- No functional changes, just refactoring and cleanup (other than warning the critter murder the two broken functions will achieve if called).
svn path=/trunk/; revision=41659
2009-06-28 07:52:30 +00:00
|
|
|
ULONG MmReadClusterSize;
|
2009-10-19 23:04:50 +00:00
|
|
|
//
|
|
|
|
// 0 | 1 is on/off paging, 2 is undocumented
|
|
|
|
//
|
|
|
|
UCHAR MmDisablePagingExecutive = 1; // Forced to off
|
2009-07-27 02:13:19 +00:00
|
|
|
PMMPTE MmSharedUserDataPte;
|
- Create mmsup.c in ReactOS memory manager directory. It hosts misc support functions:
- Copy kmap.c here, since it's the very definition of "misc support function"
- Copy some exported functions in mm.c which were listed as "misc functions"
- Warn that current implementation of MmIsNonPagedSystemAddressValid will kill kittens.
- Rename mm.c to mmfault.c, since other than the misc functions now in mmsup.c, it was all routines to handle page/access faults.
- Warn that MmIsAddressValid, as currently implemented, kills puppies.
- Move WriteWatch functions to virtual.c since they're part of the Virtual API system call set already hosted there.
- Move the global variables that people had been throwing in here to mminit.c, which is slightly more appropriate.
- Move wset.c's MmTrimUserMemory to balance.c, since that's where all other similar functions are located.
- Incidentally, kill wset.c, as this was the only function present.
- No functional changes, just refactoring and cleanup (other than warning the critter murder the two broken functions will achieve if called).
svn path=/trunk/; revision=41659
2009-06-28 07:52:30 +00:00
|
|
|
PMMSUPPORT MmKernelAddressSpace;
|
2007-09-27 18:07:44 +00:00
|
|
|
|
2008-02-14 03:08:20 +00:00
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
2000-07-04 08:52:47 +00:00
|
|
|
|
2005-09-14 01:05:50 +00:00
|
|
|
VOID
|
|
|
|
INIT_FUNCTION
|
|
|
|
NTAPI
|
2009-06-21 06:36:45 +00:00
|
|
|
MiInitSystemMemoryAreas()
|
2000-07-04 08:52:47 +00:00
|
|
|
{
|
2009-06-21 06:36:45 +00:00
|
|
|
PVOID BaseAddress;
|
|
|
|
PHYSICAL_ADDRESS BoundaryAddressMultiple;
|
|
|
|
PMEMORY_AREA MArea;
|
- Fix a bug in memory area creation: Static memory areas had the static flag embedded in their type, so code that was switch()ing on the type would fail to recognize the actual type, because MEMORY_AREA_STATIC was ORed in.
- Add a new memory area type: MEMORY_AREA_OWNED_BY_ARM3. This will allow us to instruct the ReactOS Memory MAnager to "Back. The Fuck. Off." during page faults and such, so we can handle page faults inside ARM3-owned PTEs ourselves.
- Right now, all ARM3 PTEs and data is nonpaged, so no page faults should happen, but this may change in the future.
- Also will allow us to manage our own PDEs so we can do on-demand inpage instead of syncing with the ReactOS Mm hack cache.
- Create all memory areas in one shot in MmCreateSystemMemoryAreas (get rid of MiInitPageDirectoryMap and MiInitPagedPool memory area creation).
- Mark all of ours as owned by ARM3.
- Make them all static.
- The only non-ARM3 one right now is paged pool, we own all the other static areas.
- Move this code into mm, instead of mm/ARM3, since memory areas are not an ARM3 concept.
- Also create memory areas for session space, session view, and other ARM3 memory ranges, so nobody touches those ranges.
- Dump the kernel address space after all this is done, in a MmDbg function in mm.
- This cleans up ARM3 of some ROS-specific code, and also collapses Phase 1 and 2 into a single phase.
svn path=/trunk/; revision=43486
2009-10-15 18:54:35 +00:00
|
|
|
NTSTATUS Status;
|
2009-06-21 06:36:45 +00:00
|
|
|
BoundaryAddressMultiple.QuadPart = 0;
|
|
|
|
|
|
|
|
//
|
- Fix a bug in memory area creation: Static memory areas had the static flag embedded in their type, so code that was switch()ing on the type would fail to recognize the actual type, because MEMORY_AREA_STATIC was ORed in.
- Add a new memory area type: MEMORY_AREA_OWNED_BY_ARM3. This will allow us to instruct the ReactOS Memory MAnager to "Back. The Fuck. Off." during page faults and such, so we can handle page faults inside ARM3-owned PTEs ourselves.
- Right now, all ARM3 PTEs and data is nonpaged, so no page faults should happen, but this may change in the future.
- Also will allow us to manage our own PDEs so we can do on-demand inpage instead of syncing with the ReactOS Mm hack cache.
- Create all memory areas in one shot in MmCreateSystemMemoryAreas (get rid of MiInitPageDirectoryMap and MiInitPagedPool memory area creation).
- Mark all of ours as owned by ARM3.
- Make them all static.
- The only non-ARM3 one right now is paged pool, we own all the other static areas.
- Move this code into mm, instead of mm/ARM3, since memory areas are not an ARM3 concept.
- Also create memory areas for session space, session view, and other ARM3 memory ranges, so nobody touches those ranges.
- Dump the kernel address space after all this is done, in a MmDbg function in mm.
- This cleans up ARM3 of some ROS-specific code, and also collapses Phase 1 and 2 into a single phase.
svn path=/trunk/; revision=43486
2009-10-15 18:54:35 +00:00
|
|
|
// Create the memory area to define the PTE base
|
|
|
|
//
|
|
|
|
BaseAddress = (PVOID)PTE_BASE;
|
|
|
|
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
|
|
|
|
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
|
|
|
|
&BaseAddress,
|
|
|
|
4 * 1024 * 1024,
|
|
|
|
PAGE_READWRITE,
|
|
|
|
&MArea,
|
|
|
|
TRUE,
|
|
|
|
0,
|
|
|
|
BoundaryAddressMultiple);
|
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create the memory area to define Hyperspace
|
|
|
|
//
|
|
|
|
BaseAddress = (PVOID)HYPER_SPACE;
|
|
|
|
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
|
|
|
|
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
|
|
|
|
&BaseAddress,
|
|
|
|
4 * 1024 * 1024,
|
|
|
|
PAGE_READWRITE,
|
|
|
|
&MArea,
|
|
|
|
TRUE,
|
|
|
|
0,
|
|
|
|
BoundaryAddressMultiple);
|
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Protect the PFN database
|
|
|
|
//
|
2010-06-06 15:59:42 +00:00
|
|
|
BaseAddress = MmPfnDatabase;
|
- Fix a bug in memory area creation: Static memory areas had the static flag embedded in their type, so code that was switch()ing on the type would fail to recognize the actual type, because MEMORY_AREA_STATIC was ORed in.
- Add a new memory area type: MEMORY_AREA_OWNED_BY_ARM3. This will allow us to instruct the ReactOS Memory MAnager to "Back. The Fuck. Off." during page faults and such, so we can handle page faults inside ARM3-owned PTEs ourselves.
- Right now, all ARM3 PTEs and data is nonpaged, so no page faults should happen, but this may change in the future.
- Also will allow us to manage our own PDEs so we can do on-demand inpage instead of syncing with the ReactOS Mm hack cache.
- Create all memory areas in one shot in MmCreateSystemMemoryAreas (get rid of MiInitPageDirectoryMap and MiInitPagedPool memory area creation).
- Mark all of ours as owned by ARM3.
- Make them all static.
- The only non-ARM3 one right now is paged pool, we own all the other static areas.
- Move this code into mm, instead of mm/ARM3, since memory areas are not an ARM3 concept.
- Also create memory areas for session space, session view, and other ARM3 memory ranges, so nobody touches those ranges.
- Dump the kernel address space after all this is done, in a MmDbg function in mm.
- This cleans up ARM3 of some ROS-specific code, and also collapses Phase 1 and 2 into a single phase.
svn path=/trunk/; revision=43486
2009-10-15 18:54:35 +00:00
|
|
|
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
|
|
|
|
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
|
|
|
|
&BaseAddress,
|
|
|
|
(MxPfnAllocation << PAGE_SHIFT),
|
|
|
|
PAGE_READWRITE,
|
|
|
|
&MArea,
|
|
|
|
TRUE,
|
|
|
|
0,
|
|
|
|
BoundaryAddressMultiple);
|
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
|
|
|
|
|
|
|
//
|
|
|
|
// ReactOS requires a memory area to keep the initial NP area off-bounds
|
|
|
|
//
|
|
|
|
BaseAddress = MmNonPagedPoolStart;
|
|
|
|
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
|
|
|
|
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
|
|
|
|
&BaseAddress,
|
|
|
|
MmSizeOfNonPagedPoolInBytes,
|
|
|
|
PAGE_READWRITE,
|
|
|
|
&MArea,
|
|
|
|
TRUE,
|
|
|
|
0,
|
|
|
|
BoundaryAddressMultiple);
|
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
|
|
|
|
|
|
|
//
|
|
|
|
// And we need one more for the system NP
|
2009-06-21 06:36:45 +00:00
|
|
|
//
|
- Fix a bug in memory area creation: Static memory areas had the static flag embedded in their type, so code that was switch()ing on the type would fail to recognize the actual type, because MEMORY_AREA_STATIC was ORed in.
- Add a new memory area type: MEMORY_AREA_OWNED_BY_ARM3. This will allow us to instruct the ReactOS Memory MAnager to "Back. The Fuck. Off." during page faults and such, so we can handle page faults inside ARM3-owned PTEs ourselves.
- Right now, all ARM3 PTEs and data is nonpaged, so no page faults should happen, but this may change in the future.
- Also will allow us to manage our own PDEs so we can do on-demand inpage instead of syncing with the ReactOS Mm hack cache.
- Create all memory areas in one shot in MmCreateSystemMemoryAreas (get rid of MiInitPageDirectoryMap and MiInitPagedPool memory area creation).
- Mark all of ours as owned by ARM3.
- Make them all static.
- The only non-ARM3 one right now is paged pool, we own all the other static areas.
- Move this code into mm, instead of mm/ARM3, since memory areas are not an ARM3 concept.
- Also create memory areas for session space, session view, and other ARM3 memory ranges, so nobody touches those ranges.
- Dump the kernel address space after all this is done, in a MmDbg function in mm.
- This cleans up ARM3 of some ROS-specific code, and also collapses Phase 1 and 2 into a single phase.
svn path=/trunk/; revision=43486
2009-10-15 18:54:35 +00:00
|
|
|
BaseAddress = MmNonPagedSystemStart;
|
|
|
|
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
|
|
|
|
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
|
|
|
|
&BaseAddress,
|
|
|
|
(ULONG_PTR)MmNonPagedPoolEnd -
|
|
|
|
(ULONG_PTR)MmNonPagedSystemStart,
|
|
|
|
PAGE_READWRITE,
|
|
|
|
&MArea,
|
|
|
|
TRUE,
|
|
|
|
0,
|
|
|
|
BoundaryAddressMultiple);
|
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
|
|
|
|
|
|
|
//
|
|
|
|
// We also need one for system view space
|
|
|
|
//
|
|
|
|
BaseAddress = MiSystemViewStart;
|
|
|
|
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
|
|
|
|
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
|
|
|
|
&BaseAddress,
|
|
|
|
MmSystemViewSize,
|
|
|
|
PAGE_READWRITE,
|
|
|
|
&MArea,
|
|
|
|
TRUE,
|
|
|
|
0,
|
|
|
|
BoundaryAddressMultiple);
|
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
|
|
|
|
|
|
|
//
|
|
|
|
// And another for session space
|
|
|
|
//
|
|
|
|
BaseAddress = MmSessionBase;
|
|
|
|
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
|
|
|
|
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
|
|
|
|
&BaseAddress,
|
|
|
|
(ULONG_PTR)MiSessionSpaceEnd -
|
|
|
|
(ULONG_PTR)MmSessionBase,
|
|
|
|
PAGE_READWRITE,
|
|
|
|
&MArea,
|
|
|
|
TRUE,
|
|
|
|
0,
|
|
|
|
BoundaryAddressMultiple);
|
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
|
|
|
|
|
|
|
//
|
|
|
|
// One more for ARM paged pool
|
|
|
|
//
|
|
|
|
BaseAddress = MmPagedPoolStart;
|
|
|
|
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
|
|
|
|
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
|
|
|
|
&BaseAddress,
|
|
|
|
MmSizeOfPagedPoolInBytes,
|
|
|
|
PAGE_READWRITE,
|
|
|
|
&MArea,
|
|
|
|
TRUE,
|
|
|
|
0,
|
|
|
|
BoundaryAddressMultiple);
|
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
|
|
|
|
2009-06-21 06:36:45 +00:00
|
|
|
//
|
|
|
|
// Next, the KPCR
|
|
|
|
//
|
|
|
|
BaseAddress = (PVOID)PCR;
|
2009-11-04 22:40:18 +00:00
|
|
|
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
|
|
|
|
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
|
|
|
|
&BaseAddress,
|
|
|
|
PAGE_SIZE * KeNumberProcessors,
|
|
|
|
PAGE_READWRITE,
|
|
|
|
&MArea,
|
|
|
|
TRUE,
|
|
|
|
0,
|
|
|
|
BoundaryAddressMultiple);
|
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
- Fix a bug in memory area creation: Static memory areas had the static flag embedded in their type, so code that was switch()ing on the type would fail to recognize the actual type, because MEMORY_AREA_STATIC was ORed in.
- Add a new memory area type: MEMORY_AREA_OWNED_BY_ARM3. This will allow us to instruct the ReactOS Memory MAnager to "Back. The Fuck. Off." during page faults and such, so we can handle page faults inside ARM3-owned PTEs ourselves.
- Right now, all ARM3 PTEs and data is nonpaged, so no page faults should happen, but this may change in the future.
- Also will allow us to manage our own PDEs so we can do on-demand inpage instead of syncing with the ReactOS Mm hack cache.
- Create all memory areas in one shot in MmCreateSystemMemoryAreas (get rid of MiInitPageDirectoryMap and MiInitPagedPool memory area creation).
- Mark all of ours as owned by ARM3.
- Make them all static.
- The only non-ARM3 one right now is paged pool, we own all the other static areas.
- Move this code into mm, instead of mm/ARM3, since memory areas are not an ARM3 concept.
- Also create memory areas for session space, session view, and other ARM3 memory ranges, so nobody touches those ranges.
- Dump the kernel address space after all this is done, in a MmDbg function in mm.
- This cleans up ARM3 of some ROS-specific code, and also collapses Phase 1 and 2 into a single phase.
svn path=/trunk/; revision=43486
2009-10-15 18:54:35 +00:00
|
|
|
|
2009-06-21 06:36:45 +00:00
|
|
|
//
|
|
|
|
// Now the KUSER_SHARED_DATA
|
|
|
|
//
|
|
|
|
BaseAddress = (PVOID)KI_USER_SHARED_DATA;
|
2009-11-04 22:40:18 +00:00
|
|
|
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
|
|
|
|
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
|
|
|
|
&BaseAddress,
|
|
|
|
PAGE_SIZE,
|
|
|
|
PAGE_READWRITE,
|
|
|
|
&MArea,
|
|
|
|
TRUE,
|
|
|
|
0,
|
|
|
|
BoundaryAddressMultiple);
|
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
|
|
|
|
|
|
|
//
|
|
|
|
// And the debugger mapping
|
|
|
|
//
|
|
|
|
BaseAddress = MI_DEBUG_MAPPING;
|
|
|
|
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
|
|
|
|
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
|
|
|
|
&BaseAddress,
|
|
|
|
PAGE_SIZE,
|
|
|
|
PAGE_READWRITE,
|
|
|
|
&MArea,
|
|
|
|
TRUE,
|
|
|
|
0,
|
|
|
|
BoundaryAddressMultiple);
|
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
|
|
|
|
|
|
|
#if defined(_X86_)
|
|
|
|
//
|
2010-10-05 15:59:47 +00:00
|
|
|
// Finally, reserve the 2 pages we currently make use of for HAL mappings
|
2009-11-04 22:40:18 +00:00
|
|
|
//
|
|
|
|
BaseAddress = (PVOID)0xFFC00000;
|
|
|
|
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
|
|
|
|
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
|
|
|
|
&BaseAddress,
|
|
|
|
PAGE_SIZE * 2,
|
|
|
|
PAGE_READWRITE,
|
|
|
|
&MArea,
|
|
|
|
TRUE,
|
|
|
|
0,
|
|
|
|
BoundaryAddressMultiple);
|
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
|
|
|
#endif
|
2000-07-04 08:52:47 +00:00
|
|
|
}
|
|
|
|
|
- Fix a bug in memory area creation: Static memory areas had the static flag embedded in their type, so code that was switch()ing on the type would fail to recognize the actual type, because MEMORY_AREA_STATIC was ORed in.
- Add a new memory area type: MEMORY_AREA_OWNED_BY_ARM3. This will allow us to instruct the ReactOS Memory MAnager to "Back. The Fuck. Off." during page faults and such, so we can handle page faults inside ARM3-owned PTEs ourselves.
- Right now, all ARM3 PTEs and data is nonpaged, so no page faults should happen, but this may change in the future.
- Also will allow us to manage our own PDEs so we can do on-demand inpage instead of syncing with the ReactOS Mm hack cache.
- Create all memory areas in one shot in MmCreateSystemMemoryAreas (get rid of MiInitPageDirectoryMap and MiInitPagedPool memory area creation).
- Mark all of ours as owned by ARM3.
- Make them all static.
- The only non-ARM3 one right now is paged pool, we own all the other static areas.
- Move this code into mm, instead of mm/ARM3, since memory areas are not an ARM3 concept.
- Also create memory areas for session space, session view, and other ARM3 memory ranges, so nobody touches those ranges.
- Dump the kernel address space after all this is done, in a MmDbg function in mm.
- This cleans up ARM3 of some ROS-specific code, and also collapses Phase 1 and 2 into a single phase.
svn path=/trunk/; revision=43486
2009-10-15 18:54:35 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
MiDbgDumpAddressSpace(VOID)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Print the memory layout
|
|
|
|
//
|
|
|
|
DPRINT1(" 0x%p - 0x%p\t%s\n",
|
|
|
|
MmSystemRangeStart,
|
|
|
|
(ULONG_PTR)MmSystemRangeStart + MmBootImageSize,
|
|
|
|
"Boot Loaded Image");
|
|
|
|
DPRINT1(" 0x%p - 0x%p\t%s\n",
|
2010-06-06 15:59:42 +00:00
|
|
|
MmPfnDatabase,
|
|
|
|
(ULONG_PTR)MmPfnDatabase + (MxPfnAllocation << PAGE_SHIFT),
|
- Fix a bug in memory area creation: Static memory areas had the static flag embedded in their type, so code that was switch()ing on the type would fail to recognize the actual type, because MEMORY_AREA_STATIC was ORed in.
- Add a new memory area type: MEMORY_AREA_OWNED_BY_ARM3. This will allow us to instruct the ReactOS Memory MAnager to "Back. The Fuck. Off." during page faults and such, so we can handle page faults inside ARM3-owned PTEs ourselves.
- Right now, all ARM3 PTEs and data is nonpaged, so no page faults should happen, but this may change in the future.
- Also will allow us to manage our own PDEs so we can do on-demand inpage instead of syncing with the ReactOS Mm hack cache.
- Create all memory areas in one shot in MmCreateSystemMemoryAreas (get rid of MiInitPageDirectoryMap and MiInitPagedPool memory area creation).
- Mark all of ours as owned by ARM3.
- Make them all static.
- The only non-ARM3 one right now is paged pool, we own all the other static areas.
- Move this code into mm, instead of mm/ARM3, since memory areas are not an ARM3 concept.
- Also create memory areas for session space, session view, and other ARM3 memory ranges, so nobody touches those ranges.
- Dump the kernel address space after all this is done, in a MmDbg function in mm.
- This cleans up ARM3 of some ROS-specific code, and also collapses Phase 1 and 2 into a single phase.
svn path=/trunk/; revision=43486
2009-10-15 18:54:35 +00:00
|
|
|
"PFN Database");
|
|
|
|
DPRINT1(" 0x%p - 0x%p\t%s\n",
|
|
|
|
MmNonPagedPoolStart,
|
|
|
|
(ULONG_PTR)MmNonPagedPoolStart + MmSizeOfNonPagedPoolInBytes,
|
|
|
|
"ARM³ Non Paged Pool");
|
|
|
|
DPRINT1(" 0x%p - 0x%p\t%s\n",
|
|
|
|
MiSystemViewStart,
|
|
|
|
(ULONG_PTR)MiSystemViewStart + MmSystemViewSize,
|
|
|
|
"System View Space");
|
|
|
|
DPRINT1(" 0x%p - 0x%p\t%s\n",
|
|
|
|
MmSessionBase,
|
|
|
|
MiSessionSpaceEnd,
|
|
|
|
"Session Space");
|
|
|
|
DPRINT1(" 0x%p - 0x%p\t%s\n",
|
|
|
|
PTE_BASE, PDE_BASE,
|
|
|
|
"Page Tables");
|
|
|
|
DPRINT1(" 0x%p - 0x%p\t%s\n",
|
|
|
|
PDE_BASE, HYPER_SPACE,
|
|
|
|
"Page Directories");
|
|
|
|
DPRINT1(" 0x%p - 0x%p\t%s\n",
|
|
|
|
HYPER_SPACE, HYPER_SPACE + (4 * 1024 * 1024),
|
|
|
|
"Hyperspace");
|
|
|
|
DPRINT1(" 0x%p - 0x%p\t%s\n",
|
|
|
|
MmPagedPoolStart,
|
|
|
|
(ULONG_PTR)MmPagedPoolStart + MmSizeOfPagedPoolInBytes,
|
|
|
|
"ARM³ Paged Pool");
|
|
|
|
DPRINT1(" 0x%p - 0x%p\t%s\n",
|
|
|
|
MmNonPagedSystemStart, MmNonPagedPoolExpansionStart,
|
|
|
|
"System PTE Space");
|
|
|
|
DPRINT1(" 0x%p - 0x%p\t%s\n",
|
|
|
|
MmNonPagedPoolExpansionStart, MmNonPagedPoolEnd,
|
|
|
|
"Non Paged Pool Expansion PTE Space");
|
|
|
|
}
|
|
|
|
|
2010-10-05 15:55:52 +00:00
|
|
|
NTSTATUS NTAPI
|
|
|
|
MmMpwThreadMain(PVOID Ignored)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG PagesWritten;
|
|
|
|
LARGE_INTEGER Timeout;
|
|
|
|
|
|
|
|
Timeout.QuadPart = -50000000;
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
Status = KeWaitForSingleObject(&MpwThreadEvent,
|
|
|
|
0,
|
|
|
|
KernelMode,
|
|
|
|
FALSE,
|
|
|
|
&Timeout);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DbgPrint("MpwThread: Wait failed\n");
|
|
|
|
KeBugCheck(MEMORY_MANAGEMENT);
|
|
|
|
return(STATUS_UNSUCCESSFUL);
|
|
|
|
}
|
|
|
|
|
|
|
|
PagesWritten = 0;
|
|
|
|
|
|
|
|
CcRosFlushDirtyPages(128, &PagesWritten);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
MmInitMpwThread(VOID)
|
|
|
|
{
|
|
|
|
KPRIORITY Priority;
|
|
|
|
NTSTATUS Status;
|
|
|
|
CLIENT_ID MpwThreadId;
|
|
|
|
|
|
|
|
KeInitializeEvent(&MpwThreadEvent, SynchronizationEvent, FALSE);
|
|
|
|
|
|
|
|
Status = PsCreateSystemThread(&MpwThreadHandle,
|
|
|
|
THREAD_ALL_ACCESS,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&MpwThreadId,
|
|
|
|
(PKSTART_ROUTINE) MmMpwThreadMain,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return(Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
Priority = 27;
|
|
|
|
NtSetInformationThread(MpwThreadHandle,
|
|
|
|
ThreadPriority,
|
|
|
|
&Priority,
|
|
|
|
sizeof(Priority));
|
|
|
|
|
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
MmInitBsmThread(VOID)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
HANDLE ThreadHandle;
|
|
|
|
|
|
|
|
/* Create the thread */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes, NULL, 0, NULL, NULL);
|
|
|
|
Status = PsCreateSystemThread(&ThreadHandle,
|
|
|
|
THREAD_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
KeBalanceSetManager,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Close the handle and return status */
|
|
|
|
ZwClose(ThreadHandle);
|
|
|
|
return Status;
|
|
|
|
}
|
[NTOS]: Instead of having an LRU linked list of working set pages, we instead have a bitmap.
Advantage: Pages are only in a linked list when they are NOT active (free/zeroed, for now). This makes the LIST_ENTRY fields usable when a page is active, so we can store data in there. This will make it easier to sync our PFN format with Windows.
Advantage: It's a lot faster to set/clear bits than to do list operations (both still O1 though). Scanning for the bit is a bit slower than parsing a list, on the other hand, so it's a toss.
Disadvantage: We lose LRU, which in theory makes us cannibalize working sets randomly instead of by-usage. However, considering the speed of ReactOS paging, and the effects of canabalizing the WS in the first place, I doubt this is really a problem.
The main point of this is advantage #1 -- making used pages not be on any lists. This will allow us to almost 100% sync the PFN layouts, which will lead to the eventual negation of any temporary disavantages.
svn path=/trunk/; revision=45616
2010-02-19 00:46:35 +00:00
|
|
|
|
2007-01-25 17:51:45 +00:00
|
|
|
BOOLEAN
|
2005-09-14 01:05:50 +00:00
|
|
|
NTAPI
|
2007-01-25 17:51:45 +00:00
|
|
|
MmInitSystem(IN ULONG Phase,
|
|
|
|
IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
2000-07-04 08:52:47 +00:00
|
|
|
{
|
2010-02-10 13:56:54 +00:00
|
|
|
extern MMPTE ValidKernelPte;
|
2009-07-27 02:13:19 +00:00
|
|
|
PMMPTE PointerPte;
|
2010-02-10 13:56:54 +00:00
|
|
|
MMPTE TempPte = ValidKernelPte;
|
2009-07-27 02:13:19 +00:00
|
|
|
PFN_NUMBER PageFrameNumber;
|
|
|
|
|
2010-10-18 23:07:09 +00:00
|
|
|
/* Initialize the kernel address space */
|
|
|
|
ASSERT(Phase == 1);
|
|
|
|
KeInitializeGuardedMutex(&PsIdleProcess->AddressCreationLock);
|
|
|
|
MmKernelAddressSpace = &PsIdleProcess->Vm;
|
|
|
|
|
|
|
|
/* Intialize system memory areas */
|
|
|
|
MiInitSystemMemoryAreas();
|
|
|
|
|
|
|
|
/* Dump the address space */
|
|
|
|
MiDbgDumpAddressSpace();
|
|
|
|
|
|
|
|
MmInitGlobalKernelPageDirectory();
|
|
|
|
MiInitializeUserPfnBitmap();
|
|
|
|
MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
|
|
|
|
MmInitializeRmapList();
|
|
|
|
MmInitializePageOp();
|
|
|
|
MmInitSectionImplementation();
|
|
|
|
MmInitPagingFile();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create a PTE to double-map the shared data section. We allocate it
|
|
|
|
// from paged pool so that we can't fault when trying to touch the PTE
|
|
|
|
// itself (to map it), since paged pool addresses will already be mapped
|
|
|
|
// by the fault handler.
|
|
|
|
//
|
|
|
|
MmSharedUserDataPte = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(MMPTE),
|
|
|
|
' mM');
|
|
|
|
if (!MmSharedUserDataPte) return FALSE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now get the PTE for shared data, and read the PFN that holds it
|
|
|
|
//
|
|
|
|
PointerPte = MiAddressToPte((PVOID)KI_USER_SHARED_DATA);
|
|
|
|
ASSERT(PointerPte->u.Hard.Valid == 1);
|
|
|
|
PageFrameNumber = PFN_FROM_PTE(PointerPte);
|
|
|
|
|
|
|
|
/* Build the PTE and write it */
|
|
|
|
MI_MAKE_HARDWARE_PTE_KERNEL(&TempPte,
|
|
|
|
PointerPte,
|
|
|
|
MM_READONLY,
|
|
|
|
PageFrameNumber);
|
|
|
|
*MmSharedUserDataPte = TempPte;
|
|
|
|
|
|
|
|
/* Setup the memory threshold events */
|
|
|
|
if (!MiInitializeMemoryEvents()) return FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unmap low memory
|
|
|
|
*/
|
|
|
|
MiInitBalancerThread();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise the modified page writer.
|
|
|
|
*/
|
|
|
|
MmInitMpwThread();
|
|
|
|
|
|
|
|
/* Initialize the balance set manager */
|
|
|
|
MmInitBsmThread();
|
2007-01-25 17:51:45 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2000-07-04 08:52:47 +00:00
|
|
|
}
|
|
|
|
|