[NTOS]: Delete anonmem.c and move the ARM3-compatible code to ARM3/virtual.c. Whatever remained is for sections only, so move it to mm/section.c

[NTOS]: Fix some broken assertions in NtFreeVirtualMemory. Lesson: Do not try to "optimize" Microsoft's ASSERTs.

svn path=/trunk/; revision=55982
This commit is contained in:
Sir Richard 2012-03-04 02:03:46 +00:00
parent 2d534ce868
commit 9732b09bc6
6 changed files with 1737 additions and 2070 deletions

View file

@ -223,7 +223,6 @@ list(APPEND SOURCE
mm/ARM3/vadnode.c
mm/ARM3/virtual.c
mm/ARM3/zeropage.c
mm/anonmem.c
mm/balance.c
mm/freelist.c
mm/marea.c

View file

@ -1126,6 +1126,16 @@ MiSyncARM3WithROS(
IN PVOID AddressEnd
);
NTSTATUS
NTAPI
MiRosProtectVirtualMemory(
IN PEPROCESS Process,
IN OUT PVOID *BaseAddress,
IN OUT PSIZE_T NumberOfBytesToProtect,
IN ULONG NewAccessProtection,
OUT PULONG OldAccessProtection OPTIONAL
);
NTSTATUS
NTAPI
MmArmAccessFault(
@ -1484,6 +1494,30 @@ MiLocateSubsection(
IN ULONG_PTR Vpn
);
NTSTATUS
NTAPI
MiQueryMemorySectionName(
IN HANDLE ProcessHandle,
IN PVOID BaseAddress,
OUT PVOID MemoryInformation,
IN SIZE_T MemoryInformationLength,
OUT PSIZE_T ReturnLength
);
NTSTATUS
NTAPI
MiRosAllocateVirtualMemory(
IN HANDLE ProcessHandle,
IN PEPROCESS Process,
IN PMEMORY_AREA MemoryArea,
IN PMMSUPPORT AddressSpace,
IN OUT PVOID* UBaseAddress,
IN BOOLEAN Attached,
IN OUT PSIZE_T URegionSize,
IN ULONG AllocationType,
IN ULONG Protect
);
POOL_TYPE
NTAPI
MmDeterminePoolType(

View file

@ -1130,6 +1130,71 @@ NotSection:
return Status;
}
NTSTATUS
NTAPI
MiQueryMemorySectionName(IN HANDLE ProcessHandle,
IN PVOID BaseAddress,
OUT PVOID MemoryInformation,
IN SIZE_T MemoryInformationLength,
OUT PSIZE_T ReturnLength)
{
PEPROCESS Process;
NTSTATUS Status;
WCHAR ModuleFileNameBuffer[MAX_PATH] = {0};
UNICODE_STRING ModuleFileName;
PMEMORY_SECTION_NAME SectionName = NULL;
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_QUERY_INFORMATION,
NULL,
PreviousMode,
(PVOID*)(&Process),
NULL);
if (!NT_SUCCESS(Status))
{
DPRINT("MiQueryMemorySectionName: ObReferenceObjectByHandle returned %x\n",Status);
return Status;
}
RtlInitEmptyUnicodeString(&ModuleFileName, ModuleFileNameBuffer, sizeof(ModuleFileNameBuffer));
Status = MmGetFileNameForAddress(BaseAddress, &ModuleFileName);
if (NT_SUCCESS(Status))
{
SectionName = MemoryInformation;
if (PreviousMode != KernelMode)
{
_SEH2_TRY
{
RtlInitUnicodeString(&SectionName->SectionFileName, SectionName->NameBuffer);
SectionName->SectionFileName.MaximumLength = (USHORT)MemoryInformationLength;
RtlCopyUnicodeString(&SectionName->SectionFileName, &ModuleFileName);
if (ReturnLength) *ReturnLength = ModuleFileName.Length;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
Status = _SEH2_GetExceptionCode();
}
_SEH2_END;
}
else
{
RtlInitUnicodeString(&SectionName->SectionFileName, SectionName->NameBuffer);
SectionName->SectionFileName.MaximumLength = (USHORT)MemoryInformationLength;
RtlCopyUnicodeString(&SectionName->SectionFileName, &ModuleFileName);
if (ReturnLength) *ReturnLength = ModuleFileName.Length;
}
}
ObDereferenceObject(Process);
return Status;
}
/* PUBLIC FUNCTIONS ***********************************************************/
/*
@ -1376,6 +1441,53 @@ MmMapViewOfArm3Section(IN PVOID SectionObject,
return Status;
}
/*
* @unimplemented
*/
BOOLEAN
NTAPI
MmDisableModifiedWriteOfSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer)
{
UNIMPLEMENTED;
return FALSE;
}
/*
* @unimplemented
*/
BOOLEAN
NTAPI
MmForceSectionClosed(IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
IN BOOLEAN DelayClose)
{
UNIMPLEMENTED;
return FALSE;
}
/*
* @unimplemented
*/
NTSTATUS
NTAPI
MmMapViewInSessionSpace(IN PVOID Section,
OUT PVOID *MappedBase,
IN OUT PSIZE_T ViewSize)
{
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
}
/*
* @unimplemented
*/
NTSTATUS
NTAPI
MmUnmapViewInSessionSpace(IN PVOID MappedBase)
{
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
}
/* SYSTEM CALLS ***************************************************************/
NTSTATUS
@ -1922,53 +2034,4 @@ NtExtendSection(IN HANDLE SectionHandle,
return STATUS_NOT_IMPLEMENTED;
}
/* PUBLIC FUNCTIONS ***********************************************************/
/*
* @unimplemented
*/
BOOLEAN
NTAPI
MmDisableModifiedWriteOfSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer)
{
UNIMPLEMENTED;
return FALSE;
}
/*
* @unimplemented
*/
BOOLEAN
NTAPI
MmForceSectionClosed(IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
IN BOOLEAN DelayClose)
{
UNIMPLEMENTED;
return FALSE;
}
/*
* @unimplemented
*/
NTSTATUS
NTAPI
MmMapViewInSessionSpace(IN PVOID Section,
OUT PVOID *MappedBase,
IN OUT PSIZE_T ViewSize)
{
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
}
/*
* @unimplemented
*/
NTSTATUS
NTAPI
MmUnmapViewInSessionSpace(IN PVOID MappedBase)
{
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
}
/* EOF */

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -5211,4 +5211,133 @@ MmCreateSection (OUT PVOID * Section,
return Status;
}
VOID
MmModifyAttributes(IN PMMSUPPORT AddressSpace,
IN PVOID BaseAddress,
IN SIZE_T RegionSize,
IN ULONG OldType,
IN ULONG OldProtect,
IN ULONG NewType,
IN ULONG NewProtect)
{
//
// This function is deprecated but remains in order to support VirtualAlloc
// calls with MEM_COMMIT on top of MapViewOfFile calls with SEC_RESERVE.
//
// Win32k's shared user heap, for example, uses that mechanism. The two
// conditions when this function needs to do something are ASSERTed for,
// because they should not arise.
//
if (NewType == MEM_RESERVE && OldType == MEM_COMMIT)
{
ASSERT(FALSE);
}
if ((NewType == MEM_COMMIT) && (OldType == MEM_COMMIT))
{
ASSERT(OldProtect == NewProtect);
}
}
NTSTATUS
NTAPI
MiRosAllocateVirtualMemory(IN HANDLE ProcessHandle,
IN PEPROCESS Process,
IN PMEMORY_AREA MemoryArea,
IN PMMSUPPORT AddressSpace,
IN OUT PVOID* UBaseAddress,
IN BOOLEAN Attached,
IN OUT PSIZE_T URegionSize,
IN ULONG AllocationType,
IN ULONG Protect)
{
ULONG_PTR PRegionSize;
ULONG Type, RegionSize;
NTSTATUS Status;
PVOID PBaseAddress, BaseAddress;
KAPC_STATE ApcState;
PBaseAddress = *UBaseAddress;
PRegionSize = *URegionSize;
BaseAddress = (PVOID)PAGE_ROUND_DOWN(PBaseAddress);
RegionSize = PAGE_ROUND_UP((ULONG_PTR)PBaseAddress + PRegionSize) -
PAGE_ROUND_DOWN(PBaseAddress);
Type = (AllocationType & MEM_COMMIT) ? MEM_COMMIT : MEM_RESERVE;
ASSERT(PBaseAddress != 0);
ASSERT(Type == MEM_COMMIT);
ASSERT(MemoryArea->Type == MEMORY_AREA_SECTION_VIEW);
ASSERT(((ULONG_PTR)BaseAddress + RegionSize) <= (ULONG_PTR)MemoryArea->EndingAddress);
ASSERT(((ULONG_PTR)MemoryArea->EndingAddress - (ULONG_PTR)MemoryArea->StartingAddress) >= RegionSize);
ASSERT(MemoryArea->Data.SectionData.RegionListHead.Flink);
Status = MmAlterRegion(AddressSpace,
MemoryArea->StartingAddress,
&MemoryArea->Data.SectionData.RegionListHead,
BaseAddress,
RegionSize,
Type,
Protect,
MmModifyAttributes);
MmUnlockAddressSpace(AddressSpace);
if (Attached) KeUnstackDetachProcess(&ApcState);
if (ProcessHandle != NtCurrentProcess()) ObDereferenceObject(Process);
if (NT_SUCCESS(Status))
{
*UBaseAddress = BaseAddress;
*URegionSize = RegionSize;
}
return Status;
}
NTSTATUS
NTAPI
MiRosProtectVirtualMemory(IN PEPROCESS Process,
IN OUT PVOID *BaseAddress,
IN OUT PSIZE_T NumberOfBytesToProtect,
IN ULONG NewAccessProtection,
OUT PULONG OldAccessProtection OPTIONAL)
{
PMEMORY_AREA MemoryArea;
PMMSUPPORT AddressSpace;
ULONG OldAccessProtection_;
NTSTATUS Status;
*NumberOfBytesToProtect = PAGE_ROUND_UP((ULONG_PTR)(*BaseAddress) + (*NumberOfBytesToProtect)) - PAGE_ROUND_DOWN(*BaseAddress);
*BaseAddress = (PVOID)PAGE_ROUND_DOWN(*BaseAddress);
AddressSpace = &Process->Vm;
MmLockAddressSpace(AddressSpace);
MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, *BaseAddress);
if (MemoryArea == NULL || MemoryArea->DeleteInProgress)
{
MmUnlockAddressSpace(AddressSpace);
return STATUS_UNSUCCESSFUL;
}
if (OldAccessProtection == NULL) OldAccessProtection = &OldAccessProtection_;
if (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW)
{
Status = MmProtectSectionView(AddressSpace,
MemoryArea,
*BaseAddress,
*NumberOfBytesToProtect,
NewAccessProtection,
OldAccessProtection);
}
else
{
/* FIXME: Should we return failure or success in this case? */
Status = STATUS_CONFLICTING_ADDRESSES;
}
MmUnlockAddressSpace(AddressSpace);
return Status;
}
/* EOF */