From: "Thomas Weißschuh" <thomas@t-8ch.de>
To: Yuan Tan <tanyuan@tinylab.org>
Cc: w@1wt.eu, falcon@tinylab.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v2 1/2] tools/nolibc: add pipe() and pipe2() support
Date: Mon, 31 Jul 2023 08:07:44 +0200 [thread overview]
Message-ID: <f5bcb0b3-7165-4e06-a5a5-9535d5ce3c4e@t-8ch.de> (raw)
In-Reply-To: <23019c9ad3a63d7026a60df8bc41934c3e74e564.1690733545.git.tanyuan@tinylab.org>
On 2023-07-31 13:50:45+0800, Yuan Tan wrote:
> According to manual page [1], posix spec [2] and source code like
> arch/mips/kernel/syscall.c, for historic reasons, the sys_pipe() syscall
> on some architectures has an unusual calling convention. It returns
> results in two registers which means there is no need for it to do
> verify the validity of a userspace pointer argument. Historically that
> used to be expensive in Linux. These days the performance advantage is
> negligible.
>
> Nolibc doesn't support the unusual calling convention above, luckily
> Linux provides a generic sys_pipe2() with an additional flags argument
> from 2.6.27. If flags is 0, then pipe2() is the same as pipe(). So here
> we use sys_pipe2() to implement the pipe().
>
> pipe2() is also provided to allow users to use flags argument on demand.
>
> [1]: https://man7.org/linux/man-pages/man2/pipe.2.html
> [2]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/pipe.html
>
> Suggested-by: Zhangjin Wu <falcon@tinylab.org>
> Link: https://lore.kernel.org/all/20230729100401.GA4577@1wt.eu/
> Signed-off-by: Yuan Tan <tanyuan@tinylab.org>
> ---
> tools/include/nolibc/sys.h | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
> index 8bfe7db20b80..9fec09c22dbe 100644
> --- a/tools/include/nolibc/sys.h
> +++ b/tools/include/nolibc/sys.h
> @@ -752,6 +752,30 @@ int open(const char *path, int flags, ...)
> }
>
>
> +/*
> + * int pipe2(int pipefd[2], int flags);
> + * int pipe(int pipefd[2]);
> + */
> +
> +static __attribute__((unused))
> +int sys_pipe2(int pipefd[2], int flags)
> +{
> + return my_syscall2(__NR_pipe, pipefd, flags);
> +}
Should be __NR_pipe2.
> +static __attribute__((unused))
> +int pipe2(int pipefd[2], int flags)
> +{
> + return __sysret(sys_pipe2(pipefd, flags));
> +}
> +
> +static __attribute__((unused))
> +int pipe(int pipefd[2])
> +{
> + pipe2(pipefd, 0);
> +}
> +
> +
> /*
> * int prctl(int option, unsigned long arg2, unsigned long arg3,
> * unsigned long arg4, unsigned long arg5);
> --
> 2.34.1
>
next prev parent reply other threads:[~2023-07-31 6:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-31 5:50 [PATCH v2 0/2] tools/nolibc: add pipe(), pipe2() and their testcase Yuan Tan
2023-07-31 5:50 ` [PATCH v2 1/2] tools/nolibc: add pipe() and pipe2() support Yuan Tan
2023-07-31 6:07 ` Thomas Weißschuh [this message]
2023-07-31 6:13 ` Thomas Weißschuh
2023-07-31 5:51 ` [PATCH v2 2/2] selftests/nolibc: add testcase for pipe Yuan Tan
2023-07-31 6:10 ` Thomas Weißschuh
2023-07-31 12:35 ` Yuan Tan
2023-07-31 15:41 ` Thomas Weißschuh
2023-07-31 18:01 ` Yuan Tan
2023-07-31 18:28 ` Thomas Weißschuh
2023-08-01 6:51 ` Yuan Tan
2023-08-01 7:20 ` Thomas Weißschuh
2023-08-01 12:23 ` Yuan Tan
2023-08-01 14:46 ` Thomas Weißschuh
2023-07-31 6:13 ` [PATCH v2 0/2] tools/nolibc: add pipe(), pipe2() and their testcase Thomas Weißschuh
2023-07-31 11:08 ` Yuan Tan
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=f5bcb0b3-7165-4e06-a5a5-9535d5ce3c4e@t-8ch.de \
--to=thomas@t-8ch.de \
--cc=falcon@tinylab.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=tanyuan@tinylab.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox