Changes:
- $Id: patcher.c 2360 2005-04-24 13:07:57Z jowenn $
+ $Id: patcher.c 2391 2005-04-26 19:49:15Z twisti $
*/
#include "vm/builtin.h"
#include "vm/field.h"
#include "vm/initialize.h"
+#include "vm/options.h"
#include "vm/references.h"
#include "vm/jit/helper.h"
#include "vm/exceptions.h"
+
/* patcher_get_putstatic *******************************************************
XXX
*((u8 *) ra) = mcode;
+ /* if we show disassembly, we have to skip the nop's */
+
+ if (showdisassemble)
+ ra = ra + 5;
+
/* get RIP offset from machine instruction */
ripoffset = *((u4 *) (ra + 3));
/* patcher_get_putfield ********************************************************
- XXX
-
Machine code:
45 8b 8f 00 00 00 00 mov 0x0(%r15),%r9d
*((u8 *) ra) = mcode;
+ /* if we show disassembly, we have to skip the nop's */
+
+ if (showdisassemble)
+ ra = ra + 5;
+
/* patch the field's offset: we check for the field type, because the */
/* instructions have different lengths */
/* patcher_builtin_new *********************************************************
- XXX
-
Machine code:
+ 48 bf a0 f0 92 00 00 00 00 00 mov $0x92f0a0,%rdi
+ <patched call position>
+ 48 b8 00 00 00 00 00 00 00 00 mov $0x0,%rax
+ 48 ff d0 callq *%rax
+
*******************************************************************************/
-bool patcher_builtin_new(constant_classref *cr, u1 *sp)
+bool patcher_builtin_new(u1 *sp)
{
u1 *ra;
+ u8 mcode;
+ constant_classref *cr;
classinfo *c;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 0 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ mcode = *((u8 *) (sp + 1 * 8));
+ cr = (constant_classref *) *((ptrint *) (sp + 0 * 8));
/* calculate and set the new return address */
- ra = ra - (10 + 10 + 3);
- *((ptrint *) (sp + 0 * 8)) = (ptrint) ra;
+ ra = ra - (10 + 5);
+ *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
*dontfillinexceptionstacktrace=true;
return false;
}
+ /* patch back original code */
+
+ *((u8 *) (ra + 10)) = mcode;
+
/* patch the classinfo pointer */
*((ptrint *) (ra + 2)) = (ptrint) c;
+ /* if we show disassembly, we have to skip the nop's */
+
+ if (showdisassemble)
+ ra = ra + 5;
+
/* patch new function address */
*((ptrint *) (ra + 10 + 2)) = (ptrint) BUILTIN_new;
/* patcher_builtin_newarray ****************************************************
- XXX
-
Machine code:
+ 48 be 88 13 9b 00 00 00 00 00 mov $0x9b1388,%rsi
+ <patched call position>
+ 48 b8 00 00 00 00 00 00 00 00 mov $0x0,%rax
+ 48 ff d0 callq *%rax
+
*******************************************************************************/
-bool patcher_builtin_newarray(u1 *sp, constant_classref *cr)
+bool patcher_builtin_newarray(u1 *sp)
{
u1 *ra;
+ u8 mcode;
+ constant_classref *cr;
classinfo *c;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 0 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ mcode = *((u8 *) (sp + 1 * 8));
+ cr = (constant_classref *) *((ptrint *) (sp + 0 * 8));
/* calculate and set the new return address */
- ra = ra - (10 + 10 + 3);
- *((ptrint *) (sp + 0 * 8)) = (ptrint) ra;
-
+ ra = ra - (10 + 5);
+ *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
*dontfillinexceptionstacktrace=true;
-
/* get the classinfo */
- if (!(c = helper_resolve_classinfo(cr)))
- {
+ if (!(c = helper_resolve_classinfo(cr))) {
*dontfillinexceptionstacktrace=false;
return false;
}
+
+ /* patch back original code */
+
+ *((u8 *) (ra + 10)) = mcode;
+
/* patch the class' vftbl pointer */
*((ptrint *) (ra + 2)) = (ptrint) c->vftbl;
+ /* if we show disassembly, we have to skip the nop's */
+
+ if (showdisassemble)
+ ra = ra + 5;
+
/* patch new function address */
*((ptrint *) (ra + 10 + 2)) = (ptrint) BUILTIN_newarray;
/* patcher_builtin_multianewarray **********************************************
- XXX
-
Machine code:
+ <patched call position>
+ 48 bf 02 00 00 00 00 00 00 00 mov $0x2,%rdi
+ 48 be 30 40 b2 00 00 00 00 00 mov $0xb24030,%rsi
+ 48 89 e2 mov %rsp,%rdx
+ 48 b8 7c 96 4b 00 00 00 00 00 mov $0x4b967c,%rax
+ 48 ff d0 callq *%rax
+
*******************************************************************************/
-bool patcher_builtin_multianewarray(u1 *sp, constant_classref *cr)
+bool patcher_builtin_multianewarray(u1 *sp)
{
u1 *ra;
+ u8 mcode;
+ constant_classref *cr;
classinfo *c;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 0 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ mcode = *((u8 *) (sp + 1 * 8));
+ cr = (constant_classref *) *((ptrint *) (sp + 0 * 8));
/* calculate and set the new return address */
- ra = ra - (10 + 10 + 3 + 10 + 3);
- *((ptrint *) (sp + 0 * 8)) = (ptrint) ra;
+ ra = ra - 5;
+ *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
*dontfillinexceptionstacktrace=true;
*dontfillinexceptionstacktrace=false;
return false;
}
+
+ /* patch back original code */
+
+ *((u8 *) ra) = mcode;
+
+ /* if we show disassembly, we have to skip the nop's */
+
+ if (showdisassemble)
+ ra = ra + 5;
+
/* patch the class' vftbl pointer */
*((ptrint *) (ra + 10 + 2)) = (ptrint) c->vftbl;
/* patcher_builtin_checkarraycast **********************************************
- XXX
-
Machine code:
+ 48 be b8 3f b2 00 00 00 00 00 mov $0xb23fb8,%rsi
+ <patched call position>
+ 48 b8 00 00 00 00 00 00 00 00 mov $0x0,%rax
+ 48 ff d0 callq *%rax
+
*******************************************************************************/
-bool patcher_builtin_checkarraycast(u1 *sp, constant_classref *cr)
+bool patcher_builtin_checkarraycast(u1 *sp)
{
u1 *ra;
+ u8 mcode;
+ constant_classref *cr;
classinfo *c;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 0 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ mcode = *((u8 *) (sp + 1 * 8));
+ cr = (constant_classref *) *((ptrint *) (sp + 0 * 8));
/* calculate and set the new return address */
- ra = ra - (10 + 10 + 3);
- *((ptrint *) (sp + 0 * 8)) = (ptrint) ra;
+ ra = ra - (10 + 5);
+ *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
*dontfillinexceptionstacktrace=true;
/* get the classinfo */
- if (!(c = helper_resolve_classinfo(cr)))
- {
+ if (!(c = helper_resolve_classinfo(cr))) {
*dontfillinexceptionstacktrace=false;
return false;
}
+ /* patch back original code */
+
+ *((u8 *) (ra + 10)) = mcode;
+
+ /* if we show disassembly, we have to skip the nop's */
+
+ if (showdisassemble)
+ ra = ra + 5;
+
/* patch the class' vftbl pointer */
*((ptrint *) (ra + 2)) = (ptrint) c->vftbl;
/* patcher_builtin_arrayinstanceof *********************************************
- XXX
-
Machine code:
+ 48 be 30 3c b2 00 00 00 00 00 mov $0xb23c30,%rsi
+ <patched call position>
+ 48 b8 00 00 00 00 00 00 00 00 mov $0x0,%rax
+ 48 ff d0 callq *%rax
+
*******************************************************************************/
-bool patcher_builtin_arrayinstanceof(u1 *sp, constant_classref *cr)
+bool patcher_builtin_arrayinstanceof(u1 *sp)
{
u1 *ra;
+ u8 mcode;
+ constant_classref *cr;
classinfo *c;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 0 * 8));
+ ra = (u1 *) *((ptrint *) (sp + 2 * 8));
+ mcode = *((u8 *) (sp + 1 * 8));
+ cr = (constant_classref *) *((ptrint *) (sp + 0 * 8));
/* calculate and set the new return address */
- ra = ra - (10 + 10 + 3);
- *((ptrint *) (sp + 0 * 8)) = (ptrint) ra;
-
+ ra = ra - (10 + 5);
+ *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
*dontfillinexceptionstacktrace=true;
-
/* get the classinfo */
- if (!(c = helper_resolve_classinfo(cr)))
- {
+ if (!(c = helper_resolve_classinfo(cr))) {
*dontfillinexceptionstacktrace=false;
return false;
}
+ /* patch back original code */
+
+ *((u8 *) (ra + 10)) = mcode;
+
+ /* if we show disassembly, we have to skip the nop's */
+
+ if (showdisassemble)
+ ra = ra + 5;
+
/* patch the class' vftbl pointer */
*((ptrint *) (ra + 2)) = (ptrint) c->vftbl;
*((u8 *) ra) = mcode;
+ /* if we show disassembly, we have to skip the nop's */
+
+ if (showdisassemble)
+ ra = ra + 5;
+
/* patch stubroutine */
*((ptrint *) (ra + 2)) = (ptrint) m->stubroutine;
*((u8 *) ra) = mcode;
+ /* if we show disassembly, we have to skip the nop's */
+
+ if (showdisassemble)
+ ra = ra + 5;
+
/* patch vftbl index */
*((s4 *) (ra + 3 + 3)) = (s4) (OFFSET(vftbl_t, table[0]) +
*((u8 *) ra) = mcode;
+ /* if we show disassembly, we have to skip the nop's */
+
+ if (showdisassemble)
+ ra = ra + 5;
+
/* patch interfacetable index */
*((s4 *) (ra + 3 + 3)) = (s4) (OFFSET(vftbl_t, interfacetable[0]) -
/* get the fieldinfo */
- if (!(c = helper_resolve_classinfo(cr)))
- {
+ if (!(c = helper_resolve_classinfo(cr))) {
*dontfillinexceptionstacktrace=false;
return false;
}
+
/* patch back original code */
*((u8 *) ra) = mcode;
+ /* if we show disassembly, we have to skip the nop's */
+
+ if (showdisassemble)
+ ra = ra + 5;
+
/* patch class flags */
*((s4 *) (ra + 2)) = (s4) c->flags;
ra = ra - 5;
*((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
-
*dontfillinexceptionstacktrace=true;
/* get the fieldinfo */
- if (!(c = helper_resolve_classinfo(cr)))
- {
+ if (!(c = helper_resolve_classinfo(cr))) {
*dontfillinexceptionstacktrace=false;
return false;
}
*((u8 *) ra) = mcode;
+ /* if we show disassembly, we have to skip the nop's */
+
+ if (showdisassemble)
+ ra = ra + 5;
+
/* patch super class index */
*((s4 *) (ra + 7 + 3)) = (s4) c->index;
/* get the fieldinfo */
- if (!(c = helper_resolve_classinfo(cr)))
- {
+ if (!(c = helper_resolve_classinfo(cr))) {
*dontfillinexceptionstacktrace=false;
return false;
}
*((u8 *) ra) = mcode;
+ /* if we show disassembly, we have to skip the nop's */
+
+ if (showdisassemble)
+ ra = ra + 5;
+
/* patch super class' vftbl */
*((ptrint *) (ra + 2)) = (ptrint) c->vftbl;
/* get the fieldinfo */
- if (!(c = helper_resolve_classinfo(cr)))
- {
+ if (!(c = helper_resolve_classinfo(cr))) {
*dontfillinexceptionstacktrace=false;
return false;
}
*((u8 *) ra) = mcode;
+ /* if we show disassembly, we have to skip the nop's */
+
+ if (showdisassemble)
+ ra = ra + 5;
+
/* patch super class' vftbl */
*((ptrint *) (ra + 2)) = (ptrint) c->vftbl;
/* check if the class is initialized */
- if (!c->initialized)
- {
+ if (!c->initialized) {
bool init;
{
/*struct native_stackframeinfo {