unwind-resume.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 <unwind.h>
  19. #define __libc_dlopen(x) dlopen(x, (RTLD_LOCAL | RTLD_LAZY))
  20. #define __libc_dlsym dlsym
  21. #define __libc_dlclose dlclose
  22. static void (*libgcc_s_resume) (struct _Unwind_Exception *exc);
  23. static _Unwind_Reason_Code (*libgcc_s_personality)
  24. (int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
  25. struct _Unwind_Context *);
  26. static void (*libgcc_s_sjlj_register) (struct SjLj_Function_Context *);
  27. static void (*libgcc_s_sjlj_unregister) (struct SjLj_Function_Context *);
  28. static void
  29. init (void)
  30. {
  31. void *resume, *personality;
  32. void *handle;
  33. void *sjlj_register, *sjlj_unregister;
  34. handle = __libc_dlopen ("libgcc_s.so.1");
  35. if (handle == NULL
  36. || (sjlj_register = __libc_dlsym (handle, "_Unwind_SjLj_Register")) == NULL
  37. || (sjlj_unregister = __libc_dlsym (handle, "_Unwind_SjLj_Unregister")) == NULL
  38. || (resume = __libc_dlsym (handle, "_Unwind_SjLj_Resume")) == NULL
  39. || (personality = __libc_dlsym (handle, "__gcc_personality_sj0")) == NULL)
  40. fprintf(stderr, "libgcc_s.so.1 must be installed for pthread_cancel to work\n");
  41. libgcc_s_resume = resume;
  42. libgcc_s_personality = personality;
  43. libgcc_s_sjlj_register = sjlj_register;
  44. libgcc_s_sjlj_unregister = sjlj_unregister;
  45. }
  46. void
  47. _Unwind_Resume (struct _Unwind_Exception *exc)
  48. {
  49. if (__builtin_expect (libgcc_s_resume == NULL, 0))
  50. init ();
  51. libgcc_s_resume (exc);
  52. }
  53. _Unwind_Reason_Code
  54. __gcc_personality_v0 (int version, _Unwind_Action actions,
  55. _Unwind_Exception_Class exception_class,
  56. struct _Unwind_Exception *ue_header,
  57. struct _Unwind_Context *context)
  58. {
  59. if (__builtin_expect (libgcc_s_personality == NULL, 0))
  60. init ();
  61. return libgcc_s_personality (version, actions, exception_class,
  62. ue_header, context);
  63. }
  64. void
  65. _Unwind_SjLj_Register (struct SjLj_Function_Context *fc)
  66. {
  67. if (__builtin_expect (libgcc_s_sjlj_register == NULL, 0))
  68. init ();
  69. libgcc_s_sjlj_register (fc);
  70. }
  71. void
  72. _Unwind_SjLj_Unregister (struct SjLj_Function_Context *fc)
  73. {
  74. if (__builtin_expect (libgcc_s_sjlj_unregister == NULL, 0))
  75. init ();
  76. libgcc_s_sjlj_unregister (fc);
  77. }