1998-08-25 04:27:41 +00:00
|
|
|
/*
|
|
|
|
* Higher level memory managment definitions
|
|
|
|
*/
|
|
|
|
|
1998-09-05 17:34:23 +00:00
|
|
|
#ifndef __INCLUDE_INTERNAL_MM_H
|
|
|
|
#define __INCLUDE_INTERNAL_MM_H
|
1998-08-25 04:27:41 +00:00
|
|
|
|
|
|
|
#include <internal/linkage.h>
|
1998-09-05 17:34:23 +00:00
|
|
|
#include <internal/ntoskrnl.h>
|
1998-08-25 04:27:41 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
1998-09-05 17:34:23 +00:00
|
|
|
/* TYPES *********************************************************************/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MEMORY_AREA_INVALID,
|
1998-10-05 04:01:30 +00:00
|
|
|
MEMORY_AREA_SECTION_VIEW_COMMIT,
|
1998-09-05 17:34:23 +00:00
|
|
|
MEMORY_AREA_CONTINUOUS_MEMORY,
|
|
|
|
MEMORY_AREA_NO_CACHE,
|
|
|
|
MEMORY_AREA_IO_MAPPING,
|
|
|
|
MEMORY_AREA_SYSTEM,
|
|
|
|
MEMORY_AREA_MDL_MAPPING,
|
1998-10-05 04:01:30 +00:00
|
|
|
MEMORY_AREA_COMMIT,
|
|
|
|
MEMORY_AREA_RESERVE,
|
|
|
|
MEMORY_AREA_SECTION_VIEW_RESERVE,
|
1999-04-05 15:04:46 +00:00
|
|
|
MEMORY_AREA_CACHE_SEGMENT,
|
1998-09-05 17:34:23 +00:00
|
|
|
};
|
|
|
|
|
2000-04-03 21:54:42 +00:00
|
|
|
#define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) ((x) / (4*1024*1024))
|
|
|
|
#define PAGE_TO_SECTION_PAGE_TABLE_OFFSET(x) (((x) % 4*1024*1024) / (4*1024))
|
|
|
|
|
|
|
|
#define NR_SECTION_PAGE_TABLES (1024)
|
|
|
|
#define NR_SECTION_PAGE_ENTRIES (1024)
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
PVOID Pages[NR_SECTION_PAGE_ENTRIES];
|
|
|
|
} SECTION_PAGE_TABLE, *PSECTION_PAGE_TABLE;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
PSECTION_PAGE_TABLE PageTables[NR_SECTION_PAGE_TABLES];
|
|
|
|
} SECTION_PAGE_DIRECTORY, *PSECTION_PAGE_DIRECTORY;
|
|
|
|
|
1998-09-05 17:34:23 +00:00
|
|
|
typedef struct
|
1998-08-25 04:27:41 +00:00
|
|
|
{
|
1998-09-13 15:55:55 +00:00
|
|
|
CSHORT Type;
|
|
|
|
CSHORT Size;
|
1998-10-05 04:01:30 +00:00
|
|
|
LARGE_INTEGER MaximumSize;
|
|
|
|
ULONG SectionPageProtection;
|
|
|
|
ULONG AllocateAttributes;
|
|
|
|
PFILE_OBJECT FileObject;
|
1999-11-24 11:51:55 +00:00
|
|
|
LIST_ENTRY ViewListHead;
|
|
|
|
KSPIN_LOCK ViewListLock;
|
2000-04-03 21:54:42 +00:00
|
|
|
KMUTEX Lock;
|
|
|
|
SECTION_PAGE_DIRECTORY PageDirectory;
|
1998-10-05 04:01:30 +00:00
|
|
|
} SECTION_OBJECT, *PSECTION_OBJECT;
|
1998-08-25 04:27:41 +00:00
|
|
|
|
1998-09-05 17:34:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
ULONG Type;
|
1998-10-05 04:01:30 +00:00
|
|
|
PVOID BaseAddress;
|
1998-09-05 17:34:23 +00:00
|
|
|
ULONG Length;
|
|
|
|
ULONG Attributes;
|
|
|
|
LIST_ENTRY Entry;
|
1998-09-13 15:55:55 +00:00
|
|
|
ULONG LockCount;
|
1999-11-24 11:51:55 +00:00
|
|
|
PEPROCESS Process;
|
1998-09-05 17:34:23 +00:00
|
|
|
union
|
|
|
|
{
|
1998-09-13 15:55:55 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
SECTION_OBJECT* Section;
|
|
|
|
ULONG ViewOffset;
|
1999-11-24 11:51:55 +00:00
|
|
|
LIST_ENTRY ViewListEntry;
|
1998-09-13 15:55:55 +00:00
|
|
|
} SectionData;
|
|
|
|
} Data;
|
1998-10-05 04:01:30 +00:00
|
|
|
} MEMORY_AREA, *PMEMORY_AREA;
|
1998-09-05 17:34:23 +00:00
|
|
|
|
|
|
|
|
2000-03-19 09:14:52 +00:00
|
|
|
/* FUNCTIONS */
|
|
|
|
|
2000-03-29 13:11:55 +00:00
|
|
|
VOID MmLockAddressSpace(PMADDRESS_SPACE AddressSpace);
|
|
|
|
VOID MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace);
|
|
|
|
VOID MmInitializeKernelAddressSpace(VOID);
|
|
|
|
PMADDRESS_SPACE MmGetCurrentAddressSpace(VOID);
|
|
|
|
PMADDRESS_SPACE MmGetKernelAddressSpace(VOID);
|
2000-04-07 02:24:03 +00:00
|
|
|
NTSTATUS MmInitializeAddressSpace(PEPROCESS Process,
|
|
|
|
PMADDRESS_SPACE AddressSpace);
|
2000-03-29 13:11:55 +00:00
|
|
|
NTSTATUS MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace);
|
|
|
|
PVOID STDCALL MmAllocateSection (IN ULONG Length);
|
|
|
|
NTSTATUS MmCreateMemoryArea(PEPROCESS Process,
|
|
|
|
PMADDRESS_SPACE AddressSpace,
|
1998-09-05 17:34:23 +00:00
|
|
|
ULONG Type,
|
1998-10-05 04:01:30 +00:00
|
|
|
PVOID* BaseAddress,
|
1998-09-05 17:34:23 +00:00
|
|
|
ULONG Length,
|
|
|
|
ULONG Attributes,
|
|
|
|
MEMORY_AREA** Result);
|
2000-03-29 13:11:55 +00:00
|
|
|
MEMORY_AREA* MmOpenMemoryAreaByAddress(PMADDRESS_SPACE AddressSpace,
|
|
|
|
PVOID Address);
|
1998-09-05 17:34:23 +00:00
|
|
|
NTSTATUS MmInitMemoryAreas(VOID);
|
|
|
|
VOID ExInitNonPagedPool(ULONG BaseAddress);
|
2000-03-29 13:11:55 +00:00
|
|
|
NTSTATUS MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
|
1998-10-05 04:01:30 +00:00
|
|
|
PVOID BaseAddress,
|
1998-09-05 17:34:23 +00:00
|
|
|
ULONG Length,
|
|
|
|
BOOLEAN FreePages);
|
1998-10-05 04:01:30 +00:00
|
|
|
VOID MmDumpMemoryAreas(PLIST_ENTRY ListHead);
|
|
|
|
NTSTATUS MmLockMemoryArea(MEMORY_AREA* MemoryArea);
|
|
|
|
NTSTATUS MmUnlockMemoryArea(MEMORY_AREA* MemoryArea);
|
|
|
|
NTSTATUS MmInitSectionImplementation(VOID);
|
|
|
|
|
2000-03-19 09:14:52 +00:00
|
|
|
/*void VirtualInit(boot_param* bp);*/
|
1998-08-25 04:27:41 +00:00
|
|
|
|
1998-10-05 04:01:30 +00:00
|
|
|
#define MM_LOWEST_USER_ADDRESS (4096)
|
|
|
|
|
|
|
|
PMEMORY_AREA MmSplitMemoryArea(PEPROCESS Process,
|
2000-03-29 13:11:55 +00:00
|
|
|
PMADDRESS_SPACE AddressSpace,
|
1998-10-05 04:01:30 +00:00
|
|
|
PMEMORY_AREA OriginalMemoryArea,
|
|
|
|
PVOID BaseAddress,
|
|
|
|
ULONG Length,
|
|
|
|
ULONG NewType,
|
|
|
|
ULONG NewAttributes);
|
1999-03-31 10:59:32 +00:00
|
|
|
PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
|
|
|
|
PVOID LastPhysKernelAddress,
|
|
|
|
ULONG MemorySizeInPages,
|
|
|
|
ULONG LastKernelBase);
|
|
|
|
|
|
|
|
PVOID MmAllocPage(VOID);
|
1999-12-20 02:14:40 +00:00
|
|
|
VOID MmDereferencePage(PVOID PhysicalAddress);
|
|
|
|
VOID MmReferencePage(PVOID PhysicalAddress);
|
1999-03-31 10:59:32 +00:00
|
|
|
VOID MmDeletePageTable(PEPROCESS Process, PVOID Address);
|
1999-04-01 12:39:43 +00:00
|
|
|
NTSTATUS MmCopyMmInfo(PEPROCESS Src, PEPROCESS Dest);
|
|
|
|
NTSTATUS MmReleaseMmInfo(PEPROCESS Process);
|
1999-04-14 00:52:19 +00:00
|
|
|
NTSTATUS Mmi386ReleaseMmInfo(PEPROCESS Process);
|
|
|
|
VOID MmDeletePageEntry(PEPROCESS Process, PVOID Address, BOOL FreePage);
|
1999-12-02 20:53:55 +00:00
|
|
|
|
1999-11-12 12:01:17 +00:00
|
|
|
VOID MmBuildMdlFromPages(PMDL Mdl);
|
|
|
|
PVOID MmGetMdlPageAddress(PMDL Mdl, PVOID Offset);
|
1999-11-24 11:51:55 +00:00
|
|
|
VOID MiShutdownMemoryManager(VOID);
|
|
|
|
ULONG MmGetPhysicalAddressForProcess(PEPROCESS Process,
|
|
|
|
PVOID Address);
|
2000-04-02 13:32:43 +00:00
|
|
|
NTSTATUS STDCALL MmUnmapViewOfSection(PEPROCESS Process,
|
1999-11-24 11:51:55 +00:00
|
|
|
PMEMORY_AREA MemoryArea);
|
|
|
|
PVOID MiTryToSharePageInSection(PSECTION_OBJECT Section, ULONG Offset);
|
1999-04-14 00:52:19 +00:00
|
|
|
|
1999-11-25 10:47:58 +00:00
|
|
|
NTSTATUS MmSafeCopyFromUser(PVOID Dest, PVOID Src, ULONG NumberOfBytes);
|
|
|
|
NTSTATUS MmSafeCopyToUser(PVOID Dest, PVOID Src, ULONG NumberOfBytes);
|
1999-12-10 17:04:37 +00:00
|
|
|
VOID MmInitPagingFile(VOID);
|
1999-11-25 10:47:58 +00:00
|
|
|
|
2000-04-02 13:32:43 +00:00
|
|
|
/* FIXME: it should be in ddk/mmfuncs.h */
|
|
|
|
NTSTATUS
|
|
|
|
STDCALL
|
|
|
|
MmCreateSection (
|
|
|
|
OUT PSECTION_OBJECT * SectionObject,
|
|
|
|
IN ACCESS_MASK DesiredAccess,
|
|
|
|
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
|
|
|
|
IN PLARGE_INTEGER MaximumSize,
|
|
|
|
IN ULONG SectionPageProtection,
|
|
|
|
IN ULONG AllocationAttributes,
|
|
|
|
IN HANDLE FileHandle OPTIONAL,
|
|
|
|
IN PFILE_OBJECT File OPTIONAL
|
|
|
|
);
|
|
|
|
|
2000-04-07 02:24:03 +00:00
|
|
|
NTSTATUS MmPageFault(ULONG Cs,
|
|
|
|
PULONG Eip,
|
|
|
|
PULONG Eax,
|
|
|
|
ULONG Cr2,
|
|
|
|
ULONG ErrorCode);
|
|
|
|
|
|
|
|
NTSTATUS MmAccessFault(KPROCESSOR_MODE Mode,
|
|
|
|
ULONG Address);
|
|
|
|
NTSTATUS MmNotPresentFault(KPROCESSOR_MODE Mode,
|
|
|
|
ULONG Address);
|
|
|
|
|
1998-08-25 04:27:41 +00:00
|
|
|
#endif
|