-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathubsan.cpp
191 lines (161 loc) · 6.15 KB
/
ubsan.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <kern.h>
#include <kern_runtime.hpp>
#include <kern_datatypes.hpp>
struct TypeDescriptor
{
UINT16 Kind;
UINT16 Info;
char Name[];
};
struct SourceLocation
{
const CHAR *File;
UINT32 Line;
UINT32 Col;
};
struct TypeMismatchDataV1
{
struct SourceLocation Loc;
struct TypeDescriptor *Type;
UINT8 LogAlign;
UINT8 TypeCheckKind;
};
struct ShiftOutOfBoundsData
{
struct SourceLocation Loc;
struct TypeDescriptor *LeftType;
struct TypeDescriptor *RightType;
};
struct OutOfBoundsData
{
struct SourceLocation Loc;
struct TypeDescriptor *ArrayType;
struct TypeDescriptor *IndexType;
};
struct InvalidValueData
{
struct SourceLocation Loc;
struct TypeDescriptor *Type;
};
struct OverflowData
{
struct SourceLocation Loc;
struct TypeDescriptor *Type;
};
struct VlaBoundData
{
struct SourceLocation Loc;
struct TypeDescriptor *Type;
};
struct NonnullReturnData
{
struct SourceLocation Loc;
};
struct UnreachableData
{
struct SourceLocation Loc;
};
struct NonnullArgData
{
struct SourceLocation Loc;
struct SourceLocation AttrLoc;
int ArgIndex;
};
struct InvalidBuiltinData
{
struct SourceLocation Loc;
UINT8 TypeCheckKind;
};
const char *TypeCheckKinds[] =
{
"load of",
"store to",
"ref binding to",
"member access inside",
"member call on",
"constructor call on",
"downcast of",
"downcast of",
"upcast of",
"virtual base cast of",
"non-null binding to",
"dynamic operation on",
};
extern "C"
{
void __ubsan_handle_add_overflow(struct OverflowData *Data, uintptr_t, uintptr_t)
{
pantheon::StopErrorFmt("<__ubsan_handle_add_overflow>: %s on line %u and col %u\n\t errored type was %s, because %s\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col, Data->Type->Name, TypeCheckKinds[Data->Type->Kind]);
}
void __ubsan_handle_sub_overflow(struct OverflowData *Data, uintptr_t, uintptr_t)
{
pantheon::StopErrorFmt("<__ubsan_handle_sub_overflow>: %s on line %u and col %u\n\t errored type was %s, because %s\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col, Data->Type->Name, TypeCheckKinds[Data->Type->Kind]);
}
void __ubsan_handle_mul_overflow(struct OverflowData *Data, uintptr_t, uintptr_t)
{
pantheon::StopErrorFmt("<__ubsan_handle_mul_overflow>: %s on line %u and col %u\n\t errored type was %s, because %s\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col, Data->Type->Name, TypeCheckKinds[Data->Type->Kind]);
}
void __ubsan_handle_divrem_overflow(struct OverflowData *Data, uintptr_t, uintptr_t)
{
pantheon::StopErrorFmt("<__ubsan_handle_divrem_overflow>: %s on line %u and col %u\n\t errored type was %s, because %s\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col, Data->Type->Name, TypeCheckKinds[Data->Type->Kind]);
}
void __ubsan_handle_negate_overflow(struct OverflowData *Data, uintptr_t)
{
pantheon::StopErrorFmt("<__ubsan_handle_negate_overflow>: %s on line %u and col %u\n\t errored type was %s, because %s\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col, Data->Type->Name, TypeCheckKinds[Data->Type->Kind]);
}
void __ubsan_handle_pointer_overflow(struct OverflowData *Data, uintptr_t base, uintptr_t result)
{
pantheon::StopErrorFmt("<__ubsan_handle_pointer_overflow>: %s on line %u and col %u\n\t errored type was %s, because %s. Base was %ld and result was %ld\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col, Data->Type->Name, TypeCheckKinds[Data->Type->Kind], base, result);
}
void __ubsan_handle_shift_out_of_bounds(struct ShiftOutOfBoundsData *Data, uintptr_t, uintptr_t)
{
pantheon::StopErrorFmt("<__ubsan_handle_shift_out_of_bounds>: %s on line %u and col %u\n\t errored types were %s and %s, because %s and %s\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col, Data->LeftType->Name, Data->RightType->Name, TypeCheckKinds[Data->LeftType->Kind], TypeCheckKinds[Data->RightType->Kind]);
}
void __ubsan_handle_out_of_bounds(struct OutOfBoundsData *Data, uintptr_t Index)
{
pantheon::StopErrorFmt("<__ubsan_handle_out_of_bounds>: %s on line %u and col %u\n\t on array of type %s with indexed type of %s, on index %ld\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col, Data->ArrayType->Name, Data->IndexType->Name, Index);
}
void __ubsan_handle_load_invalid_value(struct InvalidValueData *Data, uintptr_t val)
{
pantheon::StopErrorFmt("<__ubsan_handle_load_invalid_value>: %s on line %u and col %u\n\t errored value was 0x%lx\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col, val);
}
void __ubsan_handle_vla_bound_not_positive(struct VlaBoundData *Data, uintptr_t Bound)
{
pantheon::StopErrorFmt("<__ubsan_handle_vla_bound_not_positive>: %s on line %u and col %u\n\t on type %s and bound %ld\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col, Data->Type->Name, Bound);
}
void __ubsan_handle_nonnull_arg(struct NonnullArgData *Data)
{
pantheon::StopErrorFmt("<__ubsan_handle_nonnull_arg>: %s on line %u and col %u\n\t, from Non-null argument %s at line %ld and col %ld, argument number %lx\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col, Data->AttrLoc.File, Data->AttrLoc.Line, Data->AttrLoc.Col, Data->ArgIndex);
}
void __ubsan_handle_builtin_unreachable(struct UnreachableData *Data)
{
pantheon::StopErrorFmt("<__ubsan_handle_builtin_unreachable>: %s on line %u and col %u\n\t, which was marked as unreachable\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col);
}
void __ubsan_handle_invalid_builtin(struct InvalidBuiltinData *Data)
{
pantheon::StopErrorFmt("<__ubsan_handle_invalid_builtin>: %s on line %u and col %u\n\t, which is of kind %s\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col, TypeCheckKinds[Data->TypeCheckKind]);
}
void __ubsan_handle_type_mismatch_v1(struct TypeMismatchDataV1 *Data, uintptr_t Pointer)
{
pantheon::StopErrorFmt("<__ubsan_handle_type_mismatch_v1>: %s on line %u and col %u\n\t on type %s with log_align %hhd and reason %s, at address %lx\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col, Data->Type->Name, Data->LogAlign, TypeCheckKinds[Data->TypeCheckKind], Pointer);
}
void __ubsan_handle_nonnull_return_v1(struct NonnullReturnData *Data, struct SourceLocation *Loc)
{
pantheon::StopErrorFmt("<__ubsan_handle_nonnull_return_v1>: %s on line %u and col %u\n\t, from Non-null function %s at line %ld and col %ld\n",
Data->Loc.File, Data->Loc.Line, Data->Loc.Col, Loc->File, Loc->Line, Loc->Col);
}
}