mescc: syscall: return only ever error -1, set errno.

This commit is contained in:
Jan Nieuwenhuizen 2018-06-08 07:17:51 +02:00
parent b7d913d7a0
commit 831bd71a14
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
5 changed files with 60 additions and 30 deletions

View file

@ -18,6 +18,8 @@
* along with Mes. If not, see <http://www.gnu.org/licenses/>. * along with Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <errno.h>
#ifndef __MES_SIZE_T #ifndef __MES_SIZE_T
#define __MES_SIZE_T #define __MES_SIZE_T
#undef size_t #undef size_t
@ -72,3 +74,27 @@ puts (char const* s)
#include <linux-mini-gcc.c> #include <linux-mini-gcc.c>
#endif // !__MESC__ #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;
}

View file

@ -34,7 +34,10 @@ _sys_call (int sys_call)
: "eax" : "eax"
); );
if (r < 0) if (r < 0)
errno = -r; {
errno = -r;
r = -1;
}
else else
errno = 0; errno = 0;
return r; return r;
@ -56,7 +59,10 @@ _sys_call1 (int sys_call, int one)
: "eax", "ebx" : "eax", "ebx"
); );
if (r < 0) if (r < 0)
errno = -r; {
errno = -r;
r = -1;
}
else else
errno = 0; errno = 0;
return r; return r;
@ -79,7 +85,10 @@ _sys_call2 (int sys_call, int one, int two)
: "eax", "ebx", "ecx" : "eax", "ebx", "ecx"
); );
if (r < 0) if (r < 0)
errno = -r; {
errno = -r;
r = -1;
}
else else
errno = 0; errno = 0;
return r; return r;
@ -102,8 +111,11 @@ _sys_call3 (int sys_call, int one, int two, int three)
: "" (sys_call), "" (one), "" (two), "" (three) : "" (sys_call), "" (one), "" (two), "" (three)
: "eax", "ebx", "ecx", "edx" : "eax", "ebx", "ecx", "edx"
); );
if (r < 0) if (r < 0)
{
errno = -r; errno = -r;
r = -1;
}
else else
errno = 0; errno = 0;
return r; return r;

View file

@ -59,7 +59,10 @@ _sys_call (int sys_call)
{ {
int r = __sys_call (sys_call); int r = __sys_call (sys_call);
if (r < 0) if (r < 0)
errno = -r; {
errno = -r;
r = -1;
}
else else
errno = 0; errno = 0;
return r; return r;
@ -70,7 +73,10 @@ _sys_call1 (int sys_call, int one)
{ {
int r = __sys_call1 (sys_call, one); int r = __sys_call1 (sys_call, one);
if (r < 0) if (r < 0)
errno = -r; {
errno = -r;
r = -1;
}
else else
errno = 0; errno = 0;
return r; return r;
@ -81,7 +87,10 @@ _sys_call2 (int sys_call, int one, int two)
{ {
int r = __sys_call2 (sys_call, one, two); int r = __sys_call2 (sys_call, one, two);
if (r < 0) if (r < 0)
errno = -r; {
errno = -r;
r = -1;
}
else else
errno = 0; errno = 0;
return r; 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); int r = __sys_call3 (sys_call, one, two, three);
if (r < 0) if (r < 0)
errno = -r; {
errno = -r;
r = -1;
}
else else
errno = 0; errno = 0;
return r; return r;

View file

@ -45,18 +45,8 @@ _exit (int code)
_exit (0); _exit (0);
} }
void (*__call_at_exit) (void);
void
exit (int code)
{
if (__call_at_exit)
(*__call_at_exit) ();
_exit (code);
}
ssize_t ssize_t
write (int filedes, void const *buffer, size_t size) _write (int filedes, void const *buffer, size_t size)
{ {
int r; int r;
#if __GNUC__ #if __GNUC__

View file

@ -26,18 +26,8 @@ _exit ()
asm ("int____$0x80"); asm ("int____$0x80");
} }
void (*__call_at_exit) (void);
void void
exit (int code) _write ()
{
if (__call_at_exit)
(*__call_at_exit) ();
_exit (code);
}
void
write ()
{ {
asm ("mov____$i32,%eax SYS_write"); asm ("mov____$i32,%eax SYS_write");
asm ("mov____0x8(%ebp),%ebx !8"); asm ("mov____0x8(%ebp),%ebx !8");