Use gcc stack protector

Trick was to use the stack-protector-guard option otherwise gcc expect
the canary value to be stored on the Thread Local Storage of the current
thread.
That does not work the same way for us, so trying to access TLS at
%gs (the canonical place for the TLS), where gcc expect the canary to be
storeg, lead to system reboot as it is not setup.
This commit is contained in:
Mathieu Maret 2025-02-19 19:12:27 +01:00
parent 778999c8f4
commit 6854ad489f
2 changed files with 13 additions and 2 deletions

View File

@ -3,9 +3,9 @@ CPPFLAGS = -MMD
AS=nasm
ASFLAGS += -f elf32
LDFLAGS += -m elf_i386
CFLAGS += -m32 -pipe -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-pie -fno-stack-protector -fno-tree-vectorize -D__KERNEL__
CFLAGS += -m32 -pipe -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-pie -fno-tree-vectorize -D__KERNEL__ -fstack-protector-all -mstack-protector-guard=global
#keep .i and .s
#CFLAGS += -save-temps
#CFLAGS += -save-temps -fverbose-asm
#CFLAGS += -fanalyzer -Wno-analyzer-malloc-leak -Wno-analyzer-out-of-bounds
CXXFLAGS += -m32 -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-rtti -fno-pie
DEBUG_FLAGS += -g -Og -DDEBUG -fno-omit-frame-pointer -fno-inline

View File

@ -22,3 +22,14 @@
} \
} \
} while (0)
#define panic(fmt, args...) \
do { \
asm volatile("cli"); \
printf("PANIC at %s:%d\n " fmt "", __FILE__, __LINE__); \
printf("PANIC: " fmt "\n", ##args); \
printStackTrace(3); \
while (1) \
asm volatile("hlt"); \
__builtin_unreachable(); \
} while (0)