18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _LIB_UBSAN_H
38c2ecf20Sopenharmony_ci#define _LIB_UBSAN_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_cienum {
68c2ecf20Sopenharmony_ci	type_kind_int = 0,
78c2ecf20Sopenharmony_ci	type_kind_float = 1,
88c2ecf20Sopenharmony_ci	type_unknown = 0xffff
98c2ecf20Sopenharmony_ci};
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cistruct type_descriptor {
128c2ecf20Sopenharmony_ci	u16 type_kind;
138c2ecf20Sopenharmony_ci	u16 type_info;
148c2ecf20Sopenharmony_ci	char type_name[1];
158c2ecf20Sopenharmony_ci};
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistruct source_location {
188c2ecf20Sopenharmony_ci	const char *file_name;
198c2ecf20Sopenharmony_ci	union {
208c2ecf20Sopenharmony_ci		unsigned long reported;
218c2ecf20Sopenharmony_ci		struct {
228c2ecf20Sopenharmony_ci			u32 line;
238c2ecf20Sopenharmony_ci			u32 column;
248c2ecf20Sopenharmony_ci		};
258c2ecf20Sopenharmony_ci	};
268c2ecf20Sopenharmony_ci};
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistruct overflow_data {
298c2ecf20Sopenharmony_ci	struct source_location location;
308c2ecf20Sopenharmony_ci	struct type_descriptor *type;
318c2ecf20Sopenharmony_ci};
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_cistruct type_mismatch_data {
348c2ecf20Sopenharmony_ci	struct source_location location;
358c2ecf20Sopenharmony_ci	struct type_descriptor *type;
368c2ecf20Sopenharmony_ci	unsigned long alignment;
378c2ecf20Sopenharmony_ci	unsigned char type_check_kind;
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistruct type_mismatch_data_v1 {
418c2ecf20Sopenharmony_ci	struct source_location location;
428c2ecf20Sopenharmony_ci	struct type_descriptor *type;
438c2ecf20Sopenharmony_ci	unsigned char log_alignment;
448c2ecf20Sopenharmony_ci	unsigned char type_check_kind;
458c2ecf20Sopenharmony_ci};
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistruct type_mismatch_data_common {
488c2ecf20Sopenharmony_ci	struct source_location *location;
498c2ecf20Sopenharmony_ci	struct type_descriptor *type;
508c2ecf20Sopenharmony_ci	unsigned long alignment;
518c2ecf20Sopenharmony_ci	unsigned char type_check_kind;
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistruct nonnull_arg_data {
558c2ecf20Sopenharmony_ci	struct source_location location;
568c2ecf20Sopenharmony_ci	struct source_location attr_location;
578c2ecf20Sopenharmony_ci	int arg_index;
588c2ecf20Sopenharmony_ci};
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistruct out_of_bounds_data {
618c2ecf20Sopenharmony_ci	struct source_location location;
628c2ecf20Sopenharmony_ci	struct type_descriptor *array_type;
638c2ecf20Sopenharmony_ci	struct type_descriptor *index_type;
648c2ecf20Sopenharmony_ci};
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_cistruct shift_out_of_bounds_data {
678c2ecf20Sopenharmony_ci	struct source_location location;
688c2ecf20Sopenharmony_ci	struct type_descriptor *lhs_type;
698c2ecf20Sopenharmony_ci	struct type_descriptor *rhs_type;
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_cistruct unreachable_data {
738c2ecf20Sopenharmony_ci	struct source_location location;
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistruct invalid_value_data {
778c2ecf20Sopenharmony_ci	struct source_location location;
788c2ecf20Sopenharmony_ci	struct type_descriptor *type;
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistruct alignment_assumption_data {
828c2ecf20Sopenharmony_ci	struct source_location location;
838c2ecf20Sopenharmony_ci	struct source_location assumption_location;
848c2ecf20Sopenharmony_ci	struct type_descriptor *type;
858c2ecf20Sopenharmony_ci};
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#if defined(CONFIG_ARCH_SUPPORTS_INT128)
888c2ecf20Sopenharmony_citypedef __int128 s_max;
898c2ecf20Sopenharmony_citypedef unsigned __int128 u_max;
908c2ecf20Sopenharmony_ci#else
918c2ecf20Sopenharmony_citypedef s64 s_max;
928c2ecf20Sopenharmony_citypedef u64 u_max;
938c2ecf20Sopenharmony_ci#endif
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#endif
96