Source-Changes-HG archive

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

[src/trunk]: src/external/bsd/libproc/dist Switch proc_getlwpstatus from PT_L...



details:   https://anonhg.NetBSD.org/src/rev/0b13004f0010
branches:  trunk
changeset: 847033:0b13004f0010
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sat Dec 07 19:38:29 2019 +0000

description:
Switch proc_getlwpstatus from PT_LWPINFO to PT_GET_SIGINFO for NetBSD

PT_LWPINFO from FreeBSD is almost never intended to be expressed with
PT_LWPINFO in NetBSD. PT_GET_SIGINFO reads siginfo_t with the signal
information about the event, on FreeBSD siginfo_t is merged into
ptrace_lwpinfo and returns the thread that received the event (not the
first one in a list like on NetBSD).

diffstat:

 external/bsd/libproc/dist/proc_util.c |  47 ++++++++++++++++++++--------------
 1 files changed, 28 insertions(+), 19 deletions(-)

diffs (80 lines):

diff -r 2e8c4e39d37c -r 0b13004f0010 external/bsd/libproc/dist/proc_util.c
--- a/external/bsd/libproc/dist/proc_util.c     Sat Dec 07 17:56:08 2019 +0000
+++ b/external/bsd/libproc/dist/proc_util.c     Sat Dec 07 19:38:29 2019 +0000
@@ -224,42 +224,50 @@
 const lwpstatus_t *
 proc_getlwpstatus(struct proc_handle *phdl)
 {
-       struct ptrace_lwpinfo lwpinfo;
        lwpstatus_t *psp = &phdl->lwps;
        siginfo_t *siginfo;
+
+#ifdef PT_GET_SIGINFO
+       struct ptrace_siginfo si;
+
+       if (ptrace(PT_GET_SIGINFO, phdl->pid, (void *)&si,
+                  sizeof(si)) < 0)
+               return (NULL);
+
+       siginfo = &si.psi_siginfo;
+       if (siginfo->si_signo == SIGTRAP &&
+           (siginfo->si_code == TRAP_BRKPT ||
+           siginfo->si_code == TRAP_TRACE)) {
+               psp->pr_why = PR_FAULTED;
+               psp->pr_what = FLTBPT;
+       } else if (siginfo->si_signo == SIGTRAP &&
+           (siginfo->si_code == TRAP_SCE)) {
+               psp->pr_why = PR_SYSENTRY;
+       } else if (siginfo->si_signo == SIGTRAP &&
+           (siginfo->si_code == TRAP_SCX)) {
+               psp->pr_why = PR_SYSEXIT;
+       } else {
+               psp->pr_why = PR_SIGNALLED;
+               psp->pr_what = siginfo->si_signo;
+       }
+#else
+       struct ptrace_lwpinfo lwpinfo;
        bool have_siginfo, sysentry, sysexit;
 
        if (phdl == NULL)
                return (NULL);
+
        lwpinfo.pl_lwpid = 0;
        if (ptrace(PT_LWPINFO, phdl->pid, (void *)&lwpinfo,
            sizeof(lwpinfo)) < 0)
                return (NULL);
 
-#ifdef PL_FLAG_SI
        have_siginfo = (lwpinfo.pl_flags & PL_FLAG_SI) != 0;
        sysentry = (lwpinfo.pl_flags & PL_FLAG_SCE) != 0;
        sysexit = (lwpinfo.pl_flags & PL_FLAG_SCX) != 0;
-#endif
-#ifdef PT_GET_SIGINFO
-       have_siginfo = 1;
-       sysentry = 0;
-       sysexit = 0;
-#endif
 
        if (lwpinfo.pl_event == PL_EVENT_SIGNAL && have_siginfo) {
-#ifdef PL_FLAG_SI
                siginfo = &lwpinfo.pl_siginfo;
-#endif
-#ifdef PT_GET_SIGINFO
-               struct ptrace_siginfo si;
-
-               if (ptrace(PT_GET_SIGINFO, phdl->pid, (void *)&si,
-                          sizeof(si)) < 0)
-                       return (NULL);
-
-               siginfo = &si.psi_siginfo;
-#endif
                if (siginfo->si_signo == SIGTRAP &&
                    (siginfo->si_code == TRAP_BRKPT ||
                    siginfo->si_code == TRAP_TRACE)) {
@@ -274,5 +282,6 @@
        } else if (sysexit) {
                psp->pr_why = PR_SYSEXIT;
        }
+#endif
        return (psp);
 }



Home | Main Index | Thread Index | Old Index