VirtualBox

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

Last change on this file since 58591 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 21.1 KB
Line 
1/* $Id: tstVMStructSize.cpp 57358 2015-08-14 15:16:38Z 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-2015 Oracle Corporation
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
20
21/*********************************************************************************************************************************
22* Header Files *
23*********************************************************************************************************************************/
24#include <VBox/vmm/cfgm.h>
25#include <VBox/vmm/cpum.h>
26#include <VBox/vmm/mm.h>
27#include <VBox/vmm/pgm.h>
28#include <VBox/vmm/selm.h>
29#include <VBox/vmm/trpm.h>
30#include <VBox/vmm/vmm.h>
31#include <VBox/vmm/stam.h>
32#include "PDMInternal.h"
33#include <VBox/vmm/pdm.h>
34#include "CFGMInternal.h"
35#include "CPUMInternal.h"
36#include "MMInternal.h"
37#include "PGMInternal.h"
38#include "SELMInternal.h"
39#include "TRPMInternal.h"
40#include "TMInternal.h"
41#include "IOMInternal.h"
42#include "REMInternal.h"
43#include "SSMInternal.h"
44#include "HMInternal.h"
45#include "VMMInternal.h"
46#include "DBGFInternal.h"
47#include "GIMInternal.h"
48#include "STAMInternal.h"
49#include "VMInternal.h"
50#include "EMInternal.h"
51#include "IEMInternal.h"
52#include "REMInternal.h"
53#include "../VMMR0/GMMR0Internal.h"
54#include "../VMMR0/GVMMR0Internal.h"
55#ifdef VBOX_WITH_RAW_MODE
56# include "CSAMInternal.h"
57# include "PATMInternal.h"
58#endif
59#include <VBox/vmm/vm.h>
60#include <VBox/vmm/uvm.h>
61#include <VBox/vmm/gvm.h>
62#include <VBox/param.h>
63#include <VBox/dis.h>
64#include <iprt/x86.h>
65
66#include "tstHelp.h"
67#include <stdio.h>
68
69
70
71int main()
72{
73 int rc = 0;
74 printf("tstVMStructSize: TESTING\n");
75
76 printf("info: struct VM: %d bytes\n", (int)sizeof(VM));
77
78#define CHECK_PADDING_VM(align, member) \
79 do \
80 { \
81 CHECK_PADDING(VM, member, align); \
82 CHECK_MEMBER_ALIGNMENT(VM, member, align); \
83 VM *p = NULL; NOREF(p); \
84 if (sizeof(p->member.padding) >= (ssize_t)sizeof(p->member.s) + 128 + sizeof(p->member.s) / 20) \
85 printf("warning: VM::%-8s: padding=%-5d s=%-5d -> %-4d suggest=%-5u\n", \
86 #member, (int)sizeof(p->member.padding), (int)sizeof(p->member.s), \
87 (int)sizeof(p->member.padding) - (int)sizeof(p->member.s), \
88 (int)RT_ALIGN_Z(sizeof(p->member.s), (align))); \
89 } while (0)
90
91
92#define CHECK_PADDING_VMCPU(align, member) \
93 do \
94 { \
95 CHECK_PADDING(VMCPU, member, align); \
96 CHECK_MEMBER_ALIGNMENT(VMCPU, member, align); \
97 VMCPU *p = NULL; NOREF(p); \
98 if (sizeof(p->member.padding) >= (ssize_t)sizeof(p->member.s) + 128 + sizeof(p->member.s) / 20) \
99 printf("warning: VMCPU::%-8s: padding=%-5d s=%-5d -> %-4d suggest=%-5u\n", \
100 #member, (int)sizeof(p->member.padding), (int)sizeof(p->member.s), \
101 (int)sizeof(p->member.padding) - (int)sizeof(p->member.s), \
102 (int)RT_ALIGN_Z(sizeof(p->member.s), (align))); \
103 } while (0)
104
105#define CHECK_CPUMCTXCORE(member) \
106 do { \
107 unsigned off1 = RT_OFFSETOF(CPUMCTX, member) - RT_OFFSETOF(CPUMCTX, rax); \
108 unsigned off2 = RT_OFFSETOF(CPUMCTXCORE, member); \
109 if (off1 != off2) \
110 { \
111 printf("error! CPUMCTX/CORE:: %s! (%#x vs %#x (ctx))\n", #member, off1, off2); \
112 rc++; \
113 } \
114 } while (0)
115
116#define CHECK_PADDING_UVM(align, member) \
117 do \
118 { \
119 CHECK_PADDING(UVM, member, align); \
120 CHECK_MEMBER_ALIGNMENT(UVM, member, align); \
121 UVM *p = NULL; NOREF(p); \
122 if (sizeof(p->member.padding) >= (ssize_t)sizeof(p->member.s) + 128 + sizeof(p->member.s) / 20) \
123 printf("warning: UVM::%-8s: padding=%-5d s=%-5d -> %-4d suggest=%-5u\n", \
124 #member, (int)sizeof(p->member.padding), (int)sizeof(p->member.s), \
125 (int)sizeof(p->member.padding) - (int)sizeof(p->member.s), \
126 (int)RT_ALIGN_Z(sizeof(p->member.s), (align))); \
127 } while (0)
128
129#define CHECK_PADDING_UVMCPU(align, member) \
130 do \
131 { \
132 CHECK_PADDING(UVMCPU, member, align); \
133 CHECK_MEMBER_ALIGNMENT(UVMCPU, member, align); \
134 UVMCPU *p = NULL; NOREF(p); \
135 if (sizeof(p->member.padding) >= (ssize_t)sizeof(p->member.s) + 128 + sizeof(p->member.s) / 20) \
136 printf("warning: UVMCPU::%-8s: padding=%-5d s=%-5d -> %-4d suggest=%-5u\n", \
137 #member, (int)sizeof(p->member.padding), (int)sizeof(p->member.s), \
138 (int)sizeof(p->member.padding) - (int)sizeof(p->member.s), \
139 (int)RT_ALIGN_Z(sizeof(p->member.s), (align))); \
140 } while (0)
141
142#define CHECK_PADDING_GVM(align, member) \
143 do \
144 { \
145 CHECK_PADDING(GVM, member, align); \
146 CHECK_MEMBER_ALIGNMENT(GVM, member, align); \
147 GVM *p = NULL; NOREF(p); \
148 if (sizeof(p->member.padding) >= (ssize_t)sizeof(p->member.s) + 128 + sizeof(p->member.s) / 20) \
149 printf("warning: GVM::%-8s: padding=%-5d s=%-5d -> %-4d suggest=%-5u\n", \
150 #member, (int)sizeof(p->member.padding), (int)sizeof(p->member.s), \
151 (int)sizeof(p->member.padding) - (int)sizeof(p->member.s), \
152 (int)RT_ALIGN_Z(sizeof(p->member.s), (align))); \
153 } while (0)
154
155#define CHECK_PADDING_GVMCPU(align, member) \
156 do \
157 { \
158 CHECK_PADDING(GVMCPU, member, align); \
159 CHECK_MEMBER_ALIGNMENT(GVMCPU, member, align); \
160 GVMCPU *p = NULL; NOREF(p); \
161 if (sizeof(p->member.padding) >= (ssize_t)sizeof(p->member.s) + 128 + sizeof(p->member.s) / 20) \
162 printf("warning: GVMCPU::%-8s: padding=%-5d s=%-5d -> %-4d suggest=%-5u\n", \
163 #member, (int)sizeof(p->member.padding), (int)sizeof(p->member.s), \
164 (int)sizeof(p->member.padding) - (int)sizeof(p->member.s), \
165 (int)RT_ALIGN_Z(sizeof(p->member.s), (align))); \
166 } while (0)
167
168#define PRINT_OFFSET(strct, member) \
169 do \
170 { \
171 printf("info: %10s::%-24s offset %#6x (%6d) sizeof %4d\n", #strct, #member, (int)RT_OFFSETOF(strct, member), (int)RT_OFFSETOF(strct, member), (int)RT_SIZEOFMEMB(strct, member)); \
172 } while (0)
173
174
175 CHECK_SIZE(uint128_t, 128/8);
176 CHECK_SIZE(int128_t, 128/8);
177 CHECK_SIZE(uint64_t, 64/8);
178 CHECK_SIZE(int64_t, 64/8);
179 CHECK_SIZE(uint32_t, 32/8);
180 CHECK_SIZE(int32_t, 32/8);
181 CHECK_SIZE(uint16_t, 16/8);
182 CHECK_SIZE(int16_t, 16/8);
183 CHECK_SIZE(uint8_t, 8/8);
184 CHECK_SIZE(int8_t, 8/8);
185
186 CHECK_SIZE(X86DESC, 8);
187 CHECK_SIZE(X86DESC64, 16);
188 CHECK_SIZE(VBOXIDTE, 8);
189 CHECK_SIZE(VBOXIDTR, 10);
190 CHECK_SIZE(VBOXGDTR, 10);
191 CHECK_SIZE(VBOXTSS, 136);
192 CHECK_SIZE(X86FXSTATE, 512);
193 CHECK_SIZE(RTUUID, 16);
194 CHECK_SIZE(X86PTE, 4);
195 CHECK_SIZE(X86PD, PAGE_SIZE);
196 CHECK_SIZE(X86PDE, 4);
197 CHECK_SIZE(X86PT, PAGE_SIZE);
198 CHECK_SIZE(X86PTEPAE, 8);
199 CHECK_SIZE(X86PTPAE, PAGE_SIZE);
200 CHECK_SIZE(X86PDEPAE, 8);
201 CHECK_SIZE(X86PDPAE, PAGE_SIZE);
202 CHECK_SIZE(X86PDPE, 8);
203 CHECK_SIZE(X86PDPT, PAGE_SIZE);
204 CHECK_SIZE(X86PML4E, 8);
205 CHECK_SIZE(X86PML4, PAGE_SIZE);
206
207 PRINT_OFFSET(VM, cpum);
208 CHECK_PADDING_VM(64, cpum);
209 CHECK_PADDING_VM(64, vmm);
210 PRINT_OFFSET(VM, pgm);
211 PRINT_OFFSET(VM, pgm.s.CritSectX);
212 CHECK_PADDING_VM(64, pgm);
213 PRINT_OFFSET(VM, hm);
214 CHECK_PADDING_VM(64, hm);
215 CHECK_PADDING_VM(64, trpm);
216 CHECK_PADDING_VM(64, selm);
217 CHECK_PADDING_VM(64, mm);
218 CHECK_PADDING_VM(64, pdm);
219 PRINT_OFFSET(VM, pdm.s.CritSect);
220 CHECK_PADDING_VM(64, iom);
221#ifdef VBOX_WITH_RAW_MODE
222 CHECK_PADDING_VM(64, patm);
223 CHECK_PADDING_VM(64, csam);
224#endif
225 CHECK_PADDING_VM(64, em);
226 /*CHECK_PADDING_VM(64, iem);*/
227 CHECK_PADDING_VM(64, tm);
228 PRINT_OFFSET(VM, tm.s.VirtualSyncLock);
229 CHECK_PADDING_VM(64, dbgf);
230 CHECK_PADDING_VM(64, gim);
231 CHECK_PADDING_VM(64, ssm);
232 CHECK_PADDING_VM(64, rem);
233 CHECK_PADDING_VM(8, vm);
234 CHECK_PADDING_VM(8, cfgm);
235
236 PRINT_OFFSET(VMCPU, cpum);
237 CHECK_PADDING_VMCPU(64, cpum);
238 CHECK_PADDING_VMCPU(64, hm);
239 CHECK_PADDING_VMCPU(64, em);
240 CHECK_PADDING_VMCPU(64, iem);
241 CHECK_PADDING_VMCPU(64, trpm);
242 CHECK_PADDING_VMCPU(64, tm);
243 CHECK_PADDING_VMCPU(64, vmm);
244 CHECK_PADDING_VMCPU(64, pdm);
245 CHECK_PADDING_VMCPU(64, iom);
246 CHECK_PADDING_VMCPU(64, dbgf);
247 CHECK_PADDING_VMCPU(64, gim);
248#if 0
249 PRINT_OFFSET(VMCPU, abAlignment2);
250#endif
251 PRINT_OFFSET(VMCPU, pgm);
252 CHECK_PADDING_VMCPU(4096, pgm);
253#ifdef VBOX_WITH_STATISTICS
254 PRINT_OFFSET(VMCPU, pgm.s.pStatTrap0eAttributionRC);
255#endif
256
257 CHECK_MEMBER_ALIGNMENT(VM, selm.s.Tss, 16);
258 PRINT_OFFSET(VM, selm.s.Tss);
259 PVM pVM = NULL; NOREF(pVM);
260 if ((RT_OFFSETOF(VM, selm.s.Tss) & PAGE_OFFSET_MASK) > PAGE_SIZE - sizeof(pVM->selm.s.Tss))
261 {
262 printf("error! SELM:Tss is crossing a page!\n");
263 rc++;
264 }
265 PRINT_OFFSET(VM, selm.s.TssTrap08);
266 if ((RT_OFFSETOF(VM, selm.s.TssTrap08) & PAGE_OFFSET_MASK) > PAGE_SIZE - sizeof(pVM->selm.s.TssTrap08))
267 {
268 printf("error! SELM:TssTrap08 is crossing a page!\n");
269 rc++;
270 }
271 CHECK_MEMBER_ALIGNMENT(VM, trpm.s.aIdt, 16);
272 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0], PAGE_SIZE);
273 CHECK_MEMBER_ALIGNMENT(VM, aCpus[1], PAGE_SIZE);
274 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].cpum.s.Host, 64);
275 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].cpum.s.Guest, 64);
276 CHECK_MEMBER_ALIGNMENT(VM, aCpus[1].cpum.s.Host, 64);
277 CHECK_MEMBER_ALIGNMENT(VM, aCpus[1].cpum.s.Guest, 64);
278 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].cpum.s.Hyper, 64);
279 CHECK_MEMBER_ALIGNMENT(VM, aCpus[1].cpum.s.Hyper, 64);
280#ifdef VBOX_WITH_VMMR0_DISABLE_LAPIC_NMI
281 CHECK_MEMBER_ALIGNMENT(VM, aCpus[0].cpum.s.pvApicBase, 8);
282#endif
283
284 CHECK_MEMBER_ALIGNMENT(VMCPU, vmm.s.u64CallRing3Arg, 8);
285#if defined(RT_OS_WINDOWS) && defined(RT_ARCH_AMD64)
286 CHECK_MEMBER_ALIGNMENT(VMCPU, vmm.s.CallRing3JmpBufR0, 16);
287 CHECK_MEMBER_ALIGNMENT(VMCPU, vmm.s.CallRing3JmpBufR0.xmm6, 16);
288#endif
289 CHECK_MEMBER_ALIGNMENT(VM, vmm.s.u64LastYield, 8);
290 CHECK_MEMBER_ALIGNMENT(VM, vmm.s.StatRunRC, 8);
291 CHECK_MEMBER_ALIGNMENT(VM, StatTotalQemuToGC, 8);
292 CHECK_MEMBER_ALIGNMENT(VM, rem.s.uPendingExcptCR2, 8);
293 CHECK_MEMBER_ALIGNMENT(VM, rem.s.StatsInQEMU, 8);
294 CHECK_MEMBER_ALIGNMENT(VM, rem.s.Env, 64);
295
296 /* the VMCPUs are page aligned TLB hit reasons. */
297 CHECK_MEMBER_ALIGNMENT(VM, aCpus, 4096);
298 CHECK_SIZE_ALIGNMENT(VMCPU, 4096);
299
300 /* cpumctx */
301 CHECK_MEMBER_ALIGNMENT(CPUMCTX, rax, 32);
302 CHECK_MEMBER_ALIGNMENT(CPUMCTX, idtr.pIdt, 8);
303 CHECK_MEMBER_ALIGNMENT(CPUMCTX, gdtr.pGdt, 8);
304 CHECK_MEMBER_ALIGNMENT(CPUMCTX, SysEnter, 8);
305 CHECK_CPUMCTXCORE(rax);
306 CHECK_CPUMCTXCORE(rcx);
307 CHECK_CPUMCTXCORE(rdx);
308 CHECK_CPUMCTXCORE(rbx);
309 CHECK_CPUMCTXCORE(rsp);
310 CHECK_CPUMCTXCORE(rbp);
311 CHECK_CPUMCTXCORE(rsi);
312 CHECK_CPUMCTXCORE(rdi);
313 CHECK_CPUMCTXCORE(r8);
314 CHECK_CPUMCTXCORE(r9);
315 CHECK_CPUMCTXCORE(r10);
316 CHECK_CPUMCTXCORE(r11);
317 CHECK_CPUMCTXCORE(r12);
318 CHECK_CPUMCTXCORE(r13);
319 CHECK_CPUMCTXCORE(r14);
320 CHECK_CPUMCTXCORE(r15);
321 CHECK_CPUMCTXCORE(es);
322 CHECK_CPUMCTXCORE(ss);
323 CHECK_CPUMCTXCORE(cs);
324 CHECK_CPUMCTXCORE(ds);
325 CHECK_CPUMCTXCORE(fs);
326 CHECK_CPUMCTXCORE(gs);
327 CHECK_CPUMCTXCORE(rip);
328 CHECK_CPUMCTXCORE(rflags);
329
330#if HC_ARCH_BITS == 32
331 /* CPUMHOSTCTX - lss pair */
332 if (RT_OFFSETOF(CPUMHOSTCTX, esp) + 4 != RT_OFFSETOF(CPUMHOSTCTX, ss))
333 {
334 printf("error! CPUMHOSTCTX lss has been split up!\n");
335 rc++;
336 }
337#endif
338 CHECK_SIZE_ALIGNMENT(CPUMCTX, 64);
339 CHECK_SIZE_ALIGNMENT(CPUMHOSTCTX, 64);
340 CHECK_SIZE_ALIGNMENT(CPUMCTXMSRS, 64);
341
342 /* pdm */
343 PRINT_OFFSET(PDMDEVINS, Internal);
344 PRINT_OFFSET(PDMDEVINS, achInstanceData);
345 CHECK_MEMBER_ALIGNMENT(PDMDEVINS, achInstanceData, 64);
346 CHECK_PADDING(PDMDEVINS, Internal, 1);
347
348 PRINT_OFFSET(PDMUSBINS, Internal);
349 PRINT_OFFSET(PDMUSBINS, achInstanceData);
350 CHECK_MEMBER_ALIGNMENT(PDMUSBINS, achInstanceData, 32);
351 CHECK_PADDING(PDMUSBINS, Internal, 1);
352
353 PRINT_OFFSET(PDMDRVINS, Internal);
354 PRINT_OFFSET(PDMDRVINS, achInstanceData);
355 CHECK_MEMBER_ALIGNMENT(PDMDRVINS, achInstanceData, 32);
356 CHECK_PADDING(PDMDRVINS, Internal, 1);
357
358 CHECK_PADDING2(PDMCRITSECT);
359 CHECK_PADDING2(PDMCRITSECTRW);
360
361 /* pgm */
362#if defined(VBOX_WITH_2X_4GB_ADDR_SPACE) || defined(VBOX_WITH_RAW_MODE)
363 CHECK_MEMBER_ALIGNMENT(PGMCPU, AutoSet, 8);
364#endif
365 CHECK_MEMBER_ALIGNMENT(PGMCPU, GCPhysCR3, sizeof(RTGCPHYS));
366 CHECK_MEMBER_ALIGNMENT(PGMCPU, aGCPhysGstPaePDs, sizeof(RTGCPHYS));
367 CHECK_MEMBER_ALIGNMENT(PGMCPU, DisState, 8);
368 CHECK_MEMBER_ALIGNMENT(PGMCPU, cPoolAccessHandler, 8);
369 CHECK_MEMBER_ALIGNMENT(PGMPOOLPAGE, idx, sizeof(uint16_t));
370 CHECK_MEMBER_ALIGNMENT(PGMPOOLPAGE, pvPageR3, sizeof(RTHCPTR));
371 CHECK_MEMBER_ALIGNMENT(PGMPOOLPAGE, GCPhys, sizeof(RTGCPHYS));
372 CHECK_SIZE(PGMPAGE, 16);
373 CHECK_MEMBER_ALIGNMENT(PGMRAMRANGE, aPages, 16);
374 CHECK_MEMBER_ALIGNMENT(PGMMMIO2RANGE, RamRange, 16);
375
376 /* rem */
377 CHECK_MEMBER_ALIGNMENT(REM, aGCPtrInvalidatedPages, 8);
378 CHECK_PADDING3(REMHANDLERNOTIFICATION, u.PhysicalRegister, u.padding);
379 CHECK_PADDING3(REMHANDLERNOTIFICATION, u.PhysicalDeregister, u.padding);
380 CHECK_PADDING3(REMHANDLERNOTIFICATION, u.PhysicalModify, u.padding);
381 CHECK_SIZE_ALIGNMENT(REMHANDLERNOTIFICATION, 8);
382 CHECK_MEMBER_ALIGNMENT(REMHANDLERNOTIFICATION, u.PhysicalDeregister.GCPhys, 8);
383
384 /* TM */
385 CHECK_MEMBER_ALIGNMENT(TM, TimerCritSect, sizeof(uintptr_t));
386 CHECK_MEMBER_ALIGNMENT(TM, VirtualSyncLock, sizeof(uintptr_t));
387
388 /* misc */
389 CHECK_PADDING3(EMCPU, u.FatalLongJump, u.achPaddingFatalLongJump);
390 CHECK_SIZE_ALIGNMENT(VMMR0JMPBUF, 8);
391#ifdef VBOX_WITH_RAW_MODE
392 CHECK_SIZE_ALIGNMENT(PATCHINFO, 8);
393#endif
394#if 0
395 PRINT_OFFSET(VM, fForcedActions);
396 PRINT_OFFSET(VM, StatQemuToGC);
397 PRINT_OFFSET(VM, StatGCToQemu);
398#endif
399
400 CHECK_MEMBER_ALIGNMENT(IOM, CritSect, sizeof(uintptr_t));
401#ifdef VBOX_WITH_REM
402 CHECK_MEMBER_ALIGNMENT(EM, CritSectREM, sizeof(uintptr_t));
403#endif
404 CHECK_MEMBER_ALIGNMENT(PGM, CritSectX, sizeof(uintptr_t));
405 CHECK_MEMBER_ALIGNMENT(PDM, CritSect, sizeof(uintptr_t));
406 CHECK_MEMBER_ALIGNMENT(MMHYPERHEAP, Lock, sizeof(uintptr_t));
407
408 /* hm - 32-bit gcc won't align uint64_t naturally, so check. */
409 CHECK_MEMBER_ALIGNMENT(HM, uMaxAsid, 8);
410 CHECK_MEMBER_ALIGNMENT(HM, vmx, 8);
411 CHECK_MEMBER_ALIGNMENT(HM, vmx.Msrs, 8);
412 CHECK_MEMBER_ALIGNMENT(HM, svm, 8);
413 CHECK_MEMBER_ALIGNMENT(HM, PatchTree, 8);
414 CHECK_MEMBER_ALIGNMENT(HM, aPatches, 8);
415 CHECK_MEMBER_ALIGNMENT(HMCPU, vmx, 8);
416 CHECK_MEMBER_ALIGNMENT(HMCPU, vmx.pfnStartVM, 8);
417 CHECK_MEMBER_ALIGNMENT(HMCPU, vmx.HCPhysVmcs, 8);
418 CHECK_MEMBER_ALIGNMENT(HMCPU, vmx.LastError, 8);
419 CHECK_MEMBER_ALIGNMENT(HMCPU, svm, 8);
420 CHECK_MEMBER_ALIGNMENT(HMCPU, svm.pfnVMRun, 8);
421 CHECK_MEMBER_ALIGNMENT(HMCPU, Event, 8);
422 CHECK_MEMBER_ALIGNMENT(HMCPU, Event.u64IntInfo, 8);
423 CHECK_MEMBER_ALIGNMENT(HMCPU, DisState, 8);
424 CHECK_MEMBER_ALIGNMENT(HMCPU, StatEntry, 8);
425
426 /* Make sure the set is large enough and has the correct size. */
427 CHECK_SIZE(VMCPUSET, 32);
428 if (sizeof(VMCPUSET) * 8 < VMM_MAX_CPU_COUNT)
429 {
430 printf("error! VMCPUSET is too small for VMM_MAX_CPU_COUNT=%u!\n", VMM_MAX_CPU_COUNT);
431 rc++;
432 }
433
434 printf("info: struct UVM: %d bytes\n", (int)sizeof(UVM));
435
436 CHECK_PADDING_UVM(32, vm);
437 CHECK_PADDING_UVM(32, mm);
438 CHECK_PADDING_UVM(32, pdm);
439 CHECK_PADDING_UVM(32, stam);
440
441 printf("info: struct UVMCPU: %d bytes\n", (int)sizeof(UVMCPU));
442 CHECK_PADDING_UVMCPU(32, vm);
443
444#ifdef VBOX_WITH_RAW_MODE
445 /*
446 * Compare HC and RC.
447 */
448 printf("tstVMStructSize: Comparing HC and RC...\n");
449# include "tstVMStructRC.h"
450#endif /* VBOX_WITH_RAW_MODE */
451
452 CHECK_PADDING_GVM(4, gvmm);
453 CHECK_PADDING_GVM(4, gmm);
454 CHECK_PADDING_GVMCPU(4, gvmm);
455
456 /*
457 * Check that the optimized access macros for PGMPAGE works correctly.
458 */
459 PGMPAGE Page;
460 PGM_PAGE_CLEAR(&Page);
461
462 CHECK_EXPR(PGM_PAGE_GET_HNDL_PHYS_STATE(&Page) == PGM_PAGE_HNDL_PHYS_STATE_NONE);
463 CHECK_EXPR(PGM_PAGE_HAS_ANY_HANDLERS(&Page) == false);
464 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_HANDLERS(&Page) == false);
465 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_ALL_HANDLERS(&Page) == false);
466
467 PGM_PAGE_SET_HNDL_PHYS_STATE(&Page, PGM_PAGE_HNDL_PHYS_STATE_ALL);
468 CHECK_EXPR(PGM_PAGE_GET_HNDL_PHYS_STATE(&Page) == PGM_PAGE_HNDL_PHYS_STATE_ALL);
469 CHECK_EXPR(PGM_PAGE_HAS_ANY_HANDLERS(&Page) == true);
470 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_HANDLERS(&Page) == true);
471 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_ALL_HANDLERS(&Page) == true);
472
473 PGM_PAGE_SET_HNDL_PHYS_STATE(&Page, PGM_PAGE_HNDL_PHYS_STATE_WRITE);
474 CHECK_EXPR(PGM_PAGE_GET_HNDL_PHYS_STATE(&Page) == PGM_PAGE_HNDL_PHYS_STATE_WRITE);
475 CHECK_EXPR(PGM_PAGE_HAS_ANY_HANDLERS(&Page) == true);
476 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_HANDLERS(&Page) == true);
477 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_ALL_HANDLERS(&Page) == false);
478
479 PGM_PAGE_CLEAR(&Page);
480 PGM_PAGE_SET_HNDL_VIRT_STATE(&Page, PGM_PAGE_HNDL_VIRT_STATE_ALL);
481 CHECK_EXPR(PGM_PAGE_GET_HNDL_VIRT_STATE(&Page) == PGM_PAGE_HNDL_VIRT_STATE_ALL);
482 CHECK_EXPR(PGM_PAGE_HAS_ANY_HANDLERS(&Page) == true);
483 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_HANDLERS(&Page) == true);
484 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_ALL_HANDLERS(&Page) == true);
485
486 PGM_PAGE_SET_HNDL_VIRT_STATE(&Page, PGM_PAGE_HNDL_VIRT_STATE_WRITE);
487 CHECK_EXPR(PGM_PAGE_GET_HNDL_VIRT_STATE(&Page) == PGM_PAGE_HNDL_VIRT_STATE_WRITE);
488 CHECK_EXPR(PGM_PAGE_HAS_ANY_HANDLERS(&Page) == true);
489 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_HANDLERS(&Page) == true);
490 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_ALL_HANDLERS(&Page) == false);
491
492
493 PGM_PAGE_CLEAR(&Page);
494 PGM_PAGE_SET_HNDL_PHYS_STATE(&Page, PGM_PAGE_HNDL_PHYS_STATE_ALL);
495 PGM_PAGE_SET_HNDL_VIRT_STATE(&Page, PGM_PAGE_HNDL_VIRT_STATE_WRITE);
496 CHECK_EXPR(PGM_PAGE_GET_HNDL_PHYS_STATE(&Page) == PGM_PAGE_HNDL_PHYS_STATE_ALL);
497 CHECK_EXPR(PGM_PAGE_GET_HNDL_VIRT_STATE(&Page) == PGM_PAGE_HNDL_VIRT_STATE_WRITE);
498 CHECK_EXPR(PGM_PAGE_HAS_ANY_HANDLERS(&Page) == true);
499 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_HANDLERS(&Page) == true);
500 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_ALL_HANDLERS(&Page) == true);
501
502 PGM_PAGE_SET_HNDL_PHYS_STATE(&Page, PGM_PAGE_HNDL_PHYS_STATE_WRITE);
503 PGM_PAGE_SET_HNDL_VIRT_STATE(&Page, PGM_PAGE_HNDL_VIRT_STATE_ALL);
504 CHECK_EXPR(PGM_PAGE_GET_HNDL_PHYS_STATE(&Page) == PGM_PAGE_HNDL_PHYS_STATE_WRITE);
505 CHECK_EXPR(PGM_PAGE_GET_HNDL_VIRT_STATE(&Page) == PGM_PAGE_HNDL_VIRT_STATE_ALL);
506 CHECK_EXPR(PGM_PAGE_HAS_ANY_HANDLERS(&Page) == true);
507 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_HANDLERS(&Page) == true);
508 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_ALL_HANDLERS(&Page) == true);
509
510 PGM_PAGE_SET_HNDL_PHYS_STATE(&Page, PGM_PAGE_HNDL_PHYS_STATE_WRITE);
511 PGM_PAGE_SET_HNDL_VIRT_STATE(&Page, PGM_PAGE_HNDL_VIRT_STATE_WRITE);
512 CHECK_EXPR(PGM_PAGE_GET_HNDL_PHYS_STATE(&Page) == PGM_PAGE_HNDL_PHYS_STATE_WRITE);
513 CHECK_EXPR(PGM_PAGE_GET_HNDL_VIRT_STATE(&Page) == PGM_PAGE_HNDL_VIRT_STATE_WRITE);
514 CHECK_EXPR(PGM_PAGE_HAS_ANY_HANDLERS(&Page) == true);
515 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_HANDLERS(&Page) == true);
516 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_ALL_HANDLERS(&Page) == false);
517
518 PGM_PAGE_SET_HNDL_VIRT_STATE(&Page, PGM_PAGE_HNDL_VIRT_STATE_NONE);
519 CHECK_EXPR(PGM_PAGE_GET_HNDL_PHYS_STATE(&Page) == PGM_PAGE_HNDL_PHYS_STATE_WRITE);
520 CHECK_EXPR(PGM_PAGE_GET_HNDL_VIRT_STATE(&Page) == PGM_PAGE_HNDL_VIRT_STATE_NONE);
521 CHECK_EXPR(PGM_PAGE_HAS_ANY_HANDLERS(&Page) == true);
522 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_HANDLERS(&Page) == true);
523 CHECK_EXPR(PGM_PAGE_HAS_ACTIVE_ALL_HANDLERS(&Page) == false);
524
525#undef AssertFatal
526#define AssertFatal(expr) do { } while (0)
527#undef Assert
528#define Assert(expr) do { } while (0)
529
530 PGM_PAGE_CLEAR(&Page);
531 CHECK_EXPR(PGM_PAGE_GET_HCPHYS_NA(&Page) == 0);
532 PGM_PAGE_SET_HCPHYS(NULL, &Page, UINT64_C(0x0000fffeff1ff000));
533 CHECK_EXPR(PGM_PAGE_GET_HCPHYS_NA(&Page) == UINT64_C(0x0000fffeff1ff000));
534 PGM_PAGE_SET_HCPHYS(NULL, &Page, UINT64_C(0x0000000000001000));
535 CHECK_EXPR(PGM_PAGE_GET_HCPHYS_NA(&Page) == UINT64_C(0x0000000000001000));
536
537 PGM_PAGE_INIT(&Page, UINT64_C(0x0000feedfacef000), UINT32_C(0x12345678), PGMPAGETYPE_RAM, PGM_PAGE_STATE_ALLOCATED);
538 CHECK_EXPR(PGM_PAGE_GET_HCPHYS_NA(&Page) == UINT64_C(0x0000feedfacef000));
539 CHECK_EXPR(PGM_PAGE_GET_PAGEID(&Page) == UINT32_C(0x12345678));
540 CHECK_EXPR(PGM_PAGE_GET_TYPE_NA(&Page) == PGMPAGETYPE_RAM);
541 CHECK_EXPR(PGM_PAGE_GET_STATE_NA(&Page) == PGM_PAGE_STATE_ALLOCATED);
542
543
544 /*
545 * Report result.
546 */
547 if (rc)
548 printf("tstVMStructSize: FAILURE - %d errors\n", rc);
549 else
550 printf("tstVMStructSize: SUCCESS\n");
551 return rc;
552}
553
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