Author: aandrejevic
Date: Sat Nov 9 17:16:04 2013
New Revision: 60903
URL:
http://svn.reactos.org/svn/reactos?rev=60903&view=rev
Log:
[NTVDM]
Make the emulator callbacks non-static.
In BiosPrintCallback, use EmulatorWriteMemory instead of VgaWriteMemory, because
VgaWriteMemory does not do any input validation.
Improve EmulatorWriteMemory input validation and bound checking.
Modified:
branches/ntvdm/subsystems/ntvdm/bios.c
branches/ntvdm/subsystems/ntvdm/emulator.c
branches/ntvdm/subsystems/ntvdm/emulator.h
Modified: branches/ntvdm/subsystems/ntvdm/bios.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/bios.c?r…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/bios.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/bios.c [iso-8859-1] Sat Nov 9 17:16:04 2013
@@ -760,11 +760,12 @@
/* Default character */
/* Write the character */
- VgaWriteMemory(TO_LINEAR(TEXT_VIDEO_SEG,
- Page * Bda->VideoPageSize
- + (Row * Bda->ScreenColumns + Column) * sizeof(WORD)),
- (LPVOID)&CharData,
- sizeof(WORD));
+ EmulatorWriteMemory(&EmulatorContext,
+ TO_LINEAR(TEXT_VIDEO_SEG,
+ Page * Bda->VideoPageSize
+ + (Row * Bda->ScreenColumns + Column) * sizeof(WORD)),
+ (LPVOID)&CharData,
+ sizeof(WORD));
/* Advance the cursor */
Column++;
@@ -789,6 +790,8 @@
Rectangle,
Page,
DEFAULT_ATTRIBUTE);
+
+ Row--;
}
/* Set the cursor position */
Modified: branches/ntvdm/subsystems/ntvdm/emulator.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/emulator…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/emulator.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/emulator.c [iso-8859-1] Sat Nov 9 17:16:04 2013
@@ -29,7 +29,7 @@
/* PRIVATE FUNCTIONS **********************************************************/
-static VOID WINAPI EmulatorReadMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer,
ULONG Size)
+VOID WINAPI EmulatorReadMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG
Size)
{
UNREFERENCED_PARAMETER(State);
@@ -47,14 +47,16 @@
&& (Address < VgaGetVideoLimitAddress()))
{
DWORD VgaAddress = max(Address, VgaGetVideoBaseAddress());
+ DWORD ActualSize = min(Address + Size - 1, VgaGetVideoLimitAddress())
+ - VgaAddress + 1;
LPBYTE VgaBuffer = (LPBYTE)((ULONG_PTR)Buffer + VgaAddress - Address);
/* Read from the VGA memory */
- VgaReadMemory(VgaAddress, VgaBuffer, Size);
- }
-}
-
-static VOID WINAPI EmulatorWriteMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer,
ULONG Size)
+ VgaReadMemory(VgaAddress, VgaBuffer, ActualSize);
+ }
+}
+
+VOID WINAPI EmulatorWriteMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG
Size)
{
UNREFERENCED_PARAMETER(State);
@@ -75,14 +77,16 @@
&& (Address < VgaGetVideoLimitAddress()))
{
DWORD VgaAddress = max(Address, VgaGetVideoBaseAddress());
+ DWORD ActualSize = min(Address + Size - 1, VgaGetVideoLimitAddress())
+ - VgaAddress + 1;
LPBYTE VgaBuffer = (LPBYTE)((ULONG_PTR)Buffer + VgaAddress - Address);
/* Write to the VGA memory */
- VgaWriteMemory(VgaAddress, VgaBuffer, Size);
- }
-}
-
-static VOID WINAPI EmulatorReadIo(PFAST486_STATE State, ULONG Port, PVOID Buffer, ULONG
DataCount, UCHAR DataSize)
+ VgaWriteMemory(VgaAddress, VgaBuffer, ActualSize);
+ }
+}
+
+VOID WINAPI EmulatorReadIo(PFAST486_STATE State, ULONG Port, PVOID Buffer, ULONG
DataCount, UCHAR DataSize)
{
INT i, j;
LPBYTE Address = (LPBYTE)Buffer;
@@ -169,7 +173,7 @@
}
}
-static VOID WINAPI EmulatorWriteIo(PFAST486_STATE State, ULONG Port, PVOID Buffer, ULONG
DataCount, UCHAR DataSize)
+VOID WINAPI EmulatorWriteIo(PFAST486_STATE State, ULONG Port, PVOID Buffer, ULONG
DataCount, UCHAR DataSize)
{
INT i, j;
LPBYTE Address = (LPBYTE)Buffer;
@@ -268,7 +272,7 @@
}
}
-static VOID WINAPI EmulatorBiosOperation(PFAST486_STATE State, UCHAR BopCode)
+VOID WINAPI EmulatorBiosOperation(PFAST486_STATE State, UCHAR BopCode)
{
WORD StackSegment, StackPointer;
LPWORD Stack;
@@ -286,7 +290,7 @@
DPRINT1("Invalid BOP code %u\n", BopCode);
}
-static UCHAR WINAPI EmulatorIntAcknowledge(PFAST486_STATE State)
+UCHAR WINAPI EmulatorIntAcknowledge(PFAST486_STATE State)
{
UNREFERENCED_PARAMETER(State);
Modified: branches/ntvdm/subsystems/ntvdm/emulator.h
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/emulator…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/emulator.h [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/emulator.h [iso-8859-1] Sat Nov 9 17:16:04 2013
@@ -86,6 +86,51 @@
/* FUNCTIONS ******************************************************************/
+VOID WINAPI EmulatorReadMemory
+(
+ PFAST486_STATE State,
+ ULONG Address,
+ PVOID Buffer,
+ ULONG Size
+);
+
+VOID WINAPI EmulatorWriteMemory
+(
+ PFAST486_STATE State,
+ ULONG Address,
+ PVOID Buffer,
+ ULONG Size
+);
+
+VOID WINAPI EmulatorReadIo
+(
+ PFAST486_STATE State,
+ ULONG Port,
+ PVOID Buffer,
+ ULONG DataCount,
+ UCHAR DataSize
+);
+
+VOID WINAPI EmulatorWriteIo
+(
+ PFAST486_STATE State,
+ ULONG Port,
+ PVOID Buffer,
+ ULONG DataCount,
+ UCHAR DataSize
+);
+
+VOID WINAPI EmulatorBiosOperation
+(
+ PFAST486_STATE State,
+ UCHAR BopCode
+);
+
+UCHAR WINAPI EmulatorIntAcknowledge
+(
+ PFAST486_STATE State
+);
+
BOOLEAN EmulatorInitialize(VOID);
VOID EmulatorSetStack(WORD Segment, DWORD Offset);
VOID EmulatorExecute(WORD Segment, WORD Offset);