linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Alejandro Colomar (man-pages)" <alx.manpages@gmail.com>
To: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
Cc: linux-man@vger.kernel.org, linux-kernel@vger.kernel.org,
	libc-alpha@sourceware.org, Florian Weimer <fweimer@redhat.com>
Subject: Re: [RFC] execve.2: SYNOPSIS: Document both glibc wrapper and kernel sycalls
Date: Thu, 18 Feb 2021 15:01:28 +0100	[thread overview]
Message-ID: <938df2c0-04b5-f6a4-79c3-b8fe09973828@gmail.com> (raw)
In-Reply-To: <1c7043ad-b834-5270-56fc-404d82d5a0a0@gmail.com>

Hi Micahel,

On 2/18/21 1:27 PM, Michael Kerrisk (man-pages) wrote:
> Hi Alex,
> 
> On 2/14/21 2:39 PM, Alejandro Colomar wrote:
>> Until now, the manual pages have (usually) documented only either
>> the glibc (or another library) wrapper for a syscall, or the raw
>> syscall (this only when there's not a wrapper).
>>
>> Let's document both prototypes, which many times are slightly
>> different.  This will solve a problem where documenting glibc
>> wrappers implied shadowing the documentation for the raw syscall.
>>
>> It will also be much clearer for the reader where the syscall
>> comes from (kernel? glibc? other?), by adding an explicit comment
>> at the beginning of the prototypes.  This removes the need of
>> scrolling down to NOTES to see that info.
>>
>> Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
>> ---
>>
>> Hi all,
>>
>> This is a prototype for doing some important changes to the SYNOPSIS
>> of the man-pages.
>>
>> The commit message above explains the idea quite well.  A few details
>> that couldn't be shown on this commit are:
>>
>> For cases where the wrapper is provided by a library other than glibc,
>> I'd simply change the comment.  For example, for move_pages(2),
>> it would say /* libnuma wrapper function: */.
>>
>> I think this would make the samll notes warning that there's no glibc
>> wrapper function deprecated (but we could keep them for some time and
>> decide that later).
>>
>> While changing this, I'd also make sure that the headers are correct,
>> and clearly differentiate which headers are needed for the raw syscall
>> and for the wrapper function.
>>
>> This change will probably take more than one release of the man-pages
>> to complete.
>>
>> Any thoughts?
> 
> My first impression is that I'm not keen on this. We'll add extra
> text to all Section 2 pages, and in many (most?) cases the info
> will be redundant (i.e., the wrapper and the syscall() notation
> will express the same info). In other cases, I suspect the info
> will be largely irrelevant to the user. To take an example: to
> whom will the difference that you document below for execve()
> matter, how will it matter, and does it matter enough that we
> headline the info in the pages? I'd want cogent answers to
> those questions before considering a wide-ranging change.

It will matter to:

1) Users of old systems where the glibc wrapper is not yet present.

3) Users of some unicorn Linux distributions that use a C library 
different than glibc and may not have wrappers for some syscalls that 
glibc provides.

2) Library (libc) developers.

Those won't have the glibc wrapper available for them, and will have to 
use syscall(2).  The kernel syscall info would be highly valuable for 
them.  However, the sum of them is probably not a big number of people.


> 
> There are indeed cases where the wrapper API differs in
> significant ways from the syscall API (and these differences
> are usually captured in the " C library/kernel differences"
> subsections, such as for pselect()/pselect6() in select(2)).
> But I imagine that that is the case in only a smallish
> minority of the pages.
> 
> And indeed there are a very few syscalls that have wrappers
> provided in another library. But it's a very small percentage
> I think, and best documented case by case in specific pages.
> The default presumption is that the wrapper is in the C library.

Agree.

> 
> There are other cases where I think it may be worthwhile
> considering the syscall() notation:
> 
> 1. Where the system call has no wrapper. In that case, we might
>     use the syscall() notation in the SYNOPISIS as both
>     (a) a clear indication that there is no wrapper and
>     (b) instructions to the reader about how to call the
>     system call using syscall().

Yes.

> 
> 2. In cases where there is a "significant" difference between
>     the wrapper and the system call. In this case, we might
>     also place the syscall() notation in the SYNOPSIS, or
>     (perhaps more likely) in the NOTES

Yes.

I think it would be equally good to have the kernel syscall prototype in 
"C library/kernel ABI differences" in those cases where there is a glibc 
wrapper (even if it's quite different).  It would be even better, as it 
would clearly mark the syscall(2) method as a second-class method, that 
should be avoided if possible.  And also wouldn't add lines to the SYNOPSIS.

However, we should probably have that subsection for all syscalls, 
including those where the prototype is very similar to the glibc one, to 
support those who need to use the kernel syscall, and provide them with 
the exact types that the kernel expects.(except for those unsupported by 
libraries, of course, which would have the syscall(SYS_xxx) prototype in 
the SYNOPSIS).

I'll prepare a new RFC with this, with 2 pages:  one with wrapper and 
one without wrapper.

Thanks,

Alex


See also:
<https://lwn.net/Articles/534682/>
<https://www.kernel.org/doc/man-pages/todo.html#migrate_to_kernel_source>


> 
> Thanks,
> 
> Michael
> 
>>
>> Thanks,
>>
>> Alex
>>
>> ---
>>   man2/execve.2 | 12 ++++++++++--
>>   1 file changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/man2/execve.2 b/man2/execve.2
>> index 639e3b4b9..87ff022ce 100644
>> --- a/man2/execve.2
>> +++ b/man2/execve.2
>> @@ -39,10 +39,18 @@
>>   execve \- execute program
>>   .SH SYNOPSIS
>>   .nf
>> +/* Glibc wrapper function: */
>>   .B #include <unistd.h>
>>   .PP
>> -.BI "int execve(const char *" pathname ", char *const " argv [],
>> -.BI "           char *const " envp []);
>> +.BI "int execve(const char *" pathname ",
>> +.BI "           char *const " argv "[], char *const " envp []);
>> +.PP
>> + /* Raw system call: */
>> +.B #include <sys/syscall.h>
>> +.B #include <unistd.h>
>> +.PP
>> +.BI "int syscall(SYS_execve, const char *" pathname ,
>> +.BI "           const char *const " argv "[], const char *const " envp []);
>>   .fi
>>   .SH DESCRIPTION
>>   .BR execve ()
>>
> 
> 

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

  reply	other threads:[~2021-02-18 16:50 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-14 13:39 [RFC] execve.2: SYNOPSIS: Document both glibc wrapper and kernel sycalls Alejandro Colomar
2021-02-18 12:27 ` Michael Kerrisk (man-pages)
2021-02-18 14:01   ` Alejandro Colomar (man-pages) [this message]
2021-02-18 15:13     ` [RFC v2] " Alejandro Colomar
2021-02-19 12:39       ` Michael Kerrisk (man-pages)
2021-02-19 12:56         ` Alejandro Colomar (man-pages)
2021-02-26 11:52           ` Alejandro Colomar (man-pages)
2021-03-13 19:25 ` [RFC v3 00/17] man2: Use syscall(SYS_...); for system calls without a wrapper Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 01/17] access.2: " Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 02/17] alloc_hugepages.2: " Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 03/17] arch_prctl.2: " Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 04/17] arch_prctl.2: SYNOPSIS: Remove unused includes Alejandro Colomar
2021-03-15 18:00   ` AW: " Walter Harms
2021-03-16 16:50     ` Alejandro Colomar (man-pages)
2021-03-13 19:25 ` [RFC v3 05/17] capget.2: Use syscall(SYS_...); for system calls without a wrapper Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 06/17] clone.2: " Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 07/17] delete_module.2: wfix Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 08/17] epoll_wait.2: Use syscall(SYS_...); for system calls without a wrapper Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 09/17] execveat.2: " Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 10/17] exit_group.2: " Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 11/17] futex.2: " Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 12/17] getdents.2: " Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 13/17] getunwind.2: " Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 14/17] get_robust_list.2: " Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 16/17] init_module.2: " Alejandro Colomar
2021-03-13 19:25 ` [RFC v3 17/17] ioprio_set.2: " Alejandro Colomar

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=938df2c0-04b5-f6a4-79c3-b8fe09973828@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).