Source-Changes-HG archive

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

[src/trunk]: src/sys Move the sigfilter hook to a more adequate location, and...



details:   https://anonhg.NetBSD.org/src/rev/9e2b8a36d862
branches:  trunk
changeset: 556710:9e2b8a36d862
user:      manu <manu%NetBSD.org@localhost>
date:      Wed Dec 24 22:53:59 2003 +0000

description:
Move the sigfilter hook to a more adequate location, and rename it to better
fit what it does.

The softsignal feature is used in Darwin to trace processes. When the
traced process gets a signal, this raises an exception. The debugger will
receive the exception message, use ptrace with PT_THUPDATE to pass the
signal to the child or discard it, and then it will send a reply to the
exception message, to resume the child.

With the hook at the beginnng of kpsignal2, we are in the context of the
signal sender, which can be the kill(1) command, for instance. We cannot
afford to sleep until the debugger tells us if the signal should be
delivered or not.

Therefore, the hook to generate the Mach exception must be in the traced
process context. That was we can sleep awaiting for the debugger opinion
about the signal, this is not a problem. The hook is hence located into
issignal, at the place where normally SIGCHILD is sent to the debugger,
whereas the traced process is stopped. If the hook returns 0, we bypass
thoses operations, the Mach exception mecanism will take care of notifying
the debugger (through a Mach exception), and stop the faulting thread.

diffstat:

 sys/compat/darwin/darwin_exec.c   |   6 +++---
 sys/compat/darwin/darwin_signal.c |  13 ++++---------
 sys/compat/darwin/darwin_signal.h |   4 ++--
 sys/kern/kern_sig.c               |  18 +++++++++---------
 sys/sys/proc.h                    |   6 ++----
 5 files changed, 20 insertions(+), 27 deletions(-)

diffs (171 lines):

diff -r 8d0ba0f0c59b -r 9e2b8a36d862 sys/compat/darwin/darwin_exec.c
--- a/sys/compat/darwin/darwin_exec.c   Wed Dec 24 22:42:11 2003 +0000
+++ b/sys/compat/darwin/darwin_exec.c   Wed Dec 24 22:53:59 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: darwin_exec.c,v 1.32 2003/12/20 19:43:17 manu Exp $ */
+/*     $NetBSD: darwin_exec.c,v 1.33 2003/12/24 22:53:59 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include "opt_compat_darwin.h" /* For COMPAT_DARWIN in mach_port.h */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_exec.c,v 1.32 2003/12/20 19:43:17 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_exec.c,v 1.33 2003/12/24 22:53:59 manu Exp $");
 
 #include "opt_syscall_debug.h"
 
@@ -111,7 +111,7 @@
 #endif
        darwin_sendsig,
        darwin_trapsignal,
-       darwin_sigfilter,
+       darwin_tracesig,
 #if !defined(__HAVE_SIGINFO) || defined(COMPAT_16)
        sigcode,
        esigcode,
diff -r 8d0ba0f0c59b -r 9e2b8a36d862 sys/compat/darwin/darwin_signal.c
--- a/sys/compat/darwin/darwin_signal.c Wed Dec 24 22:42:11 2003 +0000
+++ b/sys/compat/darwin/darwin_signal.c Wed Dec 24 22:53:59 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: darwin_signal.c,v 1.14 2003/12/16 16:13:59 manu Exp $ */
+/*     $NetBSD: darwin_signal.c,v 1.15 2003/12/24 22:53:59 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_signal.c,v 1.14 2003/12/16 16:13:59 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_signal.c,v 1.15 2003/12/24 22:53:59 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -130,9 +130,6 @@
        struct lwp *l;
        const struct ksiginfo *ksi;
 {
-       if (darwin_sigfilter(l, ksi) == 0)
-               return;
-
        if (mach_trapsignal1(l, ksi) != 0)
                trapsignal(l, ksi);
 
@@ -140,9 +137,9 @@
 }
 
 int
-darwin_sigfilter(l, ksi)
+darwin_tracesig(l, signo)
        struct lwp *l;
-       const struct ksiginfo *ksi;
+       int signo;
 {
        struct proc *p = l->l_proc;
        struct darwin_emuldata *ded;
@@ -150,8 +147,6 @@
        int error;
        int signo;
 
-       signo = ksi->ksi_signo;
-
        /* 
         * Don't generate Mach exeption for non 
         * maskable, stop and continue signals 
diff -r 8d0ba0f0c59b -r 9e2b8a36d862 sys/compat/darwin/darwin_signal.h
--- a/sys/compat/darwin/darwin_signal.h Wed Dec 24 22:42:11 2003 +0000
+++ b/sys/compat/darwin/darwin_signal.h Wed Dec 24 22:53:59 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: darwin_signal.h,v 1.11 2003/12/16 13:38:26 manu Exp $ */
+/*     $NetBSD: darwin_signal.h,v 1.12 2003/12/24 22:53:59 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -81,7 +81,7 @@
 
 void darwin_sendsig(const ksiginfo_t *, const sigset_t *);
 void darwin_trapsignal(struct lwp *, const struct ksiginfo *);
-int darwin_sigfilter(struct lwp *, const struct ksiginfo *);
+int darwin_tracesig(struct lwp *, int);
 void native_to_darwin_siginfo(const struct ksiginfo *, struct darwin___siginfo *);
 
 #endif /* _DARWIN_SIGNAL_H_ */
diff -r 8d0ba0f0c59b -r 9e2b8a36d862 sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c       Wed Dec 24 22:42:11 2003 +0000
+++ b/sys/kern/kern_sig.c       Wed Dec 24 22:53:59 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sig.c,v 1.183 2003/12/20 19:01:30 fvdl Exp $      */
+/*     $NetBSD: kern_sig.c,v 1.184 2003/12/24 22:53:59 manu Exp $      */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.183 2003/12/20 19:01:30 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.184 2003/12/24 22:53:59 manu Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_compat_sunos.h"
@@ -1009,13 +1009,6 @@
 #endif
 
        /*
-        * Allow emulation-specific signal filtering
-        */
-       if ((p->p_emul->e_sigfilter != NULL) &&
-           ((*p->p_emul->e_sigfilter)(proc_representative_lwp(p), ksi) == 0))
-               return;
-
-       /*
         * Notify any interested parties in the signal.
         */
        KNOTE(&p->p_klist, NOTE_SIGNAL | signum);
@@ -1455,6 +1448,12 @@
                         * stopped until released by the debugger.
                         */
                        p->p_xstat = signum;
+
+                       /* Emulation-specific handling of signal trace */
+                       if ((p->p_emul->e_tracesig != NULL) &&
+                           ((*p->p_emul->e_tracesig)(p, signum) != 0))
+                               goto childresumed;
+
                        if ((p->p_flag & P_FSTRACE) == 0)
                                child_psignal(p, dolock);
                        if (dolock)
@@ -1468,6 +1467,7 @@
                        else
                                dolock = 1;
 
+               childresumed:
                        /*
                         * If we are no longer being traced, or the parent
                         * didn't give us a signal, look for more signals.
diff -r 8d0ba0f0c59b -r 9e2b8a36d862 sys/sys/proc.h
--- a/sys/sys/proc.h    Wed Dec 24 22:42:11 2003 +0000
+++ b/sys/sys/proc.h    Wed Dec 24 22:53:59 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: proc.h,v 1.184 2003/12/20 19:01:30 fvdl Exp $  */
+/*     $NetBSD: proc.h,v 1.185 2003/12/24 22:53:59 manu Exp $  */
 
 /*-
  * Copyright (c) 1986, 1989, 1991, 1993
@@ -105,13 +105,11 @@
                                          const sigset_t *));
        void            (*e_trapsignal) __P((struct lwp *,
                                             const struct ksiginfo *));
-       int             (*e_sigfilter) __P((struct lwp *,
-                                            const struct ksiginfo *));
 #else
        void            (*e_sendsig) __P((int, const sigset_t *, u_long));
        void            (*e_trapsignal) __P((struct lwp *, int, u_long));
-       int             (*e_sigfilter) __P((struct lwp *, int, u_long));
 #endif
+       int             (*e_tracesig) __P((struct proc *, int));
        char            *e_sigcode;     /* Start of sigcode */
        char            *e_esigcode;    /* End of sigcode */
                                        /* Set registers before execution */



Home | Main Index | Thread Index | Old Index