make assert do abort

This commit is contained in:
bumbread 2022-06-07 17:15:47 +11:00
parent 3252f1f10a
commit a8d1afdea2
11 changed files with 46 additions and 28 deletions

View File

@ -1,10 +0,0 @@
#include <stdlib.h>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
void _os_exit(int code)
{
ExitProcess(code);
}

View File

@ -6,7 +6,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "win32.h" #include "win.h"
extern int main(int argc, char** argv); extern int main(int argc, char** argv);

9
code/os/win/win_env.c Normal file
View File

@ -0,0 +1,9 @@
#include <stdlib.h>
#include "win.h"
_Noreturn void _os_exit(int code)
{
ExitProcess(code);
}

View File

@ -33,8 +33,7 @@ static SignalMapping map[] = {
{EXCEPTION_SINGLE_STEP, SIGSTEP}, {EXCEPTION_SINGLE_STEP, SIGSTEP},
}; };
static LONG _win32_handler(EXCEPTION_POINTERS *ExceptionInfo) static LONG _win32_handler(EXCEPTION_POINTERS *ExceptionInfo) {
{
EXCEPTION_RECORD *exception = ExceptionInfo->ExceptionRecord; EXCEPTION_RECORD *exception = ExceptionInfo->ExceptionRecord;
DWORD code = exception->ExceptionCode; DWORD code = exception->ExceptionCode;
int signal = -1; int signal = -1;

View File

@ -1,6 +1,5 @@
#define WIN32_LEAN_AND_MEAN #include "win.h"
#include <Windows.h>
// It's just mapped directly to HANDLE // It's just mapped directly to HANDLE
struct FILE { struct FILE {

View File

@ -3,7 +3,7 @@
#include <limits.h> #include <limits.h>
#include <stdbool.h> #include <stdbool.h>
#include "win32.h" #include "win.h"
// TODO: lock the heap before allocation (?) // TODO: lock the heap before allocation (?)

21
code/stdlib/env.c Normal file
View File

@ -0,0 +1,21 @@
#include <stdlib.h>
#include <signal.h>
#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);
}

View File

@ -16,6 +16,6 @@
// OS-dependent IO Functions // OS-dependent IO Functions
void _os_file_write(void* ctx, size_t n, const char str[]); 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(); void _os_init_eh();
typedef struct FILE FILE; typedef struct FILE FILE;

View File

@ -15,6 +15,9 @@
#endif #endif
#endif #endif
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
// typedef struct div_t { // typedef struct div_t {
// int quot; // int quot;
// int rem; // int rem;
@ -58,11 +61,11 @@ void free(void *ptr);
void *malloc(size_t size); void *malloc(size_t size);
void *realloc(void *ptr, size_t size); void *realloc(void *ptr, size_t size);
// _Noreturn void abort(void); _Noreturn void abort(void);
// int atexit(void (*func)(void)); // int atexit(void (*func)(void));
// int at_quick_exit(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); // char *getenv(const char *name);
// _Noreturn void quick_exit(int status); // _Noreturn void quick_exit(int status);
// int system(const char *string); // int system(const char *string);

View File

@ -9,16 +9,13 @@
#include <signal.h> #include <signal.h>
void my_va_handler(int a) { void onabort(int a) {
printf("NULLPTR deref or something idk not an expert in signals\n"); printf("I don't want to live anymore\n");
exit(-69);
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
signal(SIGSEGV, my_va_handler); signal(SIGABRT, onabort);
signal(SIGFPE, my_va_handler); assert(0 != 0);
int a = INT_MAX;
a /= 0;
return 0; return 0;
} }