unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Subject: [PATCH 07/15] mips: Use Linux kABI for syscall return
Date: Mon, 10 Feb 2020 16:20:30 -0300	[thread overview]
Message-ID: <20200210192038.23588-7-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <20200210192038.23588-1-adhemerval.zanella@linaro.org>

It changes the mips INTERNAL_SYSCALL* and internal_syscall*  macros
to return a negative value instead of 'a3' register value on 'err'
macro argument.

The macro INTERNAL_SYSCALL_DECL is no longer required, and the
INTERNAL_SYSCALL_ERROR_P follows the other Linux kABIS.  The
redefinition of INTERNAL_VSYSCALL_CALL is also no longer
required.

Checked on mips64-linux-gnu, mips64n32-linux-gnu, and mips-linux-gnu.
---
 sysdeps/unix/sysv/linux/mips/mips32/sysdep.h | 32 ++++++++------------
 sysdeps/unix/sysv/linux/mips/mips64/sysdep.h | 28 +++++++----------
 sysdeps/unix/sysv/linux/mips/sysdep.h        | 16 ----------
 3 files changed, 23 insertions(+), 53 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
index beefcf284b..6842ff5211 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
+++ b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
@@ -61,13 +61,14 @@
      result_var; })
 
 #undef INTERNAL_SYSCALL_DECL
-#define INTERNAL_SYSCALL_DECL(err) long err __attribute__ ((unused))
+#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
 
 #undef INTERNAL_SYSCALL_ERROR_P
-#define INTERNAL_SYSCALL_ERROR_P(val, err)   ((void) (val), (long) (err))
+#define INTERNAL_SYSCALL_ERROR_P(val, err) \
+  ((unsigned long) (val) >= (unsigned long) -4095)
 
 #undef INTERNAL_SYSCALL_ERRNO
-#define INTERNAL_SYSCALL_ERRNO(val, err)     ((void) (err), val)
+#define INTERNAL_SYSCALL_ERRNO(val, err)     (-(val))
 
 /* Note that the original Linux syscall restart convention required the
    instruction immediately preceding SYSCALL to initialize $v0 with the
@@ -128,7 +129,6 @@ union __mips_syscall_return
 ({									\
 	union __mips_syscall_return _sc_ret;				\
 	_sc_ret.val = __mips16_syscall##nr (args, number);		\
-	err = _sc_ret.reg.v1;						\
 	_sc_ret.reg.v0;							\
 })
 
@@ -167,8 +167,7 @@ union __mips_syscall_return
 	: "=r" (__v0), "=r" (__a3)					\
 	: input								\
 	: __SYSCALL_CLOBBERS);						\
-	err = __a3;							\
-	_sys_result = __v0;						\
+	_sys_result = __a3 != 0 ? -__v0 : __v0;				\
 	}								\
 	_sys_result;							\
 })
@@ -191,8 +190,7 @@ union __mips_syscall_return
 	: "=r" (__v0), "=r" (__a3)					\
 	: input, "r" (__a0)						\
 	: __SYSCALL_CLOBBERS);						\
-	err = __a3;							\
-	_sys_result = __v0;						\
+	_sys_result = __a3 != 0 ? -__v0 : __v0;				\
 	}								\
 	_sys_result;							\
 })
@@ -216,8 +214,7 @@ union __mips_syscall_return
 	: "=r" (__v0), "=r" (__a3)					\
 	: input, "r" (__a0), "r" (__a1)					\
 	: __SYSCALL_CLOBBERS);						\
-	err = __a3;							\
-	_sys_result = __v0;						\
+	_sys_result = __a3 != 0 ? -__v0 : __v0;				\
 	}								\
 	_sys_result;							\
 })
@@ -243,8 +240,7 @@ union __mips_syscall_return
 	: "=r" (__v0), "=r" (__a3)					\
 	: input, "r" (__a0), "r" (__a1), "r" (__a2)			\
 	: __SYSCALL_CLOBBERS);						\
-	err = __a3;							\
-	_sys_result = __v0;						\
+	_sys_result = __a3 != 0 ? -__v0 : __v0;				\
 	}								\
 	_sys_result;							\
 })
@@ -270,8 +266,7 @@ union __mips_syscall_return
 	: "=r" (__v0), "+r" (__a3)					\
 	: input, "r" (__a0), "r" (__a1), "r" (__a2)			\
 	: __SYSCALL_CLOBBERS);						\
-	err = __a3;							\
-	_sys_result = __v0;						\
+	_sys_result = __a3 != 0 ? -__v0 : __v0;				\
 	}								\
 	_sys_result;							\
 })
@@ -300,8 +295,7 @@ libc_hidden_proto (__mips_syscall5, nomips16)
 				       (long) (arg4),			\
 				       (long) (arg5),			\
 				       (long) (number));		\
-	err = _sc_ret.reg.v1;						\
-	_sc_ret.reg.v0;							\
+	_sc_ret.reg.v1 != 0 ? -_sc_ret.reg.v0 : _sc_ret.reg.v0;		\
 })
 
 long long __nomips16 __mips_syscall6 (long arg1, long arg2, long arg3,
@@ -320,8 +314,7 @@ libc_hidden_proto (__mips_syscall6, nomips16)
 				       (long) (arg5),			\
 				       (long) (arg6),			\
 				       (long) (number));		\
-	err = _sc_ret.reg.v1;						\
-	_sc_ret.reg.v0;							\
+	_sc_ret.reg.v1 != 0 ? -_sc_ret.reg.v0 : _sc_ret.reg.v0;		\
 })
 
 long long __nomips16 __mips_syscall7 (long arg1, long arg2, long arg3,
@@ -342,8 +335,7 @@ libc_hidden_proto (__mips_syscall7, nomips16)
 				       (long) (arg6),			\
 				       (long) (arg7),			\
 				       (long) (number));		\
-	err = _sc_ret.reg.v1;						\
-	_sc_ret.reg.v0;							\
+	_sc_ret.reg.v1 != 0 ? -_sc_ret.reg.v0 : _sc_ret.reg.v0;		\
 })
 
 #if __mips_isa_rev >= 6
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h
index 617e229a67..072016f07e 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/mips/mips64/sysdep.h
@@ -69,13 +69,14 @@ typedef long int __syscall_arg_t;
      result_var; })
 
 #undef INTERNAL_SYSCALL_DECL
-#define INTERNAL_SYSCALL_DECL(err) long err __attribute__ ((unused))
+#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
 
 #undef INTERNAL_SYSCALL_ERROR_P
-#define INTERNAL_SYSCALL_ERROR_P(val, err)   ((void) (val), (long) (err))
+#define INTERNAL_SYSCALL_ERROR_P(val, err) \
+  ((unsigned long) (val) >= (unsigned long) -4095)
 
 #undef INTERNAL_SYSCALL_ERRNO
-#define INTERNAL_SYSCALL_ERRNO(val, err)     ((void) (err), val)
+#define INTERNAL_SYSCALL_ERRNO(val, err)     (-(val))
 
 /* Note that the original Linux syscall restart convention required the
    instruction immediately preceding SYSCALL to initialize $v0 with the
@@ -133,8 +134,7 @@ typedef long int __syscall_arg_t;
 	: "=r" (__v0), "=r" (__a3)					\
 	: input								\
 	: __SYSCALL_CLOBBERS);						\
-	err = __a3;							\
-	_sys_result = __v0;						\
+	_sys_result = __a3 != 0 ? -__v0 : __v0;				\
 	}								\
 	_sys_result;							\
 })
@@ -157,8 +157,7 @@ typedef long int __syscall_arg_t;
 	: "=r" (__v0), "=r" (__a3)					\
 	: input, "r" (__a0)						\
 	: __SYSCALL_CLOBBERS);						\
-	err = __a3;							\
-	_sys_result = __v0;						\
+	_sys_result = __a3 != 0 ? -__v0 : __v0;				\
 	}								\
 	_sys_result;							\
 })
@@ -182,8 +181,7 @@ typedef long int __syscall_arg_t;
 	: "=r" (__v0), "=r" (__a3)					\
 	: input, "r" (__a0), "r" (__a1)					\
 	: __SYSCALL_CLOBBERS);						\
-	err = __a3;							\
-	_sys_result = __v0;						\
+	_sys_result = __a3 != 0 ? -__v0 : __v0;				\
 	}								\
 	_sys_result;							\
 })
@@ -209,8 +207,7 @@ typedef long int __syscall_arg_t;
 	: "=r" (__v0), "=r" (__a3)					\
 	: input, "r" (__a0), "r" (__a1), "r" (__a2)			\
 	: __SYSCALL_CLOBBERS);						\
-	err = __a3;							\
-	_sys_result = __v0;						\
+	_sys_result = __a3 != 0 ? -__v0 : __v0;				\
 	}								\
 	_sys_result;							\
 })
@@ -236,8 +233,7 @@ typedef long int __syscall_arg_t;
 	: "=r" (__v0), "+r" (__a3)					\
 	: input, "r" (__a0), "r" (__a1), "r" (__a2)			\
 	: __SYSCALL_CLOBBERS);						\
-	err = __a3;							\
-	_sys_result = __v0;						\
+	_sys_result = __a3 != 0 ? -__v0 : __v0;				\
 	}								\
 	_sys_result;							\
 })
@@ -264,8 +260,7 @@ typedef long int __syscall_arg_t;
 	: "=r" (__v0), "+r" (__a3)					\
 	: input, "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a4)		\
 	: __SYSCALL_CLOBBERS);						\
-	err = __a3;							\
-	_sys_result = __v0;						\
+	_sys_result = __a3 != 0 ? -__v0 : __v0;				\
 	}								\
 	_sys_result;							\
 })
@@ -294,8 +289,7 @@ typedef long int __syscall_arg_t;
 	: input, "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a4),	\
 	  "r" (__a5)							\
 	: __SYSCALL_CLOBBERS);						\
-	err = __a3;							\
-	_sys_result = __v0;						\
+	_sys_result = __a3 != 0 ? -__v0 : __v0;				\
 	}								\
 	_sys_result;							\
 })
diff --git a/sysdeps/unix/sysv/linux/mips/sysdep.h b/sysdeps/unix/sysv/linux/mips/sysdep.h
index cdfc0b1b58..877768a249 100644
--- a/sysdeps/unix/sysv/linux/mips/sysdep.h
+++ b/sysdeps/unix/sysv/linux/mips/sysdep.h
@@ -28,19 +28,3 @@
 #endif
 #define HAVE_GETTIMEOFDAY_VSYSCALL      "__vdso_gettimeofday"
 #define HAVE_CLOCK_GETRES_VSYSCALL      "__vdso_clock_getres"
-
-#ifndef __ASSEMBLER__
-
-/* Standard MIPS syscalls have an error flag, and return a positive errno
-   when the error flag is set. Emulate this behaviour for vsyscalls so that
-   the INTERNAL_SYSCALL_{ERROR_P,ERRNO} macros work correctly.  */
-#define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...)		\
-  ({									\
-    long _ret = funcptr (args);						\
-    err = ((unsigned long) (_ret) >= (unsigned long) -4095L);		\
-    if (err)								\
-      _ret = -_ret;							\
-    _ret;								\
-  })
-
-#endif /* __ASSEMBLER__  */
-- 
2.17.1


  parent reply	other threads:[~2020-02-10 19:21 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-10 19:20 [PATCH 01/15] powerpc: Consolidate Linux syscall definition Adhemerval Zanella
2020-02-10 19:20 ` [PATCH 02/15] powerpc: Use Linux kABI for syscall return Adhemerval Zanella
2020-02-11 11:18   ` Florian Weimer
2020-02-11 12:14     ` Adhemerval Zanella
2020-02-11 12:31       ` Florian Weimer
2020-02-11 13:31         ` Adhemerval Zanella
2020-02-11 19:45           ` Florian Weimer
2020-02-11 19:45   ` Florian Weimer
2020-02-12 13:24     ` Adhemerval Zanella
2020-02-10 19:20 ` [PATCH 03/15] sparc: " Adhemerval Zanella
2020-02-11 11:15   ` Florian Weimer
2020-02-11 18:55     ` Adhemerval Zanella
2020-02-11 19:24       ` Florian Weimer
2020-02-11 20:29         ` Adhemerval Zanella
2020-02-11 21:15           ` Florian Weimer
2020-02-12 12:35             ` Adhemerval Zanella
2020-02-12 12:38               ` Florian Weimer
2020-02-12 12:56                 ` Adhemerval Zanella
2020-02-10 19:20 ` [PATCH 04/15] alpha: Refactor syscall and " Adhemerval Zanella
2020-02-10 19:20 ` [PATCH 05/15] ia64: " Adhemerval Zanella
2020-02-10 19:20 ` [PATCH 06/15] mips64: Consolidate Linux sysdep.h Adhemerval Zanella
2020-02-10 22:48   ` Joseph Myers
2020-02-11 19:05     ` Adhemerval Zanella
2020-02-10 19:20 ` Adhemerval Zanella [this message]
2020-02-10 19:20 ` [PATCH 08/15] nios2: Use Linux kABI for syscall return Adhemerval Zanella
2020-02-11 11:20   ` Florian Weimer
2020-02-11 19:09     ` Adhemerval Zanella
2020-02-11 11:50   ` Andreas Schwab
2020-02-19 21:40   ` Vineet Gupta
2020-02-20 13:14     ` Adhemerval Zanella
2020-02-20 20:39       ` Vineet Gupta
2020-02-20 21:04         ` Vineet Gupta
2020-02-27 17:49           ` Adhemerval Zanella
2020-02-10 19:20 ` [PATCH 09/15] microblaze: Avoid clobbering register parameters in syscall Adhemerval Zanella
2020-02-11 11:21   ` Florian Weimer
2020-02-11 19:10     ` Adhemerval Zanella
2020-02-10 19:20 ` [PATCH 10/15] riscv: " Adhemerval Zanella
2020-02-10 19:51   ` DJ Delorie
2020-02-10 21:27     ` Palmer Dabbelt
2020-02-10 21:55       ` Adhemerval Zanella
2020-02-10 19:20 ` [PATCH 11/15] s390: Consolidate Linux syscall definition Adhemerval Zanella
2020-02-10 19:20 ` [PATCH 12/15] sparc: Avoid clobbering register parameters in syscall Adhemerval Zanella
2020-02-11 11:22   ` Florian Weimer
2020-02-11 19:17     ` Adhemerval Zanella
2020-02-10 19:20 ` [PATCH 13/15] linux: Consolidate INLINE_SYSCALL Adhemerval Zanella
2020-02-11 12:03   ` Florian Weimer
2020-02-11 20:53     ` Adhemerval Zanella
2020-02-11 21:00       ` Florian Weimer
2020-02-10 19:20 ` [PATCH 14/15] nptl: Remove ununsed pthread-errnos.h rule Adhemerval Zanella
2020-02-11 11:23   ` Florian Weimer
2020-02-11 11:51     ` Florian Weimer
2020-02-11 21:01       ` Adhemerval Zanella
2020-02-10 19:20 ` [PATCH 15/15] linux: Remove INTERNAL_SYSCALL_DECL Adhemerval Zanella
2020-02-11 12:34   ` Florian Weimer
2020-02-11 12:36   ` Florian Weimer
2020-02-11 20:57     ` Adhemerval Zanella
2020-02-11 12:48   ` Florian Weimer
2020-02-11 20:55     ` Adhemerval Zanella
2020-02-15  7:51   ` Andreas Schwab
2020-02-15  9:32     ` [PATCH] arm: fix use of INTERNAL_SYSCALL_CALL Andreas Schwab
2020-02-15  9:55       ` Florian Weimer
2020-02-11 19:43 ` [PATCH 01/15] powerpc: Consolidate Linux syscall definition Florian Weimer
2020-02-12 13:19   ` Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200210192038.23588-7-adhemerval.zanella@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).