VirtualBox

source: vbox/trunk/include/VBox/vmm/gvm.h@ 108994

Last change on this file since 108994 was 108634, checked in by vboxsync, 5 weeks ago

include/VBox/vmm/gvm.h: clang build fixes, bugref:10391

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 11.0 KB
Line 
1/* $Id: gvm.h 108634 2025-03-20 11:54:50Z vboxsync $ */
2/** @file
3 * GVM - The Global VM Data.
4 */
5
6/*
7 * Copyright (C) 2007-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef VBOX_INCLUDED_vmm_gvm_h
38#define VBOX_INCLUDED_vmm_gvm_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#ifndef USING_VMM_COMMON_DEFS
44# error "Compile job does not include VMM_COMMON_DEFS from src/VBox/Config.kmk - make sure you really need to include this file!"
45#endif
46#include <VBox/types.h>
47#include <VBox/vmm/vm.h>
48#include <VBox/param.h>
49#include <iprt/thread.h>
50#include <iprt/assertcompile.h>
51
52
53/** @defgroup grp_gvmcpu GVMCPU - The Global VMCPU Data
54 * @ingroup grp_vmm
55 * @{
56 */
57
58#if defined(__cplusplus) && !defined(GVM_C_STYLE_STRUCTURES)
59typedef struct GVMCPU : public VMCPU
60#else
61typedef struct GVMCPU
62#endif
63{
64#if !defined(__cplusplus) || defined(GVM_C_STYLE_STRUCTURES)
65 VMCPU s;
66#endif
67
68 /** VCPU id (0 - (pVM->cCpus - 1). */
69 VMCPUID idCpu;
70 /** The VM target platform architecture.
71 * Same as GVM::enmTarget, VMCPU::enmTarget and VM::enmTarget. */
72 VMTARGET enmTarget;
73
74 /** Handle to the EMT thread. */
75 RTNATIVETHREAD hEMT;
76
77 /** Pointer to the global (ring-0) VM structure this CPU belongs to. */
78 R0PTRTYPE(PGVM) pGVM;
79 /** Pointer to the GVM structure, for CTX_SUFF use in VMMAll code. */
80 PGVM pVMR0;
81 /** The ring-3 address of this structure (only VMCPU part). */
82 PVMCPUR3 pVCpuR3;
83
84 /** Padding so the noisy stuff on a 64 byte boundrary.
85 * @note Keeping this working for 32-bit header syntax checking. */
86 uint8_t abPadding1[HC_ARCH_BITS == 32 ? 40 : 24];
87
88 /** Which host CPU ID is this EMT running on.
89 * Only valid when in RC or HMR0 with scheduling disabled. */
90 RTCPUID volatile idHostCpu;
91 /** The CPU set index corresponding to idHostCpu, UINT32_MAX if not valid.
92 * @remarks Best to make sure iHostCpuSet shares cache line with idHostCpu! */
93 uint32_t volatile iHostCpuSet;
94
95 /** Padding so gvmm starts on a 64 byte boundrary.
96 * @note Keeping this working for 32-bit header syntax checking. */
97 uint8_t abPadding2[56];
98
99 /** The GVMM per vcpu data. */
100 union
101 {
102#ifdef VMM_INCLUDED_SRC_VMMR0_GVMMR0Internal_h
103 struct GVMMPERVCPU s;
104#endif
105 uint8_t padding[256];
106 } gvmm;
107
108 union
109 {
110#if defined(VMM_INCLUDED_SRC_include_VMMInternal_h) && defined(IN_RING0)
111 struct VMMR0PERVCPU s;
112#endif
113 uint8_t padding[896];
114 } vmmr0;
115
116#ifndef VBOX_WITH_MINIMAL_R0
117
118 /** The HM per vcpu data. */
119 union
120 {
121# if defined(VMM_INCLUDED_SRC_include_HMInternal_h) && defined(IN_RING0)
122 struct HMR0PERVCPU s;
123# endif
124 uint8_t padding[1024];
125 } hmr0;
126
127# ifdef VBOX_WITH_NEM_R0
128 /** The NEM per vcpu data. */
129 union
130 {
131# if defined(VMM_INCLUDED_SRC_include_NEMInternal_h) && defined(IN_RING0)
132 struct NEMR0PERVCPU s;
133# endif
134 uint8_t padding[64];
135 } nemr0;
136# endif
137
138 union
139 {
140# if defined(VMM_INCLUDED_SRC_include_PGMInternal_h) && defined(IN_RING0)
141 struct PGMR0PERVCPU s;
142# endif
143 uint8_t padding[576];
144 } pgmr0;
145
146#endif /* !VBOX_WITH_MINIMAL_R0 */
147
148 /** Padding the structure size to page boundrary. */
149#ifdef VBOX_WITH_MINIMAL_R0
150 uint8_t abPadding3[16384 - 64*2 - 256 - 896];
151#elif defined(VBOX_WITH_NEM_R0)
152 uint8_t abPadding3[16384 - 64*2 - 256 - 896 - 1024 - 64 - 576];
153#else
154 uint8_t abPadding3[16384 - 64*2 - 256 - 896 - 1024 - 576];
155#endif
156} GVMCPU;
157#ifndef IN_TSTVMSTRUCT
158# if RT_CLANG_PREREQ(3, 4) && defined(__cplusplus)
159# pragma clang diagnostic push
160# elif RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
161# pragma GCC diagnostic push
162# endif
163
164# if RT_CLANG_PREREQ(3, 4) && defined(__cplusplus)
165# pragma clang diagnostic ignored "-Winvalid-offsetof"
166# elif RT_GNUC_PREREQ(4, 3) && defined(__cplusplus)
167# pragma GCC diagnostic ignored "-Winvalid-offsetof"
168# endif
169AssertCompileMemberAlignment(GVMCPU, idCpu, 16384);
170AssertCompileMemberAlignment(GVMCPU, gvmm, 64);
171# ifndef VBOX_WITH_MINIMAL_R0
172# ifdef VBOX_WITH_NEM_R0
173AssertCompileMemberAlignment(GVMCPU, nemr0, 64);
174# endif
175# endif
176AssertCompileSizeAlignment(GVMCPU, 16384);
177# if RT_CLANG_PREREQ(3, 4) && defined(__cplusplus)
178# pragma clang diagnostic pop
179# elif RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
180# pragma GCC diagnostic pop
181# endif
182#endif
183
184/** @} */
185
186/** @defgroup grp_gvm GVM - The Global VM Data
187 * @ingroup grp_vmm
188 * @{
189 */
190
191/**
192 * The Global VM Data.
193 *
194 * This is a ring-0 only structure where we put items we don't need to
195 * share with ring-3 or GC, like for instance various RTR0MEMOBJ handles.
196 *
197 * Unlike VM, there are no special alignment restrictions here. The
198 * paddings are checked by compile time assertions.
199 */
200#if defined(__cplusplus) && !defined(GVM_C_STYLE_STRUCTURES)
201typedef struct GVM : public VM
202#else
203typedef struct GVM
204#endif
205{
206#if !defined(__cplusplus) || defined(GVM_C_STYLE_STRUCTURES)
207 VM s;
208#endif
209 /** Magic / eye-catcher (GVM_MAGIC). */
210 uint32_t u32Magic;
211 /** The global VM handle for this VM. */
212 uint32_t hSelf;
213 /** Pointer to this structure (for validation purposes). */
214 PGVM pSelf;
215 /** The ring-3 mapping of the VM structure. */
216 PVMR3 pVMR3;
217 /** The support driver session the VM is associated with. */
218 PSUPDRVSESSION pSession;
219 /** Number of Virtual CPUs, i.e. how many entries there are in aCpus.
220 * Same as VM::cCpus. */
221 uint32_t cCpus;
222 /** The VM target platform architecture.
223 * Same as VM::enmTarget. */
224 VMTARGET enmTarget;
225 /** Padding so gvmm starts on a 64 byte boundrary. */
226 uint8_t abPadding[HC_ARCH_BITS == 32 ? 12 + 24 : 24];
227
228 /** The GVMM per vm data. */
229 union
230 {
231#ifdef VMM_INCLUDED_SRC_VMMR0_GVMMR0Internal_h
232 struct GVMMPERVM s;
233#endif
234 uint8_t padding[4352];
235 } gvmm;
236
237#ifndef VBOX_WITH_MINIMAL_R0
238
239 /** The GMM per vm data. */
240 union
241 {
242# ifdef VMM_INCLUDED_SRC_VMMR0_GMMR0Internal_h
243 struct GMMPERVM s;
244# endif
245 uint8_t padding[1024];
246 } gmm;
247
248 /** The HM per vm data. */
249 union
250 {
251# if defined(VMM_INCLUDED_SRC_include_HMInternal_h) && defined(IN_RING0)
252 struct HMR0PERVM s;
253# endif
254 uint8_t padding[256];
255 } hmr0;
256
257# ifdef VBOX_WITH_NEM_R0
258 /** The NEM per vcpu data. */
259 union
260 {
261# if defined(VMM_INCLUDED_SRC_include_NEMInternal_h) && defined(IN_RING0)
262 struct NEMR0PERVM s;
263# endif
264 uint8_t padding[256];
265 } nemr0;
266# endif
267
268 /** The RAWPCIVM per vm data. */
269 union
270 {
271# ifdef VBOX_INCLUDED_rawpci_h
272 struct RAWPCIPERVM s;
273# endif
274 uint8_t padding[64];
275 } rawpci;
276
277 union
278 {
279# if defined(VMM_INCLUDED_SRC_include_PDMInternal_h) && defined(IN_RING0)
280 struct PDMR0PERVM s;
281# endif
282 uint8_t padding[3264];
283 } pdmr0;
284
285 union
286 {
287# if defined(VMM_INCLUDED_SRC_include_PGMInternal_h) && defined(IN_RING0)
288 struct PGMR0PERVM s;
289# endif
290 uint8_t padding[90112];
291 } pgmr0;
292
293 union
294 {
295# if defined(VMM_INCLUDED_SRC_include_IOMInternal_h) && defined(IN_RING0)
296 struct IOMR0PERVM s;
297# endif
298 uint8_t padding[512];
299 } iomr0;
300
301 union
302 {
303# if defined(VMM_INCLUDED_SRC_include_APICInternal_h) && defined(IN_RING0)
304 struct APICR0PERVM s;
305# endif
306 uint8_t padding[64];
307 } apicr0;
308
309 union
310 {
311# if defined(VMM_INCLUDED_SRC_include_DBGFInternal_h) && defined(IN_RING0)
312 struct DBGFR0PERVM s;
313# endif
314 uint8_t padding[1024];
315 } dbgfr0;
316
317 union
318 {
319# if defined(VMM_INCLUDED_SRC_include_TMInternal_h) && defined(IN_RING0)
320 TMR0PERVM s;
321# endif
322 uint8_t padding[192];
323 } tmr0;
324
325#endif /* !VBOX_WITH_MINIMAL_R0 */
326
327 union
328 {
329#if defined(VMM_INCLUDED_SRC_include_VMMInternal_h) && defined(IN_RING0)
330 VMMR0PERVM s;
331#endif
332 uint8_t padding[704];
333 } vmmr0;
334
335 /** Padding so aCpus starts on a page boundrary. */
336#ifdef VBOX_WITH_MINIMAL_R0
337 uint8_t abPadding2[16384*1 - 64 - 4352 - 704 - sizeof(PGVMCPU) * VMM_MAX_CPU_COUNT];
338#elif defined(VBOX_WITH_NEM_R0)
339 uint8_t abPadding2[16384*7 - 64 - 4352 - 1024 - 256 - 256 - 64 - 3264 - 90112 - 512 - 64 - 1024 - 192 - 704 - sizeof(PGVMCPU) * VMM_MAX_CPU_COUNT];
340#else
341 uint8_t abPadding2[16384*7 - 64 - 4352 - 1024 - 256 - 64 - 3264 - 90112 - 512 - 64 - 1024 - 192 - 704 - sizeof(PGVMCPU) * VMM_MAX_CPU_COUNT];
342#endif
343
344 /** For simplifying CPU enumeration in VMMAll code. */
345 PGVMCPU apCpusR0[VMM_MAX_CPU_COUNT];
346
347 /** GVMCPU array for the configured number of virtual CPUs. */
348 GVMCPU aCpus[1];
349} GVM;
350#if 0
351#if RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
352# pragma GCC diagnostic push
353#endif
354#if RT_GNUC_PREREQ(4, 3) && defined(__cplusplus)
355# pragma GCC diagnostic ignored "-Winvalid-offsetof"
356#endif
357AssertCompileMemberAlignment(GVM, u32Magic, 64);
358AssertCompileMemberAlignment(GVM, gvmm, 64);
359AssertCompileMemberAlignment(GVM, gmm, 64);
360#ifdef VBOX_WITH_NEM_R0
361AssertCompileMemberAlignment(GVM, nemr0, 64);
362#endif
363AssertCompileMemberAlignment(GVM, rawpci, 64);
364AssertCompileMemberAlignment(GVM, pdmr0, 64);
365AssertCompileMemberAlignment(GVM, aCpus, 16384);
366AssertCompileSizeAlignment(GVM, 16384);
367#if RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
368# pragma GCC diagnostic pop
369#endif
370#endif
371
372/** The GVM::u32Magic value (Wayne Shorter). */
373#define GVM_MAGIC 0x19330825
374
375/** @} */
376
377#endif /* !VBOX_INCLUDED_vmm_gvm_h */
378
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette