Author: ros-arm-bringup Date: Sun Jun 28 11:52:30 2009 New Revision: 41659
URL: http://svn.reactos.org/svn/reactos?rev=41659&view=rev Log: - 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).
Added: trunk/reactos/ntoskrnl/mm/mmfault.c - copied, changed from r41647, trunk/reactos/ntoskrnl/mm/mm.c trunk/reactos/ntoskrnl/mm/mmsup.c (with props) Removed: trunk/reactos/ntoskrnl/mm/kmap.c trunk/reactos/ntoskrnl/mm/mm.c trunk/reactos/ntoskrnl/mm/wset.c Modified: trunk/reactos/ntoskrnl/mm/balance.c trunk/reactos/ntoskrnl/mm/mminit.c trunk/reactos/ntoskrnl/mm/virtual.c trunk/reactos/ntoskrnl/ntoskrnl-generic.rbuild
Modified: trunk/reactos/ntoskrnl/mm/balance.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/balance.c?rev=4... ============================================================================== --- trunk/reactos/ntoskrnl/mm/balance.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/balance.c [iso-8859-1] Sun Jun 28 11:52:30 2009 @@ -161,6 +161,38 @@ { MiMemoryConsumers[Consumer].Trim(Target, 0, &NrFreedPages); } +} + +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
Removed: trunk/reactos/ntoskrnl/mm/kmap.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/kmap.c?rev=4165... ============================================================================== --- trunk/reactos/ntoskrnl/mm/kmap.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/kmap.c (removed) @@ -1,58 +1,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 */
Removed: trunk/reactos/ntoskrnl/mm/mm.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mm.c?rev=41658&... ============================================================================== --- trunk/reactos/ntoskrnl/mm/mm.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/mm.c (removed) @@ -1,491 +1,0 @@ -/* - * COPYRIGHT: See COPYING in the top directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/mm/mm.c - * PURPOSE: Kernel memory managment functions - * PROGRAMMERS: David Welch (welch@cwcom.net) - */ - -/* 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 ****************************************************************/ - -VOID -FASTCALL -MiSyncForProcessAttach(IN PKTHREAD Thread, - IN PEPROCESS Process) -{ - PETHREAD Ethread = CONTAINING_RECORD(Thread, ETHREAD, Tcb); - - /* Hack Sync because Mm is broken */ - MmUpdatePageDir(Process, Ethread, sizeof(ETHREAD)); - MmUpdatePageDir(Process, Ethread->ThreadsProcess, sizeof(EPROCESS)); - MmUpdatePageDir(Process, - (PVOID)Thread->StackLimit, - Thread->LargeStack ? - KERNEL_LARGE_STACK_SIZE : KERNEL_STACK_SIZE); -} - -VOID -FASTCALL -MiSyncForContextSwitch(IN PKTHREAD Thread) -{ - PVOID Process = PsGetCurrentProcess(); - PETHREAD Ethread = CONTAINING_RECORD(Thread, ETHREAD, Tcb); - - /* Hack Sync because Mm is broken */ - MmUpdatePageDir(Process, Ethread->ThreadsProcess, sizeof(EPROCESS)); - MmUpdatePageDir(Process, - (PVOID)Thread->StackLimit, - Thread->LargeStack ? - 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, - ULONG_PTR Address, - BOOLEAN FromMdl) -{ - PMMSUPPORT AddressSpace; - MEMORY_AREA* MemoryArea; - NTSTATUS Status; - BOOLEAN Locked = FromMdl; - - DPRINT("MmAccessFault(Mode %d, Address %x)\n", Mode, Address); - - if (KeGetCurrentIrql() >= DISPATCH_LEVEL) - { - DPRINT1("Page fault at high IRQL was %d\n", KeGetCurrentIrql()); - return(STATUS_UNSUCCESSFUL); - } - if (PsGetCurrentProcess() == NULL) - { - DPRINT("No current process\n"); - return(STATUS_UNSUCCESSFUL); - } - - /* - * Find the memory area for the faulting address - */ - if (Address >= (ULONG_PTR)MmSystemRangeStart) - { - /* - * Check permissions - */ - if (Mode != KernelMode) - { - DPRINT1("MmAccessFault(Mode %d, Address %x)\n", Mode, Address); - return(STATUS_ACCESS_VIOLATION); - } - AddressSpace = MmGetKernelAddressSpace(); - } - else - { - AddressSpace = &PsGetCurrentProcess()->Vm; - } - - if (!FromMdl) - { - MmLockAddressSpace(AddressSpace); - } - do - { - MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, (PVOID)Address); - if (MemoryArea == NULL || MemoryArea->DeleteInProgress) - { - if (!FromMdl) - { - MmUnlockAddressSpace(AddressSpace); - } - return (STATUS_ACCESS_VIOLATION); - } - - switch (MemoryArea->Type) - { - case MEMORY_AREA_SYSTEM: - Status = STATUS_ACCESS_VIOLATION; - break; - - case MEMORY_AREA_PAGED_POOL: - Status = STATUS_SUCCESS; - break; - - case MEMORY_AREA_SECTION_VIEW: - Status = MmAccessFaultSectionView(AddressSpace, - MemoryArea, - (PVOID)Address, - Locked); - break; - - case MEMORY_AREA_VIRTUAL_MEMORY: - Status = STATUS_ACCESS_VIOLATION; - break; - - case MEMORY_AREA_SHARED_DATA: - Status = STATUS_ACCESS_VIOLATION; - break; - - default: - Status = STATUS_ACCESS_VIOLATION; - break; - } - } - while (Status == STATUS_MM_RESTART_OPERATION); - - DPRINT("Completed page fault handling\n"); - if (!FromMdl) - { - MmUnlockAddressSpace(AddressSpace); - } - return(Status); -} - -NTSTATUS -NTAPI -MmNotPresentFault(KPROCESSOR_MODE Mode, - ULONG_PTR Address, - BOOLEAN FromMdl) -{ - PMMSUPPORT AddressSpace; - MEMORY_AREA* MemoryArea; - NTSTATUS Status; - BOOLEAN Locked = FromMdl; - PFN_TYPE Pfn; - - DPRINT("MmNotPresentFault(Mode %d, Address %x)\n", Mode, Address); - - if (KeGetCurrentIrql() >= DISPATCH_LEVEL) - { - DPRINT1("Page fault at high IRQL was %d, address %x\n", KeGetCurrentIrql(), Address); - return(STATUS_UNSUCCESSFUL); - } - - /* - * Find the memory area for the faulting address - */ - if (Address >= (ULONG_PTR)MmSystemRangeStart) - { - /* - * Check permissions - */ - if (Mode != KernelMode) - { - DPRINT1("Address: %x\n", Address); - return(STATUS_ACCESS_VIOLATION); - } - AddressSpace = MmGetKernelAddressSpace(); - } - else - { - AddressSpace = &PsGetCurrentProcess()->Vm; - } - - if (!FromMdl) - { - MmLockAddressSpace(AddressSpace); - } - - /* - * Call the memory area specific fault handler - */ - do - { - MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, (PVOID)Address); - if (MemoryArea == NULL || MemoryArea->DeleteInProgress) - { - if (!FromMdl) - { - MmUnlockAddressSpace(AddressSpace); - } - return (STATUS_ACCESS_VIOLATION); - } - - switch (MemoryArea->Type) - { - case MEMORY_AREA_PAGED_POOL: - { - Status = MmCommitPagedPoolAddress((PVOID)Address, Locked); - break; - } - - case MEMORY_AREA_SYSTEM: - Status = STATUS_ACCESS_VIOLATION; - break; - - case MEMORY_AREA_SECTION_VIEW: - Status = MmNotPresentFaultSectionView(AddressSpace, - MemoryArea, - (PVOID)Address, - Locked); - break; - - case MEMORY_AREA_VIRTUAL_MEMORY: - case MEMORY_AREA_PEB_OR_TEB: - Status = MmNotPresentFaultVirtualMemory(AddressSpace, - MemoryArea, - (PVOID)Address, - Locked); - break; - - case MEMORY_AREA_SHARED_DATA: - Pfn = MmGetPhysicalAddress((PVOID)PCR).LowPart >> PAGE_SHIFT; - Pfn++; - Status = - MmCreateVirtualMapping(PsGetCurrentProcess(), - (PVOID)PAGE_ROUND_DOWN(Address), - PAGE_READONLY, - &Pfn, - 1); - break; - - default: - Status = STATUS_ACCESS_VIOLATION; - break; - } - } - while (Status == STATUS_MM_RESTART_OPERATION); - - DPRINT("Completed page fault handling\n"); - if (!FromMdl) - { - MmUnlockAddressSpace(AddressSpace); - } - return(Status); -} - -extern BOOLEAN Mmi386MakeKernelPageTableGlobal(PVOID Address); - -NTSTATUS -NTAPI -MmAccessFault(IN BOOLEAN StoreInstruction, - IN PVOID Address, - IN KPROCESSOR_MODE Mode, - IN PVOID TrapInformation) -{ - /* Cute little hack for ROS */ - if ((ULONG_PTR)Address >= (ULONG_PTR)MmSystemRangeStart) - { -#ifdef _M_IX86 - /* Check for an invalid page directory in kernel mode */ - if (Mmi386MakeKernelPageTableGlobal(Address)) - { - /* All is well with the world */ - return STATUS_SUCCESS; - } -#endif - } - - /* Keep same old ReactOS Behaviour */ - if (StoreInstruction) - { - /* Call access fault */ - return MmpAccessFault(Mode, (ULONG_PTR)Address, TrapInformation ? FALSE : TRUE); - } - else - { - /* Call not present */ - return MmNotPresentFault(Mode, (ULONG_PTR)Address, TrapInformation ? FALSE : TRUE); - } -} - -NTSTATUS -NTAPI -MmCommitPagedPoolAddress(PVOID Address, BOOLEAN Locked) -{ - NTSTATUS Status; - PFN_TYPE AllocatedPage; - Status = MmRequestPageMemoryConsumer(MC_PPOOL, FALSE, &AllocatedPage); - if (!NT_SUCCESS(Status)) - { - MmUnlockAddressSpace(MmGetKernelAddressSpace()); - Status = MmRequestPageMemoryConsumer(MC_PPOOL, TRUE, &AllocatedPage); - MmLockAddressSpace(MmGetKernelAddressSpace()); - } - Status = - MmCreateVirtualMapping(NULL, - (PVOID)PAGE_ROUND_DOWN(Address), - PAGE_READWRITE, - &AllocatedPage, - 1); - if (Locked) - { - MmLockPage(AllocatedPage); - } - return(Status); -} - - - -/* 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); -} - -/* - * @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 */
Copied: trunk/reactos/ntoskrnl/mm/mmfault.c (from r41647, trunk/reactos/ntoskrnl/mm/mm.c) URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mmfault.c?p2=tr... ============================================================================== --- trunk/reactos/ntoskrnl/mm/mm.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/mmfault.c [iso-8859-1] Sun Jun 28 11:52:30 2009 @@ -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 @@ -55,54 +43,6 @@ (PVOID)Thread->StackLimit, Thread->LargeStack ? 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 @@ -379,113 +319,40 @@ return(Status); }
- - -/* Miscellanea functions: they may fit somewhere else */ +/* PUBLIC FUNCTIONS ***********************************************************/
/* * @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); -} - -/* - * @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; +MmIsAddressValid(IN PVOID VirtualAddress) +{ + MEMORY_AREA* MemoryArea; + PMMSUPPORT AddressSpace; + + DPRINT1("WARNING: %s returns bogus result\n", __FUNCTION__); + + 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); }
/* EOF */
Modified: trunk/reactos/ntoskrnl/mm/mminit.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mminit.c?rev=41... ============================================================================== --- trunk/reactos/ntoskrnl/mm/mminit.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/mminit.c [iso-8859-1] Sun Jun 28 11:52:30 2009 @@ -55,6 +55,13 @@ 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;
Added: trunk/reactos/ntoskrnl/mm/mmsup.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mmsup.c?rev=416... ============================================================================== --- trunk/reactos/ntoskrnl/mm/mmsup.c (added) +++ trunk/reactos/ntoskrnl/mm/mmsup.c [iso-8859-1] Sun Jun 28 11:52:30 2009 @@ -1,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 */
Propchange: trunk/reactos/ntoskrnl/mm/mmsup.c ------------------------------------------------------------------------------ svn:eol-style = native
Propchange: trunk/reactos/ntoskrnl/mm/mmsup.c ------------------------------------------------------------------------------ svn:mime-type = text/plain
Modified: trunk/reactos/ntoskrnl/mm/virtual.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/virtual.c?rev=4... ============================================================================== --- trunk/reactos/ntoskrnl/mm/virtual.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/virtual.c [iso-8859-1] Sun Jun 28 11:52:30 2009 @@ -1151,4 +1151,57 @@ 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 */
Removed: trunk/reactos/ntoskrnl/mm/wset.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/wset.c?rev=4165... ============================================================================== --- trunk/reactos/ntoskrnl/mm/wset.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/wset.c (removed) @@ -1,48 +1,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); -}
Modified: trunk/reactos/ntoskrnl/ntoskrnl-generic.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ntoskrnl-generic.r... ============================================================================== --- trunk/reactos/ntoskrnl/ntoskrnl-generic.rbuild [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/ntoskrnl-generic.rbuild [iso-8859-1] Sun Jun 28 11:52:30 2009 @@ -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>