mirror of
https://github.com/reactos/reactos.git
synced 2025-06-01 23:48:12 +00:00
- Factor out physical pages allocation and creating a virtual mapping into a standalone function called MmMapMemoryArea (idea proposed by Art Yerkes).
- As a result, removed one case of a potentially dangerous _alloca usage in the kernel, increased code readability. svn path=/trunk/; revision=32672
This commit is contained in:
parent
9901f9409a
commit
b473957147
5 changed files with 50 additions and 53 deletions
|
@ -561,16 +561,13 @@ CcRosCreateCacheSegment(PBCB Bcb,
|
|||
ULONG FileOffset,
|
||||
PCACHE_SEGMENT* CacheSeg)
|
||||
{
|
||||
ULONG i;
|
||||
PCACHE_SEGMENT current;
|
||||
PCACHE_SEGMENT previous;
|
||||
PLIST_ENTRY current_entry;
|
||||
NTSTATUS Status;
|
||||
KIRQL oldIrql;
|
||||
PPFN_TYPE Pfn;
|
||||
#ifdef CACHE_BITMAP
|
||||
ULONG StartingOffset;
|
||||
#else
|
||||
#endif
|
||||
PHYSICAL_ADDRESS BoundaryAddressMultiple;
|
||||
|
||||
|
@ -706,24 +703,10 @@ CcRosCreateCacheSegment(PBCB Bcb,
|
|||
KEBUGCHECKCC;
|
||||
}
|
||||
#endif
|
||||
Pfn = alloca(sizeof(PFN_TYPE) * ((Bcb->CacheSegmentSize / PAGE_SIZE)));
|
||||
for (i = 0; i < (Bcb->CacheSegmentSize / PAGE_SIZE); i++)
|
||||
{
|
||||
Status = MmRequestPageMemoryConsumer(MC_CACHE, TRUE, &Pfn[i]);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
KEBUGCHECKCC;
|
||||
}
|
||||
}
|
||||
Status = MmCreateVirtualMapping(NULL,
|
||||
current->BaseAddress,
|
||||
PAGE_READWRITE,
|
||||
Pfn,
|
||||
Bcb->CacheSegmentSize / PAGE_SIZE);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
KEBUGCHECKCC;
|
||||
}
|
||||
|
||||
/* Create a virtual mapping for this memory area */
|
||||
MmMapMemoryArea(current->BaseAddress, Bcb->CacheSegmentSize,
|
||||
MC_CACHE, PAGE_READWRITE);
|
||||
|
||||
return(STATUS_SUCCESS);
|
||||
}
|
||||
|
|
|
@ -503,6 +503,13 @@ MmReleaseMemoryAreaIfDecommitted(
|
|||
PVOID BaseAddress
|
||||
);
|
||||
|
||||
VOID
|
||||
NTAPI
|
||||
MmMapMemoryArea(PVOID BaseAddress,
|
||||
ULONG Length,
|
||||
ULONG Consumer,
|
||||
ULONG Protection);
|
||||
|
||||
/* npool.c *******************************************************************/
|
||||
|
||||
VOID
|
||||
|
|
|
@ -1022,6 +1022,38 @@ MmCreateMemoryArea(PMADDRESS_SPACE AddressSpace,
|
|||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
VOID NTAPI
|
||||
MmMapMemoryArea(PVOID BaseAddress,
|
||||
ULONG Length,
|
||||
ULONG Consumer,
|
||||
ULONG Protection)
|
||||
{
|
||||
ULONG i;
|
||||
NTSTATUS Status;
|
||||
|
||||
for (i = 0; i < PAGE_ROUND_UP(Length) / PAGE_SIZE; i++)
|
||||
{
|
||||
PFN_TYPE Page;
|
||||
|
||||
Status = MmRequestPageMemoryConsumer(Consumer, TRUE, &Page);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Unable to allocate page\n");
|
||||
KEBUGCHECK(0);
|
||||
}
|
||||
Status = MmCreateVirtualMapping (NULL,
|
||||
(PVOID)((ULONG_PTR)BaseAddress + (i * PAGE_SIZE)),
|
||||
Protection,
|
||||
&Page,
|
||||
1);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Unable to create virtual mapping\n");
|
||||
KEBUGCHECK(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VOID STDCALL
|
||||
MmReleaseMemoryAreaIfDecommitted(PEPROCESS Process,
|
||||
|
|
|
@ -46,7 +46,6 @@ MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
|
|||
PVOID Result;
|
||||
MEMORY_AREA* marea;
|
||||
NTSTATUS Status;
|
||||
ULONG i;
|
||||
ULONG Protect = PAGE_READWRITE|PAGE_SYSTEM|PAGE_NOCACHE|PAGE_WRITETHROUGH;
|
||||
PHYSICAL_ADDRESS BoundaryAddressMultiple;
|
||||
|
||||
|
@ -66,20 +65,14 @@ MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
|
|||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Allocating marea for noncached mem failed with Status "
|
||||
"0x%08X\n", Status);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / PAGE_SIZE); i++)
|
||||
{
|
||||
PFN_TYPE NPage;
|
||||
/* Create a virtual mapping for this memory area */
|
||||
MmMapMemoryArea(Result, NumberOfBytes, MC_NPPOOL, Protect);
|
||||
|
||||
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &NPage);
|
||||
MmCreateVirtualMapping (NULL,
|
||||
(char*)Result + (i * PAGE_SIZE),
|
||||
Protect,
|
||||
&NPage,
|
||||
1);
|
||||
}
|
||||
return ((PVOID)Result);
|
||||
}
|
||||
|
||||
|
|
|
@ -4391,7 +4391,6 @@ MmAllocateSection (IN ULONG Length, PVOID BaseAddress)
|
|||
PVOID Result;
|
||||
MEMORY_AREA* marea;
|
||||
NTSTATUS Status;
|
||||
ULONG i;
|
||||
PMADDRESS_SPACE AddressSpace;
|
||||
PHYSICAL_ADDRESS BoundaryAddressMultiple;
|
||||
|
||||
|
@ -4418,27 +4417,10 @@ MmAllocateSection (IN ULONG Length, PVOID BaseAddress)
|
|||
return (NULL);
|
||||
}
|
||||
DPRINT("Result %p\n",Result);
|
||||
for (i = 0; i < PAGE_ROUND_UP(Length) / PAGE_SIZE; i++)
|
||||
{
|
||||
PFN_TYPE Page;
|
||||
|
||||
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &Page);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Unable to allocate page\n");
|
||||
KEBUGCHECK(0);
|
||||
}
|
||||
Status = MmCreateVirtualMapping (NULL,
|
||||
(PVOID)((ULONG_PTR)Result + (i * PAGE_SIZE)),
|
||||
PAGE_READWRITE,
|
||||
&Page,
|
||||
1);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Unable to create virtual mapping\n");
|
||||
KEBUGCHECK(0);
|
||||
}
|
||||
}
|
||||
/* Create a virtual mapping for this memory area */
|
||||
MmMapMemoryArea(Result, Length, MC_NPPOOL, PAGE_READWRITE);
|
||||
|
||||
return ((PVOID)Result);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue