#endif
typedef uint16_t dfsan_label;
+typedef uint32_t dfsan_origin;
/// Stores information associated with a specific label identifier. A label
/// may be a base label created using dfsan_create_label, with associated
// | |
// | unused |
// | |
-// +--------------------+ 0x200200000000 (kUnusedAddr)
+// +--------------------+ 0x300200000000 (kUnusedAddr)
// | union table |
-// +--------------------+ 0x200000000000 (kUnionTableAddr)
+// +--------------------+ 0x300000000000 (kUnionTableAddr)
+// | origin |
+// +--------------------+ 0x200000000000 (kOriginAddr)
// | shadow memory |
// +--------------------+ 0x000000010000 (kShadowAddr)
// | reserved by kernel |
#include "dfsan_flags.h"
#include "dfsan_platform.h"
-using __sanitizer::uptr;
using __sanitizer::u16;
+using __sanitizer::u32;
+using __sanitizer::uptr;
// Copy declarations from public sanitizer/dfsan_interface.h header here.
typedef u16 dfsan_label;
+typedef u32 dfsan_origin;
struct dfsan_label_info {
dfsan_label l1;
return shadow_for(const_cast<void *>(ptr));
}
+inline uptr unaligned_origin_for(uptr ptr) {
+ return OriginAddr() + (ptr & ShadowMask());
+}
+
+inline dfsan_origin *origin_for(void *ptr) {
+ auto aligned_addr = unaligned_origin_for(reinterpret_cast<uptr>(ptr)) &
+ ~(sizeof(dfsan_origin) - 1);
+ return reinterpret_cast<dfsan_origin *>(aligned_addr);
+}
+
+inline const dfsan_origin *origin_for(const void *ptr) {
+ return origin_for(const_cast<void *>(ptr));
+}
+
+inline bool is_shadow_addr_valid(uptr shadow_addr) {
+ return (uptr)shadow_addr >= ShadowAddr() && (uptr)shadow_addr < OriginAddr();
+}
+
+inline bool has_valid_shadow_addr(const void *ptr) {
+ const dfsan_label *ptr_s = shadow_for(ptr);
+ return is_shadow_addr_valid((uptr)ptr_s);
+}
+
} // namespace __dfsan
#endif // DFSAN_H
#if defined(__x86_64__)
struct Mapping {
static const uptr kShadowAddr = 0x10000;
- static const uptr kUnionTableAddr = 0x200000000000;
+ static const uptr kOriginAddr = 0x200000000000;
+ static const uptr kUnionTableAddr = 0x300000000000;
static const uptr kAppAddr = 0x700000008000;
static const uptr kShadowMask = ~0x700000000000;
};
enum MappingType {
MAPPING_SHADOW_ADDR,
+#if defined(__x86_64__)
+ MAPPING_ORIGIN_ADDR,
+#endif
MAPPING_UNION_TABLE_ADDR,
MAPPING_APP_ADDR,
MAPPING_SHADOW_MASK
uptr MappingImpl(void) {
switch (Type) {
case MAPPING_SHADOW_ADDR: return Mapping::kShadowAddr;
+#if defined(__x86_64__)
+ case MAPPING_ORIGIN_ADDR:
+ return Mapping::kOriginAddr;
+#endif
case MAPPING_UNION_TABLE_ADDR: return Mapping::kUnionTableAddr;
case MAPPING_APP_ADDR: return Mapping::kAppAddr;
case MAPPING_SHADOW_MASK: return Mapping::kShadowMask;
return MappingArchImpl<MAPPING_SHADOW_ADDR>();
}
+#if defined(__x86_64__)
+ALWAYS_INLINE
+uptr OriginAddr() { return MappingArchImpl<MAPPING_ORIGIN_ADDR>(); }
+#endif
+
ALWAYS_INLINE
uptr UnionTableAddr() {
return MappingArchImpl<MAPPING_UNION_TABLE_ADDR>();