[compiler-rt] r236679 - Add dfsan_weak_hook_memcmp

Kostya Serebryany kcc at google.com
Wed May 6 17:04:39 PDT 2015


Author: kcc
Date: Wed May  6 19:04:39 2015
New Revision: 236679

URL: http://llvm.org/viewvc/llvm-project?rev=236679&view=rev
Log:
Add dfsan_weak_hook_memcmp

Summary:
Add a weak hook to be called from dfsan's custom memcmp.
The primary user will be lib/Fuzzer.
If this works well we'll add more hooks (strcmp, etc).

Test Plan: Will be covered by lib/Fuzzer tests.

Reviewers: pcc

Reviewed By: pcc

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D9541

Modified:
    compiler-rt/trunk/include/sanitizer/dfsan_interface.h
    compiler-rt/trunk/lib/dfsan/dfsan_custom.cc

Modified: compiler-rt/trunk/include/sanitizer/dfsan_interface.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/dfsan_interface.h?rev=236679&r1=236678&r2=236679&view=diff
==============================================================================
--- compiler-rt/trunk/include/sanitizer/dfsan_interface.h (original)
+++ compiler-rt/trunk/include/sanitizer/dfsan_interface.h Wed May  6 19:04:39 2015
@@ -91,6 +91,16 @@ void dfsan_set_write_callback(dfsan_writ
 /// <label> <parent label 1> <parent label 2> <label description if any>
 void dfsan_dump_labels(int fd);
 
+/// Whenever a dfsan's custom function is called the corresponding
+/// hook is called it non-zero. The hooks should be defined by the user.
+/// The primary use case is taint-guided fuzzing, where the fuzzer
+/// needs to see the parameters of the function and the labels.
+/// FIXME: implement more hooks.
+
+/// memcmp hook.
+void dfsan_weak_hook_memcmp(void *caller_pc, const void *s1, const void *s2,
+                            size_t n, dfsan_label s1_label,
+                            dfsan_label s2_label, dfsan_label n_label);
 #ifdef __cplusplus
 }  // extern "C"
 

Modified: compiler-rt/trunk/lib/dfsan/dfsan_custom.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan_custom.cc?rev=236679&r1=236678&r2=236679&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan_custom.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan_custom.cc Wed May  6 19:04:39 2015
@@ -82,11 +82,20 @@ SANITIZER_INTERFACE_ATTRIBUTE char *__df
   }
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
+void
+dfsan_weak_hook_memcmp(uptr caller_pc, const void *s1, const void *s2, size_t n,
+                       dfsan_label s1_label, dfsan_label s2_label,
+                       dfsan_label n_label);
+
 SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_memcmp(const void *s1, const void *s2,
                                                 size_t n, dfsan_label s1_label,
                                                 dfsan_label s2_label,
                                                 dfsan_label n_label,
                                                 dfsan_label *ret_label) {
+  if (dfsan_weak_hook_memcmp)
+    dfsan_weak_hook_memcmp(GET_CALLER_PC(), s1, s2, n, s1_label, s2_label,
+                           n_label);
   const char *cs1 = (const char *) s1, *cs2 = (const char *) s2;
   for (size_t i = 0; i != n; ++i) {
     if (cs1[i] != cs2[i]) {





More information about the llvm-commits mailing list