From owner-svn-src-all@freebsd.org Mon Nov 23 17:29:27 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 210CF4689CE; Mon, 23 Nov 2020 17:29:27 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CfvKM0Tm6z4ZdS; Mon, 23 Nov 2020 17:29:27 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F323E105A4; Mon, 23 Nov 2020 17:29:26 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0ANHTQ3D005668; Mon, 23 Nov 2020 17:29:26 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0ANHTPX9005663; Mon, 23 Nov 2020 17:29:25 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202011231729.0ANHTPX9005663@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 23 Nov 2020 17:29:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367959 - in head/sys: kern sys X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: in head/sys: kern sys X-SVN-Commit-Revision: 367959 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Nov 2020 17:29:27 -0000 Author: kib Date: Mon Nov 23 17:29:25 2020 New Revision: 367959 URL: https://svnweb.freebsd.org/changeset/base/367959 Log: Provide ABI modules hooks for process exec/exit and thread exit. Exec and exit are same as corresponding eventhandler hooks. Thread exit hook is called somewhat earlier, while thread is still owned by the process and enough context is available. Note that the process lock is owned when the hook is called. Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D27309 Modified: head/sys/kern/kern_exec.c head/sys/kern/kern_exit.c head/sys/kern/kern_kthread.c head/sys/kern/kern_thr.c head/sys/sys/sysent.h Modified: head/sys/kern/kern_exec.c ============================================================================== --- head/sys/kern/kern_exec.c Mon Nov 23 17:00:06 2020 (r367958) +++ head/sys/kern/kern_exec.c Mon Nov 23 17:29:25 2020 (r367959) @@ -1051,6 +1051,8 @@ exec_new_vmspace(struct image_params *imgp, struct sys 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); Modified: head/sys/kern/kern_exit.c ============================================================================== --- head/sys/kern/kern_exit.c Mon Nov 23 17:00:06 2020 (r367958) +++ head/sys/kern/kern_exit.c Mon Nov 23 17:29:25 2020 (r367959) @@ -72,6 +72,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #ifdef KTRACE @@ -327,6 +328,9 @@ exit1(struct thread *td, int rval, int signo) 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 @@ exit1(struct thread *td, int rval, int signo) /* 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 /* Modified: head/sys/kern/kern_kthread.c ============================================================================== --- head/sys/kern/kern_kthread.c Mon Nov 23 17:00:06 2020 (r367958) +++ head/sys/kern/kern_kthread.c Mon Nov 23 17:29:25 2020 (r367959) @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -355,6 +356,10 @@ kthread_exit(void) 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); Modified: head/sys/kern/kern_thr.c ============================================================================== --- head/sys/kern/kern_thr.c Mon Nov 23 17:00:06 2020 (r367958) +++ head/sys/kern/kern_thr.c Mon Nov 23 17:29:25 2020 (r367959) @@ -353,6 +353,9 @@ kern_thr_exit(struct thread *td) 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++; Modified: head/sys/sys/sysent.h ============================================================================== --- head/sys/sys/sysent.h Mon Nov 23 17:00:06 2020 (r367958) +++ head/sys/sys/sysent.h Mon Nov 23 17:29:25 2020 (r367959) @@ -145,6 +145,9 @@ struct sysentvec { 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. */