1 //===-- dfsan.h -------------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file is a part of DataFlowSanitizer. 10 // 11 // Private DFSan header. 12 //===----------------------------------------------------------------------===// 13 14 #ifndef DFSAN_H 15 #define DFSAN_H 16 17 #include "sanitizer_common/sanitizer_internal_defs.h" 18 #include "dfsan_platform.h" 19 20 using __sanitizer::uptr; 21 using __sanitizer::u16; 22 23 // Copy declarations from public sanitizer/dfsan_interface.h header here. 24 typedef u16 dfsan_label; 25 26 struct dfsan_label_info { 27 dfsan_label l1; 28 dfsan_label l2; 29 const char *desc; 30 void *userdata; 31 }; 32 33 extern "C" { 34 void dfsan_add_label(dfsan_label label, void *addr, uptr size); 35 void dfsan_set_label(dfsan_label label, void *addr, uptr size); 36 dfsan_label dfsan_read_label(const void *addr, uptr size); 37 dfsan_label dfsan_union(dfsan_label l1, dfsan_label l2); 38 } // extern "C" 39 40 template <typename T> 41 void dfsan_set_label(dfsan_label label, T &data) { // NOLINT 42 dfsan_set_label(label, (void *)&data, sizeof(T)); 43 } 44 45 namespace __dfsan { 46 47 void InitializeInterceptors(); 48 49 inline dfsan_label *shadow_for(void *ptr) { 50 return (dfsan_label *) ((((uptr) ptr) & ShadowMask()) << 1); 51 } 52 53 inline const dfsan_label *shadow_for(const void *ptr) { 54 return shadow_for(const_cast<void *>(ptr)); 55 } 56 57 struct Flags { 58 #define DFSAN_FLAG(Type, Name, DefaultValue, Description) Type Name; 59 #include "dfsan_flags.inc" 60 #undef DFSAN_FLAG 61 62 void SetDefaults(); 63 }; 64 65 extern Flags flags_data; 66 inline Flags &flags() { 67 return flags_data; 68 } 69 70 } // namespace __dfsan 71 72 #endif // DFSAN_H 73