VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/testcase/tstPin.cpp@ 1862

Last change on this file since 1862 was 1193, checked in by vboxsync, 18 years ago

Ported the support driver to OS/2.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1/** @file
2 *
3 * VBox host drivers - Ring-0 support drivers - Testcases:
4 * Test the memory locking interface
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#include <VBox/sup.h>
28#include <VBox/param.h>
29#include <iprt/runtime.h>
30#include <iprt/stream.h>
31#include <stdlib.h>
32#include <string.h>
33
34
35int main(int argc, char **argv)
36{
37 int rc;
38 int rcRet = 0;
39 RTHCPHYS HCPhys;
40 void *pv;
41
42 RTR3Init(true, ~0);
43 rc = SUPInit(NULL, ~0);
44 RTPrintf("SUPInit -> rc=%d\n", rc);
45 rcRet += rc != 0;
46 if (!rc)
47 {
48 static struct
49 {
50 void *pv;
51 void *pvAligned;
52 SUPPAGE aPages[16];
53 } aPinnings[500];
54 for (unsigned i = 0; i < sizeof(aPinnings) / sizeof(aPinnings[0]); i++)
55 {
56#ifdef __OS2__
57 aPinnings[i].pv = NULL;
58 SUPPageAlloc(0x10000 >> PAGE_SHIFT, &aPinnings[i].pv);
59#else
60 aPinnings[i].pv = malloc(0x10000);
61#endif
62 aPinnings[i].pvAligned = ALIGNP(aPinnings[i].pv, PAGE_SIZE);
63 rc = SUPPageLock(aPinnings[i].pvAligned, 0xf000, &aPinnings[i].aPages[0]);
64 if (!rc)
65 {
66 RTPrintf("i=%d: pvAligned=%p pv=%p:\n", i, aPinnings[i].pvAligned, aPinnings[i].pv);
67 memset(aPinnings[i].pv, 0xfa, 0x10000);
68 unsigned c4GPluss = 0;
69 for (unsigned j = 0; j < (0xf000 >> PAGE_SHIFT); j++)
70 if (aPinnings[i].aPages[j].Phys >= _4G)
71 {
72 RTPrintf("%2d: vrt=%p phys=%VHp\n", j, (char *)aPinnings[i].pvAligned + (j << PAGE_SHIFT), aPinnings[i].aPages[j].Phys);
73 c4GPluss++;
74 }
75 RTPrintf("i=%d: c4GPluss=%d\n", i, c4GPluss);
76 }
77 else
78 {
79 RTPrintf("SUPPageLock -> rc=%d\n", rc);
80 rcRet++;
81#ifdef __OS2__
82 SUPPageFree(aPinnings[i].pv);
83#else
84 free(aPinnings[i].pv);
85#endif
86 aPinnings[i].pv = aPinnings[i].pvAligned = NULL;
87 break;
88 }
89 }
90
91 for (unsigned i = 0; i < sizeof(aPinnings) / sizeof(aPinnings[0]); i += 2)
92 {
93 if (aPinnings[i].pvAligned)
94 {
95 rc = SUPPageUnlock(aPinnings[i].pvAligned);
96 if (rc)
97 {
98 RTPrintf("SUPPageUnlock(%p) -> rc=%d\n", aPinnings[i].pvAligned, rc);
99 rcRet++;
100 }
101 memset(aPinnings[i].pv, 0xaf, 0x10000);
102 }
103 }
104
105 for (unsigned i = 0; i < sizeof(aPinnings) / sizeof(aPinnings[0]); i += 2)
106 {
107 if (aPinnings[i].pv)
108 {
109 memset(aPinnings[i].pv, 0xcc, 0x10000);
110#ifdef __OS2__
111 SUPPageFree(aPinnings[i].pv);
112#else
113 free(aPinnings[i].pv);
114#endif
115 aPinnings[i].pv = NULL;
116 }
117 }
118
119
120 /*
121 * Allocate a bit of contiguous memory.
122 */
123 pv = SUPContAlloc(15003, &HCPhys);
124 rcRet += pv == NULL || HCPhys == 0;
125 if (pv && HCPhys)
126 {
127 RTPrintf("SUPContAlloc(15003) -> HCPhys=%llx pv=%p\n", HCPhys, pv);
128 void *pv0 = pv;
129 memset(pv0, 0xaf, 15003);
130 pv = SUPContAlloc(12999, &HCPhys);
131 rcRet += pv == NULL || HCPhys == 0;
132 if (pv && HCPhys)
133 {
134 RTPrintf("SUPContAlloc(12999) -> HCPhys=%llx pv=%p\n", HCPhys, pv);
135 memset(pv, 0xbf, 12999);
136 rc = SUPContFree(pv);
137 rcRet += rc != 0;
138 if (rc)
139 RTPrintf("SUPContFree failed! rc=%d\n", rc);
140 }
141 else
142 RTPrintf("SUPContAlloc (2nd) failed!\n");
143 memset(pv0, 0xaf, 15003);
144 /* pv0 is intentionally not freed! */
145 }
146 else
147 RTPrintf("SUPContAlloc failed!\n");
148
149 /*
150 * Allocate a big chunk of virtual memory and then lock it.
151 */
152 #define BIG_SIZE 72*1024*1024
153 #define BIG_SIZEPP (BIG_SIZE + PAGE_SIZE)
154#ifdef __OS2__
155 pv = NULL;
156 SUPPageAlloc(BIG_SIZEPP >> PAGE_SHIFT, &pv);
157#else
158 pv = malloc(BIG_SIZEPP);
159#endif
160 if (pv)
161 {
162 static SUPPAGE aPages[BIG_SIZE >> PAGE_SHIFT];
163 void *pvAligned = ALIGNP(pv, PAGE_SIZE);
164 rc = SUPPageLock(pvAligned, BIG_SIZE, &aPages[0]);
165 if (!rc)
166 {
167 /* dump */
168 RTPrintf("SUPPageLock(%p,%d,) succeeded!\n", pvAligned, BIG_SIZE);
169 memset(pv, 0x42, BIG_SIZEPP);
170 #if 0
171 for (unsigned j = 0; j < (BIG_SIZE >> PAGE_SHIFT); j++)
172 RTPrintf("%2d: vrt=%p phys=%08x\n", j, (char *)pvAligned + (j << PAGE_SHIFT), (uintptr_t)aPages[j].pvPhys);
173 #endif
174
175 /* unlock */
176 rc = SUPPageUnlock(pvAligned);
177 if (rc)
178 {
179 RTPrintf("SUPPageUnlock(%p) -> rc=%d\n", pvAligned, rc);
180 rcRet++;
181 }
182 memset(pv, 0xcc, BIG_SIZEPP);
183 }
184 else
185 {
186 RTPrintf("SUPPageLock(%p) -> rc=%d\n", pvAligned, rc);
187 rcRet++;
188 }
189#ifdef __OS2__
190 SUPPageFree(pv);
191#else
192 free(pv);
193#endif
194 }
195
196 rc = SUPTerm();
197 RTPrintf("SUPTerm -> rc=%d\n", rc);
198 rcRet += rc != 0;
199 }
200
201 return rcRet;
202}
Note: See TracBrowser for help on using the repository browser.

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