From d3a7b18f6955e62022b0e7074111d82f86d640c1 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Tue, 13 Sep 2011 16:49:08 +0200 Subject: [PATCH] libc now has exit() and abort() functions. --- crosscompilemakefile.mak | 2 +- libmaxsi/hsrc/process.h | 2 ++ libmaxsi/process.cpp | 18 ++++++++++++++++++ libmaxsi/start.s | 17 +++-------------- libmaxsi/thread.cpp | 7 ------- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/crosscompilemakefile.mak b/crosscompilemakefile.mak index b5195a19..9baa8840 100644 --- a/crosscompilemakefile.mak +++ b/crosscompilemakefile.mak @@ -18,7 +18,7 @@ endif LIBMAXSIROOT=$(OSROOT)/libmaxsi -LIBC=$(LIBMAXSIROOT)/libc.a $(LIBMAXSIROOT)/start.o +LIBC=$(LIBMAXSIROOT)/start.o $(LIBMAXSIROOT)/libc.a LIBS=$(LIBC) CPPFLAGS=$(CPUDEFINES) diff --git a/libmaxsi/hsrc/process.h b/libmaxsi/hsrc/process.h index dea5773d..74fde6e8 100644 --- a/libmaxsi/hsrc/process.h +++ b/libmaxsi/hsrc/process.h @@ -31,6 +31,8 @@ namespace Maxsi { int Execute(const char* filepath, int argc, const char** argv); void PrintPathFiles(); + void Abort(); + void Exit(int code); } } diff --git a/libmaxsi/process.cpp b/libmaxsi/process.cpp index 0eb8edb0..6228b5ce 100644 --- a/libmaxsi/process.cpp +++ b/libmaxsi/process.cpp @@ -42,6 +42,24 @@ namespace Maxsi { SysPrintPathFiles(); } + + void Abort() + { + // TODO: Send SIGABRT instead! + Exit(128 + 6); + } + + extern "C" void abort() { return Abort(); } + + void Exit(int code) + { + const char* sh = "sh"; + const char* argv[] = { sh }; + Execute("sh", 1, argv); + while(true); + } + + extern "C" void exit(int code) { return Exit(code); } } } diff --git a/libmaxsi/start.s b/libmaxsi/start.s index a199fd3b..4131b495 100644 --- a/libmaxsi/start.s +++ b/libmaxsi/start.s @@ -36,18 +36,7 @@ _start: push $0 # argc call main - # HACK: Just restart the shell! - mov $10, %eax - mov $SH, %ebx - int $0x80 - - # Now return mains result when exiting the process - mov %eax, %ebx - mov $1, %eax - mov $0x0, %ebx # TODO: This syscall exits a thread, not a process! - int $0x80 - -.section .data -SH: - .asciz "sh" + # Terminate the process with main's exit code. + push %eax + call exit diff --git a/libmaxsi/thread.cpp b/libmaxsi/thread.cpp index 86ea4d05..047f1f4e 100644 --- a/libmaxsi/thread.cpp +++ b/libmaxsi/thread.cpp @@ -48,13 +48,6 @@ namespace Maxsi SysExit(Result); } -#ifdef LIBMAXSI_LIBC - extern "C" void exit(int result) - { - SysExit(NULL); - } -#endif - void ThreadStartup(size_t Id, Entry Start, void* Parameter) { Exit(Start(Parameter));