Re: CVS commit: src
On Fri, 2020-10-16 at 04:59 +, Martin Husemann wrote: > On Thu, Oct 15, 2020 at 05:44:45PM +, Micha? G?rny wrote: > > Module Name:src > > Committed By: mgorny > > Date: Thu Oct 15 17:44:45 UTC 2020 > > > > Modified Files: > > src/distrib/sets/lists/tests: mi > > src/etc/mtree: NetBSD.dist.tests > > src/tests/sys: Makefile > > Added Files: > > src/tests/sys/x86: Makefile t_convert_xmm_s87.c > > > > Log Message: > > Add tests for process_xmm_to_s87() and process_s87_to_xmm() > > This breaks all non-x86 builds, you need to consistently use the same > conditions for the makefiles, set lists and mtree files. > > Probably easiest way out: create the directories always (but leave empty > on non-x86). Alternative: do not use arch specific sub dirs. > Thanks for the suggestion. I've moved the dirs to mi, and hopefully that'll resolve it for now. -- Best regards, Michał Górny
CVS commit: src
Module Name:src Committed By: mgorny Date: Mon Oct 21 17:07:01 UTC 2019 Modified Files: src/sys/kern: kern_sig.c src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Fix a race condition when handling concurrent LWP signals and add a test Fix a race condition that caused PT_GET_SIGINFO to return incorrect information when multiple signals were delivered concurrently to different LWPs. Add a regression test that verifies that when 50 threads concurrently use pthread_kill() on themselves, the debugger receives all signals with correct information. The kernel uses separate signal queues for each LWP. However, the signal context used to implement PT_GET_SIGINFO is stored in 'struct proc' and therefore common to all LWPs in the process. Previously, this member was filled in kpsignal2(), i.e. when the signal was sent. This meant that if another LWP managed to send another signal concurrently, the data was overwritten before the process was stopped. As a result, PT_GET_SIGINFO did not report the correct LWP and signal (it could even report a different signal than wait()). This can be quite reliably reproduced with the number of 20 LWPs, however it can also occur with 10. This patch moves setting of signal context to issignal(), just before the process is actually stopped. The data is taken from per-LWP or per-process signal queue. The added test confirms that the debugger correctly receives all signals, and PT_GET_SIGINFO reports both correct LWP and signal number. Reviewed by kamil. To generate a diff of this commit: cvs rdiff -u -r1.375 -r1.376 src/sys/kern/kern_sig.c cvs rdiff -u -r1.137 -r1.138 src/tests/lib/libc/sys/t_ptrace_wait.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src
Module Name:src Committed By: mgorny Date: Mon Oct 21 17:07:01 UTC 2019 Modified Files: src/sys/kern: kern_sig.c src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Fix a race condition when handling concurrent LWP signals and add a test Fix a race condition that caused PT_GET_SIGINFO to return incorrect information when multiple signals were delivered concurrently to different LWPs. Add a regression test that verifies that when 50 threads concurrently use pthread_kill() on themselves, the debugger receives all signals with correct information. The kernel uses separate signal queues for each LWP. However, the signal context used to implement PT_GET_SIGINFO is stored in 'struct proc' and therefore common to all LWPs in the process. Previously, this member was filled in kpsignal2(), i.e. when the signal was sent. This meant that if another LWP managed to send another signal concurrently, the data was overwritten before the process was stopped. As a result, PT_GET_SIGINFO did not report the correct LWP and signal (it could even report a different signal than wait()). This can be quite reliably reproduced with the number of 20 LWPs, however it can also occur with 10. This patch moves setting of signal context to issignal(), just before the process is actually stopped. The data is taken from per-LWP or per-process signal queue. The added test confirms that the debugger correctly receives all signals, and PT_GET_SIGINFO reports both correct LWP and signal number. Reviewed by kamil. To generate a diff of this commit: cvs rdiff -u -r1.375 -r1.376 src/sys/kern/kern_sig.c cvs rdiff -u -r1.137 -r1.138 src/tests/lib/libc/sys/t_ptrace_wait.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/kern/kern_sig.c diff -u src/sys/kern/kern_sig.c:1.375 src/sys/kern/kern_sig.c:1.376 --- src/sys/kern/kern_sig.c:1.375 Wed Oct 16 18:29:49 2019 +++ src/sys/kern/kern_sig.c Mon Oct 21 17:07:00 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sig.c,v 1.375 2019/10/16 18:29:49 christos Exp $ */ +/* $NetBSD: kern_sig.c,v 1.376 2019/10/21 17:07:00 mgorny Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.375 2019/10/16 18:29:49 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.376 2019/10/21 17:07:00 mgorny Exp $"); #include "opt_ptrace.h" #include "opt_dtrace.h" @@ -1318,10 +1318,6 @@ kpsignal2(struct proc *p, ksiginfo_t *ks if (p->p_stat != SACTIVE && p->p_stat != SSTOP) return 0; - /* XXX for core dump/debugger */ - p->p_sigctx.ps_lwp = ksi->ksi_lid; - p->p_sigctx.ps_info = ksi->ksi_info; - /* * Notify any interested parties of the signal. */ @@ -1831,7 +1827,7 @@ int issignal(struct lwp *l) { struct proc *p; - int signo, prop; + int siglwp, signo, prop; sigpend_t *sp; sigset_t ss; @@ -1873,6 +1869,7 @@ issignal(struct lwp *l) if (signo == 0) { sp = >l_sigpend; ss = sp->sp_set; + siglwp = l->l_lid; if ((p->p_lflag & PL_PPWAIT) != 0) sigminusset(, ); sigminusset(>l_sigmask, ); @@ -1880,6 +1877,7 @@ issignal(struct lwp *l) if ((signo = firstsig()) == 0) { sp = >p_sigpend; ss = sp->sp_set; +siglwp = 0; if ((p->p_lflag & PL_PPWAIT) != 0) sigminusset(, ); sigminusset(>l_sigmask, ); @@ -1898,6 +1896,28 @@ issignal(struct lwp *l) } } + if (sp) { + /* Overwrite process' signal context to correspond + * to the currently reported LWP. This is necessary + * for PT_GET_SIGINFO to report the correct signal when + * multiple LWPs have pending signals. We do this only + * when the signal comes from the queue, for signals + * created by the debugger we assume it set correct + * siginfo. + */ + ksiginfo_t *ksi = TAILQ_FIRST(>sp_info); + if (ksi) { +p->p_sigctx.ps_lwp = ksi->ksi_lid; +p->p_sigctx.ps_info = ksi->ksi_info; + } else { +p->p_sigctx.ps_lwp = siglwp; +memset(>p_sigctx.ps_info, 0, +sizeof(p->p_sigctx.ps_info)); +p->p_sigctx.ps_info._signo = signo; +p->p_sigctx.ps_info._code = SI_NOINFO; + } + } + /* * We should see pending but ignored signals only if * we are being traced. Index: src/tests/lib/libc/sys/t_ptrace_wait.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.137 src/tests/lib/libc/sys/t_ptrace_wait.c:1.138 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.137 Sun Oct 13 09:42:15 2019 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Mon Oct 21 17:07:00 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.137 2019/10/13 09:42:15 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.138 2019/10/21 17:07:00 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.137 2019/10/13 09:42:15 kamil Exp $"); +__RCSID("$NetBSD:
CVS commit: src/lib/libc/sys
Module Name:src Committed By: mgorny Date: Tue Jul 30 20:18:11 UTC 2019 Modified Files: src/lib/libc/sys: ptrace.2 Log Message: Include pe_lwp member in 'struct ptrace_state' Reviewed by kamil. To generate a diff of this commit: cvs rdiff -u -r1.79 -r1.80 src/lib/libc/sys/ptrace.2 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/sys/ptrace.2 diff -u src/lib/libc/sys/ptrace.2:1.79 src/lib/libc/sys/ptrace.2:1.80 --- src/lib/libc/sys/ptrace.2:1.79 Thu Jul 11 03:30:01 2019 +++ src/lib/libc/sys/ptrace.2 Tue Jul 30 20:18:11 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: ptrace.2,v 1.79 2019/07/11 03:30:01 mgorny Exp $ +.\" $NetBSD: ptrace.2,v 1.80 2019/07/30 20:18:11 mgorny Exp $ .\" .\" This file is in the public domain. .Dd July 11, 2019 @@ -519,11 +519,14 @@ This request reads the state information that stopped the traced process. The information is reported in a .Vt struct ptrace_state -defined as: +that is equivalent to: .Bd -literal -offset indent typedef struct ptrace_state { int pe_report_event; - pid_t pe_other_pid; + union { + pid_t pe_other_pid; + lwpid_t pe_lwp; + }; } ptrace_state_t; .Ed .Pp
CVS commit: src/lib/libc/sys
Module Name:src Committed By: mgorny Date: Tue Jul 30 20:18:11 UTC 2019 Modified Files: src/lib/libc/sys: ptrace.2 Log Message: Include pe_lwp member in 'struct ptrace_state' Reviewed by kamil. To generate a diff of this commit: cvs rdiff -u -r1.79 -r1.80 src/lib/libc/sys/ptrace.2 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/sys
Module Name:src Committed By: mgorny Date: Thu Jul 11 03:30:01 UTC 2019 Modified Files: src/lib/libc/sys: ptrace.2 Log Message: Fix thinko: syscalls -> signals To generate a diff of this commit: cvs rdiff -u -r1.78 -r1.79 src/lib/libc/sys/ptrace.2 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/sys
Module Name:src Committed By: mgorny Date: Thu Jul 11 03:30:01 UTC 2019 Modified Files: src/lib/libc/sys: ptrace.2 Log Message: Fix thinko: syscalls -> signals To generate a diff of this commit: cvs rdiff -u -r1.78 -r1.79 src/lib/libc/sys/ptrace.2 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/sys/ptrace.2 diff -u src/lib/libc/sys/ptrace.2:1.78 src/lib/libc/sys/ptrace.2:1.79 --- src/lib/libc/sys/ptrace.2:1.78 Wed Jul 10 19:51:14 2019 +++ src/lib/libc/sys/ptrace.2 Thu Jul 11 03:30:01 2019 @@ -1,7 +1,7 @@ -.\" $NetBSD: ptrace.2,v 1.78 2019/07/10 19:51:14 mgorny Exp $ +.\" $NetBSD: ptrace.2,v 1.79 2019/07/11 03:30:01 mgorny Exp $ .\" .\" This file is in the public domain. -.Dd July 10, 2019 +.Dd July 11, 2019 .Dt PTRACE 2 .Os .Sh NAME @@ -640,7 +640,7 @@ specifies the LWP ID of the thread to be The execution does not continue until .Dv PT_CONTINUE is issued. -This request permits combining single-stepping with sending syscalls and +This request permits combining single-stepping with sending signals and .Dv PT_SYSCALL . .It Dv PT_CLEARSTEP This request will turn off single stepping of the specified thread.
CVS commit: src/lib/libc/sys
Module Name:src Committed By: mgorny Date: Wed Jul 10 19:51:14 UTC 2019 Modified Files: src/lib/libc/sys: ptrace.2 Log Message: Improve/fix doc of PT_SETSTEP and PT_CLEARSTEP. Reviewed by kamil. To generate a diff of this commit: cvs rdiff -u -r1.77 -r1.78 src/lib/libc/sys/ptrace.2 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/sys
Module Name:src Committed By: mgorny Date: Wed Jul 10 19:51:14 UTC 2019 Modified Files: src/lib/libc/sys: ptrace.2 Log Message: Improve/fix doc of PT_SETSTEP and PT_CLEARSTEP. Reviewed by kamil. To generate a diff of this commit: cvs rdiff -u -r1.77 -r1.78 src/lib/libc/sys/ptrace.2 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/sys/ptrace.2 diff -u src/lib/libc/sys/ptrace.2:1.77 src/lib/libc/sys/ptrace.2:1.78 --- src/lib/libc/sys/ptrace.2:1.77 Wed Jul 10 19:03:47 2019 +++ src/lib/libc/sys/ptrace.2 Wed Jul 10 19:51:14 2019 @@ -1,7 +1,7 @@ -.\" $NetBSD: ptrace.2,v 1.77 2019/07/10 19:03:47 mgorny Exp $ +.\" $NetBSD: ptrace.2,v 1.78 2019/07/10 19:51:14 mgorny Exp $ .\" .\" This file is in the public domain. -.Dd June 26, 2019 +.Dd July 10, 2019 .Dt PTRACE 2 .Os .Sh NAME @@ -632,9 +632,22 @@ If the argument is less than zero, it contains the negative of the LWP ID of the thread to be stepped, and only that thread executes. .It Dv PT_SETSTEP -This request will turn on single stepping of the specified process. +This request will turn on single stepping of the specified thread. +.Fa addr +is unused. +.Fa data +specifies the LWP ID of the thread to be stepped. +The execution does not continue until +.Dv PT_CONTINUE +is issued. +This request permits combining single-stepping with sending syscalls and +.Dv PT_SYSCALL . .It Dv PT_CLEARSTEP -This request will turn off single stepping of the specified process. +This request will turn off single stepping of the specified thread. +.Fa addr +is unused. +.Fa data +specifies the LWP ID of the thread to disable single-stepping. .It Dv PT_GETREGS This request reads the traced process' machine registers into the .Vt struct reg
CVS commit: src/lib/libc/sys
Module Name:src Committed By: mgorny Date: Wed Jul 10 19:03:47 UTC 2019 Modified Files: src/lib/libc/sys: ptrace.2 Log Message: Fix typo: SIGRAP -> SIGTRAP To generate a diff of this commit: cvs rdiff -u -r1.76 -r1.77 src/lib/libc/sys/ptrace.2 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/sys/ptrace.2 diff -u src/lib/libc/sys/ptrace.2:1.76 src/lib/libc/sys/ptrace.2:1.77 --- src/lib/libc/sys/ptrace.2:1.76 Wed Jun 26 13:31:48 2019 +++ src/lib/libc/sys/ptrace.2 Wed Jul 10 19:03:47 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: ptrace.2,v 1.76 2019/06/26 13:31:48 wiz Exp $ +.\" $NetBSD: ptrace.2,v 1.77 2019/07/10 19:03:47 mgorny Exp $ .\" .\" This file is in the public domain. .Dd June 26, 2019 @@ -475,7 +475,7 @@ without pending on its termination or operation. If enabled, the child is also traced by the debugger and -.Dv SIGRAP +.Dv SIGTRAP is generated twice, first for the parent and second for the child. The
CVS commit: src/lib/libc/sys
Module Name:src Committed By: mgorny Date: Wed Jul 10 19:03:47 UTC 2019 Modified Files: src/lib/libc/sys: ptrace.2 Log Message: Fix typo: SIGRAP -> SIGTRAP To generate a diff of this commit: cvs rdiff -u -r1.76 -r1.77 src/lib/libc/sys/ptrace.2 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Sun Jun 30 21:20:04 UTC 2019 Modified Files: src/tests/lib/libc/sys: Makefile t_ptrace_wait.c Log Message: Add a test for verifying procinfo note inside coredumps. Add a first test for triggering a core dump in the debugged process (via PT_DUMPCORE) and verifying it. The test finds procinfo note and checks its contents. The core dump is processed through libelf. However, it only provides for finding all note segments (or sections?). I had to implement finding and processing individual notes myself. I've added a core_find_note() function that will be reused in future tests. Reviewed by kamil. To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/tests/lib/libc/sys/Makefile cvs rdiff -u -r1.129 -r1.130 src/tests/lib/libc/sys/t_ptrace_wait.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libc/sys/Makefile diff -u src/tests/lib/libc/sys/Makefile:1.56 src/tests/lib/libc/sys/Makefile:1.57 --- src/tests/lib/libc/sys/Makefile:1.56 Fri Apr 26 20:41:10 2019 +++ src/tests/lib/libc/sys/Makefile Sun Jun 30 21:20:04 2019 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.56 2019/04/26 20:41:10 maya Exp $ +# $NetBSD: Makefile,v 1.57 2019/06/30 21:20:04 mgorny Exp $ MKMAN= no @@ -88,12 +88,12 @@ SRCS.t_mprotect= t_mprotect.c ${SRCS_EXE LDADD.t_getpid+=-lpthread -LDADD.t_ptrace_wait+= -pthread -lm -LDADD.t_ptrace_wait3+= -pthread -lm -LDADD.t_ptrace_wait4+= -pthread -lm -LDADD.t_ptrace_wait6+= -pthread -lm -LDADD.t_ptrace_waitid+= -pthread -lm -LDADD.t_ptrace_waitpid+= -pthread -lm +LDADD.t_ptrace_wait+= -pthread -lm -lelf +LDADD.t_ptrace_wait3+= -pthread -lm -lelf +LDADD.t_ptrace_wait4+= -pthread -lm -lelf +LDADD.t_ptrace_wait6+= -pthread -lm -lelf +LDADD.t_ptrace_waitid+= -pthread -lm -lelf +LDADD.t_ptrace_waitpid+= -pthread -lm -lelf .if (${MKRUMP} != "no") && !defined(BSD_MK_COMPAT_FILE) CPPFLAGS.t_posix_fadvise.c += -D_KERNTYPES Index: src/tests/lib/libc/sys/t_ptrace_wait.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.129 src/tests/lib/libc/sys/t_ptrace_wait.c:1.130 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.129 Wed Jun 26 12:30:13 2019 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Sun Jun 30 21:20:04 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.129 2019/06/26 12:30:13 mgorny Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.130 2019/06/30 21:20:04 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,10 +27,11 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.129 2019/06/26 12:30:13 mgorny Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.130 2019/06/30 21:20:04 mgorny Exp $"); #include #include +#include #include #include #include @@ -43,6 +44,7 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.12 #include #include #include +#include #include #include #include @@ -66,6 +68,9 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.12 #include #endif +#include +#include + #include #include "h_macros.h" @@ -7639,6 +7644,180 @@ USER_VA0_DISABLE(user_va0_disable_pt_det /// +/* + * Parse the core file and find the requested note. If the reading or parsing + * fails, the test is failed. If the note is found, it is read onto buf, up to + * buf_len. The actual length of the note is returned (which can be greater + * than buf_len, indicating that it has been truncated). If the note is not + * found, -1 is returned. + */ +static ssize_t core_find_note(const char *core_path, +const char *note_name, uint64_t note_type, void *buf, size_t buf_len) +{ + int core_fd; + Elf *core_elf; + size_t core_numhdr, i; + ssize_t ret = -1; + /* note: we assume note name will be null-terminated */ + size_t name_len = strlen(note_name) + 1; + + SYSCALL_REQUIRE((core_fd = open(core_path, O_RDONLY)) != -1); + SYSCALL_REQUIRE(elf_version(EV_CURRENT) != EV_NONE); + SYSCALL_REQUIRE((core_elf = elf_begin(core_fd, ELF_C_READ, NULL))); + + SYSCALL_REQUIRE(elf_getphnum(core_elf, _numhdr) != 0); + for (i = 0; i < core_numhdr && ret == -1; i++) { + GElf_Phdr core_hdr; + size_t offset; + SYSCALL_REQUIRE(gelf_getphdr(core_elf, i, _hdr)); + if (core_hdr.p_type != PT_NOTE) + continue; + + for (offset = core_hdr.p_offset; + offset < core_hdr.p_offset + core_hdr.p_filesz;) { + Elf64_Nhdr note_hdr; + char name_buf[64]; + + switch (gelf_getclass(core_elf)) { + case ELFCLASS64: +SYSCALL_REQUIRE(pread(core_fd, _hdr, +sizeof(note_hdr), offset) +== sizeof(note_hdr)); +offset += sizeof(note_hdr); +break; + case ELFCLASS32: +{ +Elf32_Nhdr tmp_hdr; +SYSCALL_REQUIRE(pread(core_fd, _hdr, +sizeof(tmp_hdr), offset) +== sizeof(tmp_hdr)); +offset += sizeof(tmp_hdr); +note_hdr.n_namesz = tmp_hdr.n_namesz; +
CVS commit: src
Module Name:src Committed By: mgorny Date: Wed Jun 26 12:30:13 UTC 2019 Modified Files: src/lib/libc/sys: ptrace.2 src/sys/arch/amd64/amd64: netbsd32_machdep.c process_machdep.c src/sys/arch/amd64/include: netbsd32_machdep.h ptrace.h src/sys/arch/i386/i386: process_machdep.c src/sys/arch/i386/include: ptrace.h src/sys/arch/x86/include: cpu_extended_state.h fpu.h src/sys/arch/x86/x86: fpu.c src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_x86_wait.h Log Message: Implement PT_GETXSTATE and PT_SETXSTATE Introduce two new ptrace() requests: PT_GETXSTATE and PT_SETXSTATE, that provide access to the extended (and extensible) set of FPU registers on amd64 and i386. At the moment, this covers AVX (YMM) and AVX-512 (ZMM, opmask) registers. It can be easily extended to cover further register types without breaking backwards compatibility. PT_GETXSTATE issues the XSAVE instruction with all kernel-supported extended components enabled. The data is copied into 'struct xstate' (which -- unlike the XSAVE area itself -- has stable format and offsets). PT_SETXSTATE issues the XRSTOR instruction to restore the register values from user-provided 'struct xstate'. The function replaces only the specific XSAVE components that are listed in 'xs_rfbm' field, making it possible to issue partial updates. Both syscalls take a 'struct iovec' pointer rather than a direct argument. This requires the caller to explicitly specify the buffer size. As a result, existing code will continue to work correctly when the structure is extended (performing partial reads/updates). To generate a diff of this commit: cvs rdiff -u -r1.74 -r1.75 src/lib/libc/sys/ptrace.2 cvs rdiff -u -r1.123 -r1.124 src/sys/arch/amd64/amd64/netbsd32_machdep.c cvs rdiff -u -r1.39 -r1.40 src/sys/arch/amd64/amd64/process_machdep.c cvs rdiff -u -r1.23 -r1.24 src/sys/arch/amd64/include/netbsd32_machdep.h cvs rdiff -u -r1.15 -r1.16 src/sys/arch/amd64/include/ptrace.h cvs rdiff -u -r1.92 -r1.93 src/sys/arch/i386/i386/process_machdep.c cvs rdiff -u -r1.22 -r1.23 src/sys/arch/i386/include/ptrace.h cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x86/include/cpu_extended_state.h \ src/sys/arch/x86/include/fpu.h cvs rdiff -u -r1.53 -r1.54 src/sys/arch/x86/x86/fpu.c cvs rdiff -u -r1.128 -r1.129 src/tests/lib/libc/sys/t_ptrace_wait.c cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libc/sys/t_ptrace_x86_wait.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src
Module Name:src Committed By: mgorny Date: Wed Jun 26 12:30:13 UTC 2019 Modified Files: src/lib/libc/sys: ptrace.2 src/sys/arch/amd64/amd64: netbsd32_machdep.c process_machdep.c src/sys/arch/amd64/include: netbsd32_machdep.h ptrace.h src/sys/arch/i386/i386: process_machdep.c src/sys/arch/i386/include: ptrace.h src/sys/arch/x86/include: cpu_extended_state.h fpu.h src/sys/arch/x86/x86: fpu.c src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_x86_wait.h Log Message: Implement PT_GETXSTATE and PT_SETXSTATE Introduce two new ptrace() requests: PT_GETXSTATE and PT_SETXSTATE, that provide access to the extended (and extensible) set of FPU registers on amd64 and i386. At the moment, this covers AVX (YMM) and AVX-512 (ZMM, opmask) registers. It can be easily extended to cover further register types without breaking backwards compatibility. PT_GETXSTATE issues the XSAVE instruction with all kernel-supported extended components enabled. The data is copied into 'struct xstate' (which -- unlike the XSAVE area itself -- has stable format and offsets). PT_SETXSTATE issues the XRSTOR instruction to restore the register values from user-provided 'struct xstate'. The function replaces only the specific XSAVE components that are listed in 'xs_rfbm' field, making it possible to issue partial updates. Both syscalls take a 'struct iovec' pointer rather than a direct argument. This requires the caller to explicitly specify the buffer size. As a result, existing code will continue to work correctly when the structure is extended (performing partial reads/updates). To generate a diff of this commit: cvs rdiff -u -r1.74 -r1.75 src/lib/libc/sys/ptrace.2 cvs rdiff -u -r1.123 -r1.124 src/sys/arch/amd64/amd64/netbsd32_machdep.c cvs rdiff -u -r1.39 -r1.40 src/sys/arch/amd64/amd64/process_machdep.c cvs rdiff -u -r1.23 -r1.24 src/sys/arch/amd64/include/netbsd32_machdep.h cvs rdiff -u -r1.15 -r1.16 src/sys/arch/amd64/include/ptrace.h cvs rdiff -u -r1.92 -r1.93 src/sys/arch/i386/i386/process_machdep.c cvs rdiff -u -r1.22 -r1.23 src/sys/arch/i386/include/ptrace.h cvs rdiff -u -r1.16 -r1.17 src/sys/arch/x86/include/cpu_extended_state.h \ src/sys/arch/x86/include/fpu.h cvs rdiff -u -r1.53 -r1.54 src/sys/arch/x86/x86/fpu.c cvs rdiff -u -r1.128 -r1.129 src/tests/lib/libc/sys/t_ptrace_wait.c cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libc/sys/t_ptrace_x86_wait.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/sys/ptrace.2 diff -u src/lib/libc/sys/ptrace.2:1.74 src/lib/libc/sys/ptrace.2:1.75 --- src/lib/libc/sys/ptrace.2:1.74 Wed Jun 12 12:33:42 2019 +++ src/lib/libc/sys/ptrace.2 Wed Jun 26 12:30:12 2019 @@ -1,7 +1,7 @@ -.\" $NetBSD: ptrace.2,v 1.74 2019/06/12 12:33:42 wiz Exp $ +.\" $NetBSD: ptrace.2,v 1.75 2019/06/26 12:30:12 mgorny Exp $ .\" .\" This file is in the public domain. -.Dd June 12, 2019 +.Dd June 26, 2019 .Dt PTRACE 2 .Os .Sh NAME @@ -771,6 +771,69 @@ The argument contains the LWP ID of the thread whose registers are to be written. If zero is supplied, the first thread of the process is written. +.It Dv PT_GETXSTATE +This request reads the traced process' FPU extended state into +the +.Dq Li "struct xstate" +(defined in +.In machine/cpu_extended_state.h ) . +.Fa addr +should be a pointer to +.Dq Li "struct iovec" +(defined in +.In sys/uio.h ) +specifying the pointer to the aforementioned struct as +.Fa iov_base +and its size as +.Fa iov_len . +The +.Fa data +argument contains the LWP ID of the thread whose registers are to +be read. +If zero is supplied, the first thread of the process is read. +The struct will be filled up to the specified +.Fa iov_len . +The caller needs to check +.Fa xs_rfbm +bitmap in order to determine which fields were provided by the CPU, +and may check +.Fa xs_xstate_bv +to determine which component states were changed from the initial state. +.It Dv PT_SETXSTATE +This request is the converse of +.Dv PT_GETXSTATE ; +it loads the traced process' extended FPU state from the +.Dq Li "struct xstate" +(defined in +.In machine/cpu_extended_state.h ) . +.Fa addr +should be a pointer to +.Dq Li "struct iovec" +(defined in +.In sys/uio.h ) +specifying the pointer to the aforementioned struct as +.Fa iov_base +and its size as +.Fa iov_len . +The +.Fa data +argument contains the LWP ID of the thread whose registers are to +be written. +If zero is supplied, the first thread of the process is written. +The +.Fa xs_rfbm +field of the supplied xstate specifies which state components are to +be updated. Other components (fields) will be ignored. The +.Fa xs_xstate_bv +specifies whether component state should be set to provided values +(when 1) or reset to unitialized (when 0). The request +will fail if +.Fa xs_xstate_bv +is not a subset of +.Fa xs_rfbm , +or any of the specified components is not supported by the CPU or
CVS commit: src/sys/arch/x86
Module Name:src Committed By: mgorny Date: Wed Jun 26 12:29:01 UTC 2019 Modified Files: src/sys/arch/x86/include: cpu.h specialreg.h src/sys/arch/x86/x86: identcpu.c Log Message: Fetch XSAVE area component offsets and sizes when initializing x86 CPU Introduce two new arrays, x86_xsave_offsets and x86_xsave_sizes, and initialize them with XSAVE area component offsets and sizes queried via CPUID. This will be needed to implement getters and setters for additional register types. While at it, add XSAVE_* constants corresponding to specific XSAVE components. To generate a diff of this commit: cvs rdiff -u -r1.106 -r1.107 src/sys/arch/x86/include/cpu.h cvs rdiff -u -r1.147 -r1.148 src/sys/arch/x86/include/specialreg.h cvs rdiff -u -r1.91 -r1.92 src/sys/arch/x86/x86/identcpu.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/arch/amd64/amd64
Module Name:src Committed By: mgorny Date: Tue Jun 4 16:30:19 UTC 2019 Modified Files: src/sys/arch/amd64/amd64: netbsd32_machdep.c Log Message: compat32: Implement PT_GETDBREGS and PT_SETDBREGS Uncomment and improve the implementation of compat32 support for PT_GETDBREGS and PT_SETDBREGS requests. The new implementation uses x86_dbregs_read() and x86_dbregs_write() function instead of accessing pcb directly. While this might be a little slower, it guarantees that the needed pcb field is allocated correctly. Furthermore, the code introduces necessary sanity checks for PT_SETDBREGS arguments. To generate a diff of this commit: cvs rdiff -u -r1.122 -r1.123 src/sys/arch/amd64/amd64/netbsd32_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/netbsd32_machdep.c diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.122 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.123 --- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.122 Tue Jun 4 16:29:53 2019 +++ src/sys/arch/amd64/amd64/netbsd32_machdep.c Tue Jun 4 16:30:19 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_machdep.c,v 1.122 2019/06/04 16:29:53 mgorny Exp $ */ +/* $NetBSD: netbsd32_machdep.c,v 1.123 2019/06/04 16:30:19 mgorny Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.122 2019/06/04 16:29:53 mgorny Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.123 2019/06/04 16:30:19 mgorny Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -395,23 +395,19 @@ netbsd32_process_read_fpregs(struct lwp int netbsd32_process_read_dbregs(struct lwp *l, struct dbreg32 *regs, size_t *sz) { -#if notyet - struct pcb *pcb; - - pcb = lwp_getpcb(l); + struct dbreg regs64; - regs->dr[0] = pcb->pcb_dbregs->dr[0] & 0x; - regs->dr[1] = pcb->pcb_dbregs->dr[1] & 0x; - regs->dr[2] = pcb->pcb_dbregs->dr[2] & 0x; - regs->dr[3] = pcb->pcb_dbregs->dr[3] & 0x; + x86_dbregs_read(l, ); + memset(regs, 0, sizeof(*regs)); + regs->dr[0] = regs64.dr[0] & 0x; + regs->dr[1] = regs64.dr[1] & 0x; + regs->dr[2] = regs64.dr[2] & 0x; + regs->dr[3] = regs64.dr[3] & 0x; - regs->dr[6] = pcb->pcb_dbregs->dr[6] & 0x; - regs->dr[7] = pcb->pcb_dbregs->dr[7] & 0x; + regs->dr[6] = regs64.dr[6] & 0x; + regs->dr[7] = regs64.dr[7] & 0x; return 0; -#else - return ENOTSUP; -#endif } int @@ -478,23 +474,29 @@ int netbsd32_process_write_dbregs(struct lwp *l, const struct dbreg32 *regs, size_t sz) { -#if notyet - struct pcb *pcb; + size_t i; + struct dbreg regs64; - pcb = lwp_getpcb(l); + /* Check that DR0-DR3 contain user-space address */ + for (i = 0; i < X86_DBREGS; i++) { + if (regs->dr[i] >= VM_MAXUSER_ADDRESS32) + return EINVAL; + } - pcb->pcb_dbregs->dr[0] = regs->dr[0]; - pcb->pcb_dbregs->dr[1] = regs->dr[1]; - pcb->pcb_dbregs->dr[2] = regs->dr[2]; - pcb->pcb_dbregs->dr[3] = regs->dr[3]; + if (regs->dr[7] & X86_DR7_GENERAL_DETECT_ENABLE) { + return EINVAL; + } - pcb->pcb_dbregs->dr[6] = regs->dr[6]; - pcb->pcb_dbregs->dr[7] = regs->dr[7]; + regs64.dr[0] = regs->dr[0]; + regs64.dr[1] = regs->dr[1]; + regs64.dr[2] = regs->dr[2]; + regs64.dr[3] = regs->dr[3]; + regs64.dr[6] = regs->dr[6]; + regs64.dr[7] = regs->dr[7]; + + x86_dbregs_write(l, ); return 0; -#else - return ENOTSUP; -#endif } int
CVS commit: src/sys/arch/amd64/amd64
Module Name:src Committed By: mgorny Date: Tue Jun 4 16:30:19 UTC 2019 Modified Files: src/sys/arch/amd64/amd64: netbsd32_machdep.c Log Message: compat32: Implement PT_GETDBREGS and PT_SETDBREGS Uncomment and improve the implementation of compat32 support for PT_GETDBREGS and PT_SETDBREGS requests. The new implementation uses x86_dbregs_read() and x86_dbregs_write() function instead of accessing pcb directly. While this might be a little slower, it guarantees that the needed pcb field is allocated correctly. Furthermore, the code introduces necessary sanity checks for PT_SETDBREGS arguments. To generate a diff of this commit: cvs rdiff -u -r1.122 -r1.123 src/sys/arch/amd64/amd64/netbsd32_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys
Module Name:src Committed By: mgorny Date: Tue Jun 4 16:29:53 UTC 2019 Modified Files: src/sys/arch/amd64/amd64: netbsd32_machdep.c src/sys/arch/amd64/include: netbsd32_machdep.h ptrace.h src/sys/compat/netbsd32: netbsd32_ptrace.c Log Message: compat32: Translate userland PT_* request values into kernel codes Currently, the compat32 passes PT_* request values to kernel functions without translation. This works fine for low PT_* requests that happen to have the same values both on i386 and amd64. However, for requests higher than PT_SETFPREGS, the value passed from userland (matching i386 const) does not match the correct kernel (amd64) request. As a result, e.g. when compat32 process calls PT_GETDBREGS, kernel actually processes it as PT_SETSTEP. To resolve this, introduce support for compat32 PT_* request translation. The interface is based on PTRACE_TRANSLATE_REQUEST32 macro that is defined to a mapping function on architectures needing it. In case of amd64, this function maps userland i386 PT_* values into appropriate amd64 PT_* values. For the time being, the two additional PT_GETXMMREGS and PT_SETXMMREGS requests are unsupported due to lack of matching free amd64 constant. To generate a diff of this commit: cvs rdiff -u -r1.121 -r1.122 src/sys/arch/amd64/amd64/netbsd32_machdep.c cvs rdiff -u -r1.22 -r1.23 src/sys/arch/amd64/include/netbsd32_machdep.h cvs rdiff -u -r1.13 -r1.14 src/sys/arch/amd64/include/ptrace.h cvs rdiff -u -r1.6 -r1.7 src/sys/compat/netbsd32/netbsd32_ptrace.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys
Module Name:src Committed By: mgorny Date: Tue Jun 4 16:29:53 UTC 2019 Modified Files: src/sys/arch/amd64/amd64: netbsd32_machdep.c src/sys/arch/amd64/include: netbsd32_machdep.h ptrace.h src/sys/compat/netbsd32: netbsd32_ptrace.c Log Message: compat32: Translate userland PT_* request values into kernel codes Currently, the compat32 passes PT_* request values to kernel functions without translation. This works fine for low PT_* requests that happen to have the same values both on i386 and amd64. However, for requests higher than PT_SETFPREGS, the value passed from userland (matching i386 const) does not match the correct kernel (amd64) request. As a result, e.g. when compat32 process calls PT_GETDBREGS, kernel actually processes it as PT_SETSTEP. To resolve this, introduce support for compat32 PT_* request translation. The interface is based on PTRACE_TRANSLATE_REQUEST32 macro that is defined to a mapping function on architectures needing it. In case of amd64, this function maps userland i386 PT_* values into appropriate amd64 PT_* values. For the time being, the two additional PT_GETXMMREGS and PT_SETXMMREGS requests are unsupported due to lack of matching free amd64 constant. To generate a diff of this commit: cvs rdiff -u -r1.121 -r1.122 src/sys/arch/amd64/amd64/netbsd32_machdep.c cvs rdiff -u -r1.22 -r1.23 src/sys/arch/amd64/include/netbsd32_machdep.h cvs rdiff -u -r1.13 -r1.14 src/sys/arch/amd64/include/ptrace.h cvs rdiff -u -r1.6 -r1.7 src/sys/compat/netbsd32/netbsd32_ptrace.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/amd64/amd64/netbsd32_machdep.c diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.121 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.122 --- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.121 Sun May 19 08:46:15 2019 +++ src/sys/arch/amd64/amd64/netbsd32_machdep.c Tue Jun 4 16:29:53 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_machdep.c,v 1.121 2019/05/19 08:46:15 maxv Exp $ */ +/* $NetBSD: netbsd32_machdep.c,v 1.122 2019/06/04 16:29:53 mgorny Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.121 2019/05/19 08:46:15 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.122 2019/06/04 16:29:53 mgorny Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -336,6 +336,28 @@ cpu_coredump32(struct lwp *l, struct cor #endif int +netbsd32_ptrace_translate_request(int req) +{ + + switch (req) + { + case 0 ... PT_FIRSTMACH - 1: return req; + case PT32_STEP: return PT_STEP; + case PT32_GETREGS: return PT_GETREGS; + case PT32_SETREGS: return PT_SETREGS; + case PT32_GETFPREGS: return PT_GETFPREGS; + case PT32_SETFPREGS: return PT_SETFPREGS; + case PT32_GETXMMREGS: return -1; + case PT32_SETXMMREGS: return -1; + case PT32_GETDBREGS: return PT_GETDBREGS; + case PT32_SETDBREGS: return PT_SETDBREGS; + case PT32_SETSTEP: return PT_SETSTEP; + case PT32_CLEARSTEP: return PT_CLEARSTEP; + default: return -1; + } +} + +int netbsd32_process_read_regs(struct lwp *l, struct reg32 *regs) { struct trapframe *tf = l->l_md.md_regs; Index: src/sys/arch/amd64/include/netbsd32_machdep.h diff -u src/sys/arch/amd64/include/netbsd32_machdep.h:1.22 src/sys/arch/amd64/include/netbsd32_machdep.h:1.23 --- src/sys/arch/amd64/include/netbsd32_machdep.h:1.22 Thu Feb 23 03:34:22 2017 +++ src/sys/arch/amd64/include/netbsd32_machdep.h Tue Jun 4 16:29:53 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_machdep.h,v 1.22 2017/02/23 03:34:22 kamil Exp $ */ +/* $NetBSD: netbsd32_machdep.h,v 1.23 2019/06/04 16:29:53 mgorny Exp $ */ #ifndef _MACHINE_NETBSD32_H_ #define _MACHINE_NETBSD32_H_ @@ -7,6 +7,22 @@ #include #include +/* + * i386 ptrace constants + * Please keep in sync with sys/arch/i386/include/ptrace.h. + */ +#define PT32_STEP (PT_FIRSTMACH + 0) +#define PT32_GETREGS (PT_FIRSTMACH + 1) +#define PT32_SETREGS (PT_FIRSTMACH + 2) +#define PT32_GETFPREGS (PT_FIRSTMACH + 3) +#define PT32_SETFPREGS (PT_FIRSTMACH + 4) +#define PT32_GETXMMREGS (PT_FIRSTMACH + 5) +#define PT32_SETXMMREGS (PT_FIRSTMACH + 6) +#define PT32_GETDBREGS (PT_FIRSTMACH + 7) +#define PT32_SETDBREGS (PT_FIRSTMACH + 8) +#define PT32_SETSTEP (PT_FIRSTMACH + 9) +#define PT32_CLEARSTEP (PT_FIRSTMACH + 10) + #define NETBSD32_POINTER_TYPE uint32_t typedef struct { NETBSD32_POINTER_TYPE i32; } netbsd32_pointer_t; @@ -151,6 +167,9 @@ struct x86_64_set_mtrr_args32 { #define NETBSD32_MID_MACHINE MID_I386 +/* Translate ptrace() PT_* request from 32-bit userland to kernel. */ +int netbsd32_ptrace_translate_request(int); + int netbsd32_process_read_regs(struct lwp *, struct reg32 *); int netbsd32_process_read_fpregs(struct lwp *, struct fpreg32 *, size_t *); int netbsd32_process_read_dbregs(struct lwp *, struct dbreg32 *, size_t *); Index:
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Tue Jun 4 12:17:42 UTC 2019 Modified Files: src/tests/lib/libc/sys: t_ptrace_x86_wait.h Log Message: Fix alignment of SSE filling data To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/tests/lib/libc/sys/t_ptrace_x86_wait.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Tue Jun 4 12:17:42 UTC 2019 Modified Files: src/tests/lib/libc/sys: t_ptrace_x86_wait.h Log Message: Fix alignment of SSE filling data To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/tests/lib/libc/sys/t_ptrace_x86_wait.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libc/sys/t_ptrace_x86_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.14 src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.15 --- src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.14 Tue Jun 4 12:17:05 2019 +++ src/tests/lib/libc/sys/t_ptrace_x86_wait.h Tue Jun 4 12:17:42 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_x86_wait.h,v 1.14 2019/06/04 12:17:05 mgorny Exp $ */ +/* $NetBSD: t_ptrace_x86_wait.h,v 1.15 2019/06/04 12:17:42 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -2600,7 +2600,7 @@ static __inline void get_xmm_regs(void* { const struct { uint64_t a, b; - } fill = {0x0F0F0F0F0F0F0F0F, 0x0F0F0F0F0F0F0F0F}; + } fill __aligned(16) = {0x0F0F0F0F0F0F0F0F, 0x0F0F0F0F0F0F0F0F}; __asm__ __volatile__( /* fill registers with clobber pattern */
CVS commit: src/sys/kern
Module Name:src Committed By: mgorny Date: Fri May 10 21:08:26 UTC 2019 Modified Files: src/sys/kern: sys_ptrace_common.c Log Message: Fix typo: PT_GETFOREGS -> PT_GETFPREGS (NFC) To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 src/sys/kern/sys_ptrace_common.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.