pt-raise.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  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 <sysdep.h>
  18. #include <tls.h>
  19. #include <bits/kernel-features.h>
  20. int
  21. raise (
  22. int sig)
  23. {
  24. #if (defined(__ASSUME_TGKILL) && __ASSUME_TGKILL) || defined __NR_tgkill
  25. /* raise is an async-safe function. It could be called while the
  26. fork function temporarily invalidated the PID field. Adjust for
  27. that. */
  28. pid_t pid = THREAD_GETMEM (THREAD_SELF, pid);
  29. if (__builtin_expect (pid < 0, 0))
  30. pid = -pid;
  31. #endif
  32. #if defined(__ASSUME_TGKILL) && __ASSUME_TGKILL
  33. return INLINE_SYSCALL (tgkill, 3, pid, THREAD_GETMEM (THREAD_SELF, tid),
  34. sig);
  35. #else
  36. # ifdef __NR_tgkill
  37. int res = INLINE_SYSCALL (tgkill, 3, pid, THREAD_GETMEM (THREAD_SELF, tid),
  38. sig);
  39. if (res != -1 || errno != ENOSYS)
  40. return res;
  41. # endif
  42. return INLINE_SYSCALL (tkill, 2, THREAD_GETMEM (THREAD_SELF, tid), sig);
  43. #endif
  44. }