Update userspace

This commit is contained in:
Alex
2023-06-10 13:10:56 +03:00
parent ed5faa7b55
commit 22e75b9540
63 changed files with 2362 additions and 2151 deletions

View File

@@ -3,18 +3,23 @@ include ../../../Makefile.conf
NAME=ssp
OBJECT_NAME=lib$(NAME).a
ifeq ($(USERSPACE_STATIC_LIBS), 1)
OBJECT_NAME := lib$(NAME).a
else
OBJECT_NAME := lib$(NAME).so
endif
OUTPUT_DIR=../../out/lib/
SYSROOT = --sysroot=../../out/
CC = ../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)gcc
AR = ../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)ar
OBJDUMP = ../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)objdump
NASM = /usr/bin/nasm
CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc
AS = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)as
AR = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ar
C_SOURCES = $(shell find ./ -type f -name '*.c')
ASM_SOURCES = $(shell find ./ -type f -name '*.asm')
OBJ = ${C_SOURCES:.c=.o} ${ASM_SOURCES:.asm=.o}
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp')
S_SOURCES = $(shell find ./ -type f -name '*.S')
OBJ = ${C_SOURCES:.c=.o} ${CPP_SOURCES:.cpp=.o} ${S_SOURCES:.S=.o}
ifeq ($(OSARCH), amd64)
ASM_ARCH := elf64
@@ -22,14 +27,21 @@ else ifeq ($(OSARCH), i386)
ASM_ARCH := elf32
endif
CFLAGS := -fPIC -I../include -I../../libc/include
CFLAGS := -fvisibility=hidden -fPIC -I../include -I../../libc/include
ifeq ($(DEBUG), 1)
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
endif
build: $(OBJECT_NAME)
$(OBJECT_NAME): $(OBJ)
$(info Linking $@)
ifeq ($(USERSPACE_STATIC_LIBS), 1)
$(AR) rcs $(OUTPUT_DIR)$@ $(OBJ)
$(OBJDUMP) -d $(OUTPUT_DIR)$@ > file_dump.map
else
$(CC) -nostdlib -shared -fPIC -fPIE -Wl,-soname,$(OBJECT_NAME) $(SYSROOT) $(OBJ) -o $(OUTPUT_DIR)$@
endif
%.o: %.c
$(info Compiling $<)
@@ -39,9 +51,9 @@ $(OBJECT_NAME): $(OBJ)
$(info Compiling $<)
$(CC) $(CFLAGS) -std=c++20 -c $< -o $@
%.o: %.asm
%.o: %.S
$(info Compiling $<)
$(NASM) $< -f $(ASM_ARCH) -o $@
$(AS) -c $< -o $@
clean:
rm -f file_dump.map $(OBJ)
rm -f $(OBJ)

View File

@@ -6,30 +6,39 @@
#endif
#endif
__UINTPTR_TYPE__ __stack_chk_guard = 0;
#ifndef PUBLIC
#define PUBLIC __attribute__((visibility("default")))
#endif // !PUBLIC
#ifndef PRIVATE
#define PRIVATE __attribute__((visibility("hidden")))
#endif // !PRIVATE
PUBLIC __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;
if (__stack_chk_guard == 0)
__stack_chk_guard = STACK_CHK_GUARD_VALUE;
}
__attribute__((weak, noreturn, no_stack_protector)) void __stack_chk_fail(void)
PUBLIC __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");
__builtin_unreachable();
const char *msg = "Stack smashing detected";
__asm__ __volatile__("syscall"
:
: "a"(0), "D"(0x57AC)
: "rcx", "r11", "memory");
__builtin_unreachable();
}
__attribute__((weak, noreturn, no_stack_protector)) void __chk_fail(void)
PUBLIC __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");
__builtin_unreachable();
const char *msg = "Buffer overflow detected";
__asm__ __volatile__("syscall"
:
: "a"(0), "D"(0xF700)
: "rcx", "r11", "memory");
__builtin_unreachable();
}