Source-Changes-HG archive

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

[src/trunk]: src/sys Ship with syscall information with SIGTRAP TRAP_SCE/TRAP...



details:   https://anonhg.NetBSD.org/src/rev/d5826eee9325
branches:  trunk
changeset: 451104:d5826eee9325
user:      kamil <kamil%NetBSD.org@localhost>
date:      Mon May 06 08:05:03 2019 +0000

description:
Ship with syscall information with SIGTRAP TRAP_SCE/TRAP_SCX for tracers

Expand siginfo_t (struct size not changed) to new values for
SIGTRAP TRAP_SCE/TRAP_SCX events.

 - si_sysnum  -- syscall number (int)
 - si_retval  -- return value (2 x int)
 - si_error   -- error code (int)
 - si_args    -- syscall arguments (8 x uint64_t)

TRAP_SCE delivers si_sysnum and si_args.

TRAP_SCX delivers si_sysnum, si_retval, si_error and si_args.

Users: debuggers (like GDB) and syscall tracers (like strace, truss).

This MI interface is similar to the Linux kernel proposal of
PTRACE_GET_SYSCALL_INFO by the strace developer team.

diffstat:

 sys/kern/kern_sig.c     |  39 ++++++++++++++++++++++++++++-----------
 sys/kern/kern_syscall.c |   8 ++++----
 sys/sys/ptrace.h        |   4 ++--
 sys/sys/siginfo.h       |  19 ++++++++++++++++++-
 4 files changed, 52 insertions(+), 18 deletions(-)

diffs (181 lines):

diff -r 5bba0a277adf -r d5826eee9325 sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c       Mon May 06 06:56:36 2019 +0000
+++ b/sys/kern/kern_sig.c       Mon May 06 08:05:03 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sig.c,v 1.357 2019/05/03 22:34:21 kamil Exp $     */
+/*     $NetBSD: kern_sig.c,v 1.358 2019/05/06 08:05:03 kamil Exp $     */
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.357 2019/05/03 22:34:21 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.358 2019/05/06 08:05:03 kamil Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_dtrace.h"
@@ -2352,7 +2352,8 @@
 }
 
 void
-proc_stoptrace(int trapno)
+proc_stoptrace(int trapno, int sysnum, const register_t args[],
+               const register_t *ret, int error)
 {
        struct lwp *l = curlwp;
        struct proc *p = l->l_proc;
@@ -2360,14 +2361,36 @@
        sigset_t *mask;
        sig_t action;
        ksiginfo_t ksi;
+       size_t i, sy_narg;
        const int signo = SIGTRAP;
 
        KASSERT((trapno == TRAP_SCE) || (trapno == TRAP_SCX));
+       KASSERT(p->p_pptr != initproc);
+       KASSERT(ISSET(p->p_slflag, PSL_TRACED));
+       KASSERT(ISSET(p->p_slflag, PSL_SYSCALL));
+
+       sy_narg = p->p_emul->e_sysent[sysnum].sy_narg;
 
        KSI_INIT_TRAP(&ksi);
        ksi.ksi_lid = l->l_lid;
-       ksi.ksi_info._signo = signo;
-       ksi.ksi_info._code = trapno;
+       ksi.ksi_signo = signo;
+       ksi.ksi_code = trapno;
+
+       ksi.ksi_sysnum = sysnum;
+       if (trapno == TRAP_SCE) {
+               ksi.ksi_retval[0] = 0;
+               ksi.ksi_retval[1] = 0;
+               ksi.ksi_error = 0;
+       } else {
+               ksi.ksi_retval[0] = ret[0];
+               ksi.ksi_retval[1] = ret[1];
+               ksi.ksi_error = error;
+       }
+
+       memset(ksi.ksi_args, 0, sizeof(ksi.ksi_args));
+
+       for (i = 0; i < sy_narg; i++)
+               ksi.ksi_args[i] = args[i];
 
        mutex_enter(p->p_lock);
 
@@ -2385,12 +2408,6 @@
        action = SIGACTION_PS(ps, signo).sa_handler;
        mask = &l->l_sigmask;
 
-       /* initproc (PID1) cannot became a debugger */
-       KASSERT(p->p_pptr != initproc);
-
-       KASSERT(ISSET(p->p_slflag, PSL_TRACED));
-       KASSERT(ISSET(p->p_slflag, PSL_SYSCALL));
-
        p->p_xsig = signo;
        p->p_sigctx.ps_lwp = ksi.ksi_lid;
        p->p_sigctx.ps_info = ksi.ksi_info;
diff -r 5bba0a277adf -r d5826eee9325 sys/kern/kern_syscall.c
--- a/sys/kern/kern_syscall.c   Mon May 06 06:56:36 2019 +0000
+++ b/sys/kern/kern_syscall.c   Mon May 06 08:05:03 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_syscall.c,v 1.17 2018/08/10 21:44:59 pgoyette Exp $       */
+/*     $NetBSD: kern_syscall.c,v 1.18 2019/05/06 08:05:03 kamil Exp $  */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.17 2018/08/10 21:44:59 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.18 2019/05/06 08:05:03 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_modular.h"
@@ -255,7 +255,7 @@
 #ifdef PTRACE
        if ((curlwp->l_proc->p_slflag & (PSL_SYSCALL|PSL_TRACED)) ==
            (PSL_SYSCALL|PSL_TRACED)) {
-               proc_stoptrace(TRAP_SCE);
+               proc_stoptrace(TRAP_SCE, code, args, NULL, 0);
                if (curlwp->l_proc->p_slflag & PSL_SYSCALLEMU) {
                        /* tracer will emulate syscall for us */
                        error = EJUSTRETURN;
@@ -296,7 +296,7 @@
 #ifdef PTRACE
        if ((p->p_slflag & (PSL_SYSCALL|PSL_TRACED|PSL_SYSCALLEMU)) ==
            (PSL_SYSCALL|PSL_TRACED)) {
-               proc_stoptrace(TRAP_SCX);
+               proc_stoptrace(TRAP_SCX, code, args, rval, error);
        }
        CLR(p->p_slflag, PSL_SYSCALLEMU);
 #endif
diff -r 5bba0a277adf -r d5826eee9325 sys/sys/ptrace.h
--- a/sys/sys/ptrace.h  Mon May 06 06:56:36 2019 +0000
+++ b/sys/sys/ptrace.h  Mon May 06 08:05:03 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.63 2018/03/05 11:24:34 kamil Exp $        */
+/*     $NetBSD: ptrace.h,v 1.64 2019/05/06 08:05:03 kamil Exp $        */
 
 /*-
  * Copyright (c) 1984, 1993
@@ -206,7 +206,7 @@
 
 int    process_domem(struct lwp *, struct lwp *, struct uio *);
 
-void   proc_stoptrace(int);
+void   proc_stoptrace(int, int, const register_t[], const register_t *, int);
 void   proc_reparent(struct proc *, struct proc *);
 void   proc_changeparent(struct proc *, struct proc *);
 
diff -r 5bba0a277adf -r d5826eee9325 sys/sys/siginfo.h
--- a/sys/sys/siginfo.h Mon May 06 06:56:36 2019 +0000
+++ b/sys/sys/siginfo.h Mon May 06 08:05:03 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: siginfo.h,v 1.32 2017/03/01 00:19:22 kamil Exp $        */
+/*     $NetBSD: siginfo.h,v 1.33 2019/05/06 08:05:03 kamil Exp $        */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -77,6 +77,13 @@
                        long    _band;
                        int     _fd;
                } _poll;
+
+               struct {
+                       int     _sysnum;
+                       int     _retval[2];
+                       int     _error;
+                       uint64_t _args[8]; /* SYS_MAXSYSARGS */
+               } _syscall;
        } _reason;
 };
 
@@ -155,6 +162,11 @@
 #define        si_band         _info._reason._poll._band
 #define        si_fd           _info._reason._poll._fd
 
+#define        si_sysnum       _info._reason._syscall._sysnum
+#define si_retval      _info._reason._syscall._retval
+#define si_error       _info._reason._syscall._error
+#define si_args                _info._reason._syscall._args
+
 #ifdef _KERNEL
 /** Field access macros */
 #define        ksi_signo       ksi_info._signo
@@ -175,6 +187,11 @@
 
 #define        ksi_band        ksi_info._reason._poll._band
 #define        ksi_fd          ksi_info._reason._poll._fd
+
+#define        ksi_sysnum      ksi_info._reason._syscall._sysnum
+#define ksi_retval     ksi_info._reason._syscall._retval
+#define ksi_error      ksi_info._reason._syscall._error
+#define ksi_args       ksi_info._reason._syscall._args
 #endif /* _KERNEL */
 
 /** si_code */



Home | Main Index | Thread Index | Old Index