exit: Bug reporting
A message that is not in the archive (sent off-list or not yet received): [email protected]
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 <[email protected]>
To: [email protected] <[email protected]>
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 <[email protected]>
To: [email protected] <[email protected]>
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!
Hello Dave,
Quoted 29 lines · Alejandro Colomar (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 <[email protected]> To: [email protected] <[email protected]>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 <[email protected]> To: [email protected] <[email protected]>
Quoted 6 lines
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
Signature · 3 lines
Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/
Quoted 2 lines
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
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 12 lines · Dave Chupreev
Thanks a lot for such explanations. Just to make sure.
There are two system calls:
exit andexit_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 letterexit_group(2)- this is forexit_groupsys call.
Quoted 7 lines
C standard specifies these wrappers:
exit(3) - as above_Exit(3)- as aboveAnd 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
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
* Alejandro Colomar <[email protected]>, 2021-02-20, 11:05:
Quoted 1 line
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 usingsyscall(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.
Signature · 1 line
Jakub Wilk
Hello Jakub,
Quoted 7 lines · Jakub Wilk
* Alejandro Colomar <[email protected]>, 2021-02-20, 11:05:
Quoted 4 lines
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 usingsyscall(SYS_exit, ...)*but don't*), BUT it implements the functionality of_exit()(as the standards call it; see above).
Quoted 8 lines
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
man2/exit_group.2 +1 -3
@@ -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.
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/