From 367a28ce87129f8482e8d2abdbb2cf689844725d Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Tue, 12 May 2015 03:37:00 +0000 Subject: [PATCH] [NTVDM] Fix the XMS driver. AH = 08h is supposed to return the size of the largest free block in AX, and the total amount of *free* memory in DX. svn path=/trunk/; revision=67675 --- .../mvdm/ntvdm/dos/dos32krnl/himem.c | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/himem.c b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/himem.c index 3501d7d2a7a..1f2e8a0a878 100644 --- a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/himem.c +++ b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/himem.c @@ -185,6 +185,28 @@ static inline PXMS_HANDLE GetHandleRecord(WORD Handle) return Entry->Size ? Entry : NULL; } +static WORD XmsGetLargestFreeBlock(VOID) +{ + WORD Result = 0; + DWORD CurrentIndex = 0; + ULONG RunStart; + ULONG RunSize; + + while (CurrentIndex < XMS_BLOCKS) + { + RunSize = RtlFindNextForwardRunClear(&AllocBitmap, CurrentIndex, &RunStart); + if (RunSize == 0) break; + + /* Update the maximum */ + if (RunSize > Result) Result = RunSize; + + /* Go to the next run */ + CurrentIndex = RunStart + RunSize; + } + + return Result; +} + static CHAR XmsAlloc(WORD Size, PWORD Handle) { BYTE i; @@ -380,8 +402,8 @@ static VOID WINAPI XmsBopProcedure(LPWORD Stack) /* Query Free Extended Memory */ case 0x08: { - setAX(FreeBlocks); - setDX(XMS_BLOCKS); + setAX(XmsGetLargestFreeBlock()); + setDX(FreeBlocks); setBL(XMS_STATUS_SUCCESS); break; }