From owner-svn-src-stable@freebsd.org Sat Sep 3 09:03:43 2016 Return-Path: Delivered-To: svn-src-stable@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 1F840BCDE1E; Sat, 3 Sep 2016 09:03:43 +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 D4DEBFBF; Sat, 3 Sep 2016 09:03:42 +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 u8393gU1074230; Sat, 3 Sep 2016 09:03:42 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u8393fM9074219; Sat, 3 Sep 2016 09:03:41 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201609030903.u8393fM9074219@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sat, 3 Sep 2016 09:03:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r305329 - in stable/11/lib/libc: amd64/sys arm/sys i386/sys include mips/sys powerpc/sys powerpc64/sys sparc64/sys sys X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Sep 2016 09:03:43 -0000 Author: kib Date: Sat Sep 3 09:03:40 2016 New Revision: 305329 URL: https://svnweb.freebsd.org/changeset/base/305329 Log: MFC r304928: Do not obliterate errno value in the main thread during ptrace(2) call on x86. MFC r304931: Follow ABI when calling __error from the ptrace(2) wrapper. MFC r305012: Rewrite ptrace(2) wrappers in C. MFC r305022: Restore the requirement of setting errno to zero before calling ptrace(2). Added: stable/11/lib/libc/sys/ptrace.c - copied unchanged from r305012, head/lib/libc/sys/ptrace.c Deleted: stable/11/lib/libc/amd64/sys/ptrace.S stable/11/lib/libc/arm/sys/ptrace.S stable/11/lib/libc/i386/sys/ptrace.S stable/11/lib/libc/mips/sys/ptrace.S stable/11/lib/libc/powerpc/sys/ptrace.S stable/11/lib/libc/powerpc64/sys/ptrace.S stable/11/lib/libc/sparc64/sys/ptrace.S Modified: stable/11/lib/libc/amd64/sys/Makefile.inc stable/11/lib/libc/arm/sys/Makefile.inc stable/11/lib/libc/i386/sys/Makefile.inc stable/11/lib/libc/include/libc_private.h stable/11/lib/libc/mips/sys/Makefile.inc stable/11/lib/libc/powerpc/sys/Makefile.inc stable/11/lib/libc/powerpc64/sys/Makefile.inc stable/11/lib/libc/sparc64/sys/Makefile.inc stable/11/lib/libc/sys/Makefile.inc stable/11/lib/libc/sys/ptrace.2 Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libc/amd64/sys/Makefile.inc ============================================================================== --- stable/11/lib/libc/amd64/sys/Makefile.inc Sat Sep 3 08:48:51 2016 (r305328) +++ stable/11/lib/libc/amd64/sys/Makefile.inc Sat Sep 3 09:03:40 2016 (r305329) @@ -4,7 +4,7 @@ SRCS+= amd64_get_fsbase.c amd64_get_gsbase.c amd64_set_fsbase.c \ amd64_set_gsbase.c __vdso_gettc.c -MDASM= vfork.S brk.S cerror.S exect.S getcontext.S ptrace.S \ +MDASM= vfork.S brk.S cerror.S exect.S getcontext.S \ sbrk.S setlogin.S sigreturn.S # Don't generate default code for these syscalls: Modified: stable/11/lib/libc/arm/sys/Makefile.inc ============================================================================== --- stable/11/lib/libc/arm/sys/Makefile.inc Sat Sep 3 08:48:51 2016 (r305328) +++ stable/11/lib/libc/arm/sys/Makefile.inc Sat Sep 3 09:03:40 2016 (r305329) @@ -2,7 +2,7 @@ SRCS+= __vdso_gettc.c -MDASM= Ovfork.S brk.S cerror.S ptrace.S sbrk.S shmat.S sigreturn.S syscall.S +MDASM= Ovfork.S brk.S cerror.S sbrk.S shmat.S sigreturn.S syscall.S # Don't generate default code for these syscalls: NOASM= break.o exit.o getlogin.o openbsd_poll.o sstk.o vfork.o yield.o Modified: stable/11/lib/libc/i386/sys/Makefile.inc ============================================================================== --- stable/11/lib/libc/i386/sys/Makefile.inc Sat Sep 3 08:48:51 2016 (r305328) +++ stable/11/lib/libc/i386/sys/Makefile.inc Sat Sep 3 09:03:40 2016 (r305329) @@ -8,7 +8,7 @@ SRCS+= i386_get_fsbase.c i386_get_gsbase i386_set_fsbase.c i386_set_gsbase.c i386_set_ioperm.c i386_set_ldt.c \ __vdso_gettc.c -MDASM= Ovfork.S brk.S cerror.S exect.S getcontext.S ptrace.S \ +MDASM= Ovfork.S brk.S cerror.S exect.S getcontext.S \ sbrk.S setlogin.S sigreturn.S syscall.S # Don't generate default code for these syscalls: Modified: stable/11/lib/libc/include/libc_private.h ============================================================================== --- stable/11/lib/libc/include/libc_private.h Sat Sep 3 08:48:51 2016 (r305328) +++ stable/11/lib/libc/include/libc_private.h Sat Sep 3 09:03:40 2016 (r305329) @@ -335,6 +335,7 @@ int __sys_openat(int, const char *, int int __sys_pselect(int, struct fd_set *, struct fd_set *, struct fd_set *, const struct timespec *, const __sigset_t *); +int __sys_ptrace(int, __pid_t, char *, int); int __sys_poll(struct pollfd *, unsigned, int); int __sys_ppoll(struct pollfd *, unsigned, const struct timespec *, const __sigset_t *); Modified: stable/11/lib/libc/mips/sys/Makefile.inc ============================================================================== --- stable/11/lib/libc/mips/sys/Makefile.inc Sat Sep 3 08:48:51 2016 (r305328) +++ stable/11/lib/libc/mips/sys/Makefile.inc Sat Sep 3 09:03:40 2016 (r305329) @@ -3,7 +3,7 @@ SRCS+= trivial-vdso_tc.c MDASM= Ovfork.S brk.S cerror.S exect.S \ - ptrace.S sbrk.S syscall.S + sbrk.S syscall.S # Don't generate default code for these syscalls: NOASM= break.o exit.o getlogin.o openbsd_poll.o sstk.o vfork.o yield.o Modified: stable/11/lib/libc/powerpc/sys/Makefile.inc ============================================================================== --- stable/11/lib/libc/powerpc/sys/Makefile.inc Sat Sep 3 08:48:51 2016 (r305328) +++ stable/11/lib/libc/powerpc/sys/Makefile.inc Sat Sep 3 09:03:40 2016 (r305329) @@ -1,6 +1,6 @@ # $FreeBSD$ -MDASM+= brk.S cerror.S exect.S ptrace.S sbrk.S setlogin.S +MDASM+= brk.S cerror.S exect.S sbrk.S setlogin.S # Don't generate default code for these syscalls: NOASM= break.o exit.o getlogin.o openbsd_poll.o sstk.o yield.o Modified: stable/11/lib/libc/powerpc64/sys/Makefile.inc ============================================================================== --- stable/11/lib/libc/powerpc64/sys/Makefile.inc Sat Sep 3 08:48:51 2016 (r305328) +++ stable/11/lib/libc/powerpc64/sys/Makefile.inc Sat Sep 3 09:03:40 2016 (r305329) @@ -1,6 +1,6 @@ # $FreeBSD$ -MDASM+= brk.S cerror.S exect.S ptrace.S sbrk.S setlogin.S +MDASM+= brk.S cerror.S exect.S sbrk.S setlogin.S # Don't generate default code for these syscalls: NOASM= break.o exit.o getlogin.o openbsd_poll.o sstk.o yield.o Modified: stable/11/lib/libc/sparc64/sys/Makefile.inc ============================================================================== --- stable/11/lib/libc/sparc64/sys/Makefile.inc Sat Sep 3 08:48:51 2016 (r305328) +++ stable/11/lib/libc/sparc64/sys/Makefile.inc Sat Sep 3 09:03:40 2016 (r305329) @@ -12,7 +12,7 @@ SRCS+= __sparc_sigtramp_setup.c \ CFLAGS+= -I${LIBC_SRCTOP}/sparc64/fpu -MDASM+= brk.S cerror.S exect.S ptrace.S sbrk.S setlogin.S sigaction1.S +MDASM+= brk.S cerror.S exect.S sbrk.S setlogin.S sigaction1.S # Don't generate default code for these syscalls: NOASM= break.o exit.o getlogin.o openbsd_poll.o sstk.o yield.o Modified: stable/11/lib/libc/sys/Makefile.inc ============================================================================== --- stable/11/lib/libc/sys/Makefile.inc Sat Sep 3 08:48:51 2016 (r305328) +++ stable/11/lib/libc/sys/Makefile.inc Sat Sep 3 09:03:40 2016 (r305329) @@ -48,6 +48,7 @@ INTERPOSED = \ poll \ ppoll \ pselect \ + ptrace \ read \ readv \ recvfrom \ Modified: stable/11/lib/libc/sys/ptrace.2 ============================================================================== --- stable/11/lib/libc/sys/ptrace.2 Sat Sep 3 08:48:51 2016 (r305328) +++ stable/11/lib/libc/sys/ptrace.2 Sat Sep 3 09:03:40 2016 (r305329) @@ -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 July 28, 2016 +.Dd August 29, 2016 .Dt PTRACE 2 .Os .Sh NAME @@ -900,13 +900,29 @@ argument is ignored. .Pp Additionally, other machine-specific requests can exist. .Sh RETURN VALUES +Most requests return 0 on success and \-1 on error. Some requests can cause .Fn ptrace to return \-1 -as a non-error value; to disambiguate, +as a non-error value, among them are +.Dv PT_READ_I +and +.Dv PT_READ_D , +which return the value read from the process memory on success. +To disambiguate, .Va errno can be set to 0 before the call and checked afterwards. +.Pp +The current +.Fn ptrace +implementation always sets +.Va errno +to 0 before calling into the kernel, both for historic reasons and for +consistency with other operating systems. +It is recommended to assign zero to +.Va errno +explicitly for forward compatibility. .Sh ERRORS The .Fn ptrace Copied: stable/11/lib/libc/sys/ptrace.c (from r305012, head/lib/libc/sys/ptrace.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/lib/libc/sys/ptrace.c Sat Sep 3 09:03:40 2016 (r305329, copy of r305012, head/lib/libc/sys/ptrace.c) @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016 The FreeBSD Foundation. + * All rights reserved. + * + * Portions of this software were developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include "libc_private.h" + +__weak_reference(_ptrace, ptrace); + +int +_ptrace(int request, pid_t pid, caddr_t addr, int data) +{ + + errno = 0; + return (__sys_ptrace(request, pid, addr, data)); +}