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 /* patcher_function_list *******************************************************
61 
62  This is a list which maps patcher function pointers to the according
63  names of the patcher functions. It is only usefull for debugging
64  purposes.
65 
66 *******************************************************************************/
67 
68 #if !defined(NDEBUG)
69 typedef struct patcher_function_list_t {
71  const char* name;
73 
75 #endif
76 
77 /* function prototypes ********************************************************/
78 
79 void patcher_list_create(codeinfo *code);
80 void patcher_list_reset(codeinfo *code);
81 void patcher_list_free(codeinfo *code);
82 
83 #if !defined(NDEBUG)
84 void patcher_list_show(codeinfo *code);
85 #endif
86 
87 patchref_t *patcher_add_patch_ref(jitdata *jd, functionptr patcher, void* ref, s4 disp);
88 
89 void patcher_resolve(codeinfo* code);
90 
92 bool patcher_is_patched_at(void* pc);
93 
94 // MD function.
96 
97 bool patcher_handler(u1 *pc);
98 
99 
100 /* empty patcher (just patches back original mcode) ***************************/
101 
103 
104 
105 /* patcher prototypes and macros **********************************************/
106 
107 /* new patcher functions */
108 
110 #define PATCHER_resolve_class (functionptr) patcher_resolve_class
111 
113 #define PATCHER_initialize_class (functionptr) patcher_initialize_class
114 
116 #define PATCHER_resolve_classref_to_classinfo (functionptr) patcher_resolve_classref_to_classinfo
117 
119 #define PATCHER_resolve_classref_to_vftbl (functionptr) patcher_resolve_classref_to_vftbl
120 
122 #define PATCHER_resolve_classref_to_index (functionptr) patcher_resolve_classref_to_index
123 
125 #define PATCHER_resolve_classref_to_flags (functionptr) patcher_resolve_classref_to_flags
126 
128 #define PATCHER_resolve_native_function (functionptr) patcher_resolve_native_function
129 
131 #define PATCHER_breakpoint (functionptr) patcher_breakpoint
132 
133 /* old patcher functions */
134 
136 #define PATCHER_get_putstatic (functionptr) patcher_get_putstatic
137 
139 #define PATCHER_get_putfield (functionptr) patcher_get_putfield
140 
142 #define PATCHER_invokestatic_special (functionptr) patcher_invokestatic_special
143 
145 #define PATCHER_invokevirtual (functionptr) patcher_invokevirtual
146 
148 #define PATCHER_invokeinterface (functionptr) patcher_invokeinterface
149 
151 #define PATCHER_checkcast_interface (functionptr) patcher_checkcast_interface
152 
154 #define PATCHER_instanceof_interface (functionptr) patcher_instanceof_interface
155 
156 #if defined(__S390__)
157 
159 #define PATCHER_checkcast_instanceof_interface (functionptr) patcher_checkcast_instanceof_interface
160 
161 #endif /* defined(__S390__) */
162 
163 #endif // _PATCHER_COMMON_HPP
164 
165 
166 /*
167  * These are local overrides for various environment variables in Emacs.
168  * Please do not remove this and leave it at the end of the file, where
169  * Emacs will automagically detect them.
170  * ---------------------------------------------------------------------
171  * Local variables:
172  * mode: c++
173  * indent-tabs-mode: t
174  * c-basic-offset: 4
175  * tab-width: 4
176  * End:
177  * vim:noexpandtab:sw=4:ts=4:
178  */
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
patcher_function_list
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_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
patcher_function_list_t patcher_function_list[]
Definition: patcher.cpp:607
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_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_get_putfield(patchref_t *pr)
Definition: patcher.cpp:308
struct patcher_function_list_t patcher_function_list_t
bool patcher_initialize_class(patchref_t *pr)
#define pc
Definition: md-asm.hpp:56
uintptr_t datap
bool patcher_breakpoint(patchref_t *pr)
Deals with breakpoint instructions (ICMD_BREAKPOINT) compiled into a JIT method.
uint32_t mcode
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_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)