diff --git a/sys/amd64/amd64/elf_machdep.c b/sys/amd64/amd64/elf_machdep.c index a3fb1184bb0..445efa883fd 100644 --- a/sys/amd64/amd64/elf_machdep.c +++ b/sys/amd64/amd64/elf_machdep.c @@ -82,6 +82,8 @@ struct sysentvec elf64_freebsd_sysvec_la48 = { .sv_thread_detach = NULL, .sv_trap = NULL, .sv_stackgap = elf64_stackgap, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, }; struct sysentvec elf64_freebsd_sysvec_la57 = { @@ -117,6 +119,8 @@ struct sysentvec elf64_freebsd_sysvec_la57 = { .sv_thread_detach = NULL, .sv_trap = NULL, .sv_stackgap = elf64_stackgap, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, }; static void diff --git a/sys/arm/arm/elf_machdep.c b/sys/arm/arm/elf_machdep.c index d32dbb5baf9..6eaea9b92f2 100644 --- a/sys/arm/arm/elf_machdep.c +++ b/sys/arm/arm/elf_machdep.c @@ -97,6 +97,8 @@ struct sysentvec elf32_freebsd_sysvec = { .sv_trap = NULL, .sv_hwcap = &elf_hwcap, .sv_hwcap2 = &elf_hwcap2, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, }; INIT_SYSENTVEC(elf32_sysvec, &elf32_freebsd_sysvec); diff --git a/sys/arm64/arm64/elf32_machdep.c b/sys/arm64/arm64/elf32_machdep.c index 6c98f7c839c..48d6dc189e3 100644 --- a/sys/arm64/arm64/elf32_machdep.c +++ b/sys/arm64/arm64/elf32_machdep.c @@ -109,6 +109,8 @@ static struct sysentvec elf32_freebsd_sysvec = { .sv_schedtail = NULL, .sv_thread_detach = NULL, .sv_trap = NULL, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, }; INIT_SYSENTVEC(elf32_sysvec, &elf32_freebsd_sysvec); diff --git a/sys/arm64/arm64/elf_machdep.c b/sys/arm64/arm64/elf_machdep.c index cd12d40c37d..102097b2dbb 100644 --- a/sys/arm64/arm64/elf_machdep.c +++ b/sys/arm64/arm64/elf_machdep.c @@ -92,6 +92,8 @@ static struct sysentvec elf64_freebsd_sysvec = { .sv_trap = NULL, .sv_hwcap = &elf_hwcap, .sv_hwcap2 = &elf_hwcap2, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, }; INIT_SYSENTVEC(elf64_sysvec, &elf64_freebsd_sysvec); diff --git a/sys/compat/ia32/ia32_sysvec.c b/sys/compat/ia32/ia32_sysvec.c index f5a2c1200fc..3973811ab62 100644 --- a/sys/compat/ia32/ia32_sysvec.c +++ b/sys/compat/ia32/ia32_sysvec.c @@ -128,6 +128,8 @@ struct sysentvec ia32_freebsd_sysvec = { .sv_thread_detach = NULL, .sv_trap = NULL, .sv_stackgap = elf32_stackgap, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, }; INIT_SYSENTVEC(elf_ia32_sysvec, &ia32_freebsd_sysvec); diff --git a/sys/i386/i386/elf_machdep.c b/sys/i386/i386/elf_machdep.c index 0d870748967..ef808e65fd9 100644 --- a/sys/i386/i386/elf_machdep.c +++ b/sys/i386/i386/elf_machdep.c @@ -83,6 +83,8 @@ struct sysentvec elf32_freebsd_sysvec = { .sv_schedtail = NULL, .sv_thread_detach = NULL, .sv_trap = NULL, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, }; INIT_SYSENTVEC(elf32_sysvec, &elf32_freebsd_sysvec); diff --git a/sys/kern/imgact_aout.c b/sys/kern/imgact_aout.c index 3255ef169f7..9e7455e14e1 100644 --- a/sys/kern/imgact_aout.c +++ b/sys/kern/imgact_aout.c @@ -101,6 +101,8 @@ struct sysentvec aout_sysvec = { .sv_schedtail = NULL, .sv_thread_detach = NULL, .sv_trap = NULL, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, }; #elif defined(__amd64__) @@ -137,6 +139,8 @@ struct sysentvec aout_sysvec = { .sv_set_syscall_retval = ia32_set_syscall_retval, .sv_fetch_syscall_args = ia32_fetch_syscall_args, .sv_syscallnames = freebsd32_syscallnames, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, }; #else #error "Port me" diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index de1294ff695..491e5332c83 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1033,6 +1033,13 @@ exec_unmap_first_page(struct image_params *imgp) } } +void +exec_onexec_old(struct thread *td) +{ + sigfastblock_clear(td); + umtx_exec(td->td_proc); +} + /* * Destroy old address space, and allocate a new stack. * The new stack is only sgrowsiz large because it is grown @@ -1055,8 +1062,6 @@ exec_new_vmspace(struct image_params *imgp, struct sysentvec *sv) imgp->vmspace_destroyed = 1; imgp->sysent = sv; - sigfastblock_clear(td); - umtx_exec(p); if (p->p_sysent->sv_onexec_old != NULL) p->p_sysent->sv_onexec_old(td); itimers_exec(p); diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 515c2d4e639..bfd25366b49 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -195,6 +195,13 @@ proc_clear_orphan(struct proc *p) p->p_treeflag &= ~P_TREE_ORPHANED; } +void +exit_onexit(struct proc *p) +{ + MPASS(p->p_numthreads == 1); + umtx_thread_exit(FIRST_THREAD_IN_PROC(p)); +} + /* * exit -- death of process. */ @@ -370,7 +377,6 @@ exit1(struct thread *td, int rval, int signo) PROC_UNLOCK(p); - umtx_thread_exit(td); if (p->p_sysent->sv_onexit != NULL) p->p_sysent->sv_onexit(p); seltdfini(td); diff --git a/sys/mips/mips/elf_machdep.c b/sys/mips/mips/elf_machdep.c index 9e27e5e7f2a..8ac07a5b0ac 100644 --- a/sys/mips/mips/elf_machdep.c +++ b/sys/mips/mips/elf_machdep.c @@ -89,6 +89,8 @@ static struct sysentvec elf_freebsd_sysvec = { .sv_schedtail = NULL, .sv_thread_detach = NULL, .sv_trap = NULL, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, }; static __ElfN(Brandinfo) freebsd_brand_info = { diff --git a/sys/powerpc/powerpc/elf32_machdep.c b/sys/powerpc/powerpc/elf32_machdep.c index 04150f02bb9..e98b4c3f08c 100644 --- a/sys/powerpc/powerpc/elf32_machdep.c +++ b/sys/powerpc/powerpc/elf32_machdep.c @@ -131,6 +131,8 @@ struct sysentvec elf32_freebsd_sysvec = { .sv_trap = NULL, .sv_hwcap = &cpu_features, .sv_hwcap2 = &cpu_features2, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, }; INIT_SYSENTVEC(elf32_sysvec, &elf32_freebsd_sysvec); diff --git a/sys/powerpc/powerpc/elf64_machdep.c b/sys/powerpc/powerpc/elf64_machdep.c index 1bca857d9ca..37765381745 100644 --- a/sys/powerpc/powerpc/elf64_machdep.c +++ b/sys/powerpc/powerpc/elf64_machdep.c @@ -93,6 +93,8 @@ struct sysentvec elf64_freebsd_sysvec_v1 = { .sv_trap = NULL, .sv_hwcap = &cpu_features, .sv_hwcap2 = &cpu_features2, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, }; struct sysentvec elf64_freebsd_sysvec_v2 = { @@ -129,6 +131,8 @@ struct sysentvec elf64_freebsd_sysvec_v2 = { .sv_trap = NULL, .sv_hwcap = &cpu_features, .sv_hwcap2 = &cpu_features2, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, }; static boolean_t ppc64_elfv1_header_match(struct image_params *params, diff --git a/sys/riscv/riscv/elf_machdep.c b/sys/riscv/riscv/elf_machdep.c index 06d117128ef..cf479ec6d15 100644 --- a/sys/riscv/riscv/elf_machdep.c +++ b/sys/riscv/riscv/elf_machdep.c @@ -96,6 +96,8 @@ struct sysentvec elf64_freebsd_sysvec = { .sv_trap = NULL, .sv_hwcap = &elf_hwcap, .sv_machine_arch = riscv_machine_arch, + .sv_onexec_old = exec_onexec_old, + .sv_onexit = exit_onexit, }; INIT_SYSENTVEC(elf64_sysvec, &elf64_freebsd_sysvec); diff --git a/sys/sys/sysent.h b/sys/sys/sysent.h index ff37806efd9..a6b4b9fe937 100644 --- a/sys/sys/sysent.h +++ b/sys/sys/sysent.h @@ -317,6 +317,9 @@ void exec_sysvec_init(void *param); void exec_sysvec_init_secondary(struct sysentvec *sv, struct sysentvec *sv2); void exec_inittk(void); +void exit_onexit(struct proc *p); +void exec_onexec_old(struct thread *td); + #define INIT_SYSENTVEC(name, sv) \ SYSINIT(name, SI_SUB_EXEC, SI_ORDER_ANY, \ (sysinit_cfunc_t)exec_sysvec_init, sv);