1 | /* $Id: tstLow.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * SUP Testcase - Low (<4GB) Memory Allocate interface (ring 3).
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #include <VBox/sup.h>
|
---|
42 | #include <VBox/param.h>
|
---|
43 | #include <iprt/errcore.h>
|
---|
44 | #include <iprt/initterm.h>
|
---|
45 | #include <iprt/stream.h>
|
---|
46 | #include <iprt/string.h>
|
---|
47 |
|
---|
48 |
|
---|
49 | int main(int argc, char **argv)
|
---|
50 | {
|
---|
51 | int rc;
|
---|
52 | int rcRet = 0;
|
---|
53 |
|
---|
54 | RTR3InitExe(argc, &argv, 0);
|
---|
55 | RTPrintf("tstLow: TESTING...\n");
|
---|
56 |
|
---|
57 | rc = SUPR3Init(NULL);
|
---|
58 | if (RT_SUCCESS(rc))
|
---|
59 | {
|
---|
60 | /*
|
---|
61 | * Allocate a bit of contiguous memory.
|
---|
62 | */
|
---|
63 | SUPPAGE aPages0[128];
|
---|
64 | void *pvPages0 = (void *)0x77777777;
|
---|
65 | memset(&aPages0[0], 0x8f, sizeof(aPages0));
|
---|
66 | rc = SUPR3LowAlloc(RT_ELEMENTS(aPages0), &pvPages0, NULL, aPages0);
|
---|
67 | if (RT_SUCCESS(rc))
|
---|
68 | {
|
---|
69 | /* check that the pages are below 4GB and valid. */
|
---|
70 | for (unsigned iPage = 0; iPage < RT_ELEMENTS(aPages0); iPage++)
|
---|
71 | {
|
---|
72 | RTPrintf("%-4d: Phys=%RHp Reserved=%p\n", iPage, aPages0[iPage].Phys, aPages0[iPage].uReserved);
|
---|
73 | if (aPages0[iPage].uReserved != 0)
|
---|
74 | {
|
---|
75 | rcRet++;
|
---|
76 | RTPrintf("tstLow: error: aPages0[%d].uReserved=%#x expected 0!\n", iPage, aPages0[iPage].uReserved);
|
---|
77 | }
|
---|
78 | if ( aPages0[iPage].Phys >= _4G
|
---|
79 | || (aPages0[iPage].Phys & PAGE_OFFSET_MASK))
|
---|
80 | {
|
---|
81 | rcRet++;
|
---|
82 | RTPrintf("tstLow: error: aPages0[%d].Phys=%RHp!\n", iPage, aPages0[iPage].Phys);
|
---|
83 | }
|
---|
84 | }
|
---|
85 | if (!rcRet)
|
---|
86 | {
|
---|
87 | for (unsigned iPage = 0; iPage < RT_ELEMENTS(aPages0); iPage++)
|
---|
88 | memset((char *)pvPages0 + iPage * PAGE_SIZE, iPage, PAGE_SIZE);
|
---|
89 | for (unsigned iPage = 0; iPage < RT_ELEMENTS(aPages0); iPage++)
|
---|
90 | for (uint8_t *pu8 = (uint8_t *)pvPages0 + iPage * PAGE_SIZE, *pu8End = pu8 + PAGE_SIZE; pu8 < pu8End; pu8++)
|
---|
91 | if (*pu8 != (uint8_t)iPage)
|
---|
92 | {
|
---|
93 | RTPrintf("tstLow: error: invalid page content %02x != %02x. iPage=%u off=%#x\n",
|
---|
94 | *pu8, (uint8_t)iPage, iPage, (uintptr_t)pu8 & PAGE_OFFSET_MASK);
|
---|
95 | rcRet++;
|
---|
96 | }
|
---|
97 | }
|
---|
98 | SUPR3LowFree(pvPages0, RT_ELEMENTS(aPages0));
|
---|
99 | }
|
---|
100 | else
|
---|
101 | {
|
---|
102 | RTPrintf("SUPR3LowAlloc(%d,,) failed -> rc=%Rrc\n", RT_ELEMENTS(aPages0), rc);
|
---|
103 | rcRet++;
|
---|
104 | }
|
---|
105 |
|
---|
106 | /*
|
---|
107 | * Allocate odd amounts in from 1 to 127.
|
---|
108 | */
|
---|
109 | for (unsigned cPages = 1; cPages <= 127; cPages++)
|
---|
110 | {
|
---|
111 | SUPPAGE aPages1[128];
|
---|
112 | void *pvPages1 = (void *)0x77777777;
|
---|
113 | memset(&aPages1[0], 0x8f, sizeof(aPages1));
|
---|
114 | rc = SUPR3LowAlloc(cPages, &pvPages1, NULL, aPages1);
|
---|
115 | if (RT_SUCCESS(rc))
|
---|
116 | {
|
---|
117 | /* check that the pages are below 4GB and valid. */
|
---|
118 | for (unsigned iPage = 0; iPage < cPages; iPage++)
|
---|
119 | {
|
---|
120 | RTPrintf("%-4d::%-4d: Phys=%RHp Reserved=%p\n", cPages, iPage, aPages1[iPage].Phys, aPages1[iPage].uReserved);
|
---|
121 | if (aPages1[iPage].uReserved != 0)
|
---|
122 | {
|
---|
123 | rcRet++;
|
---|
124 | RTPrintf("tstLow: error: aPages1[%d].uReserved=%#x expected 0!\n", iPage, aPages1[iPage].uReserved);
|
---|
125 | }
|
---|
126 | if ( aPages1[iPage].Phys >= _4G
|
---|
127 | || (aPages1[iPage].Phys & PAGE_OFFSET_MASK))
|
---|
128 | {
|
---|
129 | rcRet++;
|
---|
130 | RTPrintf("tstLow: error: aPages1[%d].Phys=%RHp!\n", iPage, aPages1[iPage].Phys);
|
---|
131 | }
|
---|
132 | }
|
---|
133 | if (!rcRet)
|
---|
134 | {
|
---|
135 | for (unsigned iPage = 0; iPage < cPages; iPage++)
|
---|
136 | memset((char *)pvPages1 + iPage * PAGE_SIZE, iPage, PAGE_SIZE);
|
---|
137 | for (unsigned iPage = 0; iPage < cPages; iPage++)
|
---|
138 | for (uint8_t *pu8 = (uint8_t *)pvPages1 + iPage * PAGE_SIZE, *pu8End = pu8 + PAGE_SIZE; pu8 < pu8End; pu8++)
|
---|
139 | if (*pu8 != (uint8_t)iPage)
|
---|
140 | {
|
---|
141 | RTPrintf("tstLow: error: invalid page content %02x != %02x. iPage=%p off=%#x\n",
|
---|
142 | *pu8, (uint8_t)iPage, iPage, (uintptr_t)pu8 & PAGE_OFFSET_MASK);
|
---|
143 | rcRet++;
|
---|
144 | }
|
---|
145 | }
|
---|
146 | SUPR3LowFree(pvPages1, cPages);
|
---|
147 | }
|
---|
148 | else
|
---|
149 | {
|
---|
150 | RTPrintf("SUPR3LowAlloc(%d,,) failed -> rc=%Rrc\n", cPages, rc);
|
---|
151 | rcRet++;
|
---|
152 | }
|
---|
153 | }
|
---|
154 |
|
---|
155 | }
|
---|
156 | else
|
---|
157 | {
|
---|
158 | RTPrintf("SUPR3Init -> rc=%Rrc\n", rc);
|
---|
159 | rcRet++;
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 | return rcRet;
|
---|
164 | }
|
---|