ReactOS  0.4.15-dev-2985-g54406bf
procsup.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Kernel
3  * LICENSE: BSD-3-Clause (https://spdx.org/licenses/BSD-3-Clause.html)
4  * FILE: ntoskrnl/mm/i386/procsup.c
5  * PURPOSE: Process handling for i386 architecture
6  * PROGRAMMERS: Jérôme Gardou
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14 
15 #define MODULE_INVOLVED_IN_ARM3
16 #include <mm/ARM3/miarm.h>
17 
18 BOOLEAN
21  _In_ PULONG_PTR DirectoryTableBase)
22 {
23  PFN_NUMBER PdeIndex = DirectoryTableBase[0] >> PAGE_SHIFT;
24  PFN_NUMBER HyperIndex = DirectoryTableBase[1] >> PAGE_SHIFT;
25  PMMPTE PointerPte;
26  MMPTE PdePte, TempPte;
27  PMMPTE PteTable;
28  ULONG PdeOffset;
29  KIRQL OldIrql;
30 
31  /* Get a PTE */
32  PointerPte = MiReserveSystemPtes(1, SystemPteSpace);
33  if (!PointerPte)
34  return FALSE;
35  PteTable = MiPteToAddress(PointerPte);
36 
37  /* Build a page table for hyper space */
39  PointerPte,
41  HyperIndex);
42 
43  /* Set it dirty and map it */
44  MI_MAKE_DIRTY_PAGE(&PdePte);
45  MI_WRITE_VALID_PTE(PointerPte, PdePte);
46 
47  /* Now write the PTE/PDE entry for the working set list index itself */
49  TempPte.u.Hard.PageFrameNumber = Process->WorkingSetPage;
51  PteTable[PdeOffset] = TempPte;
52 
53  /* Now we map the page directory */
55  PointerPte,
57  PdeIndex);
58 
59  /* Set it dirty and map it */
60  MI_MAKE_DIRTY_PAGE(&PdePte);
61  *PointerPte = PdePte;
62  /* We changed the page! */
63  __invlpg(PteTable);
64 
65  /* Now get the page directory (which we'll double map, so call it a page table) */
66  PteTable = MiPteToAddress(PointerPte);
67 
68  /* Copy all the kernel mappings */
70  RtlCopyMemory(&PteTable[PdeOffset],
72  PAGE_SIZE - PdeOffset * sizeof(MMPTE));
73 
74  /* Now write the PTE/PDE entry for hyperspace itself */
76  TempPte.u.Hard.PageFrameNumber = HyperIndex;
77  PdeOffset = MiGetPdeOffset(HYPER_SPACE);
78  PteTable[PdeOffset] = TempPte;
79 
80  /* Sanity check */
81  PdeOffset++;
82  ASSERT(MiGetPdeOffset(MmHyperSpaceEnd) >= PdeOffset);
83 
84  /* Now do the x86 trick of making the PDE a page table itself */
85  PdeOffset = MiGetPdeOffset(PTE_BASE);
86  TempPte.u.Hard.PageFrameNumber = PdeIndex;
87  PteTable[PdeOffset] = TempPte;
88 
89  /* Let go of the system PTE */
90  MiReleaseSystemPtes(PointerPte, 1, SystemPteSpace);
91 
92  /* Insert us into the Mm process list */
94  InsertTailList(&MmProcessList, &Process->MmProcessLinks);
96 
97  return TRUE;
98 }
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define MiAddressToPde(x)
Definition: mmx86.c:20
FORCEINLINE KIRQL MiAcquireExpansionLock(VOID)
Definition: miarm.h:1536
#define TRUE
Definition: types.h:120
PMMPTE NTAPI MiReserveSystemPtes(IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:246
#define InsertTailList(ListHead, Entry)
#define MiGetPdeOffset(x)
Definition: mm.h:188
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define MI_MAKE_DIRTY_PAGE(x)
Definition: mm.h:98
ULONG PFN_NUMBER
Definition: ke.h:9
#define FALSE
Definition: types.h:117
FORCEINLINE VOID MI_WRITE_VALID_PTE(IN PMMPTE PointerPte, IN MMPTE TempPte)
Definition: miarm.h:964
unsigned char BOOLEAN
#define _In_
Definition: ms_sal.h:308
VOID NTAPI MiReleaseSystemPtes(IN PMMPTE StartingPte, IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:264
KIRQL OldIrql
Definition: mm.h:1502
#define ASSERT(a)
Definition: mode.c:44
MMPTE ValidKernelPteLocal
Definition: init.c:33
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
#define MM_READWRITE
Definition: inbv.c:12
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define PTE_BASE
Definition: mmx86.c:14
PMMWSL MmWorkingSetList
Definition: wslist.cpp:19
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
__INTRIN_INLINE void __invlpg(void *Address)
Definition: intrin_x86.h:1969
#define HYPER_SPACE
Definition: mm.h:14
PVOID MmHyperSpaceEnd
Definition: init.c:56
unsigned int ULONG
Definition: retypes.h:1
uint32_t * PULONG_PTR
Definition: typedefs.h:65
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define MiAddressToPteOffset(x)
Definition: mmx86.c:21
FORCEINLINE VOID MI_MAKE_HARDWARE_PTE_KERNEL(IN PMMPTE NewPte, IN PMMPTE MappingPte, IN ULONG_PTR ProtectionMask, IN PFN_NUMBER PageFrameNumber)
Definition: miarm.h:778
FORCEINLINE PVOID MiPteToAddress(PMMPTE PointerPte)
Definition: mm.h:201
LIST_ENTRY MmProcessList
Definition: largepag.c:20
#define MmSystemRangeStart
Definition: mm.h:32
BOOLEAN MiArchCreateProcessAddressSpace(_In_ PEPROCESS Process, _In_ PULONG_PTR DirectoryTableBase)
Definition: procsup.c:21
ULONG PageFrameNumber
Definition: mmtypes.h:109