/* $Id$ */
/** @file
* Testcase for the VMMR0JMPBUF operations.
*/
/*
* Copyright (C) 2006-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
#define IN_VMM_R0
#include "VMMInternal.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
#if !defined(VMM_R0_SWITCH_STACK) && !defined(VMM_R0_NO_SWITCH_STACK)
# error "VMM_R0_SWITCH_STACK or VMM_R0_NO_SWITCH_STACK has to be defined."
#endif
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The jump buffer. */
/** The number of jumps we've done. */
static unsigned volatile g_cJmps;
/** Number of bytes allocated last time we called foo(). */
/** Number of bytes used last time we called foo(). */
{
/* allocate a buffer which we fill up to the end. */
#ifdef VMM_R0_SWITCH_STACK
RTTESTI_CHECK_MSG_RET(g_cbFooUsed < (intptr_t)VMM_STACK_SIZE - 128, ("%#x - (%p - %p) -> %#x; cb=%#x i=%d\n", VMM_STACK_SIZE, pv, g_Jmp.pvSavedStack, g_cbFooUsed, cb, i), -15);
#elif defined(RT_ARCH_AMD64)
RTTESTI_CHECK_MSG_RET(g_cbFooUsed < VMM_STACK_SIZE - 128, ("%p - %p -> %#x; cb=%#x i=%d\n", g_Jmp.rsp, pv, g_cbFooUsed, cb, i), -15);
#elif defined(RT_ARCH_X86)
RTTESTI_CHECK_MSG_RET(g_cbFooUsed < (intptr_t)VMM_STACK_SIZE - 128, ("%p - %p -> %#x; cb=%#x i=%d\n", g_Jmp.esp, pv, g_cbFooUsed, cb, i), -15);
#endif
/* Do long jmps every 7th time */
if ((i % 7) == 0)
{
g_cJmps++;
if (!rc)
return i + 10000;
return -1;
}
return i;
}
{
return 0;
}
{
#ifdef VMM_R0_SWITCH_STACK
#endif
g_cbFoo = 0;
g_cJmps = 0;
g_cbFooUsed = 0;
{
RTTESTI_CHECK_MSG_RETV(rc == 0 || rc == 42, ("i=%d rc=%d setjmp; cbFoo=%#x cbFooUsed=%#x\n", i, rc, g_cbFoo, g_cbFooUsed));
#ifdef VMM_R0_SWITCH_STACK
/* Make the stack pointer slide for the second half of the calls. */
{
/* Note! gcc does funny rounding up of alloca(). */
RTTESTI_CHECK_MSG(cb2 >= 16 && cb2 <= 128, ("cb2=%zu pv2=%p pvPrev=%p iAlloca=%d\n", cb2, pv2, pvPrev, iItr));
}
#endif
}
}
int main()
{
/*
* Init.
*/
if (rcExit != RTEXITCODE_SUCCESS)
return rcExit;
/*
* Run two test with about 1000 long jumps each.
*/
return RTTestSummaryAndDestroy(hTest);
}