Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libc/sys Introduce PT_LWPSTATUS + PT_LWPNEXT, obso...
details: https://anonhg.NetBSD.org/src/rev/410ab3ba0b44
branches: trunk
changeset: 967862:410ab3ba0b44
user: kamil <kamil%NetBSD.org@localhost>
date: Tue Dec 24 14:50:59 2019 +0000
description:
Introduce PT_LWPSTATUS + PT_LWPNEXT, obsolete PT_LWPINFO
PT_LWPINFO is a legacy ptrace(2) operation that was originally intended
to retrieve the thread (LWP) information inside a traced process.
It has a number of flaws and is confused with PT_LWPINFO from FreeBSD.
PT_LWPSTATUS and PT_LWPNEXT address the problems (shortly by: rename,
removal of pl_event) and introduces new features: signal context
(pl_sigpend, pl_sigmask), LWP name (pl_name), LWP TLS base address
(pl_private). The private pointer was so far missing information for
a debugger.
PT_LWPSTATUS@nnn is now shipped with core(5) files and contain LWP specific
information, so far missed in the core(5) files.
PT_LWPSTATUS retrieves LWP information for the prompted thread.
PT_LWPNEXT retrieves LWP information for the next thread, borrowing the
semantics from NetBSD specific PT_LWPINFO.
PT_LWPINFO is namespaced with __LEGACY_PT_LWPINFO and still available for
the foreseeable future, without plans of removing it.
Add ATF tests for PT_LWPSTATUS + PT_LWPNEXT.
Keep ATF tests for PT_LWPINFO.
Switch GDB to new API.
Proposed on tech-kern@.
diffstat:
external/gpl3/gdb/dist/gdb/nbsd-nat.c | 8 +-
sys/arch/alpha/include/ptrace.h | 6 +-
sys/arch/hppa/include/ptrace.h | 6 +-
sys/arch/powerpc/include/ptrace.h | 6 +-
sys/arch/sh3/include/ptrace.h | 3 +-
sys/arch/sparc/include/ptrace.h | 6 +-
sys/compat/netbsd32/netbsd32.h | 15 +-
sys/compat/netbsd32/netbsd32_ptrace.c | 39 +++-
sys/kern/core_elf32.c | 33 +-
sys/kern/sys_ptrace.c | 13 +-
sys/kern/sys_ptrace_common.c | 114 +++++++++-
sys/sys/ptrace.h | 60 ++++-
tests/lib/libc/sys/t_ptrace_wait.c | 394 +++++++++++++++++++++++++++++----
13 files changed, 623 insertions(+), 80 deletions(-)
diffs (truncated from 1131 to 300 lines):
diff -r 447ff626c65c -r 410ab3ba0b44 external/gpl3/gdb/dist/gdb/nbsd-nat.c
--- a/external/gpl3/gdb/dist/gdb/nbsd-nat.c Tue Dec 24 14:10:51 2019 +0000
+++ b/external/gpl3/gdb/dist/gdb/nbsd-nat.c Tue Dec 24 14:50:59 2019 +0000
@@ -145,10 +145,10 @@
{
if (ptid.lwp_p ())
{
- struct ptrace_lwpinfo pl;
+ struct ptrace_lwpstatus pl;
pl.pl_lwpid = ptid.lwp ();
- if (ptrace (PT_LWPINFO, ptid.pid (), (caddr_t) &pl, sizeof pl)
+ if (ptrace (PT_LWPSTATUS, ptid.pid (), (caddr_t) &pl, sizeof pl)
== -1)
return 0;
}
@@ -255,10 +255,10 @@
nbsd_add_threads (pid_t pid)
{
int val;
- struct ptrace_lwpinfo pl;
+ struct ptrace_lwpstatus pl;
pl.pl_lwpid = 0;
- while ((val = ptrace (PT_LWPINFO, pid, (void *)&pl, sizeof(pl))) != -1
+ while ((val = ptrace (PT_LWPNEXT, pid, (void *)&pl, sizeof(pl))) != -1
&& pl.pl_lwpid != 0)
{
ptid_t ptid = ptid_t (pid, pl.pl_lwpid, 0);
diff -r 447ff626c65c -r 410ab3ba0b44 sys/arch/alpha/include/ptrace.h
--- a/sys/arch/alpha/include/ptrace.h Tue Dec 24 14:10:51 2019 +0000
+++ b/sys/arch/alpha/include/ptrace.h Tue Dec 24 14:50:59 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ptrace.h,v 1.10 2019/06/18 21:18:11 kamil Exp $ */
+/* $NetBSD: ptrace.h,v 1.11 2019/12/24 14:50:59 kamil Exp $ */
/*
* Copyright (c) 1994 Christopher G. Demetriou
@@ -56,3 +56,7 @@
#define PTRACE_BREAKPOINT ((const uint8_t[]) { 0x80, 0x00, 0x00, 0x00 })
#define PTRACE_BREAKPOINT_ASM __asm __volatile("bpt" ::: "memory")
#define PTRACE_BREAKPOINT_SIZE 4
+
+#ifdef _KERNEL
+#define PTRACE_LWP_GETPRIVATE(l) ((struct pcb *)lwp_getpcb(l))->pcb_hw.apcb_unique
+#endif
diff -r 447ff626c65c -r 410ab3ba0b44 sys/arch/hppa/include/ptrace.h
--- a/sys/arch/hppa/include/ptrace.h Tue Dec 24 14:10:51 2019 +0000
+++ b/sys/arch/hppa/include/ptrace.h Tue Dec 24 14:50:59 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ptrace.h,v 1.9 2019/06/18 21:18:12 kamil Exp $ */
+/* $NetBSD: ptrace.h,v 1.10 2019/12/24 14:50:59 kamil Exp $ */
/* $OpenBSD: ptrace.h,v 1.2 1998/12/01 03:05:44 mickey Exp $ */
@@ -61,3 +61,7 @@
#define PTRACE_BREAKPOINT ((const uint8_t[]) { 0x00, 0x01, 0x00, 0x04 })
#define PTRACE_BREAKPOINT_ASM __asm __volatile("break %0, %1" :: "i" (HPPA_BREAK_KERNEL), "i" (HPPA_BREAK_SS) : "memory")
#define PTRACE_BREAKPOINT_SIZE 4
+
+#ifdef _KERNEL
+#define PTRACE_LWP_GETPRIVATE(l) (l)->l_md.md_regs->tf_cr27
+#endif
diff -r 447ff626c65c -r 410ab3ba0b44 sys/arch/powerpc/include/ptrace.h
--- a/sys/arch/powerpc/include/ptrace.h Tue Dec 24 14:10:51 2019 +0000
+++ b/sys/arch/powerpc/include/ptrace.h Tue Dec 24 14:50:59 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ptrace.h,v 1.15 2019/11/29 12:04:32 martin Exp $ */
+/* $NetBSD: ptrace.h,v 1.16 2019/12/24 14:50:59 kamil Exp $ */
#ifndef _POWERPC_PTRACE_H
#define _POWERPC_PTRACE_H
@@ -77,4 +77,8 @@
#define PTRACE_BREAKPOINT_ASM __asm __volatile("trap")
#define PTRACE_BREAKPOINT_SIZE 4
+#ifdef _KERNEL
+#define PTRACE_LWP_GETPRIVATE(l) (l)->l_md.md_utf->tf_fixreg[_REG_R2]
+#endif
+
#endif /* _POWERPC_PTRACE_H */
diff -r 447ff626c65c -r 410ab3ba0b44 sys/arch/sh3/include/ptrace.h
--- a/sys/arch/sh3/include/ptrace.h Tue Dec 24 14:10:51 2019 +0000
+++ b/sys/arch/sh3/include/ptrace.h Tue Dec 24 14:50:59 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ptrace.h,v 1.16 2019/10/04 15:25:30 maya Exp $ */
+/* $NetBSD: ptrace.h,v 1.17 2019/12/24 14:50:59 kamil Exp $ */
/*
* Copyright (c) 1993 Christopher G. Demetriou
@@ -98,5 +98,6 @@
int ptrace_machdep_dorequest(struct lwp *, struct lwp *, int, void *, int);
#endif
+#define PTRACE_LWP_GETPRIVATE(l) (l)->l_md.md_regs->tf_gbr
#endif /* _KERNEL */
#endif /* !_SH3_PTRACE_H_ */
diff -r 447ff626c65c -r 410ab3ba0b44 sys/arch/sparc/include/ptrace.h
--- a/sys/arch/sparc/include/ptrace.h Tue Dec 24 14:10:51 2019 +0000
+++ b/sys/arch/sparc/include/ptrace.h Tue Dec 24 14:50:59 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ptrace.h,v 1.14 2019/06/18 21:18:13 kamil Exp $ */
+/* $NetBSD: ptrace.h,v 1.15 2019/12/24 14:50:59 kamil Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -69,3 +69,7 @@
#define PTRACE_BREAKPOINT ((const uint8_t[]) { 0x91, 0xd0, 0x20, 0x01 })
#define PTRACE_BREAKPOINT_ASM __asm __volatile("ta 1")
#define PTRACE_BREAKPOINT_SIZE 4
+
+#ifdef _KERNEL
+#define PTRACE_LWP_GETPRIVATE(l) (l)->l_md.md_tf->tf_global[7]
+#endif
diff -r 447ff626c65c -r 410ab3ba0b44 sys/compat/netbsd32/netbsd32.h
--- a/sys/compat/netbsd32/netbsd32.h Tue Dec 24 14:10:51 2019 +0000
+++ b/sys/compat/netbsd32/netbsd32.h Tue Dec 24 14:50:59 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32.h,v 1.131 2019/11/18 12:06:26 rin Exp $ */
+/* $NetBSD: netbsd32.h,v 1.132 2019/12/24 14:50:59 kamil Exp $ */
/*
* Copyright (c) 1998, 2001, 2008, 2015 Matthew R. Green
@@ -39,6 +39,7 @@
#include <sys/param.h> /* precautionary upon removal from ucred.h */
#include <sys/systm.h>
#include <sys/mount.h>
+#include <sys/ptrace.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/syscallargs.h>
@@ -331,6 +332,16 @@
* (route signal to all LWPs) */
};
+#define PL32_LNAMELEN 20
+
+struct netbsd32_ptrace_lwpstatus {
+ lwpid_t pl_lwpid;
+ sigset_t pl_sigpend;
+ sigset_t pl_sigmask;
+ char pl_name[PL32_LNAMELEN];
+ netbsd32_voidp pl_private;
+};
+
/* from <sys/quotactl.h> */
typedef netbsd32_pointer_t netbsd32_quotactlargsp_t;
struct netbsd32_quotactlargs {
@@ -1213,6 +1224,8 @@
void netbsd32_ksi32_to_ksi(struct _ksiginfo *si, const struct __ksiginfo32 *si32);
+void netbsd32_read_lwpstatus(struct lwp *, struct netbsd32_ptrace_lwpstatus *);
+
#ifdef KTRACE
void netbsd32_ktrpsig(int, sig_t, const sigset_t *, const ksiginfo_t *);
#else
diff -r 447ff626c65c -r 410ab3ba0b44 sys/compat/netbsd32/netbsd32_ptrace.c
--- a/sys/compat/netbsd32/netbsd32_ptrace.c Tue Dec 24 14:10:51 2019 +0000
+++ b/sys/compat/netbsd32/netbsd32_ptrace.c Tue Dec 24 14:50:59 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_ptrace.c,v 1.7 2019/06/04 16:29:53 mgorny Exp $ */
+/* $NetBSD: netbsd32_ptrace.c,v 1.8 2019/12/24 14:50:59 kamil Exp $ */
/*
* Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_ptrace.c,v 1.7 2019/06/04 16:29:53 mgorny Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_ptrace.c,v 1.8 2019/12/24 14:50:59 kamil Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ptrace.h"
@@ -51,6 +51,27 @@
#define PTRACE_TRANSLATE_REQUEST32(x) x
#endif
+static void
+netbsd32_lwpstatus_to_lwpstatus32(struct netbsd32_ptrace_lwpstatus *pls32,
+ const struct ptrace_lwpstatus *pls)
+{
+ pls32->pl_lwpid = pls->pl_lwpid;
+ pls32->pl_sigpend = pls->pl_sigpend;
+ pls32->pl_sigmask = pls->pl_sigmask;
+ memcpy(&pls32->pl_name, &pls->pl_name, PL_LNAMELEN);
+ NETBSD32PTR32(pls32->pl_private, pls->pl_private);
+}
+
+void
+netbsd32_read_lwpstatus(struct lwp *l, struct netbsd32_ptrace_lwpstatus *pls32)
+{
+ struct ptrace_lwpstatus pls;
+
+ process_read_lwpstatus(l, &pls);
+
+ netbsd32_lwpstatus_to_lwpstatus32(pls32, &pls);
+}
+
/*
* PTRACE methods
*/
@@ -119,6 +140,19 @@
}
static int
+netbsd32_copyout_lwpstatus(const struct ptrace_lwpstatus *pls, void *addr, size_t len)
+{
+ struct netbsd32_ptrace_lwpstatus pls32;
+
+ if (len > sizeof(pls32))
+ return EINVAL;
+
+ netbsd32_lwpstatus_to_lwpstatus32(&pls32, pls);
+
+ return copyout(&pls32, addr, MIN(len, sizeof(pls32)));
+}
+
+static int
netbsd32_doregs(struct lwp *curl /*tracer*/,
struct lwp *l /*traced*/,
struct uio *uio)
@@ -237,6 +271,7 @@
.ptm_copyout_piod = netbsd32_copyout_piod,
.ptm_copyin_siginfo = netbsd32_copyin_siginfo,
.ptm_copyout_siginfo = netbsd32_copyout_siginfo,
+ .ptm_copyout_lwpstatus = netbsd32_copyout_lwpstatus,
.ptm_doregs = netbsd32_doregs,
.ptm_dofpregs = netbsd32_dofpregs,
.ptm_dodbregs = netbsd32_dodbregs
diff -r 447ff626c65c -r 410ab3ba0b44 sys/kern/core_elf32.c
--- a/sys/kern/core_elf32.c Tue Dec 24 14:10:51 2019 +0000
+++ b/sys/kern/core_elf32.c Tue Dec 24 14:50:59 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: core_elf32.c,v 1.60 2019/11/22 15:57:49 pgoyette Exp $ */
+/* $NetBSD: core_elf32.c,v 1.61 2019/12/24 14:50:59 kamil Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.60 2019/11/22 15:57:49 pgoyette Exp $");
+__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.61 2019/12/24 14:50:59 kamil Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd32.h"
@@ -96,6 +96,9 @@
/* The 'note' section names and data are always 4-byte aligned. */
#define ELFROUNDSIZE 4 /* XXX Should it be sizeof(Elf_Word)? */
+#define elf_read_lwpstatus CONCAT(process_read_lwpstatus, ELFSIZE)
+#define elf_lwpstatus CONCAT(process_lwpstatus, ELFSIZE)
+
#define elf_process_read_regs CONCAT(process_read_regs, ELFSIZE)
#define elf_process_read_fpregs CONCAT(process_read_fpregs, ELFSIZE)
#define elf_reg CONCAT(process_reg, ELFSIZE)
@@ -369,8 +372,6 @@
{
struct proc *p;
struct netbsd_elfcore_procinfo cpi;
- struct lwp *l0;
- sigset_t ss1, ss2;
p = l->l_proc;
@@ -382,16 +383,16 @@
cpi.cpi_siglwp = p->p_sigctx.ps_lwp;
/*
- * XXX This should be per-LWP.
+ * per-LWP pending signals are stored in PT_LWPSTATUS@nnn.
*/
- ss1 = p->p_sigpend.sp_set;
- sigemptyset(&ss2);
- LIST_FOREACH(l0, &p->p_lwps, l_sibling) {
- sigplusset(&l0->l_sigpend.sp_set, &ss1);
- sigplusset(&l0->l_sigmask, &ss2);
- }
- memcpy(&cpi.cpi_sigpend, &ss1, sizeof(cpi.cpi_sigpend));
- memcpy(&cpi.cpi_sigmask, &ss2, sizeof(cpi.cpi_sigmask));
+ memcpy(&cpi.cpi_sigpend, &p->p_sigpend.sp_set, sizeof(cpi.cpi_sigpend));
+
+ /*
+ * Signal mask is stored on a per-LWP basis in PT_LWPSTATUS@nnn.
+ * For compatibility purposes, cpi_sigmask is present, but zeroed.
+ */
+ memset(&cpi.cpi_sigmask, 0, sizeof(cpi.cpi_sigmask));
+
memcpy(&cpi.cpi_sigignore, &p->p_sigctx.ps_sigignore,
sizeof(cpi.cpi_sigignore));
memcpy(&cpi.cpi_sigcatch, &p->p_sigctx.ps_sigcatch,
@@ -482,6 +483,7 @@
{
int error;
char name[64];
+ elf_lwpstatus els;
elf_reg intreg;
Home |
Main Index |
Thread Index |
Old Index