Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Rework the fork(2)/vfork(2) event signalling under ...



details:   https://anonhg.NetBSD.org/src/rev/8a46d2541243
branches:  trunk
changeset: 997944:8a46d2541243
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Apr 03 08:07:59 2019 +0000

description:
Rework the fork(2)/vfork(2) event signalling under ptrace(2)

Remove the constraint of SIGTRAP event being maskable by a tracee.

Now all SIGTRAP TRAP_CHLD events are delivered to debugger.

This code touches MD specific logic and the child_return routine.
It's an intermediate step with a room for refactoring in future and
right now the least invasive approach. This allows to assert expected
behavior in already existing ATF tests and make the code prettier
in future keeping the same semantics. Probably there is a need for a MI
wrapper of child_return for shared functionality between ports.

diffstat:

 sys/arch/alpha/alpha/syscall.c       |  16 ++++++++++++++--
 sys/arch/arm/arm/syscall.c           |  18 +++++++++++++++---
 sys/arch/hppa/hppa/trap.c            |  16 ++++++++++++++--
 sys/arch/ia64/ia64/syscall.c         |  21 +++++++++++++++++++--
 sys/arch/m68k/m68k/m68k_syscall.c    |  17 +++++++++++++++--
 sys/arch/mips/mips/trap.c            |  16 ++++++++++++++--
 sys/arch/powerpc/powerpc/syscall.c   |  17 +++++++++++++++--
 sys/arch/riscv/riscv/riscv_machdep.c |  14 +++++++++++++-
 sys/arch/sh3/sh3/vm_machdep.c        |  16 ++++++++++++++--
 sys/arch/sparc/sparc/syscall.c       |  17 ++++++++++++++---
 sys/arch/sparc64/sparc64/syscall.c   |  16 ++++++++++++++--
 sys/arch/vax/vax/syscall.c           |  16 ++++++++++++++--
 sys/arch/x86/x86/syscall.c           |  17 ++++++++++++++---
 sys/kern/kern_fork.c                 |  36 +++++++++++++-----------------------
 14 files changed, 202 insertions(+), 51 deletions(-)

diffs (truncated from 561 to 300 lines):

diff -r b9627ec4d9f8 -r 8a46d2541243 sys/arch/alpha/alpha/syscall.c
--- a/sys/arch/alpha/alpha/syscall.c    Wed Apr 03 05:34:39 2019 +0000
+++ b/sys/arch/alpha/alpha/syscall.c    Wed Apr 03 08:07:59 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: syscall.c,v 1.42 2013/06/26 15:09:59 matt Exp $ */
+/* $NetBSD: syscall.c,v 1.43 2019/04/03 08:07:59 kamil Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -89,7 +89,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.42 2013/06/26 15:09:59 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.43 2019/04/03 08:07:59 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -221,6 +221,18 @@
 child_return(void *arg)
 {
        struct lwp * const l = arg;
+       struct proc *p = l->l_proc;
+
+       if (p->p_slflag & PSL_TRACED) {
+               mutex_enter(p->p_lock);
+               p->p_xsig = SIGTRAP;
+               p->p_sigctx.ps_faked = true; // XXX
+               p->p_sigctx.ps_info._signo = p->p_xsig;
+               p->p_sigctx.ps_info._code = TRAP_CHLD;
+               sigswitch(0, SIGTRAP, true);
+               // XXX ktrpoint(KTR_PSIG)
+               mutex_exit(p->p_lock);
+       }
 
        /*
         * Return values in the frame set by cpu_lwp_fork().
diff -r b9627ec4d9f8 -r 8a46d2541243 sys/arch/arm/arm/syscall.c
--- a/sys/arch/arm/arm/syscall.c        Wed Apr 03 05:34:39 2019 +0000
+++ b/sys/arch/arm/arm/syscall.c        Wed Apr 03 08:07:59 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: syscall.c,v 1.65 2018/05/25 15:37:57 martin Exp $      */
+/*     $NetBSD: syscall.c,v 1.66 2019/04/03 08:07:59 kamil Exp $       */
 
 /*-
  * Copyright (c) 2000, 2003 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
 
 #include <sys/param.h>
 
-__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.65 2018/05/25 15:37:57 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.66 2019/04/03 08:07:59 kamil Exp $");
 
 #include <sys/cpu.h>
 #include <sys/device.h>
@@ -287,6 +287,19 @@
 child_return(void *arg)
 {
        lwp_t * const l = arg;
+       struct proc *p = l->l_proc;
+
+       if (p->p_slflag & PSL_TRACED) {
+               mutex_enter(p->p_lock);
+               p->p_xsig = SIGTRAP;
+               p->p_sigctx.ps_faked = true; // XXX
+               p->p_sigctx.ps_info._signo = p->p_xsig;
+               p->p_sigctx.ps_info._code = TRAP_CHLD;
+               sigswitch(0, SIGTRAP, true);
+               // XXX ktrpoint(KTR_PSIG)
+               mutex_exit(p->p_lock);
+       }
+
        struct trapframe * const tf = lwp_trapframe(l);
 
        tf->tf_r0 = 0;
@@ -305,4 +318,3 @@
 
        userret(l);
 }
-
diff -r b9627ec4d9f8 -r 8a46d2541243 sys/arch/hppa/hppa/trap.c
--- a/sys/arch/hppa/hppa/trap.c Wed Apr 03 05:34:39 2019 +0000
+++ b/sys/arch/hppa/hppa/trap.c Wed Apr 03 08:07:59 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.107 2015/03/02 11:05:12 martin Exp $        */
+/*     $NetBSD: trap.c,v 1.108 2019/04/03 08:07:59 kamil Exp $ */
 
 /*-
  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.107 2015/03/02 11:05:12 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.108 2019/04/03 08:07:59 kamil Exp $");
 
 /* #define INTRDEBUG */
 /* #define TRAPDEBUG */
@@ -986,6 +986,18 @@
 child_return(void *arg)
 {
        struct lwp *l = arg;
+       struct proc *p = l->l_proc;
+
+       if (p->p_slflag & PSL_TRACED) {
+               mutex_enter(p->p_lock);
+               p->p_xsig = SIGTRAP;
+               p->p_sigctx.ps_faked = true; // XXX
+               p->p_sigctx.ps_info._signo = p->p_xsig;
+               p->p_sigctx.ps_info._code = TRAP_CHLD;
+               sigswitch(0, SIGTRAP, true);
+               // XXX ktrpoint(KTR_PSIG)
+               mutex_exit(p->p_lock);
+       }
 
        /*
         * Return values in the frame set by cpu_lwp_fork().
diff -r b9627ec4d9f8 -r 8a46d2541243 sys/arch/ia64/ia64/syscall.c
--- a/sys/arch/ia64/ia64/syscall.c      Wed Apr 03 05:34:39 2019 +0000
+++ b/sys/arch/ia64/ia64/syscall.c      Wed Apr 03 08:07:59 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: syscall.c,v 1.7 2018/11/14 21:10:59 scole Exp $ */
+/* $NetBSD: syscall.c,v 1.8 2019/04/03 08:07:59 kamil Exp $ */
 
 /*
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.7 2018/11/14 21:10:59 scole Exp $");
+__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.8 2019/04/03 08:07:59 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -79,6 +79,23 @@
 child_return(void *arg)
 {
        panic("XXX %s: not implemented\n", __func__);
+
+#ifdef notyet
+       struct lwp *l = arg;
+       struct proc *p = l->l_proc;
+
+       if (p->p_slflag & PSL_TRACED) {
+               mutex_enter(p->p_lock);
+               p->p_xsig = SIGTRAP;
+               p->p_sigctx.ps_faked = true; // XXX
+               p->p_sigctx.ps_info._signo = p->p_xsig;
+               p->p_sigctx.ps_info._code = TRAP_CHLD;
+               sigswitch(0, SIGTRAP, true);
+               // XXX ktrpoint(KTR_PSIG)
+               mutex_exit(p->p_lock);
+       }
+#endif
+
        return;
 }
 
diff -r b9627ec4d9f8 -r 8a46d2541243 sys/arch/m68k/m68k/m68k_syscall.c
--- a/sys/arch/m68k/m68k/m68k_syscall.c Wed Apr 03 05:34:39 2019 +0000
+++ b/sys/arch/m68k/m68k/m68k_syscall.c Wed Apr 03 08:07:59 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: m68k_syscall.c,v 1.51 2018/12/19 13:57:48 maxv Exp $   */
+/*     $NetBSD: m68k_syscall.c,v 1.52 2019/04/03 08:07:59 kamil Exp $  */
 
 /*-
  * Portions Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: m68k_syscall.c,v 1.51 2018/12/19 13:57:48 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m68k_syscall.c,v 1.52 2019/04/03 08:07:59 kamil Exp $");
 
 #include "opt_execfmt.h"
 #include "opt_compat_netbsd.h"
@@ -394,6 +394,19 @@
 child_return(void *arg)
 {
        struct lwp *l = arg;
+       struct proc *p = l->l_proc;
+
+       if (p->p_slflag & PSL_TRACED) {
+               mutex_enter(p->p_lock);
+               p->p_xsig = SIGTRAP;
+               p->p_sigctx.ps_faked = true; // XXX
+               p->p_sigctx.ps_info._signo = p->p_xsig;
+               p->p_sigctx.ps_info._code = TRAP_CHLD;
+               sigswitch(0, SIGTRAP, true);
+               // XXX ktrpoint(KTR_PSIG)
+               mutex_exit(p->p_lock);
+       }
+
        /* See cpu_lwp_fork() */
        struct frame *f = (struct frame *)l->l_md.md_regs;
 
diff -r b9627ec4d9f8 -r 8a46d2541243 sys/arch/mips/mips/trap.c
--- a/sys/arch/mips/mips/trap.c Wed Apr 03 05:34:39 2019 +0000
+++ b/sys/arch/mips/mips/trap.c Wed Apr 03 08:07:59 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.246 2018/02/08 19:16:24 bouyer Exp $        */
+/*     $NetBSD: trap.c,v 1.247 2019/04/03 08:08:00 kamil Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.246 2018/02/08 19:16:24 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.247 2019/04/03 08:08:00 kamil Exp $");
 
 #include "opt_cputype.h"       /* which mips CPU levels do we support? */
 #include "opt_ddb.h"
@@ -129,6 +129,18 @@
 {
        struct lwp *l = arg;
        struct trapframe *utf = l->l_md.md_utf;
+       struct proc *p = l->l_proc;
+
+       if (p->p_slflag & PSL_TRACED) {
+               mutex_enter(p->p_lock);
+               p->p_xsig = SIGTRAP;
+               p->p_sigctx.ps_faked = true; // XXX
+               p->p_sigctx.ps_info._signo = p->p_xsig;
+               p->p_sigctx.ps_info._code = TRAP_CHLD;
+               sigswitch(0, SIGTRAP, true);
+               // XXX ktrpoint(KTR_PSIG)
+               mutex_exit(p->p_lock);
+       }
 
        utf->tf_regs[_R_V0] = 0;
        utf->tf_regs[_R_V1] = 1;
diff -r b9627ec4d9f8 -r 8a46d2541243 sys/arch/powerpc/powerpc/syscall.c
--- a/sys/arch/powerpc/powerpc/syscall.c        Wed Apr 03 05:34:39 2019 +0000
+++ b/sys/arch/powerpc/powerpc/syscall.c        Wed Apr 03 08:07:59 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: syscall.c,v 1.53 2013/11/03 22:22:03 mrg Exp $ */
+/*     $NetBSD: syscall.c,v 1.54 2019/04/03 08:08:00 kamil Exp $       */
 
 /*
  * Copyright (C) 2002 Matt Thomas
@@ -61,12 +61,25 @@
 #define EMULNAME(x)    (x)
 #define EMULNAMEU(x)   (x)
 
-__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.53 2013/11/03 22:22:03 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.54 2019/04/03 08:08:00 kamil Exp $");
 
 void
 child_return(void *arg)
 {
        struct lwp * const l = arg;
+       struct proc *p = l->l_proc;
+
+       if (p->p_slflag & PSL_TRACED) {
+               mutex_enter(p->p_lock);
+               p->p_xsig = SIGTRAP;
+               p->p_sigctx.ps_faked = true; // XXX
+               p->p_sigctx.ps_info._signo = p->p_xsig;
+               p->p_sigctx.ps_info._code = TRAP_CHLD;
+               sigswitch(0, SIGTRAP, true);
+               // XXX ktrpoint(KTR_PSIG)
+               mutex_exit(p->p_lock);
+       }
+
        struct trapframe * const tf = l->l_md.md_utf;
 
        tf->tf_fixreg[FIRSTARG] = 0;
diff -r b9627ec4d9f8 -r 8a46d2541243 sys/arch/riscv/riscv/riscv_machdep.c
--- a/sys/arch/riscv/riscv/riscv_machdep.c      Wed Apr 03 05:34:39 2019 +0000
+++ b/sys/arch/riscv/riscv/riscv_machdep.c      Wed Apr 03 08:07:59 2019 +0000
@@ -31,7 +31,7 @@
 
 #include "opt_modular.h"
 
-__RCSID("$NetBSD: riscv_machdep.c,v 1.2 2017/03/16 16:13:21 chs Exp $");
+__RCSID("$NetBSD: riscv_machdep.c,v 1.3 2019/04/03 08:08:00 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -120,6 +120,18 @@
 {
        struct lwp * const l = arg;
        struct trapframe * const tf = l->l_md.md_utf;
+       struct proc *p = l->l_proc;
+
+       if (p->p_slflag & PSL_TRACED) {
+               mutex_enter(p->p_lock);
+               p->p_xsig = SIGTRAP;
+               p->p_sigctx.ps_faked = true; // XXX
+               p->p_sigctx.ps_info._signo = p->p_xsig;
+               p->p_sigctx.ps_info._code = TRAP_CHLD;
+               sigswitch(0, SIGTRAP, true);
+               // XXX ktrpoint(KTR_PSIG)
+               mutex_exit(p->p_lock);
+       }
 
        tf->tf_a0 = 0;



Home | Main Index | Thread Index | Old Index