enable stack protection

This commit is contained in:
2023-10-21 13:40:49 +02:00
parent 9e0fc222c4
commit 06e2c8b6da
4 changed files with 18 additions and 5 deletions

View File

@@ -1,8 +1,8 @@
add_executable(kernel.elf)
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions -fno-rtti -ffreestanding>)
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:C>:-ffreestanding>)
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fstack-protector-all -fno-exceptions -fno-rtti -ffreestanding>)
target_compile_options(kernel.elf PUBLIC $<$<COMPILE_LANGUAGE:C>:-fstack-protector-all -ffreestanding>)
add_subdirectory(./arch/)
add_subdirectory(./kernel/)

View File

@@ -21,8 +21,7 @@ target_sources(kernel.elf PRIVATE
paging.cpp
kmain.cpp
gdt.cpp
misc.cpp
cppsupport.cpp)
misc.cpp)
target_include_directories(kernel.elf PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

View File

@@ -1,3 +1,3 @@
target_include_directories(kernel.elf PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_sources(kernel.elf PRIVATE mutex.cpp cv.cpp)
target_sources(kernel.elf PRIVATE mutex.cpp cv.cpp cppsupport.cpp)

View File

@@ -3,9 +3,23 @@
//
#include <cstddef>
#include <cstdint>
#include "kmem.hpp"
#include "misc.hpp"
#include "serial.hpp"
#if UINT32_MAX == UINTPTR_MAX
#define STACK_CHK_GUARD 0xb079a218
#else
#define STACK_CHK_GUARD 0x2e61e13e4d5ae23c
#endif
uintptr_t __stack_chk_guard = STACK_CHK_GUARD;
extern "C" __attribute__((noreturn)) void __stack_chk_fail(void) {
assert2(false, "Stack protection triggered!");
}
extern "C" void __cxa_pure_virtual() {
// Do nothing or print an error message.