diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2015-11-10 04:31:00 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2015-11-10 04:31:00 +0000 |
commit | f4c862a2e72bfacff5dcfbc873e4d27a4d848b02 (patch) | |
tree | 55ce8d828a416a6311793064b0650abf78062d59 /lib/libc | |
parent | 2de40dc0593bdf96a17ccf05b725d8b4260ec0e1 (diff) |
Split the intra-thread functionality from kill(2) into its own syscall
thrkill(2), rolling the kill(2) syscall number with the ABI change to
avoid breaking binaries during during the transition. thrkill(2) includes
a 'tcb' argument that eliminates the need for locking in pthread_kill()
and simplifies pthread_cancel(). Switch __stack_smash_handler() to use
thrkill(2) and explicitly unblock SIGABRT.
Minor bump to both libc and libpthread: make sure you install a new kernel!
ok semarie@
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/Symbols.list | 2 | ||||
-rw-r--r-- | lib/libc/gen/raise.c | 4 | ||||
-rw-r--r-- | lib/libc/hidden/signal.h | 3 | ||||
-rw-r--r-- | lib/libc/shlib_version | 2 | ||||
-rw-r--r-- | lib/libc/sys/Makefile.inc | 6 | ||||
-rw-r--r-- | lib/libc/sys/stack_protector.c | 9 | ||||
-rw-r--r-- | lib/libc/sys/thrkill.2 | 105 |
7 files changed, 119 insertions, 12 deletions
diff --git a/lib/libc/Symbols.list b/lib/libc/Symbols.list index 2c9c55189ca..70770229cd1 100644 --- a/lib/libc/Symbols.list +++ b/lib/libc/Symbols.list @@ -228,6 +228,7 @@ _thread_sys_symlinkat _thread_sys_sync _thread_sys_sysarch _thread_sys_sysctl +_thread_sys_thrkill _thread_sys_truncate _thread_sys_umask _thread_sys_unlink @@ -430,6 +431,7 @@ timer_delete timer_getoverrun timer_gettime timer_settime +thrkill truncate umask unlink diff --git a/lib/libc/gen/raise.c b/lib/libc/gen/raise.c index b477183d141..a0fa5b0f1b0 100644 --- a/lib/libc/gen/raise.c +++ b/lib/libc/gen/raise.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raise.c,v 1.7 2015/09/12 16:46:12 guenther Exp $ */ +/* $OpenBSD: raise.c,v 1.8 2015/11/10 04:30:59 guenther Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -34,6 +34,6 @@ int raise(int s) { - return (kill(getthrid(), s)); + return (thrkill(0, s, NULL)); } DEF_STRONG(raise); diff --git a/lib/libc/hidden/signal.h b/lib/libc/hidden/signal.h index f23578d725d..5a1f17fb5c1 100644 --- a/lib/libc/hidden/signal.h +++ b/lib/libc/hidden/signal.h @@ -1,4 +1,4 @@ -/* $OpenBSD: signal.h,v 1.9 2015/10/25 04:13:59 guenther Exp $ */ +/* $OpenBSD: signal.h,v 1.10 2015/11/10 04:30:59 guenther Exp $ */ /* * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> * @@ -52,5 +52,6 @@ PROTO_NORMAL(sigreturn); PROTO_NORMAL(sigsetmask); /*PROTO_CANCEL(sigsuspend); wrap to hide SIGTHR */ PROTO_DEPRECATED(sigvec); +PROTO_NORMAL(thrkill); #endif /* !_LIBC_SIGNAL_H */ diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version index 4635d2ba64c..fce886b2e0a 100644 --- a/lib/libc/shlib_version +++ b/lib/libc/shlib_version @@ -1,4 +1,4 @@ major=84 -minor=0 +minor=1 # note: If changes were made to include/thread_private.h or if system # calls were added/changed then librthread/shlib_version also be updated. diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 9fa5eb947d2..a6cd01ed765 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.135 2015/10/23 04:39:24 guenther Exp $ +# $OpenBSD: Makefile.inc,v 1.136 2015/11/10 04:30:59 guenther Exp $ # $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $ # @(#)Makefile.inc 8.1 (Berkeley) 6/17/93 @@ -57,7 +57,7 @@ ASM= __get_tcb.o __getcwd.o __semctl.o __set_tcb.o __syscall.o \ settimeofday.o setuid.o shmat.o shmctl.o shmdt.o \ shmget.o shutdown.o sigaltstack.o socket.o \ socketpair.o stat.o statfs.o swapctl.o symlink.o symlinkat.o \ - sync.o sysarch.o sysctl.o umask.o unlink.o unlinkat.o \ + sync.o sysarch.o sysctl.o thrkill.o umask.o unlink.o unlinkat.o \ unmount.o utimensat.o utimes.o utrace.o wait4.o write.o writev.o SRCS+= ${SRCS_${MACHINE_CPU}} @@ -166,7 +166,7 @@ MAN+= __get_tcb.2 __thrsigdivert.2 __thrsleep.2 _exit.2 accept.2 \ shmctl.2 shmget.2 shutdown.2 sigaction.2 sigaltstack.2 sigpending.2 \ sigprocmask.2 sigreturn.2 sigsuspend.2 socket.2 \ socketpair.2 stat.2 statfs.2 swapctl.2 symlink.2 \ - sync.2 sysarch.2 syscall.2 truncate.2 umask.2 unlink.2 \ + sync.2 sysarch.2 syscall.2 thrkill.2 truncate.2 umask.2 unlink.2 \ utimes.2 utrace.2 vfork.2 wait.2 write.2 MLINKS+=__get_tcb.2 __set_tcb.2 diff --git a/lib/libc/sys/stack_protector.c b/lib/libc/sys/stack_protector.c index 75c7ef83d79..e61a5f2f82f 100644 --- a/lib/libc/sys/stack_protector.c +++ b/lib/libc/sys/stack_protector.c @@ -1,4 +1,4 @@ -/* $OpenBSD: stack_protector.c,v 1.18 2015/11/10 04:14:03 guenther Exp $ */ +/* $OpenBSD: stack_protector.c,v 1.19 2015/11/10 04:30:59 guenther Exp $ */ /* * Copyright (c) 2002 Hiroaki Etoh, Federico G. Schwindt, and Miodrag Vallat. @@ -57,18 +57,17 @@ __stack_smash_handler(const char func[], int damaged) /* Immediately block all signal handlers from running code */ sigfillset(&mask); sigdelset(&mask, SIGABRT); - sigprocmask(SIG_BLOCK, &mask, NULL); + sigprocmask(SIG_SETMASK, &mask, NULL); - /* This may fail on a chroot jail... */ syslog_r(LOG_CRIT, &sdata, message, func); - bzero(&sa, sizeof(struct sigaction)); + memset(&sa, 0, sizeof(sa)); sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = SIG_DFL; sigaction(SIGABRT, &sa, NULL); - kill(getpid(), SIGABRT); + thrkill(0, SIGABRT, NULL); _exit(127); } diff --git a/lib/libc/sys/thrkill.2 b/lib/libc/sys/thrkill.2 new file mode 100644 index 00000000000..88fe1edebe7 --- /dev/null +++ b/lib/libc/sys/thrkill.2 @@ -0,0 +1,105 @@ +.\" $OpenBSD: thrkill.2,v 1.1 2015/11/10 04:30:59 guenther Exp $ +.\" $NetBSD: kill.2,v 1.7 1995/02/27 12:33:53 cgd Exp $ +.\" +.\" Copyright (c) 1980, 1991, 1993 +.\" 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. +.\" +.\" @(#)kill.2 8.3 (Berkeley) 4/19/94 +.\" +.Dd $Mdocdate: November 10 2015 $ +.Dt THRKILL 2 +.Os +.Sh NAME +.Nm thrkill +.Nd send signal to a thread in the same process +.Sh SYNOPSIS +.In signal.h +.Ft int +.Fn thrkill "pid_t tid" "int sig" "void *tcb" +.Sh DESCRIPTION +The +.Fn thrkill +function sends the signal given by +.Fa sig +to +.Fa tid , +a thread in the same process as the caller. +.Fn thrkill +will only succeed if +.Fa tcb +is either +.Dv NULL +or the address of the thread control block (TCB) of the target thread. +.Fa sig +may be one of the signals specified in +.Xr sigaction 2 +or it may be 0, in which case +error checking is performed but no +signal is actually sent. +.Pp +If +.Fa tid +is zero then the current thread is targeted. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn thrkill +will fail and no signal will be sent if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa sig +is not a valid signal number. +.It Bq Er ESRCH +The process doesn't have a thread with thread ID +.Fa tid . +.It Bq Er ESRCH +.Fa tcb +is not +.Dv NULL +and not the TCB address of the thread with thread ID +.Fa tid . +.El +.Sh SEE ALSO +.Xr __get_tcb 2 , +.Xr kill 2 , +.Xr sigaction 2 , +.Xr pthread_kill 3 , +.Xr raise 3 +.Sh STANDARDS +The +.Fn __thrsigdivert +function is specific to +.Ox +and should not be used in portable applications. +Use +.Xr pthread_kill 3 +instead. +.Sh HISTORY +The +.Fn thrkill +system call appeared in +.Ox 5.9 . |