mirror of
https://github.com/reactos/reactos.git
synced 2025-04-26 16:40:27 +00:00
[NTOS:MM] Reduce the magnitude of the MiRosProtectVirtualMemory hack
This commit is contained in:
parent
f60128b69d
commit
1f27911997
2 changed files with 20 additions and 47 deletions
|
@ -2153,46 +2153,6 @@ MiIsEntireRangeCommitted(IN ULONG_PTR StartingAddress,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
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_;
|
|
||||||
|
|
||||||
ASSERT(MemoryArea->Type == MEMORY_AREA_SECTION_VIEW);
|
|
||||||
Status = MmProtectSectionView(AddressSpace,
|
|
||||||
MemoryArea,
|
|
||||||
*BaseAddress,
|
|
||||||
*NumberOfBytesToProtect,
|
|
||||||
NewAccessProtection,
|
|
||||||
OldAccessProtection);
|
|
||||||
|
|
||||||
MmUnlockAddressSpace(AddressSpace);
|
|
||||||
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
MiProtectVirtualMemory(IN PEPROCESS Process,
|
MiProtectVirtualMemory(IN PEPROCESS Process,
|
||||||
|
@ -2254,13 +2214,18 @@ MiProtectVirtualMemory(IN PEPROCESS Process,
|
||||||
/* Check if this is a ROSMM VAD */
|
/* Check if this is a ROSMM VAD */
|
||||||
if (MI_IS_ROSMM_VAD(Vad))
|
if (MI_IS_ROSMM_VAD(Vad))
|
||||||
{
|
{
|
||||||
/* Not very awesome hack */
|
/* Not too shabby hack */
|
||||||
MmUnlockAddressSpace(AddressSpace);
|
ASSERT(((PMEMORY_AREA)Vad)->Type == MEMORY_AREA_SECTION_VIEW);
|
||||||
return MiRosProtectVirtualMemory(Process,
|
*NumberOfBytesToProtect = PAGE_ROUND_UP((ULONG_PTR)(*BaseAddress) + (*NumberOfBytesToProtect)) - PAGE_ROUND_DOWN(*BaseAddress);
|
||||||
BaseAddress,
|
*BaseAddress = (PVOID)PAGE_ROUND_DOWN(*BaseAddress);
|
||||||
NumberOfBytesToProtect,
|
Status = MmProtectSectionView(AddressSpace,
|
||||||
|
(PMEMORY_AREA)Vad,
|
||||||
|
*BaseAddress,
|
||||||
|
*NumberOfBytesToProtect,
|
||||||
NewAccessProtection,
|
NewAccessProtection,
|
||||||
OldAccessProtection);
|
OldAccessProtection);
|
||||||
|
MmUnlockAddressSpace(AddressSpace);
|
||||||
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure the address is within this VAD's boundaries */
|
/* Make sure the address is within this VAD's boundaries */
|
||||||
|
|
|
@ -2076,6 +2076,13 @@ MmProtectSectionView(PMMSUPPORT AddressSpace,
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
ULONG_PTR MaxLength;
|
ULONG_PTR MaxLength;
|
||||||
|
|
||||||
|
ASSERT(MemoryArea->Type == MEMORY_AREA_SECTION_VIEW);
|
||||||
|
|
||||||
|
if (MemoryArea->DeleteInProgress)
|
||||||
|
{
|
||||||
|
return STATUS_UNSUCCESSFUL;
|
||||||
|
}
|
||||||
|
|
||||||
MaxLength = MA_GetEndingAddress(MemoryArea) - (ULONG_PTR)BaseAddress;
|
MaxLength = MA_GetEndingAddress(MemoryArea) - (ULONG_PTR)BaseAddress;
|
||||||
if (Length > MaxLength)
|
if (Length > MaxLength)
|
||||||
Length = (ULONG)MaxLength;
|
Length = (ULONG)MaxLength;
|
||||||
|
@ -2091,6 +2098,7 @@ MmProtectSectionView(PMMSUPPORT AddressSpace,
|
||||||
return STATUS_INVALID_PAGE_PROTECTION;
|
return STATUS_INVALID_PAGE_PROTECTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (OldProtect != NULL)
|
||||||
*OldProtect = Region->Protect;
|
*OldProtect = Region->Protect;
|
||||||
Status = MmAlterRegion(AddressSpace, (PVOID)MA_GetStartingAddress(MemoryArea),
|
Status = MmAlterRegion(AddressSpace, (PVOID)MA_GetStartingAddress(MemoryArea),
|
||||||
&MemoryArea->SectionData.RegionListHead,
|
&MemoryArea->SectionData.RegionListHead,
|
||||||
|
|
Loading…
Reference in a new issue