ReactOS  0.4.11-dev-433-g473ca91
mm.h File Reference
#include <internal/arch/mm.h>
Include dependency graph for mm.h:

Go to the source code of this file.

Classes

struct  _MM_SECTION_SEGMENT
 
struct  _MM_IMAGE_SECTION_OBJECT
 
struct  _ROS_SECTION_OBJECT
 
struct  _MEMORY_AREA
 
struct  _MM_RMAP_ENTRY
 
struct  _MMPFNENTRY
 
struct  _MMPFN
 
struct  _MMPFNLIST
 
struct  _MM_MEMORY_CONSUMER
 
struct  _MM_REGION
 
struct  _MMFREE_POOL_ENTRY
 
struct  _MM_PAGED_POOL_INFO
 
struct  _MMPAGING_FILE
 

Macros

#define MMDBG_COPY_WRITE   0x00000001
 
#define MMDBG_COPY_PHYSICAL   0x00000002
 
#define MMDBG_COPY_UNSAFE   0x00000004
 
#define MMDBG_COPY_CACHED   0x00000008
 
#define MMDBG_COPY_UNCACHED   0x00000010
 
#define MMDBG_COPY_WRITE_COMBINED   0x00000020
 
#define MMDBG_COPY_MAX_SIZE   0x8
 
#define MI_STATIC_MEMORY_AREAS   (13)
 
#define MEMORY_AREA_SECTION_VIEW   (1)
 
#define MEMORY_AREA_CACHE   (2)
 
#define MEMORY_AREA_OWNED_BY_ARM3   (15)
 
#define MEMORY_AREA_STATIC   (0x80000000)
 
#define MM_VIRTMEM_GRANULARITY   (64 * 1024)
 
#define STATUS_MM_RESTART_OPERATION   ((NTSTATUS)0xD0000001)
 
#define PAGE_WRITETHROUGH   (1024)
 
#define PAGE_SYSTEM   (2048)
 
#define SEC_PHYSICALMEMORY   (0x80000000)
 
#define MM_PAGEFILE_SEGMENT   (0x1)
 
#define MM_DATAFILE_SEGMENT   (0x2)
 
#define MC_CACHE   (0)
 
#define MC_USER   (1)
 
#define MC_SYSTEM   (2)
 
#define MC_MAXIMUM   (3)
 
#define PAGED_POOL_MASK   1
 
#define MUST_SUCCEED_POOL_MASK   2
 
#define CACHE_ALIGNED_POOL_MASK   4
 
#define QUOTA_POOL_MASK   8
 
#define SESSION_POOL_MASK   32
 
#define VERIFIER_POOL_MASK   64
 
#define MAX_PAGING_FILES   (16)
 
#define MM_ROUND_UP(x, s)   ((PVOID)(((ULONG_PTR)(x)+(s)-1) & ~((ULONG_PTR)(s)-1)))
 
#define MM_ROUND_DOWN(x, s)   ((PVOID)(((ULONG_PTR)(x)) & ~((ULONG_PTR)(s)-1)))
 
#define PAGE_FLAGS_VALID_FOR_SECTION
 
#define PAGE_IS_READABLE
 
#define PAGE_IS_WRITABLE
 
#define PAGE_IS_EXECUTABLE
 
#define PAGE_IS_WRITECOPY
 
#define MM_WAIT_ENTRY   0x7ffffc00
 
#define InterlockedCompareExchangePte(PointerPte, Exchange, Comperand)   InterlockedCompareExchange((PLONG)(PointerPte), Exchange, Comperand)
 
#define InterlockedExchangePte(PointerPte, Value)   InterlockedExchange((PLONG)(PointerPte), Value)
 
#define MA_GetStartingAddress(_MemoryArea)   ((_MemoryArea)->VadNode.StartingVpn << PAGE_SHIFT)
 
#define MA_GetEndingAddress(_MemoryArea)   (((_MemoryArea)->VadNode.EndingVpn + 1) << PAGE_SHIFT)
 
#define MI_SET_USAGE(x)
 
#define MI_SET_PROCESS2(x)
 
#define StartOfAllocation   ReadInProgress
 
#define EndOfAllocation   WriteInProgress
 
#define MM_FREE_POOL_SIGNATURE   'ARM3'
 
#define MI_ASSERT_PFN_LOCK_HELD()   ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL)
 
#define MmDeleteHyperspaceMapping(x)   MiUnmapPageInHyperSpace(HyperProcess, x, HyperIrql);
 

Typedefs

typedef ULONG_PTR SWAPENTRY
 
typedef struct _MM_SECTION_SEGMENT MM_SECTION_SEGMENT
 
typedef struct
_MM_SECTION_SEGMENT
PMM_SECTION_SEGMENT
 
typedef struct
_MM_IMAGE_SECTION_OBJECT 
MM_IMAGE_SECTION_OBJECT
 
typedef struct
_MM_IMAGE_SECTION_OBJECT
PMM_IMAGE_SECTION_OBJECT
 
typedef struct _ROS_SECTION_OBJECT ROS_SECTION_OBJECT
 
typedef struct
_ROS_SECTION_OBJECT
PROS_SECTION_OBJECT
 
typedef struct _MEMORY_AREA MEMORY_AREA
 
typedef struct _MEMORY_AREAPMEMORY_AREA
 
typedef struct _MM_RMAP_ENTRY MM_RMAP_ENTRY
 
typedef struct _MM_RMAP_ENTRYPMM_RMAP_ENTRY
 
typedef enum _MI_PFN_USAGES MI_PFN_USAGES
 
typedef struct _MMPFNENTRY MMPFNENTRY
 
typedef struct _MMPFN MMPFN
 
typedef struct _MMPFNPMMPFN
 
typedef struct _MMPFNLIST MMPFNLIST
 
typedef struct _MMPFNLISTPMMPFNLIST
 
typedef struct _MM_MEMORY_CONSUMER MM_MEMORY_CONSUMER
 
typedef struct
_MM_MEMORY_CONSUMER
PMM_MEMORY_CONSUMER
 
typedef struct _MM_REGION MM_REGION
 
typedef struct _MM_REGIONPMM_REGION
 
typedef struct _MMFREE_POOL_ENTRY MMFREE_POOL_ENTRY
 
typedef struct _MMFREE_POOL_ENTRYPMMFREE_POOL_ENTRY
 
typedef struct _MM_PAGED_POOL_INFO MM_PAGED_POOL_INFO
 
typedef struct
_MM_PAGED_POOL_INFO
PMM_PAGED_POOL_INFO
 
typedef struct _MMPAGING_FILE MMPAGING_FILE
 
typedef struct _MMPAGING_FILEPMMPAGING_FILE
 
typedef VOID(* PMM_ALTER_REGION_FUNC )(PMMSUPPORT AddressSpace, PVOID BaseAddress, SIZE_T Length, ULONG OldType, ULONG OldProtect, ULONG NewType, ULONG NewProtect)
 
typedef VOID(* PMM_FREE_PAGE_FUNC )(PVOID Context, PMEMORY_AREA MemoryArea, PVOID Address, PFN_NUMBER Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)
 

Enumerations

enum  _MI_PFN_USAGES {
  MI_USAGE_NOT_SET = 0, MI_USAGE_PAGED_POOL, MI_USAGE_NONPAGED_POOL, MI_USAGE_NONPAGED_POOL_EXPANSION,
  MI_USAGE_KERNEL_STACK, MI_USAGE_KERNEL_STACK_EXPANSION, MI_USAGE_SYSTEM_PTE, MI_USAGE_VAD,
  MI_USAGE_PEB_TEB, MI_USAGE_SECTION, MI_USAGE_PAGE_TABLE, MI_USAGE_PAGE_DIRECTORY,
  MI_USAGE_LEGACY_PAGE_DIRECTORY, MI_USAGE_DRIVER_PAGE, MI_USAGE_CONTINOUS_ALLOCATION, MI_USAGE_MDL,
  MI_USAGE_DEMAND_ZERO, MI_USAGE_ZERO_LOOP, MI_USAGE_CACHE, MI_USAGE_PFN_DATABASE,
  MI_USAGE_BOOT_DRIVER, MI_USAGE_INIT_MEMORY, MI_USAGE_FREE_PAGE
}
 

Functions

NTSTATUS NTAPI MmDbgCopyMemory (IN ULONG64 Address, IN PVOID Buffer, IN ULONG Size, IN ULONG Flags)
 
BOOLEAN NTAPI MmIsSessionAddress (IN PVOID Address)
 
ULONG NTAPI MmGetSessionId (IN PEPROCESS Process)
 
ULONG NTAPI MmGetSessionIdEx (IN PEPROCESS Process)
 
NTSTATUS NTAPI MmCreateMemoryArea (PMMSUPPORT AddressSpace, ULONG Type, PVOID *BaseAddress, SIZE_T Length, ULONG Protection, PMEMORY_AREA *Result, ULONG AllocationFlags, ULONG AllocationGranularity)
 
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress (PMMSUPPORT AddressSpace, PVOID Address)
 
NTSTATUS NTAPI MmFreeMemoryArea (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PMM_FREE_PAGE_FUNC FreePage, PVOID FreePageContext)
 
VOID NTAPI MiRosCleanupMemoryArea (PEPROCESS Process, PMMVAD Vad)
 
PMEMORY_AREA NTAPI MmLocateMemoryAreaByRegion (PMMSUPPORT AddressSpace, PVOID Address, SIZE_T Length)
 
PVOID NTAPI MmFindGap (PMMSUPPORT AddressSpace, SIZE_T Length, ULONG_PTR Granularity, BOOLEAN TopDown)
 
VOID NTAPI MiRosCheckMemoryAreas (PMMSUPPORT AddressSpace)
 
VOID NTAPI MiCheckAllProcessMemoryAreas (VOID)
 
VOID NTAPI MiInitializeNonPagedPool (VOID)
 
PVOID NTAPI MiAllocatePoolPages (IN POOL_TYPE PoolType, IN SIZE_T SizeInBytes)
 
POOL_TYPE NTAPI MmDeterminePoolType (IN PVOID VirtualAddress)
 
ULONG NTAPI MiFreePoolPages (IN PVOID StartingAddress)
 
BOOLEAN NTAPI MiRaisePoolQuota (IN POOL_TYPE PoolType, IN ULONG CurrentMaxQuota, OUT PULONG NewMaxQuota)
 
VOID NTAPI MmBuildMdlFromPages (PMDL Mdl, PPFN_NUMBER Pages)
 
VOID NTAPI MmInit1 (VOID)
 
BOOLEAN NTAPI MmInitSystem (IN ULONG Phase, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
SWAPENTRY NTAPI MmAllocSwapPage (VOID)
 
VOID NTAPI MmFreeSwapPage (SWAPENTRY Entry)
 
VOID NTAPI MmInitPagingFile (VOID)
 
BOOLEAN NTAPI MmIsFileObjectAPagingFile (PFILE_OBJECT FileObject)
 
NTSTATUS NTAPI MmReadFromSwapPage (SWAPENTRY SwapEntry, PFN_NUMBER Page)
 
NTSTATUS NTAPI MmWriteToSwapPage (SWAPENTRY SwapEntry, PFN_NUMBER Page)
 
VOID NTAPI MmShowOutOfSpaceMessagePagingFile (VOID)
 
NTSTATUS NTAPI MiReadPageFile (_In_ PFN_NUMBER Page, _In_ ULONG PageFileIndex, _In_ ULONG_PTR PageFileOffset)
 
NTSTATUS NTAPI MmInitializeProcessAddressSpace (IN PEPROCESS Process, IN PEPROCESS Clone OPTIONAL, IN PVOID Section OPTIONAL, IN OUT PULONG Flags, IN POBJECT_NAME_INFORMATION *AuditName OPTIONAL)
 
NTSTATUS NTAPI MmCreatePeb (IN PEPROCESS Process, IN PINITIAL_PEB InitialPeb, OUT PPEB *BasePeb)
 
NTSTATUS NTAPI MmCreateTeb (IN PEPROCESS Process, IN PCLIENT_ID ClientId, IN PINITIAL_TEB InitialTeb, OUT PTEB *BaseTeb)
 
VOID NTAPI MmDeleteTeb (struct _EPROCESS *Process, PTEB Teb)
 
VOID NTAPI MmCleanProcessAddressSpace (IN PEPROCESS Process)
 
NTSTATUS NTAPI MmDeleteProcessAddressSpace (IN PEPROCESS Process)
 
ULONG NTAPI MmGetSessionLocaleId (VOID)
 
NTSTATUS NTAPI MmSetMemoryPriorityProcess (IN PEPROCESS Process, IN UCHAR MemoryPriority)
 
NTSTATUS NTAPI MmPageFault (ULONG Cs, PULONG Eip, PULONG Eax, ULONG Cr2, ULONG ErrorCode)
 
VOID NTAPI MiInitializeSpecialPool (VOID)
 
BOOLEAN NTAPI MmUseSpecialPool (IN SIZE_T NumberOfBytes, IN ULONG Tag)
 
BOOLEAN NTAPI MmIsSpecialPoolAddress (IN PVOID P)
 
BOOLEAN NTAPI MmIsSpecialPoolAddressFree (IN PVOID P)
 
PVOID NTAPI MmAllocateSpecialPool (IN SIZE_T NumberOfBytes, IN ULONG Tag, IN POOL_TYPE PoolType, IN ULONG SpecialType)
 
VOID NTAPI MmFreeSpecialPool (IN PVOID P)
 
NTSTATUS NTAPI MmAccessFault (IN ULONG FaultCode, IN PVOID Address, IN KPROCESSOR_MODE Mode, IN PVOID TrapInformation)
 
NTSTATUS NTAPI MiCopyFromUserPage (PFN_NUMBER DestPage, const VOID *SrcAddress)
 
PVOID NTAPI MmCreateKernelStack (BOOLEAN GuiStack, UCHAR Node)
 
VOID NTAPI MmDeleteKernelStack (PVOID Stack, BOOLEAN GuiStack)
 
VOID NTAPI MmInitializeMemoryConsumer (ULONG Consumer, NTSTATUS(*Trim)(ULONG Target, ULONG Priority, PULONG NrFreed))
 
VOID NTAPI MmInitializeBalancer (ULONG NrAvailablePages, ULONG NrSystemPages)
 
NTSTATUS NTAPI MmReleasePageMemoryConsumer (ULONG Consumer, PFN_NUMBER Page)
 
NTSTATUS NTAPI MmRequestPageMemoryConsumer (ULONG Consumer, BOOLEAN MyWait, PPFN_NUMBER AllocatedPage)
 
VOID NTAPI MiInitBalancerThread (VOID)
 
VOID NTAPI MmRebalanceMemoryConsumers (VOID)
 
VOID NTAPI MmSetRmapListHeadPage (PFN_NUMBER Page, struct _MM_RMAP_ENTRY *ListHead)
 
struct _MM_RMAP_ENTRY *NTAPI MmGetRmapListHeadPage (PFN_NUMBER Page)
 
VOID NTAPI MmInsertRmap (PFN_NUMBER Page, struct _EPROCESS *Process, PVOID Address)
 
VOID NTAPI MmDeleteAllRmaps (PFN_NUMBER Page, PVOID Context, VOID(*DeleteMapping)(PVOID Context, struct _EPROCESS *Process, PVOID Address))
 
VOID NTAPI MmDeleteRmap (PFN_NUMBER Page, struct _EPROCESS *Process, PVOID Address)
 
VOID NTAPI MmInitializeRmapList (VOID)
 
VOID NTAPI MmSetCleanAllRmaps (PFN_NUMBER Page)
 
VOID NTAPI MmSetDirtyAllRmaps (PFN_NUMBER Page)
 
BOOLEAN NTAPI MmIsDirtyPageRmap (PFN_NUMBER Page)
 
NTSTATUS NTAPI MmPageOutPhysicalAddress (PFN_NUMBER Page)
 
FORCEINLINE KIRQL MiAcquirePfnLock (VOID)
 
FORCEINLINE VOID MiReleasePfnLock (_In_ KIRQL OldIrql)
 
FORCEINLINE VOID MiAcquirePfnLockAtDpcLevel (VOID)
 
FORCEINLINE VOID MiReleasePfnLockFromDpcLevel (VOID)
 
FORCEINLINE PMMPFN MiGetPfnEntry (IN PFN_NUMBER Pfn)
 
FORCEINLINE PFN_NUMBER MiGetPfnEntryIndex (IN PMMPFN Pfn1)
 
PFN_NUMBER NTAPI MmGetLRUNextUserPage (PFN_NUMBER PreviousPage)
 
PFN_NUMBER NTAPI MmGetLRUFirstUserPage (VOID)
 
VOID NTAPI MmInsertLRULastUserPage (PFN_NUMBER Page)
 
VOID NTAPI MmRemoveLRUUserPage (PFN_NUMBER Page)
 
VOID NTAPI MmDumpArmPfnDatabase (IN BOOLEAN StatusOnly)
 
VOID NTAPI MmZeroPageThread (VOID)
 
PVOID NTAPI MiMapPageInHyperSpace (IN PEPROCESS Process, IN PFN_NUMBER Page, IN PKIRQL OldIrql)
 
VOID NTAPI MiUnmapPageInHyperSpace (IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
 
PVOID NTAPI MiMapPagesInZeroSpace (IN PMMPFN Pfn1, IN PFN_NUMBER NumberOfPages)
 
VOID NTAPI MiUnmapPagesInZeroSpace (IN PVOID VirtualAddress, IN PFN_NUMBER NumberOfPages)
 
FORCEINLINE PVOID MmCreateHyperspaceMapping (IN PFN_NUMBER Page)
 
NTSTATUS NTAPI MmCreateVirtualMapping (struct _EPROCESS *Process, PVOID Address, ULONG flProtect, PPFN_NUMBER Pages, ULONG PageCount)
 
NTSTATUS NTAPI MmCreateVirtualMappingUnsafe (struct _EPROCESS *Process, PVOID Address, ULONG flProtect, PPFN_NUMBER Pages, ULONG PageCount)
 
ULONG NTAPI MmGetPageProtect (struct _EPROCESS *Process, PVOID Address)
 
VOID NTAPI MmSetPageProtect (struct _EPROCESS *Process, PVOID Address, ULONG flProtect)
 
BOOLEAN NTAPI MmIsPagePresent (struct _EPROCESS *Process, PVOID Address)
 
BOOLEAN NTAPI MmIsDisabledPage (struct _EPROCESS *Process, PVOID Address)
 
VOID NTAPI MmInitGlobalKernelPageDirectory (VOID)
 
VOID NTAPI MmGetPageFileMapping (struct _EPROCESS *Process, PVOID Address, SWAPENTRY *SwapEntry)
 
VOID NTAPI MmDeletePageFileMapping (struct _EPROCESS *Process, PVOID Address, SWAPENTRY *SwapEntry)
 
NTSTATUS NTAPI MmCreatePageFileMapping (struct _EPROCESS *Process, PVOID Address, SWAPENTRY SwapEntry)
 
BOOLEAN NTAPI MmIsPageSwapEntry (struct _EPROCESS *Process, PVOID Address)
 
VOID NTAPI MmSetDirtyPage (struct _EPROCESS *Process, PVOID Address)
 
PFN_NUMBER NTAPI MmAllocPage (ULONG Consumer)
 
VOID NTAPI MmDereferencePage (PFN_NUMBER Page)
 
VOID NTAPI MmReferencePage (PFN_NUMBER Page)
 
ULONG NTAPI MmGetReferenceCountPage (PFN_NUMBER Page)
 
BOOLEAN NTAPI MmIsPageInUse (PFN_NUMBER Page)
 
VOID NTAPI MmSetSavedSwapEntryPage (PFN_NUMBER Page, SWAPENTRY SavedSwapEntry)
 
SWAPENTRY NTAPI MmGetSavedSwapEntryPage (PFN_NUMBER Page)
 
VOID NTAPI MmSetCleanPage (struct _EPROCESS *Process, PVOID Address)
 
VOID NTAPI MmDeletePageTable (struct _EPROCESS *Process, PVOID Address)
 
PFN_NUMBER NTAPI MmGetPfnForProcess (struct _EPROCESS *Process, PVOID Address)
 
BOOLEAN NTAPI MmCreateProcessAddressSpace (IN ULONG MinWs, IN PEPROCESS Dest, IN PULONG_PTR DirectoryTableBase)
 
NTSTATUS NTAPI MmInitializeHandBuiltProcess (IN PEPROCESS Process, IN PULONG_PTR DirectoryTableBase)
 
NTSTATUS NTAPI MmInitializeHandBuiltProcess2 (IN PEPROCESS Process)
 
NTSTATUS NTAPI MmSetExecuteOptions (IN ULONG ExecuteOptions)
 
NTSTATUS NTAPI MmGetExecuteOptions (IN PULONG ExecuteOptions)
 
VOID NTAPI MmDeleteVirtualMapping (struct _EPROCESS *Process, PVOID Address, BOOLEAN *WasDirty, PPFN_NUMBER Page)
 
BOOLEAN NTAPI MmIsDirtyPage (struct _EPROCESS *Process, PVOID Address)
 
NTSTATUS MmTrimUserMemory (ULONG Target, ULONG Priority, PULONG NrFreedPages)
 
NTSTATUS NTAPI MmAlterRegion (PMMSUPPORT AddressSpace, PVOID BaseAddress, PLIST_ENTRY RegionListHead, PVOID StartAddress, SIZE_T Length, ULONG NewType, ULONG NewProtect, PMM_ALTER_REGION_FUNC AlterFunc)
 
VOID NTAPI MmInitializeRegion (PLIST_ENTRY RegionListHead, SIZE_T Length, ULONG Type, ULONG Protect)
 
PMM_REGION NTAPI MmFindRegion (PVOID BaseAddress, PLIST_ENTRY RegionListHead, PVOID Address, PVOID *RegionBaseAddress)
 
VOID NTAPI MmGetImageInformation (OUT PSECTION_IMAGE_INFORMATION ImageInformation)
 
PFILE_OBJECT NTAPI MmGetFileObjectForSection (IN PVOID Section)
 
NTSTATUS NTAPI MmGetFileNameForAddress (IN PVOID Address, OUT PUNICODE_STRING ModuleName)
 
NTSTATUS NTAPI MmGetFileNameForSection (IN PVOID Section, OUT POBJECT_NAME_INFORMATION *ModuleName)
 
NTSTATUS NTAPI MmQuerySectionView (PMEMORY_AREA MemoryArea, PVOID Address, PMEMORY_BASIC_INFORMATION Info, PSIZE_T ResultLength)
 
NTSTATUS NTAPI MmProtectSectionView (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PVOID BaseAddress, SIZE_T Length, ULONG Protect, PULONG OldProtect)
 
NTSTATUS NTAPI MmInitSectionImplementation (VOID)
 
NTSTATUS NTAPI MmNotPresentFaultSectionView (PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address, BOOLEAN Locked)
 
NTSTATUS NTAPI MmPageOutSectionView (PMMSUPPORT AddressSpace, PMEMORY_AREA MemoryArea, PVOID Address, ULONG_PTR Entry)
 
NTSTATUS NTAPI MmCreatePhysicalMemorySection (VOID)
 
NTSTATUS NTAPI MmAccessFaultSectionView (PMMSUPPORT AddressSpace, MEMORY_AREA *MemoryArea, PVOID Address)
 
VOID NTAPI MmFreeSectionSegments (PFILE_OBJECT FileObject)
 
VOID NTAPI MiReloadBootLoadedDrivers (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
BOOLEAN NTAPI MiInitializeLoadedModuleList (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
NTSTATUS NTAPI MmLoadSystemImage (IN PUNICODE_STRING FileName, IN PUNICODE_STRING NamePrefix OPTIONAL, IN PUNICODE_STRING LoadedName OPTIONAL, IN ULONG Flags, OUT PVOID *ModuleObject, OUT PVOID *ImageBaseAddress)
 
NTSTATUS NTAPI MmUnloadSystemImage (IN PVOID ImageHandle)
 
NTSTATUS NTAPI MmCheckSystemImage (IN HANDLE ImageHandle, IN BOOLEAN PurgeSection)
 
NTSTATUS NTAPI MmCallDllInitialize (IN PLDR_DATA_TABLE_ENTRY LdrEntry, IN PLIST_ENTRY ListHead)
 
NTSTATUS NTAPI MmGrowKernelStack (IN PVOID StackPointer)
 
FORCEINLINE VOID MmLockAddressSpace (PMMSUPPORT AddressSpace)
 
FORCEINLINE VOID MmUnlockAddressSpace (PMMSUPPORT AddressSpace)
 
FORCEINLINE PEPROCESS MmGetAddressSpaceOwner (IN PMMSUPPORT AddressSpace)
 
FORCEINLINE PMMSUPPORT MmGetCurrentAddressSpace (VOID)
 
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace (VOID)
 
VOID NTAPI ExpCheckPoolAllocation (PVOID P, POOL_TYPE PoolType, ULONG Tag)
 
VOID NTAPI ExReturnPoolQuota (IN PVOID P)
 
NTSTATUS NTAPI MmAdjustWorkingSetSize (IN SIZE_T WorkingSetMinimumInBytes, IN SIZE_T WorkingSetMaximumInBytes, IN ULONG SystemCache, IN BOOLEAN IncreaseOkay)
 
 _IRQL_requires_max_ (APC_LEVEL) NTSTATUS NTAPI MmAttachSession(_Inout_ PVOID SessionEntry
 
VOID NTAPI MmQuitNextSession (_Inout_ PVOID SessionEntry)
 
PVOID NTAPI MmGetSessionById (_In_ ULONG SessionId)
 
VOID MmShutdownSystem (IN ULONG Phase)
 
NTSTATUS NTAPI MmCopyVirtualMemory (IN PEPROCESS SourceProcess, IN PVOID SourceAddress, IN PEPROCESS TargetProcess, OUT PVOID TargetAddress, IN SIZE_T BufferSize, IN KPROCESSOR_MODE PreviousMode, OUT PSIZE_T ReturnSize)
 

Variables

PMMSUPPORT MmKernelAddressSpace
 
PFN_COUNT MiFreeSwapPages
 
PFN_COUNT MiUsedSwapPages
 
PFN_COUNT MmNumberOfPhysicalPages
 
UCHAR MmDisablePagingExecutive
 
PFN_NUMBER MmLowestPhysicalPage
 
PFN_NUMBER MmHighestPhysicalPage
 
PFN_NUMBER MmAvailablePages
 
PFN_NUMBER MmResidentAvailablePages
 
ULONG MmThrottleTop
 
ULONG MmThrottleBottom
 
LIST_ENTRY MmLoadedUserImageList
 
KMUTANT MmSystemLoadLock
 
ULONG MmNumberOfPagingFiles
 
PVOID MmUnloadedDrivers
 
PVOID MmLastUnloadedDrivers
 
PVOID MmTriageActionTaken
 
PVOID KernelVerifier
 
MM_DRIVER_VERIFIER_DATA MmVerifierData
 
SIZE_T MmTotalCommitLimit
 
SIZE_T MmTotalCommittedPages
 
SIZE_T MmSharedCommit
 
SIZE_T MmDriverCommit
 
SIZE_T MmProcessCommit
 
SIZE_T MmPagedPoolCommit
 
SIZE_T MmPeakCommitment
 
SIZE_T MmtotalCommitLimitMaximum
 
PVOID MiDebugMapping
 
PMMPTE MmDebugPte
 
PMMPFN MmPfnDatabase
 
MMPFNLIST MmZeroedPageListHead
 
MMPFNLIST MmFreePageListHead
 
MMPFNLIST MmStandbyPageListHead
 
MMPFNLIST MmModifiedPageListHead
 
MMPFNLIST MmModifiedNoWritePageListHead
 
MM_MEMORY_CONSUMER MiMemoryConsumers [MC_MAXIMUM]
 
PMMPAGING_FILE MmPagingFile [MAX_PAGING_FILES]
 
PEPROCESS HyperProcess
 
KIRQL HyperIrql
 
_Out_ PKAPC_STATE ApcState
 

Macro Definition Documentation

#define CACHE_ALIGNED_POOL_MASK   4

Definition at line 100 of file mm.h.

#define EndOfAllocation   WriteInProgress

Definition at line 288 of file mm.h.

#define InterlockedCompareExchangePte (   PointerPte,
  Exchange,
  Comperand 
)    InterlockedCompareExchange((PLONG)(PointerPte), Exchange, Comperand)

Definition at line 154 of file mm.h.

Referenced by MmSetCleanPage(), and MmSetDirtyPage().

#define InterlockedExchangePte (   PointerPte,
  Value 
)    InterlockedExchange((PLONG)(PointerPte), Value)

Definition at line 157 of file mm.h.

#define MAX_PAGING_FILES   (16)

Definition at line 105 of file mm.h.

Referenced by MiReadPageFile(), MmAllocSwapPage(), MmInitPagingFile(), and NtCreatePagingFile().

#define MC_MAXIMUM   (3)

Definition at line 96 of file mm.h.

Referenced by MiBalancerThread().

#define MC_SYSTEM   (2)

Definition at line 95 of file mm.h.

Referenced by CcInitCacheZeroPage(), MmRequestPageMemoryConsumer(), and QSI_DEF().

#define MEMORY_AREA_STATIC   (0x80000000)

Definition at line 74 of file mm.h.

Referenced by MiCreateArm3StaticMemoryArea(), and MmCreateMemoryArea().

#define MI_STATIC_MEMORY_AREAS   (13)

Definition at line 68 of file mm.h.

Referenced by MmCreateMemoryArea().

#define MM_FREE_POOL_SIGNATURE   'ARM3'

Definition at line 409 of file mm.h.

Referenced by MiAllocatePoolPages(), MiFreePoolPages(), and MiInitializeNonPagedPool().

#define MM_ROUND_DOWN (   x,
  s 
)    ((PVOID)(((ULONG_PTR)(x)) & ~((ULONG_PTR)(s)-1)))
#define MM_ROUND_UP (   x,
  s 
)    ((PVOID)(((ULONG_PTR)(x)+(s)-1) & ~((ULONG_PTR)(s)-1)))

Definition at line 108 of file mm.h.

Referenced by MmCreateMemoryArea(), and MmFreeMemoryArea().

#define MM_VIRTMEM_GRANULARITY   (64 * 1024)
#define MMDBG_COPY_CACHED   0x00000008
#define MMDBG_COPY_MAX_SIZE   0x8

Definition at line 63 of file mm.h.

Referenced by KdpCopyMemoryChunks().

#define MMDBG_COPY_PHYSICAL   0x00000002

Definition at line 54 of file mm.h.

Referenced by KdpReadPhysicalmemory(), KdpWritePhysicalmemory(), and MmDbgCopyMemory().

#define MMDBG_COPY_UNCACHED   0x00000010
#define MMDBG_COPY_WRITE_COMBINED   0x00000020
#define MUST_SUCCEED_POOL_MASK   2

Definition at line 99 of file mm.h.

Referenced by ExAllocatePoolWithTag().

#define PAGE_FLAGS_VALID_FOR_SECTION
Value:
#define PAGE_NOCACHE
Definition: nt_native.h:1311
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
#define PAGE_NOACCESS
Definition: nt_native.h:1302
#define PAGE_EXECUTE
Definition: nt_native.h:1306
#define PAGE_READONLY
Definition: compat.h:127
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define PAGE_READWRITE
Definition: nt_native.h:1304

Definition at line 114 of file mm.h.

Referenced by MmMapViewOfSection().

#define PAGE_IS_EXECUTABLE
Value:
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
#define PAGE_EXECUTE
Definition: nt_native.h:1306
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308

Definition at line 139 of file mm.h.

Referenced by MmspPageAlignSegments(), and ProtectToPTE().

#define PAGE_IS_READABLE
Value:
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
#define PAGE_READONLY
Definition: compat.h:127
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define PAGE_READWRITE
Definition: nt_native.h:1304

Definition at line 125 of file mm.h.

Referenced by MmspPageAlignSegments(), and ProtectToPTE().

#define PAGE_IS_WRITABLE
Value:
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define PAGE_READWRITE
Definition: nt_native.h:1304

Definition at line 133 of file mm.h.

Referenced by MmspPageAlignSegments(), and ProtectToPTE().

#define PAGE_IS_WRITECOPY
Value:
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
#define PAGE_WRITECOPY
Definition: nt_native.h:1305

Definition at line 145 of file mm.h.

Referenced by MmspPageAlignSegments().

#define PAGE_SYSTEM   (2048)

Definition at line 86 of file mm.h.

Referenced by MmGetPageProtect(), and ProtectToPTE().

#define PAGE_WRITETHROUGH   (1024)

Definition at line 85 of file mm.h.

Referenced by MiGetPteProtection(), MiSetPteProtection(), MmGetPageProtect(), and ProtectToPTE().

#define PAGED_POOL_MASK   1

Definition at line 98 of file mm.h.

Referenced by PsChargeProcessPoolQuota(), and PsReturnPoolQuota().

#define QUOTA_POOL_MASK   8

Definition at line 101 of file mm.h.

#define SESSION_POOL_MASK   32
#define StartOfAllocation   ReadInProgress

Definition at line 287 of file mm.h.

#define VERIFIER_POOL_MASK   64

Definition at line 103 of file mm.h.

Referenced by MiAllocatePoolPages().

Typedef Documentation

typedef struct _MMPFN MMPFN
typedef VOID(* PMM_ALTER_REGION_FUNC)(PMMSUPPORT AddressSpace, PVOID BaseAddress, SIZE_T Length, ULONG OldType, ULONG OldProtect, ULONG NewType, ULONG NewProtect)

Definition at line 444 of file mm.h.

typedef VOID(* PMM_FREE_PAGE_FUNC)(PVOID Context, PMEMORY_AREA MemoryArea, PVOID Address, PFN_NUMBER Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)

Definition at line 455 of file mm.h.

typedef struct _MMPFN * PMMPFN

Definition at line 47 of file mm.h.

Enumeration Type Documentation

Enumerator
MI_USAGE_NOT_SET 
MI_USAGE_PAGED_POOL 
MI_USAGE_NONPAGED_POOL 
MI_USAGE_NONPAGED_POOL_EXPANSION 
MI_USAGE_KERNEL_STACK 
MI_USAGE_KERNEL_STACK_EXPANSION 
MI_USAGE_SYSTEM_PTE 
MI_USAGE_VAD 
MI_USAGE_PEB_TEB 
MI_USAGE_SECTION 
MI_USAGE_PAGE_TABLE 
MI_USAGE_PAGE_DIRECTORY 
MI_USAGE_LEGACY_PAGE_DIRECTORY 
MI_USAGE_DRIVER_PAGE 
MI_USAGE_CONTINOUS_ALLOCATION 
MI_USAGE_MDL 
MI_USAGE_DEMAND_ZERO 
MI_USAGE_ZERO_LOOP 
MI_USAGE_CACHE 
MI_USAGE_PFN_DATABASE 
MI_USAGE_BOOT_DRIVER 
MI_USAGE_INIT_MEMORY 
MI_USAGE_FREE_PAGE 

Definition at line 257 of file mm.h.

258 {
259  MI_USAGE_NOT_SET = 0,
266  MI_USAGE_VAD,
274  MI_USAGE_MDL,
282 } MI_PFN_USAGES;
enum _MI_PFN_USAGES MI_PFN_USAGES

Function Documentation

_IRQL_requires_max_ ( APC_LEVEL  )
VOID NTAPI ExpCheckPoolAllocation ( PVOID  P,
POOL_TYPE  PoolType,
ULONG  Tag 
)

Definition at line 286 of file expool.c.

290 {
292  ULONG i;
293  KIRQL OldIrql;
294  POOL_TYPE RealPoolType;
295 
296  /* Get the pool header */
297  Entry = ((PPOOL_HEADER)P) - 1;
298 
299  /* Check if this is a large allocation */
300  if (PAGE_ALIGN(P) == P)
301  {
302  /* Lock the pool table */
304 
305  /* Find the pool tag */
306  for (i = 0; i < PoolBigPageTableSize; i++)
307  {
308  /* Check if this is our allocation */
309  if (PoolBigPageTable[i].Va == P)
310  {
311  /* Make sure the tag is ok */
312  if (PoolBigPageTable[i].Key != Tag)
313  {
314  KeBugCheckEx(BAD_POOL_CALLER, 0x0A, (ULONG_PTR)P, PoolBigPageTable[i].Key, Tag);
315  }
316 
317  break;
318  }
319  }
320 
321  /* Release the lock */
323 
324  if (i == PoolBigPageTableSize)
325  {
326  /* Did not find the allocation */
327  //ASSERT(FALSE);
328  }
329 
330  /* Get Pool type by address */
331  RealPoolType = MmDeterminePoolType(P);
332  }
333  else
334  {
335  /* Verify the tag */
336  if (Entry->PoolTag != Tag)
337  {
338  DPRINT1("Allocation has wrong pool tag! Expected '%.4s', got '%.4s' (0x%08lx)\n",
339  &Tag, &Entry->PoolTag, Entry->PoolTag);
340  KeBugCheckEx(BAD_POOL_CALLER, 0x0A, (ULONG_PTR)P, Entry->PoolTag, Tag);
341  }
342 
343  /* Check the rest of the header */
344  ExpCheckPoolHeader(Entry);
345 
346  /* Get Pool type from entry */
347  RealPoolType = (Entry->PoolType - 1);
348  }
349 
350  /* Should we check the pool type? */
351  if (PoolType != -1)
352  {
353  /* Verify the pool type */
354  if (RealPoolType != PoolType)
355  {
356  DPRINT1("Wrong pool type! Expected %s, got %s\n",
357  PoolType & BASE_POOL_TYPE_MASK ? "PagedPool" : "NonPagedPool",
358  (Entry->PoolType - 1) & BASE_POOL_TYPE_MASK ? "PagedPool" : "NonPagedPool");
359  KeBugCheckEx(BAD_POOL_CALLER, 0xCC, (ULONG_PTR)P, Entry->PoolTag, Tag);
360  }
361  }
362 }
struct _Entry Entry
Definition: kefuncs.h:640
uint32_t ULONG_PTR
Definition: typedefs.h:63
KSPIN_LOCK ExpLargePoolTableLock
Definition: expool.c:45
UCHAR KIRQL
Definition: env_spec_w32.h:591
GLenum GLclampf GLint i
Definition: glfuncs.h:14
SIZE_T PoolBigPageTableSize
Definition: expool.c:39
VOID NTAPI ExpCheckPoolHeader(IN PPOOL_HEADER Entry)
Definition: expool.c:183
#define BASE_POOL_TYPE_MASK
Definition: ExPools.c:15
struct _POOL_HEADER * PPOOL_HEADER
POOL_TYPE NTAPI MmDeterminePoolType(IN PVOID VirtualAddress)
Definition: pool.c:406
INT POOL_TYPE
Definition: typedefs.h:76
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define PAGE_ALIGN(Va)
IN REFCLSID IN PUNKNOWN IN POOL_TYPE PoolType
Definition: unknown.h:68
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT1
Definition: precomp.h:8
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
PPOOL_TRACKER_BIG_PAGES PoolBigPageTable
Definition: expool.c:41
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107
#define P(row, col)
Definition: m_matrix.c:147
VOID NTAPI ExReturnPoolQuota ( IN PVOID  P)

Definition at line 1680 of file expool.c.

Referenced by IoFreeIrp().

1681 {
1684  USHORT BlockSize;
1686 
1689  {
1690  return;
1691  }
1692 
1693  Entry = P;
1694  Entry--;
1695  ASSERT((ULONG_PTR)Entry % POOL_BLOCK_SIZE == 0);
1696 
1697  PoolType = Entry->PoolType - 1;
1698  BlockSize = Entry->BlockSize;
1699 
1700  if (PoolType & QUOTA_POOL_MASK)
1701  {
1702  Process = ((PVOID *)POOL_NEXT_BLOCK(Entry))[-1];
1703  ASSERT(Process != NULL);
1704  if (Process)
1705  {
1706  if (Process->Pcb.Header.Type != ProcessObject)
1707  {
1708  DPRINT1("Object %p is not a process. Type %u, pool type 0x%x, block size %u\n",
1709  Process, Process->Pcb.Header.Type, Entry->PoolType, BlockSize);
1710  KeBugCheckEx(BAD_POOL_CALLER,
1711  0x0D,
1712  (ULONG_PTR)P,
1713  Entry->PoolTag,
1714  (ULONG_PTR)Process);
1715  }
1716  ((PVOID *)POOL_NEXT_BLOCK(Entry))[-1] = NULL;
1717  PsReturnPoolQuota(Process,
1718  PoolType & BASE_POOL_TYPE_MASK,
1719  BlockSize * POOL_BLOCK_SIZE);
1720  ObDereferenceObject(Process);
1721  }
1722  }
1723 }
DWORD *typedef PVOID
Definition: winlogon.h:61
struct _Entry Entry
Definition: kefuncs.h:640
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define POOL_FLAG_SPECIAL_POOL
Definition: miarm.h:262
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define POOL_NEXT_BLOCK(x)
Definition: expool.c:54
VOID NTAPI PsReturnPoolQuota(IN PEPROCESS Process, IN POOL_TYPE PoolType, IN SIZE_T Amount)
Definition: quota.c:237
smooth NULL
Definition: ftsmooth.c:416
#define BASE_POOL_TYPE_MASK
Definition: ExPools.c:15
INT POOL_TYPE
Definition: typedefs.h:76
IN REFCLSID IN PUNKNOWN IN POOL_TYPE PoolType
Definition: unknown.h:68
KPROCESS Pcb
Definition: pstypes.h:1193
#define QUOTA_POOL_MASK
Definition: ExPools.c:16
unsigned short USHORT
Definition: pedump.c:61
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
ULONG ExpPoolFlags
Definition: expool.c:47
#define POOL_BLOCK_SIZE
Definition: miarm.h:248
BOOLEAN NTAPI MmIsSpecialPoolAddress(IN PVOID P)
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107
DISPATCHER_HEADER Header
Definition: ketypes.h:1974
#define P(row, col)
Definition: m_matrix.c:147
FORCEINLINE KIRQL MiAcquirePfnLock ( VOID  )

Definition at line 894 of file mm.h.

Referenced by _MiFlushMappedSection(), MiAllocatePagesForMdl(), MiAllocatePoolPages(), MiBalancerThread(), MiBuildPagedPool(), MiBuildPfnDatabaseFromLoaderBlock(), MiCheckPurgeAndUpMapCount(), MiDeleteARM3Section(), MiDeleteSystemPageableVm(), MiDeleteVirtualAddresses(), MiDereferenceControlArea(), MiDispatchFault(), MiFillSystemPageDirectory(), MiFindContiguousPages(), MiFlushTbAndCapture(), MiFreeContiguousMemory(), MiGetPageProtection(), MiGetPteForProcess(), MiInitializeAndChargePfn(), MiInitMachineDependent(), MiLoadImageSection(), MiMakeSystemAddressValidPfn(), MiMapLockedPagesInUserSpace(), MiProcessValidPteList(), MiProtectVirtualMemory(), MiReleaseProcessReferenceToSessionDataPage(), MiRemoveMappedPtes(), MiRemoveMappedView(), MiResolveDemandZeroFault(), MiResolvePageFileFault(), MiResolveProtoPteFault(), MiSegmentDelete(), MiSessionCommitPageTables(), MiSessionCreateInternal(), MiSessionInitializeWorkingSetList(), MiSetControlAreaSymbolsLoaded(), MiUnmapLockedPagesInUserSpace(), MmAllocateSpecialPool(), MmAllocPage(), MmArmAccessFault(), MmCreateArm3Section(), MmCreateKernelStack(), MmCreateProcessAddressSpace(), MmDeleteKernelStack(), MmDeleteProcessAddressSpace(), MmDeleteProcessAddressSpace2(), MmDereferencePage(), MmFreeLoaderBlock(), MmFreeMemoryArea(), MmFreePagesFromMdl(), MmFreeSpecialPool(), MmGetLRUFirstUserPage(), MmGetLRUNextUserPage(), MmGetPhysicalMemoryRanges(), MmGetReferenceCountPage(), MmGetRmapListHeadPage(), MmGetSavedSwapEntryPage(), MmGrowKernelStackEx(), MmInitializeProcessAddressSpace(), MmInsertLRULastUserPage(), MmNotPresentFaultCachePage(), MmPageOutSectionView(), MmProbeAndLockPages(), MmRemoveLRUUserPage(), MmSetRmapListHeadPage(), MmSetSavedSwapEntryPage(), MmUnlockPages(), and MmZeroPageThread().

895 {
897 }
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
FORCEINLINE VOID MiAcquirePfnLockAtDpcLevel ( VOID  )

Definition at line 909 of file mm.h.

Referenced by MiAllocatePoolPages().

910 {
911  PKSPIN_LOCK_QUEUE LockQueue;
912 
914  LockQueue = &KeGetCurrentPrcb()->LockQueue[LockQueuePfnLock];
916 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
VOID FASTCALL KeAcquireQueuedSpinLockAtDpcLevel(IN OUT PKSPIN_LOCK_QUEUE LockQueue)
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
PVOID NTAPI MiAllocatePoolPages ( IN POOL_TYPE  PoolType,
IN SIZE_T  SizeInBytes 
)

Definition at line 420 of file pool.c.

Referenced by ExAllocatePoolWithTag(), and InitializePool().

422 {
423  PFN_NUMBER PageFrameNumber;
424  PFN_COUNT SizeInPages, PageTableCount;
425  ULONG i;
426  KIRQL OldIrql;
427  PLIST_ENTRY NextEntry, NextHead, LastHead;
428  PMMPTE PointerPte, StartPte;
429  PMMPDE PointerPde;
430  ULONG EndAllocation;
431  MMPTE TempPte;
432  MMPDE TempPde;
433  PMMPFN Pfn1;
434  PVOID BaseVa, BaseVaStart;
435  PMMFREE_POOL_ENTRY FreeEntry;
436 
437  //
438  // Figure out how big the allocation is in pages
439  //
440  SizeInPages = (PFN_COUNT)BYTES_TO_PAGES(SizeInBytes);
441 
442  //
443  // Check for overflow
444  //
445  if (SizeInPages == 0)
446  {
447  //
448  // Fail
449  //
450  return NULL;
451  }
452 
453  //
454  // Handle paged pool
455  //
457  {
458  //
459  // If only one page is being requested, try to grab it from the S-LIST
460  //
461  if ((SizeInPages == 1) && (ExQueryDepthSList(&MiPagedPoolSListHead)))
462  {
464  if (BaseVa) return BaseVa;
465  }
466 
467  //
468  // Lock the paged pool mutex
469  //
471 
472  //
473  // Find some empty allocation space
474  //
476  SizeInPages,
478  if (i == 0xFFFFFFFF)
479  {
480  //
481  // Get the page bit count
482  //
483  i = ((SizeInPages - 1) / PTE_COUNT) + 1;
484  DPRINT("Paged pool expansion: %lu %x\n", i, SizeInPages);
485 
486  //
487  // Check if there is enougn paged pool expansion space left
488  //
491  {
492  //
493  // Out of memory!
494  //
495  DPRINT1("FAILED to allocate %Iu bytes from paged pool\n", SizeInBytes);
497  return NULL;
498  }
499 
500  //
501  // Check if we'll have to expand past the last PTE we have available
502  //
505  {
506  //
507  // We can only support this much then
508  //
510  PageTableCount = (PFN_COUNT)(PointerPde + 1 -
512  ASSERT(PageTableCount < i);
513  i = PageTableCount;
514  }
515  else
516  {
517  //
518  // Otherwise, there is plenty of space left for this expansion
519  //
520  PageTableCount = i;
521  }
522 
523  //
524  // Get the template PDE we'll use to expand
525  //
526  TempPde = ValidKernelPde;
527 
528  //
529  // Get the first PTE in expansion space
530  //
532  BaseVa = MiPdeToPte(PointerPde);
533  BaseVaStart = BaseVa;
534 
535  //
536  // Lock the PFN database and loop pages
537  //
538  OldIrql = MiAcquirePfnLock();
539  do
540  {
541  //
542  // It should not already be valid
543  //
544  ASSERT(PointerPde->u.Hard.Valid == 0);
545 
546  /* Request a page */
548  MI_SET_PROCESS2("Kernel");
549  PageFrameNumber = MiRemoveAnyPage(MI_GET_NEXT_COLOR());
550  TempPde.u.Hard.PageFrameNumber = PageFrameNumber;
551 #if (_MI_PAGING_LEVELS >= 3)
552  /* On PAE/x64 systems, there's no double-buffering */
553  /* Initialize the PFN entry for it */
554  MiInitializePfnForOtherProcess(PageFrameNumber,
555  (PMMPTE)PointerPde,
556  PFN_FROM_PTE(MiAddressToPte(PointerPde)));
557 
558  /* Write the actual PDE now */
559  MI_WRITE_VALID_PDE(PointerPde, TempPde);
560 #else
561  //
562  // Save it into our double-buffered system page directory
563  //
564  MmSystemPagePtes[((ULONG_PTR)PointerPde & (SYSTEM_PD_SIZE - 1)) / sizeof(MMPTE)] = TempPde;
565 
566  /* Initialize the PFN */
567  MiInitializePfnForOtherProcess(PageFrameNumber,
568  (PMMPTE)PointerPde,
570 #endif
571 
572  //
573  // Move on to the next expansion address
574  //
575  PointerPde++;
576  BaseVa = (PVOID)((ULONG_PTR)BaseVa + PAGE_SIZE);
577  i--;
578  } while (i > 0);
579 
580  //
581  // Release the PFN database lock
582  //
583  MiReleasePfnLock(OldIrql);
584 
585  //
586  // These pages are now available, clear their availablity bits
587  //
590  PTE_COUNT;
592  EndAllocation,
593  PageTableCount * PTE_COUNT);
594 
595  //
596  // Update the next expansion location
597  //
599 
600  //
601  // Zero out the newly available memory
602  //
603  RtlZeroMemory(BaseVaStart, PageTableCount * PAGE_SIZE);
604 
605  //
606  // Now try consuming the pages again
607  //
609  SizeInPages,
610  0);
611  if (i == 0xFFFFFFFF)
612  {
613  //
614  // Out of memory!
615  //
616  DPRINT1("FAILED to allocate %Iu bytes from paged pool\n", SizeInBytes);
618  return NULL;
619  }
620  }
621 
622  //
623  // Update the pool hint if the request was just one page
624  //
625  if (SizeInPages == 1) MmPagedPoolInfo.PagedPoolHint = i + 1;
626 
627  //
628  // Update the end bitmap so we know the bounds of this allocation when
629  // the time comes to free it
630  //
631  EndAllocation = i + SizeInPages - 1;
633 
634  //
635  // Now we can release the lock (it mainly protects the bitmap)
636  //
638 
639  //
640  // Now figure out where this allocation starts
641  //
642  BaseVa = (PVOID)((ULONG_PTR)MmPagedPoolStart + (i << PAGE_SHIFT));
643 
644  //
645  // Flush the TLB
646  //
648 
649  /* Setup a demand-zero writable PTE */
651 
652  //
653  // Find the first and last PTE, then loop them all
654  //
655  PointerPte = MiAddressToPte(BaseVa);
656  StartPte = PointerPte + SizeInPages;
657  do
658  {
659  //
660  // Write the demand zero PTE and keep going
661  //
662  MI_WRITE_INVALID_PTE(PointerPte, TempPte);
663  } while (++PointerPte < StartPte);
664 
665  //
666  // Return the allocation address to the caller
667  //
668  return BaseVa;
669  }
670 
671  //
672  // If only one page is being requested, try to grab it from the S-LIST
673  //
674  if ((SizeInPages == 1) && (ExQueryDepthSList(&MiNonPagedPoolSListHead)))
675  {
677  if (BaseVa) return BaseVa;
678  }
679 
680  //
681  // Allocations of less than 4 pages go into their individual buckets
682  //
683  i = SizeInPages - 1;
685 
686  //
687  // Loop through all the free page lists based on the page index
688  //
689  NextHead = &MmNonPagedPoolFreeListHead[i];
691 
692  //
693  // Acquire the nonpaged pool lock
694  //
696  do
697  {
698  //
699  // Now loop through all the free page entries in this given list
700  //
701  NextEntry = NextHead->Flink;
702  while (NextEntry != NextHead)
703  {
704  /* Is freed non paged pool enabled */
706  {
707  /* We need to be able to touch this page, unprotect it */
708  MiUnProtectFreeNonPagedPool(NextEntry, 0);
709  }
710 
711  //
712  // Grab the entry and see if it can handle our allocation
713  //
714  FreeEntry = CONTAINING_RECORD(NextEntry, MMFREE_POOL_ENTRY, List);
715  ASSERT(FreeEntry->Signature == MM_FREE_POOL_SIGNATURE);
716  if (FreeEntry->Size >= SizeInPages)
717  {
718  //
719  // It does, so consume the pages from here
720  //
721  FreeEntry->Size -= SizeInPages;
722 
723  //
724  // The allocation will begin in this free page area
725  //
726  BaseVa = (PVOID)((ULONG_PTR)FreeEntry +
727  (FreeEntry->Size << PAGE_SHIFT));
728 
729  /* Remove the item from the list, depending if pool is protected */
732  else
733  RemoveEntryList(&FreeEntry->List);
734 
735  //
736  // However, check if its' still got space left
737  //
738  if (FreeEntry->Size != 0)
739  {
740  /* Check which list to insert this entry into */
741  i = FreeEntry->Size - 1;
743 
744  /* Insert the entry into the free list head, check for prot. pool */
747  else
749 
750  /* Is freed non paged pool protected? */
752  {
753  /* Protect the freed pool! */
754  MiProtectFreeNonPagedPool(FreeEntry, FreeEntry->Size);
755  }
756  }
757 
758  //
759  // Grab the PTE for this allocation
760  //
761  PointerPte = MiAddressToPte(BaseVa);
762  ASSERT(PointerPte->u.Hard.Valid == 1);
763 
764  //
765  // Grab the PFN NextEntry and index
766  //
767  Pfn1 = MiGetPfnEntry(PFN_FROM_PTE(PointerPte));
768 
769  //
770  // Now mark it as the beginning of an allocation
771  //
772  ASSERT(Pfn1->u3.e1.StartOfAllocation == 0);
773  Pfn1->u3.e1.StartOfAllocation = 1;
774 
775  /* Mark it as special pool if needed */
776  ASSERT(Pfn1->u4.VerifierAllocation == 0);
778  {
779  Pfn1->u4.VerifierAllocation = 1;
780  }
781 
782  //
783  // Check if the allocation is larger than one page
784  //
785  if (SizeInPages != 1)
786  {
787  //
788  // Navigate to the last PFN entry and PTE
789  //
790  PointerPte += SizeInPages - 1;
791  ASSERT(PointerPte->u.Hard.Valid == 1);
792  Pfn1 = MiGetPfnEntry(PointerPte->u.Hard.PageFrameNumber);
793  }
794 
795  //
796  // Mark this PFN as the last (might be the same as the first)
797  //
798  ASSERT(Pfn1->u3.e1.EndOfAllocation == 0);
799  Pfn1->u3.e1.EndOfAllocation = 1;
800 
801  //
802  // Release the nonpaged pool lock, and return the allocation
803  //
805  return BaseVa;
806  }
807 
808  //
809  // Try the next free page entry
810  //
811  NextEntry = FreeEntry->List.Flink;
812 
813  /* Is freed non paged pool protected? */
815  {
816  /* Protect the freed pool! */
817  MiProtectFreeNonPagedPool(FreeEntry, FreeEntry->Size);
818  }
819  }
820  } while (++NextHead < LastHead);
821 
822  //
823  // If we got here, we're out of space.
824  // Start by releasing the lock
825  //
827 
828  //
829  // Allocate some system PTEs
830  //
831  StartPte = MiReserveSystemPtes(SizeInPages, NonPagedPoolExpansion);
832  PointerPte = StartPte;
833  if (StartPte == NULL)
834  {
835  //
836  // Ran out of memory
837  //
838  DPRINT1("Out of NP Expansion Pool\n");
839  return NULL;
840  }
841 
842  //
843  // Acquire the pool lock now
844  //
846 
847  //
848  // Lock the PFN database too
849  //
851 
852  //
853  // Loop the pages
854  //
855  TempPte = ValidKernelPte;
856  do
857  {
858  /* Allocate a page */
860  MI_SET_PROCESS2("Kernel");
861  PageFrameNumber = MiRemoveAnyPage(MI_GET_NEXT_COLOR());
862 
863  /* Get the PFN entry for it and fill it out */
864  Pfn1 = MiGetPfnEntry(PageFrameNumber);
865  Pfn1->u3.e2.ReferenceCount = 1;
866  Pfn1->u2.ShareCount = 1;
867  Pfn1->PteAddress = PointerPte;
869  Pfn1->u4.VerifierAllocation = 0;
870 
871  /* Write the PTE for it */
872  TempPte.u.Hard.PageFrameNumber = PageFrameNumber;
873  MI_WRITE_VALID_PTE(PointerPte++, TempPte);
874  } while (--SizeInPages > 0);
875 
876  //
877  // This is the last page
878  //
879  Pfn1->u3.e1.EndOfAllocation = 1;
880 
881  //
882  // Get the first page and mark it as such
883  //
884  Pfn1 = MiGetPfnEntry(StartPte->u.Hard.PageFrameNumber);
885  Pfn1->u3.e1.StartOfAllocation = 1;
886 
887  /* Mark it as a verifier allocation if needed */
888  ASSERT(Pfn1->u4.VerifierAllocation == 0);
890 
891  //
892  // Release the PFN and nonpaged pool lock
893  //
896 
897  //
898  // Return the address
899  //
900  return MiPteToAddress(StartPte);
901 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define MI_MAKE_SOFTWARE_PTE(p, x)
Definition: miarm.h:158
struct _MMPFN::@1722::@1728 e2
PRTL_BITMAP PagedPoolAllocationMap
Definition: mm.h:414
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
NTSYSAPI void WINAPI RtlClearBits(PRTL_BITMAP, ULONG, ULONG)
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI MiUnProtectFreeNonPagedPool(IN PVOID VirtualAddress, IN ULONG PageCount)
Definition: pool.c:68
#define MiAddressToPde(x)
Definition: mmx86.c:20
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
ULONG PFN_COUNT
Definition: mmtypes.h:102
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
PMMPTE NTAPI MiReserveSystemPtes(IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:246
ULONG Signature
Definition: mm.h:404
#define VERIFIER_POOL_MASK
Definition: mm.h:103
NTSYSAPI VOID NTAPI RtlSetBit(_In_ PRTL_BITMAP BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: bitmap.c:304
#define MM_READWRITE
Definition: miarm.h:51
#define MI_GET_NEXT_COLOR()
Definition: miarm.h:211
HARDWARE_PDE_ARMV6 TempPde
Definition: winldr.c:77
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:894
VOID NTAPI MiInitializePfnForOtherProcess(IN PFN_NUMBER PageFrameIndex, IN PVOID PteAddress, IN PFN_NUMBER PteFrame)
Definition: pfnlist.c:1280
#define InsertTailList(ListHead, Entry)
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:901
USHORT PageLocation
Definition: mm.h:297
PSLIST_ENTRY WINAPI InterlockedPopEntrySList(PSLIST_HEADER ListHead)
Definition: interlocked.c:55
FORCEINLINE VOID MiReleasePfnLockFromDpcLevel(VOID)
Definition: mm.h:920
SLIST_HEADER MiNonPagedPoolSListHead
Definition: pool.c:30
uint32_t ULONG_PTR
Definition: typedefs.h:63
FORCEINLINE VOID MiAcquirePfnLockAtDpcLevel(VOID)
Definition: mm.h:909
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
MMPFNENTRY e1
Definition: mm.h:329
#define PDE_COUNT
Definition: miarm.h:32
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define MiAddressToPte(x)
Definition: mmx86.c:19
ULONG PFN_NUMBER
Definition: ke.h:8
PMMPTE LastPteForPagedPool
Definition: mm.h:417
FORCEINLINE VOID MI_WRITE_VALID_PTE(IN PMMPTE PointerPte, IN MMPTE TempPte)
Definition: miarm.h:916
ULONG_PTR ShareCount
Definition: mm.h:322
VOID NTAPI MiProtectedPoolRemoveEntryList(IN PLIST_ENTRY Entry)
Definition: pool.c:166
#define MI_SET_PROCESS2(x)
Definition: mm.h:254
LIST_ENTRY List
Definition: mm.h:402
#define MI_MAX_FREE_PAGE_LISTS
Definition: mm.h:76
smooth NULL
Definition: ftsmooth.c:416
PVOID FORCEINLINE MiPteToAddress(PMMPTE PointerPte)
Definition: mm.h:197
ULONG_PTR VerifierAllocation
Definition: mm.h:352
void DPRINT(...)
Definition: polytest.cpp:61
#define BASE_POOL_TYPE_MASK
Definition: ExPools.c:15
FORCEINLINE VOID MI_WRITE_VALID_PDE(IN PMMPDE PointerPde, IN MMPDE TempPde)
Definition: miarm.h:971
#define MI_SET_USAGE(x)
Definition: mm.h:253
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
VOID NTAPI KeFlushEntireTb(IN BOOLEAN Invalid, IN BOOLEAN AllProcessors)
Definition: cpu.c:413
PMMPDE MmSystemPagePtes
Definition: init.c:41
union _MMPFN::@1722 u3
KGUARDED_MUTEX MmPagedPoolMutex
Definition: pool.c:24
PFN_COUNT Size
Definition: mm.h:403
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define MM_FREE_POOL_SIGNATURE
Definition: mm.h:409
LIST_ENTRY List
Definition: psmgr.c:57
Definition: mm.h:400
ULONG64 Valid
Definition: mmtypes.h:150
MM_PAGED_POOL_INFO MmPagedPoolInfo
Definition: pool.c:25
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:75
FORCEINLINE USHORT ExQueryDepthSList(_In_ PSLIST_HEADER SListHead)
Definition: exfuncs.h:153
MMPTE ValidKernelPte
Definition: init.c:31
#define PTE_COUNT
Definition: miarm.h:33
VOID NTAPI MiProtectedPoolInsertList(IN PLIST_ENTRY ListHead, IN PLIST_ENTRY Entry, IN BOOLEAN Critical)
Definition: pool.c:148
#define BYTES_TO_PAGES(Size)
IN REFCLSID IN PUNKNOWN IN POOL_TYPE PoolType
Definition: unknown.h:68
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: mm.h:305
#define PAGE_SIZE
Definition: env_spec_w32.h:49
PFN_NUMBER MmSystemPageDirectory[PD_COUNT]
Definition: init.c:40
Definition: typedefs.h:117
NTSYSAPI ULONG WINAPI RtlFindClearBitsAndSet(PRTL_BITMAP, ULONG, ULONG)
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:933
MMPTE ValidKernelPde
Definition: init.c:30
PVOID MmPagedPoolStart
Definition: miarm.h:554
union _MMPFN::@1721 u2
PFN_NUMBER NTAPI MiRemoveAnyPage(IN ULONG Color)
Definition: pfnlist.c:475
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
#define SYSTEM_PD_SIZE
Definition: miarm.h:36
#define MiPteToPde(_Pte)
Definition: mm.h:232
FORCEINLINE VOID MI_WRITE_INVALID_PTE(IN PMMPTE PointerPte, IN MMPTE InvalidPte)
Definition: miarm.h:945
BOOLEAN MmProtectFreedNonPagedPool
Definition: pool.c:29
#define MiPdeToPte(_Pde)
Definition: mm.h:231
PRTL_BITMAP EndOfPagedPoolBitmap
Definition: mm.h:415
PMMPTE PteAddress
Definition: mm.h:318
union _MMPFN::@1725 u4
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
#define DPRINT1
Definition: precomp.h:8
SLIST_HEADER MiPagedPoolSListHead
Definition: pool.c:32
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ULONG_PTR
Definition: config.h:101
ULONG64 PageFrameNumber
Definition: mmtypes.h:171
VOID NTAPI MiProtectFreeNonPagedPool(IN PVOID VirtualAddress, IN ULONG PageCount)
Definition: pool.c:39
ULONG PagedPoolHint
Definition: mm.h:419
PMMPTE FirstPteForPagedPool
Definition: mm.h:416
LIST_ENTRY MmNonPagedPoolFreeListHead[MI_MAX_FREE_PAGE_LISTS]
Definition: pool.c:20
#define PFN_FROM_PTE(v)
Definition: mm.h:88
union _MMPTE::@2228 u
PMMPDE NextPdeForPagedPoolExpansion
Definition: mm.h:418
VOID NTAPI MiCheckAllProcessMemoryAreas ( VOID  )
NTSTATUS NTAPI MiCopyFromUserPage ( PFN_NUMBER  DestPage,
const VOID SrcAddress 
)

Definition at line 1043 of file section.c.

Referenced by MmAccessFaultSectionView().

1044 {
1046  KIRQL Irql;
1047  PVOID DestAddress;
1048 
1049  Process = PsGetCurrentProcess();
1050  DestAddress = MiMapPageInHyperSpace(Process, DestPage, &Irql);
1051  if (DestAddress == NULL)
1052  {
1053  return(STATUS_NO_MEMORY);
1054  }
1055  ASSERT((ULONG_PTR)DestAddress % PAGE_SIZE == 0);
1056  ASSERT((ULONG_PTR)SrcAddress % PAGE_SIZE == 0);
1057  RtlCopyMemory(DestAddress, SrcAddress, PAGE_SIZE);
1058  MiUnmapPageInHyperSpace(Process, DestAddress, Irql);
1059  return(STATUS_SUCCESS);
1060 }
DWORD *typedef PVOID
Definition: winlogon.h:61
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
_Out_ PKIRQL Irql
Definition: csq.h:179
uint32_t ULONG_PTR
Definition: typedefs.h:63
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define PsGetCurrentProcess
Definition: psfuncs.h:17
PVOID NTAPI MiMapPageInHyperSpace(IN PEPROCESS Process, IN PFN_NUMBER Page, IN PKIRQL OldIrql)
Definition: hypermap.c:30
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:93
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
return STATUS_SUCCESS
Definition: btrfs.c:2710
ULONG NTAPI MiFreePoolPages ( IN PVOID  StartingAddress)

Definition at line 905 of file pool.c.

Referenced by ExFreePoolWithTag().

906 {
907  PMMPTE PointerPte, StartPte;
908  PMMPFN Pfn1, StartPfn;
909  PFN_COUNT FreePages, NumberOfPages;
910  KIRQL OldIrql;
911  PMMFREE_POOL_ENTRY FreeEntry, NextEntry, LastEntry;
912  ULONG i, End;
914 
915  //
916  // Handle paged pool
917  //
918  if ((StartingVa >= MmPagedPoolStart) && (StartingVa <= MmPagedPoolEnd))
919  {
920  //
921  // Calculate the offset from the beginning of paged pool, and convert it
922  // into pages
923  //
924  Offset = (ULONG_PTR)StartingVa - (ULONG_PTR)MmPagedPoolStart;
925  i = (ULONG)(Offset >> PAGE_SHIFT);
926  End = i;
927 
928  //
929  // Now use the end bitmap to scan until we find a set bit, meaning that
930  // this allocation finishes here
931  //
932  while (!RtlTestBit(MmPagedPoolInfo.EndOfPagedPoolBitmap, End)) End++;
933 
934  //
935  // Now calculate the total number of pages this allocation spans. If it's
936  // only one page, add it to the S-LIST instead of freeing it
937  //
938  NumberOfPages = End - i + 1;
939  if ((NumberOfPages == 1) &&
941  {
943  return 1;
944  }
945 
946  /* Delete the actual pages */
947  PointerPte = MmPagedPoolInfo.FirstPteForPagedPool + i;
948  FreePages = MiDeleteSystemPageableVm(PointerPte, NumberOfPages, 0, NULL);
949  ASSERT(FreePages == NumberOfPages);
950 
951  //
952  // Acquire the paged pool lock
953  //
955 
956  //
957  // Clear the allocation and free bits
958  //
961 
962  //
963  // Update the hint if we need to
964  //
966 
967  //
968  // Release the lock protecting the bitmaps
969  //
971 
972  //
973  // And finally return the number of pages freed
974  //
975  return NumberOfPages;
976  }
977 
978  //
979  // Get the first PTE and its corresponding PFN entry. If this is also the
980  // last PTE, meaning that this allocation was only for one page, push it into
981  // the S-LIST instead of freeing it
982  //
983  StartPte = PointerPte = MiAddressToPte(StartingVa);
984  StartPfn = Pfn1 = MiGetPfnEntry(PointerPte->u.Hard.PageFrameNumber);
985  if ((Pfn1->u3.e1.EndOfAllocation == 1) &&
987  {
989  return 1;
990  }
991 
992  //
993  // Loop until we find the last PTE
994  //
995  while (Pfn1->u3.e1.EndOfAllocation == 0)
996  {
997  //
998  // Keep going
999  //
1000  PointerPte++;
1001  Pfn1 = MiGetPfnEntry(PointerPte->u.Hard.PageFrameNumber);
1002  }
1003 
1004  //
1005  // Now we know how many pages we have
1006  //
1007  NumberOfPages = (PFN_COUNT)(PointerPte - StartPte + 1);
1008 
1009  //
1010  // Acquire the nonpaged pool lock
1011  //
1013 
1014  //
1015  // Mark the first and last PTEs as not part of an allocation anymore
1016  //
1017  StartPfn->u3.e1.StartOfAllocation = 0;
1018  Pfn1->u3.e1.EndOfAllocation = 0;
1019 
1020  //
1021  // Assume we will free as many pages as the allocation was
1022  //
1023  FreePages = NumberOfPages;
1024 
1025  //
1026  // Peek one page past the end of the allocation
1027  //
1028  PointerPte++;
1029 
1030  //
1031  // Guard against going past initial nonpaged pool
1032  //
1034  {
1035  //
1036  // This page is on the outskirts of initial nonpaged pool, so ignore it
1037  //
1038  Pfn1 = NULL;
1039  }
1040  else
1041  {
1042  /* Sanity check */
1043  ASSERT((ULONG_PTR)StartingVa + NumberOfPages <= (ULONG_PTR)MmNonPagedPoolEnd);
1044 
1045  /* Check if protected pool is enabled */
1047  {
1048  /* The freed block will be merged, it must be made accessible */
1050  }
1051 
1052  //
1053  // Otherwise, our entire allocation must've fit within the initial non
1054  // paged pool, or the expansion nonpaged pool, so get the PFN entry of
1055  // the next allocation
1056  //
1057  if (PointerPte->u.Hard.Valid == 1)
1058  {
1059  //
1060  // It's either expansion or initial: get the PFN entry
1061  //
1062  Pfn1 = MiGetPfnEntry(PointerPte->u.Hard.PageFrameNumber);
1063  }
1064  else
1065  {
1066  //
1067  // This means we've reached the guard page that protects the end of
1068  // the expansion nonpaged pool
1069  //
1070  Pfn1 = NULL;
1071  }
1072 
1073  }
1074 
1075  //
1076  // Check if this allocation actually exists
1077  //
1078  if ((Pfn1) && (Pfn1->u3.e1.StartOfAllocation == 0))
1079  {
1080  //
1081  // It doesn't, so we should actually locate a free entry descriptor
1082  //
1083  FreeEntry = (PMMFREE_POOL_ENTRY)((ULONG_PTR)StartingVa +
1084  (NumberOfPages << PAGE_SHIFT));
1085  ASSERT(FreeEntry->Signature == MM_FREE_POOL_SIGNATURE);
1086  ASSERT(FreeEntry->Owner == FreeEntry);
1087 
1088  /* Consume this entry's pages */
1089  FreePages += FreeEntry->Size;
1090 
1091  /* Remove the item from the list, depending if pool is protected */
1093  MiProtectedPoolRemoveEntryList(&FreeEntry->List);
1094  else
1095  RemoveEntryList(&FreeEntry->List);
1096  }
1097 
1098  //
1099  // Now get the official free entry we'll create for the caller's allocation
1100  //
1101  FreeEntry = StartingVa;
1102 
1103  //
1104  // Check if the our allocation is the very first page
1105  //
1107  {
1108  //
1109  // Then we can't do anything or we'll risk underflowing
1110  //
1111  Pfn1 = NULL;
1112  }
1113  else
1114  {
1115  //
1116  // Otherwise, get the PTE for the page right before our allocation
1117  //
1118  PointerPte -= NumberOfPages + 1;
1119 
1120  /* Check if protected pool is enabled */
1122  {
1123  /* The freed block will be merged, it must be made accessible */
1125  }
1126 
1127  /* Check if this is valid pool, or a guard page */
1128  if (PointerPte->u.Hard.Valid == 1)
1129  {
1130  //
1131  // It's either expansion or initial nonpaged pool, get the PFN entry
1132  //
1133  Pfn1 = MiGetPfnEntry(PointerPte->u.Hard.PageFrameNumber);
1134  }
1135  else
1136  {
1137  //
1138  // We must've reached the guard page, so don't risk touching it
1139  //
1140  Pfn1 = NULL;
1141  }
1142  }
1143 
1144  //
1145  // Check if there is a valid PFN entry for the page before the allocation
1146  // and then check if this page was actually the end of an allocation.
1147  // If it wasn't, then we know for sure it's a free page
1148  //
1149  if ((Pfn1) && (Pfn1->u3.e1.EndOfAllocation == 0))
1150  {
1151  //
1152  // Get the free entry descriptor for that given page range
1153  //
1154  FreeEntry = (PMMFREE_POOL_ENTRY)((ULONG_PTR)StartingVa - PAGE_SIZE);
1155  ASSERT(FreeEntry->Signature == MM_FREE_POOL_SIGNATURE);
1156  FreeEntry = FreeEntry->Owner;
1157 
1158  /* Check if protected pool is enabled */
1160  {
1161  /* The freed block will be merged, it must be made accessible */
1162  MiUnProtectFreeNonPagedPool(FreeEntry, 0);
1163  }
1164 
1165  //
1166  // Check if the entry is small enough to be indexed on a free list
1167  // If it is, we'll want to re-insert it, since we're about to
1168  // collapse our pages on top of it, which will change its count
1169  //
1170  if (FreeEntry->Size < (MI_MAX_FREE_PAGE_LISTS - 1))
1171  {
1172  /* Remove the item from the list, depending if pool is protected */
1174  MiProtectedPoolRemoveEntryList(&FreeEntry->List);
1175  else
1176  RemoveEntryList(&FreeEntry->List);
1177 
1178  //
1179  // Update its size
1180  //
1181  FreeEntry->Size += FreePages;
1182 
1183  //
1184  // And now find the new appropriate list to place it in
1185  //
1186  i = (ULONG)(FreeEntry->Size - 1);
1188 
1189  /* Insert the entry into the free list head, check for prot. pool */
1192  else
1194  }
1195  else
1196  {
1197  //
1198  // Otherwise, just combine our free pages into this entry
1199  //
1200  FreeEntry->Size += FreePages;
1201  }
1202  }
1203 
1204  //
1205  // Check if we were unable to do any compaction, and we'll stick with this
1206  //
1207  if (FreeEntry == StartingVa)
1208  {
1209  //
1210  // Well, now we are a free entry. At worse we just have our newly freed
1211  // pages, at best we have our pages plus whatever entry came after us
1212  //
1213  FreeEntry->Size = FreePages;
1214 
1215  //
1216  // Find the appropriate list we should be on
1217  //
1218  i = FreeEntry->Size - 1;
1220 
1221  /* Insert the entry into the free list head, check for prot. pool */
1224  else
1226  }
1227 
1228  //
1229  // Just a sanity check
1230  //
1231  ASSERT(FreePages != 0);
1232 
1233  //
1234  // Get all the pages between our allocation and its end. These will all now
1235  // become free page chunks.
1236  //
1237  NextEntry = StartingVa;
1238  LastEntry = (PMMFREE_POOL_ENTRY)((ULONG_PTR)NextEntry + (FreePages << PAGE_SHIFT));
1239  do
1240  {
1241  //
1242  // Link back to the parent free entry, and keep going
1243  //
1244  NextEntry->Owner = FreeEntry;
1245  NextEntry->Signature = MM_FREE_POOL_SIGNATURE;
1246  NextEntry = (PMMFREE_POOL_ENTRY)((ULONG_PTR)NextEntry + PAGE_SIZE);
1247  } while (NextEntry != LastEntry);
1248 
1249  /* Is freed non paged pool protected? */
1251  {
1252  /* Protect the freed pool! */
1253  MiProtectFreeNonPagedPool(FreeEntry, FreeEntry->Size);
1254  }
1255 
1256  //
1257  // We're done, release the lock and let the caller know how much we freed
1258  //
1260  return NumberOfPages;
1261 }
PRTL_BITMAP PagedPoolAllocationMap
Definition: mm.h:414
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
NTSYSAPI void WINAPI RtlClearBits(PRTL_BITMAP, ULONG, ULONG)
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI MiUnProtectFreeNonPagedPool(IN PVOID VirtualAddress, IN ULONG PageCount)
Definition: pool.c:68
PFN_NUMBER MiEndOfInitialPoolFrame
Definition: pool.c:23
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
ULONG PFN_COUNT
Definition: mmtypes.h:102
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
ULONG Signature
Definition: mm.h:404
PVOID MmPagedPoolEnd
Definition: init.c:26
#define InsertTailList(ListHead, Entry)
SLIST_HEADER MiNonPagedPoolSListHead
Definition: pool.c:30
PVOID MmNonPagedPoolEnd
Definition: mminit.c:99
uint32_t ULONG_PTR
Definition: typedefs.h:63
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
MMPFNENTRY e1
Definition: mm.h:329
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define MiAddressToPte(x)
Definition: mmx86.c:19
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
VOID NTAPI MiProtectedPoolRemoveEntryList(IN PLIST_ENTRY Entry)
Definition: pool.c:166
PFN_NUMBER MiStartOfInitialPoolFrame
Definition: pool.c:23
LIST_ENTRY List
Definition: mm.h:402
#define MI_MAX_FREE_PAGE_LISTS
Definition: mm.h:76
smooth NULL
Definition: ftsmooth.c:416
PVOID FORCEINLINE MiPteToAddress(PMMPTE PointerPte)
Definition: mm.h:197
union _MMPFN::@1722 u3
KGUARDED_MUTEX MmPagedPoolMutex
Definition: pool.c:24
PFN_COUNT Size
Definition: mm.h:403
#define MM_FREE_POOL_SIGNATURE
Definition: mm.h:409
Definition: mm.h:400
ULONG64 Valid
Definition: mmtypes.h:150
MM_PAGED_POOL_INFO MmPagedPoolInfo
Definition: pool.c:25
VOID NTAPI RtlClearBit(_In_ PRTL_BITMAP BitMapHeader, _In_ BITMAP_INDEX BitNumber)
Definition: bitmap.c:294
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
FORCEINLINE USHORT ExQueryDepthSList(_In_ PSLIST_HEADER SListHead)
Definition: exfuncs.h:153
_Must_inspect_result_ NTSYSAPI BOOLEAN NTAPI RtlTestBit(_In_ PRTL_BITMAP BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: bitmap.c:434
ULONG MiNonPagedPoolSListMaximum
Definition: pool.c:31
VOID NTAPI MiProtectedPoolInsertList(IN PLIST_ENTRY ListHead, IN PLIST_ENTRY Entry, IN BOOLEAN Critical)
Definition: pool.c:148
struct _MMFREE_POOL_ENTRY * Owner
Definition: mm.h:405
ULONG MiPagedPoolSListMaximum
Definition: pool.c:33
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: mm.h:305
#define PAGE_SIZE
Definition: env_spec_w32.h:49
NTKERNELAPI PSLIST_ENTRY FASTCALL InterlockedPushEntrySList(IN PSLIST_HEADER ListHead, IN PSLIST_ENTRY ListEntry)
Definition: interlocked.c:82
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:933
PVOID MmPagedPoolStart
Definition: miarm.h:554
PFN_COUNT NTAPI MiDeleteSystemPageableVm(IN PMMPTE PointerPte, IN PFN_NUMBER PageCount, IN ULONG Flags, OUT PPFN_NUMBER ValidPages)
Definition: virtual.c:297
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
BOOLEAN MmProtectFreedNonPagedPool
Definition: pool.c:29
struct _MMFREE_POOL_ENTRY * PMMFREE_POOL_ENTRY
PRTL_BITMAP EndOfPagedPoolBitmap
Definition: mm.h:415
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
SLIST_HEADER MiPagedPoolSListHead
Definition: pool.c:32
FORCEINLINE PFN_NUMBER MiGetPfnEntryIndex(IN PMMPFN Pfn1)
Definition: mm.h:953
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
ULONG64 PageFrameNumber
Definition: mmtypes.h:171
VOID NTAPI MiProtectFreeNonPagedPool(IN PVOID VirtualAddress, IN ULONG PageCount)
Definition: pool.c:39
ULONG PagedPoolHint
Definition: mm.h:419
PMMPTE FirstPteForPagedPool
Definition: mm.h:416
LIST_ENTRY MmNonPagedPoolFreeListHead[MI_MAX_FREE_PAGE_LISTS]
Definition: pool.c:20
union _MMPTE::@2228 u
FORCEINLINE PMMPFN MiGetPfnEntry ( IN PFN_NUMBER  Pfn)

Definition at line 933 of file mm.h.

Referenced by MiAddHalIoMappings(), MiAllocatePagesForMdl(), MiAllocatePoolPages(), MiBuildPfnDatabaseFromLoaderBlock(), MiBuildPfnDatabaseFromPages(), MiBuildPfnDatabaseFromPageTables(), MiBuildPfnDatabaseSelf(), MiBuildPfnDatabaseZeroPage(), MiCompleteProtoPteFault(), MiCopyPfn(), MiDbgTranslatePhysicalAddress(), MiDecommitPages(), MiDeletePte(), MiDeleteSystemPageableVm(), MiFindContiguousMemory(), MiFreeContiguousMemory(), MiFreePoolPages(), MiGetPageProtection(), MiInitializeWorkingSetList(), MiInitMachineDependent(), MiLockVirtualMemory(), MiMapLockedPagesInUserSpace(), MiMapPageInHyperSpace(), MiProcessValidPteList(), MiProtectVirtualMemory(), MiReloadBootLoadedDrivers(), MiRemoveMappedPtes(), MiResolveProtoPteFault(), MiResolveTransitionFault(), MiSetPagingOfDriver(), MiSetProtectionOnSection(), MiSetupPfnForPageTable(), MiUnlockVirtualMemory(), MiUnmapLockedPagesInUserSpace(), MiZeroPfn(), MmAllocPage(), MmBuildMdlForNonPagedPool(), MmDeleteKernelStack(), MmDeleteProcessAddressSpace2(), MmDereferencePage(), MmDumpArmPfnDatabase(), MmFreeLoaderBlock(), MmFreePagesFromMdl(), MmGetLRUFirstUserPage(), MmGetLRUNextUserPage(), MmGetReferenceCountPage(), MmGetRmapListHeadPage(), MmGetSavedSwapEntryPage(), MmInsertLRULastUserPage(), MmIsPageInUse(), MmMapIoSpace(), MmNotPresentFaultCachePage(), MmProbeAndLockPages(), MmReferencePage(), MmRemoveLRUUserPage(), MmRosNotifyAvailablePage(), MmSetRmapListHeadPage(), MmSetSavedSwapEntryPage(), MmUnlockPages(), MmUnmapIoSpace(), MmZeroPageThread(), and PspCreateProcess().

934 {
935  PMMPFN Page;
936  extern RTL_BITMAP MiPfnBitMap;
937 
938  /* Make sure the PFN number is valid */
939  if (Pfn > MmHighestPhysicalPage) return NULL;
940 
941  /* Make sure this page actually has a PFN entry */
942  if ((MiPfnBitMap.Buffer) && !(RtlTestBit(&MiPfnBitMap, (ULONG)Pfn))) return NULL;
943 
944  /* Get the entry */
945  Page = &MmPfnDatabase[Pfn];
946 
947  /* Return it */
948  return Page;
949 };
PULONG Buffer
Definition: typedefs.h:89
PMMPFN MmPfnDatabase
Definition: freelist.c:24
RTL_BITMAP MiPfnBitMap
Definition: init.c:44
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ NTSYSAPI BOOLEAN NTAPI RtlTestBit(_In_ PRTL_BITMAP BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: bitmap.c:434
Definition: mm.h:305
PFN_NUMBER MmHighestPhysicalPage
Definition: meminit.c:31
unsigned int ULONG
Definition: retypes.h:1
FORCEINLINE PFN_NUMBER MiGetPfnEntryIndex ( IN PMMPFN  Pfn1)

Definition at line 953 of file mm.h.

Referenced by MiAllocatePagesForMdl(), MiDecrementShareCount(), MiDereferencePfnAndDropLockCount(), MiFreePoolPages(), MiInitializeWorkingSetList(), MiInsertPageInFreeList(), MiMapPagesInZeroSpace(), and MiUnlinkFreeOrZeroedPage().

954 {
955  //
956  // This will return the Page Frame Number (PFN) from the MMPFN
957  //
958  return Pfn1 - MmPfnDatabase;
959 }
PMMPFN MmPfnDatabase
Definition: freelist.c:24
VOID NTAPI MiInitBalancerThread ( VOID  )

Definition at line 449 of file balance.c.

Referenced by MmInitSystem().

450 {
453 #if !defined(__GNUC__)
454 
455  LARGE_INTEGER dummyJunkNeeded;
456  dummyJunkNeeded.QuadPart = -20000000; /* 2 sec */
457  ;
458 #endif
459 
460 
464 #if defined(__GNUC__)
465  (LARGE_INTEGER)(LONGLONG)-20000000LL, /* 2 sec */
466 #else
467  dummyJunkNeeded,
468 #endif
469  2000, /* 2 sec */
470  NULL);
471 
474  NULL,
475  NULL,
478  NULL);
479  if (!NT_SUCCESS(Status))
480  {
481  KeBugCheck(MEMORY_MANAGEMENT);
482  }
483 
484  Priority = LOW_REALTIME_PRIORITY + 1;
487  &Priority,
488  sizeof(Priority));
489 
490 }
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
#define LL
Definition: tui.h:72
VOID NTAPI MiBalancerThread(PVOID Unused)
Definition: balance.c:328
#define __GNUC__
Definition: _icc.h:38
_In_ KPRIORITY Priority
Definition: kefuncs.h:516
#define LOW_REALTIME_PRIORITY
BOOLEAN NTAPI KeSetTimerEx(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN LONG Period, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:294
LONG KPRIORITY
Definition: compat.h:454
static KEVENT MiBalancerEvent
Definition: balance.c:45
#define FALSE
Definition: types.h:117
static CLIENT_ID MiBalancerThreadId
Definition: balance.c:43
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
NTSTATUS NTAPI NtSetInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength)
Definition: query.c:1967
int64_t LONGLONG
Definition: typedefs.h:66
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
Status
Definition: gdiplustypes.h:24
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
static HANDLE MiBalancerThreadHandle
Definition: balance.c:44
VOID NTAPI KeInitializeTimerEx(OUT PKTIMER Timer, IN TIMER_TYPE Type)
Definition: timerobj.c:244
LONGLONG QuadPart
Definition: typedefs.h:112
static KTIMER MiBalancerTimer
Definition: balance.c:46
BOOLEAN NTAPI MiInitializeLoadedModuleList ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 2200 of file sysldr.c.

Referenced by MmArmInitSystem().

2201 {
2202  PLDR_DATA_TABLE_ENTRY LdrEntry, NewEntry;
2203  PLIST_ENTRY ListHead, NextEntry;
2204  ULONG EntrySize;
2205 
2206  /* Setup the loaded module list and locks */
2210 
2211  /* Get loop variables and the kernel entry */
2212  ListHead = &LoaderBlock->LoadOrderListHead;
2213  NextEntry = ListHead->Flink;
2214  LdrEntry = CONTAINING_RECORD(NextEntry,
2216  InLoadOrderLinks);
2217  PsNtosImageBase = (ULONG_PTR)LdrEntry->DllBase;
2218 
2219  /* Locate resource section, pool code, and system pte code */
2220  MiLocateKernelSections(LdrEntry);
2221 
2222  /* Loop the loader block */
2223  while (NextEntry != ListHead)
2224  {
2225  /* Get the loader entry */
2226  LdrEntry = CONTAINING_RECORD(NextEntry,
2228  InLoadOrderLinks);
2229 
2230  /* FIXME: ROS HACK. Make sure this is a driver */
2231  if (!RtlImageNtHeader(LdrEntry->DllBase))
2232  {
2233  /* Skip this entry */
2234  NextEntry = NextEntry->Flink;
2235  continue;
2236  }
2237 
2238  /* Calculate the size we'll need and allocate a copy */
2239  EntrySize = sizeof(LDR_DATA_TABLE_ENTRY) +
2240  LdrEntry->BaseDllName.MaximumLength +
2241  sizeof(UNICODE_NULL);
2242  NewEntry = ExAllocatePoolWithTag(NonPagedPool, EntrySize, TAG_MODULE_OBJECT);
2243  if (!NewEntry) return FALSE;
2244 
2245  /* Copy the entry over */
2246  *NewEntry = *LdrEntry;
2247 
2248  /* Allocate the name */
2249  NewEntry->FullDllName.Buffer =
2251  LdrEntry->FullDllName.MaximumLength +
2252  sizeof(UNICODE_NULL),
2253  TAG_LDR_WSTR);
2254  if (!NewEntry->FullDllName.Buffer)
2255  {
2257  return FALSE;
2258  }
2259 
2260  /* Set the base name */
2261  NewEntry->BaseDllName.Buffer = (PVOID)(NewEntry + 1);
2262 
2263  /* Copy the full and base name */
2264  RtlCopyMemory(NewEntry->FullDllName.Buffer,
2265  LdrEntry->FullDllName.Buffer,
2266  LdrEntry->FullDllName.MaximumLength);
2267  RtlCopyMemory(NewEntry->BaseDllName.Buffer,
2268  LdrEntry->BaseDllName.Buffer,
2269  LdrEntry->BaseDllName.MaximumLength);
2270 
2271  /* Null-terminate the base name */
2272  NewEntry->BaseDllName.Buffer[NewEntry->BaseDllName.Length /
2273  sizeof(WCHAR)] = UNICODE_NULL;
2274 
2275  /* Insert the entry into the list */
2277  NextEntry = NextEntry->Flink;
2278  }
2279 
2280  /* Build the import lists for the boot drivers */
2282 
2283  /* We're done */
2284  return TRUE;
2285 }
DWORD *typedef PVOID
Definition: winlogon.h:61
ERESOURCE PsLoadedModuleResource
Definition: sysldr.c:37
struct _LDR_DATA_TABLE_ENTRY LDR_DATA_TABLE_ENTRY
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
USHORT MaximumLength
Definition: env_spec_w32.h:370
ULONG_PTR PsNtosImageBase
Definition: sysldr.c:38
LIST_ENTRY PsLoadedModuleList
Definition: sysldr.c:34
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
VOID NTAPI INIT_FUNCTION MiLocateKernelSections(IN PLDR_DATA_TABLE_ENTRY LdrEntry)
Definition: sysldr.c:2139
#define InsertTailList(ListHead, Entry)
#define WCHAR
Definition: msvc.h:43
_In_ UCHAR EntrySize
Definition: iofuncs.h:640
KSPIN_LOCK PsLoadedModuleSpinLock
Definition: sysldr.c:36
PVOID DllBase
Definition: btrfs_drv.h:1766
#define TAG_LDR_WSTR
Definition: tag.h:110
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Definition: btrfs_drv.h:1762
NTSTATUS NTAPI INIT_FUNCTION MiBuildImportsForBootDrivers(VOID)
Definition: sysldr.c:1874
Definition: typedefs.h:117
LIST_ENTRY InLoadOrderLinks
Definition: ldrtypes.h:136
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
UNICODE_STRING FullDllName
Definition: btrfs_drv.h:1768
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:143
#define RtlImageNtHeader
Definition: compat.h:457
#define TAG_MODULE_OBJECT
Definition: tag.h:109
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
VOID NTAPI MiInitializeNonPagedPool ( VOID  )

Definition at line 276 of file pool.c.

Referenced by MiBuildNonPagedPool(), and MiInitMachineDependent().

277 {
278  ULONG i;
279  PFN_COUNT PoolPages;
280  PMMFREE_POOL_ENTRY FreeEntry, FirstEntry;
281  PMMPTE PointerPte;
282  PAGED_CODE();
283 
284  //
285  // Initialize the pool S-LISTs as well as their maximum count. In general,
286  // we'll allow 8 times the default on a 2GB system, and two times the default
287  // on a 1GB system.
288  //
291  if (MmNumberOfPhysicalPages >= ((2 * _1GB) /PAGE_SIZE))
292  {
295  }
296  else if (MmNumberOfPhysicalPages >= (_1GB /PAGE_SIZE))
297  {
300  }
301 
302  //
303  // However if debugging options for the pool are enabled, turn off the S-LIST
304  // to reduce the risk of messing things up even more
305  //
307  {
310  }
311 
312  //
313  // We keep 4 lists of free pages (4 lists help avoid contention)
314  //
315  for (i = 0; i < MI_MAX_FREE_PAGE_LISTS; i++)
316  {
317  //
318  // Initialize each of them
319  //
321  }
322 
323  //
324  // Calculate how many pages the initial nonpaged pool has
325  //
327  MmNumberOfFreeNonPagedPool = PoolPages;
328 
329  //
330  // Initialize the first free entry
331  //
332  FreeEntry = MmNonPagedPoolStart;
333  FirstEntry = FreeEntry;
334  FreeEntry->Size = PoolPages;
335  FreeEntry->Signature = MM_FREE_POOL_SIGNATURE;
336  FreeEntry->Owner = FirstEntry;
337 
338  //
339  // Insert it into the last list
340  //
341  InsertHeadList(&MmNonPagedPoolFreeListHead[MI_MAX_FREE_PAGE_LISTS - 1],
342  &FreeEntry->List);
343 
344  //
345  // Now create free entries for every single other page
346  //
347  while (PoolPages-- > 1)
348  {
349  //
350  // Link them all back to the original entry
351  //
352  FreeEntry = (PMMFREE_POOL_ENTRY)((ULONG_PTR)FreeEntry + PAGE_SIZE);
353  FreeEntry->Owner = FirstEntry;
354  FreeEntry->Signature = MM_FREE_POOL_SIGNATURE;
355  }
356 
357  //
358  // Validate and remember first allocated pool page
359  //
360  PointerPte = MiAddressToPte(MmNonPagedPoolStart);
361  ASSERT(PointerPte->u.Hard.Valid == 1);
363 
364  //
365  // Keep track of where initial nonpaged pool ends
366  //
369 
370  //
371  // Validate and remember last allocated pool page
372  //
373  PointerPte = MiAddressToPte((PVOID)((ULONG_PTR)MmNonPagedPoolEnd0 - 1));
374  ASSERT(PointerPte->u.Hard.Valid == 1);
376 
377  //
378  // Validate the first nonpaged pool expansion page (which is a guard page)
379  //
381  ASSERT(PointerPte->u.Hard.Valid == 0);
382 
383  //
384  // Calculate the size of the expansion region alone
385  //
388 
389  //
390  // Remove 2 pages, since there's a guard page on top and on the bottom
391  //
393 
394  //
395  // Now initialize the nonpaged pool expansion PTE space. Remember there's a
396  // guard page on top so make sure to skip it. The bottom guard page will be
397  // guaranteed by the fact our size is off by one.
398  //
399  MiInitializeSystemPtes(PointerPte + 1,
402 }
DWORD *typedef PVOID
Definition: winlogon.h:61
PFN_NUMBER MiEndOfInitialPoolFrame
Definition: pool.c:23
ULONG PFN_COUNT
Definition: mmtypes.h:102
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
ULONG Signature
Definition: mm.h:404
PVOID MmNonPagedPoolExpansionStart
Definition: init.c:25
#define PAGED_CODE()
Definition: video.h:57
SLIST_HEADER MiNonPagedPoolSListHead
Definition: pool.c:30
uint32_t ULONG_PTR
Definition: typedefs.h:63
PFN_COUNT MmNumberOfFreeNonPagedPool
Definition: pool.c:21
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define MiAddressToPte(x)
Definition: mmx86.c:19
VOID NTAPI MiInitializeSystemPtes(IN PMMPTE StartingPte, IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE PoolType)
Definition: syspte.c:399
PFN_NUMBER MiStartOfInitialPoolFrame
Definition: pool.c:23
LIST_ENTRY List
Definition: mm.h:402
#define MI_MAX_FREE_PAGE_LISTS
Definition: mm.h:76
PVOID MmNonPagedPoolEnd0
Definition: pool.c:22
PFN_COUNT MiExpansionPoolPagesInitialCharge
Definition: pool.c:21
PFN_COUNT Size
Definition: mm.h:403
#define MM_FREE_POOL_SIGNATURE
Definition: mm.h:409
Definition: mm.h:400
ULONG64 Valid
Definition: mmtypes.h:150
ULONG MiNonPagedPoolSListMaximum
Definition: pool.c:31
struct _MMFREE_POOL_ENTRY * Owner
Definition: mm.h:405
#define BYTES_TO_PAGES(Size)
ULONG MiPagedPoolSListMaximum
Definition: pool.c:33
#define PAGE_SIZE
Definition: env_spec_w32.h:49
PVOID MmNonPagedPoolStart
Definition: init.c:24
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
PFN_COUNT MmNumberOfPhysicalPages
Definition: init.c:48
BOOLEAN MmProtectFreedNonPagedPool
Definition: pool.c:29
struct _MMFREE_POOL_ENTRY * PMMFREE_POOL_ENTRY
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
ULONG MmMaximumNonPagedPoolInBytes
Definition: init.c:22
SLIST_HEADER MiPagedPoolSListHead
Definition: pool.c:32
unsigned int ULONG
Definition: retypes.h:1
ULONG MmSizeOfNonPagedPoolInBytes
Definition: init.c:21
LIST_ENTRY MmNonPagedPoolFreeListHead[MI_MAX_FREE_PAGE_LISTS]
Definition: pool.c:20
#define PFN_FROM_PTE(v)
Definition: mm.h:88
#define _1GB
Definition: miarm.h:16
union _MMPTE::@2228 u
WINBASEAPI VOID WINAPI InitializeSListHead(_Out_ PSLIST_HEADER ListHead)
Definition: rtlfuncs.h:3353
VOID NTAPI MiInitializeSpecialPool ( VOID  )

Definition at line 123 of file special.c.

Referenced by MiBuildPagedPool().

124 {
125  ULONG SpecialPoolPtes, i;
126  PMMPTE PointerPte;
127 
128  /* Check if there is a special pool tag */
129  if ((MmSpecialPoolTag == 0) ||
130  (MmSpecialPoolTag == -1)) return;
131 
132  /* Calculate number of system PTEs for the special pool */
133  if (MmNumberOfSystemPtes >= 0x3000)
134  SpecialPoolPtes = MmNumberOfSystemPtes / 3;
135  else
136  SpecialPoolPtes = MmNumberOfSystemPtes / 6;
137 
138  /* Don't let the number go too high */
139  if (SpecialPoolPtes > 0x6000) SpecialPoolPtes = 0x6000;
140 
141  /* Round up to the page size */
142  SpecialPoolPtes = PAGE_ROUND_UP(SpecialPoolPtes);
143 
144  ASSERT((SpecialPoolPtes & (PTE_PER_PAGE - 1)) == 0);
145 
146  /* Reserve those PTEs */
147  do
148  {
149  PointerPte = MiReserveAlignedSystemPtes(SpecialPoolPtes,
151  /*0x400000*/0); // FIXME:
152  if (PointerPte) break;
153 
154  /* Reserving didn't work, so try to reduce the requested size */
155  ASSERT(SpecialPoolPtes >= PTE_PER_PAGE);
156  SpecialPoolPtes -= PTE_PER_PAGE;
157  } while (SpecialPoolPtes);
158 
159  /* Fail if we couldn't reserve them at all */
160  if (!SpecialPoolPtes) return;
161 
162  /* Make sure we got enough */
163  ASSERT(SpecialPoolPtes >= PTE_PER_PAGE);
164 
165  /* Save first PTE and its address */
166  MiSpecialPoolFirstPte = PointerPte;
167  MmSpecialPoolStart = MiPteToAddress(PointerPte);
168 
169  for (i = 0; i < PTE_PER_PAGE / 2; i++)
170  {
171  /* Point it to the next entry */
172  PointerPte->u.List.NextEntry = &PointerPte[2] - MmSystemPteBase;
173 
174  /* Move to the next pair */
175  PointerPte += 2;
176  }
177 
178  /* Save extra values */
179  MiSpecialPoolExtra = PointerPte;
180  MiSpecialPoolExtraCount = SpecialPoolPtes - PTE_PER_PAGE;
181 
182  /* Mark the previous PTE as the last one */
183  MiSpecialPoolLastPte = PointerPte - 2;
185 
186  /* Save end address of the special pool */
188 
189  /* Calculate maximum non-paged part of the special pool */
191 
192  /* And limit it if it turned out to be too big */
193  if (MmNumberOfPhysicalPages > 0x3FFF)
195 
196  DPRINT1("Special pool start %p - end %p\n", MmSpecialPoolStart, MmSpecialPoolEnd);
198 
199  //MiTestSpecialPool();
200 }
PFN_NUMBER MmResidentAvailablePages
Definition: freelist.c:27
ULONG MiSpecialPoolExtraCount
Definition: special.c:41
ULONG64 NextEntry
Definition: mmtypes.h:145
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define MM_EMPTY_PTE_LIST
Definition: mm.h:83
#define POOL_FLAG_SPECIAL_POOL
Definition: miarm.h:262
ULONG MmNumberOfSystemPtes
Definition: init.c:42
#define PAGE_ROUND_UP(x)
Definition: scsiport_int.h:13
PMMPTE MiSpecialPoolLastPte
Definition: special.c:44
PVOID MmSpecialPoolEnd
Definition: special.c:39
GLenum GLclampf GLint i
Definition: glfuncs.h:14
ULONG MmSpecialPoolTag
Definition: pool.c:27
PVOID FORCEINLINE MiPteToAddress(PMMPTE PointerPte)
Definition: mm.h:197
PFN_COUNT MiSpecialPagesNonPagedMaximum
Definition: special.c:52
PVOID MiSpecialPoolExtra
Definition: special.c:40
MMPTE_LIST List
Definition: mmtypes.h:222
#define PTE_PER_PAGE
Definition: mm.h:19
PMMPTE NTAPI MiReserveAlignedSystemPtes(IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType, IN ULONG Alignment)
Definition: syspte.c:88
PFN_COUNT MmNumberOfPhysicalPages
Definition: init.c:48
PVOID MmSpecialPoolStart
Definition: special.c:38
PMMPTE MmSystemPteBase
Definition: syspte.c:21
#define DPRINT1
Definition: precomp.h:8
ULONG ExpPoolFlags
Definition: expool.c:47
unsigned int ULONG
Definition: retypes.h:1
PMMPTE MiSpecialPoolFirstPte
Definition: special.c:43
union _MMPTE::@2228 u
PVOID NTAPI MiMapPageInHyperSpace ( IN PEPROCESS  Process,
IN PFN_NUMBER  Page,
IN PKIRQL  OldIrql 
)

Definition at line 30 of file hypermap.c.

Referenced by _MiWriteBackPage(), MiCopyFromUserPage(), MiCopyPageToPage(), MiReadFilePage(), MiReadPage(), MiZeroPhysicalPage(), and MmCreateHyperspaceMapping().

33 {
34  MMPTE TempPte;
35  PMMPTE PointerPte;
37 
38  //
39  // Never accept page 0 or non-physical pages
40  //
41  ASSERT(Page != 0);
42  ASSERT(MiGetPfnEntry(Page) != NULL);
43 
44  //
45  // Build the PTE
46  //
47  TempPte = ValidKernelPteLocal;
48  TempPte.u.Hard.PageFrameNumber = Page;
49 
50  //
51  // Pick the first hyperspace PTE
52  //
53  PointerPte = MmFirstReservedMappingPte;
54 
55  //
56  // Acquire the hyperlock
57  //
59  KeAcquireSpinLock(&Process->HyperSpaceLock, OldIrql);
60 
61  //
62  // Now get the first free PTE
63  //
64  Offset = PFN_FROM_PTE(PointerPte);
65  if (!Offset)
66  {
67  //
68  // Reset the PTEs
69  //
70  Offset = MI_HYPERSPACE_PTES;
72  }
73 
74  //
75  // Prepare the next PTE
76  //
77  PointerPte->u.Hard.PageFrameNumber = Offset - 1;
78 
79  //
80  // Write the current PTE
81  //
82  PointerPte += Offset;
83  MI_WRITE_VALID_PTE(PointerPte, TempPte);
84 
85  //
86  // Return the address
87  //
88  return MiPteToAddress(PointerPte);
89 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
ULONG PFN_NUMBER
Definition: ke.h:8
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
FORCEINLINE VOID MI_WRITE_VALID_PTE(IN PMMPTE PointerPte, IN MMPTE TempPte)
Definition: miarm.h:916
PMMPTE MmFirstReservedMappingPte
Definition: hypermap.c:20
#define PsGetCurrentProcess
Definition: psfuncs.h:17
#define MI_HYPERSPACE_PTES
Definition: mm.h:77
smooth NULL
Definition: ftsmooth.c:416
PVOID FORCEINLINE MiPteToAddress(PMMPTE PointerPte)
Definition: mm.h:197
MMPTE ValidKernelPteLocal
Definition: init.c:35
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:75
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:933
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
FORCEINLINE VOID KeFlushProcessTb(VOID)
Definition: ke.h:209
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
ULONG64 PageFrameNumber
Definition: mmtypes.h:171
#define PFN_FROM_PTE(v)
Definition: mm.h:88
union _MMPTE::@2228 u
PVOID NTAPI MiMapPagesInZeroSpace ( IN PMMPFN  Pfn1,
IN PFN_NUMBER  NumberOfPages 
)

Definition at line 113 of file hypermap.c.

Referenced by MmZeroPageThread().

115 {
116  MMPTE TempPte;
117  PMMPTE PointerPte;
118  PFN_NUMBER Offset, PageFrameIndex;
119 
120  //
121  // Sanity checks
122  //
124  ASSERT(NumberOfPages != 0);
125  ASSERT(NumberOfPages <= (MI_ZERO_PTES - 1));
126 
127  //
128  // Pick the first zeroing PTE
129  //
130  PointerPte = MiFirstReservedZeroingPte;
131 
132  //
133  // Now get the first free PTE
134  //
135  Offset = PFN_FROM_PTE(PointerPte);
136  if (NumberOfPages > Offset)
137  {
138  //
139  // Reset the PTEs
140  //
141  Offset = MI_ZERO_PTES - 1;
142  PointerPte->u.Hard.PageFrameNumber = Offset;
144  }
145 
146  //
147  // Prepare the next PTE
148  //
149  PointerPte->u.Hard.PageFrameNumber = Offset - NumberOfPages;
150 
151  /* Choose the correct PTE to use, and which template */
152  PointerPte += (Offset + 1);
153  TempPte = ValidKernelPte;
154 
155  /* Make sure the list isn't empty and loop it */
156  ASSERT(Pfn1 != (PVOID)LIST_HEAD);
157  while (Pfn1 != (PVOID)LIST_HEAD)
158  {
159  /* Get the page index for this PFN */
160  PageFrameIndex = MiGetPfnEntryIndex(Pfn1);
161 
162  //
163  // Write the PFN
164  //
165  TempPte.u.Hard.PageFrameNumber = PageFrameIndex;
166 
167  //
168  // Set the correct PTE to write to, and set its new value
169  //
170  PointerPte--;
171  MI_WRITE_VALID_PTE(PointerPte, TempPte);
172 
173  /* Move to the next PFN */
174  Pfn1 = (PMMPFN)Pfn1->u1.Flink;
175  }
176 
177  //
178  // Return the address
179  //
180  return MiPteToAddress(PointerPte);
181 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
ULONG PFN_NUMBER
Definition: ke.h:8
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
FORCEINLINE VOID MI_WRITE_VALID_PTE(IN PMMPTE PointerPte, IN MMPTE TempPte)
Definition: miarm.h:916
PVOID FORCEINLINE MiPteToAddress(PMMPTE PointerPte)
Definition: mm.h:197
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:75
MMPTE ValidKernelPte
Definition: init.c:31
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
LIST_HEAD(acpi_bus_event_list)
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
struct _MMPFN * PMMPFN
FORCEINLINE VOID KeFlushProcessTb(VOID)
Definition: ke.h:209
FORCEINLINE PFN_NUMBER MiGetPfnEntryIndex(IN PMMPFN Pfn1)
Definition: mm.h:953
ULONG64 PageFrameNumber
Definition: mmtypes.h:171
PMMPTE MiFirstReservedZeroingPte
Definition: hypermap.c:21
#define MI_ZERO_PTES
Definition: mm.h:78
#define PFN_FROM_PTE(v)
Definition: mm.h:88
union _MMPTE::@2228 u
BOOLEAN NTAPI MiRaisePoolQuota ( IN POOL_TYPE  PoolType,
IN ULONG  CurrentMaxQuota,
OUT PULONG  NewMaxQuota 
)

Definition at line 1266 of file pool.c.

1269 {
1270  //
1271  // Not implemented
1272  //
1273  UNIMPLEMENTED;
1274  *NewMaxQuota = CurrentMaxQuota + 65536;
1275  return TRUE;
1276 }
#define TRUE
Definition: types.h:120
#define UNIMPLEMENTED
Definition: debug.h:114
NTSTATUS NTAPI MiReadPageFile ( _In_ PFN_NUMBER  Page,
_In_ ULONG  PageFileIndex,
_In_ ULONG_PTR  PageFileOffset 
)

Definition at line 201 of file pagefile.c.

Referenced by MiResolvePageFileFault(), and MmReadFromSwapPage().

205 {
206  LARGE_INTEGER file_offset;
209  KEVENT Event;
210  UCHAR MdlBase[sizeof(MDL) + sizeof(ULONG)];
211  PMDL Mdl = (PMDL)MdlBase;
212  PMMPAGING_FILE PagingFile;
213 
214  DPRINT("MiReadSwapFile\n");
215 
216  if (PageFileOffset == 0)
217  {
218  KeBugCheck(MEMORY_MANAGEMENT);
219  return(STATUS_UNSUCCESSFUL);
220  }
221 
222  ASSERT(PageFileIndex < MAX_PAGING_FILES);
223 
224  PagingFile = MmPagingFile[PageFileIndex];
225 
226  if (PagingFile->FileObject == NULL || PagingFile->FileObject->DeviceObject == NULL)
227  {
228  DPRINT1("Bad paging file %u\n", PageFileIndex);
229  KeBugCheck(MEMORY_MANAGEMENT);
230  }
231 
233  MmBuildMdlFromPages(Mdl, &Page);
234  Mdl->MdlFlags |= MDL_PAGES_LOCKED;
235 
236  file_offset.QuadPart = PageFileOffset * PAGE_SIZE;
237 
239  Status = IoPageRead(PagingFile->FileObject,
240  Mdl,
241  &file_offset,
242  &Event,
243  &Iosb);
244  if (Status == STATUS_PENDING)
245  {
247  Status = Iosb.Status;
248  }
249  if (Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA)
250  {
251  MmUnmapLockedPages (Mdl->MappedSystemVa, Mdl);
252  }
253  return(Status);
254 }
#define MmInitializeMdl(_MemoryDescriptorList, _BaseVa, _Length)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
VOID NTAPI MmBuildMdlFromPages(PMDL Mdl, PPFN_NUMBER Pages)
Definition: pagefile.c:98
NTSTATUS NTAPI IoPageRead(IN PFILE_OBJECT FileObject, IN PMDL Mdl, IN PLARGE_INTEGER Offset, IN PKEVENT Event, IN PIO_STATUS_BLOCK StatusBlock)
Definition: iofunc.c:1091
PFILE_OBJECT FileObject
Definition: mm.h:434
PVOID PMDL
Definition: usb.h:39
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define MDL_MAPPED_TO_SYSTEM_VA
Definition: mmtypes.h:18
ACPI_EFI_EVENT Event
Definition: acefiex.h:633
#define FALSE
Definition: types.h:117
VOID NTAPI MmUnmapLockedPages(IN PVOID BaseAddress, IN PMDL Mdl)
Definition: mdlsup.c:841
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1469
LONG NTSTATUS
Definition: precomp.h:26
#define MAX_PAGING_FILES
Definition: mm.h:105
return Iosb
Definition: create.c:4426
#define MDL_PAGES_LOCKED
Definition: mmtypes.h:19
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
unsigned char UCHAR
Definition: xmlstorage.h:181
MDL
Definition: mmtypes.h:117
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Status
Definition: gdiplustypes.h:24
PMMPAGING_FILE MmPagingFile[MAX_PAGING_FILES]
Definition: pagefile.c:44
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
LONGLONG QuadPart
Definition: typedefs.h:112
FORCEINLINE VOID MiReleasePfnLock ( _In_ KIRQL  OldIrql)

Definition at line 901 of file mm.h.

Referenced by _MiFlushMappedSection(), MiAllocatePagesForMdl(), MiAllocatePoolPages(), MiBalancerThread(), MiBuildPagedPool(), MiBuildPfnDatabaseFromLoaderBlock(), MiCheckControlArea(), MiCheckPurgeAndUpMapCount(), MiCompleteProtoPteFault(), MiDeleteSystemPageableVm(), MiDeleteVirtualAddresses(), MiDispatchFault(), MiFillSystemPageDirectory(), MiFindContiguousPages(), MiFlushTbAndCapture(), MiFreeContiguousMemory(), MiGetPageProtection(), MiGetPteForProcess(), MiInitializeAndChargePfn(), MiInitMachineDependent(), MiLoadImageSection(), MiMakeSystemAddressValidPfn(), MiMapLockedPagesInUserSpace(), MiProcessValidPteList(), MiProtectVirtualMemory(), MiReleaseProcessReferenceToSessionDataPage(), MiRemoveMappedPtes(), MiResolveDemandZeroFault(), MiResolvePageFileFault(), MiResolveProtoPteFault(), MiSegmentDelete(), MiSessionCommitPageTables(), MiSessionCreateInternal(), MiSessionInitializeWorkingSetList(), MiSetControlAreaSymbolsLoaded(), MiUnmapLockedPagesInUserSpace(), MmAllocateSpecialPool(), MmAllocPage(), MmArmAccessFault(), MmCreateArm3Section(), MmCreateKernelStack(), MmCreateProcessAddressSpace(), MmDeleteKernelStack(), MmDeleteProcessAddressSpace(), MmDeleteProcessAddressSpace2(), MmDereferencePage(), MmFreeLoaderBlock(), MmFreeMemoryArea(), MmFreePagesFromMdl(), MmFreeSpecialPool(), MmGetLRUFirstUserPage(), MmGetLRUNextUserPage(), MmGetPhysicalMemoryRanges(), MmGetReferenceCountPage(), MmGetRmapListHeadPage(), MmGetSavedSwapEntryPage(), MmGrowKernelStackEx(), MmInitializeProcessAddressSpace(), MmInsertLRULastUserPage(), MmNotPresentFaultCachePage(), MmPageOutSectionView(), MmProbeAndLockPages(), MmRemoveLRUUserPage(), MmSetRmapListHeadPage(), MmSetSavedSwapEntryPage(), MmUnlockPages(), and MmZeroPageThread().

903 {
905 }
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
FORCEINLINE VOID MiReleasePfnLockFromDpcLevel ( VOID  )

Definition at line 920 of file mm.h.

Referenced by MiAllocatePoolPages().

921 {
922  PKSPIN_LOCK_QUEUE LockQueue;
923 
924  LockQueue = &KeGetCurrentPrcb()->LockQueue[LockQueuePfnLock];
927 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
VOID FASTCALL KeReleaseQueuedSpinLockFromDpcLevel(IN OUT PKSPIN_LOCK_QUEUE LockQueue)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
VOID NTAPI MiReloadBootLoadedDrivers ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 1685 of file sysldr.c.

Referenced by MmArmInitSystem().

1686 {
1687  PLIST_ENTRY NextEntry;
1688  ULONG i = 0;
1689  PIMAGE_NT_HEADERS NtHeader;
1690  PLDR_DATA_TABLE_ENTRY LdrEntry;
1691  PIMAGE_FILE_HEADER FileHeader;
1692  BOOLEAN ValidRelocs;
1693  PIMAGE_DATA_DIRECTORY DataDirectory;
1694  PVOID DllBase, NewImageAddress;
1695  NTSTATUS Status;
1696  PMMPTE PointerPte, StartPte, LastPte;
1697  PFN_COUNT PteCount;
1698  PMMPFN Pfn1;
1699  MMPTE TempPte, OldPte;
1700 
1701  /* Loop driver list */
1702  for (NextEntry = LoaderBlock->LoadOrderListHead.Flink;
1703  NextEntry != &LoaderBlock->LoadOrderListHead;
1704  NextEntry = NextEntry->Flink)
1705  {
1706  /* Get the loader entry and NT header */
1707  LdrEntry = CONTAINING_RECORD(NextEntry,
1709  InLoadOrderLinks);
1710  NtHeader = RtlImageNtHeader(LdrEntry->DllBase);
1711 
1712  /* Debug info */
1713  DPRINT("[Mm0]: Driver at: %p ending at: %p for module: %wZ\n",
1714  LdrEntry->DllBase,
1715  (ULONG_PTR)LdrEntry->DllBase + LdrEntry->SizeOfImage,
1716  &LdrEntry->FullDllName);
1717 
1718  /* Get the first PTE and the number of PTEs we'll need */
1719  PointerPte = StartPte = MiAddressToPte(LdrEntry->DllBase);
1720  PteCount = ROUND_TO_PAGES(LdrEntry->SizeOfImage) >> PAGE_SHIFT;
1721  LastPte = StartPte + PteCount;
1722 
1723 #if MI_TRACE_PFNS
1724  /* Loop the PTEs */
1725  while (PointerPte < LastPte)
1726  {
1727  ULONG len;
1728  ASSERT(PointerPte->u.Hard.Valid == 1);
1729  Pfn1 = MiGetPfnEntry(PFN_FROM_PTE(PointerPte));
1730  len = wcslen(LdrEntry->BaseDllName.Buffer) * sizeof(WCHAR);
1731  snprintf(Pfn1->ProcessName, min(16, len), "%S", LdrEntry->BaseDllName.Buffer);
1732  PointerPte++;
1733  }
1734 #endif
1735  /* Skip kernel and HAL */
1736  /* ROS HACK: Skip BOOTVID/KDCOM too */
1737  i++;
1738  if (i <= 4) continue;
1739 
1740  /* Skip non-drivers */
1741  if (!NtHeader) continue;
1742 
1743  /* Get the file header and make sure we can relocate */
1744  FileHeader = &NtHeader->FileHeader;
1745  if (FileHeader->Characteristics & IMAGE_FILE_RELOCS_STRIPPED) continue;
1746  if (NtHeader->OptionalHeader.NumberOfRvaAndSizes <
1748 
1749  /* Everything made sense until now, check the relocation section too */
1750  DataDirectory = &NtHeader->OptionalHeader.
1751  DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
1752  if (!DataDirectory->VirtualAddress)
1753  {
1754  /* We don't really have relocations */
1755  ValidRelocs = FALSE;
1756  }
1757  else
1758  {
1759  /* Make sure the size is valid */
1760  if ((DataDirectory->VirtualAddress + DataDirectory->Size) >
1761  LdrEntry->SizeOfImage)
1762  {
1763  /* They're not, skip */
1764  continue;
1765  }
1766 
1767  /* We have relocations */
1768  ValidRelocs = TRUE;
1769  }
1770 
1771  /* Remember the original address */
1772  DllBase = LdrEntry->DllBase;
1773 
1774  /* Loop the PTEs */
1775  PointerPte = StartPte;
1776  while (PointerPte < LastPte)
1777  {
1778  /* Mark the page modified in the PFN database */
1779  ASSERT(PointerPte->u.Hard.Valid == 1);
1780  Pfn1 = MiGetPfnEntry(PFN_FROM_PTE(PointerPte));
1781  ASSERT(Pfn1->u3.e1.Rom == 0);
1782  Pfn1->u3.e1.Modified = TRUE;
1783 
1784  /* Next */
1785  PointerPte++;
1786  }
1787 
1788  /* Now reserve system PTEs for the image */
1789  PointerPte = MiReserveSystemPtes(PteCount, SystemPteSpace);
1790  if (!PointerPte)
1791  {
1792  /* Shouldn't happen */
1793  ERROR_FATAL("[Mm0]: Couldn't allocate driver section!\n");
1794  return;
1795  }
1796 
1797  /* This is the new virtual address for the module */
1798  LastPte = PointerPte + PteCount;
1799  NewImageAddress = MiPteToAddress(PointerPte);
1800 
1801  /* Sanity check */
1802  DPRINT("[Mm0]: Copying from: %p to: %p\n", DllBase, NewImageAddress);
1804 
1805  /* Loop the new driver PTEs */
1806  TempPte = ValidKernelPte;
1807  while (PointerPte < LastPte)
1808  {
1809  /* Copy the old data */
1810  OldPte = *StartPte;
1811  ASSERT(OldPte.u.Hard.Valid == 1);
1812 
1813  /* Set page number from the loader's memory */
1814  TempPte.u.Hard.PageFrameNumber = OldPte.u.Hard.PageFrameNumber;
1815 
1816  /* Write it */
1817  MI_WRITE_VALID_PTE(PointerPte, TempPte);
1818 
1819  /* Move on */
1820  PointerPte++;
1821  StartPte++;
1822  }
1823 
1824  /* Update position */
1825  PointerPte -= PteCount;
1826 
1827  /* Sanity check */
1828  ASSERT(*(PULONG)NewImageAddress == *(PULONG)DllBase);
1829 
1830  /* Set the image base to the address where the loader put it */
1831  NtHeader->OptionalHeader.ImageBase = (ULONG_PTR)DllBase;
1832 
1833  /* Check if we had relocations */
1834  if (ValidRelocs)
1835  {
1836  /* Relocate the image */
1837  Status = LdrRelocateImageWithBias(NewImageAddress,
1838  0,
1839  "SYSLDR",
1843  if (!NT_SUCCESS(Status))
1844  {
1845  /* This shouldn't happen */
1846  ERROR_FATAL("Relocations failed!\n");
1847  return;
1848  }
1849  }
1850 
1851  /* Update the loader entry */
1852  LdrEntry->DllBase = NewImageAddress;
1853 
1854  /* Update the thunks */
1855  DPRINT("[Mm0]: Updating thunks to: %wZ\n", &LdrEntry->BaseDllName);
1856  MiUpdateThunks(LoaderBlock,
1857  DllBase,
1858  NewImageAddress,
1859  LdrEntry->SizeOfImage);
1860 
1861  /* Update the loader entry */
1862  LdrEntry->Flags |= LDRP_SYSTEM_MAPPED;
1863  LdrEntry->EntryPoint = (PVOID)((ULONG_PTR)NewImageAddress +
1865  LdrEntry->SizeOfImage = PteCount << PAGE_SHIFT;
1866 
1867  /* FIXME: We'll need to fixup the PFN linkage when switching to ARM3 */
1868  }
1869 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define TRUE
Definition: types.h:120
ULONG PFN_COUNT
Definition: mmtypes.h:102
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
PMMPTE NTAPI MiReserveSystemPtes(IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:246
VOID NTAPI INIT_FUNCTION MiUpdateThunks(IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN PVOID OldBase, IN PVOID NewBase, IN ULONG Size)
Definition: sysldr.c:592
ULONG SizeOfImage
Definition: ldrtypes.h:141
#define snprintf
Definition: wintirpc.h:48
USHORT Modified
Definition: mm.h:292
#define WCHAR
Definition: msvc.h:43
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define ERROR_FATAL(...)
Definition: debug.h:238
PVOID DllBase
Definition: btrfs_drv.h:1766
MMPFNENTRY e1
Definition: mm.h:329
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define MiAddressToPte(x)
Definition: mmx86.c:19
#define FALSE
Definition: types.h:117
FORCEINLINE VOID MI_WRITE_VALID_PTE(IN PMMPTE PointerPte, IN MMPTE TempPte)
Definition: miarm.h:916
PVOID EntryPoint
Definition: ntddk_ex.h:207
PVOID FORCEINLINE MiPteToAddress(PMMPTE PointerPte)
Definition: mm.h:197
void DPRINT(...)
Definition: polytest.cpp:61
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
union _MMPFN::@1722 u3
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:345
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
ULONG64 Valid
Definition: mmtypes.h:150
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:75
MMPTE ValidKernelPte
Definition: init.c:31
Definition: mm.h:305
Definition: btrfs_drv.h:1762
ULONG ExpInitializationPhase
Definition: init.c:65
GLenum GLsizei len
Definition: glext.h:6722
Definition: typedefs.h:117
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:933
Status
Definition: gdiplustypes.h:24
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
NTSYSAPI ULONG NTAPI LdrRelocateImageWithBias(_In_ PVOID NewAddress, _In_ LONGLONG AdditionalBias, _In_ PCCH LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid)
#define ROUND_TO_PAGES(Size)
PVOID DllBase
Definition: verifier.h:6
UNICODE_STRING FullDllName
Definition: btrfs_drv.h:1768
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:143
USHORT Rom
Definition: mm.h:300
unsigned int * PULONG
Definition: retypes.h:1
#define min(a, b)
Definition: monoChain.cc:55
#define IMAGE_DIRECTORY_ENTRY_BASERELOC
Definition: pedump.c:264
#define RtlImageNtHeader
Definition: compat.h:457
ULONG Flags
Definition: ntddk_ex.h:211
unsigned int ULONG
Definition: retypes.h:1
#define IMAGE_FILE_RELOCS_STRIPPED
Definition: pedump.c:159
#define ULONG_PTR
Definition: config.h:101
ULONG64 PageFrameNumber
Definition: mmtypes.h:171
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:247
return STATUS_SUCCESS
Definition: btrfs.c:2710
#define PFN_FROM_PTE(v)
Definition: mm.h:88
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
union _MMPTE::@2228 u
#define LDRP_SYSTEM_MAPPED
Definition: ldrtypes.h:52
VOID NTAPI MiRosCheckMemoryAreas ( PMMSUPPORT  AddressSpace)
VOID NTAPI MiRosCleanupMemoryArea ( PEPROCESS  Process,
PMMVAD  Vad 
)

Definition at line 522 of file marea.c.

Referenced by MmCleanProcessAddressSpace().

525 {
529 
530  /* We must be called from MmCleanupAddressSpace and nowhere else!
531  Make sure things are as expected... */
532  ASSERT(Process == PsGetCurrentProcess());
533  ASSERT(Process->VmDeleted == TRUE);
534  ASSERT(((PsGetCurrentThread()->ThreadsProcess == Process) &&
535  (Process->ActiveThreads == 1)) ||
536  (Process->ActiveThreads == 0));
537 
538  /* We are in cleanup, we don't need to synchronize */
539  MmUnlockAddressSpace(&Process->Vm);
540 
541  MemoryArea = (PMEMORY_AREA)Vad;
542  BaseAddress = (PVOID)MA_GetStartingAddress(MemoryArea);
543 
544  if (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW)
545  {
546  Status = MiRosUnmapViewOfSection(Process, BaseAddress, Process->ProcessExiting);
547  }
548  else if (MemoryArea->Type == MEMORY_AREA_CACHE)
549  {
550  Status = MmUnmapViewOfCacheSegment(&Process->Vm, BaseAddress);
551  }
552  else
553  {
554  /* There shouldn't be anything else! */
555  ASSERT(FALSE);
556  }
557 
558  /* Make sure this worked! */
559  ASSERT(NT_SUCCESS(Status));
560 
561  /* Lock the address space again */
562  MmLockAddressSpace(&Process->Vm);
563 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define TRUE
Definition: types.h:120
ULONG Type
Definition: mm.h:214
struct _MEMORY_AREA * PMEMORY_AREA
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1410
#define MEMORY_AREA_CACHE
Definition: mm.h:72
#define FALSE
Definition: types.h:117
ULONG ProcessExiting
Definition: pstypes.h:1326
ULONG ActiveThreads
Definition: pstypes.h:1267
#define PsGetCurrentProcess
Definition: psfuncs.h:17
#define MEMORY_AREA_SECTION_VIEW
Definition: mm.h:71
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
ULONG VmDeleted
Definition: pstypes.h:1329
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define MA_GetStartingAddress(_MemoryArea)
Definition: mm.h:207
MMSUPPORT Vm
Definition: pstypes.h:1287
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI MmUnmapViewOfCacheSegment(PMMSUPPORT AddressSpace, PVOID BaseAddress)
Definition: data.c:713
NTSTATUS NTAPI MiRosUnmapViewOfSection(IN PEPROCESS Process, IN PVOID BaseAddress, IN BOOLEAN SkipDebuggerNotify)
Definition: section.c:4108
struct _MEMORY_AREA * MemoryArea
Definition: newmm.h:65
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1403
VOID NTAPI MiUnmapPageInHyperSpace ( IN PEPROCESS  Process,
IN PVOID  Address,
IN KIRQL  OldIrql 
)

Definition at line 93 of file hypermap.c.

Referenced by _MiWriteBackPage(), MiCopyFromUserPage(), MiCopyPageToPage(), MiReadFilePage(), MiReadPage(), and MiZeroPhysicalPage().

96 {
98 
99  //
100  // Blow away the mapping
101  //
102  MiAddressToPte(Address)->u.Long = 0;
103 
104  //
105  // Release the hyperlock
106  //
108  KeReleaseSpinLock(&Process->HyperSpaceLock, OldIrql);
109 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
PVOID ULONG Address
Definition: oprghdlr.h:14
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define MiAddressToPte(x)
Definition: mmx86.c:19
#define PsGetCurrentProcess
Definition: psfuncs.h:17
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
VOID NTAPI MiUnmapPagesInZeroSpace ( IN PVOID  VirtualAddress,
IN PFN_NUMBER  NumberOfPages 
)

Definition at line 185 of file hypermap.c.

Referenced by MmZeroPageThread().

187 {
188  PMMPTE PointerPte;
189 
190  //
191  // Sanity checks
192  //
194  ASSERT (NumberOfPages != 0);
195  ASSERT (NumberOfPages <= (MI_ZERO_PTES - 1));
196 
197  //
198  // Get the first PTE for the mapped zero VA
199  //
200  PointerPte = MiAddressToPte(VirtualAddress);
201 
202  //
203  // Blow away the mapped zero PTEs
204  //
205  RtlZeroMemory(PointerPte, NumberOfPages * sizeof(MMPTE));
206 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define MiAddressToPte(x)
Definition: mmx86.c:19
_In_ ULONG _In_ BOOLEAN _Must_inspect_result_ PVOID * VirtualAddress
Definition: ndis.h:3773
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MI_ZERO_PTES
Definition: mm.h:78
NTSTATUS NTAPI MmAccessFault ( IN ULONG  FaultCode,
IN PVOID  Address,
IN KPROCESSOR_MODE  Mode,
IN PVOID  TrapInformation 
)

Definition at line 204 of file mmfault.c.

Referenced by KiDataAbortHandler(), KiPageFaultHandler(), KiTrap0EHandler(), MiLockVirtualMemory(), MiMakeSystemAddressValid(), MiMakeSystemAddressValidPfn(), and MmProbeAndLockPages().

208 {
210 
211  /* Cute little hack for ROS */
213  {
214 #ifdef _M_IX86
215  /* Check for an invalid page directory in kernel mode */
217  {
218  /* All is well with the world */
219  return STATUS_SUCCESS;
220  }
221 #endif
222  }
223 
224  /* Handle shared user page, which doesn't have a VAD / MemoryArea */
226  {
227  /* This is an ARM3 fault */
228  DPRINT("ARM3 fault %p\n", MemoryArea);
229  return MmArmAccessFault(FaultCode, Address, Mode, TrapInformation);
230  }
231 
232  /* Is there a ReactOS address space yet? */
234  {
235  /* Check if this is an ARM3 memory area */
237  if (!(MemoryArea) && (Address <= MM_HIGHEST_USER_ADDRESS))
238  {
239  /* Could this be a VAD fault from user-mode? */
241  }
242  }
243 
244  /* Is this an ARM3 memory area, or is there no address space yet? */
245  if (((MemoryArea) && (MemoryArea->Type == MEMORY_AREA_OWNED_BY_ARM3)) ||
246  (!(MemoryArea) && ((ULONG_PTR)Address >= (ULONG_PTR)MmPagedPoolStart)) ||
248  {
249  /* This is an ARM3 fault */
250  DPRINT("ARM3 fault %p\n", MemoryArea);
251  return MmArmAccessFault(FaultCode, Address, Mode, TrapInformation);
252  }
253 
254  /* Keep same old ReactOS Behaviour */
255  if (!MI_IS_NOT_PRESENT_FAULT(FaultCode))
256  {
257  /* Call access fault */
258  return MmpAccessFault(Mode, (ULONG_PTR)Address, TrapInformation ? FALSE : TRUE);
259  }
260  else
261  {
262  /* Call not present */
263  return MmNotPresentFault(Mode, (ULONG_PTR)Address, TrapInformation ? FALSE : TRUE);
264  }
265 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define MM_HIGHEST_USER_ADDRESS
Definition: armddk.h:17
#define TRUE
Definition: types.h:120
PVOID ULONG Address
Definition: oprghdlr.h:14
#define MI_IS_NOT_PRESENT_FAULT(FaultCode)
Definition: mm.h:117
ULONG Type
Definition: mm.h:214
_In_ ULONG Mode
Definition: hubbusif.h:303
#define MM_SHARED_USER_DATA_VA
Definition: mmtypes.h:48
PMEMORY_AREA NTAPI MmLocateMemoryAreaByAddress(PMMSUPPORT AddressSpace, PVOID Address)
Definition: marea.c:60
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define MEMORY_AREA_OWNED_BY_ARM3
Definition: mm.h:73
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI MmpAccessFault(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
Definition: mmfault.c:23
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define PAGE_ALIGN(Va)
BOOLEAN Mmi386MakeKernelPageTableGlobal(PVOID Address)
Definition: page.c:476
PVOID MmPagedPoolStart
Definition: miarm.h:554
FORCEINLINE PMMSUPPORT MmGetKernelAddressSpace(VOID)
Definition: mm.h:1432
NTSTATUS NTAPI MmNotPresentFault(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
Definition: mmfault.c:110
NTSTATUS NTAPI MmArmAccessFault(IN ULONG FaultCode, IN PVOID Address, IN KPROCESSOR_MODE Mode, IN PVOID TrapInformation)
Definition: pagfault.c:1629
return STATUS_SUCCESS
Definition: btrfs.c:2710
#define MmSystemRangeStart
Definition: mm.h:31
FORCEINLINE PMMSUPPORT MmGetCurrentAddressSpace(VOID)
Definition: mm.h:1425
NTSTATUS NTAPI MmAccessFaultSectionView ( PMMSUPPORT  AddressSpace,
MEMORY_AREA MemoryArea,
PVOID  Address 
)

Definition at line 1690 of file section.c.

Referenced by MmpAccessFault().

1693 {
1695  PROS_SECTION_OBJECT Section;
1696  PFN_NUMBER OldPage;
1697  PFN_NUMBER NewPage;
1698  NTSTATUS Status;
1699  PVOID PAddress;
1702  ULONG_PTR Entry;
1703  PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
1704 
1705  DPRINT("MmAccessFaultSectionView(%p, %p, %p)\n", AddressSpace, MemoryArea, Address);
1706 
1707  /* Make sure we have a page mapping for this address. */
1708  Status = MmNotPresentFaultSectionView(AddressSpace, MemoryArea, Address, TRUE);
1709  if (!NT_SUCCESS(Status))
1710  {
1711  /* This is invalid access ! */
1712  return Status;
1713  }
1714 
1715  /*
1716  * Check if the page has already been set readwrite
1717  */
1718  if (MmGetPageProtect(Process, Address) & PAGE_READWRITE)
1719  {
1720  DPRINT("Address 0x%p\n", Address);
1721  return(STATUS_SUCCESS);
1722  }
1723 
1724  /*
1725  * Find the offset of the page
1726  */
1727  PAddress = MM_ROUND_DOWN(Address, PAGE_SIZE);
1728  Offset.QuadPart = (ULONG_PTR)PAddress - MA_GetStartingAddress(MemoryArea)
1729  + MemoryArea->Data.SectionData.ViewOffset.QuadPart;
1730 
1731  Segment = MemoryArea->Data.SectionData.Segment;
1732  Section = MemoryArea->Data.SectionData.Section;
1733  Region = MmFindRegion((PVOID)MA_GetStartingAddress(MemoryArea),
1734  &MemoryArea->Data.SectionData.RegionListHead,
1735  Address, NULL);
1736  ASSERT(Region != NULL);
1737 
1738  /*
1739  * Check if we are doing COW
1740  */
1741  if (!((Segment->WriteCopy) &&
1742  (Region->Protect == PAGE_READWRITE ||
1743  Region->Protect == PAGE_EXECUTE_READWRITE)))
1744  {
1745  DPRINT("Address 0x%p\n", Address);
1746  return(STATUS_ACCESS_VIOLATION);
1747  }
1748 
1749  /* Get the page mapping this section offset. */
1750  MmLockSectionSegment(Segment);
1751  Entry = MmGetPageEntrySectionSegment(Segment, &Offset);
1752 
1753  /* Get the current page mapping for the process */
1754  ASSERT(MmIsPagePresent(Process, PAddress));
1755  OldPage = MmGetPfnForProcess(Process, PAddress);
1756  ASSERT(OldPage != 0);
1757 
1758  if (IS_SWAP_FROM_SSE(Entry) ||
1759  PFN_FROM_SSE(Entry) != OldPage)
1760  {
1761  MmUnlockSectionSegment(Segment);
1762  /* This is a private page. We must only change the page protection. */
1763  MmSetPageProtect(Process, PAddress, Region->Protect);
1764  return(STATUS_SUCCESS);
1765  }
1766 
1767  /*
1768  * Allocate a page
1769  */
1771  if (Process) MI_SET_PROCESS2(Process->ImageFileName);
1772  if (!Process) MI_SET_PROCESS2("Kernel Section");
1773  Status = MmRequestPageMemoryConsumer(MC_USER, TRUE, &NewPage);
1774  if (!NT_SUCCESS(Status))
1775  {
1776  KeBugCheck(MEMORY_MANAGEMENT);
1777  }
1778 
1779  /*
1780  * Copy the old page
1781  */
1782  NT_VERIFY(NT_SUCCESS(MiCopyFromUserPage(NewPage, PAddress)));
1783 
1784  /*
1785  * Unshare the old page.
1786  */
1787  DPRINT("Swapping page (Old %x New %x)\n", OldPage, NewPage);
1788  MmDeleteVirtualMapping(Process, PAddress, NULL, NULL);
1789  MmDeleteRmap(OldPage, Process, PAddress);
1790  MmUnsharePageEntrySectionSegment(Section, Segment, &Offset, FALSE, FALSE, NULL);
1791  MmUnlockSectionSegment(Segment);
1792 
1793  /*
1794  * Set the PTE to point to the new page
1795  */
1796  Status = MmCreateVirtualMapping(Process,
1797  PAddress,
1798  Region->Protect,
1799  &NewPage,
1800  1);
1801  if (!NT_SUCCESS(Status))
1802  {
1803  DPRINT1("MmCreateVirtualMapping failed, unable to create virtual mapping, not out of memory\n");
1804  KeBugCheck(MEMORY_MANAGEMENT);
1805  return(Status);
1806  }
1807  MmInsertRmap(NewPage, Process, PAddress);
1808 
1809  MiSetPageEvent(Process, Address);
1810  DPRINT("Address 0x%p\n", Address);
1811  return(STATUS_SUCCESS);
1812 }
DWORD *typedef PVOID
Definition: winlogon.h:61
PMM_REGION NTAPI MmFindRegion(PVOID BaseAddress, PLIST_ENTRY RegionListHead, PVOID Address, PVOID *RegionBaseAddress)
Definition: region.c:257
BOOLEAN WriteCopy
Definition: mm.h:170
#define TRUE
Definition: types.h:120
PVOID ULONG Address
Definition: oprghdlr.h:14
VOID NTAPI MmInsertRmap(PFN_NUMBER Page, struct _EPROCESS *Process, PVOID Address)
#define MiSetPageEvent(Process, Address)
Definition: newmm.h:43
struct _Entry Entry
Definition: kefuncs.h:640
#define PFN_FROM_SSE(E)
Definition: newmm.h:7
NTSTATUS NTAPI MmCreateVirtualMapping(struct _EPROCESS *Process, PVOID Address, ULONG flProtect, PPFN_NUMBER Pages, ULONG PageCount)
ULONG NTAPI MmGetPageProtect(struct _EPROCESS *Process, PVOID Address)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define MC_USER
Definition: mm.h:94
VOID NTAPI MmDeleteRmap(PFN_NUMBER Page, struct _EPROCESS *Process, PVOID Address)
Definition: mm.h:390