Back to index

glibc  2.9
unwind-resume.c
Go to the documentation of this file.
00001 /* Copyright (C) 2003, 2005 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   (_Unwind_State, struct _Unwind_Exception *, struct _Unwind_Context *);
00027 
00028 static void init (void) __attribute_used__;
00029 
00030 static void
00031 init (void)
00032 {
00033   void *resume, *personality;
00034   void *handle;
00035 
00036   handle = __libc_dlopen ("libgcc_s.so.1");
00037 
00038   if (handle == NULL
00039       || (resume = __libc_dlsym (handle, "_Unwind_Resume")) == NULL
00040       || (personality = __libc_dlsym (handle, "__gcc_personality_v0")) == NULL)
00041     __libc_fatal ("libgcc_s.so.1 must be installed for pthread_cancel to work\n");
00042 
00043   libgcc_s_resume = resume;
00044   libgcc_s_personality = personality;
00045 }
00046 
00047 /* It's vitally important that _Unwind_Resume not have a stack frame; the
00048    ARM unwinder relies on register state at entrance.  So we write this in
00049    assembly.  */
00050 
00051 asm (
00052 "      .globl _Unwind_Resume\n"
00053 "      .type  _Unwind_Resume, %function\n"
00054 "_Unwind_Resume:\n"
00055 "      stmfd  sp!, {r4, r5, r6, lr}\n"
00056 "      ldr    r4, 1f\n"
00057 "      ldr    r5, 2f\n"
00058 "3:    add    r4, pc, r4\n"
00059 "      ldr    r3, [r4, r5]\n"
00060 "      mov    r6, r0\n"
00061 "      cmp    r3, #0\n"
00062 "      beq    4f\n"
00063 "5:    mov    r0, r6\n"
00064 "      ldmfd  sp!, {r4, r5, r6, lr}\n"
00065 "      bx     r3\n"
00066 "4:    bl     init\n"
00067 "      ldr    r3, [r4, r5]\n"
00068 "      b      5b\n"
00069 "1:    .word  _GLOBAL_OFFSET_TABLE_ - 3b - 8\n"
00070 "2:    .word  libgcc_s_resume(GOTOFF)\n"
00071 "      .size  _Unwind_Resume, .-_Unwind_Resume\n"
00072 );
00073 
00074 _Unwind_Reason_Code
00075 __gcc_personality_v0 (_Unwind_State state,
00076                     struct _Unwind_Exception *ue_header,
00077                     struct _Unwind_Context *context)
00078 {
00079   if (__builtin_expect (libgcc_s_personality == NULL, 0))
00080     init ();
00081   return libgcc_s_personality (state, ue_header, context);
00082 }