From owner-svn-src-all@freebsd.org Mon Jun 12 21:15:44 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CBEC1C787F2; Mon, 12 Jun 2017 21:15:44 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A25107FB39; Mon, 12 Jun 2017 21:15:44 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v5CLFh3u096496; Mon, 12 Jun 2017 21:15:43 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v5CLFhcr096493; Mon, 12 Jun 2017 21:15:43 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201706122115.v5CLFhcr096493@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 12 Jun 2017 21:15:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r319875 - in head: lib/libc/sys sys/kern sys/sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Jun 2017 21:15:44 -0000 Author: kib Date: Mon Jun 12 21:15:43 2017 New Revision: 319875 URL: https://svnweb.freebsd.org/changeset/base/319875 Log: Add ptrace(PT_GET_SC_ARGS) command to return debuggee' current syscall arguments. Reviewed by: jhb (previous version) Sponsored by: The FreeBSD Foundation MFC after: 3 weeks Differential revision: https://reviews.freebsd.org/D11080 Modified: head/lib/libc/sys/ptrace.2 head/sys/kern/sys_process.c head/sys/sys/ptrace.h Modified: head/lib/libc/sys/ptrace.2 ============================================================================== --- head/lib/libc/sys/ptrace.2 Mon Jun 12 21:11:11 2017 (r319874) +++ head/lib/libc/sys/ptrace.2 Mon Jun 12 21:15:43 2017 (r319875) @@ -2,7 +2,7 @@ .\" $NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $ .\" .\" This file is in the public domain. -.Dd August 29, 2016 +.Dd June 11, 2017 .Dt PTRACE 2 .Os .Sh NAME @@ -643,6 +643,26 @@ and .Fa data arguments are used the same as for .Dv PT_CONTINUE. +.It Dv PT_GET_SC_ARGS +For the thread which is stopped in either +.Dv PL_FLAG_SCE +or +.Dv PL_FLAG_SCX +state, that is, on entry or exit to a syscall, +this request fetches the syscall arguments. +.Pp +The arguments are copied out into the buffer pointed to by the +.Fa addr +pointer, sequentially. +Each syscall argument is stored as the machine word. +Kernel copies out as many arguments as the syscall accepts, +see the +.Va pl_syscall_narg +member of the +.Vt struct ptrace_lwpinfo , +but not more than the +.Fa data +bytes in total are copied. .It Dv PT_FOLLOW_FORK This request controls tracing for new child processes of a traced process. If Modified: head/sys/kern/sys_process.c ============================================================================== --- head/sys/kern/sys_process.c Mon Jun 12 21:11:11 2017 (r319874) +++ head/sys/kern/sys_process.c Mon Jun 12 21:15:43 2017 (r319875) @@ -586,6 +586,7 @@ sys_ptrace(struct thread *td, struct ptrace_args *uap) struct ptrace_lwpinfo32 pl32; struct ptrace_vm_entry32 pve32; #endif + char args[nitems(td->td_sa.args) * sizeof(register_t)]; int ptevents; } r; void *addr; @@ -606,6 +607,7 @@ sys_ptrace(struct thread *td, struct ptrace_args *uap) case PT_GETFPREGS: case PT_GETDBREGS: case PT_LWPINFO: + case PT_GET_SC_ARGS: break; case PT_SETREGS: error = COPYIN(uap->addr, &r.reg, sizeof r.reg); @@ -663,6 +665,10 @@ sys_ptrace(struct thread *td, struct ptrace_args *uap) /* NB: The size in uap->data is validated in kern_ptrace(). */ error = copyout(&r.pl, uap->addr, uap->data); break; + case PT_GET_SC_ARGS: + error = copyout(r.args, uap->addr, MIN(uap->data, + sizeof(r.args))); + break; } return (error); @@ -739,6 +745,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, voi case PT_GET_EVENT_MASK: case PT_SET_EVENT_MASK: case PT_DETACH: + case PT_GET_SC_ARGS: sx_xlock(&proctree_lock); proctree_locked = 1; break; @@ -1008,6 +1015,28 @@ kern_ptrace(struct thread *td, int req, pid_t pid, voi CTR3(KTR_PTRACE, "PT_SET_EVENT_MASK: pid %d mask %#x -> %#x", p->p_pid, p->p_ptevents, tmp); p->p_ptevents = tmp; + break; + + case PT_GET_SC_ARGS: + CTR1(KTR_PTRACE, "PT_GET_SC_ARGS: pid %d", p->p_pid); + if ((td2->td_dbgflags & (TDB_SCE | TDB_SCX)) == 0 +#ifdef COMPAT_FREEBSD32 + || (wrap32 && !safe) +#endif + ) { + error = EINVAL; + break; + } + bzero(addr, sizeof(td2->td_sa.args)); +#ifdef COMPAT_FREEBSD32 + if (wrap32) + for (num = 0; num < nitems(td2->td_sa.args); num++) + ((uint32_t *)addr)[num] = (uint32_t) + td2->td_sa.args[num]; + else +#endif + bcopy(td2->td_sa.args, addr, td2->td_sa.narg * + sizeof(register_t)); break; case PT_STEP: Modified: head/sys/sys/ptrace.h ============================================================================== --- head/sys/sys/ptrace.h Mon Jun 12 21:11:11 2017 (r319874) +++ head/sys/sys/ptrace.h Mon Jun 12 21:15:43 2017 (r319875) @@ -69,6 +69,8 @@ #define PT_GET_EVENT_MASK 25 /* get mask of optional events */ #define PT_SET_EVENT_MASK 26 /* set mask of optional events */ +#define PT_GET_SC_ARGS 27 /* fetch syscall args */ + #define PT_GETREGS 33 /* get general-purpose registers */ #define PT_SETREGS 34 /* set general-purpose registers */ #define PT_GETFPREGS 35 /* get floating-point registers */