Max OS 0.3
Loading...
Searching...
No Matches
ubsan.h
Go to the documentation of this file.
1
9#ifndef MAXOS_RUNTIME_UBSAN_H
10#define MAXOS_RUNTIME_UBSAN_H
11
12#include <cstdint>
13
15#define ubsan_aligned(value, alignment) !(value & (alignment - 1))
16
17namespace MaxOS::runtime {
18
26 typedef struct SourceLocation {
27
28 const char* file;
29 uint32_t line;
30 uint32_t column;
31
32 } source_location_t;
33
41 typedef struct TypeDescriptor {
42
43 uint16_t kind;
44 uint16_t info;
45 char name[];
46
47 } type_descriptor_t;
48
56 typedef struct TypeMismatchInfo {
57
60 uintptr_t alignment;
62
63 } type_mismatch_info_t;
64
72 typedef struct TypeMismatchInfoV1 {
73
76 unsigned char log_alignment;
77 unsigned char type_check_kind;
78
79 } type_mismatch_info_v1_t;
80
88 typedef struct OverflowInfo {
89
92
93 } overflow_info_t;
94
109
124
132 typedef struct LocationOnlyInfo {
133
135
136 } location_only_info_t;
137
145 typedef struct InvaildValueInfo {
146
149
150 } invalid_value_info_t;
151
159 typedef struct VLABoundNotPositiveInfo {
160
163
164 } vla_bound_not_positive_info_t;
165
167 const char* TYPE_CHECK_KINDS[] = {
168 "load of",
169 "store to",
170 "reference binding to",
171 "member access within",
172 "member call on",
173 "constructor call on",
174 "downcast of",
175 "downcast of",
176 "upcast of",
177 "cast to virtual base of",
178 };
179
185
186 public:
187 UBSanHandler();
189
190 static void handle(source_location_t location, const char* msg);
191
192 static void print_type_mismatch(type_mismatch_info_t* info, uintptr_t ptr);
193 static void print_type_mismatch_v1(type_mismatch_info_v1_t* info, uintptr_t ptr);
194 };
195}
196
197
198#endif // MAXOS_RUNTIME_UBSAN_H
Handles undefined behaviour sanitizer runtime errors.
Definition ubsan.h:184
static void handle(source_location_t location, const char *msg)
Handles the UBSan error (currently only printing the location and panicking)
Definition ubsan.cpp:25
static void print_type_mismatch(type_mismatch_info_t *info, uintptr_t ptr)
Prints the type mismatch error for UBSan.
Definition ubsan.cpp:37
static void print_type_mismatch_v1(type_mismatch_info_v1_t *info, uintptr_t ptr)
Prints the type mismatch error for UBSan v1.
Definition ubsan.cpp:56
Information about an invalid value error.
Definition ubsan.h:145
type_descriptor_t * type
The type of the invalid value.
Definition ubsan.h:148
source_location_t location
The location of the invalid value.
Definition ubsan.h:147
Information that an error that only has a location.
Definition ubsan.h:132
source_location_t location
The location of the error.
Definition ubsan.h:134
Information about an out of bounds error.
Definition ubsan.h:117
type_descriptor_t * array_type
The type of the array.
Definition ubsan.h:120
type_descriptor_t * index_type
The type of the index.
Definition ubsan.h:121
source_location_t location
The location of the out of bounds access.
Definition ubsan.h:119
Information about an overflow error.
Definition ubsan.h:88
source_location_t location
The location of the overflow.
Definition ubsan.h:90
type_descriptor_t * base_type
The base type of the operation.
Definition ubsan.h:91
Information about a shift out of bounds error.
Definition ubsan.h:102
source_location_t location
The location of the shift out of bounds.
Definition ubsan.h:104
type_descriptor_t * left_type
The type of the left operand.
Definition ubsan.h:105
type_descriptor_t * right_type
The type of the right operand.
Definition ubsan.h:106
The location in the source code where the undefined behaviour occurred.
Definition ubsan.h:26
uint32_t line
The line number in the source file.
Definition ubsan.h:29
uint32_t column
The column number in the source file.
Definition ubsan.h:30
const char * file
The name of the source file.
Definition ubsan.h:28
Describes a type in the program.
Definition ubsan.h:41
uint16_t kind
The kind of type (e.g., struct, class, union)
Definition ubsan.h:43
char name[]
The name of the type.
Definition ubsan.h:45
uint16_t info
Additional type information.
Definition ubsan.h:44
Information about a type mismatch error (version 1)
Definition ubsan.h:72
source_location_t location
The location of the type mismatch.
Definition ubsan.h:74
unsigned char log_alignment
The log2 of the required alignment.
Definition ubsan.h:76
unsigned char type_check_kind
The kind of type check that failed.
Definition ubsan.h:77
type_descriptor_t * type
The type that was expected.
Definition ubsan.h:75
Information about a type mismatch error.
Definition ubsan.h:56
source_location_t location
The location of the type mismatch.
Definition ubsan.h:58
uint8_t type_check_kind
The kind of type check that failed.
Definition ubsan.h:61
uintptr_t alignment
The required alignment.
Definition ubsan.h:60
type_descriptor_t * type
The type that was expected.
Definition ubsan.h:59
Information about a VLA bound not positive error.
Definition ubsan.h:159
type_descriptor_t * type
The type of the VLA bound.
Definition ubsan.h:162
source_location_t location
The location of the VLA bound not positive.
Definition ubsan.h:161
const char * TYPE_CHECK_KINDS[]
List of type check errors.
Definition ubsan.h:167