* Locking the address space before accessing it.

* Fixed some length calculations.

svn path=/trunk/; revision=3699
This commit is contained in:
Hartmut Birr 2002-11-05 20:35:33 +00:00
parent 4096437ab3
commit a4b5d8a978
3 changed files with 18 additions and 10 deletions

View file

@ -1,4 +1,4 @@
/* $Id: cont.c,v 1.24 2002/10/01 19:27:22 chorns Exp $ /* $Id: cont.c,v 1.25 2002/11/05 20:35:33 hbirr Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -63,11 +63,13 @@ MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
Alignment); Alignment);
if (PBase.QuadPart == 0LL) if (PBase.QuadPart == 0LL)
{ {
MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(), MmFreeMemoryArea(MmGetKernelAddressSpace(),
BaseAddress, BaseAddress,
0, 0,
NULL, NULL,
NULL); NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
return(NULL); return(NULL);
} }
for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / 4096); i++) for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / 4096); i++)
@ -142,11 +144,13 @@ MmAllocateContiguousMemory (IN ULONG NumberOfBytes,
VOID STDCALL VOID STDCALL
MmFreeContiguousMemory(IN PVOID BaseAddress) MmFreeContiguousMemory(IN PVOID BaseAddress)
{ {
MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(), MmFreeMemoryArea(MmGetKernelAddressSpace(),
BaseAddress, BaseAddress,
0, 0,
MmFreeContinuousPage, MmFreeContinuousPage,
NULL); NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
} }

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.16 2002/10/01 19:27:22 chorns Exp $ /* $Id: iospace.c,v 1.17 2002/11/05 20:35:33 hbirr Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/iospace.c * FILE: ntoskrnl/mm/iospace.c
@ -96,7 +96,7 @@ MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
{ {
Attributes |= (PAGE_NOCACHE | PAGE_WRITETHROUGH); Attributes |= (PAGE_NOCACHE | PAGE_WRITETHROUGH);
} }
for (i = 0; (i < ((NumberOfBytes + PAGE_SIZE - 1) / PAGE_SIZE)); i++) for (i = 0; (i < (PAGE_ROUND_UP(NumberOfBytes) / PAGE_SIZE)); i++)
{ {
Status = Status =
MmCreateVirtualMappingForKernel(Result + (i * PAGE_SIZE), MmCreateVirtualMappingForKernel(Result + (i * PAGE_SIZE),
@ -141,11 +141,13 @@ VOID STDCALL
MmUnmapIoSpace (IN PVOID BaseAddress, MmUnmapIoSpace (IN PVOID BaseAddress,
IN ULONG NumberOfBytes) IN ULONG NumberOfBytes)
{ {
(VOID)MmFreeMemoryArea(&PsGetCurrentProcess()->AddressSpace, MmLockAddressSpace(MmGetKernelAddressSpace());
(PVOID)(((ULONG)BaseAddress / PAGE_SIZE) * PAGE_SIZE), MmFreeMemoryArea(MmGetKernelAddressSpace(),
NumberOfBytes, (PVOID)(((ULONG)BaseAddress / PAGE_SIZE) * PAGE_SIZE),
NULL, NumberOfBytes,
NULL); NULL,
NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
} }

View file

@ -1,4 +1,4 @@
/* $Id: ncache.c,v 1.22 2002/10/01 19:27:23 chorns Exp $ /* $Id: ncache.c,v 1.23 2002/11/05 20:35:33 hbirr Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -71,7 +71,7 @@ MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
} }
Attributes = PAGE_READWRITE | PAGE_SYSTEM | PAGE_NOCACHE | Attributes = PAGE_READWRITE | PAGE_SYSTEM | PAGE_NOCACHE |
PAGE_WRITETHROUGH; PAGE_WRITETHROUGH;
for (i = 0; i <= (NumberOfBytes / PAGE_SIZE); i++) for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / PAGE_SIZE); i++)
{ {
PHYSICAL_ADDRESS NPage; PHYSICAL_ADDRESS NPage;
@ -125,11 +125,13 @@ MmFreeNonCachedPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
VOID STDCALL MmFreeNonCachedMemory (IN PVOID BaseAddress, VOID STDCALL MmFreeNonCachedMemory (IN PVOID BaseAddress,
IN ULONG NumberOfBytes) IN ULONG NumberOfBytes)
{ {
MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea (MmGetKernelAddressSpace(), MmFreeMemoryArea (MmGetKernelAddressSpace(),
BaseAddress, BaseAddress,
NumberOfBytes, NumberOfBytes,
MmFreeNonCachedPage, MmFreeNonCachedPage,
NULL); NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
} }