VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/testcase/tstLow.cpp@ 1908

Last change on this file since 1908 was 1890, checked in by vboxsync, 18 years ago

Attempt to fix ALSA on Linux kernels <= 2.6.17: use mmap not memalign for allocating pages. Use madvise or mprotect to separater VM area structs inside the kernel. Most SUP* functions work on cPages now (not cBytes anymore). The free functions take a cPages parameter which is used for munmap on Linux.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/** @file
2 *
3 * VBox host drivers - Ring-0 support drivers - Testcases:
4 * Test allocating physical memory below 4G
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 <VBox/err.h>
30#include <iprt/runtime.h>
31#include <iprt/stream.h>
32
33#include <string.h>
34
35int main(int argc, char **argv)
36{
37 int rc;
38 int rcRet = 0;
39
40 RTR3Init(false);
41 RTPrintf("tstLow: TESTING...\n");
42
43 rc = SUPInit();
44 if (VBOX_SUCCESS(rc))
45 {
46 /*
47 * Allocate a bit of contiguous memory.
48 */
49 SUPPAGE aPages0[128];
50 void *pvPages0 = (void *)0x77777777;
51 memset(&aPages0[0], 0x8f, sizeof(aPages0));
52 rc = SUPLowAlloc(ELEMENTS(aPages0), &pvPages0, NULL, aPages0);
53 if (VBOX_SUCCESS(rc))
54 {
55 /* check that the pages are below 4GB and valid. */
56 for (unsigned iPage = 0; iPage < ELEMENTS(aPages0); iPage++)
57 {
58 RTPrintf("%-4d: Phys=%VHp Reserved=%p\n", iPage, aPages0[iPage].Phys, aPages0[iPage].uReserved);
59 if (aPages0[iPage].uReserved != 0)
60 {
61 rcRet++;
62 RTPrintf("tstLow: error: aPages0[%d].uReserved=%#x expected 0!\n", iPage, aPages0[iPage].uReserved);
63 }
64 if ( aPages0[iPage].Phys >= _4G
65 || (aPages0[iPage].Phys & PAGE_OFFSET_MASK))
66 {
67 rcRet++;
68 RTPrintf("tstLow: error: aPages0[%d].Phys=%VHp!\n", iPage, aPages0[iPage].Phys);
69 }
70 }
71 if (!rcRet)
72 {
73 for (unsigned iPage = 0; iPage < ELEMENTS(aPages0); iPage++)
74 memset((char *)pvPages0 + iPage * PAGE_SIZE, iPage, PAGE_SIZE);
75 for (unsigned iPage = 0; iPage < ELEMENTS(aPages0); iPage++)
76 for (uint8_t *pu8 = (uint8_t *)pvPages0 + iPage * PAGE_SIZE, *pu8End = pu8 + PAGE_SIZE; pu8 < pu8End; pu8++)
77 if (*pu8 != (uint8_t)iPage)
78 {
79 RTPrintf("tstLow: error: invalid page content %02x != %02x. iPage=%p off=%#x\n",
80 *pu8, (uint8_t)iPage, iPage, (uintptr_t)pu8 & PAGE_OFFSET_MASK);
81 rcRet++;
82 }
83 }
84 SUPLowFree(pvPages0, ELEMENTS(aPages0));
85 }
86 else
87 {
88 RTPrintf("SUPLowAlloc(%d,,) failed -> rc=%Vrc\n", ELEMENTS(aPages0), rc);
89 rcRet++;
90 }
91
92 /*
93 * Allocate odd amounts in from 1 to 127.
94 */
95 for (unsigned cPages = 1; cPages <= 127; cPages++)
96 {
97 SUPPAGE aPages1[128];
98 void *pvPages1 = (void *)0x77777777;
99 memset(&aPages1[0], 0x8f, sizeof(aPages1));
100 rc = SUPLowAlloc(cPages, &pvPages1, NULL, aPages1);
101 if (VBOX_SUCCESS(rc))
102 {
103 /* check that the pages are below 4GB and valid. */
104 for (unsigned iPage = 0; iPage < cPages; iPage++)
105 {
106 RTPrintf("%-4d::%-4d: Phys=%VHp Reserved=%p\n", cPages, iPage, aPages1[iPage].Phys, aPages1[iPage].uReserved);
107 if (aPages1[iPage].uReserved != 0)
108 {
109 rcRet++;
110 RTPrintf("tstLow: error: aPages1[%d].uReserved=%#x expected 0!\n", iPage, aPages1[iPage].uReserved);
111 }
112 if ( aPages1[iPage].Phys >= _4G
113 || (aPages1[iPage].Phys & PAGE_OFFSET_MASK))
114 {
115 rcRet++;
116 RTPrintf("tstLow: error: aPages1[%d].Phys=%VHp!\n", iPage, aPages1[iPage].Phys);
117 }
118 }
119 if (!rcRet)
120 {
121 for (unsigned iPage = 0; iPage < cPages; iPage++)
122 memset((char *)pvPages1 + iPage * PAGE_SIZE, iPage, PAGE_SIZE);
123 for (unsigned iPage = 0; iPage < cPages; iPage++)
124 for (uint8_t *pu8 = (uint8_t *)pvPages1 + iPage * PAGE_SIZE, *pu8End = pu8 + PAGE_SIZE; pu8 < pu8End; pu8++)
125 if (*pu8 != (uint8_t)iPage)
126 {
127 RTPrintf("tstLow: error: invalid page content %02x != %02x. iPage=%p off=%#x\n",
128 *pu8, (uint8_t)iPage, iPage, (uintptr_t)pu8 & PAGE_OFFSET_MASK);
129 rcRet++;
130 }
131 }
132 SUPLowFree(pvPages1, cPages);
133 }
134 else
135 {
136 RTPrintf("SUPLowAlloc(%d,,) failed -> rc=%Vrc\n", cPages, rc);
137 rcRet++;
138 }
139 }
140
141 }
142 else
143 {
144 RTPrintf("SUPInit -> rc=%Vrc\n", rc);
145 rcRet++;
146 }
147
148
149 return rcRet;
150}
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