[NTVDM]: Limit the number of CPU recursion calls (not more than 32).

svn path=/branches/ntvdm/; revision=62305
This commit is contained in:
Hermès Bélusca-Maïto 2014-02-23 15:54:20 +00:00
parent 121bde3b83
commit 0c3c1170ab
3 changed files with 27 additions and 7 deletions

View file

@ -102,7 +102,7 @@ Call16(IN USHORT Segment,
DPRINT("Call16(0x%04X, 0x%04X)\n", Segment, Offset);
/* Start simulation */
/* Start CPU simulation */
EmulatorSimulate();
/* Restore CS:IP */

View file

@ -59,6 +59,7 @@ INT KeyboardIntCounter = 0;
VOID ClockUpdate(VOID)
{
extern BOOLEAN CpuSimulate;
UINT i;
#ifdef WORKING_TIMER
@ -127,7 +128,7 @@ VOID ClockUpdate(VOID)
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

View file

@ -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 EmulatorStep(VOID)
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)