1 /* src/vm/jit/patcher-common.hpp - architecture independent code patching stuff
3 Copyright (C) 1996-2011
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #ifndef _PATCHER_COMMON_HPP
27 #define _PATCHER_COMMON_HPP
29 /* forward typedefs ***********************************************************/
31 typedef struct patchref_t patchref_t;
36 #include "toolbox/list.hpp"
38 #include "vm/global.h"
40 #include "vm/jit/jit.hpp"
43 /* patchref_t ******************************************************************
45 A patcher reference contains information about a code position
46 which needs additional code patching during runtime.
48 *******************************************************************************/
51 uintptr_t mpc; /* absolute position in code segment */
52 uintptr_t datap; /* absolute position in data segment */
53 int32_t disp; /* displacement of ref in the data segment */
54 int16_t disp_mb; /* auxiliary code displacement (for membar) */
55 int16_t patch_align; /* auxiliary displacement for alignment */
56 functionptr patcher; /* patcher function to call */
57 void* ref; /* reference passed */
58 uint32_t mcode; /* machine code to be patched back in */
59 bool done; /* XXX preliminary: patch already applied? */
63 /* macros *********************************************************************/
66 /* function prototypes ********************************************************/
72 void patcher_list_create(codeinfo *code);
73 void patcher_list_reset(codeinfo *code);
74 void patcher_list_free(codeinfo *code);
77 void patcher_list_show(codeinfo *code);
80 patchref_t *patcher_add_patch_ref(jitdata *jd, functionptr patcher, void* ref, s4 disp);
82 void patcher_resolve(jitdata* jd);
84 bool patcher_is_patched(patchref_t* pr);
85 bool patcher_is_patched_at(void* pc);
88 bool patcher_is_valid_trap_instruction_at(void* pc);
90 bool patcher_handler(u1 *pc);
93 /* empty patcher (just patches back original mcode) ***************************/
95 void patcher_patch_code(patchref_t *pr);
98 /* patcher prototypes and macros **********************************************/
100 /* new patcher functions */
102 bool patcher_resolve_class(patchref_t *pr);
103 #define PATCHER_resolve_class (functionptr) patcher_resolve_class
105 bool patcher_initialize_class(patchref_t *pr);
106 #define PATCHER_initialize_class (functionptr) patcher_initialize_class
108 bool patcher_resolve_classref_to_classinfo(patchref_t *pr);
109 #define PATCHER_resolve_classref_to_classinfo (functionptr) patcher_resolve_classref_to_classinfo
111 bool patcher_resolve_classref_to_vftbl(patchref_t *pr);
112 #define PATCHER_resolve_classref_to_vftbl (functionptr) patcher_resolve_classref_to_vftbl
114 bool patcher_resolve_classref_to_index(patchref_t *pr);
115 #define PATCHER_resolve_classref_to_index (functionptr) patcher_resolve_classref_to_index
117 bool patcher_resolve_classref_to_flags(patchref_t *pr);
118 #define PATCHER_resolve_classref_to_flags (functionptr) patcher_resolve_classref_to_flags
120 bool patcher_resolve_native_function(patchref_t *pr);
121 #define PATCHER_resolve_native_function (functionptr) patcher_resolve_native_function
123 bool patcher_breakpoint(patchref_t *pr);
124 #define PATCHER_breakpoint (functionptr) patcher_breakpoint
126 /* old patcher functions */
128 bool patcher_get_putstatic(patchref_t *pr);
129 #define PATCHER_get_putstatic (functionptr) patcher_get_putstatic
131 #if defined(__I386__)
133 bool patcher_getfield(patchref_t *pr);
134 #define PATCHER_getfield (functionptr) patcher_getfield
136 bool patcher_putfield(patchref_t *pr);
137 #define PATCHER_putfield (functionptr) patcher_putfield
141 bool patcher_get_putfield(patchref_t *pr);
142 #define PATCHER_get_putfield (functionptr) patcher_get_putfield
144 #endif /* defined(__I386__) */
146 #if defined(__I386__) || defined(__X86_64__)
148 bool patcher_putfieldconst(patchref_t *pr);
149 #define PATCHER_putfieldconst (functionptr) patcher_putfieldconst
151 #endif /* defined(__I386__) || defined(__X86_64__) */
153 bool patcher_invokestatic_special(patchref_t *pr);
154 #define PATCHER_invokestatic_special (functionptr) patcher_invokestatic_special
156 bool patcher_invokevirtual(patchref_t *pr);
157 #define PATCHER_invokevirtual (functionptr) patcher_invokevirtual
159 bool patcher_invokeinterface(patchref_t *pr);
160 #define PATCHER_invokeinterface (functionptr) patcher_invokeinterface
162 #if defined(__ALPHA__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__S390__) || defined(__X86_64__) || defined(__M68K__)
164 bool patcher_checkcast_interface(patchref_t *pr);
165 #define PATCHER_checkcast_interface (functionptr) patcher_checkcast_interface
167 bool patcher_instanceof_interface(patchref_t *pr);
168 #define PATCHER_instanceof_interface (functionptr) patcher_instanceof_interface
170 #endif /* defined(__ALPHA__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__S390__) || defined(__X86_64__) || defined(__M68K__) */
172 #if defined(__S390__)
174 bool patcher_checkcast_instanceof_interface(patchref_t *pr);
175 #define PATCHER_checkcast_instanceof_interface (functionptr) patcher_checkcast_instanceof_interface
177 #endif /* defined(__S390__) */
179 #if defined(__I386__)
181 bool patcher_aconst(patchref_t *pr);
182 #define PATCHER_aconst (functionptr) patcher_aconst
184 bool patcher_builtin_multianewarray(patchref_t *pr);
185 #define PATCHER_builtin_multianewarray (functionptr) patcher_builtin_multianewarray
187 bool patcher_builtin_arraycheckcast(patchref_t *pr);
188 #define PATCHER_builtin_arraycheckcast (functionptr) patcher_builtin_arraycheckcast
190 bool patcher_checkcast_instanceof_flags(patchref_t *pr);
191 #define PATCHER_checkcast_instanceof_flags (functionptr) patcher_checkcast_instanceof_flags
193 bool patcher_checkcast_class(patchref_t *pr);
194 #define PATCHER_checkcast_class (functionptr) patcher_checkcast_class
196 bool patcher_instanceof_class(patchref_t *pr);
197 #define PATCHER_instanceof_class (functionptr) patcher_instanceof_class
199 #endif /* defined(__I386__) */
205 #endif // _PATCHER_COMMON_HPP
209 * These are local overrides for various environment variables in Emacs.
210 * Please do not remove this and leave it at the end of the file, where
211 * Emacs will automagically detect them.
212 * ---------------------------------------------------------------------
215 * indent-tabs-mode: t
219 * vim:noexpandtab:sw=4:ts=4: