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 * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -119,6 +119,7 @@ CcRosGetCacheSegment(PBCB Bcb,
PLIST_ENTRY current_entry; PLIST_ENTRY current_entry;
PCACHE_SEGMENT current; PCACHE_SEGMENT current;
ULONG i; ULONG i;
NTSTATUS Status;
KeAcquireSpinLock(&Bcb->BcbLock, &oldirql); KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
@ -151,8 +152,11 @@ CcRosGetCacheSegment(PBCB Bcb,
current = ExAllocatePoolWithTag(NonPagedPool, sizeof(CACHE_SEGMENT), current = ExAllocatePoolWithTag(NonPagedPool, sizeof(CACHE_SEGMENT),
TAG_CSEG); TAG_CSEG);
MmLockAddressSpace(MmGetKernelAddressSpace());
current->BaseAddress = NULL; current->BaseAddress = NULL;
MmCreateMemoryArea(KernelMode,
Status = MmCreateMemoryArea(KernelMode,
MmGetKernelAddressSpace(), MmGetKernelAddressSpace(),
MEMORY_AREA_CACHE_SEGMENT, MEMORY_AREA_CACHE_SEGMENT,
&current->BaseAddress, &current->BaseAddress,
@ -160,6 +164,12 @@ CcRosGetCacheSegment(PBCB Bcb,
PAGE_READWRITE, PAGE_READWRITE,
(PMEMORY_AREA*)&current->MemoryArea, (PMEMORY_AREA*)&current->MemoryArea,
FALSE); FALSE);
if (!NT_SUCCESS(Status))
{
MmUnlockAddressSpace(MmGetKernelAddressSpace());
KeBugCheck(0);
}
current->Valid = FALSE; current->Valid = FALSE;
current->FileOffset = ROUND_DOWN(FileOffset, Bcb->CacheSegmentSize); current->FileOffset = ROUND_DOWN(FileOffset, Bcb->CacheSegmentSize);
current->Bcb = Bcb; current->Bcb = Bcb;
@ -172,14 +182,17 @@ CcRosGetCacheSegment(PBCB Bcb,
*BaseOffset = current->FileOffset; *BaseOffset = current->FileOffset;
for (i = 0; i < (Bcb->CacheSegmentSize / PAGESIZE); i++) for (i = 0; i < (Bcb->CacheSegmentSize / PAGESIZE); i++)
{ {
MmCreateVirtualMapping(NULL, Status = MmCreateVirtualMapping(NULL,
current->BaseAddress + (i * PAGESIZE), current->BaseAddress + (i * PAGESIZE),
PAGE_READWRITE, PAGE_READWRITE,
(ULONG)MmAllocPage(0)); (ULONG)MmAllocPage(0));
if (!NT_SUCCESS(Status)){
MmUnlockAddressSpace(MmGetKernelAddressSpace());
KeBugCheck(0);
} }
}
MmUnlockAddressSpace(MmGetKernelAddressSpace());
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }

View file

@ -109,6 +109,8 @@ KeInitializeThread(PKPROCESS Process, PKTHREAD Thread, BOOLEAN First)
if (!First) if (!First)
{ {
KernelStack = NULL; KernelStack = NULL;
MmLockAddressSpace(MmGetKernelAddressSpace());
Status = MmCreateMemoryArea(NULL, Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(), MmGetKernelAddressSpace(),
MEMORY_AREA_KERNEL_STACK, MEMORY_AREA_KERNEL_STACK,
@ -117,6 +119,8 @@ KeInitializeThread(PKPROCESS Process, PKTHREAD Thread, BOOLEAN First)
0, 0,
&StackArea, &StackArea,
FALSE); FALSE);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("Failed to create thread stack\n"); DPRINT1("Failed to create thread stack\n");
@ -141,6 +145,7 @@ KeInitializeThread(PKPROCESS Process, PKTHREAD Thread, BOOLEAN First)
Thread->StackLimit = (ULONG)&init_stack; Thread->StackLimit = (ULONG)&init_stack;
Thread->KernelStack = (PVOID)&init_stack_top; Thread->KernelStack = (PVOID)&init_stack_top;
} }
/* /*
* The Native API function will initialize the TEB field later * 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -39,6 +39,7 @@ MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
PVOID PBase; PVOID PBase;
ULONG i; ULONG i;
MmLockAddressSpace(MmGetKernelAddressSpace());
Status = MmCreateMemoryArea(NULL, Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(), MmGetKernelAddressSpace(),
MEMORY_AREA_CONTINUOUS_MEMORY, MEMORY_AREA_CONTINUOUS_MEMORY,
@ -47,6 +48,8 @@ MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
0, 0,
&MArea, &MArea,
FALSE); FALSE);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return(NULL); return(NULL);

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 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 * PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/iospace.c * FILE: ntoskrnl/mm/iospace.c
@ -75,6 +75,7 @@ MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
ULONG i; ULONG i;
ULONG Attributes; ULONG Attributes;
MmLockAddressSpace(MmGetKernelAddressSpace());
Result = NULL; Result = NULL;
Status = MmCreateMemoryArea (NULL, Status = MmCreateMemoryArea (NULL,
MmGetKernelAddressSpace(), MmGetKernelAddressSpace(),
@ -84,6 +85,8 @@ MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
0, 0,
&marea, &marea,
FALSE); FALSE);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(STATUS_SUCCESS)) if (!NT_SUCCESS(STATUS_SUCCESS))
{ {
return (NULL); 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 * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -96,6 +96,8 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
BaseAddress = (PVOID)KERNEL_BASE; BaseAddress = (PVOID)KERNEL_BASE;
Length = PAGE_ROUND_UP(((ULONG)&_text_end__)) - KERNEL_BASE; Length = PAGE_ROUND_UP(((ULONG)&_text_end__)) - KERNEL_BASE;
ParamLength = ParamLength - Length; ParamLength = ParamLength - Length;
MmLockAddressSpace(MmGetKernelAddressSpace());
MmCreateMemoryArea(NULL, MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(), MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM, MEMORY_AREA_SYSTEM,
@ -104,12 +106,15 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
0, 0,
&kernel_text_desc, &kernel_text_desc,
FALSE); FALSE);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
Length = PAGE_ROUND_UP(((ULONG)&_bss_end__)) - Length = PAGE_ROUND_UP(((ULONG)&_bss_end__)) -
PAGE_ROUND_UP(((ULONG)&_text_end__)); PAGE_ROUND_UP(((ULONG)&_text_end__));
ParamLength = ParamLength - Length; ParamLength = ParamLength - Length;
DPRINT("Length %x\n",Length); DPRINT("Length %x\n",Length);
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG)&_text_end__)); BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG)&_text_end__));
DPRINT("BaseAddress %x\n",BaseAddress); DPRINT("BaseAddress %x\n",BaseAddress);
MmLockAddressSpace(MmGetKernelAddressSpace());
MmCreateMemoryArea(NULL, MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(), MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM, MEMORY_AREA_SYSTEM,
@ -152,7 +157,7 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
0, 0,
&kernel_shared_data_desc, &kernel_shared_data_desc,
FALSE); FALSE);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
MmSharedDataPagePhysicalAddress = MmAllocPage(0); MmSharedDataPagePhysicalAddress = MmAllocPage(0);
Status = MmCreateVirtualMapping(NULL, Status = MmCreateVirtualMapping(NULL,
(PVOID)KERNEL_SHARED_DATA_BASE, (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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -53,6 +53,7 @@ MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
ULONG i; ULONG i;
ULONG Attributes; ULONG Attributes;
MmLockAddressSpace(MmGetKernelAddressSpace());
Result = NULL; Result = NULL;
Status = MmCreateMemoryArea (NULL, Status = MmCreateMemoryArea (NULL,
MmGetKernelAddressSpace(), MmGetKernelAddressSpace(),
@ -62,6 +63,8 @@ MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
0, 0,
&marea, &marea,
FALSE); FALSE);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return (NULL); return (NULL);

View file

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

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 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 * PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/wset.c * FILE: ntoskrnl/mm/wset.c
@ -143,7 +143,8 @@ MmInitializeWorkingSet(PEPROCESS Process, PMADDRESS_SPACE AddressSpace)
KeBugCheck(0); KeBugCheck(0);
} }
BaseAddress = 0; MmLockAddressSpace(MmGetKernelAddressSpace());
BaseAddress = NULL;
Status = MmCreateMemoryArea(NULL, Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(), MmGetKernelAddressSpace(),
MEMORY_AREA_WORKING_SET, MEMORY_AREA_WORKING_SET,
@ -152,6 +153,7 @@ MmInitializeWorkingSet(PEPROCESS Process, PMADDRESS_SPACE AddressSpace)
0, 0,
&AddressSpace->WorkingSetArea, &AddressSpace->WorkingSetArea,
FALSE); FALSE);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
KeBugCheck(0); KeBugCheck(0);