VirtualBox

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

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

vm.h/vm.mac: tweaking.

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