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
14#include <libcommon/assert.h>
15
17#define UBSAN_ALIGNED(value, alignment) ((((uintptr_t)(value)) & ((alignment) - 1)) == 0)
18
19namespace MaxOS::runtime {
20
28 typedef struct SourceLocation {
29
30 const char* file;
31 uint32_t line;
32 uint32_t column;
33
34 } source_location_t;
35
43 typedef struct TypeDescriptor {
44
45 uint16_t kind;
46 uint16_t info;
47 char name[];
48
49 } type_descriptor_t;
50
58 typedef struct TypeMismatchInfo {
59
62 uintptr_t alignment;
64
65 } type_mismatch_info_t;
66
74 typedef struct TypeMismatchInfoV1 {
75
78 unsigned char log_alignment;
79 unsigned char type_check_kind;
80
81 } type_mismatch_info_v1_t;
82
90 typedef struct OverflowInfo {
91
94
95 } overflow_info_t;
96
111
126
134 typedef struct LocationOnlyInfo {
135
137
138 } location_only_info_t;
139
147 typedef struct InvaildValueInfo {
148
151
152 } invalid_value_info_t;
153
161 typedef struct VLABoundNotPositiveInfo {
162
165
166 } vla_bound_not_positive_info_t;
167
169 const char* TYPE_CHECK_KINDS[] = {
170 "load of",
171 "store to",
172 "reference binding to",
173 "member access within",
174 "member call on",
175 "constructor call on",
176 "downcast of",
177 "downcast of",
178 "upcast of",
179 "cast to virtual base of",
180 };
181
187
188 public:
189 UBSanHandler();
191
192 static void handle(source_location_t location, const char* msg);
193
194 static void print_type_mismatch(type_mismatch_info_t* info, uintptr_t ptr);
195 static void print_type_mismatch_v1(type_mismatch_info_v1_t* info, uintptr_t ptr);
196 };
197}
198
199
200#endif // MAXOS_RUNTIME_UBSAN_H
Handles undefined behaviour sanitizer runtime errors.
Definition ubsan.h:186
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:58
Information about an invalid value error.
Definition ubsan.h:147
type_descriptor_t * type
The type of the invalid value.
Definition ubsan.h:150
source_location_t location
The location of the invalid value.
Definition ubsan.h:149
Information that an error that only has a location.
Definition ubsan.h:134
source_location_t location
The location of the error.
Definition ubsan.h:136
Information about an out of bounds error.
Definition ubsan.h:119
type_descriptor_t * array_type
The type of the array.
Definition ubsan.h:122
type_descriptor_t * index_type
The type of the index.
Definition ubsan.h:123
source_location_t location
The location of the out of bounds access.
Definition ubsan.h:121
Information about an overflow error.
Definition ubsan.h:90
source_location_t location
The location of the overflow.
Definition ubsan.h:92
type_descriptor_t * base_type
The base type of the operation.
Definition ubsan.h:93
Information about a shift out of bounds error.
Definition ubsan.h:104
source_location_t location
The location of the shift out of bounds.
Definition ubsan.h:106
type_descriptor_t * left_type
The type of the left operand.
Definition ubsan.h:107
type_descriptor_t * right_type
The type of the right operand.
Definition ubsan.h:108
The location in the source code where the undefined behaviour occurred.
Definition ubsan.h:28
uint32_t line
The line number in the source file.
Definition ubsan.h:31
uint32_t column
The column number in the source file.
Definition ubsan.h:32
const char * file
The name of the source file.
Definition ubsan.h:30
Describes a type in the program.
Definition ubsan.h:43
uint16_t kind
The kind of type (e.g., struct, class, union)
Definition ubsan.h:45
char name[]
The name of the type.
Definition ubsan.h:47
uint16_t info
Additional type information.
Definition ubsan.h:46
Information about a type mismatch error (version 1)
Definition ubsan.h:74
source_location_t location
The location of the type mismatch.
Definition ubsan.h:76
unsigned char log_alignment
The log2 of the required alignment.
Definition ubsan.h:78
unsigned char type_check_kind
The kind of type check that failed.
Definition ubsan.h:79
type_descriptor_t * type
The type that was expected.
Definition ubsan.h:77
Information about a type mismatch error.
Definition ubsan.h:58
source_location_t location
The location of the type mismatch.
Definition ubsan.h:60
uint8_t type_check_kind
The kind of type check that failed.
Definition ubsan.h:63
uintptr_t alignment
The required alignment.
Definition ubsan.h:62
type_descriptor_t * type
The type that was expected.
Definition ubsan.h:61
Information about a VLA bound not positive error.
Definition ubsan.h:161
type_descriptor_t * type
The type of the VLA bound.
Definition ubsan.h:164
source_location_t location
The location of the VLA bound not positive.
Definition ubsan.h:163
const char * TYPE_CHECK_KINDS[]
List of type check errors.
Definition ubsan.h:169