Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::runtime::UBSanHandler Class Reference

Handles undefined behaviour sanitizer runtime errors. More...

#include <ubsan.h>

Static Public Member Functions

static void handle (source_location_t location, const char *msg)
 Handles the UBSan error (currently only printing the location and panicking)
 
static void print_type_mismatch (type_mismatch_info_t *info, uintptr_t ptr)
 Prints the type mismatch error for UBSan.
 
static void print_type_mismatch_v1 (type_mismatch_info_v1_t *info, uintptr_t ptr)
 Prints the type mismatch error for UBSan v1.
 

Detailed Description

Handles undefined behaviour sanitizer runtime errors.

Definition at line 184 of file ubsan.h.

Member Function Documentation

◆ handle()

void UBSanHandler::handle ( source_location_t  location,
const char *  msg 
)
static

Handles the UBSan error (currently only printing the location and panicking)

Parameters
locationThe location of the error
msgThe message that informs about the error

Definition at line 25 of file ubsan.cpp.

25 {
26
27 // Print the location
28 ASSERT(false, "UBSAN ERROR AT %s:%d:%d - %s", location.file, location.line, location.column, msg);
29}
#define ASSERT(condition, format,...)
If the specified condition is not met then the kernel will crash with the specified message.
Definition logger.h:100
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

References ASSERT, MaxOS::runtime::SourceLocation::column, MaxOS::runtime::SourceLocation::file, and MaxOS::runtime::SourceLocation::line.

Referenced by __ubsan_handle_add_overflow(), __ubsan_handle_builtin_unreachable(), __ubsan_handle_divrem_overflow(), __ubsan_handle_load_invalid_value(), __ubsan_handle_missing_return(), __ubsan_handle_mul_overflow(), __ubsan_handle_negate_overflow(), __ubsan_handle_out_of_bounds(), __ubsan_handle_pointer_overflow(), __ubsan_handle_shift_out_of_bounds(), __ubsan_handle_sub_overflow(), __ubsan_handle_vla_bound_not_positive(), print_type_mismatch(), and print_type_mismatch_v1().

◆ print_type_mismatch()

void UBSanHandler::print_type_mismatch ( type_mismatch_info_t info,
uintptr_t  ptr 
)
static

Prints the type mismatch error for UBSan.

Parameters
infoThe type mismatch info
ptrThe pointer to the object

Definition at line 37 of file ubsan.cpp.

37 {
38
39 // Print the error
40 string msg;
41 if (info->alignment != 0 && ubsan_aligned(ptr, info->alignment))
42 msg = "misaligned memory access";
43 else
44 msg = (StringBuilder)TYPE_CHECK_KINDS[info->type_check_kind] << " address 0x" << ptr << " with insufficient space for an object of type " << info->type->name;
45
46 // Print the location
47 handle(info->location, msg.c_str());
48}
Creates a string using a using a combination of parts with the '<<' operator. Simmilar to the logger.
Definition string.h:97
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
char name[]
The name of the type.
Definition ubsan.h:45
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
#define ubsan_aligned(value, alignment)
Check if a value is aligned to the given alignment.
Definition ubsan.h:15

References MaxOS::runtime::TypeMismatchInfo::alignment, handle(), MaxOS::runtime::TypeMismatchInfo::location, MaxOS::runtime::TypeDescriptor::name, MaxOS::runtime::TypeMismatchInfo::type, MaxOS::runtime::TypeMismatchInfo::type_check_kind, MaxOS::runtime::TYPE_CHECK_KINDS, and ubsan_aligned.

Referenced by __ubsan_handle_type_mismatch().

◆ print_type_mismatch_v1()

void UBSanHandler::print_type_mismatch_v1 ( type_mismatch_info_v1_t info,
uintptr_t  ptr 
)
static

Prints the type mismatch error for UBSan v1.

Parameters
infoThe type mismatch info
ptrThe pointer to the object

Definition at line 56 of file ubsan.cpp.

56 {
57
58 // Print the error
59 string msg;
60 if (info->log_alignment != 0 && ubsan_aligned(ptr, (1 << (info->log_alignment))))
61 msg = "misaligned memory access";
62 else
63 msg= StringBuilder() << TYPE_CHECK_KINDS[info->type_check_kind] << " address 0x" << ptr << " with insufficient space for an object of type " << info->type->name;
64
65 // Print the location
66 handle(info->location, msg.c_str());
67}
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
const char * TYPE_CHECK_KINDS[]
List of type check errors.
Definition ubsan.h:167

References handle(), MaxOS::runtime::TypeMismatchInfoV1::location, MaxOS::runtime::TypeMismatchInfoV1::log_alignment, MaxOS::runtime::TypeDescriptor::name, MaxOS::runtime::TypeMismatchInfoV1::type, MaxOS::runtime::TypeMismatchInfoV1::type_check_kind, MaxOS::runtime::TYPE_CHECK_KINDS, and ubsan_aligned.

Referenced by __ubsan_handle_type_mismatch_v1().


The documentation for this class was generated from the following files: