diff --git a/lib/libc/amd64/sys/ptrace.S b/lib/libc/amd64/sys/ptrace.S index 9c4628da8ce4..c367a4ea12d1 100644 --- a/lib/libc/amd64/sys/ptrace.S +++ b/lib/libc/amd64/sys/ptrace.S @@ -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) diff --git a/lib/libc/i386/sys/ptrace.S b/lib/libc/i386/sys/ptrace.S index e4bdf7cd28ff..d1942975fcd0 100644 --- a/lib/libc/i386/sys/ptrace.S +++ b/lib/libc/i386/sys/ptrace.S @@ -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) diff --git a/lib/libc/sys/ptrace.2 b/lib/libc/sys/ptrace.2 index 74798d27cfff..48802f42457e 100644 --- a/lib/libc/sys/ptrace.2 +++ b/lib/libc/sys/ptrace.2 @@ -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