Author: fireball
Date: Mon May 5 13:23:55 2008
New Revision: 33301
URL:
http://svn.reactos.org/svn/reactos?rev=33301&view=rev
Log:
- Fix two typos in the buffer size calculation code, spotted by Stefan Ginsberg.
Modified:
trunk/reactos/ntoskrnl/mm/virtual.c
Modified: trunk/reactos/ntoskrnl/mm/virtual.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/virtual.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/virtual.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/virtual.c [iso-8859-1] Mon May 5 13:23:55 2008
@@ -78,28 +78,28 @@
_SEH_DECLARE_LOCALS(MiGetExceptionInfo);
NTSTATUS Status = STATUS_SUCCESS;
PAGED_CODE();
-
+
/* Calculate the maximum amount of data to move */
TotalSize = MI_MAPPED_COPY_PAGES - 2;
- if (TotalSize <= (MI_MAPPED_COPY_PAGES - 2)) TotalSize = BufferSize;
+ if (BufferSize <= (MI_MAPPED_COPY_PAGES - 2)) TotalSize = BufferSize;
CurrentSize = BufferSize;
RemainingSize = TotalSize;
-
+
/* Loop as long as there is still data */
while (RemainingSize > 0)
{
/* Check if this transfer will finish everything off */
if (RemainingSize < CurrentSize) CurrentSize = RemainingSize;
-
+
/* Attach to the source address space */
KeStackAttachProcess(&SourceProcess->Pcb, &ApcState);
-
+
/* Reset state for this pass */
MdlAddress = NULL;
PagesLocked = FALSE;
FailedInMoving = FALSE;
ASSERT(FailedInProbe == FALSE);
-
+
/* Protect user-mode copy */
_SEH_TRY
{
@@ -108,19 +108,19 @@
{
/* Catch a failure here */
FailedInProbe = TRUE;
-
+
/* Do the probe */
ProbeForRead(SourceAddress, BufferSize, sizeof(CHAR));
-
+
/* Passed */
FailedInProbe = FALSE;
}
-
+
/* Initialize and probe and lock the MDL */
MmInitializeMdl (Mdl, CurrentAddress, CurrentSize);
MmProbeAndLockPages (Mdl, PreviousMode, IoReadAccess);
PagesLocked = TRUE;
-
+
/* Now map the pages */
MdlAddress = MmMapLockedPagesSpecifyCache(Mdl,
KernelMode,
@@ -134,24 +134,24 @@
FailedInMapping = TRUE;
ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES);
}
-
+
/* Now let go of the source and grab to the target process */
KeUnstackDetachProcess(&ApcState);
KeStackAttachProcess(&TargetProcess->Pcb, &ApcState);
-
+
/* Check if this is our first time through */
if ((CurrentAddress == SourceAddress) && (PreviousMode !=
KernelMode))
{
/* Catch a failure here */
FailedInProbe = TRUE;
-
+
/* Do the probe */
ProbeForWrite(TargetAddress, BufferSize, sizeof(CHAR));
-
+
/* Passed */
FailedInProbe = FALSE;
}
-
+
/* Now do the actual move */
FailedInMoving = TRUE;
RtlCopyMemory(CurrentTargetAddress, MdlAddress, CurrentSize);
@@ -160,13 +160,13 @@
{
/* Detach from whoever we may be attached to */
KeUnstackDetachProcess(&ApcState);
-
+
/* Check if we had mapped the pages */
if (MdlAddress) MmUnmapLockedPages(MdlAddress, Mdl);
-
+
/* Check if we had locked the pages */
if (PagesLocked) MmUnlockPages(Mdl);
-
+
/* Check if we failed during the probe or mapping */
if ((FailedInProbe) || (FailedInMapping))
{
@@ -174,7 +174,7 @@
Status = _SEH_GetExceptionCode();
_SEH_YIELD();
}
-
+
/* Otherwise, we failed probably during the move */
*ReturnSize = BufferSize - RemainingSize;
if (FailedInMoving)
@@ -186,28 +186,28 @@
*ReturnSize = _SEH_VAR(BadAddress) - (ULONG_PTR)SourceAddress;
}
}
-
+
/* Return partial copy */
Status = STATUS_PARTIAL_COPY;
}
_SEH_END;
-
+
/* Check for SEH status */
if (Status != STATUS_SUCCESS) return Status;
-
+
/* Detach from target */
KeUnstackDetachProcess(&ApcState);
-
+
/* Unmap and unlock */
MmUnmapLockedPages(MdlAddress, Mdl);
MmUnlockPages(Mdl);
-
+
/* Update location and size */
RemainingSize -= CurrentSize;
CurrentAddress = (PVOID)((ULONG_PTR)CurrentAddress + CurrentSize);
CurrentTargetAddress = (PVOID)((ULONG_PTR)CurrentTargetAddress + CurrentSize);
}
-
+
/* All bytes read */
*ReturnSize = BufferSize;
return STATUS_SUCCESS;
@@ -232,13 +232,13 @@
_SEH_DECLARE_LOCALS(MiGetExceptionInfo);
NTSTATUS Status = STATUS_SUCCESS;
PAGED_CODE();
-
+
/* Calculate the maximum amount of data to move */
TotalSize = MI_MAX_TRANSFER_SIZE;
- if (TotalSize <= MI_MAX_TRANSFER_SIZE) TotalSize = BufferSize;
+ if (BufferSize <= MI_MAX_TRANSFER_SIZE) TotalSize = BufferSize;
CurrentSize = BufferSize;
RemainingSize = TotalSize;
-
+
/* Check if we can use the stack */
if (BufferSize <= MI_POOL_COPY_BYTES)
{
@@ -252,20 +252,20 @@
if (!PoolAddress) ASSERT(FALSE);
HavePoolAddress = TRUE;
}
-
+
/* Loop as long as there is still data */
while (RemainingSize > 0)
{
/* Check if this transfer will finish everything off */
if (RemainingSize < CurrentSize) CurrentSize = RemainingSize;
-
+
/* Attach to the source address space */
KeStackAttachProcess(&SourceProcess->Pcb, &ApcState);
-
+
/* Reset state for this pass */
FailedInMoving = FALSE;
ASSERT(FailedInProbe == FALSE);
-
+
/* Protect user-mode copy */
_SEH_TRY
{
@@ -274,34 +274,34 @@
{
/* Catch a failure here */
FailedInProbe = TRUE;
-
+
/* Do the probe */
ProbeForRead(SourceAddress, BufferSize, sizeof(CHAR));
-
+
/* Passed */
FailedInProbe = FALSE;
}
-
+
/* Do the copy */
RtlCopyMemory(PoolAddress, CurrentAddress, CurrentSize);
-
+
/* Now let go of the source and grab to the target process */
KeUnstackDetachProcess(&ApcState);
KeStackAttachProcess(&TargetProcess->Pcb, &ApcState);
-
+
/* Check if this is our first time through */
if ((CurrentAddress == SourceAddress) && (PreviousMode !=
KernelMode))
{
/* Catch a failure here */
FailedInProbe = TRUE;
-
+
/* Do the probe */
ProbeForWrite(TargetAddress, BufferSize, sizeof(CHAR));
-
+
/* Passed */
FailedInProbe = FALSE;
}
-
+
/* Now do the actual move */
FailedInMoving = TRUE;
RtlCopyMemory(CurrentTargetAddress, PoolAddress, CurrentSize);
@@ -310,10 +310,10 @@
{
/* Detach from whoever we may be attached to */
KeUnstackDetachProcess(&ApcState);
-
+
/* Check if we had allocated pool */
if (HavePoolAddress) ExFreePool(PoolAddress);
-
+
/* Check if we failed during the probe */
if (FailedInProbe)
{
@@ -321,7 +321,7 @@
Status = _SEH_GetExceptionCode();
_SEH_YIELD();
}
-
+
/* Otherwise, we failed probably during the move */
*ReturnSize = BufferSize - RemainingSize;
if (FailedInMoving)
@@ -333,27 +333,27 @@
*ReturnSize = _SEH_VAR(BadAddress) - (ULONG_PTR)SourceAddress;
}
}
-
+
/* Return partial copy */
Status = STATUS_PARTIAL_COPY;
}
_SEH_END;
-
+
/* Check for SEH status */
if (Status != STATUS_SUCCESS) return Status;
-
+
/* Detach from target */
KeUnstackDetachProcess(&ApcState);
-
+
/* Update location and size */
RemainingSize -= CurrentSize;
CurrentAddress = (PVOID)((ULONG_PTR)CurrentAddress + CurrentSize);
CurrentTargetAddress = (PVOID)((ULONG_PTR)CurrentTargetAddress + CurrentSize);
}
-
+
/* Check if we had allocated pool */
if (HavePoolAddress) ExFreePool(PoolAddress);
-
+
/* All bytes read */
*ReturnSize = BufferSize;
return STATUS_SUCCESS;