Author: fireball
Date: Thu Mar 13 08:17:57 2008
New Revision: 32672
URL:
http://svn.reactos.org/svn/reactos?rev=3D32672&view=3Drev
Log:
- 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.
Modified:
trunk/reactos/ntoskrnl/cc/view.c
trunk/reactos/ntoskrnl/include/internal/mm.h
trunk/reactos/ntoskrnl/mm/marea.c
trunk/reactos/ntoskrnl/mm/ncache.c
trunk/reactos/ntoskrnl/mm/section.c
Modified: trunk/reactos/ntoskrnl/cc/view.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cc/view.c?re=
v=3D32672&r1=3D32671&r2=3D32672&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/ntoskrnl/cc/view.c (original)
+++ trunk/reactos/ntoskrnl/cc/view.c Thu Mar 13 08:17:57 2008
@@ -561,16 +561,13 @@
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 @@
KEBUGCHECKCC;
}
#endif
- Pfn =3D alloca(sizeof(PFN_TYPE) * ((Bcb->CacheSegmentSize / PAGE_SIZE)));
- for (i =3D 0; i < (Bcb->CacheSegmentSize / PAGE_SIZE); i++)
- {
- Status =3D MmRequestPageMemoryConsumer(MC_CACHE, TRUE, &Pfn[i]);
- if (!NT_SUCCESS(Status))
- {
- KEBUGCHECKCC;
- }
- }
- Status =3D 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);
}
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/inte=
rnal/mm.h?rev=3D32672&r1=3D32671&r2=3D32672&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/ntoskrnl/include/internal/mm.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/mm.h Thu Mar 13 08:17:57 2008
@@ -503,6 +503,13 @@
PVOID BaseAddress
);
=
+VOID
+NTAPI
+MmMapMemoryArea(PVOID BaseAddress,
+ ULONG Length,
+ ULONG Consumer,
+ ULONG Protection);
+
/* npool.c ***************************************************************=
****/
=
VOID
Modified: trunk/reactos/ntoskrnl/mm/marea.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/marea.c?r=
ev=3D32672&r1=3D32671&r2=3D32672&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/ntoskrnl/mm/marea.c (original)
+++ trunk/reactos/ntoskrnl/mm/marea.c Thu Mar 13 08:17:57 2008
@@ -1022,6 +1022,38 @@
return STATUS_SUCCESS;
}
=
+VOID NTAPI
+MmMapMemoryArea(PVOID BaseAddress,
+ ULONG Length,
+ ULONG Consumer,
+ ULONG Protection)
+{
+ ULONG i;
+ NTSTATUS Status;
+
+ for (i =3D 0; i < PAGE_ROUND_UP(Length) / PAGE_SIZE; i++)
+ {
+ PFN_TYPE Page;
+
+ Status =3D MmRequestPageMemoryConsumer(Consumer, TRUE, &Page);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Unable to allocate page\n");
+ KEBUGCHECK(0);
+ }
+ Status =3D 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,
Modified: trunk/reactos/ntoskrnl/mm/ncache.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ncache.c?=
rev=3D32672&r1=3D32671&r2=3D32672&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/ntoskrnl/mm/ncache.c (original)
+++ trunk/reactos/ntoskrnl/mm/ncache.c Thu Mar 13 08:17:57 2008
@@ -46,7 +46,6 @@
PVOID Result;
MEMORY_AREA* marea;
NTSTATUS Status;
- ULONG i;
ULONG Protect =3D PAGE_READWRITE|PAGE_SYSTEM|PAGE_NOCACHE|PAGE_WRITETHR=
OUGH;
PHYSICAL_ADDRESS BoundaryAddressMultiple;
=
@@ -66,20 +65,14 @@
=
if (!NT_SUCCESS(Status))
{
+ DPRINT1("Allocating marea for noncached mem failed with Status "
+ "0x%08X\n", Status);
return (NULL);
}
=
- for (i =3D 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 =3D MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &NPage);
- MmCreateVirtualMapping (NULL,
- (char*)Result + (i * PAGE_SIZE),
- Protect,
- &NPage,
- 1);
- }
return ((PVOID)Result);
}
=
Modified: trunk/reactos/ntoskrnl/mm/section.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/section.c=
?rev=3D32672&r1=3D32671&r2=3D32672&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/ntoskrnl/mm/section.c (original)
+++ trunk/reactos/ntoskrnl/mm/section.c Thu Mar 13 08:17:57 2008
@@ -4391,7 +4391,6 @@
PVOID Result;
MEMORY_AREA* marea;
NTSTATUS Status;
- ULONG i;
PMADDRESS_SPACE AddressSpace;
PHYSICAL_ADDRESS BoundaryAddressMultiple;
=
@@ -4418,27 +4417,10 @@
return (NULL);
}
DPRINT("Result %p\n",Result);
- for (i =3D 0; i < PAGE_ROUND_UP(Length) / PAGE_SIZE; i++)
- {
- PFN_TYPE Page;
-
- Status =3D MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &Page);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("Unable to allocate page\n");
- KEBUGCHECK(0);
- }
- Status =3D MmCreateVirtualMapping (NULL,
- (PVOID)((ULONG_PTR)Result + (i * PA=
GE_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);
}
=