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