From 12a1c9434d6e284a4bf07e498e91f4ae601ce172 Mon Sep 17 00:00:00 2001 From: kib Date: Thu, 1 Sep 2016 07:23:47 +0000 Subject: MFC r305024: Typesetting fixes. --- lib/libc/sys/ptrace.2 | 82 +++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/sys/ptrace.2 b/lib/libc/sys/ptrace.2 index 0e8c8bd..eae19cd 100644 --- a/lib/libc/sys/ptrace.2 +++ b/lib/libc/sys/ptrace.2 @@ -104,7 +104,7 @@ Each traced process has a tracing event mask. An event in the traced process only reports a signal stop if the corresponding flag is set in the tracing event mask. The current set of tracing event flags include: -.Bl -tag -width ".Dv PTRACE_SYSCALL" +.Bl -tag -width "Dv PTRACE_SYSCALL" .It Dv PTRACE_EXEC Report a stop for a successful invocation of .Xr execve 2 . @@ -231,7 +231,7 @@ The .Fa request argument can be: -.Bl -tag -width 12n +.Bl -tag -width "Dv PT_GET_EVENT_MASK" .It Dv PT_TRACE_ME This request is the only one used by the traced process; it declares that the process expects to be traced by its parent. @@ -469,31 +469,31 @@ The fields in the .Vt "struct ptrace_lwpinfo" have the following meaning: .Bl -tag -width indent -compact -.It pl_lwpid +.It Va pl_lwpid LWP id of the thread -.It pl_event +.It Va pl_event Event that caused the stop. -Currently defined events are -.Bl -tag -width indent -compact -.It PL_EVENT_NONE +Currently defined events are: +.Bl -tag -width "Dv PL_EVENT_SIGNAL" -compact +.It Dv PL_EVENT_NONE No reason given -.It PL_EVENT_SIGNAL +.It Dv PL_EVENT_SIGNAL Thread stopped due to the pending signal .El -.It pl_flags +.It Va pl_flags Flags that specify additional details about observed stop. Currently defined flags are: .Bl -tag -width indent -compact -.It PL_FLAG_SCE +.It Dv PL_FLAG_SCE The thread stopped due to system call entry, right after the kernel is entered. The debugger may examine syscall arguments that are stored in memory and registers according to the ABI of the current process, and modify them, if needed. -.It PL_FLAG_SCX +.It Dv PL_FLAG_SCX The thread is stopped immediately before syscall is returning to the usermode. The debugger may examine system call return values in the ABI-defined registers and/or memory. -.It PL_FLAG_EXEC +.It Dv PL_FLAG_EXEC When .Dv PL_FLAG_SCX is set, this flag may be additionally specified to inform that the @@ -501,13 +501,13 @@ program being executed by debuggee process has been changed by successful execution of a system call from the .Fn execve 2 family. -.It PL_FLAG_SI +.It Dv PL_FLAG_SI Indicates that .Va pl_siginfo member of .Vt "struct ptrace_lwpinfo" contains valid information. -.It PL_FLAG_FORKED +.It Dv PL_FLAG_FORKED Indicates that the process is returning from a call to .Fn fork 2 that created a new child process. @@ -515,42 +515,42 @@ The process identifier of the new process is available in the .Va pl_child_pid member of .Vt "struct ptrace_lwpinfo" . -.It PL_FLAG_CHILD +.It Dv PL_FLAG_CHILD The flag is set for first event reported from a new child which is automatically attached when .Dv PTRACE_FORK is enabled. -.It PL_FLAG_BORN +.It Dv PL_FLAG_BORN This flag is set for the first event reported from a new LWP when .Dv PTRACE_LWP is enabled. It is reported along with .Dv PL_FLAG_SCX . -.It PL_FLAG_EXITED +.It Dv PL_FLAG_EXITED This flag is set for the last event reported by an exiting LWP when .Dv PTRACE_LWP is enabled. Note that this event is not reported when the last LWP in a process exits. The termination of the last thread is reported via a normal process exit event. -.It PL_FLAG_VFORKED +.It Dv PL_FLAG_VFORKED Indicates that the thread is returning from a call to .Xr vfork 2 that created a new child process. This flag is set in addition to .Dv PL_FLAG_FORKED . -.It PL_FLAG_VFORK_DONE +.It Dv PL_FLAG_VFORK_DONE Indicates that the thread has resumed after a child process created via .Xr vfork 2 has stopped sharing its address space with the traced process. .El -.It pl_sigmask +.It Va pl_sigmask The current signal mask of the LWP -.It pl_siglist +.It Va pl_siglist The current pending set of signals for the LWP. Note that signals that are delivered to the process would not appear on an LWP siglist until the thread is selected for delivery. -.It pl_siginfo +.It Va pl_siginfo The siginfo that accompanies the signal pending. Only valid for .Dv PL_EVENT_SIGNAL @@ -558,9 +558,9 @@ stop when .Dv PL_FLAG_SI is set in .Va pl_flags . -.It pl_tdname +.It Va pl_tdname The name of the thread. -.It pl_child_pid +.It Va pl_child_pid The process identifier of the new child process. Only valid for a .Dv PL_EVENT_SIGNAL @@ -568,7 +568,7 @@ stop when .Dv PL_FLAG_FORKED is set in .Va pl_flags . -.It pl_syscall_code +.It Va pl_syscall_code The ABI-specific identifier of the current system call. Note that for indirect system calls this field reports the indirected system call. @@ -578,7 +578,7 @@ or .Dv PL_FLAG_SCX is set in .Va pl_flags. -.It pl_syscall_narg +.It Va pl_syscall_narg The number of arguments passed to the current system call not counting the system call identifier. Note that for indirect system calls this field reports the arguments @@ -590,10 +590,10 @@ or is set in .Va pl_flags. .El -.It PT_GETNUMLWPS +.It Dv PT_GETNUMLWPS This request returns the number of kernel threads associated with the traced process. -.It PT_GETLWPLIST +.It Dv PT_GETLWPLIST This request can be used to get the current thread list. A pointer to an array of type .Vt lwpid_t @@ -604,15 +604,15 @@ with the array size specified by The return value from .Fn ptrace is the count of array entries filled in. -.It PT_SETSTEP +.It Dv PT_SETSTEP This request will turn on single stepping of the specified process. -.It PT_CLEARSTEP +.It Dv PT_CLEARSTEP This request will turn off single stepping of the specified process. -.It PT_SUSPEND +.It Dv PT_SUSPEND This request will suspend the specified thread. -.It PT_RESUME +.It Dv PT_RESUME This request will resume the specified thread. -.It PT_TO_SCE +.It Dv PT_TO_SCE This request will set the .Dv PTRACE_SCE event flag to trace all future system call entries and continue the process. @@ -622,7 +622,7 @@ and .Fa data arguments are used the same as for .Dv PT_CONTINUE. -.It PT_TO_SCX +.It Dv PT_TO_SCX This request will set the .Dv PTRACE_SCX event flag to trace all future system call exits and continue the process. @@ -632,7 +632,7 @@ and .Fa data arguments are used the same as for .Dv PT_CONTINUE. -.It PT_SYSCALL +.It Dv PT_SYSCALL This request will set the .Dv PTRACE_SYSCALL event flag to trace all future system call entries and exits and continue @@ -643,7 +643,7 @@ and .Fa data arguments are used the same as for .Dv PT_CONTINUE. -.It PT_FOLLOW_FORK +.It Dv PT_FOLLOW_FORK This request controls tracing for new child processes of a traced process. If .Fa data @@ -655,7 +655,7 @@ If is zero, .Dv PTRACE_FORK is cleared from the traced process's event tracing mask. -.It PT_LWP_EVENTS +.It Dv PT_LWP_EVENTS This request controls tracing of LWP creation and destruction. If .Fa data @@ -667,25 +667,25 @@ If is zero, .Dv PTRACE_LWP is cleared from the traced process's event tracing mask. -.It PT_GET_EVENT_MASK +.It Dv PT_GET_EVENT_MASK This request reads the traced process's event tracing mask into the integer pointed to by .Fa addr . The size of the integer must be passed in .Fa data . -.It PT_SET_EVENT_MASK +.It Dv PT_SET_EVENT_MASK This request sets the traced process's event tracing mask from the integer pointed to by .Fa addr . The size of the integer must be passed in .Fa data . -.It PT_VM_TIMESTAMP +.It Dv PT_VM_TIMESTAMP This request returns the generation number or timestamp of the memory map of the traced process as the return value from .Fn ptrace . This provides a low-cost way for the tracing process to determine if the VM map changed since the last time this request was made. -.It PT_VM_ENTRY +.It Dv PT_VM_ENTRY This request is used to iterate over the entries of the VM map of the traced process. The -- cgit v1.1 From 75663f22d75f86aa3f5efc5cadbcff791f66b4f9 Mon Sep 17 00:00:00 2001 From: ngie Date: Fri, 2 Sep 2016 04:12:36 +0000 Subject: MFstable/11 r304950: MFC r304033: Increase timeout from 10 minutes to 20 minutes for all tests On particular slow networks, it can (on average) take longer to resolve hosts to IP* addresses. 20 minutes seemed reasonable for my work network This will be solved in a more meaningful way (if possible) using concurrency in the near future --- lib/libc/tests/resolv/resolv_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/tests/resolv/resolv_test.c b/lib/libc/tests/resolv/resolv_test.c index 74e89b1..1da42e3 100644 --- a/lib/libc/tests/resolv/resolv_test.c +++ b/lib/libc/tests/resolv/resolv_test.c @@ -291,7 +291,7 @@ do { \ ATF_TC(getaddrinfo_test); ATF_TC_HEAD(getaddrinfo_test, tc) { - atf_tc_set_md_var(tc, "timeout", "450"); + atf_tc_set_md_var(tc, "timeout", "1200"); } ATF_TC_BODY(getaddrinfo_test, tc) { @@ -301,7 +301,7 @@ ATF_TC_BODY(getaddrinfo_test, tc) ATF_TC(gethostby_test); ATF_TC_HEAD(gethostby_test, tc) { - atf_tc_set_md_var(tc, "timeout", "450"); + atf_tc_set_md_var(tc, "timeout", "1200"); } ATF_TC_BODY(gethostby_test, tc) { @@ -312,7 +312,7 @@ ATF_TC_BODY(gethostby_test, tc) ATF_TC(getipnodeby_test); ATF_TC_HEAD(getipnodeby_test, tc) { - atf_tc_set_md_var(tc, "timeout", "450"); + atf_tc_set_md_var(tc, "timeout", "1200"); } ATF_TC_BODY(getipnodeby_test, tc) { -- cgit v1.1 From 487da86387ce37bb7038e5186a991f82d0c7b330 Mon Sep 17 00:00:00 2001 From: ache Date: Sat, 3 Sep 2016 01:08:52 +0000 Subject: MFC r305133 Apply the same qsort() usage fix as in r304911 getaddrinfo.c qsort() can't be stabilized with just return(-1) alone. --- lib/libc/net/name6.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib/libc') diff --git a/lib/libc/net/name6.c b/lib/libc/net/name6.c index ebae9d3..b34580e 100644 --- a/lib/libc/net/name6.c +++ b/lib/libc/net/name6.c @@ -186,6 +186,7 @@ struct hp_order { #define aio_sa aio_un.aiou_sa int aio_matchlen; char *aio_h_addr; + int aio_initial_sequence; }; static struct hostent *_hpcopy(struct hostent *, int *); @@ -711,6 +712,7 @@ _hpreorder(struct hostent *hp) aio[i].aio_dstscope = gai_addr2scopetype(sa); aio[i].aio_dstpolicy = match_addrselectpolicy(sa, &policyhead); set_source(&aio[i], &policyhead); + aio[i].aio_initial_sequence = i; } /* perform sorting. */ @@ -1045,6 +1047,23 @@ comp_dst(const void *arg1, const void *arg2) } /* Rule 10: Otherwise, leave the order unchanged. */ + + /* + * Note that qsort is unstable; so, we can't return zero and + * expect the order to be unchanged. + * That also means we can't depend on the current position of + * dst2 being after dst1. We must enforce the initial order + * with an explicit compare on the original position. + * The qsort specification requires that "When the same objects + * (consisting of width bytes, irrespective of their current + * positions in the array) are passed more than once to the + * comparison function, the results shall be consistent with one + * another." + * In other words, If A < B, then we must also return B > A. + */ + if (dst2->aio_initial_sequence < dst1->aio_initial_sequence) + return(1); + return(-1); } -- cgit v1.1 From bcdec745e0ba540a8e558e912b2150c232fb472e Mon Sep 17 00:00:00 2001 From: kib Date: Sat, 3 Sep 2016 11:09:47 +0000 Subject: 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). --- lib/libc/amd64/sys/Makefile.inc | 2 +- lib/libc/amd64/sys/ptrace.S | 55 ---------------------------- lib/libc/arm/sys/Makefile.inc | 2 +- lib/libc/arm/sys/ptrace.S | 49 ------------------------- lib/libc/i386/sys/Makefile.inc | 2 +- lib/libc/i386/sys/ptrace.S | 57 ----------------------------- lib/libc/ia64/sys/Makefile.inc | 2 +- lib/libc/ia64/sys/ptrace.S | 41 --------------------- lib/libc/include/libc_private.h | 1 + lib/libc/mips/sys/Makefile.inc | 2 +- lib/libc/mips/sys/ptrace.S | 71 ------------------------------------- lib/libc/powerpc/sys/Makefile.inc | 2 +- lib/libc/powerpc/sys/ptrace.S | 60 ------------------------------- lib/libc/powerpc64/sys/Makefile.inc | 2 +- lib/libc/powerpc64/sys/ptrace.S | 67 ---------------------------------- lib/libc/sparc64/sys/Makefile.inc | 2 +- lib/libc/sparc64/sys/ptrace.S | 57 ----------------------------- lib/libc/sys/Makefile.inc | 1 + lib/libc/sys/ptrace.2 | 10 ++++-- lib/libc/sys/ptrace.c | 49 +++++++++++++++++++++++++ 20 files changed, 67 insertions(+), 467 deletions(-) delete mode 100644 lib/libc/amd64/sys/ptrace.S delete mode 100644 lib/libc/arm/sys/ptrace.S delete mode 100644 lib/libc/i386/sys/ptrace.S delete mode 100644 lib/libc/ia64/sys/ptrace.S delete mode 100644 lib/libc/mips/sys/ptrace.S delete mode 100644 lib/libc/powerpc/sys/ptrace.S delete mode 100644 lib/libc/powerpc64/sys/ptrace.S delete mode 100644 lib/libc/sparc64/sys/ptrace.S create mode 100644 lib/libc/sys/ptrace.c (limited to 'lib/libc') 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 -__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 -__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 -__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 -__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 -__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 -__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 -__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 -__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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#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)); +} -- cgit v1.1 From 1e309d41a8764622d76a93336df84be6bce2da29 Mon Sep 17 00:00:00 2001 From: ache Date: Sun, 4 Sep 2016 00:34:15 +0000 Subject: MFC r305219 If error happens, don't overwrite original errno comes from __mbrtowc() and __srefill(). --- lib/libc/stdio/fgetwc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/stdio/fgetwc.c b/lib/libc/stdio/fgetwc.c index cf649fd..3074d44 100644 --- a/lib/libc/stdio/fgetwc.c +++ b/lib/libc/stdio/fgetwc.c @@ -84,9 +84,10 @@ __fgetwc_mbs(FILE *fp, mbstate_t *mbs, int *nread, locale_t locale) return (WEOF); do { nconv = l->__mbrtowc(&wc, fp->_p, fp->_r, mbs); - if (nconv == (size_t)-1) - break; - else if (nconv == (size_t)-2) + if (nconv == (size_t)-1) { + fp->_flags |= __SERR; + return (WEOF); + } else if (nconv == (size_t)-2) continue; else if (nconv == 0) { fp->_p++; @@ -100,7 +101,9 @@ __fgetwc_mbs(FILE *fp, mbstate_t *mbs, int *nread, locale_t locale) return (wc); } } while (__srefill(fp) == 0); - fp->_flags |= __SERR; - errno = EILSEQ; + if (__sfeof(fp)) { + fp->_flags |= __SERR; + errno = EILSEQ; + } return (WEOF); } -- cgit v1.1 From 3d5d624919bed2dbb0c49b5fb0e538a47b69aca2 Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 5 Sep 2016 00:36:52 +0000 Subject: MFC r305144 'addrlen' does not matter when we need to find the first non-zero bit in the byte from the left and 'addrlen' already counted in 'lim'. PR: 212121 Submitted by: Herbie.Robinson@stratus.com --- lib/libc/net/getaddrinfo.c | 2 +- lib/libc/net/name6.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index c5bfc5e..ec22570 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -931,7 +931,7 @@ matchlen(struct sockaddr *src, struct sockaddr *dst) while (s < lim) if ((r = (*d++ ^ *s++)) != 0) { - while (r < addrlen * 8) { + while ((r & 0x80) == 0) { match++; r <<= 1; } diff --git a/lib/libc/net/name6.c b/lib/libc/net/name6.c index b34580e..38986fc 100644 --- a/lib/libc/net/name6.c +++ b/lib/libc/net/name6.c @@ -930,7 +930,7 @@ matchlen(struct sockaddr *src, struct sockaddr *dst) while (s < lim) if ((r = (*d++ ^ *s++)) != 0) { - while (r < addrlen * 8) { + while ((r & 0x80) == 0) { match++; r <<= 1; } -- cgit v1.1 From 23cf012b280ed8f8274e25a82bf44492132b1419 Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 5 Sep 2016 01:57:32 +0000 Subject: MFC r305241 fgetwc(3) may set both __SEOF and __SERR at once (in case of incomplete sequence near EOF), so we can't just check for (wc == WEOF && !__sfeof(fp)) and must relay on __sferror(fp) with __SERR clearing/restoring. --- lib/libc/stdio/fgetwln.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/libc') diff --git a/lib/libc/stdio/fgetwln.c b/lib/libc/stdio/fgetwln.c index 34a80a0..037657c 100644 --- a/lib/libc/stdio/fgetwln.c +++ b/lib/libc/stdio/fgetwln.c @@ -47,11 +47,16 @@ fgetwln_l(FILE * __restrict fp, size_t *lenp, locale_t locale) { wint_t wc; size_t len; + int savserr; + FIX_LOCALE(locale); FLOCKFILE(fp); ORIENT(fp, 1); + savserr = fp->_flags & __SERR; + fp->_flags &= ~__SERR; + len = 0; while ((wc = __fgetwc(fp, locale)) != WEOF) { #define GROW 512 @@ -64,7 +69,12 @@ fgetwln_l(FILE * __restrict fp, size_t *lenp, locale_t locale) if (wc == L'\n') break; } - if (len == 0 || (wc == WEOF && !__sfeof(fp))) + /* fgetwc(3) may set both __SEOF and __SERR at once. */ + if (__sferror(fp)) + goto error; + + fp->_flags |= savserr; + if (len == 0) goto error; FUNLOCKFILE(fp); -- cgit v1.1 From 87621d8c31cedd07df80d71e85939e7ef4d3cd52 Mon Sep 17 00:00:00 2001 From: jilles Date: Wed, 7 Sep 2016 21:04:39 +0000 Subject: MFC r305090: getvfsbyname(3): Remove [EFAULT] error. Since r101651 in 2002, getvfsbyname() has written *vfc using userland memcpy(), so the [EFAULT] error no longer occurs. --- lib/libc/gen/getvfsbyname.3 | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/gen/getvfsbyname.3 b/lib/libc/gen/getvfsbyname.3 index f2a5965..a0fc843 100644 --- a/lib/libc/gen/getvfsbyname.3 +++ b/lib/libc/gen/getvfsbyname.3 @@ -28,7 +28,7 @@ .\" @(#)kvm_getvfsbyname.3 8.3 (Berkeley) 5/4/95 .\" $FreeBSD$ .\" -.Dd April 5, 2007 +.Dd August 30, 2016 .Dt GETVFSBYNAME 3 .Os .Sh NAME @@ -97,11 +97,6 @@ sysctl is set to .Sh ERRORS The following errors may be reported: .Bl -tag -width Er -.It Bq Er EFAULT -The -.Fa vfc -argument -points to an invalid address. .It Bq Er ENOENT The .Fa name -- cgit v1.1 From 595191c4ea58a782473f4396aa34b53867c70aac Mon Sep 17 00:00:00 2001 From: jilles Date: Wed, 7 Sep 2016 21:09:44 +0000 Subject: MFC r305154: directory(3): Deprecate readdir_r(). Clarify dirent buffers. In existing implementations including FreeBSD, there is no reason to use readdir_r() in the common case where potentially multiple threads each list their own directory. Code using readdir() is simpler. What's more, although readdir_r() can safely be used on FreeBSD because NAME_MAX is forced to 255, it cannot be used safely on systems where {NAME_MAX} is not fixed. As a concrete example, FAT/NTFS filenames can be up to 255 UTF-16 code units long, which can be up to 765 UTF-8 bytes. Deprecating readdir_r() in POSIX has been proposed in http://www.austingroupbugs.net/view.php?id=696 and glibc wants to deprecate it as well. --- lib/libc/gen/directory.3 | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3 index f0d0f4b..b732863 100644 --- a/lib/libc/gen/directory.3 +++ b/lib/libc/gen/directory.3 @@ -28,7 +28,7 @@ .\" @(#)directory.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd May 6, 2015 +.Dd August 31, 2016 .Dt DIRECTORY 3 .Os .Sh NAME @@ -69,6 +69,15 @@ .Ft int .Fn dirfd "DIR *dirp" .Sh DESCRIPTION +.Bf -symbolic +The +.Fn readdir_r +interface is deprecated +because it cannot be used correctly unless +.Brq Va NAME_MAX +is a fixed value. +.Ef +.Pp The .Fn opendir function @@ -123,7 +132,13 @@ The .Fn readdir function returns a pointer to the next directory entry. -It returns +The directory entry remains valid until the next call to +.Fn readdir +or +.Fn closedir +on the same +.Em directory stream . +The function returns .Dv NULL upon reaching the end of the directory or on error. In the event of an error, @@ -140,6 +155,13 @@ provides the same functionality as but the caller must provide a directory .Fa entry buffer to store the results in. +The buffer must be large enough for a +.Vt struct dirent +with a +.Va d_name +array with +.Brq Va NAME_MAX ++ 1 elements. If the read succeeds, .Fa result is pointed at the -- cgit v1.1 From 56ade7a489e1dc176faf0206cbed2f8659a92648 Mon Sep 17 00:00:00 2001 From: ache Date: Thu, 8 Sep 2016 05:13:50 +0000 Subject: MFC r305406,r305409,r305412 1) Fix errors handling. 2) Prevent out of bounds access to ws[-1] (passed buffer) which happens when the first mb sequence is incomplete and there are not enougn chars in the read buffer. ws[-1] may lead to memory faults or false results, in case the memory here contains '\n'. 3) Fix n == 1 case. Here should be no physical read (fill buffer) attempt (we read n - 1 chars with the room for NUL, see fgets()), and no NULL return. --- lib/libc/stdio/fgetws.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/stdio/fgetws.c b/lib/libc/stdio/fgetws.c index f7a63fe..8513a37 100644 --- a/lib/libc/stdio/fgetws.c +++ b/lib/libc/stdio/fgetws.c @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); wchar_t * fgetws_l(wchar_t * __restrict ws, int n, FILE * __restrict fp, locale_t locale) { + int sret; wchar_t *wsp; size_t nconv; const char *src; @@ -56,23 +57,31 @@ fgetws_l(wchar_t * __restrict ws, int n, FILE * __restrict fp, locale_t locale) ORIENT(fp, 1); if (n <= 0) { + fp->_flags |= __SERR; errno = EINVAL; goto error; } + wsp = ws; + if (n == 1) + goto ok; + if (fp->_r <= 0 && __srefill(fp)) - /* EOF */ + /* EOF or ferror */ goto error; - wsp = ws; + + sret = 0; do { src = fp->_p; nl = memchr(fp->_p, '\n', fp->_r); nconv = l->__mbsnrtowcs(wsp, &src, nl != NULL ? (nl - fp->_p + 1) : fp->_r, n - 1, &fp->_mbstate); - if (nconv == (size_t)-1) + if (nconv == (size_t)-1) { /* Conversion error */ + fp->_flags |= __SERR; goto error; + } if (src == NULL) { /* * We hit a null byte. Increment the character count, @@ -88,23 +97,30 @@ fgetws_l(wchar_t * __restrict ws, int n, FILE * __restrict fp, locale_t locale) fp->_p = (unsigned char *)src; n -= nconv; wsp += nconv; - } while (wsp[-1] != L'\n' && n > 1 && (fp->_r > 0 || - __srefill(fp) == 0)); - if (wsp == ws) - /* EOF */ + } while ((wsp == ws || wsp[-1] != L'\n') && n > 1 && (fp->_r > 0 || + (sret = __srefill(fp)) == 0)); + if (sret && !__sfeof(fp)) + /* ferror */ goto error; - if (!l->__mbsinit(&fp->_mbstate)) + if (!l->__mbsinit(&fp->_mbstate)) { /* Incomplete character */ + fp->_flags |= __SERR; + errno = EILSEQ; goto error; + } + if (wsp == ws) + /* EOF */ + goto error; +ok: *wsp = L'\0'; FUNLOCKFILE(fp); - return (ws); error: FUNLOCKFILE(fp); return (NULL); } + wchar_t * fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp) { -- cgit v1.1 From 11eb45c08752b180e8521ee076638d3e021bc9db Mon Sep 17 00:00:00 2001 From: ache Date: Thu, 8 Sep 2016 07:14:48 +0000 Subject: MFC r305413 Fix error handling. --- lib/libc/stdio/fgets.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/stdio/fgets.c b/lib/libc/stdio/fgets.c index 9abf559..a2e39ed 100644 --- a/lib/libc/stdio/fgets.c +++ b/lib/libc/stdio/fgets.c @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93"; __FBSDID("$FreeBSD$"); #include "namespace.h" +#include #include #include #include "un-namespace.h" @@ -55,11 +56,16 @@ fgets(char * __restrict buf, int n, FILE * __restrict fp) char *s; unsigned char *p, *t; - if (n <= 0) /* sanity check */ - return (NULL); - FLOCKFILE(fp); ORIENT(fp, -1); + + if (n <= 0) { /* sanity check */ + fp->_flags |= __SERR; + errno = EINVAL; + FUNLOCKFILE(fp); + return (NULL); + } + s = buf; n--; /* leave space for NUL */ while (n != 0) { @@ -69,7 +75,7 @@ fgets(char * __restrict buf, int n, FILE * __restrict fp) if ((len = fp->_r) <= 0) { if (__srefill(fp)) { /* EOF/error: stop with partial or no line */ - if (s == buf) { + if (!__sfeof(fp) || s == buf) { FUNLOCKFILE(fp); return (NULL); } -- cgit v1.1 From 87eef91d299e2e52033532ece80c8acec27302e7 Mon Sep 17 00:00:00 2001 From: pfg Date: Thu, 8 Sep 2016 15:12:55 +0000 Subject: MFC r303889: libc/rpc: replace comma with semicolon when pertinent. Uses of commas instead of a semicolons can easily go undetected. The comma can serve as a statement separator but this shouldn't be abused when statements are meant to be standalone. --- lib/libc/rpc/svc_vc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/libc') diff --git a/lib/libc/rpc/svc_vc.c b/lib/libc/rpc/svc_vc.c index 304f90a..6ce99d3 100644 --- a/lib/libc/rpc/svc_vc.c +++ b/lib/libc/rpc/svc_vc.c @@ -740,7 +740,7 @@ svc_vc_rendezvous_ops(xprt) ops.xp_reply = (bool_t (*)(SVCXPRT *, struct rpc_msg *))abort; ops.xp_freeargs = - (bool_t (*)(SVCXPRT *, xdrproc_t, void *))abort, + (bool_t (*)(SVCXPRT *, xdrproc_t, void *))abort; ops.xp_destroy = svc_vc_destroy; ops2.xp_control = svc_vc_rendezvous_control; } -- cgit v1.1