unwind-resume.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 not,
  14. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. #include <dlfcn.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <unwind.h>
  20. static void (*libgcc_s_resume) (struct _Unwind_Exception *exc);
  21. static _Unwind_Reason_Code (*libgcc_s_personality)
  22. (int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
  23. struct _Unwind_Context *);
  24. extern
  25. void abort(void);
  26. static void
  27. init (void)
  28. {
  29. void *resume = NULL;
  30. void *personality = NULL;
  31. void *handle;
  32. resume = personality = NULL; /* make gcc silent */
  33. handle = dlopen ("libgcc_s.so.1", (RTLD_LOCAL | RTLD_LAZY));
  34. if (handle == NULL
  35. || (resume = dlsym (handle, "_Unwind_Resume")) == NULL
  36. || (personality = dlsym (handle, "__gcc_personality_v0")) == NULL)
  37. {
  38. printf("libgcc_s.so.1 must be installed for pthread_cancel to work\n");
  39. abort();
  40. }
  41. libgcc_s_resume = resume;
  42. libgcc_s_personality = personality;
  43. }
  44. void
  45. _Unwind_Resume (struct _Unwind_Exception *exc)
  46. {
  47. if (__builtin_expect (libgcc_s_resume == NULL, 0))
  48. init ();
  49. libgcc_s_resume (exc);
  50. }
  51. _Unwind_Reason_Code
  52. __gcc_personality_v0 (int version, _Unwind_Action actions,
  53. _Unwind_Exception_Class exception_class,
  54. struct _Unwind_Exception *ue_header,
  55. struct _Unwind_Context *context)
  56. {
  57. if (__builtin_expect (libgcc_s_personality == NULL, 0))
  58. init ();
  59. return libgcc_s_personality (version, actions, exception_class,
  60. ue_header, context);
  61. }