SayoriOS 0.3.3

ubsan.c
1 //
2 // Created by ndraey on 23.09.23.
3 //
4
5 #include "common.h"
6 #include "debug/ubsan.h"
7 #include "io/ports.h"
8
9 void __ubsan_handle_out_of_bounds(struct type_mismatch_info *type_mismatch,
10 size_t pointer) {
11 qemu_err("[%s:%d:%d]: Out of bounds: %x",
12 type_mismatch->location.file,
13 type_mismatch->location.line,
14 type_mismatch->location.column,
15 pointer
16 );
17 }
18
19 void __ubsan_handle_pointer_overflow(struct type_mismatch_info *type_mismatch,
20 size_t pointer) {
21 qemu_err("Pointer overflow!");
22 }
23
24 void __ubsan_handle_type_mismatch_v1(struct type_mismatch_info *type_mismatch,
25 size_t pointer) {
26 if(pointer == 0) {
27 qemu_err("[%s:%d:%d]: Null pointer access!",
28 type_mismatch->location.file,
29 type_mismatch->location.line,
30 type_mismatch->location.column);
31 } else if(type_mismatch->alignment != 0 &&
32 is_aligned(pointer, type_mismatch->alignment)) {
33 qemu_err("[%s:%d:%d]: Misaligned access: %x",
34 type_mismatch->location.file,
35 type_mismatch->location.line,
36 type_mismatch->location.column, pointer);
37 } else {
38 qemu_err("[%s:%d:%d]: %s address %x with insufficient space for object of type %s",
39 type_mismatch->location.file,
40 type_mismatch->location.line,
41 type_mismatch->location.column,
42 Type_Check_Kinds[type_mismatch->type_check_kind],
43 (void*)pointer,
44 type_mismatch->type->name
45 );
46 }
47 }
48
49 void __ubsan_handle_mul_overflow(struct type_mismatch_info *type_mismatch,
50 size_t pointer) {
51 qemu_err("Multiplication overflow!");
52 }
53
54 void __ubsan_handle_add_overflow(struct type_mismatch_info *type_mismatch,
55 size_t pointer) {
56 qemu_err("Addition overflow!");
57 }
58
59 void __ubsan_handle_sub_overflow(struct type_mismatch_info *type_mismatch,
60 size_t pointer) {
61 qemu_err("Substraction overflow!");
62 }
63
64 void __ubsan_handle_shift_out_of_bounds(struct type_mismatch_info *type_mismatch,
65 size_t pointer) {
66 qemu_err("Shift out of bounds!");
67 }
68
69 void __ubsan_handle_divrem_overflow(struct type_mismatch_info *type_mismatch,
70 size_t pointer) {
71 qemu_err("Division remainder overflow!");
72 }
73
74 void __ubsan_handle_float_cast_overflow(struct type_mismatch_info *type_mismatch,
75 size_t pointer) {
76 qemu_err("Float cast overflow!");
77 }
78
79 void __ubsan_handle_negate_overflow(struct type_mismatch_info *type_mismatch,
80 size_t pointer) {
81 qemu_err("Negation overflow!");
82 }
83
84 void __ubsan_handle_vla_bound_not_positive(struct type_mismatch_info *type_mismatch,
85 size_t pointer) {
86 qemu_err("VLA bound is not positive!");
87 }
common.h
Основные определения ядра
type_mismatch_info
Definition: ubsan.h:23