[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / mm / ARM3 / procsup.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/mm/ARM3/procsup.c
5 * PURPOSE: ARM Memory Manager Process Related Management
6 * PROGRAMMERS: ReactOS Portable Systems Group
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 "../ARM3/miarm.h"
17
18 /* GLOBALS ********************************************************************/
19
20 ULONG MmProcessColorSeed = 0x12345678;
21 PMMWSL MmWorkingSetList;
22
23 /* PRIVATE FUNCTIONS **********************************************************/
24
25 VOID
26 NTAPI
27 MiRosTakeOverPebTebRanges(IN PEPROCESS Process)
28 {
29 NTSTATUS Status;
30 PMEMORY_AREA MemoryArea;
31 PHYSICAL_ADDRESS BoundaryAddressMultiple;
32 PVOID AllocatedBase = (PVOID)USER_SHARED_DATA;
33 BoundaryAddressMultiple.QuadPart = 0;
34
35 Status = MmCreateMemoryArea(&Process->Vm,
36 MEMORY_AREA_OWNED_BY_ARM3,
37 &AllocatedBase,
38 ((ULONG_PTR)MM_HIGHEST_USER_ADDRESS - 1) -
39 (ULONG_PTR)USER_SHARED_DATA,
40 PAGE_READWRITE,
41 &MemoryArea,
42 TRUE,
43 0,
44 BoundaryAddressMultiple);
45 ASSERT(NT_SUCCESS(Status));
46 }
47
48 NTSTATUS
49 NTAPI
50 MiCreatePebOrTeb(IN PEPROCESS Process,
51 IN ULONG Size,
52 OUT PULONG_PTR Base)
53 {
54 PETHREAD Thread = PsGetCurrentThread();
55 PMMVAD_LONG Vad;
56 NTSTATUS Status;
57 ULONG RandomCoeff;
58 ULONG_PTR StartAddress, EndAddress;
59 LARGE_INTEGER CurrentTime;
60 TABLE_SEARCH_RESULT Result = TableFoundNode;
61 PMMADDRESS_NODE Parent;
62
63 /* Allocate a VAD */
64 Vad = ExAllocatePoolWithTag(NonPagedPool, sizeof(MMVAD_LONG), 'ldaV');
65 if (!Vad) return STATUS_NO_MEMORY;
66
67 /* Setup the primary flags with the size, and make it commited, private, RW */
68 Vad->u.LongFlags = 0;
69 Vad->u.VadFlags.CommitCharge = BYTES_TO_PAGES(Size);
70 Vad->u.VadFlags.MemCommit = TRUE;
71 Vad->u.VadFlags.PrivateMemory = TRUE;
72 Vad->u.VadFlags.Protection = MM_READWRITE;
73 Vad->u.VadFlags.NoChange = TRUE;
74
75 /* Setup the secondary flags to make it a secured, writable, long VAD */
76 Vad->u2.LongFlags2 = 0;
77 Vad->u2.VadFlags2.OneSecured = TRUE;
78 Vad->u2.VadFlags2.LongVad = TRUE;
79 Vad->u2.VadFlags2.ReadOnly = FALSE;
80
81 /* Lock the process address space */
82 KeAcquireGuardedMutex(&Process->AddressCreationLock);
83
84 /* Check if this is a PEB creation */
85 if (Size == sizeof(PEB))
86 {
87 /* Start at the highest valid address */
88 StartAddress = (ULONG_PTR)MM_HIGHEST_VAD_ADDRESS + 1;
89
90 /* Select the random coefficient */
91 KeQueryTickCount(&CurrentTime);
92 CurrentTime.LowPart &= ((64 * _1KB) >> PAGE_SHIFT) - 1;
93 if (CurrentTime.LowPart <= 1) CurrentTime.LowPart = 2;
94 RandomCoeff = CurrentTime.LowPart << PAGE_SHIFT;
95
96 /* Select the highest valid address minus the random coefficient */
97 StartAddress -= RandomCoeff;
98 EndAddress = StartAddress + ROUND_TO_PAGES(Size) - 1;
99
100 /* Try to find something below the random upper margin */
101 Result = MiFindEmptyAddressRangeDownTree(ROUND_TO_PAGES(Size),
102 EndAddress,
103 PAGE_SIZE,
104 &Process->VadRoot,
105 Base,
106 &Parent);
107 }
108
109 /* Check for success. TableFoundNode means nothing free. */
110 if (Result == TableFoundNode)
111 {
112 /* For TEBs, or if a PEB location couldn't be found, scan the VAD root */
113 Result = MiFindEmptyAddressRangeDownTree(ROUND_TO_PAGES(Size),
114 (ULONG_PTR)MM_HIGHEST_VAD_ADDRESS + 1,
115 PAGE_SIZE,
116 &Process->VadRoot,
117 Base,
118 &Parent);
119 /* Bail out, if still nothing free was found */
120 if (Result == TableFoundNode) return STATUS_NO_MEMORY;
121 }
122
123 /* Validate that it came from the VAD ranges */
124 ASSERT(*Base >= (ULONG_PTR)MI_LOWEST_VAD_ADDRESS);
125
126 /* Build the rest of the VAD now */
127 Vad->StartingVpn = (*Base) >> PAGE_SHIFT;
128 Vad->EndingVpn = ((*Base) + Size - 1) >> PAGE_SHIFT;
129 Vad->u3.Secured.StartVpn = *Base;
130 Vad->u3.Secured.EndVpn = (Vad->EndingVpn << PAGE_SHIFT) | (PAGE_SIZE - 1);
131 Vad->u1.Parent = NULL;
132
133 /* FIXME: Should setup VAD bitmap */
134 Status = STATUS_SUCCESS;
135
136 /* Pretend as if we own the working set */
137 MiLockProcessWorkingSet(Process, Thread);
138
139 /* Insert the VAD */
140 ASSERT(Vad->EndingVpn >= Vad->StartingVpn);
141 Process->VadRoot.NodeHint = Vad;
142 Vad->ControlArea = NULL; // For Memory-Area hack
143 Vad->FirstPrototypePte = NULL;
144 DPRINT("VAD: %p\n", Vad);
145 DPRINT("Allocated PEB/TEB at: 0x%p for %16s\n", *Base, Process->ImageFileName);
146 MiInsertNode(&Process->VadRoot, (PVOID)Vad, Parent, Result);
147
148 /* Release the working set */
149 MiUnlockProcessWorkingSet(Process, Thread);
150
151 /* Release the address space lock */
152 KeReleaseGuardedMutex(&Process->AddressCreationLock);
153
154 /* Return the status */
155 return Status;
156 }
157
158 VOID
159 NTAPI
160 MmDeleteTeb(IN PEPROCESS Process,
161 IN PTEB Teb)
162 {
163 ULONG_PTR TebEnd;
164 PETHREAD Thread = PsGetCurrentThread();
165 PMMVAD Vad;
166 PMM_AVL_TABLE VadTree = &Process->VadRoot;
167 DPRINT("Deleting TEB: %p in %16s\n", Teb, Process->ImageFileName);
168
169 /* TEB is one page */
170 TebEnd = (ULONG_PTR)Teb + ROUND_TO_PAGES(sizeof(TEB)) - 1;
171
172 /* Attach to the process */
173 KeAttachProcess(&Process->Pcb);
174
175 /* Lock the process address space */
176 KeAcquireGuardedMutex(&Process->AddressCreationLock);
177
178 /* Find the VAD, make sure it's a TEB VAD */
179 Vad = MiLocateAddress(Teb);
180 DPRINT("Removing node for VAD: %lx %lx\n", Vad->StartingVpn, Vad->EndingVpn);
181 ASSERT(Vad != NULL);
182 if (Vad->StartingVpn != ((ULONG_PTR)Teb >> PAGE_SHIFT))
183 {
184 /* Bug in the AVL code? */
185 DPRINT1("Corrupted VAD!\n");
186 }
187 else
188 {
189 /* Sanity checks for a valid TEB VAD */
190 ASSERT((Vad->StartingVpn == ((ULONG_PTR)Teb >> PAGE_SHIFT) &&
191 (Vad->EndingVpn == (TebEnd >> PAGE_SHIFT))));
192 ASSERT(Vad->u.VadFlags.NoChange == TRUE);
193 ASSERT(Vad->u2.VadFlags2.OneSecured == TRUE);
194 ASSERT(Vad->u2.VadFlags2.MultipleSecured == FALSE);
195
196 /* Lock the working set */
197 MiLockProcessWorkingSet(Process, Thread);
198
199 /* Remove this VAD from the tree */
200 ASSERT(VadTree->NumberGenericTableElements >= 1);
201 MiRemoveNode((PMMADDRESS_NODE)Vad, VadTree);
202
203 /* Release the working set */
204 MiUnlockProcessWorkingSet(Process, Thread);
205
206 /* Remove the VAD */
207 ExFreePool(Vad);
208 }
209
210 /* Release the address space lock */
211 KeReleaseGuardedMutex(&Process->AddressCreationLock);
212
213 /* Detach */
214 KeDetachProcess();
215 }
216
217 VOID
218 NTAPI
219 MmDeleteKernelStack(IN PVOID StackBase,
220 IN BOOLEAN GuiStack)
221 {
222 PMMPTE PointerPte;
223 PFN_NUMBER StackPages, PageFrameNumber;//, PageTableFrameNumber;
224 PMMPFN Pfn1;//, Pfn2;
225 ULONG i;
226 KIRQL OldIrql;
227
228 //
229 // This should be the guard page, so decrement by one
230 //
231 PointerPte = MiAddressToPte(StackBase);
232 PointerPte--;
233
234 //
235 // Calculate pages used
236 //
237 StackPages = BYTES_TO_PAGES(GuiStack ?
238 KERNEL_LARGE_STACK_SIZE : KERNEL_STACK_SIZE);
239
240 /* Acquire the PFN lock */
241 OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
242
243 //
244 // Loop them
245 //
246 for (i = 0; i < StackPages; i++)
247 {
248 //
249 // Check if this is a valid PTE
250 //
251 if (PointerPte->u.Hard.Valid == 1)
252 {
253 /* Get the PTE's page */
254 PageFrameNumber = PFN_FROM_PTE(PointerPte);
255 Pfn1 = MiGetPfnEntry(PageFrameNumber);
256 #if 0 // ARM3 might not own the page table, so don't take this risk. Leak it instead!
257 /* Now get the page of the page table mapping it */
258 PageTableFrameNumber = Pfn1->u4.PteFrame;
259 Pfn2 = MiGetPfnEntry(PageTableFrameNumber);
260
261 /* Remove a shared reference, since the page is going away */
262 MiDecrementShareCount(Pfn2, PageTableFrameNumber);
263 #endif
264 /* Set the special pending delete marker */
265 MI_SET_PFN_DELETED(Pfn1);
266
267 /* And now delete the actual stack page */
268 MiDecrementShareCount(Pfn1, PageFrameNumber);
269 }
270
271 //
272 // Next one
273 //
274 PointerPte--;
275 }
276
277 //
278 // We should be at the guard page now
279 //
280 ASSERT(PointerPte->u.Hard.Valid == 0);
281
282 /* Release the PFN lock */
283 KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
284
285 //
286 // Release the PTEs
287 //
288 MiReleaseSystemPtes(PointerPte, StackPages + 1, SystemPteSpace);
289 }
290
291 PVOID
292 NTAPI
293 MmCreateKernelStack(IN BOOLEAN GuiStack,
294 IN UCHAR Node)
295 {
296 PFN_NUMBER StackPtes, StackPages;
297 PMMPTE PointerPte, StackPte;
298 PVOID BaseAddress;
299 MMPTE TempPte, InvalidPte;
300 KIRQL OldIrql;
301 PFN_NUMBER PageFrameIndex;
302 ULONG i;
303
304 //
305 // Calculate pages needed
306 //
307 if (GuiStack)
308 {
309 //
310 // We'll allocate 64KB stack, but only commit 12K
311 //
312 StackPtes = BYTES_TO_PAGES(KERNEL_LARGE_STACK_SIZE);
313 StackPages = BYTES_TO_PAGES(KERNEL_LARGE_STACK_COMMIT);
314
315 }
316 else
317 {
318 //
319 // We'll allocate 12K and that's it
320 //
321 StackPtes = BYTES_TO_PAGES(KERNEL_STACK_SIZE);
322 StackPages = StackPtes;
323 }
324
325 //
326 // Reserve stack pages, plus a guard page
327 //
328 StackPte = MiReserveSystemPtes(StackPtes + 1, SystemPteSpace);
329 if (!StackPte) return NULL;
330
331 //
332 // Get the stack address
333 //
334 BaseAddress = MiPteToAddress(StackPte + StackPtes + 1);
335
336 //
337 // Select the right PTE address where we actually start committing pages
338 //
339 PointerPte = StackPte;
340 if (GuiStack) PointerPte += BYTES_TO_PAGES(KERNEL_LARGE_STACK_SIZE -
341 KERNEL_LARGE_STACK_COMMIT);
342
343
344 /* Setup the temporary invalid PTE */
345 MI_MAKE_SOFTWARE_PTE(&InvalidPte, MM_NOACCESS);
346
347 /* Setup the template stack PTE */
348 MI_MAKE_HARDWARE_PTE_KERNEL(&TempPte, PointerPte + 1, MM_READWRITE, 0);
349
350 //
351 // Acquire the PFN DB lock
352 //
353 OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
354
355 //
356 // Loop each stack page
357 //
358 for (i = 0; i < StackPages; i++)
359 {
360 //
361 // Next PTE
362 //
363 PointerPte++;
364
365 /* Get a page and write the current invalid PTE */
366 MI_SET_USAGE(MI_USAGE_KERNEL_STACK);
367 MI_SET_PROCESS2(PsGetCurrentProcess()->ImageFileName);
368 PageFrameIndex = MiRemoveAnyPage(MI_GET_NEXT_COLOR());
369 MI_WRITE_INVALID_PTE(PointerPte, InvalidPte);
370
371 /* Initialize the PFN entry for this page */
372 MiInitializePfn(PageFrameIndex, PointerPte, 1);
373
374 /* Write the valid PTE */
375 TempPte.u.Hard.PageFrameNumber = PageFrameIndex;
376 MI_WRITE_VALID_PTE(PointerPte, TempPte);
377 }
378
379 //
380 // Release the PFN lock
381 //
382 KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
383
384 //
385 // Return the stack address
386 //
387 return BaseAddress;
388 }
389
390 NTSTATUS
391 NTAPI
392 MmGrowKernelStackEx(IN PVOID StackPointer,
393 IN ULONG GrowSize)
394 {
395 PKTHREAD Thread = KeGetCurrentThread();
396 PMMPTE LimitPte, NewLimitPte, LastPte;
397 KIRQL OldIrql;
398 MMPTE TempPte, InvalidPte;
399 PFN_NUMBER PageFrameIndex;
400
401 //
402 // Make sure the stack did not overflow
403 //
404 ASSERT(((ULONG_PTR)Thread->StackBase - (ULONG_PTR)Thread->StackLimit) <=
405 (KERNEL_LARGE_STACK_SIZE + PAGE_SIZE));
406
407 //
408 // Get the current stack limit
409 //
410 LimitPte = MiAddressToPte(Thread->StackLimit);
411 ASSERT(LimitPte->u.Hard.Valid == 1);
412
413 //
414 // Get the new one and make sure this isn't a retarded request
415 //
416 NewLimitPte = MiAddressToPte((PVOID)((ULONG_PTR)StackPointer - GrowSize));
417 if (NewLimitPte == LimitPte) return STATUS_SUCCESS;
418
419 //
420 // Now make sure you're not going past the reserved space
421 //
422 LastPte = MiAddressToPte((PVOID)((ULONG_PTR)Thread->StackBase -
423 KERNEL_LARGE_STACK_SIZE));
424 if (NewLimitPte < LastPte)
425 {
426 //
427 // Sorry!
428 //
429 DPRINT1("Thread wants too much stack\n");
430 return STATUS_STACK_OVERFLOW;
431 }
432
433 //
434 // Calculate the number of new pages
435 //
436 LimitPte--;
437
438 /* Setup the temporary invalid PTE */
439 MI_MAKE_SOFTWARE_PTE(&InvalidPte, MM_NOACCESS);
440
441 //
442 // Acquire the PFN DB lock
443 //
444 OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
445
446 //
447 // Loop each stack page
448 //
449 while (LimitPte >= NewLimitPte)
450 {
451 /* Get a page and write the current invalid PTE */
452 MI_SET_USAGE(MI_USAGE_KERNEL_STACK_EXPANSION);
453 MI_SET_PROCESS2(PsGetCurrentProcess()->ImageFileName);
454 PageFrameIndex = MiRemoveAnyPage(MI_GET_NEXT_COLOR());
455 MI_WRITE_INVALID_PTE(LimitPte, InvalidPte);
456
457 /* Initialize the PFN entry for this page */
458 MiInitializePfn(PageFrameIndex, LimitPte, 1);
459
460 /* Setup the template stack PTE */
461 MI_MAKE_HARDWARE_PTE_KERNEL(&TempPte, LimitPte, MM_READWRITE, PageFrameIndex);
462
463 /* Write the valid PTE */
464 MI_WRITE_VALID_PTE(LimitPte--, TempPte);
465 }
466
467 //
468 // Release the PFN lock
469 //
470 KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
471
472 //
473 // Set the new limit
474 //
475 Thread->StackLimit = (ULONG_PTR)MiPteToAddress(NewLimitPte);
476 return STATUS_SUCCESS;
477 }
478
479 NTSTATUS
480 NTAPI
481 MmGrowKernelStack(IN PVOID StackPointer)
482 {
483 //
484 // Call the extended version
485 //
486 return MmGrowKernelStackEx(StackPointer, KERNEL_LARGE_STACK_COMMIT);
487 }
488
489 NTSTATUS
490 NTAPI
491 MmSetMemoryPriorityProcess(IN PEPROCESS Process,
492 IN UCHAR MemoryPriority)
493 {
494 UCHAR OldPriority;
495
496 //
497 // Check if we have less then 16MB of Physical Memory
498 //
499 if ((MmSystemSize == MmSmallSystem) &&
500 (MmNumberOfPhysicalPages < ((15 * 1024 * 1024) / PAGE_SIZE)))
501 {
502 //
503 // Always use background priority
504 //
505 MemoryPriority = MEMORY_PRIORITY_BACKGROUND;
506 }
507
508 //
509 // Save the old priority and update it
510 //
511 OldPriority = (UCHAR)Process->Vm.Flags.MemoryPriority;
512 Process->Vm.Flags.MemoryPriority = MemoryPriority;
513
514 //
515 // Return the old priority
516 //
517 return OldPriority;
518 }
519
520 LCID
521 NTAPI
522 MmGetSessionLocaleId(VOID)
523 {
524 PEPROCESS Process;
525 PAGED_CODE();
526
527 //
528 // Get the current process
529 //
530 Process = PsGetCurrentProcess();
531
532 //
533 // Check if it's the Session Leader
534 //
535 if (Process->Vm.Flags.SessionLeader)
536 {
537 //
538 // Make sure it has a valid Session
539 //
540 if (Process->Session)
541 {
542 //
543 // Get the Locale ID
544 //
545 #if ROS_HAS_SESSIONS
546 return ((PMM_SESSION_SPACE)Process->Session)->LocaleId;
547 #endif
548 }
549 }
550
551 //
552 // Not a session leader, return the default
553 //
554 return PsDefaultThreadLocaleId;
555 }
556
557 NTSTATUS
558 NTAPI
559 MmCreatePeb(IN PEPROCESS Process,
560 IN PINITIAL_PEB InitialPeb,
561 OUT PPEB *BasePeb)
562 {
563 PPEB Peb = NULL;
564 LARGE_INTEGER SectionOffset;
565 SIZE_T ViewSize = 0;
566 PVOID TableBase = NULL;
567 PIMAGE_NT_HEADERS NtHeaders;
568 PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigData;
569 NTSTATUS Status;
570 USHORT Characteristics;
571 KAFFINITY ProcessAffinityMask = 0;
572 SectionOffset.QuadPart = (ULONGLONG)0;
573 *BasePeb = NULL;
574
575 //
576 // Attach to Process
577 //
578 KeAttachProcess(&Process->Pcb);
579
580 //
581 // Allocate the PEB
582 //
583 Status = MiCreatePebOrTeb(Process, sizeof(PEB), (PULONG_PTR)&Peb);
584 ASSERT(NT_SUCCESS(Status));
585
586 //
587 // Map NLS Tables
588 //
589 Status = MmMapViewOfSection(ExpNlsSectionPointer,
590 (PEPROCESS)Process,
591 &TableBase,
592 0,
593 0,
594 &SectionOffset,
595 &ViewSize,
596 ViewShare,
597 MEM_TOP_DOWN,
598 PAGE_READONLY);
599 if (!NT_SUCCESS(Status)) return Status;
600
601 //
602 // Use SEH in case we can't load the PEB
603 //
604 _SEH2_TRY
605 {
606 //
607 // Initialize the PEB
608 //
609 RtlZeroMemory(Peb, sizeof(PEB));
610
611 //
612 // Set up data
613 //
614 Peb->ImageBaseAddress = Process->SectionBaseAddress;
615 Peb->InheritedAddressSpace = InitialPeb->InheritedAddressSpace;
616 Peb->Mutant = InitialPeb->Mutant;
617 Peb->ImageUsesLargePages = InitialPeb->ImageUsesLargePages;
618
619 //
620 // NLS
621 //
622 Peb->AnsiCodePageData = (PCHAR)TableBase + ExpAnsiCodePageDataOffset;
623 Peb->OemCodePageData = (PCHAR)TableBase + ExpOemCodePageDataOffset;
624 Peb->UnicodeCaseTableData = (PCHAR)TableBase + ExpUnicodeCaseTableDataOffset;
625
626 //
627 // Default Version Data (could get changed below)
628 //
629 Peb->OSMajorVersion = NtMajorVersion;
630 Peb->OSMinorVersion = NtMinorVersion;
631 Peb->OSBuildNumber = (USHORT)(NtBuildNumber & 0x3FFF);
632 Peb->OSPlatformId = 2; /* VER_PLATFORM_WIN32_NT */
633 Peb->OSCSDVersion = (USHORT)CmNtCSDVersion;
634
635 //
636 // Heap and Debug Data
637 //
638 Peb->NumberOfProcessors = KeNumberProcessors;
639 Peb->BeingDebugged = (BOOLEAN)(Process->DebugPort != NULL ? TRUE : FALSE);
640 Peb->NtGlobalFlag = NtGlobalFlag;
641 /*Peb->HeapSegmentReserve = MmHeapSegmentReserve;
642 Peb->HeapSegmentCommit = MmHeapSegmentCommit;
643 Peb->HeapDeCommitTotalFreeThreshold = MmHeapDeCommitTotalFreeThreshold;
644 Peb->HeapDeCommitFreeBlockThreshold = MmHeapDeCommitFreeBlockThreshold;
645 Peb->CriticalSectionTimeout = MmCriticalSectionTimeout;
646 Peb->MinimumStackCommit = MmMinimumStackCommitInBytes;
647 */
648 Peb->MaximumNumberOfHeaps = (PAGE_SIZE - sizeof(PEB)) / sizeof(PVOID);
649 Peb->ProcessHeaps = (PVOID*)(Peb + 1);
650
651 //
652 // Session ID
653 //
654 if (Process->Session) Peb->SessionId = 0; // MmGetSessionId(Process);
655 }
656 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
657 {
658 //
659 // Fail
660 //
661 KeDetachProcess();
662 _SEH2_YIELD(return _SEH2_GetExceptionCode());
663 }
664 _SEH2_END;
665
666 //
667 // Use SEH in case we can't load the image
668 //
669 _SEH2_TRY
670 {
671 //
672 // Get NT Headers
673 //
674 NtHeaders = RtlImageNtHeader(Peb->ImageBaseAddress);
675 Characteristics = NtHeaders->FileHeader.Characteristics;
676 }
677 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
678 {
679 //
680 // Fail
681 //
682 KeDetachProcess();
683 _SEH2_YIELD(return STATUS_INVALID_IMAGE_PROTECT);
684 }
685 _SEH2_END;
686
687 //
688 // Parse the headers
689 //
690 if (NtHeaders)
691 {
692 //
693 // Use SEH in case we can't load the headers
694 //
695 _SEH2_TRY
696 {
697 //
698 // Get the Image Config Data too
699 //
700 ImageConfigData = RtlImageDirectoryEntryToData(Peb->ImageBaseAddress,
701 TRUE,
702 IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG,
703 (PULONG)&ViewSize);
704 if (ImageConfigData)
705 {
706 //
707 // Probe it
708 //
709 ProbeForRead(ImageConfigData,
710 sizeof(IMAGE_LOAD_CONFIG_DIRECTORY),
711 sizeof(ULONG));
712 }
713
714 //
715 // Write subsystem data
716 //
717 Peb->ImageSubsystem = NtHeaders->OptionalHeader.Subsystem;
718 Peb->ImageSubsystemMajorVersion = NtHeaders->OptionalHeader.MajorSubsystemVersion;
719 Peb->ImageSubsystemMinorVersion = NtHeaders->OptionalHeader.MinorSubsystemVersion;
720
721 //
722 // Check for version data
723 //
724 if (NtHeaders->OptionalHeader.Win32VersionValue)
725 {
726 //
727 // Extract values and write them
728 //
729 Peb->OSMajorVersion = NtHeaders->OptionalHeader.Win32VersionValue & 0xFF;
730 Peb->OSMinorVersion = (NtHeaders->OptionalHeader.Win32VersionValue >> 8) & 0xFF;
731 Peb->OSBuildNumber = (NtHeaders->OptionalHeader.Win32VersionValue >> 16) & 0x3FFF;
732 Peb->OSPlatformId = (NtHeaders->OptionalHeader.Win32VersionValue >> 30) ^ 2;
733 }
734
735 //
736 // Process the image config data overrides if specfied
737 //
738 if (ImageConfigData != NULL)
739 {
740 //
741 // Process CSD version override
742 //
743 if (ImageConfigData->CSDVersion)
744 {
745 //
746 // Set new data
747 //
748 Peb->OSCSDVersion = ImageConfigData->CSDVersion;
749 }
750
751 //
752 // Process affinity mask ovverride
753 //
754 if (ImageConfigData->ProcessAffinityMask)
755 {
756 //
757 // Set new data
758 //
759 ProcessAffinityMask = ImageConfigData->ProcessAffinityMask;
760 }
761 }
762
763 //
764 // Check if this is a UP image
765 if (Characteristics & IMAGE_FILE_UP_SYSTEM_ONLY)
766 {
767 //
768 // Force it to use CPU 0
769 //
770 Peb->ImageProcessAffinityMask = 0;
771 }
772 else
773 {
774 //
775 // Whatever was configured
776 //
777 Peb->ImageProcessAffinityMask = ProcessAffinityMask;
778 }
779 }
780 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
781 {
782 //
783 // Fail
784 //
785 KeDetachProcess();
786 _SEH2_YIELD(return STATUS_INVALID_IMAGE_PROTECT);
787 }
788 _SEH2_END;
789 }
790
791 //
792 // Detach from the Process
793 //
794 KeDetachProcess();
795 *BasePeb = Peb;
796 return STATUS_SUCCESS;
797 }
798
799 NTSTATUS
800 NTAPI
801 MmCreateTeb(IN PEPROCESS Process,
802 IN PCLIENT_ID ClientId,
803 IN PINITIAL_TEB InitialTeb,
804 OUT PTEB *BaseTeb)
805 {
806 PTEB Teb;
807 NTSTATUS Status = STATUS_SUCCESS;
808 *BaseTeb = NULL;
809
810 //
811 // Attach to Target
812 //
813 KeAttachProcess(&Process->Pcb);
814
815 //
816 // Allocate the TEB
817 //
818 Status = MiCreatePebOrTeb(Process, sizeof(TEB), (PULONG_PTR)&Teb);
819 ASSERT(NT_SUCCESS(Status));
820
821 //
822 // Use SEH in case we can't load the TEB
823 //
824 _SEH2_TRY
825 {
826 //
827 // Initialize the PEB
828 //
829 RtlZeroMemory(Teb, sizeof(TEB));
830
831 //
832 // Set TIB Data
833 //
834 Teb->NtTib.ExceptionList = EXCEPTION_CHAIN_END;
835 Teb->NtTib.Self = (PNT_TIB)Teb;
836
837 //
838 // Identify this as an OS/2 V3.0 ("Cruiser") TIB
839 //
840 Teb->NtTib.Version = 30 << 8;
841
842 //
843 // Set TEB Data
844 //
845 Teb->ClientId = *ClientId;
846 Teb->RealClientId = *ClientId;
847 Teb->ProcessEnvironmentBlock = Process->Peb;
848 Teb->CurrentLocale = PsDefaultThreadLocaleId;
849
850 //
851 // Check if we have a grandparent TEB
852 //
853 if ((InitialTeb->PreviousStackBase == NULL) &&
854 (InitialTeb->PreviousStackLimit == NULL))
855 {
856 //
857 // Use initial TEB values
858 //
859 Teb->NtTib.StackBase = InitialTeb->StackBase;
860 Teb->NtTib.StackLimit = InitialTeb->StackLimit;
861 Teb->DeallocationStack = InitialTeb->AllocatedStackBase;
862 }
863 else
864 {
865 //
866 // Use grandparent TEB values
867 //
868 Teb->NtTib.StackBase = InitialTeb->PreviousStackBase;
869 Teb->NtTib.StackLimit = InitialTeb->PreviousStackLimit;
870 }
871
872 //
873 // Initialize the static unicode string
874 //
875 Teb->StaticUnicodeString.MaximumLength = sizeof(Teb->StaticUnicodeBuffer);
876 Teb->StaticUnicodeString.Buffer = Teb->StaticUnicodeBuffer;
877 }
878 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
879 {
880 //
881 // Get error code
882 //
883 Status = _SEH2_GetExceptionCode();
884 }
885 _SEH2_END;
886
887 //
888 // Return
889 //
890 KeDetachProcess();
891 *BaseTeb = Teb;
892 return Status;
893 }
894
895 VOID
896 NTAPI
897 MiInitializeWorkingSetList(IN PEPROCESS CurrentProcess)
898 {
899 PMMPFN Pfn1;
900
901 /* Setup some bogus list data */
902 MmWorkingSetList->LastEntry = CurrentProcess->Vm.MinimumWorkingSetSize;
903 MmWorkingSetList->HashTable = NULL;
904 MmWorkingSetList->HashTableSize = 0;
905 MmWorkingSetList->NumberOfImageWaiters = 0;
906 MmWorkingSetList->Wsle = (PVOID)0xDEADBABE;
907 MmWorkingSetList->VadBitMapHint = 1;
908 MmWorkingSetList->HashTableStart = (PVOID)0xBADAB00B;
909 MmWorkingSetList->HighestPermittedHashAddress = (PVOID)0xCAFEBABE;
910 MmWorkingSetList->FirstFree = 1;
911 MmWorkingSetList->FirstDynamic = 2;
912 MmWorkingSetList->NextSlot = 3;
913 MmWorkingSetList->LastInitializedWsle = 4;
914
915 /* The rule is that the owner process is always in the FLINK of the PDE's PFN entry */
916 Pfn1 = MiGetPfnEntry(MiAddressToPte(PDE_BASE)->u.Hard.PageFrameNumber);
917 ASSERT(Pfn1->u4.PteFrame == MiGetPfnEntryIndex(Pfn1));
918 Pfn1->u1.Event = (PKEVENT)CurrentProcess;
919 }
920
921 NTSTATUS
922 NTAPI
923 MmInitializeProcessAddressSpace(IN PEPROCESS Process,
924 IN PEPROCESS ProcessClone OPTIONAL,
925 IN PVOID Section OPTIONAL,
926 IN OUT PULONG Flags,
927 IN POBJECT_NAME_INFORMATION *AuditName OPTIONAL)
928 {
929 NTSTATUS Status = STATUS_SUCCESS;
930 SIZE_T ViewSize = 0;
931 PVOID ImageBase = 0;
932 PROS_SECTION_OBJECT SectionObject = Section;
933 PMMPTE PointerPte;
934 KIRQL OldIrql;
935 PMMPDE PointerPde;
936 PFN_NUMBER PageFrameNumber;
937 UNICODE_STRING FileName;
938 PWCHAR Source;
939 PCHAR Destination;
940 USHORT Length = 0;
941 MMPTE TempPte;
942
943 /* We should have a PDE */
944 ASSERT(Process->Pcb.DirectoryTableBase[0] != 0);
945 ASSERT(Process->PdeUpdateNeeded == FALSE);
946
947 /* Attach to the process */
948 KeAttachProcess(&Process->Pcb);
949
950 /* The address space should now been in phase 1 or 0 */
951 ASSERT(Process->AddressSpaceInitialized <= 1);
952 Process->AddressSpaceInitialized = 2;
953
954 /* Initialize the Addresss Space lock */
955 KeInitializeGuardedMutex(&Process->AddressCreationLock);
956 Process->Vm.WorkingSetExpansionLinks.Flink = NULL;
957
958 /* Initialize AVL tree */
959 ASSERT(Process->VadRoot.NumberGenericTableElements == 0);
960 Process->VadRoot.BalancedRoot.u1.Parent = &Process->VadRoot.BalancedRoot;
961
962 /* Lock PFN database */
963 OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
964
965 /* Setup the PFN for the PDE base of this process */
966 PointerPte = MiAddressToPte(PDE_BASE);
967 PageFrameNumber = PFN_FROM_PTE(PointerPte);
968 MiInitializePfn(PageFrameNumber, PointerPte, TRUE);
969
970 /* Do the same for hyperspace */
971 PointerPde = MiAddressToPde(HYPER_SPACE);
972 PageFrameNumber = PFN_FROM_PTE(PointerPde);
973 MiInitializePfn(PageFrameNumber, (PMMPTE)PointerPde, TRUE);
974
975 /* Setup the PFN for the PTE for the working set */
976 PointerPte = MiAddressToPte(MI_WORKING_SET_LIST);
977 MI_MAKE_HARDWARE_PTE(&TempPte, PointerPte, MM_READWRITE, 0);
978 ASSERT(PointerPte->u.Long != 0);
979 PageFrameNumber = PFN_FROM_PTE(PointerPte);
980 MI_WRITE_INVALID_PTE(PointerPte, DemandZeroPte);
981 MiInitializePfn(PageFrameNumber, PointerPte, TRUE);
982 TempPte.u.Hard.PageFrameNumber = PageFrameNumber;
983 MI_WRITE_VALID_PTE(PointerPte, TempPte);
984
985 /* Now initialize the working set list */
986 MiInitializeWorkingSetList(Process);
987
988 /* Sanity check */
989 ASSERT(Process->PhysicalVadRoot == NULL);
990
991 /* Release PFN lock */
992 KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
993
994 /* Lock the VAD, ARM3-owned ranges away */
995 MiRosTakeOverPebTebRanges(Process);
996
997 /* Check if there's a Section Object */
998 if (SectionObject)
999 {
1000 /* Determine the image file name and save it to EPROCESS */
1001 FileName = SectionObject->FileObject->FileName;
1002 Source = (PWCHAR)((PCHAR)FileName.Buffer + FileName.Length);
1003 if (FileName.Buffer)
1004 {
1005 /* Loop the file name*/
1006 while (Source > FileName.Buffer)
1007 {
1008 /* Make sure this isn't a backslash */
1009 if (*--Source == OBJ_NAME_PATH_SEPARATOR)
1010 {
1011 /* If so, stop it here */
1012 Source++;
1013 break;
1014 }
1015 else
1016 {
1017 /* Otherwise, keep going */
1018 Length++;
1019 }
1020 }
1021 }
1022
1023 /* Copy the to the process and truncate it to 15 characters if necessary */
1024 Destination = Process->ImageFileName;
1025 Length = min(Length, sizeof(Process->ImageFileName) - 1);
1026 while (Length--) *Destination++ = (UCHAR)*Source++;
1027 *Destination = ANSI_NULL;
1028
1029 /* Check if caller wants an audit name */
1030 if (AuditName)
1031 {
1032 /* Setup the audit name */
1033 Status = SeInitializeProcessAuditName(SectionObject->FileObject,
1034 FALSE,
1035 AuditName);
1036 if (!NT_SUCCESS(Status))
1037 {
1038 /* Fail */
1039 KeDetachProcess();
1040 return Status;
1041 }
1042 }
1043
1044 /* Map the section */
1045 Status = MmMapViewOfSection(Section,
1046 Process,
1047 (PVOID*)&ImageBase,
1048 0,
1049 0,
1050 NULL,
1051 &ViewSize,
1052 0,
1053 MEM_COMMIT,
1054 PAGE_READWRITE);
1055
1056 /* Save the pointer */
1057 Process->SectionBaseAddress = ImageBase;
1058 }
1059
1060 /* Be nice and detach */
1061 KeDetachProcess();
1062
1063 /* Return status to caller */
1064 return Status;
1065 }
1066
1067 NTSTATUS
1068 NTAPI
1069 INIT_FUNCTION
1070 MmInitializeHandBuiltProcess(IN PEPROCESS Process,
1071 IN PULONG_PTR DirectoryTableBase)
1072 {
1073 /* Share the directory base with the idle process */
1074 DirectoryTableBase[0] = PsGetCurrentProcess()->Pcb.DirectoryTableBase[0];
1075 DirectoryTableBase[1] = PsGetCurrentProcess()->Pcb.DirectoryTableBase[1];
1076
1077 /* Initialize the Addresss Space */
1078 KeInitializeGuardedMutex(&Process->AddressCreationLock);
1079 KeInitializeSpinLock(&Process->HyperSpaceLock);
1080 Process->Vm.WorkingSetExpansionLinks.Flink = NULL;
1081 ASSERT(Process->VadRoot.NumberGenericTableElements == 0);
1082 Process->VadRoot.BalancedRoot.u1.Parent = &Process->VadRoot.BalancedRoot;
1083
1084 /* Done */
1085 Process->HasAddressSpace = TRUE;//??
1086 return STATUS_SUCCESS;
1087 }
1088
1089 NTSTATUS
1090 NTAPI
1091 INIT_FUNCTION
1092 MmInitializeHandBuiltProcess2(IN PEPROCESS Process)
1093 {
1094 /* Lock the VAD, ARM3-owned ranges away */
1095 MiRosTakeOverPebTebRanges(Process);
1096 return STATUS_SUCCESS;
1097 }
1098
1099 #ifdef _M_IX86
1100 /* FIXME: Evaluate ways to make this portable yet arch-specific */
1101 BOOLEAN
1102 NTAPI
1103 MmCreateProcessAddressSpace(IN ULONG MinWs,
1104 IN PEPROCESS Process,
1105 OUT PULONG_PTR DirectoryTableBase)
1106 {
1107 KIRQL OldIrql;
1108 PFN_NUMBER PdeIndex, HyperIndex, WsListIndex;
1109 PMMPTE PointerPte;
1110 MMPTE TempPte, PdePte;
1111 ULONG PdeOffset;
1112 PMMPTE SystemTable, HyperTable;
1113 ULONG Color;
1114 PMMPFN Pfn1;
1115
1116 /* Choose a process color */
1117 Process->NextPageColor = RtlRandom(&MmProcessColorSeed);
1118
1119 /* Setup the hyperspace lock */
1120 KeInitializeSpinLock(&Process->HyperSpaceLock);
1121
1122 /* Lock PFN database */
1123 OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
1124
1125 /* Get a zero page for the PDE, if possible */
1126 Color = MI_GET_NEXT_PROCESS_COLOR(Process);
1127 MI_SET_USAGE(MI_USAGE_PAGE_DIRECTORY);
1128 PdeIndex = MiRemoveZeroPageSafe(Color);
1129 if (!PdeIndex)
1130 {
1131 /* No zero pages, grab a free one */
1132 PdeIndex = MiRemoveAnyPage(Color);
1133
1134 /* Zero it outside the PFN lock */
1135 KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
1136 MiZeroPhysicalPage(PdeIndex);
1137 OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
1138 }
1139
1140 /* Get a zero page for hyperspace, if possible */
1141 MI_SET_USAGE(MI_USAGE_PAGE_DIRECTORY);
1142 Color = MI_GET_NEXT_PROCESS_COLOR(Process);
1143 HyperIndex = MiRemoveZeroPageSafe(Color);
1144 if (!HyperIndex)
1145 {
1146 /* No zero pages, grab a free one */
1147 HyperIndex = MiRemoveAnyPage(Color);
1148
1149 /* Zero it outside the PFN lock */
1150 KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
1151 MiZeroPhysicalPage(HyperIndex);
1152 OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
1153 }
1154
1155 /* Get a zero page for the woring set list, if possible */
1156 MI_SET_USAGE(MI_USAGE_PAGE_TABLE);
1157 Color = MI_GET_NEXT_PROCESS_COLOR(Process);
1158 WsListIndex = MiRemoveZeroPageSafe(Color);
1159 if (!WsListIndex)
1160 {
1161 /* No zero pages, grab a free one */
1162 WsListIndex = MiRemoveAnyPage(Color);
1163
1164 /* Zero it outside the PFN lock */
1165 KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
1166 MiZeroPhysicalPage(WsListIndex);
1167 }
1168 else
1169 {
1170 /* Release the PFN lock */
1171 KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
1172 }
1173
1174 /* Switch to phase 1 initialization */
1175 ASSERT(Process->AddressSpaceInitialized == 0);
1176 Process->AddressSpaceInitialized = 1;
1177
1178 /* Set the base directory pointers */
1179 Process->WorkingSetPage = WsListIndex;
1180 DirectoryTableBase[0] = PdeIndex << PAGE_SHIFT;
1181 DirectoryTableBase[1] = HyperIndex << PAGE_SHIFT;
1182
1183 /* Make sure we don't already have a page directory setup */
1184 ASSERT(Process->Pcb.DirectoryTableBase[0] == 0);
1185
1186 /* Get a PTE to map hyperspace */
1187 PointerPte = MiReserveSystemPtes(1, SystemPteSpace);
1188 ASSERT(PointerPte != NULL);
1189
1190 /* Build it */
1191 MI_MAKE_HARDWARE_PTE_KERNEL(&PdePte,
1192 PointerPte,
1193 MM_READWRITE,
1194 HyperIndex);
1195
1196 /* Set it dirty and map it */
1197 MI_MAKE_DIRTY_PAGE(&PdePte);
1198 MI_WRITE_VALID_PTE(PointerPte, PdePte);
1199
1200 /* Now get hyperspace's page table */
1201 HyperTable = MiPteToAddress(PointerPte);
1202
1203 /* Now write the PTE/PDE entry for the working set list index itself */
1204 TempPte = ValidKernelPte;
1205 TempPte.u.Hard.PageFrameNumber = WsListIndex;
1206 PdeOffset = MiAddressToPteOffset(MmWorkingSetList);
1207 HyperTable[PdeOffset] = TempPte;
1208
1209 /* Let go of the system PTE */
1210 MiReleaseSystemPtes(PointerPte, 1, SystemPteSpace);
1211
1212 /* Save the PTE address of the page directory itself */
1213 Pfn1 = MiGetPfnEntry(PdeIndex);
1214 Pfn1->PteAddress = (PMMPTE)PDE_BASE;
1215
1216 /* Insert us into the Mm process list */
1217 InsertTailList(&MmProcessList, &Process->MmProcessLinks);
1218
1219 /* Get a PTE to map the page directory */
1220 PointerPte = MiReserveSystemPtes(1, SystemPteSpace);
1221 ASSERT(PointerPte != NULL);
1222
1223 /* Build it */
1224 MI_MAKE_HARDWARE_PTE_KERNEL(&PdePte,
1225 PointerPte,
1226 MM_READWRITE,
1227 PdeIndex);
1228
1229 /* Set it dirty and map it */
1230 MI_MAKE_DIRTY_PAGE(&PdePte);
1231 MI_WRITE_VALID_PTE(PointerPte, PdePte);
1232
1233 /* Now get the page directory (which we'll double map, so call it a page table */
1234 SystemTable = MiPteToAddress(PointerPte);
1235
1236 /* Copy all the kernel mappings */
1237 PdeOffset = MiGetPdeOffset(MmSystemRangeStart);
1238 RtlCopyMemory(&SystemTable[PdeOffset],
1239 MiAddressToPde(MmSystemRangeStart),
1240 PAGE_SIZE - PdeOffset * sizeof(MMPTE));
1241
1242 /* Now write the PTE/PDE entry for hyperspace itself */
1243 TempPte = ValidKernelPte;
1244 TempPte.u.Hard.PageFrameNumber = HyperIndex;
1245 PdeOffset = MiGetPdeOffset(HYPER_SPACE);
1246 SystemTable[PdeOffset] = TempPte;
1247
1248 /* Sanity check */
1249 PdeOffset++;
1250 ASSERT(MiGetPdeOffset(MmHyperSpaceEnd) >= PdeOffset);
1251
1252 /* Now do the x86 trick of making the PDE a page table itself */
1253 PdeOffset = MiGetPdeOffset(PTE_BASE);
1254 TempPte.u.Hard.PageFrameNumber = PdeIndex;
1255 SystemTable[PdeOffset] = TempPte;
1256
1257 /* Let go of the system PTE */
1258 MiReleaseSystemPtes(PointerPte, 1, SystemPteSpace);
1259 return TRUE;
1260 }
1261 #endif
1262
1263 VOID
1264 NTAPI
1265 MmCleanProcessAddressSpace(IN PEPROCESS Process)
1266 {
1267 PMMVAD Vad;
1268 PMM_AVL_TABLE VadTree;
1269 PETHREAD Thread = PsGetCurrentThread();
1270
1271 /* Only support this */
1272 ASSERT(Process->AddressSpaceInitialized == 2);
1273
1274 /* Lock the process address space from changes */
1275 MmLockAddressSpace(&Process->Vm);
1276
1277 /* VM is deleted now */
1278 Process->VmDeleted = TRUE;
1279
1280 /* Enumerate the VADs */
1281 VadTree = &Process->VadRoot;
1282 while (VadTree->NumberGenericTableElements)
1283 {
1284 /* Grab the current VAD */
1285 Vad = (PMMVAD)VadTree->BalancedRoot.RightChild;
1286
1287 /* Lock the working set */
1288 MiLockProcessWorkingSet(Process, Thread);
1289
1290 /* Remove this VAD from the tree */
1291 ASSERT(VadTree->NumberGenericTableElements >= 1);
1292 MiRemoveNode((PMMADDRESS_NODE)Vad, VadTree);
1293
1294 /* Only regular VADs supported for now */
1295 ASSERT(Vad->u.VadFlags.VadType == VadNone);
1296
1297 /* Check if this is a section VAD */
1298 if (!(Vad->u.VadFlags.PrivateMemory) && (Vad->ControlArea))
1299 {
1300 /* Remove the view */
1301 MiRemoveMappedView(Process, Vad);
1302 }
1303 else
1304 {
1305 /* Delete the addresses */
1306 MiDeleteVirtualAddresses(Vad->StartingVpn << PAGE_SHIFT,
1307 (Vad->EndingVpn << PAGE_SHIFT) | (PAGE_SIZE - 1),
1308 Vad);
1309
1310 /* Release the working set */
1311 MiUnlockProcessWorkingSet(Process, Thread);
1312 }
1313
1314 /* Skip ARM3 fake VADs, they'll be freed by MmDeleteProcessAddresSpace */
1315 if (Vad->u.VadFlags.Spare == 1)
1316 {
1317 /* Set a flag so MmDeleteMemoryArea knows to free, but not to remove */
1318 Vad->u.VadFlags.Spare = 2;
1319 continue;
1320 }
1321
1322 /* Free the VAD memory */
1323 ExFreePool(Vad);
1324 }
1325
1326 /* Release the address space */
1327 MmUnlockAddressSpace(&Process->Vm);
1328 }
1329
1330 /* SYSTEM CALLS ***************************************************************/
1331
1332 NTSTATUS
1333 NTAPI
1334 NtAllocateUserPhysicalPages(IN HANDLE ProcessHandle,
1335 IN OUT PULONG_PTR NumberOfPages,
1336 IN OUT PULONG_PTR UserPfnArray)
1337 {
1338 UNIMPLEMENTED;
1339 return STATUS_NOT_IMPLEMENTED;
1340 }
1341
1342 NTSTATUS
1343 NTAPI
1344 NtMapUserPhysicalPages(IN PVOID VirtualAddresses,
1345 IN ULONG_PTR NumberOfPages,
1346 IN OUT PULONG_PTR UserPfnArray)
1347 {
1348 UNIMPLEMENTED;
1349 return STATUS_NOT_IMPLEMENTED;
1350 }
1351
1352 NTSTATUS
1353 NTAPI
1354 NtMapUserPhysicalPagesScatter(IN PVOID *VirtualAddresses,
1355 IN ULONG_PTR NumberOfPages,
1356 IN OUT PULONG_PTR UserPfnArray)
1357 {
1358 UNIMPLEMENTED;
1359 return STATUS_NOT_IMPLEMENTED;
1360 }
1361
1362 NTSTATUS
1363 NTAPI
1364 NtFreeUserPhysicalPages(IN HANDLE ProcessHandle,
1365 IN OUT PULONG_PTR NumberOfPages,
1366 IN OUT PULONG_PTR UserPfnArray)
1367 {
1368 UNIMPLEMENTED;
1369 return STATUS_NOT_IMPLEMENTED;
1370 }
1371
1372 /* EOF */