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 implement proc_getlwpstatus() for ...



details:   https://anonhg.NetBSD.org/src/rev/d7e9af7c4d50
branches:  trunk
changeset: 821339:d7e9af7c4d50
user:      chs <chs%NetBSD.org@localhost>
date:      Wed Feb 01 20:01:39 2017 +0000

description:
implement proc_getlwpstatus() for netbsd using PT_GET_SIGINFO.

diffstat:

 external/bsd/libproc/dist/proc_util.c |  37 +++++++++++++++++++++++++++-------
 1 files changed, 29 insertions(+), 8 deletions(-)

diffs (70 lines):

diff -r 3a883b8d5900 -r d7e9af7c4d50 external/bsd/libproc/dist/proc_util.c
--- a/external/bsd/libproc/dist/proc_util.c     Wed Feb 01 19:10:33 2017 +0000
+++ b/external/bsd/libproc/dist/proc_util.c     Wed Feb 01 20:01:39 2017 +0000
@@ -36,6 +36,7 @@
 #include <err.h>
 #include <errno.h>
 #include <signal.h>
+#include <stdbool.h>
 #include <string.h>
 #include <unistd.h>
 #include "_libproc.h"
@@ -216,17 +217,39 @@
        struct ptrace_lwpinfo lwpinfo;
        lwpstatus_t *psp = &phdl->lwps;
        siginfo_t *siginfo;
+       bool have_siginfo, sysentry, sysexit;
 
        if (phdl == NULL)
                return (NULL);
-       lwpinfo.pl_lwpid = 1;
+       lwpinfo.pl_lwpid = 0;
        if (ptrace(PT_LWPINFO, phdl->pid, (void *)&lwpinfo,
            sizeof(lwpinfo)) < 0)
                return (NULL);
+
 #ifdef PL_FLAG_SI
-       siginfo = &lwpinfo.pl_siginfo;
-       if (lwpinfo.pl_event == PL_EVENT_SIGNAL &&
-           (lwpinfo.pl_flags & PL_FLAG_SI) != 0) {
+       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)) {
@@ -236,12 +259,10 @@
                        psp->pr_why = PR_SIGNALLED;
                        psp->pr_what = siginfo->si_signo;
                }
-       } else if (lwpinfo.pl_flags & PL_FLAG_SCE) {
+       } else if (sysentry) {
                psp->pr_why = PR_SYSENTRY;
-       } else if (lwpinfo.pl_flags & PL_FLAG_SCX) {
+       } else if (sysexit) {
                psp->pr_why = PR_SYSEXIT;
        }
-#endif
-
        return (psp);
 }



Home | Main Index | Thread Index | Old Index