Max OS 0.3
Loading...
Searching...
No Matches
ubsan.cpp File Reference

Implementation of the Undefined Behavior Sanitizer (UBSan) handler. More...

#include <runtime/ubsan.h>
#include <common/logger.h>

Go to the source code of this file.

Functions

void __ubsan_handle_type_mismatch (type_mismatch_info_t *info, uintptr_t ptr)
 Triggered when memory is accessed with an unexpected type.
 
void __ubsan_handle_type_mismatch_v1 (type_mismatch_info_v1_t *info, uintptr_t ptr)
 Triggered when memory is accessed with an unexpected type (UBSan v1 - includes more metadata)
 
void __ubsan_handle_pointer_overflow (overflow_info_t *info)
 Triggered when adding/subbing to a memory address is outside the expected bounds.
 
void __ubsan_handle_sub_overflow (overflow_info_t *info)
 Triggered when subtracting below the minimum value for the type.
 
void __ubsan_handle_shift_out_of_bounds (shift_out_of_bounds_info_t *info)
 Triggered when shifting beyond the capacity of the type.
 
void __ubsan_handle_out_of_bounds (out_of_bounds_info_t *info)
 Triggered when accessing an array at an index larger than its size (or negative)
 
void __ubsan_handle_add_overflow (overflow_info_t *info)
 Triggered when adding beyond the maximum value for the type.
 
void __ubsan_handle_divrem_overflow (overflow_info_t *info)
 Triggered when dividing or taking the remainder results in an overflow (eg dividing INT_MIN by -1)
 
void __ubsan_handle_negate_overflow (overflow_info_t *info)
 Triggered when negating (taking -x) when there is no corresponding positive/negative value.
 
void __ubsan_handle_builtin_unreachable (location_only_info_t *info)
 Triggered when reaching code that should be unreachable.
 
void __ubsan_handle_mul_overflow (overflow_info_t *info)
 Triggered when multiplying beyond the maximum value for the type.
 
void __ubsan_handle_load_invalid_value (invalid_value_info_t *info)
 Triggered when loading a value that is invalid for its type (eg corrupted or uninitialised)
 
void __ubsan_handle_missing_return (location_only_info_t *info)
 Triggered when a function that is expected to return a value does not.
 
void __ubsan_handle_vla_bound_not_positive (vla_bound_not_positive_info_t *info)
 Triggered when a variable length array (VLA) is declared with a non-positive bound.
 

Detailed Description

Implementation of the Undefined Behavior Sanitizer (UBSan) handler.

Date
30th December 2024
Author
Max Tyson

Definition in file ubsan.cpp.

Function Documentation

◆ __ubsan_handle_add_overflow()

void __ubsan_handle_add_overflow ( overflow_info_t info)

Triggered when adding beyond the maximum value for the type.

Parameters
infoThe location and type of the overflow

Definition at line 139 of file ubsan.cpp.

139 {
140
141 UBSanHandler::handle(info->location, "Addition overflow");
142
143}
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
source_location_t location
The location of the overflow.
Definition ubsan.h:90

References MaxOS::runtime::UBSanHandler::handle(), and MaxOS::runtime::OverflowInfo::location.

◆ __ubsan_handle_builtin_unreachable()

void __ubsan_handle_builtin_unreachable ( location_only_info_t info)

Triggered when reaching code that should be unreachable.

Parameters
infoThe location of the unreachable code

Definition at line 172 of file ubsan.cpp.

172 {
173
174 UBSanHandler::handle(info->location, "Unreachable code");
175
176}
source_location_t location
The location of the error.
Definition ubsan.h:134

References MaxOS::runtime::UBSanHandler::handle(), and MaxOS::runtime::LocationOnlyInfo::location.

◆ __ubsan_handle_divrem_overflow()

void __ubsan_handle_divrem_overflow ( overflow_info_t info)

Triggered when dividing or taking the remainder results in an overflow (eg dividing INT_MIN by -1)

Parameters
infoThe location and type of the overflow

Definition at line 150 of file ubsan.cpp.

150 {
151
152 UBSanHandler::handle(info->location, "Division overflow");
153
154}

References MaxOS::runtime::UBSanHandler::handle(), and MaxOS::runtime::OverflowInfo::location.

◆ __ubsan_handle_load_invalid_value()

void __ubsan_handle_load_invalid_value ( invalid_value_info_t info)

Triggered when loading a value that is invalid for its type (eg corrupted or uninitialised)

Parameters
infoThe location and type of the invalid value

Definition at line 194 of file ubsan.cpp.

194 {
195
196 UBSanHandler::handle(info->location, "Load of invalid value");
197
198}
source_location_t location
The location of the invalid value.
Definition ubsan.h:147

References MaxOS::runtime::UBSanHandler::handle(), and MaxOS::runtime::InvaildValueInfo::location.

◆ __ubsan_handle_missing_return()

void __ubsan_handle_missing_return ( location_only_info_t info)

Triggered when a function that is expected to return a value does not.

Parameters
infoThe location of the missing return

Definition at line 205 of file ubsan.cpp.

205 {
206
207 UBSanHandler::handle(info->location, "Missing return");
208}

References MaxOS::runtime::UBSanHandler::handle(), and MaxOS::runtime::LocationOnlyInfo::location.

◆ __ubsan_handle_mul_overflow()

void __ubsan_handle_mul_overflow ( overflow_info_t info)

Triggered when multiplying beyond the maximum value for the type.

Parameters
infoThe location and type of the overflow

Definition at line 183 of file ubsan.cpp.

183 {
184
185 UBSanHandler::handle(info->location, "Multiplication overflow");
186
187}

References MaxOS::runtime::UBSanHandler::handle(), and MaxOS::runtime::OverflowInfo::location.

◆ __ubsan_handle_negate_overflow()

void __ubsan_handle_negate_overflow ( overflow_info_t info)

Triggered when negating (taking -x) when there is no corresponding positive/negative value.

Parameters
infoThe location and type of the overflow

Definition at line 161 of file ubsan.cpp.

161 {
162
163 UBSanHandler::handle(info->location, "Negation overflow");
164
165}

References MaxOS::runtime::UBSanHandler::handle(), and MaxOS::runtime::OverflowInfo::location.

◆ __ubsan_handle_out_of_bounds()

void __ubsan_handle_out_of_bounds ( out_of_bounds_info_t info)

Triggered when accessing an array at an index larger than its size (or negative)

Parameters
infoThe location and type of the out of bounds access

Definition at line 128 of file ubsan.cpp.

128 {
129
130 UBSanHandler::handle(info->location, "Array out of bounds");
131
132}
source_location_t location
The location of the out of bounds access.
Definition ubsan.h:119

References MaxOS::runtime::UBSanHandler::handle(), and MaxOS::runtime::OutOfBoundsInfo::location.

◆ __ubsan_handle_pointer_overflow()

void __ubsan_handle_pointer_overflow ( overflow_info_t info)

Triggered when adding/subbing to a memory address is outside the expected bounds.

Parameters
infoThe overflow information

Definition at line 96 of file ubsan.cpp.

96 {
97
98 UBSanHandler::handle(info->location, "Pointer overflow");
99
100}

References MaxOS::runtime::UBSanHandler::handle(), and MaxOS::runtime::OverflowInfo::location.

◆ __ubsan_handle_shift_out_of_bounds()

void __ubsan_handle_shift_out_of_bounds ( shift_out_of_bounds_info_t info)

Triggered when shifting beyond the capacity of the type.

Parameters
infoThe shift out of bounds information

Definition at line 118 of file ubsan.cpp.

118 {
119
120 UBSanHandler::handle(info->location, "Shift out of bounds");
121}
source_location_t location
The location of the shift out of bounds.
Definition ubsan.h:104

References MaxOS::runtime::UBSanHandler::handle(), and MaxOS::runtime::ShiftOutOfBoundsInfo::location.

◆ __ubsan_handle_sub_overflow()

void __ubsan_handle_sub_overflow ( overflow_info_t info)

Triggered when subtracting below the minimum value for the type.

Parameters
infoThe location and type of the overflow

Definition at line 107 of file ubsan.cpp.

107 {
108
109 UBSanHandler::handle(info->location, "Subtraction overflow");
110
111}

References MaxOS::runtime::UBSanHandler::handle(), and MaxOS::runtime::OverflowInfo::location.

◆ __ubsan_handle_type_mismatch()

void __ubsan_handle_type_mismatch ( type_mismatch_info_t info,
uintptr_t  ptr 
)

Triggered when memory is accessed with an unexpected type.

Parameters
infoThe mismatch between the two types
ptrThe pointer to where the type mismatch occurred

Definition at line 75 of file ubsan.cpp.

75 {
76
78}
static void print_type_mismatch(type_mismatch_info_t *info, uintptr_t ptr)
Prints the type mismatch error for UBSan.
Definition ubsan.cpp:37

References MaxOS::runtime::UBSanHandler::print_type_mismatch().

◆ __ubsan_handle_type_mismatch_v1()

void __ubsan_handle_type_mismatch_v1 ( type_mismatch_info_v1_t info,
uintptr_t  ptr 
)

Triggered when memory is accessed with an unexpected type (UBSan v1 - includes more metadata)

Parameters
infoThe mismatch between the two types
ptrThe pointer to where the type mismatch occurred

Definition at line 86 of file ubsan.cpp.

86 {
87
89}
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

References MaxOS::runtime::UBSanHandler::print_type_mismatch_v1().

◆ __ubsan_handle_vla_bound_not_positive()

void __ubsan_handle_vla_bound_not_positive ( vla_bound_not_positive_info_t info)

Triggered when a variable length array (VLA) is declared with a non-positive bound.

Parameters
infoThe location and type of the VLA bound

Definition at line 215 of file ubsan.cpp.

215 {
216
217 UBSanHandler::handle(info->location, "VLA bound not positive");
218}
source_location_t location
The location of the VLA bound not positive.
Definition ubsan.h:161

References MaxOS::runtime::UBSanHandler::handle(), and MaxOS::runtime::VLABoundNotPositiveInfo::location.