(FORMATTING)

-Grrr, you stupid software

svn path=/trunk/; revision=54367
This commit is contained in:
Jérôme Gardou 2011-11-12 19:36:56 +00:00
parent 0e2151927b
commit 90875550df

View file

@ -62,7 +62,7 @@ MmPageOutVirtualMemory(PMMSUPPORT AddressSpace,
PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace); PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
DPRINT("MmPageOutVirtualMemory(Address 0x%.8X) PID %d\n", DPRINT("MmPageOutVirtualMemory(Address 0x%.8X) PID %d\n",
Address, Process->UniqueProcessId); Address, Process->UniqueProcessId);
/* /*
* Check for paging out from a deleted virtual memory area. * Check for paging out from a deleted virtual memory area.
@ -79,7 +79,7 @@ MmPageOutVirtualMemory(PMMSUPPORT AddressSpace,
* Disable the virtual mapping. * Disable the virtual mapping.
*/ */
MmDisableVirtualMapping(Process, Address, MmDisableVirtualMapping(Process, Address,
&WasDirty, &Page); &WasDirty, &Page);
if (Page == 0) if (Page == 0)
{ {
@ -132,7 +132,7 @@ MmPageOutVirtualMemory(PMMSUPPORT AddressSpace,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("MM: Failed to write to swap page (Status was 0x%.8X)\n", DPRINT1("MM: Failed to write to swap page (Status was 0x%.8X)\n",
Status); Status);
MmEnableVirtualMapping(Process, Address); MmEnableVirtualMapping(Process, Address);
PageOp->Status = STATUS_UNSUCCESSFUL; PageOp->Status = STATUS_UNSUCCESSFUL;
KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE); KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE);
@ -200,8 +200,8 @@ MmNotPresentFaultVirtualMemory(PMMSUPPORT AddressSpace,
* Get the segment corresponding to the virtual address * Get the segment corresponding to the virtual address
*/ */
Region = MmFindRegion(MemoryArea->StartingAddress, Region = MmFindRegion(MemoryArea->StartingAddress,
&MemoryArea->Data.VirtualMemoryData.RegionListHead, &MemoryArea->Data.VirtualMemoryData.RegionListHead,
Address, NULL); Address, NULL);
if (Region->Type == MEM_RESERVE || Region->Protect == PAGE_NOACCESS) if (Region->Type == MEM_RESERVE || Region->Protect == PAGE_NOACCESS)
{ {
@ -220,8 +220,8 @@ MmNotPresentFaultVirtualMemory(PMMSUPPORT AddressSpace,
* Get or create a page operation * Get or create a page operation
*/ */
PageOp = MmGetPageOp(MemoryArea, Process->UniqueProcessId, PageOp = MmGetPageOp(MemoryArea, Process->UniqueProcessId,
(PVOID)PAGE_ROUND_DOWN(Address), NULL, 0, (PVOID)PAGE_ROUND_DOWN(Address), NULL, 0,
MM_PAGEOP_PAGEIN, FALSE); MM_PAGEOP_PAGEIN, FALSE);
if (PageOp == NULL) if (PageOp == NULL)
{ {
DPRINT1("MmGetPageOp failed"); DPRINT1("MmGetPageOp failed");
@ -236,10 +236,10 @@ MmNotPresentFaultVirtualMemory(PMMSUPPORT AddressSpace,
{ {
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
Status = KeWaitForSingleObject(&PageOp->CompletionEvent, Status = KeWaitForSingleObject(&PageOp->CompletionEvent,
0, 0,
KernelMode, KernelMode,
FALSE, FALSE,
NULL); NULL);
/* /*
* Check for various strange conditions * Check for various strange conditions
*/ */
@ -319,18 +319,18 @@ MmNotPresentFaultVirtualMemory(PMMSUPPORT AddressSpace,
* try again * try again
*/ */
Status = MmCreateVirtualMapping(Process, Status = MmCreateVirtualMapping(Process,
(PVOID)PAGE_ROUND_DOWN(Address), (PVOID)PAGE_ROUND_DOWN(Address),
Region->Protect, Region->Protect,
&Page, &Page,
1); 1);
while (Status == STATUS_NO_MEMORY) while (Status == STATUS_NO_MEMORY)
{ {
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
Status = MmCreateVirtualMapping(Process, Status = MmCreateVirtualMapping(Process,
Address, Address,
Region->Protect, Region->Protect,
&Page, &Page,
1); 1);
MmLockAddressSpace(AddressSpace); MmLockAddressSpace(AddressSpace);
} }
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
@ -386,15 +386,15 @@ MmModifyAttributes(PMMSUPPORT AddressSpace,
SWAPENTRY SwapEntry; SWAPENTRY SwapEntry;
MmDeletePageFileMapping(Process, MmDeletePageFileMapping(Process,
(char*)BaseAddress + (i * PAGE_SIZE), (char*)BaseAddress + (i * PAGE_SIZE),
&SwapEntry); &SwapEntry);
MmFreeSwapPage(SwapEntry); MmFreeSwapPage(SwapEntry);
} }
else else
{ {
MmDeleteVirtualMapping(Process, MmDeleteVirtualMapping(Process,
(char*)BaseAddress + (i*PAGE_SIZE), (char*)BaseAddress + (i*PAGE_SIZE),
FALSE, NULL, &Page); FALSE, NULL, &Page);
if (Page != 0) if (Page != 0)
{ {
SWAPENTRY SavedSwapEntry; SWAPENTRY SavedSwapEntry;
@ -405,7 +405,7 @@ MmModifyAttributes(PMMSUPPORT AddressSpace,
MmSetSavedSwapEntryPage(Page, 0); MmSetSavedSwapEntryPage(Page, 0);
} }
MmDeleteRmap(Page, Process, MmDeleteRmap(Page, Process,
(char*)BaseAddress + (i * PAGE_SIZE)); (char*)BaseAddress + (i * PAGE_SIZE));
MmReleasePageMemoryConsumer(MC_USER, Page); MmReleasePageMemoryConsumer(MC_USER, Page);
} }
} }
@ -467,15 +467,15 @@ MiProtectVirtualMemory(IN PEPROCESS Process,
if (MemoryArea->Type == MEMORY_AREA_VIRTUAL_MEMORY) if (MemoryArea->Type == MEMORY_AREA_VIRTUAL_MEMORY)
{ {
Status = MmProtectAnonMem(AddressSpace, MemoryArea, *BaseAddress, Status = MmProtectAnonMem(AddressSpace, MemoryArea, *BaseAddress,
*NumberOfBytesToProtect, NewAccessProtection, *NumberOfBytesToProtect, NewAccessProtection,
OldAccessProtection); OldAccessProtection);
} }
else if (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW) else if (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW)
{ {
Status = MmProtectSectionView(AddressSpace, MemoryArea, *BaseAddress, Status = MmProtectSectionView(AddressSpace, MemoryArea, *BaseAddress,
*NumberOfBytesToProtect, *NumberOfBytesToProtect,
NewAccessProtection, NewAccessProtection,
OldAccessProtection); OldAccessProtection);
} }
else else
{ {
@ -659,11 +659,11 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
{ {
/* Reference the handle for correct permissions */ /* Reference the handle for correct permissions */
Status = ObReferenceObjectByHandle(ProcessHandle, Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_VM_OPERATION, PROCESS_VM_OPERATION,
PsProcessType, PsProcessType,
PreviousMode, PreviousMode,
(PVOID*)&Process, (PVOID*)&Process,
NULL); NULL);
if (!NT_SUCCESS(Status)) return Status; if (!NT_SUCCESS(Status)) return Status;
/* Check if not running in the current process */ /* Check if not running in the current process */
@ -722,7 +722,7 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
if (((ULONG_PTR)BaseAddress + RegionSize) > (ULONG_PTR)MemoryArea->EndingAddress) if (((ULONG_PTR)BaseAddress + RegionSize) > (ULONG_PTR)MemoryArea->EndingAddress)
{ {
DPRINT("BaseAddress + RegionSize %x is larger than MemoryArea's EndingAddress %x\n", DPRINT("BaseAddress + RegionSize %x is larger than MemoryArea's EndingAddress %x\n",
(ULONG_PTR)BaseAddress + RegionSize, MemoryArea->EndingAddress); (ULONG_PTR)BaseAddress + RegionSize, MemoryArea->EndingAddress);
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
if (Attached) KeUnstackDetachProcess(&ApcState); if (Attached) KeUnstackDetachProcess(&ApcState);
@ -752,12 +752,11 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
if (MemoryArea->Type == MEMORY_AREA_VIRTUAL_MEMORY && if (MemoryArea->Type == MEMORY_AREA_VIRTUAL_MEMORY &&
MemoryAreaLength >= RegionSize) MemoryAreaLength >= RegionSize)
{ {
Status = Status = MmAlterRegion(AddressSpace,
MmAlterRegion(AddressSpace, MemoryArea->StartingAddress,
MemoryArea->StartingAddress, &MemoryArea->Data.VirtualMemoryData.RegionListHead,
&MemoryArea->Data.VirtualMemoryData.RegionListHead, BaseAddress, RegionSize,
BaseAddress, RegionSize, Type, Protect, MmModifyAttributes);
Type, Protect, MmModifyAttributes);
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
if (Attached) KeUnstackDetachProcess(&ApcState); if (Attached) KeUnstackDetachProcess(&ApcState);
if (ProcessHandle != NtCurrentProcess()) ObDereferenceObject(Process); if (ProcessHandle != NtCurrentProcess()) ObDereferenceObject(Process);
@ -778,12 +777,11 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
/* Region list initialized? */ /* Region list initialized? */
if (MemoryArea->Data.SectionData.RegionListHead.Flink) if (MemoryArea->Data.SectionData.RegionListHead.Flink)
{ {
Status = Status = MmAlterRegion(AddressSpace,
MmAlterRegion(AddressSpace, MemoryArea->StartingAddress,
MemoryArea->StartingAddress, &MemoryArea->Data.SectionData.RegionListHead,
&MemoryArea->Data.SectionData.RegionListHead, BaseAddress, RegionSize,
BaseAddress, RegionSize, Type, Protect, MmModifyAttributes);
Type, Protect, MmModifyAttributes);
} }
else else
{ {
@ -816,14 +814,14 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
} }
Status = MmCreateMemoryArea(AddressSpace, Status = MmCreateMemoryArea(AddressSpace,
MEMORY_AREA_VIRTUAL_MEMORY, MEMORY_AREA_VIRTUAL_MEMORY,
&BaseAddress, &BaseAddress,
RegionSize, RegionSize,
Protect, Protect,
&MemoryArea, &MemoryArea,
PBaseAddress != 0, PBaseAddress != 0,
AllocationType & MEM_TOP_DOWN, AllocationType & MEM_TOP_DOWN,
BoundaryAddressMultiple); BoundaryAddressMultiple);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
@ -834,10 +832,10 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
} }
MemoryAreaLength = (ULONG_PTR)MemoryArea->EndingAddress - MemoryAreaLength = (ULONG_PTR)MemoryArea->EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress; (ULONG_PTR)MemoryArea->StartingAddress;
MmInitializeRegion(&MemoryArea->Data.VirtualMemoryData.RegionListHead, MmInitializeRegion(&MemoryArea->Data.VirtualMemoryData.RegionListHead,
MemoryAreaLength, Type, Protect); MemoryAreaLength, Type, Protect);
if ((AllocationType & MEM_COMMIT) && if ((AllocationType & MEM_COMMIT) &&
(Protect & (PAGE_READWRITE | PAGE_EXECUTE_READWRITE))) (Protect & (PAGE_READWRITE | PAGE_EXECUTE_READWRITE)))
@ -895,7 +893,7 @@ MmFreeVirtualMemory(PEPROCESS Process,
ULONG i; ULONG i;
DPRINT("MmFreeVirtualMemory(Process %p MemoryArea %p)\n", Process, DPRINT("MmFreeVirtualMemory(Process %p MemoryArea %p)\n", Process,
MemoryArea); MemoryArea);
/* Mark this memory area as about to be deleted. */ /* Mark this memory area as about to be deleted. */
MemoryArea->DeleteInProgress = TRUE; MemoryArea->DeleteInProgress = TRUE;
@ -914,17 +912,17 @@ MmFreeVirtualMemory(PEPROCESS Process,
{ {
PMM_PAGEOP PageOp; PMM_PAGEOP PageOp;
PageOp = MmCheckForPageOp(MemoryArea, Process->UniqueProcessId, PageOp = MmCheckForPageOp(MemoryArea, Process->UniqueProcessId,
(PVOID)((ULONG_PTR)MemoryArea->StartingAddress + (i * PAGE_SIZE)), (PVOID)((ULONG_PTR)MemoryArea->StartingAddress + (i * PAGE_SIZE)),
NULL, 0); NULL, 0);
if (PageOp != NULL) if (PageOp != NULL)
{ {
NTSTATUS Status; NTSTATUS Status;
MmUnlockAddressSpace(&Process->Vm); MmUnlockAddressSpace(&Process->Vm);
Status = KeWaitForSingleObject(&PageOp->CompletionEvent, Status = KeWaitForSingleObject(&PageOp->CompletionEvent,
0, 0,
KernelMode, KernelMode,
FALSE, FALSE,
NULL); NULL);
if (Status != STATUS_SUCCESS) if (Status != STATUS_SUCCESS)
{ {
DPRINT1("Failed to wait for page op\n"); DPRINT1("Failed to wait for page op\n");
@ -1046,11 +1044,11 @@ NtFreeVirtualMemory(IN HANDLE ProcessHandle,
{ {
/* Reference the handle for correct permissions */ /* Reference the handle for correct permissions */
Status = ObReferenceObjectByHandle(ProcessHandle, Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_VM_OPERATION, PROCESS_VM_OPERATION,
PsProcessType, PsProcessType,
PreviousMode, PreviousMode,
(PVOID*)&Process, (PVOID*)&Process,
NULL); NULL);
if (!NT_SUCCESS(Status)) return Status; if (!NT_SUCCESS(Status)) return Status;
/* Check if not running in the current process */ /* Check if not running in the current process */
@ -1064,7 +1062,7 @@ NtFreeVirtualMemory(IN HANDLE ProcessHandle,
BaseAddress = (PVOID)PAGE_ROUND_DOWN((PBaseAddress)); BaseAddress = (PVOID)PAGE_ROUND_DOWN((PBaseAddress));
RegionSize = PAGE_ROUND_UP((ULONG_PTR)(PBaseAddress) + (PRegionSize)) - RegionSize = PAGE_ROUND_UP((ULONG_PTR)(PBaseAddress) + (PRegionSize)) -
PAGE_ROUND_DOWN((PBaseAddress)); PAGE_ROUND_DOWN((PBaseAddress));
AddressSpace = &Process->Vm; AddressSpace = &Process->Vm;
@ -1092,17 +1090,16 @@ NtFreeVirtualMemory(IN HANDLE ProcessHandle,
goto unlock_deref_and_return; goto unlock_deref_and_return;
case MEM_DECOMMIT: case MEM_DECOMMIT:
Status = Status = MmAlterRegion(AddressSpace,
MmAlterRegion(AddressSpace, MemoryArea->StartingAddress,
MemoryArea->StartingAddress, (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW) ?
(MemoryArea->Type == MEMORY_AREA_SECTION_VIEW) ? &MemoryArea->Data.SectionData.RegionListHead :
&MemoryArea->Data.SectionData.RegionListHead : &MemoryArea->Data.VirtualMemoryData.RegionListHead,
&MemoryArea->Data.VirtualMemoryData.RegionListHead, BaseAddress,
BaseAddress, RegionSize,
RegionSize, MEM_RESERVE,
MEM_RESERVE, PAGE_NOACCESS,
PAGE_NOACCESS, MmModifyAttributes);
MmModifyAttributes);
goto unlock_deref_and_return; goto unlock_deref_and_return;
} }
@ -1135,8 +1132,8 @@ MmProtectAnonMem(PMMSUPPORT AddressSpace,
for (;;) for (;;)
{ {
Region = MmFindRegion(MemoryArea->StartingAddress, Region = MmFindRegion(MemoryArea->StartingAddress,
&MemoryArea->Data.VirtualMemoryData.RegionListHead, &MemoryArea->Data.VirtualMemoryData.RegionListHead,
(PVOID)((ULONG_PTR)BaseAddress + LengthCount), NULL); (PVOID)((ULONG_PTR)BaseAddress + LengthCount), NULL);
/* If a Region was found and it is committed */ /* If a Region was found and it is committed */
if ((Region) && (Region->Type == MEM_COMMIT)) if ((Region) && (Region->Type == MEM_COMMIT))
@ -1163,9 +1160,9 @@ MmProtectAnonMem(PMMSUPPORT AddressSpace,
{ {
*OldProtect = Region->Protect; *OldProtect = Region->Protect;
Status = MmAlterRegion(AddressSpace, MemoryArea->StartingAddress, Status = MmAlterRegion(AddressSpace, MemoryArea->StartingAddress,
&MemoryArea->Data.VirtualMemoryData.RegionListHead, &MemoryArea->Data.VirtualMemoryData.RegionListHead,
BaseAddress, Length, Region->Type, Protect, BaseAddress, Length, Region->Type, Protect,
MmModifyAttributes); MmModifyAttributes);
} }
return (Status); return (Status);
@ -1183,8 +1180,8 @@ MmQueryAnonMem(PMEMORY_AREA MemoryArea,
Info->BaseAddress = (PVOID)PAGE_ROUND_DOWN(Address); Info->BaseAddress = (PVOID)PAGE_ROUND_DOWN(Address);
Region = MmFindRegion(MemoryArea->StartingAddress, Region = MmFindRegion(MemoryArea->StartingAddress,
&MemoryArea->Data.VirtualMemoryData.RegionListHead, &MemoryArea->Data.VirtualMemoryData.RegionListHead,
Address, &RegionBase); Address, &RegionBase);
Info->BaseAddress = RegionBase; Info->BaseAddress = RegionBase;
Info->AllocationBase = MemoryArea->StartingAddress; Info->AllocationBase = MemoryArea->StartingAddress;
Info->AllocationProtect = MemoryArea->Protect; Info->AllocationProtect = MemoryArea->Protect;