41#ifdef HAVE_UBSAN_SUPPORT
46__KERNEL_RCSID(0,
"$NetBSD: ubsan.c,v 1.6 2019/06/17 18:55:37 kamil Exp $");
48__RCSID(
"$NetBSD: ubsan.c,v 1.6 2019/06/17 18:55:37 kamil Exp $");
56#define ASSERT(x) KASSERT(x)
76#define ubsan_vsyslog vsyslog_ss
77#define ASSERT(x) _DIAGASSERT(x)
79#define ubsan_vsyslog vsyslog_r
80#define ASSERT(x) assert(x)
83#define SET(t, f) ((t) |= (f))
84#define ISSET(t, f) ((t) & (f))
85#define CLR(t, f) ((t) &= ~(f))
88#ifdef UBSAN_ALWAYS_FATAL
89static const bool alwaysFatal =
true;
91static const bool alwaysFatal =
false;
94#define REINTERPRET_CAST(__dt, __st) ((__dt)(__st))
95#define STATIC_CAST(__dt, __st) ((__dt)(__st))
97#define ACK_REPORTED __BIT(31)
100#define PLUS_STRING "+"
101#define MINUS_STRING "-"
102#define DIVREM_STRING "divrem"
106#define CFI_DERIVEDCAST 2
107#define CFI_UNRELATEDCAST 3
109#define CFI_NVMFCALL 5
112#define NUMBER_MAXLEN 128
113#define LOCATION_MAXLEN (PATH_MAX + 32 )
123#define NUMBER_SIGNED_BIT 1U
125#ifdef __SIZEOF_INT128__
126typedef __int128 longest;
127typedef unsigned __int128 ulongest;
134static int ubsan_flags = -1;
135#define UBSAN_ABORT __BIT(0)
136#define UBSAN_STDOUT __BIT(1)
137#define UBSAN_STDERR __BIT(2)
138#define UBSAN_SYSLOG __BIT(3)
143#define KIND_INTEGER 0
145#define KIND_UNKNOWN UINT16_MAX
147struct CSourceLocation {
153struct CTypeDescriptor {
159struct COverflowData {
160 struct CSourceLocation mLocation;
161 struct CTypeDescriptor *mType;
164struct CUnreachableData {
165 struct CSourceLocation mLocation;
168struct CCFICheckFailData {
170 struct CSourceLocation mLocation;
171 struct CTypeDescriptor *mType;
174struct CDynamicTypeCacheMissData {
175 struct CSourceLocation mLocation;
176 struct CTypeDescriptor *mType;
181struct CFunctionTypeMismatchData {
182 struct CSourceLocation mLocation;
183 struct CTypeDescriptor *mType;
186struct CImplicitConversionData {
187 struct CSourceLocation mLocation;
188 struct CTypeDescriptor *mFromType;
189 struct CTypeDescriptor *mToType;
193struct CInvalidBuiltinData {
194 struct CSourceLocation mLocation;
198struct CInvalidValueData {
199 struct CSourceLocation mLocation;
200 struct CTypeDescriptor *mType;
203struct CNonNullArgData {
204 struct CSourceLocation mLocation;
205 struct CSourceLocation mAttributeLocation;
209struct CNonNullReturnData {
210 struct CSourceLocation mAttributeLocation;
213struct COutOfBoundsData {
214 struct CSourceLocation mLocation;
215 struct CTypeDescriptor *mArrayType;
216 struct CTypeDescriptor *mIndexType;
219struct CPointerOverflowData {
220 struct CSourceLocation mLocation;
223struct CShiftOutOfBoundsData {
224 struct CSourceLocation mLocation;
225 struct CTypeDescriptor *mLHSType;
226 struct CTypeDescriptor *mRHSType;
229struct CTypeMismatchData {
230 struct CSourceLocation mLocation;
231 struct CTypeDescriptor *mType;
232 unsigned long mLogAlignment;
236struct CTypeMismatchData_v1 {
237 struct CSourceLocation mLocation;
238 struct CTypeDescriptor *mType;
243struct CVLABoundData {
244 struct CSourceLocation mLocation;
245 struct CTypeDescriptor *mType;
248struct CFloatCastOverflowData {
249 struct CSourceLocation mLocation;
250 struct CTypeDescriptor *mFromType;
251 struct CTypeDescriptor *mToType;
256static void EFIAPI Report(
bool isFatal,
const char *pFormat, ...)
__printflike(2, 3);
257static
bool isAlreadyReported(struct CSourceLocation *pLocation);
258static
size_t zDeserializeTypeWidth(struct CTypeDescriptor *pType);
259static
void DeserializeLocation(
char *pBuffer,
size_t zBUfferLength, struct CSourceLocation *pLocation);
260#ifdef __SIZEOF_INT128__
261static void DeserializeUINT128(
char *pBuffer,
size_t zBUfferLength,
struct CTypeDescriptor *pType, __uint128_t U128);
263static void DeserializeNumberSigned(
char *pBuffer,
size_t zBUfferLength,
struct CTypeDescriptor *pType, longest L);
264static void DeserializeNumberUnsigned(
char *pBuffer,
size_t zBUfferLength,
struct CTypeDescriptor *pType, ulongest L);
266static void DeserializeFloatOverPointer(
char *pBuffer,
size_t zBUfferLength,
struct CTypeDescriptor *pType,
unsigned long *pNumber);
267static void DeserializeFloatInlined(
char *pBuffer,
size_t zBUfferLength,
struct CTypeDescriptor *pType,
unsigned long ulNumber);
269static longest llliGetNumber(
char *szLocation,
struct CTypeDescriptor *pType,
unsigned long ulNumber);
270static ulongest llluGetNumber(
char *szLocation,
struct CTypeDescriptor *pType,
unsigned long ulNumber);
272static void DeserializeNumberFloat(
char *szLocation,
char *pBuffer,
size_t zBUfferLength,
struct CTypeDescriptor *pType,
unsigned long ulNumber);
274static void DeserializeNumber(
char *szLocation,
char *pBuffer,
size_t zBUfferLength,
struct CTypeDescriptor *pType,
unsigned long ulNumber);
275static const char *DeserializeTypeCheckKind(
uint8_t hhuTypeCheckKind);
276static const char *DeserializeBuiltinCheckKind(
uint8_t hhuBuiltinCheckKind);
277static const char *DeserializeCFICheckKind(
uint8_t hhuCFICheckKind);
278static const char *DeserializeImplicitConversionCheckKind(
uint8_t hhuImplicitConversionCheckKind);
279static bool isNegativeNumber(
char *szLocation,
struct CTypeDescriptor *pType,
unsigned long ulNumber);
280static bool isShiftExponentTooLarge(
char *szLocation,
struct CTypeDescriptor *pType,
unsigned long ulNumber,
size_t zWidth);
283intptr_t __ubsan_vptr_type_cache[128];
286void __ubsan_handle_add_overflow(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS);
287void __ubsan_handle_add_overflow_abort(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS);
288void __ubsan_handle_builtin_unreachable(
struct CUnreachableData *pData);
289void __ubsan_handle_cfi_bad_type(
struct CCFICheckFailData *pData,
unsigned long ulVtable,
bool bValidVtable,
bool FromUnrecoverableHandler,
unsigned long ProgramCounter,
unsigned long FramePointer);
290void __ubsan_handle_cfi_check_fail(
struct CCFICheckFailData *pData,
unsigned long ulValue,
unsigned long ulValidVtable);
291void __ubsan_handle_cfi_check_fail_abort(
struct CCFICheckFailData *pData,
unsigned long ulValue,
unsigned long ulValidVtable);
292void __ubsan_handle_divrem_overflow(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS);
293void __ubsan_handle_divrem_overflow_abort(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS);
294void __ubsan_handle_dynamic_type_cache_miss(
struct CDynamicTypeCacheMissData *pData,
unsigned long ulPointer,
unsigned long ulHash);
295void __ubsan_handle_dynamic_type_cache_miss_abort(
struct CDynamicTypeCacheMissData *pData,
unsigned long ulPointer,
unsigned long ulHash);
296void __ubsan_handle_float_cast_overflow(
struct CFloatCastOverflowData *pData,
unsigned long ulFrom);
297void __ubsan_handle_float_cast_overflow_abort(
struct CFloatCastOverflowData *pData,
unsigned long ulFrom);
298void __ubsan_handle_function_type_mismatch(
struct CFunctionTypeMismatchData *pData,
unsigned long ulFunction);
299void __ubsan_handle_function_type_mismatch_abort(
struct CFunctionTypeMismatchData *pData,
unsigned long ulFunction);
300void __ubsan_handle_implicit_conversion(
struct CImplicitConversionData *pData,
unsigned long ulFrom,
unsigned long ulTo);
301void __ubsan_handle_implicit_conversion_abort(
struct CImplicitConversionData *pData,
unsigned long ulFrom,
unsigned long ulTo);
302void __ubsan_handle_invalid_builtin(
struct CInvalidBuiltinData *pData);
303void __ubsan_handle_invalid_builtin_abort(
struct CInvalidBuiltinData *pData);
304void __ubsan_handle_load_invalid_value(
struct CInvalidValueData *pData,
unsigned long ulVal);
305void __ubsan_handle_load_invalid_value_abort(
struct CInvalidValueData *pData,
unsigned long ulVal);
306void __ubsan_handle_missing_return(
struct CUnreachableData *pData);
307void __ubsan_handle_mul_overflow(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS);
308void __ubsan_handle_mul_overflow_abort(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS);
309void __ubsan_handle_negate_overflow(
struct COverflowData *pData,
unsigned long ulOldVal);
310void __ubsan_handle_negate_overflow_abort(
struct COverflowData *pData,
unsigned long ulOldVal);
311void __ubsan_handle_nonnull_arg(
struct CNonNullArgData *pData);
312void __ubsan_handle_nonnull_arg_abort(
struct CNonNullArgData *pData);
313void __ubsan_handle_nonnull_return_v1(
struct CNonNullReturnData *pData,
struct CSourceLocation *pLocationPointer);
314void __ubsan_handle_nonnull_return_v1_abort(
struct CNonNullReturnData *pData,
struct CSourceLocation *pLocationPointer);
315void __ubsan_handle_nullability_arg(
struct CNonNullArgData *pData);
316void __ubsan_handle_nullability_arg_abort(
struct CNonNullArgData *pData);
317void __ubsan_handle_nullability_return_v1(
struct CNonNullReturnData *pData,
struct CSourceLocation *pLocationPointer);
318void __ubsan_handle_nullability_return_v1_abort(
struct CNonNullReturnData *pData,
struct CSourceLocation *pLocationPointer);
319void __ubsan_handle_out_of_bounds(
struct COutOfBoundsData *pData,
unsigned long ulIndex);
320void __ubsan_handle_out_of_bounds_abort(
struct COutOfBoundsData *pData,
unsigned long ulIndex);
321void __ubsan_handle_pointer_overflow(
struct CPointerOverflowData *pData,
unsigned long ulBase,
unsigned long ulResult);
322void __ubsan_handle_pointer_overflow_abort(
struct CPointerOverflowData *pData,
unsigned long ulBase,
unsigned long ulResult);
323void __ubsan_handle_shift_out_of_bounds(
struct CShiftOutOfBoundsData *pData,
unsigned long ulLHS,
unsigned long ulRHS);
324void __ubsan_handle_shift_out_of_bounds_abort(
struct CShiftOutOfBoundsData *pData,
unsigned long ulLHS,
unsigned long ulRHS);
325void __ubsan_handle_sub_overflow(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS);
326void __ubsan_handle_sub_overflow_abort(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS);
327void __ubsan_handle_type_mismatch(
struct CTypeMismatchData *pData,
unsigned long ulPointer);
328void __ubsan_handle_type_mismatch_abort(
struct CTypeMismatchData *pData,
unsigned long ulPointer);
329void __ubsan_handle_type_mismatch_v1(
struct CTypeMismatchData_v1 *pData,
unsigned long ulPointer);
330void __ubsan_handle_type_mismatch_v1_abort(
struct CTypeMismatchData_v1 *pData,
unsigned long ulPointer);
331void __ubsan_handle_vla_bound_not_positive(
struct CVLABoundData *pData,
unsigned long ulBound);
332void __ubsan_handle_vla_bound_not_positive_abort(
struct CVLABoundData *pData,
unsigned long ulBound);
333void __ubsan_get_current_report_data(
const char **ppOutIssueKind,
const char **ppOutMessage,
const char **ppOutFilename,
uint32_t *pOutLine,
uint32_t *pOutCol,
char **ppOutMemoryAddr);
335static void HandleOverflow(
bool isFatal,
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS,
const char *szOperation);
336static void HandleNegateOverflow(
bool isFatal,
struct COverflowData *pData,
unsigned long ulOldValue);
337static void HandleBuiltinUnreachable(
bool isFatal,
struct CUnreachableData *pData);
338static void HandleTypeMismatch(
bool isFatal,
struct CSourceLocation *mLocation,
struct CTypeDescriptor *mType,
unsigned long mLogAlignment,
uint8_t mTypeCheckKind,
unsigned long ulPointer);
339static void HandleVlaBoundNotPositive(
bool isFatal,
struct CVLABoundData *pData,
unsigned long ulBound);
340static void HandleOutOfBounds(
bool isFatal,
struct COutOfBoundsData *pData,
unsigned long ulIndex);
341static void HandleShiftOutOfBounds(
bool isFatal,
struct CShiftOutOfBoundsData *pData,
unsigned long ulLHS,
unsigned long ulRHS);
342static void HandleImplicitConversion(
bool isFatal,
struct CImplicitConversionData *pData,
unsigned long ulFrom,
unsigned long ulTo);
343static void HandleLoadInvalidValue(
bool isFatal,
struct CInvalidValueData *pData,
unsigned long ulValue);
344static void HandleInvalidBuiltin(
bool isFatal,
struct CInvalidBuiltinData *pData);
345static void HandleFunctionTypeMismatch(
bool isFatal,
struct CFunctionTypeMismatchData *pData,
unsigned long ulFunction);
346static void HandleCFIBadType(
bool isFatal,
struct CCFICheckFailData *pData,
unsigned long ulVtable,
bool *bValidVtable,
bool *FromUnrecoverableHandler,
unsigned long *ProgramCounter,
unsigned long *FramePointer);
347static void HandleDynamicTypeCacheMiss(
bool isFatal,
struct CDynamicTypeCacheMissData *pData,
unsigned long ulPointer,
unsigned long ulHash);
348static void HandleFloatCastOverflow(
bool isFatal,
struct CFloatCastOverflowData *pData,
unsigned long ulFrom);
349static void HandleMissingReturn(
bool isFatal,
struct CUnreachableData *pData);
350static void HandleNonnullArg(
bool isFatal,
struct CNonNullArgData *pData);
351static void HandleNonnullReturn(
bool isFatal,
struct CNonNullReturnData *pData,
struct CSourceLocation *pLocationPointer);
352static void HandlePointerOverflow(
bool isFatal,
struct CPointerOverflowData *pData,
unsigned long ulBase,
unsigned long ulResult);
355HandleOverflow(
bool isFatal,
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS,
const char *szOperation)
357 char szLocation[LOCATION_MAXLEN];
358 char szLHS[NUMBER_MAXLEN];
359 char szRHS[NUMBER_MAXLEN];
363 if (isAlreadyReported(&pData->mLocation))
366 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
367 DeserializeNumber(szLocation, szLHS, NUMBER_MAXLEN, pData->mType, ulLHS);
368 DeserializeNumber(szLocation, szRHS, NUMBER_MAXLEN, pData->mType, ulRHS);
370 Report(isFatal,
"UBSan: Undefined Behavior in %s, %s integer overflow: %s %s %s cannot be represented in type %s\n",
371 szLocation,
ISSET(pData->mType->mTypeInfo, NUMBER_SIGNED_BIT) ?
"signed" :
"unsigned", szLHS, szOperation, szRHS, pData->mType->mTypeName);
375HandleNegateOverflow(
bool isFatal,
struct COverflowData *pData,
unsigned long ulOldValue)
377 char szLocation[LOCATION_MAXLEN];
378 char szOldValue[NUMBER_MAXLEN];
382 if (isAlreadyReported(&pData->mLocation))
385 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
386 DeserializeNumber(szLocation, szOldValue, NUMBER_MAXLEN, pData->mType, ulOldValue);
388 Report(isFatal,
"UBSan: Undefined Behavior in %s, negation of %s cannot be represented in type %s\n",
389 szLocation, szOldValue, pData->mType->mTypeName);
393HandleBuiltinUnreachable(
bool isFatal,
struct CUnreachableData *pData)
395 char szLocation[LOCATION_MAXLEN];
399 if (isAlreadyReported(&pData->mLocation))
402 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
404 Report(isFatal,
"UBSan: Undefined Behavior in %s, calling __builtin_unreachable()\n",
409HandleTypeMismatch(
bool isFatal,
struct CSourceLocation *mLocation,
struct CTypeDescriptor *mType,
unsigned long mLogAlignment,
uint8_t mTypeCheckKind,
unsigned long ulPointer)
411 char szLocation[LOCATION_MAXLEN];
416 if (isAlreadyReported(mLocation))
419 DeserializeLocation(szLocation, LOCATION_MAXLEN, mLocation);
421 if (ulPointer == 0) {
422 Report(isFatal,
"UBSan: Undefined Behavior in %s, %s null pointer of type %s\n",
423 szLocation, DeserializeTypeCheckKind(mTypeCheckKind), mType->mTypeName);
424 }
else if ((mLogAlignment - 1) & ulPointer) {
425 Report(isFatal,
"UBSan: Undefined Behavior in %s, %s misaligned address %p for type %s which requires %ld byte alignment\n",
426 szLocation, DeserializeTypeCheckKind(mTypeCheckKind), REINTERPRET_CAST(
void *, (
uint64_t)ulPointer), mType->mTypeName, mLogAlignment);
428 Report(isFatal,
"UBSan: Undefined Behavior in %s, %s address %p with insufficient space for an object of type %s\n",
429 szLocation, DeserializeTypeCheckKind(mTypeCheckKind), REINTERPRET_CAST(
void *, (
uint64_t)ulPointer), mType->mTypeName);
434HandleVlaBoundNotPositive(
bool isFatal,
struct CVLABoundData *pData,
unsigned long ulBound)
436 char szLocation[LOCATION_MAXLEN];
437 char szBound[NUMBER_MAXLEN];
441 if (isAlreadyReported(&pData->mLocation))
444 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
445 DeserializeNumber(szLocation, szBound, NUMBER_MAXLEN, pData->mType, ulBound);
447 Report(isFatal,
"UBSan: Undefined Behavior in %s, variable length array bound value %s <= 0\n",
448 szLocation, szBound);
452HandleOutOfBounds(
bool isFatal,
struct COutOfBoundsData *pData,
unsigned long ulIndex)
454 char szLocation[LOCATION_MAXLEN];
455 char szIndex[NUMBER_MAXLEN];
459 if (isAlreadyReported(&pData->mLocation))
462 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
463 DeserializeNumber(szLocation, szIndex, NUMBER_MAXLEN, pData->mIndexType, ulIndex);
465 Report(isFatal,
"UBSan: Undefined Behavior in %s, index %s is out of range for type %s\n",
466 szLocation, szIndex, pData->mArrayType->mTypeName);
470HandleShiftOutOfBounds(
bool isFatal,
struct CShiftOutOfBoundsData *pData,
unsigned long ulLHS,
unsigned long ulRHS)
472 char szLocation[LOCATION_MAXLEN];
473 char szLHS[NUMBER_MAXLEN];
474 char szRHS[NUMBER_MAXLEN];
478 if (isAlreadyReported(&pData->mLocation))
481 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
482 DeserializeNumber(szLocation, szLHS, NUMBER_MAXLEN, pData->mLHSType, ulLHS);
483 DeserializeNumber(szLocation, szRHS, NUMBER_MAXLEN, pData->mRHSType, ulRHS);
485 if (isNegativeNumber(szLocation, pData->mRHSType, ulRHS))
486 Report(isFatal,
"UBSan: Undefined Behavior in %s, shift exponent %s is negative\n",
488 else if (isShiftExponentTooLarge(szLocation, pData->mRHSType, ulRHS, zDeserializeTypeWidth(pData->mLHSType)))
489 Report(isFatal,
"UBSan: Undefined Behavior in %s, shift exponent %s is too large for %zu-bit type %s\n",
490 szLocation, szRHS, zDeserializeTypeWidth(pData->mLHSType), pData->mLHSType->mTypeName);
491 else if (isNegativeNumber(szLocation, pData->mLHSType, ulLHS))
492 Report(isFatal,
"UBSan: Undefined Behavior in %s, left shift of negative value %s\n",
495 Report(isFatal,
"UBSan: Undefined Behavior in %s, left shift of %s by %s places cannot be represented in type %s\n",
496 szLocation, szLHS, szRHS, pData->mLHSType->mTypeName);
500HandleImplicitConversion(
bool isFatal,
struct CImplicitConversionData *pData,
unsigned long ulFrom,
unsigned long ulTo)
502 char szLocation[LOCATION_MAXLEN];
503 char szFrom[NUMBER_MAXLEN];
504 char szTo[NUMBER_MAXLEN];
508 if (isAlreadyReported(&pData->mLocation))
511 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
512 DeserializeNumber(szLocation, szFrom, NUMBER_MAXLEN, pData->mFromType, ulFrom);
513 DeserializeNumber(szLocation, szTo, NUMBER_MAXLEN, pData->mToType, ulTo);
515 Report(isFatal,
"UBSan: Undefined Behavior in %s, %s from %s to %s\n",
516 szLocation, DeserializeImplicitConversionCheckKind(pData->mKind), pData->mFromType->mTypeName, pData->mToType->mTypeName);
520HandleLoadInvalidValue(
bool isFatal,
struct CInvalidValueData *pData,
unsigned long ulValue)
522 char szLocation[LOCATION_MAXLEN];
523 char szValue[NUMBER_MAXLEN];
527 if (isAlreadyReported(&pData->mLocation))
530 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
531 DeserializeNumber(szLocation, szValue, NUMBER_MAXLEN, pData->mType, ulValue);
533 Report(isFatal,
"UBSan: Undefined Behavior in %s, load of value %s is not a valid value for type %s\n",
534 szLocation, szValue, pData->mType->mTypeName);
538HandleInvalidBuiltin(
bool isFatal,
struct CInvalidBuiltinData *pData)
540 char szLocation[LOCATION_MAXLEN];
544 if (isAlreadyReported(&pData->mLocation))
547 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
549 Report(isFatal,
"UBSan: Undefined Behavior in %s, passing zero to %s, which is not a valid argument\n",
550 szLocation, DeserializeBuiltinCheckKind(pData->mKind));
554HandleFunctionTypeMismatch(
bool isFatal,
struct CFunctionTypeMismatchData *pData,
unsigned long ulFunction)
556 char szLocation[LOCATION_MAXLEN];
570 if (isAlreadyReported(&pData->mLocation))
573 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
575 Report(isFatal,
"UBSan: Undefined Behavior in %s, call to function %#lx through pointer to incorrect function type %s\n",
576 szLocation, ulFunction, pData->mType->mTypeName);
580HandleCFIBadType(
bool isFatal,
struct CCFICheckFailData *pData,
unsigned long ulVtable,
bool *bValidVtable,
bool *FromUnrecoverableHandler,
unsigned long *ProgramCounter,
unsigned long *FramePointer)
582 char szLocation[LOCATION_MAXLEN];
591 if (isAlreadyReported(&pData->mLocation))
594 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
596 if (pData->mCheckKind == CFI_ICALL || pData->mCheckKind == CFI_VMFCALL) {
597 Report(isFatal,
"UBSan: Undefined Behavior in %s, control flow integrity check for type %s failed during %s (vtable address %#lx)\n",
598 szLocation, pData->mType->mTypeName, DeserializeCFICheckKind(pData->mCheckKind), ulVtable);
600 Report(isFatal || FromUnrecoverableHandler,
"UBSan: Undefined Behavior in %s, control flow integrity check for type %s failed during %s (vtable address %#lx; %s vtable; from %s handler; Program Counter %#lx; Frame Pointer %#lx)\n",
601 szLocation, pData->mType->mTypeName, DeserializeCFICheckKind(pData->mCheckKind), ulVtable, *bValidVtable ?
"valid" :
"invalid", *FromUnrecoverableHandler ?
"unrecoverable" :
"recoverable", *ProgramCounter, *FramePointer);
606HandleDynamicTypeCacheMiss(
bool isFatal,
struct CDynamicTypeCacheMissData *pData,
unsigned long ulPointer,
unsigned long ulHash)
609 char szLocation[LOCATION_MAXLEN];
622 if (isAlreadyReported(&pData->mLocation))
625 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
627 Report(isFatal,
"UBSan: Undefined Behavior in %s, %s address %#lx which might not point to an object of type %s\n"
628 szLocation, DeserializeTypeCheckKind(pData->mTypeCheckKind), ulPointer, pData->mType);
633HandleFloatCastOverflow(
bool isFatal,
struct CFloatCastOverflowData *pData,
unsigned long ulFrom)
635 char szLocation[LOCATION_MAXLEN];
636 char szFrom[NUMBER_MAXLEN];
640 if (isAlreadyReported(&pData->mLocation))
643 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
644 DeserializeNumber(szLocation, szFrom, NUMBER_MAXLEN, pData->mFromType, ulFrom);
646 Report(isFatal,
"UBSan: Undefined Behavior in %s, %s (of type %s) is outside the range of representable values of type %s\n",
647 szLocation, szFrom, pData->mFromType->mTypeName, pData->mToType->mTypeName);
651HandleMissingReturn(
bool isFatal,
struct CUnreachableData *pData)
653 char szLocation[LOCATION_MAXLEN];
657 if (isAlreadyReported(&pData->mLocation))
660 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
662 Report(isFatal,
"UBSan: Undefined Behavior in %s, execution reached the end of a value-returning function without returning a value\n",
667HandleNonnullArg(
bool isFatal,
struct CNonNullArgData *pData)
669 char szLocation[LOCATION_MAXLEN];
670 char szAttributeLocation[LOCATION_MAXLEN];
674 if (isAlreadyReported(&pData->mLocation))
677 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
678 if (pData->mAttributeLocation.mFilename)
679 DeserializeLocation(szAttributeLocation, LOCATION_MAXLEN, &pData->mAttributeLocation);
681 szAttributeLocation[0] =
'\0';
683 Report(isFatal,
"UBSan: Undefined Behavior in %s, null pointer passed as argument %d, which is declared to never be null%s%s\n",
684 szLocation, pData->mArgIndex, pData->mAttributeLocation.mFilename ?
", nonnull/_Nonnull specified in " :
"", szAttributeLocation);
688HandleNonnullReturn(
bool isFatal,
struct CNonNullReturnData *pData,
struct CSourceLocation *pLocationPointer)
690 char szLocation[LOCATION_MAXLEN];
691 char szAttributeLocation[LOCATION_MAXLEN];
696 if (isAlreadyReported(pLocationPointer))
699 DeserializeLocation(szLocation, LOCATION_MAXLEN, pLocationPointer);
700 if (pData->mAttributeLocation.mFilename)
701 DeserializeLocation(szAttributeLocation, LOCATION_MAXLEN, &pData->mAttributeLocation);
703 szAttributeLocation[0] =
'\0';
705 Report(isFatal,
"UBSan: Undefined Behavior in %s, null pointer returned from function declared to never return null%s%s\n",
706 szLocation, pData->mAttributeLocation.mFilename ?
", nonnull/_Nonnull specified in " :
"", szAttributeLocation);
710HandlePointerOverflow(
bool isFatal,
struct CPointerOverflowData *pData,
unsigned long ulBase,
unsigned long ulResult)
712 char szLocation[LOCATION_MAXLEN];
716 if (isAlreadyReported(&pData->mLocation))
719 DeserializeLocation(szLocation, LOCATION_MAXLEN, &pData->mLocation);
721 Report(isFatal,
"UBSan: Undefined Behavior in %s, pointer expression with base %#lx overflowed to %#lx\n",
722 szLocation, ulBase, ulResult);
727__ubsan_handle_add_overflow(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS)
732 HandleOverflow(
false, pData, ulLHS, ulRHS, PLUS_STRING);
736__ubsan_handle_add_overflow_abort(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS)
741 HandleOverflow(
true, pData, ulLHS, ulRHS, PLUS_STRING);
745__ubsan_handle_builtin_unreachable(
struct CUnreachableData *pData)
750 HandleBuiltinUnreachable(
true, pData);
754__ubsan_handle_cfi_bad_type(
struct CCFICheckFailData *pData,
unsigned long ulVtable,
bool bValidVtable,
bool FromUnrecoverableHandler,
unsigned long ProgramCounter,
unsigned long FramePointer)
759 HandleCFIBadType(
false, pData, ulVtable, &bValidVtable, &FromUnrecoverableHandler, &ProgramCounter, &FramePointer);
763__ubsan_handle_cfi_check_fail(
struct CCFICheckFailData *pData,
unsigned long ulValue,
unsigned long ulValidVtable)
768 HandleCFIBadType(
false, pData, ulValue, 0, 0, 0, 0);
772__ubsan_handle_cfi_check_fail_abort(
struct CCFICheckFailData *pData,
unsigned long ulValue,
unsigned long ulValidVtable)
777 HandleCFIBadType(
true, pData, ulValue, 0, 0, 0, 0);
781__ubsan_handle_divrem_overflow(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS)
786 HandleOverflow(
false, pData, ulLHS, ulRHS, DIVREM_STRING);
790__ubsan_handle_divrem_overflow_abort(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS)
795 HandleOverflow(
true, pData, ulLHS, ulRHS, DIVREM_STRING);
799__ubsan_handle_dynamic_type_cache_miss(
struct CDynamicTypeCacheMissData *pData,
unsigned long ulPointer,
unsigned long ulHash)
804 HandleDynamicTypeCacheMiss(
false, pData, ulPointer, ulHash);
808__ubsan_handle_dynamic_type_cache_miss_abort(
struct CDynamicTypeCacheMissData *pData,
unsigned long ulPointer,
unsigned long ulHash)
813 HandleDynamicTypeCacheMiss(
false, pData, ulPointer, ulHash);
817__ubsan_handle_float_cast_overflow(
struct CFloatCastOverflowData *pData,
unsigned long ulFrom)
822 HandleFloatCastOverflow(
false, pData, ulFrom);
826__ubsan_handle_float_cast_overflow_abort(
struct CFloatCastOverflowData *pData,
unsigned long ulFrom)
831 HandleFloatCastOverflow(
true, pData, ulFrom);
835__ubsan_handle_function_type_mismatch(
struct CFunctionTypeMismatchData *pData,
unsigned long ulFunction)
840 HandleFunctionTypeMismatch(
false, pData, ulFunction);
844__ubsan_handle_function_type_mismatch_abort(
struct CFunctionTypeMismatchData *pData,
unsigned long ulFunction)
849 HandleFunctionTypeMismatch(
false, pData, ulFunction);
853__ubsan_handle_implicit_conversion(
struct CImplicitConversionData *pData,
unsigned long ulFrom,
unsigned long ulTo)
857 HandleImplicitConversion(
false, pData, ulFrom, ulTo);
861__ubsan_handle_implicit_conversion_abort(
struct CImplicitConversionData *pData,
unsigned long ulFrom,
unsigned long ulTo)
866 HandleImplicitConversion(
false, pData, ulFrom, ulTo);
870__ubsan_handle_invalid_builtin(
struct CInvalidBuiltinData *pData)
875 HandleInvalidBuiltin(
true, pData);
879__ubsan_handle_invalid_builtin_abort(
struct CInvalidBuiltinData *pData)
884 HandleInvalidBuiltin(
true, pData);
888__ubsan_handle_load_invalid_value(
struct CInvalidValueData *pData,
unsigned long ulValue)
893 HandleLoadInvalidValue(
false, pData, ulValue);
897__ubsan_handle_load_invalid_value_abort(
struct CInvalidValueData *pData,
unsigned long ulValue)
902 HandleLoadInvalidValue(
true, pData, ulValue);
906__ubsan_handle_missing_return(
struct CUnreachableData *pData)
911 HandleMissingReturn(
true, pData);
915__ubsan_handle_mul_overflow(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS)
920 HandleOverflow(
false, pData, ulLHS, ulRHS, MUL_STRING);
924__ubsan_handle_mul_overflow_abort(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS)
929 HandleOverflow(
true, pData, ulLHS, ulRHS, MUL_STRING);
933__ubsan_handle_negate_overflow(
struct COverflowData *pData,
unsigned long ulOldValue)
938 HandleNegateOverflow(
false, pData, ulOldValue);
942__ubsan_handle_negate_overflow_abort(
struct COverflowData *pData,
unsigned long ulOldValue)
947 HandleNegateOverflow(
true, pData, ulOldValue);
951__ubsan_handle_nonnull_arg(
struct CNonNullArgData *pData)
956 HandleNonnullArg(
false, pData);
960__ubsan_handle_nonnull_arg_abort(
struct CNonNullArgData *pData)
965 HandleNonnullArg(
true, pData);
969__ubsan_handle_nonnull_return_v1(
struct CNonNullReturnData *pData,
struct CSourceLocation *pLocationPointer)
975 HandleNonnullReturn(
false, pData, pLocationPointer);
979__ubsan_handle_nonnull_return_v1_abort(
struct CNonNullReturnData *pData,
struct CSourceLocation *pLocationPointer)
985 HandleNonnullReturn(
true, pData, pLocationPointer);
989__ubsan_handle_nullability_arg(
struct CNonNullArgData *pData)
994 HandleNonnullArg(
false, pData);
998__ubsan_handle_nullability_arg_abort(
struct CNonNullArgData *pData)
1003 HandleNonnullArg(
true, pData);
1007__ubsan_handle_nullability_return_v1(
struct CNonNullReturnData *pData,
struct CSourceLocation *pLocationPointer)
1011 ASSERT(pLocationPointer);
1013 HandleNonnullReturn(
false, pData, pLocationPointer);
1017__ubsan_handle_nullability_return_v1_abort(
struct CNonNullReturnData *pData,
struct CSourceLocation *pLocationPointer)
1021 ASSERT(pLocationPointer);
1023 HandleNonnullReturn(
true, pData, pLocationPointer);
1027__ubsan_handle_out_of_bounds(
struct COutOfBoundsData *pData,
unsigned long ulIndex)
1032 HandleOutOfBounds(
false, pData, ulIndex);
1036__ubsan_handle_out_of_bounds_abort(
struct COutOfBoundsData *pData,
unsigned long ulIndex)
1041 HandleOutOfBounds(
true, pData, ulIndex);
1045__ubsan_handle_pointer_overflow(
struct CPointerOverflowData *pData,
unsigned long ulBase,
unsigned long ulResult)
1050 HandlePointerOverflow(
false, pData, ulBase, ulResult);
1054__ubsan_handle_pointer_overflow_abort(
struct CPointerOverflowData *pData,
unsigned long ulBase,
unsigned long ulResult)
1059 HandlePointerOverflow(
true, pData, ulBase, ulResult);
1063__ubsan_handle_shift_out_of_bounds(
struct CShiftOutOfBoundsData *pData,
unsigned long ulLHS,
unsigned long ulRHS)
1068 HandleShiftOutOfBounds(
false, pData, ulLHS, ulRHS);
1072__ubsan_handle_shift_out_of_bounds_abort(
struct CShiftOutOfBoundsData *pData,
unsigned long ulLHS,
unsigned long ulRHS)
1077 HandleShiftOutOfBounds(
true, pData, ulLHS, ulRHS);
1081__ubsan_handle_sub_overflow(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS)
1086 HandleOverflow(
false, pData, ulLHS, ulRHS, MINUS_STRING);
1090__ubsan_handle_sub_overflow_abort(
struct COverflowData *pData,
unsigned long ulLHS,
unsigned long ulRHS)
1095 HandleOverflow(
true, pData, ulLHS, ulRHS, MINUS_STRING);
1099__ubsan_handle_type_mismatch(
struct CTypeMismatchData *pData,
unsigned long ulPointer)
1104 HandleTypeMismatch(
false, &pData->mLocation, pData->mType, pData->mLogAlignment, pData->mTypeCheckKind, ulPointer);
1108__ubsan_handle_type_mismatch_abort(
struct CTypeMismatchData *pData,
unsigned long ulPointer)
1113 HandleTypeMismatch(
true, &pData->mLocation, pData->mType, pData->mLogAlignment, pData->mTypeCheckKind, ulPointer);
1117__ubsan_handle_type_mismatch_v1(
struct CTypeMismatchData_v1 *pData,
unsigned long ulPointer)
1122 HandleTypeMismatch(
false, &pData->mLocation, pData->mType,
__BIT(pData->mLogAlignment), pData->mTypeCheckKind, ulPointer);
1126__ubsan_handle_type_mismatch_v1_abort(
struct CTypeMismatchData_v1 *pData,
unsigned long ulPointer)
1131 HandleTypeMismatch(
true, &pData->mLocation, pData->mType,
__BIT(pData->mLogAlignment), pData->mTypeCheckKind, ulPointer);
1135__ubsan_handle_vla_bound_not_positive(
struct CVLABoundData *pData,
unsigned long ulBound)
1140 HandleVlaBoundNotPositive(
false, pData, ulBound);
1144__ubsan_handle_vla_bound_not_positive_abort(
struct CVLABoundData *pData,
unsigned long ulBound)
1149 HandleVlaBoundNotPositive(
true, pData, ulBound);
1153__ubsan_get_current_report_data(
const char **ppOutIssueKind,
const char **ppOutMessage,
const char **ppOutFilename,
uint32_t *pOutLine,
uint32_t *pOutCol,
char **ppOutMemoryAddr)
1180Report(
bool isFatal,
const char *pFormat, ...)
1188 if (isFatal || alwaysFatal)
1193 if (ubsan_flags == -1) {
1197 ubsan_flags = UBSAN_STDERR;
1199 if (getenv_r(
"LIBC_UBSAN", buf,
sizeof(buf)) != -1) {
1200 for (p = buf; *p; p++) {
1203 SET(ubsan_flags, UBSAN_ABORT);
1206 CLR(ubsan_flags, UBSAN_ABORT);
1209 SET(ubsan_flags, UBSAN_STDERR);
1212 CLR(ubsan_flags, UBSAN_STDERR);
1215 SET(ubsan_flags, UBSAN_SYSLOG);
1218 CLR(ubsan_flags, UBSAN_SYSLOG);
1221 SET(ubsan_flags, UBSAN_STDOUT);
1224 CLR(ubsan_flags, UBSAN_STDOUT);
1235 if (
ISSET(ubsan_flags, UBSAN_STDOUT)) {
1242 if (
ISSET(ubsan_flags, UBSAN_STDERR)) {
1245 vfprintf(stderr, pFormat, tmp);
1249 if (
ISSET(ubsan_flags, UBSAN_SYSLOG)) {
1252 struct syslog_data SyslogData = SYSLOG_DATA_INIT;
1253 ubsan_vsyslog(LOG_DEBUG | LOG_USER, &SyslogData, pFormat, tmp);
1256 if (isFatal || alwaysFatal ||
ISSET(ubsan_flags, UBSAN_ABORT)) {
1266isAlreadyReported(
struct CSourceLocation *pLocation)
1278 pLine = &pLocation->mLine;
1281 siOldValue = *pLine;
1282 }
while (__sync_val_compare_and_swap(pLine, siOldValue, siOldValue | ACK_REPORTED) != siOldValue);
1284 return ISSET(siOldValue, ACK_REPORTED);
1288zDeserializeTypeWidth(
struct CTypeDescriptor *pType)
1294 switch (pType->mTypeKind) {
1299 zWidth = pType->mTypeInfo;
1302 Report(
true,
"UBSan: Unknown variable type %#04" PRIx16 "\n", pType->mTypeKind);
1314DeserializeLocation(
char *pBuffer,
size_t zBUfferLength,
struct CSourceLocation *pLocation)
1318 ASSERT(pLocation->mFilename);
1320 snprintf(pBuffer, zBUfferLength,
"%s:%" PRIu32 ":%" PRIu32, pLocation->mFilename, pLocation->mLine & (
uint32_t)~ACK_REPORTED, pLocation->mColumn);
1323#ifdef __SIZEOF_INT128__
1325DeserializeUINT128(
char *pBuffer,
size_t zBUfferLength,
struct CTypeDescriptor *pType, __uint128_t U128)
1328 char rgNumber[
sizeof(ulongest)];
1331 memcpy(rgNumber, &U128,
sizeof(U128));
1333 strlcpy(pBuffer,
"Undecoded-128-bit-Integer-Type (0x", zBUfferLength);
1334#if BYTE_ORDER == LITTLE_ENDIAN
1335 for (zI =
sizeof(ulongest) - 1; zI >= 0; zI--) {
1337 for (zI = 0; zI < (
ssize_t)
sizeof(ulongest); zI++) {
1340 strlcat(pBuffer, szBuf, zBUfferLength);
1342 strlcat(pBuffer,
")", zBUfferLength);
1347DeserializeNumberSigned(
char *pBuffer,
size_t zBUfferLength,
struct CTypeDescriptor *pType, longest L)
1351 ASSERT(zBUfferLength > 0);
1353 ASSERT(
ISSET(pType->mTypeInfo, NUMBER_SIGNED_BIT));
1355 switch (zDeserializeTypeWidth(pType)) {
1357 ASSERT(0 &&
"Invalid codepath");
1360#ifdef __SIZEOF_INT128__
1362 DeserializeUINT128(pBuffer, zBUfferLength, pType, STATIC_CAST(__uint128_t, L));
1372 snprintf(pBuffer, zBUfferLength,
"%lld", STATIC_CAST(
long long, L));
1378DeserializeNumberUnsigned(
char *pBuffer,
size_t zBUfferLength,
struct CTypeDescriptor *pType, ulongest L)
1382 ASSERT(zBUfferLength > 0);
1384 ASSERT(!
ISSET(pType->mTypeInfo, NUMBER_SIGNED_BIT));
1386 switch (zDeserializeTypeWidth(pType)) {
1388 ASSERT(0 &&
"Invalid codepath");
1391#ifdef __SIZEOF_INT128__
1393 DeserializeUINT128(pBuffer, zBUfferLength, pType, STATIC_CAST(__uint128_t, L));
1403 snprintf(pBuffer, zBUfferLength,
"%llu", STATIC_CAST(
unsigned long long, L));
1410DeserializeFloatOverPointer(
char *pBuffer,
size_t zBUfferLength,
struct CTypeDescriptor *pType,
unsigned long *pNumber)
1413#ifdef __HAVE_LONG_DOUBLE
1418 ASSERT(zBUfferLength > 0);
1424 ASSERT((
sizeof(*pNumber) *
CHAR_BIT < WIDTH_64) || (zDeserializeTypeWidth(pType) >= WIDTH_64));
1426#ifdef __HAVE_LONG_DOUBLE
1430 switch (zDeserializeTypeWidth(pType)) {
1431#ifdef __HAVE_LONG_DOUBLE
1437 memcpy(&LD, pNumber,
sizeof(
long double));
1438 snprintf(pBuffer, zBUfferLength,
"%Lg", LD);
1442 memcpy(&D, pNumber,
sizeof(
double));
1443 snprintf(pBuffer, zBUfferLength,
"%g", D);
1449DeserializeFloatInlined(
char *pBuffer,
size_t zBUfferLength,
struct CTypeDescriptor *pType,
unsigned long ulNumber)
1456 ASSERT(zBUfferLength > 0);
1461 switch (zDeserializeTypeWidth(pType)) {
1463 memcpy(&D, &ulNumber,
sizeof(
double));
1464 snprintf(pBuffer, zBUfferLength,
"%g", D);
1472 U32 = STATIC_CAST(
uint32_t, ulNumber);
1473 memcpy(&
F, &U32,
sizeof(
float));
1474 snprintf(pBuffer, zBUfferLength,
"%g",
F);
1477 snprintf(pBuffer, zBUfferLength,
"Undecoded-16-bit-Floating-Type (%#04" PRIx16 ")", STATIC_CAST(
uint16_t, ulNumber));
1484llliGetNumber(
char *szLocation,
struct CTypeDescriptor *pType,
unsigned long ulNumber)
1486 size_t zNumberWidth;
1492 zNumberWidth = zDeserializeTypeWidth(pType);
1493 switch (zNumberWidth) {
1495 Report(
true,
"UBSan: Unexpected %zu-Bit Type in %s\n", zNumberWidth, szLocation);
1499#ifdef __SIZEOF_INT128__
1500 memcpy(&L, REINTERPRET_CAST(longest *, (longest)ulNumber),
sizeof(longest));
1503 Report(
true,
"UBSan: Unexpected 128-Bit Type in %s\n", szLocation);
1508 if (
sizeof(ulNumber) *
CHAR_BIT < WIDTH_64) {
1529llluGetNumber(
char *szLocation,
struct CTypeDescriptor *pType,
unsigned long ulNumber)
1531 size_t zNumberWidth;
1536 zNumberWidth = zDeserializeTypeWidth(pType);
1537 switch (zNumberWidth) {
1539 Report(
true,
"UBSan: Unexpected %zu-Bit Type in %s\n", zNumberWidth, szLocation);
1543#ifdef __SIZEOF_INT128__
1544 memcpy(&UL, REINTERPRET_CAST(ulongest *, (ulongest)ulNumber),
sizeof(ulongest));
1547 Report(
true,
"UBSan: Unexpected 128-Bit Type in %s\n", szLocation);
1552 if (
sizeof(ulNumber) *
CHAR_BIT < WIDTH_64) {
1571DeserializeNumberFloat(
char *szLocation,
char *pBuffer,
size_t zBUfferLength,
struct CTypeDescriptor *pType,
unsigned long ulNumber)
1573 size_t zNumberWidth;
1577 ASSERT(zBUfferLength > 0);
1579 ASSERT(pType->mTypeKind == KIND_FLOAT);
1581 zNumberWidth = zDeserializeTypeWidth(pType);
1582 switch (zNumberWidth) {
1584 Report(
true,
"UBSan: Unexpected %zu-Bit Type in %s\n", zNumberWidth, szLocation);
1587#ifdef __HAVE_LONG_DOUBLE
1593 DeserializeFloatOverPointer(pBuffer, zBUfferLength, pType, REINTERPRET_CAST(
unsigned long *, ulNumber));
1597 if (
sizeof(ulNumber) *
CHAR_BIT < WIDTH_64) {
1598 DeserializeFloatOverPointer(pBuffer, zBUfferLength, pType, REINTERPRET_CAST(
unsigned long *, ulNumber));
1605 DeserializeFloatInlined(pBuffer, zBUfferLength, pType, ulNumber);
1612DeserializeNumber(
char *szLocation,
char *pBuffer,
size_t zBUfferLength,
struct CTypeDescriptor *pType,
unsigned long ulNumber)
1617 ASSERT(zBUfferLength > 0);
1620 switch(pType->mTypeKind) {
1622 if (
ISSET(pType->mTypeInfo, NUMBER_SIGNED_BIT)) {
1623 longest L = llliGetNumber(szLocation, pType, ulNumber);
1624 DeserializeNumberSigned(pBuffer, zBUfferLength, pType, L);
1626 ulongest UL = llluGetNumber(szLocation, pType, ulNumber);
1627 DeserializeNumberUnsigned(pBuffer, zBUfferLength, pType, UL);
1632 Report(
true,
"UBSan: Unexpected Float Type in %s\n", szLocation);
1636 DeserializeNumberFloat(szLocation, pBuffer, zBUfferLength, pType, ulNumber);
1640 Report(
true,
"UBSan: Unknown Type in %s\n", szLocation);
1647DeserializeTypeCheckKind(
uint8_t hhuTypeCheckKind)
1649 const char *rgczTypeCheckKinds[] = {
1652 "reference binding to",
1653 "member access within",
1655 "constructor call on",
1659 "cast to virtual base of",
1660 "_Nonnull binding to",
1661 "dynamic operation on"
1666 return rgczTypeCheckKinds[hhuTypeCheckKind];
1670DeserializeBuiltinCheckKind(
uint8_t hhuBuiltinCheckKind)
1672 const char *rgczBuiltinCheckKinds[] = {
1679 return rgczBuiltinCheckKinds[hhuBuiltinCheckKind];
1683DeserializeCFICheckKind(
uint8_t hhuCFICheckKind)
1685 const char *rgczCFICheckKinds[] = {
1688 "base-to-derived cast",
1689 "cast to unrelated type",
1690 "indirect function call",
1691 "non-virtual pointer to member function call",
1692 "virtual pointer to member function call",
1697 return rgczCFICheckKinds[hhuCFICheckKind];
1701DeserializeImplicitConversionCheckKind(
uint8_t hhuImplicitConversionCheckKind)
1703 const char *rgczImplicitConversionCheckKind[] = {
1704 "integer truncation",
1705 "unsigned integer truncation",
1706 "signed integer truncation",
1707 "integer sign change",
1708 "signed integer trunctation or sign change",
1711 ASSERT(
__arraycount(rgczImplicitConversionCheckKind) > hhuImplicitConversionCheckKind);
1713 return rgczImplicitConversionCheckKind[hhuImplicitConversionCheckKind];
1717isNegativeNumber(
char *szLocation,
struct CTypeDescriptor *pType,
unsigned long ulNumber)
1722 ASSERT(pType->mTypeKind == KIND_INTEGER);
1724 if (!
ISSET(pType->mTypeInfo, NUMBER_SIGNED_BIT))
1727 return llliGetNumber(szLocation, pType, ulNumber) < 0;
1731isShiftExponentTooLarge(
char *szLocation,
struct CTypeDescriptor *pType,
unsigned long ulNumber,
size_t zWidth)
1736 ASSERT(pType->mTypeKind == KIND_INTEGER);
1738 return llluGetNumber(szLocation, pType, ulNumber) >= zWidth;
#define __printflike(x, y)
#define __KERNEL_RCSID(x, s)
#define strlcat(Dst, Src, Size)
#define strlcpy(Dst, Src, Size)
#define __SHIFTOUT(__x, __mask)
#define memcpy(Dst, Src, Size)