X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=reactos%2Fntoskrnl%2Fmm%2Fanonmem.c;h=548ff4a9bbd91c9e288def93bd452c18dadd9236;hp=9296d839ab98f8da3528e178c8519c68c99c38c3;hb=8481c1fa105172e71517334bcfa085da87b85258;hpb=c3a96b7538f3a58e842b2d833be7d7fc3bd7a65d diff --git a/reactos/ntoskrnl/mm/anonmem.c b/reactos/ntoskrnl/mm/anonmem.c index 9296d839ab9..548ff4a9bbd 100644 --- a/reactos/ntoskrnl/mm/anonmem.c +++ b/reactos/ntoskrnl/mm/anonmem.c @@ -22,7 +22,6 @@ * PURPOSE: Implementing anonymous memory. * * PROGRAMMERS: David Welch - * Hartmut Birr * Casper Hornstrup * KJK::Hyperion * Ge van Geldorp @@ -48,6 +47,7 @@ /* FUNCTIONS *****************************************************************/ NTSTATUS +NTAPI MmWritePageVirtualMemory(PMADDRESS_SPACE AddressSpace, PMEMORY_AREA MemoryArea, PVOID Address, @@ -129,13 +129,14 @@ MmWritePageVirtualMemory(PMADDRESS_SPACE AddressSpace, } NTSTATUS +NTAPI MmPageOutVirtualMemory(PMADDRESS_SPACE AddressSpace, PMEMORY_AREA MemoryArea, PVOID Address, PMM_PAGEOP PageOp) { PFN_TYPE Page; - BOOL WasDirty; + BOOLEAN WasDirty; SWAPENTRY SwapEntry; NTSTATUS Status; @@ -169,6 +170,7 @@ MmPageOutVirtualMemory(PMADDRESS_SPACE AddressSpace, */ if (!WasDirty) { + MmLockAddressSpace(AddressSpace); MmDeleteVirtualMapping(AddressSpace->Process, Address, FALSE, NULL, NULL); MmDeleteAllRmaps(Page, NULL, NULL); if ((SwapEntry = MmGetSavedSwapEntryPage(Page)) != 0) @@ -176,6 +178,7 @@ MmPageOutVirtualMemory(PMADDRESS_SPACE AddressSpace, MmCreatePageFileMapping(AddressSpace->Process, Address, SwapEntry); MmSetSavedSwapEntryPage(Page, 0); } + MmUnlockAddressSpace(AddressSpace); MmReleasePageMemoryConsumer(MC_USER, Page); PageOp->Status = STATUS_SUCCESS; KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE); @@ -220,8 +223,10 @@ MmPageOutVirtualMemory(PMADDRESS_SPACE AddressSpace, * Otherwise we have succeeded, free the page */ DPRINT("MM: Swapped out virtual memory page 0x%.8X!\n", Page << PAGE_SHIFT); + MmLockAddressSpace(AddressSpace); MmDeleteVirtualMapping(AddressSpace->Process, Address, FALSE, NULL, NULL); MmCreatePageFileMapping(AddressSpace->Process, Address, SwapEntry); + MmUnlockAddressSpace(AddressSpace); MmDeleteAllRmaps(Page, NULL, NULL); MmSetSavedSwapEntryPage(Page, 0); MmReleasePageMemoryConsumer(MC_USER, Page); @@ -232,6 +237,7 @@ MmPageOutVirtualMemory(PMADDRESS_SPACE AddressSpace, } NTSTATUS +NTAPI MmNotPresentFaultVirtualMemory(PMADDRESS_SPACE AddressSpace, MEMORY_AREA* MemoryArea, PVOID Address, @@ -538,7 +544,7 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle, * RETURNS: Status */ { - PEPROCESS Process; + PROS_EPROCESS Process; MEMORY_AREA* MemoryArea; ULONG_PTR MemoryAreaLength; ULONG Type; @@ -720,15 +726,14 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle, } } - Status = MmCreateMemoryArea(Process, - AddressSpace, + Status = MmCreateMemoryArea(AddressSpace, MEMORY_AREA_VIRTUAL_MEMORY, &BaseAddress, RegionSize, Protect, &MemoryArea, PBaseAddress != 0, - (AllocationType & MEM_TOP_DOWN) == MEM_TOP_DOWN, + AllocationType & MEM_TOP_DOWN, BoundaryAddressMultiple); if (!NT_SUCCESS(Status)) { @@ -741,7 +746,7 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle, MemoryAreaLength = (ULONG_PTR)MemoryArea->EndingAddress - (ULONG_PTR)MemoryArea->StartingAddress; - MmInitialiseRegion(&MemoryArea->Data.VirtualMemoryData.RegionListHead, + MmInitializeRegion(&MemoryArea->Data.VirtualMemoryData.RegionListHead, MemoryAreaLength, Type, Protect); if ((AllocationType & MEM_COMMIT) && @@ -779,7 +784,7 @@ MmFreeVirtualMemoryPage(PVOID Context, MmFreeSwapPage(SavedSwapEntry); MmSetSavedSwapEntryPage(Page, 0); } - MmDeleteRmap(Page, Process, Address); + MmDeleteRmap(Page, (PROS_EPROCESS)Process, Address); MmReleasePageMemoryConsumer(MC_USER, Page); } else if (SwapEntry != 0) @@ -789,7 +794,8 @@ MmFreeVirtualMemoryPage(PVOID Context, } VOID -MmFreeVirtualMemory(PEPROCESS Process, +NTAPI +MmFreeVirtualMemory(PROS_EPROCESS Process, PMEMORY_AREA MemoryArea) { PLIST_ENTRY current_entry; @@ -883,7 +889,7 @@ NtFreeVirtualMemory(IN HANDLE ProcessHandle, { MEMORY_AREA* MemoryArea; NTSTATUS Status; - PEPROCESS Process; + PROS_EPROCESS Process; PMADDRESS_SPACE AddressSpace; PVOID BaseAddress; ULONG RegionSize; @@ -954,6 +960,7 @@ NtFreeVirtualMemory(IN HANDLE ProcessHandle, } NTSTATUS +NTAPI MmProtectAnonMem(PMADDRESS_SPACE AddressSpace, PMEMORY_AREA MemoryArea, PVOID BaseAddress, @@ -982,7 +989,7 @@ MmQueryAnonMem(PMEMORY_AREA MemoryArea, PULONG ResultLength) { PMM_REGION Region; - PVOID RegionBase; + PVOID RegionBase = NULL; Info->BaseAddress = (PVOID)PAGE_ROUND_DOWN(Address); @@ -991,8 +998,8 @@ MmQueryAnonMem(PMEMORY_AREA MemoryArea, Address, &RegionBase); Info->BaseAddress = RegionBase; Info->AllocationBase = MemoryArea->StartingAddress; - Info->AllocationProtect = MemoryArea->Attributes; - Info->RegionSize = (char*)RegionBase + Region->Length - (char*)Info->BaseAddress; + Info->AllocationProtect = MemoryArea->Protect; + Info->RegionSize = Region->Length; Info->State = Region->Type; Info->Protect = Region->Protect; Info->Type = MEM_PRIVATE;