mirror of
https://github.com/usatiuk/ficus.git
synced 2025-10-29 00:27:52 +01:00
Enable UBSAN
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
|
||||
add_executable(kernel.elf)
|
||||
|
||||
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fstack-protector-all -Wno-pointer-arith>)
|
||||
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:C>:-fstack-protector-all -Wno-pointer-arith>)
|
||||
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fstack-protector-all -Wno-pointer-arith -fsanitize=undefined>)
|
||||
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:C>:-fstack-protector-all -Wno-pointer-arith -fsanitize=undefined>)
|
||||
|
||||
add_subdirectory(./arch/)
|
||||
add_subdirectory(./kernel/)
|
||||
|
||||
@@ -16,7 +16,7 @@ struct HeapEntry {
|
||||
struct HeapEntry *prev;
|
||||
uint64_t len;
|
||||
char data[] __attribute__((aligned(16)));
|
||||
} __attribute__((packed, aligned(32)));
|
||||
} __attribute__((packed, aligned(1)));
|
||||
|
||||
extern struct HeapEntry *KERN_HeapBegin;
|
||||
extern uintptr_t KERN_HeapEnd; // Past the end
|
||||
|
||||
@@ -82,4 +82,73 @@ int __cxa_atexit(void (*f)(void *), void *objptr, void *dso) {
|
||||
writestr_no_yield("Something registered\n");
|
||||
return 0;
|
||||
};
|
||||
|
||||
struct source_location {
|
||||
const char *file;
|
||||
uint32_t line;
|
||||
uint32_t column;
|
||||
};
|
||||
|
||||
struct type_descriptor {
|
||||
uint16_t kind;
|
||||
uint16_t info;
|
||||
char *name;
|
||||
};
|
||||
|
||||
struct type_mismatch_info {
|
||||
struct source_location location;
|
||||
struct type_descriptor *type;
|
||||
uintptr_t alignment;
|
||||
uint8_t type_check_kind;
|
||||
};
|
||||
|
||||
#define is_aligned(value, alignment) !(value & (alignment - 1))
|
||||
[[maybe_unused]] void __ubsan_handle_type_mismatch_v1(struct type_mismatch_info *type_mismatch,
|
||||
uintptr_t pointer) {
|
||||
struct source_location *location = &type_mismatch->location;
|
||||
if (pointer == 0) {
|
||||
writestr_no_yield("Warning: null pointer access \n");
|
||||
} else if (type_mismatch->alignment != 0 &&
|
||||
is_aligned(pointer, type_mismatch->alignment)) {
|
||||
// Most useful on architectures with stricter memory alignment requirements, like ARM.
|
||||
writestr_no_yield("Warning: unaligned memory access \n");
|
||||
} else {
|
||||
writestr_no_yield("Warning: insufficient size ");
|
||||
}
|
||||
// log_location(location);
|
||||
// writestr_no_yield(" \n");
|
||||
|
||||
// _hcf();
|
||||
}
|
||||
|
||||
[[maybe_unused]] void __ubsan_handle_pointer_overflow() {
|
||||
writestr_no_yield("Warning: pointer overflow\n");
|
||||
}
|
||||
[[maybe_unused]] void __ubsan_handle_load_invalid_value() {
|
||||
writestr_no_yield("Warning: invalid value load\n");
|
||||
}
|
||||
[[maybe_unused]] void __ubsan_handle_out_of_bounds() {
|
||||
writestr_no_yield("Warning: out of bounds\n");
|
||||
}
|
||||
[[maybe_unused]] void __ubsan_handle_add_overflow() {
|
||||
writestr_no_yield("Warning: add overflow\n");
|
||||
}
|
||||
[[maybe_unused]] void __ubsan_handle_missing_return() {
|
||||
writestr_no_yield("Warning: missing return\n");
|
||||
}
|
||||
[[maybe_unused]] void __ubsan_handle_sub_overflow() {
|
||||
writestr_no_yield("Warning: sub overflow\n");
|
||||
}
|
||||
[[maybe_unused]] void __ubsan_handle_shift_out_of_bounds() {
|
||||
writestr_no_yield("Warning: shift overflow\n");
|
||||
}
|
||||
[[maybe_unused]] void __ubsan_handle_builtin_unreachable() {
|
||||
writestr_no_yield("Warning: unreachable\n");
|
||||
}
|
||||
[[maybe_unused]] void __ubsan_handle_mul_overflow() {
|
||||
writestr_no_yield("Warning: multiplication overflow\n");
|
||||
}
|
||||
[[maybe_unused]] void __ubsan_handle_divrem_overflow() {
|
||||
writestr_no_yield("Warning: division overflow\n");
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user