Re: Fwd: exit: Bug reporting
From: Alejandro Colomar (man-pages) <hidden>
Date: 2021-02-20 10:06:18
Possibly related (same subject, not in this thread)
- 2021-02-20 · Re: exit: Bug reporting · Michael Kerrisk (man-pages) <hidden>
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 <redacted> To: alx.manpages@gmail.com <redacted> 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 <redacted> To: alx.manpages@gmail.com <redacted> 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/