Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Correct passing debugger related events for LWP cre...



details:   https://anonhg.NetBSD.org/src/rev/725938e57e19
branches:  trunk
changeset: 841174:725938e57e19
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed May 01 21:57:34 2019 +0000

description:
Correct passing debugger related events for LWP create and exit

Add MI toplevel startlwp function.

Switch all userland LWPs to go through lwp_create using a shared
mi_startlwp() function between all MD ABIs.

Add debugger related event handling in mi_startlwp() and continue with
standard p->p_emul->e_startlwp at the end of this routine.

Use eventswitch() to notify the event of LWP exit in lwp_exit().

ATF ptrace(2) tests signal9 and signal10 now pass.

diffstat:

 sys/kern/kern_lwp.c |  53 +++++++++++++++--------------------------------------
 sys/kern/sys_lwp.c  |  34 +++++++++++++++++++++++++++++++---
 2 files changed, 46 insertions(+), 41 deletions(-)

diffs (154 lines):

diff -r e63bb55d2212 -r 725938e57e19 sys/kern/kern_lwp.c
--- a/sys/kern/kern_lwp.c       Wed May 01 21:52:35 2019 +0000
+++ b/sys/kern/kern_lwp.c       Wed May 01 21:57:34 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_lwp.c,v 1.197 2019/04/19 01:52:55 ozaki-r Exp $   */
+/*     $NetBSD: kern_lwp.c,v 1.198 2019/05/01 21:57:34 kamil Exp $     */
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -211,7 +211,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.197 2019/04/19 01:52:55 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.198 2019/05/01 21:57:34 kamil Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -969,24 +969,6 @@
        if (p2->p_emul->e_lwp_fork)
                (*p2->p_emul->e_lwp_fork)(l1, l2);
 
-       /* If the process is traced, report lwp creation to a debugger */
-       if ((p2->p_slflag & (PSL_TRACED|PSL_TRACELWP_CREATE|PSL_SYSCALL)) ==
-           (PSL_TRACED|PSL_TRACELWP_CREATE)) {
-               ksiginfo_t ksi;
-
-               /* Tracing */
-               KASSERT((l2->l_flag & LW_SYSTEM) == 0);
-
-               p2->p_lwp_created = l2->l_lid;
-
-               KSI_INIT_EMPTY(&ksi);
-               ksi.ksi_signo = SIGTRAP;
-               ksi.ksi_code = TRAP_LWP;
-               mutex_enter(proc_lock);
-               kpsignal(p2, &ksi, NULL);
-               mutex_exit(proc_lock);
-       }
-
        return (0);
 }
 
@@ -1050,24 +1032,6 @@
         */
        LOCKDEBUG_BARRIER(&kernel_lock, 0);
 
-       /* If the process is traced, report lwp termination to a debugger */
-       if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_EXIT|PSL_SYSCALL)) ==
-           (PSL_TRACED|PSL_TRACELWP_EXIT)) {
-               ksiginfo_t ksi;
-
-               /* Tracing */
-               KASSERT((l->l_flag & LW_SYSTEM) == 0);
-
-               p->p_lwp_exited = l->l_lid;
-
-               KSI_INIT_EMPTY(&ksi);
-               ksi.ksi_signo = SIGTRAP;
-               ksi.ksi_code = TRAP_LWP;
-               mutex_enter(proc_lock);
-               kpsignal(p, &ksi, NULL);
-               mutex_exit(proc_lock);
-       }
-
        /*
         * If we are the last live LWP in a process, we need to exit the
         * entire process.  We do so with an exit status of zero, because
@@ -1108,10 +1072,23 @@
        callout_destroy(&l->l_timeout_ch);
 
        /*
+        * If traced, report LWP exit event to the debugger.
+        *
         * Remove the LWP from the global list.
         * Free its LID from the PID namespace if needed.
         */
        mutex_enter(proc_lock);
+
+       if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_EXIT|PSL_SYSCALL)) ==
+           (PSL_TRACED|PSL_TRACELWP_EXIT)) {
+               mutex_enter(p->p_lock);
+               p->p_lwp_exited = l->l_lid;
+               eventswitch(SIGTRAP, TRAP_LWP);
+               // XXX ktrpoint(KTR_PSIG)
+               mutex_exit(p->p_lock);
+               mutex_enter(proc_lock);
+       }
+
        LIST_REMOVE(l, l_list);
        if ((l->l_pflag & LP_PIDLID) != 0 && l->l_lid != p->p_pid) {
                proc_free_pid(l->l_lid);
diff -r e63bb55d2212 -r 725938e57e19 sys/kern/sys_lwp.c
--- a/sys/kern/sys_lwp.c        Wed May 01 21:52:35 2019 +0000
+++ b/sys/kern/sys_lwp.c        Wed May 01 21:57:34 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_lwp.c,v 1.63 2018/01/30 07:52:23 ozaki-r Exp $     */
+/*     $NetBSD: sys_lwp.c,v 1.64 2019/05/01 21:57:34 kamil Exp $       */
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.63 2018/01/30 07:52:23 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.64 2019/05/01 21:57:34 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -69,6 +69,34 @@
        sleeptab_init(&lwp_park_tab);
 }
 
+static void
+mi_startlwp(void *arg)
+{
+       struct lwp *l = curlwp;
+       struct proc *p = l->l_proc;
+
+       /* If the process is traced, report lwp creation to a debugger */
+       if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_CREATE|PSL_SYSCALL)) ==
+           (PSL_TRACED|PSL_TRACELWP_CREATE)) {
+               /* Paranoid check */
+               mutex_enter(proc_lock);
+               if ((p->p_slflag & (PSL_TRACED|PSL_TRACELWP_CREATE|PSL_SYSCALL)) !=
+                   (PSL_TRACED|PSL_TRACELWP_CREATE)) {
+                       mutex_exit(proc_lock);
+                       goto my_tracer_is_gone;
+               }
+
+               mutex_enter(p->p_lock);
+               p->p_lwp_created = l->l_lid;
+               eventswitch(SIGTRAP, TRAP_LWP);
+               // XXX ktrpoint(KTR_PSIG)
+               mutex_exit(p->p_lock);
+       }
+
+my_tracer_is_gone:
+       (p->p_emul->e_startlwp)(arg);
+}
+
 int
 do_lwp_create(lwp_t *l, void *arg, u_long flags, lwpid_t *new_lwp,
     const sigset_t *sigmask, const stack_t *sigstk)
@@ -86,7 +114,7 @@
                return ENOMEM;
 
        error = lwp_create(l, p, uaddr, flags & LWP_DETACHED, NULL, 0,
-           p->p_emul->e_startlwp, arg, &l2, l->l_class, sigmask, &SS_INIT);
+           mi_startlwp, arg, &l2, l->l_class, sigmask, &SS_INIT);
        if (__predict_false(error)) {
                uvm_uarea_free(uaddr);
                return error;



Home | Main Index | Thread Index | Old Index