summaryrefslogtreecommitdiffstats
path: root/lib/ubsan.h
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2019-08-27 17:09:14 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-09-09 15:16:08 +0200
commit3af4f067ecd160a5ae5d60b276d4ef0bbec789be (patch)
tree66617af4a90ef076a146d3b874572143aaef30ea /lib/ubsan.h
parenta37a49bcd99d5495ed65c904ed82fbb506b01f8f (diff)
downloadbarebox-3af4f067ecd160a5ae5d60b276d4ef0bbec789be.tar.gz
barebox-3af4f067ecd160a5ae5d60b276d4ef0bbec789be.tar.xz
common: add generic CONFIG_UBSAN plumbing
-fsanitize=undefined allows compile-time instrumentation of code to detect some classes of runtime undefined behavior. In preparation for allowing arches to provide infrastructure in support of this feature, add some generic UBSAN options and associated plumbing. These are only shown in the debug menu when the arch selects the appropriate symbol. The option is named equally to their Linux counterparts. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib/ubsan.h')
-rw-r--r--lib/ubsan.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/lib/ubsan.h b/lib/ubsan.h
new file mode 100644
index 0000000000..7bbedd4b78
--- /dev/null
+++ b/lib/ubsan.h
@@ -0,0 +1,89 @@
+ /* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LIB_UBSAN_H
+#define _LIB_UBSAN_H
+
+enum {
+ type_kind_int = 0,
+ type_kind_float = 1,
+ type_unknown = 0xffff
+};
+
+struct type_descriptor {
+ u16 type_kind;
+ u16 type_info;
+ char type_name[1];
+};
+
+struct source_location {
+ const char *file_name;
+ union {
+ unsigned long reported;
+ struct {
+ u32 line;
+ u32 column;
+ };
+ };
+};
+
+struct overflow_data {
+ struct source_location location;
+ struct type_descriptor *type;
+};
+
+struct type_mismatch_data {
+ struct source_location location;
+ struct type_descriptor *type;
+ unsigned long alignment;
+ unsigned char type_check_kind;
+};
+
+struct type_mismatch_data_v1 {
+ struct source_location location;
+ struct type_descriptor *type;
+ unsigned char log_alignment;
+ unsigned char type_check_kind;
+};
+
+struct type_mismatch_data_common {
+ struct source_location *location;
+ struct type_descriptor *type;
+ unsigned long alignment;
+ unsigned char type_check_kind;
+};
+
+struct nonnull_arg_data {
+ struct source_location location;
+ struct source_location attr_location;
+ int arg_index;
+};
+
+struct out_of_bounds_data {
+ struct source_location location;
+ struct type_descriptor *array_type;
+ struct type_descriptor *index_type;
+};
+
+struct shift_out_of_bounds_data {
+ struct source_location location;
+ struct type_descriptor *lhs_type;
+ struct type_descriptor *rhs_type;
+};
+
+struct unreachable_data {
+ struct source_location location;
+};
+
+struct invalid_value_data {
+ struct source_location location;
+ struct type_descriptor *type;
+};
+
+#if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__)
+typedef __int128 s_max;
+typedef unsigned __int128 u_max;
+#else
+typedef s64 s_max;
+typedef u64 u_max;
+#endif
+
+#endif