From d1e3a786aaf69a18bbe8f43b26d9858f0f4b3160 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Thu, 7 Jun 2018 07:16:43 +0200 Subject: [PATCH] mescc: Support gcc-3.2: Reset errno. * lib/linux-gcc.c (_sys_call, _sys_call1, _sys_call2, _sys_call3): Reset errno. * lib/linux-mes.c (__sys_call, __sys_call1, __sys_call2 , __sys_call3): Rename from _*. (_sys_call, _sys_call1, _sys_call2, _sys_call3): New function. Reset errno. --- lib/linux-gcc.c | 8 ++++++++ lib/linux-mes.c | 54 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/lib/linux-gcc.c b/lib/linux-gcc.c index 79de74f3..9e6048c5 100644 --- a/lib/linux-gcc.c +++ b/lib/linux-gcc.c @@ -35,6 +35,8 @@ _sys_call (int sys_call) ); if (r < 0) errno = -r; + else + errno = 0 return r; #endif } @@ -55,6 +57,8 @@ _sys_call1 (int sys_call, int one) ); if (r < 0) errno = -r; + else + errno = 0 return r; #endif } @@ -76,6 +80,8 @@ _sys_call2 (int sys_call, int one, int two) ); if (r < 0) errno = -r; + else + errno = 0 return r; #endif } @@ -98,6 +104,8 @@ _sys_call3 (int sys_call, int one, int two, int three) ); if (r < 0) errno = -r; + else + errno = 0 return r; #endif } diff --git a/lib/linux-mes.c b/lib/linux-mes.c index 2fe00e6f..6f1a8534 100644 --- a/lib/linux-mes.c +++ b/lib/linux-mes.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * Mes --- Maxwell Equations of Software - * Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen * * This file is part of Mes. * @@ -21,14 +21,14 @@ #include int -_sys_call (int sys_call) +__sys_call (int sys_call) { asm ("mov____0x8(%ebp),%eax !8"); asm ("int____$0x80"); } int -_sys_call1 (int sys_call, int one) +__sys_call1 (int sys_call, int one) { asm ("mov____0x8(%ebp),%eax !8"); asm ("mov____0x8(%ebp),%ebx !12"); @@ -36,7 +36,7 @@ _sys_call1 (int sys_call, int one) } int -_sys_call2 (int sys_call, int one, int two) +__sys_call2 (int sys_call, int one, int two) { asm ("mov____0x8(%ebp),%eax !8"); asm ("mov____0x8(%ebp),%ebx !12"); @@ -45,7 +45,7 @@ _sys_call2 (int sys_call, int one, int two) } int -_sys_call3 (int sys_call, int one, int two, int three) +__sys_call3 (int sys_call, int one, int two, int three) { asm ("mov____0x8(%ebp),%eax !8"); asm ("mov____0x8(%ebp),%ebx !12"); @@ -53,3 +53,47 @@ _sys_call3 (int sys_call, int one, int two, int three) asm ("mov____0x8(%ebp),%edx !20"); asm ("int____$0x80"); } + +int +_sys_call (int sys_call) +{ + int r = __sys_call (sys_call); + if (r < 0) + errno = -r; + else + errno = 0 + return r; +} + +int +_sys_call1 (int sys_call, int one) +{ + int r = __sys_call1 (sys_call, one); + if (r < 0) + errno = -r; + else + errno = 0 + return r; +} + +int +_sys_call2 (int sys_call, int one, int two) +{ + int r = __sys_call2 (sys_call, one, two); + if (r < 0) + errno = -r; + else + errno = 0 + return r; +} + +int +_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; + else + errno = 0 + return r; +}