From 831bd71a148aab7742f02ac113f833e54b474eca Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 8 Jun 2018 07:17:51 +0200 Subject: [PATCH] mescc: syscall: return only ever error -1, set errno. --- lib/libc-mini.c | 26 ++++++++++++++++++++++++++ lib/linux-gcc.c | 20 ++++++++++++++++---- lib/linux-mes.c | 20 ++++++++++++++++---- lib/linux-mini-gcc.c | 12 +----------- lib/linux-mini-mes.c | 12 +----------- 5 files changed, 60 insertions(+), 30 deletions(-) diff --git a/lib/libc-mini.c b/lib/libc-mini.c index 16ac449e..2e9539ce 100644 --- a/lib/libc-mini.c +++ b/lib/libc-mini.c @@ -18,6 +18,8 @@ * along with Mes. If not, see . */ +#include + #ifndef __MES_SIZE_T #define __MES_SIZE_T #undef size_t @@ -72,3 +74,27 @@ puts (char const* s) #include #endif // !__MESC__ + +void (*__call_at_exit) (void); + +void +exit (int code) +{ + if (__call_at_exit) + (*__call_at_exit) (); + _exit (code); +} + +ssize_t +write (int filedes, void const *buffer, size_t size) +{ + int r = _write (filedes, buffer, size); + if (r < 0) + { + errno = -r; + r = -1; + } + else + errno = 0; + return r; +} diff --git a/lib/linux-gcc.c b/lib/linux-gcc.c index f92dcc68..f21704b5 100644 --- a/lib/linux-gcc.c +++ b/lib/linux-gcc.c @@ -34,7 +34,10 @@ _sys_call (int sys_call) : "eax" ); if (r < 0) - errno = -r; + { + errno = -r; + r = -1; + } else errno = 0; return r; @@ -56,7 +59,10 @@ _sys_call1 (int sys_call, int one) : "eax", "ebx" ); if (r < 0) - errno = -r; + { + errno = -r; + r = -1; + } else errno = 0; return r; @@ -79,7 +85,10 @@ _sys_call2 (int sys_call, int one, int two) : "eax", "ebx", "ecx" ); if (r < 0) - errno = -r; + { + errno = -r; + r = -1; + } else errno = 0; return r; @@ -102,8 +111,11 @@ _sys_call3 (int sys_call, int one, int two, int three) : "" (sys_call), "" (one), "" (two), "" (three) : "eax", "ebx", "ecx", "edx" ); - if (r < 0) + if (r < 0) + { errno = -r; + r = -1; + } else errno = 0; return r; diff --git a/lib/linux-mes.c b/lib/linux-mes.c index 1c4521ed..40633785 100644 --- a/lib/linux-mes.c +++ b/lib/linux-mes.c @@ -59,7 +59,10 @@ _sys_call (int sys_call) { int r = __sys_call (sys_call); if (r < 0) - errno = -r; + { + errno = -r; + r = -1; + } else errno = 0; return r; @@ -70,7 +73,10 @@ _sys_call1 (int sys_call, int one) { int r = __sys_call1 (sys_call, one); if (r < 0) - errno = -r; + { + errno = -r; + r = -1; + } else errno = 0; return r; @@ -81,7 +87,10 @@ _sys_call2 (int sys_call, int one, int two) { int r = __sys_call2 (sys_call, one, two); if (r < 0) - errno = -r; + { + errno = -r; + r = -1; + } else errno = 0; return r; @@ -92,7 +101,10 @@ _sys_call3 (int sys_call, int one, int two, int three) { int r = __sys_call3 (sys_call, one, two, three); if (r < 0) - errno = -r; + { + errno = -r; + r = -1; + } else errno = 0; return r; diff --git a/lib/linux-mini-gcc.c b/lib/linux-mini-gcc.c index 3fe3829d..737a1ba6 100644 --- a/lib/linux-mini-gcc.c +++ b/lib/linux-mini-gcc.c @@ -45,18 +45,8 @@ _exit (int code) _exit (0); } -void (*__call_at_exit) (void); - -void -exit (int code) -{ - if (__call_at_exit) - (*__call_at_exit) (); - _exit (code); -} - ssize_t -write (int filedes, void const *buffer, size_t size) +_write (int filedes, void const *buffer, size_t size) { int r; #if __GNUC__ diff --git a/lib/linux-mini-mes.c b/lib/linux-mini-mes.c index f2858a1f..ef57ac10 100644 --- a/lib/linux-mini-mes.c +++ b/lib/linux-mini-mes.c @@ -26,18 +26,8 @@ _exit () asm ("int____$0x80"); } -void (*__call_at_exit) (void); - void -exit (int code) -{ - if (__call_at_exit) - (*__call_at_exit) (); - _exit (code); -} - -void -write () +_write () { asm ("mov____$i32,%eax SYS_write"); asm ("mov____0x8(%ebp),%ebx !8");