Lock address space before calling MmCreateMemoryArea.

svn path=/trunk/; revision=2143
This commit is contained in:
Eugene Ingerman 2001-08-03 09:36:19 +00:00
parent 3208a93c26
commit e2e13b71ce
8 changed files with 61 additions and 30 deletions

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: view.c,v 1.26 2001/05/04 01:21:43 rex Exp $
/* $Id: view.c,v 1.27 2001/08/03 09:36:18 ei Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -119,7 +119,8 @@ CcRosGetCacheSegment(PBCB Bcb,
PLIST_ENTRY current_entry;
PCACHE_SEGMENT current;
ULONG i;
NTSTATUS Status;
KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
current_entry = Bcb->CacheSegmentListHead.Flink;
@ -145,14 +146,17 @@ CcRosGetCacheSegment(PBCB Bcb,
current_entry = current_entry->Flink;
}
DPRINT("Creating new segment\n");
DPRINT("Creating new segment\n");
KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
current = ExAllocatePoolWithTag(NonPagedPool, sizeof(CACHE_SEGMENT),
TAG_CSEG);
MmLockAddressSpace(MmGetKernelAddressSpace());
current->BaseAddress = NULL;
MmCreateMemoryArea(KernelMode,
Status = MmCreateMemoryArea(KernelMode,
MmGetKernelAddressSpace(),
MEMORY_AREA_CACHE_SEGMENT,
&current->BaseAddress,
@ -160,6 +164,12 @@ CcRosGetCacheSegment(PBCB Bcb,
PAGE_READWRITE,
(PMEMORY_AREA*)&current->MemoryArea,
FALSE);
if (!NT_SUCCESS(Status))
{
MmUnlockAddressSpace(MmGetKernelAddressSpace());
KeBugCheck(0);
}
current->Valid = FALSE;
current->FileOffset = ROUND_DOWN(FileOffset, Bcb->CacheSegmentSize);
current->Bcb = Bcb;
@ -172,14 +182,17 @@ CcRosGetCacheSegment(PBCB Bcb,
*BaseOffset = current->FileOffset;
for (i = 0; i < (Bcb->CacheSegmentSize / PAGESIZE); i++)
{
MmCreateVirtualMapping(NULL,
Status = MmCreateVirtualMapping(NULL,
current->BaseAddress + (i * PAGESIZE),
PAGE_READWRITE,
(ULONG)MmAllocPage(0));
}
if (!NT_SUCCESS(Status)){
MmUnlockAddressSpace(MmGetKernelAddressSpace());
KeBugCheck(0);
}
}
MmUnlockAddressSpace(MmGetKernelAddressSpace());
return(STATUS_SUCCESS);
}

View file

@ -109,7 +109,9 @@ KeInitializeThread(PKPROCESS Process, PKTHREAD Thread, BOOLEAN First)
if (!First)
{
KernelStack = NULL;
Status = MmCreateMemoryArea(NULL,
MmLockAddressSpace(MmGetKernelAddressSpace());
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_KERNEL_STACK,
&KernelStack,
@ -117,6 +119,8 @@ KeInitializeThread(PKPROCESS Process, PKTHREAD Thread, BOOLEAN First)
0,
&StackArea,
FALSE);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to create thread stack\n");
@ -141,6 +145,7 @@ KeInitializeThread(PKPROCESS Process, PKTHREAD Thread, BOOLEAN First)
Thread->StackLimit = (ULONG)&init_stack;
Thread->KernelStack = (PVOID)&init_stack_top;
}
/*
* The Native API function will initialize the TEB field later
*/

View file

@ -1,4 +1,4 @@
/* $Id: cont.c,v 1.12 2001/05/05 19:13:10 chorns Exp $
/* $Id: cont.c,v 1.13 2001/08/03 09:36:18 ei Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -38,7 +38,8 @@ MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
PVOID BaseAddress = 0;
PVOID PBase;
ULONG i;
MmLockAddressSpace(MmGetKernelAddressSpace());
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_CONTINUOUS_MEMORY,
@ -47,6 +48,8 @@ MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
0,
&MArea,
FALSE);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status))
{
return(NULL);

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: iospace.c,v 1.11 2001/05/01 23:08:20 chorns Exp $
/* $Id: iospace.c,v 1.12 2001/08/03 09:36:18 ei Exp $
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/iospace.c
@ -74,7 +74,8 @@ MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
NTSTATUS Status;
ULONG i;
ULONG Attributes;
MmLockAddressSpace(MmGetKernelAddressSpace());
Result = NULL;
Status = MmCreateMemoryArea (NULL,
MmGetKernelAddressSpace(),
@ -84,6 +85,8 @@ MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
0,
&marea,
FALSE);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(STATUS_SUCCESS))
{
return (NULL);

View file

@ -1,4 +1,4 @@
/* $Id: mminit.c,v 1.22 2001/05/03 17:23:59 chorns Exp $
/* $Id: mminit.c,v 1.23 2001/08/03 09:36:18 ei Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
@ -96,6 +96,8 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
BaseAddress = (PVOID)KERNEL_BASE;
Length = PAGE_ROUND_UP(((ULONG)&_text_end__)) - KERNEL_BASE;
ParamLength = ParamLength - Length;
MmLockAddressSpace(MmGetKernelAddressSpace());
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
@ -104,12 +106,15 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
0,
&kernel_text_desc,
FALSE);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
Length = PAGE_ROUND_UP(((ULONG)&_bss_end__)) -
PAGE_ROUND_UP(((ULONG)&_text_end__));
ParamLength = ParamLength - Length;
DPRINT("Length %x\n",Length);
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG)&_text_end__));
DPRINT("BaseAddress %x\n",BaseAddress);
MmLockAddressSpace(MmGetKernelAddressSpace());
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
@ -152,7 +157,7 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
0,
&kernel_shared_data_desc,
FALSE);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
MmSharedDataPagePhysicalAddress = MmAllocPage(0);
Status = MmCreateVirtualMapping(NULL,
(PVOID)KERNEL_SHARED_DATA_BASE,

View file

@ -1,4 +1,4 @@
/* $Id: ncache.c,v 1.10 2001/03/25 02:34:28 dwelch Exp $
/* $Id: ncache.c,v 1.11 2001/08/03 09:36:18 ei Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -53,6 +53,7 @@ MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
ULONG i;
ULONG Attributes;
MmLockAddressSpace(MmGetKernelAddressSpace());
Result = NULL;
Status = MmCreateMemoryArea (NULL,
MmGetKernelAddressSpace(),
@ -62,6 +63,8 @@ MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
0,
&marea,
FALSE);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status))
{
return (NULL);

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: section.c,v 1.58 2001/06/16 14:09:21 ekohl Exp $
/* $Id: section.c,v 1.59 2001/08/03 09:36:18 ei Exp $
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/section.c
@ -262,7 +262,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
FileObject = MemoryArea->Data.SectionData.Section->FileObject;
Fcb = (PREACTOS_COMMON_FCB_HEADER)FileObject->FsContext;
if (FileObject->Flags & FO_DIRECT_CACHE_PAGING_READ &&
(Offset->QuadPart % PAGESIZE) == 0)
{
@ -272,7 +272,6 @@ MiReadPage(PMEMORY_AREA MemoryArea,
PCACHE_SEGMENT CacheSeg;
LARGE_INTEGER SegOffset;
PHYSICAL_ADDRESS Addr;
Status = CcRosGetCacheSegment(Fcb->Bcb,
(ULONG)Offset->QuadPart,
&BaseOffset,
@ -283,12 +282,10 @@ MiReadPage(PMEMORY_AREA MemoryArea,
{
return(Status);
}
if (!UptoDate)
{
Mdl = MmCreateMdl(NULL, BaseAddress, Fcb->Bcb->CacheSegmentSize);
MmBuildMdlForNonPagedPool(Mdl);
SegOffset.QuadPart = BaseOffset;
Status = IoPageRead(FileObject,
Mdl,
@ -301,7 +298,6 @@ MiReadPage(PMEMORY_AREA MemoryArea,
return(Status);
}
}
Addr = MmGetPhysicalAddress(BaseAddress +
Offset->QuadPart - BaseOffset);
(*Page) = (PVOID)(ULONG)Addr.QuadPart;
@ -312,7 +308,6 @@ MiReadPage(PMEMORY_AREA MemoryArea,
}
else
{
/*
* Allocate a page, this is rather complicated by the possibility
* we might have to move other things out of memory
@ -329,7 +324,6 @@ MiReadPage(PMEMORY_AREA MemoryArea,
*/
Mdl = MmCreateMdl(NULL, NULL, PAGESIZE);
MmBuildMdlFromPages(Mdl, (PULONG)Page);
/*
* Call the FSD to read the page
*/
@ -1687,7 +1681,7 @@ MmMapViewOfSegment(PEPROCESS Process,
PMEMORY_AREA MArea;
NTSTATUS Status;
KIRQL oldIrql;
MmLockAddressSpace(&Process->AddressSpace);
Status = MmCreateMemoryArea(Process,
&Process->AddressSpace,
MEMORY_AREA_SECTION_VIEW_COMMIT,
@ -1696,6 +1690,7 @@ MmMapViewOfSegment(PEPROCESS Process,
Protect,
&MArea,
FALSE);
MmUnlockAddressSpace(&Process->AddressSpace);
if (!NT_SUCCESS(Status))
{
return(Status);
@ -2104,7 +2099,7 @@ NtQuerySection (IN HANDLE SectionHandle,
ObDereferenceObject(Section);
return(STATUS_INFO_LENGTH_MISMATCH);
}
Sii = (PSECTION_IMAGE_INFORMATION)SectionInformation;
Sii->EntryPoint = Section->EntryPoint;
Sii->Unknown1 = 0;
Sii->StackReserve = Section->StackReserve;
@ -2182,6 +2177,7 @@ MmAllocateSection (IN ULONG Length)
FALSE);
if (!NT_SUCCESS(STATUS_SUCCESS))
{
MmUnlockAddressSpace(AddressSpace);
return (NULL);
}
DPRINT("Result %p\n",Result);
@ -2194,7 +2190,8 @@ MmAllocateSection (IN ULONG Length)
if (!NT_SUCCESS(Status))
{
DbgPrint("Unable to create virtual mapping\n");
KeBugCheck(0);
MmUnlockAddressSpace(AddressSpace);
KeBugCheck(0);
}
}
MmUnlockAddressSpace(AddressSpace);

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: wset.c,v 1.9 2001/03/25 02:34:29 dwelch Exp $
/* $Id: wset.c,v 1.10 2001/08/03 09:36:19 ei Exp $
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/wset.c
@ -143,7 +143,8 @@ MmInitializeWorkingSet(PEPROCESS Process, PMADDRESS_SPACE AddressSpace)
KeBugCheck(0);
}
BaseAddress = 0;
MmLockAddressSpace(MmGetKernelAddressSpace());
BaseAddress = NULL;
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_WORKING_SET,
@ -152,6 +153,7 @@ MmInitializeWorkingSet(PEPROCESS Process, PMADDRESS_SPACE AddressSpace)
0,
&AddressSpace->WorkingSetArea,
FALSE);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status))
{
KeBugCheck(0);