Added kernel panic function and stack smash protection.

These are untested features.
This commit is contained in:
Zoarial94 2020-12-14 17:25:05 -05:00
parent d3e6109656
commit 318a5170e3
3 changed files with 37 additions and 1 deletions

View File

@ -46,7 +46,7 @@ LIBDIR :=
INC := -I include/ -I include/libc/
#Combined flags (Both C and C++)
FLAGS := -O2 -Wall -Wextra -g -D__is_kernel -ffreestanding
FLAGS := -O2 -Wall -Wextra -g -D__is_kernel -ffreestanding -fstack-protector
#Specific flags
CFLAGS := $(FLAGS) -std=gnu99
CXXFLAGS := $(FLAGS) -std=c++17

13
src/kernel/panic.c Normal file
View File

@ -0,0 +1,13 @@
#include <stdlib.h>
#include <stdio.h>
__attribute__((__noreturn__))
void panic(char* str) {
printf("Entered kernel panic zone./n");
printf("%s", str);
while (1) { }
__builtin_unreachable();
}

View File

@ -0,0 +1,23 @@
#include <stdint.h>
#include <stdlib.h>
#if UINT32_MAX == UINTPTR_MAX
#define STACK_CHK_GUARD 0xe2dee396
#else
#define STACK_CHK_GUARD 0x595e9fbd94fda766
#endif
uintptr_t __stack_chk_guard = STACK_CHK_GUARD;
__attribute__((noreturn))
void __stack_chk_fail(void)
{
#if __is_libc
abort();
#elif __is_libk
panic("Stack smashing detected");
#endif
while (1) { }
__builtin_unreachable();
}