[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <f549b27981484b429b7c7f98e212bf3c5561724f.1685856497.git.falcon@tinylab.org>
Date: Sun, 4 Jun 2023 13:34:29 +0800
From: Zhangjin Wu <falcon@...ylab.org>
To: w@....eu
Cc: falcon@...ylab.org, arnd@...db.de, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org, linux-riscv@...ts.infradead.org,
thomas@...ch.de
Subject: [PATCH 1/4] tools/nolibc: unistd.h: add __syscall() and __syscall_ret() helpers
most of the library routines share the same code model, let's add some
macros to simplify the coding and shrink the code lines too.
One added for syscall return, one added for syscall call, both of them
can get the typeof 'return value' automatically.
To get the return type of syscalls, __auto_type is better than typeof(),
but it is not supported by the old compilers (before 2013, see [1]), so,
use typeof() here.
[1]: https://gcc.gnu.org/legacy-ml/gcc-patches/2013-11/msg01378.html
Signed-off-by: Zhangjin Wu <falcon@...ylab.org>
---
tools/include/nolibc/sys.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 1d6f33f58629..937a8578e3d4 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -28,6 +28,21 @@
#include "errno.h"
#include "types.h"
+/* Syscall call and return helpers */
+#define __syscall_ret(ret) \
+({ \
+ if (ret < 0) { \
+ SET_ERRNO(-ret); \
+ ret = (typeof(ret))-1; \
+ } \
+ ret; \
+})
+
+#define __syscall(name, ...) \
+({ \
+ typeof(sys_##name(__VA_ARGS__)) ret = sys_##name(__VA_ARGS__); \
+ __syscall_ret(ret); \
+})
/* Functions in this file only describe syscalls. They're declared static so
* that the compiler usually decides to inline them while still being allowed
--
2.25.1
Powered by blists - more mailing lists