1 | /* $Id: tstVMStructSize.cpp 14411 2008-11-20 13:26:47Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * tstVMStructSize - testcase for check structure sizes/alignment
|
---|
4 | * and to verify that HC and GC uses the same
|
---|
5 | * representation of the structures.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
20 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
21 | * additional information or have any questions.
|
---|
22 | */
|
---|
23 |
|
---|
24 | /*******************************************************************************
|
---|
25 | * Header Files *
|
---|
26 | *******************************************************************************/
|
---|
27 | #include <VBox/cfgm.h>
|
---|
28 | #include <VBox/cpum.h>
|
---|
29 | #include <VBox/mm.h>
|
---|
30 | #include <VBox/pgm.h>
|
---|
31 | #include <VBox/selm.h>
|
---|
32 | #include <VBox/trpm.h>
|
---|
33 | #include <VBox/vmm.h>
|
---|
34 | #include <VBox/stam.h>
|
---|
35 | #include "PDMInternal.h"
|
---|
36 | #include <VBox/pdm.h>
|
---|
37 | #include "CFGMInternal.h"
|
---|
38 | #include "CPUMInternal.h"
|
---|
39 | #include "MMInternal.h"
|
---|
40 | #include "PGMInternal.h"
|
---|
41 | #include "SELMInternal.h"
|
---|
42 | #include "TRPMInternal.h"
|
---|
43 | #include "TMInternal.h"
|
---|
44 | #include "IOMInternal.h"
|
---|
45 | #include "REMInternal.h"
|
---|
46 | #include "SSMInternal.h"
|
---|
47 | #include "HWACCMInternal.h"
|
---|
48 | #include "PATMInternal.h"
|
---|
49 | #ifdef VBOX_WITH_VMI
|
---|
50 | # include "PARAVInternal.h"
|
---|
51 | #endif
|
---|
52 | #include "VMMInternal.h"
|
---|
53 | #include "DBGFInternal.h"
|
---|
54 | #include "STAMInternal.h"
|
---|
55 | #include "VMInternal.h"
|
---|
56 | #include "CSAMInternal.h"
|
---|
57 | #include "EMInternal.h"
|
---|
58 | #include "REMInternal.h"
|
---|
59 | #include <VBox/vm.h>
|
---|
60 | #include <VBox/param.h>
|
---|
61 | #include <VBox/x86.h>
|
---|
62 |
|
---|
63 | #include "tstHelp.h"
|
---|
64 | #include <stdio.h>
|
---|
65 |
|
---|
66 |
|
---|
67 |
|
---|
68 | int main()
|
---|
69 | {
|
---|
70 | int rc = 0;
|
---|
71 | printf("tstVMStructSize: TESTING\n");
|
---|
72 |
|
---|
73 | printf("struct VM: %d bytes\n", (int)sizeof(VM));
|
---|
74 |
|
---|
75 | #define CHECK_PADDING_VM(member) \
|
---|
76 | do \
|
---|
77 | { \
|
---|
78 | CHECK_PADDING(VM, member); \
|
---|
79 | CHECK_MEMBER_ALIGNMENT(VM, member, 32); \
|
---|
80 | } while (0)
|
---|
81 |
|
---|
82 |
|
---|
83 | #define CHECK_CPUMCTXCORE(member) \
|
---|
84 | do { \
|
---|
85 | if (RT_OFFSETOF(CPUMCTX, member) - RT_OFFSETOF(CPUMCTX, edi) != RT_OFFSETOF(CPUMCTXCORE, member)) \
|
---|
86 | { \
|
---|
87 | printf("CPUMCTX/CORE:: %s!\n", #member); \
|
---|
88 | rc++; \
|
---|
89 | } \
|
---|
90 | } while (0)
|
---|
91 |
|
---|
92 | #define PRINT_OFFSET(strct, member) \
|
---|
93 | do \
|
---|
94 | { \
|
---|
95 | printf("%s::%s offset %#x (%d) sizeof %d\n", #strct, #member, (int)RT_OFFSETOF(strct, member), (int)RT_OFFSETOF(strct, member), (int)RT_SIZEOFMEMB(strct, member)); \
|
---|
96 | } while (0)
|
---|
97 |
|
---|
98 |
|
---|
99 |
|
---|
100 | CHECK_SIZE(uint128_t, 128/8);
|
---|
101 | CHECK_SIZE(int128_t, 128/8);
|
---|
102 | CHECK_SIZE(uint64_t, 64/8);
|
---|
103 | CHECK_SIZE(int64_t, 64/8);
|
---|
104 | CHECK_SIZE(uint32_t, 32/8);
|
---|
105 | CHECK_SIZE(int32_t, 32/8);
|
---|
106 | CHECK_SIZE(uint16_t, 16/8);
|
---|
107 | CHECK_SIZE(int16_t, 16/8);
|
---|
108 | CHECK_SIZE(uint8_t, 8/8);
|
---|
109 | CHECK_SIZE(int8_t, 8/8);
|
---|
110 |
|
---|
111 | CHECK_SIZE(X86DESC, 8);
|
---|
112 | CHECK_SIZE(X86DESC64, 16);
|
---|
113 | CHECK_SIZE(VBOXIDTE, 8);
|
---|
114 | CHECK_SIZE(VBOXIDTR, 10);
|
---|
115 | CHECK_SIZE(VBOXGDTR, 10);
|
---|
116 | CHECK_SIZE(VBOXTSS, 136);
|
---|
117 | CHECK_SIZE(X86FXSTATE, 512);
|
---|
118 | CHECK_SIZE(RTUUID, 16);
|
---|
119 | CHECK_SIZE(X86PTE, 4);
|
---|
120 | CHECK_SIZE(X86PD, PAGE_SIZE);
|
---|
121 | CHECK_SIZE(X86PDE, 4);
|
---|
122 | CHECK_SIZE(X86PT, PAGE_SIZE);
|
---|
123 | CHECK_SIZE(X86PTEPAE, 8);
|
---|
124 | CHECK_SIZE(X86PTPAE, PAGE_SIZE);
|
---|
125 | CHECK_SIZE(X86PDEPAE, 8);
|
---|
126 | CHECK_SIZE(X86PDPAE, PAGE_SIZE);
|
---|
127 | CHECK_SIZE(X86PDPE, 8);
|
---|
128 | CHECK_SIZE(X86PDPT, PAGE_SIZE);
|
---|
129 | CHECK_SIZE(X86PML4E, 8);
|
---|
130 | CHECK_SIZE(X86PML4, PAGE_SIZE);
|
---|
131 |
|
---|
132 | CHECK_PADDING_VM(cfgm);
|
---|
133 | CHECK_PADDING_VM(cpum);
|
---|
134 | CHECK_PADDING_VM(dbgf);
|
---|
135 | CHECK_PADDING_VM(em);
|
---|
136 | CHECK_PADDING_VM(iom);
|
---|
137 | CHECK_PADDING_VM(mm);
|
---|
138 | CHECK_PADDING_VM(pdm);
|
---|
139 | CHECK_PADDING_VM(pgm);
|
---|
140 | CHECK_PADDING_VM(selm);
|
---|
141 | CHECK_PADDING_VM(tm);
|
---|
142 | CHECK_PADDING_VM(trpm);
|
---|
143 | CHECK_PADDING_VM(vm);
|
---|
144 | CHECK_PADDING_VM(vmm);
|
---|
145 | CHECK_PADDING_VM(ssm);
|
---|
146 | CHECK_PADDING_VM(rem);
|
---|
147 | CHECK_PADDING_VM(hwaccm);
|
---|
148 | CHECK_PADDING_VM(patm);
|
---|
149 | CHECK_PADDING_VM(csam);
|
---|
150 | CHECK_MEMBER_ALIGNMENT(VM, selm.s.Tss, 16);
|
---|
151 | PRINT_OFFSET(VM, selm.s.Tss);
|
---|
152 | PVM pVM;
|
---|
153 | if ((RT_OFFSETOF(VM, selm.s.Tss) & PAGE_OFFSET_MASK) > PAGE_SIZE - sizeof(pVM->selm.s.Tss))
|
---|
154 | {
|
---|
155 | printf("SELM:Tss is crossing a page!\n");
|
---|
156 | rc++;
|
---|
157 | }
|
---|
158 | PRINT_OFFSET(VM, selm.s.TssTrap08);
|
---|
159 | if ((RT_OFFSETOF(VM, selm.s.TssTrap08) & PAGE_OFFSET_MASK) > PAGE_SIZE - sizeof(pVM->selm.s.TssTrap08))
|
---|
160 | {
|
---|
161 | printf("SELM:TssTrap08 is crossing a page!\n");
|
---|
162 | rc++;
|
---|
163 | }
|
---|
164 | CHECK_MEMBER_ALIGNMENT(VM, trpm.s.aIdt, 16);
|
---|
165 | CHECK_MEMBER_ALIGNMENT(VM, cpum, 64);
|
---|
166 | CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].cpum.s.Host, 64);
|
---|
167 | CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].cpum.s.Guest, 64);
|
---|
168 | CHECK_MEMBER_ALIGNMENT(VM, aCpus[1].cpum.s.Host, 64);
|
---|
169 | CHECK_MEMBER_ALIGNMENT(VM, aCpus[1].cpum.s.Guest, 64);
|
---|
170 | CHECK_MEMBER_ALIGNMENT(VM, cpum.s.Hyper, 64);
|
---|
171 | CHECK_MEMBER_ALIGNMENT(VM, cpum.s.GuestEntry, 64);
|
---|
172 |
|
---|
173 | CHECK_MEMBER_ALIGNMENT(VM, vmm.s.CritSectVMLock, 8);
|
---|
174 | CHECK_MEMBER_ALIGNMENT(VM, vmm.s.CallHostR0JmpBuf, 8);
|
---|
175 | CHECK_MEMBER_ALIGNMENT(VM, vmm.s.StatRunRC, 8);
|
---|
176 | CHECK_MEMBER_ALIGNMENT(VM, StatTotalQemuToGC, 8);
|
---|
177 | CHECK_MEMBER_ALIGNMENT(VM, rem.s.StatsInQEMU, 8);
|
---|
178 | CHECK_MEMBER_ALIGNMENT(VM, rem.s.Env, 32);
|
---|
179 | CHECK_MEMBER_ALIGNMENT(VM, aCpus, 64);
|
---|
180 |
|
---|
181 | /* vmcpu */
|
---|
182 | CHECK_MEMBER_ALIGNMENT(VMCPU, cpum, 64);
|
---|
183 | CHECK_MEMBER_ALIGNMENT(VMCPU, vmm, 32);
|
---|
184 | CHECK_MEMBER_ALIGNMENT(VMCPU, pgm, 32);
|
---|
185 | CHECK_MEMBER_ALIGNMENT(VMCPU, em, 32);
|
---|
186 | CHECK_MEMBER_ALIGNMENT(VMCPU, hwaccm, 32);
|
---|
187 | CHECK_MEMBER_ALIGNMENT(VMCPU, tm, 32);
|
---|
188 | CHECK_SIZE_ALIGNMENT(VMCPU, 32);
|
---|
189 |
|
---|
190 | /* cpumctx */
|
---|
191 | CHECK_MEMBER_ALIGNMENT(CPUMCTX, fpu, 32);
|
---|
192 | CHECK_MEMBER_ALIGNMENT(CPUMCTX, edi, 32);
|
---|
193 | CHECK_MEMBER_ALIGNMENT(CPUMCTX, idtr, 4);
|
---|
194 | CHECK_MEMBER_ALIGNMENT(CPUMCTX, SysEnter, 8);
|
---|
195 | CHECK_CPUMCTXCORE(eax);
|
---|
196 | CHECK_CPUMCTXCORE(ebx);
|
---|
197 | CHECK_CPUMCTXCORE(ecx);
|
---|
198 | CHECK_CPUMCTXCORE(edx);
|
---|
199 | CHECK_CPUMCTXCORE(ebp);
|
---|
200 | CHECK_CPUMCTXCORE(esp);
|
---|
201 | CHECK_CPUMCTXCORE(edi);
|
---|
202 | CHECK_CPUMCTXCORE(esi);
|
---|
203 | CHECK_CPUMCTXCORE(eip);
|
---|
204 | CHECK_CPUMCTXCORE(eflags);
|
---|
205 | CHECK_CPUMCTXCORE(cs);
|
---|
206 | CHECK_CPUMCTXCORE(ds);
|
---|
207 | CHECK_CPUMCTXCORE(es);
|
---|
208 | CHECK_CPUMCTXCORE(fs);
|
---|
209 | CHECK_CPUMCTXCORE(gs);
|
---|
210 | CHECK_CPUMCTXCORE(ss);
|
---|
211 | CHECK_CPUMCTXCORE(r8);
|
---|
212 | CHECK_CPUMCTXCORE(r9);
|
---|
213 | CHECK_CPUMCTXCORE(r10);
|
---|
214 | CHECK_CPUMCTXCORE(r11);
|
---|
215 | CHECK_CPUMCTXCORE(r12);
|
---|
216 | CHECK_CPUMCTXCORE(r13);
|
---|
217 | CHECK_CPUMCTXCORE(r14);
|
---|
218 | CHECK_CPUMCTXCORE(r15);
|
---|
219 | CHECK_CPUMCTXCORE(esHid);
|
---|
220 | CHECK_CPUMCTXCORE(csHid);
|
---|
221 | CHECK_CPUMCTXCORE(ssHid);
|
---|
222 | CHECK_CPUMCTXCORE(dsHid);
|
---|
223 | CHECK_CPUMCTXCORE(fsHid);
|
---|
224 | CHECK_CPUMCTXCORE(gsHid);
|
---|
225 |
|
---|
226 | #if HC_ARCH_BITS == 32
|
---|
227 | /* CPUMHOSTCTX - lss pair */
|
---|
228 | if (RT_OFFSETOF(CPUMHOSTCTX, esp) + 4 != RT_OFFSETOF(CPUMHOSTCTX, ss))
|
---|
229 | {
|
---|
230 | printf("error: CPUMHOSTCTX lss has been split up!\n");
|
---|
231 | rc++;
|
---|
232 | }
|
---|
233 | #endif
|
---|
234 | CHECK_SIZE_ALIGNMENT(CPUMCTX, 64);
|
---|
235 | CHECK_SIZE_ALIGNMENT(CPUMHOSTCTX, 64);
|
---|
236 | CHECK_SIZE_ALIGNMENT(CPUMCTXMSR, 64);
|
---|
237 |
|
---|
238 | /* pdm */
|
---|
239 | CHECK_MEMBER_ALIGNMENT(PDMDEVINS, achInstanceData, 64);
|
---|
240 | CHECK_PADDING(PDMDEVINS, Internal);
|
---|
241 | CHECK_MEMBER_ALIGNMENT(PDMUSBINS, achInstanceData, 16);
|
---|
242 | CHECK_PADDING(PDMUSBINS, Internal);
|
---|
243 | CHECK_MEMBER_ALIGNMENT(PDMDRVINS, achInstanceData, 16);
|
---|
244 | CHECK_PADDING(PDMDRVINS, Internal);
|
---|
245 | CHECK_PADDING2(PDMCRITSECT);
|
---|
246 | CHECK_MEMBER_ALIGNMENT(PGMPOOLPAGE, idx, sizeof(uint16_t));
|
---|
247 | CHECK_MEMBER_ALIGNMENT(PGMPOOLPAGE, pvPageR3, sizeof(RTHCPTR));
|
---|
248 | CHECK_MEMBER_ALIGNMENT(PGMPOOLPAGE, GCPhys, sizeof(RTGCPHYS));
|
---|
249 | CHECK_SIZE(PGMPAGE, 16);
|
---|
250 | CHECK_MEMBER_ALIGNMENT(PGMRAMRANGE, aPages, 16);
|
---|
251 | CHECK_MEMBER_ALIGNMENT(PGMMMIO2RANGE, RamRange, 16);
|
---|
252 |
|
---|
253 | /* misc */
|
---|
254 | CHECK_MEMBER_ALIGNMENT(REM, aGCPtrInvalidatedPages, 8);
|
---|
255 | CHECK_PADDING3(EM, u.FatalLongJump, u.achPaddingFatalLongJump);
|
---|
256 | CHECK_PADDING3(REMHANDLERNOTIFICATION, u.PhysicalRegister, u.padding);
|
---|
257 | CHECK_PADDING3(REMHANDLERNOTIFICATION, u.PhysicalDeregister, u.padding);
|
---|
258 | CHECK_PADDING3(REMHANDLERNOTIFICATION, u.PhysicalModify, u.padding);
|
---|
259 | CHECK_SIZE_ALIGNMENT(VMMR0JMPBUF, 8);
|
---|
260 | CHECK_SIZE_ALIGNMENT(PATCHINFO, 8);
|
---|
261 | #if 0
|
---|
262 | PRINT_OFFSET(VM, fForcedActions);
|
---|
263 | PRINT_OFFSET(VM, StatQemuToGC);
|
---|
264 | PRINT_OFFSET(VM, StatGCToQemu);
|
---|
265 | #endif
|
---|
266 |
|
---|
267 |
|
---|
268 | /* hwaccm - 32-bit gcc won't align uint64_t naturally, so check. */
|
---|
269 | CHECK_MEMBER_ALIGNMENT(HWACCM, u64RegisterMask, 8);
|
---|
270 | CHECK_MEMBER_ALIGNMENT(HWACCM, vmx.hostCR4, 8);
|
---|
271 | CHECK_MEMBER_ALIGNMENT(HWACCM, vmx.msr.feature_ctrl, 8);
|
---|
272 | CHECK_MEMBER_ALIGNMENT(HWACCMCPU, StatEntry, 8);
|
---|
273 | CHECK_MEMBER_ALIGNMENT(HWACCMCPU, vmx.proc_ctls, 8);
|
---|
274 | CHECK_MEMBER_ALIGNMENT(HWACCMCPU, Event.intInfo, 8);
|
---|
275 |
|
---|
276 |
|
---|
277 | /*
|
---|
278 | * Compare HC and GC.
|
---|
279 | */
|
---|
280 | printf("tstVMStructSize: Comparing HC and GC...\n");
|
---|
281 | #include "tstVMStructGC.h"
|
---|
282 |
|
---|
283 | /*
|
---|
284 | * Report result.
|
---|
285 | */
|
---|
286 | if (rc)
|
---|
287 | printf("tstVMStructSize: FAILURE - %d errors\n", rc);
|
---|
288 | else
|
---|
289 | printf("tstVMStructSize: SUCCESS\n");
|
---|
290 | return rc;
|
---|
291 | }
|
---|
292 |
|
---|