summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2016-09-03 11:09:47 +0000
committerkib <kib@FreeBSD.org>2016-09-03 11:09:47 +0000
commitbcdec745e0ba540a8e558e912b2150c232fb472e (patch)
treef12120064f01cf6d143a95837ef4a6e90cca7eae /lib
parent487da86387ce37bb7038e5186a991f82d0c7b330 (diff)
downloadFreeBSD-src-bcdec745e0ba540a8e558e912b2150c232fb472e.zip
FreeBSD-src-bcdec745e0ba540a8e558e912b2150c232fb472e.tar.gz
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).
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/amd64/sys/Makefile.inc2
-rw-r--r--lib/libc/amd64/sys/ptrace.S55
-rw-r--r--lib/libc/arm/sys/Makefile.inc2
-rw-r--r--lib/libc/arm/sys/ptrace.S49
-rw-r--r--lib/libc/i386/sys/Makefile.inc2
-rw-r--r--lib/libc/i386/sys/ptrace.S57
-rw-r--r--lib/libc/ia64/sys/Makefile.inc2
-rw-r--r--lib/libc/ia64/sys/ptrace.S41
-rw-r--r--lib/libc/include/libc_private.h1
-rw-r--r--lib/libc/mips/sys/Makefile.inc2
-rw-r--r--lib/libc/mips/sys/ptrace.S71
-rw-r--r--lib/libc/powerpc/sys/Makefile.inc2
-rw-r--r--lib/libc/powerpc/sys/ptrace.S60
-rw-r--r--lib/libc/powerpc64/sys/Makefile.inc2
-rw-r--r--lib/libc/powerpc64/sys/ptrace.S67
-rw-r--r--lib/libc/sparc64/sys/Makefile.inc2
-rw-r--r--lib/libc/sparc64/sys/ptrace.S57
-rw-r--r--lib/libc/sys/Makefile.inc1
-rw-r--r--lib/libc/sys/ptrace.210
-rw-r--r--lib/libc/sys/ptrace.c49
20 files changed, 67 insertions, 467 deletions
diff --git a/lib/libc/amd64/sys/Makefile.inc b/lib/libc/amd64/sys/Makefile.inc
index 32986c9fa..9e0a217 100644
--- a/lib/libc/amd64/sys/Makefile.inc
+++ b/lib/libc/amd64/sys/Makefile.inc
@@ -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 pipe.S ptrace.S \
+MDASM= vfork.S brk.S cerror.S exect.S getcontext.S pipe.S \
sbrk.S setlogin.S sigreturn.S
# Don't generate default code for these syscalls:
diff --git a/lib/libc/amd64/sys/ptrace.S b/lib/libc/amd64/sys/ptrace.S
deleted file mode 100644
index 9c4628d..0000000
--- a/lib/libc/amd64/sys/ptrace.S
+++ /dev/null
@@ -1,55 +0,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * 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, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
- */
-
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)ptrace.s 5.1 (Berkeley) 4/23/90"
-#endif /* SYSLIBC_SCCS and not lint */
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
-ENTRY(ptrace)
- xorl %eax,%eax
-#ifdef PIC
- movq PIC_GOT(CNAME(errno)),%r8
- movl %eax,(%r8)
-#else
- movl %eax,CNAME(errno)(%rip)
-#endif
- mov $SYS_ptrace,%eax
- KERNCALL
- jb HIDENAME(cerror)
- ret
-END(ptrace)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/arm/sys/Makefile.inc b/lib/libc/arm/sys/Makefile.inc
index fd251c8..9d47547 100644
--- a/lib/libc/arm/sys/Makefile.inc
+++ b/lib/libc/arm/sys/Makefile.inc
@@ -2,7 +2,7 @@
SRCS+= __vdso_gettc.c
-MDASM= Ovfork.S brk.S cerror.S pipe.S ptrace.S sbrk.S shmat.S sigreturn.S syscall.S
+MDASM= Ovfork.S brk.S cerror.S pipe.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
diff --git a/lib/libc/arm/sys/ptrace.S b/lib/libc/arm/sys/ptrace.S
deleted file mode 100644
index 876da32..0000000
--- a/lib/libc/arm/sys/ptrace.S
+++ /dev/null
@@ -1,49 +0,0 @@
-/* $NetBSD: ptrace.S,v 1.7 2003/08/07 16:42:04 agc Exp $ */
-
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * 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, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
- *
- * from: @(#)ptrace.s 5.1 (Berkeley) 4/23/90
- */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-#include "SYS.h"
-
-ENTRY(ptrace)
- stmfd sp!, {r0-r3, lr}
- sub sp, sp, #4 /* align stack */
- bl PIC_SYM(_C_LABEL(__error), PLT)
- add sp, sp, #4 /* unalign stack */
- mov r1, #0x00000000
- str r1, [r0]
- ldmfd sp!, {r0-r3, lr}
- SYSTRAP(ptrace)
- bcs PIC_SYM(CERROR, PLT)
- RET
-END(ptrace)
diff --git a/lib/libc/i386/sys/Makefile.inc b/lib/libc/i386/sys/Makefile.inc
index ce1fed5..1149526 100644
--- a/lib/libc/i386/sys/Makefile.inc
+++ b/lib/libc/i386/sys/Makefile.inc
@@ -8,7 +8,7 @@ SRCS+= i386_get_fsbase.c i386_get_gsbase.c i386_get_ioperm.c i386_get_ldt.c \
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 pipe.S ptrace.S \
+MDASM= Ovfork.S brk.S cerror.S exect.S getcontext.S pipe.S \
sbrk.S setlogin.S sigreturn.S syscall.S
# Don't generate default code for these syscalls:
diff --git a/lib/libc/i386/sys/ptrace.S b/lib/libc/i386/sys/ptrace.S
deleted file mode 100644
index e4bdf7c..0000000
--- a/lib/libc/i386/sys/ptrace.S
+++ /dev/null
@@ -1,57 +0,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * 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, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
- */
-
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)ptrace.s 5.1 (Berkeley) 4/23/90"
-#endif /* SYSLIBC_SCCS and not lint */
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
-ENTRY(ptrace)
- xorl %eax,%eax
-#ifdef PIC
- PIC_PROLOGUE
- movl PIC_GOT(CNAME(errno)),%edx
- movl %eax,(%edx)
- PIC_EPILOGUE
-#else
- movl %eax,CNAME(errno)
-#endif
- mov $SYS_ptrace,%eax
- KERNCALL
- jb HIDENAME(cerror)
- ret
-END(ptrace)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/ia64/sys/Makefile.inc b/lib/libc/ia64/sys/Makefile.inc
index 2846590..ae75ee0 100644
--- a/lib/libc/ia64/sys/Makefile.inc
+++ b/lib/libc/ia64/sys/Makefile.inc
@@ -2,7 +2,7 @@
SRCS+= __vdso_gettc.c
-MDASM+= Ovfork.S brk.S cerror.S exect.S fork.S getcontext.S pipe.S ptrace.S \
+MDASM+= Ovfork.S brk.S cerror.S exect.S fork.S getcontext.S pipe.S \
sbrk.S setlogin.S sigreturn.S swapcontext.S
# Don't generate default code for these syscalls:
diff --git a/lib/libc/ia64/sys/ptrace.S b/lib/libc/ia64/sys/ptrace.S
deleted file mode 100644
index b6d3abd..0000000
--- a/lib/libc/ia64/sys/ptrace.S
+++ /dev/null
@@ -1,41 +0,0 @@
-/* $NetBSD: ptrace.S,v 1.4 1996/11/08 00:51:24 cgd Exp $ */
-
-/*
- * Copyright (c) 1994, 1995 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Author: Chris G. Demetriou
- *
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
-ENTRY(ptrace, 4)
- add r14=@ltoff(errno),gp ;;
- ld8 r14=[r14] ;;
- st4 [r14]=r0
- CALLSYS_ERROR(ptrace)
- br.ret.sptk.few rp
-END(ptrace)
diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h
index c219f55..b6a6ff7 100644
--- a/lib/libc/include/libc_private.h
+++ b/lib/libc/include/libc_private.h
@@ -339,6 +339,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 *);
diff --git a/lib/libc/mips/sys/Makefile.inc b/lib/libc/mips/sys/Makefile.inc
index fc11349..380825a 100644
--- a/lib/libc/mips/sys/Makefile.inc
+++ b/lib/libc/mips/sys/Makefile.inc
@@ -3,7 +3,7 @@
SRCS+= __vdso_gettc.c
MDASM= Ovfork.S brk.S cerror.S exect.S \
- fork.S pipe.S ptrace.S sbrk.S syscall.S
+ fork.S pipe.S sbrk.S syscall.S
# Don't generate default code for these syscalls:
NOASM= break.o exit.o ftruncate.o getlogin.o lseek.o mmap.o \
diff --git a/lib/libc/mips/sys/ptrace.S b/lib/libc/mips/sys/ptrace.S
deleted file mode 100644
index 8cf984a9..0000000
--- a/lib/libc/mips/sys/ptrace.S
+++ /dev/null
@@ -1,71 +0,0 @@
-/* $NetBSD: ptrace.S,v 1.9 2003/08/07 16:42:17 agc Exp $ */
-
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Ralph Campbell.
- *
- * 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, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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 <machine/asm.h>
-__FBSDID("$FreeBSD$");
-#include "SYS.h"
-
-#if defined(LIBC_SCCS) && !defined(lint)
- ASMSTR("from: @(#)ptrace.s 8.1 (Berkeley) 6/4/93")
- ASMSTR("$NetBSD: ptrace.S,v 1.9 2003/08/07 16:42:17 agc Exp $")
-#endif /* LIBC_SCCS and not lint */
-
-NESTED_NOPROFILE(ptrace, CALLFRAME_SIZ, ra)
- .mask 0x80000000, (CALLFRAME_RA - CALLFRAME_SIZ)
- SETUP_GP
- PTR_SUBU sp, sp, CALLFRAME_SIZ
- SETUP_GP64(CALLFRAME_GP, ptrace)
- SAVE_GP(CALLFRAME_GP)
-
- PTR_S ra, CALLFRAME_RA(sp)
-
- PTR_LA t9, _C_LABEL(__error) # locate address of errno
- jalr t9
-
- PTR_L ra, CALLFRAME_RA(sp)
- INT_S zero, 0(v0) # update errno value
-
- li v0, SYS_ptrace
- syscall
-
- # Load __cerror's address using our gp, then restore it.
- PTR_LA t9, __cerror
- RESTORE_GP64
- PTR_ADDU sp, sp, CALLFRAME_SIZ
-
- bne a3, zero, 1f
-
- j ra
-1: j t9
-END(ptrace)
diff --git a/lib/libc/powerpc/sys/Makefile.inc b/lib/libc/powerpc/sys/Makefile.inc
index 5193cc2..f590c76 100644
--- a/lib/libc/powerpc/sys/Makefile.inc
+++ b/lib/libc/powerpc/sys/Makefile.inc
@@ -1,6 +1,6 @@
# $FreeBSD$
-MDASM+= brk.S cerror.S exect.S pipe.S ptrace.S sbrk.S setlogin.S
+MDASM+= brk.S cerror.S exect.S pipe.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
diff --git a/lib/libc/powerpc/sys/ptrace.S b/lib/libc/powerpc/sys/ptrace.S
deleted file mode 100644
index 0bc25c9..0000000
--- a/lib/libc/powerpc/sys/ptrace.S
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-
- * Copyright (c) 2002 Peter Grehan.
- * All rights reserved.
- *
- * 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, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, 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 AUTHOR AND CONTRIBUTORS ``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 AUTHOR OR CONTRIBUTORS 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.
- */
-/* $NetBSD: ptrace.S,v 1.3 2000/02/23 20:16:57 kleink Exp $ */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
-ENTRY(ptrace)
- mflr %r0
- stwu %r1,-32(%r1)
- stw %r0,36(%r1)
- stw %r3,8(%r1)
- stw %r4,12(%r1)
- stw %r5,16(%r1)
- stw %r6,20(%r1)
-
- bl PIC_PLT(CNAME(__error))
- li %r7,0
- stw %r7,0(%r3)
-
- lwz %r3,8(%r1)
- lwz %r4,12(%r1)
- lwz %r5,16(%r1)
- lwz %r0,36(%r1)
- lwz %r6,20(%r1)
- mtlr %r0
- la %r1,32(%r1)
- li %r0,SYS_ptrace
- sc
- bso 1f
- blr
-1:
- b PIC_PLT(HIDENAME(cerror))
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/powerpc64/sys/Makefile.inc b/lib/libc/powerpc64/sys/Makefile.inc
index 5193cc2..f590c76 100644
--- a/lib/libc/powerpc64/sys/Makefile.inc
+++ b/lib/libc/powerpc64/sys/Makefile.inc
@@ -1,6 +1,6 @@
# $FreeBSD$
-MDASM+= brk.S cerror.S exect.S pipe.S ptrace.S sbrk.S setlogin.S
+MDASM+= brk.S cerror.S exect.S pipe.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
diff --git a/lib/libc/powerpc64/sys/ptrace.S b/lib/libc/powerpc64/sys/ptrace.S
deleted file mode 100644
index ede00e7..0000000
--- a/lib/libc/powerpc64/sys/ptrace.S
+++ /dev/null
@@ -1,67 +0,0 @@
-/*-
- * Copyright (c) 2002 Peter Grehan.
- * All rights reserved.
- *
- * 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, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, 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 AUTHOR AND CONTRIBUTORS ``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 AUTHOR OR CONTRIBUTORS 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.
- */
-/* $NetBSD: ptrace.S,v 1.3 2000/02/23 20:16:57 kleink Exp $ */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
-ENTRY(ptrace)
- mflr %r0
- std %r0,16(%r1)
- stdu %r1,-80(%r1)
- stw %r3,48(%r1)
- stw %r4,52(%r1)
- std %r5,56(%r1)
- stw %r6,64(%r1)
-
- bl CNAME(__error)
- nop
- li %r7,0
- stw %r7,0(%r3)
-
- lwz %r3,48(%r1)
- lwz %r4,52(%r1)
- ld %r5,56(%r1)
- lwz %r6,64(%r1)
- ld %r1,0(%r1)
- ld %r0,16(%r1)
- mtlr %r0
- li %r0,SYS_ptrace
- sc
- bso 1f
- blr
-1:
- stdu %r1,-48(%r1) /* lr already saved */
- bl HIDENAME(cerror)
- nop
- ld %r1,0(%r1)
- ld %r0,16(%r1)
- mtlr %r0
- blr
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/sparc64/sys/Makefile.inc b/lib/libc/sparc64/sys/Makefile.inc
index d1b4b2d..9678c2e 100644
--- a/lib/libc/sparc64/sys/Makefile.inc
+++ b/lib/libc/sparc64/sys/Makefile.inc
@@ -12,7 +12,7 @@ SRCS+= __sparc_sigtramp_setup.c \
CFLAGS+= -I${.CURDIR}/sparc64/fpu
-MDASM+= brk.S cerror.S exect.S pipe.S ptrace.S sbrk.S setlogin.S sigaction1.S
+MDASM+= brk.S cerror.S exect.S pipe.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
diff --git a/lib/libc/sparc64/sys/ptrace.S b/lib/libc/sparc64/sys/ptrace.S
deleted file mode 100644
index eb415cd..0000000
--- a/lib/libc/sparc64/sys/ptrace.S
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This software was developed by the Computer Systems Engineering group
- * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
- * contributed to Berkeley.
- *
- * 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, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
- *
- * from: Header: ptrace.s,v 1.2 91/12/20 01:59:00 leres Exp
- * from: NetBSD: ptrace.S,v 1.4 2000/07/24 00:11:10 mycroft Exp
- */
-
-#if defined(SYSLIBC_SCCS) && !defined(lint)
- .asciz "@(#)ptrace.s 8.1 (Berkeley) 6/4/93"
-#if 0
- RCSID("$NetBSD: ptrace.S,v 1.4 2000/07/24 00:11:10 mycroft Exp $")
-#endif
-#endif /* SYSLIBC_SCCS and not lint */
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#include "SYS.h"
-
-_SYSENTRY(ptrace)
- save %sp, -CCFSZ, %sp
- call CNAME(__error)
- nop
- stw %g0, [%o0]
- restore
- _SYSCALL(ptrace)
- retl
- nop
-_SYSEND(ptrace)
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index 25bd4a3..0da0f82 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -59,6 +59,7 @@ INTERPOSED = \
poll \
ppoll \
pselect \
+ ptrace \
read \
readv \
recvfrom \
diff --git a/lib/libc/sys/ptrace.2 b/lib/libc/sys/ptrace.2
index eae19cd..6dffefc 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
diff --git a/lib/libc/sys/ptrace.c b/lib/libc/sys/ptrace.c
new file mode 100644
index 0000000..2bb615f
--- /dev/null
+++ b/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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/ptrace.h>
+#include <errno.h>
+#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));
+}
OpenPOWER on IntegriCloud