The branch main has been updated by brooks:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=e7e964cb2ebde11593786a28cea0238d9a6e24c3

commit e7e964cb2ebde11593786a28cea0238d9a6e24c3
Author:     Brooks Davis <bro...@freebsd.org>
AuthorDate: 2025-08-08 09:30:16 +0000
Commit:     Brooks Davis <bro...@freebsd.org>
CommitDate: 2025-08-08 09:30:16 +0000

    syscalls: normalize _exit(2) declerations
    
    exit(3) is implemented by the runtime and performs a number of shutdown
    actions before ultimately calling _exit(2) to terminate the program.  We
    historically named the syscall table entry `exit` rather than `_exit`,
    but this requires special handling in libc/libsys to cause the `_exit`
    symbol to exist while implementing `exit` in libc.
    
    Declare the syscall as `_exit` and flow that through the system.
    
    Because syscall(SYS_exit, code) is fairly widely used, allow a
    configured extra line in syscall.h to define SYS_exit to SYS__exit.
    
    I've found no external uses of __sys_exit() so I've not bothered to
    create a compatability version of this private symbol.
    
    Reviewed by:    imp, kib, emaste
    Differential Revision:  https://reviews.freebsd.org/D51672
---
 lib/libsys/Makefile.sys                     | 1 -
 libexec/rtld-elf/rtld-libc/rtld_libc.h      | 6 +++---
 sys/kern/kern_exit.c                        | 2 +-
 sys/kern/syscalls.conf                      | 1 +
 sys/kern/syscalls.master                    | 2 +-
 sys/tools/syscalls/config.lua               | 1 +
 sys/tools/syscalls/scripts/syscall_h.lua    | 4 ++++
 sys/tools/syscalls/scripts/syscalls_map.lua | 2 +-
 8 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/lib/libsys/Makefile.sys b/lib/libsys/Makefile.sys
index 7871731dcdcd..bd65b58083c2 100644
--- a/lib/libsys/Makefile.sys
+++ b/lib/libsys/Makefile.sys
@@ -52,7 +52,6 @@ STATICOBJS+=  interposing_table.o
 PSEUDO= \
        __realpathat \
        clock_gettime \
-       exit \
        getlogin \
        gettimeofday \
        sched_getcpu
diff --git a/libexec/rtld-elf/rtld-libc/rtld_libc.h 
b/libexec/rtld-elf/rtld-libc/rtld_libc.h
index 35b4ef32cf87..33601d73cbf9 100644
--- a/libexec/rtld-elf/rtld-libc/rtld_libc.h
+++ b/libexec/rtld-elf/rtld-libc/rtld_libc.h
@@ -44,7 +44,7 @@
 #define __libc_interposing error, must not use this variable inside rtld
 
 int    __sys_close(int);
-void   __sys_exit(int) __dead2;
+void   __sys__exit(int) __dead2;
 int    __sys_fcntl(int, int, ...);
 int    __sys_fstat(int fd, struct stat *);
 int    __sys_fstatat(int, const char *, struct stat *, int);
@@ -70,8 +70,8 @@ int __getosreldate(void);
  */
 #define close(fd)      __sys_close(fd)
 #define _close(fd)     __sys_close(fd)
-#define exit(status)   __sys_exit(status)
-#define _exit(status)  __sys_exit(status)
+#define exit(status)   __sys__exit(status)
+#define _exit(status)  __sys__exit(status)
 #define fcntl(fd, cmd, arg)    __sys_fcntl(fd, cmd, arg)
 #define _fcntl(fd, cmd, arg)   __sys_fcntl(fd, cmd, arg)
 #define _fstat(fd, sb) __sys_fstat(fd, sb)
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 54e3044ab093..a32b5a1b3354 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -202,7 +202,7 @@ exit_onexit(struct proc *p)
  * exit -- death of process.
  */
 int
-sys_exit(struct thread *td, struct exit_args *uap)
+sys__exit(struct thread *td, struct _exit_args *uap)
 {
 
        exit1(td, uap->rval, 0);
diff --git a/sys/kern/syscalls.conf b/sys/kern/syscalls.conf
index a98d52659832..ae7bd1f87612 100644
--- a/sys/kern/syscalls.conf
+++ b/sys/kern/syscalls.conf
@@ -1,3 +1,4 @@
 libsysmap="../../lib/libsys/syscalls.map"
 libsys_h="../../lib/libsys/_libsys.h"
 sysmk="../sys/syscall.mk"
+syshdr_extra="#define  SYS_exit        SYS__exit"
diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master
index a8815afee866..29f9d9dae390 100644
--- a/sys/kern/syscalls.master
+++ b/sys/kern/syscalls.master
@@ -125,7 +125,7 @@
                );
        }
 1      AUE_EXIT        STD|CAPENABLED {
-               void exit(
+               void _exit(
                    int rval
                );
        }
diff --git a/sys/tools/syscalls/config.lua b/sys/tools/syscalls/config.lua
index fcf4c2217959..91a8a5af68dd 100644
--- a/sys/tools/syscalls/config.lua
+++ b/sys/tools/syscalls/config.lua
@@ -24,6 +24,7 @@ local util = require("tools.util")
 local config = {
        sysnames = "syscalls.c",
        syshdr = "../sys/syscall.h",
+       syshdr_extra = nil;
        sysmk = "/dev/null",
        syssw = "init_sysent.c",
        systrace = "systrace_args.c",
diff --git a/sys/tools/syscalls/scripts/syscall_h.lua 
b/sys/tools/syscalls/scripts/syscall_h.lua
index 5f8d8fb66889..d05a1799935b 100755
--- a/sys/tools/syscalls/scripts/syscall_h.lua
+++ b/sys/tools/syscalls/scripts/syscall_h.lua
@@ -38,6 +38,10 @@ function syscall_h.generate(tbl, config, fh)
        -- Write the generated preamble.
        gen:preamble("System call numbers.")
 
+       if config.syshdr_extra then
+               gen:write(string.format("%s\n\n", config.syshdr_extra))
+       end
+
        for _, v in pairs(s) do
                local c = v:compatLevel()
                if v.num > max then
diff --git a/sys/tools/syscalls/scripts/syscalls_map.lua 
b/sys/tools/syscalls/scripts/syscalls_map.lua
index 52c3b294e338..dfd61ae75bc0 100755
--- a/sys/tools/syscalls/scripts/syscalls_map.lua
+++ b/sys/tools/syscalls/scripts/syscalls_map.lua
@@ -39,7 +39,7 @@ function syscalls_map.generate(tbl, config, fh)
        for _, v in pairs(s) do
                gen:write(v.prolog)
                if v:native() and not v.type.NODEF and not v.type.NOLIB then
-                       if v.name ~= "exit" and v.name ~= "vfork" then
+                       if v.name ~= "_exit" and v.name ~= "vfork" then
                                gen:write(string.format("\t_%s;\n", v.name))
                        end
                        gen:write(string.format("\t__sys_%s;\n", v.name))

Reply via email to