All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhangjin Wu <falcon@tinylab.org>
To: w@1wt.eu
Cc: falcon@tinylab.org, david.laight@aculab.com, arnd@arndb.de,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	tanyuan@tinylab.org, thomas@t-8ch.de
Subject: [PATCH v6 1/2] tools/nolibc: let sys_brk, sys_mmap and sys_mmap2 return long
Date: Sat, 12 Aug 2023 05:50:45 +0800	[thread overview]
Message-ID: <82b584cbda5cee8d5318986644a2a64ba749a098.1691788036.git.falcon@tinylab.org> (raw)
In-Reply-To: <cover.1691788036.git.falcon@tinylab.org>

Firstly, since the sys_* functions are internally used by our library
routines, it is ok to let them preserve the 'long' return type of
my_syscall<N> macros, that means not necessary to return pointer like
their library routines do.

Secondly, in order to avoid the size inflating issues introduced by the
sign extension, it is better to let __sysret() only accept integer input
types, to do so, we must let all of the sys_* functions not return
pointers.

There are only three sys_* functions which return pointer, let's make
them return 'long' instead of pointer.

Link: https://lore.kernel.org/lkml/20230809221743.83107-1-falcon@tinylab.org/
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
 tools/include/nolibc/arch-s390.h |  4 ++--
 tools/include/nolibc/sys.h       | 16 ++++++++--------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/tools/include/nolibc/arch-s390.h b/tools/include/nolibc/arch-s390.h
index 5d60fd43f883..6396c2a6bc3a 100644
--- a/tools/include/nolibc/arch-s390.h
+++ b/tools/include/nolibc/arch-s390.h
@@ -160,7 +160,7 @@ struct s390_mmap_arg_struct {
 };
 
 static __attribute__((unused))
-void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
+long sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
 	       off_t offset)
 {
 	struct s390_mmap_arg_struct args = {
@@ -172,7 +172,7 @@ void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
 		.offset = (unsigned long)offset
 	};
 
-	return (void *)my_syscall1(__NR_mmap, &args);
+	return my_syscall1(__NR_mmap, &args);
 }
 #define sys_mmap sys_mmap
 
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 833d6c5e86dc..a28e7fbff448 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -74,9 +74,9 @@ long __sysret(unsigned long ret)
  */
 
 static __attribute__((unused))
-void *sys_brk(void *addr)
+long sys_brk(void *addr)
 {
-	return (void *)my_syscall1(__NR_brk, addr);
+	return my_syscall1(__NR_brk, addr);
 }
 
 static __attribute__((unused))
@@ -89,12 +89,12 @@ static __attribute__((unused))
 void *sbrk(intptr_t inc)
 {
 	/* first call to find current end */
-	void *ret = sys_brk(0);
+	void *ret = (void *)sys_brk(0);
 
-	if (ret && sys_brk(ret + inc) == ret + inc)
+	if (ret && (void *)sys_brk(ret + inc) == ret + inc)
 		return ret + inc;
 
-	return (void *)__sysret(-ENOMEM);
+	return (void *)__sysret((long)-ENOMEM);
 }
 
 
@@ -658,7 +658,7 @@ int mknod(const char *path, mode_t mode, dev_t dev)
 
 #ifndef sys_mmap
 static __attribute__((unused))
-void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
+long sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
 	       off_t offset)
 {
 	int n;
@@ -670,7 +670,7 @@ void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
 	n = __NR_mmap;
 #endif
 
-	return (void *)my_syscall6(n, addr, length, prot, flags, fd, offset);
+	return my_syscall6(n, addr, length, prot, flags, fd, offset);
 }
 #endif
 
@@ -682,7 +682,7 @@ void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
 static __attribute__((unused))
 void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
 {
-	return (void *)__sysret((unsigned long)sys_mmap(addr, length, prot, flags, fd, offset));
+	return (void *)__sysret(sys_mmap(addr, length, prot, flags, fd, offset));
 }
 
 static __attribute__((unused))
-- 
2.25.1


  reply	other threads:[~2023-08-11 21:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-11 21:49 [PATCH v6 0/2] tools/nolibc: fix up size inflat regression Zhangjin Wu
2023-08-11 21:50 ` Zhangjin Wu [this message]
2023-08-11 21:51 ` [PATCH v6 2/2] tools/nolibc: fix up size inflate regression Zhangjin Wu
2023-08-13  9:00   ` Willy Tarreau
2023-08-13 13:39     ` Zhangjin Wu
2023-08-14  7:25       ` Willy Tarreau
2023-08-15 12:17       ` Willy Tarreau
2023-08-15 16:34         ` Zhangjin Wu
2023-08-13  9:08 ` [PATCH v6 0/2] tools/nolibc: fix up size inflat regression Willy Tarreau
2023-08-13 13:56   ` Zhangjin Wu

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=82b584cbda5cee8d5318986644a2a64ba749a098.1691788036.git.falcon@tinylab.org \
    --to=falcon@tinylab.org \
    --cc=arnd@arndb.de \
    --cc=david.laight@aculab.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=tanyuan@tinylab.org \
    --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.