about summary refs log tree commit diff
path: root/llvm_mode
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2020-04-08 12:52:14 +0200
committervan Hauser <vh@thc.org>2020-04-09 10:23:37 +0200
commit1d1f575b5c1c40e26cc9e183bbc526e5dc1bd4cf (patch)
treef2b405207a063e88d78884939dc084768526fbcb /llvm_mode
parentecdffa03f811748f096d4ecdf9d6f2e0f6e5cd51 (diff)
downloadafl++-1d1f575b5c1c40e26cc9e183bbc526e5dc1bd4cf.tar.gz
add missing piece for CTX coverage
Diffstat (limited to 'llvm_mode')
-rw-r--r--llvm_mode/afl-llvm-pass.so.cc16
-rw-r--r--llvm_mode/afl-llvm-rt.o.c2
2 files changed, 18 insertions, 0 deletions
diff --git a/llvm_mode/afl-llvm-pass.so.cc b/llvm_mode/afl-llvm-pass.so.cc
index 31d00fec..058ab71f 100644
--- a/llvm_mode/afl-llvm-pass.so.cc
+++ b/llvm_mode/afl-llvm-pass.so.cc
@@ -682,6 +682,22 @@ bool AFLCoverage::runOnModule(Module &M) {
 
       }
 
+      // in CTX mode we have to restore the original context for the caller -
+      // she might be calling other functions which need the correct CTX
+      if (ctx_str) {
+
+        Instruction *Inst = BB.getTerminator();
+        if (isa<ReturnInst>(Inst) || isa<ResumeInst>(Inst)) {
+
+          IRBuilder<> Post_IRB(Inst);
+          StoreInst * RestoreCtx = Post_IRB.CreateStore(PrevCtx, AFLContext);
+          RestoreCtx->setMetadata(M.getMDKindID("nosanitize"),
+                                  MDNode::get(C, None));
+
+        }
+
+      }
+
       inst_blocks++;
 
     }
diff --git a/llvm_mode/afl-llvm-rt.o.c b/llvm_mode/afl-llvm-rt.o.c
index f6c60a11..aac7d061 100644
--- a/llvm_mode/afl-llvm-rt.o.c
+++ b/llvm_mode/afl-llvm-rt.o.c
@@ -273,6 +273,7 @@ static void __afl_start_snapshots(void) {
   }
 
 }
+
 #endif
 
 /* Fork server logic. */
@@ -287,6 +288,7 @@ static void __afl_start_forkserver(void) {
     return;
 
   }
+
 #endif
 
   static u8 tmp[4];