mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-28 15:34:33 +00:00
Added ubsan
This commit is contained in:
parent
11641b1ff3
commit
2571c4f539
@ -117,7 +117,7 @@ void init_limine()
|
|||||||
for (uint64_t i = 0; i < FrameBufferResponse->framebuffer_count; i++)
|
for (uint64_t i = 0; i < FrameBufferResponse->framebuffer_count; i++)
|
||||||
{
|
{
|
||||||
struct limine_framebuffer *framebuffer = FrameBufferResponse->framebuffers[i];
|
struct limine_framebuffer *framebuffer = FrameBufferResponse->framebuffers[i];
|
||||||
binfo.Framebuffer[i].BaseAddress = framebuffer->address - 0xffff800000000000;
|
binfo.Framebuffer[i].BaseAddress = (void *)((uint64_t)framebuffer->address - 0xffff800000000000);
|
||||||
binfo.Framebuffer[i].Width = framebuffer->width;
|
binfo.Framebuffer[i].Width = framebuffer->width;
|
||||||
binfo.Framebuffer[i].Height = framebuffer->height;
|
binfo.Framebuffer[i].Height = framebuffer->height;
|
||||||
binfo.Framebuffer[i].Pitch = framebuffer->pitch;
|
binfo.Framebuffer[i].Pitch = framebuffer->pitch;
|
||||||
@ -133,7 +133,7 @@ void init_limine()
|
|||||||
binfo.Framebuffer[i].EDIDSize = framebuffer->edid_size;
|
binfo.Framebuffer[i].EDIDSize = framebuffer->edid_size;
|
||||||
debug("Framebuffer %d: %dx%d %d bpp", i, framebuffer->width, framebuffer->height, framebuffer->bpp);
|
debug("Framebuffer %d: %dx%d %d bpp", i, framebuffer->width, framebuffer->height, framebuffer->bpp);
|
||||||
debug("More info:\nAddress: %p\nPitch: %ld\nMemoryModel: %d\nRedMaskSize: %d\nRedMaskShift: %d\nGreenMaskSize: %d\nGreenMaskShift: %d\nBlueMaskSize: %d\nBlueMaskShift: %d\nEDID: %p\nEDIDSize: %d",
|
debug("More info:\nAddress: %p\nPitch: %ld\nMemoryModel: %d\nRedMaskSize: %d\nRedMaskShift: %d\nGreenMaskSize: %d\nGreenMaskShift: %d\nBlueMaskSize: %d\nBlueMaskShift: %d\nEDID: %p\nEDIDSize: %d",
|
||||||
framebuffer->address - 0xffff800000000000, framebuffer->pitch, framebuffer->memory_model, framebuffer->red_mask_size, framebuffer->red_mask_shift, framebuffer->green_mask_size, framebuffer->green_mask_shift, framebuffer->blue_mask_size, framebuffer->blue_mask_shift, framebuffer->edid, framebuffer->edid_size);
|
(uint64_t)framebuffer->address - 0xffff800000000000, framebuffer->pitch, framebuffer->memory_model, framebuffer->red_mask_size, framebuffer->red_mask_shift, framebuffer->green_mask_size, framebuffer->green_mask_shift, framebuffer->blue_mask_size, framebuffer->blue_mask_shift, framebuffer->edid, framebuffer->edid_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
binfo.Memory.Entries = MemmapResponse->entry_count;
|
binfo.Memory.Entries = MemmapResponse->entry_count;
|
||||||
@ -205,16 +205,16 @@ void init_limine()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
binfo.Modules[i].Address = ModuleResponse->modules[i]->address - 0xffff800000000000;
|
binfo.Modules[i].Address = (void *)((uint64_t)ModuleResponse->modules[i]->address - 0xffff800000000000);
|
||||||
strcpy(binfo.Modules[i].Path, ModuleResponse->modules[i]->path);
|
strcpy(binfo.Modules[i].Path, ModuleResponse->modules[i]->path);
|
||||||
strcpy(binfo.Modules[i].CommandLine, ModuleResponse->modules[i]->cmdline);
|
strcpy(binfo.Modules[i].CommandLine, ModuleResponse->modules[i]->cmdline);
|
||||||
binfo.Modules[i].Size = ModuleResponse->modules[i]->size;
|
binfo.Modules[i].Size = ModuleResponse->modules[i]->size;
|
||||||
debug("Module %d:\nAddress: %p\nPath: %s\nCommand Line: %s\nSize: %ld", i,
|
debug("Module %d:\nAddress: %p\nPath: %s\nCommand Line: %s\nSize: %ld", i,
|
||||||
ModuleResponse->modules[i]->address - 0xffff800000000000, ModuleResponse->modules[i]->path,
|
(uint64_t)ModuleResponse->modules[i]->address - 0xffff800000000000, ModuleResponse->modules[i]->path,
|
||||||
ModuleResponse->modules[i]->cmdline, ModuleResponse->modules[i]->size);
|
ModuleResponse->modules[i]->cmdline, ModuleResponse->modules[i]->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
binfo.RSDP = (struct RSDPInfo *)(RsdpResponse->address - 0xffff800000000000);
|
binfo.RSDP = (struct RSDPInfo *)((uint64_t)RsdpResponse->address - 0xffff800000000000);
|
||||||
trace("RSDP: %p(%p) [Signature: %.8s] [OEM: %.6s]",
|
trace("RSDP: %p(%p) [Signature: %.8s] [OEM: %.6s]",
|
||||||
RsdpResponse->address, binfo.RSDP, binfo.RSDP->Signature, binfo.RSDP->OEMID);
|
RsdpResponse->address, binfo.RSDP, binfo.RSDP->Signature, binfo.RSDP->OEMID);
|
||||||
|
|
||||||
|
@ -232,8 +232,10 @@ namespace APIC
|
|||||||
{
|
{
|
||||||
SmartCriticalSection(APICLock);
|
SmartCriticalSection(APICLock);
|
||||||
APIC_BASE BaseStruct = {.raw = rdmsr(MSR_APIC_BASE)};
|
APIC_BASE BaseStruct = {.raw = rdmsr(MSR_APIC_BASE)};
|
||||||
APICBaseAddress = BaseStruct.ApicBaseLo << 12u | BaseStruct.ApicBaseHi << 32u;
|
uint64_t BaseLow = BaseStruct.ApicBaseLo;
|
||||||
trace("APIC Address: %#lx", APICBaseAddress);
|
uint64_t BaseHigh = BaseStruct.ApicBaseHi;
|
||||||
|
this->APICBaseAddress = BaseLow << 12u | BaseHigh << 32u;
|
||||||
|
trace("APIC Address: %#lx", this->APICBaseAddress);
|
||||||
|
|
||||||
uint32_t rcx;
|
uint32_t rcx;
|
||||||
cpuid(1, 0, 0, &rcx, 0);
|
cpuid(1, 0, 0, &rcx, 0);
|
||||||
|
@ -37,6 +37,12 @@ static inline void WritePrefix(DebugLevel Level, const char *File, int Line, con
|
|||||||
case DebugLevelFixme:
|
case DebugLevelFixme:
|
||||||
DbgLvlString = "FIXME";
|
DbgLvlString = "FIXME";
|
||||||
break;
|
break;
|
||||||
|
case DebugLevelUbsan:
|
||||||
|
{
|
||||||
|
DbgLvlString = "UBSAN";
|
||||||
|
fctprintf(uart_wrapper, nullptr, "%s|%s: ", DbgLvlString, Function);
|
||||||
|
return;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
DbgLvlString = "UNKNW";
|
DbgLvlString = "UNKNW";
|
||||||
break;
|
break;
|
||||||
|
251
Core/UndefinedBehaviorSanitization.c
Normal file
251
Core/UndefinedBehaviorSanitization.c
Normal file
@ -0,0 +1,251 @@
|
|||||||
|
#include "ubsan.h"
|
||||||
|
|
||||||
|
#include <convert.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
// TODO: implement:
|
||||||
|
/*
|
||||||
|
__ubsan_handle_type_mismatch_v1_abort
|
||||||
|
__ubsan_handle_add_overflow_abort
|
||||||
|
__ubsan_handle_sub_overflow_abort
|
||||||
|
__ubsan_handle_mul_overflow_abort
|
||||||
|
__ubsan_handle_negate_overflow_abort
|
||||||
|
__ubsan_handle_divrem_overflow_abort
|
||||||
|
__ubsan_handle_shift_out_of_bounds_abort
|
||||||
|
__ubsan_handle_out_of_bounds_abort
|
||||||
|
__ubsan_handle_vla_bound_not_positive_abort
|
||||||
|
__ubsan_handle_float_cast_overflow
|
||||||
|
__ubsan_handle_float_cast_overflow_abort
|
||||||
|
__ubsan_handle_load_invalid_value_abort
|
||||||
|
__ubsan_handle_invalid_builtin_abort
|
||||||
|
__ubsan_handle_function_type_mismatch_abort
|
||||||
|
__ubsan_handle_nonnull_return_v1
|
||||||
|
__ubsan_handle_nonnull_return_v1_abort
|
||||||
|
__ubsan_handle_nullability_return_v1
|
||||||
|
__ubsan_handle_nullability_return_v1_abort
|
||||||
|
__ubsan_handle_nonnull_arg_abort
|
||||||
|
__ubsan_handle_nullability_arg
|
||||||
|
__ubsan_handle_nullability_arg_abort
|
||||||
|
__ubsan_handle_pointer_overflow_abort
|
||||||
|
__ubsan_handle_cfi_check_fail
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern void __asan_report_load1(void *unknown) { ubsan("load1"); }
|
||||||
|
extern void __asan_report_load2(void *unknown) { ubsan("load2"); }
|
||||||
|
extern void __asan_report_load4(void *unknown) { ubsan("load4"); }
|
||||||
|
extern void __asan_report_load8(void *unknown) { ubsan("load8"); }
|
||||||
|
extern void __asan_report_load16(void *unknown) { ubsan("load16"); }
|
||||||
|
extern void __asan_report_load_n(void *unknown, uintptr_t size) { ubsan("loadn"); }
|
||||||
|
|
||||||
|
extern void __asan_report_store1(void *unknown) { ubsan("store1"); }
|
||||||
|
extern void __asan_report_store2(void *unknown) { ubsan("store2"); }
|
||||||
|
extern void __asan_report_store4(void *unknown) { ubsan("store4"); }
|
||||||
|
extern void __asan_report_store8(void *unknown) { ubsan("store8"); }
|
||||||
|
extern void __asan_report_store16(void *unknown) { ubsan("store16"); }
|
||||||
|
extern void __asan_report_store_n(void *unknown, uintptr_t size) { ubsan("storen"); }
|
||||||
|
|
||||||
|
extern void __asan_report_load1_noabort(void *unknown) { ubsan("load1"); }
|
||||||
|
extern void __asan_report_load2_noabort(void *unknown) { ubsan("load2"); }
|
||||||
|
extern void __asan_report_load4_noabort(void *unknown) { ubsan("load4"); }
|
||||||
|
extern void __asan_report_load8_noabort(void *unknown) { ubsan("load8"); }
|
||||||
|
extern void __asan_report_load16_noabort(void *unknown) { ubsan("load16"); }
|
||||||
|
extern void __asan_report_load_n_noabort(void *unknown, uintptr_t size) { ubsan("loadn"); }
|
||||||
|
|
||||||
|
extern void __asan_report_store1_noabort(void *unknown) { ubsan("store1"); }
|
||||||
|
extern void __asan_report_store2_noabort(void *unknown) { ubsan("store2"); }
|
||||||
|
extern void __asan_report_store4_noabort(void *unknown) { ubsan("store4"); }
|
||||||
|
extern void __asan_report_store8_noabort(void *unknown) { ubsan("store8"); }
|
||||||
|
extern void __asan_report_store16_noabort(void *unknown) { ubsan("store16"); }
|
||||||
|
extern void __asan_report_store_n_noabort(void *unknown, uintptr_t size) { ubsan("storen"); }
|
||||||
|
|
||||||
|
extern void __asan_stack_malloc_0(uintptr_t size) { ubsan("stack malloc 0"); }
|
||||||
|
extern void __asan_stack_malloc_1(uintptr_t size) { ubsan("stack malloc 1"); }
|
||||||
|
extern void __asan_stack_malloc_2(uintptr_t size) { ubsan("stack malloc 2"); }
|
||||||
|
extern void __asan_stack_malloc_3(uintptr_t size) { ubsan("stack malloc 3"); }
|
||||||
|
extern void __asan_stack_malloc_4(uintptr_t size) { ubsan("stack malloc 4"); }
|
||||||
|
extern void __asan_stack_malloc_5(uintptr_t size) { ubsan("stack malloc 5"); }
|
||||||
|
extern void __asan_stack_malloc_6(uintptr_t size) { ubsan("stack malloc 6"); }
|
||||||
|
extern void __asan_stack_malloc_7(uintptr_t size) { ubsan("stack malloc 7"); }
|
||||||
|
extern void __asan_stack_malloc_8(uintptr_t size) { ubsan("stack malloc 8"); }
|
||||||
|
extern void __asan_stack_malloc_9(uintptr_t size) { ubsan("stack malloc 9"); }
|
||||||
|
|
||||||
|
extern void __asan_stack_free_0(void *ptr, uintptr_t size) { ubsan("stack free 0"); }
|
||||||
|
extern void __asan_stack_free_1(void *ptr, uintptr_t size) { ubsan("stack free 1"); }
|
||||||
|
extern void __asan_stack_free_2(void *ptr, uintptr_t size) { ubsan("stack free 2"); }
|
||||||
|
extern void __asan_stack_free_3(void *ptr, uintptr_t size) { ubsan("stack free 3"); }
|
||||||
|
extern void __asan_stack_free_4(void *ptr, uintptr_t size) { ubsan("stack free 4"); }
|
||||||
|
extern void __asan_stack_free_5(void *ptr, uintptr_t size) { ubsan("stack free 5"); }
|
||||||
|
extern void __asan_stack_free_6(void *ptr, uintptr_t size) { ubsan("stack free 6"); }
|
||||||
|
extern void __asan_stack_free_7(void *ptr, uintptr_t size) { ubsan("stack free 7"); }
|
||||||
|
extern void __asan_stack_free_8(void *ptr, uintptr_t size) { ubsan("stack free 8"); }
|
||||||
|
extern void __asan_stack_free_9(void *ptr, uintptr_t size) { ubsan("stack free 9"); }
|
||||||
|
|
||||||
|
extern void __asan_poison_stack_memory(void *addr, uintptr_t size) { ubsan("poison stack memory"); }
|
||||||
|
extern void __asan_unpoison_stack_memory(void *addr, uintptr_t size) { ubsan("unpoison stack memory"); }
|
||||||
|
|
||||||
|
extern void __asan_before_dynamic_init(const char *module_name) { ubsan("before dynamic init"); }
|
||||||
|
extern void __asan_after_dynamic_init(void) { ubsan("after dynamic init"); }
|
||||||
|
|
||||||
|
extern void __asan_register_globals(void *unknown, size_t size) { ubsan("register_globals"); }
|
||||||
|
extern void __asan_unregister_globals(void) { ubsan("unregister_globals"); }
|
||||||
|
|
||||||
|
extern void __asan_init(void) { ubsan("init"); }
|
||||||
|
extern void __asan_version_mismatch_check_v8(void) { ubsan("version_mismatch_check_v8"); }
|
||||||
|
extern void __asan_option_detect_stack_use_after_return(void) { ubsan("stack use after return"); }
|
||||||
|
extern __noreturn void __asan_handle_no_return(void) { ubsan("no_return"); }
|
||||||
|
|
||||||
|
#define is_aligned(value, alignment) !(value & (alignment - 1))
|
||||||
|
|
||||||
|
const char *Type_Check_Kinds[] = {
|
||||||
|
"Load of",
|
||||||
|
"Store to",
|
||||||
|
"Reference binding to",
|
||||||
|
"Member access within",
|
||||||
|
"Member call on",
|
||||||
|
"Constructor call on",
|
||||||
|
"Downcast of",
|
||||||
|
"Downcast of",
|
||||||
|
"Upcast of",
|
||||||
|
"Cast to virtual base of",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Prevent huge spam from ubsan
|
||||||
|
bool UBSANMsg(const char *file, uint32_t line, uint32_t column)
|
||||||
|
{
|
||||||
|
// blacklist
|
||||||
|
if (strstr(file, "liballoc") || strstr(file, "cwalk"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
static char *onceFile[512] = {"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"};
|
||||||
|
static uint32_t onceLine[512] = {0};
|
||||||
|
static uint32_t onceColumn[512] = {0};
|
||||||
|
static uint32_t onceCount = 0;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < onceCount; i++)
|
||||||
|
if ((!strcmp(onceFile[i], file)) && onceLine[i] == line && onceColumn[i] == column)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
onceFile[onceCount] = (char *)file;
|
||||||
|
onceLine[onceCount] = line;
|
||||||
|
onceColumn[onceCount] = column;
|
||||||
|
ubsan("\t\tIn File: %s:%i:%i", file, line, column);
|
||||||
|
onceCount++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_type_mismatch_v1(struct type_mismatch_v1_data *type_mismatch, uintptr_t pointer)
|
||||||
|
{
|
||||||
|
struct source_location *location = &type_mismatch->location;
|
||||||
|
if (pointer == 0)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(location->file, location->line, location->column))
|
||||||
|
ubsan("Null pointer access.");
|
||||||
|
}
|
||||||
|
else if (type_mismatch->alignment != 0 && is_aligned(pointer, type_mismatch->alignment))
|
||||||
|
{
|
||||||
|
if (UBSANMsg(location->file, location->line, location->column))
|
||||||
|
ubsan("Unaligned memory access %#llx.", pointer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (UBSANMsg(location->file, location->line, location->column))
|
||||||
|
ubsan("%s address %#llx with insufficient space for object of type %s",
|
||||||
|
Type_Check_Kinds[type_mismatch->type_check_kind], (void *)pointer, type_mismatch->type->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_add_overflow(struct overflow_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Addition overflow.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_sub_overflow(struct overflow_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Subtraction overflow.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_mul_overflow(struct overflow_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Multiplication overflow.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_divrem_overflow(struct overflow_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Division overflow.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_negate_overflow(struct overflow_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Negation overflow.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_pointer_overflow(struct overflow_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Pointer overflow.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_shift_out_of_bounds(struct shift_out_of_bounds_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Shift out of bounds.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_load_invalid_value(struct invalid_value_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Invalid load value.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_out_of_bounds(struct array_out_of_bounds_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Array out of bounds.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_vla_bound_not_positive(struct negative_vla_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Variable-length argument is negative.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_nonnull_return(struct nonnull_return_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Non-null return is null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_nonnull_return_v1(struct nonnull_return_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Non-null return is null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_nonnull_arg(struct nonnull_arg_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Non-null argument is null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_builtin_unreachable(struct unreachable_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Unreachable code reached.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_invalid_builtin(struct invalid_builtin_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Invalid builtin.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __ubsan_handle_missing_return(struct unreachable_data *data)
|
||||||
|
{
|
||||||
|
if (UBSANMsg(data->location.file, data->location.line, data->location.column))
|
||||||
|
ubsan("Missing return.");
|
||||||
|
}
|
@ -22,6 +22,8 @@ namespace UniversalAsynchronousReceiverTransmitter
|
|||||||
|
|
||||||
this->Port = Port;
|
this->Port = Port;
|
||||||
|
|
||||||
|
if (Port > 7)
|
||||||
|
return;
|
||||||
if (serialports[Port])
|
if (serialports[Port])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
88
Core/ubsan.h
Normal file
88
Core/ubsan.h
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#ifndef __FENNIX_KERNEL_UBSAN_H__
|
||||||
|
#define __FENNIX_KERNEL_UBSAN_H__
|
||||||
|
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
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_v1_data
|
||||||
|
{
|
||||||
|
struct source_location location;
|
||||||
|
struct type_descriptor *type;
|
||||||
|
uint8_t alignment;
|
||||||
|
uint8_t type_check_kind;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct out_of_bounds_info
|
||||||
|
{
|
||||||
|
struct source_location location;
|
||||||
|
struct type_descriptor left_type;
|
||||||
|
struct type_descriptor right_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct overflow_data
|
||||||
|
{
|
||||||
|
struct source_location location;
|
||||||
|
struct type_descriptor *type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct negative_vla_data
|
||||||
|
{
|
||||||
|
struct source_location location;
|
||||||
|
struct type_descriptor *type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct invalid_value_data
|
||||||
|
{
|
||||||
|
struct source_location location;
|
||||||
|
struct type_descriptor *type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nonnull_return_data
|
||||||
|
{
|
||||||
|
struct source_location location;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nonnull_arg_data
|
||||||
|
{
|
||||||
|
struct source_location location;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct unreachable_data
|
||||||
|
{
|
||||||
|
struct source_location location;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct invalid_builtin_data
|
||||||
|
{
|
||||||
|
struct source_location location;
|
||||||
|
uint8_t kind;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct array_out_of_bounds_data
|
||||||
|
{
|
||||||
|
struct source_location location;
|
||||||
|
struct type_descriptor *array_type;
|
||||||
|
struct type_descriptor *index_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct shift_out_of_bounds_data
|
||||||
|
{
|
||||||
|
struct source_location location;
|
||||||
|
struct type_descriptor *left_type;
|
||||||
|
struct type_descriptor *right_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // !__FENNIX_KERNEL_UBSAN_H__
|
@ -47,6 +47,7 @@ void FetchDisks()
|
|||||||
|
|
||||||
void KernelMainThread()
|
void KernelMainThread()
|
||||||
{
|
{
|
||||||
|
TaskManager->InitIPC();
|
||||||
Vector<AuxiliaryVector> auxv;
|
Vector<AuxiliaryVector> auxv;
|
||||||
|
|
||||||
Tasking::TCB *CurrentWorker = nullptr;
|
Tasking::TCB *CurrentWorker = nullptr;
|
||||||
|
@ -356,8 +356,9 @@ int strncmp(const char *s1, const char *s2, size_t n)
|
|||||||
long unsigned strlen(const char s[])
|
long unsigned strlen(const char s[])
|
||||||
{
|
{
|
||||||
long unsigned i = 0;
|
long unsigned i = 0;
|
||||||
while (s[i] != '\0')
|
if (s)
|
||||||
++i;
|
while (s[i] != '\0')
|
||||||
|
++i;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
Makefile
2
Makefile
@ -93,7 +93,7 @@ NASMFLAGS :=
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(DEBUG), 1)
|
ifeq ($(DEBUG), 1)
|
||||||
CFLAGS += -DDEBUG -ggdb -O0 -fdiagnostics-color=always
|
CFLAGS += -DDEBUG -ggdb -O0 -fdiagnostics-color=always -fsanitize=undefined
|
||||||
LDFLAGS += -ggdb -O0 -g
|
LDFLAGS += -ggdb -O0 -g
|
||||||
NASMFLAGS += -F dwarf -g
|
NASMFLAGS += -F dwarf -g
|
||||||
WARNCFLAG += -Wno-unused-function -Wno-maybe-uninitialized -Wno-builtin-declaration-mismatch -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-variable
|
WARNCFLAG += -Wno-unused-function -Wno-maybe-uninitialized -Wno-builtin-declaration-mismatch -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-variable
|
||||||
|
@ -55,8 +55,8 @@ namespace InterProcessCommunication
|
|||||||
{
|
{
|
||||||
trace("Starting IPC Service...");
|
trace("Starting IPC Service...");
|
||||||
Vector<AuxiliaryVector> auxv;
|
Vector<AuxiliaryVector> auxv;
|
||||||
TaskManager->CreateThread(TaskManager->GetCurrentProcess(), (Tasking::IP)IPCServiceStub, nullptr, nullptr, auxv);
|
Tasking::TCB *thd = TaskManager->CreateThread(TaskManager->GetCurrentProcess(), (Tasking::IP)IPCServiceStub, nullptr, nullptr, auxv);
|
||||||
TaskManager->GetCurrentThread()->Rename("IPC Service");
|
thd->Rename("IPC Service");
|
||||||
}
|
}
|
||||||
|
|
||||||
IPC::~IPC()
|
IPC::~IPC()
|
||||||
|
@ -697,7 +697,15 @@ namespace Tasking
|
|||||||
SmartCriticalSection(TaskingLock);
|
SmartCriticalSection(TaskingLock);
|
||||||
TCB *Thread = new TCB;
|
TCB *Thread = new TCB;
|
||||||
if (Parent == nullptr)
|
if (Parent == nullptr)
|
||||||
|
{
|
||||||
Thread->Parent = this->GetCurrentProcess();
|
Thread->Parent = this->GetCurrentProcess();
|
||||||
|
if (Thread->Parent == nullptr)
|
||||||
|
{
|
||||||
|
error("Failed to get current process. Thread cannot be created.");
|
||||||
|
delete Thread;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Thread->Parent = Parent;
|
Thread->Parent = Parent;
|
||||||
|
|
||||||
@ -1086,7 +1094,6 @@ namespace Tasking
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
TaskingLock.Unlock();
|
TaskingLock.Unlock();
|
||||||
this->IPCManager = new InterProcessCommunication::IPC;
|
|
||||||
IdleProcess = CreateProcess(nullptr, (char *)"Idle", TaskTrustLevel::Idle);
|
IdleProcess = CreateProcess(nullptr, (char *)"Idle", TaskTrustLevel::Idle);
|
||||||
for (int i = 0; i < SMP::CPUCores; i++)
|
for (int i = 0; i < SMP::CPUCores; i++)
|
||||||
{
|
{
|
||||||
|
@ -11,7 +11,8 @@ enum DebugLevel
|
|||||||
DebugLevelInfo = 3,
|
DebugLevelInfo = 3,
|
||||||
DebugLevelDebug = 4,
|
DebugLevelDebug = 4,
|
||||||
DebugLevelTrace = 5,
|
DebugLevelTrace = 5,
|
||||||
DebugLevelFixme = 6
|
DebugLevelFixme = 6,
|
||||||
|
DebugLevelUbsan = 7
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -28,6 +29,7 @@ namespace SysDbg
|
|||||||
#define debug(Format, ...) SysDbg::WriteLine(DebugLevelDebug, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
#define debug(Format, ...) SysDbg::WriteLine(DebugLevelDebug, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
||||||
#define trace(Format, ...) SysDbg::WriteLine(DebugLevelTrace, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
#define trace(Format, ...) SysDbg::WriteLine(DebugLevelTrace, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
||||||
#define fixme(Format, ...) SysDbg::WriteLine(DebugLevelFixme, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
#define fixme(Format, ...) SysDbg::WriteLine(DebugLevelFixme, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
||||||
|
#define ubsan(Format, ...) SysDbg::WriteLine(DebugLevelUbsan, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -40,6 +42,7 @@ void SysDbgWriteLine(enum DebugLevel Level, const char *File, int Line, const ch
|
|||||||
#define debug(Format, ...) SysDbgWriteLine(DebugLevelDebug, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
#define debug(Format, ...) SysDbgWriteLine(DebugLevelDebug, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
||||||
#define trace(Format, ...) SysDbgWriteLine(DebugLevelTrace, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
#define trace(Format, ...) SysDbgWriteLine(DebugLevelTrace, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
||||||
#define fixme(Format, ...) SysDbgWriteLine(DebugLevelFixme, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
#define fixme(Format, ...) SysDbgWriteLine(DebugLevelFixme, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
||||||
|
#define ubsan(Format, ...) SysDbgWriteLine(DebugLevelUbsan, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
@ -108,19 +108,24 @@ namespace Video
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Size = this->framebuffer.Pitch * Height;
|
uint64_t Size = this->framebuffer.Pitch * Height;
|
||||||
if (this->Buffers[Index]->Checksum != 0xDEAD5C9EE7)
|
if (!this->Buffers[Index])
|
||||||
{
|
{
|
||||||
ScreenBuffer *buffer = new ScreenBuffer;
|
if (this->Buffers[Index]->Checksum != 0xDEAD5C9EE7)
|
||||||
buffer->Buffer = KernelAllocator.RequestPages(TO_PAGES(Size));
|
{
|
||||||
buffer->Width = Width;
|
ScreenBuffer *buffer = new ScreenBuffer;
|
||||||
buffer->Height = Height;
|
buffer->Buffer = KernelAllocator.RequestPages(TO_PAGES(Size));
|
||||||
buffer->Size = Size;
|
buffer->Width = Width;
|
||||||
buffer->Color = 0xFFFFFF;
|
buffer->Height = Height;
|
||||||
buffer->CursorX = 0;
|
buffer->Size = Size;
|
||||||
buffer->CursorY = 0;
|
buffer->Color = 0xFFFFFF;
|
||||||
this->Buffers[Index] = buffer;
|
buffer->CursorX = 0;
|
||||||
memset(this->Buffers[Index]->Buffer, 0, Size);
|
buffer->CursorY = 0;
|
||||||
this->Buffers[Index]->Checksum = 0xDEAD5C9EE7;
|
this->Buffers[Index] = buffer;
|
||||||
|
memset(this->Buffers[Index]->Buffer, 0, Size);
|
||||||
|
this->Buffers[Index]->Checksum = 0xDEAD5C9EE7;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
warn("Buffer %d already exists, skipping creation", Index);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
warn("Buffer %d already exists, skipping creation", Index);
|
warn("Buffer %d already exists, skipping creation", Index);
|
||||||
|
@ -101,6 +101,11 @@ namespace Tasking
|
|||||||
|
|
||||||
void Rename(const char *name)
|
void Rename(const char *name)
|
||||||
{
|
{
|
||||||
|
if (!Name[0])
|
||||||
|
{
|
||||||
|
warn("Tried to rename thread %d to NULL", ID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
trace("Renaming thread %s to %s", Name, name);
|
trace("Renaming thread %s to %s", Name, name);
|
||||||
for (int i = 0; i < 256; i++)
|
for (int i = 0; i < 256; i++)
|
||||||
{
|
{
|
||||||
@ -201,6 +206,12 @@ namespace Tasking
|
|||||||
bool StopScheduler = false;
|
bool StopScheduler = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void InitIPC()
|
||||||
|
{
|
||||||
|
static int once = 0;
|
||||||
|
if (!once++)
|
||||||
|
this->IPCManager = new InterProcessCommunication::IPC();
|
||||||
|
}
|
||||||
Vector<PCB *> GetProcessList() { return ListProcess; }
|
Vector<PCB *> GetProcessList() { return ListProcess; }
|
||||||
void Panic() { StopScheduler = true; }
|
void Panic() { StopScheduler = true; }
|
||||||
void Schedule();
|
void Schedule();
|
||||||
|
@ -252,5 +252,12 @@ typedef __SIZE_TYPE__ size_t;
|
|||||||
#define __nonnull_all __attribute__((nonnull))
|
#define __nonnull_all __attribute__((nonnull))
|
||||||
#define __warn_unused_result __attribute__((warn_unused_result))
|
#define __warn_unused_result __attribute__((warn_unused_result))
|
||||||
#define __no_stack_protector __attribute__((no_stack_protector))
|
#define __no_stack_protector __attribute__((no_stack_protector))
|
||||||
|
// sanitizer
|
||||||
|
#define __no_sanitize_address __attribute__((no_sanitize_address))
|
||||||
|
#define __no_sanitize_undefined __attribute__((no_sanitize_undefined))
|
||||||
|
#define __no_address_safety_analysis __attribute__((no_address_safety_analysis))
|
||||||
|
#define __no_sanitize_thread __attribute__((no_sanitize_thread))
|
||||||
|
#define __no_sanitize_memory __attribute__((no_sanitize_memory))
|
||||||
|
#define __no_sanitize_hwaddress __attribute__((no_sanitize_hwaddress))
|
||||||
|
|
||||||
#endif // !__FENNIX_KERNEL_TYPES_H__
|
#endif // !__FENNIX_KERNEL_TYPES_H__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user