VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstVMMR0CallHost-1.cpp@ 400

Last change on this file since 400 was 161, checked in by vboxsync, 18 years ago

64-bit: structure alignment.

  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1/* $Id: tstVMMR0CallHost-1.cpp 161 2007-01-18 18:25:45Z vboxsync $ */
2/** @file
3 * Testcase for the VMMR0JMPBUF operations.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#include <iprt/runtime.h>
26#include <iprt/string.h>
27#include <iprt/stream.h>
28#include <iprt/alloca.h>
29#include <VBox/err.h>
30
31#define IN_VMM_R0
32#define IN_RING0 /* pretent we're in Ring-0 to get the prototypes. */
33#include <VBox/vmm.h>
34#include "VMMInternal.h"
35
36
37
38/*******************************************************************************
39* Global Variables *
40*******************************************************************************/
41/** The jump buffer. */
42static VMMR0JMPBUF g_Jmp;
43/** The saved stack. */
44static uint8_t g_Stack[8192];
45
46
47int foo(int i, int iZero, int iMinusOne)
48{
49 char *pv = (char *)alloca(i + 32);
50 RTStrPrintf(pv, i + 32, "i=%d%*s\n", i, i+32, "");
51 if ((i % 7) == 0)
52 {
53 int rc = vmmR0CallHostLongJmp(&g_Jmp, 42);
54 if (!rc)
55 return i + 10000;
56 return -1;
57 }
58 return i;
59}
60
61
62DECLCALLBACK(int) tst2(intptr_t i)
63{
64 int iExpect = (i % 7) == 0 ? i + 10000 : i;
65 int rc = foo(i, 0, -1);
66 if (rc != iExpect)
67 {
68 RTPrintf("tstVMMR0CallHost-1: FAILURE - i=%d rc=%d expected=%d\n", i, rc, iExpect);
69 return 1;
70 }
71 return 0;
72}
73
74int tst(int iFrom, int iTo, int iInc)
75{
76 for (int i = iFrom; i < iTo; i += iInc)
77 {
78 int rc = vmmR0CallHostSetJmp(&g_Jmp, (PFNVMMR0SETJMP)tst2, (PVM)i);
79 if (rc != 0 && rc != 42)
80 {
81 RTPrintf("tstVMMR0CallHost-1: FAILURE - i=%d rc=%d setjmp\n", i, rc);
82 return 1;
83 }
84 }
85 return 0;
86}
87
88
89int main()
90{
91 /*
92 * Init.
93 */
94 RTR3Init(false);
95 RTPrintf("tstVMMR0CallHost-1: Testing...\n");
96 g_Jmp.pvSavedStack = (RTR0PTR)&g_Stack[0];
97
98 /*
99 * Try about 1000 long jumps with increasing stack size..
100 */
101 int rc = tst(0, 7000, 1);
102 if (!rc)
103 rc = tst(7599, 0, -1);
104
105 if (!rc)
106 RTPrintf("tstVMMR0CallHost-1: SUCCESS\n");
107 else
108 RTPrintf("tstVMMR0CallHost-1: FAILED\n");
109 return !!rc;
110}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette