VirtualBox

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

Last change on this file since 94991 was 94884, checked in by vboxsync, 3 years ago

Attempting to fix Darwin NEM.

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