diff mbox series

[8/8] nptl: Use pthread_kill on pthread_cancel

Message ID 20201207212757.3948164-8-adhemerval.zanella@linaro.org
State New
Headers show
Series [v2,1/8] nptl: Move Linux pthread_kill to nptl | expand

Commit Message

Adhemerval Zanella Dec. 7, 2020, 9:27 p.m. UTC
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 mbox series

Patch

diff --git a/nptl/Versions b/nptl/Versions
index 7cfe39a91c..ec68f8bb3d 100644
--- a/nptl/Versions
+++ b/nptl/Versions
@@ -66,6 +66,8 @@  libc {
     __pthread_attr_copy;
     __pthread_getattr_default_np;
     __pthread_attr_setsigmask_internal;
+    # Used for thread cancellation.
+    __pthread_kill_internal;
   }
 }
 
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 1a8518ef23..40499d6881 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -514,6 +514,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__));
 extern int __pthread_join (pthread_t threadid, void **thread_return);
 extern int __pthread_setcanceltype (int type, int *oldtype);
diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c
index 266fd77284..766dfca260 100644
--- a/nptl/pthread_cancel.c
+++ b/nptl/pthread_cancel.c
@@ -69,12 +69,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 cf12fa743f..97f1bf2b4b 100644
--- a/nptl/pthread_kill.c
+++ b/nptl/pthread_kill.c
@@ -20,13 +20,8 @@ 
 #include <pthreadP.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);
 
@@ -57,5 +52,17 @@  __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);
+}
 libc_hidden_def (__pthread_kill)
 weak_alias (__pthread_kill, pthread_kill)