Compare commits

...

2 Commits

Author SHA1 Message Date
0f5910add7 Kernel/Utilities: Add new round_{up,down}_to_nearest_page functions 2022-10-12 14:51:04 +02:00
baa71b09cc Kernel: Build with -fstack-protector-strong instead of -fstack-protector-all
We lose a LITTLE bit of security, while allowing the compiler to optimize MUCH more.

Very simple functions, like most functions in misc/utils.cpp, were being made very big when some of them can just be "jmp thingy" or "and rax, something" and waste much less space.

This change makes more sense, I think.
2022-10-12 14:50:31 +02:00
3 changed files with 14 additions and 1 deletions

View File

@ -4,7 +4,7 @@ MOON_OBJ := $(MOON_DIR)/lib
MOON_BIN := $(MOON_DIR)/bin
CFLAGS ?= -Os
CFLAGS := ${CFLAGS} -pedantic -Wall -Wextra -Werror -Wfloat-equal -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion -ffreestanding -fstack-protector-all -fno-omit-frame-pointer -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -fshort-wchar -mcmodel=kernel -I$(MOON_DIR)/include -isystem $(MOON_DIR)/include/std
CFLAGS := ${CFLAGS} -pedantic -Wall -Wextra -Werror -Wfloat-equal -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion -ffreestanding -fstack-protector-strong -fno-omit-frame-pointer -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -fshort-wchar -mcmodel=kernel -I$(MOON_DIR)/include -isystem $(MOON_DIR)/include/std
CXXFLAGS := -fno-rtti -fno-exceptions -Wsign-promo -Wstrict-null-sentinel -Wctor-dtor-privacy
ASMFLAGS := -felf64
LDFLAGS := -T$(MOON_DIR)/moon.ld -nostdlib -lgcc -Wl,--build-id=none -z max-page-size=0x1000 -mno-red-zone -mcmodel=kernel

View File

@ -8,4 +8,6 @@ namespace Utilities
uint64_t get_rflags();
uint64_t get_top_of_stack(uint64_t bottom, uint64_t stack_pages);
uint64_t round_down_to_nearest_page(uint64_t addr);
uint64_t round_up_to_nearest_page(uint64_t addr);
}

View File

@ -18,4 +18,15 @@ uint64_t Utilities::get_rflags()
uint64_t Utilities::get_top_of_stack(uint64_t bottom, uint64_t stack_pages)
{
return bottom + (stack_pages * PAGE_SIZE) - sizeof(uintptr_t);
}
uint64_t Utilities::round_down_to_nearest_page(uint64_t addr)
{
return addr - (addr % PAGE_SIZE);
}
uint64_t Utilities::round_up_to_nearest_page(uint64_t addr)
{
if (addr % PAGE_SIZE) return addr + (PAGE_SIZE - (addr % PAGE_SIZE));
return addr;
}