diff --git a/code/os/win/env.c b/code/os/win/env.c deleted file mode 100644 index 8688081..0000000 --- a/code/os/win/env.c +++ /dev/null @@ -1,10 +0,0 @@ - -#include - -#define WIN32_LEAN_AND_MEAN -#include - -void _os_exit(int code) -{ - ExitProcess(code); -} diff --git a/code/os/win/win32.h b/code/os/win/win.h similarity index 100% rename from code/os/win/win32.h rename to code/os/win/win.h diff --git a/code/os/win/entry.c b/code/os/win/win_entry.c similarity index 99% rename from code/os/win/entry.c rename to code/os/win/win_entry.c index eb538b3..314fe29 100644 --- a/code/os/win/entry.c +++ b/code/os/win/win_entry.c @@ -6,7 +6,7 @@ #include #include -#include "win32.h" +#include "win.h" extern int main(int argc, char** argv); diff --git a/code/os/win/win_env.c b/code/os/win/win_env.c new file mode 100644 index 0000000..76c3ecf --- /dev/null +++ b/code/os/win/win_env.c @@ -0,0 +1,9 @@ + +#include + +#include "win.h" + +_Noreturn void _os_exit(int code) +{ + ExitProcess(code); +} diff --git a/code/os/win/except.c b/code/os/win/win_except.c similarity index 96% rename from code/os/win/except.c rename to code/os/win/win_except.c index 9a1d38d..0e4c131 100644 --- a/code/os/win/except.c +++ b/code/os/win/win_except.c @@ -33,8 +33,7 @@ static SignalMapping map[] = { {EXCEPTION_SINGLE_STEP, SIGSTEP}, }; -static LONG _win32_handler(EXCEPTION_POINTERS *ExceptionInfo) -{ +static LONG _win32_handler(EXCEPTION_POINTERS *ExceptionInfo) { EXCEPTION_RECORD *exception = ExceptionInfo->ExceptionRecord; DWORD code = exception->ExceptionCode; int signal = -1; diff --git a/code/os/win/io.c b/code/os/win/win_io.c similarity index 81% rename from code/os/win/io.c rename to code/os/win/win_io.c index edea935..4059204 100644 --- a/code/os/win/io.c +++ b/code/os/win/win_io.c @@ -1,6 +1,5 @@ -#define WIN32_LEAN_AND_MEAN -#include +#include "win.h" // It's just mapped directly to HANDLE struct FILE { diff --git a/code/os/win/mem.c b/code/os/win/win_mem.c similarity index 98% rename from code/os/win/mem.c rename to code/os/win/win_mem.c index 0b218bc..6675287 100644 --- a/code/os/win/mem.c +++ b/code/os/win/win_mem.c @@ -3,7 +3,7 @@ #include #include -#include "win32.h" +#include "win.h" // TODO: lock the heap before allocation (?) diff --git a/code/stdlib/env.c b/code/stdlib/env.c new file mode 100644 index 0000000..9e8b349 --- /dev/null +++ b/code/stdlib/env.c @@ -0,0 +1,21 @@ + +#include +#include + +#include <_os.h> + +_Noreturn void abort(void) { + raise(SIGABRT); + _os_exit(-69); +} + +// TODO: at_exit handling + +_Noreturn void exit(int status) { + _os_exit(status); +} + +_Noreturn void _Exit(int status) { + _os_exit(status); +} + diff --git a/inc/_os.h b/inc/_os.h index 37c46d0..8a1860b 100644 --- a/inc/_os.h +++ b/inc/_os.h @@ -16,6 +16,6 @@ // OS-dependent IO Functions void _os_file_write(void* ctx, size_t n, const char str[]); -void _os_exit(int code); +_Noreturn void _os_exit(int code); void _os_init_eh(); typedef struct FILE FILE; diff --git a/inc/stdlib.h b/inc/stdlib.h index 3ca5496..bffb106 100644 --- a/inc/stdlib.h +++ b/inc/stdlib.h @@ -15,6 +15,9 @@ #endif #endif +#define EXIT_SUCCESS 0 +#define EXIT_FAILURE 1 + // typedef struct div_t { // int quot; // int rem; @@ -58,11 +61,11 @@ void free(void *ptr); void *malloc(size_t size); void *realloc(void *ptr, size_t size); -// _Noreturn void abort(void); +_Noreturn void abort(void); // int atexit(void (*func)(void)); // int at_quick_exit(void (*func)(void)); -// _Noreturn void exit(int status); -// _Noreturn void _Exit(int status); +_Noreturn void exit(int status); +_Noreturn void _Exit(int status); // char *getenv(const char *name); // _Noreturn void quick_exit(int status); // int system(const char *string); diff --git a/test/test.c b/test/test.c index 4ee6606..c214f30 100644 --- a/test/test.c +++ b/test/test.c @@ -9,16 +9,13 @@ #include -void my_va_handler(int a) { - printf("NULLPTR deref or something idk not an expert in signals\n"); +void onabort(int a) { + printf("I don't want to live anymore\n"); + exit(-69); } int main(int argc, char** argv) { - signal(SIGSEGV, my_va_handler); - signal(SIGFPE, my_va_handler); - - int a = INT_MAX; - a /= 0; - + signal(SIGABRT, onabort); + assert(0 != 0); return 0; } \ No newline at end of file