[dfsan] Introduce dfsan_read_label runtime function.
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 13 Aug 2013 22:15:40 +0000 (22:15 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Tue, 13 Aug 2013 22:15:40 +0000 (22:15 +0000)
Differential Revision: http://llvm-reviews.chandlerc.com/D1349

llvm-svn: 188319

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

index 3399c24f3071a09e3f3ed49440d0424b4cddbe34..f14d45a2b2a1d19a8b95fe470f5c4f040059c4c0 100644 (file)
@@ -61,6 +61,9 @@ void dfsan_add_label(dfsan_label label, void *addr, size_t size);
 /// 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);
 
index c8b0e6851ec584d3a6bbf2c3aa1372df436e306d..ba8e8b5112ecbece93c6f6dc8b649fa33224ec3b 100644 (file)
@@ -120,7 +120,7 @@ dfsan_label __dfsan_union(dfsan_label l1, dfsan_label l2) {
 }
 
 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_label dfsan_get_label(long data) {
   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.
index db1acb71208651dcef159a20ae3e48a3f86e7020..de11bd186e95ff82b7fb1c3f31300416d74c422b 100644 (file)
@@ -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;
 }
index d78c9ae0b33136e52d2098e11405565a060c4ae7..31b65ee72a44c66a23d7ea44279c436bf22ac145 100644 (file)
@@ -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;
 }