Back to index

glibc  2.9
unwind-resume.c
Go to the documentation of this file.
00001 /* Copyright (C) 2003 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Jakub Jelinek <jakub@redhat.com>.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public License as
00007    published by the Free Software Foundation; either version 2.1 of the
00008    License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; see the file COPYING.LIB.  If not,
00017    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.  */
00019 
00020 #include <dlfcn.h>
00021 #include <stdio.h>
00022 #include <unwind.h>
00023 
00024 static void (*libgcc_s_resume) (struct _Unwind_Exception *exc);
00025 static _Unwind_Reason_Code (*libgcc_s_personality)
00026   (int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
00027    struct _Unwind_Context *);
00028 static void (*libgcc_s_sjlj_register) (struct SjLj_Function_Context *);
00029 static void (*libgcc_s_sjlj_unregister) (struct SjLj_Function_Context *);
00030 
00031 static void
00032 init (void)
00033 {
00034   void *resume, *personality;
00035   void *handle;
00036   void *sjlj_register, *sjlj_unregister;
00037 
00038   handle = __libc_dlopen ("libgcc_s.so.1");
00039 
00040   if (handle == NULL
00041       || (sjlj_register = __libc_dlsym (handle, "_Unwind_SjLj_Register")) == NULL
00042       || (sjlj_unregister = __libc_dlsym (handle, "_Unwind_SjLj_Unregister")) == NULL
00043       || (resume = __libc_dlsym (handle, "_Unwind_SjLj_Resume")) == NULL
00044       || (personality = __libc_dlsym (handle, "__gcc_personality_sj0")) == NULL)
00045     __libc_fatal ("libgcc_s.so.1 must be installed for pthread_cancel to work\n");
00046 
00047   libgcc_s_resume = resume;
00048   libgcc_s_personality = personality;
00049   libgcc_s_sjlj_register = sjlj_register;
00050   libgcc_s_sjlj_unregister = sjlj_unregister;
00051 }
00052 
00053 void
00054 _Unwind_Resume (struct _Unwind_Exception *exc)
00055 {
00056   if (__builtin_expect (libgcc_s_resume == NULL, 0))
00057     init ();
00058   libgcc_s_resume (exc);
00059 }
00060 
00061 _Unwind_Reason_Code
00062 __gcc_personality_v0 (int version, _Unwind_Action actions,
00063                     _Unwind_Exception_Class exception_class,
00064                       struct _Unwind_Exception *ue_header,
00065                       struct _Unwind_Context *context)
00066 {
00067   if (__builtin_expect (libgcc_s_personality == NULL, 0))
00068     init ();
00069   return libgcc_s_personality (version, actions, exception_class,
00070                             ue_header, context);
00071 }
00072 
00073 void
00074 _Unwind_SjLj_Register (struct SjLj_Function_Context *fc)
00075 {
00076   if (__builtin_expect (libgcc_s_sjlj_register == NULL, 0))
00077     init ();
00078   libgcc_s_sjlj_register (fc);
00079 }
00080 
00081 void
00082 _Unwind_SjLj_Unregister (struct SjLj_Function_Context *fc)
00083 {
00084   if (__builtin_expect (libgcc_s_sjlj_unregister == NULL, 0))
00085     init ();
00086   libgcc_s_sjlj_unregister (fc);
00087 }