- 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
This commit is contained in:
ReactOS Portable Systems Group 2009-06-28 07:52:30 +00:00
parent 6da15076da
commit 9aa3e64dfc
8 changed files with 238 additions and 266 deletions

View file

@ -163,6 +163,38 @@ MiTrimMemoryConsumer(ULONG Consumer)
}
}
NTSTATUS
MmTrimUserMemory(ULONG Target, ULONG Priority, PULONG NrFreedPages)
{
PFN_TYPE CurrentPage;
PFN_TYPE NextPage;
NTSTATUS Status;
(*NrFreedPages) = 0;
CurrentPage = MmGetLRUFirstUserPage();
while (CurrentPage != 0 && Target > 0)
{
NextPage = MmGetLRUNextUserPage(CurrentPage);
Status = MmPageOutPhysicalAddress(CurrentPage);
if (NT_SUCCESS(Status))
{
DPRINT("Succeeded\n");
Target--;
(*NrFreedPages)++;
}
else if (Status == STATUS_PAGEFILE_QUOTA)
{
MmRemoveLRUUserPage(CurrentPage);
MmInsertLRULastUserPage(CurrentPage);
}
CurrentPage = NextPage;
}
return(STATUS_SUCCESS);
}
VOID
NTAPI
MmRebalanceMemoryConsumers(VOID)

View file

@ -1,58 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/kmap.c
* PURPOSE: Implements the kernel memory pool
*
* PROGRAMMERS: David Welch (welch@cwcom.net)
*/
/* INCLUDES ****************************************************************/
#include <ntoskrnl.h>
#define NDEBUG
#include <debug.h>
/* GLOBALS *****************************************************************/
/* FUNCTIONS ***************************************************************/
NTSTATUS
NTAPI
MiZeroPage(PFN_TYPE Page)
{
KIRQL Irql;
PVOID TempAddress;
Irql = KeRaiseIrqlToDpcLevel();
TempAddress = MiMapPageToZeroInHyperSpace(Page);
if (TempAddress == NULL)
{
return(STATUS_NO_MEMORY);
}
memset(TempAddress, 0, PAGE_SIZE);
MiUnmapPagesInZeroSpace(TempAddress, 1);
KeLowerIrql(Irql);
return(STATUS_SUCCESS);
}
NTSTATUS
NTAPI
MiCopyFromUserPage(PFN_TYPE DestPage, PVOID SourceAddress)
{
PEPROCESS Process;
KIRQL Irql;
PVOID TempAddress;
Process = PsGetCurrentProcess();
TempAddress = MiMapPageInHyperSpace(Process, DestPage, &Irql);
if (TempAddress == NULL)
{
return(STATUS_NO_MEMORY);
}
memcpy(TempAddress, SourceAddress, PAGE_SIZE);
MiUnmapPageInHyperSpace(Process, TempAddress, Irql);
return(STATUS_SUCCESS);
}
/* EOF */

View file

@ -1,30 +1,18 @@
/*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/mm.c
* FILE: ntoskrnl/mm/mmfault.c
* PURPOSE: Kernel memory managment functions
* PROGRAMMERS: David Welch (welch@cwcom.net)
*/
/* INCLUDES *****************************************************************/
/* INCLUDES *******************************************************************/
#include <ntoskrnl.h>
#define NDEBUG
#include <debug.h>
/* GLOBALS *****************************************************************/
ULONG MmUserProbeAddress = 0;
PVOID MmHighestUserAddress = NULL;
PBOOLEAN Mm64BitPhysicalAddress = FALSE;
PVOID MmSystemRangeStart = NULL;
ULONG MmReadClusterSize;
MM_STATS MmStats;
PMMSUPPORT MmKernelAddressSpace;
/* FUNCTIONS ****************************************************************/
/* PRIVATE FUNCTIONS **********************************************************/
VOID
FASTCALL
@ -57,54 +45,6 @@ MiSyncForContextSwitch(IN PKTHREAD Thread)
KERNEL_LARGE_STACK_SIZE : KERNEL_STACK_SIZE);
}
/*
* @implemented
*/
BOOLEAN NTAPI MmIsNonPagedSystemAddressValid(PVOID VirtualAddress)
{
return MmIsAddressValid(VirtualAddress);
}
/*
* @implemented
*/
BOOLEAN NTAPI MmIsAddressValid(PVOID VirtualAddress)
/*
* FUNCTION: Checks whether the given address is valid for a read or write
* ARGUMENTS:
* VirtualAddress = address to check
* RETURNS: True if the access would be valid
* False if the access would cause a page fault
* NOTES: This function checks whether a byte access to the page would
* succeed. Is this realistic for RISC processors which don't
* allow byte granular access?
*/
{
MEMORY_AREA* MemoryArea;
PMMSUPPORT AddressSpace;
if (VirtualAddress >= MmSystemRangeStart)
{
AddressSpace = MmGetKernelAddressSpace();
}
else
{
AddressSpace = &PsGetCurrentProcess()->Vm;
}
MmLockAddressSpace(AddressSpace);
MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace,
VirtualAddress);
if (MemoryArea == NULL || MemoryArea->DeleteInProgress)
{
MmUnlockAddressSpace(AddressSpace);
return(FALSE);
}
MmUnlockAddressSpace(AddressSpace);
return(TRUE);
}
NTSTATUS
NTAPI
MmpAccessFault(KPROCESSOR_MODE Mode,
@ -379,113 +319,40 @@ MmCommitPagedPoolAddress(PVOID Address, BOOLEAN Locked)
return(Status);
}
/* Miscellanea functions: they may fit somewhere else */
/* PUBLIC FUNCTIONS ***********************************************************/
/*
* @implemented
*/
BOOLEAN
NTAPI
MmIsRecursiveIoFault (VOID)
MmIsAddressValid(IN PVOID VirtualAddress)
{
PETHREAD Thread = PsGetCurrentThread();
return (Thread->DisablePageFaultClustering | Thread->ForwardClusterOnly);
}
/*
* @unimplemented
*/
NTSTATUS
NTAPI
MmMapUserAddressesToPage(IN PVOID BaseAddress,
IN SIZE_T NumberOfBytes,
IN PVOID PageAddress)
{
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
}
/*
* @unimplemented
*/
ULONG NTAPI
MmAdjustWorkingSetSize (ULONG Unknown0,
ULONG Unknown1,
ULONG Unknown2,
ULONG Unknown3)
{
UNIMPLEMENTED;
return (0);
}
/*
* @unimplemented
*/
BOOLEAN
NTAPI
MmSetAddressRangeModified (
IN PVOID Address,
IN ULONG Length
)
{
UNIMPLEMENTED;
return (FALSE);
}
/*
* @unimplemented
*/
NTSTATUS
NTAPI
NtGetWriteWatch(IN HANDLE ProcessHandle,
IN ULONG Flags,
IN PVOID BaseAddress,
IN ULONG RegionSize,
IN PVOID *UserAddressArray,
OUT PULONG EntriesInUserAddressArray,
OUT PULONG Granularity)
{
if (!EntriesInUserAddressArray || !Granularity)
MEMORY_AREA* MemoryArea;
PMMSUPPORT AddressSpace;
DPRINT1("WARNING: %s returns bogus result\n", __FUNCTION__);
if (VirtualAddress >= MmSystemRangeStart)
{
return STATUS_ACCESS_VIOLATION;
AddressSpace = MmGetKernelAddressSpace();
}
if (!*EntriesInUserAddressArray || !RegionSize)
else
{
return STATUS_INVALID_PARAMETER;
AddressSpace = &PsGetCurrentProcess()->Vm;
}
if (!UserAddressArray)
MmLockAddressSpace(AddressSpace);
MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace,
VirtualAddress);
if (MemoryArea == NULL || MemoryArea->DeleteInProgress)
{
return STATUS_ACCESS_VIOLATION;
MmUnlockAddressSpace(AddressSpace);
return(FALSE);
}
/* HACK: Set granularity to PAGE_SIZE */
*Granularity = PAGE_SIZE;
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
}
/*
* @unimplemented
*/
NTSTATUS
NTAPI
NtResetWriteWatch(IN HANDLE ProcessHandle,
IN PVOID BaseAddress,
IN ULONG RegionSize)
{
if (!RegionSize)
{
return STATUS_INVALID_PARAMETER;
}
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
MmUnlockAddressSpace(AddressSpace);
return(TRUE);
}
/* EOF */

View file

@ -55,6 +55,13 @@ ULONG_PTR MiKSeg0Start, MiKSeg0End;
ULONG_PTR MmPfnDatabaseEnd;
PMEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptor;
MEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptorOrg;
ULONG MmUserProbeAddress = 0;
PVOID MmHighestUserAddress = NULL;
PBOOLEAN Mm64BitPhysicalAddress = FALSE;
PVOID MmSystemRangeStart = NULL;
ULONG MmReadClusterSize;
MM_STATS MmStats;
PMMSUPPORT MmKernelAddressSpace;
extern KMUTANT MmSystemLoadLock;
extern HANDLE MpwThreadHandle;
extern BOOLEAN MpwThreadShouldTerminate;

120
reactos/ntoskrnl/mm/mmsup.c Normal file
View file

@ -0,0 +1,120 @@
/*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/mmsup.c
* PURPOSE: Kernel memory managment functions
* PROGRAMMERS: David Welch (welch@cwcom.net)
*/
/* INCLUDES *******************************************************************/
#include <ntoskrnl.h>
#define NDEBUG
#include <debug.h>
/* PRIVATE FUNCTIONS **********************************************************/
NTSTATUS
NTAPI
MiZeroPage(PFN_TYPE Page)
{
KIRQL Irql;
PVOID TempAddress;
Irql = KeRaiseIrqlToDpcLevel();
TempAddress = MiMapPageToZeroInHyperSpace(Page);
if (TempAddress == NULL)
{
return(STATUS_NO_MEMORY);
}
memset(TempAddress, 0, PAGE_SIZE);
MiUnmapPagesInZeroSpace(TempAddress, 1);
KeLowerIrql(Irql);
return(STATUS_SUCCESS);
}
NTSTATUS
NTAPI
MiCopyFromUserPage(PFN_TYPE DestPage, PVOID SourceAddress)
{
PEPROCESS Process;
KIRQL Irql;
PVOID TempAddress;
Process = PsGetCurrentProcess();
TempAddress = MiMapPageInHyperSpace(Process, DestPage, &Irql);
if (TempAddress == NULL)
{
return(STATUS_NO_MEMORY);
}
memcpy(TempAddress, SourceAddress, PAGE_SIZE);
MiUnmapPageInHyperSpace(Process, TempAddress, Irql);
return(STATUS_SUCCESS);
}
/* PRIVATE FUNCTIONS **********************************************************/
/* Miscellanea functions: they may fit somewhere else */
/*
* @implemented
*/
BOOLEAN
NTAPI
MmIsRecursiveIoFault (VOID)
{
PETHREAD Thread = PsGetCurrentThread();
return (Thread->DisablePageFaultClustering | Thread->ForwardClusterOnly);
}
/*
* @unimplemented
*/
NTSTATUS
NTAPI
MmMapUserAddressesToPage(IN PVOID BaseAddress,
IN SIZE_T NumberOfBytes,
IN PVOID PageAddress)
{
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
}
/*
* @unimplemented
*/
ULONG NTAPI
MmAdjustWorkingSetSize (ULONG Unknown0,
ULONG Unknown1,
ULONG Unknown2,
ULONG Unknown3)
{
UNIMPLEMENTED;
return (0);
}
/*
* @unimplemented
*/
BOOLEAN
NTAPI
MmSetAddressRangeModified (
IN PVOID Address,
IN ULONG Length
)
{
UNIMPLEMENTED;
return (FALSE);
}
/*
* @implemented
*/
BOOLEAN NTAPI MmIsNonPagedSystemAddressValid(PVOID VirtualAddress)
{
DPRINT1("WARNING: %s returns bogus result\n", __FUNCTION__);
return MmIsAddressValid(VirtualAddress);
}
/* EOF */

View file

@ -1151,4 +1151,57 @@ NtFlushVirtualMemory(IN HANDLE ProcessHandle,
return STATUS_SUCCESS;
}
/*
* @unimplemented
*/
NTSTATUS
NTAPI
NtGetWriteWatch(IN HANDLE ProcessHandle,
IN ULONG Flags,
IN PVOID BaseAddress,
IN ULONG RegionSize,
IN PVOID *UserAddressArray,
OUT PULONG EntriesInUserAddressArray,
OUT PULONG Granularity)
{
if (!EntriesInUserAddressArray || !Granularity)
{
return STATUS_ACCESS_VIOLATION;
}
if (!*EntriesInUserAddressArray || !RegionSize)
{
return STATUS_INVALID_PARAMETER;
}
if (!UserAddressArray)
{
return STATUS_ACCESS_VIOLATION;
}
/* HACK: Set granularity to PAGE_SIZE */
*Granularity = PAGE_SIZE;
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
}
/*
* @unimplemented
*/
NTSTATUS
NTAPI
NtResetWriteWatch(IN HANDLE ProcessHandle,
IN PVOID BaseAddress,
IN ULONG RegionSize)
{
if (!RegionSize)
{
return STATUS_INVALID_PARAMETER;
}
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
}
/* EOF */

View file

@ -1,48 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/wset.c
* PURPOSE: Manages working sets
*
* PROGRAMMERS: David Welch (welch@cwcom.net)
*/
/* INCLUDES *****************************************************************/
#include <ntoskrnl.h>
#define NDEBUG
#include <debug.h>
/* FUNCTIONS *****************************************************************/
NTSTATUS
MmTrimUserMemory(ULONG Target, ULONG Priority, PULONG NrFreedPages)
{
PFN_TYPE CurrentPage;
PFN_TYPE NextPage;
NTSTATUS Status;
(*NrFreedPages) = 0;
CurrentPage = MmGetLRUFirstUserPage();
while (CurrentPage != 0 && Target > 0)
{
NextPage = MmGetLRUNextUserPage(CurrentPage);
Status = MmPageOutPhysicalAddress(CurrentPage);
if (NT_SUCCESS(Status))
{
DPRINT("Succeeded\n");
Target--;
(*NrFreedPages)++;
}
else if (Status == STATUS_PAGEFILE_QUOTA)
{
MmRemoveLRUUserPage(CurrentPage);
MmInsertLRULastUserPage(CurrentPage);
}
CurrentPage = NextPage;
}
return(STATUS_SUCCESS);
}

View file

@ -374,10 +374,10 @@
<file>balance.c</file>
<file>dbgpool.c</file>
<file>freelist.c</file>
<file>kmap.c</file>
<file>marea.c</file>
<file>mdlsup.c</file>
<file>mm.c</file>
<file>mmfault.c</file>
<file>mmsup.c</file>
<file>mminit.c</file>
<file>mpw.c</file>
<file>ncache.c</file>
@ -393,7 +393,6 @@
<file>section.c</file>
<file>sysldr.c</file>
<file>virtual.c</file>
<file>wset.c</file>
<if property="_ELF_" value="1">
<file>elf32.c</file>
<file>elf64.c</file>