Index: head/sys/kern/kern_exec.c =================================================================== --- head/sys/kern/kern_exec.c +++ head/sys/kern/kern_exec.c @@ -1051,6 +1051,8 @@ sigfastblock_clear(td); umtx_exec(p); itimers_exec(p); + if (sv->sv_onexec != NULL) + sv->sv_onexec(p, imgp); EVENTHANDLER_DIRECT_INVOKE(process_exec, p, imgp); Index: head/sys/kern/kern_exit.c =================================================================== --- head/sys/kern/kern_exit.c +++ head/sys/kern/kern_exit.c @@ -72,6 +72,7 @@ #include #include #include +#include #include #include #ifdef KTRACE @@ -327,6 +328,9 @@ itimers_exit(p); + if (p->p_sysent->sv_onexit != NULL) + p->p_sysent->sv_onexit(p); + /* * Check if any loadable modules need anything done at process exit. * E.g. SYSV IPC stuff. @@ -560,6 +564,9 @@ /* Save exit status. */ PROC_LOCK(p); p->p_xthread = td; + + if (p->p_sysent->sv_ontdexit != NULL) + p->p_sysent->sv_ontdexit(td); #ifdef KDTRACE_HOOKS /* Index: head/sys/kern/kern_kthread.c =================================================================== --- head/sys/kern/kern_kthread.c +++ head/sys/kern/kern_kthread.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -355,6 +356,10 @@ PROC_UNLOCK(p); kproc_exit(0); } + + if (p->p_sysent->sv_ontdexit != NULL) + p->p_sysent->sv_ontdexit(td); + tidhash_remove(td); umtx_thread_exit(td); tdsigcleanup(td); Index: head/sys/kern/kern_thr.c =================================================================== --- head/sys/kern/kern_thr.c +++ head/sys/kern/kern_thr.c @@ -353,6 +353,9 @@ return (0); } + if (p->p_sysent->sv_ontdexit != NULL) + p->p_sysent->sv_ontdexit(td); + td->td_dbgflags |= TDB_EXIT; if (p->p_ptevents & PTRACE_LWP) { p->p_pendingexits++; Index: head/sys/sys/sysent.h =================================================================== --- head/sys/sys/sysent.h +++ head/sys/sys/sysent.h @@ -145,6 +145,9 @@ u_long *sv_hwcap2; /* Value passed in AT_HWCAP2. */ const char *(*sv_machine_arch)(struct proc *); vm_offset_t sv_fxrng_gen_base; + void (*sv_onexec)(struct proc *, struct image_params *); + void (*sv_onexit)(struct proc *); + void (*sv_ontdexit)(struct thread *td); }; #define SV_ILP32 0x000100 /* 32-bit executable. */