CACAO
patcher-common.hpp
Go to the documentation of this file.
1 /* src/vm/jit/patcher-common.hpp - architecture independent code patching stuff
2 
3  Copyright (C) 1996-2011
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
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.
12 
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.
17 
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
21  02110-1301, USA.
22 
23 */
24 
25 
26 #ifndef _PATCHER_COMMON_HPP
27 #define _PATCHER_COMMON_HPP
28 
29 /* forward typedefs ***********************************************************/
30 
31 typedef struct patchref_t patchref_t;
32 
33 #include "config.h"
34 #include "vm/types.hpp"
35 
36 #include "toolbox/list.hpp"
37 
38 #include "vm/global.hpp"
39 
40 struct jitdata;
41 
42 /* patchref_t ******************************************************************
43 
44  A patcher reference contains information about a code position
45  which needs additional code patching during runtime.
46 
47 *******************************************************************************/
48 
49 struct patchref_t {
50  uintptr_t mpc; /* absolute position in code segment */
51  uintptr_t datap; /* absolute position in data segment */
52  int32_t disp; /* displacement of ref in the data segment */
53  int16_t disp_mb; /* auxiliary code displacement (for membar) */
54  int16_t patch_align; /* auxiliary displacement for alignment */
55  functionptr patcher; /* patcher function to call */
56  void* ref; /* reference passed */
57  uint32_t mcode; /* machine code to be patched back in */
58 };
59 
60 
61 /* macros *********************************************************************/
62 
63 
64 /* function prototypes ********************************************************/
65 
66 void patcher_list_create(codeinfo *code);
67 void patcher_list_reset(codeinfo *code);
68 void patcher_list_free(codeinfo *code);
69 
70 #if !defined(NDEBUG)
71 void patcher_list_show(codeinfo *code);
72 #endif
73 
74 patchref_t *patcher_add_patch_ref(jitdata *jd, functionptr patcher, void* ref, s4 disp);
75 
76 void patcher_resolve(codeinfo* code);
77 
79 bool patcher_is_patched_at(void* pc);
80 
81 // MD function.
83 
84 bool patcher_handler(u1 *pc);
85 
86 
87 /* empty patcher (just patches back original mcode) ***************************/
88 
90 
91 
92 /* patcher prototypes and macros **********************************************/
93 
94 /* new patcher functions */
95 
97 #define PATCHER_resolve_class (functionptr) patcher_resolve_class
98 
100 #define PATCHER_initialize_class (functionptr) patcher_initialize_class
101 
103 #define PATCHER_resolve_classref_to_classinfo (functionptr) patcher_resolve_classref_to_classinfo
104 
106 #define PATCHER_resolve_classref_to_vftbl (functionptr) patcher_resolve_classref_to_vftbl
107 
109 #define PATCHER_resolve_classref_to_index (functionptr) patcher_resolve_classref_to_index
110 
112 #define PATCHER_resolve_classref_to_flags (functionptr) patcher_resolve_classref_to_flags
113 
115 #define PATCHER_resolve_native_function (functionptr) patcher_resolve_native_function
116 
118 #define PATCHER_breakpoint (functionptr) patcher_breakpoint
119 
120 /* old patcher functions */
121 
123 #define PATCHER_get_putstatic (functionptr) patcher_get_putstatic
124 
125 #if defined(__I386__)
126 
127 bool patcher_getfield(patchref_t *pr);
128 #define PATCHER_getfield (functionptr) patcher_getfield
129 
130 bool patcher_putfield(patchref_t *pr);
131 #define PATCHER_putfield (functionptr) patcher_putfield
132 
133 #endif /* defined(__I386__) */
134 
136 #define PATCHER_get_putfield (functionptr) patcher_get_putfield
137 
138 #if defined(__I386__) || defined(__X86_64__)
139 
141 #define PATCHER_putfieldconst (functionptr) patcher_putfieldconst
142 
143 #endif /* defined(__I386__) || defined(__X86_64__) */
144 
146 #define PATCHER_invokestatic_special (functionptr) patcher_invokestatic_special
147 
149 #define PATCHER_invokevirtual (functionptr) patcher_invokevirtual
150 
152 #define PATCHER_invokeinterface (functionptr) patcher_invokeinterface
153 
155 #define PATCHER_checkcast_interface (functionptr) patcher_checkcast_interface
156 
158 #define PATCHER_instanceof_interface (functionptr) patcher_instanceof_interface
159 
160 #if defined(__S390__)
161 
163 #define PATCHER_checkcast_instanceof_interface (functionptr) patcher_checkcast_instanceof_interface
164 
165 #endif /* defined(__S390__) */
166 
167 #if defined(__I386__)
168 
169 bool patcher_aconst(patchref_t *pr);
170 #define PATCHER_aconst (functionptr) patcher_aconst
171 
173 #define PATCHER_builtin_multianewarray (functionptr) patcher_builtin_multianewarray
174 
176 #define PATCHER_builtin_arraycheckcast (functionptr) patcher_builtin_arraycheckcast
177 
179 #define PATCHER_checkcast_instanceof_flags (functionptr) patcher_checkcast_instanceof_flags
180 
182 #define PATCHER_checkcast_class (functionptr) patcher_checkcast_class
183 
185 #define PATCHER_instanceof_class (functionptr) patcher_instanceof_class
186 
187 #endif /* defined(__I386__) */
188 
189 #endif // _PATCHER_COMMON_HPP
190 
191 
192 /*
193  * These are local overrides for various environment variables in Emacs.
194  * Please do not remove this and leave it at the end of the file, where
195  * Emacs will automagically detect them.
196  * ---------------------------------------------------------------------
197  * Local variables:
198  * mode: c++
199  * indent-tabs-mode: t
200  * c-basic-offset: 4
201  * tab-width: 4
202  * End:
203  * vim:noexpandtab:sw=4:ts=4:
204  */
bool patcher_handler(u1 *pc)
bool patcher_invokestatic_special(patchref_t *pr)
Definition: patcher.cpp:392
bool patcher_get_putstatic(patchref_t *pr)
Definition: patcher.cpp:264
functionptr patcher
Definition: jit.hpp:126
bool patcher_resolve_classref_to_classinfo(patchref_t *pr)
Definition: patcher.cpp:148
bool patcher_invokeinterface(patchref_t *pr)
Definition: patcher.cpp:477
bool patcher_checkcast_instanceof_interface(patchref_t *pr)
Definition: patcher.cpp:393
bool patcher_instanceof_class(patchref_t *pr)
Definition: patcher.cpp:697
bool patcher_resolve_native_function(patchref_t *pr)
bool patcher_is_patched(patchref_t *pr)
patchref_t * patcher_add_patch_ref(jitdata *jd, functionptr patcher, void *ref, s4 disp)
void patcher_resolve(codeinfo *code)
Resolve all patchers in the current JIT run.
uint8_t u1
Definition: types.hpp:40
bool patcher_putfield(patchref_t *pr)
Definition: patcher.cpp:181
void(* functionptr)(void)
Definition: global.hpp:39
bool patcher_resolve_class(patchref_t *pr)
void patcher_list_show(codeinfo *code)
Show the content of the whole patcher reference list for debugging purposes.
int16_t disp_mb
void patcher_patch_code(patchref_t *pr)
Definition: patcher.cpp:114
void patcher_list_create(codeinfo *code)
bool patcher_invokevirtual(patchref_t *pr)
Definition: patcher.cpp:433
bool patcher_resolve_classref_to_index(patchref_t *pr)
Definition: patcher.cpp:372
bool patcher_aconst(patchref_t *pr)
Definition: patcher.cpp:285
bool patcher_resolve_classref_to_flags(patchref_t *pr)
Definition: patcher.cpp:225
bool patcher_checkcast_interface(patchref_t *pr)
Definition: patcher.cpp:526
void patcher_list_reset(codeinfo *code)
int32_t s4
Definition: types.hpp:45
int16_t patch_align
bool patcher_putfieldconst(patchref_t *pr)
Definition: patcher.cpp:233
bool patcher_get_putfield(patchref_t *pr)
Definition: patcher.cpp:308
bool patcher_initialize_class(patchref_t *pr)
#define pc
Definition: md-asm.hpp:56
bool patcher_checkcast_instanceof_flags(patchref_t *pr)
Definition: patcher.cpp:532
uintptr_t datap
bool patcher_breakpoint(patchref_t *pr)
Deals with breakpoint instructions (ICMD_BREAKPOINT) compiled into a JIT method.
uint32_t mcode
bool patcher_builtin_arraycheckcast(patchref_t *pr)
Definition: patcher.cpp:367
bool patcher_builtin_multianewarray(patchref_t *pr)
Definition: patcher.cpp:328
uintptr_t mpc
bool patcher_is_valid_trap_instruction_at(void *pc)
Check if the trap instruction at the given PC is valid.
Definition: patcher.cpp:72
bool patcher_getfield(patchref_t *pr)
Definition: patcher.cpp:135
bool patcher_checkcast_class(patchref_t *pr)
Definition: patcher.cpp:660
bool patcher_resolve_classref_to_vftbl(patchref_t *pr)
Definition: patcher.cpp:188
void patcher_list_free(codeinfo *code)
bool patcher_instanceof_interface(patchref_t *pr)
Definition: patcher.cpp:572
bool patcher_is_patched_at(void *pc)