From c00b8e4b5d8179be5c34b9d7b3fcfc3cb364b86b Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Mon, 27 Aug 2012 11:10:08 +0200 Subject: [PATCH] traps: delete traps... TODO --- Mate/X86TrapHandling.hs | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/Mate/X86TrapHandling.hs b/Mate/X86TrapHandling.hs index 520e177..23be786 100644 --- a/Mate/X86TrapHandling.hs +++ b/Mate/X86TrapHandling.hs @@ -30,19 +30,34 @@ foreign export ccall mateHandler :: CPtrdiff -> CPtrdiff -> CPtrdiff -> CPtrdiff mateHandler :: CPtrdiff -> CPtrdiff -> CPtrdiff -> CPtrdiff -> IO CPtrdiff mateHandler reip reax rebx resi = do tmap <- getTrapMap - case M.lookup (fromIntegral reip) tmap of - (Just (StaticMethod _)) -> patchWithHarpy patchStaticCall reip - (Just (StaticField _)) -> staticFieldHandler reip - (Just (InstanceOf cn)) -> patchWithHarpy (`patchInstanceOf` cn) reip - (Just (NewObject cn)) -> patchWithHarpy (`patchNewObject` cn) reip + let reipw32 = fromIntegral reip + (deleteMe, ret_nreip) <- case M.lookup reipw32 tmap of + (Just (StaticMethod _)) -> + patchWithHarpy patchStaticCall reip >>= delTrue + (Just (StaticField _)) -> + staticFieldHandler reip >>= delTrue + (Just (InstanceOf cn)) -> + patchWithHarpy (`patchInstanceOf` cn) reip >>= delFalse + (Just (NewObject cn)) -> + patchWithHarpy (`patchNewObject` cn) reip >>= delTrue (Just (VirtualCall False _ io_offset)) -> - patchWithHarpy (patchInvoke reax reax io_offset) reip + patchWithHarpy (patchInvoke reax reax io_offset) reip + >>= delTrue (Just (VirtualCall True _ io_offset)) -> - patchWithHarpy (patchInvoke rebx reax io_offset) reip + patchWithHarpy (patchInvoke rebx reax io_offset) reip + >>= delTrue Nothing -> case resi of - 0x13371234 -> return (-1) + 0x13371234 -> return (-1) >>= delFalse _ -> error $ "getTrapType: abort :-( " ++ (showHex reip ". ") ++ (concatMap (`showHex` ", ") (M.keys tmap)) + if deleteMe + then setTrapMap $ M.delete reipw32 tmap + else return () + return ret_nreip + where + delTrue = (\nreip -> return (False, nreip)) + delFalse = (\nreip -> return (False, nreip)) + patchWithHarpy :: (CPtrdiff -> CodeGen () () CPtrdiff) -> CPtrdiff -> IO CPtrdiff patchWithHarpy patcher reip = do @@ -52,7 +67,9 @@ patchWithHarpy patcher reip = do let entry = Just (intPtrToPtr (fromIntegral reip), fixme) let cgconfig = defaultCodeGenConfig { customCodeBuffer = entry } (_, Right right) <- runCodeGenWithConfig (withDisasm $ patcher reip) () () cgconfig - mapM_ (printfJit . printf "patched: %s\n" . showAtt) $ snd right + if mateDEBUG + then mapM_ (printfJit . printf "patched: %s\n" . showAtt) $ snd right + else return () return reip withDisasm :: CodeGen e s CPtrdiff -> CodeGen e s (CPtrdiff, [Instruction]) -- 2.25.1