diff --git a/CMakeLists.txt b/CMakeLists.txt index ac5e998..d6546d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,12 +10,18 @@ file(GLOB_RECURSE SRC_FILES "${PROJECT_SOURCE_DIR}/Src/*.c") add_library(Iony STATIC ${SRC_FILES}) add_executable(IonyTest ${PROJECT_SOURCE_DIR}/Tests/Main.c) -target_link_libraries(Iony PRIVATE ${HALLOCY_LIB_PATH}) target_include_directories(IonyTest PRIVATE ${PROJECT_SOURCE_DIR}/Tests) target_link_libraries(IonyTest Iony) if (MSVC) - target_compile_options(Iony PRIVATE /W4 /Zl) + target_compile_options(Iony PRIVATE /W4 /Zl /GS- /kernel) + + target_link_options(IonyTest PRIVATE /NODEFAULTLIB /ENTRY:_start) + + target_link_libraries(Iony PRIVATE kernel32) + target_link_libraries(IonyTest PRIVATE kernel32) else() - target_compile_options(Iony PRIVATE -Wall -Wextra -pedantic) + target_compile_options(Iony PRIVATE -Wall -Wextra -pedantic -ffreestanding -fno-builtin) + target_link_options(Iony PRIVATE -nostdlib) + target_link_options(IonyTest PRIVATE -nostdlib) endif() \ No newline at end of file diff --git a/Include/Iony/Utils/System.h b/Include/Iony/Utils/System.h index fa85951..5ef96bc 100644 --- a/Include/Iony/Utils/System.h +++ b/Include/Iony/Utils/System.h @@ -23,19 +23,26 @@ #ifndef IONY_SYSTEM #define IONY_SYSTEM -#if defined(__GNUC__) +#if defined(_WIN32) +#include +#elif defined(__GNUC__) + #if defined(__x86_64__) #define IONY_SYS_READ 0 #define IONY_SYS_WRITE 1 +#define IONY_SYS_EXIT 60 #elif defined(__i386__) #define IONY_SYS_READ 3 #define IONY_SYS_WRITE 4 +#define IONY_SYS_EXIT 1 #elif defined(__aarch64__) #define IONY_SYS_READ 63 #define IONY_SYS_WRITE 64 +#define IONY_SYS_EXIT 93 #elif defined(__arm__) #define IONY_SYS_READ 3 #define IONY_SYS_WRITE 4 +#define IONY_SYS_EXIT 1 #endif static inline long iony_system_call(long number, long argument1, long argument2, long argument3, long argument4, long argument5, long argument6) { @@ -98,6 +105,16 @@ static inline long iony_system_call(long number, long argument1, long argument2, return result; } +#else +#error "Unsupported architecture" #endif +static inline void iony_exit_process(int exit_code) { + #if defined(_WIN32) + ExitProcess(exit_code); + #elif defined(__GNUC__) + iony_system_call(IONY_SYS_EXIT, exit_code, 0, 0, 0, 0, 0); + #endif +} + #endif diff --git a/Src/Core/Console.c b/Src/Core/Console.c index 81ba099..b333647 100644 --- a/Src/Core/Console.c +++ b/Src/Core/Console.c @@ -20,17 +20,15 @@ * ----------------------------------------------------------------------------- */ #include "../../Include/Iony/Core/Console.h" -#include "Iony/Utils/Error.h" + +#include "../../Include/Iony/Utils/System.h" #if defined(_WIN32) -#include - static HANDLE iony_standard_console_out = 0; static HANDLE iony_standard_console_in = 0; static WORD iony_original_console_attributes = 0; #elif defined(__GNUC__) -#include "../../Include/Iony/Utils/System.h" static const char IONY_RESET_COLOR[] = "\033[0m"; static const char *IONY_ANSI_COLORS[] = { diff --git a/Tests/Main.c b/Tests/Main.c index 4d003ac..f3aadc5 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -19,45 +19,46 @@ * Author: Mineplay * ----------------------------------------------------------------------------- */ +#include #include #include -int main(void) { +void _start(void) { if (iony_console_print("Press enter to continue...", 27) != IONY_ERROR_NONE) { - return -1; + iony_exit_process(-1); } char character = ' '; if (iony_console_get_character(&character) != IONY_ERROR_NONE) { - return -1; + iony_exit_process(-1); } if (iony_console_clear() != IONY_ERROR_NONE) { - return -1; + iony_exit_process(-1); } if (iony_console_print("Enter your name: ", 18) != IONY_ERROR_NONE) { - return -1; + iony_exit_process(-1); } char name_input[256]; long characters_read = 0; if (iony_console_get_line(name_input, 256, &characters_read) != IONY_ERROR_NONE) { - return -1; + iony_exit_process(-1); } iony_console_set_color(IONY_CONSOLE_COLOR_LIGHT_RED); if (iony_console_print("Your name is ", 14) != IONY_ERROR_NONE) { - return -1; + iony_exit_process(-1); } if (iony_console_print(name_input, characters_read) != IONY_ERROR_NONE) { - return -1; + iony_exit_process(-1); } if (iony_console_reset_color() != IONY_ERROR_NONE) { - return -1; + iony_exit_process(-1); } - return 0; + iony_exit_process(0); } \ No newline at end of file