[v2,03/23] linux: Add syscall_ret and use it on INLINE_SYSCALL

Message ID 20201113165837.121629-4-adhemerval.zanella@linaro.org
State Superseded
Headers
Series Simplify internal Linux syscall |

Commit Message

Adhemerval Zanella Nov. 13, 2020, 4:58 p.m. UTC
  It check the resulting value from INTERNAL_SYSCALL_CALL and sets the
errno accordingly.

Checked on x86_64-linux-gnu and i686-linux-gnu.
---
 sysdeps/unix/sysv/linux/fstatat.c     |  2 +-
 sysdeps/unix/sysv/linux/fstatat64.c   |  2 +-
 sysdeps/unix/sysv/linux/mq_unlink.c   | 11 +++--------
 sysdeps/unix/sysv/linux/sysdep-vdso.h | 26 +++++--------------------
 sysdeps/unix/sysv/linux/sysdep.h      | 28 +++++++++++++--------------
 5 files changed, 23 insertions(+), 46 deletions(-)
  

Patch

diff --git a/sysdeps/unix/sysv/linux/fstatat.c b/sysdeps/unix/sysv/linux/fstatat.c
index 87e5c0fc8f..5ba1b99372 100644
--- a/sysdeps/unix/sysv/linux/fstatat.c
+++ b/sysdeps/unix/sysv/linux/fstatat.c
@@ -80,7 +80,7 @@  __fstatat (int fd, const char *file, struct stat *buf, int flag)
 #  endif /* __nr_fstatat64  */
 # endif /* STAT_IS_KERNEL_STAT  */
 
-  return r == 0 ? 0 : INLINE_SYSCALL_ERROR_RETURN_VALUE (-r);
+  return syscall_ret (r);
 }
 
 weak_alias (__fstatat, fstatat)
diff --git a/sysdeps/unix/sysv/linux/fstatat64.c b/sysdeps/unix/sysv/linux/fstatat64.c
index 71216e43f5..a788940390 100644
--- a/sysdeps/unix/sysv/linux/fstatat64.c
+++ b/sysdeps/unix/sysv/linux/fstatat64.c
@@ -102,7 +102,7 @@  __fstatat64_time64 (int fd, const char *file, struct __stat64_t64 *buf,
 # endif
 #endif
 
-  return r == 0 ? 0 : INLINE_SYSCALL_ERROR_RETURN_VALUE (-r);
+  return syscall_ret (r);
 }
 #if __TIMESIZE != 64
 hidden_def (__fstatat64_time64)
diff --git a/sysdeps/unix/sysv/linux/mq_unlink.c b/sysdeps/unix/sysv/linux/mq_unlink.c
index bfba6ccfec..701bc86438 100644
--- a/sysdeps/unix/sysv/linux/mq_unlink.c
+++ b/sysdeps/unix/sysv/linux/mq_unlink.c
@@ -30,12 +30,7 @@  mq_unlink (const char *name)
 
   /* While unlink can return either EPERM or EACCES, mq_unlink should
      return just EACCES.  */
-  if (ret < 0)
-    {
-      if (ret == -EPERM)
-	ret = -EACCES;
-      return INLINE_SYSCALL_ERROR_RETURN_VALUE (-ret);
-    }
-
-  return ret;
+  if (ret == -EPERM)
+    ret = -EACCES;
+  return syscall_ret (ret);
 }
diff --git a/sysdeps/unix/sysv/linux/sysdep-vdso.h b/sysdeps/unix/sysv/linux/sysdep-vdso.h
index 17ed99d495..9f59198444 100644
--- a/sysdeps/unix/sysv/linux/sysdep-vdso.h
+++ b/sysdeps/unix/sysv/linux/sysdep-vdso.h
@@ -28,29 +28,13 @@ 
 
 #define INLINE_VSYSCALL(name, nr, args...)				      \
   ({									      \
-    __label__ out;							      \
-    __label__ iserr;							      \
-    long int sc_ret;							      \
-									      \
+    long int sc_ret = -ENOSYS;						      \
     __typeof (GLRO(dl_vdso_##name)) vdsop = GLRO(dl_vdso_##name);	      \
     if (vdsop != NULL)							      \
-      {									      \
-	sc_ret = INTERNAL_VSYSCALL_CALL (vdsop, nr, ##args);	      	      \
-	if (sc_ret == 0)						      \
-	  goto out;							      \
-	if (sc_ret != -ENOSYS)		      	      			      \
-	  goto iserr;							      \
-      }									      \
-									      \
-    sc_ret = INTERNAL_SYSCALL_CALL (name, ##args);		      	      \
-    if (sc_ret < 0)						      	      \
-      {									      \
-      iserr:								      \
-        __set_errno (-sc_ret);		      	      			      \
-        sc_ret = -1L;							      \
-      }									      \
-  out:									      \
-    sc_ret;								      \
+      sc_ret = INTERNAL_VSYSCALL_CALL (vdsop, nr, ##args);	      	      \
+    if (sc_ret == -ENOSYS)						      \
+      sc_ret = INTERNAL_SYSCALL_CALL (name, ##args);		      	      \
+    syscall_ret (sc_ret);						      \
   })
 
 #endif /* SYSDEP_VDSO_LINUX_H  */
diff --git a/sysdeps/unix/sysv/linux/sysdep.h b/sysdeps/unix/sysv/linux/sysdep.h
index d09e5ee532..e423b5e7b1 100644
--- a/sysdeps/unix/sysv/linux/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sysdep.h
@@ -23,26 +23,24 @@ 
 #include <endian.h>
 #include <errno.h>
 
-#ifndef SYSCALL_ERROR_LABEL
-# define SYSCALL_ERROR_LABEL(sc_err)					\
-  ({									\
-    __set_errno (sc_err);						\
-    -1L;								\
-  })
-#endif
-
 #ifndef __ASSEMBLER__
+static inline long int
+syscall_ret (unsigned long int val)
+{
+  if (val > -4096UL)
+    {
+      __set_errno (-val);
+      return -1;
+    }
+  return val;
+}
+
 /* Define a macro which expands into the inline wrapper code for a system
    call.  It sets the errno and returns -1 on a failure, or the syscall
    return value otherwise.  */
 #undef INLINE_SYSCALL
-#define INLINE_SYSCALL(name, nr, args...)				\
-  ({									\
-    long int sc_ret = INTERNAL_SYSCALL (name, nr, args);		\
-    __glibc_unlikely (sc_ret > -4096UL)					\
-    ? SYSCALL_ERROR_LABEL (-sc_ret)					\
-    : sc_ret;								\
-  })
+#define INLINE_SYSCALL(...)				\
+  syscall_ret (INTERNAL_SYSCALL (__VA_ARGS__))
 #endif
 
 /* Set error number and return -1.  A target may choose to return the