Added kernel panic function and stack smash protection.
These are untested features.
This commit is contained in:
parent
d3e6109656
commit
318a5170e3
2
Makefile
2
Makefile
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
Loading…
Reference in New Issue