VirtualBox

source: vbox/trunk/src/VBox/VMM/include/NEMInternal.h@ 97405

Last change on this file since 97405 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.4 KB
Line 
1/* $Id: NEMInternal.h 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * NEM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2018-2022 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 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef VMM_INCLUDED_SRC_include_NEMInternal_h
29#define VMM_INCLUDED_SRC_include_NEMInternal_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include <VBox/cdefs.h>
35#include <VBox/types.h>
36#include <VBox/vmm/nem.h>
37#include <VBox/vmm/cpum.h> /* For CPUMCPUVENDOR. */
38#include <VBox/vmm/stam.h>
39#include <VBox/vmm/vmapi.h>
40#ifdef RT_OS_WINDOWS
41#include <iprt/nt/hyperv.h>
42#include <iprt/critsect.h>
43#elif defined(RT_OS_DARWIN)
44# include "VMXInternal.h"
45#endif
46
47RT_C_DECLS_BEGIN
48
49
50/** @defgroup grp_nem_int Internal
51 * @ingroup grp_nem
52 * @internal
53 * @{
54 */
55
56#if defined(VBOX_WITH_NATIVE_NEM) && !defined(VBOX_WITH_PGM_NEM_MODE)
57# error "VBOX_WITH_NATIVE_NEM requires VBOX_WITH_PGM_NEM_MODE to be defined"
58#endif
59
60
61#ifdef RT_OS_WINDOWS
62/*
63 * Windows: Code configuration.
64 */
65/* nothing at the moment */
66
67/**
68 * Windows VID I/O control information.
69 */
70typedef struct NEMWINIOCTL
71{
72 /** The I/O control function number. */
73 uint32_t uFunction;
74 uint32_t cbInput;
75 uint32_t cbOutput;
76} NEMWINIOCTL;
77
78/** @name Windows: Our two-bit physical page state for PGMPAGE
79 * @{ */
80# define NEM_WIN_PAGE_STATE_NOT_SET 0
81# define NEM_WIN_PAGE_STATE_UNMAPPED 1
82# define NEM_WIN_PAGE_STATE_READABLE 2
83# define NEM_WIN_PAGE_STATE_WRITABLE 3
84/** @} */
85
86/** Windows: Checks if a_GCPhys is subject to the limited A20 gate emulation. */
87# define NEM_WIN_IS_SUBJECT_TO_A20(a_GCPhys) ((RTGCPHYS)((a_GCPhys) - _1M) < (RTGCPHYS)_64K)
88/** Windows: Checks if a_GCPhys is relevant to the limited A20 gate emulation. */
89# define NEM_WIN_IS_RELEVANT_TO_A20(a_GCPhys) \
90 ( ((RTGCPHYS)((a_GCPhys) - _1M) < (RTGCPHYS)_64K) || ((RTGCPHYS)(a_GCPhys) < (RTGCPHYS)_64K) )
91
92/** The CPUMCTX_EXTRN_XXX mask for IEM. */
93# define NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM ( IEM_CPUMCTX_EXTRN_MUST_MASK | CPUMCTX_EXTRN_INHIBIT_INT \
94 | CPUMCTX_EXTRN_INHIBIT_NMI )
95/** The CPUMCTX_EXTRN_XXX mask for IEM when raising exceptions. */
96# define NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM_XCPT (IEM_CPUMCTX_EXTRN_XCPT_MASK | NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM)
97
98/** @name Windows: Interrupt window flags (NEM_WIN_INTW_F_XXX).
99 * @{ */
100# define NEM_WIN_INTW_F_NMI UINT8_C(0x01)
101# define NEM_WIN_INTW_F_REGULAR UINT8_C(0x02)
102# define NEM_WIN_INTW_F_PRIO_MASK UINT8_C(0x3c)
103# define NEM_WIN_INTW_F_PRIO_SHIFT 2
104/** @} */
105
106#endif /* RT_OS_WINDOWS */
107
108
109#ifdef RT_OS_DARWIN
110/** vCPU ID declaration to avoid dragging in HV headers here. */
111typedef unsigned hv_vcpuid_t;
112/** The HV VM memory space ID (ASID). */
113typedef unsigned hv_vm_space_t;
114
115
116/** @name Darwin: Our two-bit physical page state for PGMPAGE
117 * @{ */
118# define NEM_DARWIN_PAGE_STATE_NOT_SET 0
119# define NEM_DARWIN_PAGE_STATE_UNMAPPED 1
120# define NEM_DARWIN_PAGE_STATE_READABLE 2
121# define NEM_DARWIN_PAGE_STATE_WRITABLE 3
122/** @} */
123
124/** The CPUMCTX_EXTRN_XXX mask for IEM. */
125# define NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM ( IEM_CPUMCTX_EXTRN_MUST_MASK | CPUMCTX_EXTRN_INHIBIT_INT \
126 | CPUMCTX_EXTRN_INHIBIT_NMI )
127/** The CPUMCTX_EXTRN_XXX mask for IEM when raising exceptions. */
128# define NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM_XCPT (IEM_CPUMCTX_EXTRN_XCPT_MASK | NEM_DARWIN_CPUMCTX_EXTRN_MASK_FOR_IEM)
129
130#endif
131
132
133/** Trick to make slickedit see the static functions in the template. */
134#ifndef IN_SLICKEDIT
135# define NEM_TMPL_STATIC static
136#else
137# define NEM_TMPL_STATIC
138#endif
139
140
141/**
142 * Generic NEM exit type enumeration for use with EMHistoryAddExit.
143 *
144 * On windows we've got two different set of exit types and they are both jumping
145 * around the place value wise, so EM can use their values.
146 *
147 * @note We only have exit types for exits not covered by EM here.
148 */
149typedef enum NEMEXITTYPE
150{
151 NEMEXITTYPE_INVALID = 0,
152
153 /* Common: */
154 NEMEXITTYPE_INTTERRUPT_WINDOW,
155 NEMEXITTYPE_HALT,
156
157 /* Windows: */
158 NEMEXITTYPE_UNRECOVERABLE_EXCEPTION,
159 NEMEXITTYPE_INVALID_VP_REGISTER_VALUE,
160 NEMEXITTYPE_XCPT_UD,
161 NEMEXITTYPE_XCPT_DB,
162 NEMEXITTYPE_XCPT_BP,
163 NEMEXITTYPE_CANCELED,
164 NEMEXITTYPE_MEMORY_ACCESS,
165
166 /* Linux: */
167 NEMEXITTYPE_INTERNAL_ERROR_EMULATION,
168 NEMEXITTYPE_INTERNAL_ERROR_FATAL,
169 NEMEXITTYPE_INTERRUPTED,
170 NEMEXITTYPE_FAILED_ENTRY,
171
172 /* End of valid types. */
173 NEMEXITTYPE_END
174} NEMEXITTYPE;
175
176
177/**
178 * NEM VM Instance data.
179 */
180typedef struct NEM
181{
182 /** NEM_MAGIC. */
183 uint32_t u32Magic;
184
185 /** Set if enabled. */
186 bool fEnabled;
187 /** Set if long mode guests are allowed. */
188 bool fAllow64BitGuests;
189 /** Set when the debug facility has breakpoints/events enabled that requires
190 * us to use the debug execution loop. */
191 bool fUseDebugLoop;
192
193#if defined(RT_OS_LINUX)
194 /** The '/dev/kvm' file descriptor. */
195 int32_t fdKvm;
196 /** The KVM_CREATE_VM file descriptor. */
197 int32_t fdVm;
198
199 /** KVM_GET_VCPU_MMAP_SIZE. */
200 uint32_t cbVCpuMmap;
201 /** KVM_CAP_NR_MEMSLOTS. */
202 uint32_t cMaxMemSlots;
203 /** KVM_CAP_X86_ROBUST_SINGLESTEP. */
204 bool fRobustSingleStep;
205
206 /** Hint where there might be a free slot. */
207 uint16_t idPrevSlot;
208 /** Memory slot ID allocation bitmap. */
209 uint64_t bmSlotIds[_32K / 8 / sizeof(uint64_t)];
210
211#elif defined(RT_OS_WINDOWS)
212 /** Set if we've created the EMTs. */
213 bool fCreatedEmts : 1;
214 /** WHvRunVpExitReasonX64Cpuid is supported. */
215 bool fExtendedMsrExit : 1;
216 /** WHvRunVpExitReasonX64MsrAccess is supported. */
217 bool fExtendedCpuIdExit : 1;
218 /** WHvRunVpExitReasonException is supported. */
219 bool fExtendedXcptExit : 1;
220# ifdef NEM_WIN_WITH_A20
221 /** Set if we've started more than one CPU and cannot mess with A20. */
222 bool fA20Fixed : 1;
223 /** Set if A20 is enabled. */
224 bool fA20Enabled : 1;
225# endif
226 /** The reported CPU vendor. */
227 CPUMCPUVENDOR enmCpuVendor;
228 /** Cache line flush size as a power of two. */
229 uint8_t cCacheLineFlushShift;
230 /** The result of WHvCapabilityCodeProcessorFeatures. */
231 union
232 {
233 /** 64-bit view. */
234 uint64_t u64;
235# ifdef _WINHVAPIDEFS_H_
236 /** Interpreed features. */
237 WHV_PROCESSOR_FEATURES u;
238# endif
239 } uCpuFeatures;
240
241 /** The partition handle. */
242# ifdef _WINHVAPIDEFS_H_
243 WHV_PARTITION_HANDLE
244# else
245 RTHCUINTPTR
246# endif
247 hPartition;
248 /** The device handle for the partition, for use with Vid APIs or direct I/O
249 * controls. */
250 RTR3PTR hPartitionDevice;
251
252 /** Number of currently mapped pages. */
253 uint32_t volatile cMappedPages;
254 uint32_t u32Padding;
255 STAMCOUNTER StatMapPage;
256 STAMCOUNTER StatUnmapPage;
257 STAMCOUNTER StatMapPageFailed;
258 STAMCOUNTER StatUnmapPageFailed;
259 STAMPROFILE StatProfMapGpaRange;
260 STAMPROFILE StatProfUnmapGpaRange;
261 STAMPROFILE StatProfMapGpaRangePage;
262 STAMPROFILE StatProfUnmapGpaRangePage;
263
264 /** Statistics updated by NEMR0UpdateStatistics. */
265 struct
266 {
267 uint64_t cPagesAvailable;
268 uint64_t cPagesInUse;
269 } R0Stats;
270
271#elif defined(RT_OS_DARWIN)
272 /** Set if we've created the EMTs. */
273 bool fCreatedEmts : 1;
274 /** Set if hv_vm_create() was called successfully. */
275 bool fCreatedVm : 1;
276 /** Set if hv_vm_space_create() was called successfully. */
277 bool fCreatedAsid : 1;
278 /** Set if Last Branch Record (LBR) is enabled. */
279 bool fLbr;
280 /** The ASID for this VM (only valid if fCreatedAsid is true). */
281 hv_vm_space_t uVmAsid;
282 /** Number of mach time units per NS, for hv_vcpu_run_until(). */
283 uint64_t cMachTimePerNs;
284 /** Pause-loop exiting (PLE) gap in ticks. */
285 uint32_t cPleGapTicks;
286 /** Pause-loop exiting (PLE) window in ticks. */
287 uint32_t cPleWindowTicks;
288
289 /** The host LBR TOS (top-of-stack) MSR id. */
290 uint32_t idLbrTosMsr;
291 /** The host LBR select MSR id. */
292 uint32_t idLbrSelectMsr;
293 /** The host last event record from IP MSR id. */
294 uint32_t idLerFromIpMsr;
295 /** The host last event record to IP MSR id. */
296 uint32_t idLerToIpMsr;
297
298 /** The first valid host LBR branch-from-IP stack range. */
299 uint32_t idLbrFromIpMsrFirst;
300 /** The last valid host LBR branch-from-IP stack range. */
301 uint32_t idLbrFromIpMsrLast;
302
303 /** The first valid host LBR branch-to-IP stack range. */
304 uint32_t idLbrToIpMsrFirst;
305 /** The last valid host LBR branch-to-IP stack range. */
306 uint32_t idLbrToIpMsrLast;
307
308 /** The first valid host LBR info stack range. */
309 uint32_t idLbrInfoMsrFirst;
310 /** The last valid host LBR info stack range. */
311 uint32_t idLbrInfoMsrLast;
312
313 STAMCOUNTER StatMapPage;
314 STAMCOUNTER StatUnmapPage;
315 STAMCOUNTER StatMapPageFailed;
316 STAMCOUNTER StatUnmapPageFailed;
317#endif /* RT_OS_WINDOWS */
318} NEM;
319/** Pointer to NEM VM instance data. */
320typedef NEM *PNEM;
321
322/** NEM::u32Magic value. */
323#define NEM_MAGIC UINT32_C(0x004d454e)
324/** NEM::u32Magic value after termination. */
325#define NEM_MAGIC_DEAD UINT32_C(0xdead1111)
326
327
328/**
329 * NEM VMCPU Instance data.
330 */
331typedef struct NEMCPU
332{
333 /** NEMCPU_MAGIC. */
334 uint32_t u32Magic;
335 /** Whether \#UD needs to be intercepted and presented to GIM. */
336 bool fGIMTrapXcptUD : 1;
337 /** Whether \#GP needs to be intercept for mesa driver workaround. */
338 bool fTrapXcptGpForLovelyMesaDrv: 1;
339 /** Whether we should use the debug loop because of single stepping or special
340 * debug breakpoints / events are armed. */
341 bool fUseDebugLoop : 1;
342 /** Whether we're executing a single instruction. */
343 bool fSingleInstruction : 1;
344 /** Set if we using the debug loop and wish to intercept RDTSC. */
345 bool fDebugWantRdTscExit : 1;
346 /** Whether we are currently executing in the debug loop.
347 * Mainly for assertions. */
348 bool fUsingDebugLoop : 1;
349 /** Set if we need to clear the trap flag because of single stepping. */
350 bool fClearTrapFlag : 1;
351 /** Whether we're using the hyper DR7 or guest DR7. */
352 bool fUsingHyperDR7 : 1;
353 /** Whether \#DE needs to be intercepted for GIM. */
354 bool fGCMTrapXcptDE : 1;
355
356#if defined(RT_OS_LINUX)
357 uint8_t abPadding[3];
358 /** The KVM VCpu file descriptor. */
359 int32_t fdVCpu;
360 /** Pointer to the KVM_RUN data exchange region. */
361 R3PTRTYPE(struct kvm_run *) pRun;
362 /** The MSR_IA32_APICBASE value known to KVM. */
363 uint64_t uKvmApicBase;
364
365 /** @name Statistics
366 * @{ */
367 STAMCOUNTER StatExitTotal;
368 STAMCOUNTER StatExitIo;
369 STAMCOUNTER StatExitMmio;
370 STAMCOUNTER StatExitSetTpr;
371 STAMCOUNTER StatExitTprAccess;
372 STAMCOUNTER StatExitRdMsr;
373 STAMCOUNTER StatExitWrMsr;
374 STAMCOUNTER StatExitIrqWindowOpen;
375 STAMCOUNTER StatExitHalt;
376 STAMCOUNTER StatExitIntr;
377 STAMCOUNTER StatExitHypercall;
378 STAMCOUNTER StatExitDebug;
379 STAMCOUNTER StatExitBusLock;
380 STAMCOUNTER StatExitInternalErrorEmulation;
381 STAMCOUNTER StatExitInternalErrorFatal;
382# if 0
383 STAMCOUNTER StatExitCpuId;
384 STAMCOUNTER StatExitUnrecoverable;
385 STAMCOUNTER StatGetMsgTimeout;
386 STAMCOUNTER StatStopCpuSuccess;
387 STAMCOUNTER StatStopCpuPending;
388 STAMCOUNTER StatStopCpuPendingAlerts;
389 STAMCOUNTER StatStopCpuPendingOdd;
390 STAMCOUNTER StatCancelChangedState;
391 STAMCOUNTER StatCancelAlertedThread;
392# endif
393 STAMCOUNTER StatBreakOnCancel;
394 STAMCOUNTER StatBreakOnFFPre;
395 STAMCOUNTER StatBreakOnFFPost;
396 STAMCOUNTER StatBreakOnStatus;
397 STAMCOUNTER StatFlushExitOnReturn;
398 STAMCOUNTER StatFlushExitOnReturn1Loop;
399 STAMCOUNTER StatFlushExitOnReturn2Loops;
400 STAMCOUNTER StatFlushExitOnReturn3Loops;
401 STAMCOUNTER StatFlushExitOnReturn4PlusLoops;
402 STAMCOUNTER StatImportOnDemand;
403 STAMCOUNTER StatImportOnReturn;
404 STAMCOUNTER StatImportOnReturnSkipped;
405 STAMCOUNTER StatImportPendingInterrupt;
406 STAMCOUNTER StatExportPendingInterrupt;
407 STAMCOUNTER StatQueryCpuTick;
408 /** @} */
409
410
411#elif defined(RT_OS_WINDOWS)
412 /** The current state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
413 uint8_t fCurrentInterruptWindows;
414 /** The desired state of the interrupt windows (NEM_WIN_INTW_F_XXX). */
415 uint8_t fDesiredInterruptWindows;
416 /** Last copy of HV_X64_VP_EXECUTION_STATE::InterruptShadow. */
417 bool fLastInterruptShadow : 1;
418 uint32_t uPadding;
419 /** The VID_MSHAGN_F_XXX flags.
420 * Either VID_MSHAGN_F_HANDLE_MESSAGE | VID_MSHAGN_F_GET_NEXT_MESSAGE or zero. */
421 uint32_t fHandleAndGetFlags;
422 /** What VidMessageSlotMap returns and is used for passing exit info. */
423 RTR3PTR pvMsgSlotMapping;
424 /** The windows thread handle. */
425 RTR3PTR hNativeThreadHandle;
426
427 /** @name Statistics
428 * @{ */
429 STAMCOUNTER StatExitPortIo;
430 STAMCOUNTER StatExitMemUnmapped;
431 STAMCOUNTER StatExitMemIntercept;
432 STAMCOUNTER StatExitHalt;
433 STAMCOUNTER StatExitInterruptWindow;
434 STAMCOUNTER StatExitCpuId;
435 STAMCOUNTER StatExitMsr;
436 STAMCOUNTER StatExitException;
437 STAMCOUNTER StatExitExceptionBp;
438 STAMCOUNTER StatExitExceptionDb;
439 STAMCOUNTER StatExitExceptionGp;
440 STAMCOUNTER StatExitExceptionGpMesa;
441 STAMCOUNTER StatExitExceptionUd;
442 STAMCOUNTER StatExitExceptionUdHandled;
443 STAMCOUNTER StatExitUnrecoverable;
444 STAMCOUNTER StatGetMsgTimeout;
445 STAMCOUNTER StatStopCpuSuccess;
446 STAMCOUNTER StatStopCpuPending;
447 STAMCOUNTER StatStopCpuPendingAlerts;
448 STAMCOUNTER StatStopCpuPendingOdd;
449 STAMCOUNTER StatCancelChangedState;
450 STAMCOUNTER StatCancelAlertedThread;
451 STAMCOUNTER StatBreakOnCancel;
452 STAMCOUNTER StatBreakOnFFPre;
453 STAMCOUNTER StatBreakOnFFPost;
454 STAMCOUNTER StatBreakOnStatus;
455 STAMCOUNTER StatImportOnDemand;
456 STAMCOUNTER StatImportOnReturn;
457 STAMCOUNTER StatImportOnReturnSkipped;
458 STAMCOUNTER StatQueryCpuTick;
459 /** @} */
460
461#elif defined(RT_OS_DARWIN)
462 /** The vCPU handle associated with the EMT executing this vCPU. */
463 hv_vcpuid_t hVCpuId;
464
465 /** @name State shared with the VT-x code.
466 * @{ */
467 /** An additional error code used for some gurus. */
468 uint32_t u32HMError;
469 /** The last exit-to-ring-3 reason. */
470 int32_t rcLastExitToR3;
471 /** CPU-context changed flags (see HM_CHANGED_xxx). */
472 uint64_t fCtxChanged;
473
474 /** The guest VMCS information. */
475 VMXVMCSINFO VmcsInfo;
476
477 /** VT-x data. */
478 struct HMCPUVMX
479 {
480 /** @name Guest information.
481 * @{ */
482 /** Guest VMCS information shared with ring-3. */
483 VMXVMCSINFOSHARED VmcsInfo;
484 /** Nested-guest VMCS information shared with ring-3. */
485 VMXVMCSINFOSHARED VmcsInfoNstGst;
486 /** Whether the nested-guest VMCS was the last current VMCS (shadow copy for ring-3).
487 * @see HMR0PERVCPU::vmx.fSwitchedToNstGstVmcs */
488 bool fSwitchedToNstGstVmcsCopyForRing3;
489 /** Whether the static guest VMCS controls has been merged with the
490 * nested-guest VMCS controls. */
491 bool fMergedNstGstCtls;
492 /** Whether the nested-guest VMCS has been copied to the shadow VMCS. */
493 bool fCopiedNstGstToShadowVmcs;
494 /** Whether flushing the TLB is required due to switching to/from the
495 * nested-guest. */
496 bool fSwitchedNstGstFlushTlb;
497 /** Alignment. */
498 bool afAlignment0[4];
499 /** Cached guest APIC-base MSR for identifying when to map the APIC-access page. */
500 uint64_t u64GstMsrApicBase;
501 /** @} */
502
503 /** @name Error reporting and diagnostics.
504 * @{ */
505 /** VT-x error-reporting (mainly for ring-3 propagation). */
506 struct
507 {
508 RTCPUID idCurrentCpu;
509 RTCPUID idEnteredCpu;
510 RTHCPHYS HCPhysCurrentVmcs;
511 uint32_t u32VmcsRev;
512 uint32_t u32InstrError;
513 uint32_t u32ExitReason;
514 uint32_t u32GuestIntrState;
515 } LastError;
516 /** @} */
517 } vmx;
518
519 /** Event injection state. */
520 HMEVENT Event;
521
522 /** Current shadow paging mode for updating CR4.
523 * @todo move later (@bugref{9217}). */
524 PGMMODE enmShadowMode;
525 uint32_t u32TemporaryPadding;
526
527 /** The PAE PDPEs used with Nested Paging (only valid when
528 * VMCPU_FF_HM_UPDATE_PAE_PDPES is set). */
529 X86PDPE aPdpes[4];
530 /** Pointer to the VMX statistics. */
531 PVMXSTATISTICS pVmxStats;
532
533 /** @name Statistics
534 * @{ */
535 STAMCOUNTER StatExitAll;
536 STAMCOUNTER StatBreakOnCancel;
537 STAMCOUNTER StatBreakOnFFPre;
538 STAMCOUNTER StatBreakOnFFPost;
539 STAMCOUNTER StatBreakOnStatus;
540 STAMCOUNTER StatImportOnDemand;
541 STAMCOUNTER StatImportOnReturn;
542 STAMCOUNTER StatImportOnReturnSkipped;
543 STAMCOUNTER StatQueryCpuTick;
544#ifdef VBOX_WITH_STATISTICS
545 STAMPROFILEADV StatProfGstStateImport;
546 STAMPROFILEADV StatProfGstStateExport;
547#endif
548 /** @} */
549
550 /** @} */
551#endif /* RT_OS_DARWIN */
552} NEMCPU;
553/** Pointer to NEM VMCPU instance data. */
554typedef NEMCPU *PNEMCPU;
555
556/** NEMCPU::u32Magic value. */
557#define NEMCPU_MAGIC UINT32_C(0x4d454e20)
558/** NEMCPU::u32Magic value after termination. */
559#define NEMCPU_MAGIC_DEAD UINT32_C(0xdead2222)
560
561
562#ifdef IN_RING0
563# ifdef RT_OS_WINDOWS
564/**
565 * Windows: Hypercall input/ouput page info.
566 */
567typedef struct NEMR0HYPERCALLDATA
568{
569 /** Host physical address of the hypercall input/output page. */
570 RTHCPHYS HCPhysPage;
571 /** Pointer to the hypercall input/output page. */
572 uint8_t *pbPage;
573 /** Handle to the memory object of the hypercall input/output page. */
574 RTR0MEMOBJ hMemObj;
575} NEMR0HYPERCALLDATA;
576/** Pointer to a Windows hypercall input/output page info. */
577typedef NEMR0HYPERCALLDATA *PNEMR0HYPERCALLDATA;
578# endif /* RT_OS_WINDOWS */
579
580/**
581 * NEM GVMCPU instance data.
582 */
583typedef struct NEMR0PERVCPU
584{
585 uint32_t uDummy;
586} NEMR0PERVCPU;
587
588/**
589 * NEM GVM instance data.
590 */
591typedef struct NEMR0PERVM
592{
593 uint32_t uDummy;
594} NEMR0PERVM;
595
596#endif /* IN_RING*/
597
598
599#ifdef IN_RING3
600int nemR3NativeInit(PVM pVM, bool fFallback, bool fForced);
601int nemR3NativeInitAfterCPUM(PVM pVM);
602int nemR3NativeInitCompleted(PVM pVM, VMINITCOMPLETED enmWhat);
603int nemR3NativeTerm(PVM pVM);
604void nemR3NativeReset(PVM pVM);
605void nemR3NativeResetCpu(PVMCPU pVCpu, bool fInitIpi);
606VBOXSTRICTRC nemR3NativeRunGC(PVM pVM, PVMCPU pVCpu);
607bool nemR3NativeCanExecuteGuest(PVM pVM, PVMCPU pVCpu);
608bool nemR3NativeSetSingleInstruction(PVM pVM, PVMCPU pVCpu, bool fEnable);
609
610/**
611 * Forced flag notification call from VMEmt.h.
612 *
613 * This is only called when pVCpu is in the VMCPUSTATE_STARTED_EXEC_NEM state.
614 *
615 * @param pVM The cross context VM structure.
616 * @param pVCpu The cross context virtual CPU structure of the CPU
617 * to be notified.
618 * @param fFlags Notification flags, VMNOTIFYFF_FLAGS_XXX.
619 */
620void nemR3NativeNotifyFF(PVM pVM, PVMCPU pVCpu, uint32_t fFlags);
621
622/**
623 * Called by NEMR3NotifyDebugEventChanged() to let the native backend take the final decision
624 * on whether to switch to the debug loop.
625 *
626 * @returns Final flag whether to switch to the debug loop.
627 * @param pVM The VM cross context VM structure.
628 * @param fUseDebugLoop The current value determined by NEMR3NotifyDebugEventChanged().
629 * @thread EMT(0)
630 */
631DECLHIDDEN(bool) nemR3NativeNotifyDebugEventChanged(PVM pVM, bool fUseDebugLoop);
632
633
634/**
635 * Called by NEMR3NotifyDebugEventChangedPerCpu() to let the native backend take the final decision
636 * on whether to switch to the debug loop.
637 *
638 * @returns Final flag whether to switch to the debug loop.
639 * @param pVM The VM cross context VM structure.
640 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
641 * @param fUseDebugLoop The current value determined by NEMR3NotifyDebugEventChangedPerCpu().
642 */
643DECLHIDDEN(bool) nemR3NativeNotifyDebugEventChangedPerCpu(PVM pVM, PVMCPU pVCpu, bool fUseDebugLoop);
644#endif
645
646void nemHCNativeNotifyHandlerPhysicalRegister(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhys, RTGCPHYS cb);
647void nemHCNativeNotifyHandlerPhysicalModify(PVMCC pVM, PGMPHYSHANDLERKIND enmKind, RTGCPHYS GCPhysOld,
648 RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fRestoreAsRAM);
649int nemHCNativeNotifyPhysPageAllocated(PVMCC pVM, RTGCPHYS GCPhys, RTHCPHYS HCPhys, uint32_t fPageProt,
650 PGMPAGETYPE enmType, uint8_t *pu2State);
651
652
653#ifdef RT_OS_WINDOWS
654/** Maximum number of pages we can map in a single NEMR0MapPages call. */
655# define NEM_MAX_MAP_PAGES ((HOST_PAGE_SIZE - RT_UOFFSETOF(HV_INPUT_MAP_GPA_PAGES, PageList)) / sizeof(HV_SPA_PAGE_NUMBER))
656/** Maximum number of pages we can unmap in a single NEMR0UnmapPages call. */
657# define NEM_MAX_UNMAP_PAGES 4095
658
659#endif
660/** @} */
661
662RT_C_DECLS_END
663
664#endif /* !VMM_INCLUDED_SRC_include_NEMInternal_h */
665
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