2021-02-05 21:44:26 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-05 21:44:26 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Types.h>
|
|
|
|
|
2021-05-24 04:33:40 +03:00
|
|
|
namespace AK::UBSanitizer {
|
2021-02-05 21:44:26 +03:00
|
|
|
|
2021-03-05 00:07:23 +03:00
|
|
|
extern bool g_ubsan_is_deadly;
|
|
|
|
|
2021-02-11 22:58:01 +03:00
|
|
|
typedef void* ValueHandle;
|
|
|
|
|
2021-02-05 21:44:26 +03:00
|
|
|
class SourceLocation {
|
|
|
|
public:
|
|
|
|
const char* filename() const { return m_filename; }
|
|
|
|
u32 line() const { return m_line; }
|
|
|
|
u32 column() const { return m_column; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* m_filename;
|
|
|
|
u32 m_line;
|
|
|
|
u32 m_column;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum TypeKind : u16 {
|
|
|
|
Integer = 0,
|
|
|
|
Float = 1,
|
|
|
|
Unknown = 0xffff,
|
|
|
|
};
|
|
|
|
|
|
|
|
class TypeDescriptor {
|
|
|
|
public:
|
|
|
|
const char* name() const { return m_name; }
|
|
|
|
TypeKind kind() const { return (TypeKind)m_kind; }
|
|
|
|
bool is_integer() const { return kind() == TypeKind::Integer; }
|
|
|
|
bool is_signed() const { return m_info & 1; }
|
|
|
|
bool is_unsigned() const { return !is_signed(); }
|
|
|
|
size_t bit_width() const { return 1 << (m_info >> 1); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
u16 m_kind;
|
|
|
|
u16 m_info;
|
|
|
|
char m_name[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InvalidValueData {
|
|
|
|
SourceLocation location;
|
|
|
|
const TypeDescriptor& type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NonnullArgData {
|
|
|
|
SourceLocation location;
|
|
|
|
SourceLocation attribute_location;
|
|
|
|
int argument_index;
|
|
|
|
};
|
|
|
|
|
2021-02-07 10:24:49 +03:00
|
|
|
struct NonnullReturnData {
|
|
|
|
SourceLocation attribute_location;
|
|
|
|
};
|
|
|
|
|
2021-02-05 22:03:07 +03:00
|
|
|
struct OverflowData {
|
|
|
|
SourceLocation location;
|
|
|
|
const TypeDescriptor& type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VLABoundData {
|
|
|
|
SourceLocation location;
|
|
|
|
const TypeDescriptor& type;
|
|
|
|
};
|
|
|
|
|
2021-02-06 18:08:30 +03:00
|
|
|
struct ShiftOutOfBoundsData {
|
|
|
|
SourceLocation location;
|
|
|
|
const TypeDescriptor& lhs_type;
|
|
|
|
const TypeDescriptor& rhs_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OutOfBoundsData {
|
|
|
|
SourceLocation location;
|
|
|
|
const TypeDescriptor& array_type;
|
|
|
|
const TypeDescriptor& index_type;
|
|
|
|
};
|
|
|
|
|
2021-02-06 19:34:44 +03:00
|
|
|
struct TypeMismatchData {
|
|
|
|
SourceLocation location;
|
|
|
|
const TypeDescriptor& type;
|
|
|
|
u8 log_alignment;
|
|
|
|
u8 type_check_kind;
|
|
|
|
};
|
|
|
|
|
2021-02-11 22:58:01 +03:00
|
|
|
struct AlignmentAssumptionData {
|
|
|
|
SourceLocation location;
|
|
|
|
SourceLocation assumption_location;
|
|
|
|
const TypeDescriptor& type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UnreachableData {
|
|
|
|
SourceLocation location;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ImplicitConversionData {
|
|
|
|
SourceLocation location;
|
|
|
|
const TypeDescriptor& from_type;
|
|
|
|
const TypeDescriptor& to_type;
|
|
|
|
/* ImplicitConversionCheckKind */ unsigned char kind;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InvalidBuiltinData {
|
|
|
|
SourceLocation location;
|
|
|
|
unsigned char kind;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PointerOverflowData {
|
|
|
|
SourceLocation location;
|
|
|
|
};
|
|
|
|
|
2021-08-06 09:26:21 +03:00
|
|
|
struct FloatCastOverflowData {
|
|
|
|
SourceLocation location;
|
|
|
|
TypeDescriptor const& from_type;
|
|
|
|
TypeDescriptor const& to_type;
|
|
|
|
};
|
|
|
|
|
2021-02-05 21:44:26 +03:00
|
|
|
}
|