VirtualBox

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

Last change on this file was 107893, checked in by vboxsync, 4 weeks ago

VMM,VBox/types.h,VBox/err.h: Added VM target platform arch members to the VM structures (mostly for ring-0). Also added the structure sizes and svn revision to VMMR0_DO_GVMM_CREATE_VM. jiraref:VBP-1470

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 10.7 KB
Line 
1/* $Id: gvm.h 107893 2025-01-22 15:31:45Z 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_GNUC_PREREQ(4, 6) && defined(__cplusplus)
159# pragma GCC diagnostic push
160# endif
161# if RT_GNUC_PREREQ(4, 3) && defined(__cplusplus)
162# pragma GCC diagnostic ignored "-Winvalid-offsetof"
163# endif
164AssertCompileMemberAlignment(GVMCPU, idCpu, 16384);
165AssertCompileMemberAlignment(GVMCPU, gvmm, 64);
166# ifndef VBOX_WITH_MINIMAL_R0
167# ifdef VBOX_WITH_NEM_R0
168AssertCompileMemberAlignment(GVMCPU, nemr0, 64);
169# endif
170# endif
171AssertCompileSizeAlignment(GVMCPU, 16384);
172# if RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
173# pragma GCC diagnostic pop
174# endif
175#endif
176
177/** @} */
178
179/** @defgroup grp_gvm GVM - The Global VM Data
180 * @ingroup grp_vmm
181 * @{
182 */
183
184/**
185 * The Global VM Data.
186 *
187 * This is a ring-0 only structure where we put items we don't need to
188 * share with ring-3 or GC, like for instance various RTR0MEMOBJ handles.
189 *
190 * Unlike VM, there are no special alignment restrictions here. The
191 * paddings are checked by compile time assertions.
192 */
193#if defined(__cplusplus) && !defined(GVM_C_STYLE_STRUCTURES)
194typedef struct GVM : public VM
195#else
196typedef struct GVM
197#endif
198{
199#if !defined(__cplusplus) || defined(GVM_C_STYLE_STRUCTURES)
200 VM s;
201#endif
202 /** Magic / eye-catcher (GVM_MAGIC). */
203 uint32_t u32Magic;
204 /** The global VM handle for this VM. */
205 uint32_t hSelf;
206 /** Pointer to this structure (for validation purposes). */
207 PGVM pSelf;
208 /** The ring-3 mapping of the VM structure. */
209 PVMR3 pVMR3;
210 /** The support driver session the VM is associated with. */
211 PSUPDRVSESSION pSession;
212 /** Number of Virtual CPUs, i.e. how many entries there are in aCpus.
213 * Same as VM::cCpus. */
214 uint32_t cCpus;
215 /** The VM target platform architecture.
216 * Same as VM::enmTarget. */
217 VMTARGET enmTarget;
218 /** Padding so gvmm starts on a 64 byte boundrary. */
219 uint8_t abPadding[HC_ARCH_BITS == 32 ? 12 + 24 : 24];
220
221 /** The GVMM per vm data. */
222 union
223 {
224#ifdef VMM_INCLUDED_SRC_VMMR0_GVMMR0Internal_h
225 struct GVMMPERVM s;
226#endif
227 uint8_t padding[4352];
228 } gvmm;
229
230#ifndef VBOX_WITH_MINIMAL_R0
231
232 /** The GMM per vm data. */
233 union
234 {
235# ifdef VMM_INCLUDED_SRC_VMMR0_GMMR0Internal_h
236 struct GMMPERVM s;
237# endif
238 uint8_t padding[1024];
239 } gmm;
240
241 /** The HM per vm data. */
242 union
243 {
244# if defined(VMM_INCLUDED_SRC_include_HMInternal_h) && defined(IN_RING0)
245 struct HMR0PERVM s;
246# endif
247 uint8_t padding[256];
248 } hmr0;
249
250# ifdef VBOX_WITH_NEM_R0
251 /** The NEM per vcpu data. */
252 union
253 {
254# if defined(VMM_INCLUDED_SRC_include_NEMInternal_h) && defined(IN_RING0)
255 struct NEMR0PERVM s;
256# endif
257 uint8_t padding[256];
258 } nemr0;
259# endif
260
261 /** The RAWPCIVM per vm data. */
262 union
263 {
264# ifdef VBOX_INCLUDED_rawpci_h
265 struct RAWPCIPERVM s;
266# endif
267 uint8_t padding[64];
268 } rawpci;
269
270 union
271 {
272# if defined(VMM_INCLUDED_SRC_include_PDMInternal_h) && defined(IN_RING0)
273 struct PDMR0PERVM s;
274# endif
275 uint8_t padding[3264];
276 } pdmr0;
277
278 union
279 {
280# if defined(VMM_INCLUDED_SRC_include_PGMInternal_h) && defined(IN_RING0)
281 struct PGMR0PERVM s;
282# endif
283 uint8_t padding[90112];
284 } pgmr0;
285
286 union
287 {
288# if defined(VMM_INCLUDED_SRC_include_IOMInternal_h) && defined(IN_RING0)
289 struct IOMR0PERVM s;
290# endif
291 uint8_t padding[512];
292 } iomr0;
293
294 union
295 {
296# if defined(VMM_INCLUDED_SRC_include_APICInternal_h) && defined(IN_RING0)
297 struct APICR0PERVM s;
298# endif
299 uint8_t padding[64];
300 } apicr0;
301
302 union
303 {
304# if defined(VMM_INCLUDED_SRC_include_DBGFInternal_h) && defined(IN_RING0)
305 struct DBGFR0PERVM s;
306# endif
307 uint8_t padding[1024];
308 } dbgfr0;
309
310 union
311 {
312# if defined(VMM_INCLUDED_SRC_include_TMInternal_h) && defined(IN_RING0)
313 TMR0PERVM s;
314# endif
315 uint8_t padding[192];
316 } tmr0;
317
318#endif /* !VBOX_WITH_MINIMAL_R0 */
319
320 union
321 {
322#if defined(VMM_INCLUDED_SRC_include_VMMInternal_h) && defined(IN_RING0)
323 VMMR0PERVM s;
324#endif
325 uint8_t padding[704];
326 } vmmr0;
327
328 /** Padding so aCpus starts on a page boundrary. */
329#ifdef VBOX_WITH_MINIMAL_R0
330 uint8_t abPadding2[16384*1 - 64 - 4352 - 704 - sizeof(PGVMCPU) * VMM_MAX_CPU_COUNT];
331#elif defined(VBOX_WITH_NEM_R0)
332 uint8_t abPadding2[16384*7 - 64 - 4352 - 1024 - 256 - 256 - 64 - 3264 - 90112 - 512 - 64 - 1024 - 192 - 704 - sizeof(PGVMCPU) * VMM_MAX_CPU_COUNT];
333#else
334 uint8_t abPadding2[16384*7 - 64 - 4352 - 1024 - 256 - 64 - 3264 - 90112 - 512 - 64 - 1024 - 192 - 704 - sizeof(PGVMCPU) * VMM_MAX_CPU_COUNT];
335#endif
336
337 /** For simplifying CPU enumeration in VMMAll code. */
338 PGVMCPU apCpusR0[VMM_MAX_CPU_COUNT];
339
340 /** GVMCPU array for the configured number of virtual CPUs. */
341 GVMCPU aCpus[1];
342} GVM;
343#if 0
344#if RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
345# pragma GCC diagnostic push
346#endif
347#if RT_GNUC_PREREQ(4, 3) && defined(__cplusplus)
348# pragma GCC diagnostic ignored "-Winvalid-offsetof"
349#endif
350AssertCompileMemberAlignment(GVM, u32Magic, 64);
351AssertCompileMemberAlignment(GVM, gvmm, 64);
352AssertCompileMemberAlignment(GVM, gmm, 64);
353#ifdef VBOX_WITH_NEM_R0
354AssertCompileMemberAlignment(GVM, nemr0, 64);
355#endif
356AssertCompileMemberAlignment(GVM, rawpci, 64);
357AssertCompileMemberAlignment(GVM, pdmr0, 64);
358AssertCompileMemberAlignment(GVM, aCpus, 16384);
359AssertCompileSizeAlignment(GVM, 16384);
360#if RT_GNUC_PREREQ(4, 6) && defined(__cplusplus)
361# pragma GCC diagnostic pop
362#endif
363#endif
364
365/** The GVM::u32Magic value (Wayne Shorter). */
366#define GVM_MAGIC 0x19330825
367
368/** @} */
369
370#endif /* !VBOX_INCLUDED_vmm_gvm_h */
371
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