From owner-svn-src-all@freebsd.org Sat Aug 27 23:03:24 2016 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 DA14FB771AC; Sat, 27 Aug 2016 23:03:24 +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 9E327FD0; Sat, 27 Aug 2016 23:03:24 +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 u7RN3NKT078508; Sat, 27 Aug 2016 23:03:23 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7RN3N0D078505; Sat, 27 Aug 2016 23:03:23 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201608272303.u7RN3N0D078505@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sat, 27 Aug 2016 23:03:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r304928 - in head/lib/libc: amd64/sys i386/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.22 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: Sat, 27 Aug 2016 23:03:25 -0000 Author: kib Date: Sat Aug 27 23:03:23 2016 New Revision: 304928 URL: https://svnweb.freebsd.org/changeset/base/304928 Log: Do not obliterate errno value in the main thread during ptrace(2) call on x86. Since ptrace(2) syscall can return -1 for non-error situations, libc wrappers set errno to 0 before performing the syscall, as the service to the caller. On both i386 and amd64, the errno symbol was directly referenced, which only works correctly in single-threaded process. Change assembler wrappers for ptrace(2) to get current thread errno location by calling __error(). Allow __error interposing, as currently allowed in cerror(). Sponsored by: The FreeBSD Foundation MFC after: 1 week Modified: head/lib/libc/amd64/sys/ptrace.S head/lib/libc/i386/sys/ptrace.S head/lib/libc/sys/ptrace.2 Modified: head/lib/libc/amd64/sys/ptrace.S ============================================================================== --- head/lib/libc/amd64/sys/ptrace.S Sat Aug 27 22:43:41 2016 (r304927) +++ head/lib/libc/amd64/sys/ptrace.S Sat Aug 27 23:03:23 2016 (r304928) @@ -38,14 +38,16 @@ __FBSDID("$FreeBSD$"); #include "SYS.h" + .globl CNAME(__error) + .type CNAME(__error),@function + ENTRY(ptrace) - xorl %eax,%eax #ifdef PIC - movq PIC_GOT(CNAME(errno)),%r8 - movl %eax,(%r8) + callq PIC_PLT(CNAME(__error)) #else - movl %eax,CNAME(errno)(%rip) + callq CNAME(__error) #endif + movl $0,(%rax) mov $SYS_ptrace,%eax KERNCALL jb HIDENAME(cerror) Modified: head/lib/libc/i386/sys/ptrace.S ============================================================================== --- head/lib/libc/i386/sys/ptrace.S Sat Aug 27 22:43:41 2016 (r304927) +++ head/lib/libc/i386/sys/ptrace.S Sat Aug 27 23:03:23 2016 (r304928) @@ -38,16 +38,18 @@ __FBSDID("$FreeBSD$"); #include "SYS.h" + .globl CNAME(__error) + .type CNAME(__error),@function + ENTRY(ptrace) - xorl %eax,%eax #ifdef PIC - PIC_PROLOGUE - movl PIC_GOT(CNAME(errno)),%edx - movl %eax,(%edx) - PIC_EPILOGUE + PIC_PROLOGUE + call PIC_PLT(CNAME(__error)) + PIC_EPILOGUE #else - movl %eax,CNAME(errno) + call CNAME(__error) #endif + movl $0,(%eax) mov $SYS_ptrace,%eax KERNCALL jb HIDENAME(cerror) Modified: head/lib/libc/sys/ptrace.2 ============================================================================== --- head/lib/libc/sys/ptrace.2 Sat Aug 27 22:43:41 2016 (r304927) +++ head/lib/libc/sys/ptrace.2 Sat Aug 27 23:03:23 2016 (r304928) @@ -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 28, 2016 .Dt PTRACE 2 .Os .Sh NAME @@ -906,7 +906,13 @@ to return \-1 as a non-error value; to disambiguate, .Va errno -can be set to 0 before the call and checked afterwards. +is set to 0 in the libc wrapper for the +.Fn ptrace +system call and +.Fn ptrace +callers can reliably check +.Va errno +for non-zero value afterwards. .Sh ERRORS The .Fn ptrace