All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhangjin Wu <falcon@tinylab.org>
To: thomas@t-8ch.de, w@1wt.eu
Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org,
	"Thomas Weißschuh" <linux@weissschuh.net>
Subject: [PATCH v2 1/4] tools/nolibc: sys.h: add __syscall() and __sysret() helpers
Date: Tue,  6 Jun 2023 16:09:51 +0800	[thread overview]
Message-ID: <a42fb9e1bbe0daf7d8a48ea8f44135ef851030d7.1686036862.git.falcon@tinylab.org> (raw)
In-Reply-To: <cover.1686036862.git.falcon@tinylab.org>

most of the library routines share the same code model, let's add two
helpers to simplify the coding and shrink the code lines too.

One added for syscall return, one added for syscall call.

Thomas suggested to use inline function instead of macro for __sysret(),
and he also helped to simplify the __syscall() a lot.

Willy suggested to make __sysret() be always inline.

Suggested-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/linux-riscv/ZH1+hkhiA2+ItSvX@1wt.eu/
Suggested-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/linux-riscv/ea4e7442-7223-4211-ba29-70821e907888@t-8ch.de/
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
 tools/include/nolibc/sys.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 5464f93e863e..c12c14db056e 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -28,6 +28,18 @@
 #include "errno.h"
 #include "types.h"
 
+/* Syscall return helper, set errno as -ret when ret < 0 */
+static inline __attribute__((always_inline)) long __sysret(long ret)
+{
+	if (ret < 0) {
+		SET_ERRNO(-ret);
+		ret = -1;
+	}
+	return ret;
+}
+
+/* Syscall call helper, use syscall name instead of syscall number */
+#define __syscall(name, ...) __sysret(sys_##name(__VA_ARGS__))
 
 /* 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


WARNING: multiple messages have this Message-ID (diff)
From: Zhangjin Wu <falcon@tinylab.org>
To: thomas@t-8ch.de, w@1wt.eu
Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org,
	"Thomas Weißschuh" <linux@weissschuh.net>
Subject: [PATCH v2 1/4] tools/nolibc: sys.h: add __syscall() and __sysret() helpers
Date: Tue,  6 Jun 2023 16:09:51 +0800	[thread overview]
Message-ID: <a42fb9e1bbe0daf7d8a48ea8f44135ef851030d7.1686036862.git.falcon@tinylab.org> (raw)
In-Reply-To: <cover.1686036862.git.falcon@tinylab.org>

most of the library routines share the same code model, let's add two
helpers to simplify the coding and shrink the code lines too.

One added for syscall return, one added for syscall call.

Thomas suggested to use inline function instead of macro for __sysret(),
and he also helped to simplify the __syscall() a lot.

Willy suggested to make __sysret() be always inline.

Suggested-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/linux-riscv/ZH1+hkhiA2+ItSvX@1wt.eu/
Suggested-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/linux-riscv/ea4e7442-7223-4211-ba29-70821e907888@t-8ch.de/
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
 tools/include/nolibc/sys.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 5464f93e863e..c12c14db056e 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -28,6 +28,18 @@
 #include "errno.h"
 #include "types.h"
 
+/* Syscall return helper, set errno as -ret when ret < 0 */
+static inline __attribute__((always_inline)) long __sysret(long ret)
+{
+	if (ret < 0) {
+		SET_ERRNO(-ret);
+		ret = -1;
+	}
+	return ret;
+}
+
+/* Syscall call helper, use syscall name instead of syscall number */
+#define __syscall(name, ...) __sysret(sys_##name(__VA_ARGS__))
 
 /* 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


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2023-06-06  8:10 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-06  8:08 [PATCH v2 0/4] tools/nolibc: add two new syscall helpers Zhangjin Wu
2023-06-06  8:08 ` Zhangjin Wu
2023-06-06  8:09 ` Zhangjin Wu [this message]
2023-06-06  8:09   ` [PATCH v2 1/4] tools/nolibc: sys.h: add __syscall() and __sysret() helpers Zhangjin Wu
2023-06-06 10:33   ` Zhangjin Wu
2023-06-06 10:33     ` Zhangjin Wu
2023-06-08 14:35   ` David Laight
2023-06-08 14:35     ` David Laight
2023-06-08 16:06     ` Thomas Weißschuh
2023-06-08 16:06       ` Thomas Weißschuh
2023-06-09  4:42       ` Zhangjin Wu
2023-06-09  4:42         ` Zhangjin Wu
2023-06-09  9:15         ` David Laight
2023-06-09  9:15           ` David Laight
2023-06-06  8:11 ` [PATCH v2 2/4] tools/nolibc: unistd.h: apply __sysret() helper Zhangjin Wu
2023-06-06  8:11   ` Zhangjin Wu
2023-06-06  8:16 ` [PATCH v2 3/4] tools/nolibc: sys.h: " Zhangjin Wu
2023-06-06  8:16   ` Zhangjin Wu
2023-06-06  8:17 ` [PATCH v2 4/4] tools/nolibc: sys.h: apply __syscall() helper Zhangjin Wu
2023-06-06  8:17   ` Zhangjin Wu
2023-06-06 18:36   ` Thomas Weißschuh
2023-06-06 18:36     ` Thomas Weißschuh
2023-06-07  0:34     ` Zhangjin Wu
2023-06-07  0:34       ` Zhangjin Wu
2023-06-07  4:05       ` Willy Tarreau
2023-06-07  4:05         ` Willy Tarreau
2023-06-07  5:39         ` Zhangjin Wu
2023-06-07  5:39           ` Zhangjin Wu
2023-06-07  6:05           ` Thomas Weißschuh
2023-06-07  6:05             ` Thomas Weißschuh
2023-06-07  6:38             ` Zhangjin Wu
2023-06-07  6:38               ` Zhangjin Wu
2023-06-10 16:34           ` David Laight
2023-06-10 16:34             ` David Laight
2023-06-10 16:58             ` David Laight
2023-06-10 16:58               ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a42fb9e1bbe0daf7d8a48ea8f44135ef851030d7.1686036862.git.falcon@tinylab.org \
    --to=falcon@tinylab.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux@weissschuh.net \
    --cc=thomas@t-8ch.de \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.