mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Revamped kernel panic functions with significant improvements
This commit is contained in:
@ -21,9 +21,12 @@
|
||||
|
||||
#include "../kernel.h"
|
||||
|
||||
/* EXTERNC */ __weak uintptr_t __stack_chk_guard = 0;
|
||||
extern __noreturn void HandleStackSmashing();
|
||||
extern __noreturn void HandleBufferOverflow();
|
||||
|
||||
EXTERNC __weak __no_stack_protector uintptr_t __stack_chk_guard_init(void)
|
||||
/* EXTERNC */ uintptr_t __stack_chk_guard = 0;
|
||||
|
||||
EXTERNC __no_stack_protector uintptr_t __stack_chk_guard_init(void)
|
||||
{
|
||||
int MaxRetries = 0;
|
||||
#if UINTPTR_MAX == UINT32_MAX
|
||||
@ -52,55 +55,26 @@ EXTERNC __constructor __no_stack_protector void __guard_setup(void)
|
||||
debug("Stack guard value: %ld", __stack_chk_guard);
|
||||
}
|
||||
|
||||
EXTERNC __weak __noreturn __no_stack_protector void __stack_chk_fail(void)
|
||||
EXTERNC __noreturn __no_stack_protector void __stack_chk_fail(void)
|
||||
{
|
||||
TaskingPanic();
|
||||
for (short i = 0; i < 10; i++)
|
||||
error("Stack smashing detected!");
|
||||
debug("Current stack check guard value: %#lx", __stack_chk_guard);
|
||||
KPrint("\eFF0000Stack smashing detected!");
|
||||
|
||||
void *Stack = nullptr;
|
||||
#if defined(a86)
|
||||
|
||||
#if defined(a64)
|
||||
asmv("movq %%rsp, %0"
|
||||
: "=r"(Stack));
|
||||
#elif defined(a32)
|
||||
asmv("movl %%esp, %0"
|
||||
: "=r"(Stack));
|
||||
#endif
|
||||
|
||||
#elif defined(aa64)
|
||||
|
||||
asmv("mov %%sp, %0"
|
||||
: "=r"(Stack));
|
||||
|
||||
#endif
|
||||
error("Stack address: %#lx", Stack);
|
||||
|
||||
if (DebuggerIsAttached)
|
||||
#ifdef a86
|
||||
asmv("int $0x3");
|
||||
#elif defined(aa64)
|
||||
asmv("brk #0");
|
||||
#endif
|
||||
|
||||
CPU::Stop();
|
||||
HandleStackSmashing();
|
||||
}
|
||||
|
||||
// https://github.com/gcc-mirror/gcc/blob/master/libssp/ssp.c
|
||||
EXTERNC __weak __noreturn __no_stack_protector void __chk_fail(void)
|
||||
EXTERNC __noreturn nsa void __chk_fail(void)
|
||||
{
|
||||
TaskingPanic();
|
||||
for (short i = 0; i < 10; i++)
|
||||
error("Buffer overflow detected!");
|
||||
KPrint("\eFF0000Buffer overflow detected!");
|
||||
|
||||
#if defined(a86)
|
||||
while (1)
|
||||
asmv("cli; hlt");
|
||||
#elif defined(aa64)
|
||||
asmv("wfe");
|
||||
#endif
|
||||
HandleBufferOverflow();
|
||||
}
|
||||
|
Reference in New Issue
Block a user