[PATCH 04/23] linux: Add syscall_ret and use it on INLINE_SYSCALL
Adhemerval Zanella
adhemerval.zanella@linaro.org
Mon Nov 9 20:18:07 GMT 2020
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 | 4 +---
sysdeps/unix/sysv/linux/fstatat64.c | 4 +---
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, 22 insertions(+), 51 deletions(-)
diff --git a/sysdeps/unix/sysv/linux/fstatat.c b/sysdeps/unix/sysv/linux/fstatat.c
index a61fffa6e7..5ba1b99372 100644
--- a/sysdeps/unix/sysv/linux/fstatat.c
+++ b/sysdeps/unix/sysv/linux/fstatat.c
@@ -80,9 +80,7 @@ __fstatat (int fd, const char *file, struct stat *buf, int flag)
# endif /* __nr_fstatat64 */
# endif /* STAT_IS_KERNEL_STAT */
- return syscall_error (r)
- ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r)
- : 0;
+ 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 6e12cf2456..a788940390 100644
--- a/sysdeps/unix/sysv/linux/fstatat64.c
+++ b/sysdeps/unix/sysv/linux/fstatat64.c
@@ -102,9 +102,7 @@ __fstatat64_time64 (int fd, const char *file, struct __stat64_t64 *buf,
# endif
#endif
- return syscall_error (r)
- ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r)
- : 0;
+ 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 4964eb9028..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 (__glibc_unlikely (syscall_error (ret)))
- {
- 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 7c578808c6..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 (!syscall_error (sc_ret)) \
- goto out; \
- if (sc_ret != -ENOSYS) \
- goto iserr; \
- } \
- \
- sc_ret = INTERNAL_SYSCALL_CALL (name, ##args); \
- if (syscall_error (sc_ret)) \
- { \
- 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 9750c0418e..66bac892a5 100644
--- a/sysdeps/unix/sysv/linux/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sysdep.h
@@ -29,28 +29,24 @@ syscall_error (unsigned long int val)
{
return val > -4096UL;
}
-#endif
-#ifndef SYSCALL_ERROR_LABEL
-# define SYSCALL_ERROR_LABEL(sc_err) \
- ({ \
- __set_errno (sc_err); \
- -1L; \
- })
-#endif
+static inline long int
+syscall_ret (unsigned long int val)
+{
+ if (syscall_error (val))
+ {
+ __set_errno (-val);
+ return -1;
+ }
+ return val;
+}
-#ifndef __ASSEMBLER__
/* 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 (syscall_error (sc_ret)) \
- ? 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
--
2.25.1
More information about the Libc-alpha
mailing list