VirtualBox

source: vbox/trunk/src/VBox/VMM/include/PATMA.h@ 77481

Last change on this file since 77481 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 9.9 KB
Line 
1/* $Id: PATMA.h 76585 2019-01-01 06:31:29Z vboxsync $ */
2/** @file
3 * PATM macros & definitions (identical to PATMA.mac!).
4 */
5
6/*
7 * Copyright (C) 2006-2019 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_PATMA_h
19#define VMM_INCLUDED_SRC_include_PATMA_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/** @name Patch Fixup Types
25 * @remarks These fixups types are part of the saved state.
26 * @{ */
27#define PATM_ASMFIX_VMFLAGS 0xF1ABCD00
28#ifdef VBOX_WITH_STATISTICS
29# define PATM_ASMFIX_ALLPATCHCALLS 0xF1ABCD01
30# define PATM_ASMFIX_PERPATCHCALLS 0xF1ABCD02
31#endif
32#define PATM_ASMFIX_JUMPDELTA 0xF1ABCD03
33#ifdef VBOX_WITH_STATISTICS
34# define PATM_ASMFIX_IRETEFLAGS 0xF1ABCD04
35# define PATM_ASMFIX_IRETCS 0xF1ABCD05
36# define PATM_ASMFIX_IRETEIP 0xF1ABCD06
37#endif
38#define PATM_ASMFIX_FIXUP 0xF1ABCD07
39#define PATM_ASMFIX_PENDINGACTION 0xF1ABCD08
40#define PATM_ASMFIX_CPUID_STD_PTR 0xF1ABCD09 /**< Legacy, saved state only. */
41#define PATM_ASMFIX_CPUID_EXT_PTR 0xF1ABCD0a /**< Legacy, saved state only. */
42#define PATM_ASMFIX_CPUID_DEF_PTR 0xF1ABCD0b /**< Legacy, saved state only. */
43#define PATM_ASMFIX_STACKBASE 0xF1ABCD0c /**< Stack to store our private patch return addresses */
44#define PATM_ASMFIX_STACKBASE_GUEST 0xF1ABCD0d /**< Stack to store guest return addresses */
45#define PATM_ASMFIX_STACKPTR 0xF1ABCD0e
46#define PATM_ASMFIX_PATCHBASE 0xF1ABCD0f
47#define PATM_ASMFIX_INTERRUPTFLAG 0xF1ABCD10
48#define PATM_ASMFIX_INHIBITIRQADDR 0xF1ABCD11
49#define PATM_ASMFIX_VM_FORCEDACTIONS 0xF1ABCD12
50#define PATM_ASMFIX_TEMP_EAX 0xF1ABCD13 /**< Location for original EAX register */
51#define PATM_ASMFIX_TEMP_ECX 0xF1ABCD14 /**< Location for original ECX register */
52#define PATM_ASMFIX_TEMP_EDI 0xF1ABCD15 /**< Location for original EDI register */
53#define PATM_ASMFIX_TEMP_EFLAGS 0xF1ABCD16 /**< Location for original eflags */
54#define PATM_ASMFIX_TEMP_RESTORE_FLAGS 0xF1ABCD17 /**< Which registers to restore */
55#define PATM_ASMFIX_CALL_PATCH_TARGET_ADDR 0xF1ABCD18
56#define PATM_ASMFIX_CALL_RETURN_ADDR 0xF1ABCD19
57#define PATM_ASMFIX_CPUID_CENTAUR_PTR 0xF1ABCD1a /**< Legacy, saved state only. */
58#define PATM_ASMFIX_REUSE_LATER_0 0xF1ABCD1b
59#define PATM_ASMFIX_REUSE_LATER_1 0xF1ABCD1c
60#define PATM_ASMFIX_REUSE_LATER_2 0xF1ABCD1d
61#define PATM_ASMFIX_REUSE_LATER_3 0xF1ABCD1e
62#define PATM_ASMFIX_HELPER_CPUM_CPUID 0xF1ABCD1f
63
64/* Anything larger doesn't require a fixup */
65#define PATM_ASMFIX_NO_FIXUP 0xF1ABCE00
66#define PATM_ASMFIX_CPUID_STD_MAX 0xF1ABCE00
67#define PATM_ASMFIX_CPUID_EXT_MAX 0xF1ABCE01
68#define PATM_ASMFIX_RETURNADDR 0xF1ABCE02
69#define PATM_ASMFIX_PATCHNEXTBLOCK 0xF1ABCE03
70#define PATM_ASMFIX_CALLTARGET 0xF1ABCE04 /**< relative call target */
71#define PATM_ASMFIX_NEXTINSTRADDR 0xF1ABCE05 /**< absolute guest address of the next instruction */
72#define PATM_ASMFIX_CURINSTRADDR 0xF1ABCE06 /**< absolute guest address of the current instruction */
73#define PATM_ASMFIX_LOOKUP_AND_CALL_FUNCTION 0xF1ABCE07 /**< Relative address of global PATM lookup and call function. */
74#define PATM_ASMFIX_RETURN_FUNCTION 0xF1ABCE08 /**< Relative address of global PATM return function. */
75#define PATM_ASMFIX_LOOKUP_AND_JUMP_FUNCTION 0xF1ABCE09 /**< Relative address of global PATM lookup and jump function. */
76#define PATM_ASMFIX_IRET_FUNCTION 0xF1ABCE0A /**< Relative address of global PATM iret function. */
77#define PATM_ASMFIX_CPUID_CENTAUR_MAX 0xF1ABCE0B
78
79/** Identifies an patch fixup type value (with reasonable accuracy). */
80#define PATM_IS_ASMFIX(a_uValue) \
81 ( ((a_uValue) & UINT32_C(0xfffffC00)) == UINT32_C(0xF1ABCC00) && ((a_uValue) & UINT32_C(0xff)) < UINT32_C(0x30) )
82/** @} */
83
84
85/** Everything except IOPL, NT, IF, VM, VIF, VIP and RF */
86#define PATM_FLAGS_MASK ( X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF \
87 | X86_EFL_TF | X86_EFL_DF | X86_EFL_OF | X86_EFL_AC | X86_EFL_ID)
88
89/** Flags that PATM virtualizes. Currently only IF & IOPL. */
90#define PATM_VIRTUAL_FLAGS_MASK (X86_EFL_IF | X86_EFL_IOPL)
91
92/* PATM stack size (identical in PATMA.mac!!) */
93#define PATM_STACK_SIZE (4096)
94#define PATM_STACK_TOTAL_SIZE (2 * PATM_STACK_SIZE)
95#define PATM_MAX_STACK (PATM_STACK_SIZE/sizeof(RTRCPTR))
96
97/** @name Patch Manager pending actions (in GCSTATE).
98 * @{ */
99#define PATM_ACTION_LOOKUP_ADDRESS 1
100#define PATM_ACTION_DISPATCH_PENDING_IRQ 2
101#define PATM_ACTION_PENDING_IRQ_AFTER_IRET 3
102#define PATM_ACTION_DO_V86_IRET 4
103#define PATM_ACTION_LOG_IF1 5
104#define PATM_ACTION_LOG_CLI 6
105#define PATM_ACTION_LOG_STI 7
106#define PATM_ACTION_LOG_POPF_IF1 8
107#define PATM_ACTION_LOG_POPF_IF0 9
108#define PATM_ACTION_LOG_PUSHF 10
109#define PATM_ACTION_LOG_IRET 11
110#define PATM_ACTION_LOG_RET 12
111#define PATM_ACTION_LOG_CALL 13
112#define PATM_ACTION_LOG_GATE_ENTRY 14
113/** @} */
114
115/** Magic dword found in ecx for patm pending actions. */
116#define PATM_ACTION_MAGIC 0xABCD4321
117
118/** @name PATM_ASMFIX_TEMP_RESTORE_FLAGS
119 * @{ */
120#define PATM_RESTORE_EAX RT_BIT(0)
121#define PATM_RESTORE_ECX RT_BIT(1)
122#define PATM_RESTORE_EDI RT_BIT(2)
123/** @} */
124
125/** Relocation entry for PATCHASMRECORD. */
126typedef struct PATCHASMRELOC
127{
128 /** The relocation type. */
129 uint32_t uType;
130 /** Additional information specific to the relocation type. */
131 uint32_t uInfo;
132} PATCHASMRELOC;
133typedef PATCHASMRELOC const *PCPATCHASMRELOC;
134
135/**
136 * Assembly patch descriptor record.
137 */
138typedef struct
139{
140 /** Pointer to the patch code. */
141 uint8_t *pbFunction;
142 /** Offset of the jump table? */
143 uint32_t offJump;
144 /** Used only by loop/loopz/loopnz. */
145 uint32_t offRelJump;
146 /** Size override byte position. */
147 uint32_t offSizeOverride;
148 /** The size of the patch function. */
149 uint32_t cbFunction;
150 /** The number of relocations in aRelocs. */
151 uint32_t cRelocs;
152 /** Variable sized relocation table. */
153 PATCHASMRELOC aRelocs[1];
154} PATCHASMRECORD;
155/** Pointer to a const patch descriptor record. */
156typedef PATCHASMRECORD const *PCPATCHASMRECORD;
157
158
159/* For indirect calls/jump (identical in PATMA.h & PATMA.mac!) */
160/** @note MUST BE A POWER OF TWO! */
161/** @note direct calls have only one lookup slot (PATCHDIRECTJUMPTABLE_SIZE) */
162/** @note Some statistics reveal that:
163 * - call: Windows XP boot -> max 16, 127 replacements
164 * - call: Knoppix 3.7 boot -> max 9
165 * - ret: Knoppix 5.0.1 boot -> max 16, 80000 replacements (3+ million hits)
166 */
167#define PATM_MAX_JUMPTABLE_ENTRIES 16
168typedef struct
169{
170 uint16_t nrSlots;
171 uint16_t ulInsertPos;
172 uint32_t cAddresses;
173 struct
174 {
175 RTRCPTR pInstrGC;
176 RTRCUINTPTR pRelPatchGC; /* relative to patch base */
177 } Slot[1];
178} PATCHJUMPTABLE, *PPATCHJUMPTABLE;
179
180
181RT_C_DECLS_BEGIN
182
183/** @name Patch Descriptor Records (in PATMA.asm)
184 * @{ */
185extern PATCHASMRECORD g_patmCliRecord;
186extern PATCHASMRECORD g_patmStiRecord;
187extern PATCHASMRECORD g_patmPopf32Record;
188extern PATCHASMRECORD g_patmPopf16Record;
189extern PATCHASMRECORD g_patmPopf16Record_NoExit;
190extern PATCHASMRECORD g_patmPopf32Record_NoExit;
191extern PATCHASMRECORD g_patmPushf32Record;
192extern PATCHASMRECORD g_patmPushf16Record;
193extern PATCHASMRECORD g_patmIretRecord;
194extern PATCHASMRECORD g_patmIretRing1Record;
195extern PATCHASMRECORD g_patmCpuidRecord;
196extern PATCHASMRECORD g_patmLoopRecord;
197extern PATCHASMRECORD g_patmLoopZRecord;
198extern PATCHASMRECORD g_patmLoopNZRecord;
199extern PATCHASMRECORD g_patmJEcxRecord;
200extern PATCHASMRECORD g_patmIntEntryRecord;
201extern PATCHASMRECORD g_patmIntEntryRecordErrorCode;
202extern PATCHASMRECORD g_patmTrapEntryRecord;
203extern PATCHASMRECORD g_patmTrapEntryRecordErrorCode;
204extern PATCHASMRECORD g_patmPushCSRecord;
205
206extern PATCHASMRECORD g_patmCheckIFRecord;
207extern PATCHASMRECORD PATMJumpToGuest_IF1Record;
208
209extern PATCHASMRECORD g_patmCallRecord;
210extern PATCHASMRECORD g_patmCallIndirectRecord;
211extern PATCHASMRECORD g_patmRetRecord;
212extern PATCHASMRECORD g_patmJumpIndirectRecord;
213
214extern PATCHASMRECORD g_patmLookupAndCallRecord;
215extern PATCHASMRECORD g_patmRetFunctionRecord;
216extern PATCHASMRECORD g_patmLookupAndJumpRecord;
217extern PATCHASMRECORD g_patmIretFunctionRecord;
218
219extern PATCHASMRECORD g_patmStatsRecord;
220
221extern PATCHASMRECORD g_patmSetPIFRecord;
222extern PATCHASMRECORD g_patmClearPIFRecord;
223
224extern PATCHASMRECORD g_patmSetInhibitIRQRecord;
225extern PATCHASMRECORD g_patmClearInhibitIRQFaultIF0Record;
226extern PATCHASMRECORD g_patmClearInhibitIRQContIF0Record;
227
228extern PATCHASMRECORD g_patmMovFromSSRecord;
229/** @} */
230
231extern const uint32_t g_fPatmInterruptFlag;
232
233RT_C_DECLS_END
234
235#endif /* !VMM_INCLUDED_SRC_include_PATMA_h */
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