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 143 of file ubsan.cpp.

143 {
144
145 UBSanHandler::handle(info->location, "Addition overflow");
146
147}
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:92

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 176 of file ubsan.cpp.

176 {
177
178 UBSanHandler::handle(info->location, "Unreachable code");
179
180}
source_location_t location
The location of the error.
Definition ubsan.h:136

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 154 of file ubsan.cpp.

154 {
155
156 UBSanHandler::handle(info->location, "Division overflow");
157
158}

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 198 of file ubsan.cpp.

198 {
199
200 UBSanHandler::handle(info->location, "Load of invalid value");
201
202}
source_location_t location
The location of the invalid value.
Definition ubsan.h:149

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 209 of file ubsan.cpp.

209 {
210
211 UBSanHandler::handle(info->location, "Missing return");
212}

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 187 of file ubsan.cpp.

187 {
188
189 UBSanHandler::handle(info->location, "Multiplication overflow");
190
191}

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 165 of file ubsan.cpp.

165 {
166
167 UBSanHandler::handle(info->location, "Negation overflow");
168
169}

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 132 of file ubsan.cpp.

132 {
133
134 UBSanHandler::handle(info->location, "Array out of bounds");
135
136}
source_location_t location
The location of the out of bounds access.
Definition ubsan.h:121

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 100 of file ubsan.cpp.

100 {
101
102 UBSanHandler::handle(info->location, "Pointer overflow");
103
104}

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 122 of file ubsan.cpp.

122 {
123
124 UBSanHandler::handle(info->location, "Shift out of bounds");
125}
source_location_t location
The location of the shift out of bounds.
Definition ubsan.h:106

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 111 of file ubsan.cpp.

111 {
112
113 UBSanHandler::handle(info->location, "Subtraction overflow");
114
115}

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 79 of file ubsan.cpp.

79 {
80
82}
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 90 of file ubsan.cpp.

90 {
91
93}
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

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 219 of file ubsan.cpp.

219 {
220
221 UBSanHandler::handle(info->location, "VLA bound not positive");
222}
source_location_t location
The location of the VLA bound not positive.
Definition ubsan.h:163

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