unwind-resume.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Copyright (C) 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Jakub Jelinek <jakub@redhat.com>.
  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 License as
  6. published by the Free Software Foundation; either version 2.1 of the
  7. 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; see the file COPYING.LIB. If
  14. not, see <http://www.gnu.org/licenses/>. */
  15. #include <dlfcn.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <unwind.h>
  19. #include <libgcc_s.h>
  20. #include <unwind-resume.h>
  21. #define __libc_dlopen(x) dlopen(x, (RTLD_LOCAL | RTLD_LAZY))
  22. #define __libc_dlsym dlsym
  23. #define __libc_dlclose dlclose
  24. void (*__libgcc_s_resume) (struct _Unwind_Exception *exc)
  25. attribute_hidden __attribute__ ((noreturn));
  26. static _Unwind_Reason_Code (*libgcc_s_personality) PERSONALITY_PROTO;
  27. extern
  28. void abort(void);
  29. void attribute_hidden __attribute__ ((cold))
  30. __libgcc_s_init(void)
  31. {
  32. void *resume, *personality;
  33. void *handle;
  34. handle = __libc_dlopen (LIBGCC_S_SO);
  35. if (handle == NULL
  36. || (resume = __libc_dlsym (handle, "_Unwind_Resume")) == NULL
  37. || (personality = __libc_dlsym (handle, "__gcc_personality_v0")) == NULL)
  38. {
  39. fprintf (stderr,
  40. LIBGCC_S_SO " must be installed for pthread_cancel to work\n");
  41. abort();
  42. }
  43. __libgcc_s_resume = resume;
  44. libgcc_s_personality = personality;
  45. }
  46. #if !HAVE_ARCH_UNWIND_RESUME
  47. void attribute_hidden
  48. _Unwind_Resume (struct _Unwind_Exception *exc)
  49. {
  50. if (__builtin_expect (libgcc_s_resume == NULL, 0))
  51. __libgcc_s_init ();
  52. __libgcc_s_resume (exc);
  53. }
  54. #endif
  55. _Unwind_Reason_Code attribute_hidden
  56. __gcc_personality_v0 PERSONALITY_PROTO
  57. {
  58. if (__builtin_expect (libgcc_s_personality == NULL, 0))
  59. __libgcc_s_init ();
  60. return libgcc_s_personality PERSONALITY_ARGS;
  61. }