VirtualBox

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

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

Test UVM padding as well

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