VirtualBox

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

Last change on this file since 54686 was 54686, checked in by vboxsync, 10 years ago

PATM: Added some comments and formalized the reloc array type (instead of having two anonymous uint32_t's).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.9 KB
Line 
1/* $Id: PATMA.h 54686 2015-03-08 20:51:01Z vboxsync $ */
2/** @file
3 * PATM macros & definitions (identical to PATMA.mac!).
4 */
5
6/*
7 * Copyright (C) 2006-2015 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 ___PATMA_H
19#define ___PATMA_H
20
21/** @name Patch Fixup Types
22 * @{ */
23#define PATM_VMFLAGS 0xF1ABCD00
24#ifdef VBOX_WITH_STATISTICS
25# define PATM_ALLPATCHCALLS 0xF1ABCD01
26# define PATM_PERPATCHCALLS 0xF1ABCD02
27#endif
28#define PATM_JUMPDELTA 0xF1ABCD03
29#ifdef VBOX_WITH_STATISTICS
30# define PATM_IRETEFLAGS 0xF1ABCD04
31# define PATM_IRETCS 0xF1ABCD05
32# define PATM_IRETEIP 0xF1ABCD06
33#endif
34#define PATM_FIXUP 0xF1ABCD07
35#define PATM_PENDINGACTION 0xF1ABCD08
36#define PATM_CPUID_STD_PTR 0xF1ABCD09
37#define PATM_CPUID_EXT_PTR 0xF1ABCD0a
38#define PATM_CPUID_DEF_PTR 0xF1ABCD0b
39#define PATM_STACKBASE 0xF1ABCD0c /**< Stack to store our private patch return addresses */
40#define PATM_STACKBASE_GUEST 0xF1ABCD0d /**< Stack to store guest return addresses */
41#define PATM_STACKPTR 0xF1ABCD0e
42#define PATM_PATCHBASE 0xF1ABCD0f
43#define PATM_INTERRUPTFLAG 0xF1ABCD10
44#define PATM_INHIBITIRQADDR 0xF1ABCD11
45#define PATM_VM_FORCEDACTIONS 0xF1ABCD12
46#define PATM_TEMP_EAX 0xF1ABCD13 /**< Location for original EAX register */
47#define PATM_TEMP_ECX 0xF1ABCD14 /**< Location for original ECX register */
48#define PATM_TEMP_EDI 0xF1ABCD15 /**< Location for original EDI register */
49#define PATM_TEMP_EFLAGS 0xF1ABCD16 /**< Location for original eflags */
50#define PATM_TEMP_RESTORE_FLAGS 0xF1ABCD17 /**< Which registers to restore */
51#define PATM_CALL_PATCH_TARGET_ADDR 0xF1ABCD18
52#define PATM_CALL_RETURN_ADDR 0xF1ABCD19
53#define PATM_CPUID_CENTAUR_PTR 0xF1ABCD1a
54
55/* Anything larger doesn't require a fixup */
56#define PATM_NO_FIXUP 0xF1ABCE00
57#define PATM_CPUID_STD_MAX 0xF1ABCE00
58#define PATM_CPUID_EXT_MAX 0xF1ABCE01
59#define PATM_RETURNADDR 0xF1ABCE02
60#define PATM_PATCHNEXTBLOCK 0xF1ABCE03
61#define PATM_CALLTARGET 0xF1ABCE04 /**< relative call target */
62#define PATM_NEXTINSTRADDR 0xF1ABCE05 /**< absolute guest address of the next instruction */
63#define PATM_CURINSTRADDR 0xF1ABCE06 /**< absolute guest address of the current instruction */
64#define PATM_LOOKUP_AND_CALL_FUNCTION 0xF1ABCE07 /**< Relative address of global PATM lookup and call function. */
65#define PATM_RETURN_FUNCTION 0xF1ABCE08 /**< Relative address of global PATM return function. */
66#define PATM_LOOKUP_AND_JUMP_FUNCTION 0xF1ABCE09 /**< Relative address of global PATM lookup and jump function. */
67#define PATM_IRET_FUNCTION 0xF1ABCE0A /**< Relative address of global PATM iret function. */
68#define PATM_CPUID_CENTAUR_MAX 0xF1ABCE0B
69/** @} */
70
71
72/** Everything except IOPL, NT, IF, VM, VIF, VIP and RF */
73#define PATM_FLAGS_MASK ( X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF \
74 | X86_EFL_TF | X86_EFL_DF | X86_EFL_OF | X86_EFL_AC | X86_EFL_ID)
75
76/** Flags that PATM virtualizes. Currently only IF & IOPL. */
77#define PATM_VIRTUAL_FLAGS_MASK (X86_EFL_IF | X86_EFL_IOPL)
78
79/* PATM stack size (identical in PATMA.mac!!) */
80#define PATM_STACK_SIZE (4096)
81#define PATM_STACK_TOTAL_SIZE (2 * PATM_STACK_SIZE)
82#define PATM_MAX_STACK (PATM_STACK_SIZE/sizeof(RTRCPTR))
83
84/** @name Patch Manager pending actions (in GCSTATE).
85 * @{ */
86#define PATM_ACTION_LOOKUP_ADDRESS 1
87#define PATM_ACTION_DISPATCH_PENDING_IRQ 2
88#define PATM_ACTION_PENDING_IRQ_AFTER_IRET 3
89#define PATM_ACTION_DO_V86_IRET 4
90#define PATM_ACTION_LOG_IF1 5
91#define PATM_ACTION_LOG_CLI 6
92#define PATM_ACTION_LOG_STI 7
93#define PATM_ACTION_LOG_POPF_IF1 8
94#define PATM_ACTION_LOG_POPF_IF0 9
95#define PATM_ACTION_LOG_PUSHF 10
96#define PATM_ACTION_LOG_IRET 11
97#define PATM_ACTION_LOG_RET 12
98#define PATM_ACTION_LOG_CALL 13
99#define PATM_ACTION_LOG_GATE_ENTRY 14
100/** @} */
101
102/** Magic dword found in ecx for patm pending actions. */
103#define PATM_ACTION_MAGIC 0xABCD4321
104
105/** @name PATM_TEMP_RESTORE_FLAGS
106 * @{ */
107#define PATM_RESTORE_EAX RT_BIT(0)
108#define PATM_RESTORE_ECX RT_BIT(1)
109#define PATM_RESTORE_EDI RT_BIT(2)
110/** @} */
111
112/** Relocation entry for PATCHASMRECORD. */
113typedef struct PATCHASMRELOC
114{
115 /** The relocation type. */
116 uint32_t uType;
117 /** Additional information specific to the relocation type. */
118 uint32_t uInfo;
119} PATCHASMRELOC;
120typedef PATCHASMRELOC const *PCPATCHASMRELOC;
121
122/**
123 * Assembly patch descriptor record.
124 */
125typedef struct
126{
127 /** Pointer to the patch code. */
128 uint8_t *pbFunction;
129 /** Offset of the jump table? */
130 uint32_t offJump;
131 /** Used only by loop/loopz/loopnz. */
132 uint32_t offRelJump;
133 /** Size override byte position. */
134 uint32_t offSizeOverride;
135 /** The size of the patch function. */
136 uint32_t cbFunction;
137 /** The number of relocations in aRelocs. */
138 uint32_t cRelocs;
139 /** Variable sized relocation table. */
140 PATCHASMRELOC aRelocs[1];
141} PATCHASMRECORD;
142/** Pointer to a const patch descriptor record. */
143typedef PATCHASMRECORD const *PCPATCHASMRECORD;
144
145
146/* For indirect calls/jump (identical in PATMA.h & PATMA.mac!) */
147/** @note MUST BE A POWER OF TWO! */
148/** @note direct calls have only one lookup slot (PATCHDIRECTJUMPTABLE_SIZE) */
149/** @note Some statistics reveal that:
150 * - call: Windows XP boot -> max 16, 127 replacements
151 * - call: Knoppix 3.7 boot -> max 9
152 * - ret: Knoppix 5.0.1 boot -> max 16, 80000 replacements (3+ million hits)
153 */
154#define PATM_MAX_JUMPTABLE_ENTRIES 16
155typedef struct
156{
157 uint16_t nrSlots;
158 uint16_t ulInsertPos;
159 uint32_t cAddresses;
160 struct
161 {
162 RTRCPTR pInstrGC;
163 RTRCUINTPTR pRelPatchGC; /* relative to patch base */
164 } Slot[1];
165} PATCHJUMPTABLE, *PPATCHJUMPTABLE;
166
167
168RT_C_DECLS_BEGIN
169
170/** @name Patch Descriptor Records (in PATMA.asm)
171 * @{ */
172extern PATCHASMRECORD PATMCliRecord;
173extern PATCHASMRECORD PATMStiRecord;
174extern PATCHASMRECORD PATMPopf32Record;
175extern PATCHASMRECORD PATMPopf16Record;
176extern PATCHASMRECORD PATMPopf16Record_NoExit;
177extern PATCHASMRECORD PATMPopf32Record_NoExit;
178extern PATCHASMRECORD PATMPushf32Record;
179extern PATCHASMRECORD PATMPushf16Record;
180extern PATCHASMRECORD PATMIretRecord;
181extern PATCHASMRECORD PATMIretRing1Record;
182extern PATCHASMRECORD PATMCpuidRecord;
183extern PATCHASMRECORD PATMLoopRecord;
184extern PATCHASMRECORD PATMLoopZRecord;
185extern PATCHASMRECORD PATMLoopNZRecord;
186extern PATCHASMRECORD PATMJEcxRecord;
187extern PATCHASMRECORD PATMIntEntryRecord;
188extern PATCHASMRECORD PATMIntEntryRecordErrorCode;
189extern PATCHASMRECORD PATMTrapEntryRecord;
190extern PATCHASMRECORD PATMTrapEntryRecordErrorCode;
191extern PATCHASMRECORD PATMPushCSRecord;
192
193extern PATCHASMRECORD PATMCheckIFRecord;
194extern PATCHASMRECORD PATMJumpToGuest_IF1Record;
195
196extern PATCHASMRECORD PATMCallRecord;
197extern PATCHASMRECORD PATMCallIndirectRecord;
198extern PATCHASMRECORD PATMRetRecord;
199extern PATCHASMRECORD PATMJumpIndirectRecord;
200
201extern PATCHASMRECORD PATMLookupAndCallRecord;
202extern PATCHASMRECORD PATMRetFunctionRecord;
203extern PATCHASMRECORD PATMLookupAndJumpRecord;
204extern PATCHASMRECORD PATMIretFunctionRecord;
205
206extern PATCHASMRECORD PATMStatsRecord;
207
208extern PATCHASMRECORD PATMSetPIFRecord;
209extern PATCHASMRECORD PATMClearPIFRecord;
210
211extern PATCHASMRECORD PATMSetInhibitIRQRecord;
212extern PATCHASMRECORD PATMClearInhibitIRQFaultIF0Record;
213extern PATCHASMRECORD PATMClearInhibitIRQContIF0Record;
214
215extern PATCHASMRECORD PATMMovFromSSRecord;
216/** @} */
217
218extern const uint32_t PATMInterruptFlag;
219
220RT_C_DECLS_END
221
222#endif
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