b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) /* SPDX-License-Identifier: GPL-2.0 */
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 2) #ifndef _LIB_UBSAN_H
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 3) #define _LIB_UBSAN_H
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 4)
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 5) enum {
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 6) type_kind_int = 0,
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 7) type_kind_float = 1,
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 8) type_unknown = 0xffff
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 9) };
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 10)
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 11) struct type_descriptor {
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 12) u16 type_kind;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 13) u16 type_info;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 14) char type_name[1];
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 15) };
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 16)
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 17) struct source_location {
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 18) const char *file_name;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 19) union {
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 20) unsigned long reported;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 21) struct {
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 22) u32 line;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 23) u32 column;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 24) };
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 25) };
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 26) };
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 27)
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 28) struct overflow_data {
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 29) struct source_location location;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 30) struct type_descriptor *type;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 31) };
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 32)
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 33) struct type_mismatch_data {
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 34) struct source_location location;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 35) struct type_descriptor *type;
42440c1f9911b (Andrey Ryabinin 2018-02-06 15:40:42 -0800 36) unsigned long alignment;
42440c1f9911b (Andrey Ryabinin 2018-02-06 15:40:42 -0800 37) unsigned char type_check_kind;
42440c1f9911b (Andrey Ryabinin 2018-02-06 15:40:42 -0800 38) };
42440c1f9911b (Andrey Ryabinin 2018-02-06 15:40:42 -0800 39)
42440c1f9911b (Andrey Ryabinin 2018-02-06 15:40:42 -0800 40) struct type_mismatch_data_v1 {
42440c1f9911b (Andrey Ryabinin 2018-02-06 15:40:42 -0800 41) struct source_location location;
42440c1f9911b (Andrey Ryabinin 2018-02-06 15:40:42 -0800 42) struct type_descriptor *type;
42440c1f9911b (Andrey Ryabinin 2018-02-06 15:40:42 -0800 43) unsigned char log_alignment;
42440c1f9911b (Andrey Ryabinin 2018-02-06 15:40:42 -0800 44) unsigned char type_check_kind;
42440c1f9911b (Andrey Ryabinin 2018-02-06 15:40:42 -0800 45) };
42440c1f9911b (Andrey Ryabinin 2018-02-06 15:40:42 -0800 46)
42440c1f9911b (Andrey Ryabinin 2018-02-06 15:40:42 -0800 47) struct type_mismatch_data_common {
42440c1f9911b (Andrey Ryabinin 2018-02-06 15:40:42 -0800 48) struct source_location *location;
42440c1f9911b (Andrey Ryabinin 2018-02-06 15:40:42 -0800 49) struct type_descriptor *type;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 50) unsigned long alignment;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 51) unsigned char type_check_kind;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 52) };
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 53)
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 54) struct nonnull_arg_data {
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 55) struct source_location location;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 56) struct source_location attr_location;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 57) int arg_index;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 58) };
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 59)
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 60) struct out_of_bounds_data {
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 61) struct source_location location;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 62) struct type_descriptor *array_type;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 63) struct type_descriptor *index_type;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 64) };
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 65)
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 66) struct shift_out_of_bounds_data {
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 67) struct source_location location;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 68) struct type_descriptor *lhs_type;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 69) struct type_descriptor *rhs_type;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 70) };
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 71)
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 72) struct unreachable_data {
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 73) struct source_location location;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 74) };
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 75)
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 76) struct invalid_value_data {
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 77) struct source_location location;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 78) struct type_descriptor *type;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 79) };
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 80)
28abcc963149e (Nathan Chancellor 2021-02-04 18:32:57 -0800 81) struct alignment_assumption_data {
28abcc963149e (Nathan Chancellor 2021-02-04 18:32:57 -0800 82) struct source_location location;
28abcc963149e (Nathan Chancellor 2021-02-04 18:32:57 -0800 83) struct source_location assumption_location;
28abcc963149e (Nathan Chancellor 2021-02-04 18:32:57 -0800 84) struct type_descriptor *type;
28abcc963149e (Nathan Chancellor 2021-02-04 18:32:57 -0800 85) };
28abcc963149e (Nathan Chancellor 2021-02-04 18:32:57 -0800 86)
c12d3362a74bf (Ard Biesheuvel 2019-11-08 13:22:27 +0100 87) #if defined(CONFIG_ARCH_SUPPORTS_INT128)
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 88) typedef __int128 s_max;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 89) typedef unsigned __int128 u_max;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 90) #else
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 91) typedef s64 s_max;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 92) typedef u64 u_max;
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 93) #endif
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 94)
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 95) #endif