All of lore.kernel.org
 help / color / mirror / Atom feed
* Fwd: exit: Bug reporting
       [not found] <268231613796665@mail.yandex.ru>
@ 2021-02-20  9:30 ` Alejandro Colomar (man-pages)
  2021-02-20 10:05   ` Alejandro Colomar (man-pages)
  0 siblings, 1 reply; 6+ messages in thread
From: Alejandro Colomar (man-pages) @ 2021-02-20  9:30 UTC (permalink / raw)
  To: Dave Chupreev; +Cc: linux-man, Michael Kerrisk (man-pages)

I'll forward these 2 mails to the mailing list (and Michael (mtk) too; 
maybe he can correct me).

I'll answer in a reply to this email.


-------- Forwarded Message --------
Subject: 	Bug reporting
Date: 	Sat, 20 Feb 2021 08:09:50 +0300
From: 	Dave Chupreev <cdn.dev@yandex.ru>
To: 	alx.manpages@gmail.com <alx.manpages@gmail.com>



Hello, Alejandro.

Pages this <https://man7.org/linux/man-pages/dir_section_2.html> and 
this <https://man7.org/linux/man-pages/man2/syscalls.2.html> have 
different count of 'exit' calls, 4 and 2 respectively.

According to these pages 
(<https://github.com/torvalds/linux/blob/v5.11/arch/x86/entry/syscalls/syscall_32.tbl>, 
<https://github.com/torvalds/linux/blob/v5.11/arch/x86/entry/syscalls/syscall_64.tbl>), 
there are only 2 system calls containing 'exit' - *exit* and 
*exit_group*.  So it seems '_Exit' and '_exit' are redundant here 
<https://man7.org/linux/man-pages/dir_section_2.html>. Please correct me 
if I am wrong.

Thanks in advance!

-------- Forwarded Message --------
Subject: 	Bug reporting
Date: 	Sat, 20 Feb 2021 08:18:56 +0300
From: 	Dave Chupreev <cdn.dev@yandex.ru>
To: 	alx.manpages@gmail.com <alx.manpages@gmail.com>



Hello, Alejandro.

Entry exit(2) on this 
<https://man7.org/linux/man-pages/dir_section_2.html> page directs to 
page with _exit(2) in the header.
According to these pages 
(<https://github.com/torvalds/linux/blob/v5.11/arch/x86/entry/syscalls/syscall_32.tbl>, 
<https://github.com/torvalds/linux/blob/v5.11/arch/x86/entry/syscalls/syscall_64.tbl>), 
system call itself is called *exit* so it would be nice to fix the 
header to avoid the confusion. Please correct me if I am wrong.

Thanks in advance!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Fwd: exit: Bug reporting
  2021-02-20  9:30 ` Fwd: exit: Bug reporting Alejandro Colomar (man-pages)
@ 2021-02-20 10:05   ` Alejandro Colomar (man-pages)
  2021-02-20 14:34     ` Michael Kerrisk (man-pages)
  2021-08-30 11:39     ` Jakub Wilk
  0 siblings, 2 replies; 6+ messages in thread
From: Alejandro Colomar (man-pages) @ 2021-02-20 10:05 UTC (permalink / raw)
  To: Dave Chupreev; +Cc: linux-man, Michael Kerrisk (man-pages)

Hello Dave,

On 2/20/21 10:30 AM, Alejandro Colomar (man-pages) wrote:
> I'll forward these 2 mails to the mailing list (and Michael (mtk) too; 
> maybe he can correct me).
> 
> I'll answer in a reply to this email.
> 
> 
> -------- Forwarded Message --------
> Subject:     Bug reporting
> Date:     Sat, 20 Feb 2021 08:09:50 +0300
> From:     Dave Chupreev <cdn.dev@yandex.ru>
> To:     alx.manpages@gmail.com <alx.manpages@gmail.com>
> 
> 
> 
> Hello, Alejandro.
> 
> Pages this <https://man7.org/linux/man-pages/dir_section_2.html> and 
> this <https://man7.org/linux/man-pages/man2/syscalls.2.html> have 
> different count of 'exit' calls, 4 and 2 respectively.
> 
> According to these pages 
> (<https://github.com/torvalds/linux/blob/v5.11/arch/x86/entry/syscalls/syscall_32.tbl>, 
> <https://github.com/torvalds/linux/blob/v5.11/arch/x86/entry/syscalls/syscall_64.tbl>), 
> there are only 2 system calls containing 'exit' - *exit* and 
> *exit_group*.  So it seems '_Exit' and '_exit' are redundant here 
> <https://man7.org/linux/man-pages/dir_section_2.html>. Please correct me 
> if I am wrong.
> 
> Thanks in advance!
> 
> -------- Forwarded Message --------
> Subject:     Bug reporting
> Date:     Sat, 20 Feb 2021 08:18:56 +0300
> From:     Dave Chupreev <cdn.dev@yandex.ru>
> To:     alx.manpages@gmail.com <alx.manpages@gmail.com>
> 
> 
> 
> Hello, Alejandro.
> 
> Entry exit(2) on this 
> <https://man7.org/linux/man-pages/dir_section_2.html> page directs to 
> page with _exit(2) in the header.
> According to these pages 
> (<https://github.com/torvalds/linux/blob/v5.11/arch/x86/entry/syscalls/syscall_32.tbl>, 
> <https://github.com/torvalds/linux/blob/v5.11/arch/x86/entry/syscalls/syscall_64.tbl>), 
> system call itself is called *exit* so it would be nice to fix the 
> header to avoid the confusion. Please correct me if I am wrong.
> 
> Thanks in advance!

Okay I admit there's a bit of inconsistency in these functions.

exit_group(2) apart (which I think is quite clear).

___

So, the C standard specifies two exit() vairants:

exit() and _Exit()

and POSIX specifies 3 exit() variants:

_exit(), _Exit(), and exit()

_exit() and _Exit are identical, and the only reason for _Exit() to 
exist is history, and the fact that the C standard couldn't use _exit() 
as it only reserved names that started with an underscore and an 
uppercase letter, but not a lowercase one, for future revisions.  So 
when it adopted the posix _exit(), it had to rename it with an available 
name.

exit() does something more than _exit().

That's what the standards say.

___

Now let's discuss the implementation, which is where the confusion starts.

In the Linux kernel, there's only one system call, and it's called exit 
(its entry point is sys_exit(), and can be called using 
syscall(SYS_exit, ...) *but don't*), BUT it implements the functionality 
of _exit() (as the standards call it; see above).

That's the reason that the manual page _exit(2) has a link page called 
exit(2).

But syscalls can't be called directly (you have to use syscall(2)), so 
the C library (glibc) provides a wrapper function for the system call. 
And it does it by following the standards, so the wrapper function for 
the exit system call is _exit(), as POSIX calls it.  And lately, the 
second wrapper _Exit() was added, being an alias to _exit().

These correspond to the manual pages _exit(2) and _Exit(2).

And then glibc has to provide the exit() function, as the standards 
specify it (which remember, was different than the kernel exit system 
call), and the kernel doesn't provide a system call with such 
functionality, so glibc has to implement it, probably using _exit(), but 
with much more functionality.  This is not a system call, but a library 
function.

And that's why there's an exit(3) manual page.

___

To put some more context, FreeBSD (and I guess other BSDs as well) 
provides _exit() as a system call,
and then _Exit() and exit() are functions which I guess wrap around 
_exit(), _Exit() probably just calling _exit().

It provides the following manual pages:

_exit(2), _Exit(3), and exit(3)

___

BTW, even though you can use syscall(2), to call the system calls, don't 
take my words that you can do it as a recommendation to do it.  If 
possible, always use the C library (glibc) wrappers, which hide the 
complexity of calling some system calls (and sometimes even bugs) in 
their wrappers.

___

I hope I was clear and precise.  Michael, please correct me if I was 
wrong in some point.

Cheers,

Alex

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Fwd: exit: Bug reporting
  2021-02-20 10:05   ` Alejandro Colomar (man-pages)
@ 2021-02-20 14:34     ` Michael Kerrisk (man-pages)
       [not found]       ` <379711613836030@mail.yandex.ru>
  2021-08-30 11:39     ` Jakub Wilk
  1 sibling, 1 reply; 6+ messages in thread
From: Michael Kerrisk (man-pages) @ 2021-02-20 14:34 UTC (permalink / raw)
  To: Alejandro Colomar (man-pages), Dave Chupreev; +Cc: mtk.manpages, linux-man

> I hope I was clear and precise.  Michael, please correct me if I was 
> wrong in some point.

That all seems thorough and correct to me. The only thing
I'd is: this is how it has always been. Even before Linux, the
_exit(2)/exit(3) distinction existed, and the names are long
understood to refer respestively to the syscall vs the libc
API. So, while the syscall on Linux is SYS_exit, even in the
section 2 page, where the interfaces SYS_xxxx are documented as
xxxx(2), we retain the underscore for _exit(2). At least, that
is how I've always understood it.

Thanks,

Michael

-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: exit: Bug reporting
       [not found]       ` <379711613836030@mail.yandex.ru>
@ 2021-02-20 20:14         ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 6+ messages in thread
From: Michael Kerrisk (man-pages) @ 2021-02-20 20:14 UTC (permalink / raw)
  To: Dave Chupreev; +Cc: Alejandro Colomar (man-pages), linux-man

On Sat, 20 Feb 2021 at 17:18, Dave Chupreev <cdn.dev@yandex.ru> wrote:
>
> Thanks a lot for such explanations. Just to make sure.
>
> There are two system calls:
> exit and exit_group.
>
> POSIX standard specifies 4 entries for section 2:
> _exit(2) - this is direct calling of system call
> exit(2) - eventually it does the same but with additional actions like clearing stdio buffers etc.
> _Exit(2) - the same as a _exit(2). It is created only because name should be started with an underscore and an uppercase letter
> exit_group(2) - this is for exit_group sys call.
>
> C standard specifies these wrappers:
> exit(3) - as above
> _Exit(3) - as above
>
> And everyone understands that as it is and think about it in such way.
>
> Am I right?

Nearly. POSIX specifies _exit(), exit(), and _Exit(). exit_group() is
Linux-specific.

Thanks,

Michael



-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: exit: Bug reporting
  2021-02-20 10:05   ` Alejandro Colomar (man-pages)
  2021-02-20 14:34     ` Michael Kerrisk (man-pages)
@ 2021-08-30 11:39     ` Jakub Wilk
  2021-08-30 21:45       ` Michael Kerrisk (man-pages)
  1 sibling, 1 reply; 6+ messages in thread
From: Jakub Wilk @ 2021-08-30 11:39 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: Dave Chupreev, linux-man, Michael Kerrisk

* Alejandro Colomar <alx.manpages@gmail.com>, 2021-02-20, 11:05:
>In the Linux kernel, there's only one system call, and it's called 
>exit (its entry point is sys_exit(), and can be called using 
>syscall(SYS_exit, ...) *but don't*), BUT it implements the 
>functionality of _exit() (as the standards call it; see above).

To clarify, that's how it used to be, but since 2002ish there's also 
sys_exit_group, and glibc's _exit() uses that.

BTW, the exit_group.2 man page could use an update (possibly by merging 
it into exit.2): it says that the "system call is is equivalent to 
_exit(2) except that it terminates not only the calling thread, but all 
threads in the calling process’s thread group", which isn't helpful 
these days.

-- 
Jakub Wilk

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: exit: Bug reporting
  2021-08-30 11:39     ` Jakub Wilk
@ 2021-08-30 21:45       ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 6+ messages in thread
From: Michael Kerrisk (man-pages) @ 2021-08-30 21:45 UTC (permalink / raw)
  To: Jakub Wilk; +Cc: Alejandro Colomar, Dave Chupreev, linux-man

Hello Jakub,

On Mon, 30 Aug 2021 at 13:39, Jakub Wilk <jwilk@jwilk.net> wrote:
>
> * Alejandro Colomar <alx.manpages@gmail.com>, 2021-02-20, 11:05:
> >In the Linux kernel, there's only one system call, and it's called
> >exit (its entry point is sys_exit(), and can be called using
> >syscall(SYS_exit, ...) *but don't*), BUT it implements the
> >functionality of _exit() (as the standards call it; see above).
>
> To clarify, that's how it used to be, but since 2002ish there's also
> sys_exit_group, and glibc's _exit() uses that.
>
> BTW, the exit_group.2 man page could use an update (possibly by merging
> it into exit.2): it says that the "system call is is equivalent to
> _exit(2) except that it terminates not only the calling thread, but all
> threads in the calling process’s thread group", which isn't helpful
> these days.

Fair enough. I applied the patch below.

Cheers,

Michael

diff --git a/man2/exit_group.2 b/man2/exit_group.2
index fc8cbe9ef..a6a6d9b26 100644
--- a/man2/exit_group.2
+++ b/man2/exit_group.2
@@ -39,9 +39,7 @@ glibc provides no wrapper for
 necessitating the use of
 .BR syscall (2).
 .SH DESCRIPTION
-This system call is equivalent to
-.BR _exit (2)
-except that it terminates not only the calling thread, but all threads
+This system call terminates all threads
 in the calling process's thread group.
 .SH RETURN VALUE
 This system call does not return.


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-08-30 21:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <268231613796665@mail.yandex.ru>
2021-02-20  9:30 ` Fwd: exit: Bug reporting Alejandro Colomar (man-pages)
2021-02-20 10:05   ` Alejandro Colomar (man-pages)
2021-02-20 14:34     ` Michael Kerrisk (man-pages)
     [not found]       ` <379711613836030@mail.yandex.ru>
2021-02-20 20:14         ` Michael Kerrisk (man-pages)
2021-08-30 11:39     ` Jakub Wilk
2021-08-30 21:45       ` Michael Kerrisk (man-pages)

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.