trap: give disasm some nop's, so it shows the label
authorBernhard Urban <lewurm@gmail.com>
Sun, 22 Apr 2012 18:42:50 +0000 (20:42 +0200)
committerBernhard Urban <lewurm@gmail.com>
Sun, 22 Apr 2012 18:42:50 +0000 (20:42 +0200)
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
ffi/trap.c

index df251a67abc38ef3d06ec948b7f20638088ab521..d2d62c27944bdf86b520058a42d7b6a4813df2e7 100644 (file)
@@ -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)
index 2073dae2ec285afe4c1a89343654d1a189882a00..0e1c8735c9d9a640924177925ad1a153bd68dea5 100644 (file)
@@ -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);
        }