pthread_sigqueue.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright (C) 2009-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <signal.h>
  17. #include <string.h>
  18. #include <unistd.h>
  19. #include <pthreadP.h>
  20. #include <tls.h>
  21. #include <sysdep.h>
  22. int
  23. pthread_sigqueue (pthread_t threadid, int signo, const union sigval value)
  24. {
  25. #ifdef __NR_rt_tgsigqueueinfo
  26. struct pthread *pd = (struct pthread *) threadid;
  27. /* Make sure the descriptor is valid. */
  28. if (DEBUGGING_P && INVALID_TD_P (pd))
  29. /* Not a valid thread handle. */
  30. return ESRCH;
  31. /* Force load of pd->tid into local variable or register. Otherwise
  32. if a thread exits between ESRCH test and tgkill, we might return
  33. EINVAL, because pd->tid would be cleared by the kernel. */
  34. pid_t tid = atomic_forced_read (pd->tid);
  35. if (__glibc_unlikely (tid <= 0))
  36. /* Not a valid thread handle. */
  37. return ESRCH;
  38. /* Disallow sending the signal we use for cancellation, timers,
  39. for the setxid implementation. */
  40. if (signo == SIGCANCEL || signo == SIGTIMER || signo == SIGSETXID)
  41. return EINVAL;
  42. pid_t pid = getpid ();
  43. /* Set up the siginfo_t structure. */
  44. siginfo_t info;
  45. memset (&info, '\0', sizeof (siginfo_t));
  46. info.si_signo = signo;
  47. info.si_code = SI_QUEUE;
  48. info.si_pid = pid;
  49. info.si_uid = getuid ();
  50. info.si_value = value;
  51. /* We have a special syscall to do the work. */
  52. INTERNAL_SYSCALL_DECL (err);
  53. int val = INTERNAL_SYSCALL_CALL (rt_tgsigqueueinfo, err, pid, tid, signo,
  54. &info);
  55. return (INTERNAL_SYSCALL_ERROR_P (val, err)
  56. ? INTERNAL_SYSCALL_ERRNO (val, err) : 0);
  57. #else
  58. return ENOSYS;
  59. #endif
  60. }