[compiler-rt] r188319 - [dfsan] Introduce dfsan_read_label runtime function.

Peter Collingbourne peter at pcc.me.uk
Tue Aug 13 15:15:40 PDT 2013


Author: pcc
Date: Tue Aug 13 17:15:40 2013
New Revision: 188319

URL: http://llvm.org/viewvc/llvm-project?rev=188319&view=rev
Log:
[dfsan] Introduce dfsan_read_label runtime function.

Differential Revision: http://llvm-reviews.chandlerc.com/D1349

Modified:
    compiler-rt/trunk/include/sanitizer/dfsan_interface.h
    compiler-rt/trunk/lib/dfsan/dfsan.cc
    compiler-rt/trunk/lib/dfsan/lit_tests/basic.c
    compiler-rt/trunk/lib/dfsan/lit_tests/propagate.c

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=188319&r1=188318&r2=188319&view=diff
==============================================================================
--- compiler-rt/trunk/include/sanitizer/dfsan_interface.h (original)
+++ compiler-rt/trunk/include/sanitizer/dfsan_interface.h Tue Aug 13 17:15:40 2013
@@ -61,6 +61,9 @@ void dfsan_add_label(dfsan_label label,
 /// value.
 dfsan_label dfsan_get_label(long data);
 
+/// Retrieves the label associated with the data at the given address.
+dfsan_label dfsan_read_label(const void *addr, size_t size);
+
 /// Retrieves a pointer to the dfsan_label_info struct for the given label.
 const struct dfsan_label_info *dfsan_get_label_info(dfsan_label label);
 

Modified: compiler-rt/trunk/lib/dfsan/dfsan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan.cc?rev=188319&r1=188318&r2=188319&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan.cc Tue Aug 13 17:15:40 2013
@@ -120,7 +120,7 @@ dfsan_label __dfsan_union(dfsan_label l1
 }
 
 extern "C" SANITIZER_INTERFACE_ATTRIBUTE
-dfsan_label __dfsan_union_load(dfsan_label *ls, size_t n) {
+dfsan_label __dfsan_union_load(const dfsan_label *ls, size_t n) {
   dfsan_label label = ls[0];
   for (size_t i = 1; i != n; ++i) {
     dfsan_label next_label = ls[i];
@@ -171,6 +171,13 @@ SANITIZER_INTERFACE_ATTRIBUTE dfsan_labe
   return __dfsan_arg_tls[0];
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE dfsan_label
+dfsan_read_label(const void *addr, size_t size) {
+  if (size == 0)
+    return 0;
+  return __dfsan_union_load(shadow_for(addr), size);
+}
+
 SANITIZER_INTERFACE_ATTRIBUTE
 const struct dfsan_label_info *dfsan_get_label_info(dfsan_label label) {
   __dfsan_retval_tls = 0;  // Ensures return value is unlabelled in the caller.

Modified: compiler-rt/trunk/lib/dfsan/lit_tests/basic.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/lit_tests/basic.c?rev=188319&r1=188318&r2=188319&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/lit_tests/basic.c (original)
+++ compiler-rt/trunk/lib/dfsan/lit_tests/basic.c Tue Aug 13 17:15:40 2013
@@ -13,5 +13,8 @@ int main(void) {
   dfsan_label new_label = dfsan_get_label(i);
   assert(i_label == new_label);
 
+  dfsan_label read_label = dfsan_read_label(&i, sizeof(i));
+  assert(i_label == read_label);
+
   return 0;
 }

Modified: compiler-rt/trunk/lib/dfsan/lit_tests/propagate.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/lit_tests/propagate.c?rev=188319&r1=188318&r2=188319&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/lit_tests/propagate.c (original)
+++ compiler-rt/trunk/lib/dfsan/lit_tests/propagate.c Tue Aug 13 17:15:40 2013
@@ -34,5 +34,8 @@ int main(void) {
   assert(dfsan_has_label(ijk_label, j_label));
   assert(dfsan_has_label(ijk_label, k_label));
 
+  struct { int i, j; } s = { i, j };
+  assert(dfsan_read_label(&s, sizeof(s)) == ij_label);
+
   return 0;
 }





More information about the llvm-commits mailing list