* [PATCH 0/3] tools/nolibc: add the _syscall() macro
@ 2026-04-05 9:06 Thomas Weißschuh
2026-04-05 9:06 ` [PATCH 1/3] tools/nolibc: rename the internal macros used in syscall() Thomas Weißschuh
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2026-04-05 9:06 UTC (permalink / raw)
To: Willy Tarreau; +Cc: linux-kernel, Thomas Weißschuh
The standard syscall() function or macro uses the libc return value
convention. Errors returned from the kernel as negative values are
stored in errno and -1 is returned. Users which want to avoid using
errno don't have a way to call raw syscalls and check the returned
error.
Add a new macro _syscall() which works like the standard syscall()
but passes through the return value from the kernel unchanged.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Thomas Weißschuh (3):
tools/nolibc: rename the internal macros used in syscall()
tools/nolibc: move the call to __sysret() into syscall()
tools/nolibc: add the _syscall() macro
tools/include/nolibc/sys/syscall.h | 11 ++++++-----
tools/testing/selftests/nolibc/nolibc-test.c | 4 ++++
2 files changed, 10 insertions(+), 5 deletions(-)
---
base-commit: bda9721dd49b6a2a60feee606e22f50975063ab3
change-id: 20260405-nolibc-syscall-53e8b9b7f7cc
Best regards,
--
Thomas Weißschuh <linux@weissschuh.net>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] tools/nolibc: rename the internal macros used in syscall()
2026-04-05 9:06 [PATCH 0/3] tools/nolibc: add the _syscall() macro Thomas Weißschuh
@ 2026-04-05 9:06 ` Thomas Weißschuh
2026-04-05 9:06 ` [PATCH 2/3] tools/nolibc: move the call to __sysret() into syscall() Thomas Weißschuh
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2026-04-05 9:06 UTC (permalink / raw)
To: Willy Tarreau; +Cc: linux-kernel, Thomas Weißschuh
These macros are the internal implementation of syscall().
They can not be used by users. Align them with the standard naming
scheme for internal symbols.
The current name also prevents the addition of an application-usable
_syscall() symbol.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
tools/include/nolibc/sys/syscall.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/include/nolibc/sys/syscall.h b/tools/include/nolibc/sys/syscall.h
index 8cbcae4a32aa..b673f3d0c0f8 100644
--- a/tools/include/nolibc/sys/syscall.h
+++ b/tools/include/nolibc/sys/syscall.h
@@ -10,10 +10,10 @@
#ifndef _NOLIBC_SYS_SYSCALL_H
#define _NOLIBC_SYS_SYSCALL_H
-#define __syscall_narg(_0, _1, _2, _3, _4, _5, _6, N, ...) N
-#define _syscall_narg(...) __syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)
-#define _syscall(N, ...) __sysret(__nolibc_syscall##N(__VA_ARGS__))
-#define _syscall_n(N, ...) _syscall(N, __VA_ARGS__)
-#define syscall(...) _syscall_n(_syscall_narg(__VA_ARGS__), ##__VA_ARGS__)
+#define ___nolibc_syscall_narg(_0, _1, _2, _3, _4, _5, _6, N, ...) N
+#define __nolibc_syscall_narg(...) ___nolibc_syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)
+#define __nolibc_syscall(N, ...) __sysret(__nolibc_syscall##N(__VA_ARGS__))
+#define __nolibc_syscall_n(N, ...) __nolibc_syscall(N, __VA_ARGS__)
+#define syscall(...) __nolibc_syscall_n(__nolibc_syscall_narg(__VA_ARGS__), ##__VA_ARGS__)
#endif /* _NOLIBC_SYS_SYSCALL_H */
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] tools/nolibc: move the call to __sysret() into syscall()
2026-04-05 9:06 [PATCH 0/3] tools/nolibc: add the _syscall() macro Thomas Weißschuh
2026-04-05 9:06 ` [PATCH 1/3] tools/nolibc: rename the internal macros used in syscall() Thomas Weißschuh
@ 2026-04-05 9:06 ` Thomas Weißschuh
2026-04-05 9:06 ` [PATCH 3/3] tools/nolibc: add the _syscall() macro Thomas Weißschuh
2026-04-07 7:17 ` [PATCH 0/3] " Willy Tarreau
3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2026-04-05 9:06 UTC (permalink / raw)
To: Willy Tarreau; +Cc: linux-kernel, Thomas Weißschuh
__sysret() transforms the return value from the kernel into the libc
return value convention. There is no reason for it to be called in the
middle of the internals of the syscall() implementation macros.
Move the call up, directly into syscall(), to make the code simpler.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
tools/include/nolibc/sys/syscall.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/include/nolibc/sys/syscall.h b/tools/include/nolibc/sys/syscall.h
index b673f3d0c0f8..3f43fac3d7b8 100644
--- a/tools/include/nolibc/sys/syscall.h
+++ b/tools/include/nolibc/sys/syscall.h
@@ -12,8 +12,8 @@
#define ___nolibc_syscall_narg(_0, _1, _2, _3, _4, _5, _6, N, ...) N
#define __nolibc_syscall_narg(...) ___nolibc_syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)
-#define __nolibc_syscall(N, ...) __sysret(__nolibc_syscall##N(__VA_ARGS__))
+#define __nolibc_syscall(N, ...) __nolibc_syscall##N(__VA_ARGS__)
#define __nolibc_syscall_n(N, ...) __nolibc_syscall(N, __VA_ARGS__)
-#define syscall(...) __nolibc_syscall_n(__nolibc_syscall_narg(__VA_ARGS__), ##__VA_ARGS__)
+#define syscall(...) __sysret(__nolibc_syscall_n(__nolibc_syscall_narg(__VA_ARGS__), ##__VA_ARGS__))
#endif /* _NOLIBC_SYS_SYSCALL_H */
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] tools/nolibc: add the _syscall() macro
2026-04-05 9:06 [PATCH 0/3] tools/nolibc: add the _syscall() macro Thomas Weißschuh
2026-04-05 9:06 ` [PATCH 1/3] tools/nolibc: rename the internal macros used in syscall() Thomas Weißschuh
2026-04-05 9:06 ` [PATCH 2/3] tools/nolibc: move the call to __sysret() into syscall() Thomas Weißschuh
@ 2026-04-05 9:06 ` Thomas Weißschuh
2026-04-07 7:17 ` [PATCH 0/3] " Willy Tarreau
3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2026-04-05 9:06 UTC (permalink / raw)
To: Willy Tarreau; +Cc: linux-kernel, Thomas Weißschuh
The standard syscall() function or macro uses the libc return value
convention. Errors returned from the kernel as negative values are
stored in errno and -1 is returned. Users which want to avoid using
errno don't have a way to call raw syscalls and check the returned
error.
Add a new macro _syscall() which works like the standard syscall()
but passes through the return value from the kernel unchanged.
The naming scheme and return values match the named _sys_foo()
system call wrappers already part of nolibc.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
tools/include/nolibc/sys/syscall.h | 3 ++-
tools/testing/selftests/nolibc/nolibc-test.c | 4 ++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/tools/include/nolibc/sys/syscall.h b/tools/include/nolibc/sys/syscall.h
index 3f43fac3d7b8..7f06314fcf0d 100644
--- a/tools/include/nolibc/sys/syscall.h
+++ b/tools/include/nolibc/sys/syscall.h
@@ -14,6 +14,7 @@
#define __nolibc_syscall_narg(...) ___nolibc_syscall_narg(__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)
#define __nolibc_syscall(N, ...) __nolibc_syscall##N(__VA_ARGS__)
#define __nolibc_syscall_n(N, ...) __nolibc_syscall(N, __VA_ARGS__)
-#define syscall(...) __sysret(__nolibc_syscall_n(__nolibc_syscall_narg(__VA_ARGS__), ##__VA_ARGS__))
+#define _syscall(...) __nolibc_syscall_n(__nolibc_syscall_narg(__VA_ARGS__), ##__VA_ARGS__)
+#define syscall(...) __sysret(_syscall(__VA_ARGS__))
#endif /* _NOLIBC_SYS_SYSCALL_H */
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index dd10402267ee..4bcf46867603 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -95,6 +95,8 @@ static const int is_glibc =
/* readdir_r() is likely to be marked deprecated */
#undef readdir_r
#define readdir_r(dir, dirent, result) ((errno = EINVAL), -1)
+
+#define _syscall(...) 0
#endif
/* definition of a series of tests */
@@ -1507,6 +1509,8 @@ int run_syscall(int min, int max)
CASE_TEST(ptrace); EXPECT_SYSER(1, ptrace(PTRACE_CONT, getpid(), NULL, NULL), -1, ESRCH); break;
CASE_TEST(syscall_noargs); EXPECT_SYSEQ(1, syscall(__NR_getpid), getpid()); break;
CASE_TEST(syscall_args); EXPECT_SYSER(1, syscall(__NR_statx, 0, NULL, 0, 0, NULL), -1, EFAULT); break;
+ CASE_TEST(_syscall_noargs); EXPECT_SYSEQ(is_nolibc, _syscall(__NR_getpid), getpid()); break;
+ CASE_TEST(_syscall_args); EXPECT_SYSEQ(is_nolibc, _syscall(__NR_statx, 0, NULL, 0, 0, NULL), -EFAULT); break;
CASE_TEST(namespace); EXPECT_SYSZR(euid0 && proc, test_namespace()); break;
case __LINE__:
return ret; /* must be last */
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] tools/nolibc: add the _syscall() macro
2026-04-05 9:06 [PATCH 0/3] tools/nolibc: add the _syscall() macro Thomas Weißschuh
` (2 preceding siblings ...)
2026-04-05 9:06 ` [PATCH 3/3] tools/nolibc: add the _syscall() macro Thomas Weißschuh
@ 2026-04-07 7:17 ` Willy Tarreau
3 siblings, 0 replies; 5+ messages in thread
From: Willy Tarreau @ 2026-04-07 7:17 UTC (permalink / raw)
To: Thomas Weißschuh; +Cc: linux-kernel
Hi Thomas,
On Sun, Apr 05, 2026 at 11:06:22AM +0200, Thomas Weißschuh wrote:
> The standard syscall() function or macro uses the libc return value
> convention. Errors returned from the kernel as negative values are
> stored in errno and -1 is returned. Users which want to avoid using
^^^^^
s/which/who :-)
> errno don't have a way to call raw syscalls and check the returned
> error.
>
> Add a new macro _syscall() which works like the standard syscall()
> but passes through the return value from the kernel unchanged.
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Nice and clean! For the whole series:
Acked-by: Willy Tarreau <w@1wt.eu>
Thanks!
Willy
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-07 7:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-05 9:06 [PATCH 0/3] tools/nolibc: add the _syscall() macro Thomas Weißschuh
2026-04-05 9:06 ` [PATCH 1/3] tools/nolibc: rename the internal macros used in syscall() Thomas Weißschuh
2026-04-05 9:06 ` [PATCH 2/3] tools/nolibc: move the call to __sysret() into syscall() Thomas Weißschuh
2026-04-05 9:06 ` [PATCH 3/3] tools/nolibc: add the _syscall() macro Thomas Weißschuh
2026-04-07 7:17 ` [PATCH 0/3] " Willy Tarreau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®