summaryrefslogtreecommitdiff
path: root/tools/include
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2023-05-20 10:58:57 +0300
committerPaul E. McKenney <paulmck@kernel.org>2023-06-09 21:46:07 +0300
commit53fcfafa8c5c848d4ef1712053f6ea23b263a0de (patch)
treec5042791da95744d20aab9866faac3ba883e4bfe /tools/include
parentc22c7c81af4d061e484e0833fbc3418d0f3008d4 (diff)
downloadlinux-53fcfafa8c5c848d4ef1712053f6ea23b263a0de.tar.xz
tools/nolibc/unistd: add syscall()
syscall() is used by "normal" libcs to allow users to directly call syscalls. By having the same syntax inside nolibc users can more easily write code that works with different libcs. The macro logic is adapted from systemtaps STAP_PROBEV() macro that is released in the public domain / CC0. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Diffstat (limited to 'tools/include')
-rw-r--r--tools/include/nolibc/unistd.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/include/nolibc/unistd.h b/tools/include/nolibc/unistd.h
index ac7d53d986cd..0e832e10a0b2 100644
--- a/tools/include/nolibc/unistd.h
+++ b/tools/include/nolibc/unistd.h
@@ -56,6 +56,21 @@ int tcsetpgrp(int fd, pid_t pid)
return ioctl(fd, TIOCSPGRP, &pid);
}
+#define _syscall(N, ...) \
+({ \
+ long _ret = my_syscall##N(__VA_ARGS__); \
+ if (_ret < 0) { \
+ SET_ERRNO(-_ret); \
+ _ret = -1; \
+ } \
+ _ret; \
+})
+
+#define _syscall_narg(...) __syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)
+#define __syscall_narg(_0, _1, _2, _3, _4, _5, _6, N, ...) N
+#define _syscall_n(N, ...) _syscall(N, __VA_ARGS__)
+#define syscall(...) _syscall_n(_syscall_narg(__VA_ARGS__), ##__VA_ARGS__)
+
/* make sure to include all global symbols */
#include "nolibc.h"