Date: Sat, 27 Aug 2016 23:03:23 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> 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 Message-ID: <201608272303.u7RN3N0D078505@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201608272303.u7RN3N0D078505>