diff --git a/luna/CMakeLists.txt b/luna/CMakeLists.txt index a8af5718..286619d6 100644 --- a/luna/CMakeLists.txt +++ b/luna/CMakeLists.txt @@ -8,6 +8,7 @@ set(FREESTANDING_SOURCES src/SystemError.cpp src/Bitmap.cpp src/Stack.cpp + src/Alloc.cpp ) set(SOURCES @@ -28,24 +29,24 @@ target_compile_options(luna-freestanding PRIVATE -nostdlib -mcmodel=kernel) target_include_directories(luna-freestanding PUBLIC include/) set_target_properties(luna-freestanding PROPERTIES CXX_STANDARD 20) -add_library(luna ${SOURCES}) -target_compile_options(luna PRIVATE -Wall -Wextra -Werror -Wvla) -target_compile_options(luna PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self) -target_compile_options(luna PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef) -target_compile_options(luna PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion) -target_compile_options(luna PRIVATE -fno-asynchronous-unwind-tables -fno-omit-frame-pointer) -target_include_directories(luna PUBLIC include/) -set_target_properties(luna PROPERTIES CXX_STANDARD 20) +#add_library(luna ${SOURCES}) +#target_compile_options(luna PRIVATE -Wall -Wextra -Werror -Wvla) +#target_compile_options(luna PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self) +#target_compile_options(luna PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef) +#target_compile_options(luna PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion) +#target_compile_options(luna PRIVATE -fno-asynchronous-unwind-tables -fno-omit-frame-pointer) +#target_include_directories(luna PUBLIC include/) +#set_target_properties(luna PROPERTIES CXX_STANDARD 20) if("${ARCH}" MATCHES "x86_64") target_compile_options(luna-freestanding PRIVATE -mno-red-zone) target_compile_options(luna-freestanding PRIVATE -mno-80387 -mno-mmx -mno-sse -mno-sse2) target_compile_definitions(luna-freestanding PUBLIC ARCH_X86_64) -target_compile_definitions(luna PUBLIC ARCH_X86_64) +#target_compile_definitions(luna PUBLIC ARCH_X86_64) endif() if(LUNA_DEBUG_SYMBOLS) message(STATUS "Building Luna with debug symbols") - target_compile_options(luna PRIVATE -ggdb) + #target_compile_options(luna PRIVATE -ggdb) target_compile_options(luna-freestanding PRIVATE -ggdb) endif() \ No newline at end of file diff --git a/luna/include/luna/Alloc.h b/luna/include/luna/Alloc.h index ba8a0151..d76b7442 100644 --- a/luna/include/luna/Alloc.h +++ b/luna/include/luna/Alloc.h @@ -1,6 +1,9 @@ #pragma once #include +[[nodiscard]] void* raw_malloc(usize); +void raw_free(void*); + template [[nodiscard]] Result make(Args... args) { T* const result = new T(args...); diff --git a/luna/src/Alloc.cpp b/luna/src/Alloc.cpp new file mode 100644 index 00000000..105f4ac9 --- /dev/null +++ b/luna/src/Alloc.cpp @@ -0,0 +1,25 @@ +#include + +#ifndef USE_FREESTANDING +#include +#endif + +[[nodiscard]] void* raw_malloc(usize size) +{ +#ifdef USE_FREESTANDING + char* const rc = new char[size]; + return (void*)rc; +#else + return malloc(size); +#endif +} + +void raw_free(void* ptr) +{ +#ifdef USE_FREESTANDING + char* const arr = (char*)ptr; + delete[] arr; +#else + return free(ptr); +#endif +} \ No newline at end of file