1 //===-- ubsan_type_hash.h ---------------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // Hashing of types for Clang's undefined behavior checker.
10 //===----------------------------------------------------------------------===//
11 #ifndef UBSAN_TYPE_HASH_H
12 #define UBSAN_TYPE_HASH_H
14 #include "sanitizer_common/sanitizer_common.h"
18 typedef uptr HashValue
;
20 /// \brief Information about the dynamic type of an object (extracted from its
22 class DynamicTypeInfo
{
23 const char *MostDerivedTypeName
;
25 const char *SubobjectTypeName
;
28 DynamicTypeInfo(const char *MDTN
, sptr Offset
, const char *STN
)
29 : MostDerivedTypeName(MDTN
), Offset(Offset
), SubobjectTypeName(STN
) {}
31 /// Determine whether the object had a valid dynamic type.
32 bool isValid() const { return MostDerivedTypeName
; }
33 /// Get the name of the most-derived type of the object.
34 const char *getMostDerivedTypeName() const { return MostDerivedTypeName
; }
35 /// Get the offset from the most-derived type to this base class.
36 sptr
getOffset() const { return Offset
; }
37 /// Get the name of the most-derived type at the specified offset.
38 const char *getSubobjectTypeName() const { return SubobjectTypeName
; }
41 /// \brief Get information about the dynamic type of an object.
42 DynamicTypeInfo
getDynamicTypeInfo(void *Object
);
44 /// \brief Check whether the dynamic type of \p Object has a \p Type subobject
46 /// \return \c true if the type matches, \c false if not.
47 bool checkDynamicType(void *Object
, void *Type
, HashValue Hash
);
49 const unsigned VptrTypeCacheSize
= 128;
51 /// \brief A cache of the results of checkDynamicType. \c checkDynamicType would
52 /// return \c true (modulo hash collisions) if
54 /// __ubsan_vptr_type_cache[Hash % VptrTypeCacheSize] == Hash
56 extern "C" SANITIZER_INTERFACE_ATTRIBUTE
57 HashValue __ubsan_vptr_type_cache
[VptrTypeCacheSize
];
59 } // namespace __ubsan
61 #endif // UBSAN_TYPE_HASH_H