summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2016-09-03 09:03:40 +0000
committerkib <kib@FreeBSD.org>2016-09-03 09:03:40 +0000
commitd10386210203bc911e09b0465c917418f228e54a (patch)
treed03b21baad17eac18eb6bfc7a6f3169a669f0c84
parent833d85cdfebda1a68898dd0b713a501551739080 (diff)
downloadFreeBSD-src-d10386210203bc911e09b0465c917418f228e54a.zip
FreeBSD-src-d10386210203bc911e09b0465c917418f228e54a.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).
-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.S51
-rw-r--r--lib/libc/i386/sys/Makefile.inc2
-rw-r--r--lib/libc/i386/sys/ptrace.S57
-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.S61
-rw-r--r--lib/libc/powerpc64/sys/Makefile.inc2
-rw-r--r--lib/libc/powerpc64/sys/ptrace.S68
-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.220
-rw-r--r--lib/libc/sys/ptrace.c49
18 files changed, 76 insertions, 429 deletions
diff --git a/lib/libc/amd64/sys/Makefile.inc b/lib/libc/amd64/sys/Makefile.inc
index 36c5d39..d5d416f 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 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:
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 37549bf..02ca2f7 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 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
diff --git a/lib/libc/arm/sys/ptrace.S b/lib/libc/arm/sys/ptrace.S
deleted file mode 100644
index dade223..0000000
--- a/lib/libc/arm/sys/ptrace.S
+++ /dev/null
@@ -1,51 +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)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/i386/sys/Makefile.inc b/lib/libc/i386/sys/Makefile.inc
index 588237f..9bc2a56 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 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:
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/include/libc_private.h b/lib/libc/include/libc_private.h
index cf346f1..972eb29 100644
--- a/lib/libc/include/libc_private.h
+++ b/lib/libc/include/libc_private.h
@@ -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 *);
diff --git a/lib/libc/mips/sys/Makefile.inc b/lib/libc/mips/sys/Makefile.inc
index fb6bdf6..506c036 100644
--- a/lib/libc/mips/sys/Makefile.inc
+++ b/lib/libc/mips/sys/Makefile.inc
@@ -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
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 4948f67..6451d82 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 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
diff --git a/lib/libc/powerpc/sys/ptrace.S b/lib/libc/powerpc/sys/ptrace.S
deleted file mode 100644
index cff463d..0000000
--- a/lib/libc/powerpc/sys/ptrace.S
+++ /dev/null
@@ -1,61 +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))
-END(ptrace)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/powerpc64/sys/Makefile.inc b/lib/libc/powerpc64/sys/Makefile.inc
index 4948f67..6451d82 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 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
diff --git a/lib/libc/powerpc64/sys/ptrace.S b/lib/libc/powerpc64/sys/ptrace.S
deleted file mode 100644
index 69709dd..0000000
--- a/lib/libc/powerpc64/sys/ptrace.S
+++ /dev/null
@@ -1,68 +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
-END(ptrace)
-
- .section .note.GNU-stack,"",%progbits
diff --git a/lib/libc/sparc64/sys/Makefile.inc b/lib/libc/sparc64/sys/Makefile.inc
index 3edc729..4b11d05 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${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
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 c358e67..2778cad 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -48,6 +48,7 @@ INTERPOSED = \
poll \
ppoll \
pselect \
+ ptrace \
read \
readv \
recvfrom \
diff --git a/lib/libc/sys/ptrace.2 b/lib/libc/sys/ptrace.2
index b15b012..2cd26ee 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 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
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