/*
 * @author  xamidev <xamidev@riseup.net>
 * @brief   Undefined behavior sanitization hooks
 * @license GPL-3.0-only
 */

#ifndef UBSAN_H
#define UBSAN_H

#include <stdint.h>

struct ubsan_source_location
{
	const char* filename;
	uint32_t line;
	uint32_t column;
};

struct ubsan_type_descriptor
{
	uint16_t type_kind;
	uint16_t type_info;
	char type_name[];
};

struct ubsan_type_mismatch_v1_data
{
	struct ubsan_source_location location;
	struct ubsan_type_descriptor* type;
	unsigned char log_alignment;
	unsigned char type_check_kind;
};

struct ubsan_pointer_overflow_data
{
	struct ubsan_source_location location;
};

struct ubsan_shift_out_of_bounds_data
{
	struct ubsan_source_location location;
	struct ubsan_type_descriptor* lhs_type;
	struct ubsan_type_descriptor* rhs_type;
};

struct ubsan_invalid_value_data
{
	struct ubsan_source_location location;
	struct ubsan_type_descriptor* type;
};

struct ubsan_out_of_bounds_data
{
	struct ubsan_source_location location;
	struct ubsan_type_descriptor* array_type;
	struct ubsan_type_descriptor* index_type;
};

struct ubsan_overflow_data
{
	struct ubsan_source_location location;
	struct ubsan_type_descriptor* type;
};

#endif