From d1377204f560df4d6656f58914bc4d242193c5e0 Mon Sep 17 00:00:00 2001 From: Stefan Ring Date: Sat, 14 Nov 2009 15:39:50 +0100 Subject: [PATCH] * src/vm/jit/x86_64/codegen.h: Use multi-byte NOP for code alignment. * src/vm/jit/x86_64/emit.c: Added emit_nop. * src/vm/jit/x86_64/emit.h: Likewise. --- src/vm/jit/x86_64/codegen.h | 8 ++--- src/vm/jit/x86_64/emit.c | 70 +++++++++++++++++++++++++++++++++++++ src/vm/jit/x86_64/emit.h | 1 + 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/vm/jit/x86_64/codegen.h b/src/vm/jit/x86_64/codegen.h index d5b1367df..4fa215d54 100644 --- a/src/vm/jit/x86_64/codegen.h +++ b/src/vm/jit/x86_64/codegen.h @@ -50,8 +50,9 @@ #define ALIGNCODENOP \ do { \ - for (s1 = 0; s1 < (s4) (((ptrint) cd->mcodeptr) & 7); s1++) \ - M_NOP; \ + int len = (-(ptrint) cd->mcodeptr) & 7; \ + if (len) \ + emit_nop(cd, len); \ } while (0) @@ -98,8 +99,7 @@ #define PATCHER_NOPS \ do { \ - M_NOP; \ - M_NOP; \ + emit_nop(cd, 2); \ } while (0) diff --git a/src/vm/jit/x86_64/emit.c b/src/vm/jit/x86_64/emit.c index 83dcdc401..7a4c65a39 100644 --- a/src/vm/jit/x86_64/emit.c +++ b/src/vm/jit/x86_64/emit.c @@ -1205,6 +1205,76 @@ void emit_lshift(jitdata *jd, s4 shift_op, instruction *iptr) /* low-level code emitter functions *******************************************/ +void emit_nop(codegendata *cd, int length) +{ + assert(length >= 1 && length <= 9); + switch (length) { + case 1: + *(cd->mcodeptr++) = 0x90; + break; + case 2: + *(cd->mcodeptr++) = 0x66; + *(cd->mcodeptr++) = 0x90; + break; + case 3: + *(cd->mcodeptr++) = 0x0f; + *(cd->mcodeptr++) = 0x1f; + *(cd->mcodeptr++) = 0x00; + break; + case 4: + *(cd->mcodeptr++) = 0x0f; + *(cd->mcodeptr++) = 0x1f; + *(cd->mcodeptr++) = 0x40; + *(cd->mcodeptr++) = 0x00; + break; + case 5: + *(cd->mcodeptr++) = 0x0f; + *(cd->mcodeptr++) = 0x1f; + *(cd->mcodeptr++) = 0x44; + *(cd->mcodeptr++) = 0x00; + *(cd->mcodeptr++) = 0x00; + break; + case 6: + *(cd->mcodeptr++) = 0x66; + *(cd->mcodeptr++) = 0x0f; + *(cd->mcodeptr++) = 0x1f; + *(cd->mcodeptr++) = 0x44; + *(cd->mcodeptr++) = 0x00; + *(cd->mcodeptr++) = 0x00; + break; + case 7: + *(cd->mcodeptr++) = 0x0f; + *(cd->mcodeptr++) = 0x1f; + *(cd->mcodeptr++) = 0x80; + *(cd->mcodeptr++) = 0x00; + *(cd->mcodeptr++) = 0x00; + *(cd->mcodeptr++) = 0x00; + *(cd->mcodeptr++) = 0x00; + break; + case 8: + *(cd->mcodeptr++) = 0x0f; + *(cd->mcodeptr++) = 0x1f; + *(cd->mcodeptr++) = 0x84; + *(cd->mcodeptr++) = 0x00; + *(cd->mcodeptr++) = 0x00; + *(cd->mcodeptr++) = 0x00; + *(cd->mcodeptr++) = 0x00; + *(cd->mcodeptr++) = 0x00; + break; + case 9: + *(cd->mcodeptr++) = 0x66; + *(cd->mcodeptr++) = 0x0f; + *(cd->mcodeptr++) = 0x1f; + *(cd->mcodeptr++) = 0x84; + *(cd->mcodeptr++) = 0x00; + *(cd->mcodeptr++) = 0x00; + *(cd->mcodeptr++) = 0x00; + *(cd->mcodeptr++) = 0x00; + *(cd->mcodeptr++) = 0x00; + break; + } +} + void emit_mov_reg_reg(codegendata *cd, s8 reg, s8 dreg) { emit_rex(1,(reg),0,(dreg)); diff --git a/src/vm/jit/x86_64/emit.h b/src/vm/jit/x86_64/emit.h index be63a5034..ebf6e361f 100644 --- a/src/vm/jit/x86_64/emit.h +++ b/src/vm/jit/x86_64/emit.h @@ -193,6 +193,7 @@ void emit_lshift(jitdata *jd, s4 shift_op, instruction *iptr); /* integer instructions */ +void emit_nop(codegendata *cd, int length); void emit_mov_reg_reg(codegendata *cd, s8 reg, s8 dreg); void emit_mov_imm_reg(codegendata *cd, s8 imm, s8 reg); void emit_movl_reg_reg(codegendata *cd, s8 reg, s8 dreg); -- 2.25.1