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

Go to the source code of this file.

Macros

#define NDEBUG
 
#define MODULE_INVOLVED_IN_ARM3
 

Functions

VOID NTAPI MiInitializeSessionWsSupport (VOID)
 
BOOLEAN NTAPI MmIsSessionAddress (IN PVOID Address)
 
LCID NTAPI MmGetSessionLocaleId (VOID)
 
 _IRQL_requires_max_ (APC_LEVEL)
 
VOID NTAPI MiInitializeSessionIds (VOID)
 
VOID NTAPI MiSessionLeader (IN PEPROCESS Process)
 
ULONG NTAPI MmGetSessionId (IN PEPROCESS Process)
 
ULONG NTAPI MmGetSessionIdEx (IN PEPROCESS Process)
 
VOID NTAPI MiReleaseProcessReferenceToSessionDataPage (IN PMM_SESSION_SPACE SessionGlobal)
 
VOID NTAPI MiDereferenceSessionFinal (VOID)
 
VOID NTAPI MiDereferenceSession (VOID)
 
VOID NTAPI MiSessionRemoveProcess (VOID)
 
VOID NTAPI MiSessionAddProcess (IN PEPROCESS NewProcess)
 
NTSTATUS NTAPI MiSessionInitializeWorkingSetList (VOID)
 
NTSTATUS NTAPI MiSessionCreateInternal (OUT PULONG SessionId)
 
NTSTATUS NTAPI MmSessionCreate (OUT PULONG SessionId)
 
NTSTATUS NTAPI MmSessionDelete (IN ULONG SessionId)
 
VOID NTAPI MmQuitNextSession (_Inout_ PVOID SessionEntry)
 
PVOID NTAPI MmGetSessionById (_In_ ULONG SessionId)
 

Variables

PMM_SESSION_SPACE MmSessionSpace
 
PFN_NUMBER MiSessionDataPages
 
PFN_NUMBER MiSessionTagPages
 
PFN_NUMBER MiSessionTagSizePages
 
PFN_NUMBER MiSessionBigPoolPages
 
PFN_NUMBER MiSessionCreateCharge
 
KGUARDED_MUTEX MiSessionIdMutex
 
LONG MmSessionDataPages
 
PRTL_BITMAP MiSessionIdBitmap
 
volatile LONG MiSessionLeaderExists
 
LIST_ENTRY MiSessionWsList
 
LIST_ENTRY MmWorkingSetExpansionHead
 
KSPIN_LOCK MmExpansionLock
 
PETHREAD MiExpansionLockOwner
 

Macro Definition Documentation

◆ MODULE_INVOLVED_IN_ARM3

#define MODULE_INVOLVED_IN_ARM3

Definition at line 16 of file session.c.

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file session.c.

Function Documentation

◆ _IRQL_requires_max_()

_IRQL_requires_max_ ( APC_LEVEL  )

Definition at line 89 of file session.c.

94 {
96  PAGED_CODE();
97 
98  /* Get the current process and check if it is in a session */
100  if ((CurrentProcess->Vm.Flags.SessionLeader == 0) &&
101  (CurrentProcess->Session != NULL))
102  {
103  /* Set the session locale Id */
104  ((PMM_SESSION_SPACE)CurrentProcess->Session)->LocaleId = LocaleId;
105  }
106  else
107  {
108  /* Set the default locale */
110  }
111 }
LCID PsDefaultThreadLocaleId
Definition: locale.c:25
#define PsGetCurrentProcess
Definition: psfuncs.h:17
ULONG CurrentProcess
Definition: shell.c:125
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING _In_ PCUNICODE_STRING _In_ LCID LocaleId
Definition: wdfpdo.h:430
#define NULL
Definition: types.h:112
struct _MM_SESSION_SPACE * PMM_SESSION_SPACE
#define PAGED_CODE()

◆ MiDereferenceSession()

VOID NTAPI MiDereferenceSession ( VOID  )

Definition at line 339 of file session.c.

340 {
341  PMM_SESSION_SPACE SessionGlobal;
343  ULONG ReferenceCount, SessionId;
344 
345  /* Sanity checks */
346  ASSERT(PsGetCurrentProcess()->ProcessInSession ||
347  ((MmSessionSpace->u.Flags.Initialized == 0) &&
348  (PsGetCurrentProcess()->Vm.Flags.SessionLeader == 1) &&
349  (MmSessionSpace->ReferenceCount == 1)));
350 
351  /* The session bit must be set */
354 
355  /* Get the current process */
357 
358  /* Decrement the process count */
360 
361  /* Decrement the reference count and check if was the last reference */
363  if (ReferenceCount == 0)
364  {
365  /* No more references left, kill the session completely */
367  return;
368  }
369 
370  /* Check if this is the session leader */
371  if (Process->Vm.Flags.SessionLeader)
372  {
373  /* Get the global session address before we kill the session mapping */
374  SessionGlobal = MmSessionSpace->GlobalVirtualAddress;
375 
376  /* Delete all session PDEs and flush the TB */
377  //RtlZeroMemory(MiAddressToPde(MmSessionBase),
378  // BYTES_TO_PAGES(MmSessionSize) * sizeof(MMPDE));
380 
381  /* Clean up the references here. */
382  ASSERT(Process->Session == NULL);
384  }
385 
386  /* Reset the current process' session flag */
388 }
VOID NTAPI MiDereferenceSessionFinal(VOID)
Definition: session.c:273
ULONG SessionId
Definition: miarm.h:482
LONG ReferenceCount
Definition: miarm.h:476
ULONG SessionId
Definition: dllmain.c:28
PMM_SESSION_SPACE MmSessionSpace
Definition: session.c:21
#define RtlCheckBit(BMH, BP)
Definition: rtlfuncs.h:3152
#define PSF_PROCESS_IN_SESSION_BIT
Definition: pstypes.h:288
#define FALSE
Definition: types.h:117
#define RtlInterlockedClearBits(Flags, Flag)
Definition: rtlfuncs.h:3440
#define PsGetCurrentProcess
Definition: psfuncs.h:17
VOID NTAPI KeFlushEntireTb(IN BOOLEAN Invalid, IN BOOLEAN AllProcessors)
Definition: cpu.c:403
MM_SESSION_SPACE_FLAGS Flags
Definition: miarm.h:480
struct _MM_SESSION_SPACE * GlobalVirtualAddress
Definition: miarm.h:475
union _MM_SESSION_SPACE::@1790 u
#define ASSERT(a)
Definition: mode.c:44
PRTL_BITMAP MiSessionIdBitmap
Definition: session.c:26
#define InterlockedDecrement
Definition: armddk.h:52
VOID NTAPI MiReleaseProcessReferenceToSessionDataPage(IN PMM_SESSION_SPACE SessionGlobal)
Definition: session.c:209
LONG ResidentProcessCount
Definition: miarm.h:492
#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
unsigned int ULONG
Definition: retypes.h:1

Referenced by MiSessionRemoveProcess(), and MmSessionDelete().

◆ MiDereferenceSessionFinal()

VOID NTAPI MiDereferenceSessionFinal ( VOID  )

Definition at line 273 of file session.c.

274 {
275  PMM_SESSION_SPACE SessionGlobal;
276  KIRQL OldIrql;
277 
278  /* Get the pointer to the global session address */
279  SessionGlobal = MmSessionSpace->GlobalVirtualAddress;
280 
281  /* Acquire the expansion lock */
283 
284  /* Set delete pending flag, so that processes can no longer attach to this
285  session and the last process that detaches sets the AttachEvent */
286  ASSERT(SessionGlobal->u.Flags.DeletePending == 0);
287  SessionGlobal->u.Flags.DeletePending = 1;
288 
289  /* Check if we have any attached processes */
290  if (SessionGlobal->AttachCount)
291  {
292  /* Initialize the event (it's not in use yet!) */
294 
295  /* Release the expansion lock for the wait */
297 
298  /* Wait for the event to be set due to the last process detach */
299  KeWaitForSingleObject(&SessionGlobal->AttachEvent, WrVirtualMemory, 0, 0, 0);
300 
301  /* Reacquire the expansion lock */
303 
304  /* Makes sure we still have the delete flag and no attached processes */
307  }
308 
309  /* Check if the session is in the workingset expansion list */
310  if (SessionGlobal->Vm.WorkingSetExpansionLinks.Flink != NULL)
311  {
312  /* Remove the session from the list and zero the list entry */
314  SessionGlobal->Vm.WorkingSetExpansionLinks.Flink = 0;
315  }
316 
317  /* Check if the session is in the workingset list */
318  if (SessionGlobal->WsListEntry.Flink)
319  {
320  /* Remove the session from the list and zero the list entry */
321  RemoveEntryList(&SessionGlobal->WsListEntry);
322  SessionGlobal->WsListEntry.Flink = NULL;
323  }
324 
325  /* Release the expansion lock */
327 
328  /* Check for a win32k unload routine */
329  if (SessionGlobal->Win32KDriverUnload)
330  {
331  /* Call it */
332  SessionGlobal->Win32KDriverUnload(NULL);
333  }
334 }
MMSUPPORT Vm
Definition: miarm.h:505
FORCEINLINE KIRQL MiAcquireExpansionLock(VOID)
Definition: miarm.h:1536
PMM_SESSION_SPACE MmSessionSpace
Definition: session.c:21
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
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
PDRIVER_UNLOAD Win32KDriverUnload
Definition: miarm.h:507
LIST_ENTRY WsListEntry
Definition: miarm.h:500
#define FALSE
Definition: types.h:117
KIRQL OldIrql
Definition: mm.h:1502
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
MM_SESSION_SPACE_FLAGS Flags
Definition: miarm.h:480
struct _MM_SESSION_SPACE * GlobalVirtualAddress
Definition: miarm.h:475
LIST_ENTRY WorkingSetExpansionLinks
Definition: mmtypes.h:922
union _MM_SESSION_SPACE::@1790 u
#define ASSERT(a)
Definition: mode.c:44
KEVENT AttachEvent
Definition: miarm.h:497
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NULL
Definition: types.h:112
FORCEINLINE VOID MiReleaseExpansionLock(KIRQL OldIrql)
Definition: miarm.h:1549
ULONG AttachCount
Definition: miarm.h:496

Referenced by MiDereferenceSession().

◆ MiInitializeSessionIds()

VOID NTAPI MiInitializeSessionIds ( VOID  )

Definition at line 116 of file session.c.

117 {
118  ULONG Size, BitmapSize;
119  PFN_NUMBER TotalPages;
120 
121  /* Setup the total number of data pages needed for the structure */
122  TotalPages = MI_SESSION_DATA_PAGES_MAXIMUM;
125  TotalPages -= MiSessionDataPages;
126 
127  /* Setup the number of pages needed for session pool tags */
131  ASSERT(MiSessionTagPages <= TotalPages);
133 
134  /* Total pages needed for a session (FIXME: Probably different on PAE/x64) */
136 
137  /* Initialize the lock */
139 
140  /* Allocate the bitmap */
142  BitmapSize = ((Size + 31) / 32) * sizeof(ULONG);
144  sizeof(RTL_BITMAP) + BitmapSize,
145  TAG_MM);
146  if (MiSessionIdBitmap)
147  {
148  /* Free all the bits */
150  (PVOID)(MiSessionIdBitmap + 1),
151  Size);
153  }
154  else
155  {
156  /* Die if we couldn't allocate the bitmap */
157  KeBugCheckEx(INSTALL_MORE_MEMORY,
161  0x200);
162  }
163 }
PFN_NUMBER MiSessionTagSizePages
Definition: session.c:22
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define MI_SESSION_TAG_PAGES_MAXIMUM
Definition: miarm.h:253
PFN_NUMBER MiSessionCreateCharge
Definition: session.c:23
NTSYSAPI void WINAPI RtlInitializeBitMap(PRTL_BITMAP, PULONG, ULONG)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
PFN_NUMBER MmLowestPhysicalPage
Definition: meminit.c:30
KGUARDED_MUTEX MiSessionIdMutex
Definition: session.c:24
PFN_NUMBER MiSessionTagPages
Definition: session.c:22
ULONG PFN_NUMBER
Definition: ke.h:9
#define TAG_MM
Definition: tag.h:136
#define ASSERT(a)
Definition: mode.c:44
PRTL_BITMAP MiSessionIdBitmap
Definition: session.c:26
PFN_NUMBER MiSessionDataPages
Definition: session.c:22
#define MI_SESSION_DATA_PAGES_MAXIMUM
Definition: miarm.h:252
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define MI_INITIAL_SESSION_IDS
Definition: miarm.h:212
PFN_COUNT MmNumberOfPhysicalPages
Definition: init.c:48
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
#define ROUND_TO_PAGES(Size)
NTSYSAPI void WINAPI RtlClearAllBits(PRTL_BITMAP)
unsigned int ULONG
Definition: retypes.h:1
PFN_NUMBER MmHighestPhysicalPage
Definition: meminit.c:31
PFN_NUMBER MiSessionBigPoolPages
Definition: session.c:23
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:108

Referenced by MmInitSystem().

◆ MiInitializeSessionWsSupport()

VOID NTAPI MiInitializeSessionWsSupport ( VOID  )

Definition at line 40 of file session.c.

41 {
42  /* Initialize the list heads */
44 }
LIST_ENTRY MiSessionWsList
Definition: session.c:29
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944

Referenced by MmInitSystem().

◆ MiReleaseProcessReferenceToSessionDataPage()

VOID NTAPI MiReleaseProcessReferenceToSessionDataPage ( IN PMM_SESSION_SPACE  SessionGlobal)

Definition at line 209 of file session.c.

210 {
211  ULONG i, SessionId;
212  PMMPTE PointerPte;
214  PMMPFN Pfn1;
215  KIRQL OldIrql;
216 
217  /* Is there more than just this reference? If so, bail out */
218  if (InterlockedDecrement(&SessionGlobal->ProcessReferenceToSession)) return;
219 
220  /* Get the session ID */
221  SessionId = SessionGlobal->SessionId;
222  DPRINT1("Last process in session %lu going down!!!\n", SessionId);
223 
224  /* Free the session page tables */
225 #ifndef _M_AMD64
226  ExFreePoolWithTag(SessionGlobal->PageTables, 'tHmM');
227 #endif
228  ASSERT(!MI_IS_PHYSICAL_ADDRESS(SessionGlobal));
229 
230  /* Capture the data page PFNs */
231  PointerPte = MiAddressToPte(SessionGlobal);
232  for (i = 0; i < MiSessionDataPages; i++)
233  {
234  PageFrameIndex[i] = PFN_FROM_PTE(PointerPte + i);
235  }
236 
237  /* Release them */
239 
240  /* Mark them as deleted */
241  for (i = 0; i < MiSessionDataPages; i++)
242  {
243  Pfn1 = MI_PFN_ELEMENT(PageFrameIndex[i]);
244  MI_SET_PFN_DELETED(Pfn1);
245  }
246 
247  /* Loop every data page and drop a reference count */
248  OldIrql = MiAcquirePfnLock();
249  for (i = 0; i < MiSessionDataPages; i++)
250  {
251  /* Sanity check that the page is correct, then decrement it */
252  Pfn1 = MI_PFN_ELEMENT(PageFrameIndex[i]);
253  ASSERT(Pfn1->u2.ShareCount == 1);
254  ASSERT(Pfn1->u3.e2.ReferenceCount == 1);
255  MiDecrementShareCount(Pfn1, PageFrameIndex[i]);
256  }
257 
258  /* Done playing with pages, release the lock */
259  MiReleasePfnLock(OldIrql);
260 
261  /* Decrement the number of data pages */
263 
264  /* Free this session ID from the session bitmap */
269 }
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
ULONG SessionId
Definition: dllmain.c:28
union _MMPFN::@1761 u3
#define RtlCheckBit(BMH, BP)
Definition: rtlfuncs.h:3152
KGUARDED_MUTEX MiSessionIdMutex
Definition: session.c:24
LONG MmSessionDataPages
Definition: session.c:25
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define MiAddressToPte(x)
Definition: mmx86.c:19
ULONG PFN_NUMBER
Definition: ke.h:9
ULONG_PTR ShareCount
Definition: mm.h:379
VOID NTAPI MiDecrementShareCount(IN PMMPFN Pfn1, IN PFN_NUMBER PageFrameIndex)
Definition: pfnlist.c:1143
VOID NTAPI MiReleaseSystemPtes(IN PMMPTE StartingPte, IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:264
union _MMPFN::@1760 u2
KIRQL OldIrql
Definition: mm.h:1502
#define ASSERT(a)
Definition: mode.c:44
PRTL_BITMAP MiSessionIdBitmap
Definition: session.c:26
PFN_NUMBER MiSessionDataPages
Definition: session.c:22
#define MI_SESSION_DATA_PAGES_MAXIMUM
Definition: miarm.h:252
VOID NTAPI RtlClearBit(_In_ PRTL_BITMAP BitMapHeader, _In_ BITMAP_INDEX BitNumber)
Definition: bitmap.c:294
FORCEINLINE PMMPFN MI_PFN_ELEMENT(IN PFN_NUMBER Pfn)
Definition: miarm.h:1579
#define InterlockedDecrement
Definition: armddk.h:52
Definition: mm.h:362
#define MI_SET_PFN_DELETED(x)
Definition: miarm.h:194
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
struct _MMPFN::@1761::@1767 e2
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
FORCEINLINE BOOLEAN MI_IS_PHYSICAL_ADDRESS(IN PVOID Address)
Definition: miarm.h:950
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define PFN_FROM_PTE(v)
Definition: mm.h:92

Referenced by MiDereferenceSession(), and MmDeleteProcessAddressSpace().

◆ MiSessionAddProcess()

VOID NTAPI MiSessionAddProcess ( IN PEPROCESS  NewProcess)

Definition at line 423 of file session.c.

424 {
425  PMM_SESSION_SPACE SessionGlobal;
426  KIRQL OldIrql;
427 
428  /* The current process must already be in a session */
430 
431  /* Sanity check */
433 
434  /* Get the global session */
435  SessionGlobal = MmSessionSpace->GlobalVirtualAddress;
436 
437  /* Increment counters */
438  InterlockedIncrement((PLONG)&SessionGlobal->ReferenceCount);
441 
442  /* Set the session pointer */
443  ASSERT(NewProcess->Session == NULL);
444  NewProcess->Session = SessionGlobal;
445 
446  /* Acquire the expansion lock while touching the session */
448 
449  /* Insert it into the process list */
450  InsertTailList(&SessionGlobal->ProcessList, &NewProcess->SessionProcessLinks);
451 
452  /* Release the lock again */
454 
455  /* Set the flag */
457 }
LIST_ENTRY ProcessList
Definition: miarm.h:483
LONG ReferenceCount
Definition: miarm.h:476
FORCEINLINE KIRQL MiAcquireExpansionLock(VOID)
Definition: miarm.h:1536
LONG ProcessReferenceToSession
Definition: miarm.h:499
#define TRUE
Definition: types.h:120
PMM_SESSION_SPACE MmSessionSpace
Definition: session.c:21
#define PSF_PROCESS_IN_SESSION_BIT
Definition: pstypes.h:288
#define InsertTailList(ListHead, Entry)
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define PsGetCurrentProcess
Definition: psfuncs.h:17
KIRQL OldIrql
Definition: mm.h:1502
struct _MM_SESSION_SPACE * GlobalVirtualAddress
Definition: miarm.h:475
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define ASSERT(a)
Definition: mode.c:44
BOOLEAN NTAPI MmIsAddressValid(IN PVOID VirtualAddress)
Definition: mmsup.c:174
#define InterlockedIncrement
Definition: armddk.h:53
LONG ResidentProcessCount
Definition: miarm.h:492
#define NULL
Definition: types.h:112
FORCEINLINE VOID MiReleaseExpansionLock(KIRQL OldIrql)
Definition: miarm.h:1549
#define PspSetProcessFlag(Process, Flag)
Definition: ps_x.h:33
signed int * PLONG
Definition: retypes.h:5

Referenced by MmCreateProcessAddressSpace().

◆ MiSessionCreateInternal()

NTSTATUS NTAPI MiSessionCreateInternal ( OUT PULONG  SessionId)

Definition at line 599 of file session.c.

600 {
602  ULONG NewFlags, Flags, i, Color;
603 #if (_MI_PAGING_LEVELS < 3)
604  ULONG Size;
605 #endif // (_MI_PAGING_LEVELS < 3)
606  PMMPDE PageTables = NULL;
607  KIRQL OldIrql;
608  PMMPTE PointerPte, SessionPte;
609  PMMPDE PointerPde;
610  PMM_SESSION_SPACE SessionGlobal;
611  MMPTE TempPte;
612  MMPDE TempPde;
614  BOOLEAN Result;
615  PFN_NUMBER SessionPageDirIndex;
618 
619  /* This should not exist yet */
621 
622  /* Loop so we can set the session-is-creating flag */
623  Flags = Process->Flags;
624  while (TRUE)
625  {
626  /* Check if it's already set */
628  {
629  /* Bail out */
630  DPRINT1("Lost session race\n");
632  }
633 
634  /* Now try to set it */
635  NewFlags = InterlockedCompareExchange((PLONG)&Process->Flags,
637  Flags);
638  if (NewFlags == Flags) break;
639 
640  /* It changed, try again */
641  Flags = NewFlags;
642  }
643 
644  /* Now we should own the flag */
646 
647 #if (_MI_PAGING_LEVELS < 3)
648  /*
649  * Session space covers everything from 0xA0000000 to 0xC0000000.
650  * Allocate enough page tables to describe the entire region
651  */
652  Size = (0x20000000 / PDE_MAPPED_VA) * sizeof(MMPTE);
653  PageTables = ExAllocatePoolWithTag(NonPagedPool, Size, 'tHmM');
654  ASSERT(PageTables != NULL);
655  RtlZeroMemory(PageTables, Size);
656 #endif // (_MI_PAGING_LEVELS < 3)
657 
658  /* Lock the session ID creation mutex */
660 
661  /* Allocate a new Session ID */
663  if (*SessionId == 0xFFFFFFFF)
664  {
665  /* We ran out of session IDs, we should expand */
666  DPRINT1("Too many sessions created. Expansion not yet supported\n");
667 #if (_MI_PAGING_LEVELS < 3)
668  ExFreePoolWithTag(PageTables, 'tHmM');
669 #endif // (_MI_PAGING_LEVELS < 3)
670  return STATUS_NO_MEMORY;
671  }
672 
673  /* Unlock the session ID creation mutex */
675 
676  /* Reserve the global PTEs */
678  ASSERT(SessionPte != NULL);
679 
680  /* Acquire the PFN lock while we set everything up */
681  OldIrql = MiAcquirePfnLock();
682 
683  /* Loop the global PTEs */
685  for (i = 0; i < MiSessionDataPages; i++)
686  {
687  /* Get a zeroed colored zero page */
690  DataPage[i] = MiRemoveZeroPageSafe(Color);
691  if (!DataPage[i])
692  {
693  /* No zero pages, grab a free one */
694  DataPage[i] = MiRemoveAnyPage(Color);
695 
696  /* Zero it outside the PFN lock */
697  MiReleasePfnLock(OldIrql);
698  MiZeroPhysicalPage(DataPage[i]);
699  OldIrql = MiAcquirePfnLock();
700  }
701 
702  /* Fill the PTE out */
703  TempPte.u.Hard.PageFrameNumber = DataPage[i];
704  MI_WRITE_VALID_PTE(SessionPte + i, TempPte);
705  }
706 
707  /* Set the pointer to global space */
708  SessionGlobal = MiPteToAddress(SessionPte);
709 
710  /* Get a zeroed colored zero page */
713  SessionPageDirIndex = MiRemoveZeroPageSafe(Color);
714  if (!SessionPageDirIndex)
715  {
716  /* No zero pages, grab a free one */
717  SessionPageDirIndex = MiRemoveAnyPage(Color);
718 
719  /* Zero it outside the PFN lock */
720  MiReleasePfnLock(OldIrql);
721  MiZeroPhysicalPage(SessionPageDirIndex);
722  OldIrql = MiAcquirePfnLock();
723  }
724 
725  /* Fill the PTE out */
727  TempPde.u.Hard.PageFrameNumber = SessionPageDirIndex;
728 
729  /* Setup, allocate, fill out the MmSessionSpace PTE */
730  PointerPde = MiAddressToPde(MmSessionSpace);
731  ASSERT(PointerPde->u.Long == 0);
732  MI_WRITE_VALID_PDE(PointerPde, TempPde);
733  MiInitializePfnForOtherProcess(SessionPageDirIndex,
734  PointerPde,
735  SessionPageDirIndex);
736  ASSERT(MI_PFN_ELEMENT(SessionPageDirIndex)->u1.WsIndex == 0);
737 
738  /* Loop all the local PTEs for it */
740  PointerPte = MiAddressToPte(MmSessionSpace);
741  for (i = 0; i < MiSessionDataPages; i++)
742  {
743  /* And fill them out */
744  TempPte.u.Hard.PageFrameNumber = DataPage[i];
745  MiInitializePfnAndMakePteValid(DataPage[i], PointerPte + i, TempPte);
746  ASSERT(MI_PFN_ELEMENT(DataPage[i])->u1.WsIndex == 0);
747  }
748 
749  /* Finally loop all of the session pool tag pages */
750  for (i = 0; i < MiSessionTagPages; i++)
751  {
752  /* Grab a zeroed colored page */
755  TagPage[i] = MiRemoveZeroPageSafe(Color);
756  if (!TagPage[i])
757  {
758  /* No zero pages, grab a free one */
759  TagPage[i] = MiRemoveAnyPage(Color);
760 
761  /* Zero it outside the PFN lock */
762  MiReleasePfnLock(OldIrql);
763  MiZeroPhysicalPage(TagPage[i]);
764  OldIrql = MiAcquirePfnLock();
765  }
766 
767  /* Fill the PTE out */
768  TempPte.u.Hard.PageFrameNumber = TagPage[i];
770  PointerPte + MiSessionDataPages + i,
771  TempPte);
772  }
773 
774  /* PTEs have been setup, release the PFN lock */
775  MiReleasePfnLock(OldIrql);
776 
777  /* Fill out the session space structure now */
778  MmSessionSpace->GlobalVirtualAddress = SessionGlobal;
784  MmSessionSpace->SessionPageDirectoryIndex = SessionPageDirIndex;
788 #ifndef _M_AMD64
789  MmSessionSpace->PageTables = PageTables;
790  MmSessionSpace->PageTables[PointerPde - MiAddressToPde(MmSessionBase)] = *PointerPde;
791 #endif
793 
794  DPRINT1("Session %lu is ready to go: 0x%p 0x%p, %lx 0x%p\n",
795  *SessionId, MmSessionSpace, SessionGlobal, SessionPageDirIndex, PageTables);
796 
797  /* Initialize session pool */
798  //Status = MiInitializeSessionPool();
801 
802  /* Initialize system space */
803  Result = MiInitializeSystemSpaceMap(&SessionGlobal->Session);
804  ASSERT(Result == TRUE);
805 
806  /* Initialize the process list, make sure the workign set list is empty */
807  ASSERT(SessionGlobal->WsListEntry.Flink == NULL);
808  ASSERT(SessionGlobal->WsListEntry.Blink == NULL);
809  InitializeListHead(&SessionGlobal->ProcessList);
810 
811  /* We're done, clear the flag */
814 
815  /* Insert the process into the session */
816  ASSERT(Process->Session == NULL);
817  ASSERT(SessionGlobal->ProcessReferenceToSession == 0);
818  SessionGlobal->ProcessReferenceToSession = 1;
819 
820  /* We're done */
822  return STATUS_SUCCESS;
823 }
ULONG SessionId
Definition: miarm.h:482
LIST_ENTRY ProcessList
Definition: miarm.h:483
#define PspClearProcessFlag(Process, Flag)
Definition: ps_x.h:35
SIZE_T NonPageablePages
Definition: miarm.h:486
#define MI_SESSION_TAG_PAGES_MAXIMUM
Definition: miarm.h:253
LONG ReferenceCount
Definition: miarm.h:476
#define MiAddressToPde(x)
Definition: mmx86.c:20
#define PSF_SESSION_CREATION_UNDERWAY_BIT
Definition: pstypes.h:286
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
PMMPDE PageTables
Definition: miarm.h:512
LONG ProcessReferenceToSession
Definition: miarm.h:499
#define TRUE
Definition: types.h:120
PMMPTE NTAPI MiReserveSystemPtes(IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:246
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
ULONG SessionId
Definition: dllmain.c:28
PFN_NUMBER MiSessionCreateCharge
Definition: session.c:23
LONG NTSTATUS
Definition: precomp.h:26
PMM_SESSION_SPACE MmSessionSpace
Definition: session.c:21
#define MI_GET_NEXT_COLOR()
Definition: miarm.h:237
LCID PsDefaultSystemLocaleId
Definition: locale.c:20
HARDWARE_PDE_ARMV6 TempPde
Definition: winldr.c:78
#define InterlockedCompareExchange
Definition: interlocked.h:104
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
VOID NTAPI MiInitializePfnForOtherProcess(IN PFN_NUMBER PageFrameIndex, IN PVOID PteAddress, IN PFN_NUMBER PteFrame)
Definition: pfnlist.c:1292
KGUARDED_MUTEX MiSessionIdMutex
Definition: session.c:24
VOID NTAPI MiZeroPhysicalPage(IN PFN_NUMBER PageFrameIndex)
Definition: pfnlist.c:122
GLdouble u1
Definition: glext.h:8308
struct Color Color
PFN_NUMBER MiSessionTagPages
Definition: session.c:22
LONG MmSessionDataPages
Definition: session.c:25
#define STATUS_ALREADY_COMMITTED
Definition: ntstatus.h:270
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID MmSessionBase
Definition: init.c:33
#define MiAddressToPte(x)
Definition: mmx86.c:19
ULONG PFN_NUMBER
Definition: ke.h:9
LIST_ENTRY WsListEntry
Definition: miarm.h:500
#define FALSE
Definition: types.h:117
FORCEINLINE VOID MI_WRITE_VALID_PTE(IN PMMPTE PointerPte, IN MMPTE TempPte)
Definition: miarm.h:964
#define PsGetCurrentProcess
Definition: psfuncs.h:17
FORCEINLINE PFN_NUMBER MiRemoveZeroPageSafe(IN ULONG Color)
Definition: miarm.h:2420
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
NTSYSAPI ULONG WINAPI RtlFindClearBitsAndSet(PRTL_BITMAP, ULONG, ULONG)
FORCEINLINE VOID MI_WRITE_VALID_PDE(IN PMMPDE PointerPde, IN MMPDE TempPde)
Definition: miarm.h:1023
#define MI_SET_USAGE(x)
Definition: mm.h:306
KIRQL OldIrql
Definition: mm.h:1502
ULONG LongFlags
Definition: miarm.h:479
Status
Definition: gdiplustypes.h:24
ULONG PageFrameNumber
Definition: mmtypes.h:74
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
struct _MM_SESSION_SPACE * GlobalVirtualAddress
Definition: miarm.h:475
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
union _MM_SESSION_SPACE::@1790 u
#define ASSERT(a)
Definition: mode.c:44
SIZE_T CommittedPages
Definition: miarm.h:487
PRTL_BITMAP MiSessionIdBitmap
Definition: session.c:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
MMSESSION Session
Definition: miarm.h:502
BOOLEAN NTAPI MiInitializeSystemSpaceMap(IN PMMSESSION InputSession OPTIONAL)
Definition: section.c:240
MMPTE ValidKernelPteLocal
Definition: init.c:33
PFN_NUMBER MiSessionDataPages
Definition: session.c:22
#define MI_SESSION_DATA_PAGES_MAXIMUM
Definition: miarm.h:252
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
MMPTE ValidKernelPte
Definition: init.c:29
BOOLEAN NTAPI MmIsAddressValid(IN PVOID VirtualAddress)
Definition: mmsup.c:174
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
FORCEINLINE PMMPFN MI_PFN_ELEMENT(IN PFN_NUMBER Pfn)
Definition: miarm.h:1579
LIST_ENTRY ImageList
Definition: miarm.h:494
MMPTE ValidKernelPdeLocal
Definition: init.c:32
ULONG_PTR Long
Definition: mmtypes.h:215
PFN_NUMBER NTAPI MiRemoveAnyPage(IN ULONG Color)
Definition: pfnlist.c:477
#define InterlockedIncrement
Definition: armddk.h:53
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 InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
LONG ResidentProcessCount
Definition: miarm.h:492
#define NULL
Definition: types.h:112
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
#define DPRINT1
Definition: precomp.h:8
ULONG WsIndex
Definition: mm.h:367
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
VOID NTAPI MiInitializePfnAndMakePteValid(IN PFN_NUMBER PageFrameIndex, IN PMMPTE PointerPte, IN MMPTE TempPte)
Definition: pfnlist.c:1043
unsigned int ULONG
Definition: retypes.h:1
#define PDE_MAPPED_VA
Definition: mm.h:39
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
FORCEINLINE PVOID MiPteToAddress(PMMPTE PointerPte)
Definition: mm.h:201
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
signed int * PLONG
Definition: retypes.h:5
union _MMPTE::@2287 u
ULONG PageFrameNumber
Definition: mmtypes.h:109
PFN_NUMBER SessionPageDirectoryIndex
Definition: miarm.h:485

Referenced by MmSessionCreate().

◆ MiSessionInitializeWorkingSetList()

NTSTATUS NTAPI MiSessionInitializeWorkingSetList ( VOID  )

Definition at line 461 of file session.c.

462 {
463  KIRQL OldIrql;
464  PMMPTE PointerPte;
465  PMMPDE PointerPde;
466  MMPTE TempPte;
467  MMPDE TempPde;
468  ULONG Color, Index;
469  PFN_NUMBER PageFrameIndex;
470  PMM_SESSION_SPACE SessionGlobal;
471  BOOLEAN AllocatedPageTable;
472  PMMWSL WorkingSetList;
473 
474  /* Get pointers to session global and the session working set list */
475  SessionGlobal = MmSessionSpace->GlobalVirtualAddress;
476  WorkingSetList = (PMMWSL)MiSessionSpaceWs;
477 
478  /* Fill out the two pointers */
479  MmSessionSpace->Vm.VmWorkingSetList = WorkingSetList;
480  MmSessionSpace->Wsle = (PMMWSLE)((&WorkingSetList->VadBitMapHint) + 1);
481 
482  /* Get the PDE for the working set, and check if it's already allocated */
483  PointerPde = MiAddressToPde(WorkingSetList);
484  if (PointerPde->u.Hard.Valid == 1)
485  {
486  /* Nope, we'll have to do it */
487 #ifndef _M_ARM
488  ASSERT(PointerPde->u.Hard.Global == 0);
489 #endif
490  AllocatedPageTable = FALSE;
491  }
492  else
493  {
494  /* Yep, that makes our job easier */
495  AllocatedPageTable = TRUE;
496  }
497 
498  /* Get the PTE for the working set */
499  PointerPte = MiAddressToPte(WorkingSetList);
500 
501  /* Initialize the working set lock, and lock the PFN database */
502  ExInitializePushLock(&SessionGlobal->Vm.WorkingSetMutex);
503  //MmLockPageableSectionByHandle(ExPageLockHandle);
504  OldIrql = MiAcquirePfnLock();
505 
506  /* Check if we need a page table */
507  if (AllocatedPageTable != FALSE)
508  {
509  /* Get a zeroed colored zero page */
512  PageFrameIndex = MiRemoveZeroPageSafe(Color);
513  if (!PageFrameIndex)
514  {
515  /* No zero pages, grab a free one */
516  PageFrameIndex = MiRemoveAnyPage(Color);
517 
518  /* Zero it outside the PFN lock */
519  MiReleasePfnLock(OldIrql);
520  MiZeroPhysicalPage(PageFrameIndex);
521  OldIrql = MiAcquirePfnLock();
522  }
523 
524  /* Write a valid PDE for it */
526  TempPde.u.Hard.PageFrameNumber = PageFrameIndex;
527  MI_WRITE_VALID_PDE(PointerPde, TempPde);
528 
529  /* Add this into the list */
530  Index = ((ULONG_PTR)WorkingSetList - (ULONG_PTR)MmSessionBase) >> 22;
531 #ifndef _M_AMD64
533 #endif
534  /* Initialize the page directory page, and now zero the working set list itself */
535  MiInitializePfnForOtherProcess(PageFrameIndex,
536  PointerPde,
538  KeZeroPages(PointerPte, PAGE_SIZE);
539  }
540 
541  /* Get a zeroed colored zero page */
544  PageFrameIndex = MiRemoveZeroPageSafe(Color);
545  if (!PageFrameIndex)
546  {
547  /* No zero pages, grab a free one */
548  PageFrameIndex = MiRemoveAnyPage(Color);
549 
550  /* Zero it outside the PFN lock */
551  MiReleasePfnLock(OldIrql);
552  MiZeroPhysicalPage(PageFrameIndex);
553  OldIrql = MiAcquirePfnLock();
554  }
555 
556  /* Write a valid PTE for it */
559  TempPte.u.Hard.PageFrameNumber = PageFrameIndex;
560 
561  /* Initialize the working set list page */
562  MiInitializePfnAndMakePteValid(PageFrameIndex, PointerPte, TempPte);
563 
564  /* Now we can release the PFN database lock */
565  MiReleasePfnLock(OldIrql);
566 
567  /* Fill out the working set structure */
571  WorkingSetList->LastEntry = 20;
572  WorkingSetList->HashTable = NULL;
573  WorkingSetList->HashTableSize = 0;
574  WorkingSetList->Wsle = MmSessionSpace->Wsle;
575 
576  /* Acquire the expansion lock while touching the session */
578 
579  /* Handle list insertions */
580  ASSERT(SessionGlobal->WsListEntry.Flink == NULL);
581  ASSERT(SessionGlobal->WsListEntry.Blink == NULL);
582  InsertTailList(&MiSessionWsList, &SessionGlobal->WsListEntry);
583 
584  ASSERT(SessionGlobal->Vm.WorkingSetExpansionLinks.Flink == NULL);
585  ASSERT(SessionGlobal->Vm.WorkingSetExpansionLinks.Blink == NULL);
587  &SessionGlobal->Vm.WorkingSetExpansionLinks);
588 
589  /* Release the lock again */
591 
592  /* All done, return */
593  //MmUnlockPageableImageSection(ExPageLockHandle);
594  return STATUS_SUCCESS;
595 }
MMSUPPORT Vm
Definition: miarm.h:505
#define MiAddressToPde(x)
Definition: mmx86.c:20
FORCEINLINE KIRQL MiAcquireExpansionLock(VOID)
Definition: miarm.h:1536
PMMPDE PageTables
Definition: miarm.h:512
#define TRUE
Definition: types.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
PMMWSL VmWorkingSetList
Definition: mmtypes.h:940
PMM_SESSION_SPACE MmSessionSpace
Definition: session.c:21
#define MI_GET_NEXT_COLOR()
Definition: miarm.h:237
HARDWARE_PDE_ARMV6 TempPde
Definition: winldr.c:78
VOID NTAPI MiInitializePfnForOtherProcess(IN PFN_NUMBER PageFrameIndex, IN PVOID PteAddress, IN PFN_NUMBER PteFrame)
Definition: pfnlist.c:1292
PVOID MiSessionSpaceWs
Definition: mminit.c:130
VOID NTAPI MiZeroPhysicalPage(IN PFN_NUMBER PageFrameIndex)
Definition: pfnlist.c:122
ULONG MinimumWorkingSetSize
Definition: mmtypes.h:938
#define InsertTailList(ListHead, Entry)
LIST_ENTRY MmWorkingSetExpansionHead
Definition: session.c:30
ULONG64 Global
Definition: mmtypes.h:166
struct Color Color
uint32_t ULONG_PTR
Definition: typedefs.h:65
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define MI_MAKE_DIRTY_PAGE(x)
Definition: mm.h:98
PVOID MmSessionBase
Definition: init.c:33
#define MiAddressToPte(x)
Definition: mmx86.c:19
ULONG PFN_NUMBER
Definition: ke.h:9
LIST_ENTRY WsListEntry
Definition: miarm.h:500
#define FALSE
Definition: types.h:117
ULONG SessionSpace
Definition: mmtypes.h:902
FORCEINLINE PFN_NUMBER MiRemoveZeroPageSafe(IN ULONG Color)
Definition: miarm.h:2420
unsigned char BOOLEAN
#define ExInitializePushLock
Definition: ex.h:1011
FORCEINLINE VOID MI_WRITE_VALID_PDE(IN PMMPDE PointerPde, IN MMPDE TempPde)
Definition: miarm.h:1023
#define MI_SET_USAGE(x)
Definition: mm.h:306
KIRQL OldIrql
Definition: mm.h:1502
ULONG PageFrameNumber
Definition: mmtypes.h:74
MMSUPPORT_FLAGS Flags
Definition: mmtypes.h:930
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
EX_PUSH_LOCK WorkingSetMutex
Definition: mmtypes.h:958
struct _MM_SESSION_SPACE * GlobalVirtualAddress
Definition: miarm.h:475
LIST_ENTRY WorkingSetExpansionLinks
Definition: mmtypes.h:922
VOID FASTCALL KeZeroPages(IN PVOID Address, IN ULONG Size)
Definition: stubs.c:94
#define ASSERT(a)
Definition: mode.c:44
_In_ WDFCOLLECTION _In_ ULONG Index
MMPTE ValidKernelPteLocal
Definition: init.c:33
ULONG64 Valid
Definition: mmtypes.h:150
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
struct _MMWSL * PMMWSL
PMMWSLE Wsle
Definition: mmtypes.h:872
PMMWSLE_HASH HashTable
Definition: mmtypes.h:875
#define PAGE_SIZE
Definition: env_spec_w32.h:49
LIST_ENTRY MiSessionWsList
Definition: session.c:29
MMPTE ValidKernelPdeLocal
Definition: init.c:32
PFN_NUMBER NTAPI MiRemoveAnyPage(IN ULONG Color)
Definition: pfnlist.c:477
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
ULONG HashTableSize
Definition: mmtypes.h:876
PMMWSLE Wsle
Definition: miarm.h:506
#define NULL
Definition: types.h:112
FORCEINLINE VOID MiReleaseExpansionLock(KIRQL OldIrql)
Definition: miarm.h:1549
VOID NTAPI MiInitializePfnAndMakePteValid(IN PFN_NUMBER PageFrameIndex, IN PMMPTE PointerPte, IN MMPTE TempPte)
Definition: pfnlist.c:1043
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG MaximumWorkingSetSize
Definition: mmtypes.h:939
ULONG LastEntry
Definition: mmtypes.h:870
union _MMPTE::@2287 u
struct _MMWSLE * PMMWSLE
ULONG PageFrameNumber
Definition: mmtypes.h:109
PFN_NUMBER SessionPageDirectoryIndex
Definition: miarm.h:485
ULONG VadBitMapHint
Definition: mmtypes.h:881

Referenced by MmSessionCreate().

◆ MiSessionLeader()

VOID NTAPI MiSessionLeader ( IN PEPROCESS  Process)

Definition at line 167 of file session.c.

168 {
169  KIRQL OldIrql;
170 
171  /* Set the flag while under the expansion lock */
173  Process->Vm.Flags.SessionLeader = TRUE;
175 }
FORCEINLINE KIRQL MiAcquireExpansionLock(VOID)
Definition: miarm.h:1536
#define TRUE
Definition: types.h:120
UCHAR KIRQL
Definition: env_spec_w32.h:591
KIRQL OldIrql
Definition: mm.h:1502
FORCEINLINE VOID MiReleaseExpansionLock(KIRQL OldIrql)
Definition: miarm.h:1549
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by MmSessionCreate().

◆ MiSessionRemoveProcess()

VOID NTAPI MiSessionRemoveProcess ( VOID  )

Definition at line 392 of file session.c.

393 {
395  KIRQL OldIrql;
396 
397  /* If the process isn't already in a session, or if it's the leader... */
398  if (!(CurrentProcess->Flags & PSF_PROCESS_IN_SESSION_BIT) ||
399  (CurrentProcess->Vm.Flags.SessionLeader))
400  {
401  /* Then there's nothing to do */
402  return;
403  }
404 
405  /* Sanity check */
407 
408  /* Acquire the expansion lock while touching the session */
410 
411  /* Remove the process from the list */
412  RemoveEntryList(&CurrentProcess->SessionProcessLinks);
413 
414  /* Release the lock again */
416 
417  /* Dereference the session */
419 }
FORCEINLINE KIRQL MiAcquireExpansionLock(VOID)
Definition: miarm.h:1536
#define TRUE
Definition: types.h:120
PMM_SESSION_SPACE MmSessionSpace
Definition: session.c:21
#define PSF_PROCESS_IN_SESSION_BIT
Definition: pstypes.h:288
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define PsGetCurrentProcess
Definition: psfuncs.h:17
KIRQL OldIrql
Definition: mm.h:1502
VOID NTAPI MiDereferenceSession(VOID)
Definition: session.c:339
ULONG CurrentProcess
Definition: shell.c:125
#define ASSERT(a)
Definition: mode.c:44
BOOLEAN NTAPI MmIsAddressValid(IN PVOID VirtualAddress)
Definition: mmsup.c:174
FORCEINLINE VOID MiReleaseExpansionLock(KIRQL OldIrql)
Definition: miarm.h:1549

Referenced by MmCleanProcessAddressSpace().

◆ MmGetSessionById()

PVOID NTAPI MmGetSessionById ( _In_ ULONG  SessionId)

Definition at line 1050 of file session.c.

1052 {
1053  PLIST_ENTRY ListEntry;
1054  PMM_SESSION_SPACE Session;
1056  KIRQL OldIrql;
1057 
1058  /* Acquire the expansion lock while touching the session */
1060 
1061  /* Loop all entries in the session ws list */
1062  ListEntry = MiSessionWsList.Flink;
1063  while (ListEntry != &MiSessionWsList)
1064  {
1065  Session = CONTAINING_RECORD(ListEntry, MM_SESSION_SPACE, WsListEntry);
1066  ListEntry = ListEntry->Flink;
1067 
1068  /* Check if this is the session we are looking for */
1069  if (Session->SessionId == SessionId)
1070  {
1071  /* Check if we also have a process in the process list */
1072  if (!IsListEmpty(&Session->ProcessList))
1073  {
1075  EPROCESS,
1076  SessionProcessLinks);
1077 
1078  /* Reference the process */
1080  break;
1081  }
1082  }
1083  }
1084 
1085  /* Release the lock again */
1087 
1088  return Process;
1089 }
ULONG SessionId
Definition: miarm.h:482
LIST_ENTRY ProcessList
Definition: miarm.h:483
FORCEINLINE KIRQL MiAcquireExpansionLock(VOID)
Definition: miarm.h:1536
ULONG SessionId
Definition: dllmain.c:28
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UCHAR KIRQL
Definition: env_spec_w32.h:591
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
KIRQL OldIrql
Definition: mm.h:1502
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: typedefs.h:119
LIST_ENTRY MiSessionWsList
Definition: session.c:29
#define NULL
Definition: types.h:112
FORCEINLINE VOID MiReleaseExpansionLock(KIRQL OldIrql)
Definition: miarm.h:1549
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by ExpWin32SessionCallout().

◆ MmGetSessionId()

ULONG NTAPI MmGetSessionId ( IN PEPROCESS  Process)

Definition at line 179 of file session.c.

180 {
181  PMM_SESSION_SPACE SessionGlobal;
182 
183  /* The session leader is always session zero */
184  if (Process->Vm.Flags.SessionLeader == 1) return 0;
185 
186  /* Otherwise, get the session global, and read the session ID from it */
187  SessionGlobal = (PMM_SESSION_SPACE)Process->Session;
188  if (!SessionGlobal) return 0;
189  return SessionGlobal->SessionId;
190 }
ULONG SessionId
Definition: miarm.h:482
if(dx==0 &&dy==0)
Definition: linetemp.h:174
struct _MM_SESSION_SPACE * PMM_SESSION_SPACE
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by IoGetRequestorSessionId(), MmCreatePeb(), PsGetCurrentProcessSessionId(), PsGetProcessSessionId(), PsGetThreadSessionId(), PspInitializeProcessSecurity(), and SeExchangePrimaryToken().

◆ MmGetSessionIdEx()

ULONG NTAPI MmGetSessionIdEx ( IN PEPROCESS  Process)

Definition at line 194 of file session.c.

195 {
196  PMM_SESSION_SPACE SessionGlobal;
197 
198  /* The session leader is always session zero */
199  if (Process->Vm.Flags.SessionLeader == 1) return 0;
200 
201  /* Otherwise, get the session global, and read the session ID from it */
202  SessionGlobal = (PMM_SESSION_SPACE)Process->Session;
203  if (!SessionGlobal) return -1;
204  return SessionGlobal->SessionId;
205 }
ULONG SessionId
Definition: miarm.h:482
if(dx==0 &&dy==0)
Definition: linetemp.h:174
struct _MM_SESSION_SPACE * PMM_SESSION_SPACE
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by PsGetProcessSessionIdEx().

◆ MmGetSessionLocaleId()

LCID NTAPI MmGetSessionLocaleId ( VOID  )

Definition at line 56 of file session.c.

57 {
59  PAGED_CODE();
60 
61  //
62  // Get the current process
63  //
65 
66  //
67  // Check if it's NOT the Session Leader
68  //
69  if (!Process->Vm.Flags.SessionLeader)
70  {
71  //
72  // Make sure it has a valid Session
73  //
74  if (Process->Session)
75  {
76  //
77  // Get the Locale ID
78  //
79  return ((PMM_SESSION_SPACE)Process->Session)->LocaleId;
80  }
81  }
82 
83  //
84  // Not a session leader, return the default
85  //
87 }
LCID PsDefaultThreadLocaleId
Definition: locale.c:25
#define PsGetCurrentProcess
Definition: psfuncs.h:17
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define PAGED_CODE()

Referenced by NtQueryDefaultLocale(), and PspUserThreadStartup().

◆ MmIsSessionAddress()

BOOLEAN NTAPI MmIsSessionAddress ( IN PVOID  Address)

Definition at line 48 of file session.c.

49 {
50  /* Check if it is in range */
52 }
#define TRUE
Definition: types.h:120
#define MI_IS_SESSION_ADDRESS(Address)
Definition: miarm.h:171
#define FALSE
Definition: types.h:117
static WCHAR Address[46]
Definition: ping.c:68

Referenced by KdpQueryMemory(), and MmDbgCopyMemory().

◆ MmQuitNextSession()

VOID NTAPI MmQuitNextSession ( _Inout_ PVOID  SessionEntry)

Definition at line 1030 of file session.c.

1032 {
1033  PEPROCESS EntryProcess;
1034 
1035  /* The parameter is the actual process! */
1036  EntryProcess = SessionEntry;
1037  ASSERT(EntryProcess != NULL);
1038 
1039  /* Sanity checks */
1041  ASSERT(EntryProcess->Vm.Flags.SessionLeader == 0);
1042  ASSERT(EntryProcess->Session != NULL);
1043 
1044  /* Get rid of the reference we took */
1045  ObDereferenceObject(EntryProcess);
1046 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
ULONG SessionLeader
Definition: mmtypes.h:904
PVOID Session
Definition: pstypes.h:1325
MMSUPPORT_FLAGS Flags
Definition: mmtypes.h:930
#define ASSERT(a)
Definition: mode.c:44
#define ObDereferenceObject
Definition: obfuncs.h:203
MMSUPPORT Vm
Definition: pstypes.h:1356
#define NULL
Definition: types.h:112
#define APC_LEVEL
Definition: env_spec_w32.h:695

Referenced by ExpWin32SessionCallout().

◆ MmSessionCreate()

NTSTATUS NTAPI MmSessionCreate ( OUT PULONG  SessionId)

Definition at line 827 of file session.c.

828 {
830  ULONG SessionLeaderExists;
832 
833  /* Fail if the process is already in a session */
834  if (Process->Flags & PSF_PROCESS_IN_SESSION_BIT)
835  {
836  DPRINT1("Process already in session\n");
838  }
839 
840  /* Check if the process is already the session leader */
841  if (!Process->Vm.Flags.SessionLeader)
842  {
843  /* Atomically set it as the leader */
844  SessionLeaderExists = InterlockedCompareExchange(&MiSessionLeaderExists, 1, 0);
845  if (SessionLeaderExists)
846  {
847  DPRINT1("Session leader race\n");
849  }
850 
851  /* Do the work required to upgrade him */
853  }
854 
855  /* Create the session */
858  if (!NT_SUCCESS(Status))
859  {
861  return Status;
862  }
863 
864  /* Set up the session working set */
866  if (!NT_SUCCESS(Status))
867  {
868  /* Fail */
869  //MiDereferenceSession();
870  ASSERT(FALSE);
872  return Status;
873  }
874 
875  /* All done */
877 
878  /* Set and assert the flags, and return */
882  return Status;
883 }
ULONG SessionId
Definition: dllmain.c:28
LONG NTSTATUS
Definition: precomp.h:26
PMM_SESSION_SPACE MmSessionSpace
Definition: session.c:21
#define InterlockedCompareExchange
Definition: interlocked.h:104
#define PSF_PROCESS_IN_SESSION_BIT
Definition: pstypes.h:288
#define STATUS_ALREADY_COMMITTED
Definition: ntstatus.h:270
VOID NTAPI MiSessionLeader(IN PEPROCESS Process)
Definition: session.c:167
volatile LONG MiSessionLeaderExists
Definition: session.c:27
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI MiSessionInitializeWorkingSetList(VOID)
Definition: session.c:461
#define PsGetCurrentProcess
Definition: psfuncs.h:17
NTSTATUS NTAPI MiSessionCreateInternal(OUT PULONG SessionId)
Definition: session.c:599
Status
Definition: gdiplustypes.h:24
MM_SESSION_SPACE_FLAGS Flags
Definition: miarm.h:480
union _MM_SESSION_SPACE::@1790 u
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#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 PspSetProcessFlag(Process, Flag)
Definition: ps_x.h:33
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_INVALID_SYSTEM_SERVICE
Definition: ntstatus.h:265

Referenced by SSI_DEF().

◆ MmSessionDelete()

NTSTATUS NTAPI MmSessionDelete ( IN ULONG  SessionId)

Definition at line 887 of file session.c.

888 {
890 
891  /* Process must be in a session */
892  if (!(Process->Flags & PSF_PROCESS_IN_SESSION_BIT))
893  {
894  DPRINT1("Not in a session!\n");
896  }
897 
898  /* It must be the session leader */
899  if (!Process->Vm.Flags.SessionLeader)
900  {
901  DPRINT1("Not a session leader!\n");
903  }
904 
905  /* Remove one reference count */
909 
910  /* All done */
911  return STATUS_SUCCESS;
912 }
#define PSF_PROCESS_IN_SESSION_BIT
Definition: pstypes.h:288
#define PsGetCurrentProcess
Definition: psfuncs.h:17
#define STATUS_UNABLE_TO_FREE_VM
Definition: ntstatus.h:263
VOID NTAPI MiDereferenceSession(VOID)
Definition: session.c:339
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#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 STATUS_SUCCESS
Definition: shellext.h:65

Referenced by SSI_DEF().

Variable Documentation

◆ MiExpansionLockOwner

PETHREAD MiExpansionLockOwner

Definition at line 33 of file session.c.

Referenced by MiAcquireExpansionLock(), and MiReleaseExpansionLock().

◆ MiSessionBigPoolPages

PFN_NUMBER MiSessionBigPoolPages

Definition at line 23 of file session.c.

Referenced by MiInitializeSessionIds().

◆ MiSessionCreateCharge

PFN_NUMBER MiSessionCreateCharge

Definition at line 23 of file session.c.

Referenced by MiInitializeSessionIds(), and MiSessionCreateInternal().

◆ MiSessionDataPages

◆ MiSessionIdBitmap

◆ MiSessionIdMutex

◆ MiSessionLeaderExists

volatile LONG MiSessionLeaderExists

Definition at line 27 of file session.c.

Referenced by MmSessionCreate().

◆ MiSessionTagPages

PFN_NUMBER MiSessionTagPages

Definition at line 22 of file session.c.

Referenced by MiInitializeSessionIds(), and MiSessionCreateInternal().

◆ MiSessionTagSizePages

PFN_NUMBER MiSessionTagSizePages

Definition at line 22 of file session.c.

Referenced by MiInitializeSessionIds().

◆ MiSessionWsList

LIST_ENTRY MiSessionWsList

◆ MmExpansionLock

KSPIN_LOCK MmExpansionLock

◆ MmSessionDataPages

LONG MmSessionDataPages

◆ MmSessionSpace

◆ MmWorkingSetExpansionHead

LIST_ENTRY MmWorkingSetExpansionHead