PATMA.h revision c52fc8460f9320bd211137767aa86f7d4352975a
/* $Id$ */
/** @file
* PATM macros & definitions (identical to PATMA.mac!).
*/
/*
* Copyright (C) 2006-2015 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef ___PATMA_H
#define ___PATMA_H
/** @name Patch Fixup Types
* @{ */
#define PATM_VMFLAGS 0xF1ABCD00
#ifdef VBOX_WITH_STATISTICS
# define PATM_ALLPATCHCALLS 0xF1ABCD01
# define PATM_PERPATCHCALLS 0xF1ABCD02
#endif
#define PATM_JUMPDELTA 0xF1ABCD03
#ifdef VBOX_WITH_STATISTICS
# define PATM_IRETEFLAGS 0xF1ABCD04
# define PATM_IRETCS 0xF1ABCD05
# define PATM_IRETEIP 0xF1ABCD06
#endif
#define PATM_FIXUP 0xF1ABCD07
#define PATM_PENDINGACTION 0xF1ABCD08
#define PATM_CPUID_STD_PTR 0xF1ABCD09
#define PATM_CPUID_EXT_PTR 0xF1ABCD0a
#define PATM_CPUID_DEF_PTR 0xF1ABCD0b
#define PATM_STACKPTR 0xF1ABCD0e
#define PATM_PATCHBASE 0xF1ABCD0f
#define PATM_INTERRUPTFLAG 0xF1ABCD10
#define PATM_INHIBITIRQADDR 0xF1ABCD11
#define PATM_VM_FORCEDACTIONS 0xF1ABCD12
#define PATM_CALL_PATCH_TARGET_ADDR 0xF1ABCD18
#define PATM_CALL_RETURN_ADDR 0xF1ABCD19
#define PATM_CPUID_CENTAUR_PTR 0xF1ABCD1a
/* Anything larger doesn't require a fixup */
#define PATM_NO_FIXUP 0xF1ABCE00
#define PATM_CPUID_STD_MAX 0xF1ABCE00
#define PATM_CPUID_EXT_MAX 0xF1ABCE01
#define PATM_RETURNADDR 0xF1ABCE02
#define PATM_PATCHNEXTBLOCK 0xF1ABCE03
#define PATM_LOOKUP_AND_CALL_FUNCTION 0xF1ABCE07 /**< Relative address of global PATM lookup and call function. */
#define PATM_LOOKUP_AND_JUMP_FUNCTION 0xF1ABCE09 /**< Relative address of global PATM lookup and jump function. */
#define PATM_CPUID_CENTAUR_MAX 0xF1ABCE0B
/** @} */
/** Everything except IOPL, NT, IF, VM, VIF, VIP and RF */
/** Flags that PATM virtualizes. Currently only IF & IOPL. */
/* PATM stack size (identical in PATMA.mac!!) */
#define PATM_STACK_SIZE (4096)
/** @name Patch Manager pending actions (in GCSTATE).
* @{ */
#define PATM_ACTION_LOOKUP_ADDRESS 1
#define PATM_ACTION_DISPATCH_PENDING_IRQ 2
#define PATM_ACTION_PENDING_IRQ_AFTER_IRET 3
#define PATM_ACTION_DO_V86_IRET 4
#define PATM_ACTION_LOG_IF1 5
#define PATM_ACTION_LOG_CLI 6
#define PATM_ACTION_LOG_STI 7
#define PATM_ACTION_LOG_POPF_IF1 8
#define PATM_ACTION_LOG_POPF_IF0 9
#define PATM_ACTION_LOG_PUSHF 10
#define PATM_ACTION_LOG_IRET 11
#define PATM_ACTION_LOG_RET 12
#define PATM_ACTION_LOG_CALL 13
#define PATM_ACTION_LOG_GATE_ENTRY 14
/** @} */
/** Magic dword found in ecx for patm pending actions. */
#define PATM_ACTION_MAGIC 0xABCD4321
/** @name PATM_TEMP_RESTORE_FLAGS
* @{ */
#define PATM_RESTORE_EAX RT_BIT(0)
/** @} */
/** Relocation entry for PATCHASMRECORD. */
typedef struct PATCHASMRELOC
{
/** The relocation type. */
/** Additional information specific to the relocation type. */
typedef PATCHASMRELOC const *PCPATCHASMRELOC;
/**
* Assembly patch descriptor record.
*/
typedef struct
{
/** Pointer to the patch code. */
/** Offset of the jump table? */
/** Size override byte position. */
/** The size of the patch function. */
/** The number of relocations in aRelocs. */
/** Variable sized relocation table. */
/** Pointer to a const patch descriptor record. */
typedef PATCHASMRECORD const *PCPATCHASMRECORD;
/** @note MUST BE A POWER OF TWO! */
/** @note direct calls have only one lookup slot (PATCHDIRECTJUMPTABLE_SIZE) */
/** @note Some statistics reveal that:
* - call: Windows XP boot -> max 16, 127 replacements
* - call: Knoppix 3.7 boot -> max 9
* - ret: Knoppix 5.0.1 boot -> max 16, 80000 replacements (3+ million hits)
*/
#define PATM_MAX_JUMPTABLE_ENTRIES 16
typedef struct
{
struct
{
} Slot[1];
/** @name Patch Descriptor Records (in PATMA.asm)
* @{ */
extern PATCHASMRECORD PATMCliRecord;
extern PATCHASMRECORD PATMStiRecord;
extern PATCHASMRECORD PATMPopf32Record;
extern PATCHASMRECORD PATMPopf16Record;
extern PATCHASMRECORD PATMPushf32Record;
extern PATCHASMRECORD PATMPushf16Record;
extern PATCHASMRECORD PATMIretRecord;
extern PATCHASMRECORD PATMIretRing1Record;
extern PATCHASMRECORD PATMCpuidRecord;
extern PATCHASMRECORD PATMLoopRecord;
extern PATCHASMRECORD PATMLoopZRecord;
extern PATCHASMRECORD PATMLoopNZRecord;
extern PATCHASMRECORD PATMJEcxRecord;
extern PATCHASMRECORD PATMIntEntryRecord;
extern PATCHASMRECORD PATMTrapEntryRecord;
extern PATCHASMRECORD PATMPushCSRecord;
extern PATCHASMRECORD PATMCheckIFRecord;
extern PATCHASMRECORD PATMCallRecord;
extern PATCHASMRECORD PATMCallIndirectRecord;
extern PATCHASMRECORD PATMRetRecord;
extern PATCHASMRECORD PATMJumpIndirectRecord;
extern PATCHASMRECORD PATMRetFunctionRecord;
extern PATCHASMRECORD PATMIretFunctionRecord;
extern PATCHASMRECORD PATMStatsRecord;
extern PATCHASMRECORD PATMSetPIFRecord;
extern PATCHASMRECORD PATMClearPIFRecord;
extern PATCHASMRECORD PATMMovFromSSRecord;
/** @} */
extern const uint32_t PATMInterruptFlag;
#endif