[PATCH v3 6/6] nptl: Use pthread_kill on pthread_cancel
Adhemerval Zanella
adhemerval.zanella@linaro.org
Mon May 3 21:00:05 GMT 2021
Changes from v2:
* Rebased against master.
---
It consolidates the tgkill call and it is the first step of making
pthread_cancel async-signal-safe.
Checked on x86_64-linux-gnu.
---
nptl/Versions | 2 ++
nptl/pthreadP.h | 2 ++
nptl/pthread_cancel.c | 7 +------
nptl/pthread_kill.c | 19 +++++++++++++------
4 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/nptl/Versions b/nptl/Versions
index b0c575e30f..42a07c9ca3 100644
--- a/nptl/Versions
+++ b/nptl/Versions
@@ -291,6 +291,8 @@ libc {
__pthread_testcancel;
__sched_fifo_max_prio;
__sched_fifo_min_prio;
+ # Used for thread cancellation.
+ __pthread_kill_internal;
}
}
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 7d2f33be0d..ee92217598 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -552,6 +552,8 @@ extern int __pthread_equal (pthread_t thread1, pthread_t thread2);
extern int __pthread_detach (pthread_t th);
extern int __pthread_cancel (pthread_t th);
libc_hidden_proto (__pthread_kill)
+extern int __pthread_kill_internal (pthread_t threadid, int signo);
+libc_hidden_proto (__pthread_kill_internal);
extern void __pthread_exit (void *value) __attribute__ ((__noreturn__));
libc_hidden_proto (__pthread_exit)
extern int __pthread_join (pthread_t threadid, void **thread_return);
diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c
index d48d04881c..8dc1f23fdb 100644
--- a/nptl/pthread_cancel.c
+++ b/nptl/pthread_cancel.c
@@ -78,12 +78,7 @@ __pthread_cancel (pthread_t th)
/* The cancellation handler will take care of marking the
thread as canceled. */
- pid_t pid = __getpid ();
-
- int val = INTERNAL_SYSCALL_CALL (tgkill, pid, pd->tid,
- SIGCANCEL);
- if (INTERNAL_SYSCALL_ERROR_P (val))
- result = INTERNAL_SYSCALL_ERRNO (val);
+ __pthread_kill_internal (th, SIGCANCEL);
break;
}
diff --git a/nptl/pthread_kill.c b/nptl/pthread_kill.c
index d79531c10c..b1411f46b6 100644
--- a/nptl/pthread_kill.c
+++ b/nptl/pthread_kill.c
@@ -21,13 +21,8 @@
#include <shlib-compat.h>
int
-__pthread_kill (pthread_t threadid, int signo)
+__pthread_kill_internal (pthread_t threadid, int signo)
{
- /* Disallow sending the signal we use for cancellation, timers,
- for the setxid implementation. */
- if (__is_internal_signal (signo))
- return EINVAL;
-
sigset_t set;
__libc_signal_block_all (&set);
@@ -58,6 +53,18 @@ __pthread_kill (pthread_t threadid, int signo)
return val;
}
+libc_hidden_def (__pthread_kill_internal)
+
+int
+__pthread_kill (pthread_t threadid, int signo)
+{
+ /* Disallow sending the signal we use for cancellation, timers,
+ for the setxid implementation. */
+ if (__is_internal_signal (signo))
+ return EINVAL;
+
+ return __pthread_kill_internal (threadid, signo);
+}
/* Some architectures (for instance arm) might pull raise through libgcc, so
avoid the symbol version if it ends up being used on ld.so. */
#if !IS_IN(rtld)
--
2.30.2
More information about the Libc-alpha
mailing list