From 4fdea0a41c8893e3ef258b44aa696dcbe8e71f1e Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Sun, 22 Apr 2012 20:42:50 +0200 Subject: [PATCH] trap: give disasm some nop's, so it shows the label the disasm doesn't show labels on invalid opcode, but that's convenient when debugging. one can argue it's not really efficient here, because two cycles are wastet. imho that's not true, since modern x86 cpu's eliminate such instructions sequences. we could benchmark/test that, but well, it's just on the first hit, so suck it. --- Mate/X86CodeGen.hs | 2 +- ffi/trap.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Mate/X86CodeGen.hs b/Mate/X86CodeGen.hs index df251a6..d2d62c2 100644 --- a/Mate/X86CodeGen.hs +++ b/Mate/X86CodeGen.hs @@ -179,7 +179,7 @@ emitFromBB cls hmap = do newNamedLabel (toString l) >>= defineLabel -- causes SIGILL. in the signal handler we patch it to the acutal call. -- place a nop at the end, therefore the disasm doesn't screw up - emit32 (0xffffffff :: Word32) >> emit8 (0x90 :: Word8) + emit32 (0xffff9090 :: Word32) >> emit8 (0x90 :: Word8) -- discard arguments on stack let argcnt = (methodGetArgsCount cls cpidx) * 4 when (argcnt > 0) (add esp argcnt) diff --git a/ffi/trap.c b/ffi/trap.c index 2073dae..0e1c873 100644 --- a/ffi/trap.c +++ b/ffi/trap.c @@ -54,7 +54,7 @@ void mainresult(unsigned int a) void callertrap(int nSignal, siginfo_t *info, void *ctx) { struct ucontext *uctx = (struct ucontext *) ctx; - unsigned int from = (unsigned int) uctx->uc_mcontext.eip; + unsigned int from = (unsigned int) uctx->uc_mcontext.eip - 2; unsigned int patchme = getMethodEntry(from, method_map, caller_map); printf("callertrap(mctx) by 0x%08x\n", from); @@ -64,7 +64,7 @@ void callertrap(int nSignal, siginfo_t *info, void *ctx) *insn = 0xe8; // call opcode printf(" to_patch: 0x%08x\n", (unsigned int) to_patch); printf("*to_patch: 0x%08x\n", *to_patch); - if (*to_patch != 0x90ffffff) { + if (*to_patch != 0x90ffff90) { printf("something is wrong here. abort\n"); exit(0); } -- 2.25.1