diff mbox series

[v5,07/14] tools/nolibc: arch-loongarch.h: shrink with SYSCALL_CLOBBERLIST

Message ID a906a8e5bb39d88fee89be8f2bca8bf62307d468.1687957589.git.falcon@tinylab.org (mailing list archive)
State New
Headers show
Series tools/nolibc: add a new syscall helper | expand

Commit Message

Zhangjin Wu June 28, 2023, 1:22 p.m. UTC
my_syscall<N> share a same long clobber list, define a macro for them.

Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
 tools/include/nolibc/arch-loongarch.h | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

Comments

Willy Tarreau July 2, 2023, 6:50 p.m. UTC | #1
On Wed, Jun 28, 2023 at 09:22:21PM +0800, Zhangjin Wu wrote:
> my_syscall<N> share a same long clobber list, define a macro for them.
> 
> Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
> ---
>  tools/include/nolibc/arch-loongarch.h | 25 +++++++++++--------------
>  1 file changed, 11 insertions(+), 14 deletions(-)
> 
> diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/arch-loongarch.h
> index 292d6a58dc87..fbb4844f7993 100644
> --- a/tools/include/nolibc/arch-loongarch.h
> +++ b/tools/include/nolibc/arch-loongarch.h
> @@ -23,6 +23,10 @@
>   */
>  #define __ARCH_WANT_SYS_PSELECT6
>  
> +#define SYSCALL_CLOBBERLIST			\
> +	"memory", "$t0", "$t1", "$t2", "$t3",	\
> +	"$t4", "$t5", "$t6", "$t7", "$t8"
> +

That's a good idea, but please be careful when adding macro definitions,
we're in code that is used by user space we have no control on, and we're
polluting the end user's macro namespace with plenty of names. While one
could argue that it's unlikely that some program already defines and uses
SYSCALL_CLOBBERLIST, actually with low-level code it's fairly possible.

Till now most of the definitions were for stuff that user-space really
needs (e.g. STDIN_FILENO, various integer limits). If we start to declare
random macros for internal use, at least we should probably prefix them
with _NOLIBC_ or something like this to avoid the risk of collision.

Willy
Zhangjin Wu July 3, 2023, 11:28 a.m. UTC | #2
> On Wed, Jun 28, 2023 at 09:22:21PM +0800, Zhangjin Wu wrote:
> > my_syscall<N> share a same long clobber list, define a macro for them.
> > 
> > Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
> > ---
> >  tools/include/nolibc/arch-loongarch.h | 25 +++++++++++--------------
> >  1 file changed, 11 insertions(+), 14 deletions(-)
> > 
> > diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/arch-loongarch.h
> > index 292d6a58dc87..fbb4844f7993 100644
> > --- a/tools/include/nolibc/arch-loongarch.h
> > +++ b/tools/include/nolibc/arch-loongarch.h
> > @@ -23,6 +23,10 @@
> >   */
> >  #define __ARCH_WANT_SYS_PSELECT6
> >  
> > +#define SYSCALL_CLOBBERLIST			\
> > +	"memory", "$t0", "$t1", "$t2", "$t3",	\
> > +	"$t4", "$t5", "$t6", "$t7", "$t8"
> > +
> 
> That's a good idea, but please be careful when adding macro definitions,
> we're in code that is used by user space we have no control on, and we're
> polluting the end user's macro namespace with plenty of names. While one
> could argue that it's unlikely that some program already defines and uses
> SYSCALL_CLOBBERLIST, actually with low-level code it's fairly possible.
> 
> Till now most of the definitions were for stuff that user-space really
> needs (e.g. STDIN_FILENO, various integer limits). If we start to declare
> random macros for internal use, at least we should probably prefix them
> with _NOLIBC_ or something like this to avoid the risk of collision.
>

Ok, _NOLIBC_ prefix will be applied, Thanks.

Best regards,
Zhangjin

> Willy
diff mbox series

Patch

diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/arch-loongarch.h
index 292d6a58dc87..fbb4844f7993 100644
--- a/tools/include/nolibc/arch-loongarch.h
+++ b/tools/include/nolibc/arch-loongarch.h
@@ -23,6 +23,10 @@ 
  */
 #define __ARCH_WANT_SYS_PSELECT6
 
+#define SYSCALL_CLOBBERLIST			\
+	"memory", "$t0", "$t1", "$t2", "$t3",	\
+	"$t4", "$t5", "$t6", "$t7", "$t8"
+
 #define my_syscall0(num)							\
 ({										\
 	register long _num __asm__ ("a7") = (num);				\
@@ -32,8 +36,7 @@ 
 		"syscall 0\n"							\
 		: "=r"(_arg1)							\
 		: "r"(_num)							\
-		: "memory", "$t0", "$t1", "$t2", "$t3",				\
-		  "$t4", "$t5", "$t6", "$t7", "$t8"				\
+		: SYSCALL_CLOBBERLIST						\
 	);									\
 	_arg1;									\
 })
@@ -47,8 +50,7 @@ 
 		"syscall 0\n"							\
 		: "+r"(_arg1)							\
 		: "r"(_num)							\
-		: "memory", "$t0", "$t1", "$t2", "$t3",				\
-		  "$t4", "$t5", "$t6", "$t7", "$t8"				\
+		: SYSCALL_CLOBBERLIST						\
 	);									\
 	_arg1;									\
 })
@@ -64,8 +66,7 @@ 
 		: "+r"(_arg1)							\
 		: "r"(_arg2),							\
 		  "r"(_num)							\
-		: "memory", "$t0", "$t1", "$t2", "$t3",				\
-		  "$t4", "$t5", "$t6", "$t7", "$t8"				\
+		: SYSCALL_CLOBBERLIST						\
 	);									\
 	_arg1;									\
 })
@@ -82,8 +83,7 @@ 
 		: "+r"(_arg1)							\
 		: "r"(_arg2), "r"(_arg3),					\
 		  "r"(_num)							\
-		: "memory", "$t0", "$t1", "$t2", "$t3",				\
-		  "$t4", "$t5", "$t6", "$t7", "$t8"				\
+		: SYSCALL_CLOBBERLIST						\
 	);									\
 	_arg1;									\
 })
@@ -101,8 +101,7 @@ 
 		: "+r"(_arg1)							\
 		: "r"(_arg2), "r"(_arg3), "r"(_arg4),				\
 		  "r"(_num)							\
-		: "memory", "$t0", "$t1", "$t2", "$t3",				\
-		  "$t4", "$t5", "$t6", "$t7", "$t8"				\
+		: SYSCALL_CLOBBERLIST						\
 	);									\
 	_arg1;									\
 })
@@ -121,8 +120,7 @@ 
 		: "+r"(_arg1)							\
 		: "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5),		\
 		  "r"(_num)							\
-		: "memory", "$t0", "$t1", "$t2", "$t3",				\
-		  "$t4", "$t5", "$t6", "$t7", "$t8"				\
+		: SYSCALL_CLOBBERLIST						\
 	);									\
 	_arg1;									\
 })
@@ -142,8 +140,7 @@ 
 		: "+r"(_arg1)							\
 		: "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), "r"(_arg6),	\
 		  "r"(_num)							\
-		: "memory", "$t0", "$t1", "$t2", "$t3",				\
-		  "$t4", "$t5", "$t6", "$t7", "$t8"				\
+		: SYSCALL_CLOBBERLIST						\
 	);									\
 	_arg1;									\
 })