ReactOS  0.4.15-dev-1374-g8d3e80e
procsup.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
#include <mm/ARM3/miarm.h>
Include dependency graph for procsup.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define MODULE_INVOLVED_IN_ARM3
 

Functions

NTSTATUS NTAPI MiCreatePebOrTeb (IN PEPROCESS Process, IN ULONG Size, OUT PULONG_PTR BaseAddress)
 
VOID NTAPI MmDeleteTeb (IN PEPROCESS Process, IN PTEB Teb)
 
VOID NTAPI MmDeleteKernelStack (IN PVOID StackBase, IN BOOLEAN GuiStack)
 
PVOID NTAPI MmCreateKernelStack (IN BOOLEAN GuiStack, IN UCHAR Node)
 
NTSTATUS NTAPI MmGrowKernelStackEx (IN PVOID StackPointer, IN ULONG GrowSize)
 
NTSTATUS NTAPI MmGrowKernelStack (IN PVOID StackPointer)
 
NTSTATUS NTAPI MmSetMemoryPriorityProcess (IN PEPROCESS Process, IN UCHAR MemoryPriority)
 
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 MiInitializeWorkingSetList (IN PEPROCESS CurrentProcess)
 
NTSTATUS NTAPI MmInitializeProcessAddressSpace (IN PEPROCESS Process, IN PEPROCESS ProcessClone OPTIONAL, IN PVOID Section OPTIONAL, IN OUT PULONG Flags, IN POBJECT_NAME_INFORMATION *AuditName OPTIONAL)
 
NTSTATUS NTAPI MmInitializeHandBuiltProcess (IN PEPROCESS Process, IN PULONG_PTR DirectoryTableBase)
 
NTSTATUS NTAPI MmInitializeHandBuiltProcess2 (IN PEPROCESS Process)
 
VOID NTAPI MmCleanProcessAddressSpace (IN PEPROCESS Process)
 
VOID NTAPI MmDeleteProcessAddressSpace2 (IN PEPROCESS Process)
 
NTSTATUS NTAPI NtAllocateUserPhysicalPages (IN HANDLE ProcessHandle, IN OUT PULONG_PTR NumberOfPages, IN OUT PULONG_PTR UserPfnArray)
 
NTSTATUS NTAPI NtMapUserPhysicalPages (IN PVOID VirtualAddresses, IN ULONG_PTR NumberOfPages, IN OUT PULONG_PTR UserPfnArray)
 
NTSTATUS NTAPI NtMapUserPhysicalPagesScatter (IN PVOID *VirtualAddresses, IN ULONG_PTR NumberOfPages, IN OUT PULONG_PTR UserPfnArray)
 
NTSTATUS NTAPI NtFreeUserPhysicalPages (IN HANDLE ProcessHandle, IN OUT PULONG_PTR NumberOfPages, IN OUT PULONG_PTR UserPfnArray)
 

Variables

ULONG MmProcessColorSeed = 0x12345678
 
PMMWSL MmWorkingSetList
 
ULONG MmMaximumDeadKernelStacks = 5
 
SLIST_HEADER MmDeadStackSListHead
 

Macro Definition Documentation

◆ MODULE_INVOLVED_IN_ARM3

#define MODULE_INVOLVED_IN_ARM3

Definition at line 15 of file procsup.c.

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file procsup.c.

Function Documentation

◆ MiCreatePebOrTeb()

NTSTATUS NTAPI MiCreatePebOrTeb ( IN PEPROCESS  Process,
IN ULONG  Size,
OUT PULONG_PTR  BaseAddress 
)

Definition at line 29 of file procsup.c.

32 {
33  PMMVAD_LONG Vad;
35  ULONG_PTR HighestAddress, RandomBase;
36  ULONG AlignedSize;
37  LARGE_INTEGER CurrentTime;
38 
39  /* Allocate a VAD */
40  Vad = ExAllocatePoolWithTag(NonPagedPool, sizeof(MMVAD_LONG), 'ldaV');
41  if (!Vad) return STATUS_NO_MEMORY;
42 
43  /* Setup the primary flags with the size, and make it commited, private, RW */
44  Vad->u.LongFlags = 0;
46  Vad->u.VadFlags.MemCommit = TRUE;
49  Vad->u.VadFlags.NoChange = TRUE;
50  Vad->u1.Parent = NULL;
51 
52  /* Setup the secondary flags to make it a secured, writable, long VAD */
53  Vad->u2.LongFlags2 = 0;
54  Vad->u2.VadFlags2.OneSecured = TRUE;
55  Vad->u2.VadFlags2.LongVad = TRUE;
56  Vad->u2.VadFlags2.ReadOnly = FALSE;
57 
58  Vad->ControlArea = NULL; // For Memory-Area hack
59  Vad->FirstPrototypePte = NULL;
60 
61  /* Check if this is a PEB creation */
62  ASSERT(sizeof(TEB) != sizeof(PEB));
63  if (Size == sizeof(PEB))
64  {
65  /* Create a random value to select one page in a 64k region */
66  KeQueryTickCount(&CurrentTime);
67  CurrentTime.LowPart &= (_64K / PAGE_SIZE) - 1;
68 
69  /* Calculate a random base address */
70  RandomBase = (ULONG_PTR)MM_HIGHEST_VAD_ADDRESS + 1;
71  RandomBase -= CurrentTime.LowPart << PAGE_SHIFT;
72 
73  /* Make sure the base address is not too high */
74  AlignedSize = ROUND_TO_PAGES(Size);
75  if ((RandomBase + AlignedSize) > (ULONG_PTR)MM_HIGHEST_VAD_ADDRESS + 1)
76  {
77  RandomBase = (ULONG_PTR)MM_HIGHEST_VAD_ADDRESS + 1 - AlignedSize;
78  }
79 
80  /* Calculate the highest allowed address */
81  HighestAddress = RandomBase + AlignedSize - 1;
82  }
83  else
84  {
85  HighestAddress = (ULONG_PTR)MM_HIGHEST_VAD_ADDRESS;
86  }
87 
88  *BaseAddress = 0;
91  Size,
92  HighestAddress,
93  PAGE_SIZE,
94  MEM_TOP_DOWN);
95  if (!NT_SUCCESS(Status))
96  {
97  ExFreePoolWithTag(Vad, 'ldaV');
98  return STATUS_NO_MEMORY;
99  }
100 
101  /* Success */
102  return STATUS_SUCCESS;
103 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
union _MMVAD_LONG::@2576 u2
union _MMVAD_LONG::@2574 u1
ULONG ReadOnly
Definition: mmtypes.h:720
PMMVAD Parent
Definition: mmtypes.h:764
ULONG OneSecured
Definition: mmtypes.h:718
#define TRUE
Definition: types.h:120
MMVAD_FLAGS VadFlags
Definition: mmtypes.h:773
ULONG_PTR CommitCharge
Definition: mmtypes.h:701
LONG NTSTATUS
Definition: precomp.h:26
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
PCONTROL_AREA ControlArea
Definition: mmtypes.h:775
ULONG_PTR Protection
Definition: mmtypes.h:706
ULONG LongVad
Definition: mmtypes.h:721
ULONG_PTR LongFlags
Definition: mmtypes.h:772
ULONG_PTR NoChange
Definition: mmtypes.h:703
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
ULONG LongFlags2
Definition: mmtypes.h:780
VOID NTAPI KeQueryTickCount(IN PLARGE_INTEGER TickCount)
Definition: clock.c:165
ULONG_PTR MemCommit
Definition: mmtypes.h:705
Status
Definition: gdiplustypes.h:24
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
ULONG_PTR PrivateMemory
Definition: mmtypes.h:708
NTSTATUS NTAPI MiInsertVadEx(_Inout_ PMMVAD Vad, _In_ ULONG_PTR *BaseAddress, _In_ SIZE_T ViewSize, _In_ ULONG_PTR HighestAddress, _In_ ULONG_PTR Alignment, _In_ ULONG AllocationType)
Definition: vadnode.c:204
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
union _MMVAD_LONG::@2575 u
MMVAD_FLAGS2 VadFlags2
Definition: mmtypes.h:781
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define BYTES_TO_PAGES(Size)
#define MM_READWRITE
Definition: inbv.c:12
ULONG LowPart
Definition: typedefs.h:106
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define _64K
Definition: miarm.h:19
Definition: compat.h:694
#define ROUND_TO_PAGES(Size)
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
#define MM_HIGHEST_VAD_ADDRESS
Definition: mm.h:46
unsigned int ULONG
Definition: retypes.h:1
PMMPTE FirstPrototypePte
Definition: mmtypes.h:776
#define ULONG_PTR
Definition: config.h:101
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define MEM_TOP_DOWN
Definition: nt_native.h:1321

Referenced by MmCreatePeb(), and MmCreateTeb().

◆ MiInitializeWorkingSetList()

VOID NTAPI MiInitializeWorkingSetList ( IN PEPROCESS  CurrentProcess)

Definition at line 901 of file procsup.c.

902 {
903  PMMPFN Pfn1;
904  PMMPTE sysPte;
905  MMPTE tempPte;
906 
907  /* Setup some bogus list data */
908  MmWorkingSetList->LastEntry = CurrentProcess->Vm.MinimumWorkingSetSize;
912  MmWorkingSetList->Wsle = (PVOID)(ULONG_PTR)0xDEADBABEDEADBABEULL;
914  MmWorkingSetList->HashTableStart = (PVOID)(ULONG_PTR)0xBADAB00BBADAB00BULL;
920 
921  /* The rule is that the owner process is always in the FLINK of the PDE's PFN entry */
922  Pfn1 = MiGetPfnEntry(CurrentProcess->Pcb.DirectoryTableBase[0] >> PAGE_SHIFT);
923  ASSERT(Pfn1->u4.PteFrame == MiGetPfnEntryIndex(Pfn1));
924  Pfn1->u1.Event = (PKEVENT)CurrentProcess;
925 
926  /* Map the process working set in kernel space */
927  sysPte = MiReserveSystemPtes(1, SystemPteSpace);
928  MI_MAKE_HARDWARE_PTE_KERNEL(&tempPte, sysPte, MM_READWRITE, CurrentProcess->WorkingSetPage);
929  MI_WRITE_VALID_PTE(sysPte, tempPte);
930  CurrentProcess->Vm.VmWorkingSetList = MiPteToAddress(sysPte);
931 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
struct _KEVENT * PKEVENT
PVOID HashTableStart
Definition: mmtypes.h:875
PMMPTE NTAPI MiReserveSystemPtes(IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:246
ULONG FirstDynamic
Definition: mmtypes.h:866
PVOID HighestPermittedHashAddress
Definition: mmtypes.h:876
uint32_t ULONG_PTR
Definition: typedefs.h:65
union _MMPFN::@1784 u1
FORCEINLINE VOID MI_WRITE_VALID_PTE(IN PMMPTE PointerPte, IN MMPTE TempPte)
Definition: miarm.h:942
PKEVENT Event
Definition: mm.h:317
ULONG NextSlot
Definition: mmtypes.h:868
void * PVOID
Definition: retypes.h:9
#define ULL(a, b)
Definition: format_msg.c:27
ULONG CurrentProcess
Definition: shell.c:125
#define ASSERT(a)
Definition: mode.c:45
ULONG LastInitializedWsle
Definition: mmtypes.h:870
PMMWSLE Wsle
Definition: mmtypes.h:869
PMMWSLE_HASH HashTable
Definition: mmtypes.h:872
#define MM_READWRITE
Definition: inbv.c:12
Definition: mm.h:311
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:939
ULONG HashTableSize
Definition: mmtypes.h:873
ULONG_PTR PteFrame
Definition: mm.h:356
ULONG NumberOfImageWaiters
Definition: mmtypes.h:877
ULONG FirstFree
Definition: mmtypes.h:865
#define NULL
Definition: types.h:112
PMMWSL MmWorkingSetList
Definition: procsup.c:21
union _MMPFN::@1789 u4
FORCEINLINE PFN_NUMBER MiGetPfnEntryIndex(IN PMMPFN Pfn1)
Definition: mm.h:959
FORCEINLINE VOID MI_MAKE_HARDWARE_PTE_KERNEL(IN PMMPTE NewPte, IN PMMPTE MappingPte, IN ULONG_PTR ProtectionMask, IN PFN_NUMBER PageFrameNumber)
Definition: miarm.h:774
FORCEINLINE PVOID MiPteToAddress(PMMPTE PointerPte)
Definition: mm.h:201
ULONG LastEntry
Definition: mmtypes.h:867
ULONG VadBitMapHint
Definition: mmtypes.h:878

Referenced by MmInitializeProcessAddressSpace().

◆ MmCleanProcessAddressSpace()

VOID NTAPI MmCleanProcessAddressSpace ( IN PEPROCESS  Process)

Definition at line 1325 of file procsup.c.

1326 {
1327  PMMVAD Vad;
1328  PMM_AVL_TABLE VadTree;
1330 
1331  /* Only support this */
1332  ASSERT(Process->AddressSpaceInitialized == 2);
1333 
1334  /* Remove from the session */
1336 
1337  /* Lock the process address space from changes */
1340 
1341  /* VM is deleted now */
1342  Process->VmDeleted = TRUE;
1344 
1345  /* Enumerate the VADs */
1346  VadTree = &Process->VadRoot;
1347  while (VadTree->NumberGenericTableElements)
1348  {
1349  /* Grab the current VAD */
1350  Vad = (PMMVAD)VadTree->BalancedRoot.RightChild;
1351 
1352  /* Check for old-style memory areas */
1353  if (Vad->u.VadFlags.Spare == 1)
1354  {
1355  /* Let RosMm handle this */
1357  continue;
1358  }
1359 
1360  /* Lock the working set */
1362 
1363  /* Remove this VAD from the tree */
1364  ASSERT(VadTree->NumberGenericTableElements >= 1);
1365  MiRemoveNode((PMMADDRESS_NODE)Vad, VadTree);
1366 
1367  /* Only regular VADs supported for now */
1368  ASSERT(Vad->u.VadFlags.VadType == VadNone);
1369 
1370  /* Check if this is a section VAD */
1371  if (!(Vad->u.VadFlags.PrivateMemory) && (Vad->ControlArea))
1372  {
1373  /* Remove the view */
1375  }
1376  else
1377  {
1378  /* Delete the addresses */
1380  (Vad->EndingVpn << PAGE_SHIFT) | (PAGE_SIZE - 1),
1381  Vad);
1382 
1383  /* Release the working set */
1385  }
1386 
1387  /* Skip ARM3 fake VADs, they'll be freed by MmDeleteProcessAddresSpace */
1388  if (Vad->u.VadFlags.Spare == 1)
1389  {
1390  /* Set a flag so MmDeleteMemoryArea knows to free, but not to remove */
1391  Vad->u.VadFlags.Spare = 2;
1392  continue;
1393  }
1394 
1395  /* Free the VAD memory */
1396  ExFreePool(Vad);
1397  }
1398 
1399  /* Lock the working set */
1401  ASSERT(Process->CloneRoot == NULL);
1402  ASSERT(Process->PhysicalVadRoot == NULL);
1403 
1404  /* Delete the shared user data section */
1406 
1407  /* Release the working set */
1409 
1410  /* Release the address space */
1412 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
VOID NTAPI MiSessionRemoveProcess(VOID)
Definition: session.c:396
FORCEINLINE VOID MiUnlockProcessWorkingSetUnsafe(IN PEPROCESS Process, IN PETHREAD Thread)
Definition: miarm.h:1215
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define TRUE
Definition: types.h:120
FORCEINLINE VOID MmUnlockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1423
ULONG_PTR NumberGenericTableElements
Definition: mmtypes.h:678
VOID NTAPI MiRosCleanupMemoryArea(PEPROCESS Process, PMMVAD Vad)
Definition: marea.c:522
MMVAD_FLAGS VadFlags
Definition: mmtypes.h:744
MMADDRESS_NODE BalancedRoot
Definition: mmtypes.h:672
ULONG_PTR EndingVpn
Definition: mmtypes.h:740
PCONTROL_AREA ControlArea
Definition: mmtypes.h:746
#define USER_SHARED_DATA
Definition: pstypes.h:51
ULONG_PTR StartingVpn
Definition: mmtypes.h:739
FORCEINLINE VOID MiLockProcessWorkingSetUnsafe(IN PEPROCESS Process, IN PETHREAD Thread)
Definition: miarm.h:1145
ULONG_PTR PrivateMemory
Definition: mmtypes.h:708
#define ASSERT(a)
Definition: mode.c:45
if(!(yy_init))
Definition: macro.lex.yy.c:714
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
struct _MMADDRESS_NODE * RightChild
Definition: mmtypes.h:662
#define PAGE_SIZE
Definition: env_spec_w32.h:49
VOID NTAPI MiRemoveNode(IN PMMADDRESS_NODE Node, IN PMM_AVL_TABLE Table)
Definition: vadnode.c:360
VOID NTAPI MiDeleteVirtualAddresses(IN ULONG_PTR Va, IN ULONG_PTR EndingAddress, IN PMMVAD Vad)
Definition: virtual.c:540
union _MMVAD::@2572 u
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
ULONG_PTR Spare
Definition: mmtypes.h:707
VOID NTAPI MiRemoveMappedView(IN PEPROCESS CurrentProcess, IN PMMVAD Vad)
Definition: section.c:780
FORCEINLINE VOID MmLockAddressSpace(PMMSUPPORT AddressSpace)
Definition: mm.h:1416
struct _MMVAD * PMMVAD
ULONG_PTR VadType
Definition: mmtypes.h:704
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by PspExitProcess(), and PspExitThread().

◆ MmCreateKernelStack()

PVOID NTAPI MmCreateKernelStack ( IN BOOLEAN  GuiStack,
IN UCHAR  Node 
)

Definition at line 258 of file procsup.c.

260 {
261  PFN_COUNT StackPtes, StackPages;
262  PMMPTE PointerPte, StackPte;
264  MMPTE TempPte, InvalidPte;
265  KIRQL OldIrql;
266  PFN_NUMBER PageFrameIndex;
267  ULONG i;
268  PSLIST_ENTRY SListEntry;
269 
270  //
271  // Calculate pages needed
272  //
273  if (GuiStack)
274  {
275  //
276  // We'll allocate 64KB stack, but only commit 12K
277  //
278  StackPtes = BYTES_TO_PAGES(MmLargeStackSize);
280  }
281  else
282  {
283  //
284  // If the dead stack S-LIST has a stack on it, use it instead of allocating
285  // new system PTEs for this stack
286  //
288  {
290  if (SListEntry != NULL)
291  {
292  BaseAddress = (SListEntry + 1);
293  return BaseAddress;
294  }
295  }
296 
297  //
298  // We'll allocate 12K and that's it
299  //
300  StackPtes = BYTES_TO_PAGES(KERNEL_STACK_SIZE);
301  StackPages = StackPtes;
302  }
303 
304  //
305  // Reserve stack pages, plus a guard page
306  //
307  StackPte = MiReserveSystemPtes(StackPtes + 1, SystemPteSpace);
308  if (!StackPte) return NULL;
309 
310  //
311  // Get the stack address
312  //
313  BaseAddress = MiPteToAddress(StackPte + StackPtes + 1);
314 
315  //
316  // Select the right PTE address where we actually start committing pages
317  //
318  PointerPte = StackPte;
319  if (GuiStack) PointerPte += BYTES_TO_PAGES(MmLargeStackSize -
321 
322 
323  /* Setup the temporary invalid PTE */
324  MI_MAKE_SOFTWARE_PTE(&InvalidPte, MM_NOACCESS);
325 
326  /* Setup the template stack PTE */
327  MI_MAKE_HARDWARE_PTE_KERNEL(&TempPte, PointerPte + 1, MM_READWRITE, 0);
328 
329  //
330  // Acquire the PFN DB lock
331  //
333 
334  //
335  // Loop each stack page
336  //
337  for (i = 0; i < StackPages; i++)
338  {
339  //
340  // Next PTE
341  //
342  PointerPte++;
343 
344  /* Get a page and write the current invalid PTE */
346  MI_SET_PROCESS2(PsGetCurrentProcess()->ImageFileName);
347  PageFrameIndex = MiRemoveAnyPage(MI_GET_NEXT_COLOR());
348  MI_WRITE_INVALID_PTE(PointerPte, InvalidPte);
349 
350  /* Initialize the PFN entry for this page */
351  MiInitializePfn(PageFrameIndex, PointerPte, 1);
352 
353  /* Write the valid PTE */
354  TempPte.u.Hard.PageFrameNumber = PageFrameIndex;
355  MI_WRITE_VALID_PTE(PointerPte, TempPte);
356  }
357 
358  //
359  // Release the PFN lock
360  //
362 
363  //
364  // Return the stack address
365  //
366  return BaseAddress;
367 }
#define MI_MAKE_SOFTWARE_PTE(p, x)
Definition: miarm.h:185
VOID NTAPI MiInitializePfn(IN PFN_NUMBER PageFrameIndex, IN PMMPTE PointerPte, IN BOOLEAN Modified)
Definition: pfnlist.c:969
ULONG PFN_COUNT
Definition: mmtypes.h:102
PMMPTE NTAPI MiReserveSystemPtes(IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:246
#define MI_GET_NEXT_COLOR()
Definition: miarm.h:238
#define MM_NOACCESS
Definition: miarm.h:61
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:900
#define KERNEL_LARGE_STACK_COMMIT
ULONG MmLargeStackSize
Definition: mminit.c:262
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:907
SLIST_HEADER MmDeadStackSListHead
Definition: procsup.c:23
PSLIST_ENTRY WINAPI InterlockedPopEntrySList(PSLIST_HEADER ListHead)
Definition: interlocked.c:55
UCHAR KIRQL
Definition: env_spec_w32.h:591
ULONG PFN_NUMBER
Definition: ke.h:8
FORCEINLINE VOID MI_WRITE_VALID_PTE(IN PMMPTE PointerPte, IN MMPTE TempPte)
Definition: miarm.h:942
#define MI_SET_PROCESS2(x)
Definition: mm.h:260
#define PsGetCurrentProcess
Definition: psfuncs.h:17
#define MI_SET_USAGE(x)
Definition: mm.h:259
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
#define PSLIST_ENTRY
Definition: rtltypes.h:134
FORCEINLINE USHORT ExQueryDepthSList(_In_ PSLIST_HEADER SListHead)
Definition: exfuncs.h:153
#define KERNEL_STACK_SIZE
#define BYTES_TO_PAGES(Size)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define MM_READWRITE
Definition: inbv.c:12
PFN_NUMBER NTAPI MiRemoveAnyPage(IN ULONG Color)
Definition: pfnlist.c:475
FORCEINLINE VOID MI_WRITE_INVALID_PTE(IN PMMPTE PointerPte, IN MMPTE InvalidPte)
Definition: miarm.h:975
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
FORCEINLINE VOID MI_MAKE_HARDWARE_PTE_KERNEL(IN PMMPTE NewPte, IN PMMPTE MappingPte, IN ULONG_PTR ProtectionMask, IN PFN_NUMBER PageFrameNumber)
Definition: miarm.h:774
FORCEINLINE PVOID MiPteToAddress(PMMPTE PointerPte)
Definition: mm.h:201
ULONG PageFrameNumber
Definition: mmtypes.h:109

◆ MmCreatePeb()

NTSTATUS NTAPI MmCreatePeb ( IN PEPROCESS  Process,
IN PINITIAL_PEB  InitialPeb,
OUT PPEB BasePeb 
)

Definition at line 500 of file procsup.c.

503 {
504  PPEB Peb = NULL;
506  SIZE_T ViewSize = 0;
507  PVOID TableBase = NULL;
508  PIMAGE_NT_HEADERS NtHeaders;
509  PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigData;
511  USHORT Characteristics;
513  SectionOffset.QuadPart = (ULONGLONG)0;
514  *BasePeb = NULL;
515 
516  //
517  // Attach to Process
518  //
519  KeAttachProcess(&Process->Pcb);
520 
521  //
522  // Map NLS Tables
523  //
526  &TableBase,
527  0,
528  0,
529  &SectionOffset,
530  &ViewSize,
531  ViewShare,
532  MEM_TOP_DOWN,
533  PAGE_READONLY);
534  DPRINT("NLS Tables at: %p\n", TableBase);
535  if (!NT_SUCCESS(Status))
536  {
537  /* Cleanup and exit */
538  KeDetachProcess();
539  return Status;
540  }
541 
542  //
543  // Allocate the PEB
544  //
546  DPRINT("PEB at: %p\n", Peb);
547  if (!NT_SUCCESS(Status))
548  {
549  /* Cleanup and exit */
550  KeDetachProcess();
551  return Status;
552  }
553 
554  //
555  // Use SEH in case we can't load the PEB
556  //
557  _SEH2_TRY
558  {
559  //
560  // Initialize the PEB
561  //
562  RtlZeroMemory(Peb, sizeof(PEB));
563 
564  //
565  // Set up data
566  //
567  Peb->ImageBaseAddress = Process->SectionBaseAddress;
568  Peb->InheritedAddressSpace = InitialPeb->InheritedAddressSpace;
569  Peb->Mutant = InitialPeb->Mutant;
570  Peb->ImageUsesLargePages = InitialPeb->ImageUsesLargePages;
571 
572  //
573  // NLS
574  //
578 
579  //
580  // Default Version Data (could get changed below)
581  //
584  Peb->OSBuildNumber = (USHORT)(NtBuildNumber & 0x3FFF);
586  Peb->OSCSDVersion = (USHORT)CmNtCSDVersion;
587 
588  //
589  // Heap and Debug Data
590  //
592  Peb->BeingDebugged = (BOOLEAN)(Process->DebugPort != NULL);
600  Peb->MaximumNumberOfHeaps = (PAGE_SIZE - sizeof(PEB)) / sizeof(PVOID);
601  Peb->ProcessHeaps = (PVOID*)(Peb + 1);
602 
603  //
604  // Session ID
605  //
606  if (Process->Session) Peb->SessionId = MmGetSessionId(Process);
607  }
609  {
610  //
611  // Fail
612  //
613  KeDetachProcess();
615  }
616  _SEH2_END;
617 
618  //
619  // Use SEH in case we can't load the image
620  //
621  _SEH2_TRY
622  {
623  //
624  // Get NT Headers
625  //
626  NtHeaders = RtlImageNtHeader(Peb->ImageBaseAddress);
627  Characteristics = NtHeaders->FileHeader.Characteristics;
628  }
630  {
631  //
632  // Fail
633  //
634  KeDetachProcess();
636  }
637  _SEH2_END;
638 
639  //
640  // Parse the headers
641  //
642  if (NtHeaders)
643  {
644  //
645  // Use SEH in case we can't load the headers
646  //
647  _SEH2_TRY
648  {
649  //
650  // Get the Image Config Data too
651  //
653  TRUE,
655  (PULONG)&ViewSize);
656  if (ImageConfigData)
657  {
658  //
659  // Probe it
660  //
661  ProbeForRead(ImageConfigData,
663  sizeof(ULONG));
664  }
665 
666  //
667  // Write subsystem data
668  //
672 
673  //
674  // Check for version data
675  //
676  if (NtHeaders->OptionalHeader.Win32VersionValue)
677  {
678  //
679  // Extract values and write them
680  //
681  Peb->OSMajorVersion = NtHeaders->OptionalHeader.Win32VersionValue & 0xFF;
682  Peb->OSMinorVersion = (NtHeaders->OptionalHeader.Win32VersionValue >> 8) & 0xFF;
683  Peb->OSBuildNumber = (NtHeaders->OptionalHeader.Win32VersionValue >> 16) & 0x3FFF;
684  Peb->OSPlatformId = (NtHeaders->OptionalHeader.Win32VersionValue >> 30) ^ 2;
685 
686  /* Process CSD version override */
687  if ((ImageConfigData) && (ImageConfigData->CSDVersion))
688  {
689  /* Take the value from the image configuration directory */
690  Peb->OSCSDVersion = ImageConfigData->CSDVersion;
691  }
692  }
693 
694  /* Process optional process affinity mask override */
695  if ((ImageConfigData) && (ImageConfigData->ProcessAffinityMask))
696  {
697  /* Take the value from the image configuration directory */
698  ProcessAffinityMask = ImageConfigData->ProcessAffinityMask;
699  }
700 
701  //
702  // Check if this is a UP image
703  if (Characteristics & IMAGE_FILE_UP_SYSTEM_ONLY)
704  {
705  //
706  // Force it to use CPU 0
707  //
708  /* FIXME: this should use the MmRotatingUniprocessorNumber */
710  }
711  else
712  {
713  //
714  // Whatever was configured
715  //
717  }
718  }
720  {
721  //
722  // Fail
723  //
724  KeDetachProcess();
726  }
727  _SEH2_END;
728  }
729 
730  //
731  // Detach from the Process
732  //
733  KeDetachProcess();
734  *BasePeb = Peb;
735  return STATUS_SUCCESS;
736 }
ULONG ImageSubsystemMajorVersion
Definition: ntddk_ex.h:305
#define VER_PLATFORM_WIN32_NT
Definition: rtltypes.h:236
SIZE_T MmHeapDeCommitTotalFreeThreshold
Definition: mminit.c:368
PPEB Peb
Definition: dllmain.c:27
ULONG ImageProcessAffinityMask
Definition: ntddk_ex.h:307
ULONG OSPlatformId
Definition: ntddk_ex.h:303
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
PVOID ImageBaseAddress
Definition: ntddk_ex.h:245
BYTE BeingDebugged
Definition: btrfs_drv.h:1955
SIZE_T MmMinimumStackCommitInBytes
Definition: mminit.c:370
ULONG NtMajorVersion
Definition: init.c:43
_SEH2_TRY
Definition: create.c:4226
ULONG NtGlobalFlag
Definition: ntddk_ex.h:270
HANDLE Mutant
Definition: ntddk_ex.h:243
#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG
Definition: compat.h:153
LARGE_INTEGER MmCriticalSectionTimeout
Definition: mminit.c:388
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI MmMapViewOfSection(IN PVOID SectionObject, IN PEPROCESS Process, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
Definition: section.c:4500
void * PVOID
Definition: retypes.h:9
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
ULONG HeapSegmentCommit
Definition: ntddk_ex.h:276
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER SectionOffset
Definition: mmfuncs.h:404
#define PCHAR
Definition: match.c:90
Status
Definition: gdiplustypes.h:24
#define STATUS_INVALID_IMAGE_PROTECT
Definition: ntstatus.h:540
ULONG HeapSegmentReserve
Definition: ntddk_ex.h:275
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
PVOID * ProcessHeaps
Definition: ntddk_ex.h:288
ULONG MaximumNumberOfHeaps
Definition: ntddk_ex.h:287
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
SIZE_T MmHeapDeCommitFreeBlockThreshold
Definition: mminit.c:369
uint64_t ULONGLONG
Definition: typedefs.h:67
NTSTATUS NTAPI MiCreatePebOrTeb(IN PEPROCESS Process, IN ULONG Size, OUT PULONG_PTR BaseAddress)
Definition: procsup.c:29
PVOID ExpNlsSectionPointer
Definition: init.c:87
ULONG NtMinorVersion
Definition: init.c:44
LARGE_INTEGER CriticalSectionTimeout
Definition: ntddk_ex.h:274
SIZE_T MinimumStackCommit
Definition: winternl.h:358
ULONG NtBuildNumber
Definition: init.c:48
VOID NTAPI KeDetachProcess(VOID)
Definition: procobj.c:618
SIZE_T MmHeapSegmentReserve
Definition: mminit.c:366
ULONG OSBuildNumber
Definition: ntddk_ex.h:302
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
ULONG SessionId
Definition: btrfs_drv.h:1965
#define RtlImageDirectoryEntryToData
Definition: compat.h:668
#define IMAGE_FILE_UP_SYSTEM_ONLY
Definition: pedump.c:170
ULONG ExpUnicodeCaseTableDataOffset
Definition: init.c:84
#define PAGE_SIZE
Definition: env_spec_w32.h:49
PVOID UnicodeCaseTableData
Definition: ntddk_ex.h:266
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
ULONG ExpOemCodePageDataOffset
Definition: init.c:83
ULONG_PTR SIZE_T
Definition: typedefs.h:80
ULONG OSMinorVersion
Definition: ntddk_ex.h:301
_SEH2_END
Definition: create.c:4400
unsigned short USHORT
Definition: pedump.c:61
ULONG_PTR KAFFINITY
Definition: compat.h:85
VOID NTAPI KeAttachProcess(IN PKPROCESS Process)
Definition: procobj.c:579
SIZE_T MmHeapSegmentCommit
Definition: mminit.c:367
ULONG NumberOfProcessors
Definition: ntddk_ex.h:269
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
#define PAGE_READONLY
Definition: compat.h:138
#define RtlImageNtHeader
Definition: compat.h:665
PVOID OemCodePageData
Definition: ntddk_ex.h:265
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define BOOLEAN
Definition: pedump.c:73
ULONG CmNtCSDVersion
Definition: init.c:57
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t * PULONG_PTR
Definition: typedefs.h:65
ULONG NTAPI MmGetSessionId(IN PEPROCESS Process)
Definition: session.c:180
ULONG HeapDeCommitFreeBlockThreshold
Definition: ntddk_ex.h:278
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG OSMajorVersion
Definition: ntddk_ex.h:300
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
BOOLEAN InheritedAddressSpace
Definition: ntddk_ex.h:239
struct _PEB PEB
#define MEM_TOP_DOWN
Definition: nt_native.h:1321
ULONG NtGlobalFlag
Definition: init.c:52
ULONG ExpAnsiCodePageDataOffset
Definition: init.c:83
PVOID AnsiCodePageData
Definition: ntddk_ex.h:264
ULONG ImageSubsystemMinorVersion
Definition: ntddk_ex.h:306
ULONG HeapDeCommitTotalFreeThreshold
Definition: ntddk_ex.h:277
ULONG ImageSubsystem
Definition: ntddk_ex.h:304

Referenced by PspCreateProcess().

◆ MmCreateTeb()

NTSTATUS NTAPI MmCreateTeb ( IN PEPROCESS  Process,
IN PCLIENT_ID  ClientId,
IN PINITIAL_TEB  InitialTeb,
OUT PTEB BaseTeb 
)

Definition at line 740 of file procsup.c.

744 {
745  PTEB Teb;
747  *BaseTeb = NULL;
748 
749  //
750  // Attach to Target
751  //
752  KeAttachProcess(&Process->Pcb);
753 
754  //
755  // Allocate the TEB
756  //
757  Status = MiCreatePebOrTeb(Process, sizeof(TEB), (PULONG_PTR)&Teb);
758  if (!NT_SUCCESS(Status))
759  {
760  /* Cleanup and exit */
761  KeDetachProcess();
762  return Status;
763  }
764 
765  //
766  // Use SEH in case we can't load the TEB
767  //
768  _SEH2_TRY
769  {
770  //
771  // Initialize the PEB
772  //
773  RtlZeroMemory(Teb, sizeof(TEB));
774 
775  //
776  // Set TIB Data
777  //
778 #ifdef _M_AMD64
779  Teb->NtTib.ExceptionList = NULL;
780 #else
782 #endif
783  Teb->NtTib.Self = (PNT_TIB)Teb;
784 
785  //
786  // Identify this as an OS/2 V3.0 ("Cruiser") TIB
787  //
788  Teb->NtTib.Version = 30 << 8;
789 
790  //
791  // Set TEB Data
792  //
793  Teb->ClientId = *ClientId;
794  Teb->RealClientId = *ClientId;
795  Teb->ProcessEnvironmentBlock = Process->Peb;
797 
798  //
799  // Check if we have a grandparent TEB
800  //
801  if ((InitialTeb->PreviousStackBase == NULL) &&
802  (InitialTeb->PreviousStackLimit == NULL))
803  {
804  //
805  // Use initial TEB values
806  //
807  Teb->NtTib.StackBase = InitialTeb->StackBase;
808  Teb->NtTib.StackLimit = InitialTeb->StackLimit;
809  Teb->DeallocationStack = InitialTeb->AllocatedStackBase;
810  }
811  else
812  {
813  //
814  // Use grandparent TEB values
815  //
816  Teb->NtTib.StackBase = InitialTeb->PreviousStackBase;
817  Teb->NtTib.StackLimit = InitialTeb->PreviousStackLimit;
818  }
819 
820  //
821  // Initialize the static unicode string
822  //
825  }
827  {
828  //
829  // Get error code
830  //
832  }
833  _SEH2_END;
834 
835  //
836  // Return
837  //
838  KeDetachProcess();
839  *BaseTeb = Teb;
840  return Status;
841 }
struct _NT_TIB * Self
Definition: compat.h:579
WCHAR StaticUnicodeBuffer[261]
Definition: compat.h:736
PPEB ProcessEnvironmentBlock
Definition: ntddk_ex.h:337
USHORT MaximumLength
Definition: env_spec_w32.h:370
LONG NTSTATUS
Definition: precomp.h:26
LCID PsDefaultThreadLocaleId
Definition: locale.c:25
_SEH2_TRY
Definition: create.c:4226
CLIENT_ID ClientId
Definition: compat.h:698
UNICODE_STRING StaticUnicodeString
Definition: compat.h:735
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
ULONG CurrentLocale
Definition: compat.h:708
Status
Definition: gdiplustypes.h:24
DWORD Version
Definition: compat.h:576
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PVOID DeallocationStack
Definition: compat.h:737
NTSTATUS NTAPI MiCreatePebOrTeb(IN PEPROCESS Process, IN ULONG Size, OUT PULONG_PTR BaseAddress)
Definition: procsup.c:29
struct _NT_TIB * PNT_TIB
struct _EXCEPTION_REGISTRATION_RECORD * ExceptionList
Definition: compat.h:570
CLIENT_ID RealClientId
Definition: compat.h:720
VOID NTAPI KeDetachProcess(VOID)
Definition: procobj.c:618
Definition: compat.h:694
_SEH2_END
Definition: create.c:4400
#define EXCEPTION_CHAIN_END
Definition: rtltypes.h:63
PVOID StackBase
Definition: compat.h:571
VOID NTAPI KeAttachProcess(IN PKPROCESS Process)
Definition: procobj.c:579
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t * PULONG_PTR
Definition: typedefs.h:65
PVOID StackLimit
Definition: compat.h:572
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
NT_TIB NtTib
Definition: ntddk_ex.h:332

Referenced by PspCreateThread().

◆ MmDeleteKernelStack()

VOID NTAPI MmDeleteKernelStack ( IN PVOID  StackBase,
IN BOOLEAN  GuiStack 
)

Definition at line 169 of file procsup.c.

171 {
172  PMMPTE PointerPte;
173  PFN_NUMBER PageFrameNumber, PageTableFrameNumber;
174  PFN_COUNT StackPages;
175  PMMPFN Pfn1, Pfn2;
176  ULONG i;
177  KIRQL OldIrql;
178  PSLIST_ENTRY SListEntry;
179 
180  //
181  // This should be the guard page, so decrement by one
182  //
183  PointerPte = MiAddressToPte(StackBase);
184  PointerPte--;
185 
186  //
187  // If this is a small stack, just push the stack onto the dead stack S-LIST
188  //
189  if (!GuiStack)
190  {
192  {
193  SListEntry = ((PSLIST_ENTRY)StackBase) - 1;
195  return;
196  }
197  }
198 
199  //
200  // Calculate pages used
201  //
202  StackPages = BYTES_TO_PAGES(GuiStack ?
204 
205  /* Acquire the PFN lock */
207 
208  //
209  // Loop them
210  //
211  for (i = 0; i < StackPages; i++)
212  {
213  //
214  // Check if this is a valid PTE
215  //
216  if (PointerPte->u.Hard.Valid == 1)
217  {
218  /* Get the PTE's page */
219  PageFrameNumber = PFN_FROM_PTE(PointerPte);
220  Pfn1 = MiGetPfnEntry(PageFrameNumber);
221 
222  /* Now get the page of the page table mapping it */
223  PageTableFrameNumber = Pfn1->u4.PteFrame;
224  Pfn2 = MiGetPfnEntry(PageTableFrameNumber);
225 
226  /* Remove a shared reference, since the page is going away */
227  MiDecrementShareCount(Pfn2, PageTableFrameNumber);
228 
229  /* Set the special pending delete marker */
230  MI_SET_PFN_DELETED(Pfn1);
231 
232  /* And now delete the actual stack page */
233  MiDecrementShareCount(Pfn1, PageFrameNumber);
234  }
235 
236  //
237  // Next one
238  //
239  PointerPte--;
240  }
241 
242  //
243  // We should be at the guard page now
244  //
245  ASSERT(PointerPte->u.Hard.Valid == 0);
246 
247  /* Release the PFN lock */
249 
250  //
251  // Release the PTEs
252  //
253  MiReleaseSystemPtes(PointerPte, StackPages + 1, SystemPteSpace);
254 }
ULONG PFN_COUNT
Definition: mmtypes.h:102
union _MMPTE::@2312 u
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:900
ULONG MmLargeStackSize
Definition: mminit.c:262
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:907
SLIST_HEADER MmDeadStackSListHead
Definition: procsup.c:23
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define MiAddressToPte(x)
Definition: mmx86.c:19
ULONG PFN_NUMBER
Definition: ke.h:8
ULONG MmMaximumDeadKernelStacks
Definition: procsup.c:22
VOID NTAPI MiDecrementShareCount(IN PMMPFN Pfn1, IN PFN_NUMBER PageFrameIndex)
Definition: pfnlist.c:1133
VOID NTAPI MiReleaseSystemPtes(IN PMMPTE StartingPte, IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:275
#define ASSERT(a)
Definition: mode.c:45
ULONG64 Valid
Definition: mmtypes.h:150
#define PSLIST_ENTRY
Definition: rtltypes.h:134
FORCEINLINE USHORT ExQueryDepthSList(_In_ PSLIST_HEADER SListHead)
Definition: exfuncs.h:153
#define KERNEL_STACK_SIZE
#define BYTES_TO_PAGES(Size)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
Definition: mm.h:311
NTKERNELAPI PSLIST_ENTRY FASTCALL InterlockedPushEntrySList(IN PSLIST_HEADER ListHead, IN PSLIST_ENTRY ListEntry)
Definition: interlocked.c:82
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:939
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
#define MI_SET_PFN_DELETED(x)
Definition: miarm.h:190
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ULONG_PTR PteFrame
Definition: mm.h:356
union _MMPFN::@1789 u4
unsigned int ULONG
Definition: retypes.h:1
#define PFN_FROM_PTE(v)
Definition: mm.h:92

◆ MmDeleteProcessAddressSpace2()

VOID NTAPI MmDeleteProcessAddressSpace2 ( IN PEPROCESS  Process)

Definition at line 1416 of file procsup.c.

1417 {
1418  PMMPFN Pfn1, Pfn2;
1419  KIRQL OldIrql;
1420  PFN_NUMBER PageFrameIndex;
1421 
1422  //ASSERT(Process->CommitCharge == 0);
1423 
1424  /* Acquire the PFN lock */
1426 
1427  /* Check for fully initialized process */
1428  if (Process->AddressSpaceInitialized == 2)
1429  {
1430  /* Map the working set page and its page table */
1431  Pfn1 = MiGetPfnEntry(Process->WorkingSetPage);
1432  Pfn2 = MiGetPfnEntry(Pfn1->u4.PteFrame);
1433 
1434  /* Nuke it */
1435  MI_SET_PFN_DELETED(Pfn1);
1436  MiDecrementShareCount(Pfn2, Pfn1->u4.PteFrame);
1437  MiDecrementShareCount(Pfn1, Process->WorkingSetPage);
1438  ASSERT((Pfn1->u3.e2.ReferenceCount == 0) || (Pfn1->u3.e1.WriteInProgress));
1439  MiReleaseSystemPtes(MiAddressToPte(Process->Vm.VmWorkingSetList), 1, SystemPteSpace);
1440 
1441  /* Now map hyperspace and its page table */
1442  PageFrameIndex = Process->Pcb.DirectoryTableBase[1] >> PAGE_SHIFT;
1443  Pfn1 = MiGetPfnEntry(PageFrameIndex);
1444  Pfn2 = MiGetPfnEntry(Pfn1->u4.PteFrame);
1445 
1446  /* Nuke it */
1447  MI_SET_PFN_DELETED(Pfn1);
1448  MiDecrementShareCount(Pfn2, Pfn1->u4.PteFrame);
1449  MiDecrementShareCount(Pfn1, PageFrameIndex);
1450  ASSERT((Pfn1->u3.e2.ReferenceCount == 0) || (Pfn1->u3.e1.WriteInProgress));
1451 
1452  /* Finally, nuke the PDE itself */
1453  PageFrameIndex = Process->Pcb.DirectoryTableBase[0] >> PAGE_SHIFT;
1454  Pfn1 = MiGetPfnEntry(PageFrameIndex);
1455  MI_SET_PFN_DELETED(Pfn1);
1456  MiDecrementShareCount(Pfn1, PageFrameIndex);
1457  MiDecrementShareCount(Pfn1, PageFrameIndex);
1458 
1459  /* Page table is now dead. Bye bye... */
1460  ASSERT((Pfn1->u3.e2.ReferenceCount == 0) || (Pfn1->u3.e1.WriteInProgress));
1461  }
1462  else
1463  {
1464  /* A partly-initialized process should never exit through here */
1465  ASSERT(FALSE);
1466  }
1467 
1468  /* Release the PFN lock */
1470 
1471  /* Drop a reference on the session */
1473 
1474  /* Clear out the PDE pages */
1475  Process->Pcb.DirectoryTableBase[0] = 0;
1476  Process->Pcb.DirectoryTableBase[1] = 0;
1477 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
VOID NTAPI MiReleaseProcessReferenceToSessionDataPage(IN PMM_SESSION_SPACE SessionGlobal)
Definition: session.c:210
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:900
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:907
UCHAR KIRQL
Definition: env_spec_w32.h:591
MMPFNENTRY e1
Definition: mm.h:335
#define MiAddressToPte(x)
Definition: mmx86.c:19
ULONG PFN_NUMBER
Definition: ke.h:8
#define FALSE
Definition: types.h:117
VOID NTAPI MiDecrementShareCount(IN PMMPFN Pfn1, IN PFN_NUMBER PageFrameIndex)
Definition: pfnlist.c:1133
VOID NTAPI MiReleaseSystemPtes(IN PMMPTE StartingPte, IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:275
USHORT WriteInProgress
Definition: mm.h:300
struct _MMPFN::@1786::@1792 e2
#define ASSERT(a)
Definition: mode.c:45
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
Definition: mm.h:311
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:939
#define MI_SET_PFN_DELETED(x)
Definition: miarm.h:190
ULONG_PTR PteFrame
Definition: mm.h:356
union _MMPFN::@1789 u4
union _MMPFN::@1786 u3
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by MmDeleteProcessAddressSpace().

◆ MmDeleteTeb()

VOID NTAPI MmDeleteTeb ( IN PEPROCESS  Process,
IN PTEB  Teb 
)

Definition at line 107 of file procsup.c.

109 {
110  ULONG_PTR TebEnd;
112  PMMVAD Vad;
113  PMM_AVL_TABLE VadTree = &Process->VadRoot;
114  DPRINT("Deleting TEB: %p in %16s\n", Teb, Process->ImageFileName);
115 
116  /* TEB is one page */
117  TebEnd = (ULONG_PTR)Teb + ROUND_TO_PAGES(sizeof(TEB)) - 1;
118 
119  /* Attach to the process */
120  KeAttachProcess(&Process->Pcb);
121 
122  /* Lock the process address space */
123  KeAcquireGuardedMutex(&Process->AddressCreationLock);
124 
125  /* Find the VAD, make sure it's a TEB VAD */
126  Vad = MiLocateAddress(Teb);
127  DPRINT("Removing node for VAD: %lx %lx\n", Vad->StartingVpn, Vad->EndingVpn);
128  ASSERT(Vad != NULL);
129  if (Vad->StartingVpn != ((ULONG_PTR)Teb >> PAGE_SHIFT))
130  {
131  /* Bug in the AVL code? */
132  DPRINT1("Corrupted VAD!\n");
133  }
134  else
135  {
136  /* Sanity checks for a valid TEB VAD */
137  ASSERT((Vad->StartingVpn == ((ULONG_PTR)Teb >> PAGE_SHIFT) &&
138  (Vad->EndingVpn == (TebEnd >> PAGE_SHIFT))));
139  ASSERT(Vad->u.VadFlags.NoChange == TRUE);
140  ASSERT(Vad->u2.VadFlags2.OneSecured == TRUE);
142 
143  /* Lock the working set */
145 
146  /* Remove this VAD from the tree */
147  ASSERT(VadTree->NumberGenericTableElements >= 1);
148  MiRemoveNode((PMMADDRESS_NODE)Vad, VadTree);
149 
150  /* Delete the pages */
151  MiDeleteVirtualAddresses((ULONG_PTR)Teb, TebEnd, NULL);
152 
153  /* Release the working set */
155 
156  /* Remove the VAD */
157  ExFreePool(Vad);
158  }
159 
160  /* Release the address space lock */
161  KeReleaseGuardedMutex(&Process->AddressCreationLock);
162 
163  /* Detach */
164  KeDetachProcess();
165 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
FORCEINLINE VOID MiUnlockProcessWorkingSetUnsafe(IN PEPROCESS Process, IN PETHREAD Thread)
Definition: miarm.h:1215
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
ULONG OneSecured
Definition: mmtypes.h:718
#define TRUE
Definition: types.h:120
ULONG_PTR NumberGenericTableElements
Definition: mmtypes.h:678
ULONG_PTR NoChange
Definition: mmtypes.h:703
MMVAD_FLAGS VadFlags
Definition: mmtypes.h:744
uint32_t ULONG_PTR
Definition: typedefs.h:65
ULONG_PTR EndingVpn
Definition: mmtypes.h:740
#define FALSE
Definition: types.h:117
PMMVAD NTAPI MiLocateAddress(IN PVOID VirtualAddress)
Definition: vadnode.c:48
void DPRINT(...)
Definition: polytest.cpp:61
ULONG_PTR StartingVpn
Definition: mmtypes.h:739
MMVAD_FLAGS2 VadFlags2
Definition: mmtypes.h:752
ULONG MultipleSecured
Definition: mmtypes.h:719
FORCEINLINE VOID MiLockProcessWorkingSetUnsafe(IN PEPROCESS Process, IN PETHREAD Thread)
Definition: miarm.h:1145
#define ASSERT(a)
Definition: mode.c:45
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
VOID NTAPI KeDetachProcess(VOID)
Definition: procobj.c:618
VOID NTAPI MiRemoveNode(IN PMMADDRESS_NODE Node, IN PMM_AVL_TABLE Table)
Definition: vadnode.c:360
VOID NTAPI MiDeleteVirtualAddresses(IN ULONG_PTR Va, IN ULONG_PTR EndingAddress, IN PMMVAD Vad)
Definition: virtual.c:540
union _MMVAD::@2572 u
Definition: compat.h:694
#define ROUND_TO_PAGES(Size)
VOID NTAPI KeAttachProcess(IN PKPROCESS Process)
Definition: procobj.c:579
#define NULL
Definition: types.h:112
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
#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
#define ULONG_PTR
Definition: config.h:101
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
union _MMVAD::@2573 u2

◆ MmGrowKernelStack()

NTSTATUS NTAPI MmGrowKernelStack ( IN PVOID  StackPointer)

Definition at line 459 of file procsup.c.

460 {
461  //
462  // Call the extended version
463  //
464  return MmGrowKernelStackEx(StackPointer, KERNEL_LARGE_STACK_COMMIT);
465 }
#define KERNEL_LARGE_STACK_COMMIT
NTSTATUS NTAPI MmGrowKernelStackEx(IN PVOID StackPointer, IN ULONG GrowSize)
Definition: procsup.c:371

Referenced by KiUserModeCallout().

◆ MmGrowKernelStackEx()

NTSTATUS NTAPI MmGrowKernelStackEx ( IN PVOID  StackPointer,
IN ULONG  GrowSize 
)

Definition at line 371 of file procsup.c.

373 {
375  PMMPTE LimitPte, NewLimitPte, LastPte;
376  KIRQL OldIrql;
377  MMPTE TempPte, InvalidPte;
378  PFN_NUMBER PageFrameIndex;
379 
380  //
381  // Make sure the stack did not overflow
382  //
383  ASSERT(((ULONG_PTR)Thread->StackBase - (ULONG_PTR)Thread->StackLimit) <=
385 
386  //
387  // Get the current stack limit
388  //
389  LimitPte = MiAddressToPte(Thread->StackLimit);
390  ASSERT(LimitPte->u.Hard.Valid == 1);
391 
392  //
393  // Get the new one and make sure this isn't a retarded request
394  //
395  NewLimitPte = MiAddressToPte((PVOID)((ULONG_PTR)StackPointer - GrowSize));
396  if (NewLimitPte == LimitPte) return STATUS_SUCCESS;
397 
398  //
399  // Now make sure you're not going past the reserved space
400  //
401  LastPte = MiAddressToPte((PVOID)((ULONG_PTR)Thread->StackBase -
403  if (NewLimitPte < LastPte)
404  {
405  //
406  // Sorry!
407  //
408  return STATUS_STACK_OVERFLOW;
409  }
410 
411  //
412  // Calculate the number of new pages
413  //
414  LimitPte--;
415 
416  /* Setup the temporary invalid PTE */
417  MI_MAKE_SOFTWARE_PTE(&InvalidPte, MM_NOACCESS);
418 
419  //
420  // Acquire the PFN DB lock
421  //
423 
424  //
425  // Loop each stack page
426  //
427  while (LimitPte >= NewLimitPte)
428  {
429  /* Get a page and write the current invalid PTE */
431  MI_SET_PROCESS2(PsGetCurrentProcess()->ImageFileName);
432  PageFrameIndex = MiRemoveAnyPage(MI_GET_NEXT_COLOR());
433  MI_WRITE_INVALID_PTE(LimitPte, InvalidPte);
434 
435  /* Initialize the PFN entry for this page */
436  MiInitializePfn(PageFrameIndex, LimitPte, 1);
437 
438  /* Setup the template stack PTE */
439  MI_MAKE_HARDWARE_PTE_KERNEL(&TempPte, LimitPte, MM_READWRITE, PageFrameIndex);
440 
441  /* Write the valid PTE */
442  MI_WRITE_VALID_PTE(LimitPte--, TempPte);
443  }
444 
445  //
446  // Release the PFN lock
447  //
449 
450  //
451  // Set the new limit
452  //
453  Thread->StackLimit = (ULONG_PTR)MiPteToAddress(NewLimitPte);
454  return STATUS_SUCCESS;
455 }
#define MI_MAKE_SOFTWARE_PTE(p, x)
Definition: miarm.h:185
VOID NTAPI MiInitializePfn(IN PFN_NUMBER PageFrameIndex, IN PMMPTE PointerPte, IN BOOLEAN Modified)
Definition: pfnlist.c:969
union _MMPTE::@2312 u
#define MI_GET_NEXT_COLOR()
Definition: miarm.h:238
#define MM_NOACCESS
Definition: miarm.h:61
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:900
ULONG MmLargeStackSize
Definition: mminit.c:262
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:907
uint32_t ULONG_PTR
Definition: typedefs.h:65
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define MiAddressToPte(x)
Definition: mmx86.c:19
ULONG PFN_NUMBER
Definition: ke.h:8
FORCEINLINE VOID MI_WRITE_VALID_PTE(IN PMMPTE PointerPte, IN MMPTE TempPte)
Definition: miarm.h:942
#define MI_SET_PROCESS2(x)
Definition: mm.h:260
#define PsGetCurrentProcess
Definition: psfuncs.h:17
#define MI_SET_USAGE(x)
Definition: mm.h:259
#define ASSERT(a)
Definition: mode.c:45
ULONG64 Valid
Definition: mmtypes.h:150
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define MM_READWRITE
Definition: inbv.c:12
#define PAGE_SIZE
Definition: env_spec_w32.h:49
PFN_NUMBER NTAPI MiRemoveAnyPage(IN ULONG Color)
Definition: pfnlist.c:475
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
FORCEINLINE VOID MI_WRITE_INVALID_PTE(IN PMMPTE PointerPte, IN MMPTE InvalidPte)
Definition: miarm.h:975
#define STATUS_STACK_OVERFLOW
Definition: ntstatus.h:489
#define ULONG_PTR
Definition: config.h:101
#define STATUS_SUCCESS
Definition: shellext.h:65
FORCEINLINE VOID MI_MAKE_HARDWARE_PTE_KERNEL(IN PMMPTE NewPte, IN PMMPTE MappingPte, IN ULONG_PTR ProtectionMask, IN PFN_NUMBER PageFrameNumber)
Definition: miarm.h:774
#define KeGetCurrentThread
Definition: hal.h:44
FORCEINLINE PVOID MiPteToAddress(PMMPTE PointerPte)
Definition: mm.h:201

Referenced by MmGrowKernelStack().

◆ MmInitializeHandBuiltProcess()

NTSTATUS NTAPI MmInitializeHandBuiltProcess ( IN PEPROCESS  Process,
IN PULONG_PTR  DirectoryTableBase 
)

Definition at line 1123 of file procsup.c.

1125 {
1126  /* Share the directory base with the idle process */
1127  DirectoryTableBase[0] = PsGetCurrentProcess()->Pcb.DirectoryTableBase[0];
1128  DirectoryTableBase[1] = PsGetCurrentProcess()->Pcb.DirectoryTableBase[1];
1129 
1130  /* Initialize the Addresss Space */
1131  KeInitializeGuardedMutex(&Process->AddressCreationLock);
1132  KeInitializeSpinLock(&Process->HyperSpaceLock);
1133  Process->Vm.WorkingSetExpansionLinks.Flink = NULL;
1134  ASSERT(Process->VadRoot.NumberGenericTableElements == 0);
1135  Process->VadRoot.BalancedRoot.u1.Parent = &Process->VadRoot.BalancedRoot;
1136 
1137  /* Use idle process Working set */
1138  Process->Vm.VmWorkingSetList = PsGetCurrentProcess()->Vm.VmWorkingSetList;
1139 
1140  /* Done */
1141  Process->HasAddressSpace = TRUE;//??
1142  return STATUS_SUCCESS;
1143 }
#define TRUE
Definition: types.h:120
#define PsGetCurrentProcess
Definition: psfuncs.h:17
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
#define ASSERT(a)
Definition: mode.c:45
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by PspCreateProcess().

◆ MmInitializeHandBuiltProcess2()

NTSTATUS NTAPI MmInitializeHandBuiltProcess2 ( IN PEPROCESS  Process)

Definition at line 1148 of file procsup.c.

1149 {
1150  /* Lock the VAD, ARM3-owned ranges away */
1151  return STATUS_SUCCESS;
1152 }
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by PspCreateProcess().

◆ MmInitializeProcessAddressSpace()

NTSTATUS NTAPI MmInitializeProcessAddressSpace ( IN PEPROCESS  Process,
IN PEPROCESS ProcessClone  OPTIONAL,
IN PVOID Section  OPTIONAL,
IN OUT PULONG  Flags,
IN POBJECT_NAME_INFORMATION *AuditName  OPTIONAL 
)

Definition at line 935 of file procsup.c.

940 {
942  SIZE_T ViewSize = 0;
943  PVOID ImageBase = 0;
945  PMMPTE PointerPte;
946  KIRQL OldIrql;
947  PMMPDE PointerPde;
948  PFN_NUMBER PageFrameNumber;
950  PWCHAR Source;
952  USHORT Length = 0;
953  MMPTE TempPte;
954 #if (_MI_PAGING_LEVELS >= 3)
955  PMMPPE PointerPpe;
956 #endif
957 #if (_MI_PAGING_LEVELS == 4)
958  PMMPXE PointerPxe;
959 #endif
960 
961  /* We should have a PDE */
962  ASSERT(Process->Pcb.DirectoryTableBase[0] != 0);
963  ASSERT(Process->PdeUpdateNeeded == FALSE);
964 
965  /* Attach to the process */
966  KeAttachProcess(&Process->Pcb);
967 
968  /* The address space should now been in phase 1 or 0 */
969  ASSERT(Process->AddressSpaceInitialized <= 1);
970  Process->AddressSpaceInitialized = 2;
971 
972  /* Initialize the Addresss Space lock */
973  KeInitializeGuardedMutex(&Process->AddressCreationLock);
974  Process->Vm.WorkingSetExpansionLinks.Flink = NULL;
975 
976  /* Initialize AVL tree */
977  ASSERT(Process->VadRoot.NumberGenericTableElements == 0);
978  Process->VadRoot.BalancedRoot.u1.Parent = &Process->VadRoot.BalancedRoot;
979 
980 #ifdef _M_AMD64
981  /* On x64 the PFNs for the initial process are already set up */
982  if (Process != &KiInitialProcess) {
983 #endif
984 
985  /* Lock PFN database */
987 
988  /* Setup the PFN for the PDE base of this process */
989 #if (_MI_PAGING_LEVELS == 4)
990  PointerPte = MiAddressToPte(PXE_BASE);
991 #elif (_MI_PAGING_LEVELS == 3)
992  PointerPte = MiAddressToPte(PPE_BASE);
993 #else
994  PointerPte = MiAddressToPte(PDE_BASE);
995 #endif
996  PageFrameNumber = PFN_FROM_PTE(PointerPte);
997  ASSERT(Process->Pcb.DirectoryTableBase[0] == PageFrameNumber * PAGE_SIZE);
998  MiInitializePfn(PageFrameNumber, PointerPte, TRUE);
999 
1000  /* Do the same for hyperspace */
1001  PointerPde = MiAddressToPde((PVOID)HYPER_SPACE);
1002  PageFrameNumber = PFN_FROM_PTE(PointerPde);
1003  //ASSERT(Process->Pcb.DirectoryTableBase[0] == PageFrameNumber * PAGE_SIZE); // we're not lucky
1004  MiInitializePfn(PageFrameNumber, (PMMPTE)PointerPde, TRUE);
1005 
1006 #if (_MI_PAGING_LEVELS >= 3)
1007  PointerPpe = MiAddressToPpe((PVOID)HYPER_SPACE);
1008  PageFrameNumber = PFN_FROM_PTE(PointerPpe);
1009  MiInitializePfn(PageFrameNumber, PointerPpe, TRUE);
1010 #endif
1011 #if (_MI_PAGING_LEVELS == 4)
1012  PointerPxe = MiAddressToPxe((PVOID)HYPER_SPACE);
1013  PageFrameNumber = PFN_FROM_PTE(PointerPxe);
1014  MiInitializePfn(PageFrameNumber, PointerPxe, TRUE);
1015 #endif
1016 
1017  /* Setup the PFN for the PTE for the working set */
1018  PointerPte = MiAddressToPte(MI_WORKING_SET_LIST);
1019  MI_MAKE_HARDWARE_PTE(&TempPte, PointerPte, MM_READWRITE, 0);
1020  ASSERT(PointerPte->u.Long != 0);
1021  PageFrameNumber = PFN_FROM_PTE(PointerPte);
1022  MI_WRITE_INVALID_PTE(PointerPte, DemandZeroPte);
1023  MiInitializePfn(PageFrameNumber, PointerPte, TRUE);
1024  TempPte.u.Hard.PageFrameNumber = PageFrameNumber;
1025  MI_WRITE_VALID_PTE(PointerPte, TempPte);
1026 
1027  /* Now initialize the working set list */
1029 
1030  /* Sanity check */
1031  ASSERT(Process->PhysicalVadRoot == NULL);
1032 
1033  /* Release PFN lock */
1035 
1036 #ifdef _M_AMD64
1037  } /* On x64 the PFNs for the initial process are already set up */
1038 #endif
1039 
1040 #ifdef _M_AMD64
1041  /* On x64 we need a VAD for the shared user page */
1042  Status = MiInsertSharedUserPageVad();
1043  if (!NT_SUCCESS(Status))
1044  {
1045  DPRINT1("MiCreateSharedUserPageVad() failed: 0x%lx\n", Status);
1046  return Status;
1047  }
1048 #endif
1049 
1050  /* Check if there's a Section Object */
1051  if (SectionObject)
1052  {
1053  /* Determine the image file name and save it to EPROCESS */
1054  FileName = SectionObject->FileObject->FileName;
1055  Source = (PWCHAR)((PCHAR)FileName.Buffer + FileName.Length);
1056  if (FileName.Buffer)
1057  {
1058  /* Loop the file name*/
1059  while (Source > FileName.Buffer)
1060  {
1061  /* Make sure this isn't a backslash */
1062  if (*--Source == OBJ_NAME_PATH_SEPARATOR)
1063  {
1064  /* If so, stop it here */
1065  Source++;
1066  break;
1067  }
1068  else
1069  {
1070  /* Otherwise, keep going */
1071  Length++;
1072  }
1073  }
1074  }
1075 
1076  /* Copy the to the process and truncate it to 15 characters if necessary */
1077  Destination = Process->ImageFileName;
1078  Length = min(Length, sizeof(Process->ImageFileName) - 1);
1079  while (Length--) *Destination++ = (UCHAR)*Source++;
1081 
1082  /* Check if caller wants an audit name */
1083  if (AuditName)
1084  {
1085  /* Setup the audit name */
1087  FALSE,
1088  AuditName);
1089  if (!NT_SUCCESS(Status))
1090  {
1091  /* Fail */
1092  KeDetachProcess();
1093  return Status;
1094  }
1095  }
1096 
1097  /* Map the section */
1098  Status = MmMapViewOfSection(Section,
1099  Process,
1100  (PVOID*)&ImageBase,
1101  0,
1102  0,
1103  NULL,
1104  &ViewSize,
1105  0,
1106  MEM_COMMIT,
1107  PAGE_READWRITE);
1108 
1109  /* Save the pointer */
1110  Process->SectionBaseAddress = ImageBase;
1111  }
1112 
1113  /* Be nice and detach */
1114  KeDetachProcess();
1115 
1116  /* Return status to caller */
1117  return Status;
1118 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
signed char * PCHAR
Definition: retypes.h:7
VOID NTAPI MiInitializePfn(IN PFN_NUMBER PageFrameIndex, IN PMMPTE PointerPte, IN BOOLEAN Modified)
Definition: pfnlist.c:969
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define MiAddressToPde(x)
Definition: mmx86.c:20
#define TRUE
Definition: types.h:120
union _MMPTE::@2312 u
LONG NTSTATUS
Definition: precomp.h:26
FORCEINLINE PMMPTE MiAddressToPpe(PVOID Address)
Definition: mm.h:154
FORCEINLINE KIRQL MiAcquirePfnLock(VOID)
Definition: mm.h:900
uint16_t * PWCHAR
Definition: typedefs.h:56
#define MEM_COMMIT
Definition: nt_native.h:1313
FORCEINLINE VOID MiReleasePfnLock(_In_ KIRQL OldIrql)
Definition: mm.h:907
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define MiAddressToPte(x)
Definition: mmx86.c:19
ULONG PFN_NUMBER
Definition: ke.h:8
#define FALSE
Definition: types.h:117
FORCEINLINE VOID MI_WRITE_VALID_PTE(IN PMMPTE PointerPte, IN MMPTE TempPte)
Definition: miarm.h:942
#define ANSI_NULL
#define PDE_BASE
Definition: winldr.c:21
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
NTSTATUS NTAPI MmMapViewOfSection(IN PVOID SectionObject, IN PEPROCESS Process, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
Definition: section.c:4500
VOID NTAPI MiInitializeWorkingSetList(IN PEPROCESS CurrentProcess)
Definition: procsup.c:901
Status
Definition: gdiplustypes.h:24
FORCEINLINE PMMPTE MiAddressToPxe(PVOID Address)
Definition: mm.h:164
NTSTATUS NTAPI SeInitializeProcessAuditName(IN PFILE_OBJECT FileObject, IN BOOLEAN DoAudit, OUT POBJECT_NAME_INFORMATION *AuditInfo)
Definition: audit.c:47
#define ASSERT(a)
Definition: mode.c:45
#define MI_WORKING_SET_LIST
Definition: mm.h:51
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2937
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
#define PPE_BASE
VOID NTAPI KeDetachProcess(VOID)
Definition: procobj.c:618
unsigned char UCHAR
Definition: xmlstorage.h:181
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define MM_READWRITE
Definition: inbv.c:12
#define PAGE_SIZE
Definition: env_spec_w32.h:49
EPROCESS KiInitialProcess
Definition: krnlinit.c:45
ULONG_PTR Long
Definition: mmtypes.h:215
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define PXE_BASE
struct _FileName FileName
Definition: fatprocs.h:893
FORCEINLINE VOID MI_WRITE_INVALID_PTE(IN PMMPTE PointerPte, IN MMPTE InvalidPte)
Definition: miarm.h:975
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
unsigned short USHORT
Definition: pedump.c:61
VOID NTAPI KeAttachProcess(IN PKPROCESS Process)
Definition: procobj.c:579
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
#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
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
#define HYPER_SPACE
Definition: mm.h:14
MMPTE DemandZeroPte
Definition: init.c:37
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
#define STATUS_SUCCESS
Definition: shellext.h:65
#define PFN_FROM_PTE(v)
Definition: mm.h:92
FORCEINLINE VOID MI_MAKE_HARDWARE_PTE(IN PMMPTE NewPte, IN PMMPTE MappingPte, IN ULONG_PTR ProtectionMask, IN PFN_NUMBER PageFrameNumber)
Definition: miarm.h:797
ULONG PageFrameNumber
Definition: mmtypes.h:109
#define PAGE_READWRITE
Definition: nt_native.h:1304

◆ MmSetMemoryPriorityProcess()

NTSTATUS NTAPI MmSetMemoryPriorityProcess ( IN PEPROCESS  Process,
IN UCHAR  MemoryPriority 
)

Definition at line 469 of file procsup.c.

471 {
472  UCHAR OldPriority;
473 
474  //
475  // Check if we have less then 16MB of Physical Memory
476  //
477  if ((MmSystemSize == MmSmallSystem) &&
478  (MmNumberOfPhysicalPages < ((15 * 1024 * 1024) / PAGE_SIZE)))
479  {
480  //
481  // Always use background priority
482  //
483  MemoryPriority = MEMORY_PRIORITY_BACKGROUND;
484  }
485 
486  //
487  // Save the old priority and update it
488  //
489  OldPriority = (UCHAR)Process->Vm.Flags.MemoryPriority;
490  Process->Vm.Flags.MemoryPriority = MemoryPriority;
491 
492  //
493  // Return the old priority
494  //
495  return OldPriority;
496 }
#define MEMORY_PRIORITY_BACKGROUND
Definition: pstypes.h:124
unsigned char UCHAR
Definition: xmlstorage.h:181
#define PAGE_SIZE
Definition: env_spec_w32.h:49
MM_SYSTEMSIZE MmSystemSize
Definition: mminit.c:326
PFN_COUNT MmNumberOfPhysicalPages
Definition: init.c:48
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by NtSetInformationProcess(), and PspComputeQuantumAndPriority().

◆ NtAllocateUserPhysicalPages()

NTSTATUS NTAPI NtAllocateUserPhysicalPages ( IN HANDLE  ProcessHandle,
IN OUT PULONG_PTR  NumberOfPages,
IN OUT PULONG_PTR  UserPfnArray 
)

Definition at line 1484 of file procsup.c.

1487 {
1488  UNIMPLEMENTED;
1489  return STATUS_NOT_IMPLEMENTED;
1490 }
return STATUS_NOT_IMPLEMENTED
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by AllocateUserPhysicalPages().

◆ NtFreeUserPhysicalPages()

NTSTATUS NTAPI NtFreeUserPhysicalPages ( IN HANDLE  ProcessHandle,
IN OUT PULONG_PTR  NumberOfPages,
IN OUT PULONG_PTR  UserPfnArray 
)

Definition at line 1514 of file procsup.c.

1517 {
1518  UNIMPLEMENTED;
1519  return STATUS_NOT_IMPLEMENTED;
1520 }
return STATUS_NOT_IMPLEMENTED
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by FreeUserPhysicalPages().

◆ NtMapUserPhysicalPages()

NTSTATUS NTAPI NtMapUserPhysicalPages ( IN PVOID  VirtualAddresses,
IN ULONG_PTR  NumberOfPages,
IN OUT PULONG_PTR  UserPfnArray 
)

Definition at line 1494 of file procsup.c.

1497 {
1498  UNIMPLEMENTED;
1499  return STATUS_NOT_IMPLEMENTED;
1500 }
return STATUS_NOT_IMPLEMENTED
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by MapUserPhysicalPages().

◆ NtMapUserPhysicalPagesScatter()

NTSTATUS NTAPI NtMapUserPhysicalPagesScatter ( IN PVOID VirtualAddresses,
IN ULONG_PTR  NumberOfPages,
IN OUT PULONG_PTR  UserPfnArray 
)

Definition at line 1504 of file procsup.c.

1507 {
1508  UNIMPLEMENTED;
1509  return STATUS_NOT_IMPLEMENTED;
1510 }
return STATUS_NOT_IMPLEMENTED
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by MapUserPhysicalPagesScatter().

Variable Documentation

◆ MmDeadStackSListHead

SLIST_HEADER MmDeadStackSListHead

Definition at line 23 of file procsup.c.

Referenced by MmArmInitSystem(), MmCreateKernelStack(), and MmDeleteKernelStack().

◆ MmMaximumDeadKernelStacks

ULONG MmMaximumDeadKernelStacks = 5

Definition at line 22 of file procsup.c.

Referenced by MmArmInitSystem(), and MmDeleteKernelStack().

◆ MmProcessColorSeed

ULONG MmProcessColorSeed = 0x12345678

Definition at line 20 of file procsup.c.

Referenced by MmCreateProcessAddressSpace().

◆ MmWorkingSetList