Skip to content

Commit

Permalink
Adding documentation for structs
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbor committed Jun 13, 2024
1 parent da339ab commit be9b1c0
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/ubsan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const TYPE_CHECK_KINDS: [&str; 8] = [



/// Represents the type kind used in [`TypeDescriptor`].
#[allow(dead_code)]
#[derive(Clone, Copy)]
#[repr(u16)]
Expand All @@ -34,74 +35,89 @@ pub enum TypeKind {
Unknown = 0xffff,
}

/// Location of a code segment that caused undefined behavior.
#[derive(Clone)]
#[repr(C)]
pub struct SourceLocation {
filename: *const c_char,
line: u32,
column: u32,
pub filename: *const c_char,
pub line: u32,
pub column: u32,
}

#[derive(Clone)]
#[repr(C)]
/// Describes the type of an operand.
pub struct TypeDescriptor {
type_kind: u16,
type_info: u16,
type_name: *const c_char,
/// Encodes the [`TypeKind`] of the operand.
pub type_kind: u16,
/// Encodes additional information, such as [bit width](`Self::bit_width()`) and [whether the
/// type is signed](`Self::is_signed()`).
pub type_info: u16,
/// The type name as null-terminated ASCII string.
pub type_name: *const c_char,
}

// DATA STRUCTS

/// Data struct for [`__ubsan_handle_function_type_mismatch()`]
#[repr(C)]
pub struct FunctionTypeMismatchData {
pub location: SourceLocation,
pub data_type: TypeDescriptor,
}

/// Data struct for [`__ubsan_handle_invalid_builtin()`]
#[repr(C)]
pub struct InvalidBuiltinData {
pub location: SourceLocation,
pub kind: u8,
}

/// Data struct for [`__ubsan_handle_load_invalid_value()`]
#[repr(C)]
pub struct InvalidValueData {
pub location: SourceLocation,
pub data_type: TypeDescriptor,
}

/// Data struct for [`__ubsan_handle_nonnull_arg()`]
#[repr(C)]
pub struct NonnullArgData {
pub location: SourceLocation,
pub attr_location: SourceLocation,
pub arg_index: u32,
}

/// Data struct for [`__ubsan_handle_out_of_bounds()`]
#[repr(C)]
pub struct OutOfBoundsData {
pub location: SourceLocation,
pub array_type: TypeDescriptor,
pub index_type: TypeDescriptor,
}

/// Data struct for [`__ubsan_handle_divrem_overflow()`], [`__ubsan_handle_mul_overflow()`] and [`__ubsan_handle_negate_overflow()`]
#[repr(C)]
pub struct OverflowData {
pub location: SourceLocation,
pub data_type: TypeDescriptor,
}

/// Data struct for [`__ubsan_handle_pointer_overflow()`]
#[repr(C)]
pub struct PointerOverflowData {
pub location: SourceLocation,
}

/// Data struct for [`__ubsan_handle_shift_out_of_bounds()`]
#[repr(C)]
pub struct ShiftOutOfBoundsData {
pub location: SourceLocation,
pub lhs_type: TypeDescriptor,
pub rhs_type: TypeDescriptor,
}

/// Data struct for [`__ubsan_handle_type_mismatch()`]
#[repr(C)]
pub struct TypeMismatchData {
pub location: SourceLocation,
Expand All @@ -110,6 +126,10 @@ pub struct TypeMismatchData {
pub type_check_kind: u8,
}

/// Data struct for [`__ubsan_handle_type_mismatch_v1()`]
///
/// This differs from [`TypeMismatchData`] in its [`log_alignment`](`Self::log_alignment`) member, which stores the alignment
/// as log2 of the actual value and is converted to the actual alignment internally.
#[repr(C)]
pub struct TypeMismatchDataV1 {
pub location: SourceLocation,
Expand All @@ -118,6 +138,7 @@ pub struct TypeMismatchDataV1 {
pub type_check_kind: u8,
}

/// Data struct for [`__ubsan_handle_builtin_unreachable()`]
#[repr(C)]
pub struct UnreachableData {
pub location: SourceLocation,
Expand Down

0 comments on commit be9b1c0

Please sign in to comment.