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
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, see <http://www.gnu.org/licenses/>. */
18
19 #include <dlfcn.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unwind.h>
23 #include <libgcc_s.h>
24 #include <unwind-resume.h>
25
26 #define __libc_dlopen(x) dlopen(x, (RTLD_LOCAL | RTLD_LAZY))
27 #define __libc_dlsym dlsym
28 #define __libc_dlclose dlclose
29
30 void (*__libgcc_s_resume) (struct _Unwind_Exception *exc)
31 attribute_hidden __attribute__ ((noreturn));
32
33 static _Unwind_Reason_Code (*libgcc_s_personality) PERSONALITY_PROTO;
34
35 extern
36 void abort(void);
37
38 void attribute_hidden __attribute__ ((cold))
__libgcc_s_init(void)39 __libgcc_s_init(void)
40 {
41 void *resume, *personality;
42 void *handle;
43
44 handle = __libc_dlopen (LIBGCC_S_SO);
45
46 if (handle == NULL
47 || (resume = __libc_dlsym (handle, "_Unwind_Resume")) == NULL
48 || (personality = __libc_dlsym (handle, "__gcc_personality_v0")) == NULL)
49 {
50 fprintf (stderr,
51 LIBGCC_S_SO " must be installed for pthread_cancel to work\n");
52 abort();
53 }
54
55 __libgcc_s_resume = resume;
56 libgcc_s_personality = personality;
57 }
58
59 #if !HAVE_ARCH_UNWIND_RESUME
60 void attribute_hidden
_Unwind_Resume(struct _Unwind_Exception * exc)61 _Unwind_Resume (struct _Unwind_Exception *exc)
62 {
63 if (__builtin_expect (libgcc_s_resume == NULL, 0))
64 __libgcc_s_init ();
65 __libgcc_s_resume (exc);
66 }
67 #endif
68
69 _Unwind_Reason_Code attribute_hidden
70 __gcc_personality_v0 PERSONALITY_PROTO
71 {
72 if (__builtin_expect (libgcc_s_personality == NULL, 0))
73 __libgcc_s_init ();
74 return libgcc_s_personality PERSONALITY_ARGS;
75 }
76