1 /* src/vm/jit/patcher-common.h - architecture independent code patching stuff
3 Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 #ifndef _PATCHER_COMMON_H
29 #define _PATCHER_COMMON_H
31 /* forward typedefs ***********************************************************/
36 #include "toolbox/list.h"
38 #include "vm/global.h"
40 #include "vm/jit/jit.h"
43 /* patchref_t ******************************************************************
45 A patcher reference contains information about a code position
46 which needs additional code patching during runtime.
48 *******************************************************************************/
50 typedef struct patchref_t {
51 ptrint mpc; /* absolute position in code segment */
52 ptrint datap; /* absolute position in data segment */
53 s4 disp; /* displacement of ref in the data segment */
54 functionptr patcher; /* patcher function to call */
55 voidptr ref; /* reference passed */
56 u8 mcode; /* machine code to be patched back in */
57 bool done; /* XXX preliminary: patch already applied? */
62 /* macros *********************************************************************/
65 /* function prototypes ********************************************************/
67 void patcher_list_create(codeinfo *code);
68 void patcher_list_reset(codeinfo *code);
69 void patcher_list_free(codeinfo *code);
71 void patcher_add_patch_ref(jitdata *jd, functionptr patcher, voidptr ref,
74 java_handle_t *patcher_handler(u1 *pc);
77 /* empty patcher (just patches back original mcode) ***************************/
79 void patcher_patch_code(patchref_t *pr);
82 /* patcher prototypes and macros **********************************************/
84 #if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined (__S390__) || defined(__X86_64__)
86 /* new patcher functions */
88 bool patcher_resolve_class(patchref_t *pr);
89 #define PATCHER_resolve_class (functionptr) patcher_resolve_class
91 bool patcher_initialize_class(patchref_t *pr);
92 #define PATCHER_initialize_class (functionptr) patcher_initialize_class
94 bool patcher_resolve_classref_to_classinfo(patchref_t *pr);
95 #define PATCHER_resolve_classref_to_classinfo (functionptr) patcher_resolve_classref_to_classinfo
97 bool patcher_resolve_classref_to_vftbl(patchref_t *pr);
98 #define PATCHER_resolve_classref_to_vftbl (functionptr) patcher_resolve_classref_to_vftbl
100 bool patcher_resolve_classref_to_index(patchref_t *pr);
101 #define PATCHER_resolve_classref_to_index (functionptr) patcher_resolve_classref_to_index
103 bool patcher_resolve_classref_to_flags(patchref_t *pr);
104 #define PATCHER_resolve_classref_to_flags (functionptr) patcher_resolve_classref_to_flags
106 bool patcher_resolve_native_function(patchref_t *pr);
107 #define PATCHER_resolve_native_function (functionptr) patcher_resolve_native_function
109 /* old patcher functions */
111 bool patcher_get_putstatic(patchref_t *pr);
112 #define PATCHER_get_putstatic (functionptr) patcher_get_putstatic
114 #if defined(__I386__)
116 bool patcher_getfield(patchref_t *pr);
117 #define PATCHER_getfield (functionptr) patcher_getfield
119 bool patcher_putfield(patchref_t *pr);
120 #define PATCHER_putfield (functionptr) patcher_putfield
124 bool patcher_get_putfield(patchref_t *pr);
125 #define PATCHER_get_putfield (functionptr) patcher_get_putfield
127 #endif /* defined(__I386__) */
129 #if defined(__I386__) || defined(__X86_64__)
131 bool patcher_putfieldconst(patchref_t *pr);
132 #define PATCHER_putfieldconst (functionptr) patcher_putfieldconst
134 #endif /* defined(__I386__) || defined(__X86_64__) */
136 bool patcher_invokestatic_special(patchref_t *pr);
137 #define PATCHER_invokestatic_special (functionptr) patcher_invokestatic_special
139 bool patcher_invokevirtual(patchref_t *pr);
140 #define PATCHER_invokevirtual (functionptr) patcher_invokevirtual
142 bool patcher_invokeinterface(patchref_t *pr);
143 #define PATCHER_invokeinterface (functionptr) patcher_invokeinterface
145 #if defined(__ALPHA__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__S390__) || defined(__X86_64__)
147 bool patcher_checkcast_interface(patchref_t *pr);
148 #define PATCHER_checkcast_interface (functionptr) patcher_checkcast_interface
150 bool patcher_instanceof_interface(patchref_t *pr);
151 #define PATCHER_instanceof_interface (functionptr) patcher_instanceof_interface
153 #endif /* defined(__ALPHA__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__POWERPC64__) || defined(__S390__) || defined(__X86_64__) */
155 #if defined(__S390__)
157 bool patcher_checkcast_instanceof_interface(patchref_t *pr);
158 #define PATCHER_checkcast_instanceof_interface (functionptr) patcher_checkcast_instanceof_interface
160 #endif /* defined(__S390__) */
162 #if defined(__I386__)
164 bool patcher_aconst(patchref_t *pr);
165 #define PATCHER_aconst (functionptr) patcher_aconst
167 bool patcher_builtin_multianewarray(patchref_t *pr);
168 #define PATCHER_builtin_multianewarray (functionptr) patcher_builtin_multianewarray
170 bool patcher_builtin_arraycheckcast(patchref_t *pr);
171 #define PATCHER_builtin_arraycheckcast (functionptr) patcher_builtin_arraycheckcast
173 bool patcher_checkcast_instanceof_flags(patchref_t *pr);
174 #define PATCHER_checkcast_instanceof_flags (functionptr) patcher_checkcast_instanceof_flags
176 bool patcher_checkcast_class(patchref_t *pr);
177 #define PATCHER_checkcast_class (functionptr) patcher_checkcast_class
179 bool patcher_instanceof_class(patchref_t *pr);
180 #define PATCHER_instanceof_class (functionptr) patcher_instanceof_class
182 #endif /* defined(__I386__) */
185 #endif /* architecture list */
188 #endif /* _PATCHER_COMMON_H */
192 * These are local overrides for various environment variables in Emacs.
193 * Please do not remove this and leave it at the end of the file, where
194 * Emacs will automagically detect them.
195 * ---------------------------------------------------------------------
198 * indent-tabs-mode: t
202 * vim:noexpandtab:sw=4:ts=4: