Author: hbelusca Date: Sun Feb 23 15:54:20 2014 New Revision: 62305
URL: http://svn.reactos.org/svn/reactos?rev=62305&view=rev Log: [NTVDM]: Limit the number of CPU recursion calls (not more than 32).
Modified: branches/ntvdm/subsystems/ntvdm/callback.c branches/ntvdm/subsystems/ntvdm/clock.c branches/ntvdm/subsystems/ntvdm/emulator.c
Modified: branches/ntvdm/subsystems/ntvdm/callback.c URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/callback.... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/callback.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/callback.c [iso-8859-1] Sun Feb 23 15:54:20 2014 @@ -102,7 +102,7 @@
DPRINT("Call16(0x%04X, 0x%04X)\n", Segment, Offset);
- /* Start simulation */ + /* Start CPU simulation */ EmulatorSimulate();
/* Restore CS:IP */
Modified: branches/ntvdm/subsystems/ntvdm/clock.c URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/clock.c?r... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/clock.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/clock.c [iso-8859-1] Sun Feb 23 15:54:20 2014 @@ -59,6 +59,7 @@
VOID ClockUpdate(VOID) { + extern BOOLEAN CpuSimulate; UINT i;
#ifdef WORKING_TIMER @@ -127,7 +128,7 @@ VgaHorizontalRetrace();
/* Continue CPU emulation */ - for (i = 0; (i < STEPS_PER_CYCLE) && VdmRunning; i++) + for (i = 0; VdmRunning && CpuSimulate && (i < STEPS_PER_CYCLE); i++) { EmulatorStep(); #ifdef IPS_DISPLAY
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] Sun Feb 23 15:54:20 2014 @@ -30,6 +30,12 @@ /* PRIVATE VARIABLES **********************************************************/
FAST486_STATE EmulatorContext; +BOOLEAN CpuSimulate = FALSE; + +/* No more than 'MaxCpuCallLevel' recursive CPU calls are allowed */ +const static INT MaxCpuCallLevel = 32; +static INT CpuCallLevel = 0; + LPVOID BaseAddress = NULL; BOOLEAN VdmRunning = TRUE;
@@ -177,18 +183,31 @@
VOID EmulatorSimulate(VOID) { - // FIXME: Do not mix VdmRunning (i.e. ntvdm running) and CpuSimulate!! - while (VdmRunning) ClockUpdate(); + if (CpuCallLevel > MaxCpuCallLevel) + { + DisplayMessage(L"Too many CPU levels of recursion (%d, expected maximum %d)", + CpuCallLevel, MaxCpuCallLevel); + + /* Stop the VDM */ + VdmRunning = FALSE; + return; + } + CpuCallLevel++; + + CpuSimulate = TRUE; + while (VdmRunning && CpuSimulate) ClockUpdate(); + + CpuCallLevel--; + if (CpuCallLevel < 0) CpuCallLevel = 0;
/* This takes into account for reentrance */ - VdmRunning = TRUE; + CpuSimulate = TRUE; }
VOID EmulatorUnsimulate(VOID) { /* Stop simulation */ - // FIXME: Do not mix VdmRunning (i.e. ntvdm running) and CpuSimulate!! - VdmRunning = FALSE; + CpuSimulate = FALSE; }
VOID EmulatorInterrupt(BYTE Number)