2 * Copyright (c) 2018 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
35 struct san_type_desc
{
36 uint16_t type
; // 0: integer, 1: float
39 uint16_t issigned
: 1;
41 }; /* int descriptor */
44 }; /* float descriptor */
55 struct ubsan_overflow_desc
{
56 struct san_src_loc loc
;
57 struct san_type_desc
*ty
;
60 struct ubsan_unreachable_desc
{
61 struct san_src_loc loc
;
64 struct ubsan_shift_desc
{
65 struct san_src_loc loc
;
66 struct san_type_desc
*lhs_t
;
67 struct san_type_desc
*rhs_t
;
70 struct ubsan_align_desc
{
71 struct san_src_loc loc
;
72 struct san_type_desc
*ty
;
77 struct ubsan_ptroverflow_desc
{
78 struct san_src_loc loc
;
81 struct ubsan_oob_desc
{
82 struct san_src_loc loc
;
83 struct san_type_desc
*array_ty
;
84 struct san_type_desc
*index_ty
;
87 struct ubsan_load_invalid_desc
{
88 struct san_src_loc loc
;
89 struct san_type_desc
*type
;
92 struct ubsan_nullability_arg_desc
{
93 struct san_src_loc loc
;
94 struct san_src_loc attr_loc
;
98 struct ubsan_nullability_ret_desc
{
99 struct san_src_loc loc
;
102 struct ubsan_missing_ret_desc
{
103 struct san_src_loc loc
;
106 struct ubsan_float_desc
{
107 struct san_src_loc loc
;
108 struct san_type_desc
*type_from
;
109 struct san_type_desc
*type_to
;
112 struct ubsan_implicit_conv_desc
{
113 struct san_src_loc loc
;
114 struct san_type_desc
*type_from
;
115 struct san_type_desc
*type_to
;
119 struct ubsan_func_type_mismatch_desc
{
120 struct san_src_loc loc
;
121 struct san_type_desc
*type
;
124 struct ubsan_vla_bound_desc
{
125 struct san_src_loc loc
;
126 struct san_type_desc
*type
;
129 struct ubsan_invalid_builtin
{
130 struct san_src_loc loc
;
135 UBSAN_OVERFLOW_add
= 1,
138 UBSAN_OVERFLOW_divrem
,
139 UBSAN_OVERFLOW_negate
,
143 UBSAN_POINTER_OVERFLOW
,
146 UBSAN_LOAD_INVALID_VALUE
,
147 UBSAN_NULLABILITY_ARG
,
148 UBSAN_NULLABILITY_RETURN
,
149 UBSAN_MISSING_RETURN
,
150 UBSAN_FLOAT_CAST_OVERFLOW
,
151 UBSAN_IMPLICIT_CONVERSION
,
152 UBSAN_FUNCTION_TYPE_MISMATCH
,
153 UBSAN_VLA_BOUND_NOT_POSITIVE
,
154 UBSAN_INVALID_BUILTIN
,
158 struct ubsan_violation
{
163 struct ubsan_overflow_desc
*overflow
;
164 struct ubsan_unreachable_desc
*unreachable
;
165 struct ubsan_shift_desc
*shift
;
166 struct ubsan_align_desc
*align
;
167 struct ubsan_ptroverflow_desc
*ptroverflow
;
168 struct ubsan_oob_desc
*oob
;
169 struct ubsan_load_invalid_desc
*invalid
;
170 struct ubsan_nullability_arg_desc
*nonnull_arg
;
171 struct ubsan_nullability_ret_desc
*nonnull_ret
;
172 struct ubsan_missing_ret_desc
*missing_ret
;
173 struct ubsan_float_desc
*flt
;
174 struct ubsan_implicit_conv_desc
*implicit
;
175 struct ubsan_func_type_mismatch_desc
*func_mismatch
;
176 struct ubsan_vla_bound_desc
*vla_bound
;
177 struct ubsan_invalid_builtin
*invalid_builtin
;
180 struct san_src_loc
*loc
;
189 void ubsan_log_append(struct ubsan_violation
*);
190 void ubsan_format(struct ubsan_violation
*, struct ubsan_buf
*);
196 void __ubsan_handle_add_overflow(struct ubsan_overflow_desc
*, uint64_t lhs
, uint64_t rhs
);
197 void __ubsan_handle_add_overflow_abort(struct ubsan_overflow_desc
*, uint64_t lhs
, uint64_t rhs
);
198 void __ubsan_handle_builtin_unreachable(struct ubsan_unreachable_desc
*);
199 void __ubsan_handle_divrem_overflow(struct ubsan_overflow_desc
*, uint64_t lhs
, uint64_t rhs
);
200 void __ubsan_handle_divrem_overflow_abort(struct ubsan_overflow_desc
*, uint64_t lhs
, uint64_t rhs
);
201 void __ubsan_handle_float_cast_overflow(struct ubsan_float_desc
*, uint64_t);
202 void __ubsan_handle_float_cast_overflow_abort(struct ubsan_float_desc
*, uint64_t);
203 void __ubsan_handle_function_type_mismatch(struct ubsan_func_type_mismatch_desc
*, uint64_t);
204 void __ubsan_handle_function_type_mismatch_abort(struct ubsan_func_type_mismatch_desc
*, uint64_t);
205 void __ubsan_handle_implicit_conversion(struct ubsan_implicit_conv_desc
*, uint64_t, uint64_t);
206 void __ubsan_handle_implicit_conversion_abort(struct ubsan_implicit_conv_desc
*, uint64_t, uint64_t);
207 void __ubsan_handle_invalid_builtin(struct ubsan_invalid_builtin
*);
208 void __ubsan_handle_invalid_builtin_abort(struct ubsan_invalid_builtin
*);
209 void __ubsan_handle_load_invalid_value(struct ubsan_load_invalid_desc
*, uint64_t);
210 void __ubsan_handle_load_invalid_value_abort(struct ubsan_load_invalid_desc
*, uint64_t);
211 void __ubsan_handle_missing_return(struct ubsan_missing_ret_desc
*);
212 void __ubsan_handle_missing_return_abort(struct ubsan_missing_ret_desc
*);
213 void __ubsan_handle_mul_overflow(struct ubsan_overflow_desc
*, uint64_t lhs
, uint64_t rhs
);
214 void __ubsan_handle_mul_overflow_abort(struct ubsan_overflow_desc
*, uint64_t lhs
, uint64_t rhs
);
215 void __ubsan_handle_negate_overflow(struct ubsan_overflow_desc
*, uint64_t lhs
, uint64_t rhs
);
216 void __ubsan_handle_negate_overflow_abort(struct ubsan_overflow_desc
*, uint64_t lhs
, uint64_t rhs
);
217 void __ubsan_handle_nonnull_arg(struct ubsan_nullability_arg_desc
*);
218 void __ubsan_handle_nonnull_arg_abort(struct ubsan_nullability_arg_desc
*);
219 void __ubsan_handle_nonnull_return_v1(struct ubsan_nullability_ret_desc
*, uint64_t);
220 void __ubsan_handle_nonnull_return_v1_abort(struct ubsan_nullability_ret_desc
*, uint64_t);
221 void __ubsan_handle_nullability_arg(struct ubsan_nullability_arg_desc
*);
222 void __ubsan_handle_nullability_arg_abort(struct ubsan_nullability_arg_desc
*);
223 void __ubsan_handle_nullability_return_v1(struct ubsan_nullability_ret_desc
*, uint64_t);
224 void __ubsan_handle_nullability_return_v1_abort(struct ubsan_nullability_ret_desc
*, uint64_t);
225 void __ubsan_handle_out_of_bounds(struct ubsan_oob_desc
*, uint64_t idx
);
226 void __ubsan_handle_out_of_bounds_abort(struct ubsan_oob_desc
*, uint64_t idx
);
227 void __ubsan_handle_pointer_overflow(struct ubsan_ptroverflow_desc
*, uint64_t lhs
, uint64_t rhs
);
228 void __ubsan_handle_pointer_overflow_abort(struct ubsan_ptroverflow_desc
*, uint64_t lhs
, uint64_t rhs
);
229 void __ubsan_handle_shift_out_of_bounds(struct ubsan_shift_desc
*, uint64_t lhs
, uint64_t rhs
);
230 void __ubsan_handle_shift_out_of_bounds_abort(struct ubsan_shift_desc
*, uint64_t lhs
, uint64_t rhs
);
231 void __ubsan_handle_sub_overflow(struct ubsan_overflow_desc
*, uint64_t lhs
, uint64_t rhs
);
232 void __ubsan_handle_sub_overflow_abort(struct ubsan_overflow_desc
*, uint64_t lhs
, uint64_t rhs
);
233 void __ubsan_handle_type_mismatch_v1(struct ubsan_align_desc
*, uint64_t val
);
234 void __ubsan_handle_type_mismatch_v1_abort(struct ubsan_align_desc
*, uint64_t val
);
235 void __ubsan_handle_vla_bound_not_positive(struct ubsan_vla_bound_desc
*, uint64_t);
236 void __ubsan_handle_vla_bound_not_positive_abort(struct ubsan_vla_bound_desc
*, uint64_t);
238 #endif /* _UBSAN_H_ */