Home | History | Annotate | Line # | Download | only in ubsan
ubsan_handlers.h revision 1.1.1.1
      1  1.1  mrg //===-- ubsan_handlers.h ----------------------------------------*- C++ -*-===//
      2  1.1  mrg //
      3  1.1  mrg // This file is distributed under the University of Illinois Open Source
      4  1.1  mrg // License. See LICENSE.TXT for details.
      5  1.1  mrg //
      6  1.1  mrg //===----------------------------------------------------------------------===//
      7  1.1  mrg //
      8  1.1  mrg // Entry points to the runtime library for Clang's undefined behavior sanitizer.
      9  1.1  mrg //
     10  1.1  mrg //===----------------------------------------------------------------------===//
     11  1.1  mrg #ifndef UBSAN_HANDLERS_H
     12  1.1  mrg #define UBSAN_HANDLERS_H
     13  1.1  mrg 
     14  1.1  mrg #include "ubsan_value.h"
     15  1.1  mrg 
     16  1.1  mrg namespace __ubsan {
     17  1.1  mrg 
     18  1.1  mrg struct TypeMismatchData {
     19  1.1  mrg   SourceLocation Loc;
     20  1.1  mrg   const TypeDescriptor &Type;
     21  1.1  mrg   uptr Alignment;
     22  1.1  mrg   unsigned char TypeCheckKind;
     23  1.1  mrg };
     24  1.1  mrg 
     25  1.1  mrg #define UNRECOVERABLE(checkname, ...) \
     26  1.1  mrg   extern "C" SANITIZER_INTERFACE_ATTRIBUTE NORETURN \
     27  1.1  mrg     void __ubsan_handle_ ## checkname( __VA_ARGS__ );
     28  1.1  mrg 
     29  1.1  mrg #define RECOVERABLE(checkname, ...) \
     30  1.1  mrg   extern "C" SANITIZER_INTERFACE_ATTRIBUTE \
     31  1.1  mrg     void __ubsan_handle_ ## checkname( __VA_ARGS__ ); \
     32  1.1  mrg   extern "C" SANITIZER_INTERFACE_ATTRIBUTE NORETURN \
     33  1.1  mrg     void __ubsan_handle_ ## checkname ## _abort( __VA_ARGS__ );
     34  1.1  mrg 
     35  1.1  mrg /// \brief Handle a runtime type check failure, caused by either a misaligned
     36  1.1  mrg /// pointer, a null pointer, or a pointer to insufficient storage for the
     37  1.1  mrg /// type.
     38  1.1  mrg RECOVERABLE(type_mismatch, TypeMismatchData *Data, ValueHandle Pointer)
     39  1.1  mrg 
     40  1.1  mrg struct OverflowData {
     41  1.1  mrg   SourceLocation Loc;
     42  1.1  mrg   const TypeDescriptor &Type;
     43  1.1  mrg };
     44  1.1  mrg 
     45  1.1  mrg /// \brief Handle an integer addition overflow.
     46  1.1  mrg RECOVERABLE(add_overflow, OverflowData *Data, ValueHandle LHS, ValueHandle RHS)
     47  1.1  mrg 
     48  1.1  mrg /// \brief Handle an integer subtraction overflow.
     49  1.1  mrg RECOVERABLE(sub_overflow, OverflowData *Data, ValueHandle LHS, ValueHandle RHS)
     50  1.1  mrg 
     51  1.1  mrg /// \brief Handle an integer multiplication overflow.
     52  1.1  mrg RECOVERABLE(mul_overflow, OverflowData *Data, ValueHandle LHS, ValueHandle RHS)
     53  1.1  mrg 
     54  1.1  mrg /// \brief Handle a signed integer overflow for a unary negate operator.
     55  1.1  mrg RECOVERABLE(negate_overflow, OverflowData *Data, ValueHandle OldVal)
     56  1.1  mrg 
     57  1.1  mrg /// \brief Handle an INT_MIN/-1 overflow or division by zero.
     58  1.1  mrg RECOVERABLE(divrem_overflow, OverflowData *Data,
     59  1.1  mrg             ValueHandle LHS, ValueHandle RHS)
     60  1.1  mrg 
     61  1.1  mrg struct ShiftOutOfBoundsData {
     62  1.1  mrg   SourceLocation Loc;
     63  1.1  mrg   const TypeDescriptor &LHSType;
     64  1.1  mrg   const TypeDescriptor &RHSType;
     65  1.1  mrg };
     66  1.1  mrg 
     67  1.1  mrg /// \brief Handle a shift where the RHS is out of bounds or a left shift where
     68  1.1  mrg /// the LHS is negative or overflows.
     69  1.1  mrg RECOVERABLE(shift_out_of_bounds, ShiftOutOfBoundsData *Data,
     70  1.1  mrg             ValueHandle LHS, ValueHandle RHS)
     71  1.1  mrg 
     72  1.1  mrg struct OutOfBoundsData {
     73  1.1  mrg   SourceLocation Loc;
     74  1.1  mrg   const TypeDescriptor &ArrayType;
     75  1.1  mrg   const TypeDescriptor &IndexType;
     76  1.1  mrg };
     77  1.1  mrg 
     78  1.1  mrg /// \brief Handle an array index out of bounds error.
     79  1.1  mrg RECOVERABLE(out_of_bounds, OutOfBoundsData *Data, ValueHandle Index)
     80  1.1  mrg 
     81  1.1  mrg struct UnreachableData {
     82  1.1  mrg   SourceLocation Loc;
     83  1.1  mrg };
     84  1.1  mrg 
     85  1.1  mrg /// \brief Handle a __builtin_unreachable which is reached.
     86  1.1  mrg UNRECOVERABLE(builtin_unreachable, UnreachableData *Data)
     87  1.1  mrg /// \brief Handle reaching the end of a value-returning function.
     88  1.1  mrg UNRECOVERABLE(missing_return, UnreachableData *Data)
     89  1.1  mrg 
     90  1.1  mrg struct VLABoundData {
     91  1.1  mrg   SourceLocation Loc;
     92  1.1  mrg   const TypeDescriptor &Type;
     93  1.1  mrg };
     94  1.1  mrg 
     95  1.1  mrg /// \brief Handle a VLA with a non-positive bound.
     96  1.1  mrg RECOVERABLE(vla_bound_not_positive, VLABoundData *Data, ValueHandle Bound)
     97  1.1  mrg 
     98  1.1  mrg struct FloatCastOverflowData {
     99  1.1  mrg   // FIXME: SourceLocation Loc;
    100  1.1  mrg   const TypeDescriptor &FromType;
    101  1.1  mrg   const TypeDescriptor &ToType;
    102  1.1  mrg };
    103  1.1  mrg 
    104  1.1  mrg /// \brief Handle overflow in a conversion to or from a floating-point type.
    105  1.1  mrg RECOVERABLE(float_cast_overflow, FloatCastOverflowData *Data, ValueHandle From)
    106  1.1  mrg 
    107  1.1  mrg struct InvalidValueData {
    108  1.1  mrg   SourceLocation Loc;
    109  1.1  mrg   const TypeDescriptor &Type;
    110  1.1  mrg };
    111  1.1  mrg 
    112  1.1  mrg /// \brief Handle a load of an invalid value for the type.
    113  1.1  mrg RECOVERABLE(load_invalid_value, InvalidValueData *Data, ValueHandle Val)
    114  1.1  mrg 
    115  1.1  mrg struct FunctionTypeMismatchData {
    116  1.1  mrg   SourceLocation Loc;
    117  1.1  mrg   const TypeDescriptor &Type;
    118  1.1  mrg };
    119  1.1  mrg 
    120  1.1  mrg RECOVERABLE(function_type_mismatch,
    121  1.1  mrg             FunctionTypeMismatchData *Data,
    122  1.1  mrg             ValueHandle Val)
    123  1.1  mrg 
    124  1.1  mrg struct NonNullReturnData {
    125  1.1  mrg   SourceLocation Loc;
    126  1.1  mrg   SourceLocation AttrLoc;
    127  1.1  mrg };
    128  1.1  mrg 
    129  1.1  mrg /// \brief Handle returning null from function with returns_nonnull attribute.
    130  1.1  mrg RECOVERABLE(nonnull_return, NonNullReturnData *Data)
    131  1.1  mrg 
    132  1.1  mrg struct NonNullArgData {
    133  1.1  mrg   SourceLocation Loc;
    134  1.1  mrg   SourceLocation AttrLoc;
    135  1.1  mrg   int ArgIndex;
    136  1.1  mrg };
    137  1.1  mrg 
    138  1.1  mrg /// \brief Handle passing null pointer to function with nonnull attribute.
    139  1.1  mrg RECOVERABLE(nonnull_arg, NonNullArgData *Data)
    140  1.1  mrg 
    141  1.1  mrg }
    142  1.1  mrg 
    143  1.1  mrg #endif // UBSAN_HANDLERS_H
    144