Author: aandrejevic
Date: Tue Jun 25 17:18:34 2013
New Revision: 59339
URL:
http://svn.reactos.org/svn/reactos?rev=59339&view=rev
Log:
[NTVDM]
Fix more bugs in DosResizeMemory().
Modified:
branches/ntvdm/subsystems/ntvdm/dos.c
branches/ntvdm/subsystems/ntvdm/ntvdm.h
Modified: branches/ntvdm/subsystems/ntvdm/dos.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/dos.c?re…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/dos.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/dos.c [iso-8859-1] Tue Jun 25 17:18:34 2013
@@ -152,31 +152,41 @@
return Result + 1;
}
-WORD DosResizeMemory(WORD BlockData, WORD NewSize)
-{
+BOOLEAN DosResizeMemory(WORD BlockData, WORD NewSize, WORD *MaxAvailable)
+{
+ BOOLEAN Success = TRUE;
WORD Segment = BlockData - 1, ReturnSize = 0, NextSegment;
PDOS_MCB Mcb = SEGMENT_TO_MCB(Segment), NextMcb;
/* Make sure this is a valid, allocated block */
if ((Mcb->BlockType != 'M' && Mcb->BlockType != 'Z') ||
Mcb->OwnerPsp == 0)
{
- return 0;
- }
-
- /* Check if need to expand or contract the block */
+ Success = FALSE;
+ goto Done;
+ }
+
+ ReturnSize = Mcb->Size;
+
+ /* Check if we need to expand or contract the block */
if (NewSize > Mcb->Size)
{
/* We can't expand the last block */
- if (Mcb->BlockType != 'M') return Mcb->Size;
-
- ReturnSize = Mcb->Size;
-
+ if (Mcb->BlockType != 'M')
+ {
+ Success = FALSE;
+ goto Done;
+ }
+
/* Get the pointer and segment of the next MCB */
NextSegment = Segment + Mcb->Size + 1;
NextMcb = SEGMENT_TO_MCB(NextSegment);
/* Make sure the next segment is free */
- if (NextMcb->OwnerPsp != 0) return Mcb->Size;
+ if (NextMcb->OwnerPsp != 0)
+ {
+ Success = FALSE;
+ goto Done;
+ }
/* Combine this free block with adjoining free blocks */
DosCombineFreeBlocks(NextSegment);
@@ -220,7 +230,15 @@
Mcb->Size = NewSize;
}
- return ReturnSize;
+Done:
+ /* Check if the operation failed */
+ if (!Success)
+ {
+ /* Return the maximum possible size */
+ if (MaxAvailable) *MaxAvailable = ReturnSize;
+ }
+
+ return Success;
}
BOOLEAN DosFreeMemory(WORD BlockData)
@@ -785,14 +803,17 @@
/* Resize Memory Block */
case 0x4A:
{
- WORD Size = DosResizeMemory(ExtSegment, LOWORD(Ebx));
-
- if (Size != 0)
- {
+ WORD Size;
+
+ if (DosResizeMemory(ExtSegment, LOWORD(Ebx), &Size))
+ {
+ EmulatorClearFlag(EMULATOR_FLAG_CF);
+ }
+ else
+ {
+ EmulatorSetFlag(EMULATOR_FLAG_CF);
EmulatorSetRegister(EMULATOR_REG_BX, Size);
- EmulatorClearFlag(EMULATOR_FLAG_CF);
- }
- else EmulatorSetFlag(EMULATOR_FLAG_CF);
+ }
break;
}
Modified: branches/ntvdm/subsystems/ntvdm/ntvdm.h
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/ntvdm.h?…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/ntvdm.h [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/ntvdm.h [iso-8859-1] Tue Jun 25 17:18:34 2013
@@ -208,7 +208,7 @@
BOOLEAN DosInitialize();
WORD DosAllocateMemory(WORD Size, WORD *MaxAvailable);
BOOLEAN DosFreeMemory(WORD BlockData);
-WORD DosResizeMemory(WORD BlockData, WORD NewSize);
+BOOLEAN DosResizeMemory(WORD BlockData, WORD NewSize, WORD *MaxAvailable);
BOOLEAN DosCreateProcess(LPCSTR CommandLine, WORD EnvBlock);
VOID DosInt20h(WORD CodeSegment);
VOID DosInt21h(WORD CodeSegment);