aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2020-12-07 16:21:55 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-06-09 15:16:45 -0300
commitf779b1efb35fe141e47952af3ac7f0540acca401 (patch)
treec85d1e5a2b7f93048159938802f187d98a1b8d09 /sysdeps
parent8c1c0aae2079039a629b15098d78f3d11aabefb4 (diff)
downloadglibc-f779b1efb35fe141e47952af3ac7f0540acca401.zip
glibc-f779b1efb35fe141e47952af3ac7f0540acca401.tar.gz
glibc-f779b1efb35fe141e47952af3ac7f0540acca401.tar.bz2
nptl: Implement raise in terms of pthread_kill
Now that pthread_kill is provided by libc.so it is possible to implement the generic POSIX implementation as 'pthread_kill(pthread_self(), sig)'. For Linux implementation, pthread_kill read the targeting TID from the TCB. For raise, this it not possible because it would make raise fail when issue after vfork (where creates the resulting process has a different TID from the parent, but its TCB is not updated as for pthread_create). To make raise use pthread_kill, it is make usable from vfork by getting the target thread id through gettid syscall. Checked on x86_64-linux-gnu and aarch64-linux-gnu.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/htl/pthreadP.h2
-rw-r--r--sysdeps/posix/raise.c11
-rw-r--r--sysdeps/unix/sysv/linux/raise.c52
3 files changed, 9 insertions, 56 deletions
diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h
index 8e2cf2c..3b357b7 100644
--- a/sysdeps/htl/pthreadP.h
+++ b/sysdeps/htl/pthreadP.h
@@ -31,8 +31,6 @@ extern void __pthread_init_static_tls (struct link_map *) attribute_hidden;
/* These represent the interface used by glibc itself. */
-extern pthread_t __pthread_self (void);
-extern int __pthread_kill (pthread_t threadid, int signo);
extern struct __pthread **__pthread_threads;
extern int __pthread_mutex_init (pthread_mutex_t *__mutex, const pthread_mutexattr_t *__attr);
diff --git a/sysdeps/posix/raise.c b/sysdeps/posix/raise.c
index 9fdb4d5..4806c0c 100644
--- a/sysdeps/posix/raise.c
+++ b/sysdeps/posix/raise.c
@@ -16,13 +16,20 @@
<https://www.gnu.org/licenses/>. */
#include <signal.h>
-#include <unistd.h>
+#include <errno.h>
+#include <pthread.h>
/* Raise the signal SIG. */
int
raise (int sig)
{
- return __kill (__getpid (), sig);
+ int ret = __pthread_kill (__pthread_self (), sig);
+ if (ret != 0)
+ {
+ __set_errno (ret);
+ ret = -1;
+ }
+ return ret;
}
libc_hidden_def (raise)
weak_alias (raise, gsignal)
diff --git a/sysdeps/unix/sysv/linux/raise.c b/sysdeps/unix/sysv/linux/raise.c
deleted file mode 100644
index 9be3b37..0000000
--- a/sysdeps/unix/sysv/linux/raise.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/* Copyright (C) 2002-2021 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <signal.h>
-#include <sysdep.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <internal-signals.h>
-
-int
-raise (int sig)
-{
- /* rt_sigprocmask may fail if:
-
- 1. sigsetsize != sizeof (sigset_t) (EINVAL)
- 2. a failure in copy from/to user space (EFAULT)
- 3. an invalid 'how' operation (EINVAL)
-
- The first case is already handle in glibc syscall call by using the arch
- defined _NSIG. Second case is handled by using a stack allocated mask.
- The last one should be handled by the block/unblock functions. */
-
- sigset_t set;
- __libc_signal_block_app (&set);
-
- pid_t pid = INTERNAL_SYSCALL_CALL (getpid);
- pid_t tid = INTERNAL_SYSCALL_CALL (gettid);
-
- int ret = INLINE_SYSCALL_CALL (tgkill, pid, tid, sig);
-
- __libc_signal_restore_set (&set);
-
- return ret;
-}
-libc_hidden_def (raise)
-weak_alias (raise, gsignal)