VirtualBox

source: vbox/trunk/include/VBox/vmm/vmcc.h@ 93593

Last change on this file since 93593 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1/** @file
2 * VM - The Virtual Machine, GVM/GVMCPU or VM/VMCPU depending on context.
3 */
4
5/*
6 * Copyright (C) 2019-2022 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef VBOX_INCLUDED_vmm_vmcc_h
27#define VBOX_INCLUDED_vmm_vmcc_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32
33#include <VBox/vmm/vm.h>
34#ifdef IN_RING0
35# include <VBox/vmm/gvm.h>
36#else
37# include <VBox/vmm/uvm.h>
38#endif
39
40/** @typedef VMCC
41 * Context specific VM derived structure.
42 * This is plain VM in ring-3 and GVM (inherits from VM) in ring-0. */
43/** @typedef VMCPUCC
44 * Context specific VMCPU derived structure.
45 * This is plain VM in ring-3 and GVMCPU (inherits from VMCPU) in ring-0. */
46#ifdef IN_RING0
47typedef GVM VMCC;
48typedef GVMCPU VMCPUCC;
49#else
50typedef VM VMCC;
51typedef VMCPU VMCPUCC;
52#endif
53
54/** @def VMCC_GET_CPU_0
55 * Gets the context specfic pointer to virtual CPU \#0.
56 * @param a_pVM The context specfic VM structure.
57 */
58#ifdef IN_RING0
59# define VMCC_GET_CPU_0(a_pVM) (&(a_pVM)->aCpus[0])
60#else
61# define VMCC_GET_CPU_0(a_pVM) ((a_pVM)->CTX_SUFF(apCpus)[0])
62#endif
63
64/** @def VMCC_GET_CPU
65 * Gets the context specfic pointer to a virtual CPU by index (ID).
66 * @param a_pVM The context specfic VM structure.
67 * @param a_idCpu The CPU number to get (caller ensures validity).
68 */
69#ifdef IN_RING0
70# define VMCC_GET_CPU(a_pVM, a_idCpu) (&(a_pVM)->aCpus[(a_idCpu)])
71#else
72# define VMCC_GET_CPU(a_pVM, a_idCpu) ((a_pVM)->CTX_SUFF(apCpus)[(a_idCpu)])
73#endif
74
75/** @def VMCC_FOR_EACH_VMCPU
76 * For enumerating VCpus in ascending order, avoiding unnecessary apCpusR0
77 * access in ring-0, caching the CPU count and not checking for CPU \#0.
78 *
79 * Defines local variables @c idCpu, @c pVCpu and @c cCpus.
80 *
81 * @param a_pVM The VM handle.
82 *
83 * @note Close loop with VMCC_FOR_EACH_VMCPU_END.
84 */
85#define VMCC_FOR_EACH_VMCPU(a_pVM) \
86 do { \
87 VMCPUID idCpu = 0; \
88 VMCPUID const cCpus = (a_pVM)->cCpus; \
89 PVMCPUCC pVCpu = VMCC_GET_CPU_0(a_pVM); \
90 for (;;) \
91 {
92
93/** @def VMCC_FOR_EACH_VMCPU_END
94 * Ends a VMCC_FOR_EACH_VMCPU loop.
95 * @param a_pVM The VM handle.
96 */
97#define VMCC_FOR_EACH_VMCPU_END(a_pVM) \
98 /* advance */ \
99 if (++idCpu >= cCpus) \
100 break; \
101 pVCpu = VMCC_GET_CPU(pVM, idCpu); \
102 } \
103 } while (0)
104
105/**
106 * Execute the given statement for each virtual CPU in an environment with
107 * @c pVCpu and @c idCpu variables.
108 *
109 * @param a_pVM The VM handle.
110 * @param a_Stmt The statement to execute.
111 */
112#define VMCC_FOR_EACH_VMCPU_STMT(a_pVM, a_Stmt) VMCC_FOR_EACH_VMCPU(pVM) { a_Stmt; } VMCC_FOR_EACH_VMCPU_END(pVM)
113
114/** @def VMCC_GET_VMR0_FOR_CALL(pVM) */
115#if defined(IN_RING3)
116# define VMCC_GET_VMR0_FOR_CALL(a_pVM) ((a_pVM)->pVMR0ForCall)
117#elif defined(IN_RING3)
118# define VMCC_GET_VMR0_FOR_CALL(a_pVM) ((a_pVM)->pVMR0)
119#else
120# define VMCC_GET_VMR0_FOR_CALL(a_pVM) ((a_pVM)->ring3_only_macro)
121#endif
122
123
124#endif /* !VBOX_INCLUDED_vmm_vmcc_h */
125
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