pthread_sigqueue.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Copyright (C) 2009 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. #include <bits/kernel-features.h>
  23. int
  24. pthread_sigqueue (
  25. pthread_t threadid,
  26. int signo,
  27. const union sigval value)
  28. {
  29. #ifdef __NR_rt_tgsigqueueinfo
  30. struct pthread *pd = (struct pthread *) threadid;
  31. /* Make sure the descriptor is valid. */
  32. if (DEBUGGING_P && INVALID_TD_P (pd))
  33. /* Not a valid thread handle. */
  34. return ESRCH;
  35. /* Force load of pd->tid into local variable or register. Otherwise
  36. if a thread exits between ESRCH test and tgkill, we might return
  37. EINVAL, because pd->tid would be cleared by the kernel. */
  38. pid_t tid = atomic_forced_read (pd->tid);
  39. if (__builtin_expect (tid <= 0, 0))
  40. /* Not a valid thread handle. */
  41. return ESRCH;
  42. /* Disallow sending the signal we use for cancellation, timers, for
  43. for the setxid implementation. */
  44. if (signo == SIGCANCEL || signo == SIGTIMER || signo == SIGSETXID)
  45. return EINVAL;
  46. pid_t pid = getpid ();
  47. /* Set up the siginfo_t structure. */
  48. siginfo_t info;
  49. memset (&info, '\0', sizeof (siginfo_t));
  50. info.si_signo = signo;
  51. info.si_code = SI_QUEUE;
  52. info.si_pid = pid;
  53. info.si_uid = getuid ();
  54. info.si_value = value;
  55. /* We have a special syscall to do the work. */
  56. INTERNAL_SYSCALL_DECL (err);
  57. int val = INTERNAL_SYSCALL (rt_tgsigqueueinfo, err, 4,
  58. pid, tid, signo, &info);
  59. return (INTERNAL_SYSCALL_ERROR_P (val, err)
  60. ? INTERNAL_SYSCALL_ERRNO (val, err) : 0);
  61. #else
  62. return ENOSYS;
  63. #endif
  64. }