mirror of
https://github.com/Fennix-Project/Userspace.git
synced 2025-05-28 15:34:26 +00:00
Added libssp
This commit is contained in:
parent
21c80060a8
commit
414662b24a
@ -2,9 +2,11 @@ build:
|
|||||||
cp include/* ../out/system/include
|
cp include/* ../out/system/include
|
||||||
make --quiet -C runtime build
|
make --quiet -C runtime build
|
||||||
make --quiet -C libgcc build
|
make --quiet -C libgcc build
|
||||||
|
make --quiet -C libssp build
|
||||||
make --quiet -C src build
|
make --quiet -C src build
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
make --quiet -C runtime clean
|
make --quiet -C runtime clean
|
||||||
make --quiet -C libgcc clean
|
make --quiet -C libgcc clean
|
||||||
|
make --quiet -C libssp clean
|
||||||
make --quiet -C src clean
|
make --quiet -C src clean
|
||||||
|
44
libc/libssp/Makefile
Normal file
44
libc/libssp/Makefile
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# Config file
|
||||||
|
include ../../../Makefile.conf
|
||||||
|
|
||||||
|
NAME=ssp
|
||||||
|
|
||||||
|
OBJECT_NAME=lib$(NAME).a
|
||||||
|
|
||||||
|
OUTPUT_DIR=../../out/system/lib/
|
||||||
|
|
||||||
|
CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc
|
||||||
|
AR = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ar
|
||||||
|
NASM = /usr/bin/nasm
|
||||||
|
|
||||||
|
C_SOURCES = $(shell find ./ -type f -name '*.c')
|
||||||
|
S_SOURCES = $(shell find ./ -type f -name '*.s')
|
||||||
|
ASM_SOURCES = $(shell find ./ -type f -name '*.asm')
|
||||||
|
OBJ = ${C_SOURCES:.c=.o} ${ASM_SOURCES:.asm=.o} ${S_SOURCES:.s=.o}
|
||||||
|
|
||||||
|
INCLUDE_DIR = ../include
|
||||||
|
|
||||||
|
ifeq ($(OSARCH), amd64)
|
||||||
|
ASM_ARCH := elf64
|
||||||
|
else ifeq ($(OSARCH), i686)
|
||||||
|
ASM_ARCH := elf32
|
||||||
|
endif
|
||||||
|
|
||||||
|
CFLAGS := -fPIC -I$(INCLUDE_DIR)
|
||||||
|
|
||||||
|
build: $(OBJECT_NAME)
|
||||||
|
|
||||||
|
$(OBJECT_NAME): $(OBJ)
|
||||||
|
$(AR) rcs $(OUTPUT_DIR)$@ $(OBJ)
|
||||||
|
|
||||||
|
%.o: %.c $(HEADERS) $(HEADERS2)
|
||||||
|
$(CC) $(CFLAGS) -std=c17 -c $< -o $@
|
||||||
|
|
||||||
|
%.o: %.cpp $(HEADERS) $(HEADERS2)
|
||||||
|
$(CC) $(CFLAGS) -std=c++20 -c $< -o $@
|
||||||
|
|
||||||
|
%.o: %.asm
|
||||||
|
$(NASM) $< -f $(ASM_ARCH) -o $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
|
33
libc/libssp/ssp.c
Normal file
33
libc/libssp/ssp.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef STACK_CHK_GUARD_VALUE
|
||||||
|
#if UINTPTR_MAX == UINT32_MAX
|
||||||
|
#define STACK_CHK_GUARD_VALUE 0xDEAD57AC
|
||||||
|
#else
|
||||||
|
#define STACK_CHK_GUARD_VALUE 0xDEAD57AC00000000
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__UINTPTR_TYPE__ __stack_chk_guard = 0;
|
||||||
|
|
||||||
|
static void __attribute__((constructor, no_stack_protector)) __guard_setup(void)
|
||||||
|
{
|
||||||
|
if (__stack_chk_guard == 0)
|
||||||
|
__stack_chk_guard = STACK_CHK_GUARD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((weak, noreturn, no_stack_protector)) void __stack_chk_fail(void)
|
||||||
|
{
|
||||||
|
const char *msg = "Stack smashing detected";
|
||||||
|
__asm__ __volatile__("syscall"
|
||||||
|
:
|
||||||
|
: "a"(0), "D"(0x57AC)
|
||||||
|
: "rcx", "r11", "memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((weak, noreturn, no_stack_protector)) void __chk_fail(void)
|
||||||
|
{
|
||||||
|
const char *msg = "Buffer overflow detected";
|
||||||
|
__asm__ __volatile__("syscall"
|
||||||
|
:
|
||||||
|
: "a"(0), "D"(0xF700)
|
||||||
|
: "rcx", "r11", "memory");
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user