VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstVMStructSize.cpp@ 21987

Last change on this file since 21987 was 21987, checked in by vboxsync, 15 years ago

TPR patching updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.3 KB
Line 
1/* $Id: tstVMStructSize.cpp 21987 2009-08-05 12:14:31Z 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
68int 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_PADDING_VMCPU(member) \
84 do \
85 { \
86 CHECK_PADDING(VMCPU, member); \
87 CHECK_MEMBER_ALIGNMENT(VMCPU, member, 32); \
88 } while (0)
89
90#define CHECK_CPUMCTXCORE(member) \
91 do { \
92 if (RT_OFFSETOF(CPUMCTX, member) - RT_OFFSETOF(CPUMCTX, edi) != RT_OFFSETOF(CPUMCTXCORE, member)) \
93 { \
94 printf("CPUMCTX/CORE:: %s!\n", #member); \
95 rc++; \
96 } \
97 } while (0)
98
99#define PRINT_OFFSET(strct, member) \
100 do \
101 { \
102 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)); \
103 } while (0)
104
105
106
107 CHECK_SIZE(uint128_t, 128/8);
108 CHECK_SIZE(int128_t, 128/8);
109 CHECK_SIZE(uint64_t, 64/8);
110 CHECK_SIZE(int64_t, 64/8);
111 CHECK_SIZE(uint32_t, 32/8);
112 CHECK_SIZE(int32_t, 32/8);
113 CHECK_SIZE(uint16_t, 16/8);
114 CHECK_SIZE(int16_t, 16/8);
115 CHECK_SIZE(uint8_t, 8/8);
116 CHECK_SIZE(int8_t, 8/8);
117
118 CHECK_SIZE(X86DESC, 8);
119 CHECK_SIZE(X86DESC64, 16);
120 CHECK_SIZE(VBOXIDTE, 8);
121 CHECK_SIZE(VBOXIDTR, 10);
122 CHECK_SIZE(VBOXGDTR, 10);
123 CHECK_SIZE(VBOXTSS, 136);
124 CHECK_SIZE(X86FXSTATE, 512);
125 CHECK_SIZE(RTUUID, 16);
126 CHECK_SIZE(X86PTE, 4);
127 CHECK_SIZE(X86PD, PAGE_SIZE);
128 CHECK_SIZE(X86PDE, 4);
129 CHECK_SIZE(X86PT, PAGE_SIZE);
130 CHECK_SIZE(X86PTEPAE, 8);
131 CHECK_SIZE(X86PTPAE, PAGE_SIZE);
132 CHECK_SIZE(X86PDEPAE, 8);
133 CHECK_SIZE(X86PDPAE, PAGE_SIZE);
134 CHECK_SIZE(X86PDPE, 8);
135 CHECK_SIZE(X86PDPT, PAGE_SIZE);
136 CHECK_SIZE(X86PML4E, 8);
137 CHECK_SIZE(X86PML4, PAGE_SIZE);
138
139 CHECK_PADDING_VM(cfgm);
140 CHECK_PADDING_VM(cpum);
141 CHECK_PADDING_VM(dbgf);
142 CHECK_PADDING_VM(em);
143 CHECK_PADDING_VM(iom);
144 CHECK_PADDING_VM(mm);
145 CHECK_PADDING_VM(pdm);
146 CHECK_PADDING_VM(pgm);
147 CHECK_PADDING_VM(selm);
148 CHECK_PADDING_VM(tm);
149 CHECK_PADDING_VM(trpm);
150 CHECK_PADDING_VM(vm);
151 CHECK_PADDING_VM(vmm);
152 CHECK_PADDING_VM(ssm);
153 CHECK_PADDING_VM(rem);
154 CHECK_PADDING_VM(hwaccm);
155 CHECK_PADDING_VM(patm);
156 CHECK_PADDING_VM(csam);
157
158 CHECK_PADDING_VMCPU(cpum);
159 CHECK_PADDING_VMCPU(pgm);
160 CHECK_PADDING_VMCPU(em);
161 CHECK_PADDING_VMCPU(hwaccm);
162 CHECK_PADDING_VMCPU(trpm);
163 CHECK_PADDING_VMCPU(tm);
164 CHECK_PADDING_VMCPU(vmm);
165
166 CHECK_MEMBER_ALIGNMENT(VM, selm.s.Tss, 16);
167 PRINT_OFFSET(VM, selm.s.Tss);
168 PVM pVM;
169 if ((RT_OFFSETOF(VM, selm.s.Tss) & PAGE_OFFSET_MASK) > PAGE_SIZE - sizeof(pVM->selm.s.Tss))
170 {
171 printf("SELM:Tss is crossing a page!\n");
172 rc++;
173 }
174 PRINT_OFFSET(VM, selm.s.TssTrap08);
175 if ((RT_OFFSETOF(VM, selm.s.TssTrap08) & PAGE_OFFSET_MASK) > PAGE_SIZE - sizeof(pVM->selm.s.TssTrap08))
176 {
177 printf("SELM:TssTrap08 is crossing a page!\n");
178 rc++;
179 }
180 CHECK_MEMBER_ALIGNMENT(VM, trpm.s.aIdt, 16);
181 CHECK_MEMBER_ALIGNMENT(VM, cpum, 64);
182 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0], 64);
183 CHECK_MEMBER_ALIGNMENT(VM, aCpus[1], 64);
184 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].cpum, 64);
185 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].hwaccm, 64);
186 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].pgm, 64);
187 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].em, 64);
188 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].tm, 64);
189 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].vmm, 64);
190 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].cpum.s.Host, 64);
191 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].cpum.s.Guest, 64);
192 CHECK_MEMBER_ALIGNMENT(VM, aCpus[1].cpum.s.Host, 64);
193 CHECK_MEMBER_ALIGNMENT(VM, aCpus[1].cpum.s.Guest, 64);
194 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].cpum.s.Hyper, 64);
195 CHECK_MEMBER_ALIGNMENT(VM, aCpus[1].cpum.s.Hyper, 64);
196 CHECK_MEMBER_ALIGNMENT(VM, cpum.s.GuestEntry, 64);
197
198 CHECK_MEMBER_ALIGNMENT(VMCPU, vmm.s.u64CallRing3Arg, 8);
199#if defined(RT_OS_WINDOWS) && defined(RT_ARCH_AMD64)
200 CHECK_MEMBER_ALIGNMENT(VMCPU, vmm.s.CallRing3JmpBufR0, 16);
201 CHECK_MEMBER_ALIGNMENT(VMCPU, vmm.s.CallRing3JmpBufR0.xmm6, 16);
202#endif
203 CHECK_MEMBER_ALIGNMENT(VM, vmm.s.u64LastYield, 8);
204 CHECK_MEMBER_ALIGNMENT(VM, vmm.s.StatRunRC, 8);
205 CHECK_MEMBER_ALIGNMENT(VM, StatTotalQemuToGC, 8);
206 CHECK_MEMBER_ALIGNMENT(VM, rem.s.uPendingExcptCR2, 8);
207 CHECK_MEMBER_ALIGNMENT(VM, rem.s.StatsInQEMU, 8);
208 CHECK_MEMBER_ALIGNMENT(VM, rem.s.Env, 32);
209 CHECK_MEMBER_ALIGNMENT(VM, aCpus, 64);
210
211 /* vmcpu */
212 CHECK_MEMBER_ALIGNMENT(VMCPU, cpum, 64);
213 CHECK_MEMBER_ALIGNMENT(VMCPU, vmm, 32);
214 CHECK_MEMBER_ALIGNMENT(VMCPU, pgm, 32);
215 CHECK_MEMBER_ALIGNMENT(VMCPU, em, 32);
216 CHECK_MEMBER_ALIGNMENT(VMCPU, hwaccm, 32);
217 CHECK_MEMBER_ALIGNMENT(VMCPU, tm, 32);
218 CHECK_SIZE_ALIGNMENT(VMCPU, 32);
219
220 /* cpumctx */
221 CHECK_MEMBER_ALIGNMENT(CPUMCTX, fpu, 32);
222 CHECK_MEMBER_ALIGNMENT(CPUMCTX, edi, 32);
223 CHECK_MEMBER_ALIGNMENT(CPUMCTX, idtr, 4);
224 CHECK_MEMBER_ALIGNMENT(CPUMCTX, SysEnter, 8);
225 CHECK_CPUMCTXCORE(eax);
226 CHECK_CPUMCTXCORE(ebx);
227 CHECK_CPUMCTXCORE(ecx);
228 CHECK_CPUMCTXCORE(edx);
229 CHECK_CPUMCTXCORE(ebp);
230 CHECK_CPUMCTXCORE(esp);
231 CHECK_CPUMCTXCORE(edi);
232 CHECK_CPUMCTXCORE(esi);
233 CHECK_CPUMCTXCORE(eip);
234 CHECK_CPUMCTXCORE(eflags);
235 CHECK_CPUMCTXCORE(cs);
236 CHECK_CPUMCTXCORE(ds);
237 CHECK_CPUMCTXCORE(es);
238 CHECK_CPUMCTXCORE(fs);
239 CHECK_CPUMCTXCORE(gs);
240 CHECK_CPUMCTXCORE(ss);
241 CHECK_CPUMCTXCORE(r8);
242 CHECK_CPUMCTXCORE(r9);
243 CHECK_CPUMCTXCORE(r10);
244 CHECK_CPUMCTXCORE(r11);
245 CHECK_CPUMCTXCORE(r12);
246 CHECK_CPUMCTXCORE(r13);
247 CHECK_CPUMCTXCORE(r14);
248 CHECK_CPUMCTXCORE(r15);
249 CHECK_CPUMCTXCORE(esHid);
250 CHECK_CPUMCTXCORE(csHid);
251 CHECK_CPUMCTXCORE(ssHid);
252 CHECK_CPUMCTXCORE(dsHid);
253 CHECK_CPUMCTXCORE(fsHid);
254 CHECK_CPUMCTXCORE(gsHid);
255
256#if HC_ARCH_BITS == 32
257 /* CPUMHOSTCTX - lss pair */
258 if (RT_OFFSETOF(CPUMHOSTCTX, esp) + 4 != RT_OFFSETOF(CPUMHOSTCTX, ss))
259 {
260 printf("error: CPUMHOSTCTX lss has been split up!\n");
261 rc++;
262 }
263#endif
264 CHECK_SIZE_ALIGNMENT(CPUMCTX, 64);
265 CHECK_SIZE_ALIGNMENT(CPUMHOSTCTX, 64);
266 CHECK_SIZE_ALIGNMENT(CPUMCTXMSR, 64);
267
268 /* pdm */
269 CHECK_MEMBER_ALIGNMENT(PDMDEVINS, achInstanceData, 64);
270 CHECK_PADDING(PDMDEVINS, Internal);
271 CHECK_MEMBER_ALIGNMENT(PDMUSBINS, achInstanceData, 16);
272 CHECK_PADDING(PDMUSBINS, Internal);
273 CHECK_MEMBER_ALIGNMENT(PDMDRVINS, achInstanceData, 16);
274 CHECK_PADDING(PDMDRVINS, Internal);
275 CHECK_PADDING2(PDMCRITSECT);
276 CHECK_MEMBER_ALIGNMENT(PGMPOOLPAGE, idx, sizeof(uint16_t));
277 CHECK_MEMBER_ALIGNMENT(PGMPOOLPAGE, pvPageR3, sizeof(RTHCPTR));
278 CHECK_MEMBER_ALIGNMENT(PGMPOOLPAGE, GCPhys, sizeof(RTGCPHYS));
279 CHECK_SIZE(PGMPAGE, 16);
280 CHECK_MEMBER_ALIGNMENT(PGMRAMRANGE, aPages, 16);
281 CHECK_MEMBER_ALIGNMENT(PGMMMIO2RANGE, RamRange, 16);
282
283 /* rem */
284 CHECK_MEMBER_ALIGNMENT(REM, aGCPtrInvalidatedPages, 8);
285 CHECK_PADDING3(REMHANDLERNOTIFICATION, u.PhysicalRegister, u.padding);
286 CHECK_PADDING3(REMHANDLERNOTIFICATION, u.PhysicalDeregister, u.padding);
287 CHECK_PADDING3(REMHANDLERNOTIFICATION, u.PhysicalModify, u.padding);
288 CHECK_SIZE_ALIGNMENT(REMHANDLERNOTIFICATION, 8);
289 CHECK_MEMBER_ALIGNMENT(REMHANDLERNOTIFICATION, u.PhysicalDeregister.GCPhys, 8);
290
291 /* misc */
292 CHECK_PADDING3(EMCPU, u.FatalLongJump, u.achPaddingFatalLongJump);
293 CHECK_SIZE_ALIGNMENT(VMMR0JMPBUF, 8);
294 CHECK_SIZE_ALIGNMENT(PATCHINFO, 8);
295#if 0
296 PRINT_OFFSET(VM, fForcedActions);
297 PRINT_OFFSET(VM, StatQemuToGC);
298 PRINT_OFFSET(VM, StatGCToQemu);
299#endif
300
301 /* TM */
302 CHECK_MEMBER_ALIGNMENT(TM, TimerCritSect, sizeof(uintptr_t));
303 CHECK_MEMBER_ALIGNMENT(TM, VirtualSyncLock, sizeof(uintptr_t));
304
305 CHECK_MEMBER_ALIGNMENT(IOM, EmtLock, sizeof(uintptr_t));
306 CHECK_MEMBER_ALIGNMENT(EM, CritSectREM, sizeof(uintptr_t));
307 CHECK_MEMBER_ALIGNMENT(PGM, CritSect, sizeof(uintptr_t));
308 CHECK_MEMBER_ALIGNMENT(PDM, CritSect, sizeof(uintptr_t));
309 CHECK_MEMBER_ALIGNMENT(MMHYPERHEAP, Lock, sizeof(uintptr_t));
310
311 /* hwaccm - 32-bit gcc won't align uint64_t naturally, so check. */
312 CHECK_MEMBER_ALIGNMENT(HWACCM, u64RegisterMask, 8);
313 CHECK_MEMBER_ALIGNMENT(HWACCM, vmx.hostCR4, 8);
314 CHECK_MEMBER_ALIGNMENT(HWACCM, vmx.msr.feature_ctrl, 8);
315 CHECK_MEMBER_ALIGNMENT(HWACCM, StatPatchSuccess, 8);
316 CHECK_MEMBER_ALIGNMENT(HWACCMCPU, StatEntry, 8);
317 CHECK_MEMBER_ALIGNMENT(HWACCMCPU, vmx.proc_ctls, 8);
318 CHECK_MEMBER_ALIGNMENT(HWACCMCPU, Event.intInfo, 8);
319
320 /* The various disassembler state members. */
321 CHECK_PADDING3(EMCPU, DisState, abDisStatePadding);
322 CHECK_PADDING3(HWACCMCPU, DisState, abDisStatePadding);
323 CHECK_PADDING3(IOMCPU, DisState, abDisStatePadding);
324 CHECK_PADDING3(PGMCPU, DisState, abDisStatePadding);
325
326 /* Make sure the set is large enough and has the correct size. */
327 CHECK_SIZE(VMCPUSET, 32);
328 if (sizeof(VMCPUSET) * 8 < VMM_MAX_CPU_COUNT)
329 {
330 printf("error: VMCPUSET is too small for VMM_MAX_CPU_COUNT=%u!\n", VMM_MAX_CPU_COUNT);
331 rc++;
332 }
333
334 /*
335 * Compare HC and GC.
336 */
337 printf("tstVMStructSize: Comparing HC and GC...\n");
338#include "tstVMStructGC.h"
339
340 /*
341 * Report result.
342 */
343 if (rc)
344 printf("tstVMStructSize: FAILURE - %d errors\n", rc);
345 else
346 printf("tstVMStructSize: SUCCESS\n");
347 return rc;
348}
349
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