Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1727 lines
48 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. freevm.c
  5. Abstract:
  6. This module contains the routines which implement the
  7. NtFreeVirtualMemory service.
  8. Author:
  9. Lou Perazzoli (loup) 22-May-1989
  10. Landy Wang (landyw) 02-June-1997
  11. Revision History:
  12. --*/
  13. #include "mi.h"
  14. #define MEM_CHECK_COMMIT_STATE 0x400000
  15. #define MM_VALID_PTE_SIZE (256)
  16. MMPTE MmDecommittedPte = {MM_DECOMMIT << MM_PROTECT_FIELD_SHIFT};
  17. #if DBG
  18. extern PEPROCESS MmWatchProcess;
  19. VOID MmFooBar(VOID);
  20. #endif // DBG
  21. // #include "ntos.h"
  22. #ifdef ALLOC_PRAGMA
  23. #pragma alloc_text(PAGE,NtFreeVirtualMemory)
  24. #pragma alloc_text(PAGE,MiIsEntireRangeCommitted)
  25. #endif
  26. VOID
  27. MiProcessValidPteList (
  28. IN PMMPTE *PteList,
  29. IN ULONG Count
  30. );
  31. ULONG
  32. MiDecommitPages (
  33. IN PVOID StartingAddress,
  34. IN PMMPTE EndingPte,
  35. IN PEPROCESS Process,
  36. IN PMMVAD_SHORT Vad
  37. );
  38. VOID
  39. MiDeleteFreeVm (
  40. IN PVOID StartingAddress,
  41. IN PVOID EndingAddress
  42. );
  43. NTSTATUS
  44. NtFreeVirtualMemory(
  45. IN HANDLE ProcessHandle,
  46. IN OUT PVOID *BaseAddress,
  47. IN OUT PSIZE_T RegionSize,
  48. IN ULONG FreeType
  49. )
  50. /*++
  51. Routine Description:
  52. This function deletes a region of pages within the virtual address
  53. space of a subject process.
  54. Arguments:
  55. ProcessHandle - An open handle to a process object.
  56. BaseAddress - The base address of the region of pages
  57. to be freed. This value is rounded down to the
  58. next host page address boundary.
  59. RegionSize - A pointer to a variable that will receive
  60. the actual size in bytes of the freed region of
  61. pages. The initial value of this argument is
  62. rounded up to the next host page size boundary.
  63. FreeType - A set of flags that describe the type of
  64. free that is to be performed for the specified
  65. region of pages.
  66. FreeType Flags
  67. MEM_DECOMMIT - The specified region of pages is to be decommitted.
  68. MEM_RELEASE - The specified region of pages is to be released.
  69. Return Value:
  70. NTSTATUS.
  71. --*/
  72. {
  73. KAPC_STATE ApcState;
  74. PMMVAD_SHORT Vad;
  75. PMMVAD_SHORT NewVad;
  76. PMMVAD PreviousVad;
  77. PMMVAD NextVad;
  78. PEPROCESS Process;
  79. KPROCESSOR_MODE PreviousMode;
  80. PVOID StartingAddress;
  81. PVOID EndingAddress;
  82. NTSTATUS Status;
  83. LOGICAL Attached;
  84. SIZE_T CapturedRegionSize;
  85. PVOID CapturedBase;
  86. PMMPTE StartingPte;
  87. PMMPTE EndingPte;
  88. SIZE_T OldQuota;
  89. SIZE_T QuotaCharge;
  90. SIZE_T CommitReduction;
  91. ULONG_PTR OldEnd;
  92. LOGICAL UserPhysicalPages;
  93. #if defined(_MIALT4K_)
  94. PVOID StartingAddress4k;
  95. PVOID EndingAddress4k;
  96. PVOID Wow64Process;
  97. #endif
  98. PETHREAD CurrentThread;
  99. PEPROCESS CurrentProcess;
  100. PAGED_CODE();
  101. //
  102. // Check to make sure FreeType is good.
  103. //
  104. if ((FreeType & ~(MEM_DECOMMIT | MEM_RELEASE)) != 0) {
  105. return STATUS_INVALID_PARAMETER_4;
  106. }
  107. //
  108. // One of MEM_DECOMMIT or MEM_RELEASE must be specified, but not both.
  109. //
  110. if (((FreeType & (MEM_DECOMMIT | MEM_RELEASE)) == 0) ||
  111. ((FreeType & (MEM_DECOMMIT | MEM_RELEASE)) ==
  112. (MEM_DECOMMIT | MEM_RELEASE))) {
  113. return STATUS_INVALID_PARAMETER_4;
  114. }
  115. CurrentThread = PsGetCurrentThread ();
  116. CurrentProcess = PsGetCurrentProcessByThread (CurrentThread);
  117. PreviousMode = KeGetPreviousModeByThread(&CurrentThread->Tcb);
  118. //
  119. // Establish an exception handler, probe the specified addresses
  120. // for write access and capture the initial values.
  121. //
  122. try {
  123. if (PreviousMode != KernelMode) {
  124. ProbeForWritePointer (BaseAddress);
  125. ProbeForWriteUlong_ptr (RegionSize);
  126. }
  127. //
  128. // Capture the base address.
  129. //
  130. CapturedBase = *BaseAddress;
  131. //
  132. // Capture the region size.
  133. //
  134. CapturedRegionSize = *RegionSize;
  135. } except (ExSystemExceptionFilter()) {
  136. //
  137. // If an exception occurs during the probe or capture
  138. // of the initial values, then handle the exception and
  139. // return the exception code as the status value.
  140. //
  141. return GetExceptionCode();
  142. }
  143. //
  144. // Make sure the specified starting and ending addresses are
  145. // within the user part of the virtual address space.
  146. //
  147. if (CapturedBase > MM_HIGHEST_USER_ADDRESS) {
  148. //
  149. // Invalid base address.
  150. //
  151. return STATUS_INVALID_PARAMETER_2;
  152. }
  153. if ((ULONG_PTR)MM_HIGHEST_USER_ADDRESS - (ULONG_PTR)CapturedBase <
  154. CapturedRegionSize) {
  155. //
  156. // Invalid region size;
  157. //
  158. return STATUS_INVALID_PARAMETER_3;
  159. }
  160. EndingAddress = (PVOID)(((LONG_PTR)CapturedBase + CapturedRegionSize - 1) |
  161. (PAGE_SIZE - 1));
  162. StartingAddress = PAGE_ALIGN(CapturedBase);
  163. Attached = FALSE;
  164. if (ProcessHandle == NtCurrentProcess()) {
  165. Process = CurrentProcess;
  166. }
  167. else {
  168. //
  169. // Reference the specified process handle for VM_OPERATION access.
  170. //
  171. Status = ObReferenceObjectByHandle ( ProcessHandle,
  172. PROCESS_VM_OPERATION,
  173. PsProcessType,
  174. PreviousMode,
  175. (PVOID *)&Process,
  176. NULL );
  177. if (!NT_SUCCESS(Status)) {
  178. return Status;
  179. }
  180. //
  181. // If the specified process is not the current process, attach
  182. // to the specified process.
  183. //
  184. if (CurrentProcess != Process) {
  185. KeStackAttachProcess (&Process->Pcb, &ApcState);
  186. Attached = TRUE;
  187. }
  188. }
  189. CommitReduction = 0;
  190. //
  191. // Get the address creation mutex to block multiple threads from
  192. // creating or deleting address space at the same time and
  193. // get the working set mutex so virtual address descriptors can
  194. // be inserted and walked. Block APCs to prevent page faults while
  195. // we own the working set mutex.
  196. //
  197. LOCK_ADDRESS_SPACE (Process);
  198. //
  199. // Make sure the address space was not deleted.
  200. //
  201. if (Process->Flags & PS_PROCESS_FLAGS_VM_DELETED) {
  202. Status = STATUS_PROCESS_IS_TERMINATING;
  203. goto ErrorReturn;
  204. }
  205. #if defined(_MIALT4K_)
  206. Wow64Process = Process->Wow64Process;
  207. //
  208. // Initializing these is not needed for correctness, but
  209. // without it the compiler cannot compile this code W4 to check
  210. // for use of uninitialized variables.
  211. //
  212. StartingAddress4k = NULL;
  213. EndingAddress4k = NULL;
  214. if (CapturedRegionSize != 0) {
  215. if (Wow64Process != NULL) {
  216. //
  217. // Adjust Starting/EndingAddress for the native page size.
  218. //
  219. // StartingAddress: if this happened to be 4k aligned, but not
  220. // native aligned, then look at the previous 4k page and if it's
  221. // allocated then align the starting page to the next native
  222. // page, otherwise align it to the current one.
  223. //
  224. // EndingAddress: if this happened to be 4k aligned but not
  225. // native aligned, then look at the next 4k page and if it's
  226. // allocated, then make the ending address the previous
  227. // native page, otherwise make it the current.
  228. //
  229. // This is to ensure VADs are not leaked inside
  230. // the process when releasing partial allocations.
  231. //
  232. ASSERT (StartingAddress == PAGE_ALIGN(StartingAddress));
  233. StartingAddress4k = (PVOID)PAGE_4K_ALIGN(CapturedBase);
  234. if (StartingAddress4k >= (PVOID)MM_MAX_WOW64_ADDRESS) {
  235. //
  236. // The caller's address is not in the WOW64 area, pass it
  237. // through as a native request.
  238. //
  239. Wow64Process = NULL;
  240. goto NativeRequest;
  241. }
  242. EndingAddress4k = (PVOID)(((LONG_PTR)CapturedBase + CapturedRegionSize - 1) |
  243. (PAGE_4K - 1));
  244. if (BYTE_OFFSET (StartingAddress4k) != 0) {
  245. if (MiArePreceding4kPagesAllocated (StartingAddress4k) == TRUE) {
  246. StartingAddress = PAGE_NEXT_ALIGN (StartingAddress4k);
  247. }
  248. }
  249. if (EndingAddress4k >= (PVOID)MM_MAX_WOW64_ADDRESS) {
  250. //
  251. // The caller's address is not in the WOW64 area, pass it
  252. // through as a native request.
  253. //
  254. Wow64Process = NULL;
  255. goto NativeRequest;
  256. }
  257. if (BYTE_OFFSET (EndingAddress4k) != PAGE_SIZE - 1) {
  258. if (MiAreFollowing4kPagesAllocated (EndingAddress4k) == TRUE) {
  259. EndingAddress = (PVOID)((ULONG_PTR)PAGE_ALIGN(EndingAddress4k) - 1);
  260. }
  261. }
  262. if (StartingAddress > EndingAddress) {
  263. //
  264. // There is no need to free native pages.
  265. //
  266. Vad = NULL;
  267. goto FreeAltPages;
  268. }
  269. }
  270. }
  271. NativeRequest:
  272. #endif
  273. Vad = (PMMVAD_SHORT)MiLocateAddress (StartingAddress);
  274. if (Vad == NULL) {
  275. //
  276. // No Virtual Address Descriptor located for Base Address.
  277. //
  278. Status = STATUS_MEMORY_NOT_ALLOCATED;
  279. goto ErrorReturn;
  280. }
  281. //
  282. // Found the associated Virtual Address Descriptor.
  283. //
  284. if (Vad->EndingVpn < MI_VA_TO_VPN (EndingAddress)) {
  285. //
  286. // The entire range to delete is not contained within a single
  287. // virtual address descriptor. Return an error.
  288. //
  289. Status = STATUS_UNABLE_TO_FREE_VM;
  290. goto ErrorReturn;
  291. }
  292. //
  293. // Check to ensure this Vad is deletable. Delete is required
  294. // for both decommit and release.
  295. //
  296. if ((Vad->u.VadFlags.PrivateMemory == 0) ||
  297. (Vad->u.VadFlags.PhysicalMapping == 1)) {
  298. Status = STATUS_UNABLE_TO_DELETE_SECTION;
  299. goto ErrorReturn;
  300. }
  301. if (Vad->u.VadFlags.NoChange == 1) {
  302. //
  303. // An attempt is being made to delete a secured VAD, check
  304. // to see if this deletion is allowed.
  305. //
  306. if (FreeType & MEM_RELEASE) {
  307. //
  308. // Specify the whole range, this solves the problem with
  309. // splitting the VAD and trying to decide where the various
  310. // secure ranges need to go.
  311. //
  312. Status = MiCheckSecuredVad ((PMMVAD)Vad,
  313. MI_VPN_TO_VA (Vad->StartingVpn),
  314. ((Vad->EndingVpn - Vad->StartingVpn) << PAGE_SHIFT) +
  315. (PAGE_SIZE - 1),
  316. MM_SECURE_DELETE_CHECK);
  317. }
  318. else {
  319. Status = MiCheckSecuredVad ((PMMVAD)Vad,
  320. CapturedBase,
  321. CapturedRegionSize,
  322. MM_SECURE_DELETE_CHECK);
  323. }
  324. if (!NT_SUCCESS (Status)) {
  325. goto ErrorReturn;
  326. }
  327. }
  328. UserPhysicalPages = FALSE;
  329. PreviousVad = MiGetPreviousVad (Vad);
  330. NextVad = MiGetNextVad (Vad);
  331. if (FreeType & MEM_RELEASE) {
  332. //
  333. // *****************************************************************
  334. // MEM_RELEASE was specified.
  335. // *****************************************************************
  336. //
  337. //
  338. // The descriptor for the address range is deletable. Remove or split
  339. // the descriptor.
  340. //
  341. //
  342. // If the region size is zero, remove the whole VAD.
  343. //
  344. if (CapturedRegionSize == 0) {
  345. //
  346. // If the region size is specified as 0, the base address
  347. // must be the starting address for the region.
  348. //
  349. if (MI_VA_TO_VPN (CapturedBase) != Vad->StartingVpn) {
  350. Status = STATUS_FREE_VM_NOT_AT_BASE;
  351. goto ErrorReturn;
  352. }
  353. //
  354. // This Virtual Address Descriptor has been deleted.
  355. //
  356. StartingAddress = MI_VPN_TO_VA (Vad->StartingVpn);
  357. EndingAddress = MI_VPN_TO_VA_ENDING (Vad->EndingVpn);
  358. #if defined(_MIALT4K_)
  359. StartingAddress4k = StartingAddress;
  360. EndingAddress4k = EndingAddress;
  361. #endif
  362. //
  363. // Free all the physical pages that this VAD might be mapping.
  364. // Since only the AWE lock synchronizes the remap API, carefully
  365. // remove this VAD from the list first.
  366. //
  367. LOCK_WS_UNSAFE (Process);
  368. if (Vad->u.VadFlags.UserPhysicalPages == 1) {
  369. MiAweViewRemover (Process, (PMMVAD)Vad);
  370. MiRemoveUserPhysicalPagesVad (Vad);
  371. UserPhysicalPages = TRUE;
  372. }
  373. else if (Vad->u.VadFlags.WriteWatch == 1) {
  374. MiPhysicalViewRemover (Process, (PMMVAD)Vad);
  375. }
  376. MiRemoveVad ((PMMVAD)Vad);
  377. //
  378. // Free the VAD pool after releasing our mutexes
  379. // to reduce contention.
  380. //
  381. }
  382. else {
  383. //
  384. // Region's size was not specified as zero, delete the
  385. // whole VAD or split the VAD.
  386. //
  387. if (MI_VA_TO_VPN (StartingAddress) == Vad->StartingVpn) {
  388. if (MI_VA_TO_VPN (EndingAddress) == Vad->EndingVpn) {
  389. //
  390. // This Virtual Address Descriptor has been deleted.
  391. //
  392. //
  393. // Free all the physical pages that this VAD might be
  394. // mapping. Since only the AWE lock synchronizes the
  395. // remap API, carefully remove this VAD from the list first.
  396. //
  397. LOCK_WS_UNSAFE (Process);
  398. if (Vad->u.VadFlags.UserPhysicalPages == 1) {
  399. MiAweViewRemover (Process, (PMMVAD)Vad);
  400. MiRemoveUserPhysicalPagesVad (Vad);
  401. UserPhysicalPages = TRUE;
  402. }
  403. else if (Vad->u.VadFlags.WriteWatch == 1) {
  404. MiPhysicalViewRemover (Process, (PMMVAD)Vad);
  405. }
  406. MiRemoveVad ((PMMVAD)Vad);
  407. //
  408. // Free the VAD pool after releasing our mutexes
  409. // to reduce contention.
  410. //
  411. }
  412. else {
  413. if ((Vad->u.VadFlags.UserPhysicalPages == 1) ||
  414. (Vad->u.VadFlags.WriteWatch == 1)) {
  415. //
  416. // Splitting or chopping a physical VAD or a write-watch
  417. // VAD is not allowed.
  418. //
  419. Status = STATUS_FREE_VM_NOT_AT_BASE;
  420. goto ErrorReturn;
  421. }
  422. LOCK_WS_UNSAFE (Process);
  423. //
  424. // This Virtual Address Descriptor has a new starting
  425. // address.
  426. //
  427. CommitReduction = MiCalculatePageCommitment (
  428. StartingAddress,
  429. EndingAddress,
  430. (PMMVAD)Vad,
  431. Process);
  432. Vad->StartingVpn = MI_VA_TO_VPN ((PCHAR)EndingAddress + 1);
  433. Vad->u.VadFlags.CommitCharge -= CommitReduction;
  434. ASSERT ((SSIZE_T)Vad->u.VadFlags.CommitCharge >= 0);
  435. NextVad = (PMMVAD)Vad;
  436. Vad = NULL;
  437. }
  438. }
  439. else {
  440. if ((Vad->u.VadFlags.UserPhysicalPages == 1) ||
  441. (Vad->u.VadFlags.WriteWatch == 1)) {
  442. //
  443. // Splitting or chopping a physical VAD or a write-watch
  444. // VAD is not allowed.
  445. //
  446. Status = STATUS_FREE_VM_NOT_AT_BASE;
  447. goto ErrorReturn;
  448. }
  449. //
  450. // Starting address is greater than start of VAD.
  451. //
  452. if (MI_VA_TO_VPN (EndingAddress) == Vad->EndingVpn) {
  453. //
  454. // Change the ending address of the VAD.
  455. //
  456. LOCK_WS_UNSAFE (Process);
  457. CommitReduction = MiCalculatePageCommitment (
  458. StartingAddress,
  459. EndingAddress,
  460. (PMMVAD)Vad,
  461. Process);
  462. Vad->u.VadFlags.CommitCharge -= CommitReduction;
  463. Vad->EndingVpn = MI_VA_TO_VPN ((PCHAR)StartingAddress - 1);
  464. PreviousVad = (PMMVAD)Vad;
  465. }
  466. else {
  467. //
  468. // Split this VAD as the address range is within the VAD.
  469. //
  470. NewVad = ExAllocatePoolWithTag (NonPagedPool,
  471. sizeof(MMVAD_SHORT),
  472. 'FdaV');
  473. if (NewVad == NULL) {
  474. Status = STATUS_INSUFFICIENT_RESOURCES;
  475. goto ErrorReturn;
  476. }
  477. *NewVad = *Vad;
  478. NewVad->StartingVpn = MI_VA_TO_VPN ((PCHAR)EndingAddress + 1);
  479. //
  480. // Set the commit charge to zero so MiInsertVad will
  481. // not charge commitment for splitting the VAD.
  482. //
  483. NewVad->u.VadFlags.CommitCharge = 0;
  484. OldEnd = Vad->EndingVpn;
  485. LOCK_WS_UNSAFE (Process);
  486. CommitReduction = MiCalculatePageCommitment (
  487. StartingAddress,
  488. EndingAddress,
  489. (PMMVAD)Vad,
  490. Process);
  491. OldQuota = Vad->u.VadFlags.CommitCharge - CommitReduction;
  492. Vad->EndingVpn = MI_VA_TO_VPN ((PCHAR)StartingAddress - 1);
  493. //
  494. // Insert the VAD, this could fail due to quota charges.
  495. //
  496. Status = MiInsertVad ((PMMVAD)NewVad);
  497. if (!NT_SUCCESS(Status)) {
  498. //
  499. // Inserting the Vad failed, reset the original
  500. // Vad, free the new Vad and return an error.
  501. //
  502. Vad->EndingVpn = OldEnd;
  503. UNLOCK_WS_AND_ADDRESS_SPACE (Process);
  504. ExFreePool (NewVad);
  505. goto ErrorReturn2;
  506. }
  507. //
  508. // As we have split the original VAD into 2 separate VADs
  509. // there is no way of knowing what the commit charge
  510. // is for each VAD. Calculate the charge and reset
  511. // each VAD. Note that we also use the previous value
  512. // to make sure the books stay balanced.
  513. //
  514. QuotaCharge = MiCalculatePageCommitment (MI_VPN_TO_VA (Vad->StartingVpn),
  515. (PCHAR)StartingAddress - 1,
  516. (PMMVAD)Vad,
  517. Process);
  518. Vad->u.VadFlags.CommitCharge = QuotaCharge;
  519. //
  520. // Give the remaining charge to the new VAD.
  521. //
  522. NewVad->u.VadFlags.CommitCharge = OldQuota - QuotaCharge;
  523. PreviousVad = (PMMVAD)Vad;
  524. NextVad = (PMMVAD)NewVad;
  525. }
  526. Vad = NULL;
  527. }
  528. }
  529. //
  530. // Return commitment for page table pages if possible.
  531. //
  532. MiReturnPageTablePageCommitment (StartingAddress,
  533. EndingAddress,
  534. Process,
  535. PreviousVad,
  536. NextVad);
  537. if (UserPhysicalPages == TRUE) {
  538. MiDeletePageTablesForPhysicalRange (StartingAddress, EndingAddress);
  539. }
  540. else {
  541. //
  542. // Get the PFN lock so MiDeleteVirtualAddresses can be called.
  543. //
  544. MiDeleteFreeVm (StartingAddress, EndingAddress);
  545. }
  546. UNLOCK_WS_UNSAFE (Process);
  547. CapturedRegionSize = 1 + (PCHAR)EndingAddress - (PCHAR)StartingAddress;
  548. //
  549. // Update the virtual size in the process header.
  550. //
  551. Process->VirtualSize -= CapturedRegionSize;
  552. #if defined(_MIALT4K_)
  553. if (Wow64Process != NULL) {
  554. goto FreeAltPages;
  555. }
  556. #endif
  557. Process->CommitCharge -= CommitReduction;
  558. UNLOCK_ADDRESS_SPACE (Process);
  559. if (CommitReduction != 0) {
  560. MI_INCREMENT_TOTAL_PROCESS_COMMIT (0 - CommitReduction);
  561. ASSERT (Vad == NULL);
  562. PsReturnProcessPageFileQuota (Process, CommitReduction);
  563. MiReturnCommitment (CommitReduction);
  564. if (Process->JobStatus & PS_JOB_STATUS_REPORT_COMMIT_CHANGES) {
  565. PsChangeJobMemoryUsage (-(SSIZE_T)CommitReduction);
  566. }
  567. MM_TRACK_COMMIT (MM_DBG_COMMIT_RETURN_NTFREEVM1, CommitReduction);
  568. }
  569. else if (Vad != NULL) {
  570. ExFreePool (Vad);
  571. }
  572. if (Attached == TRUE) {
  573. KeUnstackDetachProcess (&ApcState);
  574. }
  575. if (ProcessHandle != NtCurrentProcess()) {
  576. ObDereferenceObject (Process);
  577. }
  578. //
  579. // Establish an exception handler and write the size and base
  580. // address.
  581. //
  582. try {
  583. *RegionSize = CapturedRegionSize;
  584. *BaseAddress = StartingAddress;
  585. } except (EXCEPTION_EXECUTE_HANDLER) {
  586. //
  587. // An exception occurred, don't take any action (just handle
  588. // the exception and return success.
  589. }
  590. return STATUS_SUCCESS;
  591. }
  592. if (Vad->u.VadFlags.UserPhysicalPages == 1) {
  593. //
  594. // Pages from a physical VAD must be released via
  595. // NtFreeUserPhysicalPages, not this routine.
  596. //
  597. Status = STATUS_MEMORY_NOT_ALLOCATED;
  598. goto ErrorReturn;
  599. }
  600. //
  601. // **************************************************************
  602. //
  603. // MEM_DECOMMIT was specified.
  604. //
  605. // **************************************************************
  606. //
  607. //
  608. // Check to ensure the complete range of pages is already committed.
  609. //
  610. if (CapturedRegionSize == 0) {
  611. if (MI_VA_TO_VPN (CapturedBase) != Vad->StartingVpn) {
  612. Status = STATUS_FREE_VM_NOT_AT_BASE;
  613. goto ErrorReturn;
  614. }
  615. EndingAddress = MI_VPN_TO_VA_ENDING (Vad->EndingVpn);
  616. #if defined(_MIALT4K_)
  617. StartingAddress4k = StartingAddress;
  618. EndingAddress4k = EndingAddress;
  619. #endif
  620. }
  621. #if 0
  622. if (FreeType & MEM_CHECK_COMMIT_STATE) {
  623. if ( !MiIsEntireRangeCommitted(StartingAddress,
  624. EndingAddress,
  625. Vad,
  626. Process)) {
  627. //
  628. // The entire range to be decommitted is not committed,
  629. // return an error.
  630. //
  631. Status = STATUS_UNABLE_TO_DECOMMIT_VM;
  632. goto ErrorReturn;
  633. }
  634. }
  635. #endif //0
  636. //
  637. // The address range is entirely committed, decommit it now.
  638. //
  639. //
  640. // Calculate the initial quotas and commit charges for this VAD.
  641. //
  642. StartingPte = MiGetPteAddress (StartingAddress);
  643. EndingPte = MiGetPteAddress (EndingAddress);
  644. CommitReduction = 1 + EndingPte - StartingPte;
  645. LOCK_WS_UNSAFE (Process);
  646. //
  647. // Check to see if the entire range can be decommitted by
  648. // just updating the virtual address descriptor.
  649. //
  650. CommitReduction -= MiDecommitPages (StartingAddress,
  651. EndingPte,
  652. Process,
  653. Vad);
  654. UNLOCK_WS_UNSAFE (Process);
  655. //
  656. // Adjust the quota charges.
  657. //
  658. ASSERT ((LONG)CommitReduction >= 0);
  659. Vad->u.VadFlags.CommitCharge -= CommitReduction;
  660. ASSERT ((LONG)Vad->u.VadFlags.CommitCharge >= 0);
  661. Vad = NULL;
  662. #if defined(_MIALT4K_)
  663. FreeAltPages:
  664. if (Wow64Process != NULL) {
  665. if (FreeType & MEM_RELEASE) {
  666. MiReleaseFor4kPage (StartingAddress4k,
  667. EndingAddress4k,
  668. Process);
  669. }
  670. else {
  671. MiDecommitFor4kPage (StartingAddress4k,
  672. EndingAddress4k,
  673. Process);
  674. }
  675. StartingAddress = StartingAddress4k;
  676. EndingAddress = EndingAddress4k;
  677. }
  678. #endif
  679. Process->CommitCharge -= CommitReduction;
  680. UNLOCK_ADDRESS_SPACE (Process);
  681. if (CommitReduction != 0) {
  682. MI_INCREMENT_TOTAL_PROCESS_COMMIT (0 - CommitReduction);
  683. PsReturnProcessPageFileQuota (Process, CommitReduction);
  684. MiReturnCommitment (CommitReduction);
  685. if (Process->JobStatus & PS_JOB_STATUS_REPORT_COMMIT_CHANGES) {
  686. PsChangeJobMemoryUsage (-(SSIZE_T)CommitReduction);
  687. }
  688. MM_TRACK_COMMIT (MM_DBG_COMMIT_RETURN_NTFREEVM2, CommitReduction);
  689. }
  690. else if (Vad != NULL) {
  691. ExFreePool (Vad);
  692. }
  693. if (Attached == TRUE) {
  694. KeUnstackDetachProcess (&ApcState);
  695. }
  696. if (ProcessHandle != NtCurrentProcess()) {
  697. ObDereferenceObject (Process);
  698. }
  699. //
  700. // Establish an exception handler and write the size and base address.
  701. //
  702. try {
  703. *RegionSize = 1 + (PCHAR)EndingAddress - (PCHAR)StartingAddress;
  704. *BaseAddress = StartingAddress;
  705. } except (EXCEPTION_EXECUTE_HANDLER) {
  706. NOTHING;
  707. }
  708. return STATUS_SUCCESS;
  709. ErrorReturn:
  710. UNLOCK_ADDRESS_SPACE (Process);
  711. ErrorReturn2:
  712. if (Attached == TRUE) {
  713. KeUnstackDetachProcess (&ApcState);
  714. }
  715. if (ProcessHandle != NtCurrentProcess()) {
  716. ObDereferenceObject (Process);
  717. }
  718. return Status;
  719. }
  720. ULONG
  721. MiIsEntireRangeCommitted (
  722. IN PVOID StartingAddress,
  723. IN PVOID EndingAddress,
  724. IN PMMVAD Vad,
  725. IN PEPROCESS Process
  726. )
  727. /*++
  728. Routine Description:
  729. This routine examines the range of pages from the starting address
  730. up to and including the ending address and returns TRUE if every
  731. page in the range is committed, FALSE otherwise.
  732. Arguments:
  733. StartingAddress - Supplies the starting address of the range.
  734. EndingAddress - Supplies the ending address of the range.
  735. Vad - Supplies the virtual address descriptor which describes the range.
  736. Process - Supplies the current process.
  737. Return Value:
  738. TRUE if the entire range is committed.
  739. FALSE if any page within the range is not committed.
  740. Environment:
  741. Kernel mode, APCs disabled, WorkingSetMutex and AddressCreation mutexes
  742. held.
  743. --*/
  744. {
  745. PMMPTE PointerPte;
  746. PMMPTE LastPte;
  747. PMMPTE PointerPde;
  748. PMMPTE PointerPpe;
  749. PMMPTE PointerPxe;
  750. ULONG FirstTime;
  751. ULONG Waited;
  752. PVOID Va;
  753. PAGED_CODE();
  754. FirstTime = TRUE;
  755. PointerPde = MiGetPdeAddress (StartingAddress);
  756. PointerPte = MiGetPteAddress (StartingAddress);
  757. LastPte = MiGetPteAddress (EndingAddress);
  758. //
  759. // Set the Va to the starting address + 8, this solves problems
  760. // associated with address 0 (NULL) being used as a valid virtual
  761. // address and NULL in the VAD commitment field indicating no pages
  762. // are committed.
  763. //
  764. Va = (PVOID)((PCHAR)StartingAddress + 8);
  765. while (PointerPte <= LastPte) {
  766. if (MiIsPteOnPdeBoundary(PointerPte) || (FirstTime)) {
  767. //
  768. // This may be a PXE/PPE/PDE boundary, check to see if all the
  769. // PXE/PPE/PDE pages exist.
  770. //
  771. FirstTime = FALSE;
  772. PointerPde = MiGetPteAddress (PointerPte);
  773. PointerPpe = MiGetPteAddress (PointerPde);
  774. PointerPxe = MiGetPteAddress (PointerPpe);
  775. do {
  776. #if (_MI_PAGING_LEVELS >= 4)
  777. retry:
  778. #endif
  779. while (!MiDoesPxeExistAndMakeValid(PointerPxe, Process, FALSE, &Waited)) {
  780. //
  781. // No PPE exists for the starting address, check the VAD
  782. // to see if the pages are committed.
  783. //
  784. PointerPxe += 1;
  785. PointerPpe = MiGetVirtualAddressMappedByPte (PointerPxe);
  786. PointerPde = MiGetVirtualAddressMappedByPte (PointerPpe);
  787. PointerPte = MiGetVirtualAddressMappedByPte (PointerPde);
  788. Va = MiGetVirtualAddressMappedByPte (PointerPte);
  789. if (PointerPte > LastPte) {
  790. //
  791. // Make sure the entire range is committed.
  792. //
  793. if (Vad->u.VadFlags.MemCommit == 0) {
  794. //
  795. // The entire range to be decommitted is not
  796. // committed, return an error.
  797. //
  798. return FALSE;
  799. }
  800. return TRUE;
  801. }
  802. //
  803. // Make sure the range thus far is committed.
  804. //
  805. if (Vad->u.VadFlags.MemCommit == 0) {
  806. //
  807. // The entire range to be decommitted is not committed,
  808. // return an error.
  809. //
  810. return FALSE;
  811. }
  812. }
  813. while (!MiDoesPpeExistAndMakeValid(PointerPpe, Process, FALSE, &Waited)) {
  814. //
  815. // No PDE exists for the starting address, check the VAD
  816. // to see if the pages are committed.
  817. //
  818. PointerPpe += 1;
  819. PointerPde = MiGetVirtualAddressMappedByPte (PointerPpe);
  820. PointerPte = MiGetVirtualAddressMappedByPte (PointerPde);
  821. Va = MiGetVirtualAddressMappedByPte (PointerPte);
  822. if (PointerPte > LastPte) {
  823. //
  824. // Make sure the entire range is committed.
  825. //
  826. if (Vad->u.VadFlags.MemCommit == 0) {
  827. //
  828. // The entire range to be decommitted is not
  829. // committed, return an error.
  830. //
  831. return FALSE;
  832. }
  833. return TRUE;
  834. }
  835. //
  836. // Make sure the range thus far is committed.
  837. //
  838. if (Vad->u.VadFlags.MemCommit == 0) {
  839. //
  840. // The entire range to be decommitted is not committed,
  841. // return an error.
  842. //
  843. return FALSE;
  844. }
  845. #if (_MI_PAGING_LEVELS >= 4)
  846. if (MiIsPteOnPdeBoundary (PointerPpe)) {
  847. PointerPxe = MiGetPteAddress (PointerPpe);
  848. goto retry;
  849. }
  850. #endif
  851. }
  852. Waited = 0;
  853. while (!MiDoesPdeExistAndMakeValid(PointerPde, Process, FALSE, &Waited)) {
  854. //
  855. // No PDE exists for the starting address, check the VAD
  856. // to see if the pages are committed.
  857. //
  858. PointerPde += 1;
  859. PointerPpe = MiGetPteAddress (PointerPde);
  860. PointerPxe = MiGetPdeAddress (PointerPde);
  861. PointerPte = MiGetVirtualAddressMappedByPte (PointerPde);
  862. Va = MiGetVirtualAddressMappedByPte (PointerPte);
  863. if (PointerPte > LastPte) {
  864. //
  865. // Make sure the entire range is committed.
  866. //
  867. if (Vad->u.VadFlags.MemCommit == 0) {
  868. //
  869. // The entire range to be decommitted is not committed,
  870. // return an error.
  871. //
  872. return FALSE;
  873. }
  874. return TRUE;
  875. }
  876. //
  877. // Make sure the range thus far is committed.
  878. //
  879. if (Vad->u.VadFlags.MemCommit == 0) {
  880. //
  881. // The entire range to be decommitted is not committed,
  882. // return an error.
  883. //
  884. return FALSE;
  885. }
  886. #if (_MI_PAGING_LEVELS >= 3)
  887. if (MiIsPteOnPdeBoundary (PointerPde)) {
  888. PointerPpe = MiGetPteAddress (PointerPde);
  889. #if (_MI_PAGING_LEVELS >= 4)
  890. if (MiIsPteOnPpeBoundary (PointerPde)) {
  891. PointerPxe = MiGetPdeAddress (PointerPde);
  892. Waited = 1;
  893. break;
  894. }
  895. #endif
  896. Waited = 1;
  897. break;
  898. }
  899. #endif
  900. }
  901. } while (Waited != 0);
  902. }
  903. //
  904. // The page table page exists, check each PTE for commitment.
  905. //
  906. if (PointerPte->u.Long == 0) {
  907. //
  908. // This page has not been committed, check the VAD.
  909. //
  910. if (Vad->u.VadFlags.MemCommit == 0) {
  911. //
  912. // The entire range to be decommitted is not committed,
  913. // return an error.
  914. //
  915. return FALSE;
  916. }
  917. }
  918. else {
  919. //
  920. // Has this page been explicitly decommitted?
  921. //
  922. if (MiIsPteDecommittedPage (PointerPte)) {
  923. //
  924. // This page has been explicitly decommitted, return an error.
  925. //
  926. return FALSE;
  927. }
  928. }
  929. PointerPte += 1;
  930. Va = (PVOID)((PCHAR)(Va) + PAGE_SIZE);
  931. }
  932. return TRUE;
  933. }
  934. ULONG
  935. MiDecommitPages (
  936. IN PVOID StartingAddress,
  937. IN PMMPTE EndingPte,
  938. IN PEPROCESS Process,
  939. IN PMMVAD_SHORT Vad
  940. )
  941. /*++
  942. Routine Description:
  943. This routine decommits the specified range of pages.
  944. Arguments:
  945. StartingAddress - Supplies the starting address of the range.
  946. EndingPte - Supplies the ending PTE of the range.
  947. Process - Supplies the current process.
  948. Vad - Supplies the virtual address descriptor which describes the range.
  949. Return Value:
  950. Value to reduce commitment by for the VAD.
  951. Environment:
  952. Kernel mode, APCs disabled, WorkingSetMutex and AddressCreation mutexes
  953. held.
  954. --*/
  955. {
  956. PMMPTE PointerPde;
  957. PMMPTE PointerPte;
  958. PVOID Va;
  959. ULONG CommitReduction;
  960. PMMPTE CommitLimitPte;
  961. KIRQL OldIrql;
  962. PMMPTE ValidPteList[MM_VALID_PTE_SIZE];
  963. ULONG count;
  964. WSLE_NUMBER WorkingSetIndex;
  965. PMMPFN Pfn1;
  966. PMMPFN Pfn2;
  967. PVOID SwapVa;
  968. WSLE_NUMBER Entry;
  969. MMWSLENTRY Locked;
  970. MMPTE PteContents;
  971. PFN_NUMBER PageTableFrameIndex;
  972. PVOID UsedPageTableHandle;
  973. count = 0;
  974. CommitReduction = 0;
  975. if (Vad->u.VadFlags.MemCommit) {
  976. CommitLimitPte = MiGetPteAddress (MI_VPN_TO_VA (Vad->EndingVpn));
  977. }
  978. else {
  979. CommitLimitPte = NULL;
  980. }
  981. //
  982. // Decommit each page by setting the PTE to be explicitly
  983. // decommitted. The PTEs cannot be deleted all at once as
  984. // this would set the PTEs to zero which would auto-evaluate
  985. // as committed if referenced by another thread when a page
  986. // table page is being in-paged.
  987. //
  988. PointerPde = MiGetPdeAddress (StartingAddress);
  989. PointerPte = MiGetPteAddress (StartingAddress);
  990. Va = StartingAddress;
  991. //
  992. // Loop through all the PDEs which map this region and ensure that
  993. // they exist. If they don't exist create them by touching a
  994. // PTE mapped by the PDE.
  995. //
  996. MiMakePdeExistAndMakeValid(PointerPde, Process, FALSE);
  997. while (PointerPte <= EndingPte) {
  998. if (MiIsPteOnPdeBoundary (PointerPte)) {
  999. PointerPde = MiGetPdeAddress (Va);
  1000. if (count != 0) {
  1001. MiProcessValidPteList (&ValidPteList[0], count);
  1002. count = 0;
  1003. }
  1004. MiMakePdeExistAndMakeValid(PointerPde, Process, FALSE);
  1005. }
  1006. //
  1007. // The working set lock is held. No PTEs can go from
  1008. // invalid to valid or valid to invalid. Transition
  1009. // PTEs can go from transition to pagefile.
  1010. //
  1011. PteContents = *PointerPte;
  1012. if (PteContents.u.Long != 0) {
  1013. if (PointerPte->u.Long == MmDecommittedPte.u.Long) {
  1014. //
  1015. // This PTE is already decommitted.
  1016. //
  1017. CommitReduction += 1;
  1018. }
  1019. else {
  1020. Process->NumberOfPrivatePages -= 1;
  1021. if (PteContents.u.Hard.Valid == 1) {
  1022. //
  1023. // Make sure this is not a forked PTE.
  1024. //
  1025. Pfn1 = MI_PFN_ELEMENT (PteContents.u.Hard.PageFrameNumber);
  1026. if (Pfn1->u3.e1.PrototypePte) {
  1027. LOCK_PFN (OldIrql);
  1028. MiDeletePte (PointerPte,
  1029. Va,
  1030. FALSE,
  1031. Process,
  1032. NULL,
  1033. NULL);
  1034. UNLOCK_PFN (OldIrql);
  1035. Process->NumberOfPrivatePages += 1;
  1036. MI_WRITE_INVALID_PTE (PointerPte, MmDecommittedPte);
  1037. }
  1038. else {
  1039. //
  1040. // Pte is valid, process later when PFN lock is held.
  1041. //
  1042. if (count == MM_VALID_PTE_SIZE) {
  1043. MiProcessValidPteList (&ValidPteList[0], count);
  1044. count = 0;
  1045. }
  1046. ValidPteList[count] = PointerPte;
  1047. count += 1;
  1048. //
  1049. // Remove address from working set list.
  1050. //
  1051. WorkingSetIndex = Pfn1->u1.WsIndex;
  1052. ASSERT (PAGE_ALIGN(MmWsle[WorkingSetIndex].u1.Long) ==
  1053. Va);
  1054. //
  1055. // Check to see if this entry is locked in the working set
  1056. // or locked in memory.
  1057. //
  1058. Locked = MmWsle[WorkingSetIndex].u1.e1;
  1059. MiRemoveWsle (WorkingSetIndex, MmWorkingSetList);
  1060. //
  1061. // Add this entry to the list of free working set entries
  1062. // and adjust the working set count.
  1063. //
  1064. MiReleaseWsle (WorkingSetIndex, &Process->Vm);
  1065. if ((Locked.LockedInWs == 1) || (Locked.LockedInMemory == 1)) {
  1066. //
  1067. // This entry is locked.
  1068. //
  1069. MmWorkingSetList->FirstDynamic -= 1;
  1070. if (WorkingSetIndex != MmWorkingSetList->FirstDynamic) {
  1071. SwapVa = MmWsle[MmWorkingSetList->FirstDynamic].u1.VirtualAddress;
  1072. SwapVa = PAGE_ALIGN (SwapVa);
  1073. Pfn2 = MI_PFN_ELEMENT (
  1074. MiGetPteAddress (SwapVa)->u.Hard.PageFrameNumber);
  1075. Entry = MiLocateWsle (SwapVa,
  1076. MmWorkingSetList,
  1077. Pfn2->u1.WsIndex);
  1078. MiSwapWslEntries (Entry,
  1079. WorkingSetIndex,
  1080. &Process->Vm);
  1081. }
  1082. }
  1083. MI_SET_PTE_IN_WORKING_SET (PointerPte, 0);
  1084. }
  1085. }
  1086. else if (PteContents.u.Soft.Prototype) {
  1087. //
  1088. // This is a forked PTE, just delete it.
  1089. //
  1090. LOCK_PFN (OldIrql);
  1091. MiDeletePte (PointerPte,
  1092. Va,
  1093. FALSE,
  1094. Process,
  1095. NULL,
  1096. NULL);
  1097. UNLOCK_PFN (OldIrql);
  1098. Process->NumberOfPrivatePages += 1;
  1099. MI_WRITE_INVALID_PTE (PointerPte, MmDecommittedPte);
  1100. }
  1101. else if (PteContents.u.Soft.Transition == 1) {
  1102. //
  1103. // Transition PTE, get the PFN database lock
  1104. // and reprocess this one.
  1105. //
  1106. LOCK_PFN (OldIrql);
  1107. PteContents = *PointerPte;
  1108. if (PteContents.u.Soft.Transition == 1) {
  1109. //
  1110. // PTE is still in transition, delete it.
  1111. //
  1112. Pfn1 = MI_PFN_ELEMENT (PteContents.u.Trans.PageFrameNumber);
  1113. MI_SET_PFN_DELETED (Pfn1);
  1114. PageTableFrameIndex = Pfn1->u4.PteFrame;
  1115. Pfn2 = MI_PFN_ELEMENT (PageTableFrameIndex);
  1116. MiDecrementShareCountInline (Pfn2, PageTableFrameIndex);
  1117. //
  1118. // Check the reference count for the page, if the
  1119. // reference count is zero, move the page to the
  1120. // free list, if the reference count is not zero,
  1121. // ignore this page. When the reference count
  1122. // goes to zero, it will be placed on the free list.
  1123. //
  1124. if (Pfn1->u3.e2.ReferenceCount == 0) {
  1125. MiUnlinkPageFromList (Pfn1);
  1126. MiReleasePageFileSpace (Pfn1->OriginalPte);
  1127. MiInsertPageInFreeList (MI_GET_PAGE_FRAME_FROM_TRANSITION_PTE(&PteContents));
  1128. }
  1129. }
  1130. else {
  1131. //
  1132. // Page MUST be in page file format!
  1133. //
  1134. ASSERT (PteContents.u.Soft.Valid == 0);
  1135. ASSERT (PteContents.u.Soft.Prototype == 0);
  1136. ASSERT (PteContents.u.Soft.PageFileHigh != 0);
  1137. MiReleasePageFileSpace (PteContents);
  1138. }
  1139. MI_WRITE_INVALID_PTE (PointerPte, MmDecommittedPte);
  1140. UNLOCK_PFN (OldIrql);
  1141. }
  1142. else {
  1143. //
  1144. // Must be demand zero or paging file format.
  1145. //
  1146. if (PteContents.u.Soft.PageFileHigh != 0) {
  1147. LOCK_PFN (OldIrql);
  1148. MiReleasePageFileSpace (PteContents);
  1149. UNLOCK_PFN (OldIrql);
  1150. }
  1151. else {
  1152. //
  1153. // Don't subtract out the private page count for
  1154. // a demand zero page.
  1155. //
  1156. Process->NumberOfPrivatePages += 1;
  1157. }
  1158. MI_WRITE_INVALID_PTE (PointerPte, MmDecommittedPte);
  1159. }
  1160. }
  1161. }
  1162. else {
  1163. //
  1164. // The PTE is already zero.
  1165. //
  1166. //
  1167. // Increment the count of non-zero page table entries for this
  1168. // page table and the number of private pages for the process.
  1169. //
  1170. UsedPageTableHandle = MI_GET_USED_PTES_HANDLE (Va);
  1171. MI_INCREMENT_USED_PTES_BY_HANDLE (UsedPageTableHandle);
  1172. if (PointerPte > CommitLimitPte) {
  1173. //
  1174. // Pte is not committed.
  1175. //
  1176. CommitReduction += 1;
  1177. }
  1178. MI_WRITE_INVALID_PTE (PointerPte, MmDecommittedPte);
  1179. }
  1180. PointerPte += 1;
  1181. Va = (PVOID)((PCHAR)Va + PAGE_SIZE);
  1182. }
  1183. if (count != 0) {
  1184. MiProcessValidPteList (&ValidPteList[0], count);
  1185. }
  1186. return CommitReduction;
  1187. }
  1188. VOID
  1189. MiProcessValidPteList (
  1190. IN PMMPTE *ValidPteList,
  1191. IN ULONG Count
  1192. )
  1193. /*++
  1194. Routine Description:
  1195. This routine flushes the specified range of valid PTEs.
  1196. Arguments:
  1197. ValidPteList - Supplies a pointer to an array of PTEs to flush.
  1198. Count - Supplies the count of the number of elements in the array.
  1199. Return Value:
  1200. none.
  1201. Environment:
  1202. Kernel mode, APCs disabled, WorkingSetMutex and AddressCreation mutexes
  1203. held.
  1204. --*/
  1205. {
  1206. ULONG i;
  1207. MMPTE_FLUSH_LIST PteFlushList;
  1208. MMPTE PteContents;
  1209. PMMPFN Pfn1;
  1210. PMMPFN Pfn2;
  1211. PFN_NUMBER PageFrameIndex;
  1212. PFN_NUMBER PageTableFrameIndex;
  1213. KIRQL OldIrql;
  1214. i = 0;
  1215. PteFlushList.Count = Count;
  1216. LOCK_PFN (OldIrql);
  1217. do {
  1218. PteContents = *ValidPteList[i];
  1219. ASSERT (PteContents.u.Hard.Valid == 1);
  1220. PageFrameIndex = MI_GET_PAGE_FRAME_FROM_PTE(&PteContents);
  1221. Pfn1 = MI_PFN_ELEMENT (PageFrameIndex);
  1222. //
  1223. // Decrement the share and valid counts of the page table
  1224. // page which maps this PTE.
  1225. //
  1226. PageTableFrameIndex = Pfn1->u4.PteFrame;
  1227. Pfn2 = MI_PFN_ELEMENT (PageTableFrameIndex);
  1228. MiDecrementShareCountInline (Pfn2, PageTableFrameIndex);
  1229. MI_SET_PFN_DELETED (Pfn1);
  1230. //
  1231. // Decrement the share count for the physical page. As the page
  1232. // is private it will be put on the free list.
  1233. //
  1234. MiDecrementShareCountOnly (PageFrameIndex);
  1235. if (Count < MM_MAXIMUM_FLUSH_COUNT) {
  1236. PteFlushList.FlushPte[i] = ValidPteList[i];
  1237. PteFlushList.FlushVa[i] =
  1238. MiGetVirtualAddressMappedByPte (ValidPteList[i]);
  1239. }
  1240. *ValidPteList[i] = MmDecommittedPte;
  1241. i += 1;
  1242. } while (i != Count);
  1243. MiFlushPteList (&PteFlushList, FALSE, MmDecommittedPte);
  1244. UNLOCK_PFN (OldIrql);
  1245. return;
  1246. }
  1247. VOID
  1248. MiDeleteFreeVm (
  1249. IN PVOID StartingAddress,
  1250. IN PVOID EndingAddress
  1251. )
  1252. /*++
  1253. Routine Description:
  1254. Nonpagable routine to call acquire PFN lock and call
  1255. MiDeleteVirtualAddresses.
  1256. Arguments:
  1257. Return Value:
  1258. none.
  1259. Environment:
  1260. Kernel mode, APCs disabled, WorkingSetMutex and AddressCreation mutexes
  1261. held.
  1262. --*/
  1263. {
  1264. KIRQL OldIrql;
  1265. LOCK_PFN (OldIrql);
  1266. //
  1267. // Delete the address range.
  1268. //
  1269. MiDeleteVirtualAddresses (StartingAddress,
  1270. EndingAddress,
  1271. FALSE,
  1272. (PMMVAD)NULL);
  1273. UNLOCK_PFN (OldIrql);
  1274. }