0416105fab0365f22022100599730873c7ff7445
[cacao.git] / src / vm / jit / patcher-common.h
1 /* src/vm/jit/patcher-common.h - architecture independent code patching stuff
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02110-1301, USA.
24
25    $Id$
26
27 */
28
29
30 #ifndef _PATCHER_COMMON_H
31 #define _PATCHER_COMMON_H
32
33 /* forward typedefs ***********************************************************/
34
35 #include "config.h"
36 #include "vm/types.h"
37
38 #include "toolbox/list.h"
39
40 #include "vm/global.h"
41
42 #include "vm/jit/jit.h"
43
44
45 /* patchref_t ******************************************************************
46
47    A patcher reference contains information about a code position
48    which needs additional code patching during runtime.
49
50 *******************************************************************************/
51
52 typedef struct patchref_t {
53         ptrint       mpc;           /* absolute position in code segment          */
54         ptrint       datap;         /* absolute position in data segment          */
55         s4           disp;          /* displacement of ref in the data segment    */
56         functionptr  patcher;       /* patcher function to call                   */
57         voidptr      ref;           /* reference passed                           */
58         u8           mcode;         /* machine code to be patched back in         */
59         bool         done;          /* XXX preliminary: patch already applied?    */
60         listnode_t   linkage;
61 } patchref_t;
62
63
64 /* macros *********************************************************************/
65
66
67 /* function prototypes ********************************************************/
68
69 void patcher_list_create(codeinfo *code);
70 void patcher_list_reset(codeinfo *code);
71 void patcher_list_free(codeinfo *code);
72
73 void patcher_add_patch_ref(jitdata *jd, functionptr patcher, voidptr ref,
74                            s4 disp);
75
76 java_handle_t *patcher_handler(u1 *pc);
77
78
79 /* patcher prototypes and macros **********************************************/
80
81 #if defined(__ALPHA__) || defined(__ARM__) || defined(__MIPS__) || defined(__POWERPC__) || defined (__S390__)
82
83 /* new patcher functions */
84
85 bool patcher_resolve_class(patchref_t *pr);
86 #define PATCHER_resolve_class (functionptr) patcher_resolve_class
87
88 bool patcher_initialize_class(patchref_t *pr);
89 #define PATCHER_initialize_class (functionptr) patcher_initialize_class
90
91 bool patcher_resolve_classref_to_classinfo(patchref_t *pr);
92 #define PATCHER_resolve_classref_to_classinfo (functionptr) patcher_resolve_classref_to_classinfo
93
94 bool patcher_resolve_classref_to_vftbl(patchref_t *pr);
95 #define PATCHER_resolve_classref_to_vftbl (functionptr) patcher_resolve_classref_to_vftbl
96
97 bool patcher_resolve_classref_to_index(patchref_t *pr);
98 #define PATCHER_resolve_classref_to_index (functionptr) patcher_resolve_classref_to_index
99
100 bool patcher_resolve_classref_to_flags(patchref_t *pr);
101 #define PATCHER_resolve_classref_to_flags (functionptr) patcher_resolve_classref_to_flags
102
103 #if !defined(WITH_STATIC_CLASSPATH)
104 bool patcher_resolve_native_function(patchref_t *pr);
105 #define PATCHER_resolve_native_function (functionptr) patcher_resolve_native_function
106 #endif
107
108 /* old patcher functions */
109
110 bool patcher_get_putstatic(patchref_t *pr);
111 #define PATCHER_get_putstatic (functionptr) patcher_get_putstatic
112
113 #if defined(__I386__)
114
115 bool patcher_getfield(patchref_t *pr);
116 #define PATCHER_getfield (functionptr) patcher_getfield
117
118 bool patcher_putfield(patchref_t *pr);
119 #define PATCHER_putfield (functionptr) patcher_putfield
120
121 #else
122
123 bool patcher_get_putfield(patchref_t *pr);
124 #define PATCHER_get_putfield (functionptr) patcher_get_putfield
125
126 #endif /* defined(__I386__) */
127
128 #if defined(__I386__) || defined(__X86_64__)
129
130 bool patcher_putfieldconst(patchref_t *pr);
131 #define PATCHER_putfieldconst (functionptr) patcher_putfieldconst
132
133 #endif /* defined(__I386__) || defined(__X86_64__) */
134
135 bool patcher_invokestatic_special(patchref_t *pr);
136 #define PATCHER_invokestatic_special (functionptr) patcher_invokestatic_special
137
138 bool patcher_invokevirtual(patchref_t *pr);
139 #define PATCHER_invokevirtual (functionptr) patcher_invokevirtual
140
141 bool patcher_invokeinterface(patchref_t *pr);
142 #define PATCHER_invokeinterface (functionptr) patcher_invokeinterface
143
144 #if defined(__ALPHA__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__S390__) 
145
146 bool patcher_checkcast_interface(patchref_t *pr);
147 #define PATCHER_checkcast_interface (functionptr) patcher_checkcast_interface
148
149 bool patcher_instanceof_interface(patchref_t *pr);
150 #define PATCHER_instanceof_interface (functionptr) patcher_instanceof_interface
151
152 #endif /* defined(__ALPHA__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__S390__) */
153
154 /* very old patcher functions */
155 /* XXX use newer patcher function names above! */
156
157 #if defined(__S390__)
158
159 bool patcher_clinit(patchref_t *pr);
160 #define PATCHER_clinit (functionptr) patcher_clinit
161
162 bool patcher_athrow_areturn(patchref_t *pr);
163 #define PATCHER_athrow_areturn (functionptr) patcher_athrow_areturn
164
165 bool patcher_checkcast_instanceof_interface(patchref_t *pr);
166 #define PATCHER_checkcast_instanceof_interface (functionptr) patcher_checkcast_instanceof_interface
167
168 #endif /* defined (__S390__) */
169
170 #endif /* architecture list */
171
172
173 #endif /* _PATCHER_COMMON_H */
174
175
176 /*
177  * These are local overrides for various environment variables in Emacs.
178  * Please do not remove this and leave it at the end of the file, where
179  * Emacs will automagically detect them.
180  * ---------------------------------------------------------------------
181  * Local variables:
182  * mode: c
183  * indent-tabs-mode: t
184  * c-basic-offset: 4
185  * tab-width: 4
186  * End:
187  * vim:noexpandtab:sw=4:ts=4:
188  */